@draht/web-ui 2026.3.2-2
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/CHANGELOG.md +276 -0
- package/README.md +601 -0
- package/dist/ChatPanel.d.ts +28 -0
- package/dist/ChatPanel.d.ts.map +1 -0
- package/dist/ChatPanel.js +193 -0
- package/dist/ChatPanel.js.map +1 -0
- package/dist/app.css +2 -0
- package/dist/components/AgentInterface.d.ts +39 -0
- package/dist/components/AgentInterface.d.ts.map +1 -0
- package/dist/components/AgentInterface.js +384 -0
- package/dist/components/AgentInterface.js.map +1 -0
- package/dist/components/AttachmentTile.d.ts +12 -0
- package/dist/components/AttachmentTile.d.ts.map +1 -0
- package/dist/components/AttachmentTile.js +110 -0
- package/dist/components/AttachmentTile.js.map +1 -0
- package/dist/components/ConsoleBlock.d.ts +12 -0
- package/dist/components/ConsoleBlock.d.ts.map +1 -0
- package/dist/components/ConsoleBlock.js +81 -0
- package/dist/components/ConsoleBlock.js.map +1 -0
- package/dist/components/CustomProviderCard.d.ts +17 -0
- package/dist/components/CustomProviderCard.d.ts.map +1 -0
- package/dist/components/CustomProviderCard.js +112 -0
- package/dist/components/CustomProviderCard.js.map +1 -0
- package/dist/components/ExpandableSection.d.ts +15 -0
- package/dist/components/ExpandableSection.d.ts.map +1 -0
- package/dist/components/ExpandableSection.js +61 -0
- package/dist/components/ExpandableSection.js.map +1 -0
- package/dist/components/Input.d.ts +26 -0
- package/dist/components/Input.d.ts.map +1 -0
- package/dist/components/Input.js +57 -0
- package/dist/components/Input.js.map +1 -0
- package/dist/components/MessageEditor.d.ts +44 -0
- package/dist/components/MessageEditor.d.ts.map +1 -0
- package/dist/components/MessageEditor.js +418 -0
- package/dist/components/MessageEditor.js.map +1 -0
- package/dist/components/MessageList.d.ts +14 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/MessageList.js +104 -0
- package/dist/components/MessageList.js.map +1 -0
- package/dist/components/Messages.d.ts +95 -0
- package/dist/components/Messages.d.ts.map +1 -0
- package/dist/components/Messages.js +363 -0
- package/dist/components/Messages.js.map +1 -0
- package/dist/components/ProviderKeyInput.d.ts +16 -0
- package/dist/components/ProviderKeyInput.d.ts.map +1 -0
- package/dist/components/ProviderKeyInput.js +168 -0
- package/dist/components/ProviderKeyInput.js.map +1 -0
- package/dist/components/SandboxedIframe.d.ts +85 -0
- package/dist/components/SandboxedIframe.d.ts.map +1 -0
- package/dist/components/SandboxedIframe.js +518 -0
- package/dist/components/SandboxedIframe.js.map +1 -0
- package/dist/components/StreamingMessageContainer.d.ts +19 -0
- package/dist/components/StreamingMessageContainer.d.ts.map +1 -0
- package/dist/components/StreamingMessageContainer.js +117 -0
- package/dist/components/StreamingMessageContainer.js.map +1 -0
- package/dist/components/ThinkingBlock.d.ts +11 -0
- package/dist/components/ThinkingBlock.d.ts.map +1 -0
- package/dist/components/ThinkingBlock.js +56 -0
- package/dist/components/ThinkingBlock.js.map +1 -0
- 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 +192 -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 +65 -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 +159 -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 +95 -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 +166 -0
- package/dist/components/sandbox/RuntimeMessageRouter.js.map +1 -0
- package/dist/components/sandbox/SandboxRuntimeProvider.d.ts +48 -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 +15 -0
- package/dist/dialogs/ApiKeyPromptDialog.d.ts.map +1 -0
- package/dist/dialogs/ApiKeyPromptDialog.js +77 -0
- package/dist/dialogs/ApiKeyPromptDialog.js.map +1 -0
- package/dist/dialogs/AttachmentOverlay.d.ts +32 -0
- package/dist/dialogs/AttachmentOverlay.d.ts.map +1 -0
- package/dist/dialogs/AttachmentOverlay.js +576 -0
- package/dist/dialogs/AttachmentOverlay.js.map +1 -0
- package/dist/dialogs/CustomProviderDialog.d.ts +25 -0
- package/dist/dialogs/CustomProviderDialog.d.ts.map +1 -0
- package/dist/dialogs/CustomProviderDialog.js +270 -0
- package/dist/dialogs/CustomProviderDialog.js.map +1 -0
- package/dist/dialogs/ModelSelector.d.ts +27 -0
- package/dist/dialogs/ModelSelector.d.ts.map +1 -0
- package/dist/dialogs/ModelSelector.js +320 -0
- package/dist/dialogs/ModelSelector.js.map +1 -0
- 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/ProvidersModelsTab.d.ts +20 -0
- package/dist/dialogs/ProvidersModelsTab.d.ts.map +1 -0
- package/dist/dialogs/ProvidersModelsTab.js +188 -0
- package/dist/dialogs/ProvidersModelsTab.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 +30 -0
- package/dist/dialogs/SettingsDialog.d.ts.map +1 -0
- package/dist/dialogs/SettingsDialog.js +222 -0
- package/dist/dialogs/SettingsDialog.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- 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 +33 -0
- package/dist/storage/app-storage.d.ts.map +1 -0
- package/dist/storage/app-storage.js +43 -0
- package/dist/storage/app-storage.js.map +1 -0
- 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 +167 -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 +24 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/storage/stores/custom-providers-store.d.ts +25 -0
- package/dist/storage/stores/custom-providers-store.d.ts.map +1 -0
- package/dist/storage/stores/custom-providers-store.js +35 -0
- package/dist/storage/stores/custom-providers-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 +32 -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 +176 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/tools/artifacts/ArtifactElement.d.ts +9 -0
- package/dist/tools/artifacts/ArtifactElement.d.ts.map +1 -0
- package/dist/tools/artifacts/ArtifactElement.js +8 -0
- package/dist/tools/artifacts/ArtifactElement.js.map +1 -0
- 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 +23 -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 +92 -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 +205 -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 +213 -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 +114 -0
- package/dist/tools/artifacts/GenericArtifact.js.map +1 -0
- package/dist/tools/artifacts/HtmlArtifact.d.ts +27 -0
- package/dist/tools/artifacts/HtmlArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/HtmlArtifact.js +187 -0
- package/dist/tools/artifacts/HtmlArtifact.js.map +1 -0
- 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 +117 -0
- package/dist/tools/artifacts/ImageArtifact.js.map +1 -0
- package/dist/tools/artifacts/MarkdownArtifact.d.ts +19 -0
- package/dist/tools/artifacts/MarkdownArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/MarkdownArtifact.js +79 -0
- package/dist/tools/artifacts/MarkdownArtifact.js.map +1 -0
- 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 +181 -0
- package/dist/tools/artifacts/PdfArtifact.js.map +1 -0
- package/dist/tools/artifacts/SvgArtifact.d.ts +18 -0
- package/dist/tools/artifacts/SvgArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/SvgArtifact.js +75 -0
- package/dist/tools/artifacts/SvgArtifact.js.map +1 -0
- package/dist/tools/artifacts/TextArtifact.d.ts +19 -0
- package/dist/tools/artifacts/TextArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/TextArtifact.js +141 -0
- package/dist/tools/artifacts/TextArtifact.js.map +1 -0
- 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 +273 -0
- package/dist/tools/artifacts/artifacts-tool-renderer.js.map +1 -0
- package/dist/tools/artifacts/artifacts.d.ts +63 -0
- package/dist/tools/artifacts/artifacts.d.ts.map +1 -0
- package/dist/tools/artifacts/artifacts.js +664 -0
- package/dist/tools/artifacts/artifacts.js.map +1 -0
- package/dist/tools/artifacts/index.d.ts +8 -0
- package/dist/tools/artifacts/index.d.ts.map +1 -0
- package/dist/tools/artifacts/index.js +8 -0
- package/dist/tools/artifacts/index.js.map +1 -0
- 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 +216 -0
- package/dist/tools/extract-document.js.map +1 -0
- package/dist/tools/index.d.ts +16 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/javascript-repl.d.ts +44 -0
- package/dist/tools/javascript-repl.d.ts.map +1 -0
- package/dist/tools/javascript-repl.js +224 -0
- package/dist/tools/javascript-repl.js.map +1 -0
- package/dist/tools/renderer-registry.d.ts +23 -0
- package/dist/tools/renderer-registry.d.ts.map +1 -0
- package/dist/tools/renderer-registry.js +107 -0
- package/dist/tools/renderer-registry.js.map +1 -0
- package/dist/tools/renderers/BashRenderer.d.ts +10 -0
- package/dist/tools/renderers/BashRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/BashRenderer.js +42 -0
- package/dist/tools/renderers/BashRenderer.js.map +1 -0
- package/dist/tools/renderers/CalculateRenderer.d.ts +10 -0
- package/dist/tools/renderers/CalculateRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/CalculateRenderer.js +45 -0
- package/dist/tools/renderers/CalculateRenderer.js.map +1 -0
- package/dist/tools/renderers/DefaultRenderer.d.ts +6 -0
- package/dist/tools/renderers/DefaultRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/DefaultRenderer.js +94 -0
- package/dist/tools/renderers/DefaultRenderer.js.map +1 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.d.ts +10 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.js +72 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.js.map +1 -0
- package/dist/tools/types.d.ts +10 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/utils/attachment-utils.d.ts +19 -0
- package/dist/utils/attachment-utils.d.ts.map +1 -0
- package/dist/utils/attachment-utils.js +415 -0
- package/dist/utils/attachment-utils.js.map +1 -0
- package/dist/utils/auth-token.d.ts +3 -0
- package/dist/utils/auth-token.d.ts.map +1 -0
- package/dist/utils/auth-token.js +19 -0
- package/dist/utils/auth-token.js.map +1 -0
- package/dist/utils/format.d.ts +6 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +47 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/i18n.d.ts +636 -0
- package/dist/utils/i18n.d.ts.map +1 -0
- package/dist/utils/i18n.js +418 -0
- package/dist/utils/i18n.js.map +1 -0
- package/dist/utils/model-discovery.d.ts +38 -0
- package/dist/utils/model-discovery.d.ts.map +1 -0
- package/dist/utils/model-discovery.js +243 -0
- package/dist/utils/model-discovery.js.map +1 -0
- package/dist/utils/proxy-utils.d.ts +45 -0
- package/dist/utils/proxy-utils.d.ts.map +1 -0
- package/dist/utils/proxy-utils.js +116 -0
- package/dist/utils/proxy-utils.js.map +1 -0
- package/dist/utils/test-sessions.d.ts +359 -0
- package/dist/utils/test-sessions.d.ts.map +1 -0
- package/dist/utils/test-sessions.js +2325 -0
- package/dist/utils/test-sessions.js.map +1 -0
- package/example/README.md +61 -0
- package/example/index.html +13 -0
- package/example/package.json +25 -0
- package/example/src/app.css +1 -0
- package/example/src/custom-messages.ts +99 -0
- package/example/src/env.d.ts +1 -0
- package/example/src/main.ts +421 -0
- package/example/tsconfig.json +23 -0
- package/example/vite.config.ts +6 -0
- package/package.json +53 -0
- package/scripts/count-prompt-tokens.ts +88 -0
- package/src/ChatPanel.ts +207 -0
- package/src/app.css +68 -0
- package/src/components/AgentInterface.ts +388 -0
- package/src/components/AttachmentTile.ts +107 -0
- package/src/components/ConsoleBlock.ts +72 -0
- package/src/components/CustomProviderCard.ts +100 -0
- package/src/components/ExpandableSection.ts +46 -0
- package/src/components/Input.ts +113 -0
- package/src/components/MessageEditor.ts +400 -0
- package/src/components/MessageList.ts +95 -0
- package/src/components/Messages.ts +383 -0
- package/src/components/ProviderKeyInput.ts +153 -0
- package/src/components/SandboxedIframe.ts +626 -0
- package/src/components/StreamingMessageContainer.ts +103 -0
- package/src/components/ThinkingBlock.ts +43 -0
- 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 +186 -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 +52 -0
- package/src/dialogs/ApiKeyPromptDialog.ts +75 -0
- package/src/dialogs/AttachmentOverlay.ts +636 -0
- package/src/dialogs/CustomProviderDialog.ts +274 -0
- package/src/dialogs/ModelSelector.ts +313 -0
- package/src/dialogs/PersistentStorageDialog.ts +144 -0
- package/src/dialogs/ProvidersModelsTab.ts +212 -0
- package/src/dialogs/SessionListDialog.ts +150 -0
- package/src/dialogs/SettingsDialog.ts +214 -0
- package/src/index.ts +119 -0
- package/src/prompts/prompts.ts +282 -0
- package/src/storage/app-storage.ts +60 -0
- package/src/storage/backends/indexeddb-storage-backend.ts +193 -0
- package/src/storage/store.ts +33 -0
- package/src/storage/stores/custom-providers-store.ts +62 -0
- package/src/storage/stores/provider-keys-store.ts +33 -0
- package/src/storage/stores/sessions-store.ts +136 -0
- package/src/storage/stores/settings-store.ts +34 -0
- package/src/storage/types.ts +206 -0
- package/src/tools/artifacts/ArtifactElement.ts +14 -0
- package/src/tools/artifacts/ArtifactPill.ts +26 -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 +195 -0
- package/src/tools/artifacts/ImageArtifact.ts +116 -0
- package/src/tools/artifacts/MarkdownArtifact.ts +82 -0
- package/src/tools/artifacts/PdfArtifact.ts +201 -0
- package/src/tools/artifacts/SvgArtifact.ts +78 -0
- package/src/tools/artifacts/TextArtifact.ts +148 -0
- package/src/tools/artifacts/artifacts-tool-renderer.ts +310 -0
- package/src/tools/artifacts/artifacts.ts +713 -0
- package/src/tools/artifacts/index.ts +7 -0
- package/src/tools/extract-document.ts +275 -0
- package/src/tools/index.ts +46 -0
- package/src/tools/javascript-repl.ts +293 -0
- package/src/tools/renderer-registry.ts +130 -0
- package/src/tools/renderers/BashRenderer.ts +52 -0
- package/src/tools/renderers/CalculateRenderer.ts +58 -0
- package/src/tools/renderers/DefaultRenderer.ts +103 -0
- package/src/tools/renderers/GetCurrentTimeRenderer.ts +92 -0
- package/src/tools/types.ts +15 -0
- package/src/utils/attachment-utils.ts +472 -0
- package/src/utils/auth-token.ts +22 -0
- package/src/utils/format.ts +42 -0
- package/src/utils/i18n.ts +653 -0
- package/src/utils/model-discovery.ts +277 -0
- package/src/utils/proxy-utils.ts +134 -0
- package/src/utils/test-sessions.ts +2357 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console Runtime Provider
|
|
3
|
+
*
|
|
4
|
+
* REQUIRED provider that should always be included first.
|
|
5
|
+
* Provides console capture, error handling, and execution lifecycle management.
|
|
6
|
+
* Collects console output for retrieval by caller.
|
|
7
|
+
*/
|
|
8
|
+
export class ConsoleRuntimeProvider {
|
|
9
|
+
logs = [];
|
|
10
|
+
completionError = null;
|
|
11
|
+
completed = false;
|
|
12
|
+
getData() {
|
|
13
|
+
// No data needed
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
getDescription() {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
getRuntime() {
|
|
20
|
+
return (_sandboxId) => {
|
|
21
|
+
// Store truly original console methods on first wrap only
|
|
22
|
+
// This prevents accumulation of wrapper functions across multiple executions
|
|
23
|
+
if (!window.__originalConsole) {
|
|
24
|
+
window.__originalConsole = {
|
|
25
|
+
log: console.log.bind(console),
|
|
26
|
+
error: console.error.bind(console),
|
|
27
|
+
warn: console.warn.bind(console),
|
|
28
|
+
info: console.info.bind(console),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// Always use the truly original console, not the current (possibly wrapped) one
|
|
32
|
+
const originalConsole = window.__originalConsole;
|
|
33
|
+
// Track pending send promises to wait for them in onCompleted
|
|
34
|
+
const pendingSends = [];
|
|
35
|
+
["log", "error", "warn", "info"].forEach((method) => {
|
|
36
|
+
console[method] = (...args) => {
|
|
37
|
+
const text = args
|
|
38
|
+
.map((arg) => {
|
|
39
|
+
try {
|
|
40
|
+
return typeof arg === "object" ? JSON.stringify(arg) : String(arg);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return String(arg);
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
.join(" ");
|
|
47
|
+
// Always log locally too (using truly original console)
|
|
48
|
+
originalConsole[method].apply(console, args);
|
|
49
|
+
// Send immediately and track the promise (only in extension context)
|
|
50
|
+
if (window.sendRuntimeMessage) {
|
|
51
|
+
const sendPromise = window
|
|
52
|
+
.sendRuntimeMessage({
|
|
53
|
+
type: "console",
|
|
54
|
+
method,
|
|
55
|
+
text,
|
|
56
|
+
args,
|
|
57
|
+
})
|
|
58
|
+
.catch(() => { });
|
|
59
|
+
pendingSends.push(sendPromise);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
// Register completion callback to wait for all pending sends
|
|
64
|
+
if (window.onCompleted) {
|
|
65
|
+
window.onCompleted(async (_success) => {
|
|
66
|
+
// Wait for all pending console sends to complete
|
|
67
|
+
if (pendingSends.length > 0) {
|
|
68
|
+
await Promise.all(pendingSends);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Track errors for HTML artifacts
|
|
73
|
+
let lastError = null;
|
|
74
|
+
// Error handlers - track errors but don't log them
|
|
75
|
+
// (they'll be shown via execution-error message)
|
|
76
|
+
window.addEventListener("error", (e) => {
|
|
77
|
+
const text = `${e.error?.stack || e.message || String(e)} at line ${e.lineno || "?"}:${e.colno || "?"}`;
|
|
78
|
+
lastError = {
|
|
79
|
+
message: e.error?.message || e.message || String(e),
|
|
80
|
+
stack: e.error?.stack || text,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
window.addEventListener("unhandledrejection", (e) => {
|
|
84
|
+
const text = `Unhandled promise rejection: ${e.reason?.message || e.reason || "Unknown error"}`;
|
|
85
|
+
lastError = {
|
|
86
|
+
message: e.reason?.message || String(e.reason) || "Unhandled promise rejection",
|
|
87
|
+
stack: e.reason?.stack || text,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
// Expose complete() method for user code to call
|
|
91
|
+
let completionSent = false;
|
|
92
|
+
window.complete = async (error, returnValue) => {
|
|
93
|
+
if (completionSent)
|
|
94
|
+
return;
|
|
95
|
+
completionSent = true;
|
|
96
|
+
const finalError = error || lastError;
|
|
97
|
+
if (window.sendRuntimeMessage) {
|
|
98
|
+
if (finalError) {
|
|
99
|
+
await window.sendRuntimeMessage({
|
|
100
|
+
type: "execution-error",
|
|
101
|
+
error: finalError,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await window.sendRuntimeMessage({
|
|
106
|
+
type: "execution-complete",
|
|
107
|
+
returnValue,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async handleMessage(message, respond) {
|
|
115
|
+
if (message.type === "console") {
|
|
116
|
+
// Collect console output
|
|
117
|
+
this.logs.push({
|
|
118
|
+
type: message.method === "error"
|
|
119
|
+
? "error"
|
|
120
|
+
: message.method === "warn"
|
|
121
|
+
? "warn"
|
|
122
|
+
: message.method === "info"
|
|
123
|
+
? "info"
|
|
124
|
+
: "log",
|
|
125
|
+
text: message.text,
|
|
126
|
+
args: message.args,
|
|
127
|
+
});
|
|
128
|
+
// Acknowledge receipt
|
|
129
|
+
respond({ success: true });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get collected console logs
|
|
134
|
+
*/
|
|
135
|
+
getLogs() {
|
|
136
|
+
return this.logs;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get completion status
|
|
140
|
+
*/
|
|
141
|
+
isCompleted() {
|
|
142
|
+
return this.completed;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get completion error if any
|
|
146
|
+
*/
|
|
147
|
+
getCompletionError() {
|
|
148
|
+
return this.completionError;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Reset state for reuse
|
|
152
|
+
*/
|
|
153
|
+
reset() {
|
|
154
|
+
this.logs = [];
|
|
155
|
+
this.completionError = null;
|
|
156
|
+
this.completed = false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=ConsoleRuntimeProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConsoleRuntimeProvider.js","sourceRoot":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untimeProvider.js";
|
|
2
|
+
export interface DownloadableFile {
|
|
3
|
+
fileName: string;
|
|
4
|
+
content: string | Uint8Array;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* File Download Runtime Provider
|
|
9
|
+
*
|
|
10
|
+
* Provides returnDownloadableFile() for creating user downloads.
|
|
11
|
+
* Files returned this way are NOT accessible to the LLM later (one-time download).
|
|
12
|
+
* Works both online (sends to extension) and offline (triggers browser download directly).
|
|
13
|
+
* Collects files for retrieval by caller.
|
|
14
|
+
*/
|
|
15
|
+
export declare class FileDownloadRuntimeProvider implements SandboxRuntimeProvider {
|
|
16
|
+
private files;
|
|
17
|
+
getData(): Record<string, any>;
|
|
18
|
+
getRuntime(): (sandboxId: string) => void;
|
|
19
|
+
handleMessage(message: any, respond: (response: any) => void): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get collected files
|
|
22
|
+
*/
|
|
23
|
+
getFiles(): DownloadableFile[];
|
|
24
|
+
/**
|
|
25
|
+
* Reset state for reuse
|
|
26
|
+
*/
|
|
27
|
+
reset(): void;
|
|
28
|
+
getDescription(): string;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=FileDownloadRuntimeProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileDownloadRuntimeProvider.d.ts","sourceRoot":"","sources":["../../../src/components/sandbox/FileDownloadRuntimeProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,qBAAa,2BAA4B,YAAW,sBAAsB;IACzE,OAAO,CAAC,KAAK,CAA0B;IAEvC,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAG7B;IAED,UAAU,IAAI,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAqDxC;IAEK,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAWjF;IAED;;OAEG;IACH,QAAQ,IAAI,gBAAgB,EAAE,CAE7B;IAED;;OAEG;IACH,KAAK,IAAI,IAAI,CAEZ;IAED,cAAc,IAAI,MAAM,CAEvB;CACD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Download Runtime Provider
|
|
3
|
+
*
|
|
4
|
+
* Provides returnDownloadableFile() for creating user downloads.
|
|
5
|
+
* Files returned this way are NOT accessible to the LLM later (one-time download).
|
|
6
|
+
* Works both online (sends to extension) and offline (triggers browser download directly).
|
|
7
|
+
* Collects files for retrieval by caller.
|
|
8
|
+
*/
|
|
9
|
+
export class FileDownloadRuntimeProvider {
|
|
10
|
+
files = [];
|
|
11
|
+
getData() {
|
|
12
|
+
// No data needed
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
getRuntime() {
|
|
16
|
+
return (_sandboxId) => {
|
|
17
|
+
window.returnDownloadableFile = async (fileName, content, mimeType) => {
|
|
18
|
+
let finalContent, finalMimeType;
|
|
19
|
+
if (content instanceof Blob) {
|
|
20
|
+
const arrayBuffer = await content.arrayBuffer();
|
|
21
|
+
finalContent = new Uint8Array(arrayBuffer);
|
|
22
|
+
finalMimeType = mimeType || content.type || "application/octet-stream";
|
|
23
|
+
if (!mimeType && !content.type) {
|
|
24
|
+
throw new Error("returnDownloadableFile: MIME type is required for Blob content. Please provide a mimeType parameter (e.g., 'image/png').");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (content instanceof Uint8Array) {
|
|
28
|
+
finalContent = content;
|
|
29
|
+
if (!mimeType) {
|
|
30
|
+
throw new Error("returnDownloadableFile: MIME type is required for Uint8Array content. Please provide a mimeType parameter (e.g., 'image/png').");
|
|
31
|
+
}
|
|
32
|
+
finalMimeType = mimeType;
|
|
33
|
+
}
|
|
34
|
+
else if (typeof content === "string") {
|
|
35
|
+
finalContent = content;
|
|
36
|
+
finalMimeType = mimeType || "text/plain";
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
finalContent = JSON.stringify(content, null, 2);
|
|
40
|
+
finalMimeType = mimeType || "application/json";
|
|
41
|
+
}
|
|
42
|
+
// Send to extension if in extension context (online mode)
|
|
43
|
+
if (window.sendRuntimeMessage) {
|
|
44
|
+
const response = await window.sendRuntimeMessage({
|
|
45
|
+
type: "file-returned",
|
|
46
|
+
fileName,
|
|
47
|
+
content: finalContent,
|
|
48
|
+
mimeType: finalMimeType,
|
|
49
|
+
});
|
|
50
|
+
if (response.error)
|
|
51
|
+
throw new Error(response.error);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Offline mode: trigger browser download directly
|
|
55
|
+
const blob = new Blob([finalContent instanceof Uint8Array ? finalContent : finalContent], {
|
|
56
|
+
type: finalMimeType,
|
|
57
|
+
});
|
|
58
|
+
const url = URL.createObjectURL(blob);
|
|
59
|
+
const a = document.createElement("a");
|
|
60
|
+
a.href = url;
|
|
61
|
+
a.download = fileName;
|
|
62
|
+
a.click();
|
|
63
|
+
URL.revokeObjectURL(url);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async handleMessage(message, respond) {
|
|
69
|
+
if (message.type === "file-returned") {
|
|
70
|
+
// Collect file for caller
|
|
71
|
+
this.files.push({
|
|
72
|
+
fileName: message.fileName,
|
|
73
|
+
content: message.content,
|
|
74
|
+
mimeType: message.mimeType,
|
|
75
|
+
});
|
|
76
|
+
respond({ success: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get collected files
|
|
81
|
+
*/
|
|
82
|
+
getFiles() {
|
|
83
|
+
return this.files;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Reset state for reuse
|
|
87
|
+
*/
|
|
88
|
+
reset() {
|
|
89
|
+
this.files = [];
|
|
90
|
+
}
|
|
91
|
+
getDescription() {
|
|
92
|
+
return "returnDownloadableFile(filename, content, mimeType?) - Create downloadable file for user (one-time download, not accessible later)";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=FileDownloadRuntimeProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileDownloadRuntimeProvider.js","sourceRoot":"","sources":["../../../src/components/sandbox/FileDownloadRuntimeProvider.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA2B;IAC/B,KAAK,GAAuB,EAAE,CAAC;IAEvC,OAAO,GAAwB;QAC9B,iBAAiB;QACjB,OAAO,EAAE,CAAC;IAAA,CACV;IAED,UAAU,GAAgC;QACzC,OAAO,CAAC,UAAkB,EAAE,EAAE,CAAC;YAC7B,MAAc,CAAC,sBAAsB,GAAG,KAAK,EAAE,QAAgB,EAAE,OAAY,EAAE,QAAiB,EAAE,EAAE,CAAC;gBACrG,IAAI,YAAiB,EAAE,aAAqB,CAAC;gBAE7C,IAAI,OAAO,YAAY,IAAI,EAAE,CAAC;oBAC7B,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;oBAChD,YAAY,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;oBAC3C,aAAa,GAAG,QAAQ,IAAI,OAAO,CAAC,IAAI,IAAI,0BAA0B,CAAC;oBACvE,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;wBAChC,MAAM,IAAI,KAAK,CACd,0HAA0H,CAC1H,CAAC;oBACH,CAAC;gBACF,CAAC;qBAAM,IAAI,OAAO,YAAY,UAAU,EAAE,CAAC;oBAC1C,YA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CAAC,CAAC,KAAK,EAAE,CAAC;oBACV,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;gBAC1B,CAAC;YAAA,CACD,CAAC;QAAA,CACF,CAAC;IAAA,CACF;IAED,KAAK,CAAC,aAAa,CAAC,OAAY,EAAE,OAAgC,EAAiB;QAClF,IAAI,OAAO,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YACtC,0BAA0B;YAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACf,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC1B,CAAC,CAAC;YAEH,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC;IAAA,CACD;IAED;;OAEG;IACH,QAAQ,GAAuB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC;IAAA,CAClB;IAED;;OAEG;IACH,KAAK,GAAS;QACb,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAAA,CAChB;IAED,cAAc,GAAW;QACxB,OAAO,oIAAoI,CAAC;IAAA,CAC5I;CACD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates sendRuntimeMessage() function for injection into execution contexts.
|
|
3
|
+
* Provides unified messaging API that works in both sandbox iframe and user script contexts.
|
|
4
|
+
*/
|
|
5
|
+
export type MessageType = "request-response" | "fire-and-forget";
|
|
6
|
+
export interface RuntimeMessageBridgeOptions {
|
|
7
|
+
context: "sandbox-iframe" | "user-script";
|
|
8
|
+
sandboxId: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class RuntimeMessageBridge {
|
|
11
|
+
/**
|
|
12
|
+
* Generate sendRuntimeMessage() function as injectable string.
|
|
13
|
+
* Returns the function source code to be injected into target context.
|
|
14
|
+
*/
|
|
15
|
+
static generateBridgeCode(options: RuntimeMessageBridgeOptions): string;
|
|
16
|
+
private static generateSandboxBridge;
|
|
17
|
+
private static generateUserScriptBridge;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=RuntimeMessageBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeMessageBridge.d.ts","sourceRoot":"","sources":["../../../src/components/sandbox/RuntimeMessageBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;AAEjE,MAAM,WAAW,2BAA2B;IAC3C,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;CAClB;AAGD,qBAAa,oBAAoB;IAChC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,2BAA2B,GAAG,MAAM,CAMtE;IAED,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAwCpC,OAAO,CAAC,MAAM,CAAC,wBAAwB;CAevC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates sendRuntimeMessage() function for injection into execution contexts.
|
|
3
|
+
* Provides unified messaging API that works in both sandbox iframe and user script contexts.
|
|
4
|
+
*/
|
|
5
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: fine
|
|
6
|
+
export class RuntimeMessageBridge {
|
|
7
|
+
/**
|
|
8
|
+
* Generate sendRuntimeMessage() function as injectable string.
|
|
9
|
+
* Returns the function source code to be injected into target context.
|
|
10
|
+
*/
|
|
11
|
+
static generateBridgeCode(options) {
|
|
12
|
+
if (options.context === "sandbox-iframe") {
|
|
13
|
+
return RuntimeMessageBridge.generateSandboxBridge(options.sandboxId);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return RuntimeMessageBridge.generateUserScriptBridge(options.sandboxId);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static generateSandboxBridge(sandboxId) {
|
|
20
|
+
// Returns stringified function that uses window.parent.postMessage
|
|
21
|
+
return `
|
|
22
|
+
window.__completionCallbacks = [];
|
|
23
|
+
window.sendRuntimeMessage = async (message) => {
|
|
24
|
+
const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
|
|
25
|
+
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
const handler = (e) => {
|
|
28
|
+
if (e.data.type === 'runtime-response' && e.data.messageId === messageId) {
|
|
29
|
+
window.removeEventListener('message', handler);
|
|
30
|
+
if (e.data.success) {
|
|
31
|
+
resolve(e.data);
|
|
32
|
+
} else {
|
|
33
|
+
reject(new Error(e.data.error || 'Operation failed'));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
window.addEventListener('message', handler);
|
|
39
|
+
|
|
40
|
+
window.parent.postMessage({
|
|
41
|
+
...message,
|
|
42
|
+
sandboxId: ${JSON.stringify(sandboxId)},
|
|
43
|
+
messageId: messageId
|
|
44
|
+
}, '*');
|
|
45
|
+
|
|
46
|
+
// Timeout after 30s
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
window.removeEventListener('message', handler);
|
|
49
|
+
reject(new Error('Runtime message timeout'));
|
|
50
|
+
}, 30000);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
window.onCompleted = (callback) => {
|
|
54
|
+
window.__completionCallbacks.push(callback);
|
|
55
|
+
};
|
|
56
|
+
`.trim();
|
|
57
|
+
}
|
|
58
|
+
static generateUserScriptBridge(sandboxId) {
|
|
59
|
+
// Returns stringified function that uses chrome.runtime.sendMessage
|
|
60
|
+
return `
|
|
61
|
+
window.__completionCallbacks = [];
|
|
62
|
+
window.sendRuntimeMessage = async (message) => {
|
|
63
|
+
return await chrome.runtime.sendMessage({
|
|
64
|
+
...message,
|
|
65
|
+
sandboxId: ${JSON.stringify(sandboxId)}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
window.onCompleted = (callback) => {
|
|
69
|
+
window.__completionCallbacks.push(callback);
|
|
70
|
+
};
|
|
71
|
+
`.trim();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=RuntimeMessageBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeMessageBridge.js","sourceRoot":"","sources":["../../../src/components/sandbox/RuntimeMessageBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,uDAAuD;AACvD,MAAM,OAAO,oBAAoB;IAChC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAoC,EAAU;QACvE,IAAI,OAAO,CAAC,OAAO,KAAK,gBAAgB,EAAE,CAAC;YAC1C,OAAO,oBAAoB,CAAC,qBAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC;aAAM,CAAC;YACP,OAAO,oBAAoB,CAAC,wBAAwB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACzE,CAAC;IAAA,CACD;IAEO,MAAM,CAAC,qBAAqB,CAAC,SAAiB,EAAU;QAC/D,mEAAmE;QACnE,OAAO;;;;;;;;;;;;;;;;;;;;;yBAqBgB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;;;;;;;;;;;;;;CAcjD,CAAC,IAAI,EAAE,CAAC;IAAA,CACP;IAEO,MAAM,CAAC,wBAAwB,CAAC,SAAiB,EAAU;QAClE,oEAAoE;QACpE,OAAO;;;;;qBAKY,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;;;;;;CAM7C,CAAC,IAAI,EAAE,CAAC;IAAA,CACP;CACD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SandboxRuntimeProvider } from "./SandboxRuntimeProvider.js";
|
|
2
|
+
/**
|
|
3
|
+
* Message consumer interface - components that want to receive messages from sandboxes
|
|
4
|
+
*/
|
|
5
|
+
export interface MessageConsumer {
|
|
6
|
+
/**
|
|
7
|
+
* Handle a message from a sandbox.
|
|
8
|
+
* All consumers receive all messages - decide internally what to handle.
|
|
9
|
+
*/
|
|
10
|
+
handleMessage(message: any): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Centralized message router for all runtime communication.
|
|
14
|
+
*
|
|
15
|
+
* This singleton replaces all individual window.addEventListener("message") calls
|
|
16
|
+
* with a single global listener that routes messages to the appropriate handlers.
|
|
17
|
+
* Also handles user script messages from chrome.runtime.onUserScriptMessage.
|
|
18
|
+
*
|
|
19
|
+
* Benefits:
|
|
20
|
+
* - Single global listener instead of multiple independent listeners
|
|
21
|
+
* - Automatic cleanup when sandboxes are destroyed
|
|
22
|
+
* - Support for bidirectional communication (providers) and broadcasting (consumers)
|
|
23
|
+
* - Works with both sandbox iframes and user scripts
|
|
24
|
+
* - Clear lifecycle management
|
|
25
|
+
*/
|
|
26
|
+
export declare class RuntimeMessageRouter {
|
|
27
|
+
private sandboxes;
|
|
28
|
+
private messageListener;
|
|
29
|
+
private userScriptMessageListener;
|
|
30
|
+
/**
|
|
31
|
+
* Register a new sandbox with its runtime providers.
|
|
32
|
+
* Call this BEFORE creating the iframe (for sandbox contexts) or executing user script.
|
|
33
|
+
*/
|
|
34
|
+
registerSandbox(sandboxId: string, providers: SandboxRuntimeProvider[], consumers: MessageConsumer[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Update the iframe reference for a sandbox.
|
|
37
|
+
* Call this AFTER creating the iframe.
|
|
38
|
+
* This is needed so providers can send responses back to the sandbox.
|
|
39
|
+
*/
|
|
40
|
+
setSandboxIframe(sandboxId: string, iframe: HTMLIFrameElement): void;
|
|
41
|
+
/**
|
|
42
|
+
* Unregister a sandbox and remove all its consumers.
|
|
43
|
+
* Call this when the sandbox is destroyed.
|
|
44
|
+
*/
|
|
45
|
+
unregisterSandbox(sandboxId: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Add a message consumer for a sandbox.
|
|
48
|
+
* Consumers receive broadcast messages (console, execution-complete, etc.)
|
|
49
|
+
*/
|
|
50
|
+
addConsumer(sandboxId: string, consumer: MessageConsumer): void;
|
|
51
|
+
/**
|
|
52
|
+
* Remove a message consumer from a sandbox.
|
|
53
|
+
*/
|
|
54
|
+
removeConsumer(sandboxId: string, consumer: MessageConsumer): void;
|
|
55
|
+
/**
|
|
56
|
+
* Setup the global message listeners (called automatically)
|
|
57
|
+
*/
|
|
58
|
+
private setupListener;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Global singleton instance.
|
|
62
|
+
* Import this from wherever you need to interact with the message router.
|
|
63
|
+
*/
|
|
64
|
+
export declare const RUNTIME_MESSAGE_ROUTER: RuntimeMessageRouter;
|
|
65
|
+
//# sourceMappingURL=RuntimeMessageRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeMessageRouter.d.ts","sourceRoot":"","sources":["../../../src/components/sandbox/RuntimeMessageRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAK1E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;;OAGG;IACH,aAAa,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAYD;;;;;;;;;;;;;GAaG;AACH,qBAAa,oBAAoB;IAChC,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,yBAAyB,CAElB;IAEf;;;OAGG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,sBAAsB,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,IAAI,CAU1G;IAED;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAKnE;IAED;;;OAGG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAiBzC;IAED;;;OAGG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI,CAK9D;IAED;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI,CAKjE;IAED;;OAEG;IACH,OAAO,CAAC,aAAa;CAuFrB;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,sBAA6B,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized message router for all runtime communication.
|
|
3
|
+
*
|
|
4
|
+
* This singleton replaces all individual window.addEventListener("message") calls
|
|
5
|
+
* with a single global listener that routes messages to the appropriate handlers.
|
|
6
|
+
* Also handles user script messages from chrome.runtime.onUserScriptMessage.
|
|
7
|
+
*
|
|
8
|
+
* Benefits:
|
|
9
|
+
* - Single global listener instead of multiple independent listeners
|
|
10
|
+
* - Automatic cleanup when sandboxes are destroyed
|
|
11
|
+
* - Support for bidirectional communication (providers) and broadcasting (consumers)
|
|
12
|
+
* - Works with both sandbox iframes and user scripts
|
|
13
|
+
* - Clear lifecycle management
|
|
14
|
+
*/
|
|
15
|
+
export class RuntimeMessageRouter {
|
|
16
|
+
sandboxes = new Map();
|
|
17
|
+
messageListener = null;
|
|
18
|
+
userScriptMessageListener = null;
|
|
19
|
+
/**
|
|
20
|
+
* Register a new sandbox with its runtime providers.
|
|
21
|
+
* Call this BEFORE creating the iframe (for sandbox contexts) or executing user script.
|
|
22
|
+
*/
|
|
23
|
+
registerSandbox(sandboxId, providers, consumers) {
|
|
24
|
+
this.sandboxes.set(sandboxId, {
|
|
25
|
+
sandboxId,
|
|
26
|
+
iframe: null, // Will be set via setSandboxIframe() for sandbox contexts
|
|
27
|
+
providers,
|
|
28
|
+
consumers: new Set(consumers),
|
|
29
|
+
});
|
|
30
|
+
// Setup global listener if not already done
|
|
31
|
+
this.setupListener();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Update the iframe reference for a sandbox.
|
|
35
|
+
* Call this AFTER creating the iframe.
|
|
36
|
+
* This is needed so providers can send responses back to the sandbox.
|
|
37
|
+
*/
|
|
38
|
+
setSandboxIframe(sandboxId, iframe) {
|
|
39
|
+
const context = this.sandboxes.get(sandboxId);
|
|
40
|
+
if (context) {
|
|
41
|
+
context.iframe = iframe;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unregister a sandbox and remove all its consumers.
|
|
46
|
+
* Call this when the sandbox is destroyed.
|
|
47
|
+
*/
|
|
48
|
+
unregisterSandbox(sandboxId) {
|
|
49
|
+
this.sandboxes.delete(sandboxId);
|
|
50
|
+
// If no more sandboxes, remove global listeners
|
|
51
|
+
if (this.sandboxes.size === 0) {
|
|
52
|
+
// Remove iframe listener
|
|
53
|
+
if (this.messageListener) {
|
|
54
|
+
window.removeEventListener("message", this.messageListener);
|
|
55
|
+
this.messageListener = null;
|
|
56
|
+
}
|
|
57
|
+
// Remove user script listener
|
|
58
|
+
if (this.userScriptMessageListener && typeof chrome !== "undefined" && chrome.runtime?.onUserScriptMessage) {
|
|
59
|
+
chrome.runtime.onUserScriptMessage.removeListener(this.userScriptMessageListener);
|
|
60
|
+
this.userScriptMessageListener = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Add a message consumer for a sandbox.
|
|
66
|
+
* Consumers receive broadcast messages (console, execution-complete, etc.)
|
|
67
|
+
*/
|
|
68
|
+
addConsumer(sandboxId, consumer) {
|
|
69
|
+
const context = this.sandboxes.get(sandboxId);
|
|
70
|
+
if (context) {
|
|
71
|
+
context.consumers.add(consumer);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Remove a message consumer from a sandbox.
|
|
76
|
+
*/
|
|
77
|
+
removeConsumer(sandboxId, consumer) {
|
|
78
|
+
const context = this.sandboxes.get(sandboxId);
|
|
79
|
+
if (context) {
|
|
80
|
+
context.consumers.delete(consumer);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Setup the global message listeners (called automatically)
|
|
85
|
+
*/
|
|
86
|
+
setupListener() {
|
|
87
|
+
// Setup sandbox iframe listener
|
|
88
|
+
if (!this.messageListener) {
|
|
89
|
+
this.messageListener = async (e) => {
|
|
90
|
+
const { sandboxId, messageId } = e.data;
|
|
91
|
+
if (!sandboxId)
|
|
92
|
+
return;
|
|
93
|
+
const context = this.sandboxes.get(sandboxId);
|
|
94
|
+
if (!context) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// Create respond() function for bidirectional communication
|
|
98
|
+
const respond = (response) => {
|
|
99
|
+
context.iframe?.contentWindow?.postMessage({
|
|
100
|
+
type: "runtime-response",
|
|
101
|
+
messageId,
|
|
102
|
+
sandboxId,
|
|
103
|
+
...response,
|
|
104
|
+
}, "*");
|
|
105
|
+
};
|
|
106
|
+
// 1. Try provider handlers first (for bidirectional comm)
|
|
107
|
+
for (const provider of context.providers) {
|
|
108
|
+
if (provider.handleMessage) {
|
|
109
|
+
await provider.handleMessage(e.data, respond);
|
|
110
|
+
// Don't stop - let consumers also handle the message
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// 2. Broadcast to consumers (one-way messages or lifecycle events)
|
|
114
|
+
for (const consumer of context.consumers) {
|
|
115
|
+
await consumer.handleMessage(e.data);
|
|
116
|
+
// Don't stop - let all consumers see the message
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
window.addEventListener("message", this.messageListener);
|
|
120
|
+
}
|
|
121
|
+
// Setup user script message listener
|
|
122
|
+
if (!this.userScriptMessageListener) {
|
|
123
|
+
// Guard: check if we're in extension context
|
|
124
|
+
if (typeof chrome === "undefined" || !chrome.runtime?.onUserScriptMessage) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.userScriptMessageListener = (message, _sender, sendResponse) => {
|
|
128
|
+
const { sandboxId } = message;
|
|
129
|
+
if (!sandboxId)
|
|
130
|
+
return false;
|
|
131
|
+
const context = this.sandboxes.get(sandboxId);
|
|
132
|
+
if (!context)
|
|
133
|
+
return false;
|
|
134
|
+
const respond = (response) => {
|
|
135
|
+
sendResponse({
|
|
136
|
+
...response,
|
|
137
|
+
sandboxId,
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
// Route to providers (async)
|
|
141
|
+
(async () => {
|
|
142
|
+
// 1. Try provider handlers first (for bidirectional comm)
|
|
143
|
+
for (const provider of context.providers) {
|
|
144
|
+
if (provider.handleMessage) {
|
|
145
|
+
await provider.handleMessage(message, respond);
|
|
146
|
+
// Don't stop - let consumers also handle the message
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// 2. Broadcast to consumers (one-way messages or lifecycle events)
|
|
150
|
+
for (const consumer of context.consumers) {
|
|
151
|
+
await consumer.handleMessage(message);
|
|
152
|
+
// Don't stop - let all consumers see the message
|
|
153
|
+
}
|
|
154
|
+
})();
|
|
155
|
+
return true; // Indicates async response
|
|
156
|
+
};
|
|
157
|
+
chrome.runtime.onUserScriptMessage.addListener(this.userScriptMessageListener);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Global singleton instance.
|
|
163
|
+
* Import this from wherever you need to interact with the message router.
|
|
164
|
+
*/
|
|
165
|
+
export const RUNTIME_MESSAGE_ROUTER = new RuntimeMessageRouter();
|
|
166
|
+
//# sourceMappingURL=RuntimeMessageRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeMessageRouter.js","sourceRoot":"","sources":["../../../src/components/sandbox/RuntimeMessageRouter.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,oBAAoB;IACxB,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC9C,eAAe,GAAuC,IAAI,CAAC;IAC3D,yBAAyB,GAEvB,IAAI,CAA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