@svadmin/ai-elements 0.5.1 → 0.7.4

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 (98) hide show
  1. package/README.md +0 -51
  2. package/dist/ai.css +153 -2740
  3. package/dist/components/AICommandBar.svelte +6 -4
  4. package/dist/components/ChatDialog.svelte +102 -125
  5. package/dist/components/ChatDialog.svelte.d.ts +3 -9
  6. package/dist/components/Conversation.svelte +34 -10
  7. package/dist/components/ConversationContent.svelte +1 -1
  8. package/dist/components/ConversationScrollButton.svelte +0 -1
  9. package/dist/components/CopilotPanel.svelte +8 -6
  10. package/dist/components/Message.svelte +1 -1
  11. package/dist/components/MessageActions.svelte +1 -1
  12. package/dist/components/MessageContent.svelte +1 -1
  13. package/dist/components/MessageToolbar.svelte +1 -1
  14. package/dist/components/Response.svelte +31 -11
  15. package/dist/components/Response.svelte.d.ts +2 -2
  16. package/dist/components/Tool.svelte +13 -13
  17. package/dist/components/Tool.svelte.d.ts +1 -1
  18. package/dist/components/action/Action.svelte +3 -1
  19. package/dist/components/artifact/ArtifactAction.svelte +3 -1
  20. package/dist/components/attachments/Attachment.svelte +4 -2
  21. package/dist/components/attachments/Attachments.svelte +3 -1
  22. package/dist/components/attachments/types.js +3 -2
  23. package/dist/components/audio-player/AudioPlayer.svelte.d.ts +1 -1
  24. package/dist/components/canvas/Canvas.svelte +1 -1
  25. package/dist/components/checkpoint/index.d.ts +2 -2
  26. package/dist/components/code/index.d.ts +18 -1
  27. package/dist/components/code/index.js +11 -1
  28. package/dist/components/code-block/CodeBlockLanguageSelector.svelte.d.ts +1 -1
  29. package/dist/components/code-block/highlight.js +10 -9
  30. package/dist/components/commit/Commit.svelte +23 -2
  31. package/dist/components/commit/CommitActions.svelte +2 -11
  32. package/dist/components/commit/CommitCopyButton.svelte +1 -1
  33. package/dist/components/commit/CommitHeader.svelte +12 -2
  34. package/dist/components/commit/context.svelte.d.ts +6 -0
  35. package/dist/components/commit/context.svelte.js +14 -0
  36. package/dist/components/context/Context.svelte +6 -4
  37. package/dist/components/context/TokensWithCost.svelte +2 -1
  38. package/dist/components/edge/Animated.svelte +6 -6
  39. package/dist/components/edge/Temporary.svelte +6 -5
  40. package/dist/components/file-tree/FileTree.svelte +7 -5
  41. package/dist/components/jsx-preview/parser.js +10 -10
  42. package/dist/components/message/MessageAction.svelte +3 -1
  43. package/dist/components/mic-selector/MicSelector.svelte.d.ts +1 -1
  44. package/dist/components/model-selector/ModelSelectorDialog.svelte +3 -1
  45. package/dist/components/open-in-chat/OpenInChatGPT.svelte +3 -1
  46. package/dist/components/open-in-chat/OpenInClaude.svelte +3 -1
  47. package/dist/components/open-in-chat/OpenInCursor.svelte +3 -1
  48. package/dist/components/open-in-chat/OpenInGitHub.svelte +3 -1
  49. package/dist/components/open-in-chat/OpenInScira.svelte +3 -1
  50. package/dist/components/open-in-chat/OpenInT3.svelte +3 -1
  51. package/dist/components/open-in-chat/OpenInv0.svelte +3 -1
  52. package/dist/components/package-info/PackageInfo.svelte +3 -1
  53. package/dist/components/prompt-input/PromptInput.svelte +8 -18
  54. package/dist/components/prompt-input/PromptInputCommand.svelte +2 -1
  55. package/dist/components/prompt-input/PromptInputSelect.svelte.d.ts +1 -1
  56. package/dist/components/prompt-input/PromptInputSubmit.svelte +5 -18
  57. package/dist/components/prompt-input/PromptInputTextarea.svelte +6 -11
  58. package/dist/components/prompt-input/context.svelte.d.ts +1 -8
  59. package/dist/components/prompt-input/files.js +3 -2
  60. package/dist/components/question/Question.svelte +3 -1
  61. package/dist/components/schema-display/SchemaDisplay.svelte +4 -2
  62. package/dist/components/schema-display/SchemaDisplayParameter.svelte +14 -1
  63. package/dist/components/schema-display/SchemaDisplayProperty.svelte +16 -1
  64. package/dist/components/snippet/index.d.ts +3 -3
  65. package/dist/components/stack-trace/StackTrace.svelte +7 -5
  66. package/dist/components/suggestion/index.d.ts +1 -1
  67. package/dist/components/terminal/Terminal.svelte +4 -2
  68. package/dist/components/terminal/ansi.js +9 -6
  69. package/dist/components/test-results/Test.svelte +1 -1
  70. package/dist/components/test-results/TestResults.svelte +1 -1
  71. package/dist/components/test-results/context.svelte.d.ts +1 -1
  72. package/dist/components/tool/ToolContent.svelte +1 -1
  73. package/dist/components/tool/ToolHeader.svelte +5 -5
  74. package/dist/components/tool/ToolInput.svelte +2 -4
  75. package/dist/components/tool/ToolOutput.svelte +2 -4
  76. package/dist/components/tool/ToolStatusBadge.svelte +2 -3
  77. package/dist/components/voice-selector/VoiceSelector.svelte +2 -1
  78. package/dist/components/voice-selector/VoiceSelector.svelte.d.ts +2 -2
  79. package/dist/components/voice-selector/context.svelte.d.ts +2 -1
  80. package/dist/components/web-preview/WebPreview.svelte +4 -3
  81. package/dist/contracts.d.ts +2 -2
  82. package/dist/generated-components.d.ts +15 -1
  83. package/dist/generated-components.js +20 -1
  84. package/dist/internal/Tooltip.svelte +2 -1
  85. package/dist/parity-manifest.d.ts +0 -1
  86. package/dist/parity-manifest.js +0 -97
  87. package/package.json +9 -19
  88. package/UPSTREAM_PARITY.md +0 -69
  89. package/dist/ai-theme.css +0 -28
  90. package/dist/ai.theme.css +0 -2771
  91. package/dist/components/code/code-variants.d.ts +0 -25
  92. package/dist/components/code/code-variants.js +0 -20
  93. package/dist/components/conversation/scroll.d.ts +0 -4
  94. package/dist/components/conversation/scroll.js +0 -85
  95. package/dist/components/message/content-polish-html.d.ts +0 -5
  96. package/dist/components/message/content-polish-html.js +0 -75
  97. package/dist/components/tool/content-polish-scroll-region.d.ts +0 -3
  98. package/dist/components/tool/content-polish-scroll-region.js +0 -22
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import { definedOptions } from '@svadmin/core/options';
3
+
2
4
  import {
3
5
  captureAdminContext,
4
6
  toggleTheme,
@@ -44,12 +46,12 @@
44
46
  const generatedId = $props.id();
45
47
  const provider = $derived(adminContext.chatProvider);
46
48
  const resources = $derived(adminContext.resources);
47
- const chatContext = $derived<ChatContext>({
49
+ const chatContext = $derived<ChatContext>(definedOptions({
48
50
  currentResource: parsed.resource,
49
51
  selectedRecordId: parsed.id,
50
52
  currentView: parsed.action,
51
53
  pathname: adminContext.currentPath(),
52
- });
54
+ }));
53
55
 
54
56
  let query = $state('');
55
57
  let answer = $state('');
@@ -126,12 +128,12 @@
126
128
  const scopedProvider: ChatProvider | null = provider;
127
129
  const prompt = query.trim();
128
130
  if (!scopedProvider || !prompt) return;
129
- const scopedContext: ChatContext = {
131
+ const scopedContext: ChatContext = definedOptions({
130
132
  currentResource: chatContext.currentResource,
131
133
  selectedRecordId: chatContext.selectedRecordId,
132
134
  currentView: chatContext.currentView,
133
135
  pathname: chatContext.pathname,
134
- };
136
+ });
135
137
 
136
138
  cancelRequest();
137
139
  const epoch = requestEpoch;
@@ -1,6 +1,16 @@
1
+ <script module lang="ts">
2
+ export type {
3
+ GeneratedComponentDefinition,
4
+ GeneratedComponentProps,
5
+ GeneratedComponentRegistry,
6
+ } from '../generated-components.js';
7
+ </script>
8
+
1
9
  <script lang="ts">
10
+ import { definedOptions } from '@svadmin/core/options';
11
+
2
12
  import { captureAdminContext, useParsed } from '@svadmin/core';
3
- import { Bot, Maximize2, MessageCircle, Minus, RotateCcw, Trash2, X } from '@lucide/svelte';
13
+ import { Bot, Maximize2, MessageCircle, Minus, Trash2, X } from '@lucide/svelte';
4
14
  import { onDestroy, tick, untrack, type Component } from 'svelte';
5
15
  import { SvelteMap } from 'svelte/reactivity';
6
16
  import type {
@@ -8,7 +18,7 @@
8
18
  AgentProvider,
9
19
  ChatAttachment,
10
20
  ChatContext,
11
- ChatMessage as ProviderMessage,
21
+ ChatMessage,
12
22
  ChatMessagePart,
13
23
  ChatProvider,
14
24
  ChatSource,
@@ -17,7 +27,6 @@
17
27
  import Conversation from './Conversation.svelte';
18
28
  import ConversationContent from './ConversationContent.svelte';
19
29
  import ConversationEmptyState from './ConversationEmptyState.svelte';
20
- import ConversationScrollButton from './ConversationScrollButton.svelte';
21
30
  import Message from './Message.svelte';
22
31
  import MessageContent from './MessageContent.svelte';
23
32
  import MessageToolbar from './MessageToolbar.svelte';
@@ -34,12 +43,6 @@
34
43
  type GeneratedComponentRegistry as ComponentRegistry,
35
44
  } from '../generated-components.js';
36
45
 
37
- export type {
38
- GeneratedComponentDefinition,
39
- GeneratedComponentProps,
40
- GeneratedComponentRegistry,
41
- } from '../generated-components.js';
42
-
43
46
  export type ChatPersistenceOperation = 'restore' | 'persist';
44
47
 
45
48
  export interface ChatPersistenceErrorDetail {
@@ -103,8 +106,6 @@
103
106
  };
104
107
 
105
108
  type ApprovalDecision = 'approved' | 'rejected';
106
- // Display-only provenance survives restore; it never grants approval capability.
107
- type ChatMessage = ProviderMessage & { approvalConfirmationFor?: string };
108
109
 
109
110
  let {
110
111
  docked = false,
@@ -125,39 +126,18 @@
125
126
  const parsed = useParsed();
126
127
  const provider = $derived(adminContext.chatProvider);
127
128
  const agent = $derived(adminContext.agentProvider);
128
- const chatContext = $derived.by((): ChatContext => ({
129
+ const chatContext = $derived.by((): ChatContext => (definedOptions({
129
130
  currentResource: parsed.resource,
130
131
  selectedRecordId: parsed.id,
131
132
  currentView: parsed.action as ChatContext['currentView'],
132
133
  pathname: adminContext.currentPath(),
133
- }));
134
+ })));
134
135
 
135
136
  let open = $state(false);
136
137
  let minimized = $state(false);
137
138
  let inputValue = $state('');
138
139
  let inputAttachments = $state<ChatAttachment[]>([]);
139
140
  let messages = $state<ChatMessage[]>([]);
140
- const retryCandidate = $derived.by(() => {
141
- let index = messages.length - 1;
142
- while (index >= 0 && messages[index].role !== 'assistant') index -= 1;
143
- const response = messages[index];
144
- const request = messages[index - 1];
145
- if (!response || request?.role !== 'user' ||
146
- (response.status !== 'error' && response.status !== 'aborted')) return;
147
- // Approval confirmations belong to this run; never discard a later draft message.
148
- if (!messages.slice(index + 1).every((message) =>
149
- message.role === 'user' && message.parts.length === 1 &&
150
- message.parts[0].type === 'text' && message.approvalConfirmationFor === response.id,
151
- )) return;
152
- const files = [
153
- ...(request.attachments ?? []),
154
- ...request.parts.flatMap((part) => part.type === 'file' ? [part.file] : []),
155
- ];
156
- const missingFiles = files.some((file) =>
157
- !file.file && (!safeResourceUrl(file.url) || file.url?.startsWith('blob:')),
158
- );
159
- return { id: response.id, index, missingFiles };
160
- });
161
141
  let isStreaming = $state(false);
162
142
  let chatRoot = $state<HTMLElement | null>(null);
163
143
  let launcherButton = $state<HTMLButtonElement | null>(null);
@@ -239,11 +219,11 @@
239
219
  if (part.type === 'text' && previous?.type === 'text') {
240
220
  parts[parts.length - 1] = { ...previous, text: previous.text + part.text };
241
221
  } else if (part.type === 'reasoning' && previous?.type === 'reasoning') {
242
- parts[parts.length - 1] = {
222
+ parts[parts.length - 1] = definedOptions({
243
223
  ...previous,
244
224
  text: previous.text + part.text,
245
225
  streaming: part.streaming ?? previous.streaming,
246
- };
226
+ });
247
227
  } else {
248
228
  parts.push(part);
249
229
  }
@@ -256,6 +236,7 @@
256
236
  ): ResolvedGeneratedComponent | { error: 'unavailable' | 'invalid' } {
257
237
  if (!Object.prototype.hasOwnProperty.call(componentRegistry, name)) return { error: 'unavailable' };
258
238
  const definition = componentRegistry[name];
239
+ if (!definition) return { error: 'unavailable' };
259
240
  try {
260
241
  const parsedProps = decodeGeneratedComponentProps(definition, props);
261
242
  return {
@@ -286,6 +267,24 @@
286
267
  }));
287
268
  }
288
269
 
270
+ function getConversationLog(): HTMLElement | null {
271
+ return chatRoot?.querySelector<HTMLElement>('[role="log"]') ?? null;
272
+ }
273
+
274
+ function shouldStickToBottom(): boolean {
275
+ const log = getConversationLog();
276
+ if (!log) return true;
277
+ return log.scrollHeight - log.scrollTop - log.clientHeight <= 64;
278
+ }
279
+
280
+ function scrollToBottomAfterUpdate(shouldScroll: boolean): void {
281
+ if (!shouldScroll || typeof window === 'undefined') return;
282
+ window.requestAnimationFrame(() => {
283
+ const log = getConversationLog();
284
+ log?.scrollTo({ top: log.scrollHeight, behavior: 'smooth' });
285
+ });
286
+ }
287
+
289
288
  function getChatStorage(): Storage | null {
290
289
  if (typeof window === 'undefined') return null;
291
290
  return window.localStorage;
@@ -341,13 +340,13 @@
341
340
  let snapshot: PersistSnapshot;
342
341
 
343
342
  if (callback) {
344
- snapshot = {
343
+ snapshot = definedOptions({
345
344
  sink: 'callback',
346
345
  key: restoredPersistKey ?? resolvedPersistKey,
347
346
  messages: persistedMessages,
348
347
  callback,
349
348
  errorHandler: onPersistenceError,
350
- };
349
+ });
351
350
  } else {
352
351
  const key = restoredPersistKey;
353
352
  if (key === null || !key || key !== resolvedPersistKey) return;
@@ -358,13 +357,13 @@
358
357
  reportPersistenceError('persist', error);
359
358
  return;
360
359
  }
361
- snapshot = {
360
+ snapshot = definedOptions({
362
361
  sink: 'storage',
363
362
  key,
364
363
  messages: persistedMessages,
365
364
  storage,
366
365
  errorHandler: onPersistenceError,
367
- };
366
+ });
368
367
  }
369
368
 
370
369
  if (persistTimer) clearTimeout(persistTimer);
@@ -379,8 +378,10 @@
379
378
  }
380
379
 
381
380
  function replaceMessages(nextMessages: ChatMessage[], persist = true): void {
381
+ const shouldScroll = shouldStickToBottom();
382
382
  messages = nextMessages;
383
383
  if (persist) schedulePersist(nextMessages);
384
+ scrollToBottomAfterUpdate(shouldScroll);
384
385
  }
385
386
 
386
387
  function updateMessageById(
@@ -389,8 +390,10 @@
389
390
  ): boolean {
390
391
  const index = messages.findIndex((message) => message.id === messageId);
391
392
  if (index < 0) return false;
393
+ const message = messages[index];
394
+ if (!message) return false;
392
395
  const nextMessages = [...messages];
393
- nextMessages[index] = update(messages[index]);
396
+ nextMessages[index] = update(message);
394
397
  replaceMessages(nextMessages);
395
398
  return true;
396
399
  }
@@ -404,80 +407,80 @@
404
407
  }
405
408
 
406
409
  function parseStoredSource(value: unknown): ChatSource | null {
407
- if (!isRecord(value) || typeof value.title !== 'string') return null;
408
- const url = typeof value.url === 'string' ? safeResourceUrl(value.url) : undefined;
410
+ if (!isRecord(value) || typeof value['title'] !== 'string') return null;
411
+ const url = typeof value['url'] === 'string' ? safeResourceUrl(value['url']) : undefined;
409
412
  return {
410
- ...(typeof value.id === 'string' ? { id: value.id } : {}),
411
- title: value.title,
413
+ ...(typeof value['id'] === 'string' ? { id: value['id'] } : {}),
414
+ title: value['title'],
412
415
  ...(url ? { url } : {}),
413
- ...(typeof value.quote === 'string' ? { quote: value.quote } : {}),
414
- ...(typeof value.description === 'string' ? { description: value.description } : {}),
416
+ ...(typeof value['quote'] === 'string' ? { quote: value['quote'] } : {}),
417
+ ...(typeof value['description'] === 'string' ? { description: value['description'] } : {}),
415
418
  };
416
419
  }
417
420
 
418
421
  function parseStoredAttachment(value: unknown): ChatAttachment | null {
419
- if (!isRecord(value) || typeof value.id !== 'string' || typeof value.name !== 'string') return null;
420
- const url = typeof value.url === 'string' ? safeResourceUrl(value.url) : undefined;
422
+ if (!isRecord(value) || typeof value['id'] !== 'string' || typeof value['name'] !== 'string') return null;
423
+ const url = typeof value['url'] === 'string' ? safeResourceUrl(value['url']) : undefined;
421
424
  return {
422
- id: value.id,
423
- name: value.name,
424
- ...(typeof value.mediaType === 'string' ? { mediaType: value.mediaType } : {}),
425
+ id: value['id'],
426
+ name: value['name'],
427
+ ...(typeof value['mediaType'] === 'string' ? { mediaType: value['mediaType'] } : {}),
425
428
  ...(url ? { url } : {}),
426
- ...(typeof value.size === 'number' && Number.isFinite(value.size) ? { size: value.size } : {}),
429
+ ...(typeof value['size'] === 'number' && Number.isFinite(value['size']) ? { size: value['size'] } : {}),
427
430
  };
428
431
  }
429
432
 
430
433
  function parseStoredPart(value: unknown, fallbackId: string): ChatMessagePart | null {
431
- if (!isRecord(value) || typeof value.type !== 'string') return null;
432
- const id = typeof value.id === 'string' && value.id ? value.id : fallbackId;
433
- switch (value.type) {
434
+ if (!isRecord(value) || typeof value['type'] !== 'string') return null;
435
+ const id = typeof value['id'] === 'string' && value['id'] ? value['id'] : fallbackId;
436
+ switch (value['type']) {
434
437
  case 'text':
435
- return typeof value.text === 'string' ? { id, type: 'text', text: value.text } : null;
438
+ return typeof value['text'] === 'string' ? { id, type: 'text', text: value['text'] } : null;
436
439
  case 'reasoning':
437
- return typeof value.text === 'string'
438
- ? { id, type: 'reasoning', text: value.text, streaming: false }
440
+ return typeof value['text'] === 'string'
441
+ ? { id, type: 'reasoning', text: value['text'], streaming: false }
439
442
  : null;
440
443
  case 'tool-call':
441
- return typeof value.tool === 'string' && isToolState(value.state)
444
+ return typeof value['tool'] === 'string' && isToolState(value['state'])
442
445
  ? {
443
446
  id,
444
447
  type: 'tool-call',
445
- tool: value.tool,
446
- input: value.input,
447
- state: value.state,
448
- ...(typeof value.callId === 'string' ? { callId: value.callId } : {}),
448
+ tool: value['tool'],
449
+ input: value['input'],
450
+ state: value['state'],
451
+ ...(typeof value['callId'] === 'string' ? { callId: value['callId'] } : {}),
449
452
  }
450
453
  : null;
451
454
  case 'tool-result':
452
- return typeof value.tool === 'string'
455
+ return typeof value['tool'] === 'string'
453
456
  ? {
454
457
  id,
455
458
  type: 'tool-result',
456
- tool: value.tool,
457
- output: value.output,
458
- ...(typeof value.error === 'string' ? { error: value.error } : {}),
459
- ...(typeof value.callId === 'string' ? { callId: value.callId } : {}),
459
+ tool: value['tool'],
460
+ output: value['output'],
461
+ ...(typeof value['error'] === 'string' ? { error: value['error'] } : {}),
462
+ ...(typeof value['callId'] === 'string' ? { callId: value['callId'] } : {}),
460
463
  }
461
464
  : null;
462
465
  case 'source': {
463
- const source = parseStoredSource(value.source);
466
+ const source = parseStoredSource(value['source']);
464
467
  return source ? { id, type: 'source', source } : null;
465
468
  }
466
469
  case 'image': {
467
- const src = typeof value.src === 'string' ? safeResourceUrl(value.src) : undefined;
470
+ const src = typeof value['src'] === 'string' ? safeResourceUrl(value['src']) : undefined;
468
471
  return src
469
472
  ? {
470
473
  id,
471
474
  type: 'image',
472
475
  src,
473
- ...(typeof value.alt === 'string' ? { alt: value.alt } : {}),
474
- ...(typeof value.width === 'number' && Number.isFinite(value.width) ? { width: value.width } : {}),
475
- ...(typeof value.height === 'number' && Number.isFinite(value.height) ? { height: value.height } : {}),
476
+ ...(typeof value['alt'] === 'string' ? { alt: value['alt'] } : {}),
477
+ ...(typeof value['width'] === 'number' && Number.isFinite(value['width']) ? { width: value['width'] } : {}),
478
+ ...(typeof value['height'] === 'number' && Number.isFinite(value['height']) ? { height: value['height'] } : {}),
476
479
  }
477
480
  : null;
478
481
  }
479
482
  case 'file': {
480
- const file = parseStoredAttachment(value.file);
483
+ const file = parseStoredAttachment(value['file']);
481
484
  return file ? { id, type: 'file', file } : null;
482
485
  }
483
486
  case 'approval':
@@ -494,32 +497,29 @@
494
497
  function parseStoredMessage(value: unknown): ChatMessage | null {
495
498
  if (!isRecord(value)) return null;
496
499
  if (
497
- typeof value.id !== 'string'
498
- || (value.role !== 'user' && value.role !== 'assistant')
499
- || !Array.isArray(value.parts)
500
- || typeof value.createdAt !== 'number'
501
- || !Number.isFinite(value.createdAt)
500
+ typeof value['id'] !== 'string'
501
+ || (value['role'] !== 'user' && value['role'] !== 'assistant')
502
+ || !Array.isArray(value['parts'])
503
+ || typeof value['createdAt'] !== 'number'
504
+ || !Number.isFinite(value['createdAt'])
502
505
  ) return null;
503
506
 
504
- const parts = value.parts
505
- .map((part, index) => parseStoredPart(part, `${value.id}-part-${index}`))
507
+ const parts = value['parts']
508
+ .map((part, index) => parseStoredPart(part, `${value['id']}-part-${index}`))
506
509
  .filter((part): part is ChatMessagePart => part !== null);
507
510
  if (parts.length === 0) return null;
508
511
 
509
- const attachments = Array.isArray(value.attachments)
510
- ? value.attachments
512
+ const attachments = Array.isArray(value['attachments'])
513
+ ? value['attachments']
511
514
  .map(parseStoredAttachment)
512
515
  .filter((attachment): attachment is ChatAttachment => attachment !== null)
513
516
  : [];
514
517
  return {
515
- id: value.id,
516
- role: value.role,
518
+ id: value['id'],
519
+ role: value['role'],
517
520
  parts,
518
- status: value.status === 'error' || value.status === 'aborted' ? value.status : 'complete',
519
- createdAt: value.createdAt,
520
- ...(value.role === 'user' && typeof value.approvalConfirmationFor === 'string'
521
- ? { approvalConfirmationFor: value.approvalConfirmationFor }
522
- : {}),
521
+ status: value['status'] === 'error' || value['status'] === 'aborted' ? value['status'] : 'complete',
522
+ createdAt: value['createdAt'],
523
523
  ...(attachments.length > 0 ? { attachments } : {}),
524
524
  };
525
525
  }
@@ -585,7 +585,7 @@
585
585
  ? 'aborted' as const
586
586
  : message.status;
587
587
  if (status !== message.status) changed = true;
588
- return changed ? { ...message, parts, status } : message;
588
+ return changed ? definedOptions({ ...message, parts, status }) : message;
589
589
  });
590
590
  }
591
591
 
@@ -750,12 +750,12 @@
750
750
  case 'text':
751
751
  return appendPart(message, textPart(event.content));
752
752
  case 'reasoning':
753
- return appendPart(message, {
753
+ return appendPart(message, definedOptions({
754
754
  id: createId('part'),
755
755
  type: 'reasoning',
756
756
  text: event.content,
757
757
  streaming: event.streaming,
758
- });
758
+ }));
759
759
  case 'tool_call':
760
760
  return appendPart(message, {
761
761
  id: createId('part'),
@@ -872,15 +872,11 @@
872
872
  async function sendMessage(
873
873
  rawValue = inputValue,
874
874
  attachments = inputAttachments,
875
- retryId?: string,
876
875
  ): Promise<void> {
877
876
  const value = rawValue.trim();
878
877
  const activeAgent = agent;
879
878
  const activeProvider = provider;
880
- if (isStreaming || (!activeAgent && !activeProvider)) return;
881
- const retry = retryId ? retryCandidate : undefined;
882
- if (retryId && (retry?.id !== retryId || retry.missingFiles)) return;
883
- if (!retryId && value.length === 0 && attachments.length === 0) return;
879
+ if ((value.length === 0 && attachments.length === 0) || isStreaming || (!activeAgent && !activeProvider)) return;
884
880
 
885
881
  // A new run revokes unresolved approval capabilities from the previous run.
886
882
  if (approvalEntries.size > 0 || abortController) invalidateActiveRun();
@@ -910,17 +906,11 @@
910
906
  status: 'streaming',
911
907
  createdAt: Date.now(),
912
908
  };
913
- const nextMessages = retry
914
- ? [...messages.slice(0, retry.index), assistantMessage]
915
- : [...messages, userMessage, assistantMessage];
916
- const sentMessages = nextMessages
917
- .filter((message) => message.parts.length > 0)
918
- .map(({ approvalConfirmationFor: _provenance, ...message }) => message);
919
-
920
- if (!retryId) {
921
- inputValue = '';
922
- inputAttachments = [];
923
- }
909
+ const nextMessages = [...messages, userMessage, assistantMessage];
910
+ const sentMessages = nextMessages.filter((message) => message.parts.length > 0);
911
+
912
+ inputValue = '';
913
+ inputAttachments = [];
924
914
  replaceMessages(nextMessages);
925
915
 
926
916
  const controller = new AbortController();
@@ -1000,7 +990,6 @@
1000
990
  return {
1001
991
  id: createId('user'),
1002
992
  role: 'user',
1003
- approvalConfirmationFor: entry.messageId,
1004
993
  parts: [textPart(
1005
994
  `User ${decision} execution of tool '${entry.tool}'`,
1006
995
  )],
@@ -1128,10 +1117,10 @@
1128
1117
  : null;
1129
1118
  const eventLayoutScope = eventTarget
1130
1119
  ?.closest<HTMLElement>('[data-svadmin-layout-scope]')
1131
- ?.dataset.svadminLayoutScope;
1120
+ ?.dataset['svadminLayoutScope'];
1132
1121
  const eventChatScope = eventTarget
1133
1122
  ?.closest<HTMLElement>('[data-svadmin-chat-scope]')
1134
- ?.dataset.svadminChatScope;
1123
+ ?.dataset['svadminChatScope'];
1135
1124
  const layoutCount = document.querySelectorAll('[data-svadmin-layout-scope]').length;
1136
1125
  const chatCount = document.querySelectorAll('[data-svadmin-chat-scope]').length;
1137
1126
  const ownsShortcut = ownerScope
@@ -1401,22 +1390,10 @@
1401
1390
  </MessageContent>
1402
1391
  <MessageToolbar>
1403
1392
  <span>{message.status ?? 'complete'}</span>
1404
- {#if message.id === retryCandidate?.id}
1405
- <button
1406
- type="button"
1407
- class="svadmin-ai__button svadmin-ai__button--ghost size-8 min-h-8 p-0"
1408
- aria-label="Retry response"
1409
- title={retryCandidate.missingFiles ? 'Reattach files to send this request again.' : 'Retry response'}
1410
- disabled={isStreaming || retryCandidate.missingFiles}
1411
- onclick={() => { void sendMessage('', [], message.id); }}
1412
- ><RotateCcw size={14} aria-hidden="true" /></button>
1413
- {#if retryCandidate.missingFiles}<span role="status">Reattach files to send this request again.</span>{/if}
1414
- {/if}
1415
1393
  </MessageToolbar>
1416
1394
  </Message>
1417
1395
  {/each}
1418
1396
  </ConversationContent>
1419
- <ConversationScrollButton />
1420
1397
  </Conversation>
1421
1398
 
1422
1399
  <footer class="shrink-0 border-t border-border/70 bg-card p-3">
@@ -1,14 +1,12 @@
1
+ export type { GeneratedComponentDefinition, GeneratedComponentProps, GeneratedComponentRegistry, } from '../generated-components.js';
1
2
  import { type Component } from 'svelte';
2
- import type { ChatMessage as ProviderMessage } from '../contracts.js';
3
+ import type { ChatMessage } from '../contracts.js';
3
4
  import { type GeneratedComponentRegistry as ComponentRegistry } from '../generated-components.js';
4
5
  export type ChatPersistenceOperation = 'restore' | 'persist';
5
6
  export interface ChatPersistenceErrorDetail {
6
7
  operation: ChatPersistenceOperation;
7
8
  error: unknown;
8
9
  }
9
- type ChatMessage = ProviderMessage & {
10
- approvalConfirmationFor?: string;
11
- };
12
10
  type Props = {
13
11
  /** Renders a compact launcher button in the layout toolbar. */
14
12
  docked?: boolean;
@@ -25,10 +23,6 @@ type Props = {
25
23
  componentRegistry?: ComponentRegistry;
26
24
  class?: string;
27
25
  };
28
- declare const ChatDialog: Component<Props, {
29
- GeneratedComponentDefinition: typeof GeneratedComponentDefinition;
30
- GeneratedComponentProps: typeof GeneratedComponentProps;
31
- GeneratedComponentRegistry: typeof GeneratedComponentRegistry;
32
- }, "">;
26
+ declare const ChatDialog: Component<Props, {}, "">;
33
27
  type ChatDialog = ReturnType<typeof ChatDialog>;
34
28
  export default ChatDialog;
@@ -12,9 +12,8 @@
12
12
  </script>
13
13
 
14
14
  <script lang="ts">
15
- import { onDestroy } from 'svelte';
15
+ import { untrack } from 'svelte';
16
16
  import { provideConversationContext } from '../context.svelte.js';
17
- import { observeConversationScroll } from './conversation/scroll.js';
18
17
  import { cn } from '../utils.js';
19
18
 
20
19
  let {
@@ -25,18 +24,30 @@
25
24
  'aria-label': ariaLabel = 'Conversation',
26
25
  ...rest
27
26
  }: ConversationProps = $props();
28
- let scroll: ReturnType<typeof observeConversationScroll> | undefined;
27
+ let contentElement = $state<HTMLElement | null>(null);
29
28
  let isAtBottom = $state(true);
30
29
 
31
30
  function scrollToBottom(): void {
32
- scroll?.scrollToBottom();
31
+ const element = contentElement;
32
+ if (!element) return;
33
+ isAtBottom = true;
34
+ if (typeof element.scrollTo === 'function') element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' });
35
+ else element.scrollTop = element.scrollHeight;
36
+ }
37
+
38
+ function updateScrollState(): void {
39
+ const element = contentElement;
40
+ if (!element) return;
41
+ isAtBottom = element.scrollHeight - element.scrollTop - element.clientHeight <= 48;
33
42
  }
34
43
 
35
44
  function registerContent(element: HTMLElement | null): void {
36
- scroll?.destroy();
37
- scroll = element
38
- ? observeConversationScroll(element, (atBottom) => { isAtBottom = atBottom; })
39
- : undefined;
45
+ untrack(() => {
46
+ contentElement?.removeEventListener('scroll', updateScrollState);
47
+ contentElement = element;
48
+ contentElement?.addEventListener('scroll', updateScrollState, { passive: true });
49
+ updateScrollState();
50
+ });
40
51
  }
41
52
 
42
53
  provideConversationContext({
@@ -47,14 +58,27 @@
47
58
  registerContent,
48
59
  });
49
60
 
50
- onDestroy(() => scroll?.destroy());
61
+ $effect(() => {
62
+ void messages;
63
+ void isStreaming;
64
+ queueMicrotask(() => {
65
+ const element = contentElement;
66
+ if (element && isAtBottom) {
67
+ if (typeof element.scrollTo === 'function') element.scrollTo({ top: element.scrollHeight });
68
+ else element.scrollTop = element.scrollHeight;
69
+ }
70
+ updateScrollState();
71
+ });
72
+ });
51
73
  </script>
52
74
 
53
75
  <section
54
76
  {...rest}
55
- class={cn('svadmin-ai svadmin-ai__surface relative flex min-h-0 min-w-0 flex-col overflow-hidden', className)}
77
+ class={cn('svadmin-ai svadmin-ai__surface relative flex min-h-0 flex-col overflow-hidden', className)}
56
78
  aria-label={ariaLabel}
57
79
  data-slot="conversation"
58
80
  >
59
81
  {@render children?.()}
60
82
  </section>
83
+
84
+ <svelte:window onresize={updateScrollState} />
@@ -32,7 +32,7 @@
32
32
  <div
33
33
  {...rest}
34
34
  bind:this={contentElement}
35
- class={cn('flex min-h-0 min-w-0 flex-1 flex-col gap-8 overflow-x-hidden overflow-y-auto overscroll-contain p-4', className)}
35
+ class={cn('flex min-h-0 flex-1 flex-col gap-8 overflow-y-auto p-4', className)}
36
36
  {role}
37
37
  aria-live={ariaLive ?? (conversation.isStreaming ? 'off' : 'polite')}
38
38
  aria-busy={ariaBusy ?? conversation.isStreaming}
@@ -39,7 +39,6 @@
39
39
  className,
40
40
  )}
41
41
  aria-label={ariaLabel}
42
- title={ariaLabel}
43
42
  data-slot="conversation-scroll-button"
44
43
  onclick={click}
45
44
  >