@jini-ai/chat 0.7.2 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -12
- package/README.md +3 -3
- package/dist/contracts/chat-bubble-style.d.ts +1 -1
- package/dist/contracts/chat-bubble-style.js +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +125 -0
- package/dist/core/ag-ui/event-projection.js +275 -0
- package/dist/core/ag-ui/event-reduction.d.ts +39 -0
- package/dist/core/ag-ui/event-reduction.js +99 -0
- package/dist/core/ag-ui/run-input.d.ts +53 -0
- package/dist/core/ag-ui/run-input.js +87 -0
- package/dist/core/agentic/chat-capabilities.d.ts +1 -1
- package/dist/core/agentic/index.d.ts +2 -4
- package/dist/core/agentic/index.js +2 -3
- package/dist/core/agents-port.d.ts +50 -0
- package/dist/core/agents-port.js +2 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +16 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +24 -0
- package/dist/core/assistant-client/ag-ui-transport.d.ts +15 -1
- package/dist/core/assistant-client/ag-ui-transport.js +167 -145
- package/dist/core/assistant-client/attachment-liveness.js +13 -11
- package/dist/core/assistant-client/durable-run-subscription.d.ts +3 -2
- package/dist/core/assistant-client/durable-run-subscription.js +6 -5
- package/dist/core/assistant-client/messages.d.ts +7 -4
- package/dist/core/assistant-client/messages.js +5 -4
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +4 -4
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-port.d.ts +15 -0
- package/dist/core/page-port.js +2 -0
- package/dist/core/run-activity.js +1 -1
- package/dist/core/run-events/entry.js +1 -0
- package/dist/core/user-text-redaction.d.ts +1 -3
- package/dist/core/user-text-redaction.js +3 -61
- package/dist/embed-widget/browser/agent-inventory.d.ts +37 -0
- package/dist/embed-widget/browser/agent-inventory.js +36 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +2 -2
- package/dist/embed-widget/browser/frontend-session-bridge.js +17 -14
- package/dist/embed-widget/react/dialog.hooks.d.ts +16 -0
- package/dist/embed-widget/react/dialog.hooks.js +15 -0
- package/dist/embed-widget/react/embed.d.ts +7 -2
- package/dist/embed-widget/react/embed.js +6 -16
- package/dist/embed-widget/react/header.d.ts +4 -1
- package/dist/embed-widget/react/header.js +2 -2
- package/dist/embed-widget/vanilla/state.js +2 -2
- package/dist/embed-widget/vanilla/style.css +4 -4
- package/dist/react/components/A2uiSurfaceCard.d.ts +18 -4
- package/dist/react/components/A2uiSurfaceCard.hooks.d.ts +36 -0
- package/dist/react/components/A2uiSurfaceCard.hooks.js +174 -0
- package/dist/react/components/A2uiSurfaceCard.js +14 -227
- package/dist/react/components/A2uiSurfaceCard.rules.d.ts +14 -0
- package/dist/react/components/A2uiSurfaceCard.rules.js +24 -0
- package/dist/react/components/AttachmentPreviewModal.d.ts +21 -1
- package/dist/react/components/AttachmentPreviewModal.hooks.js +1 -3
- package/dist/react/components/AttachmentPreviewModal.js +11 -9
- package/dist/react/components/AttachmentTray.d.ts +11 -1
- package/dist/react/components/AttachmentTray.js +12 -8
- package/dist/react/components/ChatFab.d.ts +10 -1
- package/dist/react/components/ChatFab.js +2 -2
- package/dist/react/components/ChatSettingsDialog.d.ts +4 -3
- package/dist/react/components/ChatSettingsDialog.js +9 -6
- package/dist/react/components/ChatSettingsSegmented.d.ts +1 -1
- package/dist/react/components/ChatSettingsSegmented.js +1 -1
- package/dist/react/components/Composer.d.ts +9 -1
- package/dist/react/components/Composer.hooks.d.ts +79 -0
- package/dist/react/components/Composer.hooks.js +336 -0
- package/dist/react/components/Composer.js +40 -341
- package/dist/react/components/ComposerDiscovery.js +1 -1
- package/dist/react/components/ConversationList.d.ts +34 -1
- package/dist/react/components/ConversationList.hooks.d.ts +37 -0
- package/dist/react/components/ConversationList.hooks.js +177 -1
- package/dist/react/components/ConversationList.js +7 -174
- package/dist/react/components/ConversationTitleEditor.d.ts +17 -2
- package/dist/react/components/ConversationTitleEditor.hooks.d.ts +15 -0
- package/dist/react/components/ConversationTitleEditor.hooks.js +36 -0
- package/dist/react/components/ConversationTitleEditor.js +11 -34
- package/dist/react/components/CopyMessageButton.d.ts +6 -1
- package/dist/react/components/CopyMessageButton.js +4 -4
- package/dist/react/components/ExtEventErrorBoundary.d.ts +2 -0
- package/dist/react/components/ExtEventErrorBoundary.js +5 -3
- package/dist/react/components/FolderChips.d.ts +11 -1
- package/dist/react/components/FolderChips.hooks.d.ts +12 -0
- package/dist/react/components/FolderChips.hooks.js +10 -0
- package/dist/react/components/FolderChips.js +9 -9
- package/dist/react/components/Markdown.js +7 -5
- package/dist/react/components/McpUiSurfaceCard.d.ts +29 -5
- package/dist/react/components/McpUiSurfaceCard.js +29 -16
- package/dist/react/components/MessageList.d.ts +10 -1
- package/dist/react/components/MessageList.hooks.d.ts +0 -4
- package/dist/react/components/MessageList.hooks.js +6 -18
- package/dist/react/components/MessageList.js +17 -20
- package/dist/react/components/MessageList.rules.d.ts +0 -5
- package/dist/react/components/MessageList.rules.js +0 -4
- package/dist/react/components/MessageRow.d.ts +46 -2
- package/dist/react/components/MessageRow.hooks.d.ts +60 -0
- package/dist/react/components/MessageRow.hooks.js +94 -0
- package/dist/react/components/MessageRow.js +53 -113
- package/dist/react/components/MidRunUserMessage.d.ts +6 -1
- package/dist/react/components/MidRunUserMessage.js +5 -5
- package/dist/react/components/NextStepActions.d.ts +3 -1
- package/dist/react/components/NextStepActions.js +3 -3
- package/dist/react/components/QuestionForm.answers.hooks.d.ts +26 -0
- package/dist/react/components/QuestionForm.answers.hooks.js +89 -0
- package/dist/react/components/QuestionForm.d.ts +6 -0
- package/dist/react/components/QuestionForm.js +23 -261
- package/dist/react/components/QuestionForm.values.d.ts +22 -0
- package/dist/react/components/QuestionForm.values.js +58 -0
- package/dist/react/components/QuestionFormField.d.ts +17 -0
- package/dist/react/components/QuestionFormField.js +114 -0
- package/dist/react/components/QuestionsPanel.d.ts +3 -1
- package/dist/react/components/QuestionsPanel.js +7 -3
- package/dist/react/components/SentAttachment.d.ts +11 -2
- package/dist/react/components/SentAttachment.hooks.d.ts +1 -1
- package/dist/react/components/SentAttachment.hooks.js +6 -5
- package/dist/react/components/SentAttachment.js +5 -3
- package/dist/react/components/TodoCard.d.ts +3 -1
- package/dist/react/components/TodoCard.js +9 -4
- package/dist/react/components/ToolCallGroup.d.ts +11 -1
- package/dist/react/components/ToolCallGroup.js +10 -4
- package/dist/react/components/ToolCard.d.ts +6 -1
- package/dist/react/components/ToolCard.js +79 -69
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-question-input.js +3 -3
- package/dist/react/components/mcp-ui-surface-state.d.ts +1 -1
- package/dist/react/features/chat-pane/agent-tools.d.ts +1 -1
- package/dist/react/features/chat-pane/antigravity/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/antigravity/model-options.js +2 -0
- package/dist/react/features/chat-pane/claude/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/claude/model-options.js +2 -0
- package/dist/react/features/chat-pane/codex/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/codex/model-options.js +2 -0
- package/dist/react/features/chat-pane/components/AgentPluginUsage.d.ts +4 -1
- package/dist/react/features/chat-pane/components/AgentPluginUsage.js +2 -2
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.d.ts +10 -6
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.js +18 -132
- package/dist/react/features/chat-pane/components/ChatPane.d.ts +24 -2
- package/dist/react/features/chat-pane/components/ChatPane.js +45 -297
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.d.ts +33 -0
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.js +119 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.d.ts +42 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.js +54 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.d.ts +27 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.js +91 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.d.ts +6 -1
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +20 -19
- package/dist/react/features/chat-pane/components/RuntimePickerSections.d.ts +62 -0
- package/dist/react/features/chat-pane/components/RuntimePickerSections.js +122 -0
- package/dist/react/features/chat-pane/create-mcp-ui-tool-caller.d.ts +1 -1
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.d.ts +5 -3
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.js +78 -26
- package/dist/react/features/chat-pane/hooks/useChatPaneAgentControl.hooks.js +6 -6
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.d.ts +5 -1
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.js +7 -7
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.d.ts +7 -0
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.js +5 -0
- package/dist/react/features/chat-pane/model-options.js +7 -4
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +25 -41
- package/dist/react/features/chat-pane/types.d.ts +29 -1
- package/dist/react/hooks/assistant-chats-contracts.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.js +1 -1
- package/dist/react/hooks/fab-position.js +16 -18
- package/dist/react/hooks/useConversation.d.ts +6 -1
- package/dist/react/hooks/useConversation.js +11 -10
- package/dist/react/hooks/useRunStream.d.ts +3 -0
- package/dist/react/hooks/useRunStream.js +12 -12
- package/dist/react/hooks/useSurfaceRecovery.d.ts +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +2 -2
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -3
- package/dist/react/styles/chat-settings.css +9 -9
- package/dist/react/surfaces.d.ts +91 -0
- package/dist/react/surfaces.js +28 -0
- package/dist/server/durable-runs/recover.d.ts +4 -3
- package/dist/server/durable-runs/recover.js +4 -3
- package/dist/store/legacy/sqlite/conversations.d.ts +1 -2
- package/dist/store/legacy/sqlite/conversations.js +1 -1
- package/dist/store/legacy/sqlite/messages.d.ts +2 -3
- package/dist/store/legacy/sqlite/messages.js +6 -6
- package/dist/store/pglite/index.d.ts +7 -7
- package/dist/store/pglite/index.js +1 -1
- package/dist/store/ports.d.ts +5 -2
- package/dist/store/postgres/index.d.ts +7 -7
- package/dist/store/postgres/index.js +1 -1
- package/dist/store/runtime/chat-expiry-sweep.js +2 -4
- package/dist/store/runtime/chat-history-store.js +2 -3
- package/dist/store/runtime/durable-run-store.js +16 -2
- package/dist/store/runtime/history-tools.js +33 -11
- package/dist/store/runtime/kernel.d.ts +3 -2
- package/dist/store/runtime/run-ledger.js +2 -2
- package/dist/store/sql/boundary.d.ts +5 -5
- package/dist/store/sql/maintenance.d.ts +3 -2
- package/dist/store/sql/store.d.ts +16 -8
- package/dist/store/sql/store.js +31 -14
- package/dist/store/sqlite/index.d.ts +11 -12
- package/dist/store/sqlite/index.js +5 -5
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/package.json +46 -24
- package/dist/core/ag-ui/entry.d.ts +0 -84
- package/dist/core/ag-ui/entry.js +0 -225
- package/dist/core/browser/page-actions.d.ts +0 -121
- package/dist/core/browser/page-actions.js +0 -113
- package/dist/embed-widget/browser/page-actions.d.ts +0 -2
- package/dist/embed-widget/browser/page-actions.js +0 -3
|
@@ -12,7 +12,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
* sent message's thumbnail reads) and opens the shared `AttachmentPreviewModal`, with previous/next
|
|
13
13
|
* across the staged images - before sending, the operator can check which screenshots are going.
|
|
14
14
|
*/
|
|
15
|
-
import { agentHandleProps, agentHandleSegment } from '@jini-ai/
|
|
15
|
+
import { agentHandleProps, agentHandleSegment } from '@jini-ai/core/agent-handles';
|
|
16
16
|
import { useT } from '../hooks/context.js';
|
|
17
17
|
import { Icon } from './Icon.js';
|
|
18
18
|
import { AttachmentPreviewModal } from './AttachmentPreviewModal.js';
|
|
@@ -22,17 +22,21 @@ import { useSentAttachmentThumbnail } from './SentAttachment.hooks.js';
|
|
|
22
22
|
import { formatAttachmentSize } from './attachment-size.js';
|
|
23
23
|
// Re-exported: callers and tests have always imported it from here.
|
|
24
24
|
export { formatAttachmentSize };
|
|
25
|
-
|
|
25
|
+
/** Hooks AttachmentTray calls; defaults to the real ones, a test hands in fakes. */
|
|
26
|
+
export const defaultAttachmentTrayHooks = { useT, useAttachmentGallery };
|
|
27
|
+
export function AttachmentTray({ agentHandle, attachments, onRemove, renderItem, objectUrls, uploading = false, hooks = defaultAttachmentTrayHooks }) {
|
|
26
28
|
const base = agentHandle || undefined;
|
|
27
|
-
const t = useT();
|
|
28
|
-
const gallery = useAttachmentGallery({ attachments });
|
|
29
|
+
const t = hooks.useT();
|
|
30
|
+
const gallery = hooks.useAttachmentGallery({ attachments });
|
|
29
31
|
if (attachments.length === 0 && !uploading)
|
|
30
32
|
return null;
|
|
31
|
-
return (_jsxs("div", { className: "jini-attachment-tray", "data-testid": "composer-attachment-tray", children: [attachments.map((a) => (_jsxs("div", { className: "jini-attachment-chip", "data-testid": "attachment-chip", "data-attachment-kind": a.kind, "data-attachment-name": a.name, children: [renderItem ? renderItem(a) : _jsx(DefaultAttachmentChip, { base: base, attachment: a, onOpen: gallery.open, objectUrls: objectUrls }), _jsx("button", { ...agentHandleProps({}, { base, action: `remove-${agentHandleSegment({ value: a.path })}`, role: 'button', label: t('Remove {name}', { name: a.name }) }), type: "button", className: "jini-attachment-remove", onClick: () => onRemove(a.path), title: t('Remove {name}', { name: a.name }), "aria-label": t('Remove {name}', { name: a.name }), children: _jsx(Icon, { name: "close", size: 12 }) })] }, a.path))), uploading ? (_jsxs("div", { className: "jini-attachment-chip is-uploading", "data-testid": "attachment-uploading-chip", children: [_jsx("span", { className: "jini-attachment-chip-icon", children: _jsx(Icon, { name: "spinner", size: 15 }) }), _jsx("span", { className: "jini-attachment-chip-copy", children: _jsx("span", { className: "jini-attachment-chip-name", children: t('Uploading…') }) })] })) : null, gallery.opened ? (_jsx(AttachmentPreviewModal, { attachment: gallery.opened, onClose: gallery.close, navigation: gallery.navigation })) : null] }));
|
|
33
|
+
return (_jsxs("div", { className: "jini-attachment-tray", "data-testid": "composer-attachment-tray", children: [attachments.map((a) => (_jsxs("div", { className: "jini-attachment-chip", "data-testid": "attachment-chip", "data-attachment-kind": a.kind, "data-attachment-name": a.name, children: [renderItem ? renderItem(a) : _jsx(DefaultAttachmentChip, { base: base, attachment: a, onOpen: gallery.open, objectUrls: objectUrls }), _jsx("button", { ...agentHandleProps({}, { base, action: `remove-${agentHandleSegment({ value: a.path })}`, role: 'button', label: t('Remove {name}', { name: a.name }) }), type: "button", className: "jini-attachment-remove", onClick: () => onRemove(a.path), title: t('Remove {name}', { name: a.name }), "aria-label": t('Remove {name}', { name: a.name }), children: _jsx(Icon, { name: "close", size: 12 }) })] }, a.path))), uploading ? (_jsxs("div", { className: "jini-attachment-chip jini-is-uploading", "data-testid": "attachment-uploading-chip", children: [_jsx("span", { className: "jini-attachment-chip-icon", children: _jsx(Icon, { name: "spinner", size: 15 }) }), _jsx("span", { className: "jini-attachment-chip-copy", children: _jsx("span", { className: "jini-attachment-chip-name", children: t('Uploading…') }) })] })) : null, gallery.opened ? (_jsx(AttachmentPreviewModal, { attachment: gallery.opened, onClose: gallery.close, navigation: gallery.navigation })) : null] }));
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
/** Hooks DefaultAttachmentChip calls; defaults to the real ones, a test hands in fakes. */
|
|
36
|
+
const defaultDefaultAttachmentChipHooks = { useT, useSentAttachmentThumbnail };
|
|
37
|
+
function DefaultAttachmentChip({ base, attachment, onOpen, objectUrls, hooks = defaultDefaultAttachmentChipHooks }) {
|
|
38
|
+
const t = hooks.useT();
|
|
39
|
+
const { thumbnailUrl, onThumbnailError } = hooks.useSentAttachmentThumbnail({ attachment }, objectUrls === undefined ? {} : { objectUrls });
|
|
36
40
|
const size = formatAttachmentSize({ size: attachment.size });
|
|
37
41
|
const label = thumbnailUrl && isOpaqueAttachmentName({ name: attachment.name }) ? t('Image') : attachment.name;
|
|
38
42
|
return (_jsxs("button", { type: "button", ...agentHandleProps({}, { base, action: `open-${agentHandleSegment({ value: attachment.path })}`, role: 'button', label: t('Open {name}', { name: attachment.name }) }), className: "jini-attachment-chip-body", onClick: () => onOpen(attachment), title: t('Open {name}', { name: attachment.name }), "aria-label": t('Open {name}', { name: attachment.name }), children: [thumbnailUrl ? (_jsx("img", { className: "jini-attachment-chip-thumb", src: thumbnailUrl, alt: "", onError: onThumbnailError })) : (_jsx("span", { className: `jini-attachment-chip-icon is-${attachment.kind}`, children: _jsx(Icon, { name: attachment.kind === 'image' ? 'image' : 'file', size: 15 }) })), _jsxs("span", { className: "jini-attachment-chip-copy", children: [_jsx("span", { className: "jini-attachment-chip-name", children: label }), size ? _jsx("small", { className: "jini-attachment-chip-size", children: size }) : null] })] }));
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ChatFab
|
|
3
|
+
*
|
|
4
|
+
* A draggable floating button that opens and closes a chat pane. This package ships unstyled
|
|
5
|
+
* semantic markup (same convention as the rest of `@jini-ai/chat-react`) — a host supplies CSS
|
|
6
|
+
* for the `chat-fab`/`chat-fab-open` classes.
|
|
7
|
+
*/
|
|
8
|
+
import { useChatFabDrag } from '../hooks/useChatFabDrag.js';
|
|
1
9
|
export interface ChatFabProps {
|
|
2
10
|
readonly open: boolean;
|
|
3
11
|
readonly onToggle: () => void;
|
|
@@ -6,6 +14,7 @@ export interface ChatFabProps {
|
|
|
6
14
|
readonly 'aria-label'?: string;
|
|
7
15
|
readonly 'aria-controls'?: string;
|
|
8
16
|
readonly 'aria-haspopup'?: 'dialog';
|
|
17
|
+
useChatFabDragHook?: typeof useChatFabDrag;
|
|
9
18
|
}
|
|
10
|
-
export declare function ChatFab({ open, onToggle, label, 'aria-label': accessibleLabel, 'aria-controls': controls, 'aria-haspopup': popup }: ChatFabProps): import("react").JSX.Element;
|
|
19
|
+
export declare function ChatFab({ open, onToggle, label, 'aria-label': accessibleLabel, 'aria-controls': controls, 'aria-haspopup': popup, useChatFabDragHook }: ChatFabProps): import("react").JSX.Element;
|
|
11
20
|
//# sourceMappingURL=ChatFab.d.ts.map
|
|
@@ -7,8 +7,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
7
7
|
* for the `chat-fab`/`chat-fab-open` classes.
|
|
8
8
|
*/
|
|
9
9
|
import { useChatFabDrag } from '../hooks/useChatFabDrag.js';
|
|
10
|
-
export function ChatFab({ open, onToggle, label = 'chat', 'aria-label': accessibleLabel, 'aria-controls': controls, 'aria-haspopup': popup }) {
|
|
11
|
-
const { buttonRef, position, onPointerDown, onPointerMove, onPointerUp, onPointerCancel } =
|
|
10
|
+
export function ChatFab({ open, onToggle, label = 'chat', 'aria-label': accessibleLabel, 'aria-controls': controls, 'aria-haspopup': popup, useChatFabDragHook = useChatFabDrag }) {
|
|
11
|
+
const { buttonRef, position, onPointerDown, onPointerMove, onPointerUp, onPointerCancel } = useChatFabDragHook({ onClick: onToggle });
|
|
12
12
|
return (_jsx("button", { ref: buttonRef, type: "button", className: `chat-fab${open ? ' chat-fab-open' : ''}`,
|
|
13
13
|
// Not `onClick`: the pointer gesture already decides click-versus-drag, and keeping both
|
|
14
14
|
// would fire the toggle twice on a tap.
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { type ChatPermissionsPort, type ChatSettingsSection } from './ChatSettingsDialog.hooks.js';
|
|
1
|
+
import { useChatSettingsView, type ChatPermissionsPort, type ChatSettingsSection } from './ChatSettingsDialog.hooks.js';
|
|
2
2
|
/** Advanced chat settings; the host supplies display actions, capabilities and persistence.
|
|
3
3
|
* Native dialog semantics own modal focus containment; closing restores the opener.
|
|
4
4
|
* Header and tabs stay fixed while only the active panel scrolls.
|
|
5
5
|
*/
|
|
6
|
-
export declare function ChatSettingsDialog(required: {
|
|
6
|
+
export declare function ChatSettingsDialog({ useChatSettingsViewHook, ...required }: {
|
|
7
|
+
useChatSettingsViewHook?: typeof useChatSettingsView;
|
|
7
8
|
open: boolean;
|
|
8
9
|
onClose: () => void;
|
|
9
10
|
displaySections: readonly ChatSettingsSection[];
|
|
10
11
|
permissions: ChatPermissionsPort;
|
|
11
12
|
t?: (key: string) => string;
|
|
12
|
-
}
|
|
13
|
+
}): import("react").JSX.Element;
|
|
13
14
|
//# sourceMappingURL=ChatSettingsDialog.d.ts.map
|
|
@@ -9,7 +9,7 @@ import { ChatSettingsSegmented } from './ChatSettingsSegmented.js';
|
|
|
9
9
|
* Earlier (owner) ⓘ tips floated away from their icon, so this row showed visible text only; on 2026-10-18 the owner approved per-option ⓘ help, which InfoTip now anchors to the icon.
|
|
10
10
|
* Later that day radio groups moved to one ⓘ beside their legend; a switch keeps its own, which now
|
|
11
11
|
* sits right after its label like the legend's (owner, 2026-10-21) instead of at the row's far edge. */
|
|
12
|
-
function SettingSwitch(required
|
|
12
|
+
function SettingSwitch(required) {
|
|
13
13
|
const inputId = useId();
|
|
14
14
|
return _jsxs("div", { className: ['jini-chat-settings-row', required.className].filter(Boolean).join(' '), children: [_jsx("input", { id: inputId, type: "checkbox", role: "switch", className: "jini-checkbox jini-chat-settings-switch", checked: required.checked, disabled: required.disabled, "aria-describedby": [required.description ? required.descriptionId : '', required.tooltip ? `${required.descriptionId}-tooltip` : ''].filter(Boolean).join(' ') || undefined, onChange: event => required.onChange(event.currentTarget.checked) }), _jsxs("div", { className: "jini-chat-settings-text", children: [_jsxs("span", { className: "jini-chat-settings-label-row", children: [_jsx("label", { htmlFor: inputId, className: "jini-chat-settings-label", children: required.label }), required.tooltip && _jsx(InfoTip, { label: required.tooltip, descriptionId: `${required.descriptionId}-tooltip` })] }), required.description && _jsx("p", { id: required.descriptionId, className: "jini-chat-settings-description", children: required.description })] })] });
|
|
15
15
|
}
|
|
@@ -17,8 +17,8 @@ function SettingSwitch(required, _optional = {}) {
|
|
|
17
17
|
* Native dialog semantics own modal focus containment; closing restores the opener.
|
|
18
18
|
* Header and tabs stay fixed while only the active panel scrolls.
|
|
19
19
|
*/
|
|
20
|
-
export function ChatSettingsDialog(
|
|
21
|
-
const vm =
|
|
20
|
+
export function ChatSettingsDialog({ useChatSettingsViewHook = useChatSettingsView, ...required }) {
|
|
21
|
+
const vm = useChatSettingsViewHook(required);
|
|
22
22
|
const dialogRef = useRef(null), closeRef = useRef(null), titleId = useId();
|
|
23
23
|
const openerRef = useRef(null);
|
|
24
24
|
useLayoutEffect(() => {
|
|
@@ -56,7 +56,7 @@ export function ChatSettingsDialog(required, _optional = {}) {
|
|
|
56
56
|
}, [required.open]);
|
|
57
57
|
// Its own tip bounds: hosts mount this inside a narrow dock marked `data-jini-tip-bounds`, which
|
|
58
58
|
// pushed the ⓘ bubbles of options outside the dock across the dialog, away from their icon.
|
|
59
|
-
return
|
|
59
|
+
return _jsx("dialog", { ref: dialogRef, "aria-labelledby": titleId, "aria-modal": "true", tabIndex: -1, "data-jini-tip-bounds": "", className: "jini-dialog jini-chat-settings-dialog", onCancel: event => { event.preventDefault(); required.onClose(); }, onClick: event => {
|
|
60
60
|
if (event.target !== event.currentTarget)
|
|
61
61
|
return;
|
|
62
62
|
const { clientX: x, clientY: y } = event, box = event.currentTarget.getBoundingClientRect();
|
|
@@ -64,8 +64,7 @@ export function ChatSettingsDialog(required, _optional = {}) {
|
|
|
64
64
|
const verticalOutside = y < box.top || y > box.bottom;
|
|
65
65
|
if ((x === 0 && y === 0) || horizontalOutside || verticalOutside)
|
|
66
66
|
required.onClose();
|
|
67
|
-
}, children:
|
|
68
|
-
: renderPermissions(vm) })] });
|
|
67
|
+
}, children: _jsx(ChatSettingsBody, { vm: vm, titleId: titleId, closeRef: closeRef, onClose: required.onClose }) });
|
|
69
68
|
}
|
|
70
69
|
function renderDisplaySection(section) {
|
|
71
70
|
if (section.radio)
|
|
@@ -78,4 +77,8 @@ function renderDisplaySection(section) {
|
|
|
78
77
|
function renderPermissions(vm) {
|
|
79
78
|
return _jsxs(_Fragment, { children: [_jsx("p", { className: "jini-chat-settings-note", children: vm.t('Permission changes apply to the next run.') }), vm.permissions.unavailableReason && _jsx("p", { className: "jini-chat-settings-note", children: vm.t(vm.permissions.unavailableReason) }), _jsx(SettingSwitch, { className: "jini-chat-settings-row--master", label: vm.master.label, checked: vm.master.checked, disabled: vm.master.disabled, onChange: checked => vm.master.onCheckedChange({ checked }), description: vm.master.description, descriptionId: vm.master.descriptionId }), _jsx("div", { className: "jini-chat-settings-capabilities", children: vm.capabilities.map(item => _jsx(SettingSwitch, { label: item.control.label, checked: item.control.checked, disabled: item.control.disabled, onChange: checked => item.control.onCheckedChange({ checked }), description: item.description, descriptionId: item.descriptionId }, item.key)) }), vm.permissions.busy && _jsx("p", { role: "status", className: "jini-chat-settings-note", children: vm.t('Saving…') }), vm.permissions.error && _jsx("p", { role: "alert", className: "jini-chat-settings-error", children: vm.permissions.error })] });
|
|
80
79
|
}
|
|
80
|
+
function ChatSettingsBody({ vm, titleId, closeRef, onClose }) {
|
|
81
|
+
return _jsxs(_Fragment, { children: [_jsxs("header", { className: "jini-chat-settings-header", children: [_jsx("h2", { id: titleId, className: "jini-dialog-title", children: vm.t('Chat settings') }), _jsx("button", { ref: closeRef, type: "button", className: "jini-dialog-close jini-chat-settings-close", "aria-label": vm.t('Close'), onClick: onClose, children: _jsx("span", { "aria-hidden": "true", children: "\u00D7" }) })] }), _jsx(TabBar, { tabs: vm.tabs, activeId: vm.tab, onChange: vm.setTab, ariaLabel: vm.t('Chat settings') }), _jsx("div", { className: "jini-chat-settings-body", role: "tabpanel", "aria-label": vm.tab === 'display' ? vm.t('Display') : vm.t('Agent permissions'), children: vm.tab === 'display' ? vm.display.map(renderDisplaySection)
|
|
82
|
+
: renderPermissions(vm) }), " "] });
|
|
83
|
+
}
|
|
81
84
|
//# sourceMappingURL=ChatSettingsDialog.js.map
|
|
@@ -14,5 +14,5 @@ export declare function ChatSettingsSegmented(required: {
|
|
|
14
14
|
}[];
|
|
15
15
|
inputRole?: 'menuitemradio' | undefined;
|
|
16
16
|
checkedRef?: ((input: HTMLInputElement | null) => void) | undefined;
|
|
17
|
-
}
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
18
|
//# sourceMappingURL=ChatSettingsSegmented.d.ts.map
|
|
@@ -4,7 +4,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
* 2026-10-21: the gear's Tool calls and Agent plugins match the dialog's control), so both look alike.
|
|
5
5
|
* Inside a `role="menu"` host, `inputRole="menuitemradio"` keeps each option a valid menu child, and
|
|
6
6
|
* `checkedRef` gets the checked option (else the first) so the host's roving focus can land on it. */
|
|
7
|
-
export function ChatSettingsSegmented(required
|
|
7
|
+
export function ChatSettingsSegmented(required) {
|
|
8
8
|
const focusKey = (required.items.find(item => item.checked) ?? required.items[0])?.key;
|
|
9
9
|
return _jsx("div", { className: "jini-chat-settings-segmented", children: required.items.map(item => _jsxs("label", { className: "jini-chat-settings-segment", children: [_jsx("input", { type: "radio", name: required.name, checked: !!item.checked, disabled: item.disabled, onChange: item.change, role: required.inputRole, "aria-checked": required.inputRole ? !!item.checked : undefined, ref: item.key === focusKey ? required.checkedRef : undefined }), _jsx("span", { children: item.label })] }, item.key)) });
|
|
10
10
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import type { Logger } from '@jini-ai/core/primitives';
|
|
2
|
+
import { useAgentHandle } from '@jini-ai/ui';
|
|
3
|
+
import { useT } from '../hooks/context.js';
|
|
1
4
|
import type { UseComposerResult } from '../hooks/useComposer.js';
|
|
2
5
|
import type { ComposerSlots } from '../slots.js';
|
|
6
|
+
import { useComposerView } from './Composer.hooks.js';
|
|
3
7
|
export interface ComposerProps {
|
|
8
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
9
|
+
useAgentHandleHook?: typeof useAgentHandle;
|
|
10
|
+
useTHook?: typeof useT;
|
|
11
|
+
useComposerViewHook?: typeof useComposerView;
|
|
4
12
|
/** Stable automation base; false suppresses every package-owned control handle. */
|
|
5
13
|
agentHandle?: string | false | undefined;
|
|
6
14
|
composer: UseComposerResult;
|
|
@@ -73,5 +81,5 @@ export interface ComposerProps {
|
|
|
73
81
|
* @complexity Time/space: O(n) in rendered attachments and supplied menu items.
|
|
74
82
|
* @overallScore 100/100
|
|
75
83
|
*/
|
|
76
|
-
export declare function Composer({ agentHandle, composer, onSend, disabled, sendDisabled, sendDisabledReason, sendDisabledReasonId, placeholder, slots, attachmentPicker, running, onCancel, onInterrupt, workingDirectory, onChangeWorkingDirectory, onPickWorkingDirectory, }: ComposerProps): import("react").JSX.Element;
|
|
84
|
+
export declare function Composer({ useAgentHandleHook, useTHook, useComposerViewHook, agentHandle, composer, onSend, report, disabled, sendDisabled, sendDisabledReason, sendDisabledReasonId, placeholder, slots, attachmentPicker, running, onCancel, onInterrupt, workingDirectory, onChangeWorkingDirectory, onPickWorkingDirectory, }: ComposerProps): import("react").JSX.Element;
|
|
77
85
|
//# sourceMappingURL=Composer.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type Logger } from '@jini-ai/core/primitives';
|
|
2
|
+
import { type ChangeEvent, type ClipboardEvent, type CSSProperties, type KeyboardEvent } from 'react';
|
|
3
|
+
import type { ComposerDiscoveryGroup, ComposerDiscoveryItem } from '../slots.js';
|
|
4
|
+
import type { ComposerProps } from './Composer.js';
|
|
5
|
+
/**
|
|
6
|
+
* Invokes host code synchronously, then observes either its synchronous result or async failure.
|
|
7
|
+
*
|
|
8
|
+
* @param onResolved - Optional, called with the host's resolved (non-thrown/non-rejected) return
|
|
9
|
+
* value — never called after a synchronous throw or an async rejection. Added for
|
|
10
|
+
* `onDiscoverySelect`, whose {@link ComposerDiscoveryOutcome} return value the caller applies to
|
|
11
|
+
* the draft; the two other host effects this function backs (`plusMenuItems.onSelect`,
|
|
12
|
+
* `attachmentPicker.onFiles`) simply omit it, which reproduces their exact prior behavior.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runComposerHostEffect({ effectName, effect }: {
|
|
15
|
+
effectName: string;
|
|
16
|
+
effect: () => unknown;
|
|
17
|
+
}, { onSettled, onResolved, report }?: {
|
|
18
|
+
onSettled?: () => void;
|
|
19
|
+
onResolved?: (result: unknown) => void;
|
|
20
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
21
|
+
}): void;
|
|
22
|
+
/** Coordinate composer menus, keyboard handling, attachments, and host effects. */
|
|
23
|
+
export declare function useComposerView({ composer, slots, attachmentPicker, workingDirectory, onChangeWorkingDirectory, disabled, sendDisabled, onInterrupt, onSend }: {
|
|
24
|
+
composer: ComposerProps['composer'];
|
|
25
|
+
slots: ComposerProps['slots'];
|
|
26
|
+
attachmentPicker: ComposerProps['attachmentPicker'];
|
|
27
|
+
workingDirectory: ComposerProps['workingDirectory'];
|
|
28
|
+
onChangeWorkingDirectory: ComposerProps['onChangeWorkingDirectory'];
|
|
29
|
+
disabled: boolean;
|
|
30
|
+
sendDisabled: boolean;
|
|
31
|
+
onInterrupt: ComposerProps['onInterrupt'];
|
|
32
|
+
onSend: ComposerProps['onSend'];
|
|
33
|
+
}, { report }?: {
|
|
34
|
+
report?: Pick<Logger, 'error'> | undefined;
|
|
35
|
+
}): {
|
|
36
|
+
attachmentInputRef: import("react").RefObject<HTMLInputElement | null>;
|
|
37
|
+
textareaRef: import("react").RefObject<HTMLTextAreaElement | null>;
|
|
38
|
+
discoveryMenuOpen: boolean;
|
|
39
|
+
setDiscoveryMenuOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
40
|
+
setSlashActiveIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
41
|
+
setDismissedSlashDraft: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
42
|
+
discoveryMenuPosition: CSSProperties | undefined;
|
|
43
|
+
slashMenuPosition: CSSProperties | undefined;
|
|
44
|
+
workdirOpen: boolean;
|
|
45
|
+
setWorkdirOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
46
|
+
workdirDraft: string;
|
|
47
|
+
setWorkdirDraft: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
48
|
+
workdirPosition: CSSProperties | undefined;
|
|
49
|
+
discoveryGroups: readonly ComposerDiscoveryGroup[];
|
|
50
|
+
leadingAccessories: import("react").ReactNode;
|
|
51
|
+
footerLeadingAccessory: import("react").ReactNode;
|
|
52
|
+
footerAccessories: import("react").ReactNode;
|
|
53
|
+
plusMenuItems: import("../slots.js").ComposerPlusItem[] | undefined;
|
|
54
|
+
hasDiscoveryItems: boolean;
|
|
55
|
+
slash: {
|
|
56
|
+
matches: import("./composer-discovery.js").ComposerDiscoveryMatch[];
|
|
57
|
+
open: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* A bare "/" intentionally matches every item (`matchesFuzzyCommand`'s own doc) so the palette
|
|
60
|
+
* doubles as a browse-everything view — but with nothing typed yet, nothing on screen tells a
|
|
61
|
+
* first-time user that continuing to type narrows it, and a fuzzy substring match against full
|
|
62
|
+
* descriptions stays broad for the first character or two regardless (owner-reported "it doesn't
|
|
63
|
+
* narrow" — narrowing DOES fire on every keystroke, this is the one state where there's no visual
|
|
64
|
+
* cue that it will). Shown only here, not once the user has started typing a real query — at that
|
|
65
|
+
* point the shrinking list is its own feedback.
|
|
66
|
+
*/
|
|
67
|
+
showFilterHint: boolean;
|
|
68
|
+
};
|
|
69
|
+
slashOpen: boolean;
|
|
70
|
+
slashActiveOption: number;
|
|
71
|
+
selectSlashItem: (item: ComposerDiscoveryItem) => void;
|
|
72
|
+
selectPlusItem: (item: ComposerDiscoveryItem) => void;
|
|
73
|
+
toggleWorkdir: () => void;
|
|
74
|
+
confirmWorkdir: () => void;
|
|
75
|
+
handleKeyDown: (event: KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
76
|
+
handleAttachmentChange: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
77
|
+
handleAttachmentPaste: (event: ClipboardEvent<HTMLTextAreaElement>) => void;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=Composer.hooks.d.ts.map
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { createConsoleLogger } from '@jini-ai/core/primitives';
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useComposerHistoryKeys } from '../hooks/useComposerHistoryKeys.hooks.js';
|
|
4
|
+
import { appendComposerDiscovery, composerDiscoveryMenuPosition, composerSlashMenuPosition, filterComposerDiscovery, parseComposerSlashQuery, replaceComposerSlashTrigger, resolveComposerSlashInvocation, resolveComposerSlashKeyAction } from './composer-discovery.js';
|
|
5
|
+
function reportComposerHostEffectFailure({ effectName, error }, { report: logger = createConsoleLogger({ prefix: '' }) } = {}) {
|
|
6
|
+
logger.error({ message: `[@jini-ai/chat] Composer ${effectName} host effect failed:` }, { error });
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Invokes host code synchronously, then observes either its synchronous result or async failure.
|
|
10
|
+
*
|
|
11
|
+
* @param onResolved - Optional, called with the host's resolved (non-thrown/non-rejected) return
|
|
12
|
+
* value — never called after a synchronous throw or an async rejection. Added for
|
|
13
|
+
* `onDiscoverySelect`, whose {@link ComposerDiscoveryOutcome} return value the caller applies to
|
|
14
|
+
* the draft; the two other host effects this function backs (`plusMenuItems.onSelect`,
|
|
15
|
+
* `attachmentPicker.onFiles`) simply omit it, which reproduces their exact prior behavior.
|
|
16
|
+
*/
|
|
17
|
+
export function runComposerHostEffect({ effectName, effect }, { onSettled, onResolved, report } = {}) {
|
|
18
|
+
let result;
|
|
19
|
+
try {
|
|
20
|
+
result = effect();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
reportComposerHostEffectFailure({ effectName, error }, { report });
|
|
24
|
+
onSettled?.();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const asynchronous = result !== undefined;
|
|
28
|
+
if (!asynchronous) {
|
|
29
|
+
onResolved?.(result);
|
|
30
|
+
onSettled?.();
|
|
31
|
+
}
|
|
32
|
+
void Promise.resolve(result)
|
|
33
|
+
.then((resolved) => {
|
|
34
|
+
if (asynchronous)
|
|
35
|
+
onResolved?.(resolved);
|
|
36
|
+
})
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
reportComposerHostEffectFailure({ effectName, error }, { report });
|
|
39
|
+
})
|
|
40
|
+
.finally(() => {
|
|
41
|
+
if (asynchronous)
|
|
42
|
+
onSettled?.();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** Coordinate composer menus, keyboard handling, attachments, and host effects. */
|
|
46
|
+
export function useComposerView({ composer, slots, attachmentPicker, workingDirectory, onChangeWorkingDirectory, disabled, sendDisabled, onInterrupt, onSend }, { report } = {}) {
|
|
47
|
+
const attachmentInputRef = useRef(null);
|
|
48
|
+
const textareaRef = useRef(null);
|
|
49
|
+
const discoveryEffectInFlightRef = useRef(false);
|
|
50
|
+
/**
|
|
51
|
+
* Mirrors `composer.draft` for the ONE place it must be read outside a render: inside
|
|
52
|
+
* `notifyDiscovery`'s `onResolved` callback, which can fire after arbitrarily many re-renders
|
|
53
|
+
* (nothing here disables the textarea while a host effect is in flight, so the user is free to
|
|
54
|
+
* keep typing). Reassigned every render rather than via an effect — an effect would lag one
|
|
55
|
+
* render behind the value it needs to be compared against at the exact moment the outcome
|
|
56
|
+
* settles.
|
|
57
|
+
*/
|
|
58
|
+
const draftRef = useRef(composer.draft);
|
|
59
|
+
draftRef.current = composer.draft;
|
|
60
|
+
const [discoveryMenuOpen, setDiscoveryMenuOpen] = useState(false);
|
|
61
|
+
const [slashActiveIndex, setSlashActiveIndex] = useState(0);
|
|
62
|
+
const [dismissedSlashDraft, setDismissedSlashDraft] = useState(null);
|
|
63
|
+
const [discoveryMenuPosition, setDiscoveryMenuPosition] = useState();
|
|
64
|
+
const [slashMenuPosition, setSlashMenuPosition] = useState();
|
|
65
|
+
const [workdirOpen, setWorkdirOpen] = useState(false);
|
|
66
|
+
const [workdirDraft, setWorkdirDraft] = useState('');
|
|
67
|
+
const [workdirPosition, setWorkdirPosition] = useState();
|
|
68
|
+
const { discoveryGroups = [], leadingAccessories, footerLeadingAccessory, footerAccessories, plusMenuItems } = slots ?? {};
|
|
69
|
+
const hasDiscoveryItems = discoveryGroups.some((group) => group.items.length > 0);
|
|
70
|
+
const slash = slashPalette({ draft: composer.draft, groups: discoveryGroups, dismissedSlashDraft });
|
|
71
|
+
const slashOpen = slash.open;
|
|
72
|
+
const slashActiveOption = Math.min(slashActiveIndex, slash.matches.length - 1);
|
|
73
|
+
const popovers = { discoveryMenuOpen, slashOpen, workdirOpen };
|
|
74
|
+
const handleHistoryKey = useComposerHistoryKeys({ composer, textareaRef }, {
|
|
75
|
+
popupOpen: anyPopoverOpen(popovers) || composer.mention.open,
|
|
76
|
+
});
|
|
77
|
+
function restoreComposerFocus() {
|
|
78
|
+
textareaRef.current?.focus();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Neither popover had any way to dismiss on an outside click — Escape worked (each already wires
|
|
82
|
+
* its own keydown), but clicking away left them open with no affordance to close (bug report:
|
|
83
|
+
* "no click-outside, owner is stuck once it opens"). `mousedown`, not `click`, so this settles
|
|
84
|
+
* before the "+" trigger button's own `onToggle` fires on the SAME click — that click's target is
|
|
85
|
+
* inside `.jini-composer-discovery` (the trigger lives there too), so it's correctly treated as
|
|
86
|
+
* "inside" and left for `onToggle` to handle, not fought over by two competing handlers.
|
|
87
|
+
*
|
|
88
|
+
* Scoped by DOM lookup (`closest`/`querySelector`) off `textareaRef`, not new refs threaded
|
|
89
|
+
* through `ComposerDiscovery.tsx`'s props — both popovers already carry stable classes/ids this
|
|
90
|
+
* component doesn't otherwise need direct handles to.
|
|
91
|
+
*/
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!anyPopoverOpen(popovers))
|
|
94
|
+
return undefined;
|
|
95
|
+
const textarea = textareaRef.current;
|
|
96
|
+
const composerRoot = textarea?.closest('.jini-composer');
|
|
97
|
+
if (!textarea || !composerRoot)
|
|
98
|
+
return undefined;
|
|
99
|
+
const input = textarea;
|
|
100
|
+
const root = composerRoot;
|
|
101
|
+
function handleOutsideMouseDown(event) {
|
|
102
|
+
const target = event.target;
|
|
103
|
+
if (!target)
|
|
104
|
+
return;
|
|
105
|
+
if (discoveryMenuOpen && isOutside({ root, selector: '.jini-composer-discovery', target }))
|
|
106
|
+
setDiscoveryMenuOpen(false);
|
|
107
|
+
if (slashOpen && !input.contains(target) && isOutside({ root, selector: '#jini-composer-slash-menu', target }))
|
|
108
|
+
setDismissedSlashDraft(composer.draft);
|
|
109
|
+
if (workdirOpen && isOutside({ root, selector: '.jini-composer-workdir', target }))
|
|
110
|
+
setWorkdirOpen(false);
|
|
111
|
+
}
|
|
112
|
+
document.addEventListener('mousedown', handleOutsideMouseDown);
|
|
113
|
+
return () => document.removeEventListener('mousedown', handleOutsideMouseDown);
|
|
114
|
+
}, [discoveryMenuOpen, slashOpen, workdirOpen, composer.draft]);
|
|
115
|
+
/**
|
|
116
|
+
* Anchors the "+" menu and slash palette to `.jini-composer`'s live on-screen rect via
|
|
117
|
+
* `position: fixed` (see `composerDiscoveryMenuPosition`/`composerSlashMenuPosition`'s own doc
|
|
118
|
+
* in `composer-discovery.ts` for the ancestor-clipping bug this fixes). `useLayoutEffect`, not
|
|
119
|
+
* `useEffect`, so the measured position lands before the browser paints the just-opened popover
|
|
120
|
+
* — otherwise the very first frame would flash at the CSS default (`position: absolute`)
|
|
121
|
+
* position before snapping to the fixed one. Recomputed on scroll/resize while either popover is
|
|
122
|
+
* open, matching `useAgentRuntimePicker.hooks.ts`'s identical popover-tracking idiom: the
|
|
123
|
+
* composer's on-screen position can change under an open popover without it ever unmounting.
|
|
124
|
+
*/
|
|
125
|
+
useLayoutEffect(() => {
|
|
126
|
+
if (!anyPopoverOpen(popovers))
|
|
127
|
+
return undefined;
|
|
128
|
+
const composerRoot = textareaRef.current?.closest('.jini-composer');
|
|
129
|
+
if (!composerRoot)
|
|
130
|
+
return undefined;
|
|
131
|
+
const root = composerRoot;
|
|
132
|
+
function update() {
|
|
133
|
+
const rect = root.getBoundingClientRect();
|
|
134
|
+
if (discoveryMenuOpen)
|
|
135
|
+
setDiscoveryMenuPosition(composerDiscoveryMenuPosition({ composerRect: rect }));
|
|
136
|
+
if (slashOpen)
|
|
137
|
+
setSlashMenuPosition(composerSlashMenuPosition({ composerRect: rect }));
|
|
138
|
+
// Shares the discovery menu's own anchor math (same left inset off `.jini-composer`) rather
|
|
139
|
+
// than measuring the working-dir button's own rect — one less measurement to keep in sync,
|
|
140
|
+
// and the two popovers already never open at once (each is gated on its own trigger).
|
|
141
|
+
if (workdirOpen)
|
|
142
|
+
setWorkdirPosition(composerDiscoveryMenuPosition({ composerRect: rect }));
|
|
143
|
+
}
|
|
144
|
+
update();
|
|
145
|
+
window.addEventListener('scroll', update, true);
|
|
146
|
+
window.addEventListener('resize', update);
|
|
147
|
+
return () => {
|
|
148
|
+
window.removeEventListener('scroll', update, true);
|
|
149
|
+
window.removeEventListener('resize', update);
|
|
150
|
+
};
|
|
151
|
+
}, [discoveryMenuOpen, slashOpen, workdirOpen]);
|
|
152
|
+
/**
|
|
153
|
+
* `expectedDraft` is the draft as the user last saw it at the moment of selection — what the
|
|
154
|
+
* host's effect was computed against. `argument` is passed only for a resolved `'invoke'` on a
|
|
155
|
+
* `command`-bearing item (see `resolveComposerSlashInvocation`); omitted entirely for a plain
|
|
156
|
+
* macro item, matching `ComposerDiscoverySelection.argument`'s own "absent means no command
|
|
157
|
+
* grammar" contract.
|
|
158
|
+
*
|
|
159
|
+
* A `ComposerDiscoveryOutcome` the host returns replaces the draft — this is how a command whose
|
|
160
|
+
* effect is computed asynchronously (e.g. composing agent-directed instruction text) gets to
|
|
161
|
+
* write its result back, since nothing here can guess it in advance the way a plain item's own
|
|
162
|
+
* `insertText` can. But nothing disables the textarea while that effect is in flight, so the
|
|
163
|
+
* live draft (`draftRef.current`) may have moved on by the time it resolves. The outcome is
|
|
164
|
+
* applied only if the live draft still matches `expectedDraft` exactly; otherwise it is
|
|
165
|
+
* DISCARDED — silently overwriting keystrokes the user typed in the meantime would be worse than
|
|
166
|
+
* dropping a result they can reselect.
|
|
167
|
+
*/
|
|
168
|
+
function notifyDiscovery(item, source, expectedDraft, argument) {
|
|
169
|
+
const onDiscoverySelect = slots?.onDiscoverySelect;
|
|
170
|
+
if (!onDiscoverySelect || discoveryEffectInFlightRef.current)
|
|
171
|
+
return;
|
|
172
|
+
discoveryEffectInFlightRef.current = true;
|
|
173
|
+
runComposerHostEffect({
|
|
174
|
+
effectName: 'onDiscoverySelect',
|
|
175
|
+
effect: () => onDiscoverySelect({ item, source, ...(argument !== undefined ? { argument } : {}) }),
|
|
176
|
+
}, {
|
|
177
|
+
onSettled: () => { discoveryEffectInFlightRef.current = false; },
|
|
178
|
+
report,
|
|
179
|
+
onResolved: (outcome) => {
|
|
180
|
+
if (!outcome || typeof outcome !== 'object')
|
|
181
|
+
return;
|
|
182
|
+
const draft = outcome.draft;
|
|
183
|
+
if (draft === undefined)
|
|
184
|
+
return;
|
|
185
|
+
if (draftRef.current !== expectedDraft)
|
|
186
|
+
return;
|
|
187
|
+
composer.setDraft(draft);
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function selectSlashItem(item) {
|
|
192
|
+
const resolution = resolveComposerSlashInvocation({ draft: composer.draft, item });
|
|
193
|
+
if (!resolution)
|
|
194
|
+
return;
|
|
195
|
+
if (resolution.type === 'complete') {
|
|
196
|
+
// The command word is ambiguous or its argument is still missing — finish the trigger and
|
|
197
|
+
// keep the palette open for further typing. No host effect fires: nothing was invoked yet.
|
|
198
|
+
composer.setDraft(resolution.draft);
|
|
199
|
+
setDismissedSlashDraft(null);
|
|
200
|
+
restoreComposerFocus();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
let expectedDraft = composer.draft;
|
|
204
|
+
if (!item.command) {
|
|
205
|
+
expectedDraft = replaceComposerSlashTrigger({ draft: composer.draft, insertText: item.insertText ?? item.label });
|
|
206
|
+
composer.setDraft(expectedDraft);
|
|
207
|
+
}
|
|
208
|
+
setDismissedSlashDraft(null);
|
|
209
|
+
notifyDiscovery(item, 'slash', expectedDraft, resolution.argument);
|
|
210
|
+
restoreComposerFocus();
|
|
211
|
+
}
|
|
212
|
+
function selectPlusItem(item) {
|
|
213
|
+
const expectedDraft = item.insertText ? appendComposerDiscovery({ draft: composer.draft, insertText: item.insertText }) : composer.draft;
|
|
214
|
+
if (item.insertText)
|
|
215
|
+
composer.setDraft(expectedDraft);
|
|
216
|
+
setDiscoveryMenuOpen(false);
|
|
217
|
+
notifyDiscovery(item, 'plus', expectedDraft);
|
|
218
|
+
restoreComposerFocus();
|
|
219
|
+
}
|
|
220
|
+
/** Opens the working-directory popover, seeding its draft from the live value so a reopen never
|
|
221
|
+
* shows a stale edit from a previously-dismissed attempt. */
|
|
222
|
+
function toggleWorkdir() {
|
|
223
|
+
if (!workdirOpen)
|
|
224
|
+
setWorkdirDraft(workingDirectory ?? '');
|
|
225
|
+
setWorkdirOpen((open) => !open);
|
|
226
|
+
}
|
|
227
|
+
/** Confirms the popover's draft. Blank input is treated as "no change" (closes without calling
|
|
228
|
+
* the host) rather than clearing the directory — this lightweight control has no clear
|
|
229
|
+
* affordance of its own; `onChangeWorkingDirectory`'s own doc points to the native picker
|
|
230
|
+
* (`ChatPaneWorkingDirectoryAccess`) that does support clearing. */
|
|
231
|
+
function confirmWorkdir() {
|
|
232
|
+
const trimmed = workdirDraft.trim();
|
|
233
|
+
if (trimmed)
|
|
234
|
+
onChangeWorkingDirectory?.(trimmed);
|
|
235
|
+
setWorkdirOpen(false);
|
|
236
|
+
}
|
|
237
|
+
/** Palette navigation wins over history and Enter while the slash palette is open; true when it consumed the key. */
|
|
238
|
+
function handleSlashKey(event) {
|
|
239
|
+
if (!slashOpen)
|
|
240
|
+
return false;
|
|
241
|
+
const action = resolveComposerSlashKeyAction({ key: event.key, shiftKey: event.shiftKey });
|
|
242
|
+
if (action.type === 'none')
|
|
243
|
+
return false;
|
|
244
|
+
event.preventDefault();
|
|
245
|
+
if (action.type === 'move') {
|
|
246
|
+
setSlashActiveIndex((current) => (current + action.offset + slash.matches.length) % slash.matches.length);
|
|
247
|
+
}
|
|
248
|
+
else if (action.type === 'select') {
|
|
249
|
+
selectSlashItem(slash.matches[slashActiveOption].item);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
setDismissedSlashDraft(composer.draft);
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
function submitFromEnter(event) {
|
|
257
|
+
if (disabled || !composer.canSubmit)
|
|
258
|
+
return;
|
|
259
|
+
// Cmd/Ctrl+Enter uses the host shortcut; ChatPane routes it through the ordinary send guards.
|
|
260
|
+
// `sendDisabled` is deliberately NOT consulted here: hosts can offer a shortcut while a run
|
|
261
|
+
// itself blocks ordinary sends. ChatPane queues or delivers live without cancelling the run.
|
|
262
|
+
if ((event.metaKey || event.ctrlKey) && onInterrupt) {
|
|
263
|
+
onInterrupt();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (!sendDisabled)
|
|
267
|
+
onSend();
|
|
268
|
+
}
|
|
269
|
+
function handleKeyDown(event) {
|
|
270
|
+
if (event.nativeEvent.isComposing)
|
|
271
|
+
return;
|
|
272
|
+
if (handleSlashKey(event))
|
|
273
|
+
return;
|
|
274
|
+
if (handleHistoryKey(event))
|
|
275
|
+
return;
|
|
276
|
+
if (event.key !== 'Enter' || event.shiftKey)
|
|
277
|
+
return;
|
|
278
|
+
event.preventDefault();
|
|
279
|
+
submitFromEnter(event);
|
|
280
|
+
}
|
|
281
|
+
function handleAttachmentChange(event) {
|
|
282
|
+
const files = Array.from(event.target.files ?? []);
|
|
283
|
+
event.target.value = '';
|
|
284
|
+
if (files.length > 0 && attachmentPicker) {
|
|
285
|
+
runComposerHostEffect({ effectName: 'attachmentPicker.onFiles', effect: () => attachmentPicker.onFiles(files) }, { report });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* A screenshot or a Finder-copied video pasted into the textarea previously vanished with no
|
|
290
|
+
* feedback: the browser's default paste has nothing to do with a `File` on the clipboard (it only
|
|
291
|
+
* inserts `text/plain`, which a file-only clipboard entry never carries), so the keystroke was a
|
|
292
|
+
* silent no-op — no chip, no `/api/attachments` call, nothing. This is the paste-side counterpart
|
|
293
|
+
* to `handleAttachmentChange` (the file-input path) and `useChatPaneFileDrop` (the drag-and-drop
|
|
294
|
+
* path); all three now reach `attachmentPicker.onFiles` the same way.
|
|
295
|
+
*
|
|
296
|
+
* `preventDefault` only when `files.length > 0` — an ordinary text paste (the overwhelmingly
|
|
297
|
+
* common case) is left to the browser's own default handling untouched.
|
|
298
|
+
*/
|
|
299
|
+
function handleAttachmentPaste(event) {
|
|
300
|
+
if (!attachmentPicker)
|
|
301
|
+
return;
|
|
302
|
+
const files = Array.from(event.clipboardData?.files ?? []);
|
|
303
|
+
if (files.length === 0)
|
|
304
|
+
return;
|
|
305
|
+
event.preventDefault();
|
|
306
|
+
runComposerHostEffect({ effectName: 'attachmentPicker.onFiles', effect: () => attachmentPicker.onFiles(files) }, { report });
|
|
307
|
+
}
|
|
308
|
+
return { attachmentInputRef, textareaRef, discoveryMenuOpen, setDiscoveryMenuOpen, setSlashActiveIndex, setDismissedSlashDraft, discoveryMenuPosition, slashMenuPosition, workdirOpen, setWorkdirOpen, workdirDraft, setWorkdirDraft, workdirPosition, discoveryGroups, leadingAccessories, footerLeadingAccessory, footerAccessories, plusMenuItems, hasDiscoveryItems, slash, slashOpen, slashActiveOption, selectSlashItem, selectPlusItem, toggleWorkdir, confirmWorkdir, handleKeyDown, handleAttachmentChange, handleAttachmentPaste };
|
|
309
|
+
}
|
|
310
|
+
function anyPopoverOpen({ discoveryMenuOpen, slashOpen, workdirOpen }) {
|
|
311
|
+
return discoveryMenuOpen || slashOpen || workdirOpen;
|
|
312
|
+
}
|
|
313
|
+
/** A missing popover element counts as outside, so a stale open flag still closes. */
|
|
314
|
+
function isOutside({ root, selector, target }, _options = {}) {
|
|
315
|
+
return !root.querySelector(selector)?.contains(target);
|
|
316
|
+
}
|
|
317
|
+
/** Slash palette state derived from the live draft. */
|
|
318
|
+
function slashPalette({ draft, groups, dismissedSlashDraft }) {
|
|
319
|
+
const query = parseComposerSlashQuery({ draft });
|
|
320
|
+
const matches = query === null ? [] : filterComposerDiscovery({ groups, query });
|
|
321
|
+
return {
|
|
322
|
+
matches,
|
|
323
|
+
open: matches.length > 0 && dismissedSlashDraft !== draft,
|
|
324
|
+
/**
|
|
325
|
+
* A bare "/" intentionally matches every item (`matchesFuzzyCommand`'s own doc) so the palette
|
|
326
|
+
* doubles as a browse-everything view — but with nothing typed yet, nothing on screen tells a
|
|
327
|
+
* first-time user that continuing to type narrows it, and a fuzzy substring match against full
|
|
328
|
+
* descriptions stays broad for the first character or two regardless (owner-reported "it doesn't
|
|
329
|
+
* narrow" — narrowing DOES fire on every keystroke, this is the one state where there's no visual
|
|
330
|
+
* cue that it will). Shown only here, not once the user has started typing a real query — at that
|
|
331
|
+
* point the shrinking list is its own feedback.
|
|
332
|
+
*/
|
|
333
|
+
showFilterHint: query !== null && query.command === '' && query.argument === null,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=Composer.hooks.js.map
|