@widgetic/chat 0.1.39 → 0.1.40
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 +71 -0
- package/dist/components/Chat.svelte +35 -1
- package/dist/components/Chat.svelte.d.ts +29 -0
- package/dist/components/ChatComposer.svelte +5 -1
- package/dist/components/ChatMessages.svelte +545 -210
- package/dist/components/ChatMessages.svelte.d.ts +18 -0
- package/dist/components/agent/AgentAvatar.svelte +153 -0
- package/dist/components/agent/AgentAvatar.svelte.d.ts +27 -0
- package/dist/components/agent/AgentTurn.svelte +64 -0
- package/dist/components/agent/AgentTurn.svelte.d.ts +32 -0
- package/dist/components/agent/AvatarBoundary.svelte +29 -0
- package/dist/components/agent/AvatarBoundary.svelte.d.ts +20 -0
- package/dist/components/agent/CodeCard.svelte +288 -0
- package/dist/components/agent/CodeCard.svelte.d.ts +12 -0
- package/dist/components/agent/GenerationModule.svelte +99 -0
- package/dist/components/agent/GenerationModule.svelte.d.ts +16 -0
- package/dist/components/agent/MemberAvatar.svelte +87 -0
- package/dist/components/agent/MemberAvatar.svelte.d.ts +8 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +9 -0
- package/dist/i18n/messages.d.ts +31 -9
- package/dist/i18n/messages.js +31 -9
- package/dist/types/agent.d.ts +74 -0
- package/dist/types/agent.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/agentTurn.d.ts +219 -0
- package/dist/utils/agentTurn.js +301 -0
- package/dist/utils/bubbleFit.d.ts +75 -0
- package/dist/utils/bubbleFit.js +116 -0
- package/dist/utils/bubbleShrinkWrap.d.ts +32 -0
- package/dist/utils/bubbleShrinkWrap.js +360 -0
- package/dist/utils/codeHighlight.d.ts +13 -0
- package/dist/utils/codeHighlight.js +61 -0
- package/dist/utils/codePrettier.d.ts +6 -0
- package/dist/utils/codePrettier.js +34 -0
- package/dist/utils/codeStreamFormat.d.ts +90 -0
- package/dist/utils/codeStreamFormat.js +429 -0
- package/dist/utils/generationArchiveStore.d.ts +5 -0
- package/dist/utils/generationArchiveStore.js +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/package.json +3 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* One part of the assistant's work, shown in the chat and folded away with one press: its thinking, as plain text like a
|
|
4
|
+
* message, or the code it wrote, as a code card (see `CodeCard`, which draws the code kind: Prettier lays the code out as it
|
|
5
|
+
* is written and highlight.js colours it).
|
|
6
|
+
*
|
|
7
|
+
* It is open while it is the part being written and closed once the next part (or the conclusion) has taken over; the
|
|
8
|
+
* person's own choice wins from the moment they press it. Under a conclusion it comes back closed, for the person to open.
|
|
9
|
+
*/
|
|
10
|
+
import { tick } from 'svelte';
|
|
11
|
+
import IconChevronRight from '@tabler/icons-svelte/icons/chevron-right';
|
|
12
|
+
import { useChatLanguage } from '../../i18n/language.js';
|
|
13
|
+
import { chatLog } from '../../utils/logger.js';
|
|
14
|
+
import CodeCard from './CodeCard.svelte';
|
|
15
|
+
|
|
16
|
+
// The words of the module, in the language of the chat above
|
|
17
|
+
const { t } = useChatLanguage();
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
/** What this part of the work is. */
|
|
21
|
+
kind: 'thinking' | 'code';
|
|
22
|
+
/** Everything written so far. */
|
|
23
|
+
text: string;
|
|
24
|
+
/** The text is still arriving: the title says so, and the newest line stays in view. */
|
|
25
|
+
streaming?: boolean;
|
|
26
|
+
/** Whole seconds the thinking took, once it is over. */
|
|
27
|
+
seconds?: number | null;
|
|
28
|
+
/** Open until the person chooses (the live part), or closed until they do (the part under a conclusion). */
|
|
29
|
+
openByDefault?: boolean;
|
|
30
|
+
class?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let { kind, text, streaming = false, seconds = null, openByDefault = false, class: className = '' }: Props = $props();
|
|
34
|
+
|
|
35
|
+
// What the person chose, once they have chosen: from then on it wins over the default
|
|
36
|
+
let chosenOpen = $state<boolean | null>(null);
|
|
37
|
+
const isOpen = $derived(chosenOpen ?? openByDefault);
|
|
38
|
+
|
|
39
|
+
const bodyId = $props.id();
|
|
40
|
+
let bodyElement = $state<HTMLElement | null>(null);
|
|
41
|
+
|
|
42
|
+
// (The code kind has its own card, which says what it is itself.)
|
|
43
|
+
const title = $derived.by(() => {
|
|
44
|
+
if (!streaming && seconds != null) return $t('chat.generation.thoughtFor', { seconds: String(seconds) });
|
|
45
|
+
return $t('chat.generation.thinking');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// What the button does, for a screen reader (the title says what it is)
|
|
49
|
+
const toggleLabel = $derived(isOpen ? $t('chat.generation.collapseThought') : $t('chat.generation.expandThought'));
|
|
50
|
+
|
|
51
|
+
function toggleOpen(): void {
|
|
52
|
+
chosenOpen = !isOpen;
|
|
53
|
+
chatLog('[Chat] generation module', kind, chosenOpen ? 'opened' : 'closed', 'by the person');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// While the text arrives, keep its newest line in view
|
|
57
|
+
$effect(() => {
|
|
58
|
+
if (!streaming || !isOpen || !bodyElement) return;
|
|
59
|
+
if (text.length === 0) return;
|
|
60
|
+
tick()
|
|
61
|
+
.then(() => {
|
|
62
|
+
if (bodyElement) bodyElement.scrollTop = bodyElement.scrollHeight;
|
|
63
|
+
})
|
|
64
|
+
.catch((error) => console.warn('[Chat] Could not keep the newest line in view:', error));
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
{#if kind === 'code'}
|
|
69
|
+
<!-- The code is a card of its own (open, closed, copy, the status line): see CodeCard -->
|
|
70
|
+
<CodeCard code={text} {streaming} {openByDefault} class={className} />
|
|
71
|
+
{:else}
|
|
72
|
+
<div class="flex min-w-0 flex-col {className}" data-testid="generation-module" data-generation-module={kind} data-open={isOpen}>
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
class="text-caption-medium text-muted-foreground hover:text-foreground focus-visible:ring-ring flex min-h-7 w-fit max-w-full items-center gap-1 rounded-sm text-start transition-colors focus-visible:ring-2 focus-visible:outline-none"
|
|
76
|
+
aria-expanded={isOpen}
|
|
77
|
+
aria-controls={bodyId}
|
|
78
|
+
onclick={toggleOpen}
|
|
79
|
+
>
|
|
80
|
+
<IconChevronRight
|
|
81
|
+
class="size-4 shrink-0 stroke-2 transition-transform motion-reduce:transition-none rtl:-scale-x-100 {isOpen
|
|
82
|
+
? 'rotate-90 rtl:-rotate-90'
|
|
83
|
+
: ''}"
|
|
84
|
+
aria-hidden="true"
|
|
85
|
+
/>
|
|
86
|
+
<span class="min-w-0 truncate">{title}</span>
|
|
87
|
+
<span class="sr-only">{toggleLabel}</span>
|
|
88
|
+
</button>
|
|
89
|
+
<div id={bodyId} class="min-w-0">
|
|
90
|
+
{#if isOpen}
|
|
91
|
+
<div
|
|
92
|
+
bind:this={bodyElement}
|
|
93
|
+
class="text-caption text-muted-foreground max-h-40 overflow-auto ps-5 break-words whitespace-pre-wrap"
|
|
94
|
+
dir="auto"
|
|
95
|
+
data-testid="generation-thinking-text">{text}</div>
|
|
96
|
+
{/if}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
{/if}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/** What this part of the work is. */
|
|
3
|
+
kind: 'thinking' | 'code';
|
|
4
|
+
/** Everything written so far. */
|
|
5
|
+
text: string;
|
|
6
|
+
/** The text is still arriving: the title says so, and the newest line stays in view. */
|
|
7
|
+
streaming?: boolean;
|
|
8
|
+
/** Whole seconds the thinking took, once it is over. */
|
|
9
|
+
seconds?: number | null;
|
|
10
|
+
/** Open until the person chooses (the live part), or closed until they do (the part under a conclusion). */
|
|
11
|
+
openByDefault?: boolean;
|
|
12
|
+
class?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const GenerationModule: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type GenerationModule = ReturnType<typeof GenerationModule>;
|
|
16
|
+
export default GenerationModule;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The face next to a message a person of the team wrote: their picture, or their initials, and their e-mail when the pointer
|
|
4
|
+
* rests on it (or the keyboard is on it). The same tooltip as the member avatars in the project header of the Widgetic site,
|
|
5
|
+
* and the same click: with an e-mail the face is a link that writes to the person (`mailto:`, with the hand cursor), as
|
|
6
|
+
* in that header. Without one it is only a picture: nothing to click, nothing to reach with the keyboard.
|
|
7
|
+
*
|
|
8
|
+
* `Avatar` and `Tooltip` come from the components barrel of the design system, like the panel header's: its export map has
|
|
9
|
+
* no path to them anywhere else. Neither shows a word of its own (initials from a name, an e-mail address in the tooltip),
|
|
10
|
+
* so there are no words of the design system to hand over.
|
|
11
|
+
*/
|
|
12
|
+
import { Avatar, Tooltip } from '@widgetic/design-system/components';
|
|
13
|
+
import { useChatLanguage } from '../../i18n/language.js';
|
|
14
|
+
import type { ChatMember } from '../../types/agent.js';
|
|
15
|
+
import { memberDisplayName, memberMailtoHref, memberTooltipEmail } from '../../utils/agentTurn.js';
|
|
16
|
+
|
|
17
|
+
// The words of the avatar, in the language of the chat above
|
|
18
|
+
const { t } = useChatLanguage();
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
member: ChatMember;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let { member, class: className = '' }: Props = $props();
|
|
26
|
+
|
|
27
|
+
const displayName = $derived(memberDisplayName(member));
|
|
28
|
+
// Null when the person has no e-mail (or a placeholder word for one): then there is nothing to show on hover, and nowhere to write to
|
|
29
|
+
const tooltipEmail = $derived(memberTooltipEmail(member.email));
|
|
30
|
+
const mailtoHref = $derived(memberMailtoHref(member.email));
|
|
31
|
+
// What a screen reader says: "Name (email)", just the name, just the e-mail, or that it is a person of the team
|
|
32
|
+
const accessibleLabel = $derived.by(() => {
|
|
33
|
+
if (displayName && tooltipEmail) return $t('chat.member.avatarLabel', { name: displayName, email: tooltipEmail });
|
|
34
|
+
return displayName || tooltipEmail || $t('chat.member.unknown');
|
|
35
|
+
});
|
|
36
|
+
// What it says when it is a link, as the header's does: "Email Name" (the e-mail itself when the person has no name)
|
|
37
|
+
const emailLabel = $derived($t('chat.member.emailLabel', { name: displayName || tooltipEmail || '' }));
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<!-- The picture, the same whether the face is a link or not -->
|
|
41
|
+
{#snippet face()}
|
|
42
|
+
<Avatar name={displayName} src={member.avatarUrl ?? undefined} size="sm" />
|
|
43
|
+
{/snippet}
|
|
44
|
+
|
|
45
|
+
<Tooltip.Provider delayDuration={200}>
|
|
46
|
+
<Tooltip.Root disabled={!tooltipEmail}>
|
|
47
|
+
<Tooltip.Trigger>
|
|
48
|
+
{#snippet child({ props }: { props: Record<string, unknown> })}
|
|
49
|
+
{#if mailtoHref}
|
|
50
|
+
<!-- A mail address, not a route of an app: SvelteKit's `resolve()` (the hint of the Svelte tools for any `href`) is for routes -->
|
|
51
|
+
<a
|
|
52
|
+
{...props}
|
|
53
|
+
href={mailtoHref}
|
|
54
|
+
class="ring-offset-background focus-visible:ring-ring inline-flex shrink-0 cursor-pointer rounded-full focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none {className}"
|
|
55
|
+
aria-label={emailLabel}
|
|
56
|
+
data-testid="chat-member-avatar"
|
|
57
|
+
>
|
|
58
|
+
{@render face()}
|
|
59
|
+
</a>
|
|
60
|
+
{:else}
|
|
61
|
+
<span
|
|
62
|
+
{...props}
|
|
63
|
+
class="inline-flex shrink-0 rounded-full {className}"
|
|
64
|
+
role="img"
|
|
65
|
+
aria-label={accessibleLabel}
|
|
66
|
+
data-testid="chat-member-avatar"
|
|
67
|
+
>
|
|
68
|
+
{@render face()}
|
|
69
|
+
</span>
|
|
70
|
+
{/if}
|
|
71
|
+
{/snippet}
|
|
72
|
+
</Tooltip.Trigger>
|
|
73
|
+
{#if tooltipEmail}
|
|
74
|
+
<Tooltip.Portal>
|
|
75
|
+
<Tooltip.Content
|
|
76
|
+
side="bottom"
|
|
77
|
+
align="center"
|
|
78
|
+
collisionPadding={8}
|
|
79
|
+
class="max-w-[min(20rem,calc(100vw-2rem))] break-all text-center"
|
|
80
|
+
data-testid="chat-member-email-tooltip"
|
|
81
|
+
>
|
|
82
|
+
{tooltipEmail}
|
|
83
|
+
</Tooltip.Content>
|
|
84
|
+
</Tooltip.Portal>
|
|
85
|
+
{/if}
|
|
86
|
+
</Tooltip.Root>
|
|
87
|
+
</Tooltip.Provider>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChatMember } from '../../types/agent.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
member: ChatMember;
|
|
4
|
+
class?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const MemberAvatar: import("svelte").Component<Props, {}, "">;
|
|
7
|
+
type MemberAvatar = ReturnType<typeof MemberAvatar>;
|
|
8
|
+
export default MemberAvatar;
|
|
@@ -9,4 +9,9 @@ export { default as AttachmentDisplay } from './AttachmentDisplay.svelte';
|
|
|
9
9
|
export { default as CodeBlock } from './CodeBlock.svelte';
|
|
10
10
|
export { default as StatusIndicator } from './StatusIndicator.svelte';
|
|
11
11
|
export { default as LoadingIndicator } from './LoadingIndicator.svelte';
|
|
12
|
+
export { default as AgentAvatar } from './agent/AgentAvatar.svelte';
|
|
13
|
+
export { default as AgentTurn } from './agent/AgentTurn.svelte';
|
|
14
|
+
export { default as CodeCard } from './agent/CodeCard.svelte';
|
|
15
|
+
export { default as GenerationModule } from './agent/GenerationModule.svelte';
|
|
16
|
+
export { default as MemberAvatar } from './agent/MemberAvatar.svelte';
|
|
12
17
|
export type { ComponentProps } from 'svelte';
|
package/dist/components/index.js
CHANGED
|
@@ -10,3 +10,12 @@ export { default as AttachmentDisplay } from './AttachmentDisplay.svelte';
|
|
|
10
10
|
export { default as CodeBlock } from './CodeBlock.svelte';
|
|
11
11
|
export { default as StatusIndicator } from './StatusIndicator.svelte';
|
|
12
12
|
export { default as LoadingIndicator } from './LoadingIndicator.svelte';
|
|
13
|
+
// The assistant's turn, for a page that builds its own panel: the moving avatar, the turn around it (the avatar with its
|
|
14
|
+
// content beside it), the collapsible thinking and the code card (the code, laid out by Prettier as it is written), and a
|
|
15
|
+
// team member's avatar with the e-mail on hover.
|
|
16
|
+
// Inside `Chat` they speak the page's language; used on their own they speak English.
|
|
17
|
+
export { default as AgentAvatar } from './agent/AgentAvatar.svelte';
|
|
18
|
+
export { default as AgentTurn } from './agent/AgentTurn.svelte';
|
|
19
|
+
export { default as CodeCard } from './agent/CodeCard.svelte';
|
|
20
|
+
export { default as GenerationModule } from './agent/GenerationModule.svelte';
|
|
21
|
+
export { default as MemberAvatar } from './agent/MemberAvatar.svelte';
|
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -44,20 +44,43 @@ export declare const CHAT_MESSAGES: {
|
|
|
44
44
|
readonly 'chat.messages.emptyTitle': "What do you want to build?";
|
|
45
45
|
readonly 'chat.messages.emptyHint': "Sketch it on the canvas, or describe it here.";
|
|
46
46
|
readonly 'chat.messages.loadingHistory': "Loading chat history...";
|
|
47
|
-
/** Said while the assistant works on an answer. */
|
|
48
|
-
readonly 'chat.messages.thinking': "
|
|
47
|
+
/** Said while the assistant works on an answer (typed out, in a shimmer, by the avatar). */
|
|
48
|
+
readonly 'chat.messages.thinking': "Thinking…";
|
|
49
49
|
/** Header while streamed reasoning is visible during codegen. */
|
|
50
|
-
readonly 'chat.generation.thinking': "Thinking";
|
|
50
|
+
readonly 'chat.generation.thinking': "Thinking…";
|
|
51
51
|
/** Header while streamed code is visible during codegen. */
|
|
52
|
-
readonly 'chat.generation.writingCode': "Writing code";
|
|
52
|
+
readonly 'chat.generation.writingCode': "Writing code…";
|
|
53
53
|
/** Collapsed reasoning summary after code begins streaming. */
|
|
54
54
|
readonly 'chat.generation.thoughtFor': "Thought for {seconds} s";
|
|
55
55
|
readonly 'chat.generation.expandThought': "Show thinking";
|
|
56
56
|
readonly 'chat.generation.collapseThought': "Hide thinking";
|
|
57
57
|
/** Polite screen-reader line when codegen enters the thinking phase. */
|
|
58
|
-
readonly 'chat.generation.statusThinking': "
|
|
58
|
+
readonly 'chat.generation.statusThinking': "Thinking";
|
|
59
59
|
/** Polite screen-reader line when codegen enters the writing-code phase. */
|
|
60
|
-
readonly 'chat.generation.statusWritingCode': "
|
|
60
|
+
readonly 'chat.generation.statusWritingCode': "Writing code";
|
|
61
|
+
/** Title of the code the assistant wrote, once it has finished writing it (while it writes, the title is `chat.generation.writingCode`). */
|
|
62
|
+
readonly 'chat.generation.codeTitle': "Code";
|
|
63
|
+
/** The status line of the code card once the assistant has finished writing the code (while it writes, the line is `chat.generation.writingCode`). */
|
|
64
|
+
readonly 'chat.generation.codeWritten': "Code written";
|
|
65
|
+
/** The size of the code in the code card: its lines as they are laid out. */
|
|
66
|
+
readonly 'chat.generation.codeLineCount': "{count, plural, one {# line} other {# lines}}";
|
|
67
|
+
readonly 'chat.generation.expandCode': "Show code";
|
|
68
|
+
readonly 'chat.generation.collapseCode': "Hide code";
|
|
69
|
+
/**
|
|
70
|
+
* The conclusion line under the success avatar, when the assistant finished building and said nothing else the chat shows
|
|
71
|
+
* (the "Code generation completed" lines the host saves are not shown: they become the version label of the turn).
|
|
72
|
+
*/
|
|
73
|
+
readonly 'chat.generation.doneMessage': "Done. Your changes are ready.";
|
|
74
|
+
/** What a screen reader says about the avatar once what the assistant was asked to do is done. */
|
|
75
|
+
readonly 'chat.agent.avatar.success': "Done";
|
|
76
|
+
/** What a screen reader says about the avatar when the assistant's work failed. */
|
|
77
|
+
readonly 'chat.agent.avatar.error': "Something went wrong";
|
|
78
|
+
/** What a screen reader says about the avatar of a person of the team (`{name}` and `{email}`). */
|
|
79
|
+
readonly 'chat.member.avatarLabel': "{name} ({email})";
|
|
80
|
+
/** What a screen reader says about the avatar of a person of the team when it is a link that writes to them (`{name}`). */
|
|
81
|
+
readonly 'chat.member.emailLabel': "Email {name}";
|
|
82
|
+
/** The name of a person of the team the page did not tell the chat about. */
|
|
83
|
+
readonly 'chat.member.unknown': "Team member";
|
|
61
84
|
/** Heading when the gateway plan has no title. */
|
|
62
85
|
readonly 'chat.plan.title': "Build plan";
|
|
63
86
|
/** Progress badge on the plan card (`{current}` / `{total}`). */
|
|
@@ -69,9 +92,9 @@ export declare const CHAT_MESSAGES: {
|
|
|
69
92
|
readonly 'chat.messages.attachmentMissingTitle': "Attachment not available";
|
|
70
93
|
readonly 'chat.messages.attachmentMissingLabel': "Missing file attachment";
|
|
71
94
|
readonly 'chat.messages.attachmentMissingCaption': "Attachment not saved. Re-attach with Upload, then send it again.";
|
|
72
|
-
/**
|
|
95
|
+
/** A failed reply in the docked panel is one short line (this, or what the server said) with a refresh icon that runs the prompt again. */
|
|
73
96
|
readonly 'chat.messages.failedTitle': "Could not build the widget";
|
|
74
|
-
|
|
97
|
+
/** The name of the refresh icon next to a failure: its tooltip and what a screen reader says. */
|
|
75
98
|
readonly 'chat.messages.failedRetry': "Try again";
|
|
76
99
|
/** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
|
|
77
100
|
readonly 'chat.messages.stoppedByYou': "You stopped the build.";
|
|
@@ -145,7 +168,6 @@ export declare const CHAT_MESSAGES: {
|
|
|
145
168
|
readonly 'chat.input.send': "Send message";
|
|
146
169
|
readonly 'chat.input.tooLong': "Message is too long";
|
|
147
170
|
readonly 'chat.input.publishNudge': "First generate your widget, then you can publish it.";
|
|
148
|
-
readonly 'chat.composer.assistant': "Assistant";
|
|
149
171
|
readonly 'chat.messages.scrollToBottom': "Scroll to latest messages";
|
|
150
172
|
readonly 'chat.messages.clarificationPrompt': "Which option fits best?";
|
|
151
173
|
readonly 'chat.checkpoint.version': "Version {n}";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -48,20 +48,43 @@ export const CHAT_MESSAGES = {
|
|
|
48
48
|
'chat.messages.emptyTitle': 'What do you want to build?',
|
|
49
49
|
'chat.messages.emptyHint': 'Sketch it on the canvas, or describe it here.',
|
|
50
50
|
'chat.messages.loadingHistory': 'Loading chat history...',
|
|
51
|
-
/** Said while the assistant works on an answer. */
|
|
52
|
-
'chat.messages.thinking': '
|
|
51
|
+
/** Said while the assistant works on an answer (typed out, in a shimmer, by the avatar). */
|
|
52
|
+
'chat.messages.thinking': 'Thinking…',
|
|
53
53
|
/** Header while streamed reasoning is visible during codegen. */
|
|
54
|
-
'chat.generation.thinking': 'Thinking',
|
|
54
|
+
'chat.generation.thinking': 'Thinking…',
|
|
55
55
|
/** Header while streamed code is visible during codegen. */
|
|
56
|
-
'chat.generation.writingCode': 'Writing code',
|
|
56
|
+
'chat.generation.writingCode': 'Writing code…',
|
|
57
57
|
/** Collapsed reasoning summary after code begins streaming. */
|
|
58
58
|
'chat.generation.thoughtFor': 'Thought for {seconds} s',
|
|
59
59
|
'chat.generation.expandThought': 'Show thinking',
|
|
60
60
|
'chat.generation.collapseThought': 'Hide thinking',
|
|
61
61
|
/** Polite screen-reader line when codegen enters the thinking phase. */
|
|
62
|
-
'chat.generation.statusThinking': '
|
|
62
|
+
'chat.generation.statusThinking': 'Thinking',
|
|
63
63
|
/** Polite screen-reader line when codegen enters the writing-code phase. */
|
|
64
|
-
'chat.generation.statusWritingCode': '
|
|
64
|
+
'chat.generation.statusWritingCode': 'Writing code',
|
|
65
|
+
/** Title of the code the assistant wrote, once it has finished writing it (while it writes, the title is `chat.generation.writingCode`). */
|
|
66
|
+
'chat.generation.codeTitle': 'Code',
|
|
67
|
+
/** The status line of the code card once the assistant has finished writing the code (while it writes, the line is `chat.generation.writingCode`). */
|
|
68
|
+
'chat.generation.codeWritten': 'Code written',
|
|
69
|
+
/** The size of the code in the code card: its lines as they are laid out. */
|
|
70
|
+
'chat.generation.codeLineCount': '{count, plural, one {# line} other {# lines}}',
|
|
71
|
+
'chat.generation.expandCode': 'Show code',
|
|
72
|
+
'chat.generation.collapseCode': 'Hide code',
|
|
73
|
+
/**
|
|
74
|
+
* The conclusion line under the success avatar, when the assistant finished building and said nothing else the chat shows
|
|
75
|
+
* (the "Code generation completed" lines the host saves are not shown: they become the version label of the turn).
|
|
76
|
+
*/
|
|
77
|
+
'chat.generation.doneMessage': 'Done. Your changes are ready.',
|
|
78
|
+
/** What a screen reader says about the avatar once what the assistant was asked to do is done. */
|
|
79
|
+
'chat.agent.avatar.success': 'Done',
|
|
80
|
+
/** What a screen reader says about the avatar when the assistant's work failed. */
|
|
81
|
+
'chat.agent.avatar.error': 'Something went wrong',
|
|
82
|
+
/** What a screen reader says about the avatar of a person of the team (`{name}` and `{email}`). */
|
|
83
|
+
'chat.member.avatarLabel': '{name} ({email})',
|
|
84
|
+
/** What a screen reader says about the avatar of a person of the team when it is a link that writes to them (`{name}`). */
|
|
85
|
+
'chat.member.emailLabel': 'Email {name}',
|
|
86
|
+
/** The name of a person of the team the page did not tell the chat about. */
|
|
87
|
+
'chat.member.unknown': 'Team member',
|
|
65
88
|
/** Heading when the gateway plan has no title. */
|
|
66
89
|
'chat.plan.title': 'Build plan',
|
|
67
90
|
/** Progress badge on the plan card (`{current}` / `{total}`). */
|
|
@@ -73,9 +96,9 @@ export const CHAT_MESSAGES = {
|
|
|
73
96
|
'chat.messages.attachmentMissingTitle': 'Attachment not available',
|
|
74
97
|
'chat.messages.attachmentMissingLabel': 'Missing file attachment',
|
|
75
98
|
'chat.messages.attachmentMissingCaption': 'Attachment not saved. Re-attach with Upload, then send it again.',
|
|
76
|
-
/**
|
|
99
|
+
/** A failed reply in the docked panel is one short line (this, or what the server said) with a refresh icon that runs the prompt again. */
|
|
77
100
|
'chat.messages.failedTitle': 'Could not build the widget',
|
|
78
|
-
|
|
101
|
+
/** The name of the refresh icon next to a failure: its tooltip and what a screen reader says. */
|
|
79
102
|
'chat.messages.failedRetry': 'Try again',
|
|
80
103
|
/** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
|
|
81
104
|
'chat.messages.stoppedByYou': 'You stopped the build.',
|
|
@@ -151,7 +174,6 @@ export const CHAT_MESSAGES = {
|
|
|
151
174
|
'chat.input.send': 'Send message',
|
|
152
175
|
'chat.input.tooLong': 'Message is too long',
|
|
153
176
|
'chat.input.publishNudge': 'First generate your widget, then you can publish it.',
|
|
154
|
-
'chat.composer.assistant': 'Assistant',
|
|
155
177
|
'chat.messages.scrollToBottom': 'Scroll to latest messages',
|
|
156
178
|
'chat.messages.clarificationPrompt': 'Which option fits best?',
|
|
157
179
|
'chat.checkpoint.version': 'Version {n}',
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
/**
|
|
3
|
+
* The five looks of the assistant's avatar.
|
|
4
|
+
*
|
|
5
|
+
* They are the states of the Scribble Mascot of `@widgetic/brand`, word for word, so a page that draws the mascot
|
|
6
|
+
* passes `state` straight on. `success` and `error` play once and then rest (the mascot's `settleTo`).
|
|
7
|
+
*/
|
|
8
|
+
export type AgentAvatarState = 'idle' | 'thinking' | 'writing' | 'success' | 'error';
|
|
9
|
+
/** What the chat gives the page's avatar snippet each time something about the avatar changes. */
|
|
10
|
+
export interface AgentAvatarRenderProps {
|
|
11
|
+
/** What the assistant is doing right now. */
|
|
12
|
+
state: AgentAvatarState;
|
|
13
|
+
/**
|
|
14
|
+
* Side of the square the avatar is drawn in, in CSS pixels. It changes a little at a time while the avatar grows
|
|
15
|
+
* or shrinks, so the page only has to draw the avatar at this size.
|
|
16
|
+
*/
|
|
17
|
+
size: number;
|
|
18
|
+
/**
|
|
19
|
+
* False for an avatar that only has to sit there (a message that is not the newest): draw a still picture and keep
|
|
20
|
+
* nothing running. True for the one that moves.
|
|
21
|
+
*/
|
|
22
|
+
live: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* What a screen reader says about the avatar, already in the language of the page. Empty when it should say nothing (an
|
|
25
|
+
* avatar at rest sits beside words that say it all): draw it as decoration then.
|
|
26
|
+
*/
|
|
27
|
+
label: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* How a page draws the assistant's avatar. The chat has no dependency on any drawing code: a page that has the
|
|
31
|
+
* Scribble Mascot gives a snippet that draws it, and a page that does not gets a plain round avatar.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```svelte
|
|
35
|
+
* {#snippet agentAvatar({ state: avatarState, size, live, label })}
|
|
36
|
+
* <Mascot state={avatarState} {size} {label} decorative={!label} frozenAt={live ? undefined : 0.5} settleTo="idle" />
|
|
37
|
+
* {/snippet}
|
|
38
|
+
* <Chat renderAgentAvatar={agentAvatar} … />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export type AgentAvatarRenderer = Snippet<[AgentAvatarRenderProps]>;
|
|
42
|
+
/**
|
|
43
|
+
* How a page lets the assistant's avatar be heard. The chat has no dependency on any sound code: a page that has the
|
|
44
|
+
* mascot's sound gives it (`createMascotSound()` of `@widgetic/brand/mascot/sound` fits as it is), and a page that does not
|
|
45
|
+
* gets silence. The chat tells it the state of the avatar the person is looking at, once for each change, and only for what
|
|
46
|
+
* the person watched happen: never for a conversation that was just opened, whatever state its last message left the avatar in.
|
|
47
|
+
*
|
|
48
|
+
* Whether sound is on, how loud, the browser's lock on audio and every other rule of sounding belong to the player (the
|
|
49
|
+
* mascot's is off until the person asks, and keeps the same cue from repeating): the chat has no control for it, the page does.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { createMascotSound } from '@widgetic/brand/mascot/sound';
|
|
54
|
+
* const agentSound = createMascotSound(); // off until `agentSound.enable()` runs inside a click
|
|
55
|
+
* // <Chat {agentSound} … />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export interface AgentSoundPlayer {
|
|
59
|
+
/** The avatar the person is looking at went to `state`. The player decides whether anything sounds for it. */
|
|
60
|
+
notifyStateChange(state: AgentAvatarState): unknown;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A person of the team, as the chat needs to know them to put a face on what they wrote.
|
|
64
|
+
* Everything but `id` is optional: a person without a name still gets their initials from the e-mail.
|
|
65
|
+
*/
|
|
66
|
+
export interface ChatMember {
|
|
67
|
+
/** The id the messages carry as `userId`. */
|
|
68
|
+
id: string;
|
|
69
|
+
name?: string | null;
|
|
70
|
+
/** Shown when the pointer rests on the avatar. */
|
|
71
|
+
email?: string | null;
|
|
72
|
+
/** A picture of the person. Without one (or when it cannot be loaded) the initials stay. */
|
|
73
|
+
avatarUrl?: string | null;
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './state.js';
|
|
|
7
7
|
export * from './config.js';
|
|
8
8
|
export * from './adapter.js';
|
|
9
9
|
export * from './events.js';
|
|
10
|
+
export * from './agent.js';
|
|
10
11
|
export type { ChatService, ChatInstance, ChatFactory } from './chat.js';
|
|
11
12
|
export type { ChatMessage, MessageInput } from './message.js';
|
|
12
13
|
export type { ChatConversation, ConversationInput } from './conversation.js';
|
package/dist/types/index.js
CHANGED