@jini-ai/chat 0.7.2 → 0.7.3-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/README.md +3 -3
- package/dist/contracts/chat-bubble-style.d.ts +1 -1
- package/dist/contracts/chat-bubble-style.js +1 -1
- package/dist/core/ag-ui/event-projection.d.ts +125 -0
- package/dist/core/ag-ui/event-projection.js +275 -0
- package/dist/core/ag-ui/event-reduction.d.ts +39 -0
- package/dist/core/ag-ui/event-reduction.js +99 -0
- package/dist/core/ag-ui/run-input.d.ts +53 -0
- package/dist/core/ag-ui/run-input.js +87 -0
- package/dist/core/agentic/chat-capabilities.d.ts +1 -1
- package/dist/core/agentic/index.d.ts +2 -4
- package/dist/core/agentic/index.js +2 -3
- package/dist/core/agents-port.d.ts +50 -0
- package/dist/core/agents-port.js +2 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.d.ts +16 -0
- package/dist/core/assistant-client/ag-ui-fetch-agent.js +24 -0
- package/dist/core/assistant-client/ag-ui-transport.d.ts +15 -1
- package/dist/core/assistant-client/ag-ui-transport.js +167 -145
- package/dist/core/assistant-client/attachment-liveness.js +13 -11
- package/dist/core/assistant-client/durable-run-subscription.d.ts +3 -2
- package/dist/core/assistant-client/durable-run-subscription.js +6 -5
- package/dist/core/assistant-client/messages.d.ts +7 -4
- package/dist/core/assistant-client/messages.js +5 -4
- package/dist/core/assistant-client/transport.d.ts +1 -1
- package/dist/core/assistant-client/transport.js +4 -4
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-port.d.ts +15 -0
- package/dist/core/page-port.js +2 -0
- package/dist/core/run-activity.js +1 -1
- package/dist/core/run-events/entry.js +1 -0
- package/dist/core/user-text-redaction.d.ts +1 -3
- package/dist/core/user-text-redaction.js +3 -61
- package/dist/embed-widget/browser/agent-inventory.d.ts +37 -0
- package/dist/embed-widget/browser/agent-inventory.js +36 -0
- package/dist/embed-widget/browser/frontend-session-bridge.d.ts +2 -2
- package/dist/embed-widget/browser/frontend-session-bridge.js +17 -14
- package/dist/embed-widget/react/dialog.hooks.d.ts +16 -0
- package/dist/embed-widget/react/dialog.hooks.js +15 -0
- package/dist/embed-widget/react/embed.d.ts +7 -2
- package/dist/embed-widget/react/embed.js +6 -16
- package/dist/embed-widget/react/header.d.ts +4 -1
- package/dist/embed-widget/react/header.js +2 -2
- package/dist/embed-widget/vanilla/state.js +2 -2
- package/dist/embed-widget/vanilla/style.css +4 -4
- package/dist/react/components/A2uiSurfaceCard.d.ts +18 -4
- package/dist/react/components/A2uiSurfaceCard.hooks.d.ts +36 -0
- package/dist/react/components/A2uiSurfaceCard.hooks.js +174 -0
- package/dist/react/components/A2uiSurfaceCard.js +14 -227
- package/dist/react/components/A2uiSurfaceCard.rules.d.ts +14 -0
- package/dist/react/components/A2uiSurfaceCard.rules.js +24 -0
- package/dist/react/components/AttachmentPreviewModal.d.ts +21 -1
- package/dist/react/components/AttachmentPreviewModal.hooks.js +1 -3
- package/dist/react/components/AttachmentPreviewModal.js +11 -9
- package/dist/react/components/AttachmentTray.d.ts +11 -1
- package/dist/react/components/AttachmentTray.js +12 -8
- package/dist/react/components/ChatFab.d.ts +10 -1
- package/dist/react/components/ChatFab.js +2 -2
- package/dist/react/components/ChatSettingsDialog.d.ts +4 -3
- package/dist/react/components/ChatSettingsDialog.js +9 -6
- package/dist/react/components/ChatSettingsSegmented.d.ts +1 -1
- package/dist/react/components/ChatSettingsSegmented.js +1 -1
- package/dist/react/components/Composer.d.ts +9 -1
- package/dist/react/components/Composer.hooks.d.ts +79 -0
- package/dist/react/components/Composer.hooks.js +336 -0
- package/dist/react/components/Composer.js +40 -341
- package/dist/react/components/ComposerDiscovery.js +1 -1
- package/dist/react/components/ConversationList.d.ts +34 -1
- package/dist/react/components/ConversationList.hooks.d.ts +37 -0
- package/dist/react/components/ConversationList.hooks.js +177 -1
- package/dist/react/components/ConversationList.js +7 -174
- package/dist/react/components/ConversationTitleEditor.d.ts +17 -2
- package/dist/react/components/ConversationTitleEditor.hooks.d.ts +15 -0
- package/dist/react/components/ConversationTitleEditor.hooks.js +36 -0
- package/dist/react/components/ConversationTitleEditor.js +11 -34
- package/dist/react/components/CopyMessageButton.d.ts +6 -1
- package/dist/react/components/CopyMessageButton.js +4 -4
- package/dist/react/components/ExtEventErrorBoundary.d.ts +2 -0
- package/dist/react/components/ExtEventErrorBoundary.js +5 -3
- package/dist/react/components/FolderChips.d.ts +11 -1
- package/dist/react/components/FolderChips.hooks.d.ts +12 -0
- package/dist/react/components/FolderChips.hooks.js +10 -0
- package/dist/react/components/FolderChips.js +9 -9
- package/dist/react/components/Markdown.js +7 -5
- package/dist/react/components/McpUiSurfaceCard.d.ts +29 -5
- package/dist/react/components/McpUiSurfaceCard.js +29 -16
- package/dist/react/components/MessageList.d.ts +10 -1
- package/dist/react/components/MessageList.hooks.js +4 -2
- package/dist/react/components/MessageList.js +12 -8
- package/dist/react/components/MessageRow.d.ts +46 -2
- package/dist/react/components/MessageRow.hooks.d.ts +60 -0
- package/dist/react/components/MessageRow.hooks.js +94 -0
- package/dist/react/components/MessageRow.js +53 -113
- package/dist/react/components/MidRunUserMessage.d.ts +6 -1
- package/dist/react/components/MidRunUserMessage.js +5 -5
- package/dist/react/components/NextStepActions.d.ts +3 -1
- package/dist/react/components/NextStepActions.js +3 -3
- package/dist/react/components/QuestionForm.answers.hooks.d.ts +26 -0
- package/dist/react/components/QuestionForm.answers.hooks.js +89 -0
- package/dist/react/components/QuestionForm.d.ts +6 -0
- package/dist/react/components/QuestionForm.js +23 -261
- package/dist/react/components/QuestionForm.values.d.ts +22 -0
- package/dist/react/components/QuestionForm.values.js +58 -0
- package/dist/react/components/QuestionFormField.d.ts +17 -0
- package/dist/react/components/QuestionFormField.js +114 -0
- package/dist/react/components/QuestionsPanel.d.ts +3 -1
- package/dist/react/components/QuestionsPanel.js +7 -3
- package/dist/react/components/SentAttachment.d.ts +11 -2
- package/dist/react/components/SentAttachment.hooks.d.ts +1 -1
- package/dist/react/components/SentAttachment.hooks.js +6 -5
- package/dist/react/components/SentAttachment.js +5 -3
- package/dist/react/components/TodoCard.d.ts +3 -1
- package/dist/react/components/TodoCard.js +9 -4
- package/dist/react/components/ToolCallGroup.d.ts +11 -1
- package/dist/react/components/ToolCallGroup.js +10 -4
- package/dist/react/components/ToolCard.d.ts +6 -1
- package/dist/react/components/ToolCard.js +79 -69
- package/dist/react/components/mcp-ui-question-input.d.ts +1 -1
- package/dist/react/components/mcp-ui-question-input.js +3 -3
- package/dist/react/components/mcp-ui-surface-state.d.ts +1 -1
- package/dist/react/features/chat-pane/agent-tools.d.ts +1 -1
- package/dist/react/features/chat-pane/antigravity/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/antigravity/model-options.js +2 -0
- package/dist/react/features/chat-pane/claude/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/claude/model-options.js +2 -0
- package/dist/react/features/chat-pane/codex/model-options.d.ts +2 -0
- package/dist/react/features/chat-pane/codex/model-options.js +2 -0
- package/dist/react/features/chat-pane/components/AgentPluginUsage.d.ts +4 -1
- package/dist/react/features/chat-pane/components/AgentPluginUsage.js +2 -2
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.d.ts +10 -6
- package/dist/react/features/chat-pane/components/AgentRuntimePicker.js +18 -132
- package/dist/react/features/chat-pane/components/ChatPane.d.ts +24 -2
- package/dist/react/features/chat-pane/components/ChatPane.js +45 -297
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.d.ts +33 -0
- package/dist/react/features/chat-pane/components/ChatPaneComposerArea.js +119 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.d.ts +42 -0
- package/dist/react/features/chat-pane/components/ChatPaneLayout.js +54 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.d.ts +27 -0
- package/dist/react/features/chat-pane/components/ChatPaneStatus.js +91 -0
- package/dist/react/features/chat-pane/components/RuntimeDropUp.d.ts +6 -1
- package/dist/react/features/chat-pane/components/RuntimeDropUp.js +20 -19
- package/dist/react/features/chat-pane/components/RuntimePickerSections.d.ts +62 -0
- package/dist/react/features/chat-pane/components/RuntimePickerSections.js +122 -0
- package/dist/react/features/chat-pane/create-mcp-ui-tool-caller.d.ts +1 -1
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.d.ts +5 -3
- package/dist/react/features/chat-pane/hooks/useChatPane.hooks.js +78 -26
- package/dist/react/features/chat-pane/hooks/useChatPaneAgentControl.hooks.js +6 -6
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.d.ts +5 -1
- package/dist/react/features/chat-pane/hooks/useChatPaneFileDrop.hooks.js +7 -7
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.d.ts +7 -0
- package/dist/react/features/chat-pane/hooks/useRuntimeDropUp.hooks.js +5 -0
- package/dist/react/features/chat-pane/model-options.js +7 -4
- package/dist/react/features/chat-pane/styles.d.ts +1 -1
- package/dist/react/features/chat-pane/styles.js +14 -14
- package/dist/react/features/chat-pane/types.d.ts +29 -1
- package/dist/react/hooks/assistant-chats-contracts.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.d.ts +1 -1
- package/dist/react/hooks/attachment-preview-cache.js +1 -1
- package/dist/react/hooks/fab-position.js +16 -18
- package/dist/react/hooks/useConversation.d.ts +6 -1
- package/dist/react/hooks/useConversation.js +11 -10
- package/dist/react/hooks/useRunStream.d.ts +3 -0
- package/dist/react/hooks/useRunStream.js +12 -12
- package/dist/react/hooks/useSurfaceRecovery.d.ts +1 -1
- package/dist/react/hooks/useSurfaceRecovery.js +2 -2
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.js +5 -3
- package/dist/react/styles/chat-settings.css +9 -9
- package/dist/react/surfaces.d.ts +91 -0
- package/dist/react/surfaces.js +28 -0
- package/dist/server/durable-runs/recover.d.ts +4 -3
- package/dist/server/durable-runs/recover.js +4 -3
- package/dist/store/legacy/sqlite/conversations.d.ts +1 -2
- package/dist/store/legacy/sqlite/conversations.js +1 -1
- package/dist/store/legacy/sqlite/messages.d.ts +2 -3
- package/dist/store/legacy/sqlite/messages.js +6 -6
- package/dist/store/pglite/index.d.ts +7 -7
- package/dist/store/pglite/index.js +1 -1
- package/dist/store/ports.d.ts +5 -2
- package/dist/store/postgres/index.d.ts +7 -7
- package/dist/store/postgres/index.js +1 -1
- package/dist/store/runtime/chat-expiry-sweep.js +2 -4
- package/dist/store/runtime/chat-history-store.js +2 -3
- package/dist/store/runtime/durable-run-store.js +16 -2
- package/dist/store/runtime/history-tools.js +33 -11
- package/dist/store/runtime/kernel.d.ts +3 -2
- package/dist/store/runtime/run-ledger.js +2 -2
- package/dist/store/sql/boundary.d.ts +5 -5
- package/dist/store/sql/maintenance.d.ts +3 -2
- package/dist/store/sql/store.d.ts +16 -8
- package/dist/store/sql/store.js +31 -14
- package/dist/store/sqlite/index.d.ts +11 -12
- package/dist/store/sqlite/index.js +5 -5
- package/dist/store/sqlite/schema.d.ts +1 -1
- package/package.json +49 -27
- 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
|
@@ -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
|