@widgetic/chat 0.1.38 → 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.
Files changed (59) hide show
  1. package/README.md +71 -0
  2. package/dist/components/AttachmentDisplay.svelte +14 -4
  3. package/dist/components/Chat.svelte +131 -106
  4. package/dist/components/Chat.svelte.d.ts +29 -0
  5. package/dist/components/ChatComposer.svelte +5 -1
  6. package/dist/components/ChatMessages.svelte +595 -175
  7. package/dist/components/ChatMessages.svelte.d.ts +20 -0
  8. package/dist/components/CodeBlock.svelte +9 -1
  9. package/dist/components/ComposerAttachmentsTray.svelte +64 -0
  10. package/dist/components/ComposerAttachmentsTray.svelte.d.ts +11 -0
  11. package/dist/components/PanelChatHeader.svelte +26 -6
  12. package/dist/components/PanelChatHeader.svelte.d.ts +1 -0
  13. package/dist/components/PanelFollowUpSuggestions.svelte +2 -2
  14. package/dist/components/PanelSuggestionButtons.svelte +2 -1
  15. package/dist/components/agent/AgentAvatar.svelte +153 -0
  16. package/dist/components/agent/AgentAvatar.svelte.d.ts +27 -0
  17. package/dist/components/agent/AgentTurn.svelte +64 -0
  18. package/dist/components/agent/AgentTurn.svelte.d.ts +32 -0
  19. package/dist/components/agent/AvatarBoundary.svelte +29 -0
  20. package/dist/components/agent/AvatarBoundary.svelte.d.ts +20 -0
  21. package/dist/components/agent/CodeCard.svelte +288 -0
  22. package/dist/components/agent/CodeCard.svelte.d.ts +12 -0
  23. package/dist/components/agent/GenerationModule.svelte +99 -0
  24. package/dist/components/agent/GenerationModule.svelte.d.ts +16 -0
  25. package/dist/components/agent/MemberAvatar.svelte +87 -0
  26. package/dist/components/agent/MemberAvatar.svelte.d.ts +8 -0
  27. package/dist/components/index.d.ts +5 -0
  28. package/dist/components/index.js +9 -0
  29. package/dist/i18n/messages.d.ts +32 -10
  30. package/dist/i18n/messages.js +32 -10
  31. package/dist/types/agent.d.ts +74 -0
  32. package/dist/types/agent.js +1 -0
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.js +2 -0
  35. package/dist/utils/agentTurn.d.ts +219 -0
  36. package/dist/utils/agentTurn.js +301 -0
  37. package/dist/utils/attachmentPreviewUrl.d.ts +21 -0
  38. package/dist/utils/attachmentPreviewUrl.js +39 -0
  39. package/dist/utils/bubbleFit.d.ts +75 -0
  40. package/dist/utils/bubbleFit.js +116 -0
  41. package/dist/utils/bubbleShrinkWrap.d.ts +32 -0
  42. package/dist/utils/bubbleShrinkWrap.js +360 -0
  43. package/dist/utils/chatImageUploadPrep.d.ts +22 -0
  44. package/dist/utils/chatImageUploadPrep.js +90 -0
  45. package/dist/utils/codeHighlight.d.ts +13 -0
  46. package/dist/utils/codeHighlight.js +61 -0
  47. package/dist/utils/codePrettier.d.ts +6 -0
  48. package/dist/utils/codePrettier.js +34 -0
  49. package/dist/utils/codeStreamFormat.d.ts +90 -0
  50. package/dist/utils/codeStreamFormat.js +429 -0
  51. package/dist/utils/generationArchiveStore.d.ts +15 -0
  52. package/dist/utils/generationArchiveStore.js +89 -0
  53. package/dist/utils/imageTransform.d.ts +12 -0
  54. package/dist/utils/imageTransform.js +45 -0
  55. package/dist/utils/index.d.ts +2 -0
  56. package/dist/utils/index.js +3 -0
  57. package/dist/utils/suggestionDraft.d.ts +5 -0
  58. package/dist/utils/suggestionDraft.js +15 -0
  59. package/package.json +5 -4
@@ -34,6 +34,7 @@ export const CHAT_MESSAGES = {
34
34
  /** The name of a conversation that has none. */
35
35
  'chat.header.untitled': 'Untitled',
36
36
  'chat.header.newConversationTitle': 'New chat',
37
+ 'chat.header.noPastChats': 'No previous chats yet',
37
38
  'chat.header.newConversation': 'Start new conversation',
38
39
  /** Label for the debug console icon in the panel chat header. */
39
40
  'chat.header.console': 'Console',
@@ -47,20 +48,43 @@ export const CHAT_MESSAGES = {
47
48
  'chat.messages.emptyTitle': 'What do you want to build?',
48
49
  'chat.messages.emptyHint': 'Sketch it on the canvas, or describe it here.',
49
50
  'chat.messages.loadingHistory': 'Loading chat history...',
50
- /** Said while the assistant works on an answer. */
51
- 'chat.messages.thinking': 'Assistant is thinking',
51
+ /** Said while the assistant works on an answer (typed out, in a shimmer, by the avatar). */
52
+ 'chat.messages.thinking': 'Thinking…',
52
53
  /** Header while streamed reasoning is visible during codegen. */
53
- 'chat.generation.thinking': 'Thinking',
54
+ 'chat.generation.thinking': 'Thinking…',
54
55
  /** Header while streamed code is visible during codegen. */
55
- 'chat.generation.writingCode': 'Writing code',
56
+ 'chat.generation.writingCode': 'Writing code…',
56
57
  /** Collapsed reasoning summary after code begins streaming. */
57
58
  'chat.generation.thoughtFor': 'Thought for {seconds} s',
58
59
  'chat.generation.expandThought': 'Show thinking',
59
60
  'chat.generation.collapseThought': 'Hide thinking',
60
61
  /** Polite screen-reader line when codegen enters the thinking phase. */
61
- 'chat.generation.statusThinking': 'Assistant is thinking',
62
+ 'chat.generation.statusThinking': 'Thinking',
62
63
  /** Polite screen-reader line when codegen enters the writing-code phase. */
63
- 'chat.generation.statusWritingCode': 'Assistant is writing code',
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',
64
88
  /** Heading when the gateway plan has no title. */
65
89
  'chat.plan.title': 'Build plan',
66
90
  /** Progress badge on the plan card (`{current}` / `{total}`). */
@@ -72,9 +96,9 @@ export const CHAT_MESSAGES = {
72
96
  'chat.messages.attachmentMissingTitle': 'Attachment not available',
73
97
  'chat.messages.attachmentMissingLabel': 'Missing file attachment',
74
98
  'chat.messages.attachmentMissingCaption': 'Attachment not saved. Re-attach with Upload, then send it again.',
75
- /** The alert card a failed reply is shown in (docked panel): its title, its line, and the button that runs the prompt again. */
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. */
76
100
  'chat.messages.failedTitle': 'Could not build the widget',
77
- 'chat.messages.failedHint': 'The build did not finish. Your sketch is safe, so you can try again.',
101
+ /** The name of the refresh icon next to a failure: its tooltip and what a screen reader says. */
78
102
  'chat.messages.failedRetry': 'Try again',
79
103
  /** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
80
104
  'chat.messages.stoppedByYou': 'You stopped the build.',
@@ -150,7 +174,6 @@ export const CHAT_MESSAGES = {
150
174
  'chat.input.send': 'Send message',
151
175
  'chat.input.tooLong': 'Message is too long',
152
176
  'chat.input.publishNudge': 'First generate your widget, then you can publish it.',
153
- 'chat.composer.assistant': 'Assistant',
154
177
  'chat.messages.scrollToBottom': 'Scroll to latest messages',
155
178
  'chat.messages.clarificationPrompt': 'Which option fits best?',
156
179
  'chat.checkpoint.version': 'Version {n}',
@@ -222,7 +245,6 @@ export const CHAT_MESSAGES = {
222
245
  'chat.error.loadConversations': 'Failed to load conversations.',
223
246
  'chat.error.loadConversation': 'Failed to load conversation.',
224
247
  'chat.error.sendMessage': 'Failed to send message. Please try again.',
225
- 'chat.error.sendSuggestion': 'Failed to send the selected suggestion. Please try again.',
226
248
  'chat.error.screenshotUnavailable': 'Screenshot capture failed — no preview available.',
227
249
  'chat.error.screenshotFailed': 'Failed to capture screenshot',
228
250
  'chat.error.screenshotActionFailed': 'Screenshot action failed. Please try again.',
@@ -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 {};
@@ -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';
@@ -8,3 +8,5 @@ export * from './state.js';
8
8
  export * from './config.js';
9
9
  export * from './adapter.js';
10
10
  export * from './events.js';
11
+ // The assistant's avatar and the people of the team (what a page hands over to put faces on the messages)
12
+ export * from './agent.js';
@@ -0,0 +1,219 @@
1
+ import type { ChatMessageKey } from '../i18n/messages.js';
2
+ import type { AgentAvatarState, ChatMember } from '../types/agent.js';
3
+ import type { GenerationActivityPhase } from './generationActivity.js';
4
+ /**
5
+ * The rules of the assistant's turn: what its avatar looks like and does at each moment, how a finished turn is judged,
6
+ * who wrote a message of a person, and what is kept of the work once it is done.
7
+ *
8
+ * Plain TypeScript with no Svelte in it, so the rules can be tested in Node as they are (`tests/agent-turn.test.mjs`)
9
+ * and a page that is not the chat (the workflows assistant) can follow the same choreography.
10
+ */
11
+ /** `large` is the avatar of the moments that matter (waiting, a card to answer, the conclusion); `small` sits by the text. */
12
+ export type AgentAvatarSize = 'large' | 'small';
13
+ /** What the avatar of an assistant turn looks like and does. */
14
+ export interface AgentLook {
15
+ state: AgentAvatarState;
16
+ size: AgentAvatarSize;
17
+ /** True for the avatar that moves (the newest turn); false for one that only sits there as a still picture. */
18
+ live: boolean;
19
+ }
20
+ /**
21
+ * The look while a generation runs.
22
+ *
23
+ * - Waiting for the first word of the model: the avatar is large and thinks. A plan card or a question, when there is
24
+ * one, sits to its right.
25
+ * - Its reasoning streams: the avatar shrinks to the left and KEEPS THINKING for as long as the reasoning is being written.
26
+ * The words beside it say "Thinking…" (the thinking module's own title): the avatar carries no name or label.
27
+ * - What it writes next streams (the code, or the reply the model writes: the chat has no other stream than the reasoning and
28
+ * this one): still small, and now it WRITES; the code module's title says "Writing code…".
29
+ *
30
+ * (The mascot package maps the phases the same way: `thinking-stream` is its `thinking` state.)
31
+ */
32
+ export declare function liveAgentLook(phase: GenerationActivityPhase): AgentLook;
33
+ /** How a turn ended, as far as the avatar cares. */
34
+ export type TurnOutcome =
35
+ /** The assistant built something (a commit, "Code generation completed") or a generation ran for this turn. */
36
+ 'success'
37
+ /** The last thing it said is a failure. */
38
+ | 'error'
39
+ /** The person stopped it: their own command, not a failure. */
40
+ | 'stopped'
41
+ /** The last thing it said is a card waiting for an answer. */
42
+ | 'question'
43
+ /** Anything else it said (a plain answer). */
44
+ | 'answer';
45
+ /** What the chat found out about one visible reply of a turn (the chat's own tests of the text, kept out of this file). */
46
+ export interface TurnReplyFacts {
47
+ isFailure: boolean;
48
+ isStopped: boolean;
49
+ /** The reply carries clarification suggestions: a question card waits under it. */
50
+ hasQuestion: boolean;
51
+ /** The reply announces a widget commit. */
52
+ hasCommit: boolean;
53
+ /** The reply is the "Code generation completed" line. */
54
+ isCompletion: boolean;
55
+ }
56
+ /**
57
+ * Judges a turn from its visible replies. The LAST reply decides how it ended; a commit or a completion line anywhere in
58
+ * the turn (or a generation that ran for it) makes an ordinary last reply a success.
59
+ */
60
+ export declare function turnOutcome(replies: readonly TurnReplyFacts[], generationRanForTurn: boolean): TurnOutcome | null;
61
+ /**
62
+ * The look of a turn that is not running. Only the newest turn moves, and only its conclusion is large (the success or
63
+ * the error avatar, or a question to answer): older turns are small still pictures, so a long chat keeps one mascot
64
+ * alive instead of one per message.
65
+ */
66
+ export declare function settledAgentLook(outcome: TurnOutcome, isNewestTurn: boolean): AgentLook;
67
+ /** Where the avatar that takes over from the live one starts. */
68
+ export interface AvatarStart {
69
+ /** The size it glides from to its own. */
70
+ startSize: AgentAvatarSize;
71
+ /** The state it is drawn in first, before it moves on to its own (a mascot blends between the two). Undefined: its own from the start. */
72
+ startState: AgentAvatarState | undefined;
73
+ }
74
+ /**
75
+ * The live avatar of a run and the one of its ending are two avatars, one after the other, in the same place. The second one starts
76
+ * from how the first one looked when the run ended, so what the person watched carries on instead of being swapped: a Stop pressed
77
+ * while the avatar is still large shrinks it down to its small size, and the mascot calms from what it was doing; a conclusion
78
+ * grows out of the avatar of the work.
79
+ *
80
+ * Without a live avatar to take over from (the conversation was opened or reloaded after the run) it starts from the small one,
81
+ * which is where a conclusion has always grown out of.
82
+ */
83
+ export declare function avatarStartAfter(lastLiveLook: AgentLook | null): AvatarStart;
84
+ /** What `soundStateOf` looks at. */
85
+ export interface SoundStateInput {
86
+ /** A run is working and its live avatar is on screen. */
87
+ runIsLive: boolean;
88
+ /** How the live avatar looks for the phase the run is in. */
89
+ liveLook: AgentLook;
90
+ /** A run worked while this conversation was open here (the person saw it happen). */
91
+ runWasWatched: boolean;
92
+ /** How the avatar of the newest turn looks, or null when that turn has no assistant to show (yet). */
93
+ newestTurnLook: AgentLook | null;
94
+ }
95
+ /**
96
+ * The state of the avatar the person is looking at, for the page's sound to follow, or null when there is nothing to hear.
97
+ *
98
+ * - While a run works, the live avatar's own state: thinking when it starts, writing when code or the answer is written.
99
+ * - When it ends, the state of the newest turn's avatar: success or error say how it went, and idle (a question, a stop) says it
100
+ * is waiting.
101
+ * - Never for a conversation that was only opened: its newest turn may be left in `error` or `success`, but nothing happened in
102
+ * front of the person, so nothing is heard. Opening a chat must not play the sound of a failure.
103
+ * - Null as well while the newest turn has nothing to show yet (a prompt just sent, or a run that has ended a moment before its
104
+ * conclusion arrives): the sound keeps what it last heard.
105
+ *
106
+ * Only a change of this value is worth telling the sound about, and the caller tells it once for each.
107
+ */
108
+ export declare function soundStateOf(input: SoundStateInput): AgentAvatarState | null;
109
+ /** The side of the avatar in pixels. Without a page's own avatar the large one is only a little larger: a plain circle that big is noise. */
110
+ export declare const AGENT_AVATAR_PIXELS: {
111
+ /** The mascot's full drawing (64 px and up). */
112
+ readonly largeWithPageAvatar: 80;
113
+ readonly largeWithoutPageAvatar: 32;
114
+ /** The mascot's compact drawing, which still moves (28 px and up). */
115
+ readonly small: 28;
116
+ };
117
+ export declare function agentAvatarPixels(size: AgentAvatarSize, hasPageAvatar: boolean): number;
118
+ /**
119
+ * The catalog key of what a screen reader says about the avatar in a state, or null when it says nothing: an avatar at rest
120
+ * sits beside the words of the turn, which are what is read (the others say what is going on, which no words beside it do).
121
+ */
122
+ export declare function agentAvatarLabelKey(state: AgentAvatarState): ChatMessageKey | null;
123
+ /** A stable text for a look, so the chat can say a change once and not on every redraw. */
124
+ export declare function agentLookSignature(look: AgentLook): string;
125
+ /** Which parts of the work are on screen, and which of them start open. */
126
+ export interface GenerationModulesView {
127
+ /** The typed "Assistant is thinking" line: nothing has streamed yet. */
128
+ showShimmer: boolean;
129
+ showThinking: boolean;
130
+ /** Reasoning is still arriving (and nothing else has started). */
131
+ thinkingStreaming: boolean;
132
+ /** A module is open while it is the live one, and closed once the next has taken over. The person can still open it. */
133
+ thinkingOpenByDefault: boolean;
134
+ showCode: boolean;
135
+ codeStreaming: boolean;
136
+ codeOpenByDefault: boolean;
137
+ }
138
+ /** The modules while a generation runs. The thoughts fold away once the code starts, the code stays open while it streams. */
139
+ export declare function liveModulesView(phase: GenerationActivityPhase): GenerationModulesView;
140
+ /** The modules under a conclusion: whatever was kept, closed, for the person to open. */
141
+ export declare function finishedModulesView(finished: Pick<FinishedGeneration, 'thinking' | 'code'> | null): GenerationModulesView;
142
+ /**
143
+ * The thinking and the code of the generation that just ended: what the modules under the conclusion show.
144
+ * Kept in memory for the newest turn only (the host saves neither); it is gone after a reload, and the conclusion
145
+ * simply shows without them.
146
+ */
147
+ export interface FinishedGeneration {
148
+ /** The prompt of the turn it belongs to, normalized with `normalizePromptText`. */
149
+ prompt: string;
150
+ thinking: string;
151
+ code: string;
152
+ thoughtSeconds: number | null;
153
+ }
154
+ /**
155
+ * The most text kept of either part. A generation streams tails; the chat stitches them, and a runaway stream
156
+ * must not grow memory without end.
157
+ */
158
+ export declare const MAX_KEPT_GENERATION_CHARS = 120000;
159
+ /**
160
+ * A prompt as a way to recognise its turn. A message id is no use: the host swaps a made-up id for the saved one, and
161
+ * may reload the whole conversation after a generation. The words the person wrote survive both.
162
+ */
163
+ export declare function normalizePromptText(content: string | null | undefined): string;
164
+ /** What to keep of a generation that ended, or null when it left nothing to show. */
165
+ export declare function keepFinishedGeneration(input: {
166
+ promptText: string | null | undefined;
167
+ thinking: string;
168
+ code: string;
169
+ thoughtSeconds: number | null;
170
+ }): FinishedGeneration | null;
171
+ /** Whether the kept work belongs under the turn of this prompt: the newest turn, found again by the words of its prompt. */
172
+ export declare function finishedGenerationBelongsTo(finished: FinishedGeneration | null, newestTurnPromptText: string | null | undefined): finished is FinishedGeneration;
173
+ /**
174
+ * Whether the work kept for a run is out of date because the person sent another prompt after the one that run answered.
175
+ * The words of a prompt sent again (a retry) are the same, so `finishedGenerationBelongsTo` cannot tell the new turn from the
176
+ * old one, and for as long as the host takes to save the prompt and start the run (the chat adds the message first) the new turn
177
+ * would show the last run's conclusion. The message the kept work answered tells them apart: a user message after it is a new turn.
178
+ *
179
+ * That message is found by its id, not by the object: the chat builds new message objects when a prompt is sent (it clears the
180
+ * marks of the last version first), while the id of a prompt is the saved one by the time its run ends, because the host
181
+ * saves a prompt before it starts the run.
182
+ *
183
+ * When there is no id, or no message with it in the list any more (the host loaded the conversation again, or the work came back
184
+ * from the archive, which knows only the words) there is nothing to tell by, and the words decide, as they always did.
185
+ */
186
+ export declare function keptWorkIsOutdated(answeredMessageId: string | null, messagesInOrder: ReadonlyArray<{
187
+ id: string;
188
+ messageType: string;
189
+ }>): boolean;
190
+ /** The `userId` the chat gives a message the signed-in person adds with `addUserMessage`, before the host has saved it and told the real one. */
191
+ export declare const CURRENT_USER_PLACEHOLDER_ID = "current_user";
192
+ /**
193
+ * The `userId` the chat's own local service gives every message the person types: `Chat.sendMessage` shows the message at
194
+ * once, made by that service, and `onSaveMessage` swaps the id of the message but never this. A made-up id too: until the page
195
+ * loads the history again (and the messages carry the real ids), it stands for the signed-in person.
196
+ */
197
+ export declare const LOCAL_SERVICE_USER_ID = "test_user";
198
+ /**
199
+ * Finds the person behind a message. The team the page gave wins (it is the list the page keeps up to date); the
200
+ * signed-in person comes next, which is also who the made-up ids of a message that is not saved yet stand for.
201
+ * Null when nobody can be named: the message then has no face and no tooltip, instead of a wrong one.
202
+ */
203
+ export declare function resolveChatMember(userId: string | null | undefined, members: readonly ChatMember[], currentUser: ChatMember | null | undefined): ChatMember | null;
204
+ /** The text the initials of an avatar come from: the name, or the part of the e-mail before the @. Empty when there is neither. */
205
+ export declare function memberDisplayName(member: ChatMember | null | undefined): string;
206
+ /**
207
+ * The e-mail line of the tooltip over an avatar: the e-mail only, never a placeholder word. The same rule as the
208
+ * project header of the Widgetic site (`projectMemberTooltipEmail`), so a person sees the same thing in both places.
209
+ */
210
+ export declare function memberTooltipEmail(email: string | null | undefined): string | null;
211
+ /**
212
+ * Where a click on an avatar goes: a `mailto:` link to the e-mail of the person, as the avatars of the project header of the
213
+ * Widgetic site do (`personMailtoHref`). Null when there is no e-mail to write to (the same rule as the tooltip's: never a
214
+ * placeholder word), and the avatar is then only a picture. The part before the @ is encoded (a `+` in it would otherwise be
215
+ * read as a space); the domain is left as it is.
216
+ */
217
+ export declare function memberMailtoHref(email: string | null | undefined): string | null;
218
+ /** Whether the page told the chat anything about who is who: without it the chat draws no faces next to what people wrote. */
219
+ export declare function pageNamesPeople(members: readonly ChatMember[], currentUser: ChatMember | null | undefined): boolean;