@flamingo-stack/openframe-frontend-core 0.0.692 → 0.0.693
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat-protocol/events.d.ts +3 -0
- package/dist/chat-protocol/events.d.ts.map +1 -1
- package/dist/chat-protocol/frames.d.ts +6 -0
- package/dist/chat-protocol/frames.d.ts.map +1 -1
- package/dist/chat-protocol/index.cjs +26 -1
- package/dist/chat-protocol/index.cjs.map +1 -1
- package/dist/chat-protocol/index.d.ts +1 -0
- package/dist/chat-protocol/index.d.ts.map +1 -1
- package/dist/chat-protocol/index.js +23 -2
- package/dist/chat-protocol/index.js.map +1 -1
- package/dist/chat-protocol/leading-frames.d.ts.map +1 -1
- package/dist/chat-protocol/progress.d.ts +35 -0
- package/dist/chat-protocol/progress.d.ts.map +1 -0
- package/dist/{chunk-ATREVNIN.cjs → chunk-3HGVRJTC.cjs} +33 -33
- package/dist/{chunk-ATREVNIN.cjs.map → chunk-3HGVRJTC.cjs.map} +1 -1
- package/dist/{chunk-F6LXGP6S.cjs → chunk-4KM5MVBM.cjs} +3 -3
- package/dist/{chunk-F6LXGP6S.cjs.map → chunk-4KM5MVBM.cjs.map} +1 -1
- package/dist/{chunk-CKO6NKNE.js → chunk-5CZZ4JLE.js} +2 -2
- package/dist/{chunk-RK47E3PP.js → chunk-5NUOZZRR.js} +2 -2
- package/dist/{chunk-DUURFYGS.cjs → chunk-6H5PPQWP.cjs} +3 -3
- package/dist/{chunk-DUURFYGS.cjs.map → chunk-6H5PPQWP.cjs.map} +1 -1
- package/dist/{chunk-FTK3S57R.cjs → chunk-7BC3NJAV.cjs} +15 -15
- package/dist/{chunk-FTK3S57R.cjs.map → chunk-7BC3NJAV.cjs.map} +1 -1
- package/dist/{chunk-Q25VYAEL.cjs → chunk-BDGNKIHU.cjs} +22 -22
- package/dist/{chunk-Q25VYAEL.cjs.map → chunk-BDGNKIHU.cjs.map} +1 -1
- package/dist/{chunk-TEIHEFXP.js → chunk-BFV4L3D7.js} +5 -5
- package/dist/{chunk-GZRU2A4L.cjs → chunk-CMA74BXW.cjs} +40 -3
- package/dist/chunk-CMA74BXW.cjs.map +1 -0
- package/dist/{chunk-WTYQCT4A.cjs → chunk-DDCQG3WO.cjs} +10 -10
- package/dist/{chunk-WTYQCT4A.cjs.map → chunk-DDCQG3WO.cjs.map} +1 -1
- package/dist/{chunk-KDCIYRZV.cjs → chunk-DVEFZ5DU.cjs} +22 -22
- package/dist/{chunk-KDCIYRZV.cjs.map → chunk-DVEFZ5DU.cjs.map} +1 -1
- package/dist/{chunk-X5XFKI6N.js → chunk-EZFSUHNP.js} +2 -2
- package/dist/{chunk-IQTQIBZ3.js → chunk-F2ZBNRTF.js} +5 -5
- package/dist/{chunk-EXWS2QSD.cjs → chunk-FMPH6G3E.cjs} +339 -339
- package/dist/{chunk-EXWS2QSD.cjs.map → chunk-FMPH6G3E.cjs.map} +1 -1
- package/dist/{chunk-RLNNV46K.js → chunk-GVMVPMDE.js} +3 -3
- package/dist/{chunk-7BNWMOPM.cjs → chunk-HRGG56GC.cjs} +45 -45
- package/dist/{chunk-7BNWMOPM.cjs.map → chunk-HRGG56GC.cjs.map} +1 -1
- package/dist/{chunk-ZAV2F4VX.js → chunk-I72FRMF6.js} +2 -2
- package/dist/{chunk-PKZGXRU2.js → chunk-IC2SDW6U.js} +4 -4
- package/dist/{chunk-Y7ZEVTLC.js → chunk-ID5QPM3X.js} +40 -3
- package/dist/chunk-ID5QPM3X.js.map +1 -0
- package/dist/{chunk-LYQULSK4.js → chunk-INVP4WLX.js} +5 -5
- package/dist/{chunk-DKJDO7YM.cjs → chunk-JAQK3GQJ.cjs} +26 -26
- package/dist/{chunk-DKJDO7YM.cjs.map → chunk-JAQK3GQJ.cjs.map} +1 -1
- package/dist/{chunk-LYJJH4D6.js → chunk-PPRD3PTW.js} +3 -3
- package/dist/{chunk-MCNQKS6I.js → chunk-QDH62H4N.js} +3 -3
- package/dist/{chunk-5XPK2QGU.cjs → chunk-RKIMG67Q.cjs} +10 -10
- package/dist/{chunk-5XPK2QGU.cjs.map → chunk-RKIMG67Q.cjs.map} +1 -1
- package/dist/{chunk-RTKF5AYA.cjs → chunk-S54QA2VE.cjs} +5 -5
- package/dist/{chunk-RTKF5AYA.cjs.map → chunk-S54QA2VE.cjs.map} +1 -1
- package/dist/{chunk-CG7OWW7X.cjs → chunk-SG57SBYG.cjs} +10 -10
- package/dist/{chunk-CG7OWW7X.cjs.map → chunk-SG57SBYG.cjs.map} +1 -1
- package/dist/{chunk-A5NHAHV6.js → chunk-TFSRPBVT.js} +2 -2
- package/dist/{chunk-KQZMM3QJ.cjs → chunk-UWJZRI5J.cjs} +71 -71
- package/dist/{chunk-KQZMM3QJ.cjs.map → chunk-UWJZRI5J.cjs.map} +1 -1
- package/dist/{chunk-TXFGG47A.js → chunk-WJAMBSMW.js} +3 -3
- package/dist/{chunk-CKUPANVU.cjs → chunk-WSYCPIRG.cjs} +4 -4
- package/dist/{chunk-CKUPANVU.cjs.map → chunk-WSYCPIRG.cjs.map} +1 -1
- package/dist/{chunk-AVAZ6BD6.js → chunk-XI2BAIKJ.js} +3 -3
- package/dist/{chunk-Z7QCNCBN.js → chunk-XWAT6ZP5.js} +6 -6
- package/dist/components/case-studies/index.cjs +14 -14
- package/dist/components/case-studies/index.js +3 -3
- package/dist/components/chat/chat-message-list.d.ts.map +1 -1
- package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-unified-chat.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +2 -2
- package/dist/components/chat/index.js +1 -1
- package/dist/components/chat/stream/chat-dialog-store.d.ts.map +1 -1
- package/dist/components/chat/stream/chat-stream-reducer.d.ts +4 -0
- package/dist/components/chat/stream/chat-stream-reducer.d.ts.map +1 -1
- package/dist/components/chat/types/component.types.d.ts +2 -0
- package/dist/components/chat/types/component.types.d.ts.map +1 -1
- package/dist/components/chat/types/unified-chat-state.types.d.ts +5 -0
- package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +4 -4
- package/dist/components/contact/index.js +3 -3
- package/dist/components/docs/index.cjs +7 -7
- package/dist/components/docs/index.js +6 -6
- package/dist/components/embeds/index.cjs +4 -4
- package/dist/components/embeds/index.js +3 -3
- package/dist/components/faq/index.cjs +4 -4
- package/dist/components/faq/index.js +3 -3
- package/dist/components/features/index.cjs +3 -3
- package/dist/components/features/index.js +2 -2
- package/dist/components/help-center-pages/index.cjs +73 -73
- package/dist/components/help-center-pages/index.js +14 -14
- package/dist/components/index.cjs +40 -40
- package/dist/components/index.js +13 -13
- package/dist/components/meeting-scheduler/index.cjs +25 -25
- package/dist/components/meeting-scheduler/index.js +2 -2
- package/dist/components/navigation/index.cjs +6 -6
- package/dist/components/navigation/index.js +5 -5
- package/dist/components/onboarding-guides/index.cjs +6 -6
- package/dist/components/onboarding-guides/index.js +5 -5
- package/dist/components/tickets/index.cjs +7 -7
- package/dist/components/tickets/index.js +6 -6
- package/dist/components/ui/index.cjs +3 -3
- package/dist/components/ui/index.js +2 -2
- package/dist/index.cjs +7 -7
- package/dist/index.js +6 -6
- package/package.json +1 -1
- package/src/chat-protocol/__tests__/progress.test.ts +39 -0
- package/src/chat-protocol/events.ts +3 -0
- package/src/chat-protocol/frames.ts +7 -0
- package/src/chat-protocol/index.ts +2 -0
- package/src/chat-protocol/leading-frames.ts +4 -1
- package/src/chat-protocol/progress.ts +55 -0
- package/src/components/chat/chat-message-list.tsx +10 -1
- package/src/components/chat/embeddable-chat.tsx +5 -0
- package/src/components/chat/hooks/use-sse-chat-adapter.ts +2 -0
- package/src/components/chat/hooks/use-unified-chat.ts +1 -0
- package/src/components/chat/stream/__tests__/chat-stream-reducer-progress.test.ts +40 -0
- package/src/components/chat/stream/chat-dialog-store.ts +1 -0
- package/src/components/chat/stream/chat-stream-reducer.ts +13 -0
- package/src/components/chat/types/component.types.ts +2 -0
- package/src/components/chat/types/unified-chat-state.types.ts +6 -0
- package/dist/chunk-GZRU2A4L.cjs.map +0 -1
- package/dist/chunk-Y7ZEVTLC.js.map +0 -1
- /package/dist/{chunk-CKO6NKNE.js.map → chunk-5CZZ4JLE.js.map} +0 -0
- /package/dist/{chunk-RK47E3PP.js.map → chunk-5NUOZZRR.js.map} +0 -0
- /package/dist/{chunk-TEIHEFXP.js.map → chunk-BFV4L3D7.js.map} +0 -0
- /package/dist/{chunk-X5XFKI6N.js.map → chunk-EZFSUHNP.js.map} +0 -0
- /package/dist/{chunk-IQTQIBZ3.js.map → chunk-F2ZBNRTF.js.map} +0 -0
- /package/dist/{chunk-RLNNV46K.js.map → chunk-GVMVPMDE.js.map} +0 -0
- /package/dist/{chunk-ZAV2F4VX.js.map → chunk-I72FRMF6.js.map} +0 -0
- /package/dist/{chunk-PKZGXRU2.js.map → chunk-IC2SDW6U.js.map} +0 -0
- /package/dist/{chunk-LYQULSK4.js.map → chunk-INVP4WLX.js.map} +0 -0
- /package/dist/{chunk-LYJJH4D6.js.map → chunk-PPRD3PTW.js.map} +0 -0
- /package/dist/{chunk-MCNQKS6I.js.map → chunk-QDH62H4N.js.map} +0 -0
- /package/dist/{chunk-A5NHAHV6.js.map → chunk-TFSRPBVT.js.map} +0 -0
- /package/dist/{chunk-TXFGG47A.js.map → chunk-WJAMBSMW.js.map} +0 -0
- /package/dist/{chunk-AVAZ6BD6.js.map → chunk-XI2BAIKJ.js.map} +0 -0
- /package/dist/{chunk-Z7QCNCBN.js.map → chunk-XWAT6ZP5.js.map} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createSseFrameDecoder } from '../decode';
|
|
3
|
+
import { chatProgressLabel, chatProgressOf } from '../progress';
|
|
4
|
+
|
|
5
|
+
const frame = (o: unknown) => new TextEncoder().encode(`${JSON.stringify(o)}\0`);
|
|
6
|
+
|
|
7
|
+
describe('chat progress: the stage a turn reports before its first token', () => {
|
|
8
|
+
it('a status frame with a stage decodes to a status event carrying it', () => {
|
|
9
|
+
const d = createSseFrameDecoder();
|
|
10
|
+
expect(d.push(frame({ status: 'thinking', stage: 'searching', count: 28 }))).toEqual([
|
|
11
|
+
{ type: 'status', phase: 'thinking', progress: { stage: 'searching', count: 28 } },
|
|
12
|
+
]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('a plain status frame, and one whose stage this client does not know, is a plain "thinking"', () => {
|
|
16
|
+
const d = createSseFrameDecoder();
|
|
17
|
+
expect(d.push(frame({ status: 'thinking' }))).toEqual([{ type: 'status', phase: 'thinking' }]);
|
|
18
|
+
expect(d.push(frame({ status: 'thinking', stage: 'a-stage-from-the-future' }))).toEqual([
|
|
19
|
+
{ type: 'status', phase: 'thinking' },
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('keeps only a real count', () => {
|
|
24
|
+
expect(chatProgressOf({ stage: 'reading', count: 0 })).toEqual({ stage: 'reading' });
|
|
25
|
+
expect(chatProgressOf({ stage: 'reading', count: '12' })).toEqual({ stage: 'reading' });
|
|
26
|
+
expect(chatProgressOf({ stage: 'reading', count: 12.7 })).toEqual({ stage: 'reading', count: 12 });
|
|
27
|
+
expect(chatProgressOf({ stage: 'nope' })).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('words each stage, specific when a count is known', () => {
|
|
31
|
+
expect(chatProgressLabel({ stage: 'understanding' })).toBe('Understanding your question');
|
|
32
|
+
expect(chatProgressLabel({ stage: 'searching', count: 28 })).toBe('Searching 28 sources');
|
|
33
|
+
expect(chatProgressLabel({ stage: 'searching', count: 1 })).toBe('Searching 1 source');
|
|
34
|
+
expect(chatProgressLabel({ stage: 'searching' })).toBe('Searching');
|
|
35
|
+
expect(chatProgressLabel({ stage: 'searching_again' })).toBe('Searching more broadly');
|
|
36
|
+
expect(chatProgressLabel({ stage: 'reading', count: 43 })).toBe('Reading 43 results');
|
|
37
|
+
expect(chatProgressLabel({ stage: 'reading' })).toBe('Reading the results');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -17,6 +17,7 @@ import type { AskOptionData, ChatSource } from '../components/chat/types/message
|
|
|
17
17
|
// The wire-frame shapes these events carry through are defined ONCE in
|
|
18
18
|
// `./frames.ts` — reuse them here rather than restating their fields.
|
|
19
19
|
import type { ApprovalRequestField, DecisionResolvedFrame, UsageTelemetry } from './frames';
|
|
20
|
+
import type { ChatProgress } from './progress';
|
|
20
21
|
|
|
21
22
|
/** Optional envelope on every event. `seq` carries the transport's
|
|
22
23
|
* stream sequence (JetStream `streamSeq` on NATS; unused on SSE). */
|
|
@@ -72,6 +73,8 @@ export interface AskEvent extends ChatStreamEventBase {
|
|
|
72
73
|
export interface StatusEvent extends ChatStreamEventBase {
|
|
73
74
|
type: 'status';
|
|
74
75
|
phase: 'thinking';
|
|
76
|
+
/** What the turn is doing right now, when the server says (`./progress`). */
|
|
77
|
+
progress?: ChatProgress;
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/** NATS tool execution progress (EXECUTING_TOOL / EXECUTED_TOOL). */
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* Server-safe: no React, no browser APIs beyond TextEncoder/TextDecoder.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import type { ChatProgressStage } from './progress';
|
|
22
|
+
|
|
21
23
|
// =============================================================================
|
|
22
24
|
// Sentinel constants
|
|
23
25
|
// =============================================================================
|
|
@@ -82,6 +84,11 @@ export interface RoutedAnswerBreakdown {
|
|
|
82
84
|
* within ~200ms, before any upstream byte arrives. */
|
|
83
85
|
export interface StatusThinkingFrame {
|
|
84
86
|
status: 'thinking';
|
|
87
|
+
/** What the turn is doing right now (`./progress`): a fixed vocabulary, shown
|
|
88
|
+
* as one line while the user waits. May be sent again as the stage moves. */
|
|
89
|
+
stage?: ChatProgressStage;
|
|
90
|
+
/** How many of the thing the stage works on (sources searched, results read). */
|
|
91
|
+
count?: number;
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
/** Per-turn metadata frame. The emitter sends `options.metadata`
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
export * from './frames';
|
|
13
13
|
export * from './events';
|
|
14
|
+
// The stages a turn reports before its first answer token, and their copy.
|
|
15
|
+
export * from './progress';
|
|
14
16
|
export * from './encode';
|
|
15
17
|
export * from './decode';
|
|
16
18
|
export * from './nats-decoder';
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { ChatStreamEvent } from './events';
|
|
13
|
+
import { chatProgressOf } from './progress';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Escape `<` so markdown renderers that pass HTML through (rehypeRaw)
|
|
@@ -50,7 +51,9 @@ export function frameNum(value: unknown): number | undefined {
|
|
|
50
51
|
*/
|
|
51
52
|
export function mapLeadingFrame(meta: Record<string, unknown>, out: ChatStreamEvent[]): void {
|
|
52
53
|
if (meta.status === 'thinking') {
|
|
53
|
-
|
|
54
|
+
// The frame may name the stage the turn is in; an unknown stage is a plain "thinking".
|
|
55
|
+
const progress = chatProgressOf(meta);
|
|
56
|
+
out.push(progress ? { type: 'status', phase: 'thinking', progress } : { type: 'status', phase: 'thinking' });
|
|
54
57
|
} else if (meta.kind === 'thinking-delta' && typeof meta.text === 'string') {
|
|
55
58
|
// Wire is ALREADY delta — emit verbatim, append-only contract.
|
|
56
59
|
out.push({ type: 'thinking-delta', text: meta.text });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a turn is doing before its first answer token: the named stages a server
|
|
3
|
+
* reports while it works, and the line a client shows for each.
|
|
4
|
+
*
|
|
5
|
+
* A retrieval chat spends seconds before any text exists (reading the question,
|
|
6
|
+
* searching, reading what it found). A generic spinner for that whole time says
|
|
7
|
+
* nothing; a line naming the real step ("Searching 28 sources") does, and people
|
|
8
|
+
* wait more willingly for it. The stage is a FIXED vocabulary on the wire (never
|
|
9
|
+
* model text, a rewritten query or a source name), so it is safe on a public
|
|
10
|
+
* chat and the wording stays the client's: `chatProgressLabel` is the one place
|
|
11
|
+
* the copy lives.
|
|
12
|
+
*
|
|
13
|
+
* Wire: the existing `{ status: 'thinking' }` leading frame, with an optional
|
|
14
|
+
* `stage` and `count`. A client that predates the stage reads the frame exactly
|
|
15
|
+
* as before; a client that knows it shows the line. A stage it does not know is
|
|
16
|
+
* dropped (the frame is still a plain "thinking").
|
|
17
|
+
*
|
|
18
|
+
* Server-safe: no React, no browser APIs.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const CHAT_PROGRESS_STAGES = ['understanding', 'searching', 'searching_again', 'reading'] as const;
|
|
22
|
+
|
|
23
|
+
export type ChatProgressStage = (typeof CHAT_PROGRESS_STAGES)[number];
|
|
24
|
+
|
|
25
|
+
export interface ChatProgress {
|
|
26
|
+
stage: ChatProgressStage;
|
|
27
|
+
/** How many of the thing the stage works on: sources searched, results read. */
|
|
28
|
+
count?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isChatProgressStage(value: unknown): value is ChatProgressStage {
|
|
32
|
+
return typeof value === 'string' && (CHAT_PROGRESS_STAGES as readonly string[]).includes(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A parsed status frame's progress, or null when it carries no stage this client knows. */
|
|
36
|
+
export function chatProgressOf(frame: { stage?: unknown; count?: unknown }): ChatProgress | null {
|
|
37
|
+
if (!isChatProgressStage(frame.stage)) return null;
|
|
38
|
+
const count =
|
|
39
|
+
typeof frame.count === 'number' && Number.isFinite(frame.count) && frame.count > 0
|
|
40
|
+
? Math.floor(frame.count)
|
|
41
|
+
: undefined;
|
|
42
|
+
return count === undefined ? { stage: frame.stage } : { stage: frame.stage, count };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const PROGRESS_LABEL: Record<ChatProgressStage, (count: number | undefined) => string> = {
|
|
46
|
+
understanding: () => 'Understanding your question',
|
|
47
|
+
searching: count => (count ? `Searching ${count} ${count === 1 ? 'source' : 'sources'}` : 'Searching'),
|
|
48
|
+
searching_again: () => 'Searching more broadly',
|
|
49
|
+
reading: count => (count ? `Reading ${count} ${count === 1 ? 'result' : 'results'}` : 'Reading the results'),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** The one line shown for a stage. Specific when the server gave a real count, never an invented one. */
|
|
53
|
+
export function chatProgressLabel(progress: ChatProgress): string {
|
|
54
|
+
return PROGRESS_LABEL[progress.stage](progress.count);
|
|
55
|
+
}
|
|
@@ -122,6 +122,7 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
122
122
|
dialogId,
|
|
123
123
|
isLoading = false,
|
|
124
124
|
isTyping = false,
|
|
125
|
+
typingMessage,
|
|
125
126
|
autoScroll = true,
|
|
126
127
|
overscrollContain = true,
|
|
127
128
|
pinBottom = false,
|
|
@@ -1080,7 +1081,15 @@ const ChatMessageList = forwardRef<HTMLDivElement, ChatMessageListProps>(
|
|
|
1080
1081
|
aria-live="polite"
|
|
1081
1082
|
>
|
|
1082
1083
|
<DotsLoaderIcon className="h-6 w-6" />
|
|
1083
|
-
|
|
1084
|
+
{/* What the turn is actually doing, when the host knows; the
|
|
1085
|
+
cycling phrase when it does not. One line, updated in place. */}
|
|
1086
|
+
{typingMessage ? (
|
|
1087
|
+
<span className="text-h6" aria-atomic="true">
|
|
1088
|
+
{typingMessage}
|
|
1089
|
+
</span>
|
|
1090
|
+
) : (
|
|
1091
|
+
<CyclingPhrase words={STREAMING_WORDS} className="text-h6" />
|
|
1092
|
+
)}
|
|
1084
1093
|
</div>
|
|
1085
1094
|
)}
|
|
1086
1095
|
|
|
@@ -37,6 +37,7 @@ import { usePreventScroll } from '@react-aria/overlays';
|
|
|
37
37
|
import { isIOS } from '@react-aria/utils';
|
|
38
38
|
import { MessageSquare } from 'lucide-react';
|
|
39
39
|
import React, { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
40
|
+
import { chatProgressLabel } from '../../chat-protocol/progress';
|
|
40
41
|
import { useRequiredChatRuntime } from '../../contexts/chat-runtime-context';
|
|
41
42
|
import { useRouter } from '../../embed-shims/next-navigation';
|
|
42
43
|
import { useIsHydrated } from '../../hooks/ui/use-is-hydrated';
|
|
@@ -1219,6 +1220,7 @@ function EmbeddableChatInner({
|
|
|
1219
1220
|
const {
|
|
1220
1221
|
messages: rawMessages,
|
|
1221
1222
|
isLoading: chatLoading,
|
|
1223
|
+
streamingProgress,
|
|
1222
1224
|
sendMessage: sendMessageRaw,
|
|
1223
1225
|
discussRef,
|
|
1224
1226
|
stopMessage,
|
|
@@ -2522,6 +2524,9 @@ function EmbeddableChatInner({
|
|
|
2522
2524
|
<ChatMessageList
|
|
2523
2525
|
messages={messages}
|
|
2524
2526
|
isTyping={chatLoading}
|
|
2527
|
+
// The stage the turn reports while the user waits
|
|
2528
|
+
// ("Searching 28 sources"); the generic phrase otherwise.
|
|
2529
|
+
typingMessage={streamingProgress ? chatProgressLabel(streamingProgress) : undefined}
|
|
2525
2530
|
// Sticky footer for approvals the host lifted out of the
|
|
2526
2531
|
// thread — see the prop's docblock.
|
|
2527
2532
|
pendingApprovals={pendingApprovals}
|
|
@@ -859,6 +859,8 @@ export function useSseChatAdapter(
|
|
|
859
859
|
stopMessage,
|
|
860
860
|
clearMessages,
|
|
861
861
|
streamingPhase,
|
|
862
|
+
/** The stage the pending turn reports before its first token, or null. */
|
|
863
|
+
streamingProgress: state.streamingProgress,
|
|
862
864
|
/** True while the mount-time rebuild from the server transcript runs. */
|
|
863
865
|
isHydratingHistory,
|
|
864
866
|
/** Provider key for the lib's `<ModelDisplay>` icon. */
|
|
@@ -214,6 +214,7 @@ export function useUnifiedChat(options: UseUnifiedChatOptions): UnifiedChatState
|
|
|
214
214
|
messages: activeState.messages,
|
|
215
215
|
isLoading: activeState.isLoading,
|
|
216
216
|
streamingPhase: activeState.streamingPhase,
|
|
217
|
+
streamingProgress: activeState.streamingProgress ?? null,
|
|
217
218
|
sendMessage,
|
|
218
219
|
stopMessage,
|
|
219
220
|
clearMessages,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stage a pending turn reports ("searching 28 sources") lives in reducer
|
|
3
|
+
* state only while the turn is still thinking: it is replaced as the stage
|
|
4
|
+
* moves, kept through a plain status frame, gone once text streams, and never
|
|
5
|
+
* carried into the next turn.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { createChatStreamReducer } from '../chat-stream-reducer';
|
|
10
|
+
|
|
11
|
+
describe('SSE kernel: the stage a pending turn reports', () => {
|
|
12
|
+
it('follows the stage, keeps it through a plain status frame, and drops it when text starts', () => {
|
|
13
|
+
const r = createChatStreamReducer({ transport: 'sse' });
|
|
14
|
+
r.beginSseSend({ text: 'what is the price', assistantName: 'Mingo AI' });
|
|
15
|
+
expect(r.state.streamingProgress).toBeNull();
|
|
16
|
+
|
|
17
|
+
r.apply({ type: 'status', phase: 'thinking', progress: { stage: 'understanding' } });
|
|
18
|
+
expect(r.state.streamingProgress).toEqual({ stage: 'understanding' });
|
|
19
|
+
|
|
20
|
+
r.apply({ type: 'status', phase: 'thinking', progress: { stage: 'searching', count: 28 } });
|
|
21
|
+
expect(r.state.streamingProgress).toEqual({ stage: 'searching', count: 28 });
|
|
22
|
+
|
|
23
|
+
// The model stream's own first frame carries no stage: the last one stands.
|
|
24
|
+
r.apply({ type: 'status', phase: 'thinking' });
|
|
25
|
+
expect(r.state.streamingProgress).toEqual({ stage: 'searching', count: 28 });
|
|
26
|
+
|
|
27
|
+
r.apply({ type: 'turn-start' });
|
|
28
|
+
expect(r.state.streamingPhase).toBe('streaming');
|
|
29
|
+
expect(r.state.streamingProgress).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('a new turn starts with no stage', () => {
|
|
33
|
+
const r = createChatStreamReducer({ transport: 'sse' });
|
|
34
|
+
r.beginSseSend({ text: 'first', assistantName: 'Mingo AI' });
|
|
35
|
+
r.apply({ type: 'status', phase: 'thinking', progress: { stage: 'reading', count: 12 } });
|
|
36
|
+
r.beginSseSend({ text: 'second', assistantName: 'Mingo AI' });
|
|
37
|
+
expect(r.state.streamingPhase).toBe('thinking');
|
|
38
|
+
expect(r.state.streamingProgress).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -199,6 +199,7 @@ export interface EvictedReducerState {
|
|
|
199
199
|
const EMPTY_STATE: ChatReducerState = Object.freeze({
|
|
200
200
|
messages: Object.freeze([]) as unknown as ChatReducerState['messages'],
|
|
201
201
|
streamingPhase: 'idle',
|
|
202
|
+
streamingProgress: null,
|
|
202
203
|
turnMeta: Object.freeze({
|
|
203
204
|
meta: new Map(),
|
|
204
205
|
sources: new Map(),
|
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
type ParticipantEvent,
|
|
61
61
|
type UsageEvent,
|
|
62
62
|
} from '../../../chat-protocol/events';
|
|
63
|
+
import type { ChatProgress } from '../../../chat-protocol/progress';
|
|
63
64
|
import { mergeSourceMetadata, type SourceMetadata } from '../../../chat-protocol/source-metadata';
|
|
64
65
|
import type {
|
|
65
66
|
ApprovalBatchSegment,
|
|
@@ -154,6 +155,9 @@ export interface ChatTurnMetaState {
|
|
|
154
155
|
export interface ChatReducerState {
|
|
155
156
|
messages: UnifiedChatMessage[];
|
|
156
157
|
streamingPhase: StreamingPhase;
|
|
158
|
+
/** What the pending turn is doing, while it is still thinking and the server
|
|
159
|
+
* has said (`chat-protocol/progress`). Null once text streams or the turn ends. */
|
|
160
|
+
streamingProgress: ChatProgress | null;
|
|
157
161
|
turnMeta: ChatTurnMetaState;
|
|
158
162
|
dialogTokenUsage?: DialogTokenUsage | null;
|
|
159
163
|
liveModel?: {
|
|
@@ -529,6 +533,7 @@ export function createChatStreamReducer(options: ChatStreamReducerOptions = {}):
|
|
|
529
533
|
// ── Mutable internals ──────────────────────────────────────────────────
|
|
530
534
|
let messages: UnifiedChatMessage[] = [];
|
|
531
535
|
let streamingPhase: StreamingPhase = 'idle';
|
|
536
|
+
let streamingProgress: ChatProgress | null = null;
|
|
532
537
|
let dialogTokenUsage: DialogTokenUsage | null = null;
|
|
533
538
|
let liveModel: ChatReducerState['liveModel'] = null;
|
|
534
539
|
let approvalStatuses: Record<string, ChatApprovalStatus> = {
|
|
@@ -688,6 +693,8 @@ export function createChatStreamReducer(options: ChatStreamReducerOptions = {}):
|
|
|
688
693
|
stateCache = {
|
|
689
694
|
messages,
|
|
690
695
|
streamingPhase,
|
|
696
|
+
// A stage describes the wait before the first token only.
|
|
697
|
+
streamingProgress: streamingPhase === 'thinking' ? streamingProgress : null,
|
|
691
698
|
turnMeta: { meta: metaMap, sources: sourcesMap, sendCount },
|
|
692
699
|
dialogTokenUsage,
|
|
693
700
|
liveModel,
|
|
@@ -1581,6 +1588,10 @@ export function createChatStreamReducer(options: ChatStreamReducerOptions = {}):
|
|
|
1581
1588
|
const sendIdx = sendCount - 1;
|
|
1582
1589
|
switch (event.type) {
|
|
1583
1590
|
case 'status':
|
|
1591
|
+
if (event.progress) {
|
|
1592
|
+
streamingProgress = event.progress;
|
|
1593
|
+
invalidate();
|
|
1594
|
+
}
|
|
1584
1595
|
setPhaseInternal('thinking');
|
|
1585
1596
|
break;
|
|
1586
1597
|
case 'thinking-delta':
|
|
@@ -1901,6 +1912,7 @@ export function createChatStreamReducer(options: ChatStreamReducerOptions = {}):
|
|
|
1901
1912
|
{ id: nextId('assistant'), role: 'assistant', content: '', segments: [] },
|
|
1902
1913
|
];
|
|
1903
1914
|
streamingPhase = 'thinking';
|
|
1915
|
+
streamingProgress = null;
|
|
1904
1916
|
invalidate();
|
|
1905
1917
|
},
|
|
1906
1918
|
clearThread() {
|
|
@@ -1948,6 +1960,7 @@ export function createChatStreamReducer(options: ChatStreamReducerOptions = {}):
|
|
|
1948
1960
|
sendCount += 1;
|
|
1949
1961
|
sseCurrentText = '';
|
|
1950
1962
|
streamingPhase = 'thinking';
|
|
1963
|
+
streamingProgress = null;
|
|
1951
1964
|
invalidate();
|
|
1952
1965
|
},
|
|
1953
1966
|
endSseTurn() {
|
|
@@ -255,6 +255,8 @@ export interface ChatMessageListProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
255
255
|
dialogId?: string;
|
|
256
256
|
isLoading?: boolean;
|
|
257
257
|
isTyping?: boolean;
|
|
258
|
+
/** The line shown beside the pending-turn loader: what the turn is doing right
|
|
259
|
+
* now ("Searching 28 sources"). Omitted, the loader cycles its generic phrases. */
|
|
258
260
|
typingMessage?: string;
|
|
259
261
|
smoothScroll?: boolean;
|
|
260
262
|
autoScroll?: boolean;
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* `sources`). In the off-mode they're null/undefined.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import type { ChatProgress } from '../../../chat-protocol/progress';
|
|
19
20
|
import type { ChatRef } from '../chat-ref.types';
|
|
20
21
|
import type { ChatAttachment } from '../utils/chat-attachment-markdown';
|
|
21
22
|
import type { AuthorType } from './chat.types';
|
|
@@ -335,6 +336,11 @@ export interface UnifiedChatState {
|
|
|
335
336
|
/** Granular phase for the "Thinking..."/"Streaming..." status row above input. */
|
|
336
337
|
streamingPhase: StreamingPhase;
|
|
337
338
|
|
|
339
|
+
/** What the pending turn is doing before its first token ("searching 28
|
|
340
|
+
* sources"), when the transport reports it. Optional: a transport with no
|
|
341
|
+
* stages leaves it out and the status row keeps its generic phrase. */
|
|
342
|
+
streamingProgress?: ChatProgress | null;
|
|
343
|
+
|
|
338
344
|
/** True while the adapter is rebuilding the message list from the
|
|
339
345
|
* server-side transcript store (SSE/Guide mount-time hydration). Optional —
|
|
340
346
|
* transports without server hydration (NATS manages its own dialog
|