mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-17 00:20:51 +00:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<DB>,
|
||||
Path(w_id): Path<String>,
|
||||
) -> JsonResult<Vec<SharedArtifactInfo>> {
|
||||
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,
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
|
||||
@@ -290,7 +290,13 @@ not this component) — so the lead can run the whole line.
|
||||
<ChevronDown size={ICON} class="flex-shrink-0" />
|
||||
</span>
|
||||
{:else}
|
||||
<BreadcrumbNavPicker {item} pagePath={routePage?.path} {actingWorkspaceId} iconSize={ICON} />
|
||||
<BreadcrumbNavPicker
|
||||
{item}
|
||||
pagePath={routePage?.path}
|
||||
artifacts={section?.navArtifacts}
|
||||
{actingWorkspaceId}
|
||||
iconSize={ICON}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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<PersistedArtifact, 'id' | 'name'>[]
|
||||
/** The session chat, whose Use mode opens items in their viewer. Read from the
|
||||
* `aiChatManager` context when omitted. */
|
||||
chat?: { readonly workMode: AIWorkMode }
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { resource } from 'runed'
|
||||
import { Code, Eye, FileText, Link2Off } from 'lucide-svelte'
|
||||
import { Code, Eye, Link2Off } from 'lucide-svelte'
|
||||
import { Button, EmptyState, Skeleton } from '$lib/components/common'
|
||||
import ToggleButtonGroup from '$lib/components/common/toggleButton-v2/ToggleButtonGroup.svelte'
|
||||
import ToggleButton from '$lib/components/common/toggleButton-v2/ToggleButton.svelte'
|
||||
import PageHeaderContent from '$lib/components/PageHeaderContent.svelte'
|
||||
import { pageHeader } from '$lib/components/pageHeaderRegistry.svelte'
|
||||
import Tooltip from '$lib/components/Tooltip.svelte'
|
||||
import ArtifactBody from '$lib/components/copilot/chat/artifacts/ArtifactBody.svelte'
|
||||
import ArtifactExportButton from '$lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte'
|
||||
import MermaidCodeBlock from '$lib/components/copilot/chat/artifacts/MermaidCodeBlock.svelte'
|
||||
import { sharedArtifactPath } from '$lib/components/copilot/chat/artifacts/artifactSharing'
|
||||
import { AiService } from '$lib/gen'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
@@ -42,6 +46,31 @@
|
||||
|
||||
const artifact = $derived(shared.current?.state === 'found' ? shared.current.artifact : undefined)
|
||||
|
||||
// The header picker's siblings. A backend without the list endpoint leaves the picker with
|
||||
// the open artifact alone rather than failing the page.
|
||||
const siblings = resource(
|
||||
() => workspace,
|
||||
async (workspace) => {
|
||||
if (!workspace) return []
|
||||
try {
|
||||
return await AiService.listSharedAiArtifacts({ workspace })
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
)
|
||||
const navItems = $derived.by(() => {
|
||||
const items = (siblings.current ?? []).map((a) => ({ id: a.id, name: a.name }))
|
||||
if (artifact && !items.some((a) => a.id === artifact.id)) {
|
||||
items.unshift({ id: artifact.id, name: artifact.name })
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
// The bar's one fold (`actionFolds` below), once the name has given all it can: Stop sharing
|
||||
// and Copy keep their icons and drop their labels.
|
||||
const folded = $derived(pageHeader.actionFold >= 1)
|
||||
|
||||
let showSource = $state(false)
|
||||
const source = $derived(artifact?.kind !== 'md' || showSource)
|
||||
|
||||
@@ -52,6 +81,7 @@
|
||||
try {
|
||||
await AiService.unshareAiArtifact({ workspace, id: artifact.id })
|
||||
shared.mutate({ state: 'gone' })
|
||||
siblings.refetch()
|
||||
sendUserToast('Stopped sharing: the link no longer opens')
|
||||
} catch (err) {
|
||||
sendUserToast(`Could not stop sharing: ${(err as { body?: unknown })?.body ?? err}`, true)
|
||||
@@ -61,72 +91,89 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex h-full flex-col px-4 py-6 sm:px-8">
|
||||
<div class="mx-auto flex h-full min-h-0 w-full max-w-4xl flex-col gap-3">
|
||||
{#if artifact}
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div class="flex min-w-0 flex-col gap-1">
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<FileText size={16} class="shrink-0 text-secondary" />
|
||||
<h1 class="truncate text-lg font-semibold text-emphasis" title={artifact.name}>
|
||||
{artifact.name}
|
||||
</h1>
|
||||
</div>
|
||||
<span class="text-xs font-normal text-secondary">
|
||||
Shared by {artifact.created_by} · v{artifact.version} · {displayDate(
|
||||
artifact.shared_at
|
||||
)} · expires {displayDate(artifact.expires_at)}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
{#if artifact.can_unshare}
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
variant="default"
|
||||
destructive
|
||||
loading={removing}
|
||||
onClick={stopSharing}
|
||||
>
|
||||
Stop sharing
|
||||
</Button>
|
||||
{/if}
|
||||
<ArtifactExportButton
|
||||
name={artifact.name}
|
||||
kind={artifact.kind}
|
||||
content={artifact.content}
|
||||
/>
|
||||
{#if artifact.kind === 'md'}
|
||||
<ToggleButtonGroup
|
||||
noWFull
|
||||
selected={showSource ? 'source' : 'preview'}
|
||||
onSelected={(v) => (showSource = v === 'source')}
|
||||
>
|
||||
{#snippet children({ item })}
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="preview"
|
||||
icon={Eye}
|
||||
iconOnly
|
||||
tooltip="Preview"
|
||||
size="sm"
|
||||
/>
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="source"
|
||||
icon={Code}
|
||||
iconOnly
|
||||
tooltip="View source"
|
||||
size="sm"
|
||||
/>
|
||||
{/snippet}
|
||||
</ToggleButtonGroup>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="min-h-0 flex-1 overflow-auto rounded-md bg-surface-tertiary px-8">
|
||||
<ArtifactBody content={artifact.content} {source} pre={MermaidCodeBlock} />
|
||||
</div>
|
||||
{:else if shared.current?.state === 'gone'}
|
||||
<PageHeaderContent
|
||||
section={{
|
||||
label: artifact?.name ?? 'Shared artifact',
|
||||
navArtifacts: workspace
|
||||
? {
|
||||
items: navItems,
|
||||
currentId: artifact?.id,
|
||||
href: (id) => sharedArtifactPath(workspace, id)
|
||||
}
|
||||
: undefined
|
||||
}}
|
||||
afterName={artifact ? shareDetails : undefined}
|
||||
actions={artifact ? artifactActions : undefined}
|
||||
separator="always"
|
||||
actionFolds={1}
|
||||
/>
|
||||
|
||||
{#snippet shareDetails()}
|
||||
{#if artifact}
|
||||
<Tooltip>
|
||||
Shared by {artifact.created_by} · v{artifact.version} · {displayDate(artifact.shared_at)} · expires
|
||||
{displayDate(artifact.expires_at)}
|
||||
</Tooltip>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#snippet artifactActions()}
|
||||
{#if artifact}
|
||||
<div class="flex items-center gap-2">
|
||||
{#if artifact.can_unshare}
|
||||
<Button
|
||||
unifiedSize="sm"
|
||||
variant="default"
|
||||
destructive
|
||||
loading={removing}
|
||||
onClick={stopSharing}
|
||||
iconOnly={folded}
|
||||
startIcon={folded ? { icon: Link2Off } : undefined}
|
||||
title="Stop sharing"
|
||||
>
|
||||
Stop sharing
|
||||
</Button>
|
||||
{/if}
|
||||
<ArtifactExportButton
|
||||
name={artifact.name}
|
||||
kind={artifact.kind}
|
||||
content={artifact.content}
|
||||
iconOnly={folded}
|
||||
/>
|
||||
{#if artifact.kind === 'md'}
|
||||
<ToggleButtonGroup
|
||||
noWFull
|
||||
selected={showSource ? 'source' : 'preview'}
|
||||
onSelected={(v) => (showSource = v === 'source')}
|
||||
>
|
||||
{#snippet children({ item })}
|
||||
<ToggleButton {item} value="preview" icon={Eye} iconOnly tooltip="Preview" size="sm" />
|
||||
<ToggleButton
|
||||
{item}
|
||||
value="source"
|
||||
icon={Code}
|
||||
iconOnly
|
||||
tooltip="View source"
|
||||
size="sm"
|
||||
/>
|
||||
{/snippet}
|
||||
</ToggleButtonGroup>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#if artifact}
|
||||
<div class="h-full min-h-0 overflow-auto bg-surface-tertiary px-8">
|
||||
<!-- Full height only for the source editor: the rendered document's sticky top fade sticks
|
||||
only while its parent box lasts, so that box must grow with the text. -->
|
||||
<div class="mx-auto max-w-4xl {source ? 'h-full' : ''}">
|
||||
<ArtifactBody content={artifact.content} {source} pre={MermaidCodeBlock} />
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="mx-auto flex h-full w-full max-w-4xl flex-col px-4 py-6 sm:px-8">
|
||||
{#if shared.current?.state === 'gone'}
|
||||
<EmptyState
|
||||
icon={Link2Off}
|
||||
title="This shared artifact is no longer available"
|
||||
@@ -142,4 +189,4 @@
|
||||
<Skeleton layout={[[3], 1, [30]]} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user