diff --git a/backend/.sqlx/query-b43d739234309a9341ddd9b18db229a409ffd8c1f96bb07904333bdb94670b52.json b/backend/.sqlx/query-b43d739234309a9341ddd9b18db229a409ffd8c1f96bb07904333bdb94670b52.json new file mode 100644 index 0000000000..8d3c392e8b --- /dev/null +++ b/backend/.sqlx/query-b43d739234309a9341ddd9b18db229a409ffd8c1f96bb07904333bdb94670b52.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO ai_shared_session_opened (share_id, email) VALUES ($1, $2)\n ON CONFLICT (share_id, email) DO UPDATE SET opened_at = now()", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "b43d739234309a9341ddd9b18db229a409ffd8c1f96bb07904333bdb94670b52" +} diff --git a/backend/.sqlx/query-ce5a5c8798e7b525b8dd10f16c63aaca0b6e002c32d33dd1e6c3b03e5e6b18d7.json b/backend/.sqlx/query-ce5a5c8798e7b525b8dd10f16c63aaca0b6e002c32d33dd1e6c3b03e5e6b18d7.json new file mode 100644 index 0000000000..4ef8280599 --- /dev/null +++ b/backend/.sqlx/query-ce5a5c8798e7b525b8dd10f16c63aaca0b6e002c32d33dd1e6c3b03e5e6b18d7.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM ai_shared_session_opened o\n USING ai_shared_session s\n WHERE o.share_id = s.id AND s.workspace_id = $1 AND o.share_id = $2 AND o.email = $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Uuid", + "Text" + ] + }, + "nullable": [] + }, + "hash": "ce5a5c8798e7b525b8dd10f16c63aaca0b6e002c32d33dd1e6c3b03e5e6b18d7" +} diff --git a/backend/.sqlx/query-d492e188a54842b4e7580e6668e894a966bb72705e6b29eeb790bda6b4d64f4e.json b/backend/.sqlx/query-d492e188a54842b4e7580e6668e894a966bb72705e6b29eeb790bda6b4d64f4e.json new file mode 100644 index 0000000000..451dac97ff --- /dev/null +++ b/backend/.sqlx/query-d492e188a54842b4e7580e6668e894a966bb72705e6b29eeb790bda6b4d64f4e.json @@ -0,0 +1,72 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT s.id, s.session_id, s.email, s.name, s.is_public, s.message_count, s.created_by,\n s.shared_at, o.opened_at AS \"opened_at?\"\n FROM ai_shared_session s\n LEFT JOIN ai_shared_session_opened o ON o.share_id = s.id AND o.email = $2\n WHERE s.workspace_id = $1 AND (s.email = $2 OR o.share_id IS NOT NULL)\n ORDER BY COALESCE(o.opened_at, s.shared_at) DESC\n LIMIT $3", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "session_id", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "email", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 4, + "name": "is_public", + "type_info": "Bool" + }, + { + "ordinal": 5, + "name": "message_count", + "type_info": "Int4" + }, + { + "ordinal": 6, + "name": "created_by", + "type_info": "Varchar" + }, + { + "ordinal": 7, + "name": "shared_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "opened_at?", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "d492e188a54842b4e7580e6668e894a966bb72705e6b29eeb790bda6b4d64f4e" +} diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 6e6ea31ba7..f0bdbb534c 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -e4bfe4229dfd07f6c356835c2ac0e80c2729d582 +9ffb89ad54e2ab508573f8f7779b6471b49dcb9f diff --git a/backend/migrations/20261117111023_ai_shared_session_opened.down.sql b/backend/migrations/20261117111023_ai_shared_session_opened.down.sql new file mode 100644 index 0000000000..4d72edec92 --- /dev/null +++ b/backend/migrations/20261117111023_ai_shared_session_opened.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS ai_shared_session_opened; diff --git a/backend/migrations/20261117111023_ai_shared_session_opened.up.sql b/backend/migrations/20261117111023_ai_shared_session_opened.up.sql new file mode 100644 index 0000000000..b841c7011d --- /dev/null +++ b/backend/migrations/20261117111023_ai_shared_session_opened.up.sql @@ -0,0 +1,17 @@ +-- The shares a member opened by link, which is what lists them in that member's sidebar. +-- Removing one from the list deletes its row; opening the link again brings it back. +CREATE TABLE ai_shared_session_opened ( + share_id UUID NOT NULL REFERENCES ai_shared_session(id) ON DELETE CASCADE, + email VARCHAR(255) NOT NULL, + opened_at TIMESTAMPTZ NOT NULL DEFAULT now(), + PRIMARY KEY (share_id, email) +); + +GRANT ALL ON ai_shared_session_opened TO windmill_admin; +GRANT ALL ON ai_shared_session_opened TO windmill_user; + +-- The handlers go through the raw pool and scope every query themselves; this is the backstop +-- for a future query that reaches the table through UserDB. +ALTER TABLE ai_shared_session_opened ENABLE ROW LEVEL SECURITY; + +CREATE POLICY admin_policy ON ai_shared_session_opened FOR ALL TO windmill_admin USING (true); diff --git a/backend/tests/ai_shared_sessions.rs b/backend/tests/ai_shared_sessions.rs index 75334a5440..424465fd20 100644 --- a/backend/tests/ai_shared_sessions.rs +++ b/backend/tests/ai_shared_sessions.rs @@ -118,3 +118,70 @@ async fn private_share_is_for_members_and_public_share_for_anyone( Ok(()) } + +#[sqlx::test(fixtures("base"))] +async fn a_share_is_listed_for_a_member_only_once_they_open_it( + db: Pool, +) -> anyhow::Result<()> { + initialize_tracing().await; + let server = ApiServer::start(db.clone()).await?; + let port = server.addr.port(); + let authed = format!("http://localhost:{port}/api/w/test-workspace/ai/shared_sessions"); + let client = reqwest::Client::new(); + + let share: Value = client + .post(format!("{authed}/share")) + .header("Authorization", MEMBER) + .json(&json!({ + "session_id": "session-1", + "name": "Debugging", + "message_count": 1, + "snapshot": { "messages": [], "artifacts": [] }, + })) + .send() + .await? + .json() + .await?; + let id = share["id"].as_str().unwrap().to_string(); + + let listed = |token: &'static str| { + let req = client + .get(format!("{authed}/list")) + .header("Authorization", token); + async move { anyhow::Ok(req.send().await?.json::>().await?) } + }; + + let mine = listed(MEMBER).await?; + assert_eq!(mine.len(), 1, "the author does not see their own share"); + assert_eq!(mine[0]["session_id"], "session-1"); + assert!( + listed(OTHER_MEMBER).await?.is_empty(), + "a share was listed for a member who never opened its link" + ); + + let resp = client + .get(format!( + "http://localhost:{port}/api/w/test-workspace/ai_u/shared_sessions/get/{id}" + )) + .header("Authorization", OTHER_MEMBER) + .send() + .await?; + assert_eq!(resp.status(), 200); + let opened = listed(OTHER_MEMBER).await?; + assert_eq!(opened.len(), 1, "opening the link did not list the share"); + assert!( + opened[0].get("session_id").is_none(), + "the author's session id was sent to a reader" + ); + assert!(opened[0]["opened_at"].is_string()); + + let resp = client + .delete(format!("{authed}/opened/{id}")) + .header("Authorization", OTHER_MEMBER) + .send() + .await?; + assert_eq!(resp.status(), 200, "{}", resp.text().await?); + assert!(listed(OTHER_MEMBER).await?.is_empty()); + + Ok(()) +} diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index 7c9fb8ea6c..7db216f173 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -15730,6 +15730,41 @@ paths: share: $ref: "#/components/schemas/SharedAiSessionInfo" + /w/{workspace}/ai/shared_sessions/list: + get: + summary: list the caller's shared AI sessions + description: > + The caller's own shares and the ones they opened by link, most recently shared or opened + first, without their snapshot. Capped at 500. `session_id` is set on the caller's own + shares only, `opened_at` on the others. + operationId: listSharedAiSessions + tags: + - ai + parameters: + - $ref: "#/components/parameters/WorkspaceId" + responses: + "200": + description: the shares + content: + application/json: + schema: + type: array + items: + allOf: + - $ref: "#/components/schemas/SharedAiSessionInfo" + - type: object + properties: + mine: + type: boolean + session_id: + type: string + opened_at: + type: string + format: date-time + description: when the caller last opened this share by link + required: + - mine + /w/{workspace}/ai/shared_sessions/set_public/{id}: post: summary: make a shared AI session public, or reserve it to workspace members @@ -15792,6 +15827,7 @@ paths: required: - snapshot - can_unshare + - mine properties: snapshot: type: object @@ -15799,6 +15835,33 @@ paths: can_unshare: type: boolean description: whether the caller authored the share or is a workspace admin + mine: + type: boolean + description: whether the caller authored the share + + /w/{workspace}/ai/shared_sessions/opened/{id}: + delete: + summary: remove a shared AI session from the caller's list + description: > + The share stays readable by link; opening it again lists it again. + operationId: forgetOpenedAiSession + tags: + - ai + parameters: + - $ref: "#/components/parameters/WorkspaceId" + - name: id + in: path + required: true + schema: + type: string + format: uuid + responses: + "200": + description: removed from the list + content: + text/plain: + schema: + type: string /w/{workspace}/ai/shared_sessions/delete/{id}: delete: diff --git a/backend/windmill-api/src/ai_shared_sessions.rs b/backend/windmill-api/src/ai_shared_sessions.rs index c6554305db..f506640144 100644 --- a/backend/windmill-api/src/ai_shared_sessions.rs +++ b/backend/windmill-api/src/ai_shared_sessions.rs @@ -39,6 +39,8 @@ pub fn workspaced_service() -> Router { post(share_session).layer(DefaultBodyLimit::max(SHARE_BODY_LIMIT)), ) .route("/status", get(get_share_status)) + .route("/list", get(list_shared_sessions)) + .route("/opened/{id}", delete(forget_opened_session)) .route("/set_public/{id}", post(set_public)) .route("/delete/{id}", delete(unshare_session)) } @@ -75,6 +77,8 @@ struct SharedSession { snapshot: Box, /// Whether the caller may stop sharing it: its author, or a workspace admin. can_unshare: bool, + /// Whether the caller is its author. + mine: bool, } #[derive(Serialize)] @@ -83,6 +87,19 @@ struct ShareStatus { share: Option, } +#[derive(Serialize)] +struct SharedSessionListItem { + #[serde(flatten)] + info: SharedSessionInfo, + mine: bool, + /// The author's own session id, which means nothing to anyone else: sent to its author only. + #[serde(skip_serializing_if = "Option::is_none")] + session_id: Option, + /// When the caller last opened someone else's share: what dates it in their list. + #[serde(skip_serializing_if = "Option::is_none")] + opened_at: Option>, +} + #[derive(Deserialize)] struct ShareStatusQuery { session_id: String, @@ -230,6 +247,53 @@ async fn get_share_status( Ok(Json(ShareStatus { share })) } +const LIST_LIMIT: i64 = 500; + +/// The caller's own shares and the ones they opened by link, most recently shared or opened +/// first and without their snapshot. A share nobody sent the caller stays out of their list. +async fn list_shared_sessions( + authed: ApiAuthed, + Extension(db): Extension, + Path(w_id): Path, +) -> JsonResult> { + require_plain_user_token(&authed)?; + let rows = sqlx::query!( + "SELECT s.id, s.session_id, s.email, s.name, s.is_public, s.message_count, s.created_by, + s.shared_at, o.opened_at AS \"opened_at?\" + FROM ai_shared_session s + LEFT JOIN ai_shared_session_opened o ON o.share_id = s.id AND o.email = $2 + WHERE s.workspace_id = $1 AND (s.email = $2 OR o.share_id IS NOT NULL) + ORDER BY COALESCE(o.opened_at, s.shared_at) DESC + LIMIT $3", + &w_id, + &authed.email, + LIST_LIMIT, + ) + .fetch_all(&db) + .await?; + + Ok(Json( + rows.into_iter() + .map(|row| { + let mine = row.email == authed.email; + SharedSessionListItem { + mine, + session_id: mine.then_some(row.session_id), + opened_at: if mine { None } else { row.opened_at }, + info: SharedSessionInfo { + id: row.id, + name: row.name, + is_public: row.is_public, + message_count: row.message_count, + created_by: row.created_by, + shared_at: row.shared_at, + }, + } + }) + .collect(), + )) +} + /// Only the author changes who can open their link; an admin may only take it down. async fn set_public( authed: ApiAuthed, @@ -311,7 +375,27 @@ async fn get_shared_session( _ => return Err(not_found()), }; + let mine = member.is_some_and(|a| row.email == a.email); + if let Some(reader) = member.filter(|_| !mine) { + // Reading must not depend on the sidebar entry being written. + if let Err(e) = sqlx::query!( + "INSERT INTO ai_shared_session_opened (share_id, email) VALUES ($1, $2) + ON CONFLICT (share_id, email) DO UPDATE SET opened_at = now()", + row.id, + &reader.email, + ) + .execute(&db) + .await + { + tracing::warn!( + "Could not record that {} opened shared session {id}: {e}", + reader.email + ); + } + } + Ok(Json(SharedSession { + mine, can_unshare: member.is_some_and(|a| row.email == a.email || a.is_admin), snapshot: RawValue::from_string(row.snapshot).map_err(|e| { Error::internal_err(format!("Stored session snapshot is not valid JSON: {e}")) @@ -327,6 +411,26 @@ async fn get_shared_session( })) } +/// Takes a share out of the caller's list. The share itself stays readable by link. +async fn forget_opened_session( + authed: ApiAuthed, + Extension(db): Extension, + Path((w_id, id)): Path<(String, Uuid)>, +) -> Result { + require_plain_user_token(&authed)?; + sqlx::query!( + "DELETE FROM ai_shared_session_opened o + USING ai_shared_session s + WHERE o.share_id = s.id AND s.workspace_id = $1 AND o.share_id = $2 AND o.email = $3", + &w_id, + id, + &authed.email, + ) + .execute(&db) + .await?; + Ok("Removed from your shared sessions".to_string()) +} + async fn unshare_session( authed: ApiAuthed, Extension(db): Extension, diff --git a/docs/feature-telemetry.md b/docs/feature-telemetry.md index 783b08f760..506a306154 100644 --- a/docs/feature-telemetry.md +++ b/docs/feature-telemetry.md @@ -4,7 +4,7 @@ anonymous usage-stats payload. It answers "does anyone use this, and which variant do they pick" without any identifying data leaving the instance. -It currently carries 103 registered actions across forty-one features (`access_view`, `ai_session`, `ai_chat`, +It currently carries 105 registered actions across forty-one features (`access_view`, `ai_session`, `ai_chat`, `ai_fix`, `ai_agent`, `ai_decision`, `ai_agent_eval`, `app_sandbox`, `datatable`, `db_manager`, `flow_editor`, `flow_run`, `flow_step`, `home`, `header_nav`, `run_form`, `sharing`, `debugger`, `trigger`, `command_script`, `mcp`, `mcp_workspace`, `mcp_external_client`, `hub_script`, `usage_meter`, `sso_groups_claim`, diff --git a/frontend/src/lib/assets/app.css b/frontend/src/lib/assets/app.css index 71e73a8c68..f34427d7a7 100644 --- a/frontend/src/lib/assets/app.css +++ b/frontend/src/lib/assets/app.css @@ -339,6 +339,32 @@ transition: none !important; } +/* Draggable gutter between a session's chat and its preview: a real (layout-occupying) + 10px-wide grab zone, no overlap tricks that could cover the chat's scrollbar + or the preview's edge. Transparent at rest; on hover the app-global + `.splitpanes__splitter::after` grabber fades in. Uses a dedicated class, not + the shared `.splitter-hidden`, which force-zeroes splitter opacity and would + hide that grabber. */ +.splitpanes--vertical.session-splitter > .splitpanes__splitter { + background-color: transparent !important; + border: none !important; + width: 10px !important; +} +/* Inset the global hover grabber from the pane's top/bottom edges so the line + doesn't run the full height, and round its ends into a pill. */ +.splitpanes--vertical.session-splitter > .splitpanes__splitter::after { + top: 8px !important; + bottom: 8px !important; + height: auto !important; + border-radius: 9999px !important; +} +/* Collapsed preview: the pane is resized to 0 but stays mounted, so remove + the gutter entirely — it would otherwise leave a dead 10px drag zone on the + chat's right edge. */ +.splitpanes--vertical.splitter-off > .splitpanes__splitter { + display: none !important; +} + .monaco-workbench > .notifications-toasts.visible { display: none !important; } diff --git a/frontend/src/lib/components/DraftBadge.svelte b/frontend/src/lib/components/DraftBadge.svelte index f42d80289e..be3fe0a86b 100644 --- a/frontend/src/lib/components/DraftBadge.svelte +++ b/frontend/src/lib/components/DraftBadge.svelte @@ -19,6 +19,7 @@ */ import Popover from './meltComponents/Popover.svelte' import Tooltip from './meltComponents/Tooltip.svelte' + import { userColorClass, userInitials } from './userInitials' import { Badge } from './common' import Button from './common/button/Button.svelte' import type DiffDrawer from './DiffDrawer.svelte' @@ -86,35 +87,16 @@ return [self, ...rest] }) - /** Two-letter initials; `john.doe` → `JD`, `alice` → `AL`, no username → `?`. */ function initials(u: DraftUser): string { - const name = u.username - if (!name) return '?' - const parts = name.split(/[._\-\s]+/).filter(Boolean) - if (parts.length >= 2) { - return (parts[0][0] + parts[1][0]).toUpperCase() - } - return name.slice(0, 2).toUpperCase() + return userInitials(u.username) } function fullLabel(u: DraftUser): string { return u.username ?? 'Legacy workspace draft' } - // Deterministic color per username, same circle across rows. - const PALETTE = [ - 'bg-blue-500', - 'bg-emerald-500', - 'bg-amber-500', - 'bg-rose-500', - 'bg-violet-500', - 'bg-cyan-500' - ] function colorFor(u: DraftUser): string { - const name = u.username ?? '' - let hash = 0 - for (let i = 0; i < name.length; i++) hash = (hash * 31 + name.charCodeAt(i)) >>> 0 - return PALETTE[hash % PALETTE.length] + return userColorClass(u.username) } // First 3 circles when ≤3 users; first 2 + "+N" overflow when 4+. Sliced from diff --git a/frontend/src/lib/components/copilot/chat/AssistantMessage.svelte b/frontend/src/lib/components/copilot/chat/AssistantMessage.svelte index b52155973d..841966a687 100644 --- a/frontend/src/lib/components/copilot/chat/AssistantMessage.svelte +++ b/frontend/src/lib/components/copilot/chat/AssistantMessage.svelte @@ -6,6 +6,7 @@ import { thinkingPreferences } from './thinkingPreferences.svelte' import CodeDisplay from './script/CodeDisplay.svelte' import LinkRenderer from './LinkRenderer.svelte' + import MarkdownImage from './MarkdownImage.svelte' import { extractCandidatePaths, remarkWindmillPaths, @@ -98,11 +99,12 @@ }) const candidatePaths = $derived(extractCandidatePaths(message.content)) - const reasoningPlugins = [gfmPlugin(), { renderer: { a: LinkRenderer } }] + const reasoningPlugins = [gfmPlugin(), { renderer: { a: LinkRenderer, img: MarkdownImage } }] const rendererPlugin = { renderer: { pre: CodeDisplay, - a: LinkRenderer + a: LinkRenderer, + img: MarkdownImage } } diff --git a/frontend/src/lib/components/copilot/chat/MarkdownImage.svelte b/frontend/src/lib/components/copilot/chat/MarkdownImage.svelte new file mode 100644 index 0000000000..1f5320d91c --- /dev/null +++ b/frontend/src/lib/components/copilot/chat/MarkdownImage.svelte @@ -0,0 +1,37 @@ + + +{#if !blocked} + +{:else if href} + + {label} + +{:else} + + {label} + +{/if} diff --git a/frontend/src/lib/components/copilot/chat/MarkdownImageSource.svelte b/frontend/src/lib/components/copilot/chat/MarkdownImageSource.svelte new file mode 100644 index 0000000000..cfb53003c5 --- /dev/null +++ b/frontend/src/lib/components/copilot/chat/MarkdownImageSource.svelte @@ -0,0 +1,14 @@ + + +{#if !untrusted} + +{/if} diff --git a/frontend/src/lib/components/copilot/chat/ToolExecutionDisplay.svelte b/frontend/src/lib/components/copilot/chat/ToolExecutionDisplay.svelte index 90c745a738..c1fac18c7a 100644 --- a/frontend/src/lib/components/copilot/chat/ToolExecutionDisplay.svelte +++ b/frontend/src/lib/components/copilot/chat/ToolExecutionDisplay.svelte @@ -40,6 +40,7 @@ import { gfmPlugin } from 'svelte-exmarkdown/gfm' import CodeDisplay from './script/CodeDisplay.svelte' import LinkRenderer from './LinkRenderer.svelte' + import MarkdownImage from './MarkdownImage.svelte' import ToolContentDisplay from './ToolContentDisplay.svelte' import ToolConfirmationFooter from './ToolConfirmationFooter.svelte' import ToolMessageActions from './ToolMessageActions.svelte' @@ -105,7 +106,10 @@ ) // The preview pane's renderers, so a model-written link opens in a new tab either way. - const planPlugins = [gfmPlugin(), { renderer: { pre: CodeDisplay, a: LinkRenderer } }] + const planPlugins = [ + gfmPlugin(), + { renderer: { pre: CodeDisplay, a: LinkRenderer, img: MarkdownImage } } + ] const confirmAction = $derived(TOOL_CONFIRM_ACTIONS[message.confirmAction ?? 'confirm']) diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactBody.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactBody.svelte index e10c47c4c2..473f646e81 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactBody.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactBody.svelte @@ -3,6 +3,8 @@ import Markdown from 'svelte-exmarkdown' import SimpleEditor from '$lib/components/SimpleEditor.svelte' import LinkRenderer from '../LinkRenderer.svelte' + import MarkdownImage from '../MarkdownImage.svelte' + import MarkdownImageSource from '../MarkdownImageSource.svelte' import { artifactPlugins } from './artifactPlugins' import '@fontsource-variable/jetbrains-mono/wght.css' import './artifactDocument.css' @@ -27,7 +29,14 @@ // link pill and, when given, its code block sit on top of it. const plugins = $derived([ ...artifactPlugins, - { renderer: { a: LinkRenderer, ...(pre ? { pre } : {}) } } + { + renderer: { + a: LinkRenderer, + img: MarkdownImage, + source: MarkdownImageSource, + ...(pre ? { pre } : {}) + } + } ]) diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte index 1bbcb53566..fc77a02f69 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactExportButton.svelte @@ -5,6 +5,7 @@ import { artifactFilename, artifactMimeType, type ArtifactKind } from './artifactsDB' import { artifactHtmlFile } from './artifactExport' import { printArtifact } from './printArtifact' + import { hasUntrustedImages } from '../untrustedImages' interface Props { name: string @@ -17,6 +18,8 @@ let { name, kind, content, disabled = false, iconOnly = false }: Props = $props() + const untrustedImages = hasUntrustedImages() + let copied = $state(false) async function copyRaw() { if (!(await copyToClipboard(content))) return @@ -43,7 +46,9 @@ }, // Markdown only: an html artifact already downloads as .html, and printing it would run its // scripts in this origin. - ...(kind === 'md' + // No .html for someone else's artifact: the file draws its mermaid here and keeps its + // images' outside URLs, which the shared viewer blocks. + ...(kind === 'md' && !untrustedImages ? [ { label: 'Download as .html', @@ -55,11 +60,15 @@ artifactMimeType('html') ), disabled - }, + } + ] + : []), + ...(kind === 'md' + ? [ { label: 'Download as PDF', icon: FileDown, - onClick: () => printArtifact(name, content), + onClick: () => printArtifact(name, content, { untrustedImages }), disabled } ] diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintBody.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintBody.svelte index 0939621116..dabc15ab9c 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintBody.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintBody.svelte @@ -2,13 +2,25 @@ import Markdown from 'svelte-exmarkdown' import { artifactPlugins } from './artifactPlugins' import ArtifactPrintCodeBlock from './ArtifactPrintCodeBlock.svelte' + import MarkdownImage from '../MarkdownImage.svelte' + import MarkdownImageSource from '../MarkdownImageSource.svelte' + import { setUntrustedImages } from '../untrustedImages' + import { untrack } from 'svelte' // These load into the app's page, not the print frame: the frame copies the page's stylesheets. import '@fontsource-variable/jetbrains-mono/wght.css' import './artifactDocument.css' - let { content }: { content: string } = $props() + let { content, untrustedImages = false }: { content: string; untrustedImages?: boolean } = + $props() - const plugins = [...artifactPlugins, { renderer: { pre: ArtifactPrintCodeBlock } }] + // Mounted in its own root, so the viewer's context does not reach it: the printing page + // passes it on, or a shared artifact's outside images load while the PDF is prepared. + if (untrack(() => untrustedImages)) setUntrustedImages() + + const plugins = [ + ...artifactPlugins, + { renderer: { pre: ArtifactPrintCodeBlock, img: MarkdownImage, source: MarkdownImageSource } } + ]
diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintCodeBlock.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintCodeBlock.svelte index 7e3dd552f2..f495307099 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintCodeBlock.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactPrintCodeBlock.svelte @@ -1,7 +1,12 @@ - - + + diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactViewer.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactViewer.svelte index 8331825ee2..7445ac9b17 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactViewer.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactViewer.svelte @@ -18,18 +18,22 @@ interface Props { artifact: PersistedArtifact - store: SessionArtifactsStore + /** Absent for a `sharedCopy`, which has no history to read. */ + store?: SessionArtifactsStore /** Version being viewed, or undefined for the current one. Owned by the caller — it * outlives this component, so the viewer must not keep a copy of its own. */ pinned?: number onPin: (version: number | undefined) => void + /** A copy read from someone else's shared session. A share keeps only the latest text, + * so there is no history to pick from, and sharing it again is the author's call. */ + sharedCopy?: boolean } - let { artifact, store, pinned, onPin }: Props = $props() + let { artifact, store, pinned, onPin, sharedCopy = false }: Props = $props() const latest = $derived(currentVersion(artifact)) // Nothing to pick between until a second version exists. - const hasHistory = $derived(latest > 1) + const hasHistory = $derived(!sharedCopy && !!store && latest > 1) let pinnedContent = $state(undefined) // A pin that arrives with the tab has nothing honest to show until its snapshot lands: the @@ -58,6 +62,7 @@ return } const id = artifact.id + if (!store) return void store.getVersion(id, version).then( (snapshot) => { if (pinned !== version || artifact.id !== id) return @@ -132,7 +137,7 @@ {badge.label} {/if} - {#if hasHistory} + {#if hasHistory && store} - + {#if !sharedCopy} + + {/if} - This revision is not approved · the plan you approved is v{view.backToPlan} + {#if sharedCopy} + This revision is not approved · the approved plan is v{view.backToPlan} + {:else} + This revision is not approved · the plan you approved is v{view.backToPlan} + {/if} -
- -
+ {#if !sharedCopy} +
+ +
+ {/if}
{/if} diff --git a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactsSegment.svelte b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactsSegment.svelte index b1a204346c..c9391a0f65 100644 --- a/frontend/src/lib/components/copilot/chat/artifacts/ArtifactsSegment.svelte +++ b/frontend/src/lib/components/copilot/chat/artifacts/ArtifactsSegment.svelte @@ -10,8 +10,15 @@ import { currentVersion, type PersistedArtifact } from './artifactsDB' import { planFirst } from './artifactsState.svelte' + let { + readOnly + }: { + /** A transcript nobody can change: its own artifacts, opened by the caller, none deleted. */ + readOnly?: { artifacts: PersistedArtifact[]; open: (artifact: PersistedArtifact) => void } + } = $props() + const aiChatManager = getAiChatManager() - const artifacts = $derived(aiChatManager.artifacts.artifacts) + const artifacts = $derived(readOnly?.artifacts ?? aiChatManager.artifacts.artifacts) // The plan is what the user comes back to, and in update order it sinks under // everything the approved run then produces. const planCount = $derived(artifacts.filter((a) => a.role === 'plan').length) @@ -33,7 +40,9 @@ itemKey={(a) => a.id} rowTitle={(a) => a.name} separatorAfter={(_, index) => index === planCount - 1 && planCount < orderedArtifacts.length} - onPick={(a: PersistedArtifact) => aiChatManager.openArtifact?.(a.id, a.name, listOpenTarget(a))} + onPick={(a: PersistedArtifact) => + readOnly ? readOnly.open(a) : aiChatManager.openArtifact?.(a.id, a.name, listOpenTarget(a))} + actions={readOnly ? undefined : deleteAction} > {#snippet row(a)} {@const Icon = rowIcon(a)} @@ -55,26 +64,30 @@ > {badge?.label ?? a.kind} - - {#if currentVersion(a) > 1}v{currentVersion(a)} ·{/if} - - - {/snippet} - {#snippet actions(a)} - + {#if actions} +
+ {@render actions()} +
+ {/if} +
+ onReorder(order.map((t) => t.id))} + class="session-preview-tab-strip h-8 border-b border-light bg-surface-secondary/50 pl-9 pr-[var(--preview-actions-w)]" + /> +
+ +
+ {#each tabs as artifact (artifact.id)} +
+ {}} /> +
+ {/each} +
+ + diff --git a/frontend/src/lib/components/sessions/SharedSessionStatusBar.svelte b/frontend/src/lib/components/sessions/SharedSessionStatusBar.svelte new file mode 100644 index 0000000000..0e86b6b183 --- /dev/null +++ b/frontend/src/lib/components/sessions/SharedSessionStatusBar.svelte @@ -0,0 +1,193 @@ + + + + +{#snippet lockedNote()} +
+ + + {draftsLockedReason} + {#if draftsSignInHref} + Sign in + {/if} + +
+{/snippet} + +{#if edits.length > 0 || artifacts.length > 0} +
+ {#if edits.length > 0} + `${e.kind}:${e.path}`} + itemHref={deployedHref} + {rowTitle} + itemDisabled={(edit) => (edit.draft ? !opensDraft(edit) : !deployedHref(edit))} + onPick={(edit) => void viewDraft(edit)} + triggerClass={`${TOKEN_TRIGGER_CLASS} ${token.class}`} + widthClass="w-96" + maxHeightClass="max-h-[min(9rem,50vh)]" + footer={draftsLockedReason && hasLockedRow ? lockedNote : undefined} + > + {#snippet row(edit)} + + + {edit.path} + + {#if edit.draft} + {edit.draftOnly ? 'Draft only' : 'Draft'} + {#if opensDraft(edit)} + + {:else} + + {/if} + {:else} + Deployed + {#if deployedHref(edit)} + + {/if} + {/if} + {/snippet} + + {/if} + {#if artifacts.length > 0} + + {/if} +
+{/if} + +{#if diffDrawerModule.current} + {@const LoadedDiffDrawer = diffDrawerModule.current.default} + +{/if} diff --git a/frontend/src/lib/components/sessions/SharedSessionTitle.svelte b/frontend/src/lib/components/sessions/SharedSessionTitle.svelte new file mode 100644 index 0000000000..1d4eb19a9f --- /dev/null +++ b/frontend/src/lib/components/sessions/SharedSessionTitle.svelte @@ -0,0 +1,52 @@ + + + +{name} +{#if author} + + + + + + {userInitials(author)} + + + {#snippet text()} +
+ Shared by {author} + {#if sharedAt} + {displayDate(sharedAt)} + {/if} +
+ {/snippet} +
+{/if} +{#if isPublic} + + +{/if} diff --git a/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte b/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte index d0f74f4b6b..52934afd52 100644 --- a/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte +++ b/frontend/src/lib/components/sessions/SharedSessionTranscript.svelte @@ -1,11 +1,17 @@ + +{#snippet sessionName()} + +{/snippet} + +{#snippet headerActions()} + {#if found?.session.mine} + + {:else if found && isMember} +
+ + + {#if found.session.can_unshare} + shared.stopSharing() + } + ]} + > + {#snippet buttonReplacement()} + + + + {/snippet} + + {/if} +
+ {/if} +{/snippet} + + + +
+ +
diff --git a/frontend/src/routes/(styled)/shared_sessions/[workspace]/[id]/+page.svelte b/frontend/src/routes/(styled)/shared_sessions/[workspace]/[id]/+page.svelte index 57e0ca654b..ed49de048d 100644 --- a/frontend/src/routes/(styled)/shared_sessions/[workspace]/[id]/+page.svelte +++ b/frontend/src/routes/(styled)/shared_sessions/[workspace]/[id]/+page.svelte @@ -1,16 +1,21 @@ - - - - +{#if member.current !== false} + +{:else} + {#snippet sessionName()} + + {/snippet} -
-
-
- - {#if found} -
-
-

- {found.session.name} -

- {#if found.session.is_public} - Public - {:else} - {workspace} - {/if} -
- - Read-only AI session shared by {found.session.created_by} · {displayDate( - found.session.shared_at - )} - -
- {#if found.session.can_unshare} - - {/if} - {:else} - Shared AI session - {/if} + + {#snippet headerActions()} + {#if signInHref && rightInset === undefined} +
+ Signed out + +
+ {/if} + {/snippet} + {#snippet previewActions()} + {#if signInHref} + Signed out + + {/if} + {/snippet} + + + +
+ +
+ + + + +
+ +
+
+ +
+
- -
- {#if found} - {#if found.snapshot.messages.length > 0} - {#key found.session.id} - - {/key} - {:else} - - {/if} - {:else if shared.current?.state === 'signin'} - - - - {:else if shared.current?.state === 'gone'} - - {:else if shared.current?.state === 'error'} - - {:else} - - {/if} -
-
+{/if}