@svadmin/ai-elements 0.4.1 → 0.5.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 (39) hide show
  1. package/README.md +46 -0
  2. package/dist/ai-theme.css +28 -0
  3. package/dist/ai.css +2740 -153
  4. package/dist/ai.theme.css +2771 -0
  5. package/dist/components/ChatDialog.svelte +58 -28
  6. package/dist/components/ChatDialog.svelte.d.ts +4 -1
  7. package/dist/components/Conversation.svelte +10 -34
  8. package/dist/components/ConversationContent.svelte +1 -1
  9. package/dist/components/ConversationScrollButton.svelte +1 -0
  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 +6 -20
  15. package/dist/components/Tool.svelte +13 -13
  16. package/dist/components/Tool.svelte.d.ts +1 -1
  17. package/dist/components/checkpoint/index.d.ts +2 -2
  18. package/dist/components/code/code-variants.d.ts +25 -0
  19. package/dist/components/code/code-variants.js +20 -0
  20. package/dist/components/code/index.d.ts +1 -18
  21. package/dist/components/code/index.js +1 -11
  22. package/dist/components/conversation/scroll.d.ts +4 -0
  23. package/dist/components/conversation/scroll.js +85 -0
  24. package/dist/components/message/content-polish-html.d.ts +5 -0
  25. package/dist/components/message/content-polish-html.js +75 -0
  26. package/dist/components/prompt-input/PromptInput.svelte +17 -5
  27. package/dist/components/prompt-input/PromptInputSubmit.svelte +18 -5
  28. package/dist/components/prompt-input/PromptInputTextarea.svelte +11 -6
  29. package/dist/components/prompt-input/context.svelte.d.ts +7 -0
  30. package/dist/components/snippet/index.d.ts +3 -3
  31. package/dist/components/suggestion/index.d.ts +1 -1
  32. package/dist/components/tool/ToolContent.svelte +1 -1
  33. package/dist/components/tool/ToolHeader.svelte +5 -5
  34. package/dist/components/tool/ToolInput.svelte +4 -2
  35. package/dist/components/tool/ToolOutput.svelte +4 -2
  36. package/dist/components/tool/ToolStatusBadge.svelte +3 -2
  37. package/dist/components/tool/content-polish-scroll-region.d.ts +3 -0
  38. package/dist/components/tool/content-polish-scroll-region.js +22 -0
  39. package/package.json +16 -6
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { captureAdminContext, useParsed } from '@svadmin/core';
3
- import { Bot, Maximize2, MessageCircle, Minus, Trash2, X } from '@lucide/svelte';
3
+ import { Bot, Maximize2, MessageCircle, Minus, RotateCcw, Trash2, X } from '@lucide/svelte';
4
4
  import { onDestroy, tick, untrack, type Component } from 'svelte';
5
5
  import { SvelteMap } from 'svelte/reactivity';
6
6
  import type {
@@ -8,7 +8,7 @@
8
8
  AgentProvider,
9
9
  ChatAttachment,
10
10
  ChatContext,
11
- ChatMessage,
11
+ ChatMessage as ProviderMessage,
12
12
  ChatMessagePart,
13
13
  ChatProvider,
14
14
  ChatSource,
@@ -17,6 +17,7 @@
17
17
  import Conversation from './Conversation.svelte';
18
18
  import ConversationContent from './ConversationContent.svelte';
19
19
  import ConversationEmptyState from './ConversationEmptyState.svelte';
20
+ import ConversationScrollButton from './ConversationScrollButton.svelte';
20
21
  import Message from './Message.svelte';
21
22
  import MessageContent from './MessageContent.svelte';
22
23
  import MessageToolbar from './MessageToolbar.svelte';
@@ -102,6 +103,8 @@
102
103
  };
103
104
 
104
105
  type ApprovalDecision = 'approved' | 'rejected';
106
+ // Display-only provenance survives restore; it never grants approval capability.
107
+ type ChatMessage = ProviderMessage & { approvalConfirmationFor?: string };
105
108
 
106
109
  let {
107
110
  docked = false,
@@ -134,6 +137,27 @@
134
137
  let inputValue = $state('');
135
138
  let inputAttachments = $state<ChatAttachment[]>([]);
136
139
  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
+ });
137
161
  let isStreaming = $state(false);
138
162
  let chatRoot = $state<HTMLElement | null>(null);
139
163
  let launcherButton = $state<HTMLButtonElement | null>(null);
@@ -262,24 +286,6 @@
262
286
  }));
263
287
  }
264
288
 
265
- function getConversationLog(): HTMLElement | null {
266
- return chatRoot?.querySelector<HTMLElement>('[role="log"]') ?? null;
267
- }
268
-
269
- function shouldStickToBottom(): boolean {
270
- const log = getConversationLog();
271
- if (!log) return true;
272
- return log.scrollHeight - log.scrollTop - log.clientHeight <= 64;
273
- }
274
-
275
- function scrollToBottomAfterUpdate(shouldScroll: boolean): void {
276
- if (!shouldScroll || typeof window === 'undefined') return;
277
- window.requestAnimationFrame(() => {
278
- const log = getConversationLog();
279
- log?.scrollTo({ top: log.scrollHeight, behavior: 'smooth' });
280
- });
281
- }
282
-
283
289
  function getChatStorage(): Storage | null {
284
290
  if (typeof window === 'undefined') return null;
285
291
  return window.localStorage;
@@ -373,10 +379,8 @@
373
379
  }
374
380
 
375
381
  function replaceMessages(nextMessages: ChatMessage[], persist = true): void {
376
- const shouldScroll = shouldStickToBottom();
377
382
  messages = nextMessages;
378
383
  if (persist) schedulePersist(nextMessages);
379
- scrollToBottomAfterUpdate(shouldScroll);
380
384
  }
381
385
 
382
386
  function updateMessageById(
@@ -513,6 +517,9 @@
513
517
  parts,
514
518
  status: value.status === 'error' || value.status === 'aborted' ? value.status : 'complete',
515
519
  createdAt: value.createdAt,
520
+ ...(value.role === 'user' && typeof value.approvalConfirmationFor === 'string'
521
+ ? { approvalConfirmationFor: value.approvalConfirmationFor }
522
+ : {}),
516
523
  ...(attachments.length > 0 ? { attachments } : {}),
517
524
  };
518
525
  }
@@ -865,11 +872,15 @@
865
872
  async function sendMessage(
866
873
  rawValue = inputValue,
867
874
  attachments = inputAttachments,
875
+ retryId?: string,
868
876
  ): Promise<void> {
869
877
  const value = rawValue.trim();
870
878
  const activeAgent = agent;
871
879
  const activeProvider = provider;
872
- if ((value.length === 0 && attachments.length === 0) || isStreaming || (!activeAgent && !activeProvider)) return;
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;
873
884
 
874
885
  // A new run revokes unresolved approval capabilities from the previous run.
875
886
  if (approvalEntries.size > 0 || abortController) invalidateActiveRun();
@@ -899,11 +910,17 @@
899
910
  status: 'streaming',
900
911
  createdAt: Date.now(),
901
912
  };
902
- const nextMessages = [...messages, userMessage, assistantMessage];
903
- const sentMessages = nextMessages.filter((message) => message.parts.length > 0);
904
-
905
- inputValue = '';
906
- inputAttachments = [];
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
+ }
907
924
  replaceMessages(nextMessages);
908
925
 
909
926
  const controller = new AbortController();
@@ -983,6 +1000,7 @@
983
1000
  return {
984
1001
  id: createId('user'),
985
1002
  role: 'user',
1003
+ approvalConfirmationFor: entry.messageId,
986
1004
  parts: [textPart(
987
1005
  `User ${decision} execution of tool '${entry.tool}'`,
988
1006
  )],
@@ -1383,10 +1401,22 @@
1383
1401
  </MessageContent>
1384
1402
  <MessageToolbar>
1385
1403
  <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}
1386
1415
  </MessageToolbar>
1387
1416
  </Message>
1388
1417
  {/each}
1389
1418
  </ConversationContent>
1419
+ <ConversationScrollButton />
1390
1420
  </Conversation>
1391
1421
 
1392
1422
  <footer class="shrink-0 border-t border-border/70 bg-card p-3">
@@ -1,11 +1,14 @@
1
1
  import { type Component } from 'svelte';
2
- import type { ChatMessage } from '../contracts.js';
2
+ import type { ChatMessage as ProviderMessage } from '../contracts.js';
3
3
  import { type GeneratedComponentRegistry as ComponentRegistry } from '../generated-components.js';
4
4
  export type ChatPersistenceOperation = 'restore' | 'persist';
5
5
  export interface ChatPersistenceErrorDetail {
6
6
  operation: ChatPersistenceOperation;
7
7
  error: unknown;
8
8
  }
9
+ type ChatMessage = ProviderMessage & {
10
+ approvalConfirmationFor?: string;
11
+ };
9
12
  type Props = {
10
13
  /** Renders a compact launcher button in the layout toolbar. */
11
14
  docked?: boolean;
@@ -12,8 +12,9 @@
12
12
  </script>
13
13
 
14
14
  <script lang="ts">
15
- import { untrack } from 'svelte';
15
+ import { onDestroy } from 'svelte';
16
16
  import { provideConversationContext } from '../context.svelte.js';
17
+ import { observeConversationScroll } from './conversation/scroll.js';
17
18
  import { cn } from '../utils.js';
18
19
 
19
20
  let {
@@ -24,30 +25,18 @@
24
25
  'aria-label': ariaLabel = 'Conversation',
25
26
  ...rest
26
27
  }: ConversationProps = $props();
27
- let contentElement = $state<HTMLElement | null>(null);
28
+ let scroll: ReturnType<typeof observeConversationScroll> | undefined;
28
29
  let isAtBottom = $state(true);
29
30
 
30
31
  function scrollToBottom(): void {
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;
32
+ scroll?.scrollToBottom();
42
33
  }
43
34
 
44
35
  function registerContent(element: HTMLElement | null): void {
45
- untrack(() => {
46
- contentElement?.removeEventListener('scroll', updateScrollState);
47
- contentElement = element;
48
- contentElement?.addEventListener('scroll', updateScrollState, { passive: true });
49
- updateScrollState();
50
- });
36
+ scroll?.destroy();
37
+ scroll = element
38
+ ? observeConversationScroll(element, (atBottom) => { isAtBottom = atBottom; })
39
+ : undefined;
51
40
  }
52
41
 
53
42
  provideConversationContext({
@@ -58,27 +47,14 @@
58
47
  registerContent,
59
48
  });
60
49
 
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
- });
50
+ onDestroy(() => scroll?.destroy());
73
51
  </script>
74
52
 
75
53
  <section
76
54
  {...rest}
77
- class={cn('svadmin-ai svadmin-ai__surface relative flex min-h-0 flex-col overflow-hidden', className)}
55
+ class={cn('svadmin-ai svadmin-ai__surface relative flex min-h-0 min-w-0 flex-col overflow-hidden', className)}
78
56
  aria-label={ariaLabel}
79
57
  data-slot="conversation"
80
58
  >
81
59
  {@render children?.()}
82
60
  </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 flex-1 flex-col gap-8 overflow-y-auto p-4', className)}
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)}
36
36
  {role}
37
37
  aria-live={ariaLive ?? (conversation.isStreaming ? 'off' : 'polite')}
38
38
  aria-busy={ariaBusy ?? conversation.isStreaming}
@@ -39,6 +39,7 @@
39
39
  className,
40
40
  )}
41
41
  aria-label={ariaLabel}
42
+ title={ariaLabel}
42
43
  data-slot="conversation-scroll-button"
43
44
  onclick={click}
44
45
  >
@@ -26,7 +26,7 @@
26
26
  {...rest}
27
27
  {id}
28
28
  class={cn(
29
- 'group flex w-full max-w-[95%] flex-col gap-2',
29
+ 'group flex w-full min-w-0 max-w-[95%] flex-col gap-2',
30
30
  from === 'user' ? 'is-user ml-auto justify-end' : 'is-assistant',
31
31
  className,
32
32
  )}
@@ -3,4 +3,4 @@
3
3
  type Props = { children?: Snippet; class?: string };
4
4
  let { children, class: className = '' }: Props = $props();
5
5
  </script>
6
- <div class="mt-2 flex flex-wrap gap-2 {className}">{@render children?.()}</div>
6
+ <div class="mt-2 flex min-w-0 max-w-full flex-wrap gap-2 {className}">{@render children?.()}</div>
@@ -17,7 +17,7 @@
17
17
  <div
18
18
  {...rest}
19
19
  class={cn(
20
- 'flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm',
20
+ 'flex w-fit min-w-0 max-w-full flex-col gap-2 text-sm [overflow-wrap:anywhere]',
21
21
  'group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground',
22
22
  'group-[.is-assistant]:text-foreground',
23
23
  className,
@@ -3,4 +3,4 @@
3
3
  type Props = { children?: Snippet; class?: string };
4
4
  let { children, class: className = '' }: Props = $props();
5
5
  </script>
6
- <div class="mt-2 flex items-center gap-2 text-xs svadmin-ai__muted {className}">{@render children?.()}</div>
6
+ <div class="mt-2 flex min-w-0 max-w-full flex-wrap items-center gap-2 text-xs svadmin-ai__muted {className}">{@render children?.()}</div>
@@ -15,6 +15,7 @@
15
15
  <script lang="ts">
16
16
  import { Streamdown } from 'streamdown-svelte';
17
17
  import { cn } from '../utils.js';
18
+ import { createResponseHtmlPreparer } from './message/content-polish-html.js';
18
19
 
19
20
  let {
20
21
  content = '',
@@ -25,35 +26,20 @@
25
26
  skipHtml = true,
26
27
  controls = { code: { copy: true, download: false }, mermaid: false, table: false },
27
28
  translations,
29
+ extensions = [],
28
30
  ...rest
29
31
  }: ResponseProps = $props();
30
32
 
31
- function escapeRawHtmlTags(markdown: string): string {
32
- let inFence = false;
33
- return markdown
34
- .split('\n')
35
- .map((line) => {
36
- if (/^\s{0,3}(`{3,}|~{3,})/.test(line)) {
37
- inFence = !inFence;
38
- return line;
39
- }
40
- return inFence
41
- ? line
42
- : line.replace(/<\/?[A-Za-z][A-Za-z0-9:-]*(?:\s[^<>]*?)?\/?\s*>/g, (tag) =>
43
- tag.replaceAll('<', '&lt;').replaceAll('>', '&gt;'),
44
- );
45
- })
46
- .join('\n');
47
- }
48
-
49
- const responseText = $derived(escapeRawHtmlTags(text ?? content));
33
+ const prepareResponseHtml = createResponseHtmlPreparer();
34
+ const response = $derived(prepareResponseHtml(text ?? content, extensions));
50
35
  let streamdownContext = $state<StreamdownContext>();
51
36
  </script>
52
37
 
53
38
  <Streamdown
54
39
  bind:streamdown={streamdownContext}
55
40
  {...rest}
56
- content={responseText}
41
+ content={response.content}
42
+ extensions={response.extensions}
57
43
  class={cn('svadmin-ai__markdown', className)}
58
44
  mode={streaming ? 'streaming' : 'static'}
59
45
  isAnimating={streaming}
@@ -4,7 +4,11 @@
4
4
  import type { ChatMessagePart } from '../contracts.js';
5
5
  import { cn } from '../utils.js';
6
6
  import { provideToolContext } from './tool/context.svelte.js';
7
- import { formatToolValue, getStatusBadge, type ToolDisplayState } from './tool/status.js';
7
+ import type { ToolDisplayState } from './tool/status.js';
8
+ import ToolHeader from './tool/ToolHeader.svelte';
9
+ import ToolContent from './tool/ToolContent.svelte';
10
+ import ToolInput from './tool/ToolInput.svelte';
11
+ import ToolOutput from './tool/ToolOutput.svelte';
8
12
  type ToolPart = Extract<ChatMessagePart, { type: 'tool-call' }>;
9
13
  type Props = Omit<HTMLAttributes<HTMLDetailsElement>, 'children' | 'class' | 'open' | 'ontoggle' | 'part'> & { part?: ToolPart; name?: string; input?: unknown; output?: unknown; errorText?: string; state?: ToolDisplayState; open?: boolean; onapprove?: () => void; onreject?: () => void; class?: string; children?: Snippet; onOpenChange?: (open: boolean) => void };
10
14
  let { part, name, input, output, errorText, state: stateProp, open = $bindable(false), onapprove, onreject, class: className = '', children, onOpenChange, ...rest }: Props = $props();
@@ -12,9 +16,9 @@
12
16
  const toolInput = $derived(part?.input ?? input);
13
17
  const toolState = $derived<ToolDisplayState>(part?.state ?? stateProp ?? 'input-available');
14
18
  const needsApproval = $derived(toolState === 'approval-requested');
15
- const statusBadge = $derived(getStatusBadge(toolState));
16
19
 
17
20
  function setOpen(nextOpen: boolean): void {
21
+ if (open === nextOpen) return;
18
22
  open = nextOpen;
19
23
  onOpenChange?.(nextOpen);
20
24
  }
@@ -30,19 +34,15 @@
30
34
  });
31
35
  </script>
32
36
 
33
- <details {...rest} class={cn('svadmin-ai__surface my-2 text-sm', className)} {open} data-slot="tool" ontoggle={(event) => setOpen(event.currentTarget.open)}>
37
+ <details {...rest} class={cn('svadmin-ai__surface my-2 min-w-0 max-w-full text-sm', className)} {open} data-slot="tool" data-state={toolState} ontoggle={(event) => setOpen(event.currentTarget.open)}>
34
38
  {#if children}
35
39
  {@render children()}
36
40
  {:else}
37
- <summary class="flex cursor-pointer list-none items-center justify-between gap-3 px-3 py-2 font-medium focus-visible:outline-2 focus-visible:outline-offset-2">
38
- <span>{toolName}</span><span class="svadmin-ai__muted text-xs">{statusBadge.label}</span>
39
- </summary>
40
- {#if open}
41
- <div class="space-y-3 border-t border-border/70 p-3">
42
- {#if toolInput !== undefined}<pre class="max-h-48 overflow-auto rounded bg-muted p-2 text-xs">{formatToolValue(toolInput)}</pre>{/if}
43
- {#if needsApproval}<div role="alert" class="flex flex-wrap items-center gap-2 rounded border border-warning/40 bg-warning/10 p-2"><span>Approval required</span><button type="button" class="svadmin-ai__button min-h-8 px-2" onclick={() => onapprove?.()}>Approve</button><button type="button" class="svadmin-ai__button svadmin-ai__button--ghost min-h-8 px-2" onclick={() => onreject?.()}>Reject</button></div>{/if}
44
- {#if output !== undefined || errorText}<pre class="max-h-48 overflow-auto rounded bg-muted p-2 text-xs">{errorText ?? formatToolValue(output)}</pre>{/if}
45
- </div>
46
- {/if}
41
+ <ToolHeader />
42
+ <ToolContent>
43
+ <ToolInput />
44
+ {#if needsApproval}<div role="alert" class="flex flex-wrap items-center gap-2 rounded border border-warning/40 bg-warning/10 p-2"><span>Approval required</span><button type="button" class="svadmin-ai__button min-h-8 px-2" disabled={!onapprove} onclick={() => onapprove?.()}>Approve</button><button type="button" class="svadmin-ai__button svadmin-ai__button--ghost min-h-8 px-2" disabled={!onreject} onclick={() => onreject?.()}>Reject</button></div>{/if}
45
+ <ToolOutput />
46
+ </ToolContent>
47
47
  {/if}
48
48
  </details>
@@ -1,7 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import type { ChatMessagePart } from '../contracts.js';
4
- import { type ToolDisplayState } from './tool/status.js';
4
+ import type { ToolDisplayState } from './tool/status.js';
5
5
  type ToolPart = Extract<ChatMessagePart, {
6
6
  type: 'tool-call';
7
7
  }>;
@@ -2,11 +2,11 @@ import Checkpoint from './Checkpoint.svelte';
2
2
  import CheckpointIcon from './CheckpointIcon.svelte';
3
3
  import CheckpointTrigger from './CheckpointTrigger.svelte';
4
4
  export { Checkpoint, CheckpointIcon, CheckpointTrigger };
5
- export declare const Root: import("svelte").Component<Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children" | "class"> & {
5
+ export declare const Root: import("svelte").Component<Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "class" | "children"> & {
6
6
  class?: string;
7
7
  children?: import("svelte").Snippet;
8
8
  }, {}, "">;
9
- export declare const Icon: import("svelte").Component<Omit<import("@lucide/svelte").LucideProps, "children" | "class"> & {
9
+ export declare const Icon: import("svelte").Component<Omit<import("@lucide/svelte").LucideProps, "class" | "children"> & {
10
10
  class?: string;
11
11
  children?: import("svelte").Snippet;
12
12
  }, {}, "">;
@@ -0,0 +1,25 @@
1
+ import { type ClassValue } from 'cn';
2
+ export type CodeVariant = 'default' | 'secondary' | undefined;
3
+ declare function composeCodeVariants({ variant, class: className, className: extraClassName, }?: {
4
+ variant?: CodeVariant | null;
5
+ class?: ClassValue;
6
+ className?: ClassValue;
7
+ }): string;
8
+ export declare const codeVariants: typeof composeCodeVariants & {
9
+ base: string;
10
+ variants: {
11
+ variant: {
12
+ default: string;
13
+ secondary: string;
14
+ };
15
+ };
16
+ defaultVariants: {
17
+ variant: "default";
18
+ };
19
+ variantKeys: Array<"variant">;
20
+ slots: undefined;
21
+ extend: undefined;
22
+ compoundVariants: never[];
23
+ compoundSlots: never[];
24
+ };
25
+ export {};
@@ -0,0 +1,20 @@
1
+ import { cn } from 'cn';
2
+ function composeCodeVariants({ variant = 'default', class: className, className: extraClassName, } = {}) {
3
+ return cn('svadmin-ai-code', variant && `svadmin-ai-code--${variant}`, className, extraClassName);
4
+ }
5
+ // Preserve the metadata read by consumers that extend this public helper.
6
+ export const codeVariants = Object.assign(composeCodeVariants, {
7
+ base: 'svadmin-ai-code',
8
+ variants: {
9
+ variant: {
10
+ default: 'svadmin-ai-code--default',
11
+ secondary: 'svadmin-ai-code--secondary',
12
+ },
13
+ },
14
+ defaultVariants: { variant: 'default' },
15
+ variantKeys: ['variant'],
16
+ slots: undefined,
17
+ extend: undefined,
18
+ compoundVariants: [],
19
+ compoundSlots: [],
20
+ });
@@ -1,21 +1,4 @@
1
- import { type VariantProps } from 'tailwind-variants';
2
- export declare const codeVariants: import("tailwind-variants").TVReturnType<{
3
- variant: {
4
- default: "";
5
- secondary: "border-transparent bg-secondary";
6
- };
7
- }, undefined, "relative h-full overflow-auto rounded-md border border-border bg-background text-foreground", {
8
- variant: {
9
- default: "";
10
- secondary: "border-transparent bg-secondary";
11
- };
12
- }, undefined, import("tailwind-variants").TVReturnTypeLike<{
13
- variant: {
14
- default: "";
15
- secondary: "border-transparent bg-secondary";
16
- };
17
- }, undefined>>;
18
- export type CodeVariant = VariantProps<typeof codeVariants>['variant'];
1
+ export { codeVariants, type CodeVariant } from './code-variants.js';
19
2
  export { default, default as Root, default as Code } from './Code.svelte';
20
3
  export { default as Overflow, default as CodeOverflow } from '../code-block/CodeBlockOverflow.svelte';
21
4
  export { default as CopyButton, default as CodeCopyButton } from '../code-block/CodeBlockCopyButton.svelte';
@@ -1,14 +1,4 @@
1
- import { tv } from 'tailwind-variants';
2
- export const codeVariants = tv({
3
- base: 'relative h-full overflow-auto rounded-md border border-border bg-background text-foreground',
4
- variants: {
5
- variant: {
6
- default: '',
7
- secondary: 'border-transparent bg-secondary',
8
- },
9
- },
10
- defaultVariants: { variant: 'default' },
11
- });
1
+ export { codeVariants } from './code-variants.js';
12
2
  export { default, default as Root, default as Code } from './Code.svelte';
13
3
  export { default as Overflow, default as CodeOverflow } from '../code-block/CodeBlockOverflow.svelte';
14
4
  export { default as CopyButton, default as CodeCopyButton } from '../code-block/CodeBlockCopyButton.svelte';
@@ -0,0 +1,4 @@
1
+ export declare function observeConversationScroll(element: HTMLElement, onAtBottomChange: (atBottom: boolean) => void): {
2
+ scrollToBottom(): void;
3
+ destroy(): void;
4
+ };
@@ -0,0 +1,85 @@
1
+ export function observeConversationScroll(element, onAtBottomChange) {
2
+ let following = true;
3
+ let previousTop = element.scrollTop;
4
+ let frame;
5
+ let destroyed = false;
6
+ const observed = new Set();
7
+ const atBottom = () => element.scrollHeight - element.scrollTop - element.clientHeight <= 48;
8
+ function scrollToBottom() {
9
+ if (destroyed)
10
+ return;
11
+ following = true;
12
+ if (typeof element.scrollTo === 'function') {
13
+ element.scrollTo({ top: element.scrollHeight, behavior: 'instant' });
14
+ }
15
+ else {
16
+ element.scrollTop = element.scrollHeight;
17
+ }
18
+ previousTop = element.scrollTop;
19
+ onAtBottomChange(true);
20
+ }
21
+ function schedule() {
22
+ if (destroyed || frame !== undefined)
23
+ return;
24
+ frame = requestAnimationFrame(() => {
25
+ frame = undefined;
26
+ if (destroyed)
27
+ return;
28
+ if (atBottom())
29
+ following = true;
30
+ if (following)
31
+ scrollToBottom();
32
+ else
33
+ onAtBottomChange(atBottom());
34
+ });
35
+ }
36
+ function onScroll() {
37
+ const nextTop = element.scrollTop;
38
+ // Layout changes can emit scroll events without a user moving away.
39
+ if (atBottom())
40
+ following = true;
41
+ else if (nextTop !== previousTop)
42
+ following = false;
43
+ previousTop = nextTop;
44
+ onAtBottomChange(atBottom());
45
+ }
46
+ const resize = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(schedule);
47
+ function observeChildren() {
48
+ const children = new Set(element.children);
49
+ for (const child of observed) {
50
+ if (!children.has(child)) {
51
+ resize?.unobserve(child);
52
+ observed.delete(child);
53
+ }
54
+ }
55
+ for (const child of children) {
56
+ if (!observed.has(child)) {
57
+ resize?.observe(child);
58
+ observed.add(child);
59
+ }
60
+ }
61
+ }
62
+ resize?.observe(element);
63
+ observeChildren();
64
+ const mutation = new MutationObserver((records) => {
65
+ if (records.some((record) => record.type === 'childList'))
66
+ observeChildren();
67
+ schedule();
68
+ });
69
+ mutation.observe(element, { childList: true, subtree: true, characterData: true });
70
+ element.addEventListener('scroll', onScroll, { passive: true });
71
+ window.addEventListener('resize', schedule, { passive: true });
72
+ schedule();
73
+ return {
74
+ scrollToBottom,
75
+ destroy() {
76
+ destroyed = true;
77
+ if (frame !== undefined)
78
+ cancelAnimationFrame(frame);
79
+ resize?.disconnect();
80
+ mutation.disconnect();
81
+ element.removeEventListener('scroll', onScroll);
82
+ window.removeEventListener('resize', schedule);
83
+ },
84
+ };
85
+ }
@@ -0,0 +1,5 @@
1
+ import type { Extension } from 'streamdown-svelte';
2
+ export declare function createResponseHtmlPreparer(): (markdown: string, extensions?: Extension[]) => {
3
+ content: string;
4
+ extensions: Extension[];
5
+ };