@salmonui/chat 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/conversation/Conversation.d.ts +4 -0
  4. package/dist/conversation/Conversation.d.ts.map +1 -0
  5. package/dist/conversation/Conversation.js +588 -0
  6. package/dist/conversation/Conversation.js.map +1 -0
  7. package/dist/conversation/Item.d.ts +67 -0
  8. package/dist/conversation/Item.d.ts.map +1 -0
  9. package/dist/conversation/Item.js +149 -0
  10. package/dist/conversation/Item.js.map +1 -0
  11. package/dist/conversation/assistant-lazy.d.ts +6 -0
  12. package/dist/conversation/assistant-lazy.d.ts.map +1 -0
  13. package/dist/conversation/assistant-lazy.js +16 -0
  14. package/dist/conversation/assistant-lazy.js.map +1 -0
  15. package/dist/conversation/assistant-static.d.ts +4 -0
  16. package/dist/conversation/assistant-static.d.ts.map +1 -0
  17. package/dist/conversation/assistant-static.js +9 -0
  18. package/dist/conversation/assistant-static.js.map +1 -0
  19. package/dist/conversation/assistant-types.d.ts +2 -0
  20. package/dist/conversation/assistant-types.d.ts.map +1 -0
  21. package/dist/conversation/assistant-types.js +3 -0
  22. package/dist/conversation/assistant-types.js.map +1 -0
  23. package/dist/conversation/assistant.d.ts +54 -0
  24. package/dist/conversation/assistant.d.ts.map +1 -0
  25. package/dist/conversation/assistant.js +348 -0
  26. package/dist/conversation/assistant.js.map +1 -0
  27. package/dist/conversation/context.d.ts +80 -0
  28. package/dist/conversation/context.d.ts.map +1 -0
  29. package/dist/conversation/context.js +40 -0
  30. package/dist/conversation/context.js.map +1 -0
  31. package/dist/conversation/format.d.ts +33 -0
  32. package/dist/conversation/format.d.ts.map +1 -0
  33. package/dist/conversation/format.js +150 -0
  34. package/dist/conversation/format.js.map +1 -0
  35. package/dist/conversation/parts.d.ts +16 -0
  36. package/dist/conversation/parts.d.ts.map +1 -0
  37. package/dist/conversation/parts.js +326 -0
  38. package/dist/conversation/parts.js.map +1 -0
  39. package/dist/conversation/runner.d.ts +15 -0
  40. package/dist/conversation/runner.d.ts.map +1 -0
  41. package/dist/conversation/runner.js +52 -0
  42. package/dist/conversation/runner.js.map +1 -0
  43. package/dist/conversation/store.d.ts +63 -0
  44. package/dist/conversation/store.d.ts.map +1 -0
  45. package/dist/conversation/store.js +142 -0
  46. package/dist/conversation/store.js.map +1 -0
  47. package/dist/conversation/types.d.ts +479 -0
  48. package/dist/conversation/types.d.ts.map +1 -0
  49. package/dist/conversation/types.js +5 -0
  50. package/dist/conversation/types.js.map +1 -0
  51. package/dist/conversation.css +788 -0
  52. package/dist/conversation.d.ts +18 -0
  53. package/dist/conversation.d.ts.map +1 -0
  54. package/dist/conversation.js +26 -0
  55. package/dist/conversation.js.map +1 -0
  56. package/dist/inline-assist/InlineAssist.d.ts +16 -0
  57. package/dist/inline-assist/InlineAssist.d.ts.map +1 -0
  58. package/dist/inline-assist/InlineAssist.js +384 -0
  59. package/dist/inline-assist/InlineAssist.js.map +1 -0
  60. package/dist/inline-assist/model.d.ts +40 -0
  61. package/dist/inline-assist/model.d.ts.map +1 -0
  62. package/dist/inline-assist/model.js +87 -0
  63. package/dist/inline-assist/model.js.map +1 -0
  64. package/dist/inline-assist/types.d.ts +222 -0
  65. package/dist/inline-assist/types.d.ts.map +1 -0
  66. package/dist/inline-assist/types.js +5 -0
  67. package/dist/inline-assist/types.js.map +1 -0
  68. package/dist/inline-assist.css +890 -0
  69. package/dist/inline-assist.d.ts +5 -0
  70. package/dist/inline-assist.d.ts.map +1 -0
  71. package/dist/inline-assist.js +12 -0
  72. package/dist/inline-assist.js.map +1 -0
  73. package/dist/internal/stream-run.d.ts +71 -0
  74. package/dist/internal/stream-run.d.ts.map +1 -0
  75. package/dist/internal/stream-run.js +161 -0
  76. package/dist/internal/stream-run.js.map +1 -0
  77. package/dist/internal/suggest.d.ts +96 -0
  78. package/dist/internal/suggest.d.ts.map +1 -0
  79. package/dist/internal/suggest.js +332 -0
  80. package/dist/internal/suggest.js.map +1 -0
  81. package/dist/smart-paste/fields.d.ts +31 -0
  82. package/dist/smart-paste/fields.d.ts.map +1 -0
  83. package/dist/smart-paste/fields.js +162 -0
  84. package/dist/smart-paste/fields.js.map +1 -0
  85. package/dist/smart-paste/useSmartPaste.d.ts +38 -0
  86. package/dist/smart-paste/useSmartPaste.d.ts.map +1 -0
  87. package/dist/smart-paste/useSmartPaste.js +56 -0
  88. package/dist/smart-paste/useSmartPaste.js.map +1 -0
  89. package/dist/smart-paste.d.ts +3 -0
  90. package/dist/smart-paste.d.ts.map +1 -0
  91. package/dist/smart-paste.js +6 -0
  92. package/dist/smart-paste.js.map +1 -0
  93. package/dist/styles.css +1754 -0
  94. package/dist/text-suggest/useTextSuggest.d.ts +13 -0
  95. package/dist/text-suggest/useTextSuggest.d.ts.map +1 -0
  96. package/dist/text-suggest/useTextSuggest.js +55 -0
  97. package/dist/text-suggest/useTextSuggest.js.map +1 -0
  98. package/dist/text-suggest.css +78 -0
  99. package/dist/text-suggest.d.ts +4 -0
  100. package/dist/text-suggest.d.ts.map +1 -0
  101. package/dist/text-suggest.js +9 -0
  102. package/dist/text-suggest.js.map +1 -0
  103. package/package.json +68 -4
@@ -0,0 +1,18 @@
1
+ import { ConversationRoot } from './conversation/Conversation.js';
2
+ import { ConversationItem, ConversationItemActions } from './conversation/Item.js';
3
+ import { ConversationComposer, ConversationDictation, ConversationFooter, ConversationHeader, ConversationJumpButton, ConversationSuggestions } from './conversation/parts.js';
4
+ /** `<Conversation variant="chat" | "assistant">` with its parts as static members (also exported flat). */
5
+ export declare const Conversation: typeof ConversationRoot & {
6
+ readonly Header: typeof ConversationHeader;
7
+ readonly Item: typeof ConversationItem;
8
+ readonly ItemActions: typeof ConversationItemActions;
9
+ readonly Suggestions: typeof ConversationSuggestions;
10
+ readonly Composer: typeof ConversationComposer;
11
+ readonly Dictation: typeof ConversationDictation;
12
+ readonly JumpButton: typeof ConversationJumpButton;
13
+ readonly Footer: typeof ConversationFooter;
14
+ };
15
+ export { ConversationComposer, ConversationDictation, ConversationFooter, ConversationHeader, ConversationItem, ConversationItemActions, ConversationJumpButton, ConversationSuggestions };
16
+ export { CONVERSATION_DEFAULT_LOCALE_TEXT } from './conversation/format.js';
17
+ export type { ConversationActionItem, ConversationAdapter, ConversationApi, ConversationAttachEvent, ConversationAttachment, ConversationAttachmentError, ConversationAttachmentEvent, ConversationAttachmentOptions, ConversationBeforeAttachEvent, ConversationBeforeMentionSelectEvent, ConversationBeforeSendEvent, ConversationBuiltInAction, ConversationChangeEvent, ConversationChangeReason, ConversationComposerProps, ConversationContentContext, ConversationCustomAction, ConversationDictationProps, ConversationFooterProps, ConversationHeaderProps, ConversationItemActionEvent, ConversationItemActionsProps, ConversationItemProps, ConversationItemRenderContext, ConversationJumpButtonProps, ConversationLocaleText, ConversationMentionConfig, ConversationMentionSelectEvent, ConversationMentionUser, ConversationMessage, ConversationMessageStatus, ConversationPart, ConversationProps, ConversationReplyPreview, ConversationRequest, ConversationResponsePart, ConversationSendEvent, ConversationSuggestionsProps, ConversationToolPart, ConversationTypingEvent, ConversationUploadTransport, ConversationUser, } from './conversation/types.js';
18
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAE/K,2GAA2G;AAC3G,eAAO,MAAM,YAAY,EAAE,OAAO,gBAAgB,GAAG;IACnD,QAAQ,CAAC,MAAM,EAAE,OAAO,kBAAkB,CAAC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}
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import { expectStylesheet } from '@salmonui/core/internal/dev';
3
+ // `@salmonui/chat/conversation`: Conversation (chat and assistant variants)
4
+ // and its parts. The assistant renderers are a chunk
5
+ // loaded only for `variant="assistant"`. Styles:
6
+ // `@salmonui/chat/conversation/styles.css` (self-contained: it includes the
7
+ // Mention popup rules the composer uses).
8
+ import { ConversationRoot } from './conversation/Conversation.js';
9
+ import { ConversationItem, ConversationItemActions } from './conversation/Item.js';
10
+ import { ConversationComposer, ConversationDictation, ConversationFooter, ConversationHeader, ConversationJumpButton, ConversationSuggestions } from './conversation/parts.js';
11
+ /** `<Conversation variant="chat" | "assistant">` with its parts as static members (also exported flat). */
12
+ export const Conversation = Object.assign(ConversationRoot, {
13
+ Header: ConversationHeader,
14
+ Item: ConversationItem,
15
+ ItemActions: ConversationItemActions,
16
+ Suggestions: ConversationSuggestions,
17
+ Composer: ConversationComposer,
18
+ Dictation: ConversationDictation,
19
+ JumpButton: ConversationJumpButton,
20
+ Footer: ConversationFooter,
21
+ });
22
+ export { ConversationComposer, ConversationDictation, ConversationFooter, ConversationHeader, ConversationItem, ConversationItemActions, ConversationJumpButton, ConversationSuggestions };
23
+ export { CONVERSATION_DEFAULT_LOCALE_TEXT } from './conversation/format.js';
24
+ if (process.env.NODE_ENV !== 'production')
25
+ expectStylesheet('@salmonui/chat/conversation', 'salmon-conversation');
26
+ //# sourceMappingURL=conversation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.js","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,4EAA4E;AAC5E,qDAAqD;AACrD,iDAAiD;AACjD,4EAA4E;AAC5E,0CAA0C;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAE/K,2GAA2G;AAC3G,MAAM,CAAC,MAAM,YAAY,GASrB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE;IAClC,MAAM,EAAE,kBAAkB;IAC1B,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,uBAAuB;IACpC,WAAW,EAAE,uBAAuB;IACpC,QAAQ,EAAE,oBAAoB;IAC9B,SAAS,EAAE,qBAAqB;IAChC,UAAU,EAAE,sBAAsB;IAClC,MAAM,EAAE,kBAAkB;CAC3B,CAAC,CAAC;AAEH,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,CAAC;AAC3L,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AAiD5E,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAAE,gBAAgB,CAAC,6BAA6B,EAAE,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type ReactElement } from 'react';
2
+ import { type SpeechToTextButtonProps } from '@salmonui/inputs/speech-to-text';
3
+ import type { InlineAssistProps } from './types.js';
4
+ export declare function InlineAssist(props: InlineAssistProps): ReactElement | null;
5
+ export declare namespace InlineAssist {
6
+ export { InlineAssistDictation as Dictation };
7
+ }
8
+ /** `SpeechToTextButton` props; the transcript is written into the prompt. */
9
+ export type InlineAssistDictationProps = SpeechToTextButtonProps;
10
+ /**
11
+ * Dictation into the prompt: the Inputs `SpeechToTextButton`; the
12
+ * transcript is appended to the prompt text present when listening started.
13
+ * Render it as a child of `InlineAssist`.
14
+ */
15
+ export declare function InlineAssistDictation(props: InlineAssistDictationProps): ReactElement;
16
+ //# sourceMappingURL=InlineAssist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InlineAssist.d.ts","sourceRoot":"","sources":["../../src/inline-assist/InlineAssist.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAwK,KAAK,YAAY,EAAkC,MAAM,OAAO,CAAC;AAGhP,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAUnG,OAAO,KAAK,EASV,iBAAiB,EAElB,MAAM,YAAY,CAAC;AA0CpB,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,GAAG,IAAI,CAsR1E;yBAtRe,YAAY;aAmaH,qBAAqB;;AA/B9C,6EAA6E;AAC7E,MAAM,MAAM,0BAA0B,GAAG,uBAAuB,CAAC;AAEjE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,GAAG,YAAY,CAqBrF"}
@@ -0,0 +1,384 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ // InlineAssist: a prompt anchored to an editor element, a text range or a
4
+ // point, with a slash command menu (the Buttons `Menu`), an adapter that
5
+ // streams the response and response actions. APG non-modal dialog: focus
6
+ // moves into the prompt on open and returns to the editor on close, Tab is
7
+ // not contained, Escape and an outside press close it (popover mode).
8
+ //
9
+ // State: the open, prompt and history triads are React state (they change on
10
+ // user actions only); the streamed text lives in the per-instance store and
11
+ // is published once per animation frame. Without `renderContent` the
12
+ // streaming text is appended to a text node outside React (no commit per
13
+ // chunk). The server renders nothing (the assist opens on the client).
14
+ import { createContext, use, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
15
+ import { Button } from '@salmonui/buttons/button';
16
+ import { Menu } from '@salmonui/buttons/menu';
17
+ import { SpeechToTextButton } from '@salmonui/inputs/speech-to-text';
18
+ import { useControllableState } from '@salmonui/core/internal/controllable';
19
+ import { useLocaleText } from '@salmonui/core/internal/locale';
20
+ import { useFocusScope } from '@salmonui/core/internal/focus-scope';
21
+ import { liveRegionProps, announce } from '@salmonui/core/internal/live-region';
22
+ import { Overlay, useHydrated } from '@salmonui/core/internal/overlay';
23
+ import { pointRect } from '@salmonui/core/internal/position';
24
+ import { runStream } from '../internal/stream-run.js';
25
+ import { buildRequest, cancelable, commandQuery, commitMessage, createAssistStore, filterCommands, INLINE_ASSIST_DEFAULT_LOCALE_TEXT, isPoint, isRange, mergeTranscript, selectionText } from './model.js';
26
+ const EMPTY_MESSAGES = Object.freeze([]);
27
+ const EMPTY_COMMANDS = Object.freeze([]);
28
+ const DEFAULT_ACTIONS = Object.freeze(['accept', 'discard', 'retry']);
29
+ const EDITABLE = 'textarea, input, select, [contenteditable]:not([contenteditable="false"]), [tabindex], a[href], button';
30
+ const cx = (base, extra) => (extra ? `${base} ${extra}` : base);
31
+ /** The latest value, readable from stable callbacks (written after commit). */
32
+ function useLatest(value) {
33
+ const ref = useRef(value);
34
+ useLayoutEffect(() => {
35
+ ref.current = value;
36
+ });
37
+ return ref;
38
+ }
39
+ /** The element of an anchor (an element, a ref, or the node a range starts in). Event time only. */
40
+ function anchorElement(anchor) {
41
+ if (!anchor || isPoint(anchor))
42
+ return null;
43
+ if (isRange(anchor)) {
44
+ const node = anchor.startContainer;
45
+ return node.nodeType === 1 ? node : node.parentElement;
46
+ }
47
+ if ('current' in anchor)
48
+ return anchor.current;
49
+ return anchor;
50
+ }
51
+ /** The editor focus returns to: the focusable element at or around the anchor. Event time only. */
52
+ function editorOf(anchor) {
53
+ return anchorElement(anchor)?.closest(EDITABLE) ?? null;
54
+ }
55
+ const AssistContext = createContext(null);
56
+ export function InlineAssist(props) {
57
+ const { mode = 'popover', open: openProp, defaultOpen, onOpenChange, ref } = props;
58
+ const localeText = useLocaleText('inlineAssist', props.localeText);
59
+ const notifyOpen = onOpenChange && ((next, reason) => onOpenChange(next, Object.freeze({ reason })));
60
+ const [openState, setOpen] = useControllableState(openProp, defaultOpen ?? false, notifyOpen, 'InlineAssist open');
61
+ const [value, setValue] = useControllableState(props.value, props.defaultValue ?? '', props.onValueChange, 'InlineAssist value');
62
+ const [messages, setMessages] = useControllableState(props.messages, props.defaultMessages ?? EMPTY_MESSAGES, props.onMessagesChange, 'InlineAssist messages');
63
+ const hydrated = useHydrated();
64
+ const open = openState && hydrated;
65
+ const [store] = useState(createAssistStore);
66
+ const view = useSyncExternalStore(store.subscribe, store.getView, store.getView);
67
+ const text = localeText ? { ...INLINE_ASSIST_DEFAULT_LOCALE_TEXT, ...localeText } : INLINE_ASSIST_DEFAULT_LOCALE_TEXT;
68
+ const base = useId();
69
+ const counter = useRef(0);
70
+ const run = useRef(null);
71
+ const inputRef = useRef(null);
72
+ const panelRef = useRef(null);
73
+ const menuRef = useRef(null);
74
+ const liveRef = useRef(null);
75
+ const latest = useLatest({ props, value, messages, open, setOpen, setValue, setMessages, text });
76
+ // Closing (any way, controlled included) aborts the running response and clears the shown one.
77
+ useEffect(() => {
78
+ if (open)
79
+ return;
80
+ run.current?.controller.abort();
81
+ store.setView({ phase: 'idle', message: null, commands: false });
82
+ }, [open, store]);
83
+ useEffect(() => () => {
84
+ run.current?.controller.abort();
85
+ store.dispose();
86
+ }, [store]);
87
+ const api = useMemo(() => {
88
+ const close = (reason) => latest.current.setOpen(false, reason);
89
+ const start = async (prompt, command, retry) => {
90
+ const l = latest.current;
91
+ const history = retry ? l.messages.slice(0, -1) : l.messages;
92
+ const request = buildRequest(prompt, command, selectionText(l.props.anchor, l.props.selection), history);
93
+ if (l.props.onBeforeSend) {
94
+ const event = cancelable({ request });
95
+ l.props.onBeforeSend(event);
96
+ if (event.defaultPrevented)
97
+ return;
98
+ }
99
+ l.props.onSend?.(Object.freeze({ request }));
100
+ if (!retry)
101
+ l.setValue('');
102
+ if (!l.open)
103
+ l.setOpen(true, 'api');
104
+ run.current?.controller.abort();
105
+ const token = { controller: new AbortController() };
106
+ run.current = token;
107
+ const id = `${base}${(counter.current += 1)}`;
108
+ store.setView({ phase: 'pending', message: null, commands: false });
109
+ store.stream.start();
110
+ const adapter = l.props.adapter;
111
+ const outcome = await runStream(() => (adapter ? adapter(request, { signal: token.controller.signal }) : Promise.resolve('')), token.controller.signal, {
112
+ text(delta) {
113
+ if (run.current !== token)
114
+ return;
115
+ store.stream.push(delta);
116
+ if (store.getView().phase === 'pending')
117
+ store.setView({ phase: 'streaming' });
118
+ },
119
+ });
120
+ // A newer request owns the view; this one is dropped.
121
+ if (run.current !== token)
122
+ return;
123
+ run.current = null;
124
+ store.stream.end();
125
+ const message = Object.freeze({ id, prompt, ...(command ? { command: command.id } : {}), response: outcome.text, status: outcome.status });
126
+ const after = latest.current;
127
+ if (outcome.status === 'error')
128
+ after.props.onError?.(outcome.error);
129
+ after.setMessages((previous) => commitMessage(previous, message, retry), Object.freeze({ reason: retry ? 'retry' : 'response' }));
130
+ if (!after.open)
131
+ return;
132
+ store.setView({ phase: 'done', message });
133
+ announce(liveRef.current, outcome.status === 'error' ? after.text.error : outcome.text);
134
+ };
135
+ const send = (input, command, retry = false) => {
136
+ const prompt = (input ?? latest.current.value).trim();
137
+ if (prompt !== '')
138
+ void start(prompt, command, retry);
139
+ };
140
+ const selectCommand = (command) => {
141
+ const l = latest.current;
142
+ store.setView({ commands: false });
143
+ if (commandQuery(l.value) !== null)
144
+ l.setValue('');
145
+ inputRef.current?.focus({ preventScroll: true });
146
+ if (l.props.onCommandSelect) {
147
+ const event = cancelable({ command });
148
+ l.props.onCommandSelect(event);
149
+ if (event.defaultPrevented)
150
+ return;
151
+ }
152
+ send(command.prompt ?? command.label, command);
153
+ };
154
+ const respond = (action) => {
155
+ const l = latest.current;
156
+ const message = store.getView().message;
157
+ if (!message)
158
+ return;
159
+ const id = typeof action === 'string' ? action : action.id;
160
+ const event = cancelable({ action: id, text: message.response, message });
161
+ l.props.onResponseActionClick?.(event);
162
+ if (event.defaultPrevented || typeof action !== 'string')
163
+ return;
164
+ if (action === 'accept') {
165
+ l.props.onAccept?.(Object.freeze({ text: message.response, message }));
166
+ close('accept');
167
+ }
168
+ else if (action === 'discard') {
169
+ l.props.onDiscard?.(Object.freeze({ message }));
170
+ close('discard');
171
+ }
172
+ else {
173
+ const command = message.command === undefined ? undefined : (l.props.commands ?? EMPTY_COMMANDS).find((c) => c.id === message.command);
174
+ send(message.prompt, command, true);
175
+ }
176
+ };
177
+ const handle = {
178
+ open: () => latest.current.setOpen(true, 'api'),
179
+ close: () => close('api'),
180
+ send: (input) => send(input),
181
+ stop: () => run.current?.controller.abort(),
182
+ showCommands: () => {
183
+ if (!latest.current.open)
184
+ latest.current.setOpen(true, 'api');
185
+ store.setView({ commands: true });
186
+ },
187
+ hideCommands: () => store.setView({ commands: false }),
188
+ focus: () => inputRef.current?.focus({ preventScroll: true }),
189
+ get element() {
190
+ return panelRef.current;
191
+ },
192
+ };
193
+ return { handle, close, send, selectCommand, respond };
194
+ }, [base, latest, store]);
195
+ useImperativeHandle(ref, () => api.handle, [api]);
196
+ const ctx = useMemo(() => ({ text, getValue: () => latest.current.value, setValue: (next) => latest.current.setValue(next) }), [text, latest]);
197
+ const anchor = props.anchor;
198
+ // Stable per anchor and per opening (a point rect or the fallback getter must not change on each render).
199
+ const overlayAnchor = useMemo(() => (open ? toOverlayAnchor(anchor) : null), [anchor, open]);
200
+ if (!open)
201
+ return null;
202
+ const commands = props.commands ?? EMPTY_COMMANDS;
203
+ const query = commandQuery(value);
204
+ const shown = commands.length > 0 && (view.commands || query !== null) ? filterCommands(commands, query ?? '') : EMPTY_COMMANDS;
205
+ const menuId = `${base}commands`;
206
+ const responding = view.phase === 'pending' || view.phase === 'streaming';
207
+ const focusMenu = () => {
208
+ const item = menuRef.current?.querySelector('[role="menuitem"]:not([aria-disabled="true"])');
209
+ item?.focus();
210
+ return !!item;
211
+ };
212
+ const hideCommands = () => {
213
+ store.setView({ commands: false });
214
+ if (query !== null)
215
+ setValue('');
216
+ };
217
+ const onInputKeyDown = (event) => {
218
+ if (event.nativeEvent.isComposing)
219
+ return;
220
+ if (shown.length > 0) {
221
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
222
+ if (focusMenu())
223
+ event.preventDefault();
224
+ return;
225
+ }
226
+ if (event.key === 'Enter' && !event.shiftKey) {
227
+ event.preventDefault();
228
+ const first = shown.find((c) => !c.disabled);
229
+ if (first)
230
+ api.selectCommand(first);
231
+ return;
232
+ }
233
+ }
234
+ if (event.key === 'Enter' && !event.shiftKey) {
235
+ event.preventDefault();
236
+ if (!responding)
237
+ api.send();
238
+ }
239
+ };
240
+ // Escape in the prompt or the menu hides the command menu first (the dismiss layer then skips it).
241
+ // Inline mode has no dismiss layer: Escape inside the panel closes it.
242
+ const onPanelKeyDown = (event) => {
243
+ if (event.key !== 'Escape' || event.defaultPrevented)
244
+ return;
245
+ if (shown.length > 0) {
246
+ event.preventDefault();
247
+ hideCommands();
248
+ inputRef.current?.focus({ preventScroll: true });
249
+ }
250
+ else if (mode === 'inline') {
251
+ event.preventDefault();
252
+ api.close('escape');
253
+ }
254
+ };
255
+ const inputProps = {
256
+ ref: inputRef,
257
+ id: `${base}prompt`,
258
+ className: 'salmon-inline-assist__input',
259
+ value,
260
+ rows: 1,
261
+ placeholder: props.placeholder ?? text.placeholder,
262
+ 'aria-label': text.prompt,
263
+ 'aria-controls': shown.length > 0 ? menuId : undefined,
264
+ onChange: (event) => setValue(event.currentTarget.value),
265
+ onKeyDown: onInputKeyDown,
266
+ };
267
+ const defaultComposer = _jsx("textarea", { ...inputProps });
268
+ const composer = props.renderComposer
269
+ ? props.renderComposer({ value, setValue: (next) => setValue(next), send: (input) => api.send(input), stop: api.handle.stop, responding, inputProps, defaultComposer })
270
+ : defaultComposer;
271
+ const placement = props.toolbarPlacement ?? 'inline';
272
+ const toolbar = props.toolbar != null ? (_jsx("div", { className: "salmon-inline-assist__toolbar", "data-placement": placement, children: props.toolbar })) : null;
273
+ const content = (_jsxs(AssistContext, { value: ctx, children: [_jsxs("div", { className: "salmon-inline-assist__composer", children: [composer, placement === 'inline' ? toolbar : null, props.children, responding ? (_jsx(Button, { variant: "outline", className: "salmon-inline-assist__stop", onClick: api.handle.stop, children: text.stop })) : (_jsx(Button, { tone: "primary", className: "salmon-inline-assist__send", disabled: value.trim() === '', onClick: () => api.send(), children: text.send }))] }), shown.length > 0 ? (_jsx(Menu, { ref: menuRef, id: menuId, className: "salmon-inline-assist__commands", "aria-label": text.commands, items: shown.map(toMenuItem), onAction: (event) => {
274
+ const command = shown.find((c) => c.id === event.id);
275
+ if (command)
276
+ api.selectCommand(command);
277
+ } })) : null, placement === 'bottom' ? toolbar : null, view.phase !== 'idle' ? _jsx(Response, { store: store, view: view.phase, message: view.message, text: text, actions: props.responseActions ?? DEFAULT_ACTIONS, renderContent: props.renderContent, onAction: api.respond }) : null, _jsx("span", { ref: liveRef, className: "salmon-visually-hidden", ...liveRegionProps('polite') })] }));
278
+ const shared = {
279
+ ref: panelRef,
280
+ role: 'dialog',
281
+ 'aria-label': props['aria-labelledby'] ? undefined : (props['aria-label'] ?? text.label),
282
+ 'aria-labelledby': props['aria-labelledby'],
283
+ className: cx('salmon-inline-assist', props.className),
284
+ style: props.style,
285
+ 'data-mode': mode,
286
+ 'data-phase': view.phase,
287
+ onKeyDown: onPanelKeyDown,
288
+ };
289
+ const returnFocus = props.returnFocus !== false;
290
+ const restore = !returnFocus ? false : anchor && !isPoint(anchor) ? { get current() { return editorOf(anchor); } } : true;
291
+ const focus = { autoFocus: 'first', tab: 'leave', restoreFocus: restore };
292
+ if (mode === 'inline') {
293
+ return (_jsx(InlinePanel, { ...shared, focus: focus, children: content }));
294
+ }
295
+ return (_jsx(Overlay, { ...shared, anchor: overlayAnchor, placement: "bottom-start", offset: 6, onDismiss: (reason) => api.close(reason), dismissOnOutsidePress: true, dismissOnEscape: true, dismissOnFocusOutside: true, focus: focus, children: content }));
296
+ }
297
+ /** The overlay anchor of a public anchor; without one, the element focused when the assist opened. */
298
+ function toOverlayAnchor(anchor) {
299
+ if (isPoint(anchor))
300
+ return pointRect(anchor.x, anchor.y);
301
+ if (anchor)
302
+ return anchor;
303
+ let fallback = null;
304
+ return () => (fallback ??= globalThis.document?.activeElement ?? null);
305
+ }
306
+ /** A command as a `Menu` items entry. */
307
+ function toMenuItem(command) {
308
+ return { id: command.id, label: command.label, ...(command.icon != null ? { icon: command.icon } : {}), ...(command.disabled ? { disabled: true } : {}) };
309
+ }
310
+ /** Inline mode: the dialog in the page flow (no dismiss layer; Escape is handled by the panel). */
311
+ function InlinePanel(props) {
312
+ const { ref, focus, children, ...rest } = props;
313
+ useFocusScope(ref, focus);
314
+ return (_jsx("div", { ...rest, ref: ref, children: children }));
315
+ }
316
+ function Response(props) {
317
+ const { store, view, message, text, actions, renderContent, onAction } = props;
318
+ const done = view === 'done' && message !== null;
319
+ const failed = done && message.status === 'error';
320
+ let body;
321
+ if (done)
322
+ body = renderContent ? renderContent(message.response, { streaming: false }) : _jsx("div", { className: "salmon-inline-assist__text", dir: "auto", children: message.response });
323
+ else if (renderContent)
324
+ body = _jsx(RenderedStream, { stream: store.stream, render: renderContent });
325
+ else
326
+ body = _jsx(StreamText, { stream: store.stream });
327
+ return (_jsxs("div", { className: "salmon-inline-assist__response", "data-status": done ? message.status : view, "aria-busy": done ? undefined : true, children: [view === 'pending' ? _jsx("div", { className: "salmon-inline-assist__pending", children: text.pending }) : null, body, failed ? _jsx("div", { className: "salmon-inline-assist__error", children: text.error }) : null, done ? (_jsx("div", { className: "salmon-inline-assist__actions", role: "group", "aria-label": text.responseActions, children: actions.map((action) => {
328
+ const builtIn = typeof action === 'string';
329
+ const id = builtIn ? action : action.id;
330
+ return (_jsx(Button, { size: "sm", variant: id === 'accept' ? 'solid' : 'ghost', tone: id === 'accept' ? 'primary' : 'neutral', "data-action": id, disabled: id === 'accept' && message.response === '', iconStart: builtIn ? undefined : action.icon, onClick: () => onAction(action), children: builtIn ? text[action] : action.label }, id));
331
+ }) })) : null] }));
332
+ }
333
+ /** Default streaming renderer: appends each published delta to one text node, outside React. */
334
+ function StreamText(props) {
335
+ const ref = useRef(null);
336
+ const { stream } = props;
337
+ useLayoutEffect(() => {
338
+ const el = ref.current;
339
+ if (!el)
340
+ return;
341
+ const node = el.ownerDocument.createTextNode('');
342
+ el.append(node);
343
+ const paint = () => {
344
+ const next = stream.getSnapshot().text;
345
+ if (next.length > node.data.length && next.startsWith(node.data))
346
+ node.appendData(next.slice(node.data.length));
347
+ else if (next !== node.data)
348
+ node.data = next;
349
+ };
350
+ paint();
351
+ const unsubscribe = stream.subscribe(paint);
352
+ return () => {
353
+ unsubscribe();
354
+ node.remove();
355
+ };
356
+ }, [stream]);
357
+ return _jsx("div", { ref: ref, className: "salmon-inline-assist__text", dir: "auto" });
358
+ }
359
+ /** `renderContent` while streaming: one render per published frame. */
360
+ function RenderedStream(props) {
361
+ const snapshot = useSyncExternalStore(props.stream.subscribe, props.stream.getSnapshot, props.stream.getSnapshot);
362
+ return props.render(snapshot.text, { streaming: true });
363
+ }
364
+ /**
365
+ * Dictation into the prompt: the Inputs `SpeechToTextButton`; the
366
+ * transcript is appended to the prompt text present when listening started.
367
+ * Render it as a child of `InlineAssist`.
368
+ */
369
+ export function InlineAssistDictation(props) {
370
+ const ctx = use(AssistContext);
371
+ if (!ctx)
372
+ throw new Error('[salmonui] <InlineAssist.Dictation> must be rendered inside <InlineAssist>.');
373
+ const startValue = useRef('');
374
+ const { onStart, onTranscriptChange, localeText, className, ...rest } = props;
375
+ return (_jsx(SpeechToTextButton, { variant: "ghost", ...rest, className: cx('salmon-inline-assist__dictation', className), localeText: { label: ctx.text.dictation, ...localeText }, onStart: () => {
376
+ startValue.current = ctx.getValue();
377
+ onStart?.();
378
+ }, onTranscriptChange: (transcript, details) => {
379
+ ctx.setValue(mergeTranscript(startValue.current, transcript));
380
+ onTranscriptChange?.(transcript, details);
381
+ } }));
382
+ }
383
+ InlineAssist.Dictation = InlineAssistDictation;
384
+ //# sourceMappingURL=InlineAssist.js.map
@@ -0,0 +1 @@
1
+ {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W,CAAC,CAAC;IAClH,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC;AAKD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAiC;IACrE,MAAM,GAAG,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACzG,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAC9B,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC9E,OAAO,CACL,KAAC,kBAAkB,IACjB,OAAO,EAAC,OAAO,KACX,IAAI,EACR,SAAS,EAAE,EAAE,CAAC,iCAAiC,EAAE,SAAS,CAAC,EAC3D,UAAU,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,UAAU,EAAE,EACxD,OAAO,EAAE,GAAG,EAAE;YACZ,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO,EAAE,EAAE,CAAC;QACd,CAAC,EACD,kBAAkB,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE;YAC1C,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;YAC9D,kBAAkB,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC,GACD,CACH,CAAC;AACJ,CAAC;AAED,YAAY,CAAC,SAAS,GAAG,qBAAqB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type FrameScheduler, type StreamBuffer } from '../internal/stream-run.js';
2
+ import type { InlineAssistAnchor, InlineAssistCommand, InlineAssistLocaleText, InlineAssistMessage, InlineAssistPoint, InlineAssistRequest } from './types.js';
3
+ export declare const INLINE_ASSIST_DEFAULT_LOCALE_TEXT: Required<InlineAssistLocaleText>;
4
+ /** `'idle'`: no response shown; `'pending'`: waiting for the first chunk; `'streaming'`; `'done'`: a finished (or stopped, or failed) response. */
5
+ export type AssistPhase = 'idle' | 'pending' | 'streaming' | 'done';
6
+ export interface AssistView {
7
+ readonly phase: AssistPhase;
8
+ /** The shown response once finished (`phase: 'done'`). */
9
+ readonly message: InlineAssistMessage | null;
10
+ /** The command menu is shown through `api.showCommands()` (typing `/` shows it too). */
11
+ readonly commands: boolean;
12
+ }
13
+ export interface AssistStore {
14
+ getView(): AssistView;
15
+ setView(patch: Partial<AssistView>): void;
16
+ subscribe(listener: () => void): () => void;
17
+ readonly stream: StreamBuffer;
18
+ dispose(): void;
19
+ }
20
+ export declare function createAssistStore(schedule?: FrameScheduler): AssistStore;
21
+ /** The filter text after a leading `/` (no whitespace), or `null` when the prompt is not a command query. */
22
+ export declare function commandQuery(value: string): string | null;
23
+ /** Commands whose label or keywords contain `query` (case-insensitive); all of them for an empty query. */
24
+ export declare function filterCommands(commands: readonly InlineAssistCommand[], query: string): readonly InlineAssistCommand[];
25
+ export declare const isPoint: (anchor: unknown) => anchor is InlineAssistPoint;
26
+ /** A DOM `Range` (duck-typed, so the module stays free of DOM globals). */
27
+ export declare const isRange: (anchor: unknown) => anchor is Range;
28
+ /** The request's `selection`: the prop, else the text of a `Range` anchor, else `''`. Event time only. */
29
+ export declare function selectionText(anchor: InlineAssistAnchor | null | undefined, selection: string | undefined): string;
30
+ export declare function buildRequest(prompt: string, command: InlineAssistCommand | undefined, selection: string, messages: readonly InlineAssistMessage[]): InlineAssistRequest;
31
+ /** Appends `message`, or replaces the last message when `replaceLast` (Retry). */
32
+ export declare function commitMessage(messages: readonly InlineAssistMessage[], message: InlineAssistMessage, replaceLast: boolean): readonly InlineAssistMessage[];
33
+ /** The prompt after dictation: the text before dictation started, a space, then the transcript. */
34
+ export declare function mergeTranscript(base: string, transcript: string): string;
35
+ /** A frozen event whose `preventDefault()` cancels the built-in follow-up. */
36
+ export declare function cancelable<T extends object>(fields: T): T & {
37
+ preventDefault(): void;
38
+ readonly defaultPrevented: boolean;
39
+ };
40
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/inline-assist/model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE/J,eAAO,MAAM,iCAAiC,EAAE,QAAQ,CAAC,sBAAsB,CAc7E,CAAC;AAEH,mJAAmJ;AACnJ,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,IAAI,UAAU,CAAC;IACtB,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IAC1C,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,OAAO,IAAI,IAAI,CAAC;CACjB;AAID,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,WAAW,CAoBxE;AAED,6GAA6G;AAC7G,wBAA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