@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.
- package/README.md +0 -51
- package/dist/ai.css +153 -2740
- package/dist/components/AICommandBar.svelte +6 -4
- package/dist/components/ChatDialog.svelte +102 -125
- package/dist/components/ChatDialog.svelte.d.ts +3 -9
- package/dist/components/Conversation.svelte +34 -10
- package/dist/components/ConversationContent.svelte +1 -1
- package/dist/components/ConversationScrollButton.svelte +0 -1
- package/dist/components/CopilotPanel.svelte +8 -6
- package/dist/components/Message.svelte +1 -1
- package/dist/components/MessageActions.svelte +1 -1
- package/dist/components/MessageContent.svelte +1 -1
- package/dist/components/MessageToolbar.svelte +1 -1
- package/dist/components/Response.svelte +31 -11
- package/dist/components/Response.svelte.d.ts +2 -2
- package/dist/components/Tool.svelte +13 -13
- package/dist/components/Tool.svelte.d.ts +1 -1
- package/dist/components/action/Action.svelte +3 -1
- package/dist/components/artifact/ArtifactAction.svelte +3 -1
- package/dist/components/attachments/Attachment.svelte +4 -2
- package/dist/components/attachments/Attachments.svelte +3 -1
- package/dist/components/attachments/types.js +3 -2
- package/dist/components/audio-player/AudioPlayer.svelte.d.ts +1 -1
- package/dist/components/canvas/Canvas.svelte +1 -1
- package/dist/components/checkpoint/index.d.ts +2 -2
- package/dist/components/code/index.d.ts +18 -1
- package/dist/components/code/index.js +11 -1
- package/dist/components/code-block/CodeBlockLanguageSelector.svelte.d.ts +1 -1
- package/dist/components/code-block/highlight.js +10 -9
- package/dist/components/commit/Commit.svelte +23 -2
- package/dist/components/commit/CommitActions.svelte +2 -11
- package/dist/components/commit/CommitCopyButton.svelte +1 -1
- package/dist/components/commit/CommitHeader.svelte +12 -2
- package/dist/components/commit/context.svelte.d.ts +6 -0
- package/dist/components/commit/context.svelte.js +14 -0
- package/dist/components/context/Context.svelte +6 -4
- package/dist/components/context/TokensWithCost.svelte +2 -1
- package/dist/components/edge/Animated.svelte +6 -6
- package/dist/components/edge/Temporary.svelte +6 -5
- package/dist/components/file-tree/FileTree.svelte +7 -5
- package/dist/components/jsx-preview/parser.js +10 -10
- package/dist/components/message/MessageAction.svelte +3 -1
- package/dist/components/mic-selector/MicSelector.svelte.d.ts +1 -1
- package/dist/components/model-selector/ModelSelectorDialog.svelte +3 -1
- package/dist/components/open-in-chat/OpenInChatGPT.svelte +3 -1
- package/dist/components/open-in-chat/OpenInClaude.svelte +3 -1
- package/dist/components/open-in-chat/OpenInCursor.svelte +3 -1
- package/dist/components/open-in-chat/OpenInGitHub.svelte +3 -1
- package/dist/components/open-in-chat/OpenInScira.svelte +3 -1
- package/dist/components/open-in-chat/OpenInT3.svelte +3 -1
- package/dist/components/open-in-chat/OpenInv0.svelte +3 -1
- package/dist/components/package-info/PackageInfo.svelte +3 -1
- package/dist/components/prompt-input/PromptInput.svelte +8 -18
- package/dist/components/prompt-input/PromptInputCommand.svelte +2 -1
- package/dist/components/prompt-input/PromptInputSelect.svelte.d.ts +1 -1
- package/dist/components/prompt-input/PromptInputSubmit.svelte +5 -18
- package/dist/components/prompt-input/PromptInputTextarea.svelte +6 -11
- package/dist/components/prompt-input/context.svelte.d.ts +1 -8
- package/dist/components/prompt-input/files.js +3 -2
- package/dist/components/question/Question.svelte +3 -1
- package/dist/components/schema-display/SchemaDisplay.svelte +4 -2
- package/dist/components/schema-display/SchemaDisplayParameter.svelte +14 -1
- package/dist/components/schema-display/SchemaDisplayProperty.svelte +16 -1
- package/dist/components/snippet/index.d.ts +3 -3
- package/dist/components/stack-trace/StackTrace.svelte +7 -5
- package/dist/components/suggestion/index.d.ts +1 -1
- package/dist/components/terminal/Terminal.svelte +4 -2
- package/dist/components/terminal/ansi.js +9 -6
- package/dist/components/test-results/Test.svelte +1 -1
- package/dist/components/test-results/TestResults.svelte +1 -1
- package/dist/components/test-results/context.svelte.d.ts +1 -1
- package/dist/components/tool/ToolContent.svelte +1 -1
- package/dist/components/tool/ToolHeader.svelte +5 -5
- package/dist/components/tool/ToolInput.svelte +2 -4
- package/dist/components/tool/ToolOutput.svelte +2 -4
- package/dist/components/tool/ToolStatusBadge.svelte +2 -3
- package/dist/components/voice-selector/VoiceSelector.svelte +2 -1
- package/dist/components/voice-selector/VoiceSelector.svelte.d.ts +2 -2
- package/dist/components/voice-selector/context.svelte.d.ts +2 -1
- package/dist/components/web-preview/WebPreview.svelte +4 -3
- package/dist/contracts.d.ts +2 -2
- package/dist/generated-components.d.ts +15 -1
- package/dist/generated-components.js +20 -1
- package/dist/internal/Tooltip.svelte +2 -1
- package/dist/parity-manifest.d.ts +0 -1
- package/dist/parity-manifest.js +0 -97
- package/package.json +9 -19
- package/UPSTREAM_PARITY.md +0 -69
- package/dist/ai-theme.css +0 -28
- package/dist/ai.theme.css +0 -2771
- package/dist/components/code/code-variants.d.ts +0 -25
- package/dist/components/code/code-variants.js +0 -20
- package/dist/components/conversation/scroll.d.ts +0 -4
- package/dist/components/conversation/scroll.js +0 -85
- package/dist/components/message/content-polish-html.d.ts +0 -5
- package/dist/components/message/content-polish-html.js +0 -75
- package/dist/components/tool/content-polish-scroll-region.d.ts +0 -3
- 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 { captureAdminContext, useParsed } from '@svadmin/core';
|
|
3
5
|
import { LoaderCircle, RefreshCcw, Sparkles, X } from '@lucide/svelte';
|
|
4
6
|
import { slide } from 'svelte/transition';
|
|
@@ -15,12 +17,12 @@
|
|
|
15
17
|
const parsed = useParsed();
|
|
16
18
|
const generatedId = $props.id();
|
|
17
19
|
const provider = $derived(adminContext.chatProvider);
|
|
18
|
-
const chatContext = $derived<ChatContext>({
|
|
20
|
+
const chatContext = $derived<ChatContext>(definedOptions({
|
|
19
21
|
currentResource: parsed.resource,
|
|
20
22
|
selectedRecordId: parsed.id,
|
|
21
23
|
currentView: parsed.action,
|
|
22
24
|
pathname: adminContext.currentPath(),
|
|
23
|
-
});
|
|
25
|
+
}));
|
|
24
26
|
|
|
25
27
|
let text = $state('');
|
|
26
28
|
let loading = $state(false);
|
|
@@ -90,22 +92,22 @@ Use bullet points and do not include introductory text.`;
|
|
|
90
92
|
async function refresh(): Promise<void> {
|
|
91
93
|
const scopedProvider: ChatProvider | null = provider;
|
|
92
94
|
if (!scopedProvider) return;
|
|
93
|
-
await requestInsights(scopedProvider, {
|
|
95
|
+
await requestInsights(scopedProvider, definedOptions({
|
|
94
96
|
currentResource: chatContext.currentResource,
|
|
95
97
|
selectedRecordId: chatContext.selectedRecordId,
|
|
96
98
|
currentView: chatContext.currentView,
|
|
97
99
|
pathname: chatContext.pathname,
|
|
98
|
-
});
|
|
100
|
+
}));
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
$effect(() => {
|
|
102
104
|
const scopedProvider: ChatProvider | null = provider;
|
|
103
|
-
const scopedContext: ChatContext = {
|
|
105
|
+
const scopedContext: ChatContext = definedOptions({
|
|
104
106
|
currentResource: chatContext.currentResource,
|
|
105
107
|
selectedRecordId: chatContext.selectedRecordId,
|
|
106
108
|
currentView: chatContext.currentView,
|
|
107
109
|
pathname: chatContext.pathname,
|
|
108
|
-
};
|
|
110
|
+
});
|
|
109
111
|
const tenant = adminContext.tenantCacheKey?.__svadminTenant;
|
|
110
112
|
const shouldFetch = open;
|
|
111
113
|
void tenant;
|
|
@@ -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
|
|
6
|
+
<div class="mt-2 flex 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 text-sm
|
|
20
|
+
'flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm',
|
|
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
|
|
6
|
+
<div class="mt-2 flex items-center gap-2 text-xs svadmin-ai__muted {className}">{@render children?.()}</div>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
|
-
import type {
|
|
2
|
+
import type { StreamdownProps } from 'streamdown-svelte';
|
|
3
3
|
|
|
4
4
|
export type ResponseProps = Omit<
|
|
5
|
-
StreamdownProps,
|
|
5
|
+
StreamdownProps<Record<string, unknown>>,
|
|
6
6
|
'content' | 'class' | 'className' | 'mode' | 'static' | 'isAnimating' | 'caret'
|
|
7
7
|
> & {
|
|
8
8
|
content?: string;
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<script lang="ts">
|
|
16
|
+
import { definedReactiveOptions } from '@svadmin/core/options';
|
|
16
17
|
import { Streamdown } from 'streamdown-svelte';
|
|
17
18
|
import { cn } from '../utils.js';
|
|
18
|
-
import { createResponseHtmlPreparer } from './message/content-polish-html.js';
|
|
19
19
|
|
|
20
20
|
let {
|
|
21
21
|
content = '',
|
|
@@ -26,24 +26,44 @@
|
|
|
26
26
|
skipHtml = true,
|
|
27
27
|
controls = { code: { copy: true, download: false }, mermaid: false, table: false },
|
|
28
28
|
translations,
|
|
29
|
-
|
|
29
|
+
streamdown = $bindable(),
|
|
30
30
|
...rest
|
|
31
31
|
}: ResponseProps = $props();
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
function escapeRawHtmlTags(markdown: string): string {
|
|
34
|
+
let inFence = false;
|
|
35
|
+
return markdown
|
|
36
|
+
.split('\n')
|
|
37
|
+
.map((line) => {
|
|
38
|
+
if (/^\s{0,3}(`{3,}|~{3,})/.test(line)) {
|
|
39
|
+
inFence = !inFence;
|
|
40
|
+
return line;
|
|
41
|
+
}
|
|
42
|
+
return inFence
|
|
43
|
+
? line
|
|
44
|
+
: line.replace(/<\/?[A-Za-z][A-Za-z0-9:-]*(?:\s[^<>]*?)?\/?\s*>/g, (tag) =>
|
|
45
|
+
tag.replaceAll('<', '<').replaceAll('>', '>'),
|
|
46
|
+
);
|
|
47
|
+
})
|
|
48
|
+
.join('\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const responseText = $derived(escapeRawHtmlTags(text ?? content));
|
|
52
|
+
// Preserve the renderer-owned context when parent props or streaming state change.
|
|
53
|
+
const contextBinding = definedReactiveOptions({
|
|
54
|
+
get streamdown() { return streamdown; },
|
|
55
|
+
set streamdown(next: StreamdownProps<Record<string, unknown>>['streamdown']) { streamdown = next; },
|
|
56
|
+
});
|
|
36
57
|
</script>
|
|
37
58
|
|
|
38
59
|
<Streamdown
|
|
39
|
-
bind:streamdown={streamdownContext}
|
|
40
60
|
{...rest}
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
{...contextBinding}
|
|
62
|
+
content={responseText}
|
|
43
63
|
class={cn('svadmin-ai__markdown', className)}
|
|
44
64
|
mode={streaming ? 'streaming' : 'static'}
|
|
45
65
|
isAnimating={streaming}
|
|
46
|
-
caret=
|
|
66
|
+
caret="block"
|
|
47
67
|
{baseTheme}
|
|
48
68
|
{skipHtml}
|
|
49
69
|
{controls}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { StreamdownProps } from 'streamdown-svelte';
|
|
2
|
-
export type ResponseProps = Omit<StreamdownProps, 'content' | 'class' | 'className' | 'mode' | 'static' | 'isAnimating' | 'caret'> & {
|
|
2
|
+
export type ResponseProps = Omit<StreamdownProps<Record<string, unknown>>, 'content' | 'class' | 'className' | 'mode' | 'static' | 'isAnimating' | 'caret'> & {
|
|
3
3
|
content?: string;
|
|
4
4
|
text?: string;
|
|
5
5
|
streaming?: boolean;
|
|
6
6
|
class?: string;
|
|
7
7
|
};
|
|
8
|
-
declare const Response: import("svelte").Component<ResponseProps, {}, "">;
|
|
8
|
+
declare const Response: import("svelte").Component<ResponseProps, {}, "streamdown">;
|
|
9
9
|
type Response = ReturnType<typeof Response>;
|
|
10
10
|
export default Response;
|
|
@@ -4,11 +4,7 @@
|
|
|
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 type
|
|
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';
|
|
7
|
+
import { formatToolValue, getStatusBadge, type ToolDisplayState } from './tool/status.js';
|
|
12
8
|
type ToolPart = Extract<ChatMessagePart, { type: 'tool-call' }>;
|
|
13
9
|
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 };
|
|
14
10
|
let { part, name, input, output, errorText, state: stateProp, open = $bindable(false), onapprove, onreject, class: className = '', children, onOpenChange, ...rest }: Props = $props();
|
|
@@ -16,9 +12,9 @@
|
|
|
16
12
|
const toolInput = $derived(part?.input ?? input);
|
|
17
13
|
const toolState = $derived<ToolDisplayState>(part?.state ?? stateProp ?? 'input-available');
|
|
18
14
|
const needsApproval = $derived(toolState === 'approval-requested');
|
|
15
|
+
const statusBadge = $derived(getStatusBadge(toolState));
|
|
19
16
|
|
|
20
17
|
function setOpen(nextOpen: boolean): void {
|
|
21
|
-
if (open === nextOpen) return;
|
|
22
18
|
open = nextOpen;
|
|
23
19
|
onOpenChange?.(nextOpen);
|
|
24
20
|
}
|
|
@@ -34,15 +30,19 @@
|
|
|
34
30
|
});
|
|
35
31
|
</script>
|
|
36
32
|
|
|
37
|
-
<details {...rest} class={cn('svadmin-ai__surface my-2
|
|
33
|
+
<details {...rest} class={cn('svadmin-ai__surface my-2 text-sm', className)} {open} data-slot="tool" ontoggle={(event) => setOpen(event.currentTarget.open)}>
|
|
38
34
|
{#if children}
|
|
39
35
|
{@render children()}
|
|
40
36
|
{:else}
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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}
|
|
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
|
|
4
|
+
import { type ToolDisplayState } from './tool/status.js';
|
|
5
5
|
type ToolPart = Extract<ChatMessagePart, {
|
|
6
6
|
type: 'tool-call';
|
|
7
7
|
}>;
|
|
@@ -12,13 +12,15 @@
|
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<script lang="ts">
|
|
15
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
16
|
+
|
|
15
17
|
import Tooltip from '../../internal/Tooltip.svelte';
|
|
16
18
|
import { cn } from '../../utils.js';
|
|
17
19
|
let { tooltip, label, size = 'icon-sm', variant = 'ghost', class: className = '', type = 'button', children, 'aria-describedby': ariaDescribedBy, ...rest }: ActionProps = $props();
|
|
18
20
|
const actionChildren = $derived(children);
|
|
19
21
|
</script>
|
|
20
22
|
|
|
21
|
-
<Tooltip content
|
|
23
|
+
<Tooltip {...definedOptions({ "content": tooltip })}>
|
|
22
24
|
{#snippet children({ describedBy })}
|
|
23
25
|
<button {...rest} {type} class={cn('svadmin-ai-action', className)} data-slot="action" data-size={size} data-variant={variant} aria-describedby={[ariaDescribedBy, describedBy].filter(Boolean).join(' ') || undefined}>
|
|
24
26
|
{@render actionChildren?.()}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<script lang="ts">
|
|
19
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
20
|
+
|
|
19
21
|
import { cn } from '../../utils.js';
|
|
20
22
|
import Tooltip from '../../internal/Tooltip.svelte';
|
|
21
23
|
let {
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
const actionChildren = $derived(children);
|
|
37
39
|
</script>
|
|
38
40
|
|
|
39
|
-
<Tooltip content
|
|
41
|
+
<Tooltip {...definedOptions({ "content": tooltip })}>
|
|
40
42
|
{#snippet children({ describedBy: tooltipDescribedBy })}
|
|
41
43
|
<button {...rest} {type} class={cn('svadmin-ai-artifact-part__action', className)} aria-label={accessibleLabel} aria-describedby={[ariaDescribedBy, tooltipDescribedBy].filter(Boolean).join(' ') || undefined} {title} data-slot="artifact-action" data-size={size} data-variant={variant}>
|
|
42
44
|
{#if Icon}<Icon size={16} aria-hidden="true" />{:else}{@render actionChildren?.()}{/if}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<script lang="ts">
|
|
16
|
+
import { definedReactiveOptions } from '@svadmin/core/options';
|
|
17
|
+
|
|
16
18
|
import { cn } from '../../utils.js';
|
|
17
19
|
import { getMediaCategory } from './attachments.js';
|
|
18
20
|
import { provideAttachmentContext, useAttachmentsContext } from './context.svelte.js';
|
|
@@ -23,12 +25,12 @@
|
|
|
23
25
|
const normalizedData = $derived(normalizeAttachmentData(data));
|
|
24
26
|
const mediaCategory = $derived(getMediaCategory(data));
|
|
25
27
|
|
|
26
|
-
provideAttachmentContext({
|
|
28
|
+
provideAttachmentContext(definedReactiveOptions({
|
|
27
29
|
get data() { return normalizedData; },
|
|
28
30
|
get mediaCategory() { return mediaCategory; },
|
|
29
31
|
get onRemove() { return onRemove ?? onremove; },
|
|
30
32
|
get variant() { return attachments.variant; },
|
|
31
|
-
});
|
|
33
|
+
}));
|
|
32
34
|
</script>
|
|
33
35
|
|
|
34
36
|
<div
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
</script>
|
|
22
22
|
|
|
23
23
|
<script lang="ts">
|
|
24
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
25
|
+
|
|
24
26
|
import { File as FileIcon, Image as ImageIcon, Paperclip, Trash2, Upload } from '@lucide/svelte';
|
|
25
27
|
import { cn, safeResourceUrl } from '../../utils.js';
|
|
26
28
|
import { provideAttachmentsContext } from './context.svelte.js';
|
|
@@ -84,7 +86,7 @@
|
|
|
84
86
|
const id = makeId(file, index);
|
|
85
87
|
const url = typeof URL !== 'undefined' ? URL.createObjectURL(file) : undefined;
|
|
86
88
|
if (url) objectUrls.set(id, url);
|
|
87
|
-
accepted.push({ id, name: file.name, mediaType: file.type || undefined, size: file.size, url, file });
|
|
89
|
+
accepted.push(definedOptions({ id, name: file.name, mediaType: file.type || undefined, size: file.size, url, file }));
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
const next = multiple ? [...currentAttachments, ...accepted] : accepted.slice(0, 1);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
1
2
|
export function normalizeAttachmentData(data) {
|
|
2
3
|
if ('type' in data)
|
|
3
4
|
return data;
|
|
4
|
-
return {
|
|
5
|
+
return definedOptions({
|
|
5
6
|
id: data.id,
|
|
6
7
|
type: 'file',
|
|
7
8
|
mediaType: data.mediaType,
|
|
8
9
|
filename: data.name,
|
|
9
10
|
url: data.url,
|
|
10
|
-
};
|
|
11
|
+
});
|
|
11
12
|
}
|
|
@@ -24,6 +24,6 @@ export interface AudioPlayerProps extends Omit<HTMLAttributes<HTMLElement>, 'chi
|
|
|
24
24
|
onended?: () => void;
|
|
25
25
|
onerror?: (event: Event) => void;
|
|
26
26
|
}
|
|
27
|
-
declare const AudioPlayer: import("svelte").Component<AudioPlayerProps, {}, "
|
|
27
|
+
declare const AudioPlayer: import("svelte").Component<AudioPlayerProps, {}, "currentTime" | "playing" | "muted" | "volume">;
|
|
28
28
|
type AudioPlayer = ReturnType<typeof AudioPlayer>;
|
|
29
29
|
export default AudioPlayer;
|
|
@@ -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>, "
|
|
5
|
+
export declare const Root: import("svelte").Component<Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children" | "class"> & {
|
|
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, "
|
|
9
|
+
export declare const Icon: import("svelte").Component<Omit<import("@lucide/svelte").LucideProps, "children" | "class"> & {
|
|
10
10
|
class?: string;
|
|
11
11
|
children?: import("svelte").Snippet;
|
|
12
12
|
}, {}, "">;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
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'];
|
|
2
19
|
export { default, default as Root, default as Code } from './Code.svelte';
|
|
3
20
|
export { default as Overflow, default as CodeOverflow } from '../code-block/CodeBlockOverflow.svelte';
|
|
4
21
|
export { default as CopyButton, default as CodeCopyButton } from '../code-block/CodeBlockCopyButton.svelte';
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
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
|
+
});
|
|
2
12
|
export { default, default as Root, default as Code } from './Code.svelte';
|
|
3
13
|
export { default as Overflow, default as CodeOverflow } from '../code-block/CodeBlockOverflow.svelte';
|
|
4
14
|
export { default as CopyButton, default as CodeCopyButton } from '../code-block/CodeBlockCopyButton.svelte';
|
|
@@ -9,6 +9,6 @@ type $$ComponentProps = {
|
|
|
9
9
|
onopenchange?: (open: boolean) => void;
|
|
10
10
|
[key: string]: unknown;
|
|
11
11
|
};
|
|
12
|
-
declare const CodeBlockLanguageSelector: import("svelte").Component<$$ComponentProps, {}, "
|
|
12
|
+
declare const CodeBlockLanguageSelector: import("svelte").Component<$$ComponentProps, {}, "open" | "value">;
|
|
13
13
|
type CodeBlockLanguageSelector = ReturnType<typeof CodeBlockLanguageSelector>;
|
|
14
14
|
export default CodeBlockLanguageSelector;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createCodePlugin } from 'streamdown-svelte/plugins';
|
|
2
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
2
3
|
const LIGHT_THEME = 'github-light';
|
|
3
4
|
const DARK_THEME = 'github-dark';
|
|
4
5
|
const codeHighlighter = createCodePlugin();
|
|
@@ -26,28 +27,28 @@ function readStyle(token) {
|
|
|
26
27
|
if (!token)
|
|
27
28
|
return {};
|
|
28
29
|
const htmlStyle = token.htmlStyle ?? {};
|
|
29
|
-
const fontStyle = htmlStyle['font-style'] === 'italic' || htmlStyle
|
|
30
|
+
const fontStyle = htmlStyle['font-style'] === 'italic' || htmlStyle['fontStyle'] === 'italic'
|
|
30
31
|
? 'italic'
|
|
31
32
|
: token.fontStyle && (token.fontStyle & 1) !== 0
|
|
32
33
|
? 'italic'
|
|
33
34
|
: undefined;
|
|
34
|
-
const fontWeight = htmlStyle['font-weight'] === 'bold' || htmlStyle
|
|
35
|
+
const fontWeight = htmlStyle['font-weight'] === 'bold' || htmlStyle['fontWeight'] === 'bold'
|
|
35
36
|
? 'bold'
|
|
36
37
|
: token.fontStyle && (token.fontStyle & 2) !== 0
|
|
37
38
|
? 'bold'
|
|
38
39
|
: undefined;
|
|
39
|
-
const textDecoration = htmlStyle['text-decoration'] === 'underline' || htmlStyle
|
|
40
|
+
const textDecoration = htmlStyle['text-decoration'] === 'underline' || htmlStyle['textDecoration'] === 'underline'
|
|
40
41
|
? 'underline'
|
|
41
42
|
: token.fontStyle && (token.fontStyle & 4) !== 0
|
|
42
43
|
? 'underline'
|
|
43
44
|
: undefined;
|
|
44
|
-
return {
|
|
45
|
-
color: htmlStyle
|
|
46
|
-
backgroundColor: htmlStyle['background-color'] ?? htmlStyle
|
|
45
|
+
return definedOptions({
|
|
46
|
+
color: htmlStyle['color'] ?? token.color,
|
|
47
|
+
backgroundColor: htmlStyle['background-color'] ?? htmlStyle['backgroundColor'] ?? token.bgColor,
|
|
47
48
|
fontStyle,
|
|
48
49
|
fontWeight,
|
|
49
50
|
textDecoration,
|
|
50
|
-
};
|
|
51
|
+
});
|
|
51
52
|
}
|
|
52
53
|
function mergeLine(line, lightTokens, darkTokens) {
|
|
53
54
|
if (line.length === 0)
|
|
@@ -68,7 +69,7 @@ function mergeLine(line, lightTokens, darkTokens) {
|
|
|
68
69
|
continue;
|
|
69
70
|
const light = readStyle(tokenAt(lightRanges, start));
|
|
70
71
|
const dark = readStyle(tokenAt(darkRanges, start));
|
|
71
|
-
tokens.push({
|
|
72
|
+
tokens.push(definedOptions({
|
|
72
73
|
content: line.slice(start, end),
|
|
73
74
|
color: light.color,
|
|
74
75
|
backgroundColor: light.backgroundColor,
|
|
@@ -80,7 +81,7 @@ function mergeLine(line, lightTokens, darkTokens) {
|
|
|
80
81
|
darkFontStyle: dark.fontStyle,
|
|
81
82
|
darkFontWeight: dark.fontWeight,
|
|
82
83
|
darkTextDecoration: dark.textDecoration,
|
|
83
|
-
});
|
|
84
|
+
}));
|
|
84
85
|
}
|
|
85
86
|
return tokens;
|
|
86
87
|
}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte'; import { cn } from '../../utils.js';
|
|
2
|
+
import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; import { onMount } from 'svelte'; import { provideCommitContext } from './context.svelte.js';
|
|
3
3
|
let { defaultOpen = false, open = $bindable(defaultOpen), class: className = '', children, onopenchange, ...rest }: { open?: boolean; defaultOpen?: boolean; class?: string; children?: Snippet; onopenchange?: (open: boolean) => void; [key: string]: unknown } = $props();
|
|
4
|
+
let detailsElement: HTMLDetailsElement;
|
|
5
|
+
let actionDisclosure = false;
|
|
6
|
+
provideCommitContext({ get open() { return open; }, toggle() { open = !open; } });
|
|
7
|
+
onMount(() => {
|
|
8
|
+
const markAction = (event: MouseEvent) => {
|
|
9
|
+
actionDisclosure = event.target instanceof Element && Boolean(event.target.closest('[data-slot="commit-actions"]'));
|
|
10
|
+
};
|
|
11
|
+
detailsElement.addEventListener('click', markAction, true);
|
|
12
|
+
return () => detailsElement.removeEventListener('click', markAction, true);
|
|
13
|
+
});
|
|
14
|
+
function handleToggle(event: Event): void {
|
|
15
|
+
const next = (event.currentTarget as HTMLDetailsElement).open;
|
|
16
|
+
if (actionDisclosure) {
|
|
17
|
+
actionDisclosure = false;
|
|
18
|
+
detailsElement.open = false;
|
|
19
|
+
open = false;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
open = next;
|
|
23
|
+
onopenchange?.(next);
|
|
24
|
+
}
|
|
4
25
|
</script>
|
|
5
|
-
<details class={cn('svadmin-ai rounded-lg border border-border bg-background text-foreground', className)} {open} ontoggle={
|
|
26
|
+
<details bind:this={detailsElement} class={cn('svadmin-ai rounded-lg border border-border bg-background text-foreground', className)} {open} ontoggle={handleToggle} {...rest}>{@render children?.()}</details>
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
<script lang="ts">import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; let { class: className = '', children, ...rest }: { class?: string; children?: Snippet; [key: string]: unknown } = $props()
|
|
2
|
-
<div
|
|
3
|
-
class={cn('flex items-center gap-1', className)}
|
|
4
|
-
role="group"
|
|
5
|
-
onclickcapture={(event) => event.preventDefault()}
|
|
6
|
-
onclick={(event) => {
|
|
7
|
-
event.stopPropagation();
|
|
8
|
-
}}
|
|
9
|
-
onkeydown={(event) => event.stopPropagation()}
|
|
10
|
-
{...rest}
|
|
11
|
-
>{@render children?.()}</div>
|
|
1
|
+
<script lang="ts">import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; let { class: className = '', children, ...rest }: { class?: string; children?: Snippet; [key: string]: unknown } = $props(); function preventDisclosure(event: MouseEvent | KeyboardEvent): void { event.preventDefault(); event.stopPropagation(); }</script>
|
|
2
|
+
<div class={cn('flex items-center gap-1', className)} role="group" data-slot="commit-actions" onmousedown={preventDisclosure} onclick={preventDisclosure} onkeydown={preventDisclosure} {...rest}>{@render children?.()}</div>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte'; import { onDestroy } from 'svelte'; import { Check, Copy } from '@lucide/svelte'; import { cn } from '../../utils.js';
|
|
3
3
|
let { hash, timeout = 2000, class: className = '', children, oncopy, onerror, disabled = false, ...rest }: { hash: string; timeout?: number; class?: string; children?: Snippet<[boolean]>; oncopy?: () => void; onerror?: (error: Error) => void; disabled?: boolean; [key: string]: unknown } = $props();
|
|
4
4
|
let copied = $state(false); let timer: ReturnType<typeof setTimeout> | undefined;
|
|
5
|
-
async function copyHash(): Promise<void> { if (disabled || copied) return; if (typeof navigator === 'undefined' || !navigator.clipboard?.writeText) { onerror?.(new Error('Clipboard API not available')); return; } try { await navigator.clipboard.writeText(hash); copied = true; oncopy?.(); if (timer) clearTimeout(timer); timer = setTimeout(() => { copied = false; }, timeout); } catch (error) { onerror?.(error instanceof Error ? error : new Error('Copy failed')); } }
|
|
5
|
+
async function copyHash(event: MouseEvent): Promise<void> { event.preventDefault(); event.stopPropagation(); if (disabled || copied) return; if (typeof navigator === 'undefined' || !navigator.clipboard?.writeText) { onerror?.(new Error('Clipboard API not available')); return; } try { await navigator.clipboard.writeText(hash); copied = true; oncopy?.(); if (timer) clearTimeout(timer); timer = setTimeout(() => { copied = false; }, timeout); } catch (error) { onerror?.(error instanceof Error ? error : new Error('Copy failed')); } }
|
|
6
6
|
onDestroy(() => { if (timer) clearTimeout(timer); });
|
|
7
7
|
</script>
|
|
8
8
|
<button type="button" class={cn('inline-flex size-7 shrink-0 items-center justify-center rounded-md border-0 bg-transparent text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring disabled:opacity-50', className)} aria-label={copied ? 'Copied commit hash' : 'Copy commit hash'} {disabled} onclick={copyHash} {...rest}>{#if children}{@render children(copied)}{:else}{#if copied}<Check size={14} aria-hidden="true" />{:else}<Copy size={14} aria-hidden="true" />{/if}{/if}</button>
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte'; import { cn } from '../../utils.js';
|
|
2
|
+
import type { Snippet } from 'svelte'; import { cn } from '../../utils.js'; import { useCommitContext } from './context.svelte.js';
|
|
3
3
|
let { class: className = '', children, ...rest }: { class?: string; children?: Snippet; [key: string]: unknown } = $props();
|
|
4
|
+
const disclosure = useCommitContext();
|
|
5
|
+
function toggle(event: MouseEvent): void {
|
|
6
|
+
if (event.target instanceof Element && event.target.closest('[data-slot="commit-actions"]')) return;
|
|
7
|
+
disclosure.toggle();
|
|
8
|
+
}
|
|
9
|
+
function toggleFromKeyboard(event: KeyboardEvent): void {
|
|
10
|
+
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
toggle(event as unknown as MouseEvent);
|
|
13
|
+
}
|
|
4
14
|
</script>
|
|
5
|
-
<
|
|
15
|
+
<div class={cn('group flex cursor-pointer items-center justify-between gap-4 p-3 text-left transition-opacity hover:opacity-80 focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-ring', className)} role="button" tabindex="0" aria-expanded={disclosure.open} onclick={toggle} onkeydown={toggleFromKeyboard} {...rest}>{@render children?.()}</div>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface CommitDisclosureContext {
|
|
2
|
+
readonly open: boolean;
|
|
3
|
+
toggle(): void;
|
|
4
|
+
}
|
|
5
|
+
export declare function provideCommitContext(value: CommitDisclosureContext): CommitDisclosureContext;
|
|
6
|
+
export declare function useCommitContext(component?: string): CommitDisclosureContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createContext } from 'svelte';
|
|
2
|
+
const [getCommitContext, setCommitContext] = createContext();
|
|
3
|
+
export function provideCommitContext(value) {
|
|
4
|
+
setCommitContext(value);
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export function useCommitContext(component = 'Commit component') {
|
|
8
|
+
try {
|
|
9
|
+
return getCommitContext();
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new Error(`${component} must be used within Commit`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { definedOptions, definedReactiveOptions } from '@svadmin/core/options';
|
|
3
|
+
|
|
2
4
|
import type { Snippet } from 'svelte';
|
|
3
5
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
6
|
import { BarChart3, ChevronDown, ChevronUp, CircleAlert } from '@lucide/svelte';
|
|
@@ -78,22 +80,22 @@
|
|
|
78
80
|
if (onOpenChange !== onopenchange) onOpenChange?.(nextOpen);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
provideContextContext({
|
|
83
|
+
provideContextContext(definedReactiveOptions({
|
|
82
84
|
get usedTokens() { return safeUsed; },
|
|
83
85
|
get maxTokens() { return safeLimit ?? 0; },
|
|
84
86
|
get usage() {
|
|
85
|
-
return usage ?? {
|
|
87
|
+
return usage ?? definedOptions({
|
|
86
88
|
inputTokens: resolvedInputTokens,
|
|
87
89
|
outputTokens: resolvedOutputTokens,
|
|
88
90
|
cachedInputTokens: resolvedCachedTokens,
|
|
89
|
-
};
|
|
91
|
+
});
|
|
90
92
|
},
|
|
91
93
|
get modelId() { return modelId; },
|
|
92
94
|
get cost() { return cost; },
|
|
93
95
|
get currency() { return currency; },
|
|
94
96
|
get open() { return open; },
|
|
95
97
|
setOpen,
|
|
96
|
-
});
|
|
98
|
+
}));
|
|
97
99
|
|
|
98
100
|
$effect(() => {
|
|
99
101
|
if (!children || !open || typeof document === 'undefined') return;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<script lang="ts">
|
|
14
|
+
import { definedOptions } from '@svadmin/core/options';
|
|
14
15
|
import { cn } from '../../utils.js';
|
|
15
16
|
|
|
16
17
|
let { tokens, costText, class: className = '', children, ...rest }: TokensWithCostProps = $props();
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
|
|
22
23
|
<span {...rest} class={cn('svadmin-ai-tokens-with-cost', className)} data-slot="tokens-with-cost">
|
|
23
24
|
{#if children}
|
|
24
|
-
{@render children({ tokens: formattedTokens, costText })}
|
|
25
|
+
{@render children(definedOptions({ tokens: formattedTokens, costText }))}
|
|
25
26
|
{:else}
|
|
26
27
|
{formattedTokens}
|
|
27
28
|
{#if costText}<span class="svadmin-ai-tokens-with-cost__cost">• {costText}</span>{/if}
|