From fa83659b482d2674c7509bfaa3d22d7e77d485bd Mon Sep 17 00:00:00 2001 From: Guilhem Date: Wed, 4 Nov 2026 18:10:07 +0100 Subject: [PATCH] feat: open shared artifacts full screen and switch between them (#12206) * feat: open shared artifacts full screen and switch between them from the header * fix: drop the shared artifact actions' labels when the header bar is narrow --- backend/tests/ai_shared_artifacts.rs | 25 +++ backend/windmill-api/openapi.yaml | 21 ++ .../windmill-api/src/ai_shared_artifacts.rs | 31 ++- .../lib/components/BreadcrumbNavPicker.svelte | 18 +- .../src/lib/components/NavBreadcrumb.svelte | 8 +- .../components/common/button/Button.svelte | 5 +- .../artifacts/ArtifactExportButton.svelte | 5 +- .../copilot/chat/artifacts/artifactSharing.ts | 10 +- .../components/pageHeaderRegistry.svelte.ts | 8 + .../sessions/PreviewRouterPicker.svelte | 2 +- .../shared_artifacts/[id]/+page.svelte | 183 +++++++++++------- 11 files changed, 237 insertions(+), 79 deletions(-) diff --git a/backend/tests/ai_shared_artifacts.rs b/backend/tests/ai_shared_artifacts.rs index 17dd313755..6282244b05 100644 --- a/backend/tests/ai_shared_artifacts.rs +++ b/backend/tests/ai_shared_artifacts.rs @@ -75,6 +75,22 @@ async fn shared_artifact_is_served_to_members_until_it_expires( "a share was served through another workspace's path" ); + let listed: Value = client + .get(format!("{base}/list")) + .header("Authorization", ADMIN) + .send() + .await? + .json() + .await?; + assert_eq!( + listed[0]["id"], id, + "the live share was not listed: {listed}" + ); + assert!( + listed[0].get("content").is_none(), + "the list carried content" + ); + sqlx::query( "UPDATE ai_shared_artifact SET shared_at = now() - ($1::bigint + 60) * interval '1 second'", ) @@ -89,6 +105,15 @@ async fn shared_artifact_is_served_to_members_until_it_expires( .await?; assert_eq!(resp.status(), 404, "an expired share was served"); + let listed: Value = client + .get(format!("{base}/list")) + .header("Authorization", ADMIN) + .send() + .await? + .json() + .await?; + assert_eq!(listed, json!([]), "an expired share was listed"); + let status: Value = client .get(format!("{base}/status?artifact_id=plan:session-1")) .header("Authorization", MEMBER) diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index bfe317c1b7..8809520103 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -15116,6 +15116,27 @@ paths: share: $ref: "#/components/schemas/SharedAiArtifactInfo" + /w/{workspace}/ai/shared_artifacts/list: + get: + summary: list the workspace's live shared AI session artifacts + description: > + Every share still inside its retention window, newest first, without its content. + Capped at 500. + operationId: listSharedAiArtifacts + tags: + - ai + parameters: + - $ref: "#/components/parameters/WorkspaceId" + responses: + "200": + description: the live shares + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/SharedAiArtifactInfo" + /w/{workspace}/ai/shared_artifacts/get/{id}: get: summary: get a shared AI session artifact diff --git a/backend/windmill-api/src/ai_shared_artifacts.rs b/backend/windmill-api/src/ai_shared_artifacts.rs index 36ad0ecd2e..a1fce3abf9 100644 --- a/backend/windmill-api/src/ai_shared_artifacts.rs +++ b/backend/windmill-api/src/ai_shared_artifacts.rs @@ -42,6 +42,7 @@ pub fn workspaced_service() -> Router { post(share_artifact).layer(DefaultBodyLimit::max(SHARE_BODY_LIMIT)), ) .route("/status", get(get_share_status)) + .route("/list", get(list_shared_artifacts)) .route("/get/{id}", get(get_shared_artifact)) .route("/delete/{id}", delete(unshare_artifact)) } @@ -71,7 +72,7 @@ struct ShareArtifact { content: String, } -#[derive(Serialize)] +#[derive(Serialize, sqlx::FromRow)] struct SharedArtifactInfo { id: Uuid, name: String, @@ -243,6 +244,34 @@ async fn get_share_status( Ok(Json(ShareStatus { retention_secs, share })) } +/// Live shares cap at one per author and artifact, but nothing caps authors, so the list is. +const LIST_LIMIT: i64 = 500; + +/// Every live share of the workspace, newest first, without content: any member may open each +/// of them, so any member may see which there are. +async fn list_shared_artifacts( + _authed: ApiAuthed, + Extension(db): Extension, + Path(w_id): Path, +) -> JsonResult> { + let retention_secs = ai_shared_artifact_retention_secs(); + let rows = sqlx::query_as::<_, SharedArtifactInfo>( + "SELECT id, name, kind, version, created_by, shared_at, + shared_at + ($2::bigint::text || ' s')::interval AS expires_at + FROM ai_shared_artifact + WHERE workspace_id = $1 + AND shared_at > now() - ($2::bigint::text || ' s')::interval + ORDER BY shared_at DESC + LIMIT $3", + ) + .bind(&w_id) + .bind(retention_secs) + .bind(LIST_LIMIT) + .fetch_all(&db) + .await?; + Ok(Json(rows)) +} + /// Any member of the workspace may read a live share: that is what sharing it granted. async fn get_shared_artifact( authed: ApiAuthed, diff --git a/frontend/src/lib/components/BreadcrumbNavPicker.svelte b/frontend/src/lib/components/BreadcrumbNavPicker.svelte index 1f053c0d92..33b688c206 100644 --- a/frontend/src/lib/components/BreadcrumbNavPicker.svelte +++ b/frontend/src/lib/components/BreadcrumbNavPicker.svelte @@ -13,14 +13,20 @@ highlighted, a workspace page inside Pages with that page highlighted. import { page } from '$app/state' import Popover from '$lib/components/meltComponents/Popover.svelte' import PreviewRouterPicker, { type Scope } from './sessions/PreviewRouterPicker.svelte' - import { pageKey, parsePreviewItemRoute, type PreviewTarget } from './sessions/previewRouter' + import { + artifactKey, + pageKey, + parsePreviewItemRoute, + type PreviewTarget + } from './sessions/previewRouter' import { editPathFor, leafKeyFor, viewPathFor, type WorkspaceItem } from './workspacePicker' import { logFeatureUsage } from '$lib/utils/featureUsage' - import type { PageHeaderItem } from './pageHeaderRegistry.svelte' + import type { PageHeaderItem, PageHeaderSection } from './pageHeaderRegistry.svelte' let { item, pagePath, + artifacts, actingWorkspaceId, iconSize = 14 }: { @@ -28,6 +34,8 @@ highlighted, a workspace page inside Pages with that page highlighted. item?: PageHeaderItem /** The route of a workspace page, to highlight it among the pages. */ pagePath?: string + /** Artifacts to list, and the one the page shows, to land on it among them. */ + artifacts?: PageHeaderSection['navArtifacts'] /** Load from, and navigate within, this workspace rather than the one the app points at. */ actingWorkspaceId?: string iconSize?: number @@ -53,7 +61,9 @@ highlighted, a workspace page inside Pages with that page highlighted. return parts.length >= 3 ? { kind: 'all', dir: parts.slice(0, -1).join('/') } : undefined }) const initialHighlight = $derived( - currentItem + artifacts?.currentId + ? artifactKey(artifacts.currentId) + : currentItem ? leafKeyFor(currentItem.kind, currentItem.path) : pagePath ? pageKey(pagePath) @@ -70,6 +80,7 @@ highlighted, a workspace page inside Pages with that page highlighted. function hrefFor(target: PreviewTarget): string | undefined { if (target.type === 'page') return target.href + if (target.type === 'artifact') return artifacts?.href(target.id) if (target.type === 'item') return target.mode === 'view' ? viewPathFor(target.item) : editPathFor(target.item) return undefined @@ -115,6 +126,7 @@ highlighted, a workspace page inside Pages with that page highlighted. {initialScope} {initialHighlight} {currentItem} + artifacts={artifacts?.items} workspaceId={actingWorkspaceId} onPick={pick} /> diff --git a/frontend/src/lib/components/NavBreadcrumb.svelte b/frontend/src/lib/components/NavBreadcrumb.svelte index 98b613e1c3..6d776e6a84 100644 --- a/frontend/src/lib/components/NavBreadcrumb.svelte +++ b/frontend/src/lib/components/NavBreadcrumb.svelte @@ -290,7 +290,13 @@ not this component) — so the lead can run the whole line. {:else} - + {/if} {/if} {/snippet} diff --git a/frontend/src/lib/components/common/button/Button.svelte b/frontend/src/lib/components/common/button/Button.svelte index f3cfc78478..bfb974b3f1 100644 --- a/frontend/src/lib/components/common/button/Button.svelte +++ b/frontend/src/lib/components/common/button/Button.svelte @@ -252,7 +252,10 @@ function getDividerClass(color, variant) { // Check if using new design system variants if (variant === 'default') { - return 'border border-border-light divide-x divide-border-light' + // An inset outline, not a border: a border would add 2px around the `unifiedSize` + // height the buttons inside already have, so a split button would stand taller than a + // plain one of the same size. + return 'outline outline-1 -outline-offset-1 outline-border-light divide-x divide-border-light' } else if (variant === 'accent') { return 'divide-x divide-blue-100 dark:divide-blue-200' } else if (variant === 'accent-secondary') { diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte index 674411f461..95de830a29 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte @@ -10,9 +10,11 @@ kind: ArtifactKind content: string disabled?: boolean + /** The icon alone, for a bar too narrow for the label. */ + iconOnly?: boolean } - let { name, kind, content, disabled = false }: Props = $props() + let { name, kind, content, disabled = false, iconOnly = false }: Props = $props() let copied = $state(false) async function copyRaw() { @@ -27,6 +29,7 @@ unifiedSize="sm" variant="default" {disabled} + {iconOnly} startIcon={{ icon: copied ? Check : Copy }} onClick={copyRaw} title="Copy raw markdown" diff --git a/frontend/src/lib/components/copilot/chat/artifacts/artifactSharing.ts b/frontend/src/lib/components/copilot/chat/artifacts/artifactSharing.ts index 269eb6354b..abebe3e133 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/artifactSharing.ts +++ b/frontend/src/lib/components/copilot/chat/artifacts/artifactSharing.ts @@ -17,10 +17,14 @@ export function shareWorkspaceId( } } +export function sharedArtifactPath(workspaceId: string, shareId: string): string { + return `/shared_artifacts/${encodeURIComponent(shareId)}?workspace=${encodeURIComponent( + workspaceId + )}` +} + export function sharedArtifactUrl(workspaceId: string, shareId: string): string { - return `${window.location.origin}/shared_artifacts/${encodeURIComponent( - shareId - )}?workspace=${encodeURIComponent(workspaceId)}` + return `${window.location.origin}${sharedArtifactPath(workspaceId, shareId)}` } /** "30 days", "12 hours": the retention window in the largest whole unit it fills. */ diff --git a/frontend/src/lib/components/pageHeaderRegistry.svelte.ts b/frontend/src/lib/components/pageHeaderRegistry.svelte.ts index 4fc47ef101..194ae899e6 100644 --- a/frontend/src/lib/components/pageHeaderRegistry.svelte.ts +++ b/frontend/src/lib/components/pageHeaderRegistry.svelte.ts @@ -35,6 +35,14 @@ export type PageHeaderSection = { /** No chevron after the name: the page's siblings are not the workspace's pages and items, * which is all that picker offers. A session is one. */ noNavPicker?: boolean + /** Artifacts the section is one of — a shared artifact's page. The nav picker lists them in + * its Artifacts branch, opens on that branch with `currentId` highlighted, and navigates to + * `href(id)` when one is picked. */ + navArtifacts?: { + items: { id: string; name: string }[] + currentId?: string + href: (id: string) => string + } } export type PageHeaderContent = { diff --git a/frontend/src/lib/components/sessions/PreviewRouterPicker.svelte b/frontend/src/lib/components/sessions/PreviewRouterPicker.svelte index 8c29bd9286..3886b90b19 100644 --- a/frontend/src/lib/components/sessions/PreviewRouterPicker.svelte +++ b/frontend/src/lib/components/sessions/PreviewRouterPicker.svelte @@ -75,7 +75,7 @@ section or the flat layout. workspaceId?: string // Session artifacts to surface as an "Artifacts" branch; omitted or empty // hides the branch (non-session consumers, sessions without artifacts). - artifacts?: PersistedArtifact[] + artifacts?: Pick[] /** The session chat, whose Use mode opens items in their viewer. Read from the * `aiChatManager` context when omitted. */ chat?: { readonly workMode: AIWorkMode } diff --git a/frontend/src/routes/(root)/(logged)/shared_artifacts/[id]/+page.svelte b/frontend/src/routes/(root)/(logged)/shared_artifacts/[id]/+page.svelte index 877d47d6dc..ac0d3cac02 100644 --- a/frontend/src/routes/(root)/(logged)/shared_artifacts/[id]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/shared_artifacts/[id]/+page.svelte @@ -1,13 +1,17 @@ -
-
- {#if artifact} -
-
-
- -

- {artifact.name} -

-
- - Shared by {artifact.created_by} · v{artifact.version} · {displayDate( - artifact.shared_at - )} · expires {displayDate(artifact.expires_at)} - -
-
- {#if artifact.can_unshare} - - {/if} - - {#if artifact.kind === 'md'} - (showSource = v === 'source')} - > - {#snippet children({ item })} - - - {/snippet} - - {/if} -
-
-
- -
- {:else if shared.current?.state === 'gone'} + sharedArtifactPath(workspace, id) + } + : undefined + }} + afterName={artifact ? shareDetails : undefined} + actions={artifact ? artifactActions : undefined} + separator="always" + actionFolds={1} +/> + +{#snippet shareDetails()} + {#if artifact} + + Shared by {artifact.created_by} · v{artifact.version} · {displayDate(artifact.shared_at)} · expires + {displayDate(artifact.expires_at)} + + {/if} +{/snippet} + +{#snippet artifactActions()} + {#if artifact} +
+ {#if artifact.can_unshare} + + {/if} + + {#if artifact.kind === 'md'} + (showSource = v === 'source')} + > + {#snippet children({ item })} + + + {/snippet} + + {/if} +
+ {/if} +{/snippet} + +{#if artifact} +
+ +
+ +
+
+{:else} +
+ {#if shared.current?.state === 'gone'} {/if}
-
+{/if}