-
Notifications
You must be signed in to change notification settings - Fork 257
Add Recent Drafts section and Drafts library tab #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SajalChaplot
wants to merge
11
commits into
main
Choose a base branch
from
ai_main_e7ce0f2d56ed4d349867
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dd55159
Add recent drafts section and library drafts tab
builderio-bot 8687072
Commit unstaged changes
builderio-bot 5bb7a25
fix: format code to pass linting checks
builderio-bot 8299e06
Merge branch 'main' into ai_main_e7ce0f2d56ed4d349867
SajalChaplot 9fe7a15
Add agent skills and docs for visual answers, actions, and mini-apps
builderio-bot 87b9604
Merge remote-tracking branch 'refs/remotes/origin/main' into ai_main_…
builderio-bot f84f07d
Show all library drafts in standalone picker Drafts tab
builderio-bot 59183b4
Merge remote-tracking branch 'refs/remotes/origin/main' into ai_main_…
builderio-bot aaa1a6d
Add tsup bundled config artifacts to gitignore
builderio-bot db05d9a
commit pending changes
builderio-bot 95606b0
Resolve merge conflicts in visual-plan skill documentation
builderio-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import action from "./list-draft-assets.js"; | ||
|
|
||
| describe("list-draft-assets schema", () => { | ||
| it("defaults to no filters when given an empty object", () => { | ||
| const parsed = action.schema.parse({}); | ||
| expect(parsed.libraryId).toBeUndefined(); | ||
| expect(parsed.limit).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("coerces a numeric string limit", () => { | ||
| const parsed = action.schema.parse({ limit: "5" }); | ||
| expect(parsed.limit).toBe(5); | ||
| }); | ||
|
|
||
| it("rejects an out-of-range limit", () => { | ||
| expect(() => action.schema.parse({ limit: 0 })).toThrow(); | ||
| expect(() => action.schema.parse({ limit: 999 })).toThrow(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { defineAction } from "@agent-native/core"; | ||
| import { z } from "zod"; | ||
| import { and, desc, eq, inArray, isNull } from "drizzle-orm"; | ||
| import { accessFilter } from "@agent-native/core/sharing"; | ||
| import { getDb, schema } from "../server/db/index.js"; | ||
| import { serializeAsset } from "./_helpers.js"; | ||
|
|
||
| export default defineAction({ | ||
| description: | ||
| "List unsaved draft generations (generated candidate assets) across accessible libraries, newest first.", | ||
| schema: z.object({ | ||
| libraryId: z.string().optional(), | ||
| limit: z.coerce.number().int().min(1).max(500).optional(), | ||
| }), | ||
| http: { method: "GET" }, | ||
| readOnly: true, | ||
| run: async ({ libraryId, limit }) => { | ||
| const db = getDb(); | ||
| const libraryFilters = [ | ||
| accessFilter(schema.assetLibraries, schema.assetLibraryShares), | ||
| isNull(schema.assetLibraries.archivedAt), | ||
| ]; | ||
| if (libraryId) libraryFilters.push(eq(schema.assetLibraries.id, libraryId)); | ||
| const accessibleLibraries = await db | ||
| .select({ id: schema.assetLibraries.id }) | ||
| .from(schema.assetLibraries) | ||
| .where(and(...libraryFilters)); | ||
| const libraryIds = accessibleLibraries.map((row) => row.id); | ||
| if (!libraryIds.length) return { count: 0, assets: [] }; | ||
|
|
||
| const rows = await db | ||
| .select() | ||
| .from(schema.assets) | ||
| .where( | ||
| and( | ||
| inArray(schema.assets.libraryId, libraryIds), | ||
| eq(schema.assets.role, "generated"), | ||
| eq(schema.assets.status, "candidate"), | ||
| ), | ||
| ) | ||
| .orderBy(desc(schema.assets.createdAt)) | ||
| .limit(limit ?? 50); | ||
|
|
||
| return { | ||
| count: rows.length, | ||
| assets: rows.map((row) => serializeAsset(row)), | ||
| }; | ||
| }, | ||
| }); | ||
95 changes: 95 additions & 0 deletions
95
templates/assets/app/components/create/RecentDraftsSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { Link } from "react-router"; | ||
| import { IconArrowUpRight, IconPhoto } from "@tabler/icons-react"; | ||
| import { useActionQuery } from "@agent-native/core/client"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Skeleton } from "@/components/ui/skeleton"; | ||
|
|
||
| type DraftAsset = { | ||
| id: string; | ||
| title?: string | null; | ||
| prompt?: string | null; | ||
| mediaType?: string | null; | ||
| mimeType?: string | null; | ||
| thumbnailUrl?: string | null; | ||
| previewUrl?: string | null; | ||
| url?: string | null; | ||
| }; | ||
|
|
||
| const RECENT_DRAFTS_LIMIT = 5; | ||
|
|
||
| export function RecentDraftsSection() { | ||
| const { data, isLoading } = useActionQuery("list-draft-assets", { | ||
| limit: RECENT_DRAFTS_LIMIT, | ||
| }); | ||
| const drafts = ((data as any)?.assets ?? []) as DraftAsset[]; | ||
|
|
||
| if (!isLoading && drafts.length === 0) return null; | ||
|
|
||
| return ( | ||
| <section className="space-y-3"> | ||
| <div className="flex flex-wrap items-center justify-between gap-3"> | ||
| <h2 className="text-sm font-semibold text-foreground">Recent Drafts</h2> | ||
| <Button asChild variant="outline" size="sm"> | ||
| <Link to="/library?tab=drafts"> | ||
| View all drafts | ||
| <IconArrowUpRight size={15} className="ml-1.5" /> | ||
| </Link> | ||
| </Button> | ||
| </div> | ||
|
|
||
| <div className="grid grid-cols-3 gap-3 sm:grid-cols-5"> | ||
| {isLoading | ||
| ? Array.from({ length: RECENT_DRAFTS_LIMIT }).map((_, index) => ( | ||
| <Skeleton key={index} className="aspect-square rounded-lg" /> | ||
| )) | ||
| : drafts.map((draft) => ( | ||
| <Link | ||
| key={draft.id} | ||
| to={`/asset/${encodeURIComponent(draft.id)}`} | ||
| title={draft.title || draft.prompt || "Draft asset"} | ||
| className="group block overflow-hidden rounded-lg border border-border bg-card shadow-sm transition hover:border-primary/60 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" | ||
| > | ||
| <div className="aspect-square bg-muted"> | ||
| <DraftThumbnail draft={draft} /> | ||
| </div> | ||
| </Link> | ||
| ))} | ||
| </div> | ||
| </section> | ||
| ); | ||
| } | ||
|
|
||
| function DraftThumbnail({ draft }: { draft: DraftAsset }) { | ||
| const isVideo = | ||
| draft.mediaType === "video" || draft.mimeType?.startsWith("video/"); | ||
| const source = draft.thumbnailUrl ?? draft.previewUrl ?? draft.url ?? ""; | ||
|
|
||
| if (isVideo && !draft.thumbnailUrl) { | ||
| return ( | ||
| <video | ||
| src={draft.previewUrl ?? draft.url ?? undefined} | ||
| muted | ||
| playsInline | ||
| preload="metadata" | ||
| className="h-full w-full object-cover transition group-hover:scale-[1.02]" | ||
| /> | ||
|
Copilot marked this conversation as resolved.
|
||
| ); | ||
| } | ||
|
|
||
| if (!source) { | ||
| return ( | ||
| <div className="flex h-full w-full items-center justify-center text-muted-foreground"> | ||
| <IconPhoto className="size-5" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <img | ||
| src={source} | ||
| alt={draft.title ?? draft.prompt ?? "Draft asset"} | ||
| loading="lazy" | ||
| className="h-full w-full object-cover transition group-hover:scale-[1.02]" | ||
| /> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Added
actions/list-draft-assets.spec.tscovering schema defaults, limit coercion, and out-of-range rejection (mirroringlist-assets.spec.ts). Passes locally.