@elyracode/web-ui 0.9.57 → 1.0.0

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/components/SandboxedIframe.d.ts +15 -1
  3. package/dist/components/SandboxedIframe.d.ts.map +1 -1
  4. package/dist/components/SandboxedIframe.js +129 -67
  5. package/dist/components/SandboxedIframe.js.map +1 -1
  6. package/dist/components/sandbox/RuntimeMessageRouter.d.ts +12 -2
  7. package/dist/components/sandbox/RuntimeMessageRouter.d.ts.map +1 -1
  8. package/dist/components/sandbox/RuntimeMessageRouter.js +26 -2
  9. package/dist/components/sandbox/RuntimeMessageRouter.js.map +1 -1
  10. package/package.json +18 -8
  11. package/example/README.md +0 -61
  12. package/example/index.html +0 -13
  13. package/example/package.json +0 -25
  14. package/example/src/app.css +0 -1
  15. package/example/src/css-modules.d.ts +0 -3
  16. package/example/src/custom-messages.ts +0 -99
  17. package/example/src/main.ts +0 -421
  18. package/example/tsconfig.json +0 -23
  19. package/example/vite.config.ts +0 -6
  20. package/scripts/count-prompt-tokens.ts +0 -88
  21. package/src/ChatPanel.ts +0 -209
  22. package/src/app.css +0 -68
  23. package/src/components/AgentInterface.ts +0 -403
  24. package/src/components/AttachmentTile.ts +0 -107
  25. package/src/components/ConsoleBlock.ts +0 -72
  26. package/src/components/CustomProviderCard.ts +0 -100
  27. package/src/components/ExpandableSection.ts +0 -46
  28. package/src/components/Input.ts +0 -113
  29. package/src/components/MessageEditor.ts +0 -405
  30. package/src/components/MessageList.ts +0 -98
  31. package/src/components/Messages.ts +0 -383
  32. package/src/components/ProviderKeyInput.ts +0 -153
  33. package/src/components/SandboxedIframe.ts +0 -627
  34. package/src/components/StreamingMessageContainer.ts +0 -103
  35. package/src/components/ThinkingBlock.ts +0 -43
  36. package/src/components/message-renderer-registry.ts +0 -28
  37. package/src/components/sandbox/ArtifactsRuntimeProvider.ts +0 -226
  38. package/src/components/sandbox/AttachmentsRuntimeProvider.ts +0 -68
  39. package/src/components/sandbox/ConsoleRuntimeProvider.ts +0 -188
  40. package/src/components/sandbox/FileDownloadRuntimeProvider.ts +0 -114
  41. package/src/components/sandbox/RuntimeMessageBridge.ts +0 -82
  42. package/src/components/sandbox/RuntimeMessageRouter.ts +0 -215
  43. package/src/components/sandbox/SandboxRuntimeProvider.ts +0 -54
  44. package/src/components/sandbox/runtime-messages.ts +0 -146
  45. package/src/dialogs/ApiKeyPromptDialog.ts +0 -75
  46. package/src/dialogs/AttachmentOverlay.ts +0 -637
  47. package/src/dialogs/CustomProviderDialog.ts +0 -274
  48. package/src/dialogs/ModelSelector.ts +0 -370
  49. package/src/dialogs/PersistentStorageDialog.ts +0 -144
  50. package/src/dialogs/ProvidersModelsTab.ts +0 -212
  51. package/src/dialogs/SessionListDialog.ts +0 -150
  52. package/src/dialogs/SettingsDialog.ts +0 -218
  53. package/src/index.ts +0 -120
  54. package/src/prompts/prompts.ts +0 -282
  55. package/src/storage/app-storage.ts +0 -60
  56. package/src/storage/backends/indexeddb-storage-backend.ts +0 -193
  57. package/src/storage/store.ts +0 -33
  58. package/src/storage/stores/custom-providers-store.ts +0 -62
  59. package/src/storage/stores/provider-keys-store.ts +0 -33
  60. package/src/storage/stores/sessions-store.ts +0 -136
  61. package/src/storage/stores/settings-store.ts +0 -34
  62. package/src/storage/types.ts +0 -206
  63. package/src/tools/artifacts/ArtifactElement.ts +0 -14
  64. package/src/tools/artifacts/ArtifactPill.ts +0 -26
  65. package/src/tools/artifacts/Console.ts +0 -93
  66. package/src/tools/artifacts/DocxArtifact.ts +0 -213
  67. package/src/tools/artifacts/ExcelArtifact.ts +0 -231
  68. package/src/tools/artifacts/GenericArtifact.ts +0 -117
  69. package/src/tools/artifacts/HtmlArtifact.ts +0 -195
  70. package/src/tools/artifacts/ImageArtifact.ts +0 -116
  71. package/src/tools/artifacts/MarkdownArtifact.ts +0 -82
  72. package/src/tools/artifacts/PdfArtifact.ts +0 -202
  73. package/src/tools/artifacts/SvgArtifact.ts +0 -119
  74. package/src/tools/artifacts/TextArtifact.ts +0 -148
  75. package/src/tools/artifacts/artifacts-tool-renderer.ts +0 -310
  76. package/src/tools/artifacts/artifacts.ts +0 -713
  77. package/src/tools/artifacts/index.ts +0 -7
  78. package/src/tools/extract-document.ts +0 -275
  79. package/src/tools/index.ts +0 -46
  80. package/src/tools/javascript-repl.ts +0 -293
  81. package/src/tools/renderer-registry.ts +0 -130
  82. package/src/tools/renderers/BashRenderer.ts +0 -52
  83. package/src/tools/renderers/CalculateRenderer.ts +0 -58
  84. package/src/tools/renderers/DefaultRenderer.ts +0 -103
  85. package/src/tools/renderers/GetCurrentTimeRenderer.ts +0 -92
  86. package/src/tools/types.ts +0 -15
  87. package/src/utils/attachment-utils.ts +0 -479
  88. package/src/utils/auth-token.ts +0 -22
  89. package/src/utils/format.ts +0 -42
  90. package/src/utils/i18n.ts +0 -653
  91. package/src/utils/model-discovery.ts +0 -290
  92. package/src/utils/proxy-utils.ts +0 -139
  93. package/src/utils/test-sessions.ts +0 -2357
  94. package/tsconfig.build.json +0 -20
  95. package/tsconfig.json +0 -7
@@ -1,114 +0,0 @@
1
- import type { RuntimeMessage, RuntimeResponse, SandboxRuntimeWindow } from "./runtime-messages.js";
2
- import type { SandboxRuntimeProvider } from "./SandboxRuntimeProvider.js";
3
-
4
- export interface DownloadableFile {
5
- fileName: string;
6
- content: string | Uint8Array;
7
- mimeType: string;
8
- }
9
-
10
- /**
11
- * File Download Runtime Provider
12
- *
13
- * Provides returnDownloadableFile() for creating user downloads.
14
- * Files returned this way are NOT accessible to the LLM later (one-time download).
15
- * Works both online (sends to extension) and offline (triggers browser download directly).
16
- * Collects files for retrieval by caller.
17
- */
18
- export class FileDownloadRuntimeProvider implements SandboxRuntimeProvider {
19
- private files: DownloadableFile[] = [];
20
-
21
- getData(): Record<string, unknown> {
22
- // No data needed
23
- return {};
24
- }
25
-
26
- getRuntime(): (sandboxId: string) => void {
27
- return (_sandboxId: string) => {
28
- const win = window as unknown as SandboxRuntimeWindow;
29
- win.returnDownloadableFile = async (fileName: string, content: unknown, mimeType?: string) => {
30
- let finalContent: string | Uint8Array, finalMimeType: string;
31
-
32
- if (content instanceof Blob) {
33
- const arrayBuffer = await content.arrayBuffer();
34
- finalContent = new Uint8Array(arrayBuffer);
35
- finalMimeType = mimeType || content.type || "application/octet-stream";
36
- if (!mimeType && !content.type) {
37
- throw new Error(
38
- "returnDownloadableFile: MIME type is required for Blob content. Please provide a mimeType parameter (e.g., 'image/png').",
39
- );
40
- }
41
- } else if (content instanceof Uint8Array) {
42
- finalContent = content;
43
- if (!mimeType) {
44
- throw new Error(
45
- "returnDownloadableFile: MIME type is required for Uint8Array content. Please provide a mimeType parameter (e.g., 'image/png').",
46
- );
47
- }
48
- finalMimeType = mimeType;
49
- } else if (typeof content === "string") {
50
- finalContent = content;
51
- finalMimeType = mimeType || "text/plain";
52
- } else {
53
- finalContent = JSON.stringify(content, null, 2);
54
- finalMimeType = mimeType || "application/json";
55
- }
56
-
57
- // Send to extension if in extension context (online mode)
58
- if (win.sendRuntimeMessage) {
59
- const response = await win.sendRuntimeMessage({
60
- type: "file-returned",
61
- fileName,
62
- content: finalContent,
63
- mimeType: finalMimeType,
64
- });
65
- if (response.error) throw new Error(response.error);
66
- } else {
67
- // Offline mode: trigger browser download directly
68
- const blobPart: BlobPart =
69
- typeof finalContent === "string" ? finalContent : new Uint8Array(finalContent);
70
- const blob = new Blob([blobPart], {
71
- type: finalMimeType,
72
- });
73
- const url = URL.createObjectURL(blob);
74
- const a = document.createElement("a");
75
- a.href = url;
76
- a.download = fileName;
77
- a.click();
78
- URL.revokeObjectURL(url);
79
- }
80
- };
81
- };
82
- }
83
-
84
- async handleMessage(message: RuntimeMessage, respond: (response: RuntimeResponse) => void): Promise<void> {
85
- if (message.type === "file-returned") {
86
- // Collect file for caller
87
- this.files.push({
88
- fileName: message.fileName,
89
- content: message.content,
90
- mimeType: message.mimeType,
91
- });
92
-
93
- respond({ success: true });
94
- }
95
- }
96
-
97
- /**
98
- * Get collected files
99
- */
100
- getFiles(): DownloadableFile[] {
101
- return this.files;
102
- }
103
-
104
- /**
105
- * Reset state for reuse
106
- */
107
- reset(): void {
108
- this.files = [];
109
- }
110
-
111
- getDescription(): string {
112
- return "returnDownloadableFile(filename, content, mimeType?) - Create downloadable file for user (one-time download, not accessible later)";
113
- }
114
- }
@@ -1,82 +0,0 @@
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
-
6
- export type MessageType = "request-response" | "fire-and-forget";
7
-
8
- export interface RuntimeMessageBridgeOptions {
9
- context: "sandbox-iframe" | "user-script";
10
- sandboxId: string;
11
- }
12
-
13
- // biome-ignore lint/complexity/noStaticOnlyClass: fine
14
- export class RuntimeMessageBridge {
15
- /**
16
- * Generate sendRuntimeMessage() function as injectable string.
17
- * Returns the function source code to be injected into target context.
18
- */
19
- static generateBridgeCode(options: RuntimeMessageBridgeOptions): string {
20
- if (options.context === "sandbox-iframe") {
21
- return RuntimeMessageBridge.generateSandboxBridge(options.sandboxId);
22
- } else {
23
- return RuntimeMessageBridge.generateUserScriptBridge(options.sandboxId);
24
- }
25
- }
26
-
27
- private static generateSandboxBridge(sandboxId: string): string {
28
- // Returns stringified function that uses window.parent.postMessage
29
- return `
30
- window.__completionCallbacks = [];
31
- window.sendRuntimeMessage = async (message) => {
32
- const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
33
-
34
- return new Promise((resolve, reject) => {
35
- const handler = (e) => {
36
- if (e.data.type === 'runtime-response' && e.data.messageId === messageId) {
37
- window.removeEventListener('message', handler);
38
- if (e.data.success) {
39
- resolve(e.data);
40
- } else {
41
- reject(new Error(e.data.error || 'Operation failed'));
42
- }
43
- }
44
- };
45
-
46
- window.addEventListener('message', handler);
47
-
48
- window.parent.postMessage({
49
- ...message,
50
- sandboxId: ${JSON.stringify(sandboxId)},
51
- messageId: messageId
52
- }, '*');
53
-
54
- // Timeout after 30s
55
- setTimeout(() => {
56
- window.removeEventListener('message', handler);
57
- reject(new Error('Runtime message timeout'));
58
- }, 30000);
59
- });
60
- };
61
- window.onCompleted = (callback) => {
62
- window.__completionCallbacks.push(callback);
63
- };
64
- `.trim();
65
- }
66
-
67
- private static generateUserScriptBridge(sandboxId: string): string {
68
- // Returns stringified function that uses chrome.runtime.sendMessage
69
- return `
70
- window.__completionCallbacks = [];
71
- window.sendRuntimeMessage = async (message) => {
72
- return await chrome.runtime.sendMessage({
73
- ...message,
74
- sandboxId: ${JSON.stringify(sandboxId)}
75
- });
76
- };
77
- window.onCompleted = (callback) => {
78
- window.__completionCallbacks.push(callback);
79
- };
80
- `.trim();
81
- }
82
- }
@@ -1,215 +0,0 @@
1
- import type { ChromeApi, RuntimeMessage, RuntimeResponse, UserScriptMessageListener } from "./runtime-messages.js";
2
- import type { SandboxRuntimeProvider } from "./SandboxRuntimeProvider.js";
3
-
4
- // Type declaration for chrome extension API (when available)
5
- declare const chrome: ChromeApi | undefined;
6
-
7
- /**
8
- * Message consumer interface - components that want to receive messages from sandboxes
9
- */
10
- export interface MessageConsumer {
11
- /**
12
- * Handle a message from a sandbox.
13
- * All consumers receive all messages - decide internally what to handle.
14
- */
15
- handleMessage(message: RuntimeMessage): Promise<void>;
16
- }
17
-
18
- /**
19
- * Sandbox context - tracks active sandboxes and their consumers
20
- */
21
- interface SandboxContext {
22
- sandboxId: string;
23
- iframe: HTMLIFrameElement | null; // null until setSandboxIframe() or null for user scripts
24
- providers: SandboxRuntimeProvider[];
25
- consumers: Set<MessageConsumer>;
26
- }
27
-
28
- /**
29
- * Centralized message router for all runtime communication.
30
- *
31
- * This singleton replaces all individual window.addEventListener("message") calls
32
- * with a single global listener that routes messages to the appropriate handlers.
33
- * Also handles user script messages from chrome.runtime.onUserScriptMessage.
34
- *
35
- * Benefits:
36
- * - Single global listener instead of multiple independent listeners
37
- * - Automatic cleanup when sandboxes are destroyed
38
- * - Support for bidirectional communication (providers) and broadcasting (consumers)
39
- * - Works with both sandbox iframes and user scripts
40
- * - Clear lifecycle management
41
- */
42
- export class RuntimeMessageRouter {
43
- private sandboxes = new Map<string, SandboxContext>();
44
- private messageListener: ((e: MessageEvent) => void) | null = null;
45
- private userScriptMessageListener: UserScriptMessageListener | null = null;
46
-
47
- /**
48
- * Register a new sandbox with its runtime providers.
49
- * Call this BEFORE creating the iframe (for sandbox contexts) or executing user script.
50
- */
51
- registerSandbox(sandboxId: string, providers: SandboxRuntimeProvider[], consumers: MessageConsumer[]): void {
52
- this.sandboxes.set(sandboxId, {
53
- sandboxId,
54
- iframe: null, // Will be set via setSandboxIframe() for sandbox contexts
55
- providers,
56
- consumers: new Set(consumers),
57
- });
58
-
59
- // Setup global listener if not already done
60
- this.setupListener();
61
- }
62
-
63
- /**
64
- * Update the iframe reference for a sandbox.
65
- * Call this AFTER creating the iframe.
66
- * This is needed so providers can send responses back to the sandbox.
67
- */
68
- setSandboxIframe(sandboxId: string, iframe: HTMLIFrameElement): void {
69
- const context = this.sandboxes.get(sandboxId);
70
- if (context) {
71
- context.iframe = iframe;
72
- }
73
- }
74
-
75
- /**
76
- * Unregister a sandbox and remove all its consumers.
77
- * Call this when the sandbox is destroyed.
78
- */
79
- unregisterSandbox(sandboxId: string): void {
80
- this.sandboxes.delete(sandboxId);
81
-
82
- // If no more sandboxes, remove global listeners
83
- if (this.sandboxes.size === 0) {
84
- // Remove iframe listener
85
- if (this.messageListener) {
86
- window.removeEventListener("message", this.messageListener);
87
- this.messageListener = null;
88
- }
89
-
90
- // Remove user script listener
91
- if (this.userScriptMessageListener && chrome?.runtime?.onUserScriptMessage) {
92
- chrome.runtime.onUserScriptMessage.removeListener(this.userScriptMessageListener);
93
- this.userScriptMessageListener = null;
94
- }
95
- }
96
- }
97
-
98
- /**
99
- * Add a message consumer for a sandbox.
100
- * Consumers receive broadcast messages (console, execution-complete, etc.)
101
- */
102
- addConsumer(sandboxId: string, consumer: MessageConsumer): void {
103
- const context = this.sandboxes.get(sandboxId);
104
- if (context) {
105
- context.consumers.add(consumer);
106
- }
107
- }
108
-
109
- /**
110
- * Remove a message consumer from a sandbox.
111
- */
112
- removeConsumer(sandboxId: string, consumer: MessageConsumer): void {
113
- const context = this.sandboxes.get(sandboxId);
114
- if (context) {
115
- context.consumers.delete(consumer);
116
- }
117
- }
118
-
119
- /**
120
- * Setup the global message listeners (called automatically)
121
- */
122
- private setupListener(): void {
123
- // Setup sandbox iframe listener
124
- if (!this.messageListener) {
125
- this.messageListener = async (e: MessageEvent) => {
126
- const { sandboxId, messageId } = e.data;
127
- if (!sandboxId) return;
128
-
129
- const context = this.sandboxes.get(sandboxId);
130
- if (!context) {
131
- return;
132
- }
133
-
134
- // Create respond() function for bidirectional communication
135
- const respond = (response: RuntimeResponse) => {
136
- context.iframe?.contentWindow?.postMessage(
137
- {
138
- type: "runtime-response",
139
- messageId,
140
- sandboxId,
141
- ...response,
142
- },
143
- "*",
144
- );
145
- };
146
-
147
- // 1. Try provider handlers first (for bidirectional comm)
148
- for (const provider of context.providers) {
149
- if (provider.handleMessage) {
150
- await provider.handleMessage(e.data, respond);
151
- // Don't stop - let consumers also handle the message
152
- }
153
- }
154
-
155
- // 2. Broadcast to consumers (one-way messages or lifecycle events)
156
- for (const consumer of context.consumers) {
157
- await consumer.handleMessage(e.data);
158
- // Don't stop - let all consumers see the message
159
- }
160
- };
161
-
162
- window.addEventListener("message", this.messageListener);
163
- }
164
-
165
- // Setup user script message listener
166
- if (!this.userScriptMessageListener) {
167
- // Guard: check if we're in extension context
168
- if (typeof chrome === "undefined" || !chrome.runtime?.onUserScriptMessage) {
169
- return;
170
- }
171
-
172
- this.userScriptMessageListener = (message, _sender, sendResponse) => {
173
- const { sandboxId } = message;
174
- if (!sandboxId) return false;
175
-
176
- const context = this.sandboxes.get(sandboxId);
177
- if (!context) return false;
178
-
179
- const respond = (response: RuntimeResponse) => {
180
- sendResponse({
181
- ...response,
182
- sandboxId,
183
- });
184
- };
185
-
186
- // Route to providers (async)
187
- (async () => {
188
- // 1. Try provider handlers first (for bidirectional comm)
189
- for (const provider of context.providers) {
190
- if (provider.handleMessage) {
191
- await provider.handleMessage(message, respond);
192
- // Don't stop - let consumers also handle the message
193
- }
194
- }
195
-
196
- // 2. Broadcast to consumers (one-way messages or lifecycle events)
197
- for (const consumer of context.consumers) {
198
- await consumer.handleMessage(message);
199
- // Don't stop - let all consumers see the message
200
- }
201
- })();
202
-
203
- return true; // Indicates async response
204
- };
205
-
206
- chrome.runtime.onUserScriptMessage.addListener(this.userScriptMessageListener);
207
- }
208
- }
209
- }
210
-
211
- /**
212
- * Global singleton instance.
213
- * Import this from wherever you need to interact with the message router.
214
- */
215
- export const RUNTIME_MESSAGE_ROUTER = new RuntimeMessageRouter();
@@ -1,54 +0,0 @@
1
- import type { RuntimeMessage, RuntimeResponse } from "./runtime-messages.js";
2
-
3
- /**
4
- * Interface for providing runtime capabilities to sandboxed iframes.
5
- * Each provider injects data and runtime functions into the sandbox context.
6
- */
7
- export interface SandboxRuntimeProvider {
8
- /**
9
- * Returns data to inject into window scope.
10
- * Keys become window properties (e.g., { attachments: [...] } -> window.attachments)
11
- */
12
- getData(): Record<string, unknown>;
13
-
14
- /**
15
- * Returns a runtime function that will be stringified and executed in the sandbox.
16
- * The function receives sandboxId and has access to data from getData() via window.
17
- *
18
- * IMPORTANT: This function will be converted to string via .toString() and injected
19
- * into the sandbox, so it cannot reference external variables or imports.
20
- */
21
- getRuntime(): (sandboxId: string) => void;
22
-
23
- /**
24
- * Optional message handler for bidirectional communication.
25
- * All providers receive all messages - decide internally what to handle.
26
- *
27
- * @param message - The message from the sandbox
28
- * @param respond - Function to send a response back to the sandbox
29
- */
30
- handleMessage?(message: RuntimeMessage, respond: (response: RuntimeResponse) => void): Promise<void>;
31
-
32
- /**
33
- * Optional documentation describing what globals/functions this provider injects.
34
- * This will be appended to tool descriptions dynamically so the LLM knows what's available.
35
- */
36
- getDescription(): string;
37
-
38
- /**
39
- * Optional lifecycle callback invoked when sandbox execution starts.
40
- * Providers can use this to track abort signals for cancellation of async operations.
41
- *
42
- * @param sandboxId - The unique identifier for this sandbox execution
43
- * @param signal - Optional AbortSignal that will be triggered if execution is cancelled
44
- */
45
- onExecutionStart?(sandboxId: string, signal?: AbortSignal): void;
46
-
47
- /**
48
- * Optional lifecycle callback invoked when sandbox execution ends (success, error, or abort).
49
- * Providers can use this to clean up any resources associated with the sandbox.
50
- *
51
- * @param sandboxId - The unique identifier for this sandbox execution
52
- */
53
- onExecutionEnd?(sandboxId: string): void;
54
- }
@@ -1,146 +0,0 @@
1
- /**
2
- * Shared types for the sandbox runtime messaging protocol.
3
- *
4
- * These describe the message envelopes exchanged between the host page
5
- * (SandboxedIframe / RuntimeMessageRouter / *RuntimeProvider classes) and the
6
- * sandboxed execution context (iframe or user script).
7
- */
8
-
9
- /** Fields attached to every message routed through the runtime bridge. */
10
- export interface RuntimeMessageEnvelope {
11
- sandboxId?: string;
12
- messageId?: string;
13
- }
14
-
15
- /** Artifact CRUD request issued from sandboxed code. */
16
- export type ArtifactOperationMessage =
17
- | { type: "artifact-operation"; action: "list" }
18
- | { type: "artifact-operation"; action: "get"; filename: string }
19
- | { type: "artifact-operation"; action: "delete"; filename: string }
20
- | {
21
- type: "artifact-operation";
22
- action: "createOrUpdate";
23
- filename: string;
24
- content: string;
25
- mimeType?: string;
26
- };
27
-
28
- /** Captured console output forwarded from sandboxed code. */
29
- export interface ConsoleRuntimeMessage {
30
- type: "console";
31
- method: string;
32
- text: string;
33
- args?: unknown[];
34
- }
35
-
36
- /** A one-time downloadable file returned from sandboxed code. */
37
- export interface FileReturnedMessage {
38
- type: "file-returned";
39
- fileName: string;
40
- content: string | Uint8Array;
41
- mimeType: string;
42
- }
43
-
44
- /** Successful execution lifecycle completion. */
45
- export interface ExecutionCompleteMessage {
46
- type: "execution-complete";
47
- returnValue?: unknown;
48
- }
49
-
50
- /** Failed execution lifecycle completion. */
51
- export interface ExecutionErrorMessage {
52
- type: "execution-error";
53
- error: { message: string; stack: string };
54
- }
55
-
56
- /** Discriminated union of all messages a provider/consumer can receive. */
57
- export type RuntimeMessage = RuntimeMessageEnvelope &
58
- (
59
- | ArtifactOperationMessage
60
- | ConsoleRuntimeMessage
61
- | FileReturnedMessage
62
- | ExecutionCompleteMessage
63
- | ExecutionErrorMessage
64
- );
65
-
66
- /** Response sent back to sandboxed code via the bridge. */
67
- export interface RuntimeResponse {
68
- success?: boolean;
69
- error?: string;
70
- result?: unknown;
71
- }
72
-
73
- /**
74
- * Shape of the resolved value of `window.sendRuntimeMessage` inside the sandbox.
75
- * Mirrors the `runtime-response` payload posted back by the router.
76
- */
77
- export interface SendRuntimeMessageResponse extends RuntimeResponse, RuntimeMessageEnvelope {
78
- type?: string;
79
- }
80
-
81
- /** A single attachment record injected into the sandbox via `window.attachments`. */
82
- export interface SandboxAttachment {
83
- id: string;
84
- fileName: string;
85
- mimeType: string;
86
- size: number;
87
- content: string;
88
- extractedText?: string;
89
- }
90
-
91
- /**
92
- * Window surface exposed inside the sandbox by the injected runtime functions.
93
- *
94
- * The runtime functions are stringified and injected, so this interface only
95
- * exists to type-check the function bodies at build time; the assertions are
96
- * erased from the emitted JavaScript.
97
- */
98
- export interface SandboxRuntimeWindow extends Window {
99
- sandboxId?: string;
100
- sendRuntimeMessage?: (message: Record<string, unknown>) => Promise<SendRuntimeMessageResponse>;
101
- onCompleted?: (callback: (success: boolean) => void | Promise<void>) => void;
102
- complete?: (error?: { message: string; stack: string } | null, returnValue?: unknown) => Promise<void>;
103
- __completionCallbacks?: Array<(success: boolean) => void | Promise<void>>;
104
- __originalConsole?: Record<"log" | "error" | "warn" | "info", (...args: unknown[]) => void>;
105
- artifacts?: Record<string, string>;
106
- attachments?: SandboxAttachment[];
107
- listArtifacts?: () => Promise<string[]>;
108
- getArtifact?: (filename: string) => Promise<unknown>;
109
- createOrUpdateArtifact?: (filename: string, content: unknown, mimeType?: string) => Promise<void>;
110
- deleteArtifact?: (filename: string) => Promise<void>;
111
- listAttachments?: () => Array<{ id: string; fileName: string; mimeType: string; size: number }>;
112
- readTextAttachment?: (attachmentId: string) => string;
113
- readBinaryAttachment?: (attachmentId: string) => Uint8Array;
114
- returnDownloadableFile?: (fileName: string, content: unknown, mimeType?: string) => Promise<void>;
115
- }
116
-
117
- /** Listener registered with `chrome.runtime.onUserScriptMessage`. */
118
- export type UserScriptMessageListener = (
119
- message: RuntimeMessage,
120
- sender: unknown,
121
- sendResponse: (response: RuntimeResponse & RuntimeMessageEnvelope) => void,
122
- ) => boolean;
123
-
124
- /** Minimal subset of the `chrome.runtime.onUserScriptMessage` event API. */
125
- export interface ChromeUserScriptMessageEvent {
126
- addListener(listener: UserScriptMessageListener): void;
127
- removeListener(listener: UserScriptMessageListener): void;
128
- }
129
-
130
- /** Minimal subset of `chrome.runtime` used by the runtime router/bridge. */
131
- export interface ChromeRuntime {
132
- onUserScriptMessage?: ChromeUserScriptMessageEvent;
133
- sendMessage?(message: unknown): Promise<unknown>;
134
- getURL?(path: string): string;
135
- }
136
-
137
- /** Minimal subset of `chrome.tabs` used to open external URLs. */
138
- export interface ChromeTabs {
139
- create(createProperties: { url: string }): void;
140
- }
141
-
142
- /** Minimal subset of the chrome extension API surface used by the sandbox. */
143
- export interface ChromeApi {
144
- runtime?: ChromeRuntime;
145
- tabs?: ChromeTabs;
146
- }
@@ -1,75 +0,0 @@
1
- import { customElement, state } from "lit/decorators.js";
2
- import "../components/ProviderKeyInput.js";
3
- import { DialogContent, DialogHeader } from "@elyracode/mini-lit/dist/Dialog.js";
4
- import { DialogBase } from "@elyracode/mini-lit/dist/DialogBase.js";
5
- import { html } from "lit";
6
- import { getAppStorage } from "../storage/app-storage.js";
7
- import { i18n } from "../utils/i18n.js";
8
-
9
- @customElement("api-key-prompt-dialog")
10
- export class ApiKeyPromptDialog extends DialogBase {
11
- @state() private provider = "";
12
-
13
- private resolvePromise?: (success: boolean) => void;
14
- private unsubscribe?: () => void;
15
-
16
- protected modalWidth = "min(500px, 90vw)";
17
- protected modalHeight = "auto";
18
-
19
- static async prompt(provider: string): Promise<boolean> {
20
- const dialog = new ApiKeyPromptDialog();
21
- dialog.provider = provider;
22
- dialog.open();
23
-
24
- return new Promise((resolve) => {
25
- dialog.resolvePromise = resolve;
26
- });
27
- }
28
-
29
- override async connectedCallback() {
30
- super.connectedCallback();
31
-
32
- // Poll for key existence - when key is added, resolve and close
33
- const checkInterval = setInterval(async () => {
34
- const hasKey = !!(await getAppStorage().providerKeys.get(this.provider));
35
- if (hasKey) {
36
- clearInterval(checkInterval);
37
- if (this.resolvePromise) {
38
- this.resolvePromise(true);
39
- this.resolvePromise = undefined;
40
- }
41
- this.close();
42
- }
43
- }, 500);
44
-
45
- this.unsubscribe = () => clearInterval(checkInterval);
46
- }
47
-
48
- override disconnectedCallback() {
49
- super.disconnectedCallback();
50
- if (this.unsubscribe) {
51
- this.unsubscribe();
52
- this.unsubscribe = undefined;
53
- }
54
- }
55
-
56
- override close() {
57
- super.close();
58
- if (this.resolvePromise) {
59
- this.resolvePromise(false);
60
- }
61
- }
62
-
63
- protected override renderContent() {
64
- return html`
65
- ${DialogContent({
66
- children: html`
67
- ${DialogHeader({
68
- title: i18n("API Key Required"),
69
- })}
70
- <provider-key-input .provider=${this.provider}></provider-key-input>
71
- `,
72
- })}
73
- `;
74
- }
75
- }