@elyracode/web-ui 0.9.58 → 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 +13 -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,290 +0,0 @@
1
- import type { Api, Model } from "@elyracode/ai";
2
- import { LMStudioClient } from "@lmstudio/sdk";
3
- import { Ollama } from "ollama/browser";
4
-
5
- /** Minimal shape of a model entry from an OpenAI-compatible /v1/models endpoint. */
6
- interface OpenAICompatibleModel {
7
- id: string;
8
- context_length?: number;
9
- max_tokens?: number;
10
- max_model_len?: number;
11
- }
12
-
13
- /** Minimal shape of the response from an OpenAI-compatible /v1/models endpoint. */
14
- interface OpenAICompatibleModelsResponse {
15
- data?: OpenAICompatibleModel[];
16
- }
17
-
18
- /**
19
- * Discover models from an Ollama server.
20
- * @param baseUrl - Base URL of the Ollama server (e.g., "http://localhost:11434")
21
- * @param apiKey - Optional API key (currently unused by Ollama)
22
- * @returns Array of discovered models
23
- */
24
- export async function discoverOllamaModels(baseUrl: string, _apiKey?: string): Promise<Model<Api>[]> {
25
- try {
26
- // Create Ollama client
27
- const ollama = new Ollama({ host: baseUrl });
28
-
29
- // Get list of available models
30
- const { models } = await ollama.list();
31
-
32
- // Fetch details for each model and convert to Model format
33
- const ollamaModelPromises: Promise<Model<Api> | null>[] = models.map(async (model) => {
34
- try {
35
- // Get model details
36
- const details = await ollama.show({
37
- model: model.name,
38
- });
39
-
40
- // Check capabilities - filter out models that don't support tools
41
- const capabilities: string[] = details.capabilities || [];
42
- if (!capabilities.includes("tools")) {
43
- console.debug(`Skipping model ${model.name}: does not support tools`);
44
- return null;
45
- }
46
-
47
- // Extract model info
48
- const modelInfo = (details.model_info || {}) as unknown as Record<string, string>;
49
-
50
- // Get context window size - look for architecture-specific keys
51
- const architecture = modelInfo["general.architecture"] || "";
52
- const contextKey = `${architecture}.context_length`;
53
- const contextWindow = parseInt(modelInfo[contextKey] || "8192", 10);
54
-
55
- // Ollama caps max tokens at 10x context length
56
- const maxTokens = contextWindow * 10;
57
-
58
- // Ollama only supports completions API
59
- const ollamaModel: Model<Api> = {
60
- id: model.name,
61
- name: model.name,
62
- api: "openai-completions",
63
- provider: "", // Will be set by caller
64
- baseUrl: `${baseUrl}/v1`,
65
- reasoning: capabilities.includes("thinking"),
66
- input: ["text"],
67
- cost: {
68
- input: 0,
69
- output: 0,
70
- cacheRead: 0,
71
- cacheWrite: 0,
72
- },
73
- contextWindow: contextWindow,
74
- maxTokens: maxTokens,
75
- };
76
-
77
- return ollamaModel;
78
- } catch (err) {
79
- console.error(`Failed to fetch details for model ${model.name}:`, err);
80
- return null;
81
- }
82
- });
83
-
84
- const results = await Promise.all(ollamaModelPromises);
85
- return results.filter((m): m is Model<Api> => m !== null);
86
- } catch (err) {
87
- console.error("Failed to discover Ollama models:", err);
88
- throw new Error(`Ollama discovery failed: ${err instanceof Error ? err.message : String(err)}`);
89
- }
90
- }
91
-
92
- /**
93
- * Discover models from a llama.cpp server via OpenAI-compatible /v1/models endpoint.
94
- * @param baseUrl - Base URL of the llama.cpp server (e.g., "http://localhost:8080")
95
- * @param apiKey - Optional API key
96
- * @returns Array of discovered models
97
- */
98
- export async function discoverLlamaCppModels(baseUrl: string, apiKey?: string): Promise<Model<Api>[]> {
99
- try {
100
- const headers: HeadersInit = {
101
- "Content-Type": "application/json",
102
- };
103
-
104
- if (apiKey) {
105
- headers.Authorization = `Bearer ${apiKey}`;
106
- }
107
-
108
- const response = await fetch(`${baseUrl}/v1/models`, {
109
- method: "GET",
110
- headers,
111
- });
112
-
113
- if (!response.ok) {
114
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
115
- }
116
-
117
- const data = (await response.json()) as OpenAICompatibleModelsResponse;
118
-
119
- if (!data.data || !Array.isArray(data.data)) {
120
- throw new Error("Invalid response format from llama.cpp server");
121
- }
122
-
123
- return data.data.map((model) => {
124
- // llama.cpp doesn't always provide context window info
125
- const contextWindow = model.context_length || 8192;
126
- const maxTokens = model.max_tokens || 4096;
127
-
128
- const llamaModel: Model<Api> = {
129
- id: model.id,
130
- name: model.id,
131
- api: "openai-completions",
132
- provider: "", // Will be set by caller
133
- baseUrl: `${baseUrl}/v1`,
134
- reasoning: false,
135
- input: ["text"],
136
- cost: {
137
- input: 0,
138
- output: 0,
139
- cacheRead: 0,
140
- cacheWrite: 0,
141
- },
142
- contextWindow: contextWindow,
143
- maxTokens: maxTokens,
144
- };
145
-
146
- return llamaModel;
147
- });
148
- } catch (err) {
149
- console.error("Failed to discover llama.cpp models:", err);
150
- throw new Error(`llama.cpp discovery failed: ${err instanceof Error ? err.message : String(err)}`);
151
- }
152
- }
153
-
154
- /**
155
- * Discover models from a vLLM server via OpenAI-compatible /v1/models endpoint.
156
- * @param baseUrl - Base URL of the vLLM server (e.g., "http://localhost:8000")
157
- * @param apiKey - Optional API key
158
- * @returns Array of discovered models
159
- */
160
- export async function discoverVLLMModels(baseUrl: string, apiKey?: string): Promise<Model<Api>[]> {
161
- try {
162
- const headers: HeadersInit = {
163
- "Content-Type": "application/json",
164
- };
165
-
166
- if (apiKey) {
167
- headers.Authorization = `Bearer ${apiKey}`;
168
- }
169
-
170
- const response = await fetch(`${baseUrl}/v1/models`, {
171
- method: "GET",
172
- headers,
173
- });
174
-
175
- if (!response.ok) {
176
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
177
- }
178
-
179
- const data = (await response.json()) as OpenAICompatibleModelsResponse;
180
-
181
- if (!data.data || !Array.isArray(data.data)) {
182
- throw new Error("Invalid response format from vLLM server");
183
- }
184
-
185
- return data.data.map((model) => {
186
- // vLLM provides max_model_len which is the context window
187
- const contextWindow = model.max_model_len || 8192;
188
- const maxTokens = Math.min(contextWindow, 4096); // Cap max tokens
189
-
190
- const vllmModel: Model<Api> = {
191
- id: model.id,
192
- name: model.id,
193
- api: "openai-completions",
194
- provider: "", // Will be set by caller
195
- baseUrl: `${baseUrl}/v1`,
196
- reasoning: false,
197
- input: ["text"],
198
- cost: {
199
- input: 0,
200
- output: 0,
201
- cacheRead: 0,
202
- cacheWrite: 0,
203
- },
204
- contextWindow: contextWindow,
205
- maxTokens: maxTokens,
206
- };
207
-
208
- return vllmModel;
209
- });
210
- } catch (err) {
211
- console.error("Failed to discover vLLM models:", err);
212
- throw new Error(`vLLM discovery failed: ${err instanceof Error ? err.message : String(err)}`);
213
- }
214
- }
215
-
216
- /**
217
- * Discover models from an LM Studio server using the LM Studio SDK.
218
- * @param baseUrl - Base URL of the LM Studio server (e.g., "http://localhost:1234")
219
- * @param apiKey - Optional API key (unused for LM Studio SDK)
220
- * @returns Array of discovered models
221
- */
222
- export async function discoverLMStudioModels(baseUrl: string, _apiKey?: string): Promise<Model<Api>[]> {
223
- try {
224
- // Extract host and port from baseUrl
225
- const url = new URL(baseUrl);
226
- const port = url.port ? parseInt(url.port, 10) : 1234;
227
-
228
- // Create LM Studio client
229
- const client = new LMStudioClient({ baseUrl: `ws://${url.hostname}:${port}` });
230
-
231
- // List all downloaded models
232
- const models = await client.system.listDownloadedModels();
233
-
234
- // Filter to only LLM models and map to our Model format
235
- return models
236
- .filter((model) => model.type === "llm")
237
- .map((model) => {
238
- const contextWindow = model.maxContextLength;
239
- // Use 10x context length like Ollama does
240
- const maxTokens = contextWindow;
241
-
242
- const lmStudioModel: Model<Api> = {
243
- id: model.path,
244
- name: model.displayName || model.path,
245
- api: "openai-completions",
246
- provider: "", // Will be set by caller
247
- baseUrl: `${baseUrl}/v1`,
248
- reasoning: model.trainedForToolUse || false,
249
- input: model.vision ? ["text", "image"] : ["text"],
250
- cost: {
251
- input: 0,
252
- output: 0,
253
- cacheRead: 0,
254
- cacheWrite: 0,
255
- },
256
- contextWindow: contextWindow,
257
- maxTokens: maxTokens,
258
- };
259
-
260
- return lmStudioModel;
261
- });
262
- } catch (err) {
263
- console.error("Failed to discover LM Studio models:", err);
264
- throw new Error(`LM Studio discovery failed: ${err instanceof Error ? err.message : String(err)}`);
265
- }
266
- }
267
-
268
- /**
269
- * Convenience function to discover models based on provider type.
270
- * @param type - Provider type
271
- * @param baseUrl - Base URL of the server
272
- * @param apiKey - Optional API key
273
- * @returns Array of discovered models
274
- */
275
- export async function discoverModels(
276
- type: "ollama" | "llama.cpp" | "vllm" | "lmstudio",
277
- baseUrl: string,
278
- apiKey?: string,
279
- ): Promise<Model<Api>[]> {
280
- switch (type) {
281
- case "ollama":
282
- return discoverOllamaModels(baseUrl, apiKey);
283
- case "llama.cpp":
284
- return discoverLlamaCppModels(baseUrl, apiKey);
285
- case "vllm":
286
- return discoverVLLMModels(baseUrl, apiKey);
287
- case "lmstudio":
288
- return discoverLMStudioModels(baseUrl, apiKey);
289
- }
290
- }
@@ -1,139 +0,0 @@
1
- import type { Api, Context, Model, SimpleStreamOptions } from "@elyracode/ai";
2
- import { streamSimple } from "@elyracode/ai";
3
-
4
- /**
5
- * Centralized proxy decision logic.
6
- *
7
- * Determines whether to use a CORS proxy for LLM API requests based on:
8
- * - Provider name
9
- * - API key pattern (for providers where it matters)
10
- */
11
-
12
- /**
13
- * Check if a provider/API key combination requires a CORS proxy.
14
- *
15
- * @param provider - Provider name (e.g., "anthropic", "openai", "zai")
16
- * @param apiKey - API key for the provider
17
- * @returns true if proxy is required, false otherwise
18
- */
19
- export function shouldUseProxyForProvider(provider: string, apiKey: string): boolean {
20
- switch (provider.toLowerCase()) {
21
- case "zai":
22
- // Z-AI always requires proxy
23
- return true;
24
-
25
- case "anthropic":
26
- // Anthropic OAuth tokens (sk-ant-oat-*) require proxy
27
- // Regular API keys (sk-ant-api-*) do NOT require proxy
28
- return apiKey.startsWith("sk-ant-oat") || apiKey.startsWith("{");
29
-
30
- case "openai-codex":
31
- // Codex uses chatgpt.com/backend-api which has no CORS
32
- return true;
33
-
34
- // These providers work without proxy
35
- case "openai":
36
- case "google":
37
- case "groq":
38
- case "openrouter":
39
- case "cerebras":
40
- case "xai":
41
- case "ollama":
42
- case "lmstudio":
43
- case "github-copilot":
44
- return false;
45
-
46
- // Unknown providers - assume no proxy needed
47
- // This allows new providers to work by default
48
- default:
49
- return false;
50
- }
51
- }
52
-
53
- /**
54
- * Apply CORS proxy to a model's baseUrl if needed.
55
- *
56
- * @param model - The model to potentially proxy
57
- * @param apiKey - API key for the provider
58
- * @param proxyUrl - CORS proxy URL (e.g., "https://proxy.mariozechner.at/proxy")
59
- * @returns Model with modified baseUrl if proxy is needed, otherwise original model
60
- */
61
- export function applyProxyIfNeeded<T extends Api>(model: Model<T>, apiKey: string, proxyUrl?: string): Model<T> {
62
- // If no proxy URL configured, return original model
63
- if (!proxyUrl) {
64
- return model;
65
- }
66
-
67
- // If model has no baseUrl, can't proxy it
68
- if (!model.baseUrl) {
69
- return model;
70
- }
71
-
72
- // Check if this provider/key needs proxy
73
- if (!shouldUseProxyForProvider(model.provider, apiKey)) {
74
- return model;
75
- }
76
-
77
- // Apply proxy to baseUrl
78
- return {
79
- ...model,
80
- baseUrl: `${proxyUrl}/?url=${encodeURIComponent(model.baseUrl)}`,
81
- };
82
- }
83
-
84
- /**
85
- * Check if an error is likely a CORS error.
86
- *
87
- * CORS errors in browsers typically manifest as:
88
- * - TypeError with message "Failed to fetch"
89
- * - NetworkError
90
- *
91
- * @param error - The error to check
92
- * @returns true if error is likely a CORS error
93
- */
94
- export function isCorsError(error: unknown): boolean {
95
- if (!(error instanceof Error)) {
96
- return false;
97
- }
98
-
99
- // Check for common CORS error patterns
100
- const message = error.message.toLowerCase();
101
-
102
- // "Failed to fetch" is the standard CORS error in most browsers
103
- if (error.name === "TypeError" && message.includes("failed to fetch")) {
104
- return true;
105
- }
106
-
107
- // Some browsers report "NetworkError"
108
- if (error.name === "NetworkError") {
109
- return true;
110
- }
111
-
112
- // CORS-specific messages
113
- if (message.includes("cors") || message.includes("cross-origin")) {
114
- return true;
115
- }
116
-
117
- return false;
118
- }
119
-
120
- /**
121
- * Create a streamFn that applies CORS proxy when needed.
122
- * Reads proxy settings from storage on each call.
123
- *
124
- * @param getProxyUrl - Async function to get current proxy URL (or undefined if disabled)
125
- * @returns A streamFn compatible with Agent's streamFn option
126
- */
127
- export function createStreamFn(getProxyUrl: () => Promise<string | undefined>) {
128
- return async (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => {
129
- const apiKey = options?.apiKey;
130
- const proxyUrl = await getProxyUrl();
131
-
132
- if (!apiKey || !proxyUrl) {
133
- return streamSimple(model, context, options);
134
- }
135
-
136
- const proxiedModel = applyProxyIfNeeded(model, apiKey, proxyUrl);
137
- return streamSimple(proxiedModel, context, options);
138
- };
139
- }