@jini-ai/chat 0.7.3-next.2 → 0.7.3-next.4
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/README.md +49 -0
- package/dist/core/accepted-input.d.ts +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +14 -69
- package/dist/core/ag-ui/event-projection.js +58 -133
- package/dist/core/ag-ui/event-reduction.d.ts +12 -2
- package/dist/core/ag-ui/event-reduction.js +35 -10
- package/dist/core/ag-ui/resume.d.ts +110 -0
- package/dist/core/ag-ui/resume.js +200 -0
- package/dist/core/ag-ui/run-input.d.ts +23 -0
- package/dist/core/ag-ui/run-input.js +45 -0
- package/dist/core/ag-ui/server.d.ts +69 -0
- package/dist/core/ag-ui/server.js +71 -0
- package/dist/core/agent-plugin-chat-state.js +13 -11
- package/dist/core/assistant-client/ag-ui-approval-relay.d.ts +113 -0
- package/dist/core/assistant-client/ag-ui-approval-relay.js +287 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +25 -10
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +25 -6
- package/dist/core/assistant-client/ag-ui-transport.d.ts +86 -3
- package/dist/core/assistant-client/ag-ui-transport.js +310 -80
- package/dist/core/assistant-client/browser-durable-subscription.d.ts +25 -0
- package/dist/core/assistant-client/browser-durable-subscription.js +78 -0
- package/dist/core/assistant-client/durable-run-subscription.js +141 -130
- package/dist/core/assistant-client/entry.d.ts +2 -1
- package/dist/core/assistant-client/entry.js +1 -0
- package/dist/core/assistant-client/transport-prompt.d.ts +94 -0
- package/dist/core/assistant-client/transport-prompt.js +180 -0
- package/dist/core/assistant-client/transport-run.d.ts +49 -0
- package/dist/core/assistant-client/transport-run.js +432 -0
- package/dist/core/assistant-client/transport-stream.d.ts +73 -0
- package/dist/core/assistant-client/transport-stream.js +128 -0
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +129 -835
- package/dist/core/assistant-content.d.ts +1 -17
- package/dist/core/assistant-content.js +16 -0
- package/dist/core/assistant-tool-metadata.d.ts +103 -0
- package/dist/core/assistant-tool-metadata.js +56 -0
- package/dist/core/checkpoint-interval.d.ts +1 -1
- package/dist/core/compact-events.d.ts +1 -1
- package/dist/core/durable-projection.d.ts +1 -1
- package/dist/core/durable-runs/continuation.d.ts +1 -1
- package/dist/core/durable-runs/ledger-contracts.d.ts +4 -1
- package/dist/core/durable-runs/ports.d.ts +2 -1
- package/dist/core/durable-runs/run-contracts.d.ts +1 -1
- package/dist/core/durable-runs/run-finalizer.d.ts +145 -0
- package/dist/core/durable-runs/run-finalizer.js +171 -0
- package/dist/core/events.d.ts +4 -82
- package/dist/core/events.js +2 -1
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.js +2 -1
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/persistence/index.d.ts +1 -1
- package/dist/core/persistence/index.js +1 -1
- package/dist/core/question-form/normalize.d.ts +9 -3
- package/dist/core/question-form/normalize.js +20 -20
- package/dist/core/question-form/scan.js +15 -19
- package/dist/core/run-activity.d.ts +1 -1
- package/dist/core/run-events/entry.d.ts +11 -63
- package/dist/core/run-events/entry.js +12 -7
- package/dist/core/todos.d.ts +1 -1
- package/dist/core/todos.js +8 -0
- package/dist/core/tool-call-detail.d.ts +8 -1
- package/dist/core/tool-call-detail.js +35 -12
- package/dist/core/tool-events.d.ts +1 -1
- package/dist/core/tool-output.js +2 -6
- package/dist/core/tools.d.ts +2 -1
- package/dist/core/transport.d.ts +1 -1
- package/dist/core/turn-usage.d.ts +1 -1
- package/dist/core/util/parser.js +70 -69
- package/dist/embed-widget/browser/embed-send-bridge.d.ts +44 -0
- package/dist/embed-widget/browser/embed-send-bridge.js +60 -0
- package/dist/embed-widget/browser/frontend-invocation-handler.d.ts +39 -0
- package/dist/embed-widget/browser/frontend-invocation-handler.js +151 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +28 -0
- package/dist/embed-widget/browser/frontend-session-bridge.js +201 -257
- package/dist/embed-widget/browser/lazy-loader.js +16 -12
- package/dist/embed-widget/browser/session-store.d.ts +19 -1
- package/dist/embed-widget/browser/session-store.js +48 -17
- package/dist/embed-widget/transports/fetch-sse.d.ts +1 -1
- package/dist/embed-widget/vanilla/index.js +131 -67
- package/dist/embed-widget/vanilla/state.js +53 -38
- package/dist/react/admin-execution/ai-agent-presentation.d.ts +35 -0
- package/dist/react/admin-execution/ai-agent-presentation.js +39 -0
- package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.d.ts +22 -0
- package/dist/react/admin-execution/hooks/use-ai-agent-presentation.hooks.js +25 -0
- package/dist/react/chat-cleanup/ChatCleanupPanel.d.ts +32 -0
- package/dist/react/chat-cleanup/ChatCleanupPanel.js +34 -0
- package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +174 -0
- package/dist/react/chat-cleanup/chat-cleanup.hooks.js +83 -0
- package/dist/react/components/ChatCleanupDialog.d.ts +38 -0
- package/dist/react/components/ChatCleanupDialog.js +15 -0
- package/dist/react/components/ChatSettingsDialog.d.ts +3 -0
- package/dist/react/components/ChatSettingsDialog.js +3 -3
- package/dist/react/components/ConversationList.d.ts +19 -5
- package/dist/react/components/ConversationList.hooks.d.ts +1 -0
- package/dist/react/components/ConversationList.hooks.js +4 -2
- package/dist/react/components/ConversationList.js +66 -9
- package/dist/react/components/Icon.d.ts +1 -1
- package/dist/react/components/Icon.js +7 -0
- package/dist/react/components/Markdown.js +6 -6
- package/dist/react/components/MarkdownLink.d.ts +25 -0
- package/dist/react/components/MarkdownLink.js +17 -0
- package/dist/react/components/RoutedA2uiSurfaceCard.d.ts +80 -0
- package/dist/react/components/RoutedA2uiSurfaceCard.js +15 -0
- package/dist/react/components/ToolCard.d.ts +4 -2
- package/dist/react/components/ToolCard.js +46 -4
- package/dist/react/components/ToolCard.rules.d.ts +5 -2
- package/dist/react/components/ToolCard.rules.js +12 -5
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-surface-state.d.ts +3 -1
- package/dist/react/components/mcp-ui-surface-state.js +2 -2
- package/dist/react/components/own-link.d.ts +26 -0
- package/dist/react/components/own-link.js +36 -0
- package/dist/react/features/bridged-chat/create-staged-attachment-uploader.d.ts +7 -0
- package/dist/react/features/bridged-chat/create-staged-attachment-uploader.js +26 -0
- package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.d.ts +12 -0
- package/dist/react/features/bridged-chat/hooks/useBridgedChatTransport.hooks.js +60 -0
- package/dist/react/features/bridged-chat/index.d.ts +8 -0
- package/dist/react/features/bridged-chat/index.js +7 -0
- package/dist/react/features/bridged-chat/types.d.ts +49 -0
- package/dist/react/features/bridged-chat/types.js +2 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +1 -1
- package/dist/react/features/chat-pane/create-daemon-attachment-uploader.d.ts +6 -0
- package/dist/react/features/chat-pane/create-daemon-attachment-uploader.js +101 -59
- package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.d.ts +3 -0
- package/dist/react/features/chat-pane/hooks/useChatPaneNewTabLinks.hooks.js +26 -16
- package/dist/react/features/chat-pane/model-options.d.ts +3 -1
- package/dist/react/features/chat-pane/model-options.js +3 -3
- package/dist/react/features/chat-pane/rules.js +4 -3
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +16 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.d.ts +10 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPane.js +19 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.d.ts +12 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneChat.js +21 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.d.ts +13 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationChatPaneHeader.js +9 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.d.ts +12 -0
- package/dist/react/features/conversation-chat-pane/components/ConversationDeleteConfirm.js +12 -0
- package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.d.ts +7 -0
- package/dist/react/features/conversation-chat-pane/hooks/useConversationChatPane.hooks.js +43 -0
- package/dist/react/features/conversation-chat-pane/index.d.ts +9 -0
- package/dist/react/features/conversation-chat-pane/index.js +8 -0
- package/dist/react/features/conversation-chat-pane/rules.d.ts +25 -0
- package/dist/react/features/conversation-chat-pane/rules.js +29 -0
- package/dist/react/features/conversation-chat-pane/types.d.ts +139 -0
- package/dist/react/features/conversation-chat-pane/types.js +2 -0
- package/dist/react/features/conversations/conversation-controller.d.ts +16 -0
- package/dist/react/features/conversations/conversation-controller.js +280 -0
- package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.d.ts +15 -0
- package/dist/react/features/conversations/hooks/useConversationDeleteConfirmation.hooks.js +33 -0
- package/dist/react/features/conversations/hooks/useStoredConversations.hooks.d.ts +16 -0
- package/dist/react/features/conversations/hooks/useStoredConversations.hooks.js +36 -0
- package/dist/react/features/conversations/index.d.ts +9 -0
- package/dist/react/features/conversations/index.js +8 -0
- package/dist/react/features/conversations/types.d.ts +120 -0
- package/dist/react/features/conversations/types.js +2 -0
- package/dist/react/features/voice-input/space-hold-rules.d.ts +65 -0
- package/dist/react/features/voice-input/space-hold-rules.js +48 -0
- package/dist/react/hooks/testing/fake-transport.d.ts +1 -1
- package/dist/react/hooks/useAnsweredCards.d.ts +2 -1
- package/dist/react/hooks/useConversation.js +5 -2
- package/dist/react/hooks/useExtEventGroups.d.ts +1 -1
- package/dist/react/hooks/useRunActivity.d.ts +2 -1
- package/dist/react/hooks/useRunStream.d.ts +1 -1
- package/dist/react/hooks/useRunStream.js +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +3 -1
- package/dist/react/hooks/useToolTimeline.d.ts +2 -1
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +4 -2
- package/dist/react/message-blocks.d.ts +1 -48
- package/dist/react/message-blocks.js +47 -0
- package/dist/react/styles/chat-settings.css +42 -14
- package/dist/server/chat-cleanup-routes.d.ts +56 -0
- package/dist/server/chat-cleanup-routes.js +56 -0
- package/dist/server/durable-runs/recover.js +193 -171
- package/dist/server/run-finalizer/entry.js +133 -110
- package/dist/store/legacy/sqlite/conversations.js +29 -17
- package/dist/store/pglite/index.d.ts +1 -0
- package/dist/store/pglite/index.js +1 -0
- package/dist/store/ports.d.ts +12 -0
- package/dist/store/postgres/index.d.ts +1 -0
- package/dist/store/postgres/index.js +1 -0
- package/dist/store/runtime/attempt-base-retention.d.ts +57 -0
- package/dist/store/runtime/attempt-base-retention.js +103 -0
- package/dist/store/runtime/chat-maintenance.d.ts +16 -0
- package/dist/store/runtime/chat-maintenance.js +19 -0
- package/dist/store/runtime/chat-principal.d.ts +63 -0
- package/dist/store/runtime/chat-principal.js +39 -0
- package/dist/store/runtime/checkpoint-delta.d.ts +1 -1
- package/dist/store/runtime/durable-run-queries.d.ts +124 -0
- package/dist/store/runtime/durable-run-queries.js +122 -0
- package/dist/store/runtime/durable-run-store.d.ts +1 -1
- package/dist/store/runtime/durable-run-store.js +291 -343
- package/dist/store/runtime/entry.d.ts +3 -0
- package/dist/store/runtime/entry.js +3 -0
- package/dist/store/runtime/events-json.d.ts +1 -1
- package/dist/store/runtime/lazy-run-ledger.d.ts +19 -0
- package/dist/store/runtime/lazy-run-ledger.js +28 -0
- package/dist/store/runtime/run-ledger.d.ts +4 -1
- package/dist/store/runtime/run-ledger.js +256 -204
- package/dist/store/sql/bulk-deletion.d.ts +36 -0
- package/dist/store/sql/bulk-deletion.js +103 -0
- package/dist/store/sql/store-queries.d.ts +170 -0
- package/dist/store/sql/store-queries.js +212 -0
- package/dist/store/sql/store-rows.d.ts +106 -0
- package/dist/store/sql/store-rows.js +116 -0
- package/dist/store/sql/store-writes.d.ts +46 -0
- package/dist/store/sql/store-writes.js +161 -0
- package/dist/store/sql/store.d.ts +3 -16
- package/dist/store/sql/store.js +58 -428
- package/dist/store/sql/tables.d.ts +1 -0
- package/dist/store/sqlite/index.d.ts +1 -0
- package/dist/store/sqlite/index.js +1 -0
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/dist/store/sqlite/schema.js +5 -1
- package/package.json +171 -20
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/chat/react/conversation-chat-pane` — `ConversationChatPane` (a conversation switcher +
|
|
3
|
+
* `ChatPane` composition) and its hook, rules and types. See this folder's README for the wiring.
|
|
4
|
+
*/
|
|
5
|
+
export { ConversationChatPane } from './components/ConversationChatPane.js';
|
|
6
|
+
export { useConversationChatPane } from './hooks/useConversationChatPane.hooks.js';
|
|
7
|
+
export { conversationListView, selectionRunContext } from './rules.js';
|
|
8
|
+
export type { ConversationChatPaneComponents, ConversationChatPaneConversations, ConversationChatPaneDeleteConfirmation, ConversationChatPaneFolderDrop, ConversationChatPaneHooks, ConversationChatPaneInput, ConversationChatPaneLabels, ConversationChatPaneProps, ConversationChatPaneState, ConversationChatPaneTransport, ConversationListView, } from './types.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/chat/react/conversation-chat-pane` — `ConversationChatPane` (a conversation switcher +
|
|
3
|
+
* `ChatPane` composition) and its hook, rules and types. See this folder's README for the wiring.
|
|
4
|
+
*/
|
|
5
|
+
export { ConversationChatPane } from './components/ConversationChatPane.js';
|
|
6
|
+
export { useConversationChatPane } from './hooks/useConversationChatPane.hooks.js';
|
|
7
|
+
export { conversationListView, selectionRunContext } from './rules.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConversationChatPaneConversations, ConversationListView } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The picker's model/reasoning choice reaches the transport through `runContext`, not through
|
|
4
|
+
* `startRun`'s own arguments: `ChatTransport.StartRunInput` carries `agentId` but nothing about how
|
|
5
|
+
* that agent should be configured, and `context` is the port's designated opaque per-host payload.
|
|
6
|
+
*
|
|
7
|
+
* An unset `model` or `reasoning` is left out of the context entirely rather than sent as
|
|
8
|
+
* `undefined`. `satisfies` rather than a `ChatPaneRunContext` annotation so the constant keeps its
|
|
9
|
+
* callable type — `ChatPaneRunContext` is a union with a plain object, which a test cannot call.
|
|
10
|
+
*/
|
|
11
|
+
export declare const selectionRunContext: ({ selection }: import("../chat-pane/types.js").ChatPaneRunContextInput) => {
|
|
12
|
+
reasoning?: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The two values the pane derives from the host's conversations hook.
|
|
17
|
+
*
|
|
18
|
+
* `listItems` is a shallow copy: `ConversationListItem[]` (mutable) is `ConversationList`'s own prop
|
|
19
|
+
* type, while a host's conversations hook may return `readonly` for consistency with its other
|
|
20
|
+
* lists, so the boundary copies here rather than widening the host hook's contract for one caller.
|
|
21
|
+
*
|
|
22
|
+
* @complexity O(n) in the number of conversations (the copy).
|
|
23
|
+
*/
|
|
24
|
+
export declare function conversationListView({ conversations, activeId }: Pick<ConversationChatPaneConversations, 'conversations' | 'activeId'>, _optional?: Record<string, never>): ConversationListView;
|
|
25
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picker's model/reasoning choice reaches the transport through `runContext`, not through
|
|
3
|
+
* `startRun`'s own arguments: `ChatTransport.StartRunInput` carries `agentId` but nothing about how
|
|
4
|
+
* that agent should be configured, and `context` is the port's designated opaque per-host payload.
|
|
5
|
+
*
|
|
6
|
+
* An unset `model` or `reasoning` is left out of the context entirely rather than sent as
|
|
7
|
+
* `undefined`. `satisfies` rather than a `ChatPaneRunContext` annotation so the constant keeps its
|
|
8
|
+
* callable type — `ChatPaneRunContext` is a union with a plain object, which a test cannot call.
|
|
9
|
+
*/
|
|
10
|
+
export const selectionRunContext = (({ selection }) => ({
|
|
11
|
+
...(selection.model === undefined ? {} : { model: selection.model }),
|
|
12
|
+
...(selection.reasoning === undefined ? {} : { reasoning: selection.reasoning }),
|
|
13
|
+
}));
|
|
14
|
+
/**
|
|
15
|
+
* The two values the pane derives from the host's conversations hook.
|
|
16
|
+
*
|
|
17
|
+
* `listItems` is a shallow copy: `ConversationListItem[]` (mutable) is `ConversationList`'s own prop
|
|
18
|
+
* type, while a host's conversations hook may return `readonly` for consistency with its other
|
|
19
|
+
* lists, so the boundary copies here rather than widening the host hook's contract for one caller.
|
|
20
|
+
*
|
|
21
|
+
* @complexity O(n) in the number of conversations (the copy).
|
|
22
|
+
*/
|
|
23
|
+
export function conversationListView({ conversations, activeId }, _optional = {}) {
|
|
24
|
+
return {
|
|
25
|
+
listItems: [...conversations],
|
|
26
|
+
conversationIdProp: activeId === null ? {} : { conversationId: activeId },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the conversation-chat-pane feature: the three host hooks it requires (structural, so a
|
|
3
|
+
* host's own hooks fit without importing anything from here), the injected copy, and the state the
|
|
4
|
+
* pane's hook hands its markup.
|
|
5
|
+
*/
|
|
6
|
+
import type { ComponentType, Dispatch, DragEvent, RefObject, SetStateAction } from 'react';
|
|
7
|
+
import type { ConversationListItem, ConversationListProps } from '../../components/ConversationList.js';
|
|
8
|
+
import type { ChatPaneComposerHandle, ChatPaneProps } from '../chat-pane/index.js';
|
|
9
|
+
/** What the host's `useTransport` returns. Every member is `undefined` without a host bridge. */
|
|
10
|
+
export interface ConversationChatPaneTransport {
|
|
11
|
+
transport: ChatPaneProps['transport'] | undefined;
|
|
12
|
+
runtimeAccess: ChatPaneProps['runtimeAccess'];
|
|
13
|
+
workingDirectoryAccess: ChatPaneProps['workingDirectoryAccess'];
|
|
14
|
+
/** The host's dropped-file path lookup; `undefined` leaves every drop to `ChatPane`. */
|
|
15
|
+
getPathForFile: ((file: File) => string) | undefined;
|
|
16
|
+
uploadAttachments: ChatPaneProps['uploadAttachments'];
|
|
17
|
+
}
|
|
18
|
+
/** What the host's `useConversations` returns: the persisted threads and the open one. */
|
|
19
|
+
export interface ConversationChatPaneConversations {
|
|
20
|
+
conversations: readonly ConversationListItem[];
|
|
21
|
+
activeId: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* `ChatPane`'s `key`, deliberately not `activeId`: `activeId` also moves when an untitled pane
|
|
24
|
+
* adopts a freshly created conversation mid-turn, and re-keying on that would remount the pane
|
|
25
|
+
* out from under the reply it is streaming. `paneKey` changes only on a real switch.
|
|
26
|
+
*/
|
|
27
|
+
paneKey: string;
|
|
28
|
+
initialMessages: NonNullable<ChatPaneProps['initialMessages']>;
|
|
29
|
+
select: (id: string) => void;
|
|
30
|
+
create: () => void | Promise<void>;
|
|
31
|
+
remove: (id: string) => void | Promise<void>;
|
|
32
|
+
rename: (id: string, title: string) => void | Promise<void>;
|
|
33
|
+
onMessagesChange: NonNullable<ChatPaneProps['onMessagesChange']>;
|
|
34
|
+
}
|
|
35
|
+
/** What the host's `useDeleteConfirmation` returns: an inline (never native-modal) delete confirm. */
|
|
36
|
+
export interface ConversationChatPaneDeleteConfirmation {
|
|
37
|
+
/** The title asking to be confirmed, or `null` when nothing is pending. */
|
|
38
|
+
pendingTitle: string | null;
|
|
39
|
+
/** `ConversationList`'s `confirmDelete`; resolves when the inline confirmation is answered. */
|
|
40
|
+
confirmDelete: (item: ConversationListItem) => boolean | Promise<boolean>;
|
|
41
|
+
/** Answers the pending confirmation, if any. */
|
|
42
|
+
resolvePending: (input: {
|
|
43
|
+
confirmed: boolean;
|
|
44
|
+
}) => void;
|
|
45
|
+
}
|
|
46
|
+
/** The three host hooks. Required, with no defaults: each must keep its call position stable. */
|
|
47
|
+
export interface ConversationChatPaneHooks {
|
|
48
|
+
useTransport: () => ConversationChatPaneTransport;
|
|
49
|
+
useConversations: () => ConversationChatPaneConversations;
|
|
50
|
+
useDeleteConfirmation: () => ConversationChatPaneDeleteConfirmation;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The capture-phase folder-drop rule, injected by the host (`@jini-ai/ui/core`'s
|
|
54
|
+
* `captureFolderPathDrop` fits): a drop carrying a FOLDER is swallowed and its path written into
|
|
55
|
+
* `composer` as text; any other drop, or any drop without a `port`, passes through untouched.
|
|
56
|
+
*/
|
|
57
|
+
export type ConversationChatPaneFolderDrop = (input: {
|
|
58
|
+
event: {
|
|
59
|
+
readonly dataTransfer: DataTransfer;
|
|
60
|
+
preventDefault(): void;
|
|
61
|
+
stopPropagation(): void;
|
|
62
|
+
};
|
|
63
|
+
port: {
|
|
64
|
+
getPathForFile(file: File): string;
|
|
65
|
+
} | undefined;
|
|
66
|
+
composer: {
|
|
67
|
+
readonly current: {
|
|
68
|
+
insertText(text: string): void;
|
|
69
|
+
} | null;
|
|
70
|
+
};
|
|
71
|
+
}) => unknown;
|
|
72
|
+
/** The pane hook's input: the three host hooks plus the injected folder-drop rule. */
|
|
73
|
+
export interface ConversationChatPaneInput extends ConversationChatPaneHooks {
|
|
74
|
+
captureFolderDrop: ConversationChatPaneFolderDrop;
|
|
75
|
+
}
|
|
76
|
+
/** Every visible string the pane renders. The pane ships no default copy. */
|
|
77
|
+
export interface ConversationChatPaneLabels {
|
|
78
|
+
/** The `<aside>`'s accessible name. */
|
|
79
|
+
paneAriaLabel: string;
|
|
80
|
+
/** The small line above the title. */
|
|
81
|
+
eyebrow: string;
|
|
82
|
+
title: string;
|
|
83
|
+
/** The close button's visible glyph or text, and its accessible name. */
|
|
84
|
+
close: string;
|
|
85
|
+
closeAriaLabel: string;
|
|
86
|
+
confirmDeleteAriaLabel: string;
|
|
87
|
+
/** The inline delete prompt for the pending conversation's title. */
|
|
88
|
+
deletePrompt: (input: {
|
|
89
|
+
title: string;
|
|
90
|
+
}) => string;
|
|
91
|
+
cancel: string;
|
|
92
|
+
delete: string;
|
|
93
|
+
/** Shown instead of the chat while the host has no transport or runtime access. */
|
|
94
|
+
unavailable: string;
|
|
95
|
+
/** The composer placeholder. */
|
|
96
|
+
placeholder: string;
|
|
97
|
+
}
|
|
98
|
+
/** What the pane hands `ConversationList` and `ChatPane`, derived from the conversations hook. */
|
|
99
|
+
export interface ConversationListView {
|
|
100
|
+
/** `ConversationList`'s `conversations` (a mutable copy of the readonly list). */
|
|
101
|
+
listItems: ConversationListItem[];
|
|
102
|
+
/** Spread onto `ChatPane`: `{}` while nothing is active, so no `conversationId` prop is passed. */
|
|
103
|
+
conversationIdProp: {
|
|
104
|
+
conversationId?: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export interface ConversationChatPaneState extends ConversationListView {
|
|
108
|
+
transport: ConversationChatPaneTransport['transport'];
|
|
109
|
+
runtimeAccess: ConversationChatPaneTransport['runtimeAccess'];
|
|
110
|
+
workingDirectoryAccess: ConversationChatPaneTransport['workingDirectoryAccess'];
|
|
111
|
+
uploadAttachments: ConversationChatPaneTransport['uploadAttachments'];
|
|
112
|
+
conversations: ConversationChatPaneConversations;
|
|
113
|
+
deleteConfirmation: ConversationChatPaneDeleteConfirmation;
|
|
114
|
+
/** The working-directory picker's value. */
|
|
115
|
+
workingDirectory: string | null;
|
|
116
|
+
setWorkingDirectory: Dispatch<SetStateAction<string | null>>;
|
|
117
|
+
/** Handed to `ChatPane`, which populates it once mounted. */
|
|
118
|
+
composerHandle: RefObject<ChatPaneComposerHandle | null>;
|
|
119
|
+
/** The `<aside>`'s capture-phase `onDropCapture` (the injected `captureFolderDrop`). */
|
|
120
|
+
onDropCapture: (event: DragEvent<HTMLElement>) => void;
|
|
121
|
+
}
|
|
122
|
+
/** The two components the pane composes; omitted entries get this package's real ones. */
|
|
123
|
+
export interface ConversationChatPaneComponents {
|
|
124
|
+
ConversationList?: ComponentType<ConversationListProps>;
|
|
125
|
+
ChatPane?: ComponentType<ChatPaneProps>;
|
|
126
|
+
}
|
|
127
|
+
export interface ConversationChatPaneProps extends ConversationChatPaneInput {
|
|
128
|
+
conversationListHooks: ConversationListProps['hooks'];
|
|
129
|
+
onClose: () => void;
|
|
130
|
+
/** The pane's state hook; pass `useConversationChatPane` from this entry. Required: no default hook. */
|
|
131
|
+
useConversationChatPaneHook: (input: ConversationChatPaneInput) => ConversationChatPaneState;
|
|
132
|
+
labels: ConversationChatPaneLabels;
|
|
133
|
+
variant?: ChatPaneProps['variant'];
|
|
134
|
+
/** Added beside `jini-conversation-chat-pane` on the `<aside>`, for a host's own skin. */
|
|
135
|
+
className?: string;
|
|
136
|
+
/** Test/host seam for the composed chat components. */
|
|
137
|
+
components?: ConversationChatPaneComponents;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ConversationController, ConversationLog, ConversationState, ConversationStorePort, ConversationSummaryLike } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the controller. Nothing is read from the bridge until a method is called — the initial
|
|
4
|
+
* list load is the caller's `refresh()`.
|
|
5
|
+
* @param bridge the host's conversation store; `undefined` when the host has none (every action
|
|
6
|
+
* is then a no-op).
|
|
7
|
+
* @param log where failures are reported; defaults to `console.error`, looked up at call time.
|
|
8
|
+
* @param onChange called with each newly published state, before subscribers are notified.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createConversationController<S extends ConversationSummaryLike = ConversationSummaryLike>({ bridge }: {
|
|
11
|
+
bridge: ConversationStorePort<S> | undefined;
|
|
12
|
+
}, { log, onChange }?: {
|
|
13
|
+
log?: ConversationLog;
|
|
14
|
+
onChange?: (state: ConversationState<S>) => void;
|
|
15
|
+
}): ConversationController<S>;
|
|
16
|
+
//# sourceMappingURL=conversation-controller.d.ts.map
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { persistableMessages } from '../../../core/assistant-client/messages.js';
|
|
2
|
+
const INITIAL_STATE = { conversations: [], activeId: null, paneKey: 'new', initialMessages: [] };
|
|
3
|
+
/**
|
|
4
|
+
* Builds the controller. Nothing is read from the bridge until a method is called — the initial
|
|
5
|
+
* list load is the caller's `refresh()`.
|
|
6
|
+
* @param bridge the host's conversation store; `undefined` when the host has none (every action
|
|
7
|
+
* is then a no-op).
|
|
8
|
+
* @param log where failures are reported; defaults to `console.error`, looked up at call time.
|
|
9
|
+
* @param onChange called with each newly published state, before subscribers are notified.
|
|
10
|
+
*/
|
|
11
|
+
export function createConversationController({ bridge }, { log = (...args) => console.error(...args), onChange } = {}) {
|
|
12
|
+
const core = {
|
|
13
|
+
bridge, log, onChange, listeners: new Set(), state: INITIAL_STATE, written: new Map(),
|
|
14
|
+
switchSeq: 0, navigating: false, adopting: null, adoptionGen: 0, paneNonce: 0, deleted: new Set(),
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
getState: () => core.state,
|
|
18
|
+
subscribe: ({ listener }) => subscribe({ core, listener }),
|
|
19
|
+
refresh: () => refresh(core),
|
|
20
|
+
select: ({ id }) => select({ core, id }),
|
|
21
|
+
create: () => create(core),
|
|
22
|
+
remove: ({ id }) => remove({ core, id }),
|
|
23
|
+
rename: ({ id, title }) => rename({ core, id, title }),
|
|
24
|
+
onMessagesChange: ({ messages }) => onMessagesChange({ core, messages }),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function subscribe({ core, listener }, _options = {}) {
|
|
28
|
+
core.listeners.add(listener);
|
|
29
|
+
return () => {
|
|
30
|
+
core.listeners.delete(listener);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Replaces state immutably and tells everyone listening. */
|
|
34
|
+
function publish({ core, patch }, _options = {}) {
|
|
35
|
+
core.state = { ...core.state, ...patch };
|
|
36
|
+
core.onChange?.(core.state);
|
|
37
|
+
for (const listener of core.listeners)
|
|
38
|
+
listener();
|
|
39
|
+
}
|
|
40
|
+
function resetAdoption(core) {
|
|
41
|
+
core.adopting = null;
|
|
42
|
+
core.adoptionGen += 1;
|
|
43
|
+
}
|
|
44
|
+
/** Invalidate pane adoption at navigation intent, retaining its promise for outgoing deltas.
|
|
45
|
+
* @returns The latest navigation sequence. @complexity O(1), controller state only.
|
|
46
|
+
*/
|
|
47
|
+
function beginSwitch(core, _options = {}) {
|
|
48
|
+
core.switchSeq += 1;
|
|
49
|
+
core.adoptionGen += 1;
|
|
50
|
+
core.navigating = true;
|
|
51
|
+
return core.switchSeq;
|
|
52
|
+
}
|
|
53
|
+
function withConversation({ core, conversation }, _options = {}) {
|
|
54
|
+
return [conversation, ...core.state.conversations];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Falls back to the list last published — which is what `remove` needs when its own `refresh()`
|
|
58
|
+
* lands stale: the optimistic filter it just published is already in that list.
|
|
59
|
+
*/
|
|
60
|
+
async function refresh(core) {
|
|
61
|
+
if (core.bridge === undefined)
|
|
62
|
+
return core.state.conversations;
|
|
63
|
+
try {
|
|
64
|
+
// A list requested before deletion may finish afterwards. Tombstones govern every
|
|
65
|
+
// publication, not only remove's own follow-up request.
|
|
66
|
+
const list = (await core.bridge.listConversations()).filter(c => !core.deleted.has(c.id));
|
|
67
|
+
publish({ core, patch: { conversations: list } });
|
|
68
|
+
return list;
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
core.log('could not load conversations —', err);
|
|
72
|
+
return core.state.conversations;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function select({ core, id }, _options = {}) {
|
|
76
|
+
const bridge = core.bridge;
|
|
77
|
+
if (bridge === undefined || core.deleted.has(id))
|
|
78
|
+
return;
|
|
79
|
+
const seq = beginSwitch(core);
|
|
80
|
+
const commit = (messages) => commitSelection({ core, id, seq, messages });
|
|
81
|
+
void bridge
|
|
82
|
+
.loadConversationMessages({ conversationId: id })
|
|
83
|
+
.then(commit)
|
|
84
|
+
// A failed load still switches, to an empty pane — leaving the user on the previous
|
|
85
|
+
// conversation while the switcher already says otherwise is the worse of the two failures.
|
|
86
|
+
.catch((err) => {
|
|
87
|
+
core.log(`could not load conversation ${id} —`, err);
|
|
88
|
+
commit([]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Only `select` publishes id, transcript and written-ids together, in the order that keeps a
|
|
93
|
+
* remount from ever showing an empty pane under a non-empty switcher entry.
|
|
94
|
+
*/
|
|
95
|
+
function commitSelection({ core, id, seq, messages }, _options = {}) {
|
|
96
|
+
// A slower load for a conversation the user has since navigated away from must not land.
|
|
97
|
+
if (core.switchSeq !== seq)
|
|
98
|
+
return;
|
|
99
|
+
core.navigating = false;
|
|
100
|
+
if (core.deleted.has(id))
|
|
101
|
+
return;
|
|
102
|
+
core.written.set(id, new Set(messages.map((m) => m.id)));
|
|
103
|
+
resetAdoption(core);
|
|
104
|
+
// A deliberate switch is exactly when remounting the pane IS the intent.
|
|
105
|
+
publish({ core, patch: { initialMessages: messages, activeId: id, paneKey: id } });
|
|
106
|
+
}
|
|
107
|
+
async function create(core) {
|
|
108
|
+
const bridge = core.bridge;
|
|
109
|
+
if (bridge === undefined)
|
|
110
|
+
return;
|
|
111
|
+
// Claimed BEFORE the request and re-checked after, so a selection made after the click (while
|
|
112
|
+
// the create is still in flight) wins rather than yanking the user back into a new, empty
|
|
113
|
+
// pane the moment the slower create resolves.
|
|
114
|
+
const seq = beginSwitch(core);
|
|
115
|
+
let conversation;
|
|
116
|
+
try {
|
|
117
|
+
conversation = await bridge.createConversation();
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (core.switchSeq === seq)
|
|
121
|
+
core.navigating = false;
|
|
122
|
+
}
|
|
123
|
+
if (core.deleted.has(conversation.id))
|
|
124
|
+
return;
|
|
125
|
+
const conversations = withConversation({ core, conversation });
|
|
126
|
+
if (core.switchSeq !== seq) {
|
|
127
|
+
publish({ core, patch: { conversations } });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
core.written.set(conversation.id, new Set());
|
|
131
|
+
resetAdoption(core);
|
|
132
|
+
publish({ core, patch: { conversations, activeId: conversation.id, initialMessages: [], paneKey: conversation.id } });
|
|
133
|
+
}
|
|
134
|
+
async function remove({ core, id }, _options = {}) {
|
|
135
|
+
const bridge = core.bridge;
|
|
136
|
+
if (bridge === undefined)
|
|
137
|
+
return;
|
|
138
|
+
await bridge.deleteConversation({ id });
|
|
139
|
+
core.written.delete(id);
|
|
140
|
+
core.deleted.add(id);
|
|
141
|
+
// The delete succeeded, so the thread leaves the switcher now — and is filtered out of what
|
|
142
|
+
// `refresh` returns, whose failure fallback is the list still on screen (deleted row included).
|
|
143
|
+
publish({ core, patch: { conversations: core.state.conversations.filter((c) => c.id !== id) } });
|
|
144
|
+
const list = (await refresh(core)).filter((c) => c.id !== id);
|
|
145
|
+
if (core.state.activeId !== id)
|
|
146
|
+
return;
|
|
147
|
+
const next = list[0]?.id ?? null;
|
|
148
|
+
if (next === null) {
|
|
149
|
+
landOnFreshPane(core);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// `select`, deliberately, not a raw publish of `activeId: next` — see `commitSelection`'s doc:
|
|
153
|
+
// only `select` publishes id, transcript and written-ids together, in the order that keeps a
|
|
154
|
+
// remount from ever showing an empty pane under a non-empty switcher entry.
|
|
155
|
+
select({ core, id: next });
|
|
156
|
+
}
|
|
157
|
+
/** `remove` of the open thread when no other thread is left. */
|
|
158
|
+
function landOnFreshPane(core) {
|
|
159
|
+
// Nothing left to land on. Bump the token so a switch already in flight cannot resurrect a
|
|
160
|
+
// transcript into what is about to become an empty pane.
|
|
161
|
+
core.switchSeq += 1;
|
|
162
|
+
core.navigating = false;
|
|
163
|
+
core.paneNonce += 1;
|
|
164
|
+
// This is the one place `activeId` goes back to `null`, which is the only state that
|
|
165
|
+
// re-enters the lazy-adoption path below — without this reset, the fresh pane would
|
|
166
|
+
// inherit the deleted conversation's adoption and never persist again.
|
|
167
|
+
resetAdoption(core);
|
|
168
|
+
publish({ core, patch: { activeId: null, initialMessages: [], paneKey: `new-${core.paneNonce}` } });
|
|
169
|
+
}
|
|
170
|
+
async function rename({ core, id, title }, _options = {}) {
|
|
171
|
+
const bridge = core.bridge;
|
|
172
|
+
if (bridge === undefined)
|
|
173
|
+
return;
|
|
174
|
+
// Optimistic: a rename that only appears after a round trip feels broken mid-edit.
|
|
175
|
+
publish({ core, patch: { conversations: core.state.conversations.map((c) => (c.id === id ? { ...c, title } : c)) } });
|
|
176
|
+
try {
|
|
177
|
+
await bridge.renameConversation({ id, title });
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
core.log(`could not rename conversation ${id} —`, err);
|
|
181
|
+
}
|
|
182
|
+
void refresh(core);
|
|
183
|
+
}
|
|
184
|
+
/** Writes whatever in `messages` has settled and is not already stored, into `conversationId`. */
|
|
185
|
+
function flush({ core, conversationId, messages }, _options = {}) {
|
|
186
|
+
const bridge = core.bridge;
|
|
187
|
+
if (bridge === undefined || core.deleted.has(conversationId))
|
|
188
|
+
return;
|
|
189
|
+
// Always registered by now: every id that can reach here got its set when it became flushable
|
|
190
|
+
// — `select`'s commit, `create` and lazy adoption each register one before `activeId` (or the
|
|
191
|
+
// adoption's own flush) can name it — and `remove` drops a set only after marking the id
|
|
192
|
+
// deleted, which the guard above returns on first. (This used to fall back to a fresh set,
|
|
193
|
+
// which no path could reach.)
|
|
194
|
+
const written = core.written.get(conversationId);
|
|
195
|
+
const pending = persistableMessages({ messages }, { includePendingUser: true }).filter((m) => !written.has(m.id));
|
|
196
|
+
if (pending.length === 0)
|
|
197
|
+
return;
|
|
198
|
+
// Marked before the request resolves so a second `onMessagesChange` arriving mid-flight —
|
|
199
|
+
// which it will, since deltas keep coming — does not queue the same message twice.
|
|
200
|
+
for (const message of pending)
|
|
201
|
+
written.add(message.id);
|
|
202
|
+
for (const message of pending)
|
|
203
|
+
saveMessage({ core, bridge, conversationId, message, written });
|
|
204
|
+
// The first turn is what gives an untitled conversation its auto-generated title, and every
|
|
205
|
+
// turn changes `messageCount`/`updatedAt` — re-read rather than patch, so the switcher stays
|
|
206
|
+
// honest without this controller re-deriving the store's own title/ordering rules.
|
|
207
|
+
void refresh(core);
|
|
208
|
+
}
|
|
209
|
+
function saveMessage({ core, bridge, conversationId, message, written }, _options = {}) {
|
|
210
|
+
void bridge.saveConversationMessage({ conversationId, message }).catch((err) => {
|
|
211
|
+
core.log('could not persist a conversation message —', err);
|
|
212
|
+
// Un-marked so a later delta gets one more chance, rather than a single failed write
|
|
213
|
+
// silently dropping this message from the durable transcript forever.
|
|
214
|
+
written.delete(message.id);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Fires once on `ChatPane` MOUNT with whatever `initialMessages` seeded it with, so a fresh pane
|
|
219
|
+
* with nothing selected calls this with `[]` — `persistableMessages({ messages: [] }).length === 0` makes that a
|
|
220
|
+
* no-op below, rather than mistaking a mount echo for new content to save.
|
|
221
|
+
*/
|
|
222
|
+
function onMessagesChange({ core, messages }, _options = {}) {
|
|
223
|
+
const conversationId = core.state.activeId;
|
|
224
|
+
if (conversationId !== null) {
|
|
225
|
+
flush({ core, conversationId, messages });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// No conversation is active — the DEFAULT state, not an edge case: nothing selects one on
|
|
229
|
+
// mount, so typing straight into a freshly opened chat (without first clicking "New" or
|
|
230
|
+
// picking from history) lands here. Adopt one lazily, at the first moment there is actually
|
|
231
|
+
// something worth saving, rather than littering the switcher with an empty row per app open.
|
|
232
|
+
const bridge = core.bridge;
|
|
233
|
+
if (bridge === undefined || persistableMessages({ messages }, { includePendingUser: true }).length === 0)
|
|
234
|
+
return;
|
|
235
|
+
const adoption = claimAdoption({ core, bridge });
|
|
236
|
+
void adoption.then((id) => afterAdoption({ core, adoption, id, messages }));
|
|
237
|
+
}
|
|
238
|
+
function claimAdoption({ core, bridge }, _options = {}) {
|
|
239
|
+
const generation = core.adoptionGen;
|
|
240
|
+
// Claimed only if nothing is already in flight, so two deltas arriving before the create
|
|
241
|
+
// resolves await the SAME creation, not two. (Not `core.adopting ??= …` — Biome's
|
|
242
|
+
// `noAssignInExpressions` refuses an assignment inside the expression that reads it back.)
|
|
243
|
+
if (core.adopting === null)
|
|
244
|
+
core.adopting = adoptConversation({ core, bridge, generation });
|
|
245
|
+
return core.adopting;
|
|
246
|
+
}
|
|
247
|
+
function adoptConversation({ core, bridge, generation }, _options = {}) {
|
|
248
|
+
return bridge
|
|
249
|
+
.createConversation()
|
|
250
|
+
.then((conversation) => {
|
|
251
|
+
// The persisted row can be listed and deleted before its create acknowledgement arrives.
|
|
252
|
+
if (core.deleted.has(conversation.id))
|
|
253
|
+
return null;
|
|
254
|
+
core.written.set(conversation.id, new Set());
|
|
255
|
+
// Superseded: the row exists and shows up in the switcher, but the pane that asked for
|
|
256
|
+
// it is gone (the user switched away while this was in flight) — pointing
|
|
257
|
+
// `activeId` at it now would route the NEXT pane's writes here. The flush in
|
|
258
|
+
// `afterAdoption` still runs regardless: these messages came from the pane that asked for
|
|
259
|
+
// this conversation, and dropping them would be exactly the data loss lazy adoption exists
|
|
260
|
+
// to prevent.
|
|
261
|
+
const adopt = core.adoptionGen === generation && !core.navigating ? { activeId: conversation.id } : {};
|
|
262
|
+
publish({ core, patch: { conversations: withConversation({ core, conversation }), ...adopt } });
|
|
263
|
+
return conversation.id;
|
|
264
|
+
})
|
|
265
|
+
.catch((err) => {
|
|
266
|
+
core.log('could not create a conversation —', err);
|
|
267
|
+
return null;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function afterAdoption({ core, adoption, id, messages }, _options = {}) {
|
|
271
|
+
if (id === null) {
|
|
272
|
+
// Cleared so a later turn can retry — leaving a rejected promise in place would wedge
|
|
273
|
+
// persistence for the rest of the session.
|
|
274
|
+
if (core.adopting === adoption)
|
|
275
|
+
core.adopting = null;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
flush({ core, conversationId: id, messages });
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=conversation-controller.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ConversationDeleteConfirmationState } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* `ConversationList` accepts a `confirmDelete` callback returning `boolean | Promise<boolean>` for
|
|
4
|
+
* exactly this purpose — this one resolves it from a real user click on the host pane's own inline
|
|
5
|
+
* banner (rendered from `pendingTitle`) rather than from a blocking native dialog.
|
|
6
|
+
*
|
|
7
|
+
* @param labels.untitled the title shown for an untitled conversation; defaults to `'Untitled'`,
|
|
8
|
+
* the same source key `ConversationList` renders.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useConversationDeleteConfirmation(_required?: Record<string, never>, { labels: { untitled } }?: {
|
|
11
|
+
labels?: {
|
|
12
|
+
untitled?: string;
|
|
13
|
+
};
|
|
14
|
+
}): ConversationDeleteConfirmationState;
|
|
15
|
+
//# sourceMappingURL=useConversationDeleteConfirmation.hooks.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A conversation-delete confirmation answered from an inline banner rather than a blocking
|
|
3
|
+
* native dialog.
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback, useRef, useState } from 'react';
|
|
6
|
+
/**
|
|
7
|
+
* `ConversationList` accepts a `confirmDelete` callback returning `boolean | Promise<boolean>` for
|
|
8
|
+
* exactly this purpose — this one resolves it from a real user click on the host pane's own inline
|
|
9
|
+
* banner (rendered from `pendingTitle`) rather than from a blocking native dialog.
|
|
10
|
+
*
|
|
11
|
+
* @param labels.untitled the title shown for an untitled conversation; defaults to `'Untitled'`,
|
|
12
|
+
* the same source key `ConversationList` renders.
|
|
13
|
+
*/
|
|
14
|
+
export function useConversationDeleteConfirmation(_required = {}, { labels: { untitled = 'Untitled' } = {} } = {}) {
|
|
15
|
+
const resolverRef = useRef(null);
|
|
16
|
+
const [pendingTitle, setPendingTitle] = useState(null);
|
|
17
|
+
const confirmDelete = useCallback((item) => {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
// An unresolved earlier prompt loses to a newer one rather than leaving two pending — the
|
|
20
|
+
// user can only be looking at (and answering) one banner at a time.
|
|
21
|
+
resolverRef.current?.(false);
|
|
22
|
+
resolverRef.current = resolve;
|
|
23
|
+
setPendingTitle(item.title ?? untitled);
|
|
24
|
+
});
|
|
25
|
+
}, [untitled]);
|
|
26
|
+
const resolvePending = useCallback(({ confirmed }) => {
|
|
27
|
+
resolverRef.current?.(confirmed);
|
|
28
|
+
resolverRef.current = null;
|
|
29
|
+
setPendingTitle(null);
|
|
30
|
+
}, []);
|
|
31
|
+
return { pendingTitle, confirmDelete, resolvePending };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=useConversationDeleteConfirmation.hooks.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ConversationLog, ConversationStorePort, ConversationSummaryLike, UseStoredConversations } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Owns a chat's persisted conversation threads: which one is open, what's in it, and writing new
|
|
4
|
+
* turns back to the host's store. The list is loaded once on mount.
|
|
5
|
+
*
|
|
6
|
+
* @param getStore the host's store lookup (e.g. a preload bridge accessor). Called once per
|
|
7
|
+
* identity of `getStore`, never per render; `undefined` makes every action a no-op.
|
|
8
|
+
* @param log where failures are reported; defaults to `console.error`. A host prefixes its own
|
|
9
|
+
* label here. Must be referentially stable (see below).
|
|
10
|
+
*/
|
|
11
|
+
export declare function useStoredConversations<S extends ConversationSummaryLike = ConversationSummaryLike>({ getStore }: {
|
|
12
|
+
getStore: () => ConversationStorePort<S> | undefined;
|
|
13
|
+
}, { log }?: {
|
|
14
|
+
log?: ConversationLog;
|
|
15
|
+
}): UseStoredConversations<S>;
|
|
16
|
+
//# sourceMappingURL=useStoredConversations.hooks.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The React binding for {@link createConversationController}: one controller per store, read
|
|
3
|
+
* through `useSyncExternalStore`. Every rule and race guard — and the reasoning behind each — lives
|
|
4
|
+
* in the controller (`../conversation-controller.ts`), not here.
|
|
5
|
+
*/
|
|
6
|
+
import { useCallback, useEffect, useMemo, useSyncExternalStore } from 'react';
|
|
7
|
+
import { createConversationController } from '../conversation-controller.js';
|
|
8
|
+
/**
|
|
9
|
+
* Owns a chat's persisted conversation threads: which one is open, what's in it, and writing new
|
|
10
|
+
* turns back to the host's store. The list is loaded once on mount.
|
|
11
|
+
*
|
|
12
|
+
* @param getStore the host's store lookup (e.g. a preload bridge accessor). Called once per
|
|
13
|
+
* identity of `getStore`, never per render; `undefined` makes every action a no-op.
|
|
14
|
+
* @param log where failures are reported; defaults to `console.error`. A host prefixes its own
|
|
15
|
+
* label here. Must be referentially stable (see below).
|
|
16
|
+
*/
|
|
17
|
+
export function useStoredConversations({ getStore }, { log } = {}) {
|
|
18
|
+
const store = useMemo(() => getStore(), [getStore]);
|
|
19
|
+
// A new `log` identity rebuilds the controller (and drops its state), so a host passes a
|
|
20
|
+
// module-level function, not an inline closure.
|
|
21
|
+
const controller = useMemo(() => createConversationController({ bridge: store }, log ? { log } : {}), [store, log]);
|
|
22
|
+
const subscribe = useCallback((listener) => controller.subscribe({ listener }), [controller]);
|
|
23
|
+
const state = useSyncExternalStore(subscribe, controller.getState);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
void controller.refresh();
|
|
26
|
+
}, [controller]);
|
|
27
|
+
const actions = useMemo(() => ({
|
|
28
|
+
select: (id) => controller.select({ id }),
|
|
29
|
+
create: controller.create,
|
|
30
|
+
remove: (id) => controller.remove({ id }),
|
|
31
|
+
rename: (id, title) => controller.rename({ id, title }),
|
|
32
|
+
onMessagesChange: (messages) => controller.onMessagesChange({ messages }),
|
|
33
|
+
}), [controller]);
|
|
34
|
+
return { ...state, ...actions };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useStoredConversations.hooks.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/chat/react/conversations` — persisted conversation threads behind an injected store:
|
|
3
|
+
* the framework-free controller, its React binding, and the inline delete confirmation.
|
|
4
|
+
*/
|
|
5
|
+
export { createConversationController } from './conversation-controller.js';
|
|
6
|
+
export { useStoredConversations } from './hooks/useStoredConversations.hooks.js';
|
|
7
|
+
export { useConversationDeleteConfirmation } from './hooks/useConversationDeleteConfirmation.hooks.js';
|
|
8
|
+
export type { ConversationController, ConversationDeleteConfirmationState, ConversationLog, ConversationState, ConversationStorePort, ConversationSummaryLike, UseStoredConversations, } from './types.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/chat/react/conversations` — persisted conversation threads behind an injected store:
|
|
3
|
+
* the framework-free controller, its React binding, and the inline delete confirmation.
|
|
4
|
+
*/
|
|
5
|
+
export { createConversationController } from './conversation-controller.js';
|
|
6
|
+
export { useStoredConversations } from './hooks/useStoredConversations.hooks.js';
|
|
7
|
+
export { useConversationDeleteConfirmation } from './hooks/useConversationDeleteConfirmation.hooks.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|