@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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { createConsoleLogger } from '@jini-ai/core/primitives';
|
|
2
3
|
import { stripConversationTitleMarkdown } from '../../core/persistence/title.js';
|
|
3
4
|
/** Project saved/search titles for presentation without renaming durable conversations.
|
|
4
5
|
* The switcher has no prompt or title provenance, so keep wording and casing while stripping
|
|
@@ -22,4 +23,179 @@ export function useConversationListTitles({ conversations, serverResults }, _opt
|
|
|
22
23
|
return { conversations: display(conversations), serverResults: serverResults === null ? null : display(serverResults), rawTitles };
|
|
23
24
|
}, [conversations, serverResults]);
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* How long a click waits to see whether it is really the first half of a double-click.
|
|
28
|
+
*
|
|
29
|
+
* Covers the common OS double-click window, including deliberate clicks 300ms apart.
|
|
30
|
+
*/
|
|
31
|
+
const DOUBLE_CLICK_GRACE_MS = 500;
|
|
32
|
+
function reportConversationListHostEffectFailure({ effectName, error }, { report: logger = createConsoleLogger({ prefix: '' }) } = {}) {
|
|
33
|
+
logger.error({ message: `[@jini-ai/chat] ConversationList ${effectName} host effect failed:` }, { error });
|
|
34
|
+
}
|
|
35
|
+
/** Invokes a host callback and reports a synchronous throw or async rejection without leaving it unhandled. */
|
|
36
|
+
function runConversationListHostEffect({ effectName, effect }, { report } = {}) {
|
|
37
|
+
let result;
|
|
38
|
+
try {
|
|
39
|
+
result = effect();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
reportConversationListHostEffectFailure({ effectName, error }, { report });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
void Promise.resolve(result).catch((error) => {
|
|
46
|
+
reportConversationListHostEffectFailure({ effectName, error }, { report });
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Manage search, selection timing, rename, deletion, and host effects for the switcher. */
|
|
50
|
+
export function useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report } = {}) {
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const [query, setQuery] = useState('');
|
|
53
|
+
const [savedServerResults, setServerResults] = useState(null);
|
|
54
|
+
const { conversations, serverResults, rawTitles } = useConversationListTitles({ conversations: savedConversations, serverResults: savedServerResults });
|
|
55
|
+
const [editingId, setEditingId] = useState(null);
|
|
56
|
+
const rootRef = useRef(null);
|
|
57
|
+
const deferredQuery = useDeferredValue(query);
|
|
58
|
+
/**
|
|
59
|
+
* Pending single-click selection, held so a double-click can cancel it.
|
|
60
|
+
*
|
|
61
|
+
* A double-click always delivers its first `click` too, so selecting immediately would close
|
|
62
|
+
* the menu out from under the rename editor — the row would be selected and the switcher shut
|
|
63
|
+
* before `dblclick` ever arrived. Open Design's original switcher has exactly this bug. The
|
|
64
|
+
* delay is only perceptible if you are looking for it, and it costs nothing but a timer.
|
|
65
|
+
*/
|
|
66
|
+
const pendingSelectRef = useRef(null);
|
|
67
|
+
const cancelPendingSelect = useCallback(() => {
|
|
68
|
+
if (pendingSelectRef.current === null)
|
|
69
|
+
return;
|
|
70
|
+
clearTimeout(pendingSelectRef.current);
|
|
71
|
+
pendingSelectRef.current = null;
|
|
72
|
+
}, []);
|
|
73
|
+
// A timer that fires after unmount would call `setOpen` on a dead component.
|
|
74
|
+
useEffect(() => cancelPendingSelect, [cancelPendingSelect]);
|
|
75
|
+
/*
|
|
76
|
+
* Closing the switcher also abandons a click that has not yet resolved into a selection.
|
|
77
|
+
*
|
|
78
|
+
* The grace window exists so a double-click can become a rename rather than a selection, which
|
|
79
|
+
* means a single click stays pending for the grace window. Press Escape (or click outside) inside it
|
|
80
|
+
* and the menu closes while the timer survives, so the row is selected anyway — and if the pending
|
|
81
|
+
* click was on Delete, it selects an id that no longer exists.
|
|
82
|
+
*/
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!open)
|
|
85
|
+
cancelPendingSelect();
|
|
86
|
+
}, [open, cancelPendingSelect]);
|
|
87
|
+
// Close on outside click / Escape. Registered only while open so a closed switcher costs
|
|
88
|
+
// nothing on every document event.
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!open)
|
|
91
|
+
return undefined;
|
|
92
|
+
// The root div is committed before any effect runs, so it is never null here. Capturing it
|
|
93
|
+
// (rather than reading the ref per event) keeps a late event during unmount, after React has
|
|
94
|
+
// detached the ref but before this cleanup runs, measured against the real node.
|
|
95
|
+
const root = rootRef.current;
|
|
96
|
+
function onPointerDown(event) {
|
|
97
|
+
if (!root.contains(event.target))
|
|
98
|
+
setOpen(false);
|
|
99
|
+
}
|
|
100
|
+
function onKeyDown(event) {
|
|
101
|
+
if (event.key === 'Escape')
|
|
102
|
+
setOpen(false);
|
|
103
|
+
}
|
|
104
|
+
document.addEventListener('mousedown', onPointerDown);
|
|
105
|
+
document.addEventListener('keydown', onKeyDown);
|
|
106
|
+
return () => {
|
|
107
|
+
document.removeEventListener('mousedown', onPointerDown);
|
|
108
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
109
|
+
};
|
|
110
|
+
}, [open]);
|
|
111
|
+
// A stale query is worse than no query: reopening to yesterday's filter looks like data loss.
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (open)
|
|
114
|
+
return;
|
|
115
|
+
setQuery('');
|
|
116
|
+
setServerResults(null);
|
|
117
|
+
setEditingId(null);
|
|
118
|
+
}, [open]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!onSearch)
|
|
121
|
+
return undefined;
|
|
122
|
+
if (!deferredQuery) {
|
|
123
|
+
setServerResults(null);
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
// `cancelled` guards the classic out-of-order response: a slow query for "a" resolving after
|
|
127
|
+
// a fast one for "abc" would otherwise overwrite the newer, correct results.
|
|
128
|
+
let cancelled = false;
|
|
129
|
+
// A search failure just leaves the prior (possibly stale) results in place rather than
|
|
130
|
+
// wiping the list — degraded, not wrong, so reporting the rejection is all that's warranted.
|
|
131
|
+
runConversationListHostEffect({ effectName: 'onSearch', effect: () => onSearch(deferredQuery).then((results) => {
|
|
132
|
+
if (!cancelled)
|
|
133
|
+
setServerResults(results);
|
|
134
|
+
}),
|
|
135
|
+
}, { report });
|
|
136
|
+
return () => {
|
|
137
|
+
cancelled = true;
|
|
138
|
+
};
|
|
139
|
+
}, [onSearch, deferredQuery, report]);
|
|
140
|
+
const visible = useMemo(() => {
|
|
141
|
+
if (onSearch)
|
|
142
|
+
return serverResults ?? conversations;
|
|
143
|
+
const needle = deferredQuery.trim().toLocaleLowerCase();
|
|
144
|
+
if (!needle)
|
|
145
|
+
return conversations;
|
|
146
|
+
return conversations.filter((c) => (c.title ?? t('Untitled')).toLocaleLowerCase().includes(needle));
|
|
147
|
+
}, [onSearch, serverResults, conversations, deferredQuery, t]);
|
|
148
|
+
// One timestamp for the whole render so every row's "5m ago" is computed against the same
|
|
149
|
+
// instant — otherwise rows drawn either side of a second boundary disagree.
|
|
150
|
+
const now = Date.now();
|
|
151
|
+
const commitRename = useCallback((id, next) => {
|
|
152
|
+
setEditingId(null);
|
|
153
|
+
// No optimistic title update happens here — the row keeps rendering `item.title` from
|
|
154
|
+
// props until the host's own state updates, so a rejection cannot leave the UI showing a
|
|
155
|
+
// title the server didn't accept. Reporting the failure is what closes the remaining gap.
|
|
156
|
+
if (onRename)
|
|
157
|
+
runConversationListHostEffect({ effectName: 'onRename', effect: () => onRename(id, next) }, { report });
|
|
158
|
+
}, [onRename, report]);
|
|
159
|
+
const startRename = (id) => {
|
|
160
|
+
if (!onRename)
|
|
161
|
+
return;
|
|
162
|
+
cancelPendingSelect();
|
|
163
|
+
setEditingId(id);
|
|
164
|
+
};
|
|
165
|
+
const requestDelete = useCallback((item) => {
|
|
166
|
+
if (!onDelete)
|
|
167
|
+
return;
|
|
168
|
+
const confirmer = confirmDelete ??
|
|
169
|
+
// Only ever called from a click handler, so a browser `window` always exists here.
|
|
170
|
+
((c) => window.confirm(t('Delete "{title}"? This cannot be undone.').replace('{title}', () => c.title ?? t('Untitled'))));
|
|
171
|
+
// No optimistic removal — the row stays in `conversations` until the host's own state
|
|
172
|
+
// drops it — so a rejected confirmer or `onDelete` cannot leave a deleted-looking row
|
|
173
|
+
// behind; it only means the item silently never disappears. `onDelete` is the effect name
|
|
174
|
+
// reported here since a rejecting confirmer is, from the host's perspective, also "the
|
|
175
|
+
// delete didn't happen."
|
|
176
|
+
runConversationListHostEffect({ effectName: 'onDelete', effect: async () => {
|
|
177
|
+
if (await confirmer(item))
|
|
178
|
+
await onDelete(item.id);
|
|
179
|
+
} }, { report });
|
|
180
|
+
}, [confirmDelete, onDelete, t, report]);
|
|
181
|
+
const active = conversations.find((c) => c.id === activeConversationId) ?? null;
|
|
182
|
+
const emptyLabel = () => conversations.length === 0 ? emptyState ?? t('No conversations yet') : t('No conversations match');
|
|
183
|
+
const scheduleSelect = (id) => {
|
|
184
|
+
cancelPendingSelect();
|
|
185
|
+
pendingSelectRef.current = setTimeout(() => {
|
|
186
|
+
pendingSelectRef.current = null;
|
|
187
|
+
onSelect(id);
|
|
188
|
+
setOpen(false);
|
|
189
|
+
}, DOUBLE_CLICK_GRACE_MS);
|
|
190
|
+
};
|
|
191
|
+
// No optimistic row is inserted — the list still comes straight from props — so a
|
|
192
|
+
// rejection here cannot leave a phantom conversation on screen; it only means the
|
|
193
|
+
// switcher closed without one actually being created. Reporting the failure closes
|
|
194
|
+
// the remaining gap between "switcher closed" and "the host actually knows".
|
|
195
|
+
const createConversation = () => {
|
|
196
|
+
runConversationListHostEffect({ effectName: 'onCreate', effect: () => onCreate() }, { report });
|
|
197
|
+
setOpen(false);
|
|
198
|
+
};
|
|
199
|
+
return { open, setOpen, query, setQuery, conversations, rawTitles, editingId, setEditingId, rootRef, visible, now, commitRename, startRename, requestDelete, active, emptyLabel, scheduleSelect, createConversation };
|
|
200
|
+
}
|
|
25
201
|
//# sourceMappingURL=ConversationList.hooks.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { formatErrorForLog } from '@jini-ai/core';
|
|
3
2
|
/**
|
|
4
3
|
* @module ConversationList
|
|
5
4
|
*
|
|
@@ -21,35 +20,11 @@ import { formatErrorForLog } from '@jini-ai/core';
|
|
|
21
20
|
* Unstyled semantic markup with `jini-conv-*` class names, matching every other component in this
|
|
22
21
|
* package — a host supplies the CSS.
|
|
23
22
|
*/
|
|
24
|
-
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react';
|
|
25
23
|
import { useT } from '../hooks/context.js';
|
|
26
24
|
import { Icon } from './Icon.js';
|
|
27
|
-
import {
|
|
25
|
+
import { useConversationListView } from './ConversationList.hooks.js';
|
|
28
26
|
import { conversationTriggerAttributes } from './ConversationList.rules.js';
|
|
29
27
|
import { ConversationTitleEditor } from './ConversationTitleEditor.js';
|
|
30
|
-
/**
|
|
31
|
-
* How long a click waits to see whether it is really the first half of a double-click.
|
|
32
|
-
*
|
|
33
|
-
* Covers the common OS double-click window, including deliberate clicks 300ms apart.
|
|
34
|
-
*/
|
|
35
|
-
const DOUBLE_CLICK_GRACE_MS = 500;
|
|
36
|
-
function reportConversationListHostEffectFailure(effectName, error) {
|
|
37
|
-
console.error(`[@jini-ai/chat] ConversationList ${effectName} host effect failed:`, formatErrorForLog({ error }));
|
|
38
|
-
}
|
|
39
|
-
/** Invokes a host callback and reports a synchronous throw or async rejection without leaving it unhandled. */
|
|
40
|
-
function runConversationListHostEffect(effectName, effect) {
|
|
41
|
-
let result;
|
|
42
|
-
try {
|
|
43
|
-
result = effect();
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
reportConversationListHostEffectFailure(effectName, error);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
void Promise.resolve(result).catch((error) => {
|
|
50
|
-
reportConversationListHostEffectFailure(effectName, error);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
28
|
function relativeTime(updatedAt, now) {
|
|
54
29
|
if (updatedAt === undefined)
|
|
55
30
|
return '';
|
|
@@ -71,155 +46,13 @@ function ConversationActions({ itemId, editing, canRename, canDelete, onRename,
|
|
|
71
46
|
onDelete();
|
|
72
47
|
}, children: _jsx(Icon, { name: "close", size: 12 }) }) : null] });
|
|
73
48
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const { conversations, serverResults, rawTitles } = useConversationListTitles({ conversations: savedConversations, serverResults: savedServerResults });
|
|
80
|
-
const [editingId, setEditingId] = useState(null);
|
|
81
|
-
const rootRef = useRef(null);
|
|
82
|
-
const deferredQuery = useDeferredValue(query);
|
|
83
|
-
/**
|
|
84
|
-
* Pending single-click selection, held so a double-click can cancel it.
|
|
85
|
-
*
|
|
86
|
-
* A double-click always delivers its first `click` too, so selecting immediately would close
|
|
87
|
-
* the menu out from under the rename editor — the row would be selected and the switcher shut
|
|
88
|
-
* before `dblclick` ever arrived. Open Design's original switcher has exactly this bug. The
|
|
89
|
-
* delay is only perceptible if you are looking for it, and it costs nothing but a timer.
|
|
90
|
-
*/
|
|
91
|
-
const pendingSelectRef = useRef(null);
|
|
92
|
-
const cancelPendingSelect = useCallback(() => {
|
|
93
|
-
if (pendingSelectRef.current === null)
|
|
94
|
-
return;
|
|
95
|
-
clearTimeout(pendingSelectRef.current);
|
|
96
|
-
pendingSelectRef.current = null;
|
|
97
|
-
}, []);
|
|
98
|
-
// A timer that fires after unmount would call `setOpen` on a dead component.
|
|
99
|
-
useEffect(() => cancelPendingSelect, [cancelPendingSelect]);
|
|
100
|
-
/*
|
|
101
|
-
* Closing the switcher also abandons a click that has not yet resolved into a selection.
|
|
102
|
-
*
|
|
103
|
-
* The grace window exists so a double-click can become a rename rather than a selection, which
|
|
104
|
-
* means a single click stays pending for the grace window. Press Escape (or click outside) inside it
|
|
105
|
-
* and the menu closes while the timer survives, so the row is selected anyway — and if the pending
|
|
106
|
-
* click was on Delete, it selects an id that no longer exists.
|
|
107
|
-
*/
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
if (!open)
|
|
110
|
-
cancelPendingSelect();
|
|
111
|
-
}, [open, cancelPendingSelect]);
|
|
112
|
-
// Close on outside click / Escape. Registered only while open so a closed switcher costs
|
|
113
|
-
// nothing on every document event.
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
if (!open)
|
|
116
|
-
return undefined;
|
|
117
|
-
// The root div is committed before any effect runs, so it is never null here. Capturing it
|
|
118
|
-
// (rather than reading the ref per event) keeps a late event during unmount, after React has
|
|
119
|
-
// detached the ref but before this cleanup runs, measured against the real node.
|
|
120
|
-
const root = rootRef.current;
|
|
121
|
-
function onPointerDown(event) {
|
|
122
|
-
if (!root.contains(event.target))
|
|
123
|
-
setOpen(false);
|
|
124
|
-
}
|
|
125
|
-
function onKeyDown(event) {
|
|
126
|
-
if (event.key === 'Escape')
|
|
127
|
-
setOpen(false);
|
|
128
|
-
}
|
|
129
|
-
document.addEventListener('mousedown', onPointerDown);
|
|
130
|
-
document.addEventListener('keydown', onKeyDown);
|
|
131
|
-
return () => {
|
|
132
|
-
document.removeEventListener('mousedown', onPointerDown);
|
|
133
|
-
document.removeEventListener('keydown', onKeyDown);
|
|
134
|
-
};
|
|
135
|
-
}, [open]);
|
|
136
|
-
// A stale query is worse than no query: reopening to yesterday's filter looks like data loss.
|
|
137
|
-
useEffect(() => {
|
|
138
|
-
if (open)
|
|
139
|
-
return;
|
|
140
|
-
setQuery('');
|
|
141
|
-
setServerResults(null);
|
|
142
|
-
setEditingId(null);
|
|
143
|
-
}, [open]);
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
if (!onSearch)
|
|
146
|
-
return undefined;
|
|
147
|
-
if (!deferredQuery) {
|
|
148
|
-
setServerResults(null);
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
// `cancelled` guards the classic out-of-order response: a slow query for "a" resolving after
|
|
152
|
-
// a fast one for "abc" would otherwise overwrite the newer, correct results.
|
|
153
|
-
let cancelled = false;
|
|
154
|
-
// A search failure just leaves the prior (possibly stale) results in place rather than
|
|
155
|
-
// wiping the list — degraded, not wrong, so reporting the rejection is all that's warranted.
|
|
156
|
-
runConversationListHostEffect('onSearch', () => onSearch(deferredQuery).then((results) => {
|
|
157
|
-
if (!cancelled)
|
|
158
|
-
setServerResults(results);
|
|
159
|
-
}));
|
|
160
|
-
return () => {
|
|
161
|
-
cancelled = true;
|
|
162
|
-
};
|
|
163
|
-
}, [onSearch, deferredQuery]);
|
|
164
|
-
const visible = useMemo(() => {
|
|
165
|
-
if (onSearch)
|
|
166
|
-
return serverResults ?? conversations;
|
|
167
|
-
const needle = deferredQuery.trim().toLocaleLowerCase();
|
|
168
|
-
if (!needle)
|
|
169
|
-
return conversations;
|
|
170
|
-
return conversations.filter((c) => (c.title ?? t('Untitled')).toLocaleLowerCase().includes(needle));
|
|
171
|
-
}, [onSearch, serverResults, conversations, deferredQuery, t]);
|
|
172
|
-
// One timestamp for the whole render so every row's "5m ago" is computed against the same
|
|
173
|
-
// instant — otherwise rows drawn either side of a second boundary disagree.
|
|
174
|
-
const now = Date.now();
|
|
175
|
-
const commitRename = useCallback((id, next) => {
|
|
176
|
-
setEditingId(null);
|
|
177
|
-
// No optimistic title update happens here — the row keeps rendering `item.title` from
|
|
178
|
-
// props until the host's own state updates, so a rejection cannot leave the UI showing a
|
|
179
|
-
// title the server didn't accept. Reporting the failure is what closes the remaining gap.
|
|
180
|
-
if (onRename)
|
|
181
|
-
runConversationListHostEffect('onRename', () => onRename(id, next));
|
|
182
|
-
}, [onRename]);
|
|
183
|
-
const startRename = (id) => {
|
|
184
|
-
if (!onRename)
|
|
185
|
-
return;
|
|
186
|
-
cancelPendingSelect();
|
|
187
|
-
setEditingId(id);
|
|
188
|
-
};
|
|
189
|
-
const requestDelete = useCallback((item) => {
|
|
190
|
-
if (!onDelete)
|
|
191
|
-
return;
|
|
192
|
-
const confirmer = confirmDelete ??
|
|
193
|
-
// Only ever called from a click handler, so a browser `window` always exists here.
|
|
194
|
-
((c) => window.confirm(t('Delete "{title}"? This cannot be undone.').replace('{title}', c.title ?? t('Untitled'))));
|
|
195
|
-
// No optimistic removal — the row stays in `conversations` until the host's own state
|
|
196
|
-
// drops it — so a rejected confirmer or `onDelete` cannot leave a deleted-looking row
|
|
197
|
-
// behind; it only means the item silently never disappears. `onDelete` is the effect name
|
|
198
|
-
// reported here since a rejecting confirmer is, from the host's perspective, also "the
|
|
199
|
-
// delete didn't happen."
|
|
200
|
-
runConversationListHostEffect('onDelete', async () => {
|
|
201
|
-
if (await confirmer(item))
|
|
202
|
-
await onDelete(item.id);
|
|
203
|
-
});
|
|
204
|
-
}, [confirmDelete, onDelete, t]);
|
|
205
|
-
const active = conversations.find((c) => c.id === activeConversationId) ?? null;
|
|
206
|
-
const emptyLabel = () => conversations.length === 0 ? emptyState ?? t('No conversations yet') : t('No conversations match');
|
|
49
|
+
/** Hooks ConversationList calls; defaults to the real ones, a test hands in fakes. */
|
|
50
|
+
export const defaultConversationListHooks = { useT, useConversationListView };
|
|
51
|
+
export function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled = false, emptyState, triggerLabel, nativeTitle = true, hooks = defaultConversationListHooks, report, }) {
|
|
52
|
+
const t = hooks.useT();
|
|
53
|
+
const { open, setOpen, query, setQuery, conversations, rawTitles, editingId, setEditingId, rootRef, visible, now, commitRename, startRename, requestDelete, active, emptyLabel, scheduleSelect, createConversation } = hooks.useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report });
|
|
207
54
|
return (_jsxs("div", { className: "jini-conv", ref: rootRef, children: [_jsx("button", { type: "button", className: `jini-conv-trigger${open ? ' jini-conv-trigger-open' : ''}`, "aria-haspopup": "menu", "aria-expanded": open, ...conversationTriggerAttributes({ activeTitle: active?.title, t }, { label: triggerLabel, nativeTitle }), "data-testid": "conversation-trigger", onClick: () => setOpen((v) => !v), children: _jsx(Icon, { name: "comment", size: 16 }) }), open ? (_jsxs("div", { className: "jini-conv-menu", role: "menu", "data-testid": "conversation-menu", children: [_jsxs("div", { className: "jini-conv-head", children: [_jsxs("span", { className: "jini-conv-heading", children: [t('Conversations'), _jsx("span", { className: "jini-conv-count", "data-testid": "conversation-count", children: conversations.length })] }), _jsxs("button", { type: "button", className: "jini-conv-new", disabled: createDisabled, "data-testid": "conversation-new",
|
|
208
55
|
// `disabled` alone guards this: a disabled button never dispatches a click.
|
|
209
|
-
onClick: () => {
|
|
210
|
-
// No optimistic row is inserted — the list still comes straight from props — so a
|
|
211
|
-
// rejection here cannot leave a phantom conversation on screen; it only means the
|
|
212
|
-
// switcher closed without one actually being created. Reporting the failure closes
|
|
213
|
-
// the remaining gap between "switcher closed" and "the host actually knows".
|
|
214
|
-
runConversationListHostEffect('onCreate', () => onCreate());
|
|
215
|
-
setOpen(false);
|
|
216
|
-
}, children: [_jsx(Icon, { name: "plus", size: 12 }), _jsx("span", { children: t('New') })] })] }), _jsxs("label", { className: "jini-conv-search", children: [_jsx(Icon, { name: "search", size: 13 }), _jsx("input", { type: "search", value: query, placeholder: t('Search conversations'), "data-testid": "conversation-search", onChange: (event) => setQuery(event.currentTarget.value) })] }), _jsx("div", { className: "jini-conv-list", "data-testid": "conversation-list", children: conversations.length === 0 || visible.length === 0 ? (_jsx("div", { className: "jini-conv-empty", children: emptyLabel() })) : (visible.map((item) => (_jsxs("div", { className: `jini-conv-item${item.id === activeConversationId ? ' jini-conv-item-active' : ''}`, "data-testid": `conversation-item-${item.id}`, children: [onRename && editingId === item.id ? (_jsx(ConversationTitleEditor, { title: rawTitles.get(item.id) ?? null, "data-testid": `conversation-rename-${item.id}`, onCommit: (next) => commitRename(item.id, next), onCancel: () => setEditingId(null) })) : (_jsxs("button", { type: "button", className: "jini-conv-item-select", "data-testid": `conversation-select-${item.id}`, title: onRename ? t('Double-click to rename') : undefined, onClick: () => {
|
|
217
|
-
cancelPendingSelect();
|
|
218
|
-
pendingSelectRef.current = setTimeout(() => {
|
|
219
|
-
pendingSelectRef.current = null;
|
|
220
|
-
onSelect(item.id);
|
|
221
|
-
setOpen(false);
|
|
222
|
-
}, DOUBLE_CLICK_GRACE_MS);
|
|
223
|
-
}, onDoubleClick: onRename ? () => startRename(item.id) : undefined, children: [_jsx("span", { className: "jini-conv-item-title", children: item.title ?? t('Untitled') }), _jsxs("span", { className: "jini-conv-item-meta", children: [item.messageCount === undefined ? '' : `${item.messageCount} msg · `, relativeTime(item.updatedAt, now)] })] })), _jsx(ConversationActions, { itemId: item.id, editing: editingId === item.id, canRename: Boolean(onRename), canDelete: Boolean(onDelete), onRename: () => startRename(item.id), onDelete: () => requestDelete(item), t: t })] }, item.id)))) })] })) : null] }));
|
|
56
|
+
onClick: createConversation, children: [_jsx(Icon, { name: "plus", size: 12 }), _jsx("span", { children: t('New') })] })] }), _jsxs("label", { className: "jini-conv-search", children: [_jsx(Icon, { name: "search", size: 13 }), _jsx("input", { type: "search", value: query, placeholder: t('Search conversations'), "data-testid": "conversation-search", onChange: (event) => setQuery(event.currentTarget.value) })] }), _jsx("div", { className: "jini-conv-list", "data-testid": "conversation-list", children: conversations.length === 0 || visible.length === 0 ? (_jsx("div", { className: "jini-conv-empty", children: emptyLabel() })) : (visible.map((item) => (_jsxs("div", { className: `jini-conv-item${item.id === activeConversationId ? ' jini-conv-item-active' : ''}`, "data-testid": `conversation-item-${item.id}`, children: [onRename && editingId === item.id ? (_jsx(ConversationTitleEditor, { title: rawTitles.get(item.id) ?? null, "data-testid": `conversation-rename-${item.id}`, onCommit: (next) => commitRename(item.id, next), onCancel: () => setEditingId(null) })) : (_jsxs("button", { type: "button", className: "jini-conv-item-select", "data-testid": `conversation-select-${item.id}`, title: onRename ? t('Double-click to rename') : undefined, onClick: () => scheduleSelect(item.id), onDoubleClick: onRename ? () => startRename(item.id) : undefined, children: [_jsx("span", { className: "jini-conv-item-title", children: item.title ?? t('Untitled') }), _jsxs("span", { className: "jini-conv-item-meta", children: [item.messageCount === undefined ? '' : `${item.messageCount} msg · `, relativeTime(item.updatedAt, now)] })] })), _jsx(ConversationActions, { itemId: item.id, editing: editingId === item.id, canRename: Boolean(onRename), canDelete: Boolean(onDelete), onRename: () => startRename(item.id), onDelete: () => requestDelete(item), t: t })] }, item.id)))) })] })) : null] }));
|
|
224
57
|
}
|
|
225
58
|
//# sourceMappingURL=ConversationList.js.map
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import type { Logger } from '@jini-ai/core/primitives';
|
|
2
|
+
import { useConversationTitleEditor } from './ConversationTitleEditor.hooks.js';
|
|
3
|
+
import { useT } from '../hooks/context.js';
|
|
1
4
|
export interface ConversationTitleEditorProps {
|
|
5
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
2
6
|
title: string | null;
|
|
3
7
|
onCommit: (title: string) => void | Promise<void>;
|
|
4
8
|
onCancel: () => void;
|
|
5
9
|
className?: string;
|
|
6
10
|
'data-testid'?: string;
|
|
7
11
|
}
|
|
12
|
+
/** Hooks ConversationTitleEditor calls; defaults to the real ones, a test hands in fakes. */
|
|
13
|
+
export declare const defaultConversationTitleEditorHooks: {
|
|
14
|
+
useT: typeof useT;
|
|
15
|
+
useConversationTitleEditor: typeof useConversationTitleEditor;
|
|
16
|
+
};
|
|
17
|
+
export type ConversationTitleEditorHooks = typeof defaultConversationTitleEditorHooks;
|
|
8
18
|
/**
|
|
9
19
|
* Shared inline rename lifecycle. Enter/blur save once; Escape, empty and unchanged drafts cancel.
|
|
10
20
|
* Snapshots the raw title on mount so a background title refresh cannot become a user edit.
|
|
@@ -12,8 +22,11 @@ export interface ConversationTitleEditorProps {
|
|
|
12
22
|
* @complexity O(n) time/space to trim a draft of n code units; the saved title is bounded.
|
|
13
23
|
* @example <ConversationTitleEditor title={title} onCommit={rename} onCancel={close} />
|
|
14
24
|
*/
|
|
15
|
-
export declare function ConversationTitleEditor({ title, onCommit, onCancel, className, 'data-testid': testId }: ConversationTitleEditorProps
|
|
25
|
+
export declare function ConversationTitleEditor({ title, onCommit, onCancel, className, 'data-testid': testId, hooks, report }: ConversationTitleEditorProps & {
|
|
26
|
+
hooks?: ConversationTitleEditorHooks | undefined;
|
|
27
|
+
}): import("react").JSX.Element;
|
|
16
28
|
export interface ConversationTitleProps {
|
|
29
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
17
30
|
title: string | null;
|
|
18
31
|
displayTitle: string;
|
|
19
32
|
onRename: (title: string) => void | Promise<void>;
|
|
@@ -23,5 +36,7 @@ export interface ConversationTitleProps {
|
|
|
23
36
|
* @complexity O(1) outside the shared editor's draft normalization.
|
|
24
37
|
* @example <ConversationTitle key={id} title={rawTitle} displayTitle={label} onRename={rename} />
|
|
25
38
|
*/
|
|
26
|
-
export declare function ConversationTitle({ title, displayTitle, onRename, disabled }: ConversationTitleProps
|
|
39
|
+
export declare function ConversationTitle({ title, displayTitle, onRename, disabled, useTHook, report }: ConversationTitleProps & {
|
|
40
|
+
useTHook?: typeof useT;
|
|
41
|
+
}): import("react").JSX.Element;
|
|
27
42
|
//# sourceMappingURL=ConversationTitleEditor.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Logger } from '@jini-ai/core/primitives';
|
|
2
|
+
import { type KeyboardEvent } from 'react';
|
|
3
|
+
import type { ConversationTitleEditorProps } from './ConversationTitleEditor.js';
|
|
4
|
+
/** Commit or cancel a draft once, even when keyboard activation also triggers blur. */
|
|
5
|
+
export declare function useConversationTitleEditor({ title, onCommit, onCancel }: Pick<ConversationTitleEditorProps, 'title' | 'onCommit' | 'onCancel'>, { report }?: {
|
|
6
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
7
|
+
}): {
|
|
8
|
+
draft: string;
|
|
9
|
+
setDraft: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
10
|
+
finish: ({ cancel }?: {
|
|
11
|
+
cancel?: boolean | undefined;
|
|
12
|
+
}) => Promise<void>;
|
|
13
|
+
handleKeyDown: (event: KeyboardEvent<HTMLInputElement>) => void;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=ConversationTitleEditor.hooks.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createConsoleLogger } from '@jini-ai/core/primitives';
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { MAX_CONVERSATION_TITLE_LENGTH } from '../../core/conversation-title.js';
|
|
4
|
+
/** Commit or cancel a draft once, even when keyboard activation also triggers blur. */
|
|
5
|
+
export function useConversationTitleEditor({ title, onCommit, onCancel }, { report } = {}) {
|
|
6
|
+
const original = useRef(title ?? '');
|
|
7
|
+
const [draft, setDraft] = useState(original.current);
|
|
8
|
+
const finished = useRef(false);
|
|
9
|
+
// Enter/Escape can unmount a focused input and cause blur; only the first completion may act.
|
|
10
|
+
const finish = async ({ cancel = false } = {}) => {
|
|
11
|
+
if (finished.current)
|
|
12
|
+
return;
|
|
13
|
+
finished.current = true;
|
|
14
|
+
const next = draft.trim().slice(0, MAX_CONVERSATION_TITLE_LENGTH);
|
|
15
|
+
if (cancel || !next || draft === original.current) {
|
|
16
|
+
onCancel();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await onCommit(next);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const logger = report ?? createConsoleLogger({ prefix: '' });
|
|
24
|
+
logger.error({ message: '[@jini-ai/chat] ConversationTitleEditor onCommit host effect failed:' }, { error });
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const handleKeyDown = (event) => {
|
|
28
|
+
if (event.key === 'Enter' || event.key === 'Escape') {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
void finish({ cancel: event.key === 'Escape' });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return { draft, setDraft, finish, handleKeyDown };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=ConversationTitleEditor.hooks.js.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useConversationTitleEditor } from './ConversationTitleEditor.hooks.js';
|
|
4
4
|
import { MAX_CONVERSATION_TITLE_LENGTH } from '../../core/conversation-title.js';
|
|
5
5
|
import { useT } from '../hooks/context.js';
|
|
6
|
+
/** Hooks ConversationTitleEditor calls; defaults to the real ones, a test hands in fakes. */
|
|
7
|
+
export const defaultConversationTitleEditorHooks = { useT, useConversationTitleEditor };
|
|
6
8
|
/**
|
|
7
9
|
* Shared inline rename lifecycle. Enter/blur save once; Escape, empty and unchanged drafts cancel.
|
|
8
10
|
* Snapshots the raw title on mount so a background title refresh cannot become a user edit.
|
|
@@ -10,44 +12,19 @@ import { useT } from '../hooks/context.js';
|
|
|
10
12
|
* @complexity O(n) time/space to trim a draft of n code units; the saved title is bounded.
|
|
11
13
|
* @example <ConversationTitleEditor title={title} onCommit={rename} onCancel={close} />
|
|
12
14
|
*/
|
|
13
|
-
export function ConversationTitleEditor({ title, onCommit, onCancel, className = 'jini-conv-rename', 'data-testid': testId }) {
|
|
14
|
-
const t = useT();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const finished = useRef(false);
|
|
18
|
-
// Enter/Escape can unmount a focused input and cause blur; only the first completion may act.
|
|
19
|
-
const finish = async ({ cancel = false } = {}) => {
|
|
20
|
-
if (finished.current)
|
|
21
|
-
return;
|
|
22
|
-
finished.current = true;
|
|
23
|
-
const next = draft.trim().slice(0, MAX_CONVERSATION_TITLE_LENGTH);
|
|
24
|
-
if (cancel || !next || draft === original.current) {
|
|
25
|
-
onCancel();
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
await onCommit(next);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error('[@jini-ai/chat] ConversationTitleEditor onCommit host effect failed:', formatErrorForLog({ error }));
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return _jsx("input", { autoFocus: true, className: className, "aria-label": t('Rename chat'), "data-testid": testId, maxLength: MAX_CONVERSATION_TITLE_LENGTH, value: draft, onChange: (event) => setDraft(event.currentTarget.value), onBlur: () => { void finish(); }, onKeyDown: (event) => {
|
|
36
|
-
if (event.key === 'Enter' || event.key === 'Escape') {
|
|
37
|
-
event.preventDefault();
|
|
38
|
-
event.stopPropagation();
|
|
39
|
-
void finish({ cancel: event.key === 'Escape' });
|
|
40
|
-
}
|
|
41
|
-
} });
|
|
15
|
+
export function ConversationTitleEditor({ title, onCommit, onCancel, className = 'jini-conv-rename', 'data-testid': testId, hooks = defaultConversationTitleEditorHooks, report }) {
|
|
16
|
+
const t = hooks.useT();
|
|
17
|
+
const { draft, setDraft, finish, handleKeyDown } = hooks.useConversationTitleEditor({ title, onCommit, onCancel }, { report });
|
|
18
|
+
return _jsx("input", { autoFocus: true, className: className, "aria-label": t('Rename chat'), "data-testid": testId, maxLength: MAX_CONVERSATION_TITLE_LENGTH, value: draft, onChange: (event) => setDraft(event.currentTarget.value), onBlur: () => { void finish(); }, onKeyDown: handleKeyDown });
|
|
42
19
|
}
|
|
43
20
|
/** Clickable title using the same editor as ConversationList; a host keys it by conversation ID.
|
|
44
21
|
* @complexity O(1) outside the shared editor's draft normalization.
|
|
45
22
|
* @example <ConversationTitle key={id} title={rawTitle} displayTitle={label} onRename={rename} />
|
|
46
23
|
*/
|
|
47
|
-
export function ConversationTitle({ title, displayTitle, onRename, disabled = false }) {
|
|
48
|
-
const t =
|
|
24
|
+
export function ConversationTitle({ title, displayTitle, onRename, disabled = false, useTHook = useT, report }) {
|
|
25
|
+
const t = useTHook();
|
|
49
26
|
const [editing, setEditing] = useState(false);
|
|
50
|
-
return editing ? _jsx(ConversationTitleEditor, { title: title, onCancel: () => setEditing(false), onCommit: (next) => {
|
|
27
|
+
return editing ? _jsx(ConversationTitleEditor, { report: report, title: title, onCancel: () => setEditing(false), onCommit: (next) => {
|
|
51
28
|
setEditing(false);
|
|
52
29
|
return onRename(next);
|
|
53
30
|
} }) : _jsx("button", { type: "button", className: "jini-conv-title-button", "aria-label": t('Rename chat'), title: displayTitle, disabled: disabled, onClick: () => setEditing(true), children: displayTitle });
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** Shared message-copy affordance for ordinary messages and mid-run user receipts. */
|
|
2
|
+
import { useT } from '../hooks/context.js';
|
|
3
|
+
import { useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
|
|
1
4
|
interface CopyMessageButtonProps {
|
|
2
5
|
/** Inherited control identity; ordinary message-copy buttons remain opt-in. */
|
|
3
6
|
agentHandle?: string | false | undefined;
|
|
@@ -7,6 +10,8 @@ interface CopyMessageButtonProps {
|
|
|
7
10
|
label: string;
|
|
8
11
|
/** Optional hover tooltip; icon-only buttons outside a message action row have no other visible label. */
|
|
9
12
|
title?: string | undefined;
|
|
13
|
+
useTHook?: typeof useT;
|
|
14
|
+
useCopyToClipboardHook?: typeof useCopyToClipboard;
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
12
17
|
* Quiet, icon-only copy affordance shared by the user- and assistant-message
|
|
@@ -18,6 +23,6 @@ interface CopyMessageButtonProps {
|
|
|
18
23
|
* @param props.title - Optional hover tooltip (already translated); swaps to "Copied" like the label.
|
|
19
24
|
* @complexity O(1) — one child hook call, no branching beyond the copied-state read.
|
|
20
25
|
*/
|
|
21
|
-
export declare function CopyMessageButton({ agentHandle, text, label, title }: CopyMessageButtonProps): import("react").JSX.Element;
|
|
26
|
+
export declare function CopyMessageButton({ agentHandle, text, label, title, useTHook, useCopyToClipboardHook }: CopyMessageButtonProps): import("react").JSX.Element;
|
|
22
27
|
export {};
|
|
23
28
|
//# sourceMappingURL=CopyMessageButton.d.ts.map
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { useT } from '../hooks/context.js';
|
|
4
4
|
import { useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
|
|
5
5
|
import { Icon } from './Icon.js';
|
|
6
|
-
import { agentHandleProps } from '@jini-ai/
|
|
6
|
+
import { agentHandleProps } from '@jini-ai/core/agent-handles';
|
|
7
7
|
/**
|
|
8
8
|
* Quiet, icon-only copy affordance shared by the user- and assistant-message
|
|
9
9
|
* action rows. Delegates the actual clipboard write (and its
|
|
@@ -14,9 +14,9 @@ import { agentHandleProps } from '@jini-ai/agentic';
|
|
|
14
14
|
* @param props.title - Optional hover tooltip (already translated); swaps to "Copied" like the label.
|
|
15
15
|
* @complexity O(1) — one child hook call, no branching beyond the copied-state read.
|
|
16
16
|
*/
|
|
17
|
-
export function CopyMessageButton({ agentHandle, text, label, title }) {
|
|
18
|
-
const t =
|
|
19
|
-
const { copied, copy } =
|
|
17
|
+
export function CopyMessageButton({ agentHandle, text, label, title, useTHook = useT, useCopyToClipboardHook = useCopyToClipboard }) {
|
|
18
|
+
const t = useTHook();
|
|
19
|
+
const { copied, copy } = useCopyToClipboardHook();
|
|
20
20
|
return (_jsxs(_Fragment, { children: [_jsx("button", { ...agentHandleProps({}, { base: agentHandle || undefined, role: 'button', label }), type: "button", className: "jini-message-action-btn", "aria-label": copied ? t('Copied') : label, title: title && (copied ? t('Copied') : title), onClick: () => {
|
|
21
21
|
void copy(text);
|
|
22
22
|
}, children: _jsx(Icon, { name: copied ? 'check' : 'copy' }) }), _jsx("span", { className: "jini-message-copy-status", "aria-live": "polite", children: copied ? t('Copied to clipboard') : '' })] }));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Logger } from '@jini-ai/core/primitives';
|
|
1
2
|
/**
|
|
2
3
|
* @module ExtEventErrorBoundary
|
|
3
4
|
*
|
|
@@ -16,6 +17,7 @@
|
|
|
16
17
|
*/
|
|
17
18
|
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
18
19
|
export interface ExtEventErrorBoundaryProps {
|
|
20
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
19
21
|
/** The ext-event `name` this boundary wraps — surfaced in the fallback and passed to `onError`, so a host can tell which protocol/renderer failed. */
|
|
20
22
|
name: string;
|
|
21
23
|
/** Called once per catch, in addition to always rendering the built-in fallback — for a host that wants to log/report beyond what this module does on its own. */
|