@ruckc/truss-chat 1.48.1 → 1.49.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.
- package/dist/ChatMessage.svelte +35 -4
- package/dist/ChatMessage.svelte.d.ts +16 -0
- package/dist/ChatSessions.svelte +59 -16
- package/dist/ChatSessions.svelte.d.ts +28 -8
- package/dist/ChatThread.svelte +22 -6
- package/dist/ChatThread.svelte.d.ts +10 -2
- package/dist/QuestionAnswers.svelte +29 -9
- package/dist/QuestionAnswers.svelte.d.ts +15 -3
- package/dist/QuestionForm.svelte +85 -19
- package/dist/QuestionForm.svelte.d.ts +41 -1
- package/dist/ToolCall.svelte +78 -13
- package/dist/ToolCall.svelte.d.ts +42 -2
- package/dist/ToolCalls.svelte +17 -3
- package/dist/ToolCalls.svelte.d.ts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/labels.d.ts +6 -0
- package/dist/labels.js +23 -0
- package/package.json +2 -2
package/dist/ChatMessage.svelte
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type ChatMessageLabels = {
|
|
3
|
+
/** Name of a `user` message when `label` is not set. */
|
|
4
|
+
you: string;
|
|
5
|
+
/** Name of an `assistant` message when `label` is not set. */
|
|
6
|
+
assistant: string;
|
|
7
|
+
/** Button that unfolds the reasoning. */
|
|
8
|
+
showReasoning: string;
|
|
9
|
+
/** Button that folds the reasoning. */
|
|
10
|
+
hideReasoning: string;
|
|
11
|
+
/** Text beside the reasoning button while the reply is streaming and the reasoning is folded. */
|
|
12
|
+
thinking: string;
|
|
13
|
+
/** Text read out by the thread's live region when a message finishes: the speaker and the (cut) message. */
|
|
14
|
+
announcement: (name: string, text: string) => string;
|
|
15
|
+
};
|
|
16
|
+
const DEFAULTS: ChatMessageLabels = {
|
|
17
|
+
you: 'You',
|
|
18
|
+
assistant: 'Assistant',
|
|
19
|
+
showReasoning: 'Show reasoning',
|
|
20
|
+
hideReasoning: 'Hide reasoning',
|
|
21
|
+
thinking: 'Thinking…',
|
|
22
|
+
announcement: (name, text) => `${name}: ${text}`
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
1
26
|
<script lang="ts">
|
|
27
|
+
import { useLabels } from './labels.js';
|
|
2
28
|
import { untrack, type Snippet } from 'svelte';
|
|
3
29
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
30
|
import { Icon } from '@ruckc/truss-ui';
|
|
@@ -23,6 +49,7 @@
|
|
|
23
49
|
link,
|
|
24
50
|
class: klass = '',
|
|
25
51
|
children,
|
|
52
|
+
labels,
|
|
26
53
|
...rest
|
|
27
54
|
}: Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
28
55
|
/** `user` messages are right-aligned bubbles; `assistant` messages are full-width prose. */
|
|
@@ -65,8 +92,12 @@
|
|
|
65
92
|
markdown?: boolean;
|
|
66
93
|
/** The message body in place of `text`, for anything it cannot express. Same as `content`. */
|
|
67
94
|
children?: Snippet;
|
|
95
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
96
|
+
labels?: Partial<ChatMessageLabels>;
|
|
68
97
|
} = $props();
|
|
69
98
|
|
|
99
|
+
const L = useLabels('ChatMessage', DEFAULTS, () => labels);
|
|
100
|
+
|
|
70
101
|
const thread = useThread();
|
|
71
102
|
let body: HTMLDivElement;
|
|
72
103
|
const codeSnippet = $derived(code ?? thread?.code);
|
|
@@ -81,13 +112,13 @@
|
|
|
81
112
|
else localShow = next;
|
|
82
113
|
}
|
|
83
114
|
const rid = $props.id();
|
|
84
|
-
const name = $derived(label ?? (role === 'user' ?
|
|
115
|
+
const name = $derived(label ?? (role === 'user' ? L.you : L.assistant));
|
|
85
116
|
|
|
86
117
|
/** At most this many characters are read out; the full reply stays in the log. */
|
|
87
118
|
const MAX = 300;
|
|
88
119
|
function speak() {
|
|
89
120
|
const said = body.textContent!.replace(/\s+/g, ' ').trim();
|
|
90
|
-
thread?.announce(
|
|
121
|
+
thread?.announce(L.announcement(name, said.length > MAX ? `${said.slice(0, MAX)}…` : said));
|
|
91
122
|
}
|
|
92
123
|
|
|
93
124
|
let was = false;
|
|
@@ -110,8 +141,8 @@
|
|
|
110
141
|
<div class="reasoning" data-open={shown}>
|
|
111
142
|
<button type="button" class="rtoggle" aria-expanded={shown} aria-controls="{rid}-reasoning" onclick={toggleReasoning}>
|
|
112
143
|
<span class="chev" data-open={shown}><Icon name="chevron-down" /></span>
|
|
113
|
-
{shown ?
|
|
114
|
-
{#if streaming && !shown}<span class="thinking">
|
|
144
|
+
{shown ? L.hideReasoning : L.showReasoning}
|
|
145
|
+
{#if streaming && !shown}<span class="thinking">{L.thinking}</span>{/if}
|
|
115
146
|
</button>
|
|
116
147
|
<div class="rbody" id="{rid}-reasoning" hidden={!shown}>{#if shown}<Markdown text={reasoning} code={codeSnippet} link={linkSnippet} />{/if}</div>
|
|
117
148
|
</div>
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
export type ChatMessageLabels = {
|
|
2
|
+
/** Name of a `user` message when `label` is not set. */
|
|
3
|
+
you: string;
|
|
4
|
+
/** Name of an `assistant` message when `label` is not set. */
|
|
5
|
+
assistant: string;
|
|
6
|
+
/** Button that unfolds the reasoning. */
|
|
7
|
+
showReasoning: string;
|
|
8
|
+
/** Button that folds the reasoning. */
|
|
9
|
+
hideReasoning: string;
|
|
10
|
+
/** Text beside the reasoning button while the reply is streaming and the reasoning is folded. */
|
|
11
|
+
thinking: string;
|
|
12
|
+
/** Text read out by the thread's live region when a message finishes: the speaker and the (cut) message. */
|
|
13
|
+
announcement: (name: string, text: string) => string;
|
|
14
|
+
};
|
|
1
15
|
import { type Snippet } from 'svelte';
|
|
2
16
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
17
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
@@ -47,6 +61,8 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'>
|
|
|
47
61
|
markdown?: boolean;
|
|
48
62
|
/** The message body in place of `text`, for anything it cannot express. Same as `content`. */
|
|
49
63
|
children?: Snippet;
|
|
64
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
65
|
+
labels?: Partial<ChatMessageLabels>;
|
|
50
66
|
};
|
|
51
67
|
declare const ChatMessage: import("svelte").Component<$$ComponentProps, {}, "showReasoning">;
|
|
52
68
|
type ChatMessage = ReturnType<typeof ChatMessage>;
|
package/dist/ChatSessions.svelte
CHANGED
|
@@ -12,9 +12,39 @@
|
|
|
12
12
|
/** When the conversation was last active: shown as a right-aligned, live, narrow relative time ("5m", "3h", "2d") on the title line. */
|
|
13
13
|
time?: TimeValue;
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
export type ChatSessionsLabels = {
|
|
17
|
+
/** Accessible name of the list and its heading. */
|
|
18
|
+
conversations: string;
|
|
19
|
+
/** Text of the switch that includes archived conversations. */
|
|
20
|
+
showArchived: string;
|
|
21
|
+
/** Badge on an archived conversation. */
|
|
22
|
+
archived: string;
|
|
23
|
+
/** Text of the Rename menu entry (and the name of the rename field). */
|
|
24
|
+
rename: string;
|
|
25
|
+
/** Text of the Archive menu entry. */
|
|
26
|
+
archive: string;
|
|
27
|
+
/** Text of the Unarchive menu entry. */
|
|
28
|
+
unarchive: string;
|
|
29
|
+
/** Accessible name of each row's menu button, followed by the conversation's title. */
|
|
30
|
+
actions: string;
|
|
31
|
+
/** Shown when nothing is listed. */
|
|
32
|
+
empty: string;
|
|
33
|
+
};
|
|
34
|
+
const DEFAULTS: ChatSessionsLabels = {
|
|
35
|
+
conversations: 'Conversations',
|
|
36
|
+
showArchived: 'Show archived',
|
|
37
|
+
archived: 'Archived',
|
|
38
|
+
rename: 'Rename',
|
|
39
|
+
archive: 'Archive',
|
|
40
|
+
unarchive: 'Unarchive',
|
|
41
|
+
actions: 'Actions',
|
|
42
|
+
empty: 'No conversations'
|
|
43
|
+
};
|
|
15
44
|
</script>
|
|
16
45
|
|
|
17
46
|
<script lang="ts">
|
|
47
|
+
import { useLabels } from './labels.js';
|
|
18
48
|
import { tick } from 'svelte';
|
|
19
49
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
20
50
|
import { MenuButton, RelativeTime, Switch } from '@ruckc/truss-ui';
|
|
@@ -27,14 +57,15 @@
|
|
|
27
57
|
onselect,
|
|
28
58
|
onrename,
|
|
29
59
|
onarchive,
|
|
30
|
-
label
|
|
31
|
-
archivedLabel
|
|
32
|
-
archivedText
|
|
33
|
-
renameLabel
|
|
34
|
-
archiveLabel
|
|
35
|
-
unarchiveLabel
|
|
36
|
-
actionsLabel
|
|
37
|
-
empty
|
|
60
|
+
label: labelProp,
|
|
61
|
+
archivedLabel: archivedLabelProp,
|
|
62
|
+
archivedText: archivedTextProp,
|
|
63
|
+
renameLabel: renameLabelProp,
|
|
64
|
+
archiveLabel: archiveLabelProp,
|
|
65
|
+
unarchiveLabel: unarchiveLabelProp,
|
|
66
|
+
actionsLabel: actionsLabelProp,
|
|
67
|
+
empty: emptyProp,
|
|
68
|
+
labels,
|
|
38
69
|
class: klass = '',
|
|
39
70
|
...rest
|
|
40
71
|
}: Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
@@ -50,26 +81,38 @@
|
|
|
50
81
|
onrename?: (id: string, title: string) => void;
|
|
51
82
|
/** The reader archived (`true`) or unarchived (`false`) a conversation from its menu. You update `sessions`; an archived one disappears unless `showArchived`. */
|
|
52
83
|
onarchive?: (id: string, archived: boolean) => void;
|
|
53
|
-
/** Accessible name of the list and its heading. */
|
|
84
|
+
/** Accessible name of the list and its heading (default: "Conversations"). */
|
|
54
85
|
label?: string;
|
|
55
|
-
/** Text of the switch that includes archived conversations. */
|
|
86
|
+
/** Text of the switch that includes archived conversations (default: "Show archived"). */
|
|
56
87
|
archivedLabel?: string;
|
|
57
|
-
/** Badge on an archived conversation. */
|
|
88
|
+
/** Badge on an archived conversation (default: "Archived"). */
|
|
58
89
|
archivedText?: string;
|
|
59
|
-
/** Text of the Rename menu entry
|
|
90
|
+
/** Text of the Rename menu entry and the name of the rename field (default: "Rename"). */
|
|
60
91
|
renameLabel?: string;
|
|
61
|
-
/** Text of the Archive menu entry. */
|
|
92
|
+
/** Text of the Archive menu entry (default: "Archive"). */
|
|
62
93
|
archiveLabel?: string;
|
|
63
|
-
/** Text of the Unarchive menu entry. */
|
|
94
|
+
/** Text of the Unarchive menu entry (default: "Unarchive"). */
|
|
64
95
|
unarchiveLabel?: string;
|
|
65
|
-
/** Accessible name of each row's menu button, followed by the title. */
|
|
96
|
+
/** Accessible name of each row's menu button, followed by the title (default: "Actions"). */
|
|
66
97
|
actionsLabel?: string;
|
|
67
|
-
/** Shown when nothing is listed. */
|
|
98
|
+
/** Shown when nothing is listed (default: "No conversations"). */
|
|
68
99
|
empty?: string;
|
|
69
100
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<section>`. `class` is added to it. */
|
|
70
101
|
class?: string;
|
|
102
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
103
|
+
labels?: Partial<ChatSessionsLabels>;
|
|
71
104
|
} = $props();
|
|
72
105
|
|
|
106
|
+
const L = useLabels('ChatSessions', DEFAULTS, () => labels);
|
|
107
|
+
const label = $derived(labelProp ?? L.conversations);
|
|
108
|
+
const archivedLabel = $derived(archivedLabelProp ?? L.showArchived);
|
|
109
|
+
const archivedText = $derived(archivedTextProp ?? L.archived);
|
|
110
|
+
const renameLabel = $derived(renameLabelProp ?? L.rename);
|
|
111
|
+
const archiveLabel = $derived(archiveLabelProp ?? L.archive);
|
|
112
|
+
const unarchiveLabel = $derived(unarchiveLabelProp ?? L.unarchive);
|
|
113
|
+
const actionsLabel = $derived(actionsLabelProp ?? L.actions);
|
|
114
|
+
const empty = $derived(emptyProp ?? L.empty);
|
|
115
|
+
|
|
73
116
|
let editing = $state<string | undefined>();
|
|
74
117
|
const shown = $derived(sessions.filter((s) => showArchived || !s.archived));
|
|
75
118
|
const hasArchived = $derived(sessions.some((s) => s.archived));
|
|
@@ -10,6 +10,24 @@ export type ChatSession = {
|
|
|
10
10
|
/** When the conversation was last active: shown as a right-aligned, live, narrow relative time ("5m", "3h", "2d") on the title line. */
|
|
11
11
|
time?: TimeValue;
|
|
12
12
|
};
|
|
13
|
+
export type ChatSessionsLabels = {
|
|
14
|
+
/** Accessible name of the list and its heading. */
|
|
15
|
+
conversations: string;
|
|
16
|
+
/** Text of the switch that includes archived conversations. */
|
|
17
|
+
showArchived: string;
|
|
18
|
+
/** Badge on an archived conversation. */
|
|
19
|
+
archived: string;
|
|
20
|
+
/** Text of the Rename menu entry (and the name of the rename field). */
|
|
21
|
+
rename: string;
|
|
22
|
+
/** Text of the Archive menu entry. */
|
|
23
|
+
archive: string;
|
|
24
|
+
/** Text of the Unarchive menu entry. */
|
|
25
|
+
unarchive: string;
|
|
26
|
+
/** Accessible name of each row's menu button, followed by the conversation's title. */
|
|
27
|
+
actions: string;
|
|
28
|
+
/** Shown when nothing is listed. */
|
|
29
|
+
empty: string;
|
|
30
|
+
};
|
|
13
31
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
14
32
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
15
33
|
/** The conversations, in the order to show them. */
|
|
@@ -24,24 +42,26 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'>
|
|
|
24
42
|
onrename?: (id: string, title: string) => void;
|
|
25
43
|
/** The reader archived (`true`) or unarchived (`false`) a conversation from its menu. You update `sessions`; an archived one disappears unless `showArchived`. */
|
|
26
44
|
onarchive?: (id: string, archived: boolean) => void;
|
|
27
|
-
/** Accessible name of the list and its heading. */
|
|
45
|
+
/** Accessible name of the list and its heading (default: "Conversations"). */
|
|
28
46
|
label?: string;
|
|
29
|
-
/** Text of the switch that includes archived conversations. */
|
|
47
|
+
/** Text of the switch that includes archived conversations (default: "Show archived"). */
|
|
30
48
|
archivedLabel?: string;
|
|
31
|
-
/** Badge on an archived conversation. */
|
|
49
|
+
/** Badge on an archived conversation (default: "Archived"). */
|
|
32
50
|
archivedText?: string;
|
|
33
|
-
/** Text of the Rename menu entry
|
|
51
|
+
/** Text of the Rename menu entry and the name of the rename field (default: "Rename"). */
|
|
34
52
|
renameLabel?: string;
|
|
35
|
-
/** Text of the Archive menu entry. */
|
|
53
|
+
/** Text of the Archive menu entry (default: "Archive"). */
|
|
36
54
|
archiveLabel?: string;
|
|
37
|
-
/** Text of the Unarchive menu entry. */
|
|
55
|
+
/** Text of the Unarchive menu entry (default: "Unarchive"). */
|
|
38
56
|
unarchiveLabel?: string;
|
|
39
|
-
/** Accessible name of each row's menu button, followed by the title. */
|
|
57
|
+
/** Accessible name of each row's menu button, followed by the title (default: "Actions"). */
|
|
40
58
|
actionsLabel?: string;
|
|
41
|
-
/** Shown when nothing is listed. */
|
|
59
|
+
/** Shown when nothing is listed (default: "No conversations"). */
|
|
42
60
|
empty?: string;
|
|
43
61
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<section>`. `class` is added to it. */
|
|
44
62
|
class?: string;
|
|
63
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
64
|
+
labels?: Partial<ChatSessionsLabels>;
|
|
45
65
|
};
|
|
46
66
|
declare const ChatSessions: import("svelte").Component<$$ComponentProps, {
|
|
47
67
|
rename: (id: string) => void;
|
package/dist/ChatThread.svelte
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type ChatThreadLabels = {
|
|
3
|
+
/** Accessible name of the scrolling log. */
|
|
4
|
+
conversation: string;
|
|
5
|
+
/** Text of the button shown once the reader has scrolled away from the latest message. */
|
|
6
|
+
jump: string;
|
|
7
|
+
};
|
|
8
|
+
const DEFAULTS: ChatThreadLabels = { conversation: 'Conversation', jump: 'Jump to latest' };
|
|
9
|
+
</script>
|
|
10
|
+
|
|
1
11
|
<script lang="ts">
|
|
12
|
+
import { useLabels } from './labels.js';
|
|
2
13
|
import { onDestroy, onMount, type Snippet } from 'svelte';
|
|
3
14
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
15
|
import { Button } from '@ruckc/truss-ui';
|
|
5
16
|
import { provideThread } from './internal/chat-context.js';
|
|
6
17
|
|
|
7
18
|
let {
|
|
8
|
-
label
|
|
9
|
-
jumpLabel
|
|
19
|
+
label,
|
|
20
|
+
jumpLabel,
|
|
10
21
|
follow = $bindable(true),
|
|
11
22
|
showReasoning = $bindable(false),
|
|
12
23
|
reasoningStorageKey,
|
|
@@ -14,11 +25,12 @@
|
|
|
14
25
|
link,
|
|
15
26
|
class: klass = '',
|
|
16
27
|
children,
|
|
28
|
+
labels,
|
|
17
29
|
...rest
|
|
18
30
|
}: Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role'> & {
|
|
19
|
-
/** Accessible name of the scrolling log. */
|
|
31
|
+
/** Accessible name of the scrolling log (default: "Conversation"). */
|
|
20
32
|
label?: string;
|
|
21
|
-
/** Text of the button shown once the reader has scrolled away from the latest message. */
|
|
33
|
+
/** Text of the button shown once the reader has scrolled away from the latest message (default: "Jump to latest"). */
|
|
22
34
|
jumpLabel?: string;
|
|
23
35
|
/** Whether the thread is following the bottom. It sticks to the bottom while content grows, turns `false` when the reader scrolls up and `true` again at the bottom or on "Jump to latest". Bindable: set it to `true` to scroll to the latest message. */
|
|
24
36
|
follow?: boolean;
|
|
@@ -40,8 +52,12 @@
|
|
|
40
52
|
class?: string;
|
|
41
53
|
/** The messages: `ChatMessage`, `ChatStatus` and anything else. A `ChatMessage` inside reports its finished reply to the thread's live region. */
|
|
42
54
|
children: Snippet;
|
|
55
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
56
|
+
labels?: Partial<ChatThreadLabels>;
|
|
43
57
|
} = $props();
|
|
44
58
|
|
|
59
|
+
const L = useLabels('ChatThread', DEFAULTS, () => labels);
|
|
60
|
+
|
|
45
61
|
let log: HTMLDivElement;
|
|
46
62
|
let content: HTMLDivElement;
|
|
47
63
|
let live = $state('');
|
|
@@ -146,11 +162,11 @@
|
|
|
146
162
|
|
|
147
163
|
<div {...rest} class={['thread', klass]}>
|
|
148
164
|
<!-- aria-live="off": a log is implicitly polite, which would announce every streamed token; finished replies go through the live region below instead -->
|
|
149
|
-
<div class="log" role="log" aria-live="off" aria-label={label} bind:this={log} onscroll={(e) => { onscroll(e); measure(); }} onfocusin={infocus} onfocusout={outfocus}>
|
|
165
|
+
<div class="log" role="log" aria-live="off" aria-label={label ?? L.conversation} bind:this={log} onscroll={(e) => { onscroll(e); measure(); }} onfocusin={infocus} onfocusout={outfocus}>
|
|
150
166
|
<div class="content" bind:this={content}>{@render children()}</div>
|
|
151
167
|
</div>
|
|
152
168
|
{#if !follow && !stepAside}
|
|
153
|
-
<div class="jump"><Button size="sm" variant="tonal" icon="arrow-down" onclick={jump}>{jumpLabel}</Button></div>
|
|
169
|
+
<div class="jump"><Button size="sm" variant="tonal" icon="arrow-down" onclick={jump}>{jumpLabel ?? L.jump}</Button></div>
|
|
154
170
|
{/if}
|
|
155
171
|
<div class="tr-visually-hidden" role="status" aria-live="polite" aria-atomic="true">{live}</div>
|
|
156
172
|
</div>
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
export type ChatThreadLabels = {
|
|
2
|
+
/** Accessible name of the scrolling log. */
|
|
3
|
+
conversation: string;
|
|
4
|
+
/** Text of the button shown once the reader has scrolled away from the latest message. */
|
|
5
|
+
jump: string;
|
|
6
|
+
};
|
|
1
7
|
import { type Snippet } from 'svelte';
|
|
2
8
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
9
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role'> & {
|
|
4
|
-
/** Accessible name of the scrolling log. */
|
|
10
|
+
/** Accessible name of the scrolling log (default: "Conversation"). */
|
|
5
11
|
label?: string;
|
|
6
|
-
/** Text of the button shown once the reader has scrolled away from the latest message. */
|
|
12
|
+
/** Text of the button shown once the reader has scrolled away from the latest message (default: "Jump to latest"). */
|
|
7
13
|
jumpLabel?: string;
|
|
8
14
|
/** Whether the thread is following the bottom. It sticks to the bottom while content grows, turns `false` when the reader scrolls up and `true` again at the bottom or on "Jump to latest". Bindable: set it to `true` to scroll to the latest message. */
|
|
9
15
|
follow?: boolean;
|
|
@@ -31,6 +37,8 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class
|
|
|
31
37
|
class?: string;
|
|
32
38
|
/** The messages: `ChatMessage`, `ChatStatus` and anything else. A `ChatMessage` inside reports its finished reply to the thread's live region. */
|
|
33
39
|
children: Snippet;
|
|
40
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
41
|
+
labels?: Partial<ChatThreadLabels>;
|
|
34
42
|
};
|
|
35
43
|
declare const ChatThread: import("svelte").Component<$$ComponentProps, {}, "showReasoning" | "follow">;
|
|
36
44
|
type ChatThread = ReturnType<typeof ChatThread>;
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type QuestionAnswersLabels = {
|
|
3
|
+
/** The heading of an answered form. */
|
|
4
|
+
answered: string;
|
|
5
|
+
/** The heading of a declined form. */
|
|
6
|
+
declined: string;
|
|
7
|
+
/** Shown for a question without an answer. */
|
|
8
|
+
empty: string;
|
|
9
|
+
/** The free-text answer, after the selected options. */
|
|
10
|
+
other: (text: string) => string;
|
|
11
|
+
};
|
|
12
|
+
const DEFAULTS: QuestionAnswersLabels = { answered: 'You answered', declined: 'You declined to answer', empty: 'No answer', other: (text) => `Other: ${text}` };
|
|
13
|
+
</script>
|
|
14
|
+
|
|
1
15
|
<script lang="ts">
|
|
16
|
+
import { useLabels } from './labels.js';
|
|
2
17
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
18
|
import type { Question, QuestionAnswer } from './QuestionForm.svelte';
|
|
4
19
|
|
|
@@ -6,9 +21,10 @@
|
|
|
6
21
|
questions,
|
|
7
22
|
answers = [],
|
|
8
23
|
declined = false,
|
|
9
|
-
label
|
|
10
|
-
declinedLabel
|
|
11
|
-
emptyLabel
|
|
24
|
+
label,
|
|
25
|
+
declinedLabel,
|
|
26
|
+
emptyLabel,
|
|
27
|
+
labels,
|
|
12
28
|
class: klass = '',
|
|
13
29
|
...rest
|
|
14
30
|
}: Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
@@ -18,23 +34,27 @@
|
|
|
18
34
|
answers?: QuestionAnswer[];
|
|
19
35
|
/** The whole form was skipped (`onskip`): shows `declinedLabel` instead of `label`, and every question as unanswered. */
|
|
20
36
|
declined?: boolean;
|
|
21
|
-
/** The heading of an answered form
|
|
37
|
+
/** The heading of an answered form (default: "You answered"). */
|
|
22
38
|
label?: string;
|
|
23
|
-
/** The heading of a declined form. */
|
|
39
|
+
/** The heading of a declined form (default: "You declined to answer"). */
|
|
24
40
|
declinedLabel?: string;
|
|
25
|
-
/** Shown for a question without an answer
|
|
41
|
+
/** Shown for a question without an answer: an `optional` one that was passed, or any question when `declined` (default: "No answer"). */
|
|
26
42
|
emptyLabel?: string;
|
|
27
43
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<section>`. `class` is added to it. */
|
|
28
44
|
class?: string;
|
|
45
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
46
|
+
labels?: Partial<QuestionAnswersLabels>;
|
|
29
47
|
} = $props();
|
|
30
48
|
|
|
31
|
-
const
|
|
49
|
+
const L = useLabels('QuestionAnswers', DEFAULTS, () => labels);
|
|
50
|
+
|
|
51
|
+
const parts = (a: QuestionAnswer | undefined) => (declined || !a ? [] : [...a.selected, ...(a.other ? [L.other(a.other)] : [])]);
|
|
32
52
|
const uid = $props.id();
|
|
33
53
|
</script>
|
|
34
54
|
|
|
35
55
|
<!-- a read-only record of an exchange, aligned and tinted like the user's own message so the thread reads question, then answer -->
|
|
36
56
|
<section {...rest} class={['qa', klass]} data-declined={declined} aria-labelledby="{uid}-h">
|
|
37
|
-
<p class="who" id="{uid}-h">{declined ? declinedLabel : label}</p>
|
|
57
|
+
<p class="who" id="{uid}-h">{declined ? (declinedLabel ?? L.declined) : (label ?? L.answered)}</p>
|
|
38
58
|
<dl class="list">
|
|
39
59
|
{#each questions as item, i (i)}
|
|
40
60
|
{@const shown = parts(answers[i])}
|
|
@@ -43,7 +63,7 @@
|
|
|
43
63
|
{#if shown.length}
|
|
44
64
|
{#each shown as s, j (j)}<dd class="a">{s}</dd>{/each}
|
|
45
65
|
{:else}
|
|
46
|
-
<dd class="a empty">{emptyLabel}</dd>
|
|
66
|
+
<dd class="a empty">{emptyLabel ?? L.empty}</dd>
|
|
47
67
|
{/if}
|
|
48
68
|
</div>
|
|
49
69
|
{/each}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export type QuestionAnswersLabels = {
|
|
2
|
+
/** The heading of an answered form. */
|
|
3
|
+
answered: string;
|
|
4
|
+
/** The heading of a declined form. */
|
|
5
|
+
declined: string;
|
|
6
|
+
/** Shown for a question without an answer. */
|
|
7
|
+
empty: string;
|
|
8
|
+
/** The free-text answer, after the selected options. */
|
|
9
|
+
other: (text: string) => string;
|
|
10
|
+
};
|
|
1
11
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
12
|
import type { Question, QuestionAnswer } from './QuestionForm.svelte';
|
|
3
13
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'> & {
|
|
@@ -7,14 +17,16 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'class'>
|
|
|
7
17
|
answers?: QuestionAnswer[];
|
|
8
18
|
/** The whole form was skipped (`onskip`): shows `declinedLabel` instead of `label`, and every question as unanswered. */
|
|
9
19
|
declined?: boolean;
|
|
10
|
-
/** The heading of an answered form
|
|
20
|
+
/** The heading of an answered form (default: "You answered"). */
|
|
11
21
|
label?: string;
|
|
12
|
-
/** The heading of a declined form. */
|
|
22
|
+
/** The heading of a declined form (default: "You declined to answer"). */
|
|
13
23
|
declinedLabel?: string;
|
|
14
|
-
/** Shown for a question without an answer
|
|
24
|
+
/** Shown for a question without an answer: an `optional` one that was passed, or any question when `declined` (default: "No answer"). */
|
|
15
25
|
emptyLabel?: string;
|
|
16
26
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<section>`. `class` is added to it. */
|
|
17
27
|
class?: string;
|
|
28
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
29
|
+
labels?: Partial<QuestionAnswersLabels>;
|
|
18
30
|
};
|
|
19
31
|
declare const QuestionAnswers: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
20
32
|
type QuestionAnswers = ReturnType<typeof QuestionAnswers>;
|
package/dist/QuestionForm.svelte
CHANGED
|
@@ -12,9 +12,69 @@
|
|
|
12
12
|
};
|
|
13
13
|
/** What was answered to one question. `selected` holds option labels; `other` is the free-text answer. */
|
|
14
14
|
export type QuestionAnswer = { selected: string[]; other?: string };
|
|
15
|
+
|
|
16
|
+
export type QuestionFormLabels = {
|
|
17
|
+
/** Accessible name of the form and of the tab list. */
|
|
18
|
+
questions: string;
|
|
19
|
+
/** Text of the final button (the review page's, or the tabs mode's). */
|
|
20
|
+
submit: string;
|
|
21
|
+
/** Text of the button that skips the whole form. */
|
|
22
|
+
skip: string;
|
|
23
|
+
/** Text of the button back to the previous page. */
|
|
24
|
+
back: string;
|
|
25
|
+
/** Text of the button on to the next page. */
|
|
26
|
+
next: string;
|
|
27
|
+
/** Name of a tab or page for a question without a `header`; `n` counts from 1. */
|
|
28
|
+
question: (n: number) => string;
|
|
29
|
+
/** Progress line above a question: its number and how many there are. */
|
|
30
|
+
step: (n: number, total: number) => string;
|
|
31
|
+
/** Added to the progress line for an optional question. */
|
|
32
|
+
optional: string;
|
|
33
|
+
/** Screen-reader text after the name of a tab whose question is answered. */
|
|
34
|
+
answered: string;
|
|
35
|
+
/** Label of the free-text field. */
|
|
36
|
+
other: string;
|
|
37
|
+
/** Placeholder of the free-text field. */
|
|
38
|
+
otherPlaceholder: string;
|
|
39
|
+
/** A free-text answer, in the review. */
|
|
40
|
+
otherAnswer: (text: string) => string;
|
|
41
|
+
/** Review text for a question without an answer. */
|
|
42
|
+
noAnswer: string;
|
|
43
|
+
/** An option the author recommends. */
|
|
44
|
+
recommended: (label: string) => string;
|
|
45
|
+
/** Small heading of the review page. */
|
|
46
|
+
review: string;
|
|
47
|
+
/** Title of the review page. */
|
|
48
|
+
reviewTitle: string;
|
|
49
|
+
/** Button that goes back to a question from the review. */
|
|
50
|
+
edit: string;
|
|
51
|
+
/** Accessible name of that button; `question` is the question's text. */
|
|
52
|
+
editAnswer: (question: string) => string;
|
|
53
|
+
};
|
|
54
|
+
const DEFAULTS: QuestionFormLabels = {
|
|
55
|
+
questions: 'Questions',
|
|
56
|
+
submit: 'Submit',
|
|
57
|
+
skip: 'Skip',
|
|
58
|
+
back: 'Back',
|
|
59
|
+
next: 'Next',
|
|
60
|
+
question: (n) => `Question ${n}`,
|
|
61
|
+
step: (n, total) => `Question ${n} of ${total}`,
|
|
62
|
+
optional: 'optional',
|
|
63
|
+
answered: '(answered)',
|
|
64
|
+
other: 'Other',
|
|
65
|
+
otherPlaceholder: 'Type your own answer',
|
|
66
|
+
otherAnswer: (text) => `Other: ${text}`,
|
|
67
|
+
noAnswer: 'No answer',
|
|
68
|
+
recommended: (label) => `${label} (Recommended)`,
|
|
69
|
+
review: 'Review',
|
|
70
|
+
reviewTitle: 'Review your answers',
|
|
71
|
+
edit: 'Edit',
|
|
72
|
+
editAnswer: (question) => `Edit answer: ${question}`
|
|
73
|
+
};
|
|
15
74
|
</script>
|
|
16
75
|
|
|
17
76
|
<script lang="ts">
|
|
77
|
+
import { useLabels } from './labels.js';
|
|
18
78
|
import { tick, untrack, type Snippet } from 'svelte';
|
|
19
79
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
20
80
|
import { Button, Checkbox, Icon, Kbd, RadioGroup, Textarea } from '@ruckc/truss-ui';
|
|
@@ -24,12 +84,13 @@
|
|
|
24
84
|
allowOther = true,
|
|
25
85
|
onsubmit,
|
|
26
86
|
onskip,
|
|
27
|
-
submitLabel
|
|
87
|
+
submitLabel,
|
|
28
88
|
mode = 'wizard',
|
|
29
89
|
review = 'auto',
|
|
30
90
|
header,
|
|
31
91
|
numberKeys = false,
|
|
32
92
|
submitOnModEnter = false,
|
|
93
|
+
labels,
|
|
33
94
|
class: klass = '',
|
|
34
95
|
...rest
|
|
35
96
|
}: Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'onkeydown' | 'onsubmit'> & {
|
|
@@ -41,7 +102,7 @@
|
|
|
41
102
|
onsubmit?: (answers: QuestionAnswer[]) => void;
|
|
42
103
|
/** Called when the user skips the whole form (the Skip button or Escape). Without it there is no Skip button and Escape does nothing. */
|
|
43
104
|
onskip?: () => void;
|
|
44
|
-
/** Text of the final button on the review page. */
|
|
105
|
+
/** Text of the final button on the review page (default: "Submit"). */
|
|
45
106
|
submitLabel?: string;
|
|
46
107
|
/**
|
|
47
108
|
* `wizard` (default): one question per page, then a review page.
|
|
@@ -63,8 +124,13 @@
|
|
|
63
124
|
submitOnModEnter?: boolean;
|
|
64
125
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<div>`. `class` is added to it. */
|
|
65
126
|
class?: string;
|
|
127
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
128
|
+
labels?: Partial<QuestionFormLabels>;
|
|
66
129
|
} = $props();
|
|
67
130
|
|
|
131
|
+
const L = useLabels('QuestionForm', DEFAULTS, () => labels);
|
|
132
|
+
const submitText = $derived(submitLabel ?? L.submit);
|
|
133
|
+
|
|
68
134
|
const uid = $props.id();
|
|
69
135
|
const qs = untrack(() => questions);
|
|
70
136
|
const tabs = untrack(() => mode) === 'tabs';
|
|
@@ -131,11 +197,11 @@
|
|
|
131
197
|
return other ? { selected: picked[i], other } : { selected: picked[i] };
|
|
132
198
|
})
|
|
133
199
|
);
|
|
134
|
-
const summary = (a: QuestionAnswer) => [...a.selected, ...(a.other ? [
|
|
200
|
+
const summary = (a: QuestionAnswer) => [...a.selected, ...(a.other ? [L.otherAnswer(a.other)] : [])].join(', ') || L.noAnswer;
|
|
135
201
|
const submit = () => onsubmit?.($state.snapshot(answers));
|
|
136
202
|
const canSubmit = $derived(qs.every((item, i) => item.optional || isAnswered(i)));
|
|
137
|
-
const optionLabel = (o: Question['options'][number]) => (o.recommended ?
|
|
138
|
-
const tabLabel = (i: number) => qs[i].header ??
|
|
203
|
+
const optionLabel = (o: Question['options'][number]) => (o.recommended ? L.recommended(o.label) : o.label);
|
|
204
|
+
const tabLabel = (i: number) => qs[i].header ?? L.question(i + 1);
|
|
139
205
|
const selectTab = (i: number, focus = false) => {
|
|
140
206
|
page = (i + total) % total;
|
|
141
207
|
if (focus) document.getElementById(`${uid}-tab-${page}`)?.focus();
|
|
@@ -217,25 +283,25 @@
|
|
|
217
283
|
/>
|
|
218
284
|
{/if}
|
|
219
285
|
{#if allowOther}
|
|
220
|
-
<Textarea label=
|
|
286
|
+
<Textarea label={L.other} placeholder={L.otherPlaceholder} rows={1} autosize bind:value={() => others[page], (v) => setOther(page, v)} />
|
|
221
287
|
{/if}
|
|
222
288
|
{/snippet}
|
|
223
289
|
|
|
224
290
|
<!-- the keydown handler lives on the wrapper so Enter and Escape work from any control inside -->
|
|
225
|
-
<div {...rest} data-tr-question-form class={['qf', klass]} role="group" aria-label=
|
|
291
|
+
<div {...rest} data-tr-question-form class={['qf', klass]} role="group" aria-label={L.questions} {onkeydown} onkeyup={() => (arrowed = false)}>
|
|
226
292
|
{#if header}<div class="attn">{@render header()}</div>{/if}
|
|
227
293
|
{#if tabs}
|
|
228
|
-
<div class="tabs" role="tablist" aria-label=
|
|
294
|
+
<div class="tabs" role="tablist" aria-label={L.questions} aria-orientation="horizontal">
|
|
229
295
|
{#each qs as _, i (i)}
|
|
230
296
|
<button type="button" role="tab" class="tab" id="{uid}-tab-{i}" aria-selected={page === i} aria-controls="{uid}-panel" tabindex={page === i ? 0 : -1} onclick={() => selectTab(i)} onkeydown={onTabKey}>
|
|
231
|
-
{tabLabel(i)}{#if isAnswered(i)}<span class="tick"><Icon name="tick" /></span><span class="tr-visually-hidden">
|
|
297
|
+
{tabLabel(i)}{#if isAnswered(i)}<span class="tick"><Icon name="tick" /></span><span class="tr-visually-hidden"> {L.answered}</span>{/if}
|
|
232
298
|
</button>
|
|
233
299
|
{/each}
|
|
234
300
|
</div>
|
|
235
301
|
{/if}
|
|
236
302
|
{#if reviewing}
|
|
237
|
-
<p class="step">
|
|
238
|
-
<h3 class="title" tabindex="-1" bind:this={head}>
|
|
303
|
+
<p class="step">{L.review}</p>
|
|
304
|
+
<h3 class="title" tabindex="-1" bind:this={head}>{L.reviewTitle}</h3>
|
|
239
305
|
<ol class="review">
|
|
240
306
|
{#each qs as item, i (i)}
|
|
241
307
|
<li>
|
|
@@ -243,7 +309,7 @@
|
|
|
243
309
|
<span class="rq">{item.question}</span>
|
|
244
310
|
<span class="rv">{summary(answers[i])}</span>
|
|
245
311
|
</div>
|
|
246
|
-
<Button size="sm" variant="minimal" onclick={() => edit(i)} aria-label={
|
|
312
|
+
<Button size="sm" variant="minimal" onclick={() => edit(i)} aria-label={L.editAnswer(item.question)}>{L.edit}</Button>
|
|
247
313
|
</li>
|
|
248
314
|
{/each}
|
|
249
315
|
</ol>
|
|
@@ -252,24 +318,24 @@
|
|
|
252
318
|
{#if tabs}
|
|
253
319
|
<div class="panel" role="tabpanel" id="{uid}-panel" aria-labelledby="{uid}-tab-{page}">{@render question()}</div>
|
|
254
320
|
{:else}
|
|
255
|
-
{#if numbered || q.optional}<p class="step">{#if numbered}
|
|
321
|
+
{#if numbered || q.optional}<p class="step">{#if numbered}{L.step(page + 1, total)}{/if}{#if q.optional}{numbered ? ' · ' : ''}{L.optional}{/if}</p>{/if}
|
|
256
322
|
{@render question()}
|
|
257
323
|
{/if}
|
|
258
324
|
{/key}
|
|
259
325
|
{/if}
|
|
260
326
|
|
|
261
327
|
<div class="nav">
|
|
262
|
-
{#if onskip}<Button variant="minimal" onclick={onskip}>
|
|
328
|
+
{#if onskip}<Button variant="minimal" onclick={onskip}>{L.skip}</Button>{/if}
|
|
263
329
|
<span class="grow"></span>
|
|
264
330
|
{#if tabs}
|
|
265
331
|
{#if submitOnModEnter}<span class="hint"><Kbd keys="mod+enter" /></span>{/if}
|
|
266
|
-
<Button disabled={!canSubmit} onclick={submit}>{
|
|
332
|
+
<Button disabled={!canSubmit} onclick={submit}>{submitText}</Button>
|
|
267
333
|
{:else if reviewing}
|
|
268
|
-
<Button variant="outlined" onclick={() => go(total - 1)}>
|
|
269
|
-
<Button onclick={submit}>{
|
|
334
|
+
<Button variant="outlined" onclick={() => go(total - 1)}>{L.back}</Button>
|
|
335
|
+
<Button onclick={submit}>{submitText}</Button>
|
|
270
336
|
{:else}
|
|
271
|
-
<Button variant="outlined" disabled={page === 0} onclick={back}>
|
|
272
|
-
<Button disabled={!canNext} onclick={next}>{!withReview && lastPage ?
|
|
337
|
+
<Button variant="outlined" disabled={page === 0} onclick={back}>{L.back}</Button>
|
|
338
|
+
<Button disabled={!canNext} onclick={next}>{!withReview && lastPage ? submitText : L.next}</Button>
|
|
273
339
|
{/if}
|
|
274
340
|
</div>
|
|
275
341
|
</div>
|
|
@@ -18,6 +18,44 @@ export type QuestionAnswer = {
|
|
|
18
18
|
selected: string[];
|
|
19
19
|
other?: string;
|
|
20
20
|
};
|
|
21
|
+
export type QuestionFormLabels = {
|
|
22
|
+
/** Accessible name of the form and of the tab list. */
|
|
23
|
+
questions: string;
|
|
24
|
+
/** Text of the final button (the review page's, or the tabs mode's). */
|
|
25
|
+
submit: string;
|
|
26
|
+
/** Text of the button that skips the whole form. */
|
|
27
|
+
skip: string;
|
|
28
|
+
/** Text of the button back to the previous page. */
|
|
29
|
+
back: string;
|
|
30
|
+
/** Text of the button on to the next page. */
|
|
31
|
+
next: string;
|
|
32
|
+
/** Name of a tab or page for a question without a `header`; `n` counts from 1. */
|
|
33
|
+
question: (n: number) => string;
|
|
34
|
+
/** Progress line above a question: its number and how many there are. */
|
|
35
|
+
step: (n: number, total: number) => string;
|
|
36
|
+
/** Added to the progress line for an optional question. */
|
|
37
|
+
optional: string;
|
|
38
|
+
/** Screen-reader text after the name of a tab whose question is answered. */
|
|
39
|
+
answered: string;
|
|
40
|
+
/** Label of the free-text field. */
|
|
41
|
+
other: string;
|
|
42
|
+
/** Placeholder of the free-text field. */
|
|
43
|
+
otherPlaceholder: string;
|
|
44
|
+
/** A free-text answer, in the review. */
|
|
45
|
+
otherAnswer: (text: string) => string;
|
|
46
|
+
/** Review text for a question without an answer. */
|
|
47
|
+
noAnswer: string;
|
|
48
|
+
/** An option the author recommends. */
|
|
49
|
+
recommended: (label: string) => string;
|
|
50
|
+
/** Small heading of the review page. */
|
|
51
|
+
review: string;
|
|
52
|
+
/** Title of the review page. */
|
|
53
|
+
reviewTitle: string;
|
|
54
|
+
/** Button that goes back to a question from the review. */
|
|
55
|
+
edit: string;
|
|
56
|
+
/** Accessible name of that button; `question` is the question's text. */
|
|
57
|
+
editAnswer: (question: string) => string;
|
|
58
|
+
};
|
|
21
59
|
import { type Snippet } from 'svelte';
|
|
22
60
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
23
61
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'onkeydown' | 'onsubmit'> & {
|
|
@@ -29,7 +67,7 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class
|
|
|
29
67
|
onsubmit?: (answers: QuestionAnswer[]) => void;
|
|
30
68
|
/** Called when the user skips the whole form (the Skip button or Escape). Without it there is no Skip button and Escape does nothing. */
|
|
31
69
|
onskip?: () => void;
|
|
32
|
-
/** Text of the final button on the review page. */
|
|
70
|
+
/** Text of the final button on the review page (default: "Submit"). */
|
|
33
71
|
submitLabel?: string;
|
|
34
72
|
/**
|
|
35
73
|
* `wizard` (default): one question per page, then a review page.
|
|
@@ -51,6 +89,8 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class
|
|
|
51
89
|
submitOnModEnter?: boolean;
|
|
52
90
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<div>`. `class` is added to it. */
|
|
53
91
|
class?: string;
|
|
92
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
93
|
+
labels?: Partial<QuestionFormLabels>;
|
|
54
94
|
};
|
|
55
95
|
declare const QuestionForm: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
56
96
|
type QuestionForm = ReturnType<typeof QuestionForm>;
|
package/dist/ToolCall.svelte
CHANGED
|
@@ -1,4 +1,69 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type ToolCallLabels = {
|
|
3
|
+
/** Status text: queued. */
|
|
4
|
+
pending: string;
|
|
5
|
+
/** Status text: waiting for the user to confirm or approve the call. */
|
|
6
|
+
awaiting: string;
|
|
7
|
+
/** Status text: running. */
|
|
8
|
+
in_progress: string;
|
|
9
|
+
/** Status text: finished. */
|
|
10
|
+
completed: string;
|
|
11
|
+
/** Status text: failed. */
|
|
12
|
+
failed: string;
|
|
13
|
+
/** Status text: not run. */
|
|
14
|
+
skipped: string;
|
|
15
|
+
/** Prefix of the status line in the details: `Status: Done`. */
|
|
16
|
+
status: string;
|
|
17
|
+
/** Prefix of the details line for a skipped call's `reason`. */
|
|
18
|
+
reason: string;
|
|
19
|
+
/** Prefix of the details line for a call's `summary`. */
|
|
20
|
+
result: string;
|
|
21
|
+
/** Title of the Input section. */
|
|
22
|
+
input: string;
|
|
23
|
+
/** Title of the Output section. */
|
|
24
|
+
output: string;
|
|
25
|
+
/** Title of the Error section. */
|
|
26
|
+
error: string;
|
|
27
|
+
/** Button that unfolds the Input section (`inputOpen={false}`). */
|
|
28
|
+
showInput: string;
|
|
29
|
+
/** Button that folds the Input section again. */
|
|
30
|
+
hideInput: string;
|
|
31
|
+
/** Accessible name of a section's copy button; `section` is that section's title. */
|
|
32
|
+
copy: (section: string) => string;
|
|
33
|
+
/** Button that unfolds the lines cut by `maxOutputLines`. */
|
|
34
|
+
showAll: (hidden: number) => string;
|
|
35
|
+
/** Button that folds them again. */
|
|
36
|
+
showLess: string;
|
|
37
|
+
/** Live-region text after a successful copy. */
|
|
38
|
+
copied: string;
|
|
39
|
+
/** Live-region text when copying failed. */
|
|
40
|
+
copyFailed: string;
|
|
41
|
+
};
|
|
42
|
+
const DEFAULTS: ToolCallLabels = {
|
|
43
|
+
pending: 'Pending',
|
|
44
|
+
awaiting: 'Awaiting confirmation',
|
|
45
|
+
in_progress: 'Running',
|
|
46
|
+
completed: 'Done',
|
|
47
|
+
failed: 'Failed',
|
|
48
|
+
skipped: 'Not run',
|
|
49
|
+
status: 'Status',
|
|
50
|
+
reason: 'Reason',
|
|
51
|
+
result: 'Result',
|
|
52
|
+
input: 'Input',
|
|
53
|
+
output: 'Output',
|
|
54
|
+
error: 'Error',
|
|
55
|
+
showInput: 'Show input',
|
|
56
|
+
hideInput: 'Hide input',
|
|
57
|
+
copy: (section) => `Copy ${section.toLowerCase()}`,
|
|
58
|
+
showAll: (hidden) => `Show all (${hidden} more ${hidden === 1 ? 'line' : 'lines'})`,
|
|
59
|
+
showLess: 'Show less',
|
|
60
|
+
copied: 'Copied',
|
|
61
|
+
copyFailed: 'Copy failed'
|
|
62
|
+
};
|
|
63
|
+
</script>
|
|
64
|
+
|
|
1
65
|
<script lang="ts">
|
|
66
|
+
import { useLabels } from './labels.js';
|
|
2
67
|
import { onDestroy, untrack, type Snippet } from 'svelte';
|
|
3
68
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
69
|
import { Button, Dialog, Icon, Tooltip } from '@ruckc/truss-ui';
|
|
@@ -33,8 +98,8 @@
|
|
|
33
98
|
variant?: 'row' | 'chip';
|
|
34
99
|
/** Turns `name` into what is displayed, e.g. `formatToolName`, which strips an `mcp__server__` prefix and replaces underscores with spaces (`mcp__github__create_issue` becomes `create issue`). */
|
|
35
100
|
formatName?: (name: string) => string;
|
|
36
|
-
/** Replaces the
|
|
37
|
-
labels?: Partial<
|
|
101
|
+
/** Replaces the built-in texts (translation): the status texts (Pending, Awaiting confirmation, Running, Done, Failed, Not run), the section titles, the buttons and the copy announcements. Missing keys keep the defaults. */
|
|
102
|
+
labels?: Partial<ToolCallLabels>;
|
|
38
103
|
/** A one-line result for the row, e.g. "3 rows" or the error message: shown between the name and the status, muted and cut with an ellipsis (the full text is its tooltip and is repeated in the details). In a chip it is added to the tooltip and the accessible name. */
|
|
39
104
|
summary?: string;
|
|
40
105
|
/** Why the call did not run, for `status="skipped"`, e.g. "depends on a denied change". Takes the place of `summary`: shown in the row beside the status, added to the chip's tooltip and accessible name, and repeated as "Reason" in the details. */
|
|
@@ -65,19 +130,19 @@
|
|
|
65
130
|
} = $props();
|
|
66
131
|
|
|
67
132
|
const uid = $props.id();
|
|
68
|
-
const
|
|
133
|
+
const L = useLabels('ToolCall', DEFAULTS, () => labels);
|
|
69
134
|
const ICONS = { pending: 'clock', awaiting: 'help', in_progress: 'refresh', completed: 'success', failed: 'error', skipped: 'ban' } as const;
|
|
70
135
|
const shown = $derived(formatName ? formatName(name) : name);
|
|
71
|
-
const statusText = $derived(
|
|
136
|
+
const statusText = $derived(L[status]);
|
|
72
137
|
|
|
73
138
|
const custom = $derived(typeof details === 'function' ? details : undefined);
|
|
74
139
|
const mode = $derived(typeof details === 'string' ? details : variant === 'chip' ? 'dialog' : 'inline');
|
|
75
140
|
const present = (v: unknown) => v !== undefined && v !== null;
|
|
76
141
|
const sections = $derived(
|
|
77
142
|
[
|
|
78
|
-
present(input) && { key: 'input', title:
|
|
79
|
-
present(output) && { key: 'output', title:
|
|
80
|
-
!!error && { key: 'error', title:
|
|
143
|
+
present(input) && { key: 'input', title: L.input, text: formatValue(input) },
|
|
144
|
+
present(output) && { key: 'output', title: L.output, text: formatValue(output) },
|
|
145
|
+
!!error && { key: 'error', title: L.error, text: error }
|
|
81
146
|
].filter((s) => !!s)
|
|
82
147
|
);
|
|
83
148
|
const limit = $derived(maxOutputLines !== undefined && maxOutputLines >= 1 ? Math.floor(maxOutputLines) : undefined);
|
|
@@ -129,8 +194,8 @@
|
|
|
129
194
|
{/snippet}
|
|
130
195
|
|
|
131
196
|
{#snippet body()}
|
|
132
|
-
<p class="line">
|
|
133
|
-
{#if line}<p class="line">{reason ?
|
|
197
|
+
<p class="line">{L.status}: <strong>{statusText}</strong></p>
|
|
198
|
+
{#if line}<p class="line">{reason ? L.reason : L.result}: <strong>{line}</strong></p>{/if}
|
|
134
199
|
{#if custom}{@render custom()}{/if}
|
|
135
200
|
{#each sections as s (s.key)}
|
|
136
201
|
{@const c = cut(s.text, s.key)}
|
|
@@ -140,20 +205,20 @@
|
|
|
140
205
|
<span class="sec-title">{s.title}</span>
|
|
141
206
|
<span class="sec-actions">
|
|
142
207
|
{#if s.key === 'input' && !inputOpen}
|
|
143
|
-
<Button variant="minimal" size="sm" aria-expanded={inputShown} aria-controls="{uid}-{s.key}" onclick={() => (inputShown = !inputShown)}>{inputShown ?
|
|
208
|
+
<Button variant="minimal" size="sm" aria-expanded={inputShown} aria-controls="{uid}-{s.key}" onclick={() => (inputShown = !inputShown)}>{inputShown ? L.hideInput : L.showInput}</Button>
|
|
144
209
|
{/if}
|
|
145
|
-
<Button variant="minimal" size="sm" icon={copied?.key === s.key && copied.ok ? 'tick' : 'copy'} aria-label=
|
|
210
|
+
<Button variant="minimal" size="sm" icon={copied?.key === s.key && copied.ok ? 'tick' : 'copy'} aria-label={L.copy(s.title)} onclick={() => copy(s.key, s.text)} />
|
|
146
211
|
</span>
|
|
147
212
|
</div>
|
|
148
213
|
{#if !folded}
|
|
149
214
|
<pre id="{uid}-{s.key}" {@attach focusable} role="region" aria-label={s.title}>{c.text}</pre>
|
|
150
215
|
{#if c.hidden}
|
|
151
|
-
<Button variant="minimal" size="sm" aria-expanded={c.open} aria-controls="{uid}-{s.key}" onclick={() => (expanded[s.key] = !c.open)}>{c.open ?
|
|
216
|
+
<Button variant="minimal" size="sm" aria-expanded={c.open} aria-controls="{uid}-{s.key}" onclick={() => (expanded[s.key] = !c.open)}>{c.open ? L.showLess : L.showAll(c.hidden)}</Button>
|
|
152
217
|
{/if}
|
|
153
218
|
{/if}
|
|
154
219
|
</section>
|
|
155
220
|
{/each}
|
|
156
|
-
<span class="tr-visually-hidden" role="status" aria-live="polite">{copied ? (copied.ok ?
|
|
221
|
+
<span class="tr-visually-hidden" role="status" aria-live="polite">{copied ? (copied.ok ? L.copied : L.copyFailed) : ''}</span>
|
|
157
222
|
{/snippet}
|
|
158
223
|
|
|
159
224
|
<div {...rest} class={['tool', klass]} data-status={status} data-variant={variant} data-open={open && hasBody && mode === 'inline'}>
|
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
export type ToolCallLabels = {
|
|
2
|
+
/** Status text: queued. */
|
|
3
|
+
pending: string;
|
|
4
|
+
/** Status text: waiting for the user to confirm or approve the call. */
|
|
5
|
+
awaiting: string;
|
|
6
|
+
/** Status text: running. */
|
|
7
|
+
in_progress: string;
|
|
8
|
+
/** Status text: finished. */
|
|
9
|
+
completed: string;
|
|
10
|
+
/** Status text: failed. */
|
|
11
|
+
failed: string;
|
|
12
|
+
/** Status text: not run. */
|
|
13
|
+
skipped: string;
|
|
14
|
+
/** Prefix of the status line in the details: `Status: Done`. */
|
|
15
|
+
status: string;
|
|
16
|
+
/** Prefix of the details line for a skipped call's `reason`. */
|
|
17
|
+
reason: string;
|
|
18
|
+
/** Prefix of the details line for a call's `summary`. */
|
|
19
|
+
result: string;
|
|
20
|
+
/** Title of the Input section. */
|
|
21
|
+
input: string;
|
|
22
|
+
/** Title of the Output section. */
|
|
23
|
+
output: string;
|
|
24
|
+
/** Title of the Error section. */
|
|
25
|
+
error: string;
|
|
26
|
+
/** Button that unfolds the Input section (`inputOpen={false}`). */
|
|
27
|
+
showInput: string;
|
|
28
|
+
/** Button that folds the Input section again. */
|
|
29
|
+
hideInput: string;
|
|
30
|
+
/** Accessible name of a section's copy button; `section` is that section's title. */
|
|
31
|
+
copy: (section: string) => string;
|
|
32
|
+
/** Button that unfolds the lines cut by `maxOutputLines`. */
|
|
33
|
+
showAll: (hidden: number) => string;
|
|
34
|
+
/** Button that folds them again. */
|
|
35
|
+
showLess: string;
|
|
36
|
+
/** Live-region text after a successful copy. */
|
|
37
|
+
copied: string;
|
|
38
|
+
/** Live-region text when copying failed. */
|
|
39
|
+
copyFailed: string;
|
|
40
|
+
};
|
|
1
41
|
import { type Snippet } from 'svelte';
|
|
2
42
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
43
|
type Status = 'pending' | 'awaiting' | 'in_progress' | 'completed' | 'failed' | 'skipped';
|
|
@@ -10,8 +50,8 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class
|
|
|
10
50
|
variant?: 'row' | 'chip';
|
|
11
51
|
/** Turns `name` into what is displayed, e.g. `formatToolName`, which strips an `mcp__server__` prefix and replaces underscores with spaces (`mcp__github__create_issue` becomes `create issue`). */
|
|
12
52
|
formatName?: (name: string) => string;
|
|
13
|
-
/** Replaces the
|
|
14
|
-
labels?: Partial<
|
|
53
|
+
/** Replaces the built-in texts (translation): the status texts (Pending, Awaiting confirmation, Running, Done, Failed, Not run), the section titles, the buttons and the copy announcements. Missing keys keep the defaults. */
|
|
54
|
+
labels?: Partial<ToolCallLabels>;
|
|
15
55
|
/** A one-line result for the row, e.g. "3 rows" or the error message: shown between the name and the status, muted and cut with an ellipsis (the full text is its tooltip and is repeated in the details). In a chip it is added to the tooltip and the accessible name. */
|
|
16
56
|
summary?: string;
|
|
17
57
|
/** Why the call did not run, for `status="skipped"`, e.g. "depends on a denied change". Takes the place of `summary`: shown in the row beside the status, added to the chip's tooltip and accessible name, and repeated as "Reason" in the details. */
|
package/dist/ToolCalls.svelte
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type ToolCallsLabels = {
|
|
3
|
+
/** Accessible name of the group. */
|
|
4
|
+
toolCalls: string;
|
|
5
|
+
};
|
|
6
|
+
const DEFAULTS: ToolCallsLabels = { toolCalls: 'Tool calls' };
|
|
7
|
+
</script>
|
|
8
|
+
|
|
1
9
|
<script lang="ts">
|
|
10
|
+
import { useLabels } from './labels.js';
|
|
2
11
|
import type { Snippet } from 'svelte';
|
|
3
12
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
13
|
|
|
5
14
|
let {
|
|
6
|
-
label
|
|
15
|
+
label,
|
|
7
16
|
class: klass = '',
|
|
8
17
|
children,
|
|
18
|
+
labels,
|
|
9
19
|
...rest
|
|
10
20
|
}: Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
|
|
11
|
-
/** Accessible name of the group. */
|
|
21
|
+
/** Accessible name of the group (default: "Tool calls"). */
|
|
12
22
|
label?: string;
|
|
13
23
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<div>`. `class` is added to it. */
|
|
14
24
|
class?: string;
|
|
15
25
|
/** The `ToolCall`s. Chips wrap onto new lines, so many of them fit a narrow sidebar or a phone. */
|
|
16
26
|
children: Snippet;
|
|
27
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
28
|
+
labels?: Partial<ToolCallsLabels>;
|
|
17
29
|
} = $props();
|
|
30
|
+
|
|
31
|
+
const L = useLabels('ToolCalls', DEFAULTS, () => labels);
|
|
18
32
|
</script>
|
|
19
33
|
|
|
20
|
-
<div {...rest} class={['calls', klass]} role="group" aria-label={label}>{@render children()}</div>
|
|
34
|
+
<div {...rest} class={['calls', klass]} role="group" aria-label={label ?? L.toolCalls}>{@render children()}</div>
|
|
21
35
|
|
|
22
36
|
<style>
|
|
23
37
|
.calls { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--tr-space-1); width: 100%; min-width: 0; max-width: 100%; }
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
export type ToolCallsLabels = {
|
|
2
|
+
/** Accessible name of the group. */
|
|
3
|
+
toolCalls: string;
|
|
4
|
+
};
|
|
1
5
|
import type { Snippet } from 'svelte';
|
|
2
6
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
7
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class'> & {
|
|
4
|
-
/** Accessible name of the group. */
|
|
8
|
+
/** Accessible name of the group (default: "Tool calls"). */
|
|
5
9
|
label?: string;
|
|
6
10
|
/** Other attributes (`data-testid`, `id`, ...) go to the root `<div>`. `class` is added to it. */
|
|
7
11
|
class?: string;
|
|
8
12
|
/** The `ToolCall`s. Chips wrap onto new lines, so many of them fit a narrow sidebar or a phone. */
|
|
9
13
|
children: Snippet;
|
|
14
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
15
|
+
labels?: Partial<ToolCallsLabels>;
|
|
10
16
|
};
|
|
11
17
|
declare const ToolCalls: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
12
18
|
type ToolCalls = ReturnType<typeof ToolCalls>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export { default as ChatThread } from './ChatThread.svelte';
|
|
2
2
|
export { default as ChatMessage } from './ChatMessage.svelte';
|
|
3
3
|
export { default as ToolCall } from './ToolCall.svelte';
|
|
4
|
+
export type { ToolCallLabels } from './ToolCall.svelte';
|
|
4
5
|
export { default as ToolCalls } from './ToolCalls.svelte';
|
|
6
|
+
export type { ToolCallsLabels } from './ToolCalls.svelte';
|
|
7
|
+
export type { ChatThreadLabels } from './ChatThread.svelte';
|
|
8
|
+
export type { ChatMessageLabels } from './ChatMessage.svelte';
|
|
9
|
+
export type { ChatSessionsLabels } from './ChatSessions.svelte';
|
|
10
|
+
export type { QuestionAnswersLabels } from './QuestionAnswers.svelte';
|
|
5
11
|
export { default as ChatComposer } from './ChatComposer.svelte';
|
|
6
12
|
export { default as ChatStatus } from './ChatStatus.svelte';
|
|
7
13
|
export { default as ChatSessions } from './ChatSessions.svelte';
|
|
@@ -9,7 +15,7 @@ export type { ChatSession } from './ChatSessions.svelte';
|
|
|
9
15
|
export { default as ChatTitle } from './ChatTitle.svelte';
|
|
10
16
|
export { default as QuestionForm } from './QuestionForm.svelte';
|
|
11
17
|
export { default as QuestionAnswers } from './QuestionAnswers.svelte';
|
|
12
|
-
export type { Question, QuestionAnswer } from './QuestionForm.svelte';
|
|
18
|
+
export type { Question, QuestionAnswer, QuestionFormLabels } from './QuestionForm.svelte';
|
|
13
19
|
export { formatToolName, previewInput, formatValue } from './chat.js';
|
|
14
20
|
export { default as CommentThread } from './CommentThread.svelte';
|
|
15
21
|
export { default as Comment } from './Comment.svelte';
|
package/dist/labels.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** One label: a string, or a function for a string with values (`(n: number) => \`${n} selected\``). That covers plurals and word order without an ICU dependency. */
|
|
2
|
+
export type LabelValue = string | ((...args: never[]) => string);
|
|
3
|
+
/** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
|
|
4
|
+
export declare function useLabels<T extends object>(component: string, defaults: T, prop: () => Partial<T> | undefined): T;
|
|
5
|
+
/** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
|
|
6
|
+
export declare function labelFor<T extends LabelValue>(component: string, key: string, fallback: T): T;
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
const KEY = Symbol.for('@ruckc/truss-ui:labels');
|
|
3
|
+
const STATE = Symbol.for('@ruckc/truss-ui:labels-config');
|
|
4
|
+
// What `configureLabels` set for a component. Read-only here (no copy of this file has to create the state), and `Object(undefined)` is `{}`.
|
|
5
|
+
const config = (component) => Object(Object(globalThis[STATE])[component]);
|
|
6
|
+
// The strongest defined value wins (layers run from the weakest to the strongest). This reader is written without branches on purpose
|
|
7
|
+
// (`filter`, `Object(x)`, no `?.` / `??` / `if`): it is copied into every package, and V8 coverage counts each short-circuit as a branch,
|
|
8
|
+
// so a copy would need a test under every combination of context and config to reach the per-file coverage floor.
|
|
9
|
+
const none = () => undefined;
|
|
10
|
+
const pick = (...layers) => layers.filter((v) => v !== undefined).at(-1);
|
|
11
|
+
/** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
|
|
12
|
+
export function useLabels(component, defaults, prop) {
|
|
13
|
+
const lookup = [getContext(KEY), none].filter(Boolean)[0];
|
|
14
|
+
const out = {};
|
|
15
|
+
for (const k of Object.keys(defaults))
|
|
16
|
+
Object.defineProperty(out, k, { enumerable: true, get: () => pick(labelFor(component, k, defaults[k]), Object(lookup(component))[k], Object(prop())[k]) });
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
|
|
20
|
+
export function labelFor(component, key, fallback) {
|
|
21
|
+
return pick(fallback, config(component)[key]);
|
|
22
|
+
}
|
|
23
|
+
// </reader>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruckc/truss-chat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "Chat building blocks for Truss UI: thread, messages, tool calls, composer, status line and a question form",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@ruckc/truss-ui": "^1.0.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ruckc/truss-markdown": "^1.
|
|
30
|
+
"@ruckc/truss-markdown": "^1.49.0"
|
|
31
31
|
},
|
|
32
32
|
"author": "Curtis Ruck",
|
|
33
33
|
"homepage": "https://truss.ruck.io",
|