@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,26 @@
|
|
|
1
|
+
/** `File.type` is the browser's own MIME sniff off the dropped/picked file — good enough to tell
|
|
2
|
+
* `ChatPane` how to render the attachment chip; not a security boundary either way. */
|
|
3
|
+
function attachmentKind({ file }, _options = {}) {
|
|
4
|
+
return file.type.startsWith('image/') ? 'image' : 'file';
|
|
5
|
+
}
|
|
6
|
+
async function stageOne({ bridge, file, order }, _options = {}) {
|
|
7
|
+
const data = await file.arrayBuffer();
|
|
8
|
+
const { path } = await bridge.saveChatAttachment({ name: file.name, data });
|
|
9
|
+
return { path, name: file.name, kind: attachmentKind({ file }), size: file.size, order };
|
|
10
|
+
}
|
|
11
|
+
/** Builds the uploader over the host's staging bridge. */
|
|
12
|
+
export function createStagedAttachmentUploader({ bridge }, _options = {}) {
|
|
13
|
+
return async function uploadAttachments(files, options) {
|
|
14
|
+
if (files.length === 0)
|
|
15
|
+
return [];
|
|
16
|
+
// `options?.signal` covers a composer reset/unmount mid-upload; there is nothing partial to
|
|
17
|
+
// clean up on the host's side (its staging directory is wiped at every boot, not accumulated
|
|
18
|
+
// across a session's worth of abandoned drafts), so an abort simply drops the result on the
|
|
19
|
+
// floor rather than rolling anything back.
|
|
20
|
+
const staged = await Promise.all(files.map((file, order) => stageOne({ bridge, file, order })));
|
|
21
|
+
if (options?.signal.aborted === true)
|
|
22
|
+
return [];
|
|
23
|
+
return staged;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=create-staged-attachment-uploader.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BridgedChatTransport, ChatBridgePort, DisposableChatTransport } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* @param getBridge the host's bridge lookup; called once per identity, never per render.
|
|
4
|
+
* @param createTransport builds the host's run transport on the bridge. Its construction may
|
|
5
|
+
* install a listener; the hook disposes it when the bridge changes or the pane unmounts. Must
|
|
6
|
+
* be referentially stable.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useBridgedChatTransport<B extends ChatBridgePort, TTransport extends DisposableChatTransport>({ getBridge, createTransport }: {
|
|
9
|
+
getBridge: () => B | undefined;
|
|
10
|
+
createTransport: (bridge: B) => TTransport;
|
|
11
|
+
}, _options?: Record<string, never>): BridgedChatTransport<TTransport>;
|
|
12
|
+
//# sourceMappingURL=useBridgedChatTransport.hooks.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A chat pane's bridge-backed surfaces: the run transport built on the host bridge, plus the
|
|
3
|
+
* runtime-access, working-directory, file-path and attachment surfaces `ChatPane` needs. All of them
|
|
4
|
+
* come from one bridge lookup, so they live in one hook rather than one per concern.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
import { createStagedAttachmentUploader } from '../create-staged-attachment-uploader.js';
|
|
8
|
+
/**
|
|
9
|
+
* @param getBridge the host's bridge lookup; called once per identity, never per render.
|
|
10
|
+
* @param createTransport builds the host's run transport on the bridge. Its construction may
|
|
11
|
+
* install a listener; the hook disposes it when the bridge changes or the pane unmounts. Must
|
|
12
|
+
* be referentially stable.
|
|
13
|
+
*/
|
|
14
|
+
export function useBridgedChatTransport({ getBridge, createTransport }, _options = {}) {
|
|
15
|
+
const bridge = useMemo(() => getBridge(), [getBridge]);
|
|
16
|
+
const runtimeAccess = useMemo(() => {
|
|
17
|
+
if (bridge === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
return {
|
|
20
|
+
listAgents: bridge.listAgents,
|
|
21
|
+
rescanAgents: bridge.rescanAgents,
|
|
22
|
+
daemonOnline: bridge.daemonOnline,
|
|
23
|
+
};
|
|
24
|
+
}, [bridge]);
|
|
25
|
+
const workingDirectoryAccess = useMemo(() => {
|
|
26
|
+
if (bridge === undefined)
|
|
27
|
+
return undefined;
|
|
28
|
+
return {
|
|
29
|
+
normalizeWorkingDirectory: (directory) => bridge.normalizeWorkingDirectory({ directory }),
|
|
30
|
+
pickWorkingDirectory: (currentDirectory) => bridge.pickWorkingDirectory({}, { currentDirectory }),
|
|
31
|
+
recentDirectories: bridge.recentWorkingDirectories,
|
|
32
|
+
directoryExists: (directory) => bridge.workingDirectoryExists({ directory }),
|
|
33
|
+
};
|
|
34
|
+
}, [bridge]);
|
|
35
|
+
const [binding, setBinding] = useState();
|
|
36
|
+
// Construction installs a listener, so setup and disposal must share an effect lifetime.
|
|
37
|
+
// StrictMode can discard a render and replay setup/cleanup without rebuilding memoized values.
|
|
38
|
+
// A new `createTransport` identity rebuilds the transport, so a host passes a module-level factory.
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (bridge === undefined) {
|
|
41
|
+
setBinding(undefined);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const transport = createTransport(bridge);
|
|
45
|
+
setBinding({ bridge, transport });
|
|
46
|
+
return () => transport.dispose();
|
|
47
|
+
}, [bridge, createTransport]);
|
|
48
|
+
const transport = binding?.bridge === bridge ? binding?.transport : undefined;
|
|
49
|
+
// A bridge host has no HTTP server, so this is the staging uploader
|
|
50
|
+
// (`create-staged-attachment-uploader.ts`), not the daemon-backed one — see that module's doc.
|
|
51
|
+
const uploadAttachments = useMemo(() => (bridge === undefined ? undefined : createStagedAttachmentUploader({ bridge })), [bridge]);
|
|
52
|
+
return {
|
|
53
|
+
transport,
|
|
54
|
+
runtimeAccess,
|
|
55
|
+
workingDirectoryAccess,
|
|
56
|
+
getPathForFile: bridge?.getPathForFile,
|
|
57
|
+
uploadAttachments,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=useBridgedChatTransport.hooks.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/chat/react/bridged-chat` — `ChatPane` surfaces for a host that reaches its runtime,
|
|
3
|
+
* working directories and attachment staging through one injected bridge instead of HTTP.
|
|
4
|
+
*/
|
|
5
|
+
export { createStagedAttachmentUploader } from './create-staged-attachment-uploader.js';
|
|
6
|
+
export { useBridgedChatTransport } from './hooks/useBridgedChatTransport.hooks.js';
|
|
7
|
+
export type { AttachmentStagingPort, BridgedChatTransport, ChatBridgePort, DisposableChatTransport, } from './types.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/chat/react/bridged-chat` — `ChatPane` surfaces for a host that reaches its runtime,
|
|
3
|
+
* working directories and attachment staging through one injected bridge instead of HTTP.
|
|
4
|
+
*/
|
|
5
|
+
export { createStagedAttachmentUploader } from './create-staged-attachment-uploader.js';
|
|
6
|
+
export { useBridgedChatTransport } from './hooks/useBridgedChatTransport.hooks.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Structural ports for a chat pane whose host reaches its agent runtime, working directories
|
|
3
|
+
* and attachment staging through one injected bridge object (an Electron preload bridge, typically)
|
|
4
|
+
* instead of HTTP. A host's own bridge satisfies these as-is.
|
|
5
|
+
*/
|
|
6
|
+
import type { ChatPaneProps, ChatPaneRuntimeAccess, ChatPaneWorkingDirectoryAccess } from '../chat-pane/types.js';
|
|
7
|
+
/** Writes one file's bytes into the host's staging area and answers with the staged absolute path. */
|
|
8
|
+
export interface AttachmentStagingPort {
|
|
9
|
+
/** `name` is the `File`'s original name; a host derives at most an extension from it, never a path. */
|
|
10
|
+
saveChatAttachment: (input: {
|
|
11
|
+
name: string;
|
|
12
|
+
data: ArrayBuffer;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
path: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
/** The slice of a host bridge {@link useBridgedChatTransport} reads. */
|
|
18
|
+
export interface ChatBridgePort extends AttachmentStagingPort {
|
|
19
|
+
listAgents: ChatPaneRuntimeAccess['listAgents'];
|
|
20
|
+
rescanAgents: ChatPaneRuntimeAccess['rescanAgents'];
|
|
21
|
+
daemonOnline: ChatPaneRuntimeAccess['daemonOnline'];
|
|
22
|
+
normalizeWorkingDirectory: (required: {
|
|
23
|
+
directory: string;
|
|
24
|
+
}) => Promise<string | null>;
|
|
25
|
+
pickWorkingDirectory: (required: Record<string, never>, options?: {
|
|
26
|
+
currentDirectory?: string | undefined;
|
|
27
|
+
}) => Promise<string | null>;
|
|
28
|
+
recentWorkingDirectories: ChatPaneWorkingDirectoryAccess['recentDirectories'];
|
|
29
|
+
workingDirectoryExists: (required: {
|
|
30
|
+
directory: string;
|
|
31
|
+
}) => Promise<boolean>;
|
|
32
|
+
/** Resolves a dropped/picked `File` to its absolute path without a round trip. */
|
|
33
|
+
getPathForFile: (file: File) => string;
|
|
34
|
+
}
|
|
35
|
+
/** A run transport built on the bridge. Construction may install a listener, which `dispose` removes. */
|
|
36
|
+
export interface DisposableChatTransport {
|
|
37
|
+
dispose: () => void;
|
|
38
|
+
}
|
|
39
|
+
/** What {@link useBridgedChatTransport} hands a chat pane. Every field is `undefined` without a bridge. */
|
|
40
|
+
export interface BridgedChatTransport<TTransport extends DisposableChatTransport = DisposableChatTransport> {
|
|
41
|
+
transport: TTransport | undefined;
|
|
42
|
+
runtimeAccess: ChatPaneRuntimeAccess | undefined;
|
|
43
|
+
workingDirectoryAccess: ChatPaneWorkingDirectoryAccess | undefined;
|
|
44
|
+
/** `undefined` only when the bridge itself is. See {@link ChatBridgePort.getPathForFile}. */
|
|
45
|
+
getPathForFile: ((file: File) => string) | undefined;
|
|
46
|
+
/** `undefined` only when the bridge itself is. See `createStagedAttachmentUploader`. */
|
|
47
|
+
uploadAttachments: ChatPaneProps['uploadAttachments'];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -6,7 +6,7 @@ import { agentHandleProps, agentHandleSegment } from '@jini-ai/core/agent-handle
|
|
|
6
6
|
import { createRuntimeDropUpTipHandler, useRuntimeDropUp } from '../hooks/useRuntimeDropUp.hooks.js';
|
|
7
7
|
/** The full `valueLabel` in the same white bubble `InfoTip` uses, portalled to `document.body`. */
|
|
8
8
|
function RuntimeDropUpTipBubble({ tip, valueLabel }) {
|
|
9
|
-
return createPortal(_jsx("span", { ref: tip.bubbleRef, className: tip.placement === 'below' ? 'info-tip-bubble info-tip-bubble-below' : 'info-tip-bubble', role: "presentation", "aria-hidden": "true", style: infoTipBubbleStyle(tip.coords), children: valueLabel }), document.body);
|
|
9
|
+
return createPortal(_jsx("span", { ref: tip.bubbleRef, className: tip.placement === 'below' ? 'jini-ui-info-tip-bubble jini-ui-info-tip-bubble-below' : 'jini-ui-info-tip-bubble', role: "presentation", "aria-hidden": "true", style: infoTipBubbleStyle(tip.coords), children: valueLabel }), document.body);
|
|
10
10
|
}
|
|
11
11
|
function RuntimeDropUpMenu({ base, dropUp, label, value, options, onSelect, note }) {
|
|
12
12
|
if (!dropUp.open || !dropUp.position)
|
|
@@ -2,6 +2,12 @@ import type { ChatPaneProps } from './types.js';
|
|
|
2
2
|
export interface CreateDaemonAttachmentUploaderOptions {
|
|
3
3
|
/** Per-file cap checked before any request is sent. Defaults to 20 MB, matching the route pack. */
|
|
4
4
|
readonly maxAttachmentBytes?: number;
|
|
5
|
+
/** Per-file cap chosen from the file itself (a host that lets videos exceed every other type passes one
|
|
6
|
+
* function backed by its single upload-limit source). Wins over {@link maxAttachmentBytes} when given. */
|
|
7
|
+
readonly maxAttachmentBytesFor?: (file: {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly type: string;
|
|
10
|
+
}) => number;
|
|
5
11
|
/** Files per composer turn. Defaults to 10, matching the route pack. */
|
|
6
12
|
readonly maxAttachmentCount?: number;
|
|
7
13
|
/** Total bytes per composer turn. Defaults to 50 MB, matching the route pack. */
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module create-daemon-attachment-uploader
|
|
3
|
+
*
|
|
4
|
+
* The client half of `@jini-ai/http-kit`'s attachment capability: a ready-made
|
|
5
|
+
* `ChatPaneProps['uploadAttachments']` that talks to `POST`/`DELETE /api/attachments`.
|
|
6
|
+
*
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <ChatPane transport={transport} uploadAttachments={createDaemonAttachmentUploader({ baseUrl: daemonUrl, fetch })} />
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* That one line is the whole wire-up for composer drag-and-drop and the file picker — `ChatPane`
|
|
12
|
+
* gates both on `uploadAttachments` being present (see `ChatPane.tsx`'s `resolveDropTargetProps`).
|
|
13
|
+
*
|
|
14
|
+
* **Why the client enforces quotas at all**, when the daemon enforces them anyway: a user who drags
|
|
15
|
+
* in a 400 MB video should be told immediately, not after the browser has finished streaming it to
|
|
16
|
+
* localhost. These checks are a courtesy, never the security boundary — the daemon re-derives every
|
|
17
|
+
* one of them, and only its answer decides anything.
|
|
18
|
+
*
|
|
19
|
+
* **Bounded concurrency, preserved order.** Two workers pull from a shared index, so at most two
|
|
20
|
+
* requests are in flight while results still land at their input positions. The first failure aborts
|
|
21
|
+
* the rest and deletes whatever already landed, so a partly-uploaded turn never leaves files behind
|
|
22
|
+
* on the daemon waiting for their TTL.
|
|
23
|
+
*
|
|
24
|
+
* **`content-type` is always `application/octet-stream`**, deliberately not `file.type`. The daemon
|
|
25
|
+
* sniffs the real kind from the leading bytes and ignores this header entirely, so forwarding the
|
|
26
|
+
* browser's guess buys nothing — and actively breaks things: a dropped `.json` file gets
|
|
27
|
+
* `content-type: application/json` from the browser, which an app-wide `express.json()` on the
|
|
28
|
+
* daemon then claims, draining the request stream before the upload route can read a byte. A fixed
|
|
29
|
+
* octet-stream type is immune to every body parser.
|
|
30
|
+
*/
|
|
31
|
+
import { describeUploadOverLimit } from "@jini-ai/core/text";
|
|
1
32
|
const DEFAULTS = {
|
|
2
33
|
maxAttachmentBytes: 20 * 1024 * 1024,
|
|
3
34
|
maxAttachmentCount: 10,
|
|
@@ -45,8 +76,10 @@ async function messageForFailedUpload(response, fallback) {
|
|
|
45
76
|
}
|
|
46
77
|
/** Refuses a selection that would break a per-file, per-turn count, or per-turn byte quota. */
|
|
47
78
|
function assertWithinQuota({ files, current, incomingBytes, quota }) {
|
|
48
|
-
|
|
49
|
-
|
|
79
|
+
const capOf = (file) => quota.maxAttachmentBytesFor?.(file) ?? quota.maxAttachmentBytes;
|
|
80
|
+
const tooBig = files.find((file) => file.size > capOf(file));
|
|
81
|
+
if (tooBig) {
|
|
82
|
+
throw new Error(describeUploadOverLimit({ fileBytes: tooBig.size, limitBytes: capOf(tooBig) }));
|
|
50
83
|
}
|
|
51
84
|
if (current.count + files.length > quota.maxAttachmentCount) {
|
|
52
85
|
throw new Error(`You can attach at most ${quota.maxAttachmentCount} files to one message.`);
|
|
@@ -103,6 +136,67 @@ function throwIfUploadFailed({ firstError, signal }) {
|
|
|
103
136
|
: new Error('Attachment upload was canceled.');
|
|
104
137
|
}
|
|
105
138
|
}
|
|
139
|
+
async function uploadOneAttachment({ file, batchId, signal, send, endpoint }) {
|
|
140
|
+
const query = new URLSearchParams({ batch: batchId, name: file.name });
|
|
141
|
+
const response = await send(`${endpoint}?${query}`, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
// Fixed, not `file.type` — see this module's doc.
|
|
144
|
+
headers: { 'content-type': 'application/octet-stream' },
|
|
145
|
+
body: file,
|
|
146
|
+
signal,
|
|
147
|
+
});
|
|
148
|
+
if (!response.ok) {
|
|
149
|
+
throw new Error(await messageForFailedUpload(response, `Could not attach ${file.name}`));
|
|
150
|
+
}
|
|
151
|
+
const body = (await response.json());
|
|
152
|
+
if (!body.attachment) {
|
|
153
|
+
throw new Error(`The daemon did not return an attachment for ${file.name}`);
|
|
154
|
+
}
|
|
155
|
+
return body.attachment;
|
|
156
|
+
}
|
|
157
|
+
async function deletePartialAttachments({ batchId, attachments, send, endpoint }) {
|
|
158
|
+
if (attachments.length === 0)
|
|
159
|
+
return;
|
|
160
|
+
try {
|
|
161
|
+
// QUICK, not the upload's own composed timeout: this has no
|
|
162
|
+
// caller-supplied signal to compose with and no large body — it is a small best-effort JSON
|
|
163
|
+
// DELETE, and an unprotected `fetch` here would hang `uploadAttachments`'s rejection (the
|
|
164
|
+
// `await` below) on a stalled daemon instead of surfacing `firstError` promptly.
|
|
165
|
+
await send(endpoint, {
|
|
166
|
+
method: 'DELETE',
|
|
167
|
+
signal: AbortSignal.timeout(15_000),
|
|
168
|
+
headers: { 'content-type': 'application/json' },
|
|
169
|
+
body: JSON.stringify({ batchId, paths: attachments.map((attachment) => attachment.path) }),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// Best effort by design: the daemon expires unclaimed uploads on its own, so a failed cleanup
|
|
174
|
+
// costs disk until the TTL rather than leaking indefinitely. Never worth failing the turn for.
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function reserveAttachmentBatch({ files, requestedBatch, quota, batchUsage, now, newBatchId }) {
|
|
178
|
+
pruneBatchUsage(batchUsage, now);
|
|
179
|
+
const batchId = requestedBatch?.batchId ?? newBatchId();
|
|
180
|
+
const incomingBytes = files.reduce((total, file) => total + file.size, 0);
|
|
181
|
+
const current = batchUsage.get(batchId) ?? { count: 0, bytes: 0, touchedAt: now };
|
|
182
|
+
assertWithinQuota({ files, current, incomingBytes, quota });
|
|
183
|
+
// Reserved up front and rolled back on failure, so two overlapping calls for the same turn
|
|
184
|
+
// cannot each see the same free headroom.
|
|
185
|
+
batchUsage.set(batchId, {
|
|
186
|
+
count: current.count + files.length,
|
|
187
|
+
bytes: current.bytes + incomingBytes,
|
|
188
|
+
touchedAt: now,
|
|
189
|
+
});
|
|
190
|
+
return { batchId, current };
|
|
191
|
+
}
|
|
192
|
+
function resolveUploadQuota({ options }) {
|
|
193
|
+
return {
|
|
194
|
+
maxAttachmentBytes: options.maxAttachmentBytes ?? DEFAULTS.maxAttachmentBytes,
|
|
195
|
+
maxAttachmentBytesFor: options.maxAttachmentBytesFor,
|
|
196
|
+
maxAttachmentCount: options.maxAttachmentCount ?? DEFAULTS.maxAttachmentCount,
|
|
197
|
+
maxBatchBytes: options.maxBatchBytes ?? DEFAULTS.maxBatchBytes,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
106
200
|
/**
|
|
107
201
|
* Builds a `ChatPaneProps['uploadAttachments']` bound to one daemon.
|
|
108
202
|
*
|
|
@@ -110,11 +204,7 @@ function throwIfUploadFailed({ firstError, signal }) {
|
|
|
110
204
|
* when the page is served through a proxy that already forwards `/api`.
|
|
111
205
|
*/
|
|
112
206
|
export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {}) {
|
|
113
|
-
const quota = {
|
|
114
|
-
maxAttachmentBytes: options.maxAttachmentBytes ?? DEFAULTS.maxAttachmentBytes,
|
|
115
|
-
maxAttachmentCount: options.maxAttachmentCount ?? DEFAULTS.maxAttachmentCount,
|
|
116
|
-
maxBatchBytes: options.maxBatchBytes ?? DEFAULTS.maxBatchBytes,
|
|
117
|
-
};
|
|
207
|
+
const quota = resolveUploadQuota({ options });
|
|
118
208
|
const timeoutMs = options.timeoutMs ?? DEFAULTS.timeoutMs;
|
|
119
209
|
const concurrency = options.concurrency ?? DEFAULTS.concurrency;
|
|
120
210
|
const endpoint = `${baseUrl.replace(/\/$/u, '')}/api/attachments`;
|
|
@@ -122,59 +212,11 @@ export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {})
|
|
|
122
212
|
const send = (input, init) => (fetch ?? globalThis.fetch)(input, init);
|
|
123
213
|
// Per-uploader, not module-level: two panes pointed at two daemons must not share a quota.
|
|
124
214
|
const batchUsage = new Map();
|
|
125
|
-
async function uploadOne(file, batchId, signal) {
|
|
126
|
-
const query = new URLSearchParams({ batch: batchId, name: file.name });
|
|
127
|
-
const response = await send(`${endpoint}?${query}`, {
|
|
128
|
-
method: 'POST',
|
|
129
|
-
// Fixed, not `file.type` — see this module's doc.
|
|
130
|
-
headers: { 'content-type': 'application/octet-stream' },
|
|
131
|
-
body: file,
|
|
132
|
-
signal,
|
|
133
|
-
});
|
|
134
|
-
if (!response.ok) {
|
|
135
|
-
throw new Error(await messageForFailedUpload(response, `Could not attach ${file.name}`));
|
|
136
|
-
}
|
|
137
|
-
const body = (await response.json());
|
|
138
|
-
if (!body.attachment) {
|
|
139
|
-
throw new Error(`The daemon did not return an attachment for ${file.name}`);
|
|
140
|
-
}
|
|
141
|
-
return body.attachment;
|
|
142
|
-
}
|
|
143
|
-
async function deletePartialUpload(batchId, attachments) {
|
|
144
|
-
if (attachments.length === 0)
|
|
145
|
-
return;
|
|
146
|
-
try {
|
|
147
|
-
// QUICK, not `uploadOne`'s own composed timeout: unlike the upload itself, this has no
|
|
148
|
-
// caller-supplied signal to compose with and no large body — it is a small best-effort JSON
|
|
149
|
-
// DELETE, and an unprotected `fetch` here would hang `uploadAttachments`'s rejection (the
|
|
150
|
-
// `await` below) on a stalled daemon instead of surfacing `firstError` promptly.
|
|
151
|
-
await send(endpoint, {
|
|
152
|
-
method: 'DELETE',
|
|
153
|
-
signal: AbortSignal.timeout(15_000),
|
|
154
|
-
headers: { 'content-type': 'application/json' },
|
|
155
|
-
body: JSON.stringify({ batchId, paths: attachments.map((attachment) => attachment.path) }),
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
// Best effort by design: the daemon expires unclaimed uploads on its own, so a failed cleanup
|
|
160
|
-
// costs disk until the TTL rather than leaking indefinitely. Never worth failing the turn for.
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
215
|
return async function uploadAttachments(files, uploadOptions) {
|
|
164
216
|
if (files.length === 0)
|
|
165
217
|
return [];
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
const batchId = uploadOptions?.batchId ?? crypto.randomUUID();
|
|
169
|
-
const incomingBytes = files.reduce((total, file) => total + file.size, 0);
|
|
170
|
-
const current = batchUsage.get(batchId) ?? { count: 0, bytes: 0, touchedAt: now };
|
|
171
|
-
assertWithinQuota({ files, current, incomingBytes, quota });
|
|
172
|
-
// Reserved up front and rolled back on failure, so two overlapping calls for the same turn
|
|
173
|
-
// cannot each see the same free headroom.
|
|
174
|
-
batchUsage.set(batchId, {
|
|
175
|
-
count: current.count + files.length,
|
|
176
|
-
bytes: current.bytes + incomingBytes,
|
|
177
|
-
touchedAt: now,
|
|
218
|
+
const { batchId, current } = reserveAttachmentBatch({
|
|
219
|
+
files, requestedBatch: uploadOptions, quota, batchUsage, now: Date.now(), newBatchId: () => crypto.randomUUID(),
|
|
178
220
|
});
|
|
179
221
|
const controller = new AbortController();
|
|
180
222
|
const unlinkParentAbort = linkParentAbort({ controller, parent: uploadOptions?.signal });
|
|
@@ -192,7 +234,7 @@ export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {})
|
|
|
192
234
|
concurrency,
|
|
193
235
|
controller,
|
|
194
236
|
uploaded,
|
|
195
|
-
uploadOne: (file) =>
|
|
237
|
+
uploadOne: (file) => uploadOneAttachment({ file, batchId, signal: controller.signal, send, endpoint }),
|
|
196
238
|
});
|
|
197
239
|
throwIfUploadFailed({ firstError, signal: controller.signal });
|
|
198
240
|
succeeded = true;
|
|
@@ -208,7 +250,7 @@ export function createDaemonAttachmentUploader({ baseUrl, fetch }, options = {})
|
|
|
208
250
|
return settled();
|
|
209
251
|
// Roll the reservation back only after the daemon-side files are gone, so a retry of this turn
|
|
210
252
|
// starts from a clean slate on both sides.
|
|
211
|
-
await
|
|
253
|
+
await deletePartialAttachments({ batchId, attachments: settled(), send, endpoint });
|
|
212
254
|
batchUsage.set(batchId, current);
|
|
213
255
|
throw failure;
|
|
214
256
|
};
|
|
@@ -4,12 +4,15 @@ import type { MouseEvent as ReactMouseEvent } from 'react';
|
|
|
4
4
|
*
|
|
5
5
|
* @param input.event - The click, native (React's `nativeEvent` or a DOM listener's own).
|
|
6
6
|
* @param input.root - The pane root; an anchor outside it (one wrapping the whole pane) is ignored.
|
|
7
|
+
* @param options.origin - The origin that counts as the owner's own; defaults to the page's own.
|
|
7
8
|
* @returns The anchor's resolved absolute URL to open, or `null` to leave the click to the browser.
|
|
8
9
|
* @complexity O(d) for `closest` over the target's ancestor depth d.
|
|
9
10
|
*/
|
|
10
11
|
export declare function newTabLinkHref({ event, root }: {
|
|
11
12
|
event: MouseEvent;
|
|
12
13
|
root: Element;
|
|
14
|
+
}, { origin }?: {
|
|
15
|
+
origin?: string;
|
|
13
16
|
}): string | null;
|
|
14
17
|
/**
|
|
15
18
|
* The pane root's `onClickCapture` handler: opens qualifying link clicks in a new tab and cancels
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module useChatPaneNewTabLinks
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* conversation lives in
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* A link inside the chat pane to ANOTHER website opens in a new tab, so following it never navigates
|
|
5
|
+
* the tab the conversation lives in. A link to the owner's own site or admin is left alone (owner
|
|
6
|
+
* decision 2026-11-21, reversing 2026-10-08's "every link"): its text navigates the current tab — the
|
|
7
|
+
* admin's own link handler turns an admin path into an in-app navigation, so the chat dock stays —
|
|
8
|
+
* and the small icon `MarkdownLink` draws after it opens the new tab instead. One capture-phase click
|
|
9
|
+
* guard on the pane's root covers every link source at once — markdown in messages, tool cards,
|
|
10
|
+
* host-registered ext-event cards, A2UI surfaces, the header slot — instead of each renderer setting
|
|
11
|
+
* `target` on its own anchors and the next new card forgetting to.
|
|
9
12
|
*
|
|
10
13
|
* Capture phase, then `preventDefault()`: the guard runs before any anchor's own `onClick`, so a
|
|
11
14
|
* router `<Link>` (React Router, TanStack Router — both skip their in-app navigation once
|
|
12
15
|
* `defaultPrevented` is set) does not ALSO navigate the chat's tab after the new tab opens.
|
|
13
16
|
*
|
|
14
|
-
* Left to the browser:
|
|
15
|
-
* user asked), anchors that already say
|
|
16
|
-
* links, `role="button"` anchors (an action,
|
|
17
|
-
* `mailto:`/`tel:` hand off to another app without
|
|
17
|
+
* Left to the browser: the owner's own links (see `isOwnLinkHref`), modified or non-primary clicks
|
|
18
|
+
* (the browser already opens those however the user asked), anchors that already say
|
|
19
|
+
* `target="_blank"`, `#` same-document anchors, `download` links, `role="button"` anchors (an action,
|
|
20
|
+
* not a link), and any scheme other than http(s) — `mailto:`/`tel:` hand off to another app without
|
|
21
|
+
* navigating the tab anyway.
|
|
18
22
|
*
|
|
19
23
|
* MCP-UI Views render inside a sandboxed iframe, out of this guard's reach; their proxy page
|
|
20
24
|
* forwards link clicks as `ui/open-link` (`@jini-ai/ui/mcp-ui`'s sandbox proxy) instead.
|
|
21
25
|
*/
|
|
22
26
|
import { useCallback } from 'react';
|
|
27
|
+
import { currentOrigin, isOwnLinkHref } from '../../../components/own-link.js';
|
|
23
28
|
const NEW_TAB_PROTOCOLS = new Set(['http:', 'https:']);
|
|
24
29
|
/** Opens `url` in a new tab with no opener or referrer — `rel="noopener noreferrer"` for `window.open`. */
|
|
25
30
|
function openInNewTabDefault(url) {
|
|
@@ -38,35 +43,40 @@ function isPlainPrimaryClick({ event }) {
|
|
|
38
43
|
return !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey);
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
41
|
-
* Whether an anchor is an ordinary in-tab
|
|
42
|
-
*
|
|
46
|
+
* Whether an anchor is an ordinary in-tab link to ANOTHER website that the guard should redirect to
|
|
47
|
+
* a new tab — not the owner's own site or admin, one already opening elsewhere, a download, an
|
|
48
|
+
* action styled as a link, or a `#` same-document jump.
|
|
43
49
|
*
|
|
44
50
|
* @param input.link - An anchor matched by `a[href]`, so its `href` attribute is present.
|
|
45
|
-
* @
|
|
51
|
+
* @param input.origin - The origin that counts as the owner's own.
|
|
52
|
+
* @returns `true` when following the link would navigate the chat's own tab away to another website.
|
|
46
53
|
*/
|
|
47
|
-
function
|
|
54
|
+
function isInTabOtherWebsiteLink({ link, origin }) {
|
|
48
55
|
if (link.target === '_blank' || link.hasAttribute('download') || link.getAttribute('role') === 'button')
|
|
49
56
|
return false;
|
|
50
57
|
if (link.getAttribute('href').startsWith('#'))
|
|
51
58
|
return false;
|
|
52
|
-
|
|
59
|
+
if (!NEW_TAB_PROTOCOLS.has(link.protocol))
|
|
60
|
+
return false;
|
|
61
|
+
return !isOwnLinkHref({ href: link.href, origin });
|
|
53
62
|
}
|
|
54
63
|
/**
|
|
55
64
|
* Decides whether a click inside the pane should open a link in a new tab.
|
|
56
65
|
*
|
|
57
66
|
* @param input.event - The click, native (React's `nativeEvent` or a DOM listener's own).
|
|
58
67
|
* @param input.root - The pane root; an anchor outside it (one wrapping the whole pane) is ignored.
|
|
68
|
+
* @param options.origin - The origin that counts as the owner's own; defaults to the page's own.
|
|
59
69
|
* @returns The anchor's resolved absolute URL to open, or `null` to leave the click to the browser.
|
|
60
70
|
* @complexity O(d) for `closest` over the target's ancestor depth d.
|
|
61
71
|
*/
|
|
62
|
-
export function newTabLinkHref({ event, root }) {
|
|
72
|
+
export function newTabLinkHref({ event, root }, { origin = currentOrigin() } = {}) {
|
|
63
73
|
const target = event.target;
|
|
64
74
|
if (!isPlainPrimaryClick({ event }) || !(target instanceof Element))
|
|
65
75
|
return null;
|
|
66
76
|
const link = target.closest('a[href]');
|
|
67
77
|
if (!(link instanceof HTMLAnchorElement) || !root.contains(link))
|
|
68
78
|
return null;
|
|
69
|
-
return
|
|
79
|
+
return isInTabOtherWebsiteLink({ link, origin }) ? link.href : null;
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
72
82
|
* The pane root's `onClickCapture` handler: opens qualifying link clicks in a new tab and cancels
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { I18nAdapter } from '../../slots.js';
|
|
2
2
|
import type { ChatPaneAgent, ChatPaneAgentOption } from './types.js';
|
|
3
|
-
export declare function isConcretePickerModel(id
|
|
3
|
+
export declare function isConcretePickerModel({ id }: {
|
|
4
|
+
id: string;
|
|
5
|
+
}, _optional?: Record<string, never>): boolean;
|
|
4
6
|
/** Aliases are selectable only as their evidence-backed concrete ID. Never render a Default row.
|
|
5
7
|
* Keeps the first position per concrete ID, upgrading raw-ID labels from later human labels.
|
|
6
8
|
* Legacy Default labels are rewritten to the ID before deduplication, never used as human labels.
|
|
@@ -4,7 +4,7 @@ import { codexBarVendorWords } from './codex/model-options.js';
|
|
|
4
4
|
import { antigravityBarVendorWords } from './antigravity/model-options.js';
|
|
5
5
|
// Model names and timestamps are metadata; only surrounding picker copy is translated.
|
|
6
6
|
const passthrough = key => key;
|
|
7
|
-
export function isConcretePickerModel(id) {
|
|
7
|
+
export function isConcretePickerModel({ id }, _optional = {}) {
|
|
8
8
|
return modelIdentityKind({ id }) === 'concrete';
|
|
9
9
|
}
|
|
10
10
|
/** Aliases are selectable only as their evidence-backed concrete ID. Never render a Default row.
|
|
@@ -20,13 +20,13 @@ export function configuredPickerModel(agent) {
|
|
|
20
20
|
if (agent.supportsConcreteModelSelection === false)
|
|
21
21
|
return undefined;
|
|
22
22
|
const resolution = agent.defaultModelResolution;
|
|
23
|
-
return resolution?.status === 'resolved' && isConcretePickerModel(resolution.id) ? resolution.id : undefined;
|
|
23
|
+
return resolution?.status === 'resolved' && isConcretePickerModel({ id: resolution.id }) ? resolution.id : undefined;
|
|
24
24
|
}
|
|
25
25
|
export function pickerModelLabel(agent, requested, t = passthrough) {
|
|
26
26
|
if (!agent)
|
|
27
27
|
return t('Choose model');
|
|
28
28
|
const id = !requested || requested === 'default' ? configuredPickerModel(agent) : requested;
|
|
29
|
-
if (!id || !isConcretePickerModel(id))
|
|
29
|
+
if (!id || !isConcretePickerModel({ id }))
|
|
30
30
|
return t('Choose model');
|
|
31
31
|
return pickerModelOptions(agent).find((row) => row.id === id)?.label || id;
|
|
32
32
|
}
|
|
@@ -26,7 +26,7 @@ function isSelectableAgent(agent) {
|
|
|
26
26
|
/** A concrete custom model passes through when the agent accepts one; anything else must be on the picker list. */
|
|
27
27
|
function resolveRequestedModel({ agent, requested, fallback }) {
|
|
28
28
|
const acceptsCustom = agent.supportsCustomModel && agent.supportsConcreteModelSelection !== false;
|
|
29
|
-
if (requested && acceptsCustom && isConcretePickerModel(requested))
|
|
29
|
+
if (requested && acceptsCustom && isConcretePickerModel({ id: requested }))
|
|
30
30
|
return requested;
|
|
31
31
|
return validatedOptionId(pickerModelOptions(agent), requested, fallback);
|
|
32
32
|
}
|
|
@@ -95,7 +95,7 @@ function isModelUnresolved({ agent, model }) {
|
|
|
95
95
|
const refusesConcrete = agent.supportsConcreteModelSelection === false;
|
|
96
96
|
if (!agent.modelCatalog && !refusesConcrete)
|
|
97
97
|
return false;
|
|
98
|
-
return refusesConcrete || !model || !isConcretePickerModel(model);
|
|
98
|
+
return refusesConcrete || !model || !isConcretePickerModel({ id: model });
|
|
99
99
|
}
|
|
100
100
|
/** The agent/model half of {@link findChatPaneSendBlocker}: a configured API mode stands in for a missing CLI. */
|
|
101
101
|
function findAgentSendBlocker(state) {
|
|
@@ -151,7 +151,8 @@ const ATTACHMENT_DETAILS_MAX = 300;
|
|
|
151
151
|
export function describeAttachmentError({ error }) {
|
|
152
152
|
const redacted = redactUserText({ text: error.message }).text.trim();
|
|
153
153
|
return {
|
|
154
|
-
|
|
154
|
+
// A failed file is never staged, so there is no chip to remove: the only action is to choose it again.
|
|
155
|
+
summary: 'Attachment upload failed. The file was not attached. Choose it again to retry.',
|
|
155
156
|
details: redacted.length > ATTACHMENT_DETAILS_MAX ? `${redacted.slice(0, ATTACHMENT_DETAILS_MAX)}…` : redacted,
|
|
156
157
|
};
|
|
157
158
|
}
|