@mariozechner/pi-web-ui 0.5.44
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 +252 -0
- package/dist/ChatPanel.d.ts +23 -0
- package/dist/ChatPanel.d.ts.map +1 -0
- package/dist/ChatPanel.js +224 -0
- package/dist/ChatPanel.js.map +1 -0
- package/dist/app.css +2 -0
- package/dist/components/AgentInterface.d.ts +35 -0
- package/dist/components/AgentInterface.d.ts.map +1 -0
- package/dist/components/AgentInterface.js +308 -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 +114 -0
- package/dist/components/AttachmentTile.js.map +1 -0
- package/dist/components/ConsoleBlock.d.ts +11 -0
- package/dist/components/ConsoleBlock.d.ts.map +1 -0
- package/dist/components/ConsoleBlock.js +77 -0
- package/dist/components/ConsoleBlock.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 +56 -0
- package/dist/components/Input.js.map +1 -0
- package/dist/components/MessageEditor.d.ts +38 -0
- package/dist/components/MessageEditor.d.ts.map +1 -0
- package/dist/components/MessageEditor.js +296 -0
- package/dist/components/MessageEditor.js.map +1 -0
- package/dist/components/MessageList.d.ts +13 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/MessageList.js +88 -0
- package/dist/components/MessageList.js.map +1 -0
- package/dist/components/Messages.d.ts +53 -0
- package/dist/components/Messages.d.ts.map +1 -0
- package/dist/components/Messages.js +323 -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 +183 -0
- package/dist/components/ProviderKeyInput.js.map +1 -0
- package/dist/components/SandboxedIframe.d.ts +63 -0
- package/dist/components/SandboxedIframe.d.ts.map +1 -0
- package/dist/components/SandboxedIframe.js +435 -0
- package/dist/components/SandboxedIframe.js.map +1 -0
- package/dist/components/StreamingMessageContainer.d.ts +17 -0
- package/dist/components/StreamingMessageContainer.d.ts.map +1 -0
- package/dist/components/StreamingMessageContainer.js +114 -0
- package/dist/components/StreamingMessageContainer.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 +80 -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 +575 -0
- package/dist/dialogs/AttachmentOverlay.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 +334 -0
- package/dist/dialogs/ModelSelector.js.map +1 -0
- package/dist/dialogs/SettingsDialog.d.ts +31 -0
- package/dist/dialogs/SettingsDialog.d.ts.map +1 -0
- package/dist/dialogs/SettingsDialog.js +228 -0
- package/dist/dialogs/SettingsDialog.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/state/agent-session.d.ts +58 -0
- package/dist/state/agent-session.d.ts.map +1 -0
- package/dist/state/agent-session.js +252 -0
- package/dist/state/agent-session.js.map +1 -0
- package/dist/state/transports/AppTransport.d.ts +13 -0
- package/dist/state/transports/AppTransport.d.ts.map +1 -0
- package/dist/state/transports/AppTransport.js +316 -0
- package/dist/state/transports/AppTransport.js.map +1 -0
- package/dist/state/transports/ProviderTransport.d.ts +12 -0
- package/dist/state/transports/ProviderTransport.d.ts.map +1 -0
- package/dist/state/transports/ProviderTransport.js +44 -0
- package/dist/state/transports/ProviderTransport.js.map +1 -0
- package/dist/state/transports/index.d.ts +4 -0
- package/dist/state/transports/index.d.ts.map +1 -0
- package/dist/state/transports/index.js +4 -0
- package/dist/state/transports/index.js.map +1 -0
- package/dist/state/transports/proxy-types.d.ts +48 -0
- package/dist/state/transports/proxy-types.d.ts.map +1 -0
- package/dist/state/transports/proxy-types.js +2 -0
- package/dist/state/transports/proxy-types.js.map +1 -0
- package/dist/state/transports/types.d.ts +11 -0
- package/dist/state/transports/types.d.ts.map +1 -0
- package/dist/state/transports/types.js +2 -0
- package/dist/state/transports/types.js.map +1 -0
- package/dist/state/types.d.ts +15 -0
- package/dist/state/types.d.ts.map +1 -0
- package/dist/state/types.js +2 -0
- package/dist/state/types.js.map +1 -0
- package/dist/storage/app-storage.d.ts +26 -0
- package/dist/storage/app-storage.d.ts.map +1 -0
- package/dist/storage/app-storage.js +44 -0
- package/dist/storage/app-storage.js.map +1 -0
- package/dist/storage/backends/chrome-storage-backend.d.ts +18 -0
- package/dist/storage/backends/chrome-storage-backend.d.ts.map +1 -0
- package/dist/storage/backends/chrome-storage-backend.js +67 -0
- package/dist/storage/backends/chrome-storage-backend.js.map +1 -0
- package/dist/storage/backends/indexeddb-backend.d.ts +20 -0
- package/dist/storage/backends/indexeddb-backend.d.ts.map +1 -0
- package/dist/storage/backends/indexeddb-backend.js +89 -0
- package/dist/storage/backends/indexeddb-backend.js.map +1 -0
- package/dist/storage/backends/local-storage-backend.d.ts +18 -0
- package/dist/storage/backends/local-storage-backend.d.ts.map +1 -0
- package/dist/storage/backends/local-storage-backend.js +69 -0
- package/dist/storage/backends/local-storage-backend.js.map +1 -0
- package/dist/storage/repositories/provider-keys-repository.d.ts +34 -0
- package/dist/storage/repositories/provider-keys-repository.d.ts.map +1 -0
- package/dist/storage/repositories/provider-keys-repository.js +50 -0
- package/dist/storage/repositories/provider-keys-repository.js.map +1 -0
- package/dist/storage/repositories/settings-repository.d.ts +34 -0
- package/dist/storage/repositories/settings-repository.d.ts.map +1 -0
- package/dist/storage/repositories/settings-repository.js +46 -0
- package/dist/storage/repositories/settings-repository.js.map +1 -0
- package/dist/storage/types.d.ts +43 -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 +10 -0
- package/dist/tools/artifacts/ArtifactElement.d.ts.map +1 -0
- package/dist/tools/artifacts/ArtifactElement.js +12 -0
- package/dist/tools/artifacts/ArtifactElement.js.map +1 -0
- package/dist/tools/artifacts/HtmlArtifact.d.ts +30 -0
- package/dist/tools/artifacts/HtmlArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/HtmlArtifact.js +217 -0
- package/dist/tools/artifacts/HtmlArtifact.js.map +1 -0
- package/dist/tools/artifacts/MarkdownArtifact.d.ts +20 -0
- package/dist/tools/artifacts/MarkdownArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/MarkdownArtifact.js +84 -0
- package/dist/tools/artifacts/MarkdownArtifact.js.map +1 -0
- package/dist/tools/artifacts/SvgArtifact.d.ts +19 -0
- package/dist/tools/artifacts/SvgArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/SvgArtifact.js +80 -0
- package/dist/tools/artifacts/SvgArtifact.js.map +1 -0
- package/dist/tools/artifacts/TextArtifact.d.ts +20 -0
- package/dist/tools/artifacts/TextArtifact.d.ts.map +1 -0
- package/dist/tools/artifacts/TextArtifact.js +147 -0
- package/dist/tools/artifacts/TextArtifact.js.map +1 -0
- package/dist/tools/artifacts/artifacts.d.ts +67 -0
- package/dist/tools/artifacts/artifacts.d.ts.map +1 -0
- package/dist/tools/artifacts/artifacts.js +836 -0
- package/dist/tools/artifacts/artifacts.js.map +1 -0
- package/dist/tools/artifacts/index.d.ts +7 -0
- package/dist/tools/artifacts/index.d.ts.map +1 -0
- package/dist/tools/artifacts/index.js +7 -0
- package/dist/tools/artifacts/index.js.map +1 -0
- package/dist/tools/index.d.ts +14 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +29 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/javascript-repl.d.ts +43 -0
- package/dist/tools/javascript-repl.d.ts.map +1 -0
- package/dist/tools/javascript-repl.js +252 -0
- package/dist/tools/javascript-repl.js.map +1 -0
- package/dist/tools/renderer-registry.d.ts +11 -0
- package/dist/tools/renderer-registry.d.ts.map +1 -0
- package/dist/tools/renderer-registry.js +15 -0
- package/dist/tools/renderer-registry.js.map +1 -0
- package/dist/tools/renderers/BashRenderer.d.ts +12 -0
- package/dist/tools/renderers/BashRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/BashRenderer.js +35 -0
- package/dist/tools/renderers/BashRenderer.js.map +1 -0
- package/dist/tools/renderers/CalculateRenderer.d.ts +12 -0
- package/dist/tools/renderers/CalculateRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/CalculateRenderer.js +38 -0
- package/dist/tools/renderers/CalculateRenderer.js.map +1 -0
- package/dist/tools/renderers/DefaultRenderer.d.ts +8 -0
- package/dist/tools/renderers/DefaultRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/DefaultRenderer.js +31 -0
- package/dist/tools/renderers/DefaultRenderer.js.map +1 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.d.ts +12 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.d.ts.map +1 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.js +30 -0
- package/dist/tools/renderers/GetCurrentTimeRenderer.js.map +1 -0
- package/dist/tools/types.d.ts +7 -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 +111 -0
- package/dist/utils/i18n.d.ts.map +1 -0
- package/dist/utils/i18n.js +224 -0
- package/dist/utils/i18n.js.map +1 -0
- package/dist/utils/test-sessions.d.ts +347 -0
- package/dist/utils/test-sessions.d.ts.map +1 -0
- package/dist/utils/test-sessions.js +2215 -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-lock.json +1965 -0
- package/example/package.json +22 -0
- package/example/src/app.css +1 -0
- package/example/src/main.ts +57 -0
- package/example/src/test-sessions.ts +104 -0
- package/example/tsconfig.json +15 -0
- package/example/vite.config.ts +6 -0
- package/package.json +45 -0
- package/src/ChatPanel.ts +214 -0
- package/src/app.css +44 -0
- package/src/components/AgentInterface.ts +316 -0
- package/src/components/AttachmentTile.ts +112 -0
- package/src/components/ConsoleBlock.ts +67 -0
- package/src/components/Input.ts +112 -0
- package/src/components/MessageEditor.ts +272 -0
- package/src/components/MessageList.ts +82 -0
- package/src/components/Messages.ts +310 -0
- package/src/components/ProviderKeyInput.ts +170 -0
- package/src/components/SandboxedIframe.ts +525 -0
- package/src/components/StreamingMessageContainer.ts +101 -0
- package/src/dialogs/ApiKeyPromptDialog.ts +76 -0
- package/src/dialogs/AttachmentOverlay.ts +635 -0
- package/src/dialogs/ModelSelector.ts +324 -0
- package/src/dialogs/SettingsDialog.ts +223 -0
- package/src/index.ts +63 -0
- package/src/state/agent-session.ts +311 -0
- package/src/state/transports/AppTransport.ts +363 -0
- package/src/state/transports/ProviderTransport.ts +49 -0
- package/src/state/transports/index.ts +3 -0
- package/src/state/transports/proxy-types.ts +15 -0
- package/src/state/transports/types.ts +16 -0
- package/src/state/types.ts +11 -0
- package/src/storage/app-storage.ts +53 -0
- package/src/storage/backends/chrome-storage-backend.ts +82 -0
- package/src/storage/backends/indexeddb-backend.ts +107 -0
- package/src/storage/backends/local-storage-backend.ts +74 -0
- package/src/storage/repositories/provider-keys-repository.ts +55 -0
- package/src/storage/repositories/settings-repository.ts +51 -0
- package/src/storage/types.ts +48 -0
- package/src/tools/artifacts/ArtifactElement.ts +15 -0
- package/src/tools/artifacts/HtmlArtifact.ts +221 -0
- package/src/tools/artifacts/MarkdownArtifact.ts +81 -0
- package/src/tools/artifacts/SvgArtifact.ts +77 -0
- package/src/tools/artifacts/TextArtifact.ts +148 -0
- package/src/tools/artifacts/artifacts.ts +888 -0
- package/src/tools/artifacts/index.ts +6 -0
- package/src/tools/index.ts +35 -0
- package/src/tools/javascript-repl.ts +309 -0
- package/src/tools/renderer-registry.ts +18 -0
- package/src/tools/renderers/BashRenderer.ts +45 -0
- package/src/tools/renderers/CalculateRenderer.ts +49 -0
- package/src/tools/renderers/DefaultRenderer.ts +36 -0
- package/src/tools/renderers/GetCurrentTimeRenderer.ts +39 -0
- package/src/tools/types.ts +7 -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 +343 -0
- package/src/utils/test-sessions.ts +2247 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { LitElement } from "lit";
|
|
8
|
+
import { customElement, property } from "lit/decorators.js";
|
|
9
|
+
let SandboxIframe = class SandboxIframe extends LitElement {
|
|
10
|
+
createRenderRoot() {
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
connectedCallback() {
|
|
14
|
+
super.connectedCallback();
|
|
15
|
+
}
|
|
16
|
+
disconnectedCallback() {
|
|
17
|
+
super.disconnectedCallback();
|
|
18
|
+
this.iframe?.remove();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Load HTML content into sandbox and keep it displayed (for HTML artifacts)
|
|
22
|
+
* @param sandboxId Unique ID
|
|
23
|
+
* @param htmlContent Full HTML content
|
|
24
|
+
* @param attachments Attachments available
|
|
25
|
+
*/
|
|
26
|
+
loadContent(sandboxId, htmlContent, attachments) {
|
|
27
|
+
const completeHtml = this.prepareHtmlDocument(sandboxId, htmlContent, attachments);
|
|
28
|
+
if (this.sandboxUrlProvider) {
|
|
29
|
+
// Browser extension mode: use sandbox.html with postMessage
|
|
30
|
+
this.loadViaSandboxUrl(sandboxId, completeHtml, attachments);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// Web mode: use srcdoc
|
|
34
|
+
this.loadViaSrcdoc(completeHtml);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
loadViaSandboxUrl(sandboxId, completeHtml, attachments) {
|
|
38
|
+
// Wait for sandbox-ready and send content
|
|
39
|
+
const readyHandler = (e) => {
|
|
40
|
+
if (e.data.type === "sandbox-ready" && e.source === this.iframe?.contentWindow) {
|
|
41
|
+
window.removeEventListener("message", readyHandler);
|
|
42
|
+
this.iframe?.contentWindow?.postMessage({
|
|
43
|
+
type: "sandbox-load",
|
|
44
|
+
sandboxId,
|
|
45
|
+
code: completeHtml,
|
|
46
|
+
attachments,
|
|
47
|
+
}, "*");
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
window.addEventListener("message", readyHandler);
|
|
51
|
+
// Always recreate iframe to ensure fresh sandbox and sandbox-ready message
|
|
52
|
+
this.iframe?.remove();
|
|
53
|
+
this.iframe = document.createElement("iframe");
|
|
54
|
+
this.iframe.sandbox.add("allow-scripts");
|
|
55
|
+
this.iframe.sandbox.add("allow-modals");
|
|
56
|
+
this.iframe.style.width = "100%";
|
|
57
|
+
this.iframe.style.height = "100%";
|
|
58
|
+
this.iframe.style.border = "none";
|
|
59
|
+
this.iframe.src = this.sandboxUrlProvider();
|
|
60
|
+
this.appendChild(this.iframe);
|
|
61
|
+
}
|
|
62
|
+
loadViaSrcdoc(completeHtml) {
|
|
63
|
+
// Always recreate iframe to ensure fresh sandbox
|
|
64
|
+
this.iframe?.remove();
|
|
65
|
+
this.iframe = document.createElement("iframe");
|
|
66
|
+
this.iframe.sandbox.add("allow-scripts");
|
|
67
|
+
this.iframe.sandbox.add("allow-modals");
|
|
68
|
+
this.iframe.style.width = "100%";
|
|
69
|
+
this.iframe.style.height = "100%";
|
|
70
|
+
this.iframe.style.border = "none";
|
|
71
|
+
// Set content directly via srcdoc (no CSP restrictions in web apps)
|
|
72
|
+
this.iframe.srcdoc = completeHtml;
|
|
73
|
+
this.appendChild(this.iframe);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Execute code in sandbox
|
|
77
|
+
* @param sandboxId Unique ID for this execution
|
|
78
|
+
* @param code User code (plain JS for REPL, or full HTML for artifacts)
|
|
79
|
+
* @param attachments Attachments available to the code
|
|
80
|
+
* @param signal Abort signal
|
|
81
|
+
* @returns Promise resolving to execution result
|
|
82
|
+
*/
|
|
83
|
+
async execute(sandboxId, code, attachments, signal) {
|
|
84
|
+
if (signal?.aborted) {
|
|
85
|
+
throw new Error("Execution aborted");
|
|
86
|
+
}
|
|
87
|
+
// Prepare the complete HTML document with runtime + user code
|
|
88
|
+
const completeHtml = this.prepareHtmlDocument(sandboxId, code, attachments);
|
|
89
|
+
// Wait for execution to complete
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const logs = [];
|
|
92
|
+
const files = [];
|
|
93
|
+
let completed = false;
|
|
94
|
+
const messageHandler = (e) => {
|
|
95
|
+
// Ignore messages not for this sandbox
|
|
96
|
+
if (e.data.sandboxId !== sandboxId)
|
|
97
|
+
return;
|
|
98
|
+
if (e.data.type === "console") {
|
|
99
|
+
logs.push({
|
|
100
|
+
type: e.data.method === "error" ? "error" : "log",
|
|
101
|
+
text: e.data.text,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else if (e.data.type === "file-returned") {
|
|
105
|
+
files.push({
|
|
106
|
+
fileName: e.data.fileName,
|
|
107
|
+
content: e.data.content,
|
|
108
|
+
mimeType: e.data.mimeType,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else if (e.data.type === "execution-complete") {
|
|
112
|
+
completed = true;
|
|
113
|
+
cleanup();
|
|
114
|
+
resolve({
|
|
115
|
+
success: true,
|
|
116
|
+
console: logs,
|
|
117
|
+
files: files,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else if (e.data.type === "execution-error") {
|
|
121
|
+
completed = true;
|
|
122
|
+
cleanup();
|
|
123
|
+
resolve({
|
|
124
|
+
success: false,
|
|
125
|
+
console: logs,
|
|
126
|
+
error: e.data.error,
|
|
127
|
+
files,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const abortHandler = () => {
|
|
132
|
+
if (!completed) {
|
|
133
|
+
cleanup();
|
|
134
|
+
reject(new Error("Execution aborted"));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
let readyHandler;
|
|
138
|
+
const cleanup = () => {
|
|
139
|
+
window.removeEventListener("message", messageHandler);
|
|
140
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
141
|
+
if (readyHandler) {
|
|
142
|
+
window.removeEventListener("message", readyHandler);
|
|
143
|
+
}
|
|
144
|
+
clearTimeout(timeoutId);
|
|
145
|
+
};
|
|
146
|
+
// Set up listeners BEFORE creating iframe
|
|
147
|
+
window.addEventListener("message", messageHandler);
|
|
148
|
+
signal?.addEventListener("abort", abortHandler);
|
|
149
|
+
// Timeout after 30 seconds
|
|
150
|
+
const timeoutId = setTimeout(() => {
|
|
151
|
+
if (!completed) {
|
|
152
|
+
cleanup();
|
|
153
|
+
resolve({
|
|
154
|
+
success: false,
|
|
155
|
+
error: { message: "Execution timeout (30s)", stack: "" },
|
|
156
|
+
console: logs,
|
|
157
|
+
files,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}, 30000);
|
|
161
|
+
if (this.sandboxUrlProvider) {
|
|
162
|
+
// Browser extension mode: wait for sandbox-ready and send content
|
|
163
|
+
readyHandler = (e) => {
|
|
164
|
+
if (e.data.type === "sandbox-ready" && e.source === this.iframe?.contentWindow) {
|
|
165
|
+
window.removeEventListener("message", readyHandler);
|
|
166
|
+
// Send the complete HTML
|
|
167
|
+
this.iframe?.contentWindow?.postMessage({
|
|
168
|
+
type: "sandbox-load",
|
|
169
|
+
sandboxId,
|
|
170
|
+
code: completeHtml,
|
|
171
|
+
attachments,
|
|
172
|
+
}, "*");
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
window.addEventListener("message", readyHandler);
|
|
176
|
+
// Create iframe AFTER all listeners are set up
|
|
177
|
+
this.iframe?.remove();
|
|
178
|
+
this.iframe = document.createElement("iframe");
|
|
179
|
+
this.iframe.sandbox.add("allow-scripts");
|
|
180
|
+
this.iframe.sandbox.add("allow-modals");
|
|
181
|
+
this.iframe.style.width = "100%";
|
|
182
|
+
this.iframe.style.height = "100%";
|
|
183
|
+
this.iframe.style.border = "none";
|
|
184
|
+
this.iframe.src = this.sandboxUrlProvider();
|
|
185
|
+
this.appendChild(this.iframe);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// Web mode: use srcdoc
|
|
189
|
+
this.iframe?.remove();
|
|
190
|
+
this.iframe = document.createElement("iframe");
|
|
191
|
+
this.iframe.sandbox.add("allow-scripts");
|
|
192
|
+
this.iframe.sandbox.add("allow-modals");
|
|
193
|
+
this.iframe.style.width = "100%";
|
|
194
|
+
this.iframe.style.height = "100%";
|
|
195
|
+
this.iframe.style.border = "none";
|
|
196
|
+
// Set content via srcdoc BEFORE appending to DOM
|
|
197
|
+
this.iframe.srcdoc = completeHtml;
|
|
198
|
+
this.appendChild(this.iframe);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Prepare complete HTML document with runtime + user code
|
|
204
|
+
*/
|
|
205
|
+
prepareHtmlDocument(sandboxId, userCode, attachments) {
|
|
206
|
+
// Runtime script that will be injected
|
|
207
|
+
const runtime = this.getRuntimeScript(sandboxId, attachments);
|
|
208
|
+
// Check if user provided full HTML
|
|
209
|
+
const hasHtmlTag = /<html[^>]*>/i.test(userCode);
|
|
210
|
+
if (hasHtmlTag) {
|
|
211
|
+
// HTML Artifact - inject runtime into existing HTML
|
|
212
|
+
const headMatch = userCode.match(/<head[^>]*>/i);
|
|
213
|
+
if (headMatch) {
|
|
214
|
+
const index = headMatch.index + headMatch[0].length;
|
|
215
|
+
return userCode.slice(0, index) + runtime + userCode.slice(index);
|
|
216
|
+
}
|
|
217
|
+
const htmlMatch = userCode.match(/<html[^>]*>/i);
|
|
218
|
+
if (htmlMatch) {
|
|
219
|
+
const index = htmlMatch.index + htmlMatch[0].length;
|
|
220
|
+
return userCode.slice(0, index) + runtime + userCode.slice(index);
|
|
221
|
+
}
|
|
222
|
+
// Fallback: prepend runtime
|
|
223
|
+
return runtime + userCode;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// REPL - wrap code in HTML with runtime and call complete() when done
|
|
227
|
+
return `<!DOCTYPE html>
|
|
228
|
+
<html>
|
|
229
|
+
<head>
|
|
230
|
+
${runtime}
|
|
231
|
+
</head>
|
|
232
|
+
<body>
|
|
233
|
+
<script type="module">
|
|
234
|
+
(async () => {
|
|
235
|
+
try {
|
|
236
|
+
${userCode}
|
|
237
|
+
window.complete();
|
|
238
|
+
} catch (error) {
|
|
239
|
+
console.error(error?.stack || error?.message || String(error));
|
|
240
|
+
window.complete({
|
|
241
|
+
message: error?.message || String(error),
|
|
242
|
+
stack: error?.stack || new Error().stack
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
})();
|
|
246
|
+
</script>
|
|
247
|
+
</body>
|
|
248
|
+
</html>`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get the runtime script that captures console, provides helpers, etc.
|
|
253
|
+
*/
|
|
254
|
+
getRuntimeScript(sandboxId, attachments) {
|
|
255
|
+
// Convert attachments to serializable format
|
|
256
|
+
const attachmentsData = attachments.map((a) => ({
|
|
257
|
+
id: a.id,
|
|
258
|
+
fileName: a.fileName,
|
|
259
|
+
mimeType: a.mimeType,
|
|
260
|
+
size: a.size,
|
|
261
|
+
content: a.content,
|
|
262
|
+
extractedText: a.extractedText,
|
|
263
|
+
}));
|
|
264
|
+
// Runtime function that will run in the sandbox (NO parameters - values injected before function)
|
|
265
|
+
const runtimeFunc = () => {
|
|
266
|
+
// Helper functions
|
|
267
|
+
window.listFiles = () => (attachments || []).map((a) => ({
|
|
268
|
+
id: a.id,
|
|
269
|
+
fileName: a.fileName,
|
|
270
|
+
mimeType: a.mimeType,
|
|
271
|
+
size: a.size,
|
|
272
|
+
}));
|
|
273
|
+
window.readTextFile = (attachmentId) => {
|
|
274
|
+
const a = (attachments || []).find((x) => x.id === attachmentId);
|
|
275
|
+
if (!a)
|
|
276
|
+
throw new Error("Attachment not found: " + attachmentId);
|
|
277
|
+
if (a.extractedText)
|
|
278
|
+
return a.extractedText;
|
|
279
|
+
try {
|
|
280
|
+
return atob(a.content);
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
throw new Error("Failed to decode text content for: " + attachmentId);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
window.readBinaryFile = (attachmentId) => {
|
|
287
|
+
const a = (attachments || []).find((x) => x.id === attachmentId);
|
|
288
|
+
if (!a)
|
|
289
|
+
throw new Error("Attachment not found: " + attachmentId);
|
|
290
|
+
const bin = atob(a.content);
|
|
291
|
+
const bytes = new Uint8Array(bin.length);
|
|
292
|
+
for (let i = 0; i < bin.length; i++)
|
|
293
|
+
bytes[i] = bin.charCodeAt(i);
|
|
294
|
+
return bytes;
|
|
295
|
+
};
|
|
296
|
+
window.returnFile = async (fileName, content, mimeType) => {
|
|
297
|
+
let finalContent, finalMimeType;
|
|
298
|
+
if (content instanceof Blob) {
|
|
299
|
+
const arrayBuffer = await content.arrayBuffer();
|
|
300
|
+
finalContent = new Uint8Array(arrayBuffer);
|
|
301
|
+
finalMimeType = mimeType || content.type || "application/octet-stream";
|
|
302
|
+
if (!mimeType && !content.type) {
|
|
303
|
+
throw new Error("returnFile: MIME type is required for Blob content. Please provide a mimeType parameter (e.g., 'image/png').");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else if (content instanceof Uint8Array) {
|
|
307
|
+
finalContent = content;
|
|
308
|
+
if (!mimeType) {
|
|
309
|
+
throw new Error("returnFile: MIME type is required for Uint8Array content. Please provide a mimeType parameter (e.g., 'image/png').");
|
|
310
|
+
}
|
|
311
|
+
finalMimeType = mimeType;
|
|
312
|
+
}
|
|
313
|
+
else if (typeof content === "string") {
|
|
314
|
+
finalContent = content;
|
|
315
|
+
finalMimeType = mimeType || "text/plain";
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
finalContent = JSON.stringify(content, null, 2);
|
|
319
|
+
finalMimeType = mimeType || "application/json";
|
|
320
|
+
}
|
|
321
|
+
window.parent.postMessage({
|
|
322
|
+
type: "file-returned",
|
|
323
|
+
sandboxId,
|
|
324
|
+
fileName,
|
|
325
|
+
content: finalContent,
|
|
326
|
+
mimeType: finalMimeType,
|
|
327
|
+
}, "*");
|
|
328
|
+
};
|
|
329
|
+
// Console capture
|
|
330
|
+
const originalConsole = {
|
|
331
|
+
log: console.log,
|
|
332
|
+
error: console.error,
|
|
333
|
+
warn: console.warn,
|
|
334
|
+
info: console.info,
|
|
335
|
+
};
|
|
336
|
+
["log", "error", "warn", "info"].forEach((method) => {
|
|
337
|
+
console[method] = (...args) => {
|
|
338
|
+
const text = args
|
|
339
|
+
.map((arg) => {
|
|
340
|
+
try {
|
|
341
|
+
return typeof arg === "object" ? JSON.stringify(arg) : String(arg);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
return String(arg);
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
.join(" ");
|
|
348
|
+
window.parent.postMessage({
|
|
349
|
+
type: "console",
|
|
350
|
+
sandboxId,
|
|
351
|
+
method,
|
|
352
|
+
text,
|
|
353
|
+
}, "*");
|
|
354
|
+
originalConsole[method].apply(console, args);
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
// Track errors for HTML artifacts
|
|
358
|
+
let lastError = null;
|
|
359
|
+
// Error handlers
|
|
360
|
+
window.addEventListener("error", (e) => {
|
|
361
|
+
const text = (e.error?.stack || e.message || String(e)) + " at line " + (e.lineno || "?") + ":" + (e.colno || "?");
|
|
362
|
+
// Store the error
|
|
363
|
+
lastError = {
|
|
364
|
+
message: e.error?.message || e.message || String(e),
|
|
365
|
+
stack: e.error?.stack || text,
|
|
366
|
+
};
|
|
367
|
+
window.parent.postMessage({
|
|
368
|
+
type: "console",
|
|
369
|
+
sandboxId,
|
|
370
|
+
method: "error",
|
|
371
|
+
text,
|
|
372
|
+
}, "*");
|
|
373
|
+
});
|
|
374
|
+
window.addEventListener("unhandledrejection", (e) => {
|
|
375
|
+
const text = "Unhandled promise rejection: " + (e.reason?.message || e.reason || "Unknown error");
|
|
376
|
+
// Store the error
|
|
377
|
+
lastError = {
|
|
378
|
+
message: e.reason?.message || String(e.reason) || "Unhandled promise rejection",
|
|
379
|
+
stack: e.reason?.stack || text,
|
|
380
|
+
};
|
|
381
|
+
window.parent.postMessage({
|
|
382
|
+
type: "console",
|
|
383
|
+
sandboxId,
|
|
384
|
+
method: "error",
|
|
385
|
+
text,
|
|
386
|
+
}, "*");
|
|
387
|
+
});
|
|
388
|
+
// Expose complete() method for user code to call
|
|
389
|
+
let completionSent = false;
|
|
390
|
+
window.complete = (error) => {
|
|
391
|
+
if (completionSent)
|
|
392
|
+
return;
|
|
393
|
+
completionSent = true;
|
|
394
|
+
// Use provided error or last caught error
|
|
395
|
+
const finalError = error || lastError;
|
|
396
|
+
if (finalError) {
|
|
397
|
+
window.parent.postMessage({
|
|
398
|
+
type: "execution-error",
|
|
399
|
+
sandboxId,
|
|
400
|
+
error: finalError,
|
|
401
|
+
}, "*");
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
window.parent.postMessage({
|
|
405
|
+
type: "execution-complete",
|
|
406
|
+
sandboxId,
|
|
407
|
+
}, "*");
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
// Fallback timeout for HTML artifacts that don't call complete()
|
|
411
|
+
if (document.readyState === "complete" || document.readyState === "interactive") {
|
|
412
|
+
setTimeout(() => window.complete(), 2000);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
window.addEventListener("load", () => {
|
|
416
|
+
setTimeout(() => window.complete(), 2000);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
// Prepend the const declarations, then the function
|
|
421
|
+
return (`<script>\n` +
|
|
422
|
+
`window.sandboxId = ${JSON.stringify(sandboxId)};\n` +
|
|
423
|
+
`window.attachments = ${JSON.stringify(attachmentsData)};\n` +
|
|
424
|
+
`(${runtimeFunc.toString()})();\n` +
|
|
425
|
+
`</script>`);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
__decorate([
|
|
429
|
+
property({ attribute: false })
|
|
430
|
+
], SandboxIframe.prototype, "sandboxUrlProvider", void 0);
|
|
431
|
+
SandboxIframe = __decorate([
|
|
432
|
+
customElement("sandbox-iframe")
|
|
433
|
+
], SandboxIframe);
|
|
434
|
+
export { SandboxIframe };
|
|
435
|
+
//# sourceMapp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,EAAE,CAAC;gBACjF,UAAU,CAAC,GAAG,EAAE,CAAE,MAAc,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;oBACpC,UAAU,CAAC,GAAG,EAAE,CAAE,MAAc,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACJ,CAAC;QACF,CAAC,CAAC;QAEF,oDAAoD;QACpD,OAAO,CACN,YAAY;YACZ,sBAAsB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK;YACpD,wBAAwB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK;YAC5D,IAAI,WAAW,CAAC,QAAQ,EAAE,QAAQ;YAClC,WAAW,CACX,CAAC;IACH,CAAC;CACD,CAAA;AA5egC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;yDAAyC;AAR5D,aAAa;IADzB,aAAa,CAAC,gBAAgB,CAAC;GACnB,aAAa,CAofzB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AgentTool, Message, ToolResultMessage } from "@mariozechner/pi-ai";
|
|
2
|
+
import { LitElement } from "lit";
|
|
3
|
+
export declare class StreamingMessageContainer extends LitElement {
|
|
4
|
+
tools: AgentTool[];
|
|
5
|
+
isStreaming: boolean;
|
|
6
|
+
pendingToolCalls?: Set<string>;
|
|
7
|
+
toolResultsById?: Map<string, ToolResultMessage>;
|
|
8
|
+
private _message;
|
|
9
|
+
private _pendingMessage;
|
|
10
|
+
private _updateScheduled;
|
|
11
|
+
private _immediateUpdate;
|
|
12
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
13
|
+
connectedCallback(): void;
|
|
14
|
+
setMessage(message: Message | null, immediate?: boolean): void;
|
|
15
|
+
render(): import("lit-html").TemplateResult<1> | undefined;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=StreamingMessageContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamingMessageContainer.d.ts","sourceRoot":"","sources":["../../src/components/StreamingMessageContainer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAGjC,qBAAa,yBAA0B,SAAQ,UAAU;IAC7B,KAAK,EAAE,SAAS,EAAE,CAAM;IACtB,WAAW,UAAS;IACrB,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAEpE,OAAO,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;cAEd,gBAAgB,IAAI,WAAW,GAAG,gBAAgB;IAI5D,iBAAiB,IAAI,IAAI;IAM3B,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,EAAE,SAAS,UAAQ;IAmCnD,MAAM;CAkCf"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html } from "@mariozechner/mini-lit";
|
|
8
|
+
import { LitElement } from "lit";
|
|
9
|
+
import { property, state } from "lit/decorators.js";
|
|
10
|
+
export class StreamingMessageContainer extends LitElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.tools = [];
|
|
14
|
+
this.isStreaming = false;
|
|
15
|
+
this._message = null;
|
|
16
|
+
this._pendingMessage = null;
|
|
17
|
+
this._updateScheduled = false;
|
|
18
|
+
this._immediateUpdate = false;
|
|
19
|
+
}
|
|
20
|
+
createRenderRoot() {
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
connectedCallback() {
|
|
24
|
+
super.connectedCallback();
|
|
25
|
+
this.style.display = "block";
|
|
26
|
+
}
|
|
27
|
+
// Public method to update the message with batching for performance
|
|
28
|
+
setMessage(message, immediate = false) {
|
|
29
|
+
// Store the latest message
|
|
30
|
+
this._pendingMessage = message;
|
|
31
|
+
// If this is an immediate update (like clearing), apply it right away
|
|
32
|
+
if (immediate || message === null) {
|
|
33
|
+
this._immediateUpdate = true;
|
|
34
|
+
this._message = message;
|
|
35
|
+
this.requestUpdate();
|
|
36
|
+
// Cancel any pending updates since we're clearing
|
|
37
|
+
this._pendingMessage = null;
|
|
38
|
+
this._updateScheduled = false;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// Otherwise batch updates for performance during streaming
|
|
42
|
+
if (!this._updateScheduled) {
|
|
43
|
+
this._updateScheduled = true;
|
|
44
|
+
requestAnimationFrame(async () => {
|
|
45
|
+
// Only apply the update if we haven't been cleared
|
|
46
|
+
if (!this._immediateUpdate && this._pendingMessage !== null) {
|
|
47
|
+
// Deep clone the message to ensure Lit detects changes in nested properties
|
|
48
|
+
// (like toolCall.arguments being mutated during streaming)
|
|
49
|
+
this._message = JSON.parse(JSON.stringify(this._pendingMessage));
|
|
50
|
+
this.requestUpdate();
|
|
51
|
+
}
|
|
52
|
+
// Reset for next batch
|
|
53
|
+
this._pendingMessage = null;
|
|
54
|
+
this._updateScheduled = false;
|
|
55
|
+
this._immediateUpdate = false;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
// Show loading indicator if loading but no message yet
|
|
61
|
+
if (!this._message) {
|
|
62
|
+
if (this.isStreaming)
|
|
63
|
+
return html `<div class="flex flex-col gap-3 mb-3">
|
|
64
|
+
<span class="mx-4 inline-block w-2 h-4 bg-muted-foreground animate-pulse"></span>
|
|
65
|
+
</div>`;
|
|
66
|
+
return html ``; // Empty until a message is set
|
|
67
|
+
}
|
|
68
|
+
const msg = this._message;
|
|
69
|
+
if (msg.role === "toolResult") {
|
|
70
|
+
// Skip standalone tool result in streaming; the stable list will render paired tool-message
|
|
71
|
+
return html ``;
|
|
72
|
+
}
|
|
73
|
+
else if (msg.role === "user") {
|
|
74
|
+
// Skip standalone tool result in streaming; the stable list will render it immediiately
|
|
75
|
+
return html ``;
|
|
76
|
+
}
|
|
77
|
+
else if (msg.role === "assistant") {
|
|
78
|
+
// Assistant message - render inline tool messages during streaming
|
|
79
|
+
return html `
|
|
80
|
+
<div class="flex flex-col gap-3 mb-3">
|
|
81
|
+
<assistant-message
|
|
82
|
+
.message=${msg}
|
|
83
|
+
.tools=${this.tools}
|
|
84
|
+
.isStreaming=${this.isStreaming}
|
|
85
|
+
.pendingToolCalls=${this.pendingToolCalls}
|
|
86
|
+
.toolResultsById=${this.toolResultsById}
|
|
87
|
+
.hideToolCalls=${false}
|
|
88
|
+
></assistant-message>
|
|
89
|
+
${this.isStreaming ? html `<span class="mx-4 inline-block w-2 h-4 bg-muted-foreground animate-pulse"></span>` : ""}
|
|
90
|
+
</div>
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
__decorate([
|
|
96
|
+
property({ type: Array })
|
|
97
|
+
], StreamingMessageContainer.prototype, "tools", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
property({ type: Boolean })
|
|
100
|
+
], StreamingMessageContainer.prototype, "isStreaming", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
property({ type: Object })
|
|
103
|
+
], StreamingMessageContainer.prototype, "pendingToolCalls", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
property({ type: Object })
|
|
106
|
+
], StreamingMessageContainer.prototype, "toolResultsById", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
state()
|
|
109
|
+
], StreamingMessageContainer.prototype, "_message", void 0);
|
|
110
|
+
// Register custom element
|
|
111
|
+
if (!customElements.get("streaming-message-container")) {
|
|
112
|
+
customElements.define("streaming-message-container", StreamingMessageContainer);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=StreamingMessageContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamingMessageContainer.js","sourceRoot":"","sources":["../../src/components/StreamingMessageContainer.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,OAAO,yBAA0B,SAAQ,UAAU;IAAzD;;QAC4B,UAAK,GAAgB,EAAE,CAAC;QACtB,gBAAW,GAAG,KAAK,CAAC;QAIhC,aAAQ,GAAmB,IAAI,CAAC;QACzC,oBAAe,GAAmB,IAAI,CAAC;QACvC,qBAAgB,GAAG,KAAK,CAAC;QACzB,qBAAgB,GAAG,KAAK,CAAC;IAiFlC,CAAC;IA/EmB,gBAAgB;QAClC,OAAO,IAAI,CAAC;IACb,CAAC;IAEQ,iBAAiB;QACzB,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IAC9B,CAAC;IAED,oEAAoE;IAC7D,UAAU,CAAC,OAAuB,EAAE,SAAS,GAAG,KAAK;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
|
|
3
|
+
export declare class ApiKeyPromptDialog extends DialogBase {
|
|
4
|
+
private provider;
|
|
5
|
+
private resolvePromise?;
|
|
6
|
+
private unsubscribe?;
|
|
7
|
+
protected modalWidth: string;
|
|
8
|
+
protected modalHeight: string;
|
|
9
|
+
static prompt(provider: string): Promise<boolean>;
|
|
10
|
+
connectedCallback(): Promise<void>;
|
|
11
|
+
disconnectedCallback(): void;
|
|
12
|
+
close(): void;
|
|
13
|
+
protected renderContent(): import("lit-html").TemplateResult<1>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=ApiKeyPromptDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiKeyPromptDialog.d.ts","sourceRoot":"","sources":["../../src/dialogs/ApiKeyPromptDialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqC,MAAM,wBAAwB,CAAC;AAEvF,OAAO,mCAAmC,CAAC;AAI3C,qBACa,kBAAmB,SAAQ,UAAU;IACxC,OAAO,CAAC,QAAQ,CAAM;IAE/B,OAAO,CAAC,cAAc,CAAC,CAA6B;IACpD,OAAO,CAAC,WAAW,CAAC,CAAa;IAEjC,SAAS,CAAC,UAAU,SAAsB;IAC1C,SAAS,CAAC,WAAW,SAAU;WAElB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUxC,iBAAiB;IAmBvB,oBAAoB;IAQpB,KAAK;cAOK,aAAa;CAehC"}
|