@mariozechner/pi-web-ui 0.5.44 → 0.5.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -99
- package/dist/ChatPanel.d.ts +15 -10
- package/dist/ChatPanel.d.ts.map +1 -1
- package/dist/ChatPanel.js +68 -100
- package/dist/ChatPanel.js.map +1 -1
- package/dist/{state/agent-session.d.ts → agent/agent.d.ts} +23 -19
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/{state/agent-session.js → agent/agent.js} +50 -32
- package/dist/agent/agent.js.map +1 -0
- package/dist/{state → agent}/transports/AppTransport.d.ts +1 -3
- package/dist/agent/transports/AppTransport.d.ts.map +1 -0
- package/dist/{state → agent}/transports/AppTransport.js +5 -4
- package/dist/{state → agent}/transports/AppTransport.js.map +1 -1
- package/dist/{state → agent}/transports/ProviderTransport.d.ts +1 -3
- package/dist/agent/transports/ProviderTransport.d.ts.map +1 -0
- package/dist/{state → agent}/transports/ProviderTransport.js +6 -7
- package/dist/agent/transports/ProviderTransport.js.map +1 -0
- package/dist/{state → agent}/transports/index.d.ts.map +1 -1
- package/dist/agent/transports/index.js.map +1 -0
- package/dist/{state → agent}/transports/proxy-types.d.ts.map +1 -1
- package/dist/agent/transports/proxy-types.js.map +1 -0
- package/dist/agent/transports/types.d.ts +12 -0
- package/dist/agent/transports/types.d.ts.map +1 -0
- package/dist/{state → agent}/transports/types.js.map +1 -1
- package/dist/{state → agent}/types.d.ts.map +1 -1
- package/dist/{state → agent}/types.js.map +1 -1
- package/dist/app.css +1 -1
- package/dist/components/AgentInterface.d.ts +7 -4
- package/dist/components/AgentInterface.d.ts.map +1 -1
- package/dist/components/AgentInterface.js +29 -17
- package/dist/components/AgentInterface.js.map +1 -1
- package/dist/components/ConsoleBlock.d.ts +1 -0
- package/dist/components/ConsoleBlock.d.ts.map +1 -1
- package/dist/components/ConsoleBlock.js +7 -1
- package/dist/components/ConsoleBlock.js.map +1 -1
- package/dist/components/ExpandableSection.d.ts +15 -0
- package/dist/components/ExpandableSection.d.ts.map +1 -0
- package/dist/components/ExpandableSection.js +63 -0
- package/dist/components/ExpandableSection.js.map +1 -0
- package/dist/components/MessageEditor.d.ts +8 -1
- package/dist/components/MessageEditor.d.ts.map +1 -1
- package/dist/components/MessageEditor.js +149 -6
- package/dist/components/MessageEditor.js.map +1 -1
- package/dist/components/MessageList.d.ts +3 -2
- package/dist/components/MessageList.d.ts.map +1 -1
- package/dist/components/MessageList.js +14 -1
- package/dist/components/MessageList.js.map +1 -1
- package/dist/components/Messages.d.ts +15 -6
- package/dist/components/Messages.d.ts.map +1 -1
- package/dist/components/Messages.js +17 -83
- package/dist/components/Messages.js.map +1 -1
- package/dist/components/ProviderKeyInput.d.ts.map +1 -1
- package/dist/components/ProviderKeyInput.js +6 -5
- package/dist/components/ProviderKeyInput.js.map +1 -1
- package/dist/components/SandboxedIframe.d.ts +29 -7
- package/dist/components/SandboxedIframe.d.ts.map +1 -1
- package/dist/components/SandboxedIframe.js +350 -282
- package/dist/components/SandboxedIframe.js.map +1 -1
- package/dist/components/message-renderer-registry.d.ts +12 -0
- package/dist/components/message-renderer-registry.d.ts.map +1 -0
- package/dist/components/message-renderer-registry.js +12 -0
- package/dist/components/message-renderer-registry.js.map +1 -0
- package/dist/components/sandbox/ArtifactsRuntimeProvider.d.ts +35 -0
- package/dist/components/sandbox/ArtifactsRuntimeProvider.d.ts.map +1 -0
- package/dist/components/sandbox/ArtifactsRuntimeProvider.js +189 -0
- package/dist/components/sandbox/ArtifactsRuntimeProvider.js.map +1 -0
- package/dist/components/sandbox/AttachmentsRuntimeProvider.d.ts +17 -0
- package/dist/components/sandbox/AttachmentsRuntimeProvider.d.ts.map +1 -0
- package/dist/components/sandbox/AttachmentsRuntimeProvider.js +64 -0
- package/dist/components/sandbox/AttachmentsRuntimeProvider.js.map +1 -0
- package/dist/components/sandbox/ConsoleRuntimeProvider.d.ts +42 -0
- package/dist/components/sandbox/ConsoleRuntimeProvider.d.ts.map +1 -0
- package/dist/components/sandbox/ConsoleRuntimeProvider.js +161 -0
- package/dist/components/sandbox/ConsoleRuntimeProvider.js.map +1 -0
- package/dist/components/sandbox/FileDownloadRuntimeProvider.d.ts +30 -0
- package/dist/components/sandbox/FileDownloadRuntimeProvider.d.ts.map +1 -0
- package/dist/components/sandbox/FileDownloadRuntimeProvider.js +97 -0
- package/dist/components/sandbox/FileDownloadRuntimeProvider.js.map +1 -0
- package/dist/components/sandbox/RuntimeMessageBridge.d.ts +19 -0
- package/dist/components/sandbox/RuntimeMessageBridge.d.ts.map +1 -0
- package/dist/components/sandbox/RuntimeMessageBridge.js +74 -0
- package/dist/components/sandbox/RuntimeMessageBridge.js.map +1 -0
- package/dist/components/sandbox/RuntimeMessageRouter.d.ts +65 -0
- package/dist/components/sandbox/RuntimeMessageRouter.d.ts.map +1 -0
- package/dist/components/sandbox/RuntimeMessageRouter.js +168 -0
- package/dist/components/sandbox/RuntimeMessageRouter.js.map +1 -0
- package/dist/components/sandbox/SandboxRuntimeProvider.d.ts +33 -0
- package/dist/components/sandbox/SandboxRuntimeProvider.d.ts.map +1 -0
- package/dist/components/sandbox/SandboxRuntimeProvider.js +2 -0
- package/dist/components/sandbox/SandboxRuntimeProvider.js.map +1 -0
- package/dist/dialogs/ApiKeyPromptDialog.d.ts.map +1 -1
- package/dist/dialogs/ApiKeyPromptDialog.js +2 -5
- package/dist/dialogs/ApiKeyPromptDialog.js.map +1 -1
- package/dist/dialogs/ModelSelector.js.map +1 -1
- package/dist/dialogs/PersistentStorageDialog.d.ts +17 -0
- package/dist/dialogs/PersistentStorageDialog.d.ts.map +1 -0
- package/dist/dialogs/PersistentStorageDialog.js +144 -0
- package/dist/dialogs/PersistentStorageDialog.js.map +1 -0
- package/dist/dialogs/SessionListDialog.d.ts +19 -0
- package/dist/dialogs/SessionListDialog.d.ts.map +1 -0
- package/dist/dialogs/SessionListDialog.js +152 -0
- package/dist/dialogs/SessionListDialog.js.map +1 -0
- package/dist/dialogs/SettingsDialog.d.ts.map +1 -1
- package/dist/dialogs/SettingsDialog.js +1 -0
- package/dist/dialogs/SettingsDialog.js.map +1 -1
- package/dist/index.d.ts +34 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -14
- package/dist/index.js.map +1 -1
- package/dist/prompts/prompts.d.ts +11 -0
- package/dist/prompts/prompts.d.ts.map +1 -0
- package/dist/prompts/prompts.js +272 -0
- package/dist/prompts/prompts.js.map +1 -0
- package/dist/storage/app-storage.d.ts +17 -12
- package/dist/storage/app-storage.d.ts.map +1 -1
- package/dist/storage/app-storage.js +13 -20
- package/dist/storage/app-storage.js.map +1 -1
- package/dist/storage/backends/indexeddb-storage-backend.d.ts +27 -0
- package/dist/storage/backends/indexeddb-storage-backend.d.ts.map +1 -0
- package/dist/storage/backends/indexeddb-storage-backend.js +166 -0
- package/dist/storage/backends/indexeddb-storage-backend.js.map +1 -0
- package/dist/storage/store.d.ts +23 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/store.js +26 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/storage/stores/provider-keys-store.d.ts +14 -0
- package/dist/storage/stores/provider-keys-store.d.ts.map +1 -0
- package/dist/storage/stores/provider-keys-store.js +27 -0
- package/dist/storage/stores/provider-keys-store.js.map +1 -0
- package/dist/storage/stores/sessions-store.d.ts +31 -0
- package/dist/storage/stores/sessions-store.d.ts.map +1 -0
- package/dist/storage/stores/sessions-store.js +113 -0
- package/dist/storage/stores/sessions-store.js.map +1 -0
- package/dist/storage/stores/settings-store.d.ts +14 -0
- package/dist/storage/stores/settings-store.d.ts.map +1 -0
- package/dist/storage/stores/settings-store.js +28 -0
- package/dist/storage/stores/settings-store.js.map +1 -0
- package/dist/storage/types.d.ts +156 -22
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/tools/artifacts/ArtifactElement.d.ts +0 -1
- package/dist/tools/artifacts/ArtifactElement.d.ts.map +1 -1
- package/dist/tools/artifacts/ArtifactElement.js +0 -1
- package/dist/tools/artifacts/ArtifactElement.js.map +1 -1
- package/dist/tools/artifacts/ArtifactPill.d.ts +4 -0
- package/dist/tools/artifacts/ArtifactPill.d.ts.map +1 -0
- package/dist/tools/artifacts/ArtifactPill.js +22 -0
- package/dist/tools/artifacts/ArtifactPill.js.map +1 -0
- package/dist/tools/artifacts/Console.d.ts +18 -0
- package/dist/tools/artifacts/Console.d.ts.map +1 -0
- package/dist/tools/artifacts/Console.js +95 -0
- package/dist/tools/artifacts/Console.js.map +1 -0
- package/dist/tools/artifacts/DocxArtifact.d.ts +22 -0
- package/dist/tools/artifacts/DocxArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/DocxArtifact.js +208 -0
- package/dist/tools/artifacts/DocxArtifact.js.map +1 -0
- package/dist/tools/artifacts/ExcelArtifact.d.ts +24 -0
- package/dist/tools/artifacts/ExcelArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/ExcelArtifact.js +216 -0
- package/dist/tools/artifacts/ExcelArtifact.js.map +1 -0
- package/dist/tools/artifacts/GenericArtifact.d.ts +19 -0
- package/dist/tools/artifacts/GenericArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/GenericArtifact.js +117 -0
- package/dist/tools/artifacts/GenericArtifact.js.map +1 -0
- package/dist/tools/artifacts/HtmlArtifact.d.ts +8 -11
- package/dist/tools/artifacts/HtmlArtifact.d.ts.map +1 -1
- package/dist/tools/artifacts/HtmlArtifact.js +56 -88
- package/dist/tools/artifacts/HtmlArtifact.js.map +1 -1
- package/dist/tools/artifacts/ImageArtifact.d.ts +20 -0
- package/dist/tools/artifacts/ImageArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/ImageArtifact.js +120 -0
- package/dist/tools/artifacts/ImageArtifact.js.map +1 -0
- package/dist/tools/artifacts/MarkdownArtifact.d.ts +0 -1
- package/dist/tools/artifacts/MarkdownArtifact.d.ts.map +1 -1
- package/dist/tools/artifacts/MarkdownArtifact.js +0 -4
- package/dist/tools/artifacts/MarkdownArtifact.js.map +1 -1
- package/dist/tools/artifacts/PdfArtifact.d.ts +25 -0
- package/dist/tools/artifacts/PdfArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/PdfArtifact.js +184 -0
- package/dist/tools/artifacts/PdfArtifact.js.map +1 -0
- package/dist/tools/artifacts/SvgArtifact.d.ts +0 -1
- package/dist/tools/artifacts/SvgArtifact.d.ts.map +1 -1
- package/dist/tools/artifacts/SvgArtifact.js +0 -4
- package/dist/tools/artifacts/SvgArtifact.js.map +1 -1
- package/dist/tools/artifacts/TextArtifact.d.ts +0 -1
- package/dist/tools/artifacts/TextArtifact.d.ts.map +1 -1
- package/dist/tools/artifacts/TextArtifact.js +0 -4
- package/dist/tools/artifacts/TextArtifact.js.map +1 -1
- package/dist/tools/artifacts/artifacts-tool-renderer.d.ts +11 -0
- package/dist/tools/artifacts/artifacts-tool-renderer.d.ts.map +1 -0
- package/dist/tools/artifacts/artifacts-tool-renderer.js +262 -0
- package/dist/tools/artifacts/artifacts-tool-renderer.js.map +1 -0
- package/dist/tools/artifacts/artifacts.d.ts +10 -13
- package/dist/tools/artifacts/artifacts.d.ts.map +1 -1
- package/dist/tools/artifacts/artifacts.js +166 -344
- package/dist/tools/artifacts/artifacts.js.map +1 -1
- package/dist/tools/artifacts/index.d.ts +1 -0
- package/dist/tools/artifacts/index.d.ts.map +1 -1
- package/dist/tools/artifacts/index.js +1 -0
- package/dist/tools/artifacts/index.js.map +1 -1
- package/dist/tools/extract-document.d.ts +24 -0
- package/dist/tools/extract-document.d.ts.map +1 -0
- package/dist/tools/extract-document.js +193 -0
- package/dist/tools/extract-document.js.map +1 -0
- package/dist/tools/index.d.ts +9 -7
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +17 -13
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/javascript-repl.d.ts +16 -15
- package/dist/tools/javascript-repl.d.ts.map +1 -1
- package/dist/tools/javascript-repl.js +101 -133
- package/dist/tools/javascript-repl.js.map +1 -1
- package/dist/tools/renderer-registry.d.ts +12 -0
- package/dist/tools/renderer-registry.d.ts.map +1 -1
- package/dist/tools/renderer-registry.js +78 -0
- package/dist/tools/renderer-registry.js.map +1 -1
- package/dist/tools/renderers/BashRenderer.d.ts +2 -4
- package/dist/tools/renderers/BashRenderer.d.ts.map +1 -1
- package/dist/tools/renderers/BashRenderer.js +30 -26
- package/dist/tools/renderers/BashRenderer.js.map +1 -1
- package/dist/tools/renderers/CalculateRenderer.d.ts +2 -4
- package/dist/tools/renderers/CalculateRenderer.d.ts.map +1 -1
- package/dist/tools/renderers/CalculateRenderer.js +32 -28
- package/dist/tools/renderers/CalculateRenderer.js.map +1 -1
- package/dist/tools/renderers/DefaultRenderer.d.ts +2 -4
- package/dist/tools/renderers/DefaultRenderer.d.ts.map +1 -1
- package/dist/tools/renderers/DefaultRenderer.js +78 -18
- package/dist/tools/renderers/DefaultRenderer.js.map +1 -1
- package/dist/tools/renderers/GetCurrentTimeRenderer.d.ts +2 -4
- package/dist/tools/renderers/GetCurrentTimeRenderer.d.ts.map +1 -1
- package/dist/tools/renderers/GetCurrentTimeRenderer.js +57 -21
- package/dist/tools/renderers/GetCurrentTimeRenderer.js.map +1 -1
- package/dist/tools/types.d.ts +5 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/i18n.d.ts +424 -1
- package/dist/utils/i18n.d.ts.map +1 -1
- package/dist/utils/i18n.js +131 -7
- package/dist/utils/i18n.js.map +1 -1
- package/example/package.json +2 -1
- package/example/src/custom-messages.ts +112 -0
- package/example/src/main.ts +391 -38
- package/package.json +48 -43
- package/scripts/count-prompt-tokens.ts +88 -0
- package/src/ChatPanel.ts +93 -101
- package/src/{state/agent-session.ts → agent/agent.ts} +80 -55
- package/src/{state → agent}/transports/AppTransport.ts +6 -6
- package/src/{state → agent}/transports/ProviderTransport.ts +13 -7
- package/src/{state → agent}/transports/types.ts +8 -2
- package/src/components/AgentInterface.ts +32 -16
- package/src/components/ConsoleBlock.ts +5 -1
- package/src/components/ExpandableSection.ts +46 -0
- package/src/components/MessageEditor.ts +159 -5
- package/src/components/MessageList.ts +18 -3
- package/src/components/Messages.ts +48 -89
- package/src/components/ProviderKeyInput.ts +6 -5
- package/src/components/SandboxedIframe.ts +412 -321
- package/src/components/message-renderer-registry.ts +28 -0
- package/src/components/sandbox/ArtifactsRuntimeProvider.ts +219 -0
- package/src/components/sandbox/AttachmentsRuntimeProvider.ts +66 -0
- package/src/components/sandbox/ConsoleRuntimeProvider.ts +187 -0
- package/src/components/sandbox/FileDownloadRuntimeProvider.ts +110 -0
- package/src/components/sandbox/RuntimeMessageBridge.ts +82 -0
- package/src/components/sandbox/RuntimeMessageRouter.ts +216 -0
- package/src/components/sandbox/SandboxRuntimeProvider.ts +35 -0
- package/src/dialogs/ApiKeyPromptDialog.ts +2 -5
- package/src/dialogs/ModelSelector.ts +2 -2
- package/src/dialogs/PersistentStorageDialog.ts +141 -0
- package/src/dialogs/SessionListDialog.ts +148 -0
- package/src/dialogs/SettingsDialog.ts +1 -0
- package/src/index.ts +61 -20
- package/src/prompts/prompts.ts +282 -0
- package/src/storage/app-storage.ts +27 -24
- package/src/storage/backends/indexeddb-storage-backend.ts +193 -0
- package/src/storage/store.ts +33 -0
- package/src/storage/stores/provider-keys-store.ts +33 -0
- package/src/storage/stores/sessions-store.ts +130 -0
- package/src/storage/stores/settings-store.ts +34 -0
- package/src/storage/types.ts +182 -22
- package/src/tools/artifacts/ArtifactElement.ts +0 -1
- package/src/tools/artifacts/ArtifactPill.ts +25 -0
- package/src/tools/artifacts/Console.ts +93 -0
- package/src/tools/artifacts/DocxArtifact.ts +213 -0
- package/src/tools/artifacts/ExcelArtifact.ts +231 -0
- package/src/tools/artifacts/GenericArtifact.ts +117 -0
- package/src/tools/artifacts/HtmlArtifact.ts +64 -94
- package/src/tools/artifacts/ImageArtifact.ts +116 -0
- package/src/tools/artifacts/MarkdownArtifact.ts +0 -1
- package/src/tools/artifacts/PdfArtifact.ts +201 -0
- package/src/tools/artifacts/SvgArtifact.ts +0 -1
- package/src/tools/artifacts/TextArtifact.ts +0 -1
- package/src/tools/artifacts/artifacts-tool-renderer.ts +298 -0
- package/src/tools/artifacts/artifacts.ts +190 -366
- package/src/tools/artifacts/index.ts +1 -0
- package/src/tools/extract-document.ts +250 -0
- package/src/tools/index.ts +25 -14
- package/src/tools/javascript-repl.ts +138 -160
- package/src/tools/renderer-registry.ts +98 -0
- package/src/tools/renderers/BashRenderer.ts +33 -30
- package/src/tools/renderers/CalculateRenderer.ts +36 -31
- package/src/tools/renderers/DefaultRenderer.ts +84 -21
- package/src/tools/renderers/GetCurrentTimeRenderer.ts +68 -23
- package/src/tools/types.ts +10 -2
- package/src/utils/i18n.ts +203 -8
- package/dist/state/agent-session.d.ts.map +0 -1
- package/dist/state/agent-session.js.map +0 -1
- package/dist/state/transports/AppTransport.d.ts.map +0 -1
- package/dist/state/transports/ProviderTransport.d.ts.map +0 -1
- package/dist/state/transports/ProviderTransport.js.map +0 -1
- package/dist/state/transports/index.js.map +0 -1
- package/dist/state/transports/proxy-types.js.map +0 -1
- package/dist/state/transports/types.d.ts +0 -11
- package/dist/state/transports/types.d.ts.map +0 -1
- package/dist/storage/backends/chrome-storage-backend.d.ts +0 -18
- package/dist/storage/backends/chrome-storage-backend.d.ts.map +0 -1
- package/dist/storage/backends/chrome-storage-backend.js +0 -67
- package/dist/storage/backends/chrome-storage-backend.js.map +0 -1
- package/dist/storage/backends/indexeddb-backend.d.ts +0 -20
- package/dist/storage/backends/indexeddb-backend.d.ts.map +0 -1
- package/dist/storage/backends/indexeddb-backend.js +0 -89
- package/dist/storage/backends/indexeddb-backend.js.map +0 -1
- package/dist/storage/backends/local-storage-backend.d.ts +0 -18
- package/dist/storage/backends/local-storage-backend.d.ts.map +0 -1
- package/dist/storage/backends/local-storage-backend.js +0 -69
- package/dist/storage/backends/local-storage-backend.js.map +0 -1
- package/dist/storage/repositories/provider-keys-repository.d.ts +0 -34
- package/dist/storage/repositories/provider-keys-repository.d.ts.map +0 -1
- package/dist/storage/repositories/provider-keys-repository.js +0 -50
- package/dist/storage/repositories/provider-keys-repository.js.map +0 -1
- package/dist/storage/repositories/settings-repository.d.ts +0 -34
- package/dist/storage/repositories/settings-repository.d.ts.map +0 -1
- package/dist/storage/repositories/settings-repository.js +0 -46
- package/dist/storage/repositories/settings-repository.js.map +0 -1
- package/src/storage/backends/chrome-storage-backend.ts +0 -82
- package/src/storage/backends/indexeddb-backend.ts +0 -107
- package/src/storage/backends/local-storage-backend.ts +0 -74
- package/src/storage/repositories/provider-keys-repository.ts +0 -55
- package/src/storage/repositories/settings-repository.ts +0 -51
- /package/dist/{state → agent}/transports/index.d.ts +0 -0
- /package/dist/{state → agent}/transports/index.js +0 -0
- /package/dist/{state → agent}/transports/proxy-types.d.ts +0 -0
- /package/dist/{state → agent}/transports/proxy-types.js +0 -0
- /package/dist/{state → agent}/transports/types.js +0 -0
- /package/dist/{state → agent}/types.d.ts +0 -0
- /package/dist/{state → agent}/types.js +0 -0
- /package/src/{state → agent}/transports/index.ts +0 -0
- /package/src/{state → agent}/transports/proxy-types.ts +0 -0
- /package/src/{state → agent}/types.ts +0 -0
|
@@ -4,35 +4,37 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { Button,
|
|
7
|
+
import { Button, icon } from "@mariozechner/mini-lit";
|
|
8
|
+
import "@mariozechner/mini-lit/dist/MarkdownBlock.js";
|
|
8
9
|
import { StringEnum } from "@mariozechner/pi-ai";
|
|
9
10
|
import { Type } from "@sinclair/typebox";
|
|
10
11
|
import { html, LitElement } from "lit";
|
|
11
12
|
import { customElement, property, state } from "lit/decorators.js";
|
|
12
13
|
import { createRef, ref } from "lit/directives/ref.js";
|
|
13
14
|
import { X } from "lucide";
|
|
15
|
+
import { ArtifactsRuntimeProvider } from "../../components/sandbox/ArtifactsRuntimeProvider.js";
|
|
16
|
+
import { AttachmentsRuntimeProvider } from "../../components/sandbox/AttachmentsRuntimeProvider.js";
|
|
17
|
+
import { ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION_RO, ARTIFACTS_TOOL_DESCRIPTION, ATTACHMENTS_RUNTIME_DESCRIPTION, } from "../../prompts/prompts.js";
|
|
14
18
|
import { i18n } from "../../utils/i18n.js";
|
|
19
|
+
import { DocxArtifact } from "./DocxArtifact.js";
|
|
20
|
+
import { ExcelArtifact } from "./ExcelArtifact.js";
|
|
21
|
+
import { GenericArtifact } from "./GenericArtifact.js";
|
|
15
22
|
import { HtmlArtifact } from "./HtmlArtifact.js";
|
|
23
|
+
import { ImageArtifact } from "./ImageArtifact.js";
|
|
16
24
|
import { MarkdownArtifact } from "./MarkdownArtifact.js";
|
|
25
|
+
import { PdfArtifact } from "./PdfArtifact.js";
|
|
17
26
|
import { SvgArtifact } from "./SvgArtifact.js";
|
|
18
27
|
import { TextArtifact } from "./TextArtifact.js";
|
|
19
|
-
import "@mariozechner/mini-lit/dist/MarkdownBlock.js";
|
|
20
|
-
import "@mariozechner/mini-lit/dist/CodeBlock.js";
|
|
21
28
|
// JSON-schema friendly parameters object (LLM-facing)
|
|
22
29
|
const artifactsParamsSchema = Type.Object({
|
|
23
30
|
command: StringEnum(["create", "update", "rewrite", "get", "delete", "logs"], {
|
|
24
31
|
description: "The operation to perform",
|
|
25
32
|
}),
|
|
26
33
|
filename: Type.String({ description: "Filename including extension (e.g., 'index.html', 'script.js')" }),
|
|
27
|
-
title: Type.Optional(Type.String({ description: "Display title for the tab (defaults to filename)" })),
|
|
28
34
|
content: Type.Optional(Type.String({ description: "File content" })),
|
|
29
35
|
old_str: Type.Optional(Type.String({ description: "String to replace (for update command)" })),
|
|
30
36
|
new_str: Type.Optional(Type.String({ description: "Replacement string (for update command)" })),
|
|
31
37
|
});
|
|
32
|
-
// Minimal helper to render plain text outputs consistently
|
|
33
|
-
function plainOutput(text) {
|
|
34
|
-
return html `<div class="text-xs text-muted-foreground whitespace-pre-wrap font-mono">${text}</div>`;
|
|
35
|
-
}
|
|
36
38
|
let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
37
39
|
constructor() {
|
|
38
40
|
super(...arguments);
|
|
@@ -50,6 +52,25 @@ let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
|
50
52
|
get artifacts() {
|
|
51
53
|
return this._artifacts;
|
|
52
54
|
}
|
|
55
|
+
// Get runtime providers for HTML artifacts (read-only: attachments + artifacts)
|
|
56
|
+
getHtmlArtifactRuntimeProviders() {
|
|
57
|
+
const providers = [];
|
|
58
|
+
// Get attachments from agent messages
|
|
59
|
+
if (this.agent) {
|
|
60
|
+
const attachments = [];
|
|
61
|
+
for (const message of this.agent.state.messages) {
|
|
62
|
+
if (message.role === "user" && message.attachments) {
|
|
63
|
+
attachments.push(...message.attachments);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (attachments.length > 0) {
|
|
67
|
+
providers.push(new AttachmentsRuntimeProvider(attachments));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Add read-only artifacts provider
|
|
71
|
+
providers.push(new ArtifactsRuntimeProvider(this, this.agent, false));
|
|
72
|
+
return providers;
|
|
73
|
+
}
|
|
53
74
|
createRenderRoot() {
|
|
54
75
|
return this; // light DOM for shared styles
|
|
55
76
|
}
|
|
@@ -86,53 +107,53 @@ let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
|
86
107
|
return "svg";
|
|
87
108
|
if (ext === "md" || ext === "markdown")
|
|
88
109
|
return "markdown";
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
110
|
+
if (ext === "pdf")
|
|
111
|
+
return "pdf";
|
|
112
|
+
if (ext === "xlsx" || ext === "xls")
|
|
113
|
+
return "excel";
|
|
114
|
+
if (ext === "docx")
|
|
115
|
+
return "docx";
|
|
116
|
+
if (ext === "png" ||
|
|
117
|
+
ext === "jpg" ||
|
|
118
|
+
ext === "jpeg" ||
|
|
119
|
+
ext === "gif" ||
|
|
120
|
+
ext === "webp" ||
|
|
121
|
+
ext === "bmp" ||
|
|
122
|
+
ext === "ico")
|
|
123
|
+
return "image";
|
|
124
|
+
// Text files
|
|
125
|
+
if (ext === "txt" ||
|
|
126
|
+
ext === "json" ||
|
|
127
|
+
ext === "xml" ||
|
|
128
|
+
ext === "yaml" ||
|
|
129
|
+
ext === "yml" ||
|
|
130
|
+
ext === "csv" ||
|
|
131
|
+
ext === "js" ||
|
|
132
|
+
ext === "ts" ||
|
|
133
|
+
ext === "jsx" ||
|
|
134
|
+
ext === "tsx" ||
|
|
135
|
+
ext === "py" ||
|
|
136
|
+
ext === "java" ||
|
|
137
|
+
ext === "c" ||
|
|
138
|
+
ext === "cpp" ||
|
|
139
|
+
ext === "h" ||
|
|
140
|
+
ext === "css" ||
|
|
141
|
+
ext === "scss" ||
|
|
142
|
+
ext === "sass" ||
|
|
143
|
+
ext === "less" ||
|
|
144
|
+
ext === "sh")
|
|
94
145
|
return "text";
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
js: "javascript",
|
|
98
|
-
jsx: "javascript",
|
|
99
|
-
ts: "typescript",
|
|
100
|
-
tsx: "typescript",
|
|
101
|
-
html: "html",
|
|
102
|
-
css: "css",
|
|
103
|
-
scss: "scss",
|
|
104
|
-
json: "json",
|
|
105
|
-
py: "python",
|
|
106
|
-
md: "markdown",
|
|
107
|
-
svg: "xml",
|
|
108
|
-
xml: "xml",
|
|
109
|
-
yaml: "yaml",
|
|
110
|
-
yml: "yaml",
|
|
111
|
-
sh: "bash",
|
|
112
|
-
bash: "bash",
|
|
113
|
-
sql: "sql",
|
|
114
|
-
java: "java",
|
|
115
|
-
c: "c",
|
|
116
|
-
cpp: "cpp",
|
|
117
|
-
cs: "csharp",
|
|
118
|
-
go: "go",
|
|
119
|
-
rs: "rust",
|
|
120
|
-
php: "php",
|
|
121
|
-
rb: "ruby",
|
|
122
|
-
swift: "swift",
|
|
123
|
-
kt: "kotlin",
|
|
124
|
-
r: "r",
|
|
125
|
-
};
|
|
126
|
-
return languageMap[ext || ""] || "text";
|
|
146
|
+
// Everything else gets generic fallback
|
|
147
|
+
return "generic";
|
|
127
148
|
}
|
|
128
149
|
// Get or create artifact element
|
|
129
|
-
getOrCreateArtifactElement(filename, content
|
|
150
|
+
getOrCreateArtifactElement(filename, content) {
|
|
130
151
|
let element = this.artifactElements.get(filename);
|
|
131
152
|
if (!element) {
|
|
132
153
|
const type = this.getFileType(filename);
|
|
133
154
|
if (type === "html") {
|
|
134
155
|
element = new HtmlArtifact();
|
|
135
|
-
element.
|
|
156
|
+
element.runtimeProviders = this.getHtmlArtifactRuntimeProviders();
|
|
136
157
|
if (this.sandboxUrlProvider) {
|
|
137
158
|
element.sandboxUrlProvider = this.sandboxUrlProvider;
|
|
138
159
|
}
|
|
@@ -143,11 +164,25 @@ let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
|
143
164
|
else if (type === "markdown") {
|
|
144
165
|
element = new MarkdownArtifact();
|
|
145
166
|
}
|
|
146
|
-
else {
|
|
167
|
+
else if (type === "image") {
|
|
168
|
+
element = new ImageArtifact();
|
|
169
|
+
}
|
|
170
|
+
else if (type === "pdf") {
|
|
171
|
+
element = new PdfArtifact();
|
|
172
|
+
}
|
|
173
|
+
else if (type === "excel") {
|
|
174
|
+
element = new ExcelArtifact();
|
|
175
|
+
}
|
|
176
|
+
else if (type === "docx") {
|
|
177
|
+
element = new DocxArtifact();
|
|
178
|
+
}
|
|
179
|
+
else if (type === "text") {
|
|
147
180
|
element = new TextArtifact();
|
|
148
181
|
}
|
|
182
|
+
else {
|
|
183
|
+
element = new GenericArtifact();
|
|
184
|
+
}
|
|
149
185
|
element.filename = filename;
|
|
150
|
-
element.displayTitle = title;
|
|
151
186
|
element.content = content;
|
|
152
187
|
element.style.display = "none";
|
|
153
188
|
element.style.height = "100%";
|
|
@@ -169,9 +204,8 @@ let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
|
169
204
|
else {
|
|
170
205
|
// Just update content
|
|
171
206
|
element.content = content;
|
|
172
|
-
element.displayTitle = title;
|
|
173
207
|
if (element instanceof HtmlArtifact) {
|
|
174
|
-
element.
|
|
208
|
+
element.runtimeProviders = this.getHtmlArtifactRuntimeProviders();
|
|
175
209
|
}
|
|
176
210
|
}
|
|
177
211
|
return element;
|
|
@@ -189,6 +223,13 @@ let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
|
189
223
|
});
|
|
190
224
|
this._activeFilename = filename;
|
|
191
225
|
this.requestUpdate(); // Only for tab bar update
|
|
226
|
+
// Scroll the active tab into view after render
|
|
227
|
+
requestAnimationFrame(() => {
|
|
228
|
+
const activeButton = this.querySelector(`button[data-filename="${filename}"]`);
|
|
229
|
+
if (activeButton) {
|
|
230
|
+
activeButton.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" });
|
|
231
|
+
}
|
|
232
|
+
});
|
|
192
233
|
}
|
|
193
234
|
// Open panel and focus an artifact tab by filename
|
|
194
235
|
openArtifact(filename) {
|
|
@@ -203,103 +244,14 @@ let ArtifactsPanel = class ArtifactsPanel extends LitElement {
|
|
|
203
244
|
return {
|
|
204
245
|
label: "Artifacts",
|
|
205
246
|
name: "artifacts",
|
|
206
|
-
description
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
- content: File content (required)
|
|
215
|
-
|
|
216
|
-
2. update: Update part of an existing file
|
|
217
|
-
- filename: File to update (required)
|
|
218
|
-
- old_str: Exact string to replace (required)
|
|
219
|
-
- new_str: Replacement string (required)
|
|
220
|
-
|
|
221
|
-
3. rewrite: Completely replace a file's content
|
|
222
|
-
- filename: File to rewrite (required)
|
|
223
|
-
- content: New content (required)
|
|
224
|
-
- title: Optionally update display title
|
|
225
|
-
|
|
226
|
-
4. get: Retrieve the full content of a file
|
|
227
|
-
- filename: File to retrieve (required)
|
|
228
|
-
- Returns the complete file content
|
|
229
|
-
|
|
230
|
-
5. delete: Delete a file
|
|
231
|
-
- filename: File to delete (required)
|
|
232
|
-
|
|
233
|
-
6. logs: Get console logs and errors (HTML files only)
|
|
234
|
-
- filename: HTML file to get logs for (required)
|
|
235
|
-
- Returns all console output and runtime errors
|
|
236
|
-
|
|
237
|
-
For text/html artifacts with attachments:
|
|
238
|
-
- HTML artifacts automatically have access to user attachments via JavaScript
|
|
239
|
-
- Available global functions in HTML artifacts:
|
|
240
|
-
* listFiles() - Returns array of {id, fileName, mimeType, size} for all attachments
|
|
241
|
-
* readTextFile(attachmentId) - Returns text content of attachment (for CSV, JSON, text files)
|
|
242
|
-
* readBinaryFile(attachmentId) - Returns Uint8Array of binary data (for images, Excel, etc.)
|
|
243
|
-
- Example HTML artifact that processes a CSV attachment:
|
|
244
|
-
<script>
|
|
245
|
-
// List available files
|
|
246
|
-
const files = listFiles();
|
|
247
|
-
console.log('Available files:', files);
|
|
248
|
-
|
|
249
|
-
// Find CSV file
|
|
250
|
-
const csvFile = files.find(f => f.mimeType === 'text/csv');
|
|
251
|
-
if (csvFile) {
|
|
252
|
-
const csvContent = readTextFile(csvFile.id);
|
|
253
|
-
// Process CSV data...
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Display image
|
|
257
|
-
const imageFile = files.find(f => f.mimeType.startsWith('image/'));
|
|
258
|
-
if (imageFile) {
|
|
259
|
-
const bytes = readBinaryFile(imageFile.id);
|
|
260
|
-
const blob = new Blob([bytes], {type: imageFile.mimeType});
|
|
261
|
-
const url = URL.createObjectURL(blob);
|
|
262
|
-
document.body.innerHTML = '<img src="' + url + '">';
|
|
263
|
-
}
|
|
264
|
-
</script>
|
|
265
|
-
|
|
266
|
-
For text/html artifacts:
|
|
267
|
-
- Must be a single self-contained file
|
|
268
|
-
- External scripts: Use CDNs like https://esm.sh, https://unpkg.com, or https://cdnjs.cloudflare.com
|
|
269
|
-
- Preferred: Use https://esm.sh for npm packages (e.g., https://esm.sh/three for Three.js)
|
|
270
|
-
- For ES modules, use: <script type="module">import * as THREE from 'https://esm.sh/three';</script>
|
|
271
|
-
- For Three.js specifically: import from 'https://esm.sh/three' or 'https://esm.sh/three@0.160.0'
|
|
272
|
-
- For addons: import from 'https://esm.sh/three/examples/jsm/controls/OrbitControls.js'
|
|
273
|
-
- No localStorage/sessionStorage - use in-memory variables only
|
|
274
|
-
- CSS should be included inline
|
|
275
|
-
- CRITICAL REMINDER FOR HTML ARTIFACTS:
|
|
276
|
-
- ALWAYS set a background color inline in <style> or directly on body element
|
|
277
|
-
- Failure to set a background color is a COMPLIANCE ERROR
|
|
278
|
-
- Background color MUST be explicitly defined to ensure visibility and proper rendering
|
|
279
|
-
- Can embed base64 images directly in img tags
|
|
280
|
-
- Ensure the layout is responsive as the iframe might be resized
|
|
281
|
-
- Note: Network errors (404s) for external scripts may not be captured in logs due to browser security
|
|
282
|
-
|
|
283
|
-
For application/vnd.ant.code artifacts:
|
|
284
|
-
- Include the language parameter for syntax highlighting
|
|
285
|
-
- Supports all major programming languages
|
|
286
|
-
|
|
287
|
-
For text/markdown:
|
|
288
|
-
- Standard markdown syntax
|
|
289
|
-
- Will be rendered with full formatting
|
|
290
|
-
- Can include base64 images using markdown syntax
|
|
291
|
-
|
|
292
|
-
For image/svg+xml:
|
|
293
|
-
- Complete SVG markup
|
|
294
|
-
- Will be rendered inline
|
|
295
|
-
- Can embed raster images as base64 in SVG
|
|
296
|
-
|
|
297
|
-
CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
298
|
-
- Prefer to update existing files rather than creating new ones
|
|
299
|
-
- Keep filenames consistent and descriptive
|
|
300
|
-
- Use appropriate file extensions
|
|
301
|
-
- Ensure HTML artifacts have a defined background color
|
|
302
|
-
`,
|
|
247
|
+
get description() {
|
|
248
|
+
// HTML artifacts have read-only access to attachments and artifacts
|
|
249
|
+
const runtimeProviderDescriptions = [
|
|
250
|
+
ATTACHMENTS_RUNTIME_DESCRIPTION,
|
|
251
|
+
ARTIFACTS_RUNTIME_PROVIDER_DESCRIPTION_RO,
|
|
252
|
+
];
|
|
253
|
+
return ARTIFACTS_TOOL_DESCRIPTION(runtimeProviderDescriptions);
|
|
254
|
+
},
|
|
303
255
|
parameters: artifactsParamsSchema,
|
|
304
256
|
// Execute mutates our local store and returns a plain output
|
|
305
257
|
execute: async (_toolCallId, args, _signal) => {
|
|
@@ -308,143 +260,6 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
308
260
|
},
|
|
309
261
|
};
|
|
310
262
|
}
|
|
311
|
-
// ToolRenderer implementation
|
|
312
|
-
renderParams(params, isStreaming) {
|
|
313
|
-
if (isStreaming && !params.command) {
|
|
314
|
-
return html `<div class="text-sm text-muted-foreground">${i18n("Processing artifact...")}</div>`;
|
|
315
|
-
}
|
|
316
|
-
let commandLabel = i18n("Processing");
|
|
317
|
-
if (params.command) {
|
|
318
|
-
switch (params.command) {
|
|
319
|
-
case "create":
|
|
320
|
-
commandLabel = i18n("Create");
|
|
321
|
-
break;
|
|
322
|
-
case "update":
|
|
323
|
-
commandLabel = i18n("Update");
|
|
324
|
-
break;
|
|
325
|
-
case "rewrite":
|
|
326
|
-
commandLabel = i18n("Rewrite");
|
|
327
|
-
break;
|
|
328
|
-
case "get":
|
|
329
|
-
commandLabel = i18n("Get");
|
|
330
|
-
break;
|
|
331
|
-
case "delete":
|
|
332
|
-
commandLabel = i18n("Delete");
|
|
333
|
-
break;
|
|
334
|
-
case "logs":
|
|
335
|
-
commandLabel = i18n("Get logs");
|
|
336
|
-
break;
|
|
337
|
-
default:
|
|
338
|
-
commandLabel = params.command.charAt(0).toUpperCase() + params.command.slice(1);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
const filename = params.filename || "";
|
|
342
|
-
switch (params.command) {
|
|
343
|
-
case "create":
|
|
344
|
-
return html `
|
|
345
|
-
<div
|
|
346
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
347
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
348
|
-
>
|
|
349
|
-
<div>
|
|
350
|
-
<span class="font-medium">${i18n("Create")}</span>
|
|
351
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
352
|
-
</div>
|
|
353
|
-
${params.content
|
|
354
|
-
? html `<code-block
|
|
355
|
-
.code=${params.content}
|
|
356
|
-
language=${this.getLanguageFromFilename(params.filename)}
|
|
357
|
-
class="mt-2"
|
|
358
|
-
></code-block>`
|
|
359
|
-
: ""}
|
|
360
|
-
</div>
|
|
361
|
-
`;
|
|
362
|
-
case "update":
|
|
363
|
-
return html `
|
|
364
|
-
<div
|
|
365
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
366
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
367
|
-
>
|
|
368
|
-
<div>
|
|
369
|
-
<span class="font-medium">${i18n("Update")}</span>
|
|
370
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
371
|
-
</div>
|
|
372
|
-
${params.old_str !== undefined && params.new_str !== undefined
|
|
373
|
-
? Diff({ oldText: params.old_str, newText: params.new_str, className: "mt-2" })
|
|
374
|
-
: ""}
|
|
375
|
-
</div>
|
|
376
|
-
`;
|
|
377
|
-
case "rewrite":
|
|
378
|
-
return html `
|
|
379
|
-
<div
|
|
380
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
381
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
382
|
-
>
|
|
383
|
-
<div>
|
|
384
|
-
<span class="font-medium">${i18n("Rewrite")}</span>
|
|
385
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
386
|
-
</div>
|
|
387
|
-
${params.content
|
|
388
|
-
? html `<code-block
|
|
389
|
-
.code=${params.content}
|
|
390
|
-
language=${this.getLanguageFromFilename(params.filename)}
|
|
391
|
-
class="mt-2"
|
|
392
|
-
></code-block>`
|
|
393
|
-
: ""}
|
|
394
|
-
</div>
|
|
395
|
-
`;
|
|
396
|
-
case "get":
|
|
397
|
-
return html `
|
|
398
|
-
<div
|
|
399
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
400
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
401
|
-
>
|
|
402
|
-
<span class="font-medium">${i18n("Get")}</span>
|
|
403
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
404
|
-
</div>
|
|
405
|
-
`;
|
|
406
|
-
case "delete":
|
|
407
|
-
return html `
|
|
408
|
-
<div
|
|
409
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
410
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
411
|
-
>
|
|
412
|
-
<span class="font-medium">${i18n("Delete")}</span>
|
|
413
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
414
|
-
</div>
|
|
415
|
-
`;
|
|
416
|
-
case "logs":
|
|
417
|
-
return html `
|
|
418
|
-
<div
|
|
419
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
420
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
421
|
-
>
|
|
422
|
-
<span class="font-medium">${i18n("Get logs")}</span>
|
|
423
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
424
|
-
</div>
|
|
425
|
-
`;
|
|
426
|
-
default:
|
|
427
|
-
// Fallback for any command not yet handled during streaming
|
|
428
|
-
return html `
|
|
429
|
-
<div
|
|
430
|
-
class="text-sm cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1"
|
|
431
|
-
@click=${() => this.openArtifact(params.filename)}
|
|
432
|
-
>
|
|
433
|
-
<span class="font-medium">${commandLabel}</span>
|
|
434
|
-
<span class="text-muted-foreground ml-1">${filename}</span>
|
|
435
|
-
</div>
|
|
436
|
-
`;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
renderResult(params, result) {
|
|
440
|
-
// Make result clickable to focus the referenced file when applicable
|
|
441
|
-
const content = result.output || i18n("(no output)");
|
|
442
|
-
return html `
|
|
443
|
-
<div class="cursor-pointer hover:bg-muted/50 rounded-sm px-2 py-1" @click=${() => this.openArtifact(params.filename)}>
|
|
444
|
-
${plainOutput(content)}
|
|
445
|
-
</div>
|
|
446
|
-
`;
|
|
447
|
-
}
|
|
448
263
|
// Re-apply artifacts by scanning a message list (optional utility)
|
|
449
264
|
async reconstructFromMessages(messages) {
|
|
450
265
|
const toolCalls = new Map();
|
|
@@ -462,7 +277,33 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
462
277
|
// 2) Build an ordered list of successful artifact operations
|
|
463
278
|
const operations = [];
|
|
464
279
|
for (const m of messages) {
|
|
465
|
-
if (m.role === "
|
|
280
|
+
if (m.role === "artifact") {
|
|
281
|
+
const artifactMsg = m;
|
|
282
|
+
switch (artifactMsg.action) {
|
|
283
|
+
case "create":
|
|
284
|
+
operations.push({
|
|
285
|
+
command: "create",
|
|
286
|
+
filename: artifactMsg.filename,
|
|
287
|
+
content: artifactMsg.content,
|
|
288
|
+
});
|
|
289
|
+
break;
|
|
290
|
+
case "update":
|
|
291
|
+
operations.push({
|
|
292
|
+
command: "rewrite",
|
|
293
|
+
filename: artifactMsg.filename,
|
|
294
|
+
content: artifactMsg.content,
|
|
295
|
+
});
|
|
296
|
+
break;
|
|
297
|
+
case "delete":
|
|
298
|
+
operations.push({
|
|
299
|
+
command: "delete",
|
|
300
|
+
filename: artifactMsg.filename,
|
|
301
|
+
});
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Handle tool result messages (from artifacts tool calls)
|
|
306
|
+
else if (m.role === "toolResult" && m.toolName === artifactToolName && !m.isError) {
|
|
466
307
|
const toolCallId = m.toolCallId;
|
|
467
308
|
const call = toolCalls.get(toolCallId);
|
|
468
309
|
if (!call)
|
|
@@ -473,30 +314,29 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
473
314
|
operations.push(params);
|
|
474
315
|
}
|
|
475
316
|
}
|
|
317
|
+
// 3) Compute final state per filename by simulating operations in-memory
|
|
476
318
|
const finalArtifacts = new Map();
|
|
477
319
|
for (const op of operations) {
|
|
478
320
|
const filename = op.filename;
|
|
479
321
|
switch (op.command) {
|
|
480
322
|
case "create": {
|
|
481
323
|
if (op.content) {
|
|
482
|
-
finalArtifacts.set(filename,
|
|
324
|
+
finalArtifacts.set(filename, op.content);
|
|
483
325
|
}
|
|
484
326
|
break;
|
|
485
327
|
}
|
|
486
328
|
case "rewrite": {
|
|
487
329
|
if (op.content) {
|
|
488
|
-
|
|
489
|
-
const existing = finalArtifacts.get(filename);
|
|
490
|
-
finalArtifacts.set(filename, { title: op.title || existing?.title || filename, content: op.content });
|
|
330
|
+
finalArtifacts.set(filename, op.content);
|
|
491
331
|
}
|
|
492
332
|
break;
|
|
493
333
|
}
|
|
494
334
|
case "update": {
|
|
495
|
-
|
|
335
|
+
let existing = finalArtifacts.get(filename);
|
|
496
336
|
if (!existing)
|
|
497
337
|
break; // skip invalid update (shouldn't happen for successful results)
|
|
498
338
|
if (op.old_str !== undefined && op.new_str !== undefined) {
|
|
499
|
-
existing
|
|
339
|
+
existing = existing.replace(op.old_str, op.new_str);
|
|
500
340
|
finalArtifacts.set(filename, existing);
|
|
501
341
|
}
|
|
502
342
|
break;
|
|
@@ -520,8 +360,8 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
520
360
|
this._activeFilename = null;
|
|
521
361
|
this._artifacts = new Map(this._artifacts);
|
|
522
362
|
// 5) Create artifacts in a single pass without waiting for iframe execution or tab switching
|
|
523
|
-
for (const [filename,
|
|
524
|
-
const createParams = { command: "create", filename,
|
|
363
|
+
for (const [filename, content] of finalArtifacts.entries()) {
|
|
364
|
+
const createParams = { command: "create", filename, content };
|
|
525
365
|
try {
|
|
526
366
|
await this.createArtifact(createParams, { skipWait: true, silent: true });
|
|
527
367
|
}
|
|
@@ -563,48 +403,25 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
563
403
|
return "";
|
|
564
404
|
}
|
|
565
405
|
return new Promise((resolve) => {
|
|
566
|
-
|
|
567
|
-
// Listen for the execution-complete message
|
|
568
|
-
const messageHandler = (event) => {
|
|
569
|
-
if (event.data?.type === "execution-complete" && event.data?.artifactId === filename) {
|
|
570
|
-
if (!resolved) {
|
|
571
|
-
resolved = true;
|
|
572
|
-
window.removeEventListener("message", messageHandler);
|
|
573
|
-
// Get the logs from the element
|
|
574
|
-
const logs = element.getLogs();
|
|
575
|
-
if (logs.includes("[error]")) {
|
|
576
|
-
resolve(`\n\nExecution completed with errors:\n${logs}`);
|
|
577
|
-
}
|
|
578
|
-
else if (logs !== `No logs for ${filename}`) {
|
|
579
|
-
resolve(`\n\nExecution logs:\n${logs}`);
|
|
580
|
-
}
|
|
581
|
-
else {
|
|
582
|
-
resolve("");
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
};
|
|
587
|
-
window.addEventListener("message", messageHandler);
|
|
588
|
-
// Fallback timeout in case the message never arrives
|
|
406
|
+
// Fallback timeout - just get logs after execution should complete
|
|
589
407
|
setTimeout(() => {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
// Get whatever logs we have so far
|
|
594
|
-
const logs = element.getLogs();
|
|
595
|
-
if (logs.includes("[error]")) {
|
|
596
|
-
resolve(`\n\nExecution timed out with errors:\n${logs}`);
|
|
597
|
-
}
|
|
598
|
-
else if (logs !== `No logs for ${filename}`) {
|
|
599
|
-
resolve(`\n\nExecution timed out. Partial logs:\n${logs}`);
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
resolve("");
|
|
603
|
-
}
|
|
604
|
-
}
|
|
408
|
+
// Get whatever logs we have
|
|
409
|
+
const logs = element.getLogs();
|
|
410
|
+
resolve(logs);
|
|
605
411
|
}, 1500);
|
|
606
412
|
});
|
|
607
413
|
}
|
|
414
|
+
// Reload all HTML artifacts (called when any artifact changes)
|
|
415
|
+
reloadAllHtmlArtifacts() {
|
|
416
|
+
this.artifactElements.forEach((element) => {
|
|
417
|
+
if (element instanceof HtmlArtifact && element.sandboxIframeRef.value) {
|
|
418
|
+
// Update runtime providers with latest artifact state
|
|
419
|
+
element.runtimeProviders = this.getHtmlArtifactRuntimeProviders();
|
|
420
|
+
// Re-execute the HTML content
|
|
421
|
+
element.executeContent(element.content);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
608
425
|
async createArtifact(params, options = {}) {
|
|
609
426
|
if (!params.filename || !params.content) {
|
|
610
427
|
return "Error: create command requires filename and content";
|
|
@@ -612,10 +429,8 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
612
429
|
if (this._artifacts.has(params.filename)) {
|
|
613
430
|
return `Error: File ${params.filename} already exists`;
|
|
614
431
|
}
|
|
615
|
-
const title = params.title || params.filename;
|
|
616
432
|
const artifact = {
|
|
617
433
|
filename: params.filename,
|
|
618
|
-
title: title,
|
|
619
434
|
content: params.content,
|
|
620
435
|
createdAt: new Date(),
|
|
621
436
|
updatedAt: new Date(),
|
|
@@ -623,17 +438,19 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
623
438
|
this._artifacts.set(params.filename, artifact);
|
|
624
439
|
this._artifacts = new Map(this._artifacts);
|
|
625
440
|
// Create or update element
|
|
626
|
-
this.getOrCreateArtifactElement(params.filename, params.content
|
|
441
|
+
this.getOrCreateArtifactElement(params.filename, params.content);
|
|
627
442
|
if (!options.silent) {
|
|
628
443
|
this.showArtifact(params.filename);
|
|
629
444
|
this.onArtifactsChange?.();
|
|
630
445
|
this.requestUpdate();
|
|
631
446
|
}
|
|
447
|
+
// Reload all HTML artifacts since they might depend on this new artifact
|
|
448
|
+
this.reloadAllHtmlArtifacts();
|
|
632
449
|
// For HTML files, wait for execution
|
|
633
450
|
let result = `Created file ${params.filename}`;
|
|
634
451
|
if (this.getFileType(params.filename) === "html" && !options.skipWait) {
|
|
635
452
|
const logs = await this.waitForHtmlExecution(params.filename);
|
|
636
|
-
result += logs
|
|
453
|
+
result += `\n${logs}`;
|
|
637
454
|
}
|
|
638
455
|
return result;
|
|
639
456
|
}
|
|
@@ -655,18 +472,20 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
655
472
|
artifact.updatedAt = new Date();
|
|
656
473
|
this._artifacts.set(params.filename, artifact);
|
|
657
474
|
// Update element
|
|
658
|
-
this.getOrCreateArtifactElement(params.filename, artifact.content
|
|
475
|
+
this.getOrCreateArtifactElement(params.filename, artifact.content);
|
|
659
476
|
if (!options.silent) {
|
|
660
477
|
this.onArtifactsChange?.();
|
|
661
478
|
this.requestUpdate();
|
|
662
479
|
}
|
|
663
480
|
// Show the artifact
|
|
664
481
|
this.showArtifact(params.filename);
|
|
482
|
+
// Reload all HTML artifacts since they might depend on this updated artifact
|
|
483
|
+
this.reloadAllHtmlArtifacts();
|
|
665
484
|
// For HTML files, wait for execution
|
|
666
485
|
let result = `Updated file ${params.filename}`;
|
|
667
486
|
if (this.getFileType(params.filename) === "html" && !options.skipWait) {
|
|
668
487
|
const logs = await this.waitForHtmlExecution(params.filename);
|
|
669
|
-
result += logs
|
|
488
|
+
result += `\n${logs}`;
|
|
670
489
|
}
|
|
671
490
|
return result;
|
|
672
491
|
}
|
|
@@ -682,22 +501,22 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
682
501
|
return "Error: rewrite command requires content";
|
|
683
502
|
}
|
|
684
503
|
artifact.content = params.content;
|
|
685
|
-
if (params.title)
|
|
686
|
-
artifact.title = params.title;
|
|
687
504
|
artifact.updatedAt = new Date();
|
|
688
505
|
this._artifacts.set(params.filename, artifact);
|
|
689
506
|
// Update element
|
|
690
|
-
this.getOrCreateArtifactElement(params.filename, artifact.content
|
|
507
|
+
this.getOrCreateArtifactElement(params.filename, artifact.content);
|
|
691
508
|
if (!options.silent) {
|
|
692
509
|
this.onArtifactsChange?.();
|
|
693
510
|
}
|
|
694
511
|
// Show the artifact
|
|
695
512
|
this.showArtifact(params.filename);
|
|
513
|
+
// Reload all HTML artifacts since they might depend on this rewritten artifact
|
|
514
|
+
this.reloadAllHtmlArtifacts();
|
|
696
515
|
// For HTML files, wait for execution
|
|
697
|
-
let result =
|
|
516
|
+
let result = "";
|
|
698
517
|
if (this.getFileType(params.filename) === "html" && !options.skipWait) {
|
|
699
518
|
const logs = await this.waitForHtmlExecution(params.filename);
|
|
700
|
-
result += logs
|
|
519
|
+
result += `\n${logs}`;
|
|
701
520
|
}
|
|
702
521
|
return result;
|
|
703
522
|
}
|
|
@@ -740,6 +559,8 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
740
559
|
}
|
|
741
560
|
this.onArtifactsChange?.();
|
|
742
561
|
this.requestUpdate();
|
|
562
|
+
// Reload all HTML artifacts since they might have depended on this deleted artifact
|
|
563
|
+
this.reloadAllHtmlArtifacts();
|
|
743
564
|
return `Deleted file ${params.filename}`;
|
|
744
565
|
}
|
|
745
566
|
getLogs(params) {
|
|
@@ -774,6 +595,7 @@ CRITICAL REMINDER FOR ALL ARTIFACTS:
|
|
|
774
595
|
return html `
|
|
775
596
|
<button
|
|
776
597
|
class="px-3 py-2 whitespace-nowrap border-b-2 ${activeClass}"
|
|
598
|
+
data-filename="${a.filename}"
|
|
777
599
|
@click=${() => this.showArtifact(a.filename)}
|
|
778
600
|
>
|
|
779
601
|
<span class="font-mono text-xs">${a.filename}</span>
|
|
@@ -810,7 +632,7 @@ __decorate([
|
|
|
810
632
|
], ArtifactsPanel.prototype, "_activeFilename", void 0);
|
|
811
633
|
__decorate([
|
|
812
634
|
property({ attribute: false })
|
|
813
|
-
], ArtifactsPanel.prototype, "
|
|
635
|
+
], ArtifactsPanel.prototype, "agent", void 0);
|
|
814
636
|
__decorate([
|
|
815
637
|
property({ attribute: false })
|
|
816
638
|
], ArtifactsPanel.prototype, "sandboxUrlProvider", void 0);
|