@strands-agents/cli 0.1.0
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/LICENSE +175 -0
- package/NOTICE +1 -0
- package/README.md +576 -0
- package/bin/strands.js +256 -0
- package/dist/src/cli/arguments.js +198 -0
- package/dist/src/cli/arguments.js.map +1 -0
- package/dist/src/cli/invocation.js +124 -0
- package/dist/src/cli/invocation.js.map +1 -0
- package/dist/src/cli/run.js +252 -0
- package/dist/src/cli/run.js.map +1 -0
- package/dist/src/console.js +235 -0
- package/dist/src/console.js.map +1 -0
- package/dist/src/logging.js +103 -0
- package/dist/src/logging.js.map +1 -0
- package/dist/src/main.js +7 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/tui/acp/projection.js +276 -0
- package/dist/src/tui/acp/projection.js.map +1 -0
- package/dist/src/tui/acp/server.js +263 -0
- package/dist/src/tui/acp/server.js.map +1 -0
- package/dist/src/tui/agent-configuration.js +335 -0
- package/dist/src/tui/agent-configuration.js.map +1 -0
- package/dist/src/tui/agent-setup.js +80 -0
- package/dist/src/tui/agent-setup.js.map +1 -0
- package/dist/src/tui/background/activity.js +273 -0
- package/dist/src/tui/background/activity.js.map +1 -0
- package/dist/src/tui/background/inbox.js +120 -0
- package/dist/src/tui/background/inbox.js.map +1 -0
- package/dist/src/tui/background/tasks.js +98 -0
- package/dist/src/tui/background/tasks.js.map +1 -0
- package/dist/src/tui/builtin-tools.js +65 -0
- package/dist/src/tui/builtin-tools.js.map +1 -0
- package/dist/src/tui/chat/commands.js +98 -0
- package/dist/src/tui/chat/commands.js.map +1 -0
- package/dist/src/tui/chat/controller-helpers.js +62 -0
- package/dist/src/tui/chat/controller-helpers.js.map +1 -0
- package/dist/src/tui/chat/controller.js +1913 -0
- package/dist/src/tui/chat/controller.js.map +1 -0
- package/dist/src/tui/chat/help.js +94 -0
- package/dist/src/tui/chat/help.js.map +1 -0
- package/dist/src/tui/chat/panels.js +418 -0
- package/dist/src/tui/chat/panels.js.map +1 -0
- package/dist/src/tui/chat/projector.js +443 -0
- package/dist/src/tui/chat/projector.js.map +1 -0
- package/dist/src/tui/chat/sdk-projector.js +194 -0
- package/dist/src/tui/chat/sdk-projector.js.map +1 -0
- package/dist/src/tui/chat/shell.js +263 -0
- package/dist/src/tui/chat/shell.js.map +1 -0
- package/dist/src/tui/chat/types.js +2 -0
- package/dist/src/tui/chat/types.js.map +1 -0
- package/dist/src/tui/config.js +497 -0
- package/dist/src/tui/config.js.map +1 -0
- package/dist/src/tui/configuration-instructions.js +14 -0
- package/dist/src/tui/configuration-instructions.js.map +1 -0
- package/dist/src/tui/mcp/config.js +370 -0
- package/dist/src/tui/mcp/config.js.map +1 -0
- package/dist/src/tui/mcp.js +98 -0
- package/dist/src/tui/mcp.js.map +1 -0
- package/dist/src/tui/memory-options.js +10 -0
- package/dist/src/tui/memory-options.js.map +1 -0
- package/dist/src/tui/messaging.js +193 -0
- package/dist/src/tui/messaging.js.map +1 -0
- package/dist/src/tui/model/context.js +13 -0
- package/dist/src/tui/model/context.js.map +1 -0
- package/dist/src/tui/model/display.js +59 -0
- package/dist/src/tui/model/display.js.map +1 -0
- package/dist/src/tui/model/runtime.js +365 -0
- package/dist/src/tui/model/runtime.js.map +1 -0
- package/dist/src/tui/model/selection.js +160 -0
- package/dist/src/tui/model/selection.js.map +1 -0
- package/dist/src/tui/package-version.js +47 -0
- package/dist/src/tui/package-version.js.map +1 -0
- package/dist/src/tui/permissions/file-change-preview.js +182 -0
- package/dist/src/tui/permissions/file-change-preview.js.map +1 -0
- package/dist/src/tui/permissions/policy.js +223 -0
- package/dist/src/tui/permissions/policy.js.map +1 -0
- package/dist/src/tui/permissions/settings.js +21 -0
- package/dist/src/tui/permissions/settings.js.map +1 -0
- package/dist/src/tui/project/acp.js +93 -0
- package/dist/src/tui/project/acp.js.map +1 -0
- package/dist/src/tui/project/archive.js +239 -0
- package/dist/src/tui/project/archive.js.map +1 -0
- package/dist/src/tui/project/configuration-secrets.js +107 -0
- package/dist/src/tui/project/configuration-secrets.js.map +1 -0
- package/dist/src/tui/project/configuration.js +201 -0
- package/dist/src/tui/project/configuration.js.map +1 -0
- package/dist/src/tui/project/export.js +560 -0
- package/dist/src/tui/project/export.js.map +1 -0
- package/dist/src/tui/project/import.js +75 -0
- package/dist/src/tui/project/import.js.map +1 -0
- package/dist/src/tui/project/module-loader.js +157 -0
- package/dist/src/tui/project/module-loader.js.map +1 -0
- package/dist/src/tui/project/packaging.js +53 -0
- package/dist/src/tui/project/packaging.js.map +1 -0
- package/dist/src/tui/project/portable-dependencies.js +34 -0
- package/dist/src/tui/project/portable-dependencies.js.map +1 -0
- package/dist/src/tui/project/portable-mcp.js +118 -0
- package/dist/src/tui/project/portable-mcp.js.map +1 -0
- package/dist/src/tui/project/python.js +414 -0
- package/dist/src/tui/project/python.js.map +1 -0
- package/dist/src/tui/project/run.js +118 -0
- package/dist/src/tui/project/run.js.map +1 -0
- package/dist/src/tui/project/source.js +307 -0
- package/dist/src/tui/project/source.js.map +1 -0
- package/dist/src/tui/project/typescript.js +135 -0
- package/dist/src/tui/project/typescript.js.map +1 -0
- package/dist/src/tui/project/worker.py +731 -0
- package/dist/src/tui/provider/aws-client.js +67 -0
- package/dist/src/tui/provider/aws-client.js.map +1 -0
- package/dist/src/tui/provider/aws-config.js +66 -0
- package/dist/src/tui/provider/aws-config.js.map +1 -0
- package/dist/src/tui/provider/bedrock-catalog.js +87 -0
- package/dist/src/tui/provider/bedrock-catalog.js.map +1 -0
- package/dist/src/tui/provider/discovery.js +323 -0
- package/dist/src/tui/provider/discovery.js.map +1 -0
- package/dist/src/tui/provider/environment.js +138 -0
- package/dist/src/tui/provider/environment.js.map +1 -0
- package/dist/src/tui/provider/packages.js +42 -0
- package/dist/src/tui/provider/packages.js.map +1 -0
- package/dist/src/tui/run.js +257 -0
- package/dist/src/tui/run.js.map +1 -0
- package/dist/src/tui/runtime.js +520 -0
- package/dist/src/tui/runtime.js.map +1 -0
- package/dist/src/tui/session/agent-definition.js +100 -0
- package/dist/src/tui/session/agent-definition.js.map +1 -0
- package/dist/src/tui/session/catalog.js +159 -0
- package/dist/src/tui/session/catalog.js.map +1 -0
- package/dist/src/tui/session/context.js +118 -0
- package/dist/src/tui/session/context.js.map +1 -0
- package/dist/src/tui/session/conversation-helpers.js +46 -0
- package/dist/src/tui/session/conversation-helpers.js.map +1 -0
- package/dist/src/tui/session/conversations.js +456 -0
- package/dist/src/tui/session/conversations.js.map +1 -0
- package/dist/src/tui/session/desktop-profile.js +80 -0
- package/dist/src/tui/session/desktop-profile.js.map +1 -0
- package/dist/src/tui/session/options.js +44 -0
- package/dist/src/tui/session/options.js.map +1 -0
- package/dist/src/tui/session/sessions.js +251 -0
- package/dist/src/tui/session/sessions.js.map +1 -0
- package/dist/src/tui/session/voice.js +353 -0
- package/dist/src/tui/session/voice.js.map +1 -0
- package/dist/src/tui/settings.js +362 -0
- package/dist/src/tui/settings.js.map +1 -0
- package/dist/src/tui/setup/questions.js +277 -0
- package/dist/src/tui/setup/questions.js.map +1 -0
- package/dist/src/tui/skills.js +135 -0
- package/dist/src/tui/skills.js.map +1 -0
- package/dist/src/tui/steering.js +67 -0
- package/dist/src/tui/steering.js.map +1 -0
- package/dist/src/tui/strands-backend.js +368 -0
- package/dist/src/tui/strands-backend.js.map +1 -0
- package/dist/src/tui/stream-presentation.js +138 -0
- package/dist/src/tui/stream-presentation.js.map +1 -0
- package/dist/src/tui/telemetry.js +46 -0
- package/dist/src/tui/telemetry.js.map +1 -0
- package/dist/src/tui/terminal/composer.js +237 -0
- package/dist/src/tui/terminal/composer.js.map +1 -0
- package/dist/src/tui/terminal/directory-picker.js +76 -0
- package/dist/src/tui/terminal/directory-picker.js.map +1 -0
- package/dist/src/tui/terminal/ink.js +94 -0
- package/dist/src/tui/terminal/ink.js.map +1 -0
- package/dist/src/tui/terminal/mouse-input.js +83 -0
- package/dist/src/tui/terminal/mouse-input.js.map +1 -0
- package/dist/src/tui/terminal/open-url.js +21 -0
- package/dist/src/tui/terminal/open-url.js.map +1 -0
- package/dist/src/tui/terminal/process-tree.js +132 -0
- package/dist/src/tui/terminal/process-tree.js.map +1 -0
- package/dist/src/tui/terminal/sanitize.js +71 -0
- package/dist/src/tui/terminal/sanitize.js.map +1 -0
- package/dist/src/tui/terminal/shell-output.js +43 -0
- package/dist/src/tui/terminal/shell-output.js.map +1 -0
- package/dist/src/tui/terminal/terminal.js +39 -0
- package/dist/src/tui/terminal/terminal.js.map +1 -0
- package/dist/src/tui/view/agents-panel.js +21 -0
- package/dist/src/tui/view/agents-panel.js.map +1 -0
- package/dist/src/tui/view/app.js +1068 -0
- package/dist/src/tui/view/app.js.map +1 -0
- package/dist/src/tui/view/chat-root.js +88 -0
- package/dist/src/tui/view/chat-root.js.map +1 -0
- package/dist/src/tui/view/chat-view.js +185 -0
- package/dist/src/tui/view/chat-view.js.map +1 -0
- package/dist/src/tui/view/command-palette.js +18 -0
- package/dist/src/tui/view/command-palette.js.map +1 -0
- package/dist/src/tui/view/custom-theme-editor.js +301 -0
- package/dist/src/tui/view/custom-theme-editor.js.map +1 -0
- package/dist/src/tui/view/export-panel.js +14 -0
- package/dist/src/tui/view/export-panel.js.map +1 -0
- package/dist/src/tui/view/fade-in.js +106 -0
- package/dist/src/tui/view/fade-in.js.map +1 -0
- package/dist/src/tui/view/frog-canvas.js +375 -0
- package/dist/src/tui/view/frog-canvas.js.map +1 -0
- package/dist/src/tui/view/frog-drawing.js +415 -0
- package/dist/src/tui/view/frog-drawing.js.map +1 -0
- package/dist/src/tui/view/frog-easter-egg.js +53 -0
- package/dist/src/tui/view/frog-easter-egg.js.map +1 -0
- package/dist/src/tui/view/frog-intro-renderer.js +634 -0
- package/dist/src/tui/view/frog-intro-renderer.js.map +1 -0
- package/dist/src/tui/view/help-footer.js +36 -0
- package/dist/src/tui/view/help-footer.js.map +1 -0
- package/dist/src/tui/view/interaction.js +349 -0
- package/dist/src/tui/view/interaction.js.map +1 -0
- package/dist/src/tui/view/intro.js +35 -0
- package/dist/src/tui/view/intro.js.map +1 -0
- package/dist/src/tui/view/markdown.js +99 -0
- package/dist/src/tui/view/markdown.js.map +1 -0
- package/dist/src/tui/view/media.js +70 -0
- package/dist/src/tui/view/media.js.map +1 -0
- package/dist/src/tui/view/model-panel.js +65 -0
- package/dist/src/tui/view/model-panel.js.map +1 -0
- package/dist/src/tui/view/panel-components.js +17 -0
- package/dist/src/tui/view/panel-components.js.map +1 -0
- package/dist/src/tui/view/panels.js +129 -0
- package/dist/src/tui/view/panels.js.map +1 -0
- package/dist/src/tui/view/presentation.js +382 -0
- package/dist/src/tui/view/presentation.js.map +1 -0
- package/dist/src/tui/view/prompt-editor.js +74 -0
- package/dist/src/tui/view/prompt-editor.js.map +1 -0
- package/dist/src/tui/view/provider-list.js +14 -0
- package/dist/src/tui/view/provider-list.js.map +1 -0
- package/dist/src/tui/view/sessions-panel.js +15 -0
- package/dist/src/tui/view/sessions-panel.js.map +1 -0
- package/dist/src/tui/view/settings-panel.js +146 -0
- package/dist/src/tui/view/settings-panel.js.map +1 -0
- package/dist/src/tui/view/setup-question.js +90 -0
- package/dist/src/tui/view/setup-question.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/brand.js +18 -0
- package/dist/src/tui/view/setup-wizard/brand.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/index.js +1557 -0
- package/dist/src/tui/view/setup-wizard/index.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/opening-menu.js +88 -0
- package/dist/src/tui/view/setup-wizard/opening-menu.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/path-completion.js +53 -0
- package/dist/src/tui/view/setup-wizard/path-completion.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/profile-fields.js +29 -0
- package/dist/src/tui/view/setup-wizard/profile-fields.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/progress.js +42 -0
- package/dist/src/tui/view/setup-wizard/progress.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/providers.js +344 -0
- package/dist/src/tui/view/setup-wizard/providers.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/settings-panel.js +74 -0
- package/dist/src/tui/view/setup-wizard/settings-panel.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/steps.js +544 -0
- package/dist/src/tui/view/setup-wizard/steps.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/types.js +2 -0
- package/dist/src/tui/view/setup-wizard/types.js.map +1 -0
- package/dist/src/tui/view/setup-wizard/use-provider-discovery.js +145 -0
- package/dist/src/tui/view/setup-wizard/use-provider-discovery.js.map +1 -0
- package/dist/src/tui/view/startup-view.js +42 -0
- package/dist/src/tui/view/startup-view.js.map +1 -0
- package/dist/src/tui/view/text-input.js +33 -0
- package/dist/src/tui/view/text-input.js.map +1 -0
- package/dist/src/tui/view/theme-detection.js +45 -0
- package/dist/src/tui/view/theme-detection.js.map +1 -0
- package/dist/src/tui/view/theme.js +127 -0
- package/dist/src/tui/view/theme.js.map +1 -0
- package/dist/src/tui/view/transcript-layout.js +60 -0
- package/dist/src/tui/view/transcript-layout.js.map +1 -0
- package/dist/src/tui/view/transcript-turn.js +135 -0
- package/dist/src/tui/view/transcript-turn.js.map +1 -0
- package/dist/src/tui/view/transcript.js +138 -0
- package/dist/src/tui/view/transcript.js.map +1 -0
- package/dist/src/tui/view/use-party-frame.js +15 -0
- package/dist/src/tui/view/use-party-frame.js.map +1 -0
- package/dist/src/tui/view/use-spinner.js +14 -0
- package/dist/src/tui/view/use-spinner.js.map +1 -0
- package/dist/src/tui/voice/session.js +515 -0
- package/dist/src/tui/voice/session.js.map +1 -0
- package/dist/src/tui/workspace/sandbox.js +156 -0
- package/dist/src/tui/workspace/sandbox.js.map +1 -0
- package/dist/src/tui/workspace/trust.js +147 -0
- package/dist/src/tui/workspace/trust.js.map +1 -0
- package/dist/src/usage.js +187 -0
- package/dist/src/usage.js.map +1 -0
- package/package.json +97 -0
- package/src/tui/voice/sidecar.py +606 -0
|
@@ -0,0 +1,1068 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement, useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { renderToString, useApp, useInput, useStdout } from 'ink';
|
|
4
|
+
import { commandAssistance } from '../chat/commands.js';
|
|
5
|
+
import { sanitizeTerminalText } from '../terminal/sanitize.js';
|
|
6
|
+
import { completeSuggestion, emptyEditor, graphemes, reduceInputSequence, submitEditor, } from '../terminal/composer.js';
|
|
7
|
+
import { parseMouseInput, selectScreenText, shouldProcessMouseInput, } from '../terminal/mouse-input.js';
|
|
8
|
+
import { copyTerminalText, setTerminalMouseMotion } from '../terminal/terminal.js';
|
|
9
|
+
import { openExternalUrl } from '../terminal/open-url.js';
|
|
10
|
+
import { ChatView } from './chat-view.js';
|
|
11
|
+
import { activateMetadataTarget, adjacentSettingOption, adjacentSliderOption, agentGridCapacity, agentGridColumns, cycleModelPanelFocus, cyclePanelFilter, detailPageSize, elementAtMouse, elementContainsMouse, filterPanelRows, MODEL_COPY_TARGET, mouseScrollDirection, moveAgentGridSelection, moveSelection, panelRowCapacity, parsePanelControlTarget, registerElement, revealAgentGridSelection, revealPanelSelection, scrollAgentGridViewport, scrollDetail, scrollPanelViewport, scrollTranscript, shouldToggleVoiceMute, settingsLayout, settingsThemeLayout, sliderOptionAtMouse, } from './interaction.js';
|
|
12
|
+
import { parseFrogCommand } from './frog-easter-egg.js';
|
|
13
|
+
import { maxDetailScroll, maxPermissionScroll } from './presentation.js';
|
|
14
|
+
import { CustomThemeEditor } from './custom-theme-editor.js';
|
|
15
|
+
export function ChatApp({ controller, openUrl = openExternalUrl, }) {
|
|
16
|
+
const snapshot = useSyncExternalStore(controller.subscribe, controller.getSnapshot);
|
|
17
|
+
const [appearanceOpen, setAppearanceOpen] = useState(false);
|
|
18
|
+
const [previewAppearance, setPreviewAppearance] = useState();
|
|
19
|
+
const [footerElements, registerFooterElement] = useElementMap();
|
|
20
|
+
const activateRow = useCallback((row) => {
|
|
21
|
+
if (controller.getSnapshot().panel?.kind === 'settings' &&
|
|
22
|
+
(row.value === 'frogTheme=custom' ||
|
|
23
|
+
(row.value === 'frogTheme' && controller.getSnapshot().settings.frogTheme === 'custom'))) {
|
|
24
|
+
setAppearanceOpen(true);
|
|
25
|
+
return Promise.resolve(true);
|
|
26
|
+
}
|
|
27
|
+
return controller.activatePanelRow(row);
|
|
28
|
+
}, [controller]);
|
|
29
|
+
const closeAppearance = useCallback(() => {
|
|
30
|
+
setAppearanceOpen(false);
|
|
31
|
+
setPreviewAppearance(undefined);
|
|
32
|
+
}, []);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (snapshot.panel?.kind !== 'settings')
|
|
35
|
+
closeAppearance();
|
|
36
|
+
}, [snapshot.panel?.kind, closeAppearance]);
|
|
37
|
+
const { exit } = useApp();
|
|
38
|
+
const { stdout } = useStdout();
|
|
39
|
+
const [terminal, setTerminal] = useState({
|
|
40
|
+
width: stdout.columns || 80,
|
|
41
|
+
height: stdout.rows || 24,
|
|
42
|
+
});
|
|
43
|
+
const [editor, setEditorState] = useState(emptyEditor);
|
|
44
|
+
const [suggestionSelection, setSuggestionSelection] = useState(0);
|
|
45
|
+
const [dismissedSuggestions, setDismissedSuggestions] = useState();
|
|
46
|
+
const [panelSelection, setPanelSelection] = useState(0);
|
|
47
|
+
const [panelQuery, setPanelQuery] = useState('');
|
|
48
|
+
const [panelFilter, setPanelFilter] = useState('all');
|
|
49
|
+
const [modelPanelFocus, setModelPanelFocus] = useState('models');
|
|
50
|
+
const [panelViewportStart, setPanelViewportStart] = useState(0);
|
|
51
|
+
const [detailScroll, setDetailScroll] = useState(0);
|
|
52
|
+
const [transcriptScroll, setTranscriptScroll] = useState(0);
|
|
53
|
+
// A ref, not state: the maximum changes on every streamed line and only clamps scroll input.
|
|
54
|
+
const maxTranscriptScrollRef = useRef(0);
|
|
55
|
+
const [pressedMetadata, setPressedMetadata] = useState();
|
|
56
|
+
const [pressedPanelFilter, setPressedPanelFilter] = useState();
|
|
57
|
+
const [pressedPanelRow, setPressedPanelRow] = useState();
|
|
58
|
+
const [pressedPanelControl, setPressedPanelControl] = useState();
|
|
59
|
+
const [pressedPanelSlider, setPressedPanelSlider] = useState(false);
|
|
60
|
+
const [pressedSuggestion, setPressedSuggestion] = useState();
|
|
61
|
+
const [hoveredPanelRow, setHoveredPanelRow] = useState();
|
|
62
|
+
const [hoveredPanelControl, setHoveredPanelControl] = useState();
|
|
63
|
+
const [hoveredPanelFilter, setHoveredPanelFilter] = useState();
|
|
64
|
+
const [hoveredPanelSlider, setHoveredPanelSlider] = useState(false);
|
|
65
|
+
const [hoveredSuggestion, setHoveredSuggestion] = useState();
|
|
66
|
+
const [pressedQueuedPrompt, setPressedQueuedPrompt] = useState();
|
|
67
|
+
const [editingQueuedPromptId, setEditingQueuedPromptId] = useState();
|
|
68
|
+
const [screenSelection, setScreenSelection] = useState([]);
|
|
69
|
+
const [clipboardNotice, setClipboardNotice] = useState();
|
|
70
|
+
const [frog, setFrog] = useState();
|
|
71
|
+
const [frogBrandAnimationId, setFrogBrandAnimationId] = useState();
|
|
72
|
+
const [party, setParty] = useState(false);
|
|
73
|
+
const [expandedToolGroups, setExpandedToolGroups] = useState(new Set());
|
|
74
|
+
const editorRef = useRef(editor);
|
|
75
|
+
const nextFrogId = useRef(0);
|
|
76
|
+
const nextFrogBrandAnimationId = useRef(0);
|
|
77
|
+
const previousFrogVariant = useRef(undefined);
|
|
78
|
+
const leftMouseDownRef = useRef(false);
|
|
79
|
+
const copyNoticeTimerRef = useRef(undefined);
|
|
80
|
+
const selectionDragRef = useRef(undefined);
|
|
81
|
+
const panelSliderDraggingRef = useRef(false);
|
|
82
|
+
const panelSliderValueRef = useRef(undefined);
|
|
83
|
+
const mouseMoveStateRef = useRef({
|
|
84
|
+
column: -1,
|
|
85
|
+
row: -1,
|
|
86
|
+
acceptedAt: Number.NEGATIVE_INFINITY,
|
|
87
|
+
});
|
|
88
|
+
const suggestionSelectionRef = useRef(0);
|
|
89
|
+
const panelSelectionRef = useRef(0);
|
|
90
|
+
const panelViewportStartRef = useRef(0);
|
|
91
|
+
const [metadataElements, registerMetadataElement] = useElementMap();
|
|
92
|
+
const panelElement = useRef(undefined);
|
|
93
|
+
const [panelRowElements, registerPanelRowElement] = useElementMap();
|
|
94
|
+
const [panelControlElements, registerPanelControlElement] = useElementMap();
|
|
95
|
+
const [panelFilterElements, registerPanelFilterElement] = useElementMap();
|
|
96
|
+
const [panelPinElements, registerPanelPinElement] = useElementMap();
|
|
97
|
+
const panelSearchElement = useRef(undefined);
|
|
98
|
+
const panelSliderElement = useRef(undefined);
|
|
99
|
+
const [suggestionElements, registerSuggestionElement] = useElementMap();
|
|
100
|
+
const [queuedPromptElements, registerQueuedPromptElement] = useElementMap();
|
|
101
|
+
const [toolGroupElements, registerToolGroupElement] = useElementMap();
|
|
102
|
+
const frogElement = useRef(undefined);
|
|
103
|
+
const frogPressRef = useRef(undefined);
|
|
104
|
+
const toolGroupPressRef = useRef(undefined);
|
|
105
|
+
const setEditor = useCallback((next) => {
|
|
106
|
+
editorRef.current = next;
|
|
107
|
+
setEditorState(next);
|
|
108
|
+
}, []);
|
|
109
|
+
const resetPanelPosition = useCallback(() => {
|
|
110
|
+
panelSelectionRef.current = 0;
|
|
111
|
+
panelViewportStartRef.current = 0;
|
|
112
|
+
setPanelSelection(0);
|
|
113
|
+
setPanelViewportStart(0);
|
|
114
|
+
}, []);
|
|
115
|
+
const selectPanelRow = useCallback((selection, capacity, rowCount) => {
|
|
116
|
+
panelSelectionRef.current = selection;
|
|
117
|
+
setPanelSelection(selection);
|
|
118
|
+
const start = revealPanelSelection(selection, panelViewportStartRef.current, capacity, rowCount);
|
|
119
|
+
panelViewportStartRef.current = start;
|
|
120
|
+
setPanelViewportStart(start);
|
|
121
|
+
}, []);
|
|
122
|
+
const resetHover = useCallback(() => {
|
|
123
|
+
setHoveredPanelRow(undefined);
|
|
124
|
+
setHoveredPanelControl(undefined);
|
|
125
|
+
setHoveredPanelFilter(undefined);
|
|
126
|
+
setHoveredPanelSlider(false);
|
|
127
|
+
setHoveredSuggestion(undefined);
|
|
128
|
+
}, []);
|
|
129
|
+
const resetPressed = useCallback(() => {
|
|
130
|
+
setPressedMetadata(undefined);
|
|
131
|
+
setPressedPanelFilter(undefined);
|
|
132
|
+
setPressedPanelRow(undefined);
|
|
133
|
+
setPressedPanelControl(undefined);
|
|
134
|
+
setPressedPanelSlider(false);
|
|
135
|
+
setPressedSuggestion(undefined);
|
|
136
|
+
setPressedQueuedPrompt(undefined);
|
|
137
|
+
}, []);
|
|
138
|
+
const rawAssistance = snapshot.panel || dismissedSuggestions === editor.input || controller.busy
|
|
139
|
+
? undefined
|
|
140
|
+
: commandAssistance(editor.input);
|
|
141
|
+
const assistance = rawAssistance && (rawAssistance.completions.length > 0 || /^\/[^\s]+\s$/.test(editor.input))
|
|
142
|
+
? rawAssistance
|
|
143
|
+
: undefined;
|
|
144
|
+
const suggestions = assistance?.completions ?? [];
|
|
145
|
+
const startupCovered = snapshot.panel !== undefined || assistance !== undefined;
|
|
146
|
+
const actionableCommandToken = controller.actionableCommandToken(editor.input);
|
|
147
|
+
const panelRows = snapshot.panel
|
|
148
|
+
? filterPanelRows(snapshot.panel.rows, panelQuery, snapshot.panel.kind === 'settings' && snapshot.panel.settingsCategory ? 'all' : panelFilter, snapshot.panel.kind === 'models')
|
|
149
|
+
: undefined;
|
|
150
|
+
const viewProps = {
|
|
151
|
+
snapshot,
|
|
152
|
+
input: editor.input,
|
|
153
|
+
cursor: editor.cursor,
|
|
154
|
+
terminalWidth: terminal.width,
|
|
155
|
+
terminalHeight: terminal.height,
|
|
156
|
+
suggestions,
|
|
157
|
+
...(panelRows ? { panelRows } : {}),
|
|
158
|
+
panelQuery,
|
|
159
|
+
panelFilter,
|
|
160
|
+
modelPanelFocus,
|
|
161
|
+
panelViewportStart,
|
|
162
|
+
suggestionSelection,
|
|
163
|
+
panelSelection,
|
|
164
|
+
detailScroll,
|
|
165
|
+
transcriptScroll,
|
|
166
|
+
...(actionableCommandToken ? { actionableCommandToken } : {}),
|
|
167
|
+
...(assistance ? { commandAssistance: assistance } : {}),
|
|
168
|
+
party,
|
|
169
|
+
expandedToolGroups,
|
|
170
|
+
};
|
|
171
|
+
const viewPropsRef = useRef(viewProps);
|
|
172
|
+
viewPropsRef.current = viewProps;
|
|
173
|
+
const registerPanelElement = useCallback((element) => {
|
|
174
|
+
panelElement.current = element ?? undefined;
|
|
175
|
+
}, []);
|
|
176
|
+
const registerPanelSearchElement = useCallback((element) => {
|
|
177
|
+
panelSearchElement.current = element ?? undefined;
|
|
178
|
+
}, []);
|
|
179
|
+
const registerPanelSliderElement = useCallback((element) => {
|
|
180
|
+
panelSliderElement.current = element ?? undefined;
|
|
181
|
+
}, []);
|
|
182
|
+
const registerFrogElement = useCallback((element) => {
|
|
183
|
+
frogElement.current = element ?? undefined;
|
|
184
|
+
}, []);
|
|
185
|
+
const updateMaxTranscriptScroll = useCallback((maximum) => {
|
|
186
|
+
maxTranscriptScrollRef.current = maximum;
|
|
187
|
+
setTranscriptScroll((value) => Math.min(value, maximum));
|
|
188
|
+
}, []);
|
|
189
|
+
const dispatchPrompt = useCallback((prompt, steer = false) => {
|
|
190
|
+
const command = prompt.trim().toLowerCase();
|
|
191
|
+
if (command === '/party') {
|
|
192
|
+
setParty((enabled) => !enabled);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (command === '/strands') {
|
|
196
|
+
openUrl('https://strandsagents.com');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const variant = parseFrogCommand(prompt, previousFrogVariant.current);
|
|
200
|
+
if (variant) {
|
|
201
|
+
nextFrogId.current += 1;
|
|
202
|
+
previousFrogVariant.current = variant;
|
|
203
|
+
setFrog({ id: nextFrogId.current, variant });
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
void (steer ? controller.steer(prompt) : controller.submit(prompt));
|
|
207
|
+
}, [controller, openUrl]);
|
|
208
|
+
const finishFrog = useCallback((id) => {
|
|
209
|
+
setFrog((current) => (current?.id === id ? undefined : current));
|
|
210
|
+
}, []);
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
const resize = () => {
|
|
213
|
+
const size = { width: stdout.columns || 80, height: stdout.rows || 24 };
|
|
214
|
+
const { snapshot, panelRows } = viewPropsRef.current;
|
|
215
|
+
if (snapshot.panel && panelRows) {
|
|
216
|
+
const agents = snapshot.panel.kind === 'agents';
|
|
217
|
+
const capacity = agents
|
|
218
|
+
? agentGridCapacity(size.width, size.height)
|
|
219
|
+
: panelRowCapacity(snapshot.panel.kind, size.height, size.width, panelRows);
|
|
220
|
+
const start = agents
|
|
221
|
+
? revealAgentGridSelection(panelSelectionRef.current, panelViewportStartRef.current, capacity, panelRows.length, agentGridColumns(size.width))
|
|
222
|
+
: revealPanelSelection(panelSelectionRef.current, panelViewportStartRef.current, capacity, panelRows.length);
|
|
223
|
+
panelViewportStartRef.current = start;
|
|
224
|
+
setPanelViewportStart(start);
|
|
225
|
+
}
|
|
226
|
+
setTerminal(size);
|
|
227
|
+
};
|
|
228
|
+
stdout.on('resize', resize);
|
|
229
|
+
return () => {
|
|
230
|
+
stdout.off('resize', resize);
|
|
231
|
+
};
|
|
232
|
+
}, [stdout]);
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
if (snapshot.status === 'closed') {
|
|
235
|
+
exit();
|
|
236
|
+
}
|
|
237
|
+
}, [exit, snapshot.status]);
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
suggestionSelectionRef.current = 0;
|
|
240
|
+
setSuggestionSelection(0);
|
|
241
|
+
setDismissedSuggestions(undefined);
|
|
242
|
+
}, [editor.input]);
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
resetPanelPosition();
|
|
245
|
+
setPanelQuery('');
|
|
246
|
+
setPanelFilter(snapshot.panel?.kind === 'help'
|
|
247
|
+
? 'controls'
|
|
248
|
+
: snapshot.panel?.kind === 'settings' && snapshot.panel.settingsCategory
|
|
249
|
+
? `settings:${snapshot.panel.settingsCategory}`
|
|
250
|
+
: 'all');
|
|
251
|
+
setModelPanelFocus(snapshot.panel?.slider?.focused ? 'effort' : 'models');
|
|
252
|
+
setPressedPanelFilter(undefined);
|
|
253
|
+
setPressedPanelRow(undefined);
|
|
254
|
+
setPressedPanelControl(undefined);
|
|
255
|
+
setPressedPanelSlider(false);
|
|
256
|
+
resetHover();
|
|
257
|
+
setPressedQueuedPrompt(undefined);
|
|
258
|
+
setDetailScroll(0);
|
|
259
|
+
panelSliderDraggingRef.current = false;
|
|
260
|
+
panelSliderValueRef.current = snapshot.panel?.slider?.options.find((option) => option.active)?.id;
|
|
261
|
+
}, [snapshot.panel?.id, resetPanelPosition, resetHover]);
|
|
262
|
+
useEffect(() => {
|
|
263
|
+
if (startupCovered) {
|
|
264
|
+
setFrogBrandAnimationId(undefined);
|
|
265
|
+
}
|
|
266
|
+
}, [startupCovered]);
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
if (!snapshot.activeTurn && snapshot.completedTurns.length === 0) {
|
|
269
|
+
setExpandedToolGroups((current) => (current.size > 0 ? new Set() : current));
|
|
270
|
+
}
|
|
271
|
+
}, [snapshot.activeTurn, snapshot.completedTurns.length]);
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (editingQueuedPromptId &&
|
|
274
|
+
!snapshot.queuedPrompts.some((prompt) => prompt.id === editingQueuedPromptId && prompt.source !== 'peer')) {
|
|
275
|
+
setEditingQueuedPromptId(undefined);
|
|
276
|
+
}
|
|
277
|
+
}, [editingQueuedPromptId, snapshot.queuedPrompts]);
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
panelSliderValueRef.current = snapshot.panel?.slider?.options.find((option) => option.active)?.id;
|
|
280
|
+
}, [snapshot.panel?.slider]);
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
setTranscriptScroll(0);
|
|
283
|
+
}, [snapshot.activeTurn?.id]);
|
|
284
|
+
const menuOpen = snapshot.panel !== undefined || suggestions.length > 0;
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
setTerminalMouseMotion(menuOpen, stdout);
|
|
287
|
+
return () => {
|
|
288
|
+
setTerminalMouseMotion(false, stdout);
|
|
289
|
+
};
|
|
290
|
+
}, [menuOpen, stdout]);
|
|
291
|
+
useEffect(() => () => {
|
|
292
|
+
clearTimeout(copyNoticeTimerRef.current);
|
|
293
|
+
}, []);
|
|
294
|
+
const copyText = useCallback((text) => {
|
|
295
|
+
const characterCount = graphemes(text).length;
|
|
296
|
+
void copyTerminalText(text, stdout).then((copied) => {
|
|
297
|
+
clearTimeout(copyNoticeTimerRef.current);
|
|
298
|
+
setClipboardNotice(copied ? { status: 'success', characterCount } : { status: 'error' });
|
|
299
|
+
copyNoticeTimerRef.current = setTimeout(() => {
|
|
300
|
+
setClipboardNotice(undefined);
|
|
301
|
+
}, 2_000);
|
|
302
|
+
});
|
|
303
|
+
}, [stdout]);
|
|
304
|
+
const toggleModelPin = useCallback((modelId) => {
|
|
305
|
+
void controller.toggleModelPin(modelId).then((changed) => {
|
|
306
|
+
if (!changed) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const state = viewPropsRef.current;
|
|
310
|
+
const rows = filterPanelRows(controller.getSnapshot().panel?.rows ?? [], state.panelQuery, state.panelFilter, true);
|
|
311
|
+
const selection = Math.max(0, rows.findIndex((row) => row.value === modelId));
|
|
312
|
+
selectPanelRow(selection, panelRowCapacity('models', state.terminalHeight), rows.length);
|
|
313
|
+
});
|
|
314
|
+
}, [controller, selectPanelRow]);
|
|
315
|
+
const handleMouse = useCallback((mouse) => {
|
|
316
|
+
if (!shouldProcessMouseInput(mouse, mouseMoveStateRef.current)) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const { snapshot, terminalWidth, terminalHeight, suggestions, panelRows } = viewPropsRef.current;
|
|
320
|
+
const currentEditor = editorRef.current;
|
|
321
|
+
const button = mouse.button & 3;
|
|
322
|
+
const scroll = mouseScrollDirection(mouse);
|
|
323
|
+
if (scroll !== undefined) {
|
|
324
|
+
resetHover();
|
|
325
|
+
leftMouseDownRef.current = false;
|
|
326
|
+
frogPressRef.current = undefined;
|
|
327
|
+
toolGroupPressRef.current = undefined;
|
|
328
|
+
selectionDragRef.current = undefined;
|
|
329
|
+
setScreenSelection([]);
|
|
330
|
+
panelSliderDraggingRef.current = false;
|
|
331
|
+
setPressedPanelRow(undefined);
|
|
332
|
+
setPressedPanelControl(undefined);
|
|
333
|
+
setPressedSuggestion(undefined);
|
|
334
|
+
if (snapshot.panel?.kind === 'detail') {
|
|
335
|
+
const maxScroll = maxDetailScroll(snapshot.panel, terminalWidth, terminalHeight);
|
|
336
|
+
setDetailScroll((value) => scrollDetail(value, scroll, maxScroll, snapshot.panel?.followTail === true, 3));
|
|
337
|
+
}
|
|
338
|
+
else if (snapshot.panel?.kind === 'permission') {
|
|
339
|
+
const maxScroll = maxPermissionScroll(snapshot.panel, terminalHeight, terminalWidth);
|
|
340
|
+
setDetailScroll((value) => scrollDetail(value, scroll, maxScroll, false, 3));
|
|
341
|
+
}
|
|
342
|
+
else if (snapshot.panel) {
|
|
343
|
+
const rows = panelRows ?? [];
|
|
344
|
+
const agents = snapshot.panel.kind === 'agents';
|
|
345
|
+
const capacity = agents
|
|
346
|
+
? agentGridCapacity(terminalWidth, terminalHeight)
|
|
347
|
+
: panelRowCapacity(snapshot.panel.kind, terminalHeight, terminalWidth, rows);
|
|
348
|
+
const nextStart = agents
|
|
349
|
+
? scrollAgentGridViewport(panelViewportStartRef.current, scroll, rows.length, capacity, agentGridColumns(terminalWidth))
|
|
350
|
+
: scrollPanelViewport(panelViewportStartRef.current, scroll, rows.length, capacity);
|
|
351
|
+
panelViewportStartRef.current = nextStart;
|
|
352
|
+
setPanelViewportStart(nextStart);
|
|
353
|
+
}
|
|
354
|
+
else if (suggestions.length > 0) {
|
|
355
|
+
const nextSelection = moveSelection(suggestionSelectionRef.current, scroll < 0 ? { upArrow: true } : { downArrow: true }, suggestions.length, suggestions.length);
|
|
356
|
+
if (nextSelection !== undefined) {
|
|
357
|
+
suggestionSelectionRef.current = nextSelection;
|
|
358
|
+
setSuggestionSelection(nextSelection);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
setTranscriptScroll((value) => scrollTranscript(value, scroll, maxTranscriptScrollRef.current));
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const panelHit = panelElement.current ? elementContainsMouse(panelElement.current, mouse) : false;
|
|
367
|
+
const metadataTarget = panelHit ? undefined : elementAtMouse(metadataElements, mouse);
|
|
368
|
+
const footerAction = !snapshot.panel ? elementAtMouse(footerElements, mouse) : undefined;
|
|
369
|
+
const panelRowIndex = snapshot.panel ? elementAtMouse(panelRowElements, mouse) : undefined;
|
|
370
|
+
const panelControlTarget = snapshot.panel?.kind === 'settings' || snapshot.panel?.kind === 'voice' || snapshot.panel?.kind === 'models'
|
|
371
|
+
? elementAtMouse(panelControlElements, mouse)
|
|
372
|
+
: undefined;
|
|
373
|
+
const panelFilterId = snapshot.panel ? elementAtMouse(panelFilterElements, mouse) : undefined;
|
|
374
|
+
const panelPinIndex = snapshot.panel?.kind === 'models' ? elementAtMouse(panelPinElements, mouse) : undefined;
|
|
375
|
+
const suggestionIndex = !snapshot.panel && suggestions.length > 0 ? elementAtMouse(suggestionElements, mouse) : undefined;
|
|
376
|
+
const queuedPromptTarget = !snapshot.panel ? elementAtMouse(queuedPromptElements, mouse) : undefined;
|
|
377
|
+
const toolGroupTarget = !snapshot.panel ? elementAtMouse(toolGroupElements, mouse) : undefined;
|
|
378
|
+
const sliderElement = snapshot.panel?.kind === 'models' ? panelSliderElement.current : undefined;
|
|
379
|
+
const sliderHit = sliderElement ? elementContainsMouse(sliderElement, mouse) : false;
|
|
380
|
+
const searchElement = snapshot.panel?.kind === 'models' ? panelSearchElement.current : undefined;
|
|
381
|
+
const searchHit = searchElement ? elementContainsMouse(searchElement, mouse) : false;
|
|
382
|
+
const frogHit = frogElement.current ? elementContainsMouse(frogElement.current, mouse) : false;
|
|
383
|
+
if (mouse.action === 'move' && !leftMouseDownRef.current) {
|
|
384
|
+
setHoveredPanelRow(panelRowIndex);
|
|
385
|
+
setHoveredPanelControl(panelControlTarget);
|
|
386
|
+
setHoveredPanelFilter(panelFilterId);
|
|
387
|
+
setHoveredPanelSlider(sliderHit);
|
|
388
|
+
setHoveredSuggestion(suggestionIndex);
|
|
389
|
+
}
|
|
390
|
+
if (mouse.action === 'press' && button === 0) {
|
|
391
|
+
resetHover();
|
|
392
|
+
setFrog(undefined);
|
|
393
|
+
leftMouseDownRef.current = true;
|
|
394
|
+
frogPressRef.current = frogHit ? { column: mouse.column, row: mouse.row } : undefined;
|
|
395
|
+
toolGroupPressRef.current = toolGroupTarget;
|
|
396
|
+
setScreenSelection([]);
|
|
397
|
+
selectionDragRef.current =
|
|
398
|
+
sliderHit || panelControlTarget || toolGroupTarget || queuedPromptTarget
|
|
399
|
+
? undefined
|
|
400
|
+
: {
|
|
401
|
+
anchor: mouse,
|
|
402
|
+
lines: sanitizeTerminalText(renderToString(createElement(ChatView, {
|
|
403
|
+
...viewPropsRef.current,
|
|
404
|
+
input: currentEditor.input,
|
|
405
|
+
cursor: currentEditor.cursor,
|
|
406
|
+
synchronousTranscriptLayout: true,
|
|
407
|
+
}), { columns: terminalWidth })).split('\n'),
|
|
408
|
+
};
|
|
409
|
+
setPressedMetadata(metadataTarget);
|
|
410
|
+
setPressedPanelFilter(panelFilterId);
|
|
411
|
+
setPressedPanelRow(panelRowIndex);
|
|
412
|
+
setPressedPanelControl(panelControlTarget);
|
|
413
|
+
setPressedPanelSlider(sliderHit);
|
|
414
|
+
setPressedSuggestion(suggestionIndex);
|
|
415
|
+
setPressedQueuedPrompt(queuedPromptTarget);
|
|
416
|
+
if (sliderHit) {
|
|
417
|
+
setModelPanelFocus('effort');
|
|
418
|
+
}
|
|
419
|
+
else if (searchHit) {
|
|
420
|
+
setModelPanelFocus('search');
|
|
421
|
+
}
|
|
422
|
+
else if (panelFilterId) {
|
|
423
|
+
setModelPanelFocus('providers');
|
|
424
|
+
}
|
|
425
|
+
else if (panelRowIndex !== undefined) {
|
|
426
|
+
setModelPanelFocus('models');
|
|
427
|
+
}
|
|
428
|
+
else if (panelControlTarget === MODEL_COPY_TARGET) {
|
|
429
|
+
setModelPanelFocus('copy');
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const leftRelease = mouse.action === 'release' && leftMouseDownRef.current;
|
|
433
|
+
const frogClicked = leftRelease &&
|
|
434
|
+
frogHit &&
|
|
435
|
+
frogPressRef.current?.column === mouse.column &&
|
|
436
|
+
frogPressRef.current?.row === mouse.row;
|
|
437
|
+
const toolGroupClicked = leftRelease && toolGroupTarget !== undefined && toolGroupPressRef.current === toolGroupTarget;
|
|
438
|
+
const completedSelection = leftRelease && selectionDragRef.current
|
|
439
|
+
? selectScreenText(selectionDragRef.current.lines, selectionDragRef.current.anchor, mouse)
|
|
440
|
+
: undefined;
|
|
441
|
+
if (mouse.action === 'release') {
|
|
442
|
+
leftMouseDownRef.current = false;
|
|
443
|
+
frogPressRef.current = undefined;
|
|
444
|
+
toolGroupPressRef.current = undefined;
|
|
445
|
+
selectionDragRef.current = undefined;
|
|
446
|
+
resetPressed();
|
|
447
|
+
}
|
|
448
|
+
const updateSliderSelection = () => {
|
|
449
|
+
const slider = snapshot.panel?.slider;
|
|
450
|
+
if (!sliderElement || !slider || slider.disabled) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const option = sliderOptionAtMouse(slider, sliderElement, mouse);
|
|
454
|
+
if (!option || option.id === panelSliderValueRef.current) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
panelSliderValueRef.current = option.id;
|
|
458
|
+
void activateRow({
|
|
459
|
+
label: slider.label,
|
|
460
|
+
description: option.label,
|
|
461
|
+
value: `effort:${option.id}`,
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
if (mouse.action === 'move' && panelSliderDraggingRef.current) {
|
|
465
|
+
updateSliderSelection();
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (mouse.action === 'press' && button === 0 && sliderHit) {
|
|
469
|
+
panelSliderDraggingRef.current = true;
|
|
470
|
+
updateSliderSelection();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (mouse.action === 'release' && panelSliderDraggingRef.current) {
|
|
474
|
+
panelSliderDraggingRef.current = false;
|
|
475
|
+
updateSliderSelection();
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if (completedSelection) {
|
|
479
|
+
setScreenSelection(completedSelection.segments);
|
|
480
|
+
copyText(completedSelection.text);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if (frogClicked) {
|
|
484
|
+
setFrogBrandAnimationId(++nextFrogBrandAnimationId.current);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (toolGroupClicked) {
|
|
488
|
+
setExpandedToolGroups((current) => {
|
|
489
|
+
const next = new Set(current);
|
|
490
|
+
if (next.has(toolGroupTarget)) {
|
|
491
|
+
next.delete(toolGroupTarget);
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
next.add(toolGroupTarget);
|
|
495
|
+
}
|
|
496
|
+
return next;
|
|
497
|
+
});
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (mouse.action === 'move') {
|
|
501
|
+
const selection = selectionDragRef.current
|
|
502
|
+
? selectScreenText(selectionDragRef.current.lines, selectionDragRef.current.anchor, mouse)
|
|
503
|
+
: undefined;
|
|
504
|
+
if (selection) {
|
|
505
|
+
resetPressed();
|
|
506
|
+
setScreenSelection(selection.segments);
|
|
507
|
+
}
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (mouse.action !== 'release' || (!leftRelease && button !== 0)) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
if (panelFilterId) {
|
|
514
|
+
if (snapshot.panel?.kind === 'settings' && snapshot.panel.settingsCategory) {
|
|
515
|
+
void activateRow({ label: '', description: '', value: panelFilterId });
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
setPanelFilter(panelFilterId);
|
|
519
|
+
resetPanelPosition();
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
else if (panelControlTarget) {
|
|
523
|
+
if (panelControlTarget === MODEL_COPY_TARGET) {
|
|
524
|
+
const modelId = panelRows?.[panelSelectionRef.current]?.value;
|
|
525
|
+
if (modelId) {
|
|
526
|
+
copyText(modelId);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
const target = parsePanelControlTarget(panelControlTarget);
|
|
531
|
+
const row = target ? panelRows?.[target.index] : undefined;
|
|
532
|
+
if (!row?.value || !target) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
void activateRow({
|
|
536
|
+
...row,
|
|
537
|
+
value: row.control?.kind === 'toggle' ? row.value : `${row.value}=${target.value}`,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else if (panelPinIndex !== undefined) {
|
|
542
|
+
const row = panelRows?.[panelPinIndex];
|
|
543
|
+
if (row?.value) {
|
|
544
|
+
toggleModelPin(row.value);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else if (panelRowIndex !== undefined) {
|
|
548
|
+
panelSelectionRef.current = panelRowIndex;
|
|
549
|
+
setPanelSelection(panelRowIndex);
|
|
550
|
+
const row = panelRows?.[panelRowIndex];
|
|
551
|
+
if (row?.value && (snapshot.panel?.kind !== 'settings' || !row.control)) {
|
|
552
|
+
void activateRow(row);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
else if (snapshot.panel && !panelHit && !metadataTarget) {
|
|
556
|
+
controller.dismissPanel();
|
|
557
|
+
}
|
|
558
|
+
else if (suggestionIndex !== undefined) {
|
|
559
|
+
suggestionSelectionRef.current = suggestionIndex;
|
|
560
|
+
setSuggestionSelection(suggestionIndex);
|
|
561
|
+
const suggestion = suggestions[suggestionIndex];
|
|
562
|
+
if (suggestion) {
|
|
563
|
+
if (suggestion.replacement) {
|
|
564
|
+
setEditor(completeSuggestion(currentEditor, suggestion));
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
const result = submitEditor(currentEditor, `/${suggestion.name}`);
|
|
568
|
+
setEditor(result.state);
|
|
569
|
+
if (result.action === 'submit') {
|
|
570
|
+
dispatchPrompt(result.prompt);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
else if (queuedPromptTarget) {
|
|
576
|
+
const target = parseQueuedPromptTarget(queuedPromptTarget);
|
|
577
|
+
if (!target) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (target.action === 'steer') {
|
|
581
|
+
controller.steerQueued(target.id);
|
|
582
|
+
}
|
|
583
|
+
else if (target.action === 'up' || target.action === 'down') {
|
|
584
|
+
controller.moveQueuedPrompt(target.id, target.action === 'up' ? -1 : 1);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
const prompt = snapshot.queuedPrompts.find((candidate) => candidate.id === target.id);
|
|
588
|
+
if (prompt && prompt.source !== 'peer') {
|
|
589
|
+
setEditingQueuedPromptId(prompt.id);
|
|
590
|
+
setEditor({
|
|
591
|
+
...currentEditor,
|
|
592
|
+
input: prompt.prompt,
|
|
593
|
+
cursor: graphemes(prompt.prompt).length,
|
|
594
|
+
historyIndex: currentEditor.history.length,
|
|
595
|
+
draft: prompt.prompt,
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
else if (footerAction) {
|
|
601
|
+
void controller.submit(`/${footerAction}`);
|
|
602
|
+
}
|
|
603
|
+
else if (metadataTarget) {
|
|
604
|
+
void activateMetadataTarget(controller, metadataTarget);
|
|
605
|
+
}
|
|
606
|
+
}, [
|
|
607
|
+
activateRow,
|
|
608
|
+
copyText,
|
|
609
|
+
controller,
|
|
610
|
+
dispatchPrompt,
|
|
611
|
+
footerElements,
|
|
612
|
+
metadataElements,
|
|
613
|
+
panelControlElements,
|
|
614
|
+
panelFilterElements,
|
|
615
|
+
panelPinElements,
|
|
616
|
+
panelRowElements,
|
|
617
|
+
queuedPromptElements,
|
|
618
|
+
resetHover,
|
|
619
|
+
resetPanelPosition,
|
|
620
|
+
resetPressed,
|
|
621
|
+
setEditor,
|
|
622
|
+
suggestionElements,
|
|
623
|
+
toggleModelPin,
|
|
624
|
+
toolGroupElements,
|
|
625
|
+
]);
|
|
626
|
+
const handleInput = useCallback((character, key) => {
|
|
627
|
+
if (appearanceOpen)
|
|
628
|
+
return;
|
|
629
|
+
const { snapshot, terminalWidth, terminalHeight, suggestions, panelRows, panelQuery, panelFilter, modelPanelFocus, } = viewPropsRef.current;
|
|
630
|
+
const currentEditor = editorRef.current;
|
|
631
|
+
const mouse = parseMouseInput(character);
|
|
632
|
+
if (mouse) {
|
|
633
|
+
handleMouse(mouse);
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
selectionDragRef.current = undefined;
|
|
637
|
+
setScreenSelection([]);
|
|
638
|
+
resetHover();
|
|
639
|
+
setPressedPanelRow(undefined);
|
|
640
|
+
setPressedPanelControl(undefined);
|
|
641
|
+
setPressedPanelSlider(false);
|
|
642
|
+
setPressedSuggestion(undefined);
|
|
643
|
+
setPressedQueuedPrompt(undefined);
|
|
644
|
+
if (key.ctrl && (character === 'c' || character === 'd')) {
|
|
645
|
+
if (controller.busy) {
|
|
646
|
+
controller.cancel();
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
controller.close(character === 'c' ? 130 : 0);
|
|
650
|
+
}
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (frog && key.escape) {
|
|
654
|
+
setFrog(undefined);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (snapshot.composerStatus) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (snapshot.panel?.kind === 'voice' &&
|
|
661
|
+
shouldToggleVoiceMute(character, key, currentEditor.input, snapshot.voice?.status)) {
|
|
662
|
+
controller.toggleVoiceMute?.();
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (snapshot.setupGuide &&
|
|
666
|
+
snapshot.panel?.kind === 'question' &&
|
|
667
|
+
editsSetupAnswer(character, key, currentEditor.input)) {
|
|
668
|
+
const result = reduceInputSequence(currentEditor, character, key, 'idle');
|
|
669
|
+
setEditor(result.state);
|
|
670
|
+
if (result.action === 'submit') {
|
|
671
|
+
void controller.submit(result.prompt);
|
|
672
|
+
}
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (snapshot.panel) {
|
|
676
|
+
if (snapshot.panel.kind === 'detail') {
|
|
677
|
+
if (key.escape || key.return || key.backspace || key.delete || character === '\u007f') {
|
|
678
|
+
controller.dismissPanel();
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const page = detailPageSize(terminalHeight, snapshot.panel.rows.length);
|
|
682
|
+
const maxScroll = maxDetailScroll(snapshot.panel, terminalWidth, terminalHeight);
|
|
683
|
+
if (key.upArrow) {
|
|
684
|
+
setDetailScroll((value) => scrollDetail(value, -1, maxScroll, snapshot.panel?.followTail === true, 1));
|
|
685
|
+
}
|
|
686
|
+
else if (key.downArrow) {
|
|
687
|
+
setDetailScroll((value) => scrollDetail(value, 1, maxScroll, snapshot.panel?.followTail === true, 1));
|
|
688
|
+
}
|
|
689
|
+
else if (key.pageUp) {
|
|
690
|
+
setDetailScroll((value) => scrollDetail(value, -1, maxScroll, snapshot.panel?.followTail === true, page));
|
|
691
|
+
}
|
|
692
|
+
else if (key.pageDown) {
|
|
693
|
+
setDetailScroll((value) => scrollDetail(value, 1, maxScroll, snapshot.panel?.followTail === true, page));
|
|
694
|
+
}
|
|
695
|
+
else if (key.home) {
|
|
696
|
+
setDetailScroll(snapshot.panel.followTail ? maxScroll : 0);
|
|
697
|
+
}
|
|
698
|
+
else if (key.end) {
|
|
699
|
+
setDetailScroll(snapshot.panel.followTail ? 0 : maxScroll);
|
|
700
|
+
}
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const rows = panelRows ?? [];
|
|
704
|
+
const rowCapacity = snapshot.panel.kind === 'agents'
|
|
705
|
+
? agentGridCapacity(terminalWidth, terminalHeight)
|
|
706
|
+
: panelRowCapacity(snapshot.panel.kind, terminalHeight, terminalWidth, rows);
|
|
707
|
+
if (snapshot.panel.kind === 'permission' && key.escape) {
|
|
708
|
+
const reject = rows.find((row) => row.tone === 'danger');
|
|
709
|
+
if (reject) {
|
|
710
|
+
void activateRow(reject);
|
|
711
|
+
}
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (snapshot.panel.kind === 'permission' && (key.pageUp || key.pageDown || key.home || key.end)) {
|
|
715
|
+
const maximum = maxPermissionScroll(snapshot.panel, terminalHeight, terminalWidth);
|
|
716
|
+
if (key.home) {
|
|
717
|
+
setDetailScroll(0);
|
|
718
|
+
}
|
|
719
|
+
else if (key.end) {
|
|
720
|
+
setDetailScroll(maximum);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
setDetailScroll((value) => scrollDetail(value, key.pageUp ? -1 : 1, maximum, false, Math.max(3, terminalHeight - 16)));
|
|
724
|
+
}
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
if (key.escape) {
|
|
728
|
+
if (panelQuery) {
|
|
729
|
+
setPanelQuery('');
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
controller.dismissPanel();
|
|
733
|
+
}
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (snapshot.panel.kind === 'models') {
|
|
737
|
+
if (key.tab) {
|
|
738
|
+
setModelPanelFocus(cycleModelPanelFocus(modelPanelFocus, snapshot.panel, key.shift ? -1 : 1, true));
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
if ((key.return || character === ' ') && modelPanelFocus === 'copy') {
|
|
742
|
+
const modelId = rows[Math.min(panelSelectionRef.current, rows.length - 1)]?.value;
|
|
743
|
+
if (modelId) {
|
|
744
|
+
copyText(modelId);
|
|
745
|
+
}
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
if (character === ' ' && modelPanelFocus === 'models') {
|
|
749
|
+
const selected = rows[Math.min(panelSelectionRef.current, rows.length - 1)];
|
|
750
|
+
if (selected?.value) {
|
|
751
|
+
toggleModelPin(selected.value);
|
|
752
|
+
}
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (modelPanelFocus === 'effort' &&
|
|
756
|
+
snapshot.panel.slider &&
|
|
757
|
+
!snapshot.panel.slider.disabled &&
|
|
758
|
+
(key.leftArrow || key.rightArrow)) {
|
|
759
|
+
const option = adjacentSliderOption(snapshot.panel.slider, key.leftArrow ? -1 : 1);
|
|
760
|
+
if (option) {
|
|
761
|
+
void activateRow({
|
|
762
|
+
label: snapshot.panel.slider.label,
|
|
763
|
+
description: option.label,
|
|
764
|
+
value: `effort:${option.id}`,
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
if (modelPanelFocus === 'providers' && snapshot.panel.filters?.length) {
|
|
770
|
+
if (key.upArrow || key.downArrow) {
|
|
771
|
+
setPanelFilter(cyclePanelFilter(snapshot.panel.filters, panelFilter, key.upArrow ? -1 : 1));
|
|
772
|
+
resetPanelPosition();
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (key.rightArrow) {
|
|
776
|
+
setModelPanelFocus('models');
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
if (modelPanelFocus === 'models') {
|
|
781
|
+
if (key.leftArrow && snapshot.panel.filters?.length) {
|
|
782
|
+
setModelPanelFocus('providers');
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
if (key.rightArrow) {
|
|
786
|
+
setModelPanelFocus('copy');
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const nextSelection = moveSelection(panelSelectionRef.current, key, rows.length, rowCapacity);
|
|
790
|
+
if (nextSelection !== undefined) {
|
|
791
|
+
selectPanelRow(nextSelection, rowCapacity, rows.length);
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (modelPanelFocus === 'copy' && key.leftArrow) {
|
|
796
|
+
setModelPanelFocus('models');
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (modelPanelFocus === 'search') {
|
|
800
|
+
if (key.downArrow) {
|
|
801
|
+
setModelPanelFocus('models');
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
if (key.upArrow && snapshot.panel.slider) {
|
|
805
|
+
setModelPanelFocus('effort');
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (key.backspace || key.delete || character === '\u007f') {
|
|
810
|
+
setModelPanelFocus('search');
|
|
811
|
+
setPanelQuery(graphemes(panelQuery).slice(0, -1).join(''));
|
|
812
|
+
resetPanelPosition();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
if (key.ctrl && character === 'u') {
|
|
816
|
+
setModelPanelFocus('search');
|
|
817
|
+
setPanelQuery('');
|
|
818
|
+
resetPanelPosition();
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
if (!key.ctrl && !key.meta && !key.super && character) {
|
|
822
|
+
const clean = sanitizeTerminalText(character).replaceAll('\n', '');
|
|
823
|
+
if (clean) {
|
|
824
|
+
setModelPanelFocus('search');
|
|
825
|
+
setPanelQuery((query) => query + clean);
|
|
826
|
+
resetPanelPosition();
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (key.tab &&
|
|
832
|
+
snapshot.panel.kind === 'settings' &&
|
|
833
|
+
snapshot.panel.settingsCategory &&
|
|
834
|
+
snapshot.panel.filters?.length) {
|
|
835
|
+
const category = cyclePanelFilter(snapshot.panel.filters, `settings:${snapshot.panel.settingsCategory}`, key.shift ? -1 : 1);
|
|
836
|
+
void activateRow({ label: '', description: '', value: category });
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
if (key.tab && snapshot.panel.filters?.length) {
|
|
840
|
+
setPanelFilter(cyclePanelFilter(snapshot.panel.filters, panelFilter, key.shift ? -1 : 1));
|
|
841
|
+
resetPanelPosition();
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if ((snapshot.panel.kind === 'settings' || snapshot.panel.kind === 'voice') &&
|
|
845
|
+
(key.leftArrow || key.rightArrow || (snapshot.panel.kind === 'settings' && (key.upArrow || key.downArrow)))) {
|
|
846
|
+
const selected = rows[Math.min(panelSelectionRef.current, rows.length - 1)];
|
|
847
|
+
if (selected?.value && selected.control?.kind === 'segmented') {
|
|
848
|
+
const { columns } = selected.value === 'frogTheme'
|
|
849
|
+
? settingsThemeLayout(terminalWidth - 4)
|
|
850
|
+
: settingsLayout(terminalWidth - 4, selected.value);
|
|
851
|
+
const index = adjacentSettingOption(selected.control, key, columns);
|
|
852
|
+
const option = index === undefined ? undefined : selected.control.options[index];
|
|
853
|
+
if (option) {
|
|
854
|
+
if (!option.active) {
|
|
855
|
+
void activateRow({
|
|
856
|
+
...selected,
|
|
857
|
+
value: `${selected.value}=${option.value}`,
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (key.leftArrow || key.rightArrow) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if ((snapshot.panel.kind === 'settings' ||
|
|
868
|
+
snapshot.panel.kind === 'voice' ||
|
|
869
|
+
snapshot.panel.kind === 'permissions') &&
|
|
870
|
+
character === ' ') {
|
|
871
|
+
const selected = rows[Math.min(panelSelectionRef.current, rows.length - 1)];
|
|
872
|
+
if (selected?.value) {
|
|
873
|
+
void activateRow(selected);
|
|
874
|
+
}
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
if (snapshot.panel.kind === 'agents') {
|
|
878
|
+
const nextSelection = moveAgentGridSelection(panelSelectionRef.current, key, rows.length, agentGridColumns(terminalWidth), rowCapacity);
|
|
879
|
+
if (nextSelection !== undefined) {
|
|
880
|
+
panelSelectionRef.current = nextSelection;
|
|
881
|
+
setPanelSelection(nextSelection);
|
|
882
|
+
const nextStart = revealAgentGridSelection(nextSelection, panelViewportStartRef.current, rowCapacity, rows.length, agentGridColumns(terminalWidth));
|
|
883
|
+
panelViewportStartRef.current = nextStart;
|
|
884
|
+
setPanelViewportStart(nextStart);
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
if (key.return) {
|
|
889
|
+
const selected = rows[Math.min(panelSelectionRef.current, rows.length - 1)];
|
|
890
|
+
if (selected?.value) {
|
|
891
|
+
void activateRow(selected);
|
|
892
|
+
}
|
|
893
|
+
else if (!snapshot.panel.searchable) {
|
|
894
|
+
controller.dismissPanel();
|
|
895
|
+
}
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const nextSelection = moveSelection(panelSelectionRef.current, key, rows.length, rowCapacity);
|
|
899
|
+
if (nextSelection !== undefined) {
|
|
900
|
+
if (snapshot.panel.kind === 'settings' && key.upArrow && nextSelection < panelSelectionRef.current) {
|
|
901
|
+
const row = rows[nextSelection];
|
|
902
|
+
if (row?.value && row.control?.kind === 'segmented') {
|
|
903
|
+
const { columns } = row.value === 'frogTheme'
|
|
904
|
+
? settingsThemeLayout(terminalWidth - 4)
|
|
905
|
+
: settingsLayout(terminalWidth - 4, row.value);
|
|
906
|
+
const options = row.control.options;
|
|
907
|
+
const active = Math.max(0, options.findIndex((option) => option.active));
|
|
908
|
+
const lastRow = Math.floor((options.length - 1) / columns) * columns;
|
|
909
|
+
const option = options[Math.min(options.length - 1, lastRow + (active % columns))];
|
|
910
|
+
if (option && !option.active) {
|
|
911
|
+
void activateRow({ ...row, value: `${row.value}=${option.value}` });
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
selectPanelRow(nextSelection, rowCapacity, rows.length);
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
if (snapshot.panel.searchable && (key.backspace || key.delete || character === '\u007f')) {
|
|
919
|
+
setPanelQuery(graphemes(panelQuery).slice(0, -1).join(''));
|
|
920
|
+
resetPanelPosition();
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
if (snapshot.panel.searchable && key.ctrl && character === 'u') {
|
|
924
|
+
setPanelQuery('');
|
|
925
|
+
resetPanelPosition();
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (snapshot.panel.searchable && !key.ctrl && !key.meta && !key.super && character) {
|
|
929
|
+
const clean = sanitizeTerminalText(character).replaceAll('\n', '');
|
|
930
|
+
if (clean) {
|
|
931
|
+
setPanelQuery((query) => query + clean);
|
|
932
|
+
resetPanelPosition();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
if (editingQueuedPromptId && key.escape) {
|
|
938
|
+
setEditingQueuedPromptId(undefined);
|
|
939
|
+
setEditor({
|
|
940
|
+
...currentEditor,
|
|
941
|
+
input: '',
|
|
942
|
+
cursor: 0,
|
|
943
|
+
historyIndex: currentEditor.history.length,
|
|
944
|
+
draft: '',
|
|
945
|
+
});
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
const phase = editingQueuedPromptId ? 'idle' : controller.busy ? 'running' : 'idle';
|
|
949
|
+
if (phase === 'idle' && suggestions.length > 0) {
|
|
950
|
+
if (key.escape) {
|
|
951
|
+
setDismissedSuggestions(currentEditor.input);
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
const current = Math.min(suggestionSelectionRef.current, suggestions.length - 1);
|
|
955
|
+
const next = moveSelection(current, key, suggestions.length, suggestions.length);
|
|
956
|
+
if (next !== undefined) {
|
|
957
|
+
suggestionSelectionRef.current = next;
|
|
958
|
+
setSuggestionSelection(next);
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const selected = suggestions[current];
|
|
962
|
+
if (key.tab) {
|
|
963
|
+
setEditor(completeSuggestion(currentEditor, selected));
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
if (key.return) {
|
|
967
|
+
if (selected.replacement && currentEditor.input.trim() !== selected.replacement.trim()) {
|
|
968
|
+
setEditor(completeSuggestion(currentEditor, selected));
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
const prompt = selected.replacement ? currentEditor.input : `/${selected.name}`;
|
|
972
|
+
const result = submitEditor(currentEditor, prompt);
|
|
973
|
+
setEditor(result.state);
|
|
974
|
+
if (result.action === 'submit') {
|
|
975
|
+
dispatchPrompt(result.prompt);
|
|
976
|
+
}
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
if (key.pageUp || key.pageDown || (key.ctrl && (key.upArrow || key.downArrow || key.home || key.end))) {
|
|
981
|
+
if (key.ctrl && key.home) {
|
|
982
|
+
setTranscriptScroll(maxTranscriptScrollRef.current);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
if (key.ctrl && key.end) {
|
|
986
|
+
setTranscriptScroll(0);
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
const direction = key.pageUp || key.upArrow ? -1 : 1;
|
|
990
|
+
setTranscriptScroll((value) => scrollTranscript(value, direction, maxTranscriptScrollRef.current, key.pageUp || key.pageDown ? Math.max(3, terminalHeight - 8) : 3));
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
if (shouldToggleVoiceMute(character, key, currentEditor.input, snapshot.voice?.status)) {
|
|
994
|
+
controller.toggleVoiceMute?.();
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const result = reduceInputSequence(currentEditor, character, key, phase);
|
|
998
|
+
if (phase === 'running' && key.ctrl && character === 'g' && !currentEditor.input.trim()) {
|
|
999
|
+
controller.steerQueued();
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
setEditor(result.state);
|
|
1003
|
+
if (result.action === 'submit') {
|
|
1004
|
+
if (editingQueuedPromptId && controller.updateQueuedPrompt(editingQueuedPromptId, result.prompt)) {
|
|
1005
|
+
setEditingQueuedPromptId(undefined);
|
|
1006
|
+
}
|
|
1007
|
+
else {
|
|
1008
|
+
dispatchPrompt(result.prompt);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
else if (result.action === 'steer') {
|
|
1012
|
+
dispatchPrompt(result.prompt, true);
|
|
1013
|
+
}
|
|
1014
|
+
else if (result.action === 'cancel') {
|
|
1015
|
+
controller.cancel();
|
|
1016
|
+
}
|
|
1017
|
+
}, [
|
|
1018
|
+
activateRow,
|
|
1019
|
+
appearanceOpen,
|
|
1020
|
+
controller,
|
|
1021
|
+
dispatchPrompt,
|
|
1022
|
+
editingQueuedPromptId,
|
|
1023
|
+
frog,
|
|
1024
|
+
handleMouse,
|
|
1025
|
+
resetHover,
|
|
1026
|
+
resetPanelPosition,
|
|
1027
|
+
selectPanelRow,
|
|
1028
|
+
setEditor,
|
|
1029
|
+
toggleModelPin,
|
|
1030
|
+
]);
|
|
1031
|
+
useInput(handleInput);
|
|
1032
|
+
return (_jsx(ChatView, { ...viewProps, snapshot: previewAppearance ? { ...snapshot, settings: { ...snapshot.settings, ...previewAppearance } } : snapshot, onActionElement: registerFooterElement, ...(appearanceOpen
|
|
1033
|
+
? {
|
|
1034
|
+
overlay: (_jsx(CustomThemeEditor, { settings: snapshot.settings, animate: snapshot.settings.animations, width: terminal.width, height: terminal.height, onPreview: setPreviewAppearance, onClose: closeAppearance, onApply: async (appearance) => {
|
|
1035
|
+
const value = `customTheme=${encodeURIComponent(JSON.stringify(appearance.customTheme))}`;
|
|
1036
|
+
const applied = await controller.activatePanelRow({ label: 'Theme', description: '', value });
|
|
1037
|
+
if (!applied)
|
|
1038
|
+
throw new Error('Could not save the theme.');
|
|
1039
|
+
} })),
|
|
1040
|
+
}
|
|
1041
|
+
: {}), ...(controller.voice ? { voice: controller.voice } : {}), onMaxTranscriptScroll: updateMaxTranscriptScroll, onMetadataElement: registerMetadataElement, onPanelElement: registerPanelElement, onPanelRowElement: registerPanelRowElement, onPanelControlElement: registerPanelControlElement, onPanelFilterElement: registerPanelFilterElement, onPanelPinElement: registerPanelPinElement, onPanelSearchElement: registerPanelSearchElement, onPanelSliderElement: registerPanelSliderElement, onSuggestionElement: registerSuggestionElement, ...(pressedMetadata ? { pressedMetadata } : {}), ...(pressedPanelFilter ? { pressedPanelFilter } : {}), ...(pressedPanelRow !== undefined ? { pressedPanelRow } : {}), ...(pressedPanelControl ? { pressedPanelControl } : {}), ...(hoveredPanelControl ? { hoveredPanelControl } : {}), pressedPanelSlider: pressedPanelSlider, ...(pressedSuggestion !== undefined ? { pressedSuggestion } : {}), ...(hoveredPanelRow !== undefined ? { hoveredPanelRow } : {}), ...(hoveredPanelFilter ? { hoveredPanelFilter } : {}), hoveredPanelSlider: hoveredPanelSlider, ...(hoveredSuggestion !== undefined ? { hoveredSuggestion } : {}), ...(pressedQueuedPrompt ? { pressedQueuedPrompt } : {}), ...(editingQueuedPromptId ? { editingQueuedPromptId } : {}), ...(frog ? { frog, onFrogComplete: finishFrog } : {}), ...(frogBrandAnimationId !== undefined ? { frogBrandAnimationId } : {}), selection: screenSelection, ...(clipboardNotice ? { clipboardNotice } : {}), onQueuedPromptElement: registerQueuedPromptElement, onFrogElement: registerFrogElement, onToolGroupElement: registerToolGroupElement }));
|
|
1042
|
+
}
|
|
1043
|
+
function editsSetupAnswer(character, key, input) {
|
|
1044
|
+
if (key.return) {
|
|
1045
|
+
return input.trim().length > 0;
|
|
1046
|
+
}
|
|
1047
|
+
if (key.escape || key.tab || key.upArrow || key.downArrow || key.pageUp || key.pageDown) {
|
|
1048
|
+
return false;
|
|
1049
|
+
}
|
|
1050
|
+
return Boolean(character || key.backspace || key.delete || key.leftArrow || key.rightArrow || key.home || key.end);
|
|
1051
|
+
}
|
|
1052
|
+
function useElementMap() {
|
|
1053
|
+
const elements = useRef(new Map()).current;
|
|
1054
|
+
const register = useCallback((key, element) => {
|
|
1055
|
+
registerElement(elements, key, element);
|
|
1056
|
+
}, [elements]);
|
|
1057
|
+
return [elements, register];
|
|
1058
|
+
}
|
|
1059
|
+
function parseQueuedPromptTarget(target) {
|
|
1060
|
+
const separator = target.lastIndexOf(':');
|
|
1061
|
+
const id = target.slice(0, separator);
|
|
1062
|
+
const action = target.slice(separator + 1);
|
|
1063
|
+
if (!id || (action !== 'edit' && action !== 'up' && action !== 'down' && action !== 'steer')) {
|
|
1064
|
+
return undefined;
|
|
1065
|
+
}
|
|
1066
|
+
return { id, action };
|
|
1067
|
+
}
|
|
1068
|
+
//# sourceMappingURL=app.js.map
|