@ai-zen/cli 1.0.0-alpha.20 → 1.0.0-alpha.22
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 +158 -0
- package/README.md +43 -17
- package/README.zh.md +43 -17
- package/dist/agent-creator.d.ts.map +1 -1
- package/dist/agent-creator.js +32 -10
- package/dist/agent-creator.js.map +1 -1
- package/dist/agent-switch.d.ts +61 -0
- package/dist/agent-switch.d.ts.map +1 -0
- package/dist/agent-switch.js +83 -0
- package/dist/agent-switch.js.map +1 -0
- package/dist/agents-store.d.ts +6 -1
- package/dist/agents-store.d.ts.map +1 -1
- package/dist/agents-store.js +6 -1
- package/dist/agents-store.js.map +1 -1
- package/dist/auto-migrate-confirm.d.ts.map +1 -1
- package/dist/auto-migrate-confirm.js +2 -1
- package/dist/auto-migrate-confirm.js.map +1 -1
- package/dist/config-editor.d.ts +9 -1
- package/dist/config-editor.d.ts.map +1 -1
- package/dist/config-editor.js +30 -19
- package/dist/config-editor.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -13
- package/dist/config.js.map +1 -1
- package/dist/conversation-commands/registry.d.ts +123 -4
- package/dist/conversation-commands/registry.d.ts.map +1 -1
- package/dist/conversation-commands/registry.js +92 -17
- package/dist/conversation-commands/registry.js.map +1 -1
- package/dist/conversation-persist-plugin.d.ts.map +1 -1
- package/dist/conversation-persist-plugin.js +6 -14
- package/dist/conversation-persist-plugin.js.map +1 -1
- package/dist/conversation-repository.d.ts +68 -14
- package/dist/conversation-repository.d.ts.map +1 -1
- package/dist/conversation-repository.js +81 -23
- package/dist/conversation-repository.js.map +1 -1
- package/dist/cwd-tracker-plugin.d.ts.map +1 -1
- package/dist/cwd-tracker-plugin.js +6 -2
- package/dist/cwd-tracker-plugin.js.map +1 -1
- package/dist/format-time.d.ts +17 -6
- package/dist/format-time.d.ts.map +1 -1
- package/dist/format-time.js +32 -14
- package/dist/format-time.js.map +1 -1
- package/dist/handoff-service.d.ts.map +1 -1
- package/dist/handoff-service.js +22 -19
- package/dist/handoff-service.js.map +1 -1
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +69 -15
- package/dist/hook.js.map +1 -1
- package/dist/i18n/en-wizard.d.ts +8 -0
- package/dist/i18n/en-wizard.d.ts.map +1 -0
- package/dist/i18n/en-wizard.js +290 -0
- package/dist/i18n/en-wizard.js.map +1 -0
- package/dist/i18n/en.d.ts +7 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +224 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/index.d.ts +57 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +109 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/preferences.d.ts +34 -0
- package/dist/i18n/preferences.d.ts.map +1 -0
- package/dist/i18n/preferences.js +69 -0
- package/dist/i18n/preferences.js.map +1 -0
- package/dist/i18n/zh-wizard.d.ts +11 -0
- package/dist/i18n/zh-wizard.d.ts.map +1 -0
- package/dist/i18n/zh-wizard.js +293 -0
- package/dist/i18n/zh-wizard.js.map +1 -0
- package/dist/i18n/zh.d.ts +10 -0
- package/dist/i18n/zh.d.ts.map +1 -0
- package/dist/i18n/zh.js +228 -0
- package/dist/i18n/zh.js.map +1 -0
- package/dist/index.js +41 -23
- package/dist/index.js.map +1 -1
- package/dist/mcp-command.d.ts +32 -0
- package/dist/mcp-command.d.ts.map +1 -0
- package/dist/mcp-command.js +37 -0
- package/dist/mcp-command.js.map +1 -0
- package/dist/mode.d.ts +31 -4
- package/dist/mode.d.ts.map +1 -1
- package/dist/mode.js +42 -7
- package/dist/mode.js.map +1 -1
- package/dist/model-switch.d.ts.map +1 -1
- package/dist/model-switch.js +5 -4
- package/dist/model-switch.js.map +1 -1
- package/dist/reasoning-effort.d.ts +23 -4
- package/dist/reasoning-effort.d.ts.map +1 -1
- package/dist/reasoning-effort.js +51 -24
- package/dist/reasoning-effort.js.map +1 -1
- package/dist/sdk-log.d.ts +23 -16
- package/dist/sdk-log.d.ts.map +1 -1
- package/dist/sdk-log.js +43 -19
- package/dist/sdk-log.js.map +1 -1
- package/dist/stdio-runner.d.ts.map +1 -1
- package/dist/stdio-runner.js +19 -19
- package/dist/stdio-runner.js.map +1 -1
- package/dist/tui/chat-session.d.ts +27 -0
- package/dist/tui/chat-session.d.ts.map +1 -1
- package/dist/tui/chat-session.js +120 -28
- package/dist/tui/chat-session.js.map +1 -1
- package/dist/tui/components.d.ts +43 -2
- package/dist/tui/components.d.ts.map +1 -1
- package/dist/tui/components.js +97 -4
- package/dist/tui/components.js.map +1 -1
- package/dist/tui/config-wizard/detail.d.ts +12 -6
- package/dist/tui/config-wizard/detail.d.ts.map +1 -1
- package/dist/tui/config-wizard/detail.js +33 -32
- package/dist/tui/config-wizard/detail.js.map +1 -1
- package/dist/tui/config-wizard/engine.d.ts.map +1 -1
- package/dist/tui/config-wizard/engine.js +26 -20
- package/dist/tui/config-wizard/engine.js.map +1 -1
- package/dist/tui/config-wizard/fields.d.ts.map +1 -1
- package/dist/tui/config-wizard/fields.js +176 -164
- package/dist/tui/config-wizard/fields.js.map +1 -1
- package/dist/tui/config-wizard/kv-editor.d.ts.map +1 -1
- package/dist/tui/config-wizard/kv-editor.js +9 -5
- package/dist/tui/config-wizard/kv-editor.js.map +1 -1
- package/dist/tui/config-wizard/list.d.ts.map +1 -1
- package/dist/tui/config-wizard/list.js +2 -1
- package/dist/tui/config-wizard/list.js.map +1 -1
- package/dist/tui/config-wizard/mcp-helpers.d.ts.map +1 -1
- package/dist/tui/config-wizard/mcp-helpers.js +4 -3
- package/dist/tui/config-wizard/mcp-helpers.js.map +1 -1
- package/dist/tui/config-wizard/menu.d.ts.map +1 -1
- package/dist/tui/config-wizard/menu.js +32 -19
- package/dist/tui/config-wizard/menu.js.map +1 -1
- package/dist/tui/config-wizard/prompt-editor.d.ts.map +1 -1
- package/dist/tui/config-wizard/prompt-editor.js +4 -3
- package/dist/tui/config-wizard/prompt-editor.js.map +1 -1
- package/dist/tui/config-wizard/prompt.d.ts.map +1 -1
- package/dist/tui/config-wizard/prompt.js +8 -7
- package/dist/tui/config-wizard/prompt.js.map +1 -1
- package/dist/tui/config-wizard/step-agents.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-agents.js +29 -20
- package/dist/tui/config-wizard/step-agents.js.map +1 -1
- package/dist/tui/config-wizard/step-defaults.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-defaults.js +21 -17
- package/dist/tui/config-wizard/step-defaults.js.map +1 -1
- package/dist/tui/config-wizard/step-endpoints.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-endpoints.js +16 -6
- package/dist/tui/config-wizard/step-endpoints.js.map +1 -1
- package/dist/tui/config-wizard/step-mcp.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-mcp.js +17 -19
- package/dist/tui/config-wizard/step-mcp.js.map +1 -1
- package/dist/tui/config-wizard/step-models.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-models.js +41 -26
- package/dist/tui/config-wizard/step-models.js.map +1 -1
- package/dist/tui/config-wizard/step-new-endpoint.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-new-endpoint.js +16 -12
- package/dist/tui/config-wizard/step-new-endpoint.js.map +1 -1
- package/dist/tui/config-wizard/step-simple.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-simple.js +18 -17
- package/dist/tui/config-wizard/step-simple.js.map +1 -1
- package/dist/tui/index.d.ts +17 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +25 -14
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/input-editing.d.ts +4 -1
- package/dist/tui/input-editing.d.ts.map +1 -1
- package/dist/tui/input-editing.js +7 -3
- package/dist/tui/input-editing.js.map +1 -1
- package/dist/tui/phase.d.ts +64 -0
- package/dist/tui/phase.d.ts.map +1 -0
- package/dist/tui/phase.js +112 -0
- package/dist/tui/phase.js.map +1 -0
- package/dist/tui/screens/chat-commands.d.ts +54 -3
- package/dist/tui/screens/chat-commands.d.ts.map +1 -1
- package/dist/tui/screens/chat-commands.js +469 -330
- package/dist/tui/screens/chat-commands.js.map +1 -1
- package/dist/tui/screens/chat.d.ts +8 -0
- package/dist/tui/screens/chat.d.ts.map +1 -1
- package/dist/tui/screens/chat.js +206 -405
- package/dist/tui/screens/chat.js.map +1 -1
- package/dist/tui/screens/common-keys.d.ts +36 -0
- package/dist/tui/screens/common-keys.d.ts.map +1 -0
- package/dist/tui/screens/common-keys.js +67 -0
- package/dist/tui/screens/common-keys.js.map +1 -0
- package/dist/tui/screens/handoff-choice.d.ts.map +1 -1
- package/dist/tui/screens/handoff-choice.js +4 -3
- package/dist/tui/screens/handoff-choice.js.map +1 -1
- package/dist/tui/screens/index.d.ts +1 -1
- package/dist/tui/screens/index.d.ts.map +1 -1
- package/dist/tui/screens/index.js +1 -1
- package/dist/tui/screens/index.js.map +1 -1
- package/dist/tui/screens/input-row.d.ts +64 -0
- package/dist/tui/screens/input-row.d.ts.map +1 -0
- package/dist/tui/screens/input-row.js +67 -0
- package/dist/tui/screens/input-row.js.map +1 -0
- package/dist/tui/screens/input.d.ts +11 -1
- package/dist/tui/screens/input.d.ts.map +1 -1
- package/dist/tui/screens/input.js +21 -12
- package/dist/tui/screens/input.js.map +1 -1
- package/dist/tui/screens/layout.d.ts +8 -0
- package/dist/tui/screens/layout.d.ts.map +1 -1
- package/dist/tui/screens/layout.js +6 -2
- package/dist/tui/screens/layout.js.map +1 -1
- package/dist/tui/screens/lines.d.ts.map +1 -1
- package/dist/tui/screens/lines.js +6 -6
- package/dist/tui/screens/lines.js.map +1 -1
- package/dist/tui/screens/messages-view.d.ts.map +1 -1
- package/dist/tui/screens/messages-view.js +5 -4
- package/dist/tui/screens/messages-view.js.map +1 -1
- package/dist/tui/screens/notice-bar.d.ts +5 -0
- package/dist/tui/screens/notice-bar.d.ts.map +1 -0
- package/dist/tui/screens/notice-bar.js +15 -0
- package/dist/tui/screens/notice-bar.js.map +1 -0
- package/dist/tui/screens/notice.d.ts +40 -8
- package/dist/tui/screens/notice.d.ts.map +1 -1
- package/dist/tui/screens/notice.js +75 -15
- package/dist/tui/screens/notice.js.map +1 -1
- package/dist/tui/screens/overlays.d.ts.map +1 -1
- package/dist/tui/screens/overlays.js +3 -2
- package/dist/tui/screens/overlays.js.map +1 -1
- package/dist/tui/screens/splash.d.ts +1 -1
- package/dist/tui/screens/splash.d.ts.map +1 -1
- package/dist/tui/screens/splash.js +5 -2
- package/dist/tui/screens/splash.js.map +1 -1
- package/dist/tui/screens/use-chat-viewport.d.ts +22 -0
- package/dist/tui/screens/use-chat-viewport.d.ts.map +1 -0
- package/dist/tui/screens/use-chat-viewport.js +50 -0
- package/dist/tui/screens/use-chat-viewport.js.map +1 -0
- package/dist/tui/screens/use-input-editing.d.ts +44 -0
- package/dist/tui/screens/use-input-editing.d.ts.map +1 -0
- package/dist/tui/screens/use-input-editing.js +192 -0
- package/dist/tui/screens/use-input-editing.js.map +1 -0
- package/dist/tui/screens/use-overlays.d.ts +25 -0
- package/dist/tui/screens/use-overlays.d.ts.map +1 -0
- package/dist/tui/screens/use-overlays.js +32 -0
- package/dist/tui/screens/use-overlays.js.map +1 -0
- package/dist/tui/screens/use-wizard-host.d.ts +35 -0
- package/dist/tui/screens/use-wizard-host.d.ts.map +1 -0
- package/dist/tui/screens/use-wizard-host.js +103 -0
- package/dist/tui/screens/use-wizard-host.js.map +1 -0
- package/dist/tui/status-segments.d.ts +37 -0
- package/dist/tui/status-segments.d.ts.map +1 -0
- package/dist/tui/status-segments.js +166 -0
- package/dist/tui/status-segments.js.map +1 -0
- package/dist/tui/text.d.ts +8 -5
- package/dist/tui/text.d.ts.map +1 -1
- package/dist/tui/text.js +95 -35
- package/dist/tui/text.js.map +1 -1
- package/dist/tui/token-rate.d.ts +83 -0
- package/dist/tui/token-rate.d.ts.map +1 -0
- package/dist/tui/token-rate.js +195 -0
- package/dist/tui/token-rate.js.map +1 -0
- package/dist/types.d.ts +0 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/tui/screens/chat.js
CHANGED
|
@@ -3,28 +3,34 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { Box, Text, useApp, useCursor, useInput, useWindowSize } from "ink";
|
|
5
5
|
import { keyDebug } from "../key-debug.js";
|
|
6
|
-
import {
|
|
6
|
+
import { phaseLabel } from "../phase.js";
|
|
7
7
|
import { AgentNS } from "@ai-zen/agents-core";
|
|
8
8
|
import { theme } from "../theme.js";
|
|
9
|
-
import { Spinner, StatusBar, SlashMenu } from "../components.js";
|
|
10
|
-
import { layoutInput, usableFrameRows
|
|
9
|
+
import { Spinner, StatusBar, statusBarRows, SlashMenu } from "../components.js";
|
|
10
|
+
import { graphemes, layoutInput, usableFrameRows } from "../text.js";
|
|
11
11
|
import { ChatSession } from "../chat-session.js";
|
|
12
|
-
import { matchCommandHints } from "../../conversation-commands/registry.js";
|
|
13
|
-
import { readConfig,
|
|
12
|
+
import { commandBlocksInput, matchCommandHints, parseCommandInput, } from "../../conversation-commands/registry.js";
|
|
13
|
+
import { readConfig, readReasoningPresets, saveConfig, writeMcpConfig } from "../../config.js";
|
|
14
14
|
import { readAgentStore } from "../../agents-store.js";
|
|
15
|
-
import { resolveCredential } from "../../config-editor.js";
|
|
16
15
|
import { ConfigWizard } from "../config-wizard/index.js";
|
|
17
|
-
import { computeInputCursorPosition
|
|
18
|
-
import {
|
|
19
|
-
import { clampViewTop, computeChatLayout } from "./layout.js";
|
|
16
|
+
import { computeInputCursorPosition } from "./input.js";
|
|
17
|
+
import { computeChatLayout } from "./layout.js";
|
|
20
18
|
import { FrameBuffer } from "./frame-buffer.js";
|
|
21
19
|
import { LineView } from "./render.js";
|
|
22
20
|
import { messageToLines, transcriptLines } from "./messages-view.js";
|
|
23
21
|
import { PickerOverlay, Confirm } from "./overlays.js";
|
|
22
|
+
import { CursorInputRow } from "./input-row.js";
|
|
24
23
|
import { chooseHandoffMode } from "./handoff-choice.js";
|
|
25
24
|
import { runCommand } from "./chat-commands.js";
|
|
26
|
-
import {
|
|
25
|
+
import { describeEffortView } from "../../reasoning-effort.js";
|
|
26
|
+
import { t } from "../../i18n/index.js";
|
|
27
27
|
import { NoticeChannel, noticeLines } from "./notice.js";
|
|
28
|
+
import { NoticeBar } from "./notice-bar.js";
|
|
29
|
+
import { useChatViewport } from "./use-chat-viewport.js";
|
|
30
|
+
import { useChatOverlays } from "./use-overlays.js";
|
|
31
|
+
import { useWizardHost } from "./use-wizard-host.js";
|
|
32
|
+
import { useInputEditing } from "./use-input-editing.js";
|
|
33
|
+
import { handleCtrlDExit, handleScrollKey } from "./common-keys.js";
|
|
28
34
|
/**
|
|
29
35
|
* 计算回车时应提交的文本。
|
|
30
36
|
*
|
|
@@ -44,34 +50,17 @@ export function Chat(props) {
|
|
|
44
50
|
const { exit, suspendTerminal } = useApp();
|
|
45
51
|
const { setCursorPosition } = useCursor();
|
|
46
52
|
const { columns, rows } = useWindowSize();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const [cursor, setCursor] = useState(Array.from(props.initialInput ?? "").length);
|
|
50
|
-
const [menuIndex, setMenuIndex] = useState(0);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
setMenuIndex(0);
|
|
53
|
-
}, [input]);
|
|
54
|
-
const [confirmState, setConfirmState] = useState(null);
|
|
55
|
-
const [pickerState, setPickerState] = useState(null);
|
|
56
|
-
/** 配置向导:非 null 时整屏接管(凭据设置 / 配置中心) */
|
|
57
|
-
const [wizardStep, setWizardStep] = useState(null);
|
|
58
|
-
const [wizardConfig, setWizardConfig] = useState(null);
|
|
59
|
-
const [wizardPresets, setWizardPresets] = useState({});
|
|
60
|
-
const [wizardAgents, setWizardAgents] = useState([]);
|
|
61
|
-
const [wizardMcp, setWizardMcp] = useState(null);
|
|
62
|
-
const [wizardAgentStore, setWizardAgentStore] = useState(null);
|
|
63
|
-
const currentEndpointRef = useRef(null);
|
|
64
|
-
const [history, setHistory] = useState([]);
|
|
65
|
-
const historyIndex = useRef(-1);
|
|
53
|
+
/** 覆盖层(确认框 / 选择器):弹窗与 resolve 生命周期见 use-overlays.ts */
|
|
54
|
+
const { confirmState, pickerState, setConfirmState, setPickerState, resolveConfirm, resolvePicker } = useChatOverlays();
|
|
66
55
|
const sessionRef = useRef(null);
|
|
67
56
|
const [bootError, setBootError] = useState(null);
|
|
68
57
|
const [ready, setReady] = useState(false);
|
|
69
|
-
/**
|
|
70
|
-
const
|
|
71
|
-
/** 最近一次布局,供键盘回调读取总行数 / 视口高度(应用内翻页) */
|
|
72
|
-
const layoutRef = useRef(null);
|
|
58
|
+
/** 视口:滚动状态与翻页 / 按行 / 滚轮换算(唯一入口见 use-chat-viewport.ts) */
|
|
59
|
+
const { viewTop, layoutRef, scrollByPage, scrollByLine, scrollByWheel, scrollToBottom } = useChatViewport();
|
|
73
60
|
/** 本轮是否在生成中(spinner / 输入禁用) */
|
|
74
61
|
const [busy, setBusy] = useState(false);
|
|
62
|
+
/** 生成速率快照(token/s):生成中为实时值,结束后保留本轮平均 */
|
|
63
|
+
const [rate, setRate] = useState(null);
|
|
75
64
|
/**
|
|
76
65
|
* 当前模型 id —— **从会话(即 Agent 定义)读**,不作为 prop 传入。
|
|
77
66
|
*
|
|
@@ -85,19 +74,21 @@ export function Chat(props) {
|
|
|
85
74
|
* 真相在配置里(模型的 `defaultParams`),这里只镜像一份供状态栏用:
|
|
86
75
|
* `/think` 写入后由命令层回调刷新,切模型(会话重建)时靠 `modelId` 变化重读。
|
|
87
76
|
*/
|
|
88
|
-
const [
|
|
77
|
+
const [effortView, setEffortView] = useState(null);
|
|
78
|
+
/**
|
|
79
|
+
* 语言切换计数(`/lang`):`t()` 是模块级函数,语言变了已渲染的文案不会自更新,
|
|
80
|
+
* 递增这个计数只为逼 React 重跑一遍渲染函数。
|
|
81
|
+
*/
|
|
82
|
+
const [localeTick, bumpLocale] = useState(0);
|
|
83
|
+
/**
|
|
84
|
+
* IME 光标位置:由光标所在行**渲染后实测**而来(渲染器给的帧内坐标)。
|
|
85
|
+
* 带上 key —— 只有「产生它的那个输入状态」与当前一致时才能用,否则就是上一帧的陈旧值。
|
|
86
|
+
*/
|
|
87
|
+
const [imePosition, setImePosition] = useState(null);
|
|
89
88
|
/** 乐观回显:提交后、真实 user 消息落进 messages 之前,先显示用户提问 */
|
|
90
89
|
const [pendingUser, setPendingUser] = useState(null);
|
|
91
90
|
/** 转录显示起点(/clear 清屏用:隐藏此索引之前的消息,但不改上下文) */
|
|
92
91
|
const [transcriptFrom, setTranscriptFrom] = useState(0);
|
|
93
|
-
// ---- Claude Code 同款编辑状态 ----
|
|
94
|
-
/** kill ring:Ctrl+W/U/K 删掉的文本,Ctrl+Y 取回、Alt+Y 循环 */
|
|
95
|
-
const killRingRef = useRef([]);
|
|
96
|
-
const yankIndexRef = useRef(-1);
|
|
97
|
-
/** 编辑撤销栈(Ctrl+_) */
|
|
98
|
-
const undoStackRef = useRef([]);
|
|
99
|
-
/** 暂存区(Ctrl+S) */
|
|
100
|
-
const stashRef = useRef(null);
|
|
101
92
|
/** Ctrl+D 双击退出计时 */
|
|
102
93
|
const ctrlDAtRef = useRef(0);
|
|
103
94
|
/**
|
|
@@ -107,8 +98,28 @@ export function Chat(props) {
|
|
|
107
98
|
if (noticeChannelRef.current == null)
|
|
108
99
|
noticeChannelRef.current = new NoticeChannel();
|
|
109
100
|
const noticeChannel = noticeChannelRef.current;
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
/**
|
|
102
|
+
* 通知队列(最近的在最后)。通道内部保留最近 `MAX_NOTICE_HISTORY` 条,
|
|
103
|
+
* 这里只做镜像:单槽 state 会让「同一批摘要 / 分阶段进度」只剩最后一条。
|
|
104
|
+
*/
|
|
105
|
+
const [notices, setNotices] = useState(noticeChannel.notices);
|
|
106
|
+
useEffect(() => noticeChannel.subscribe(setNotices), [noticeChannel]);
|
|
107
|
+
/**
|
|
108
|
+
* 配置向导宿主(凭据 / 配置中心):整屏接管与「关闭后让改动生效」见
|
|
109
|
+
* use-wizard-host.ts。这里只提供出口:通知走通知通道、重启 / 重载走会话。
|
|
110
|
+
*/
|
|
111
|
+
const { wizardStep, wizardConfig, wizardPresets, wizardAgents, wizardMcp, wizardAgentStore, openWizard, openKeyEditor, closeWizard, } = useWizardHost({
|
|
112
|
+
modelId,
|
|
113
|
+
notify: (text, tone) => noticeChannel.push(text, tone),
|
|
114
|
+
hasSession: () => sessionRef.current != null,
|
|
115
|
+
restart: () => exit({ restart: true, messages: props.messages }),
|
|
116
|
+
reloadSession: () => {
|
|
117
|
+
void sessionRef.current
|
|
118
|
+
?.reload()
|
|
119
|
+
.then(() => noticeChannel.push(t("notice.reloaded")))
|
|
120
|
+
.catch((error) => noticeChannel.push(t("chat.sessionReloadFailed", { error: error?.message ?? error }), "error"));
|
|
121
|
+
},
|
|
122
|
+
});
|
|
112
123
|
/**
|
|
113
124
|
* 重挂载附带的系统提示(如 `/model` 的切换结果)。
|
|
114
125
|
*
|
|
@@ -116,6 +127,8 @@ export function Chat(props) {
|
|
|
116
127
|
* 会把「展示一条提示」误变成「重建会话」。
|
|
117
128
|
*/
|
|
118
129
|
const initialNoticeRef = useRef(props.initialNotice);
|
|
130
|
+
/** 钩子带来的首条消息:只在会话建好后发一次,重挂载不再重发 */
|
|
131
|
+
const initialPromptRef = useRef(props.initialPrompt);
|
|
119
132
|
/**
|
|
120
133
|
* 渲染信号 + 合帧:SDK 内容变更 → FrameBuffer 合帧 → setTick 触发重渲染。
|
|
121
134
|
* 转录内容始终从 `agent.messages` 现取,tick 只负责「告诉 React 该重画了」。
|
|
@@ -138,16 +151,17 @@ export function Chat(props) {
|
|
|
138
151
|
const agentId = props.agentId ?? "default";
|
|
139
152
|
const definition = store.agents.find((item) => item.id === agentId) ?? null;
|
|
140
153
|
if (alive)
|
|
141
|
-
|
|
154
|
+
setEffortView(describeEffortView(model, presets, definition));
|
|
142
155
|
})
|
|
143
156
|
.catch(() => {
|
|
144
157
|
if (alive)
|
|
145
|
-
|
|
158
|
+
setEffortView(null);
|
|
146
159
|
});
|
|
147
160
|
return () => {
|
|
148
161
|
alive = false;
|
|
149
162
|
};
|
|
150
|
-
|
|
163
|
+
// localeTick:切语言后档位文案要重算(它缓存的是已本地化的字符串,不是档位名)
|
|
164
|
+
}, [modelId, props.agentId, localeTick]);
|
|
151
165
|
// 创建会话
|
|
152
166
|
useEffect(() => {
|
|
153
167
|
let disposed = false;
|
|
@@ -168,7 +182,7 @@ export function Chat(props) {
|
|
|
168
182
|
conversationId: props.conversationId,
|
|
169
183
|
conversationName: props.conversationName,
|
|
170
184
|
// 自动迁移:与手动 /migrate、/handoff 共用同一套「交接方式三选一」选择器
|
|
171
|
-
requestMode: (info) => chooseHandoffMode(setPickerState,
|
|
185
|
+
requestMode: (info) => chooseHandoffMode(setPickerState, t("handoff.pickTitle", { used: info.promptTokens, limit: info.handoffTokens })),
|
|
172
186
|
}, notifier)
|
|
173
187
|
.then((session) => {
|
|
174
188
|
if (disposed) {
|
|
@@ -183,6 +197,14 @@ export function Chat(props) {
|
|
|
183
197
|
noticeChannel.push(initialNoticeRef.current);
|
|
184
198
|
initialNoticeRef.current = undefined;
|
|
185
199
|
}
|
|
200
|
+
// shell 钩子:会话就绪后立即把原命令当**用户消息**发出去(不经命令解析)
|
|
201
|
+
if (initialPromptRef.current) {
|
|
202
|
+
const prompt = initialPromptRef.current;
|
|
203
|
+
initialPromptRef.current = undefined;
|
|
204
|
+
setTick((t) => t + 1);
|
|
205
|
+
void runSubmit(prompt, { asMessage: true });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
186
208
|
setTick((t) => t + 1);
|
|
187
209
|
})
|
|
188
210
|
.catch((error) => setBootError(error?.message ?? String(error)));
|
|
@@ -197,231 +219,49 @@ export function Chat(props) {
|
|
|
197
219
|
props.conversationId,
|
|
198
220
|
props.conversationName,
|
|
199
221
|
]);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const resolvePicker = (value) => {
|
|
207
|
-
setPickerState((ps) => {
|
|
208
|
-
ps?.resolve(value);
|
|
209
|
-
return null;
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
// ---- 配置向导(凭据 / 配置中心)----
|
|
213
|
-
const openWizard = async (step) => {
|
|
214
|
-
try {
|
|
215
|
-
const config = await readConfig();
|
|
216
|
-
currentEndpointRef.current = resolveCredential(config, modelId)?.endpointId ?? null;
|
|
217
|
-
const agentStore = await readAgentStore();
|
|
218
|
-
setWizardConfig(config);
|
|
219
|
-
setWizardPresets(await readReasoningPresets());
|
|
220
|
-
setWizardAgents(agentStore.agents.map((agent) => ({ id: agent.id, name: agent.name || agent.id })));
|
|
221
|
-
setWizardAgentStore(agentStore);
|
|
222
|
-
setWizardMcp({ global: await readMcpConfig("global"), project: await readMcpConfig("project") });
|
|
223
|
-
setWizardStep(step);
|
|
224
|
-
}
|
|
225
|
-
catch (error) {
|
|
226
|
-
noticeChannel.push(`读取配置失败:${error?.message ?? error}`, "error");
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
/** `/key`:直达「当前模型所用端点」的 API Key 编辑步骤 */
|
|
230
|
-
const openKeyEditor = async () => {
|
|
231
|
-
try {
|
|
232
|
-
const config = await readConfig();
|
|
233
|
-
const credential = resolveCredential(config, modelId);
|
|
234
|
-
if (!credential) {
|
|
235
|
-
noticeChannel.push(`模型 ${modelId} 未绑定可用端点,请用 /config 检查配置`, "error");
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
currentEndpointRef.current = credential.endpointId;
|
|
239
|
-
setWizardConfig(config);
|
|
240
|
-
setWizardStep({ kind: "edit", field: "apiKey", endpointId: credential.endpointId });
|
|
241
|
-
}
|
|
242
|
-
catch (error) {
|
|
243
|
-
noticeChannel.push(`读取配置失败:${error?.message ?? error}`, "error");
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
/** 向导关闭:渲染变更摘要;若改到当前端点则重建会话(消息保留) */
|
|
247
|
-
const closeWizard = (result) => {
|
|
248
|
-
setWizardStep(null);
|
|
249
|
-
setWizardConfig(null);
|
|
250
|
-
setWizardMcp(null);
|
|
251
|
-
setWizardAgentStore(null);
|
|
252
|
-
for (const line of result.summary)
|
|
253
|
-
noticeChannel.push(`配置已更新:${line}`);
|
|
254
|
-
if (!result.dirty)
|
|
255
|
-
return;
|
|
256
|
-
if (!sessionRef.current) {
|
|
257
|
-
exit({ restart: true, messages: props.messages });
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
const endpointChanged = !!currentEndpointRef.current && result.changedEndpointIds.includes(currentEndpointRef.current);
|
|
261
|
-
if (endpointChanged || result.mcpChanged || result.agentsChanged) {
|
|
262
|
-
sessionRef.current
|
|
263
|
-
.reload()
|
|
264
|
-
.then(() => noticeChannel.push("已按新配置重建会话(消息与上下文保留)"))
|
|
265
|
-
.catch((error) => noticeChannel.push(`重建会话失败:${error?.message ?? error}`, "error"));
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
// ---- 滚动视口控制(应用内翻页,回看历史)----
|
|
269
|
-
const scrollTo = (nextTop) => {
|
|
270
|
-
const L = layoutRef.current;
|
|
271
|
-
if (!L)
|
|
272
|
-
return;
|
|
273
|
-
setViewTop(clampViewTop(L.totalLines, L.budget, nextTop));
|
|
274
|
-
};
|
|
275
|
-
const scrollByPage = (dir) => {
|
|
276
|
-
const L = layoutRef.current;
|
|
277
|
-
if (!L)
|
|
278
|
-
return;
|
|
279
|
-
scrollTo(L.viewTop + dir * Math.max(1, L.budget - 1));
|
|
280
|
-
};
|
|
281
|
-
const scrollByLine = (dir) => {
|
|
282
|
-
const L = layoutRef.current;
|
|
283
|
-
if (!L)
|
|
284
|
-
return;
|
|
285
|
-
scrollTo(L.viewTop + dir);
|
|
286
|
-
};
|
|
287
|
-
/** 鼠标滚轮:一格滚 `WHEEL_STEP` 行(与按行滚动共用一个钳制入口) */
|
|
288
|
-
const scrollByWheel = (dir) => {
|
|
289
|
-
const L = layoutRef.current;
|
|
290
|
-
if (!L)
|
|
222
|
+
// 速率采样:Spinner 的重渲染只影响它自己,不会带着状态栏一起刷,所以生成中要自己定时读快照。
|
|
223
|
+
// 生成结束(busy → false)时再读一次,拿本轮平均速率并留在状态栏上。
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
const read = () => setRate(sessionRef.current?.rateSample ?? null);
|
|
226
|
+
read();
|
|
227
|
+
if (!busy)
|
|
291
228
|
return;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
229
|
+
const timer = setInterval(read, 250);
|
|
230
|
+
return () => clearInterval(timer);
|
|
231
|
+
}, [busy]);
|
|
295
232
|
/** 清屏但保留上下文:把显示起点推到当前消息末尾 */
|
|
296
233
|
const clearTranscript = () => {
|
|
297
234
|
setTranscriptFrom(sessionRef.current?.messages.length ?? 0);
|
|
298
|
-
|
|
299
|
-
};
|
|
300
|
-
// ---- 输入编辑(光标感知)----
|
|
301
|
-
const setInputText = (text) => {
|
|
302
|
-
setInput(text);
|
|
303
|
-
setCursor(Array.from(text).length);
|
|
304
|
-
};
|
|
305
|
-
const insertAtCursor = (text) => {
|
|
306
|
-
const chars = Array.from(input);
|
|
307
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
308
|
-
setInput(chars.slice(0, cp).join("") + text + chars.slice(cp).join(""));
|
|
309
|
-
setCursor(cp + Array.from(text).length);
|
|
310
|
-
};
|
|
311
|
-
const deleteBeforeCursor = () => {
|
|
312
|
-
const chars = Array.from(input);
|
|
313
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
314
|
-
if (cp === 0)
|
|
315
|
-
return;
|
|
316
|
-
setInput(chars.slice(0, cp - 1).join("") + chars.slice(cp).join(""));
|
|
317
|
-
setCursor(cp - 1);
|
|
318
|
-
};
|
|
319
|
-
const deleteAfterCursor = () => {
|
|
320
|
-
const chars = Array.from(input);
|
|
321
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
322
|
-
if (cp >= chars.length)
|
|
323
|
-
return;
|
|
324
|
-
setInput(chars.slice(0, cp).join("") + chars.slice(cp + 1).join(""));
|
|
325
|
-
};
|
|
326
|
-
/** 套用纯函数算好的「文本 + 光标」结果(无变化则不触发重渲染) */
|
|
327
|
-
const applyEdit = (r) => {
|
|
328
|
-
if (r.text === input && r.cursor === cursor)
|
|
329
|
-
return;
|
|
330
|
-
undoStackRef.current = pushUndo(undoStackRef.current, { text: input, cursor });
|
|
331
|
-
setInput(r.text);
|
|
332
|
-
setCursor(r.cursor);
|
|
333
|
-
};
|
|
334
|
-
/** 删除类编辑:额外把删掉的文本放进 kill ring(Ctrl+Y 可取回) */
|
|
335
|
-
const applyKill = (r) => {
|
|
336
|
-
if (r.text === input && r.cursor === cursor)
|
|
337
|
-
return;
|
|
338
|
-
killRingRef.current = pushKill(killRingRef.current, killedText(input, r.text));
|
|
339
|
-
yankIndexRef.current = -1;
|
|
340
|
-
applyEdit(r);
|
|
341
|
-
};
|
|
342
|
-
const deleteWordBeforeCursor = () => applyKill(deleteWordLeft(input, cursor));
|
|
343
|
-
const deleteWordAfterCursor = () => applyKill(deleteWordRight(input, cursor));
|
|
344
|
-
const deleteToEndOfLine = () => applyKill(deleteToLineEnd(input, cursor));
|
|
345
|
-
const deleteToStartOfLine = () => applyKill(deleteToLineStart(input, cursor));
|
|
346
|
-
/** Ctrl+W:删到前一空白(标点不切分,整条路径一次删掉) */
|
|
347
|
-
const deletePrevWhitespace = () => applyKill(deleteToPrevWhitespace(input, cursor));
|
|
348
|
-
/** Ctrl+Y / Alt+Y:插入 kill ring 中的一段(index 循环) */
|
|
349
|
-
const yank = (advance) => {
|
|
350
|
-
const ring = killRingRef.current;
|
|
351
|
-
if (ring.length === 0)
|
|
352
|
-
return;
|
|
353
|
-
const next = advance ? yankIndexRef.current + 1 : 0;
|
|
354
|
-
if (next >= ring.length)
|
|
355
|
-
return;
|
|
356
|
-
yankIndexRef.current = next;
|
|
357
|
-
const text = killAt(ring, next) ?? "";
|
|
358
|
-
insertAtCursor(text);
|
|
359
|
-
};
|
|
360
|
-
/** Ctrl+_:撤销上一次编辑 */
|
|
361
|
-
const undoEdit = () => {
|
|
362
|
-
const popped = popUndo(undoStackRef.current);
|
|
363
|
-
if (!popped)
|
|
364
|
-
return;
|
|
365
|
-
undoStackRef.current = popped.rest;
|
|
366
|
-
setInput(popped.state.text);
|
|
367
|
-
setCursor(popped.state.cursor);
|
|
368
|
-
};
|
|
369
|
-
/** Ctrl+S:暂存 / 恢复输入 */
|
|
370
|
-
const toggleStash = () => {
|
|
371
|
-
if (input.length > 0) {
|
|
372
|
-
stashRef.current = { text: input, cursor };
|
|
373
|
-
setInputText("");
|
|
374
|
-
noticeChannel.push("已暂存输入(Ctrl+S 恢复)");
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
const stashed = stashRef.current;
|
|
378
|
-
if (!stashed)
|
|
379
|
-
return;
|
|
380
|
-
stashRef.current = null;
|
|
381
|
-
setInput(stashed.text);
|
|
382
|
-
setCursor(stashed.cursor);
|
|
383
|
-
noticeChannel.push("已恢复暂存的输入");
|
|
384
|
-
};
|
|
385
|
-
/** Ctrl+V:粘粘图片 —— 暂未支持(需先做「文件 → 内容块」能力探测,见 SKILL/后续迭代) */
|
|
386
|
-
const pasteImageUnsupported = () => {
|
|
387
|
-
noticeChannel.push("暂不支持粘贴图片(Ctrl+V 预留给图片粘贴,当前未实现)", "error");
|
|
388
|
-
};
|
|
389
|
-
const moveCursor = (delta) => {
|
|
390
|
-
const len = Array.from(input).length;
|
|
391
|
-
setCursor((c) => Math.max(0, Math.min(len, c + delta)));
|
|
392
|
-
};
|
|
393
|
-
const moveCursorToLineStart = () => {
|
|
394
|
-
const chars = Array.from(input);
|
|
395
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
396
|
-
let i = cp;
|
|
397
|
-
while (i > 0 && chars[i - 1] !== "\n")
|
|
398
|
-
i -= 1;
|
|
399
|
-
setCursor(i);
|
|
400
|
-
};
|
|
401
|
-
const moveCursorToLineEnd = () => {
|
|
402
|
-
const chars = Array.from(input);
|
|
403
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
404
|
-
let i = cp;
|
|
405
|
-
while (i < chars.length && chars[i] !== "\n")
|
|
406
|
-
i += 1;
|
|
407
|
-
setCursor(i);
|
|
235
|
+
noticeChannel.clear();
|
|
408
236
|
};
|
|
237
|
+
/**
|
|
238
|
+
* 输入编辑(文本 / 光标 / 历史 / kill ring / undo / stash):
|
|
239
|
+
* 全部语义在 use-input-editing.ts,这里只把通知出口接上。
|
|
240
|
+
*/
|
|
241
|
+
const { input, cursor, setInputText, insertAtCursor, deleteBeforeCursor, deleteAfterCursor, deleteWordBeforeCursor, deleteWordAfterCursor, deleteToStartOfLine, deleteToEndOfLine, deletePrevWhitespace, yank, undoEdit, toggleStash, moveCursor, moveCursorToLineStart, moveCursorToLineEnd, moveCursorByWord, historyPrev, historyNext, clearDraft, rememberSubmitted, } = useInputEditing({
|
|
242
|
+
initialText: props.initialInput,
|
|
243
|
+
notify: (text, tone) => noticeChannel.push(text, tone),
|
|
244
|
+
});
|
|
245
|
+
/** 斜杠候选菜单的高亮索引;输入一变就回到第一个候选 */
|
|
246
|
+
const [menuIndex, setMenuIndex] = useState(0);
|
|
247
|
+
useEffect(() => {
|
|
248
|
+
setMenuIndex(0);
|
|
249
|
+
}, [input]);
|
|
409
250
|
// 命令候选人
|
|
410
251
|
const slash = input.startsWith("/") && !input.includes("\n") && !input.includes(" ");
|
|
411
252
|
const hints = slash ? matchCommandHints(input.slice(1)) : [];
|
|
412
|
-
const runSubmit = async (text) => {
|
|
253
|
+
const runSubmit = async (text, options = {}) => {
|
|
413
254
|
const trimmed = text.trim();
|
|
414
255
|
if (!trimmed || !sessionRef.current || busy)
|
|
415
256
|
return;
|
|
416
|
-
|
|
417
|
-
historyIndex.current = -1;
|
|
257
|
+
clearDraft();
|
|
418
258
|
scrollToBottom();
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const blocksInput = name
|
|
259
|
+
noticeChannel.clear();
|
|
260
|
+
// 斜杠命令:命令名怎么解析、哪些命令会调用模型(要拦输入框),都来自命令元数据
|
|
261
|
+
const command = options.asMessage ? null : parseCommandInput(trimmed);
|
|
262
|
+
if (command) {
|
|
263
|
+
const name = command.name;
|
|
264
|
+
const blocksInput = commandBlocksInput(name);
|
|
425
265
|
if (blocksInput)
|
|
426
266
|
setBusy(true);
|
|
427
267
|
try {
|
|
@@ -438,7 +278,8 @@ export function Chat(props) {
|
|
|
438
278
|
setPickerState,
|
|
439
279
|
setConfirmState,
|
|
440
280
|
setInputText,
|
|
441
|
-
|
|
281
|
+
setEffortView,
|
|
282
|
+
refreshLocale: () => bumpLocale((n) => n + 1),
|
|
442
283
|
});
|
|
443
284
|
}
|
|
444
285
|
finally {
|
|
@@ -447,7 +288,7 @@ export function Chat(props) {
|
|
|
447
288
|
}
|
|
448
289
|
return;
|
|
449
290
|
}
|
|
450
|
-
|
|
291
|
+
rememberSubmitted(trimmed);
|
|
451
292
|
const base = sessionRef.current.messages.filter((m) => m.role === AgentNS.Role.User).length;
|
|
452
293
|
setPendingUser({ text: trimmed, base });
|
|
453
294
|
setBusy(true);
|
|
@@ -462,6 +303,16 @@ export function Chat(props) {
|
|
|
462
303
|
const doExit = () => {
|
|
463
304
|
exit("done");
|
|
464
305
|
};
|
|
306
|
+
/**
|
|
307
|
+
* 两个 `useInput`(空闲 / 忙碌)共用的键位上下文 —— 判定逻辑在 common-keys.ts。
|
|
308
|
+
* 放这里而不是各自内联,是为了让「什么时候能滚、Ctrl+D 怎么退」只有一份定义。
|
|
309
|
+
*/
|
|
310
|
+
const scrollKeys = { scrollByWheel, scrollByPage, scrollByLine };
|
|
311
|
+
const ctrlDExit = {
|
|
312
|
+
lastAt: ctrlDAtRef,
|
|
313
|
+
notify: () => noticeChannel.push(t("notice.pressCtrlDAgain")),
|
|
314
|
+
exit: doExit,
|
|
315
|
+
};
|
|
465
316
|
// 输入处理
|
|
466
317
|
useInput((char, key) => {
|
|
467
318
|
// 按键诊断(AIZ_DEBUG_KEYS=1):必须在任何 return 之前记录,否则被吞掉的键不会留痕
|
|
@@ -475,41 +326,9 @@ export function Chat(props) {
|
|
|
475
326
|
exit("done");
|
|
476
327
|
return;
|
|
477
328
|
}
|
|
478
|
-
//
|
|
479
|
-
|
|
480
|
-
// 交给 `isTerminalReply` 丢弃,绝不落下到输入框。
|
|
481
|
-
const wheel = parseWheel(char);
|
|
482
|
-
if (wheel) {
|
|
483
|
-
scrollByWheel(wheel.direction);
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
if (isTerminalReply(char))
|
|
487
|
-
return;
|
|
488
|
-
if (key.pageUp) {
|
|
489
|
-
scrollByPage(-1);
|
|
329
|
+
// 回看历史类按键(滚轮 / PgUp/PgDn / ⌘[ ⌘] / ⌘; ⌘' / Alt+V)与忙碌态共用
|
|
330
|
+
if (handleScrollKey(char, key, scrollKeys))
|
|
490
331
|
return;
|
|
491
|
-
}
|
|
492
|
-
if (key.pageDown) {
|
|
493
|
-
scrollByPage(1);
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
// 翻页的「兜底键」:部分终端把 PgUp/PgDn 留给自己滚 scrollback(应用收不到)。
|
|
497
|
-
// 注意 `Ctrl+V` 预留给图片粘贴(当前未实现),不再兼任 page-down。
|
|
498
|
-
if (char === "v" && key.meta) {
|
|
499
|
-
scrollByPage(-1);
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
// macOS 习惯键:⌘[ / ⌘] 翻页、⌘; / ⌘' 按行滚动。
|
|
503
|
-
// Cmd 只在 kitty 键盘协议下才会带 super 位(或终端把 ⌘ 组合映射成带 8 号
|
|
504
|
-
// 修饰位的转义序列,那种会落到上面的 meta 分支里,同样生效)。
|
|
505
|
-
if (key.super && (char === "[" || char === "]")) {
|
|
506
|
-
scrollByPage(char === "[" ? -1 : 1);
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
if (key.super && (char === ";" || char === "'")) {
|
|
510
|
-
scrollByLine(char === ";" ? -1 : 1);
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
332
|
if (key.return && (key.ctrl || key.meta || key.shift)) {
|
|
514
333
|
insertAtCursor("\n");
|
|
515
334
|
return;
|
|
@@ -520,27 +339,19 @@ export function Chat(props) {
|
|
|
520
339
|
sessionRef.current?.abort();
|
|
521
340
|
else if (input.length > 0) {
|
|
522
341
|
setInputText("");
|
|
523
|
-
noticeChannel.push("
|
|
342
|
+
noticeChannel.push(t("notice.inputCleared"));
|
|
524
343
|
}
|
|
525
344
|
else
|
|
526
345
|
void doExit();
|
|
527
346
|
return;
|
|
528
347
|
}
|
|
529
|
-
if (char === "d" && key.ctrl) {
|
|
530
|
-
// Claude Code
|
|
531
|
-
|
|
532
|
-
deleteAfterCursor();
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
const now = Date.now();
|
|
536
|
-
if (now - ctrlDAtRef.current < 800) {
|
|
537
|
-
void doExit();
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
ctrlDAtRef.current = now;
|
|
541
|
-
noticeChannel.push("再按一次 Ctrl+D 退出");
|
|
348
|
+
if (char === "d" && key.ctrl && input.length > 0) {
|
|
349
|
+
// Claude Code:有草稿时删光标后一个字符(空闲态独有)
|
|
350
|
+
deleteAfterCursor();
|
|
542
351
|
return;
|
|
543
352
|
}
|
|
353
|
+
if (handleCtrlDExit(char, key, ctrlDExit))
|
|
354
|
+
return;
|
|
544
355
|
if (char === "l" && key.ctrl) {
|
|
545
356
|
clearTranscript();
|
|
546
357
|
return;
|
|
@@ -578,7 +389,8 @@ export function Chat(props) {
|
|
|
578
389
|
return;
|
|
579
390
|
}
|
|
580
391
|
if ((char === "v" && key.ctrl) || (key.super && (char === "v" || char === "V"))) {
|
|
581
|
-
|
|
392
|
+
// 图片粘贴暂未支持:需要先做「文件 → 内容块」的能力探测(见后续迭代)
|
|
393
|
+
noticeChannel.push(t("notice.pasteImageUnsupported"), "error");
|
|
582
394
|
return;
|
|
583
395
|
}
|
|
584
396
|
// readline 的行首 / 行尾(macOS 上部分终端把 ⌘← / ⌘→ 发成 ^A / ^E)
|
|
@@ -601,22 +413,10 @@ export function Chat(props) {
|
|
|
601
413
|
setMenuIndex((i) => (up ? (i - 1 + hints.length) % hints.length : (i + 1) % hints.length));
|
|
602
414
|
return;
|
|
603
415
|
}
|
|
604
|
-
if (up
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
else if (!up && historyIndex.current >= 0) {
|
|
610
|
-
const idx = historyIndex.current + 1;
|
|
611
|
-
if (idx >= history.length) {
|
|
612
|
-
historyIndex.current = -1;
|
|
613
|
-
setInputText("");
|
|
614
|
-
}
|
|
615
|
-
else {
|
|
616
|
-
historyIndex.current = idx;
|
|
617
|
-
setInputText(history[idx]);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
416
|
+
if (up)
|
|
417
|
+
historyPrev();
|
|
418
|
+
else
|
|
419
|
+
historyNext();
|
|
620
420
|
return;
|
|
621
421
|
}
|
|
622
422
|
// 按词删除:Alt+Backspace / Ctrl+Backspace 删前一个词;Alt+D / Ctrl+Delete 删后一个词。
|
|
@@ -650,34 +450,22 @@ export function Chat(props) {
|
|
|
650
450
|
setMenuIndex((i) => key.upArrow ? (i - 1 + hints.length) % hints.length : (i + 1) % hints.length);
|
|
651
451
|
return;
|
|
652
452
|
}
|
|
653
|
-
if (key.upArrow
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
else if (key.downArrow && historyIndex.current >= 0) {
|
|
659
|
-
const idx = historyIndex.current + 1;
|
|
660
|
-
if (idx >= history.length) {
|
|
661
|
-
historyIndex.current = -1;
|
|
662
|
-
setInputText("");
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
historyIndex.current = idx;
|
|
666
|
-
setInputText(history[idx]);
|
|
667
|
-
}
|
|
668
|
-
}
|
|
453
|
+
if (key.upArrow)
|
|
454
|
+
historyPrev();
|
|
455
|
+
else
|
|
456
|
+
historyNext();
|
|
669
457
|
return;
|
|
670
458
|
}
|
|
671
459
|
if (key.leftArrow) {
|
|
672
460
|
if (key.ctrl || key.meta || key.super)
|
|
673
|
-
|
|
461
|
+
moveCursorByWord(-1);
|
|
674
462
|
else
|
|
675
463
|
moveCursor(-1);
|
|
676
464
|
return;
|
|
677
465
|
}
|
|
678
466
|
if (key.rightArrow) {
|
|
679
467
|
if (key.ctrl || key.meta || key.super)
|
|
680
|
-
|
|
468
|
+
moveCursorByWord(1);
|
|
681
469
|
else
|
|
682
470
|
moveCursor(1);
|
|
683
471
|
return;
|
|
@@ -686,11 +474,11 @@ export function Chat(props) {
|
|
|
686
474
|
// (readline 的 backward-word / forward-word),并不带 leftArrow 标记;
|
|
687
475
|
// 而 Ctrl+←/→ 常被系统「Mission Control → 左右切换空间」截走,应用根本收不到。
|
|
688
476
|
if (char === "b" && key.meta) {
|
|
689
|
-
|
|
477
|
+
moveCursorByWord(-1);
|
|
690
478
|
return;
|
|
691
479
|
}
|
|
692
480
|
if (char === "f" && key.meta) {
|
|
693
|
-
|
|
481
|
+
moveCursorByWord(1);
|
|
694
482
|
return;
|
|
695
483
|
}
|
|
696
484
|
if (key.home) {
|
|
@@ -731,12 +519,7 @@ export function Chat(props) {
|
|
|
731
519
|
useInput((char, key) => {
|
|
732
520
|
keyDebug(char, key);
|
|
733
521
|
// 忙碌期只剩「中止 / 退出 / 回看」,滚轮同样生效(生成时正是最想往回看的时机)
|
|
734
|
-
|
|
735
|
-
if (wheel) {
|
|
736
|
-
scrollByWheel(wheel.direction);
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
if (isTerminalReply(char))
|
|
522
|
+
if (handleScrollKey(char, key, scrollKeys))
|
|
740
523
|
return;
|
|
741
524
|
if (char === "c" && key.ctrl) {
|
|
742
525
|
sessionRef.current?.abort();
|
|
@@ -747,40 +530,16 @@ export function Chat(props) {
|
|
|
747
530
|
sessionRef.current?.abort();
|
|
748
531
|
return;
|
|
749
532
|
}
|
|
750
|
-
if (char
|
|
751
|
-
const now = Date.now();
|
|
752
|
-
if (now - ctrlDAtRef.current < 800) {
|
|
753
|
-
void doExit();
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
ctrlDAtRef.current = now;
|
|
757
|
-
noticeChannel.push("再按一次 Ctrl+D 退出");
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
if (key.pageUp) {
|
|
761
|
-
scrollByPage(-1);
|
|
533
|
+
if (handleCtrlDExit(char, key, ctrlDExit))
|
|
762
534
|
return;
|
|
763
|
-
}
|
|
764
|
-
if (key.pageDown) {
|
|
765
|
-
scrollByPage(1);
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
535
|
if ((key.upArrow || key.downArrow) && (key.shift || key.meta || key.super)) {
|
|
769
536
|
scrollByLine(key.upArrow ? -1 : 1);
|
|
770
537
|
return;
|
|
771
538
|
}
|
|
772
|
-
if (char === "v" &&
|
|
539
|
+
if (char === "v" && key.super) {
|
|
773
540
|
scrollByPage(-1);
|
|
774
541
|
return;
|
|
775
542
|
}
|
|
776
|
-
if (key.super && (char === "[" || char === "]")) {
|
|
777
|
-
scrollByPage(char === "[" ? -1 : 1);
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
if (key.super && (char === ";" || char === "'")) {
|
|
781
|
-
scrollByLine(char === ";" ? -1 : 1);
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
543
|
}, { isActive: busy && !confirmState && !pickerState && !wizardStep });
|
|
785
544
|
// 配置向导:整屏接管(凭据设置 / 配置中心),关闭后回到对话屏
|
|
786
545
|
if (wizardStep && wizardConfig) {
|
|
@@ -790,7 +549,7 @@ export function Chat(props) {
|
|
|
790
549
|
}
|
|
791
550
|
if (bootError) {
|
|
792
551
|
setCursorPosition(undefined);
|
|
793
|
-
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [
|
|
552
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Text, { color: theme.error, wrap: "truncate", children: t("chat.bootFailed", { error: bootError }) }), _jsx(Text, { color: theme.dim, wrap: "truncate", children: t("chat.bootHint") })] }));
|
|
794
553
|
}
|
|
795
554
|
const session = sessionRef.current;
|
|
796
555
|
const lastTokens = session?.lastUsage?.total_tokens;
|
|
@@ -803,7 +562,27 @@ export function Chat(props) {
|
|
|
803
562
|
if (showPending) {
|
|
804
563
|
transcript.push(...messageToLines({ id: "__pending_user", role: AgentNS.Role.User, content: pendingUser.text }, cols));
|
|
805
564
|
}
|
|
806
|
-
const noticeTextLines =
|
|
565
|
+
const noticeTextLines = noticeLines(notices, cols);
|
|
566
|
+
// 状态栏:先按当前状态算出「折行后实际几行」,交给布局预留高度(否则窄屏下一旦提示折行,
|
|
567
|
+
// 整帧就会高出一行,把输入框顶出屏幕)。这里用 `viewTop` 状态判断滚动,而不是
|
|
568
|
+
// `layout.scrolled` —— 后者要等布局算完才有,会与行数测量形成循环。
|
|
569
|
+
const statusProps = {
|
|
570
|
+
model: modelId,
|
|
571
|
+
agent: props.agentId ?? "default",
|
|
572
|
+
effort: effortView?.text ?? null,
|
|
573
|
+
effortDimmed: effortView?.dimmed ?? false,
|
|
574
|
+
lastTokens,
|
|
575
|
+
totalTokens,
|
|
576
|
+
busy,
|
|
577
|
+
hint: !ready
|
|
578
|
+
? t("input.hint.initializing")
|
|
579
|
+
: viewTop != null
|
|
580
|
+
? t("input.hint.scrolling")
|
|
581
|
+
: t("input.hint.ready"),
|
|
582
|
+
rate,
|
|
583
|
+
columns: cols,
|
|
584
|
+
};
|
|
585
|
+
const statusRows = statusBarRows(statusProps, cols);
|
|
807
586
|
const layout = computeChatLayout({
|
|
808
587
|
columns: cols,
|
|
809
588
|
rows: usableFrameRows(rows ?? 24),
|
|
@@ -815,42 +594,64 @@ export function Chat(props) {
|
|
|
815
594
|
overlay: confirmState ? "confirm" : pickerState ? "picker" : "none",
|
|
816
595
|
pickerItems: pickerState?.items.length ?? 0,
|
|
817
596
|
viewTop,
|
|
597
|
+
statusBarLines: statusRows.length,
|
|
818
598
|
});
|
|
819
599
|
layoutRef.current = layout;
|
|
820
600
|
const isPlaceholder = input.length === 0;
|
|
821
|
-
const inputLayout = layoutInput(isPlaceholder ? "
|
|
601
|
+
const inputLayout = layoutInput(isPlaceholder ? t("input.placeholder") : input, isPlaceholder ? 0 : cursor, Math.max(4, cols - 4));
|
|
822
602
|
const bodyLines = inputLayout.lines;
|
|
823
|
-
//
|
|
603
|
+
// 光标所在行的三段拆分(与 `CursorInputRow` 的渲染一一对应)
|
|
604
|
+
const cursorRowIndex = inputLayout.cursorRow;
|
|
605
|
+
const cursorRowChars = graphemes(bodyLines[cursorRowIndex] ?? "");
|
|
606
|
+
const cursorColInRow = Math.min(inputLayout.cursorCol, cursorRowChars.length);
|
|
607
|
+
const cursorBefore = cursorRowChars.slice(0, cursorColInRow).join("");
|
|
608
|
+
const cursorAt = cursorRowChars[cursorColInRow] ?? " ";
|
|
609
|
+
const cursorAfter = cursorRowChars.slice(cursorColInRow + 1).join("");
|
|
610
|
+
/** 实测结果的身份标记:输入段落一改,上一帧的实测值就作废 */
|
|
611
|
+
const cursorKey = `${cursorRowIndex}\u0000${cursorBefore}\u0000${cursorAt}\u0000${cursorAfter}`;
|
|
612
|
+
/** 渲染后实测(值不变则不会重渲染);闭包捕获当帧的 key,保证标的是「这一帧」的结果 */
|
|
613
|
+
const onCursorMeasure = (position) => {
|
|
614
|
+
setImePosition((prev) => prev && prev.position.x === position.x && prev.position.y === position.y
|
|
615
|
+
? prev
|
|
616
|
+
: { key: cursorKey, position });
|
|
617
|
+
};
|
|
618
|
+
// 把终端硬件光标移到编辑光标处,让 IME(输入法)候选框正确定位:
|
|
619
|
+
// 首选「渲染器实测」(宽字符 / emoji 的宽度由 Ink 自己算,不会偏);
|
|
620
|
+
// 首次渲染还没量到时,退回手算值顶一帧(下一帧即被实测值纠正)。
|
|
824
621
|
if (!busy && !confirmState && !pickerState) {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
622
|
+
const measured = imePosition && imePosition.key === cursorKey ? imePosition.position : null;
|
|
623
|
+
setCursorPosition(measured ??
|
|
624
|
+
computeInputCursorPosition({
|
|
625
|
+
transcriptLines: layout.lines.length,
|
|
626
|
+
// 通知栏夹在对话区与斜杠菜单之间:漏算会让硬件光标整体偏上(多行通知如 /help 最明显)
|
|
627
|
+
noticeCount: noticeTextLines.length,
|
|
628
|
+
hintCount: hints.length,
|
|
629
|
+
cursorRow: inputLayout.cursorRow,
|
|
630
|
+
cursorCol: inputLayout.cursorCol,
|
|
631
|
+
lineText: bodyLines[inputLayout.cursorRow] ?? "",
|
|
632
|
+
placeholder: isPlaceholder,
|
|
633
|
+
}));
|
|
833
634
|
}
|
|
834
635
|
else {
|
|
835
636
|
setCursorPosition(undefined);
|
|
836
637
|
}
|
|
837
|
-
return (_jsxs(Box, { flexDirection: "column", width: cols, children: [layout.lines.map((line) => (_jsx(LineView, { line: line }, line.key))), confirmState ? (_jsx(Confirm, { question: confirmState.question, onAnswer: resolveConfirm })) : pickerState ? (_jsx(PickerOverlay, { title: pickerState.title, items: pickerState.items, columns: cols, onPick: resolvePicker })) : (_jsxs(Box, { flexDirection: "column", children: [
|
|
638
|
+
return (_jsxs(Box, { flexDirection: "column", width: cols, children: [layout.lines.map((line) => (_jsx(LineView, { line: line }, line.key))), confirmState ? (_jsx(Confirm, { question: confirmState.question, onAnswer: resolveConfirm })) : pickerState ? (_jsx(PickerOverlay, { title: pickerState.title, items: pickerState.items, columns: cols, onPick: resolvePicker })) : (_jsxs(Box, { flexDirection: "column", children: [_jsx(NoticeBar, { lines: noticeTextLines }), hints.length > 0 ? _jsx(SlashMenu, { hints: hints, selected: menuIndex }) : null, _jsx(Box, { paddingX: 1, children: _jsx(Text, { color: theme.border, wrap: "truncate", children: "─".repeat(Math.max(1, cols - 2)) }) }), _jsx(Box, { flexDirection: "column", paddingX: 1, children: busy ? (
|
|
639
|
+
// 阶段随 SDK 事件推进:连接中 → 排队中 → 思考 / 输出 / 调用工具 → 等工具返回。
|
|
640
|
+
// 渲染期现取(不另存 state):chunk 与轮次边界都会触发重渲染,
|
|
641
|
+
// 而 `busy` 置 true 本身也会重渲一次,捕得到首轮的「连接中」。
|
|
642
|
+
_jsx(Spinner, { label: phaseLabel(sessionRef.current?.phase ?? null) })) : (bodyLines.map((line, i) => {
|
|
838
643
|
const prompt = i === 0 ? (_jsx(Text, { color: theme.brand[0], bold: true, children: "❯ " })) : (_jsx(Text, { children: " " }));
|
|
839
644
|
if (isPlaceholder) {
|
|
840
|
-
|
|
645
|
+
// 占位态不画「假光标」(那个行尾的 ▏):硬件光标这时就停在提示语开头
|
|
646
|
+
// (x = 前缀宽),终端自己会把它显示出来;再画一个方块等于屏幕上两个光标,
|
|
647
|
+
// 而且位置还在提示语末尾,反而误导。
|
|
648
|
+
return (_jsxs(Text, { wrap: "truncate", children: [prompt, _jsx(Text, { color: theme.faint, children: line })] }, i));
|
|
841
649
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const at = rowChars[inputLayout.cursorCol];
|
|
846
|
-
const after = rowChars.slice(inputLayout.cursorCol + 1).join("");
|
|
847
|
-
return (_jsxs(Text, { wrap: "truncate", children: [prompt, _jsx(Text, { children: before }), _jsx(Text, { inverse: true, color: theme.brand[0], children: at ?? " " }), _jsx(Text, { children: after })] }, i));
|
|
650
|
+
// 光标行:把光标字符包成独立节点,渲染后由渲染器给出真实坐标(IME 定位)
|
|
651
|
+
if (i === cursorRowIndex) {
|
|
652
|
+
return (_jsx(CursorInputRow, { firstLine: i === 0, before: cursorBefore, at: cursorAt, after: cursorAfter, onMeasure: onCursorMeasure }, i));
|
|
848
653
|
}
|
|
849
654
|
return (_jsxs(Text, { wrap: "truncate", children: [prompt, _jsx(Text, { children: line })] }, i));
|
|
850
|
-
})) })] })), _jsx(StatusBar, {
|
|
851
|
-
? "初始化中…"
|
|
852
|
-
: layout.scrolled
|
|
853
|
-
? "↕ 滚动中 · PgUp/PgDn 翻页 · 发送回到底部"
|
|
854
|
-
: "Enter 发送 · Ctrl+J 换行 · / 命令 · PgUp 看历史" })] }));
|
|
655
|
+
})) })] })), _jsx(StatusBar, { ...statusProps })] }));
|
|
855
656
|
}
|
|
856
657
|
//# sourceMappingURL=chat.js.map
|