@jini-ai/chat 0.7.3-next.1 → 0.7.3-next.3
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 +10 -0
- 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 +15 -0
- package/dist/react/chat-cleanup/ChatCleanupPanel.js +17 -0
- package/dist/react/chat-cleanup/chat-cleanup.hooks.d.ts +168 -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 +12 -0
- package/dist/react/components/ConversationList.d.ts +14 -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 +41 -5
- package/dist/react/components/Icon.d.ts +1 -1
- package/dist/react/components/Icon.js +2 -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/MessageList.hooks.d.ts +4 -0
- package/dist/react/components/MessageList.hooks.js +16 -2
- package/dist/react/components/MessageList.js +14 -7
- package/dist/react/components/MessageList.rules.d.ts +5 -0
- package/dist/react/components/MessageList.rules.js +4 -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 +43 -11
- 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 +14 -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 +174 -23
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { createAgentPresentationPort, localCliScopeCopy, selectedAgentWarning } from '../ai-agent-presentation.js';
|
|
3
|
+
/** Observe the same detection that renders Settings cards, including rescans and selection changes. */
|
|
4
|
+
export function useAiAgentPresentation({ port, config, locale, desktop, defaultLocalAgentId, translate, scopeKeys }, _optional = {}) {
|
|
5
|
+
const [agents, setAgents] = useState([]);
|
|
6
|
+
const live = useRef(false);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
live.current = true;
|
|
9
|
+
return () => { live.current = false; };
|
|
10
|
+
}, []);
|
|
11
|
+
const presentationPort = useMemo(() => createAgentPresentationPort({
|
|
12
|
+
port,
|
|
13
|
+
// Detection can finish after navigating away; no state should be written to an unmounted tab.
|
|
14
|
+
onAgents: ({ agents: next }, _options = {}) => { if (live.current)
|
|
15
|
+
setAgents((previous) => JSON.stringify(previous) === JSON.stringify(next) ? previous : next); },
|
|
16
|
+
}), [port]);
|
|
17
|
+
return {
|
|
18
|
+
port: presentationPort,
|
|
19
|
+
scopeCopy: localCliScopeCopy({ desktop, ...scopeKeys }),
|
|
20
|
+
// The dock's useLocalCliSelection defaults an unset ledger selection to Claude. Warn about
|
|
21
|
+
// that same effective choice here, including a fresh desktop install with no saved agent id.
|
|
22
|
+
warning: selectedAgentWarning({ mode: config?.mode ?? '', agentId: config?.localCli.agentId ?? defaultLocalAgentId, agents, locale, translate }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=use-ai-agent-presentation.hooks.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChatCleanupConfirm, WiredChatCleanup } from "./chat-cleanup.hooks.js";
|
|
2
|
+
/**
|
|
3
|
+
* The dock's chat cleanup controls, beside the switcher: a toggle that turns on row ticking, the
|
|
4
|
+
* 1–365 day chooser in front of `ChatCleanupDialog` (which shows the server's count, bytes and kept
|
|
5
|
+
* reasons before anything is deleted), and "Delete selected", which asks `confirm` first. Holds no
|
|
6
|
+
* state of its own; everything comes from the injected {@link WiredChatCleanup}.
|
|
7
|
+
*
|
|
8
|
+
* @param props.confirm - The admin confirm dialog; delete-selected waits for its visible answer.
|
|
9
|
+
* @complexity O(k) in the number of kept chats the preview names.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ChatCleanupPanel({ cleanup, confirm }: {
|
|
12
|
+
cleanup: WiredChatCleanup;
|
|
13
|
+
confirm: ChatCleanupConfirm;
|
|
14
|
+
}, _optional?: {}): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=ChatCleanupPanel.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChatCleanupDialog } from "../components/ChatCleanupDialog.js";
|
|
3
|
+
/**
|
|
4
|
+
* The dock's chat cleanup controls, beside the switcher: a toggle that turns on row ticking, the
|
|
5
|
+
* 1–365 day chooser in front of `ChatCleanupDialog` (which shows the server's count, bytes and kept
|
|
6
|
+
* reasons before anything is deleted), and "Delete selected", which asks `confirm` first. Holds no
|
|
7
|
+
* state of its own; everything comes from the injected {@link WiredChatCleanup}.
|
|
8
|
+
*
|
|
9
|
+
* @param props.confirm - The admin confirm dialog; delete-selected waits for its visible answer.
|
|
10
|
+
* @complexity O(k) in the number of kept chats the preview names.
|
|
11
|
+
*/
|
|
12
|
+
export function ChatCleanupPanel({ cleanup, confirm }, _optional = {}) {
|
|
13
|
+
const { Button } = cleanup.kit;
|
|
14
|
+
const count = cleanup.selectedIds.length;
|
|
15
|
+
return (_jsxs("div", { className: "assistant-chat-cleanup", children: [_jsx(Button, { type: "button", "aria-expanded": cleanup.open, onClick: () => cleanup.setOpen(!cleanup.open), children: cleanup.copy.open }), cleanup.open ? _jsxs("div", { className: "assistant-chat-cleanup__panel", children: [_jsxs("label", { children: [cleanup.copy.olderThan, _jsx("input", { type: "number", min: 1, max: 365, step: 1, value: Number.isNaN(cleanup.olderThanDays) ? "" : cleanup.olderThanDays, onChange: (event) => cleanup.setOlderThanDays(event.currentTarget.valueAsNumber) })] }), _jsx(ChatCleanupDialog, { useChatCleanup: cleanup.useDialog, kit: cleanup.kit, copy: cleanup.copy.dialog, onDone: () => cleanup.setOpen(false) }), _jsx(Button, { type: "button", disabled: count === 0, onClick: () => { void cleanup.deleteSelected({ confirm }); }, children: cleanup.copy.deleteSelected({ count }) }), cleanup.error ? _jsx("p", { role: "alert", children: cleanup.error }) : null] }) : null] }));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ChatCleanupPanel.js.map
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ComponentProps, type ElementType } from "react";
|
|
2
|
+
import type { ChatCleanupDialog } from "../components/ChatCleanupDialog.js";
|
|
3
|
+
import type { ConversationListHooks, ConversationListItem } from "../components/ConversationList.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file The dock's chat cleanup state: optimistic pins, chats hidden after a confirmed deletion,
|
|
6
|
+
* the age preview and its token-bound apply, and delete-selected behind a visible confirmation.
|
|
7
|
+
* No network here: every call goes through the injected {@link ChatCleanupClient}.
|
|
8
|
+
*
|
|
9
|
+
* Why selection or an optimistic pin does not authorize deletion: both are browser-only guesses.
|
|
10
|
+
* A ticked checkbox is a pointer gesture, not consent, so delete-selected still waits for the
|
|
11
|
+
* admin's visible confirmation and then sends `confirm: true` (owner rule d). An optimistic pin is
|
|
12
|
+
* not a saved pin until the server answers, so it can protect nothing; the age cleanup trusts only
|
|
13
|
+
* the server's own preview (which re-reads `pinned` and names every kept chat) and applies only
|
|
14
|
+
* with the token the server issued for that same confirmed preview. The token lives in React state
|
|
15
|
+
* for this mounted dock and is never written to browser storage, so a reload means choosing again.
|
|
16
|
+
*/
|
|
17
|
+
/** A chat the server kept out of a cleanup, and why (`pinned`, `open`, `active`, `recoverable`, `changed`, `unknown`). */
|
|
18
|
+
export interface ChatCleanupKept {
|
|
19
|
+
id: string;
|
|
20
|
+
title: string | null;
|
|
21
|
+
reason: string;
|
|
22
|
+
}
|
|
23
|
+
/** `POST cleanup/preview`'s answer: the server's own count, bytes and kept list, plus the token apply needs. */
|
|
24
|
+
export interface ChatCleanupPreview {
|
|
25
|
+
count: number;
|
|
26
|
+
bytes: number;
|
|
27
|
+
kept: ChatCleanupKept[];
|
|
28
|
+
previewToken: string;
|
|
29
|
+
}
|
|
30
|
+
/** `cleanup/apply` and `delete-selected`; a `previewToken` means the same confirmed preview has more to delete. */
|
|
31
|
+
export interface ChatCleanupResult {
|
|
32
|
+
deleted: string[];
|
|
33
|
+
kept: ChatCleanupKept[];
|
|
34
|
+
previewToken?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Every string the cleanup panel and `ChatCleanupDialog` show. */
|
|
37
|
+
export interface ChatCleanupCopy {
|
|
38
|
+
dialog: {
|
|
39
|
+
preview: string;
|
|
40
|
+
confirm: string;
|
|
41
|
+
expired: string;
|
|
42
|
+
choose: string;
|
|
43
|
+
partial: string;
|
|
44
|
+
count: (required: {
|
|
45
|
+
count: number;
|
|
46
|
+
bytes: number;
|
|
47
|
+
}) => string;
|
|
48
|
+
};
|
|
49
|
+
open: string;
|
|
50
|
+
olderThan: string;
|
|
51
|
+
deleteSelected: (required: {
|
|
52
|
+
count: number;
|
|
53
|
+
}) => string;
|
|
54
|
+
deleteSelectedBody: string;
|
|
55
|
+
untitled: string;
|
|
56
|
+
reason: (required: {
|
|
57
|
+
reason: string;
|
|
58
|
+
}) => string;
|
|
59
|
+
errors: {
|
|
60
|
+
notConfigured: string;
|
|
61
|
+
invalid: string;
|
|
62
|
+
failed: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** The cleanup half of the admin chat client; the real one is bound in `assistant-chats-dependencies.hooks.ts`. */
|
|
66
|
+
export interface ChatCleanupClient {
|
|
67
|
+
setPinned: (required: {
|
|
68
|
+
id: string;
|
|
69
|
+
pinned: boolean;
|
|
70
|
+
}) => Promise<{
|
|
71
|
+
id: string;
|
|
72
|
+
pinned: boolean;
|
|
73
|
+
}>;
|
|
74
|
+
preview: (required: {
|
|
75
|
+
before: number;
|
|
76
|
+
}) => Promise<ChatCleanupPreview>;
|
|
77
|
+
apply: (required: {
|
|
78
|
+
previewToken: string;
|
|
79
|
+
}) => Promise<ChatCleanupResult>;
|
|
80
|
+
deleteSelected: (required: {
|
|
81
|
+
ids: readonly string[];
|
|
82
|
+
confirm: true;
|
|
83
|
+
}) => Promise<ChatCleanupResult>;
|
|
84
|
+
}
|
|
85
|
+
export type ChatCleanupKit = {
|
|
86
|
+
Button: ElementType<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
87
|
+
};
|
|
88
|
+
/** The admin confirm dialog's request (`useConfirmRequest().confirm`). */
|
|
89
|
+
export type ChatCleanupConfirm = (required: {
|
|
90
|
+
dialog: {
|
|
91
|
+
title: string;
|
|
92
|
+
body: string;
|
|
93
|
+
confirmLabel: string;
|
|
94
|
+
tone: "danger";
|
|
95
|
+
};
|
|
96
|
+
}) => Promise<boolean>;
|
|
97
|
+
export type ChatCleanupDialogState = ReturnType<ComponentProps<typeof ChatCleanupDialog>["useChatCleanup"]>;
|
|
98
|
+
/** Everything the dock header and cleanup panel need; the dock takes it from a required hook prop. */
|
|
99
|
+
export interface WiredChatCleanup {
|
|
100
|
+
listHooks: ConversationListHooks;
|
|
101
|
+
kit: ChatCleanupKit;
|
|
102
|
+
copy: ChatCleanupCopy;
|
|
103
|
+
open: boolean;
|
|
104
|
+
setOpen: (open: boolean) => void;
|
|
105
|
+
olderThanDays: number;
|
|
106
|
+
setOlderThanDays: (days: number) => void;
|
|
107
|
+
selectedIds: readonly string[];
|
|
108
|
+
select: (required: {
|
|
109
|
+
ids: string[];
|
|
110
|
+
}) => void;
|
|
111
|
+
togglePin: (required: {
|
|
112
|
+
id: string;
|
|
113
|
+
pinned: boolean;
|
|
114
|
+
}) => void;
|
|
115
|
+
visibleConversations: <T extends ConversationListItem>(required: {
|
|
116
|
+
conversations: T[];
|
|
117
|
+
}) => T[];
|
|
118
|
+
useDialog: () => ChatCleanupDialogState;
|
|
119
|
+
deleteSelected: (required: {
|
|
120
|
+
confirm: ChatCleanupConfirm;
|
|
121
|
+
}) => Promise<void>;
|
|
122
|
+
error: string | null;
|
|
123
|
+
}
|
|
124
|
+
/** Plain words for a failed cleanup call; expiry is handled as a state, not an error. @complexity O(1). */
|
|
125
|
+
export declare function cleanupErrorText({ error, copy }: {
|
|
126
|
+
error: unknown;
|
|
127
|
+
copy: ChatCleanupCopy;
|
|
128
|
+
}, _optional?: {}): string;
|
|
129
|
+
/** Optimistic pins and locally hidden (deleted) chats layered over the dock's conversation list. */
|
|
130
|
+
export declare function useChatListOverlay({ client, onError }: {
|
|
131
|
+
client: ChatCleanupClient;
|
|
132
|
+
onError: (error: unknown) => void;
|
|
133
|
+
}, _optional?: {}): {
|
|
134
|
+
togglePin: ({ id, pinned }: {
|
|
135
|
+
id: string;
|
|
136
|
+
pinned: boolean;
|
|
137
|
+
}) => void;
|
|
138
|
+
hide: (ids: readonly string[]) => void;
|
|
139
|
+
visibleConversations: <T extends ConversationListItem>({ conversations }: {
|
|
140
|
+
conversations: T[];
|
|
141
|
+
}) => T[];
|
|
142
|
+
};
|
|
143
|
+
/** The age chooser's preview → confirm → apply (→ partial continuation) cycle for `ChatCleanupDialog`. */
|
|
144
|
+
export declare function useCleanupPreview({ client, copy, clock, olderThanDays, hide, onError }: {
|
|
145
|
+
client: ChatCleanupClient;
|
|
146
|
+
copy: ChatCleanupCopy;
|
|
147
|
+
clock: () => number;
|
|
148
|
+
olderThanDays: number;
|
|
149
|
+
hide: (ids: readonly string[]) => void;
|
|
150
|
+
onError: (error: unknown) => void;
|
|
151
|
+
}, _optional?: {}): () => ChatCleanupDialogState;
|
|
152
|
+
/** Ticked chats and their deletion, which waits for the admin's visible confirmation first. */
|
|
153
|
+
export declare function useSelectedDeletion({ client, copy, hide, onError, clearError }: {
|
|
154
|
+
client: ChatCleanupClient;
|
|
155
|
+
copy: ChatCleanupCopy;
|
|
156
|
+
hide: (ids: readonly string[]) => void;
|
|
157
|
+
onError: (error: unknown) => void;
|
|
158
|
+
clearError: () => void;
|
|
159
|
+
}, _optional?: {}): {
|
|
160
|
+
selectedIds: readonly string[];
|
|
161
|
+
select: ({ ids }: {
|
|
162
|
+
ids: string[];
|
|
163
|
+
}) => void;
|
|
164
|
+
deleteSelected: ({ confirm }: {
|
|
165
|
+
confirm: ChatCleanupConfirm;
|
|
166
|
+
}) => Promise<void>;
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=chat-cleanup.hooks.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
const DAY_MS = 86_400_000;
|
|
3
|
+
/** Plain words for a failed cleanup call; expiry is handled as a state, not an error. @complexity O(1). */
|
|
4
|
+
export function cleanupErrorText({ error, copy }, _optional = {}) {
|
|
5
|
+
const { status, code } = (error ?? {});
|
|
6
|
+
if (status === 503 || code === "NOT_CONFIGURED")
|
|
7
|
+
return copy.errors.notConfigured;
|
|
8
|
+
if (status === 400 || code === "VALIDATION_ERROR")
|
|
9
|
+
return copy.errors.invalid;
|
|
10
|
+
return copy.errors.failed;
|
|
11
|
+
}
|
|
12
|
+
const isExpired = (error) => error?.code === "PREVIEW_EXPIRED";
|
|
13
|
+
/** Optimistic pins and locally hidden (deleted) chats layered over the dock's conversation list. */
|
|
14
|
+
export function useChatListOverlay({ client, onError }, _optional = {}) {
|
|
15
|
+
const [pins, setPins] = useState(new Map());
|
|
16
|
+
const [hidden, setHidden] = useState(new Set());
|
|
17
|
+
const togglePin = useCallback(({ id, pinned }) => {
|
|
18
|
+
setPins((map) => new Map(map).set(id, pinned));
|
|
19
|
+
client.setPinned({ id, pinned }).then((saved) => setPins((map) => new Map(map).set(id, saved.pinned)), (error) => { setPins((map) => { const next = new Map(map); next.delete(id); return next; }); onError(error); });
|
|
20
|
+
}, [client, onError]);
|
|
21
|
+
const hide = useCallback((ids) => setHidden((set) => new Set([...set, ...ids])), []);
|
|
22
|
+
const visibleConversations = useCallback(({ conversations }) => conversations.filter((item) => !hidden.has(item.id)).map((item) => pins.has(item.id) ? { ...item, pinned: pins.get(item.id) } : item), [pins, hidden]);
|
|
23
|
+
return { togglePin, hide, visibleConversations };
|
|
24
|
+
}
|
|
25
|
+
/** The age chooser's preview → confirm → apply (→ partial continuation) cycle for `ChatCleanupDialog`. */
|
|
26
|
+
export function useCleanupPreview({ client, copy, clock, olderThanDays, hide, onError }, _optional = {}) {
|
|
27
|
+
const [phase, setPhase] = useState({ state: "preview" });
|
|
28
|
+
const preview = () => {
|
|
29
|
+
if (!Number.isInteger(olderThanDays) || olderThanDays < 1 || olderThanDays > 365) {
|
|
30
|
+
onError({ code: "VALIDATION_ERROR" });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
client.preview({ before: clock() - olderThanDays * DAY_MS }).then(({ previewToken, count, bytes, kept }) => setPhase({ state: "confirm", previewToken, count, bytes, kept }), onError);
|
|
34
|
+
};
|
|
35
|
+
const apply = async ({ previewToken }) => {
|
|
36
|
+
// Continue only the confirmed preview this dialog is showing, never a token from elsewhere.
|
|
37
|
+
if ((phase.state !== "confirm" && phase.state !== "partial") || phase.previewToken !== previewToken)
|
|
38
|
+
return { complete: false };
|
|
39
|
+
try {
|
|
40
|
+
const result = await client.apply({ previewToken });
|
|
41
|
+
hide(result.deleted);
|
|
42
|
+
setPhase(result.previewToken ? { ...phase, state: "partial", previewToken: result.previewToken, kept: result.kept } : { state: "preview" });
|
|
43
|
+
return { complete: !result.previewToken };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (isExpired(error))
|
|
47
|
+
setPhase({ state: "expired" });
|
|
48
|
+
else
|
|
49
|
+
onError(error);
|
|
50
|
+
return { complete: false };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const shown = phase.state === "confirm" || phase.state === "partial"
|
|
54
|
+
? { ...phase, kept: phase.kept.map((item) => ({ id: item.id, title: item.title ?? copy.untitled, reason: copy.reason({ reason: item.reason }) })) }
|
|
55
|
+
: { state: phase.state, count: 0, bytes: 0, kept: [] };
|
|
56
|
+
const choose = () => setPhase({ state: "preview" });
|
|
57
|
+
return () => ({ ...shown, preview, choose, apply });
|
|
58
|
+
}
|
|
59
|
+
/** Ticked chats and their deletion, which waits for the admin's visible confirmation first. */
|
|
60
|
+
export function useSelectedDeletion({ client, copy, hide, onError, clearError }, _optional = {}) {
|
|
61
|
+
const [selectedIds, setSelectedIds] = useState([]);
|
|
62
|
+
const select = useCallback(({ ids }) => setSelectedIds(ids), []);
|
|
63
|
+
const deleteSelected = async ({ confirm }) => {
|
|
64
|
+
const ids = selectedIds;
|
|
65
|
+
if (ids.length === 0)
|
|
66
|
+
return;
|
|
67
|
+
const label = copy.deleteSelected({ count: ids.length });
|
|
68
|
+
if (await confirm({ dialog: { title: label, body: copy.deleteSelectedBody, confirmLabel: label, tone: "danger" } }) !== true)
|
|
69
|
+
return;
|
|
70
|
+
try {
|
|
71
|
+
const result = await client.deleteSelected({ ids, confirm: true });
|
|
72
|
+
hide(result.deleted);
|
|
73
|
+
// The server rechecks every id; chats it kept stay ticked so the admin can see them.
|
|
74
|
+
setSelectedIds(result.kept.map((item) => item.id));
|
|
75
|
+
clearError();
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
onError(error);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return { selectedIds, select, deleteSelected };
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=chat-cleanup.hooks.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ElementType } from 'react';
|
|
2
|
+
export declare function ChatCleanupDialog({ useChatCleanup, kit: { Button }, copy, onDone }: {
|
|
3
|
+
useChatCleanup: () => {
|
|
4
|
+
state: 'preview' | 'confirm' | 'partial' | 'expired';
|
|
5
|
+
previewToken?: string;
|
|
6
|
+
count: number;
|
|
7
|
+
bytes: number;
|
|
8
|
+
kept: readonly {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string | null;
|
|
11
|
+
reason: string;
|
|
12
|
+
}[];
|
|
13
|
+
preview: () => void;
|
|
14
|
+
choose: () => void;
|
|
15
|
+
apply: (required: {
|
|
16
|
+
previewToken: string;
|
|
17
|
+
confirm: true;
|
|
18
|
+
}) => Promise<{
|
|
19
|
+
complete: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
kit: {
|
|
23
|
+
Button: ElementType<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
24
|
+
};
|
|
25
|
+
copy: {
|
|
26
|
+
preview: string;
|
|
27
|
+
confirm: string;
|
|
28
|
+
expired: string;
|
|
29
|
+
choose: string;
|
|
30
|
+
partial: string;
|
|
31
|
+
count: (required: {
|
|
32
|
+
count: number;
|
|
33
|
+
bytes: number;
|
|
34
|
+
}) => string;
|
|
35
|
+
};
|
|
36
|
+
onDone: () => void;
|
|
37
|
+
}, _optional?: {}): import("react").JSX.Element;
|
|
38
|
+
//# sourceMappingURL=ChatCleanupDialog.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export function ChatCleanupDialog({ useChatCleanup, kit: { Button }, copy, onDone }, _optional = {}) {
|
|
3
|
+
const cleanup = useChatCleanup();
|
|
4
|
+
return _jsxs("div", { role: "dialog", children: [cleanup.state === 'preview' ? _jsx(Button, { type: "button", onClick: cleanup.preview, children: copy.preview }) : null, cleanup.state === 'expired' ? _jsxs(_Fragment, { children: [_jsx("p", { children: copy.expired }), _jsx(Button, { type: "button", onClick: cleanup.choose, children: copy.choose })] }) : null, cleanup.state === 'confirm' || cleanup.state === 'partial' ? _jsxs(_Fragment, { children: [_jsx("p", { children: copy.count({ count: cleanup.count, bytes: cleanup.bytes }) }), cleanup.state === 'partial' ? _jsx("p", { children: copy.partial }) : null, _jsx("ul", { children: cleanup.kept.map(item => _jsxs("li", { children: [item.title, ": ", item.reason] }, item.id)) }), _jsx(Button, { type: "button", disabled: !cleanup.previewToken, onClick: async () => {
|
|
5
|
+
if (!cleanup.previewToken)
|
|
6
|
+
return;
|
|
7
|
+
const result = await cleanup.apply({ previewToken: cleanup.previewToken, confirm: true });
|
|
8
|
+
if (result.complete)
|
|
9
|
+
onDone();
|
|
10
|
+
}, children: copy.confirm })] }) : null] });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ChatCleanupDialog.js.map
|
|
@@ -6,7 +6,7 @@ import type { Logger } from '@jini-ai/core/primitives';
|
|
|
6
6
|
* into `ChatPane`'s `leadingAccessory` slot — it needs no changes to `ChatPane` itself.
|
|
7
7
|
*
|
|
8
8
|
* Storage-agnostic by construction. It takes data and callbacks and owns nothing durable, so a
|
|
9
|
-
* host backs it with `@jini-ai/sqlite
|
|
9
|
+
* host backs it with `@jini-ai/chat/store/sqlite`'s `ChatHistoryStore`, an HTTP endpoint, or an in-memory
|
|
10
10
|
* array without this file knowing the difference.
|
|
11
11
|
*
|
|
12
12
|
* Search is a **client-side filter by default**, and delegates to `onSearch` when a host provides
|
|
@@ -28,8 +28,19 @@ export interface ConversationListItem {
|
|
|
28
28
|
title: string | null;
|
|
29
29
|
messageCount?: number;
|
|
30
30
|
updatedAt?: number;
|
|
31
|
+
pinned?: boolean;
|
|
31
32
|
}
|
|
32
33
|
export interface ConversationListProps {
|
|
34
|
+
hooks: ConversationListHooks;
|
|
35
|
+
selectable?: boolean;
|
|
36
|
+
selectedIds?: readonly string[];
|
|
37
|
+
onTogglePin?: (required: {
|
|
38
|
+
id: string;
|
|
39
|
+
pinned: boolean;
|
|
40
|
+
}) => void;
|
|
41
|
+
onSelectionChange?: (required: {
|
|
42
|
+
ids: string[];
|
|
43
|
+
}) => void;
|
|
33
44
|
report?: Pick<Logger, 'error'> | undefined;
|
|
34
45
|
conversations: ConversationListItem[];
|
|
35
46
|
activeConversationId: string | null;
|
|
@@ -61,13 +72,11 @@ export interface ConversationListProps {
|
|
|
61
72
|
*/
|
|
62
73
|
nativeTitle?: boolean;
|
|
63
74
|
}
|
|
64
|
-
/** Hooks ConversationList calls;
|
|
75
|
+
/** Hooks ConversationList calls; the host passes the real ones or a test hands in fakes. */
|
|
65
76
|
export declare const defaultConversationListHooks: {
|
|
66
77
|
useT: typeof useT;
|
|
67
78
|
useConversationListView: typeof useConversationListView;
|
|
68
79
|
};
|
|
69
80
|
export type ConversationListHooks = typeof defaultConversationListHooks;
|
|
70
|
-
export declare function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled, emptyState, triggerLabel, nativeTitle, hooks, report, }: ConversationListProps
|
|
71
|
-
hooks?: ConversationListHooks | undefined;
|
|
72
|
-
}): import("react").JSX.Element;
|
|
81
|
+
export declare function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled, emptyState, triggerLabel, nativeTitle, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, }: ConversationListProps, _optional?: {}): import("react").JSX.Element;
|
|
73
82
|
//# sourceMappingURL=ConversationList.d.ts.map
|
|
@@ -51,5 +51,6 @@ export declare function useConversationListView({ savedConversations, activeConv
|
|
|
51
51
|
emptyLabel: () => string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined>;
|
|
52
52
|
scheduleSelect: (id: string) => void;
|
|
53
53
|
createConversation: () => void;
|
|
54
|
+
selectionAnchor: import("react").RefObject<string | null>;
|
|
54
55
|
};
|
|
55
56
|
//# sourceMappingURL=ConversationList.hooks.d.ts.map
|
|
@@ -137,7 +137,7 @@ export function useConversationListView({ savedConversations, activeConversation
|
|
|
137
137
|
cancelled = true;
|
|
138
138
|
};
|
|
139
139
|
}, [onSearch, deferredQuery, report]);
|
|
140
|
-
const
|
|
140
|
+
const filtered = useMemo(() => {
|
|
141
141
|
if (onSearch)
|
|
142
142
|
return serverResults ?? conversations;
|
|
143
143
|
const needle = deferredQuery.trim().toLocaleLowerCase();
|
|
@@ -145,6 +145,8 @@ export function useConversationListView({ savedConversations, activeConversation
|
|
|
145
145
|
return conversations;
|
|
146
146
|
return conversations.filter((c) => (c.title ?? t('Untitled')).toLocaleLowerCase().includes(needle));
|
|
147
147
|
}, [onSearch, serverResults, conversations, deferredQuery, t]);
|
|
148
|
+
const visible = useMemo(() => [...filtered].sort((a, b) => Number(Boolean(b.pinned)) - Number(Boolean(a.pinned))), [filtered]);
|
|
149
|
+
const selectionAnchor = useRef(null);
|
|
148
150
|
// One timestamp for the whole render so every row's "5m ago" is computed against the same
|
|
149
151
|
// instant — otherwise rows drawn either side of a second boundary disagree.
|
|
150
152
|
const now = Date.now();
|
|
@@ -196,6 +198,6 @@ export function useConversationListView({ savedConversations, activeConversation
|
|
|
196
198
|
runConversationListHostEffect({ effectName: 'onCreate', effect: () => onCreate() }, { report });
|
|
197
199
|
setOpen(false);
|
|
198
200
|
};
|
|
199
|
-
return { open, setOpen, query, setQuery, conversations, rawTitles, editingId, setEditingId, rootRef, visible, now, commitRename, startRename, requestDelete, active, emptyLabel, scheduleSelect, createConversation };
|
|
201
|
+
return { open, setOpen, query, setQuery, conversations, rawTitles, editingId, setEditingId, rootRef, visible, now, commitRename, startRename, requestDelete, active, emptyLabel, scheduleSelect, createConversation, selectionAnchor };
|
|
200
202
|
}
|
|
201
203
|
//# sourceMappingURL=ConversationList.hooks.js.map
|
|
@@ -6,7 +6,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
6
6
|
* into `ChatPane`'s `leadingAccessory` slot — it needs no changes to `ChatPane` itself.
|
|
7
7
|
*
|
|
8
8
|
* Storage-agnostic by construction. It takes data and callbacks and owns nothing durable, so a
|
|
9
|
-
* host backs it with `@jini-ai/sqlite
|
|
9
|
+
* host backs it with `@jini-ai/chat/store/sqlite`'s `ChatHistoryStore`, an HTTP endpoint, or an in-memory
|
|
10
10
|
* array without this file knowing the difference.
|
|
11
11
|
*
|
|
12
12
|
* Search is a **client-side filter by default**, and delegates to `onSearch` when a host provides
|
|
@@ -46,13 +46,49 @@ function ConversationActions({ itemId, editing, canRename, canDelete, onRename,
|
|
|
46
46
|
onDelete();
|
|
47
47
|
}, children: _jsx(Icon, { name: "close", size: 12 }) }) : null] });
|
|
48
48
|
}
|
|
49
|
-
/** Hooks ConversationList calls;
|
|
49
|
+
/** Hooks ConversationList calls; the host passes the real ones or a test hands in fakes. */
|
|
50
50
|
export const defaultConversationListHooks = { useT, useConversationListView };
|
|
51
|
-
|
|
51
|
+
/** The selection after a click on `itemId`: shift-click extends from the anchor, otherwise it toggles. */
|
|
52
|
+
function nextSelection({ selectedIds, visible, anchorId, itemId, shiftKey }) {
|
|
53
|
+
const selected = new Set(selectedIds);
|
|
54
|
+
const anchor = visible.findIndex(row => row.id === anchorId);
|
|
55
|
+
const target = visible.findIndex(row => row.id === itemId);
|
|
56
|
+
if (shiftKey && anchor !== -1) {
|
|
57
|
+
for (const row of visible.slice(Math.min(anchor, target), Math.max(anchor, target) + 1))
|
|
58
|
+
selected.add(row.id);
|
|
59
|
+
}
|
|
60
|
+
else if (selected.has(itemId))
|
|
61
|
+
selected.delete(itemId);
|
|
62
|
+
else
|
|
63
|
+
selected.add(itemId);
|
|
64
|
+
return selected;
|
|
65
|
+
}
|
|
66
|
+
function SelectCheckbox({ item, view, t, selectedIds, onSelectionChange }) {
|
|
67
|
+
const { visible, selectionAnchor } = view;
|
|
68
|
+
return _jsx("button", { type: "button", role: "checkbox", "aria-checked": selectedIds?.includes(item.id) ?? false, "aria-label": `${t('Select')} ${item.title ?? t('Untitled')}`, onClick: event => {
|
|
69
|
+
// Optimistic state belongs to the host, which also owns persistence and rejection handling.
|
|
70
|
+
const selected = nextSelection({ selectedIds, visible, anchorId: selectionAnchor.current, itemId: item.id, shiftKey: event.shiftKey });
|
|
71
|
+
selectionAnchor.current = item.id;
|
|
72
|
+
onSelectionChange?.({ ids: [...selected] });
|
|
73
|
+
} });
|
|
74
|
+
}
|
|
75
|
+
function ConversationItemBody({ item, view, t, onRename }) {
|
|
76
|
+
const { rawTitles, editingId, setEditingId, commitRename, startRename, scheduleSelect, now } = view;
|
|
77
|
+
if (onRename && editingId === item.id) {
|
|
78
|
+
return (_jsx(ConversationTitleEditor, { title: rawTitles.get(item.id) ?? null, "data-testid": `conversation-rename-${item.id}`, onCommit: (next) => commitRename(item.id, next), onCancel: () => setEditingId(null) }));
|
|
79
|
+
}
|
|
80
|
+
return (_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)] })] }));
|
|
81
|
+
}
|
|
82
|
+
function ConversationRow({ item, view, t, activeConversationId, selectable, selectedIds, onSelectionChange, onTogglePin, onRename, onDelete }) {
|
|
83
|
+
const { editingId, startRename, requestDelete } = view;
|
|
84
|
+
return (_jsxs("div", { className: `jini-conv-item${item.id === activeConversationId ? ' jini-conv-item-active' : ''}`, "data-testid": `conversation-item-${item.id}`, children: [selectable ? _jsx(SelectCheckbox, { item: item, view: view, t: t, selectedIds: selectedIds, onSelectionChange: onSelectionChange }) : null, onTogglePin ? _jsx("button", { type: "button", "aria-label": `${t(item.pinned ? 'Unpin' : 'Pin')} ${item.title ?? t('Untitled')}`, onClick: () => onTogglePin({ id: item.id, pinned: !item.pinned }), children: t(item.pinned ? 'Unpin' : 'Pin') }) : null, _jsx(ConversationItemBody, { item: item, view: view, t: t, onRename: onRename }), _jsx(ConversationActions, { itemId: item.id, editing: editingId === item.id, canRename: Boolean(onRename), canDelete: Boolean(onDelete), onRename: () => startRename(item.id), onDelete: () => requestDelete(item), t: t })] }));
|
|
85
|
+
}
|
|
86
|
+
export function ConversationList({ conversations: savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, createDisabled = false, emptyState, triggerLabel, nativeTitle = true, hooks, report, selectable, selectedIds, onTogglePin, onSelectionChange, }, _optional = {}) {
|
|
52
87
|
const t = hooks.useT();
|
|
53
|
-
const
|
|
88
|
+
const view = hooks.useConversationListView({ savedConversations, activeConversationId, onSelect, onCreate, onDelete, onRename, onSearch, confirmDelete, emptyState, t }, { report });
|
|
89
|
+
const { open, setOpen, query, setQuery, conversations, visible, now, active, emptyLabel, createConversation, rootRef } = view;
|
|
54
90
|
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",
|
|
55
91
|
// `disabled` alone guards this: a disabled button never dispatches a click.
|
|
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) => (
|
|
92
|
+
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) => (_jsx(ConversationRow, { item: item, view: view, t: t, activeConversationId: activeConversationId, selectable: selectable, selectedIds: selectedIds, onSelectionChange: onSelectionChange, onTogglePin: onTogglePin, onRename: onRename, onDelete: onDelete }, item.id)))) })] })) : null] }));
|
|
57
93
|
}
|
|
58
94
|
//# sourceMappingURL=ConversationList.js.map
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* AgentIcon and WorkingDirPicker.
|
|
8
8
|
*/
|
|
9
9
|
import type { SVGProps } from 'react';
|
|
10
|
-
export type IconName = 'spinner' | 'check' | 'close' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'attach' | 'folder' | 'file' | 'image' | 'x' | 'comment' | 'search' | 'plus' | 'pencil' | 'copy' | 'retry';
|
|
10
|
+
export type IconName = 'spinner' | 'check' | 'close' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'attach' | 'folder' | 'file' | 'image' | 'x' | 'comment' | 'search' | 'plus' | 'pencil' | 'copy' | 'external-link' | 'retry';
|
|
11
11
|
interface IconProps extends Omit<SVGProps<SVGSVGElement>, 'name'> {
|
|
12
12
|
name: IconName;
|
|
13
13
|
size?: number | string;
|
|
@@ -21,6 +21,8 @@ const ICON_GLYPHS = {
|
|
|
21
21
|
pencil: _jsxs(_Fragment, { children: [_jsx("path", { d: "m16 3 5 5L8 21H3v-5L16 3Z" }), _jsx("path", { d: "m14 5 5 5" })] }),
|
|
22
22
|
/** Per-message copy affordance (MessageRow.tsx). Two overlapping squares -- the conventional copy glyph. */
|
|
23
23
|
copy: _jsxs(_Fragment, { children: [_jsx("rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2" }), _jsx("path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" })] }),
|
|
24
|
+
/** The small "open in new tab" arrow after a link to the owner's own site or admin (MarkdownLink.tsx). */
|
|
25
|
+
'external-link': _jsxs(_Fragment, { children: [_jsx("path", { d: "M7 17 17 7" }), _jsx("path", { d: "M8 7h9v9" })] }),
|
|
24
26
|
};
|
|
25
27
|
export function Icon({ name, size = 14, strokeWidth = 1.6, ...rest }) {
|
|
26
28
|
// The spinner alone puts its spin class in front of any caller-supplied one.
|
|
@@ -42,6 +42,7 @@ import { Fragment, useEffect, useRef, useState } from 'react';
|
|
|
42
42
|
import { useCopyToClipboard } from '../hooks/useCopyToClipboard.js';
|
|
43
43
|
import { useT } from '../hooks/context.js';
|
|
44
44
|
import { Icon } from './Icon.js';
|
|
45
|
+
import { MarkdownLink } from './MarkdownLink.js';
|
|
45
46
|
export function Markdown({ children }) {
|
|
46
47
|
const blocks = parseBlocks(children);
|
|
47
48
|
return (_jsx(_Fragment, { children: blocks.map((block, i) => (_jsx(Fragment, { children: renderBlock(block) }, i))) }));
|
|
@@ -418,16 +419,15 @@ const INLINE_RE = new RegExp(String.raw `(\x60[^\x60]+\x60)|(${MD_LINK})|(\*\*[^
|
|
|
418
419
|
// Only these targets become anchors; anything else (`javascript:`, `data:`, protocol-relative
|
|
419
420
|
// `//host`) stays literal text, since the text is untrusted model output.
|
|
420
421
|
export const SAFE_LINK_HREF = /^(?:https?:\/\/|mailto:|\/(?!\/)|#)/iu;
|
|
421
|
-
//
|
|
422
|
-
//
|
|
423
|
-
//
|
|
424
|
-
const NEW_TAB = { target: '_blank', rel: 'noopener noreferrer' };
|
|
422
|
+
// Own-or-other link handling (and the new-tab icon after an own link) lives in `MarkdownLink`: owner
|
|
423
|
+
// decision 2026-11-21, reversing 2026-10-08's "every link opens a new tab". ChatPane's click guard
|
|
424
|
+
// (`useChatPaneNewTabLinks`) applies the same split to links this renderer does not draw.
|
|
425
425
|
function renderMarkdownLink(source, key) {
|
|
426
426
|
// `MD_LINK` already matched `source`, so these two groups always capture.
|
|
427
427
|
const [, label, href] = MD_LINK_PARTS.exec(source);
|
|
428
428
|
if (!SAFE_LINK_HREF.test(href))
|
|
429
429
|
return source;
|
|
430
|
-
return
|
|
430
|
+
return _jsx(MarkdownLink, { href: href, children: renderInline(label) }, key);
|
|
431
431
|
}
|
|
432
432
|
function renderInline(text) {
|
|
433
433
|
const nodes = [];
|
|
@@ -464,7 +464,7 @@ function renderInlineToken({ match, key }) {
|
|
|
464
464
|
if (italic)
|
|
465
465
|
return _jsx("em", { children: renderInline(italic.slice(1, -1)) }, key);
|
|
466
466
|
if (link)
|
|
467
|
-
return _jsx(
|
|
467
|
+
return _jsx(MarkdownLink, { href: link, children: link }, key);
|
|
468
468
|
return null;
|
|
469
469
|
}
|
|
470
470
|
//# sourceMappingURL=Markdown.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module MarkdownLink
|
|
3
|
+
*
|
|
4
|
+
* The one anchor the chat's markdown draws for a link, so a `[label](url)` and a bare autolink
|
|
5
|
+
* cannot drift apart. Owner decision 2026-11-21, reversing 2026-10-08 (when every chat link opened a
|
|
6
|
+
* new tab so the chat and the page under it were never navigated away from):
|
|
7
|
+
* - a link to the owner's own site or admin navigates the current tab from its text (the admin's
|
|
8
|
+
* own link handler turns an admin path into an in-app navigation, so the chat dock stays), with a
|
|
9
|
+
* small icon right after it that opens a new tab instead;
|
|
10
|
+
* - a link to any other website opens a new tab, with no icon (it already does);
|
|
11
|
+
* - a same-document `#anchor` stays in place, with no icon.
|
|
12
|
+
* `ChatPane`'s click guard (`useChatPaneNewTabLinks`) applies the same own-or-other split to links
|
|
13
|
+
* this renderer does not draw.
|
|
14
|
+
*/
|
|
15
|
+
import type { ReactNode } from 'react';
|
|
16
|
+
import { useT } from '../hooks/context.js';
|
|
17
|
+
export interface MarkdownLinkProps {
|
|
18
|
+
readonly href: string;
|
|
19
|
+
readonly children: ReactNode;
|
|
20
|
+
/** The origin that counts as the owner's own; defaults to the page's own origin. */
|
|
21
|
+
readonly origin?: string;
|
|
22
|
+
readonly useTHook?: typeof useT;
|
|
23
|
+
}
|
|
24
|
+
export declare function MarkdownLink({ href, children, origin, useTHook }: MarkdownLinkProps): import("react").JSX.Element;
|
|
25
|
+
//# sourceMappingURL=MarkdownLink.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useT } from '../hooks/context.js';
|
|
3
|
+
import { Icon } from './Icon.js';
|
|
4
|
+
import { currentOrigin, isOwnLinkHref } from './own-link.js';
|
|
5
|
+
const NEW_TAB = { target: '_blank', rel: 'noopener noreferrer' };
|
|
6
|
+
/** The icon's label, also its tooltip: it is the only text the icon has. */
|
|
7
|
+
const OPEN_IN_NEW_TAB = 'Open in new tab';
|
|
8
|
+
export function MarkdownLink({ href, children, origin = currentOrigin(), useTHook = useT }) {
|
|
9
|
+
const t = useTHook();
|
|
10
|
+
if (href.startsWith('#'))
|
|
11
|
+
return _jsx("a", { href: href, children: children });
|
|
12
|
+
if (!isOwnLinkHref({ href, origin }))
|
|
13
|
+
return _jsx("a", { href: href, ...NEW_TAB, children: children });
|
|
14
|
+
const label = t(OPEN_IN_NEW_TAB);
|
|
15
|
+
return (_jsxs(_Fragment, { children: [_jsx("a", { href: href, children: children }), _jsx("a", { className: "jini-md-link-newtab", href: href, ...NEW_TAB, "aria-label": label, title: label, children: _jsx(Icon, { name: "external-link", size: 11 }) })] }));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=MarkdownLink.js.map
|
|
@@ -14,6 +14,10 @@ export interface MessageListAutoScroll {
|
|
|
14
14
|
awayFromLatest: boolean;
|
|
15
15
|
/** Scrolls to the newest message and resumes following new output. */
|
|
16
16
|
jumpToLatest: () => void;
|
|
17
|
+
/** True while the transcript is taller than its box — the "Jump to top" arrow needs somewhere to go. */
|
|
18
|
+
scrollable: boolean;
|
|
19
|
+
/** Scrolls to the oldest message and stops following new output. */
|
|
20
|
+
jumpToTop: () => void;
|
|
17
21
|
}
|
|
18
22
|
/** Recompute costs once per immutable transcript snapshot, including saved history on reload. */
|
|
19
23
|
export declare function useConversationUsage({ messages }: {
|