@draht/web-ui 2026.7.13 → 2026.9.5-1

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 (91) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/app.css +1 -1
  3. package/dist/components/AgentInterface.d.ts +1 -1
  4. package/dist/components/AgentInterface.d.ts.map +1 -1
  5. package/dist/components/AgentInterface.js +11 -5
  6. package/dist/components/AgentInterface.js.map +1 -1
  7. package/package.json +10 -5
  8. package/example/README.md +0 -61
  9. package/example/index.html +0 -13
  10. package/example/package.json +0 -25
  11. package/example/src/app.css +0 -1
  12. package/example/src/custom-messages.ts +0 -99
  13. package/example/src/env.d.ts +0 -1
  14. package/example/src/main.ts +0 -421
  15. package/example/tsconfig.json +0 -23
  16. package/example/vite.config.ts +0 -6
  17. package/scripts/count-prompt-tokens.ts +0 -88
  18. package/src/ChatPanel.ts +0 -209
  19. package/src/app.css +0 -68
  20. package/src/components/AgentInterface.ts +0 -403
  21. package/src/components/AttachmentTile.ts +0 -107
  22. package/src/components/ConsoleBlock.ts +0 -72
  23. package/src/components/CustomProviderCard.ts +0 -100
  24. package/src/components/ExpandableSection.ts +0 -46
  25. package/src/components/Input.ts +0 -113
  26. package/src/components/MessageEditor.ts +0 -405
  27. package/src/components/MessageList.ts +0 -98
  28. package/src/components/Messages.ts +0 -383
  29. package/src/components/ProviderKeyInput.ts +0 -153
  30. package/src/components/SandboxedIframe.ts +0 -626
  31. package/src/components/StreamingMessageContainer.ts +0 -103
  32. package/src/components/ThinkingBlock.ts +0 -43
  33. package/src/components/message-renderer-registry.ts +0 -28
  34. package/src/components/sandbox/ArtifactsRuntimeProvider.ts +0 -220
  35. package/src/components/sandbox/AttachmentsRuntimeProvider.ts +0 -66
  36. package/src/components/sandbox/ConsoleRuntimeProvider.ts +0 -186
  37. package/src/components/sandbox/FileDownloadRuntimeProvider.ts +0 -110
  38. package/src/components/sandbox/RuntimeMessageBridge.ts +0 -82
  39. package/src/components/sandbox/RuntimeMessageRouter.ts +0 -216
  40. package/src/components/sandbox/SandboxRuntimeProvider.ts +0 -52
  41. package/src/dialogs/ApiKeyPromptDialog.ts +0 -75
  42. package/src/dialogs/AttachmentOverlay.ts +0 -636
  43. package/src/dialogs/CustomProviderDialog.ts +0 -274
  44. package/src/dialogs/ModelSelector.ts +0 -370
  45. package/src/dialogs/PersistentStorageDialog.ts +0 -144
  46. package/src/dialogs/ProvidersModelsTab.ts +0 -212
  47. package/src/dialogs/SessionListDialog.ts +0 -150
  48. package/src/dialogs/SettingsDialog.ts +0 -218
  49. package/src/index.ts +0 -120
  50. package/src/prompts/prompts.ts +0 -282
  51. package/src/storage/app-storage.ts +0 -60
  52. package/src/storage/backends/indexeddb-storage-backend.ts +0 -193
  53. package/src/storage/store.ts +0 -33
  54. package/src/storage/stores/custom-providers-store.ts +0 -62
  55. package/src/storage/stores/provider-keys-store.ts +0 -33
  56. package/src/storage/stores/sessions-store.ts +0 -136
  57. package/src/storage/stores/settings-store.ts +0 -34
  58. package/src/storage/types.ts +0 -206
  59. package/src/tools/artifacts/ArtifactElement.ts +0 -14
  60. package/src/tools/artifacts/ArtifactPill.ts +0 -26
  61. package/src/tools/artifacts/Console.ts +0 -93
  62. package/src/tools/artifacts/DocxArtifact.ts +0 -213
  63. package/src/tools/artifacts/ExcelArtifact.ts +0 -231
  64. package/src/tools/artifacts/GenericArtifact.ts +0 -117
  65. package/src/tools/artifacts/HtmlArtifact.ts +0 -195
  66. package/src/tools/artifacts/ImageArtifact.ts +0 -116
  67. package/src/tools/artifacts/MarkdownArtifact.ts +0 -82
  68. package/src/tools/artifacts/PdfArtifact.ts +0 -201
  69. package/src/tools/artifacts/SvgArtifact.ts +0 -119
  70. package/src/tools/artifacts/TextArtifact.ts +0 -148
  71. package/src/tools/artifacts/artifacts-tool-renderer.ts +0 -310
  72. package/src/tools/artifacts/artifacts.ts +0 -713
  73. package/src/tools/artifacts/index.ts +0 -7
  74. package/src/tools/extract-document.ts +0 -275
  75. package/src/tools/index.ts +0 -46
  76. package/src/tools/javascript-repl.ts +0 -293
  77. package/src/tools/renderer-registry.ts +0 -130
  78. package/src/tools/renderers/BashRenderer.ts +0 -52
  79. package/src/tools/renderers/CalculateRenderer.ts +0 -58
  80. package/src/tools/renderers/DefaultRenderer.ts +0 -103
  81. package/src/tools/renderers/GetCurrentTimeRenderer.ts +0 -92
  82. package/src/tools/types.ts +0 -15
  83. package/src/utils/attachment-utils.ts +0 -472
  84. package/src/utils/auth-token.ts +0 -22
  85. package/src/utils/format.ts +0 -42
  86. package/src/utils/i18n.ts +0 -653
  87. package/src/utils/model-discovery.ts +0 -277
  88. package/src/utils/proxy-utils.ts +0 -139
  89. package/src/utils/test-sessions.ts +0 -2357
  90. package/tsconfig.build.json +0 -20
  91. package/tsconfig.json +0 -7
@@ -1,405 +0,0 @@
1
- import type { Model } from "@draht/ai/compat";
2
- import { icon } from "@mariozechner/mini-lit";
3
- import { Button } from "@mariozechner/mini-lit/dist/Button.js";
4
- import { Select, type SelectOption } from "@mariozechner/mini-lit/dist/Select.js";
5
- import { html, LitElement } from "lit";
6
- import { customElement, property, state } from "lit/decorators.js";
7
- import { createRef, ref } from "lit/directives/ref.js";
8
- import { Brain, Loader2, Paperclip, Send, Sparkles, Square } from "lucide";
9
- import { type Attachment, loadAttachment } from "../utils/attachment-utils.js";
10
- import { i18n } from "../utils/i18n.js";
11
- import "./AttachmentTile.js";
12
- import type { ThinkingLevel } from "@draht/agent-core";
13
-
14
- @customElement("message-editor")
15
- export class MessageEditor extends LitElement {
16
- private _value = "";
17
- private textareaRef = createRef<HTMLTextAreaElement>();
18
-
19
- @property()
20
- get value() {
21
- return this._value;
22
- }
23
-
24
- set value(val: string) {
25
- const oldValue = this._value;
26
- this._value = val;
27
- this.requestUpdate("value", oldValue);
28
- }
29
-
30
- @property() isStreaming = false;
31
- @property() currentModel?: Model<any>;
32
- @property() thinkingLevel: ThinkingLevel = "off";
33
- @property() showAttachmentButton = true;
34
- @property() showModelSelector = true;
35
- @property() showThinkingSelector = true;
36
- @property() onInput?: (value: string) => void;
37
- @property() onSend?: (input: string, attachments: Attachment[]) => void;
38
- @property() onAbort?: () => void;
39
- @property() onModelSelect?: () => void;
40
- @property() onThinkingChange?: (level: "off" | "minimal" | "low" | "medium" | "high") => void;
41
- @property() onFilesChange?: (files: Attachment[]) => void;
42
- @property() attachments: Attachment[] = [];
43
- @property() maxFiles = 10;
44
- @property() maxFileSize = 20 * 1024 * 1024; // 20MB
45
- @property() acceptedTypes =
46
- "image/*,application/pdf,.docx,.pptx,.xlsx,.xls,.txt,.md,.json,.xml,.html,.css,.js,.ts,.jsx,.tsx,.yml,.yaml";
47
-
48
- @state() processingFiles = false;
49
- @state() isDragging = false;
50
- private fileInputRef = createRef<HTMLInputElement>();
51
-
52
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
53
- return this;
54
- }
55
-
56
- private handleTextareaInput = (e: Event) => {
57
- const textarea = e.target as HTMLTextAreaElement;
58
- this.value = textarea.value;
59
- this.onInput?.(this.value);
60
- };
61
-
62
- private handleKeyDown = (e: KeyboardEvent) => {
63
- // Ignore key events during IME composition (e.g. CJK input)
64
- if (e.isComposing || e.key === "Process") return;
65
-
66
- if (e.key === "Enter" && !e.shiftKey) {
67
- e.preventDefault();
68
- if (!this.isStreaming && !this.processingFiles && (this.value.trim() || this.attachments.length > 0)) {
69
- this.handleSend();
70
- }
71
- } else if (e.key === "Escape" && this.isStreaming) {
72
- e.preventDefault();
73
- this.onAbort?.();
74
- }
75
- };
76
-
77
- private handlePaste = async (e: ClipboardEvent) => {
78
- const items = e.clipboardData?.items;
79
- if (!items) return;
80
-
81
- const imageFiles: File[] = [];
82
-
83
- // Check for image items in clipboard
84
- for (let i = 0; i < items.length; i++) {
85
- const item = items[i];
86
- if (item.type.startsWith("image/")) {
87
- const file = item.getAsFile();
88
- if (file) {
89
- imageFiles.push(file);
90
- }
91
- }
92
- }
93
-
94
- // If we found images, process them
95
- if (imageFiles.length > 0) {
96
- e.preventDefault(); // Prevent default paste behavior
97
-
98
- if (imageFiles.length + this.attachments.length > this.maxFiles) {
99
- alert(`Maximum ${this.maxFiles} files allowed`);
100
- return;
101
- }
102
-
103
- this.processingFiles = true;
104
- const newAttachments: Attachment[] = [];
105
-
106
- for (const file of imageFiles) {
107
- try {
108
- if (file.size > this.maxFileSize) {
109
- alert(`Image exceeds maximum size of ${Math.round(this.maxFileSize / 1024 / 1024)}MB`);
110
- continue;
111
- }
112
-
113
- const attachment = await loadAttachment(file);
114
- newAttachments.push(attachment);
115
- } catch (error) {
116
- console.error("Error processing pasted image:", error);
117
- alert(`Failed to process pasted image: ${String(error)}`);
118
- }
119
- }
120
-
121
- this.attachments = [...this.attachments, ...newAttachments];
122
- this.onFilesChange?.(this.attachments);
123
- this.processingFiles = false;
124
- }
125
- };
126
-
127
- private handleSend = () => {
128
- this.onSend?.(this.value, this.attachments);
129
- };
130
-
131
- private handleAttachmentClick = () => {
132
- this.fileInputRef.value?.click();
133
- };
134
-
135
- private async handleFilesSelected(e: Event) {
136
- const input = e.target as HTMLInputElement;
137
- const files = Array.from(input.files || []);
138
- if (files.length === 0) return;
139
-
140
- if (files.length + this.attachments.length > this.maxFiles) {
141
- alert(`Maximum ${this.maxFiles} files allowed`);
142
- input.value = "";
143
- return;
144
- }
145
-
146
- this.processingFiles = true;
147
- const newAttachments: Attachment[] = [];
148
-
149
- for (const file of files) {
150
- try {
151
- if (file.size > this.maxFileSize) {
152
- alert(`${file.name} exceeds maximum size of ${Math.round(this.maxFileSize / 1024 / 1024)}MB`);
153
- continue;
154
- }
155
-
156
- const attachment = await loadAttachment(file);
157
- newAttachments.push(attachment);
158
- } catch (error) {
159
- console.error(`Error processing ${file.name}:`, error);
160
- alert(`Failed to process ${file.name}: ${String(error)}`);
161
- }
162
- }
163
-
164
- this.attachments = [...this.attachments, ...newAttachments];
165
- this.onFilesChange?.(this.attachments);
166
- this.processingFiles = false;
167
- input.value = ""; // Reset input
168
- }
169
-
170
- private removeFile(fileId: string) {
171
- this.attachments = this.attachments.filter((f) => f.id !== fileId);
172
- this.onFilesChange?.(this.attachments);
173
- }
174
-
175
- private handleDragOver = (e: DragEvent) => {
176
- e.preventDefault();
177
- e.stopPropagation();
178
- if (!this.isDragging) {
179
- this.isDragging = true;
180
- }
181
- };
182
-
183
- private handleDragLeave = (e: DragEvent) => {
184
- e.preventDefault();
185
- e.stopPropagation();
186
- // Only set isDragging to false if we're leaving the entire component
187
- const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
188
- const x = e.clientX;
189
- const y = e.clientY;
190
- if (x <= rect.left || x >= rect.right || y <= rect.top || y >= rect.bottom) {
191
- this.isDragging = false;
192
- }
193
- };
194
-
195
- private handleDrop = async (e: DragEvent) => {
196
- e.preventDefault();
197
- e.stopPropagation();
198
- this.isDragging = false;
199
-
200
- const files = Array.from(e.dataTransfer?.files || []);
201
- if (files.length === 0) return;
202
-
203
- if (files.length + this.attachments.length > this.maxFiles) {
204
- alert(`Maximum ${this.maxFiles} files allowed`);
205
- return;
206
- }
207
-
208
- this.processingFiles = true;
209
- const newAttachments: Attachment[] = [];
210
-
211
- for (const file of files) {
212
- try {
213
- if (file.size > this.maxFileSize) {
214
- alert(`${file.name} exceeds maximum size of ${Math.round(this.maxFileSize / 1024 / 1024)}MB`);
215
- continue;
216
- }
217
-
218
- const attachment = await loadAttachment(file);
219
- newAttachments.push(attachment);
220
- } catch (error) {
221
- console.error(`Error processing ${file.name}:`, error);
222
- alert(`Failed to process ${file.name}: ${String(error)}`);
223
- }
224
- }
225
-
226
- this.attachments = [...this.attachments, ...newAttachments];
227
- this.onFilesChange?.(this.attachments);
228
- this.processingFiles = false;
229
- };
230
-
231
- override firstUpdated() {
232
- const textarea = this.textareaRef.value;
233
- if (textarea) {
234
- textarea.focus();
235
- }
236
- }
237
-
238
- override render() {
239
- // Check if current model supports thinking/reasoning
240
- const model = this.currentModel;
241
- const supportsThinking = model?.reasoning === true; // Models with reasoning:true support thinking
242
-
243
- return html`
244
- <div
245
- class="bg-card rounded-xl border shadow-sm relative ${this.isDragging ? "border-primary border-2 bg-primary/5" : "border-border"}"
246
- @dragover=${this.handleDragOver}
247
- @dragleave=${this.handleDragLeave}
248
- @drop=${this.handleDrop}
249
- >
250
- <!-- Drag overlay -->
251
- ${
252
- this.isDragging
253
- ? html`
254
- <div class="absolute inset-0 bg-primary/10 rounded-xl pointer-events-none z-10 flex items-center justify-center">
255
- <div class="text-primary font-medium">${i18n("Drop files here")}</div>
256
- </div>
257
- `
258
- : ""
259
- }
260
-
261
- <!-- Attachments -->
262
- ${
263
- this.attachments.length > 0
264
- ? html`
265
- <div class="px-4 pt-3 pb-2 flex flex-wrap gap-2">
266
- ${this.attachments.map(
267
- (attachment) => html`
268
- <attachment-tile
269
- .attachment=${attachment}
270
- .showDelete=${true}
271
- .onDelete=${() => this.removeFile(attachment.id)}
272
- ></attachment-tile>
273
- `,
274
- )}
275
- </div>
276
- `
277
- : ""
278
- }
279
-
280
- <textarea
281
- class="w-full bg-transparent p-4 text-foreground placeholder-muted-foreground outline-none resize-none overflow-y-auto"
282
- placeholder=${i18n("Type a message...")}
283
- rows="1"
284
- style="max-height: 200px; field-sizing: content; min-height: 1lh; height: auto;"
285
- .value=${this.value}
286
- @input=${this.handleTextareaInput}
287
- @keydown=${this.handleKeyDown}
288
- @paste=${this.handlePaste}
289
- ${ref(this.textareaRef)}
290
- ></textarea>
291
-
292
- <!-- Hidden file input -->
293
- <input
294
- type="file"
295
- ${ref(this.fileInputRef)}
296
- @change=${this.handleFilesSelected}
297
- accept=${this.acceptedTypes}
298
- multiple
299
- style="display: none;"
300
- />
301
-
302
- <!-- Button Row -->
303
- <div class="px-2 pb-2 flex items-center justify-between">
304
- <!-- Left side - attachment and thinking selector -->
305
- <div class="flex gap-2 items-center">
306
- ${
307
- this.showAttachmentButton
308
- ? this.processingFiles
309
- ? html`
310
- <div class="h-8 w-8 flex items-center justify-center">
311
- ${icon(Loader2, "sm", "animate-spin text-muted-foreground")}
312
- </div>
313
- `
314
- : html`
315
- ${Button({
316
- variant: "ghost",
317
- size: "icon",
318
- className: "h-8 w-8",
319
- onClick: this.handleAttachmentClick,
320
- children: icon(Paperclip, "sm"),
321
- })}
322
- `
323
- : ""
324
- }
325
- ${
326
- supportsThinking && this.showThinkingSelector
327
- ? html`
328
- ${Select({
329
- value: this.thinkingLevel,
330
- placeholder: i18n("Off"),
331
- options: [
332
- { value: "off", label: i18n("Off"), icon: icon(Brain, "sm") },
333
- { value: "minimal", label: i18n("Minimal"), icon: icon(Brain, "sm") },
334
- { value: "low", label: i18n("Low"), icon: icon(Brain, "sm") },
335
- { value: "medium", label: i18n("Medium"), icon: icon(Brain, "sm") },
336
- { value: "high", label: i18n("High"), icon: icon(Brain, "sm") },
337
- ] as SelectOption[],
338
- onChange: (value: string) => {
339
- const level = value as "off" | "minimal" | "low" | "medium" | "high";
340
- this.thinkingLevel = level;
341
- this.onThinkingChange?.(level);
342
- },
343
- width: "80px",
344
- size: "sm",
345
- variant: "ghost",
346
- fitContent: true,
347
- })}
348
- `
349
- : ""
350
- }
351
- </div>
352
-
353
- <!-- Model selector and send on the right -->
354
- <div class="flex gap-2 items-center">
355
- ${
356
- this.showModelSelector && this.currentModel
357
- ? html`
358
- ${Button({
359
- variant: "ghost",
360
- size: "sm",
361
- onClick: () => {
362
- // Focus textarea before opening model selector so focus returns there
363
- this.textareaRef.value?.focus();
364
- // Wait for next frame to ensure focus takes effect before dialog captures it
365
- requestAnimationFrame(() => {
366
- this.onModelSelect?.();
367
- });
368
- },
369
- children: html`
370
- ${icon(Sparkles, "sm")}
371
- <span class="ml-1">${this.currentModel.id}</span>
372
- `,
373
- className: "h-8 text-xs truncate",
374
- })}
375
- `
376
- : ""
377
- }
378
- ${
379
- this.isStreaming
380
- ? html`
381
- ${Button({
382
- variant: "ghost",
383
- size: "icon",
384
- onClick: this.onAbort,
385
- children: icon(Square, "sm"),
386
- className: "h-8 w-8",
387
- })}
388
- `
389
- : html`
390
- ${Button({
391
- variant: "ghost",
392
- size: "icon",
393
- onClick: this.handleSend,
394
- disabled: (!this.value.trim() && this.attachments.length === 0) || this.processingFiles,
395
- children: html`<div style="transform: rotate(-45deg)">${icon(Send, "sm")}</div>`,
396
- className: "h-8 w-8",
397
- })}
398
- `
399
- }
400
- </div>
401
- </div>
402
- </div>
403
- `;
404
- }
405
- }
@@ -1,98 +0,0 @@
1
- import type { AgentMessage, AgentTool } from "@draht/agent-core";
2
- import type {
3
- AssistantMessage as AssistantMessageType,
4
- ToolResultMessage as ToolResultMessageType,
5
- } from "@draht/ai/compat";
6
- import { html, LitElement, type TemplateResult } from "lit";
7
- import { property } from "lit/decorators.js";
8
- import { repeat } from "lit/directives/repeat.js";
9
- import { renderMessage } from "./message-renderer-registry.js";
10
-
11
- export class MessageList extends LitElement {
12
- @property({ type: Array }) messages: AgentMessage[] = [];
13
- @property({ type: Array }) tools: AgentTool[] = [];
14
- @property({ type: Object }) pendingToolCalls?: ReadonlySet<string>;
15
- @property({ type: Boolean }) isStreaming: boolean = false;
16
- @property({ attribute: false }) onCostClick?: () => void;
17
-
18
- protected override createRenderRoot(): HTMLElement | DocumentFragment {
19
- return this;
20
- }
21
-
22
- override connectedCallback(): void {
23
- super.connectedCallback();
24
- this.style.display = "block";
25
- }
26
-
27
- private buildRenderItems() {
28
- // Map tool results by call id for quick lookup
29
- const resultByCallId = new Map<string, ToolResultMessageType>();
30
- for (const message of this.messages) {
31
- if (message.role === "toolResult") {
32
- resultByCallId.set(message.toolCallId, message);
33
- }
34
- }
35
-
36
- const items: Array<{ key: string; template: TemplateResult }> = [];
37
- let index = 0;
38
- for (const msg of this.messages) {
39
- // Skip artifact messages - they're for session persistence only, not UI display
40
- if (msg.role === "artifact") {
41
- continue;
42
- }
43
-
44
- // Try custom renderer first
45
- const customTemplate = renderMessage(msg);
46
- if (customTemplate) {
47
- items.push({ key: `msg:${index}`, template: customTemplate });
48
- index++;
49
- continue;
50
- }
51
-
52
- // Fall back to built-in renderers
53
- if (msg.role === "user" || msg.role === "user-with-attachments") {
54
- items.push({
55
- key: `msg:${index}`,
56
- template: html`<user-message .message=${msg}></user-message>`,
57
- });
58
- index++;
59
- } else if (msg.role === "assistant") {
60
- const amsg = msg as AssistantMessageType;
61
- items.push({
62
- key: `msg:${index}`,
63
- template: html`<assistant-message
64
- .message=${amsg}
65
- .tools=${this.tools}
66
- .isStreaming=${false}
67
- .pendingToolCalls=${this.pendingToolCalls}
68
- .toolResultsById=${resultByCallId}
69
- .hideToolCalls=${false}
70
- .hidePendingToolCalls=${this.isStreaming}
71
- .onCostClick=${this.onCostClick}
72
- ></assistant-message>`,
73
- });
74
- index++;
75
- } else {
76
- // Skip standalone toolResult messages; they are rendered via paired tool-message above
77
- // Skip unknown roles
78
- }
79
- }
80
- return items;
81
- }
82
-
83
- override render() {
84
- const items = this.buildRenderItems();
85
- return html`<div class="flex flex-col gap-3">
86
- ${repeat(
87
- items,
88
- (it) => it.key,
89
- (it) => it.template,
90
- )}
91
- </div>`;
92
- }
93
- }
94
-
95
- // Register custom element
96
- if (!customElements.get("message-list")) {
97
- customElements.define("message-list", MessageList);
98
- }