@jini-ai/chat 0.7.1 → 0.7.3-next.1
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/CHANGELOG.md +2 -2
- package/README.md +3 -3
- package/dist/contracts/chat-bubble-style.d.ts +1 -1
- package/dist/contracts/chat-bubble-style.js +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +125 -0
- package/dist/core/ag-ui/event-projection.js +275 -0
- package/dist/core/ag-ui/event-reduction.d.ts +39 -0
- package/dist/core/ag-ui/event-reduction.js +99 -0
- package/dist/core/ag-ui/run-input.d.ts +53 -0
- package/dist/core/ag-ui/run-input.js +87 -0
- package/dist/core/agentic/chat-capabilities.d.ts +1 -1
- package/dist/core/agentic/index.d.ts +2 -4
- package/dist/core/agentic/index.js +2 -3
- package/dist/core/agents-port.d.ts +50 -0
- package/dist/core/agents-port.js +2 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +16 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +24 -0
- package/dist/core/assistant-client/ag-ui-transport.d.ts +15 -1
- package/dist/core/assistant-client/ag-ui-transport.js +167 -145
- package/dist/core/assistant-client/attachment-liveness.js +13 -11
- package/dist/core/assistant-client/durable-run-subscription.d.ts +3 -2
- package/dist/core/assistant-client/durable-run-subscription.js +6 -5
- package/dist/core/assistant-client/messages.d.ts +7 -4
- package/dist/core/assistant-client/messages.js +5 -4
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +4 -4
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-port.d.ts +15 -0
- package/dist/core/page-port.js +2 -0
- package/dist/core/run-activity.js +1 -1
- package/dist/core/run-events/entry.js +1 -0
- package/dist/core/user-text-redaction.d.ts +1 -3
- package/dist/core/user-text-redaction.js +3 -61
- package/dist/embed-widget/browser/agent-inventory.d.ts +37 -0
- package/dist/embed-widget/browser/agent-inventory.js +36 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +2 -2
- package/dist/embed-widget/browser/frontend-session-bridge.js +17 -14
- package/dist/embed-widget/react/dialog.hooks.d.ts +16 -0
- package/dist/embed-widget/react/dialog.hooks.js +15 -0
- package/dist/embed-widget/react/embed.d.ts +7 -2
- package/dist/embed-widget/react/embed.js +6 -16
- package/dist/embed-widget/react/header.d.ts +4 -1
- package/dist/embed-widget/react/header.js +2 -2
- package/dist/embed-widget/vanilla/state.js +2 -2
- package/dist/embed-widget/vanilla/style.css +4 -4
- package/dist/react/components/A2uiSurfaceCard.d.ts +18 -4
- package/dist/react/components/A2uiSurfaceCard.hooks.d.ts +36 -0
- package/dist/react/components/A2uiSurfaceCard.hooks.js +174 -0
- package/dist/react/components/A2uiSurfaceCard.js +14 -227
- package/dist/react/components/A2uiSurfaceCard.rules.d.ts +14 -0
- package/dist/react/components/A2uiSurfaceCard.rules.js +24 -0
- package/dist/react/components/AttachmentPreviewModal.d.ts +21 -1
- package/dist/react/components/AttachmentPreviewModal.hooks.js +1 -3
- package/dist/react/components/AttachmentPreviewModal.js +11 -9
- package/dist/react/components/AttachmentTray.d.ts +11 -1
- package/dist/react/components/AttachmentTray.js +12 -8
- package/dist/react/components/ChatFab.d.ts +10 -1
- package/dist/react/components/ChatFab.js +2 -2
- package/dist/react/components/ChatSettingsDialog.d.ts +4 -3
- package/dist/react/components/ChatSettingsDialog.js +9 -6
- package/dist/react/components/ChatSettingsSegmented.d.ts +1 -1
- package/dist/react/components/ChatSettingsSegmented.js +1 -1
- package/dist/react/components/Composer.d.ts +9 -1
- package/dist/react/components/Composer.hooks.d.ts +79 -0
- package/dist/react/components/Composer.hooks.js +336 -0
- package/dist/react/components/Composer.js +40 -341
- package/dist/react/components/ComposerDiscovery.js +1 -1
- package/dist/react/components/ConversationList.d.ts +34 -1
- package/dist/react/components/ConversationList.hooks.d.ts +37 -0
- package/dist/react/components/ConversationList.hooks.js +177 -1
- package/dist/react/components/ConversationList.js +7 -174
- package/dist/react/components/ConversationTitleEditor.d.ts +17 -2
- package/dist/react/components/ConversationTitleEditor.hooks.d.ts +15 -0
- package/dist/react/components/ConversationTitleEditor.hooks.js +36 -0
- package/dist/react/components/ConversationTitleEditor.js +11 -34
- package/dist/react/components/CopyMessageButton.d.ts +6 -1
- package/dist/react/components/CopyMessageButton.js +4 -4
- package/dist/react/components/ExtEventErrorBoundary.d.ts +2 -0
- package/dist/react/components/ExtEventErrorBoundary.js +5 -3
- package/dist/react/components/FolderChips.d.ts +11 -1
- package/dist/react/components/FolderChips.hooks.d.ts +12 -0
- package/dist/react/components/FolderChips.hooks.js +10 -0
- package/dist/react/components/FolderChips.js +9 -9
- package/dist/react/components/Markdown.js +7 -5
- package/dist/react/components/McpUiSurfaceCard.d.ts +29 -5
- package/dist/react/components/McpUiSurfaceCard.js +29 -16
- package/dist/react/components/MessageList.d.ts +10 -1
- package/dist/react/components/MessageList.hooks.js +4 -2
- package/dist/react/components/MessageList.js +12 -8
- package/dist/react/components/MessageRow.d.ts +46 -2
- package/dist/react/components/MessageRow.hooks.d.ts +60 -0
- package/dist/react/components/MessageRow.hooks.js +94 -0
- package/dist/react/components/MessageRow.js +53 -113
- package/dist/react/components/MidRunUserMessage.d.ts +6 -1
- package/dist/react/components/MidRunUserMessage.js +5 -5
- package/dist/react/components/NextStepActions.d.ts +3 -1
- package/dist/react/components/NextStepActions.js +3 -3
- package/dist/react/components/QuestionForm.answers.hooks.d.ts +26 -0
- package/dist/react/components/QuestionForm.answers.hooks.js +89 -0
- package/dist/react/components/QuestionForm.d.ts +6 -0
- package/dist/react/components/QuestionForm.js +23 -261
- package/dist/react/components/QuestionForm.values.d.ts +22 -0
- package/dist/react/components/QuestionForm.values.js +58 -0
- package/dist/react/components/QuestionFormField.d.ts +17 -0
- package/dist/react/components/QuestionFormField.js +114 -0
- package/dist/react/components/QuestionsPanel.d.ts +3 -1
- package/dist/react/components/QuestionsPanel.js +7 -3
- package/dist/react/components/SentAttachment.d.ts +11 -2
- package/dist/react/components/SentAttachment.hooks.d.ts +1 -1
- package/dist/react/components/SentAttachment.hooks.js +6 -5
- package/dist/react/components/SentAttachment.js +5 -3
- package/dist/react/components/TodoCard.d.ts +3 -1
- package/dist/react/components/TodoCard.js +9 -4
- package/dist/react/components/ToolCallGroup.d.ts +11 -1
- package/dist/react/components/ToolCallGroup.js +10 -4
- package/dist/react/components/ToolCard.d.ts +6 -1
- package/dist/react/components/ToolCard.js +79 -69
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-question-input.js +3 -3
- package/dist/react/components/mcp-ui-surface-state.d.ts +1 -1
- package/dist/react/features/chat-pane/agent-tools.d.ts +1 -1
- package/dist/react/features/chat-pane/antigravity/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/antigravity/model-options.js +2 -0
- package/dist/react/features/chat-pane/claude/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/claude/model-options.js +2 -0
- package/dist/react/features/chat-pane/codex/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/codex/model-options.js +2 -0
- package/dist/react/features/chat-pane/components/AgentPluginUsage.d.ts +4 -1
- package/dist/react/features/chat-pane/components/AgentPluginUsage.js +2 -2
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.d.ts +10 -6
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.js +18 -132
- package/dist/react/features/chat-pane/components/ChatPane.d.ts +24 -2
- package/dist/react/features/chat-pane/components/ChatPane.js +45 -297
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.d.ts +33 -0
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.js +119 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.d.ts +42 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.js +54 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.d.ts +27 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.js +91 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.d.ts +6 -1
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +20 -19
- package/dist/react/features/chat-pane/components/RuntimePickerSections.d.ts +62 -0
- package/dist/react/features/chat-pane/components/RuntimePickerSections.js +122 -0
- package/dist/react/features/chat-pane/create-mcp-ui-tool-caller.d.ts +1 -1
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.d.ts +5 -3
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.js +78 -26
- package/dist/react/features/chat-pane/hooks/useChatPaneAgentControl.hooks.js +6 -6
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.d.ts +5 -1
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.js +7 -7
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.d.ts +7 -0
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.js +5 -0
- package/dist/react/features/chat-pane/model-options.js +7 -4
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +14 -14
- package/dist/react/features/chat-pane/types.d.ts +29 -1
- package/dist/react/hooks/assistant-chats-contracts.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.js +1 -1
- package/dist/react/hooks/fab-position.js +16 -18
- package/dist/react/hooks/useConversation.d.ts +6 -1
- package/dist/react/hooks/useConversation.js +11 -10
- package/dist/react/hooks/useRunStream.d.ts +3 -0
- package/dist/react/hooks/useRunStream.js +12 -12
- package/dist/react/hooks/useSurfaceRecovery.d.ts +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +2 -2
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -3
- package/dist/react/styles/chat-settings.css +9 -9
- package/dist/react/surfaces.d.ts +91 -0
- package/dist/react/surfaces.js +28 -0
- package/dist/server/durable-runs/recover.d.ts +4 -3
- package/dist/server/durable-runs/recover.js +4 -3
- package/dist/store/legacy/sqlite/conversations.d.ts +1 -2
- package/dist/store/legacy/sqlite/conversations.js +1 -1
- package/dist/store/legacy/sqlite/messages.d.ts +2 -3
- package/dist/store/legacy/sqlite/messages.js +6 -6
- package/dist/store/pglite/index.d.ts +7 -7
- package/dist/store/pglite/index.js +1 -1
- package/dist/store/ports.d.ts +5 -2
- package/dist/store/postgres/index.d.ts +7 -7
- package/dist/store/postgres/index.js +1 -1
- package/dist/store/runtime/chat-expiry-sweep.js +2 -4
- package/dist/store/runtime/chat-history-store.js +2 -3
- package/dist/store/runtime/durable-run-store.js +16 -2
- package/dist/store/runtime/history-tools.js +33 -11
- package/dist/store/runtime/kernel.d.ts +3 -2
- package/dist/store/runtime/run-ledger.js +2 -2
- package/dist/store/sql/boundary.d.ts +5 -5
- package/dist/store/sql/maintenance.d.ts +3 -2
- package/dist/store/sql/store.d.ts +16 -8
- package/dist/store/sql/store.js +31 -14
- package/dist/store/sqlite/index.d.ts +11 -12
- package/dist/store/sqlite/index.js +5 -5
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/package.json +46 -24
- package/dist/core/ag-ui/entry.d.ts +0 -84
- package/dist/core/ag-ui/entry.js +0 -225
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, {} from 'react';
|
|
3
|
+
import { splitOnQuestionForms } from '../../core/index.js';
|
|
4
|
+
import { retriedToolRowIds } from '../tool-call-display.js';
|
|
5
|
+
import { usageLineMeetsActions } from './MessageRow.usage.js';
|
|
6
|
+
import { MidRunUserMessage, MID_RUN_USER_MESSAGE_EXT_EVENT_NAME } from './MidRunUserMessage.js';
|
|
7
|
+
import { ExtEventErrorBoundary } from './ExtEventErrorBoundary.js';
|
|
8
|
+
import { Markdown } from './Markdown.js';
|
|
9
|
+
import { ToolCard } from './ToolCard.js';
|
|
10
|
+
import { QuestionForm } from './QuestionForm.js';
|
|
11
|
+
import { ToolCallGroup } from './ToolCallGroup.js';
|
|
12
|
+
/** Preserve optional render-prop presence for custom extension renderers. */
|
|
13
|
+
function answerRenderProps({ answeredCards, slot, answerText }, _options = {}) {
|
|
14
|
+
return { ...(answeredCards.isRecorded(slot) ? { answerRecorded: true } : {}),
|
|
15
|
+
...(answerText === undefined ? {} : { answerText }) };
|
|
16
|
+
}
|
|
17
|
+
/** Build the assistant transcript renderers with the current row's state and host callbacks. */
|
|
18
|
+
export function useAssistantMessageRenderers({ message, rows, runStreaming, runSucceeded, projectFileNames, onRequestOpenFile, toolCallDisplay, registry, answeredCards, runInProgress, awaitingAnswer, questionFormInteractive, questionFormSubmittedAnswers, onQuestionFormSubmit, usage, showUsageLine, showUsageTotal, lastFinishedReply, extGroups, footerUsage, terminalNotice, pending, runSending, sendingLabel, visibleContent, flatTools, flatExtGroups, UsageSummary, ThinkingBlock, AssistantMessageFooter }, { report } = {}) {
|
|
19
|
+
const retriedRows = retriedToolRowIds({ rows });
|
|
20
|
+
const renderToolCard = (row) => (_jsx(ToolCard, { report: report, retried: retriedRows.has(row.id), use: row.use, result: row.result, runStreaming: runStreaming, runSucceeded: runSucceeded, ...(projectFileNames !== undefined ? { projectFileNames } : {}), ...(onRequestOpenFile !== undefined ? { onRequestOpenFile } : {}) }, row.id));
|
|
21
|
+
// Hidden mode reuses the same disclosure and card renderer for unrecovered failures.
|
|
22
|
+
const renderTools = (rows, key) => (toolCallDisplay !== 'show'
|
|
23
|
+
? _jsx(ToolCallGroup, { rows: rows, renderRow: renderToolCard, failureOnly: toolCallDisplay === 'hidden' }, key)
|
|
24
|
+
: _jsx("div", { className: "jini-message-tools", children: rows.map(renderToolCard) }, key));
|
|
25
|
+
const renderExtGroup = (group) => {
|
|
26
|
+
const transcriptRow = group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME;
|
|
27
|
+
const renderer = registry.get({ name: group.name });
|
|
28
|
+
if (!renderer && group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME)
|
|
29
|
+
return _jsx(MidRunUserMessage, { events: group.events, runStreaming: runInProgress, transcriptRow: true }, group.slot);
|
|
30
|
+
if (!renderer)
|
|
31
|
+
return null;
|
|
32
|
+
const answerText = answeredCards.answerText(group.slot);
|
|
33
|
+
const node = renderer({
|
|
34
|
+
name: group.name,
|
|
35
|
+
events: group.events,
|
|
36
|
+
runStreaming: group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME ? runInProgress : answeredCards.runStreaming,
|
|
37
|
+
...(group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME ? { transcriptRow: true } : {}),
|
|
38
|
+
runSucceeded,
|
|
39
|
+
awaitingAnswer,
|
|
40
|
+
runId: message.runId,
|
|
41
|
+
...(group.call === undefined ? {} : { call: group.call }),
|
|
42
|
+
answered: answeredCards.isAnswered(group.slot),
|
|
43
|
+
onAnswered: () => answeredCards.markAnswered(group.slot),
|
|
44
|
+
onAnswerText: (text) => answeredCards.markAnswered(group.slot, text),
|
|
45
|
+
...answerRenderProps({ answeredCards, slot: group.slot, answerText }),
|
|
46
|
+
});
|
|
47
|
+
if (!node)
|
|
48
|
+
return null;
|
|
49
|
+
return (
|
|
50
|
+
// `key` includes the event count so a group that failed on an earlier, shorter event list
|
|
51
|
+
// gets a fresh boundary instance (not the still-tripped one) once a new event actually
|
|
52
|
+
// arrives for it, instead of staying tombstoned for the message's whole lifetime.
|
|
53
|
+
_jsx(ExtEventErrorBoundary, { name: group.name, report: report, children: transcriptRow ? node : _jsx("div", { children: node }) }, `${group.slot}:${group.events.length}`));
|
|
54
|
+
};
|
|
55
|
+
const renderTextSegments = (text, keyPrefix) => splitOnQuestionForms({ input: text }).map((segment, i) => {
|
|
56
|
+
if (segment.kind === 'text')
|
|
57
|
+
return segment.text.trim() ? (_jsx("div", { className: "jini-message-content", children: _jsx(Markdown, { children: segment.text }) }, `${keyPrefix}-${i}`)) : null;
|
|
58
|
+
return (_jsx(QuestionForm, { form: segment.form, interactive: questionFormInteractive, ...(questionFormSubmittedAnswers !== undefined ? { submittedAnswers: questionFormSubmittedAnswers } : {}), ...(onQuestionFormSubmit !== undefined ? { onSubmit: onQuestionFormSubmit } : {}) }, `${keyPrefix}-${i}`));
|
|
59
|
+
});
|
|
60
|
+
const renderBlock = (block) => {
|
|
61
|
+
if (block.kind === 'text') {
|
|
62
|
+
return _jsx(React.Fragment, { children: renderTextSegments(block.text, block.key) }, block.key);
|
|
63
|
+
}
|
|
64
|
+
if (block.kind === 'reply-end') {
|
|
65
|
+
const reply = usage.replies[block.index];
|
|
66
|
+
// A trailing input may have no reply: its predecessor's usage belongs above that input.
|
|
67
|
+
if (!reply || !showUsageLine)
|
|
68
|
+
return null;
|
|
69
|
+
return _jsx(UsageSummary, { usage: reply, showTotal: showUsageTotal, ...(block.index === lastFinishedReply ? { message } : {}) }, block.key);
|
|
70
|
+
}
|
|
71
|
+
if (block.kind === 'tools')
|
|
72
|
+
return renderTools(block.rows, block.key);
|
|
73
|
+
if (block.kind === 'thinking')
|
|
74
|
+
return _jsx(ThinkingBlock, { text: block.text }, block.key);
|
|
75
|
+
return renderExtBlock(block);
|
|
76
|
+
};
|
|
77
|
+
// A mid-run bubble is its own transcript row, so it skips the ext-events wrapper and its spacing.
|
|
78
|
+
const renderExtBlock = (block) => {
|
|
79
|
+
const group = extGroups.find((g) => g.slot === block.slot);
|
|
80
|
+
if (!group)
|
|
81
|
+
return null;
|
|
82
|
+
if (group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME)
|
|
83
|
+
return _jsx(React.Fragment, { children: renderExtGroup(group) }, block.key);
|
|
84
|
+
return (_jsx("div", { className: "jini-message-ext-events", children: renderExtGroup(group) }, block.key));
|
|
85
|
+
};
|
|
86
|
+
// The live footer follows the run as transcript sections split; its clock must not remount.
|
|
87
|
+
const renderAssistantSection = ({ section, key, footer }) => (_jsxs("div", { className: usageLineMeetsActions({ footer: footerUsage, terminalNotice, pending, runInProgress }, { showTotal: showUsageTotal })
|
|
88
|
+
? 'jini-message jini-message-assistant jini-message-assistant--usage-actions'
|
|
89
|
+
: 'jini-message jini-message-assistant', "data-message-id": message.id, "data-run-status": message.runStatus, "data-agent-element": `chat-message-${message.id}`, "data-agent-role": "region", "data-agent-label": "A reply from the assistant", children: [message.agentName ? _jsx("div", { className: "jini-message-agent", children: message.agentName }) : null, section
|
|
90
|
+
? section.map(renderBlock)
|
|
91
|
+
: (_jsxs(_Fragment, { children: [renderTextSegments(visibleContent, 'text'), flatTools.map((group) => renderTools(group.rows, group.key)), flatExtGroups.length > 0 ? _jsx("div", { className: "jini-message-ext-events", children: flatExtGroups.map(renderExtGroup) }) : null] })), footer && _jsx(AssistantMessageFooter, { message, usageEvent: footerUsage, showUsageTotal, terminalNotice, pending, runInProgress, runStreaming, runSending, sendingLabel, visibleContent, isAnsweredCard: answeredCards.isAnsweredCard })] }, footer ? message.id : key));
|
|
92
|
+
return { renderBlock, renderExtGroup, renderAssistantSection };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=MessageRow.hooks.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { FolderChips } from './FolderChips.js';
|
|
3
3
|
import { projectAcceptedInputEvents } from '../../core/accepted-input.js';
|
|
4
|
-
import {
|
|
4
|
+
import { MID_RUN_USER_MESSAGE_EXT_EVENT_NAME } from './MidRunUserMessage.js';
|
|
5
5
|
import { useSurfaceAnswerContexts } from './mcp-ui-question-input.js';
|
|
6
6
|
import { terminalMessageNotice, continuingRunNotice } from '../../core/durable-projection.js';
|
|
7
|
-
import { usageEndLabel, usageLayout,
|
|
7
|
+
import { usageEndLabel, usageLayout, useMessageUsage, useUsageSummary } from './MessageRow.usage.js';
|
|
8
8
|
/**
|
|
9
9
|
* @module MessageRow
|
|
10
10
|
*
|
|
@@ -56,23 +56,19 @@ import { usageEndLabel, usageLayout, usageLineMeetsActions, useMessageUsage, use
|
|
|
56
56
|
* chunk stopped arriving.
|
|
57
57
|
*/
|
|
58
58
|
import React, { memo, useMemo } from 'react';
|
|
59
|
-
import { assistantContentFromEvents, isAwaitingAnswer, isTerminalRunStatus,
|
|
59
|
+
import { assistantContentFromEvents, isAwaitingAnswer, isTerminalRunStatus, stripArtifact } from '../../core/index.js';
|
|
60
60
|
import { useToolTimeline } from '../hooks/useToolTimeline.js';
|
|
61
61
|
import { useExtEventGroups } from '../hooks/useExtEventGroups.js';
|
|
62
62
|
import { useRunActivity } from '../hooks/useRunActivity.js';
|
|
63
63
|
import { useAnsweredCards } from '../hooks/useAnsweredCards.js';
|
|
64
64
|
import { interleaveMessageBlocks, splitMidRunBlocks } from '../message-blocks.js';
|
|
65
65
|
import { useT, useExtEventRendererRegistry } from '../hooks/context.js';
|
|
66
|
-
import { ExtEventErrorBoundary } from './ExtEventErrorBoundary.js';
|
|
67
66
|
import { AttachmentPreviewModal } from './AttachmentPreviewModal.js';
|
|
68
67
|
import { SentAttachmentButton } from './SentAttachment.js';
|
|
69
68
|
import { useAttachmentGallery } from './AttachmentGallery.hooks.js';
|
|
70
69
|
import { CopyMessageButton } from './CopyMessageButton.js';
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
import { QuestionForm } from './QuestionForm.js';
|
|
74
|
-
import { ToolCallGroup } from './ToolCallGroup.js';
|
|
75
|
-
import { applyToolCallDisplay, retriedToolRowIds, toolRowsForDisplay } from '../tool-call-display.js';
|
|
70
|
+
import { applyToolCallDisplay, toolRowsForDisplay } from '../tool-call-display.js';
|
|
71
|
+
import { useAssistantMessageRenderers } from './MessageRow.hooks.js';
|
|
76
72
|
/**
|
|
77
73
|
* True while an assistant message is still fully pending — no visible text
|
|
78
74
|
* and no tool rows have arrived yet. Shared by the "Thinking…" placeholder
|
|
@@ -109,13 +105,15 @@ function isPendingWithNoContent(message, visibleContent, toolRowCount) {
|
|
|
109
105
|
function isRunInProgress(runStatus) {
|
|
110
106
|
return runStatus !== undefined && !isTerminalRunStatus({ status: runStatus });
|
|
111
107
|
}
|
|
108
|
+
/** Hooks UsageSummary calls; defaults to the real ones, a test hands in fakes. */
|
|
109
|
+
export const defaultUsageSummaryHooks = { useT, useUsageSummary };
|
|
112
110
|
/** One "Done · 6m 29s · $0.41 · total $2.50" line from reported usage, never estimated (the total is
|
|
113
111
|
* left off when `showTotal` is false). Partial usage stays partial; output tokens are available to
|
|
114
112
|
* assistive technology and in the tooltip. */
|
|
115
|
-
function UsageSummary({ usage, showTotal, message, awaitingAnswer }) {
|
|
116
|
-
const t = useT();
|
|
113
|
+
export function UsageSummary({ usage, showTotal, message, awaitingAnswer, hooks = defaultUsageSummaryHooks }) {
|
|
114
|
+
const t = hooks.useT();
|
|
117
115
|
const label = usageEndLabel({ usage, ...(message === undefined ? {} : { message }), ...(awaitingAnswer === undefined ? {} : { awaitingAnswer }) });
|
|
118
|
-
const { text, title, ariaLabel } = useUsageSummary({ usage }, { showTotal, label });
|
|
116
|
+
const { text, title, ariaLabel } = hooks.useUsageSummary({ usage }, { showTotal, label });
|
|
119
117
|
if (!text)
|
|
120
118
|
return null;
|
|
121
119
|
return (_jsxs("div", { className: "jini-message-usage", title: title, role: "note", "aria-label": ariaLabel, children: [label === 'Done' ? _jsx("span", { className: "jini-message-usage-dot", "aria-hidden": true, children: "\u25CF" }) : null, t(label), " \u00B7 ", text] }));
|
|
@@ -142,15 +140,17 @@ function flatToolGroups({ message, rows, registry, displayBlocks }, { toolCallDi
|
|
|
142
140
|
}
|
|
143
141
|
/** The model's reasoning, folded under a "Thinking" summary so it never crowds the answer. */
|
|
144
142
|
/** A host status belongs to the run that emitted it, regardless of the current picker selection. */
|
|
145
|
-
function RunAccessNotice({ events }) {
|
|
146
|
-
const t =
|
|
143
|
+
function RunAccessNotice({ show, events, useTHook = useT }) {
|
|
144
|
+
const t = useTHook();
|
|
145
|
+
if (!show)
|
|
146
|
+
return null;
|
|
147
147
|
const notice = events?.find(event => event.kind === 'status' && event.label === 'full_cli_access');
|
|
148
148
|
if (notice?.kind !== 'status' || !notice.detail)
|
|
149
149
|
return null;
|
|
150
150
|
return _jsx("div", { className: "jini-chat-pane__notice", role: "status", children: t(notice.detail) });
|
|
151
151
|
}
|
|
152
|
-
function ThinkingBlock({ text }) {
|
|
153
|
-
const t =
|
|
152
|
+
export function ThinkingBlock({ text, useTHook = useT }) {
|
|
153
|
+
const t = useTHook();
|
|
154
154
|
if (!text.trim())
|
|
155
155
|
return null;
|
|
156
156
|
return (_jsxs("details", { className: "jini-message-thinking", children: [_jsx("summary", { children: t('Thinking') }), _jsx("div", { className: "jini-message-thinking__text", children: text })] }));
|
|
@@ -158,8 +158,8 @@ function ThinkingBlock({ text }) {
|
|
|
158
158
|
function messageAwaitingAnswer({ runStreaming, runInProgress, events }, { isAnsweredCard } = {}) {
|
|
159
159
|
return runStreaming === true && runInProgress && isAwaitingAnswer({ events }, { isAnsweredCard });
|
|
160
160
|
}
|
|
161
|
-
function AssistantMessageFooter({ message, usageEvent, showUsageTotal, terminalNotice, pending, runInProgress, runStreaming, runSending, sendingLabel, visibleContent, isAnsweredCard
|
|
162
|
-
const t =
|
|
161
|
+
export function AssistantMessageFooter({ message, usageEvent, showUsageTotal, terminalNotice, pending, runInProgress, runStreaming, runSending, sendingLabel, visibleContent, isAnsweredCard, useTHook = useT }) {
|
|
162
|
+
const t = useTHook();
|
|
163
163
|
return _jsxs(_Fragment, { children: [usageEvent ? _jsx(UsageSummary, { usage: usageEvent, showTotal: showUsageTotal, message: message, awaitingAnswer: isAwaitingAnswer({ events: message.events }, { isAnsweredCard }) }) : null, terminalNotice ? _jsx("div", { className: message.runStatus === 'canceled' ? 'jini-chat-pane__notice' : 'jini-message-error', role: "status", children: t(terminalNotice) }) : null, !pending && !runInProgress ? (_jsx("div", { className: "jini-message-actions jini-message-actions--assistant", children: _jsx(CopyMessageButton, { text: visibleContent, label: t('Copy message') }) })) : null, runInProgress ? _jsx(RunActivityLine, { events: message.events, active: pending || (runStreaming === true && runInProgress), isAnsweredCard: isAnsweredCard, sending: runSending, sendingLabel: sendingLabel }) : null] });
|
|
164
164
|
}
|
|
165
165
|
/** Stable empty list for a message with no attachments. */
|
|
@@ -169,22 +169,29 @@ const NO_ATTACHMENTS = [];
|
|
|
169
169
|
* re-renders per composer keystroke) only re-renders rows whose props actually changed. Messages
|
|
170
170
|
* are replaced, never mutated, so identity is a sound change signal.
|
|
171
171
|
*/
|
|
172
|
-
export const MessageRow = memo(function MessageRow({
|
|
173
|
-
const answerContexts =
|
|
172
|
+
export const MessageRow = memo(function MessageRow({ useSurfaceAnswerContextsHook = useSurfaceAnswerContexts, ...props }) {
|
|
173
|
+
const answerContexts = useSurfaceAnswerContextsHook({ events: props.message.events });
|
|
174
174
|
const message = useMemo(() => props.message.events === undefined ? props.message : {
|
|
175
175
|
...props.message, events: projectAcceptedInputEvents({ events: props.message.events }, answerContexts),
|
|
176
176
|
}, [props.message, answerContexts]);
|
|
177
177
|
if (message.role === 'user')
|
|
178
178
|
return _jsx(UserMessageRow, { ...props, message: message });
|
|
179
|
-
return _jsx(AssistantMessageRow, { ...props, message: message
|
|
179
|
+
return _jsx(AssistantMessageRow, { ...resolveDisplayProps(props), message: message });
|
|
180
180
|
});
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
/** `MessageRow`'s display props with their defaults applied, ready for `AssistantMessageRow`. */
|
|
182
|
+
function resolveDisplayProps(props, _options = {}) {
|
|
183
|
+
const { showUsageTotal = true, showUsageLine = true, toolCallDisplay = 'show', showThinking = false, runStreaming = false, runSending = false, runSucceeded = false, questionFormInteractive = false, } = props;
|
|
184
|
+
return { ...props, showUsageTotal, showUsageLine, toolCallDisplay, showThinking, runStreaming, runSending, runSucceeded, questionFormInteractive };
|
|
185
|
+
}
|
|
186
|
+
/** Hooks UserMessageRow calls; defaults to the real ones, a test hands in fakes. */
|
|
187
|
+
const defaultUserMessageRowHooks = { useT, useAttachmentGallery };
|
|
188
|
+
function UserMessageRow({ message, renderAttachment, hooks = defaultUserMessageRowHooks }) {
|
|
189
|
+
const t = hooks.useT();
|
|
183
190
|
// Which attachment chip (if any) this row's preview modal is open for. Row-local, not
|
|
184
191
|
// module-level: two attachments in the same message can never be "open" at once, but two
|
|
185
192
|
// different messages opening their own attachments independently is fine and expected.
|
|
186
193
|
// Previous/next steps through this message's images only.
|
|
187
|
-
const gallery = useAttachmentGallery({ attachments: message.attachments ?? NO_ATTACHMENTS });
|
|
194
|
+
const gallery = hooks.useAttachmentGallery({ attachments: message.attachments ?? NO_ATTACHMENTS });
|
|
188
195
|
return (_jsxs("div", { className: "jini-message jini-message-user", "data-message-id": message.id, "data-agent-element": `chat-message-${message.id}`, "data-agent-role": "region", "data-agent-label": "A message from the user", children: [(message.attachments?.length || message.folders?.length) ? (_jsxs("div", { className: "jini-message-attachments", children: [_jsx(FolderChips, { folders: message.folders }), (message.attachments ?? []).map((a) => (_jsx(SentAttachmentButton, { attachment: a, onOpen: gallery.open, renderAttachment: renderAttachment }, a.path)))] })) : null, _jsx("div", { className: "jini-message-content", children: message.content }), _jsx("div", { className: "jini-message-actions jini-message-actions--user", children: _jsx(CopyMessageButton, { text: message.content, label: t('Copy message') }) }), gallery.opened ? (_jsx(AttachmentPreviewModal, { attachment: gallery.opened, onClose: gallery.close, navigation: gallery.navigation })) : null] }));
|
|
189
196
|
}
|
|
190
197
|
// A validated extension may already show the explanation. Keep the generic fallback when its
|
|
@@ -197,12 +204,14 @@ function assistantTerminalNotice({ message, runStreaming, runSucceeded, extGroup
|
|
|
197
204
|
function lastFinishedReplyIndex({ runInProgress, usage }, _options = {}) {
|
|
198
205
|
return !runInProgress && !usage.footer ? usage.replies.findLastIndex(value => value !== undefined) : -1;
|
|
199
206
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
207
|
+
/** Hooks AssistantMessageRow calls; defaults to the real ones, a test hands in fakes. */
|
|
208
|
+
const defaultAssistantMessageRowHooks = { useExtEventRendererRegistry, useMessageUsage, useToolTimeline, useExtEventGroups, useAnsweredCards, useAssistantMessageRenderers };
|
|
209
|
+
function AssistantMessageRow({ showAccessNotice = true, message, usageSummary, showUsageTotal, showUsageLine, toolCallDisplay, showThinking, runStreaming, runSending, sendingLabel, runSucceeded, questionFormInteractive, questionFormSubmittedAnswers, onQuestionFormSubmit, projectFileNames, onRequestOpenFile, hooks = defaultAssistantMessageRowHooks, report, }) {
|
|
210
|
+
const registry = hooks.useExtEventRendererRegistry();
|
|
211
|
+
const messageUsage = hooks.useMessageUsage({ message, ...(usageSummary === undefined ? {} : { summary: usageSummary }) });
|
|
212
|
+
const timeline = hooks.useToolTimeline({ events: message.events }, { runStreaming, runSucceeded });
|
|
213
|
+
const extGroups = hooks.useExtEventGroups({ events: message.events }, { slotOf: (name, data) => registry.slot({ name, data }) });
|
|
214
|
+
const answeredCards = hooks.useAnsweredCards({ slotOf: registry.slot, events: message.events ?? [], groups: extGroups, runStreaming, runStatus: message.runStatus });
|
|
206
215
|
const terminalNotice = assistantTerminalNotice({ message, runStreaming, runSucceeded, extGroups, registry });
|
|
207
216
|
const visibleContent = stripArtifact({ content: message.content });
|
|
208
217
|
const displayBlocks = messageBlocks({ message, rows: timeline.rows, registry }, { toolCallDisplay, includeThinking: showThinking });
|
|
@@ -217,98 +226,27 @@ function AssistantMessageRow({ showAccessNotice = true, message, usageSummary, s
|
|
|
217
226
|
});
|
|
218
227
|
const footerUsage = showUsageLine ? usage.footer : undefined;
|
|
219
228
|
const lastFinishedReply = lastFinishedReplyIndex({ runInProgress, usage });
|
|
220
|
-
const retriedRows = retriedToolRowIds({ rows: timeline.rows });
|
|
221
|
-
const renderToolCard = (row) => (_jsx(ToolCard, { retried: retriedRows.has(row.id), use: row.use, result: row.result, runStreaming: runStreaming, runSucceeded: runSucceeded, ...(projectFileNames !== undefined ? { projectFileNames } : {}), ...(onRequestOpenFile !== undefined ? { onRequestOpenFile } : {}) }, row.id));
|
|
222
|
-
// Hidden mode reuses the same disclosure and card renderer for unrecovered failures.
|
|
223
|
-
const renderTools = (rows, key) => (toolCallDisplay !== 'show'
|
|
224
|
-
? _jsx(ToolCallGroup, { rows: rows, renderRow: renderToolCard, failureOnly: toolCallDisplay === 'hidden' }, key)
|
|
225
|
-
: _jsx("div", { className: "jini-message-tools", children: rows.map(renderToolCard) }, key));
|
|
226
229
|
const flatTools = flatToolGroups({ message, rows: timeline.rows, registry, displayBlocks }, { toolCallDisplay });
|
|
227
230
|
const flatExtGroups = extGroups.filter(group => group.name !== MID_RUN_USER_MESSAGE_EXT_EVENT_NAME);
|
|
228
|
-
const renderExtGroup = (
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const answerText = answeredCards.answerText(group.slot);
|
|
236
|
-
const node = renderer({
|
|
237
|
-
name: group.name,
|
|
238
|
-
events: group.events,
|
|
239
|
-
runStreaming: group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME ? runInProgress : answeredCards.runStreaming,
|
|
240
|
-
...(group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME ? { transcriptRow: true } : {}),
|
|
241
|
-
runSucceeded,
|
|
242
|
-
awaitingAnswer,
|
|
243
|
-
runId: message.runId,
|
|
244
|
-
...(group.call === undefined ? {} : { call: group.call }),
|
|
245
|
-
answered: answeredCards.isAnswered(group.slot),
|
|
246
|
-
onAnswered: () => answeredCards.markAnswered(group.slot),
|
|
247
|
-
onAnswerText: (text) => answeredCards.markAnswered(group.slot, text),
|
|
248
|
-
...answerRenderProps({ answeredCards, slot: group.slot, answerText }),
|
|
249
|
-
});
|
|
250
|
-
if (!node)
|
|
251
|
-
return null;
|
|
252
|
-
return (
|
|
253
|
-
// `key` includes the event count so a group that failed on an earlier, shorter event list
|
|
254
|
-
// gets a fresh boundary instance (not the still-tripped one) once a new event actually
|
|
255
|
-
// arrives for it, instead of staying tombstoned for the message's whole lifetime.
|
|
256
|
-
_jsx(ExtEventErrorBoundary, { name: group.name, children: transcriptRow ? node : _jsx("div", { children: node }) }, `${group.slot}:${group.events.length}`));
|
|
257
|
-
};
|
|
258
|
-
const renderTextSegments = (text, keyPrefix) => splitOnQuestionForms({ input: text }).map((segment, i) => {
|
|
259
|
-
if (segment.kind === 'text')
|
|
260
|
-
return segment.text.trim() ? (_jsx("div", { className: "jini-message-content", children: _jsx(Markdown, { children: segment.text }) }, `${keyPrefix}-${i}`)) : null;
|
|
261
|
-
return (_jsx(QuestionForm, { form: segment.form, interactive: questionFormInteractive, ...(questionFormSubmittedAnswers !== undefined ? { submittedAnswers: questionFormSubmittedAnswers } : {}), ...(onQuestionFormSubmit !== undefined ? { onSubmit: onQuestionFormSubmit } : {}) }, `${keyPrefix}-${i}`));
|
|
262
|
-
});
|
|
263
|
-
const renderBlock = (block) => {
|
|
264
|
-
if (block.kind === 'text') {
|
|
265
|
-
return _jsx(React.Fragment, { children: renderTextSegments(block.text, block.key) }, block.key);
|
|
266
|
-
}
|
|
267
|
-
if (block.kind === 'reply-end') {
|
|
268
|
-
const reply = usage.replies[block.index];
|
|
269
|
-
// A trailing input may have no reply: its predecessor's usage belongs above that input.
|
|
270
|
-
if (!reply || !showUsageLine)
|
|
271
|
-
return null;
|
|
272
|
-
return _jsx(UsageSummary, { usage: reply, showTotal: showUsageTotal, ...(block.index === lastFinishedReply ? { message } : {}) }, block.key);
|
|
273
|
-
}
|
|
274
|
-
if (block.kind === 'tools')
|
|
275
|
-
return renderTools(block.rows, block.key);
|
|
276
|
-
if (block.kind === 'thinking')
|
|
277
|
-
return _jsx(ThinkingBlock, { text: block.text }, block.key);
|
|
278
|
-
return renderExtBlock(block);
|
|
279
|
-
};
|
|
280
|
-
// A mid-run bubble is its own transcript row, so it skips the ext-events wrapper and its spacing.
|
|
281
|
-
const renderExtBlock = (block) => {
|
|
282
|
-
const group = extGroups.find((g) => g.slot === block.slot);
|
|
283
|
-
if (!group)
|
|
284
|
-
return null;
|
|
285
|
-
if (group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME)
|
|
286
|
-
return _jsx(React.Fragment, { children: renderExtGroup(group) }, block.key);
|
|
287
|
-
return (_jsx("div", { className: "jini-message-ext-events", children: renderExtGroup(group) }, block.key));
|
|
288
|
-
};
|
|
289
|
-
// The live footer follows the run as transcript sections split; its clock must not remount.
|
|
290
|
-
const renderAssistantSection = ({ section, key, footer }) => (_jsxs("div", { className: usageLineMeetsActions({ footer: footerUsage, terminalNotice, pending, runInProgress }, { showTotal: showUsageTotal })
|
|
291
|
-
? 'jini-message jini-message-assistant jini-message-assistant--usage-actions'
|
|
292
|
-
: 'jini-message jini-message-assistant', "data-message-id": message.id, "data-run-status": message.runStatus, "data-agent-element": `chat-message-${message.id}`, "data-agent-role": "region", "data-agent-label": "A reply from the assistant", children: [message.agentName ? _jsx("div", { className: "jini-message-agent", children: message.agentName }) : null, section
|
|
293
|
-
? section.map(renderBlock)
|
|
294
|
-
: (_jsxs(_Fragment, { children: [renderTextSegments(visibleContent, 'text'), flatTools.map((group) => renderTools(group.rows, group.key)), flatExtGroups.length > 0 ? _jsx("div", { className: "jini-message-ext-events", children: flatExtGroups.map(renderExtGroup) }) : null] })), footer && _jsx(AssistantMessageFooter, { message, usageEvent: footerUsage, showUsageTotal, terminalNotice, pending, runInProgress, runStreaming, runSending, sendingLabel, visibleContent, isAnsweredCard: answeredCards.isAnsweredCard })] }, footer ? message.id : key));
|
|
231
|
+
const { renderBlock, renderExtGroup, renderAssistantSection } = hooks.useAssistantMessageRenderers({
|
|
232
|
+
message, rows: timeline.rows, runStreaming, runSucceeded, projectFileNames, onRequestOpenFile,
|
|
233
|
+
toolCallDisplay, registry, answeredCards, runInProgress, awaitingAnswer, questionFormInteractive,
|
|
234
|
+
questionFormSubmittedAnswers, onQuestionFormSubmit, usage, showUsageLine, showUsageTotal,
|
|
235
|
+
lastFinishedReply, extGroups, footerUsage, terminalNotice, pending, runSending, sendingLabel,
|
|
236
|
+
visibleContent, flatTools, flatExtGroups, UsageSummary, ThinkingBlock, AssistantMessageFooter,
|
|
237
|
+
}, { report });
|
|
295
238
|
// The lossless fallback keeps the host's text intact; user receipts still own separate rows,
|
|
296
239
|
// in their original receipt order, outside the assistant's actions and usage footer.
|
|
297
240
|
// Keep the same child-array nesting as the interleaved path so React preserves the footer.
|
|
298
241
|
if (blocks === null)
|
|
299
|
-
return _jsxs(_Fragment, { children: [
|
|
242
|
+
return _jsxs(_Fragment, { children: [_jsx(RunAccessNotice, { show: showAccessNotice, events: message.events }), [renderAssistantSection({ section: null, key: message.id, footer: true })], extGroups.filter(group => group.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME).map(renderExtGroup)] });
|
|
300
243
|
// A reply boundary without reported usage renders nothing; it must not create an empty row's gap.
|
|
301
244
|
const visibleBlocks = blocks.filter(block => block.kind !== 'reply-end' || (showUsageLine && usage.replies[block.index] !== undefined));
|
|
302
245
|
const { sections, footerIndex } = transcriptSections({ blocks: visibleBlocks, runInProgress });
|
|
303
|
-
return _jsxs(_Fragment, { children: [
|
|
246
|
+
return _jsxs(_Fragment, { children: [_jsx(RunAccessNotice, { show: showAccessNotice, events: message.events }), sections.map((section, index) => isUserSection({ section })
|
|
304
247
|
? _jsx(React.Fragment, { children: section.map(renderBlock) }, section[0].key)
|
|
305
248
|
: renderAssistantSection({ section, key: section[0]?.key ?? message.id, footer: index === footerIndex }))] });
|
|
306
249
|
}
|
|
307
|
-
/** Preserve optional render-prop presence for custom extension renderers. */
|
|
308
|
-
function answerRenderProps({ answeredCards, slot, answerText }, _options = {}) {
|
|
309
|
-
return { ...(answeredCards.isRecorded(slot) ? { answerRecorded: true } : {}),
|
|
310
|
-
...(answerText === undefined ? {} : { answerText }) };
|
|
311
|
-
}
|
|
312
250
|
/** Place the one footer on the last assistant section, never below a completed trailing input. */
|
|
313
251
|
function transcriptSections({ blocks, runInProgress }, _options = {}) {
|
|
314
252
|
const sections = splitMidRunBlocks({ blocks });
|
|
@@ -326,15 +264,17 @@ function isUserSection({ section }, _options = {}) {
|
|
|
326
264
|
const block = section?.[0];
|
|
327
265
|
return block?.kind === 'ext' && block.name === MID_RUN_USER_MESSAGE_EXT_EVENT_NAME;
|
|
328
266
|
}
|
|
267
|
+
/** Hooks RunActivityLine calls; defaults to the real ones, a test hands in fakes. */
|
|
268
|
+
const defaultRunActivityLineHooks = { useT, useRunActivity };
|
|
329
269
|
/**
|
|
330
270
|
* The live "what is it doing" line under a running reply (see `core/run-activity.ts`). Replaces the
|
|
331
271
|
* old "Thinking…" placeholder, which vanished for good as soon as the first tool row appeared.
|
|
332
272
|
* Kept a separate component so its one-second tick re-renders only this line, not the whole row.
|
|
333
273
|
* A host's already-localized sending label is used verbatim until acceptance.
|
|
334
274
|
*/
|
|
335
|
-
function RunActivityLine({ events, active, isAnsweredCard, sending, sendingLabel }) {
|
|
336
|
-
const t = useT();
|
|
337
|
-
const activityLabel = useRunActivity({ events: events, active: active }, { isAnsweredCard });
|
|
275
|
+
function RunActivityLine({ events, active, isAnsweredCard, sending, sendingLabel, hooks = defaultRunActivityLineHooks }) {
|
|
276
|
+
const t = hooks.useT();
|
|
277
|
+
const activityLabel = hooks.useRunActivity({ events: events, active: active }, { isAnsweredCard });
|
|
338
278
|
// Until the server accepts the start the turn is still on its way: "Thinking…" there read as the
|
|
339
279
|
// model working while the text had not even arrived (owner, 2026-10-27). No timeout.
|
|
340
280
|
const label = active && sending ? sendingLabel ?? t('Sending…') : continuingRunNotice({ events, active }, {}) ?? activityLabel;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useAttachmentGallery } from './AttachmentGallery.hooks.js';
|
|
2
|
+
import { useT } from '../hooks/context.js';
|
|
1
3
|
import { type ExtEventRenderProps } from '../ext-event-renderer-registry.js';
|
|
2
4
|
/** The ext-event name the daemon's mid-run `user_message` run event arrives under. One source with
|
|
3
5
|
* the core reply split (`replySegments`), which ends a reply's usage at this same event. */
|
|
@@ -7,7 +9,10 @@ export declare function midRunUserMessageSlotKey({ data }: {
|
|
|
7
9
|
data: unknown;
|
|
8
10
|
}): string | undefined;
|
|
9
11
|
/** The bubble for one mid-run message — the same classes as a sent user message, so it reads as one. */
|
|
10
|
-
export declare function MidRunUserMessage({ events, runStreaming, transcriptRow
|
|
12
|
+
export declare function MidRunUserMessage({ events, runStreaming, transcriptRow, useTHook, useAttachmentGalleryHook }: {
|
|
13
|
+
useTHook?: typeof useT;
|
|
14
|
+
useAttachmentGalleryHook?: typeof useAttachmentGallery;
|
|
15
|
+
} & Pick<ExtEventRenderProps, 'events'> & Partial<Pick<ExtEventRenderProps, 'runStreaming' | 'transcriptRow'>>): import("react").JSX.Element | null;
|
|
11
16
|
/**
|
|
12
17
|
* Registers {@link MidRunUserMessage} against the ext-event registry.
|
|
13
18
|
*
|
|
@@ -31,7 +31,7 @@ export function midRunUserMessageSlotKey({ data }) {
|
|
|
31
31
|
return field(data, 'id');
|
|
32
32
|
}
|
|
33
33
|
/** The bubble for one mid-run message — the same classes as a sent user message, so it reads as one. */
|
|
34
|
-
export function MidRunUserMessage({ events, runStreaming = false, transcriptRow = false }) {
|
|
34
|
+
export function MidRunUserMessage({ events, runStreaming = false, transcriptRow = false, useTHook, useAttachmentGalleryHook }) {
|
|
35
35
|
const data = events.at(-1);
|
|
36
36
|
const text = field(data, 'text');
|
|
37
37
|
if (text === undefined)
|
|
@@ -40,15 +40,15 @@ export function MidRunUserMessage({ events, runStreaming = false, transcriptRow
|
|
|
40
40
|
// MOVE: A single live delivery may contain several queued inputs; display their original receipts.
|
|
41
41
|
const inputs = receipt?.data.inputs ?? [receipt?.data ?? { id: field(data, 'id') ?? 'mid-run', text }];
|
|
42
42
|
// A run that ended without reading the message hands it to the next turn; it is no longer queued here.
|
|
43
|
-
return _jsx(_Fragment, { children: inputs.map(input => _jsx(MidRunInput, { input: input, transcriptRow: transcriptRow, queued: runStreaming && (input.deliveryState ?? receipt?.data.deliveryState) === 'queued' }, input.id)) });
|
|
43
|
+
return _jsx(_Fragment, { children: inputs.map(input => _jsx(MidRunInput, { input: input, transcriptRow: transcriptRow, queued: runStreaming && (input.deliveryState ?? receipt?.data.deliveryState) === 'queued', ...(useTHook ? { useTHook } : {}), ...(useAttachmentGalleryHook ? { useAttachmentGalleryHook } : {}) }, input.id)) });
|
|
44
44
|
}
|
|
45
45
|
/** One receipt's text, files and shared copy action; queued state belongs to this input alone.
|
|
46
46
|
* @complexity O(a) time/space for a attachments; clipboard and gallery effects stay with their owners.
|
|
47
47
|
*/
|
|
48
|
-
function MidRunInput({ input, queued, transcriptRow }) {
|
|
49
|
-
const t =
|
|
48
|
+
function MidRunInput({ input, queued, transcriptRow, useTHook = useT, useAttachmentGalleryHook = useAttachmentGallery }) {
|
|
49
|
+
const t = useTHook();
|
|
50
50
|
const attachments = input.attachments ?? [];
|
|
51
|
-
const gallery =
|
|
51
|
+
const gallery = useAttachmentGalleryHook({ attachments });
|
|
52
52
|
return (_jsxs("div", { className: `jini-message jini-message-user${transcriptRow ? '' : ' jini-message-user--mid-run'}`, "data-agent-role": "region", "data-agent-label": "A message from the user, sent while the agent was working", children: [queued && _jsx("div", { className: "jini-chat-pane__status jini-message-user__queued", role: "status", children: t('Queued — read after the current step') }), input.folders?.length ? _jsx("div", { className: "jini-message-attachments", children: _jsx(FolderChips, { folders: input.folders }) }) : null, _jsx("div", { className: "jini-message-content", children: input.text }), attachments.length > 0 && _jsx("div", { className: "jini-message-attachments", children: attachments.map(attachment => _jsx(SentAttachmentButton, { attachment: attachment, onOpen: gallery.open }, attachment.path)) }), _jsx("div", { className: "jini-message-actions jini-message-actions--user", children: _jsx(CopyMessageButton, { text: input.text, label: t('Copy message') }) }), gallery.opened !== null && _jsx(AttachmentPreviewModal, { attachment: gallery.opened, onClose: gallery.close, navigation: gallery.navigation })] }));
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* action-row shape; every user-facing string wrapped in `useT()`.
|
|
17
17
|
*/
|
|
18
18
|
import type { ReactNode } from 'react';
|
|
19
|
+
import { useT } from '../hooks/context.js';
|
|
19
20
|
export interface NextStepAction {
|
|
20
21
|
id: string;
|
|
21
22
|
label: string;
|
|
@@ -29,6 +30,7 @@ export interface NextStepAction {
|
|
|
29
30
|
export interface NextStepActionsProps {
|
|
30
31
|
actions: NextStepAction[];
|
|
31
32
|
onSelect: (actionId: string) => void;
|
|
33
|
+
useTHook?: typeof useT;
|
|
32
34
|
}
|
|
33
|
-
export declare function NextStepActions({ actions, onSelect }: NextStepActionsProps): import("react").JSX.Element | null;
|
|
35
|
+
export declare function NextStepActions({ actions, onSelect, useTHook }: NextStepActionsProps): import("react").JSX.Element | null;
|
|
34
36
|
//# sourceMappingURL=NextStepActions.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useT } from '../hooks/context.js';
|
|
3
|
-
export function NextStepActions({ actions, onSelect }) {
|
|
4
|
-
const t =
|
|
3
|
+
export function NextStepActions({ actions, onSelect, useTHook = useT }) {
|
|
4
|
+
const t = useTHook();
|
|
5
5
|
if (actions.length === 0)
|
|
6
6
|
return null;
|
|
7
|
-
return (_jsx("div", { className: "next-step-actions", children: actions.map((action) => (_jsxs("button", { type: "button", className: "next-step-action", disabled: action.disabled || action.busy, onClick: () => onSelect(action.id), children: [action.icon ? (_jsx("span", { className: "next-step-action-icon", "aria-hidden": true, children: action.icon })) : null, _jsxs("span", { className: "next-step-action-body", children: [_jsx("span", { className: "next-step-action-title", children: action.busy && action.busyLabel ? t(action.busyLabel) : t(action.label) }), action.description ? _jsx("span", { className: "next-step-action-desc", children: t(action.description) }) : null] })] }, action.id))) }));
|
|
7
|
+
return (_jsx("div", { className: "jini-next-step-actions", children: actions.map((action) => (_jsxs("button", { type: "button", className: "jini-next-step-action", disabled: action.disabled || action.busy, onClick: () => onSelect(action.id), children: [action.icon ? (_jsx("span", { className: "jini-next-step-action-icon", "aria-hidden": true, children: action.icon })) : null, _jsxs("span", { className: "jini-next-step-action-body", children: [_jsx("span", { className: "jini-next-step-action-title", children: action.busy && action.busyLabel ? t(action.busyLabel) : t(action.label) }), action.description ? _jsx("span", { className: "jini-next-step-action-desc", children: t(action.description) }) : null] })] }, action.id))) }));
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=NextStepActions.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { QuestionForm as QuestionFormType } from '../../core/index.js';
|
|
2
|
+
import type { QuestionFormProps } from './QuestionForm.js';
|
|
3
|
+
type Question = QuestionFormType['questions'][number];
|
|
4
|
+
type Answers = Record<string, string | string[]>;
|
|
5
|
+
/** Owns the editable answers plus the picked files; every edit is a no-op once the form is locked. */
|
|
6
|
+
export declare function useQuestionAnswers({ form, submittedAnswers, draftAnswers, locked }: {
|
|
7
|
+
form: QuestionFormType;
|
|
8
|
+
submittedAnswers: Answers | undefined;
|
|
9
|
+
draftAnswers: Answers | undefined;
|
|
10
|
+
locked: boolean;
|
|
11
|
+
}, { onDraftChange, onAnswerChange }?: {
|
|
12
|
+
onDraftChange?: QuestionFormProps['onDraftChange'] | undefined;
|
|
13
|
+
onAnswerChange?: QuestionFormProps['onAnswerChange'] | undefined;
|
|
14
|
+
}): {
|
|
15
|
+
answers: Answers;
|
|
16
|
+
setAnswers: import("react").Dispatch<import("react").SetStateAction<Answers>>;
|
|
17
|
+
fileAnswers: Record<string, File[]>;
|
|
18
|
+
handlers: {
|
|
19
|
+
update: (id: string, value: string | string[]) => void;
|
|
20
|
+
toggleCheckbox: (id: string, option: string, maxSelections?: number) => void;
|
|
21
|
+
updateCheckboxCustom: (q: Question, raw: string) => void;
|
|
22
|
+
selectFiles: (q: Question, list: FileList | null) => void;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=QuestionForm.answers.hooks.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { redactQuestionAnswers } from '../../core/index.js';
|
|
3
|
+
import { canonicalizeQuestionValue, emptyQuestionValue, questionValueIsKnown, splitCustomEntries } from './QuestionForm.values.js';
|
|
4
|
+
/** Owns the editable answers plus the picked files; every edit is a no-op once the form is locked. */
|
|
5
|
+
export function useQuestionAnswers({ form, submittedAnswers, draftAnswers, locked }, { onDraftChange, onAnswerChange } = {}) {
|
|
6
|
+
const initial = useMemo(() => buildInitialState(form, submittedAnswers, draftAnswers), [form, submittedAnswers, draftAnswers]);
|
|
7
|
+
const [answers, setAnswers] = useState(initial);
|
|
8
|
+
const [fileAnswers, setFileAnswers] = useState({});
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setFileAnswers({});
|
|
11
|
+
}, [form.id]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setAnswers((prev) => backfillAnswers(prev, form, submittedAnswers));
|
|
14
|
+
}, [form, submittedAnswers]);
|
|
15
|
+
function update(id, value) {
|
|
16
|
+
if (locked)
|
|
17
|
+
return;
|
|
18
|
+
const next = { ...answers, [id]: value };
|
|
19
|
+
setAnswers(next);
|
|
20
|
+
onDraftChange?.(redactQuestionAnswers({ form, answers: draftSafeAnswers(form, next) }).answers);
|
|
21
|
+
onAnswerChange?.(id, redactQuestionAnswers({ form, answers: { [id]: value } }).answers[id]);
|
|
22
|
+
}
|
|
23
|
+
function toggleCheckbox(id, option, maxSelections) {
|
|
24
|
+
if (locked)
|
|
25
|
+
return;
|
|
26
|
+
const current = Array.isArray(answers[id]) ? answers[id] : [];
|
|
27
|
+
const has = current.includes(option);
|
|
28
|
+
if (!has && maxSelections !== undefined && current.length >= maxSelections)
|
|
29
|
+
return;
|
|
30
|
+
const next = has ? current.filter((v) => v !== option) : [...current, option];
|
|
31
|
+
const nextAnswers = { ...answers, [id]: next };
|
|
32
|
+
setAnswers(nextAnswers);
|
|
33
|
+
onDraftChange?.(redactQuestionAnswers({ form, answers: draftSafeAnswers(form, nextAnswers) }).answers);
|
|
34
|
+
onAnswerChange?.(id, next);
|
|
35
|
+
}
|
|
36
|
+
function updateCheckboxCustom(q, raw) {
|
|
37
|
+
if (locked)
|
|
38
|
+
return;
|
|
39
|
+
const current = Array.isArray(answers[q.id]) ? answers[q.id] : [];
|
|
40
|
+
const fixed = current.filter((entry) => questionValueIsKnown({ q, value: entry }));
|
|
41
|
+
update(q.id, [...fixed, ...splitCustomEntries(raw)]);
|
|
42
|
+
}
|
|
43
|
+
function selectFiles(q, list) {
|
|
44
|
+
const files = Array.from(list ?? []), names = files.map((file) => file.name);
|
|
45
|
+
setFileAnswers((current) => ({ ...current, [q.id]: files }));
|
|
46
|
+
update(q.id, q.multiple ? names : (names[0] ?? ''));
|
|
47
|
+
}
|
|
48
|
+
return { answers, setAnswers, fileAnswers, handlers: { update, toggleCheckbox, updateCheckboxCustom, selectFiles } };
|
|
49
|
+
}
|
|
50
|
+
function buildInitialState(form, submitted, draft) {
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const q of form.questions)
|
|
53
|
+
out[q.id] = initialQuestionValue(q, submitted, draft);
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/** Submitted beats draft beats default beats empty; file drafts are never restored (the File objects are gone). */
|
|
57
|
+
function initialQuestionValue(q, submitted, draft) {
|
|
58
|
+
if (submitted?.[q.id] !== undefined)
|
|
59
|
+
return canonicalizeQuestionValue({ q, value: submitted[q.id] });
|
|
60
|
+
if (draft?.[q.id] !== undefined && q.type !== 'file')
|
|
61
|
+
return canonicalizeQuestionValue({ q, value: draft[q.id] });
|
|
62
|
+
if (q.defaultValue !== undefined)
|
|
63
|
+
return canonicalizeQuestionValue({ q, value: q.defaultValue });
|
|
64
|
+
return emptyQuestionValue(q);
|
|
65
|
+
}
|
|
66
|
+
/** Questions that stream in after mount get their initial value; answers already set are kept. */
|
|
67
|
+
function backfillAnswers(prev, form, submitted) {
|
|
68
|
+
let changed = false;
|
|
69
|
+
const next = { ...prev };
|
|
70
|
+
for (const q of form.questions) {
|
|
71
|
+
if (next[q.id] !== undefined)
|
|
72
|
+
continue;
|
|
73
|
+
changed = true;
|
|
74
|
+
next[q.id] = initialQuestionValue(q, submitted, undefined);
|
|
75
|
+
}
|
|
76
|
+
return changed ? next : prev;
|
|
77
|
+
}
|
|
78
|
+
function draftSafeAnswers(form, answers) {
|
|
79
|
+
const fileQuestionIds = new Set(form.questions.filter((q) => q.type === 'file').map((q) => q.id));
|
|
80
|
+
if (fileQuestionIds.size === 0)
|
|
81
|
+
return answers;
|
|
82
|
+
const out = {};
|
|
83
|
+
for (const [id, value] of Object.entries(answers)) {
|
|
84
|
+
if (!fileQuestionIds.has(id))
|
|
85
|
+
out[id] = value;
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=QuestionForm.answers.hooks.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type UserTextRedactionOptions } from '../../core/user-text-redaction.js';
|
|
2
|
+
import { useUserTextGuard } from '../hooks/useUserTextGuard.js';
|
|
2
3
|
import type { QuestionForm as QuestionFormType } from '../../core/index.js';
|
|
4
|
+
import { useT } from '../hooks/context.js';
|
|
5
|
+
import { useQuestionAnswers } from './QuestionForm.answers.hooks.js';
|
|
3
6
|
export interface QuestionFormFileSubmission {
|
|
4
7
|
questionId: string;
|
|
5
8
|
questionLabel: string;
|
|
@@ -11,6 +14,9 @@ export interface QuestionFormHandle {
|
|
|
11
14
|
skipAll: () => void;
|
|
12
15
|
}
|
|
13
16
|
export interface QuestionFormProps extends UserTextRedactionOptions {
|
|
17
|
+
useTHook?: typeof useT;
|
|
18
|
+
useUserTextGuardHook?: typeof useUserTextGuard;
|
|
19
|
+
useQuestionAnswersHook?: typeof useQuestionAnswers;
|
|
14
20
|
form: QuestionFormType;
|
|
15
21
|
/** Whether the user can still submit answers — the host disables this once the turn is no longer the most recent one. */
|
|
16
22
|
interactive: boolean;
|