diff --git a/packages/web-ui/src/components/sandbox/ArtifactsRuntimeProvider.ts b/packages/web-ui/src/components/sandbox/ArtifactsRuntimeProvider.ts index 75a6be27..b0a7c3a5 100644 --- a/packages/web-ui/src/components/sandbox/ArtifactsRuntimeProvider.ts +++ b/packages/web-ui/src/components/sandbox/ArtifactsRuntimeProvider.ts @@ -41,20 +41,19 @@ export class ArtifactsRuntimeProvider implements SandboxRuntimeProvider { // Auto-parse/stringify for .json files const isJsonFile = (filename: string) => filename.endsWith(".json"); - (window as any).hasArtifact = async (filename: string): Promise => { + (window as any).listArtifacts = async (): Promise => { // Online: ask extension if ((window as any).sendRuntimeMessage) { const response = await (window as any).sendRuntimeMessage({ type: "artifact-operation", - action: "has", - filename, + action: "list", }); if (!response.success) throw new Error(response.error); return response.result; } - // Offline: check snapshot + // Offline: return snapshot keys else { - return !!(window as any).artifacts?.[filename]; + return Object.keys((window as any).artifacts || {}); } }; @@ -141,9 +140,9 @@ export class ArtifactsRuntimeProvider implements SandboxRuntimeProvider { try { switch (action) { - case "has": { - const exists = this.artifactsPanel.artifacts.has(filename); - respond({ success: true, result: exists }); + case "list": { + const filenames = Array.from(this.artifactsPanel.artifacts.keys()); + respond({ success: true, result: filenames }); break; } diff --git a/packages/web-ui/src/prompts/tool-prompts.ts b/packages/web-ui/src/prompts/tool-prompts.ts index 2b376960..6ebf23b0 100644 --- a/packages/web-ui/src/prompts/tool-prompts.ts +++ b/packages/web-ui/src/prompts/tool-prompts.ts @@ -187,14 +187,14 @@ ${ARTIFACTS_RUNTIME_EXAMPLE} export const ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION = ` Artifact Management (persistent session files you can access/modify programmatically): -- await hasArtifact(filename) - Check if artifact exists, returns boolean - * Example: if (await hasArtifact('data.json')) { ... } +- await listArtifacts() - Get list of all artifact filenames, returns string[] + * Example: const files = await listArtifacts(); // ['data.json', 'notes.md', 'chart.png'] - await getArtifact(filename) - Read artifact content, returns string or object * Auto-parses .json files to objects, otherwise returns raw string content * Example: const data = await getArtifact('data.json'); // Returns parsed object * Example: const markdown = await getArtifact('notes.md'); // Returns string - await createOrUpdateArtifact(filename, content, mimeType?) - Create or update a persistent artifact - * Automatically creates if new, updates if exists (no need to check hasArtifact first) + * Automatically creates if new, updates if exists * Auto-stringifies objects for .json files * Example: await createOrUpdateArtifact('data.json', {items: []}) // Auto-stringifies * Example: await createOrUpdateArtifact('research-notes.md', '# Research Notes\\n', 'text/markdown') @@ -203,7 +203,8 @@ Artifact Management (persistent session files you can access/modify programmatic * Example: await deleteArtifact('old-notes.md') Powerful pattern for evolving data: - const data = await hasArtifact('data.json') ? await getArtifact('data.json') : {items: []}; + const files = await listArtifacts(); + const data = files.includes('data.json') ? await getArtifact('data.json') : {items: []}; data.items.push(newScrapedItem); await createOrUpdateArtifact('data.json', data);