ycodium-acp-executor 0.2.5634 → 0.2.5751
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/_private/ycodium-jsonl-stream/appendedJsonl.d.ts +47 -0
- package/dist/_private/ycodium-jsonl-stream/appendedJsonl.js +172 -0
- package/dist/_private/ycodium-jsonl-stream/claudeSessions.d.ts +63 -0
- package/dist/_private/ycodium-jsonl-stream/claudeSessions.js +220 -0
- package/dist/_private/ycodium-jsonl-stream/codexSessions.d.ts +41 -0
- package/dist/_private/ycodium-jsonl-stream/codexSessions.js +197 -0
- package/dist/_private/ycodium-jsonl-stream/history.d.ts +6 -0
- package/dist/_private/ycodium-jsonl-stream/history.js +389 -0
- package/dist/_private/ycodium-jsonl-stream/historyErrors.d.ts +6 -0
- package/dist/_private/ycodium-jsonl-stream/historyErrors.js +6 -0
- package/dist/_private/ycodium-jsonl-stream/historyFile.d.ts +19 -0
- package/dist/_private/ycodium-jsonl-stream/historyFile.js +117 -0
- package/dist/_private/ycodium-jsonl-stream/historyRecord.d.ts +31 -0
- package/dist/_private/ycodium-jsonl-stream/historyRecord.js +144 -0
- package/dist/_private/ycodium-jsonl-stream/historyWaiting.d.ts +8 -0
- package/dist/_private/ycodium-jsonl-stream/historyWaiting.js +142 -0
- package/dist/_private/ycodium-jsonl-stream/jsonObjectLine.d.ts +5 -0
- package/dist/_private/ycodium-jsonl-stream/jsonObjectLine.js +18 -0
- package/dist/_private/ycodium-jsonl-stream/jsonlStream.d.ts +79 -0
- package/dist/_private/ycodium-jsonl-stream/jsonlStream.js +603 -0
- package/dist/_private/ycodium-jsonl-stream/scanCache.d.ts +69 -0
- package/dist/_private/ycodium-jsonl-stream/scanCache.js +106 -0
- package/dist/_private/ycodium-jsonl-stream/sessionDirectory.d.ts +5 -0
- package/dist/_private/ycodium-jsonl-stream/sessionDirectory.js +32 -0
- package/dist/_private/ycodium-jsonl-stream/usageFields.d.ts +5 -0
- package/dist/_private/ycodium-jsonl-stream/usageFields.js +11 -0
- package/dist/_private/ycodium-workspace-path/directoryScope.d.ts +5 -0
- package/dist/_private/ycodium-workspace-path/directoryScope.js +28 -0
- package/dist/_private/ycodium-workspace-path/workspacePath.d.ts +19 -0
- package/dist/_private/ycodium-workspace-path/workspacePath.js +90 -0
- package/dist/adapter-support.d.ts.map +1 -1
- package/dist/adapter-support.js.map +1 -1
- package/dist/apply-effort.d.ts.map +1 -1
- package/dist/apply-effort.js.map +1 -1
- package/dist/approvals.d.ts.map +1 -1
- package/dist/approvals.js.map +1 -1
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js.map +1 -1
- package/dist/card-defaults.d.ts.map +1 -1
- package/dist/card-defaults.js.map +1 -1
- package/dist/config-option-wiring.d.ts.map +1 -1
- package/dist/config-option-wiring.js.map +1 -1
- package/dist/config-options.d.ts.map +1 -1
- package/dist/config-options.js.map +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/event-stream.d.ts.map +1 -1
- package/dist/event-stream.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/executor/child-sessions.d.ts.map +1 -1
- package/dist/executor/child-sessions.js.map +1 -1
- package/dist/executor/lifecycle.d.ts.map +1 -1
- package/dist/executor/lifecycle.js.map +1 -1
- package/dist/executor/prompt-results.d.ts.map +1 -1
- package/dist/executor/prompt-results.js.map +1 -1
- package/dist/executor/prompt.d.ts.map +1 -1
- package/dist/executor/prompt.js.map +1 -1
- package/dist/executor/requests.d.ts.map +1 -1
- package/dist/executor/requests.js.map +1 -1
- package/dist/executor/runtime.d.ts.map +1 -1
- package/dist/executor/runtime.js.map +1 -1
- package/dist/executor/session.d.ts.map +1 -1
- package/dist/executor/session.js +17 -1
- package/dist/executor/session.js.map +1 -1
- package/dist/executor/settlement.d.ts.map +1 -1
- package/dist/executor/settlement.js.map +1 -1
- package/dist/executor/subagent-sessions.d.ts.map +1 -1
- package/dist/executor/subagent-sessions.js.map +1 -1
- package/dist/executor/support.d.ts.map +1 -1
- package/dist/executor/support.js.map +1 -1
- package/dist/executor/updates.d.ts.map +1 -1
- package/dist/executor/updates.js.map +1 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js.map +1 -1
- package/dist/failureCategory.d.ts.map +1 -1
- package/dist/failureCategory.js.map +1 -1
- package/dist/handshake.d.ts.map +1 -1
- package/dist/handshake.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instance-kit.d.ts.map +1 -1
- package/dist/instance-kit.js.map +1 -1
- package/dist/jsonrpc.d.ts.map +1 -1
- package/dist/jsonrpc.js.map +1 -1
- package/dist/line-buffer.d.ts.map +1 -1
- package/dist/line-buffer.js.map +1 -1
- package/dist/mcp-servers.d.ts +26 -4
- package/dist/mcp-servers.d.ts.map +1 -1
- package/dist/mcp-servers.js +25 -4
- package/dist/mcp-servers.js.map +1 -1
- package/dist/model-selection.d.ts.map +1 -1
- package/dist/model-selection.js.map +1 -1
- package/dist/model-send.d.ts.map +1 -1
- package/dist/model-send.js.map +1 -1
- package/dist/mutex.d.ts.map +1 -1
- package/dist/mutex.js.map +1 -1
- package/dist/native-session-transcript.d.ts.map +1 -1
- package/dist/native-session-transcript.js.map +1 -1
- package/dist/native-sessions.d.ts.map +1 -1
- package/dist/native-sessions.js.map +1 -1
- package/dist/openCommands.d.ts.map +1 -1
- package/dist/openCommands.js.map +1 -1
- package/dist/permission-statement.d.ts.map +1 -1
- package/dist/permission-statement.js.map +1 -1
- package/dist/probe-process.d.ts.map +1 -1
- package/dist/probe-process.js.map +1 -1
- package/dist/probe-session.d.ts.map +1 -1
- package/dist/probe-session.js.map +1 -1
- package/dist/probe.d.ts.map +1 -1
- package/dist/probe.js.map +1 -1
- package/dist/prompt-dispatch.d.ts.map +1 -1
- package/dist/prompt-dispatch.js.map +1 -1
- package/dist/protocol-log.d.ts.map +1 -1
- package/dist/protocol-log.js.map +1 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/dist/refreshDeadline.d.ts.map +1 -1
- package/dist/refreshDeadline.js.map +1 -1
- package/dist/runtime-mode.d.ts.map +1 -1
- package/dist/runtime-mode.js.map +1 -1
- package/dist/runtime-model.d.ts.map +1 -1
- package/dist/runtime-model.js.map +1 -1
- package/dist/session-cleanup.d.ts.map +1 -1
- package/dist/session-cleanup.js.map +1 -1
- package/dist/session-registry.d.ts.map +1 -1
- package/dist/session-registry.js.map +1 -1
- package/dist/session-update.d.ts.map +1 -1
- package/dist/session-update.js.map +1 -1
- package/dist/sessionProcess.d.ts.map +1 -1
- package/dist/sessionProcess.js.map +1 -1
- package/dist/source/_private/ycodium-executor-common/catalogModel.ts +40 -0
- package/dist/source/_private/ycodium-executor-common/eventTypes.ts +97 -0
- package/dist/source/_private/ycodium-executor-common/modelSelection.ts +24 -0
- package/dist/source/_private/ycodium-executor-common/nodeStreams.ts +212 -0
- package/dist/source/_private/ycodium-executor-common/raceAbort.ts +25 -0
- package/dist/source/_private/ycodium-executor-common/reasoningLevelFallback.ts +28 -0
- package/dist/source/_private/ycodium-executor-common/stderrTail.ts +27 -0
- package/dist/source/_private/ycodium-executor-common/toolPresentation.ts +268 -0
- package/dist/source/_private/ycodium-jsonl-stream/appendedJsonl.ts +222 -0
- package/dist/source/_private/ycodium-jsonl-stream/claudeSessions.ts +263 -0
- package/dist/source/_private/ycodium-jsonl-stream/codexSessions.ts +254 -0
- package/dist/source/_private/ycodium-jsonl-stream/history.ts +492 -0
- package/dist/source/_private/ycodium-jsonl-stream/historyErrors.ts +6 -0
- package/dist/source/_private/ycodium-jsonl-stream/historyFile.ts +139 -0
- package/dist/source/_private/ycodium-jsonl-stream/historyRecord.ts +180 -0
- package/dist/source/_private/ycodium-jsonl-stream/historyWaiting.ts +140 -0
- package/dist/source/_private/ycodium-jsonl-stream/jsonObjectLine.ts +15 -0
- package/dist/source/_private/ycodium-jsonl-stream/jsonlStream.ts +650 -0
- package/dist/source/_private/ycodium-jsonl-stream/scanCache.ts +163 -0
- package/dist/source/_private/ycodium-jsonl-stream/sessionDirectory.ts +39 -0
- package/dist/source/_private/ycodium-jsonl-stream/sessionTranscript.ts +136 -0
- package/dist/source/_private/ycodium-jsonl-stream/usageFields.ts +13 -0
- package/dist/source/_private/ycodium-workspace-path/directoryScope.ts +34 -0
- package/dist/source/_private/ycodium-workspace-path/workspacePath.ts +110 -0
- package/dist/source/adapter-support.ts +115 -0
- package/dist/source/apply-effort.ts +66 -0
- package/dist/source/approvals.ts +94 -0
- package/dist/source/artifacts.ts +88 -0
- package/dist/source/card-defaults.ts +25 -0
- package/dist/source/config-option-wiring.ts +119 -0
- package/dist/source/config-options.ts +270 -0
- package/dist/source/connection.ts +553 -0
- package/dist/source/errors.ts +207 -0
- package/dist/source/event-stream.ts +91 -0
- package/dist/source/events.ts +341 -0
- package/dist/source/executor/child-sessions.ts +87 -0
- package/dist/source/executor/lifecycle.ts +282 -0
- package/dist/source/executor/prompt-results.ts +123 -0
- package/dist/source/executor/prompt.ts +606 -0
- package/dist/source/executor/requests.ts +323 -0
- package/dist/source/executor/runtime.ts +137 -0
- package/dist/source/executor/session.ts +553 -0
- package/dist/source/executor/settlement.ts +92 -0
- package/dist/source/executor/subagent-sessions.ts +183 -0
- package/dist/source/executor/support.ts +129 -0
- package/dist/source/executor/updates.ts +427 -0
- package/dist/source/executor.ts +537 -0
- package/dist/source/failureCategory.ts +74 -0
- package/dist/source/handshake.ts +66 -0
- package/dist/source/index.ts +210 -0
- package/dist/source/instance-kit.ts +478 -0
- package/dist/source/jsonrpc.ts +59 -0
- package/dist/source/line-buffer.ts +54 -0
- package/dist/source/mcp-servers.ts +83 -0
- package/dist/source/model-selection.ts +138 -0
- package/dist/source/model-send.ts +80 -0
- package/dist/source/mutex.ts +47 -0
- package/dist/source/native-session-transcript.ts +167 -0
- package/dist/source/native-sessions.ts +271 -0
- package/dist/source/openCommands.ts +39 -0
- package/dist/source/permission-statement.ts +49 -0
- package/dist/source/probe-process.ts +95 -0
- package/dist/source/probe-session.ts +81 -0
- package/dist/source/probe.ts +261 -0
- package/dist/source/prompt-dispatch.ts +42 -0
- package/dist/source/protocol-log.ts +143 -0
- package/dist/source/protocol.ts +36 -0
- package/dist/source/refreshDeadline.ts +2 -0
- package/dist/source/runtime-mode.ts +125 -0
- package/dist/source/runtime-model.ts +598 -0
- package/dist/source/session-cleanup.ts +82 -0
- package/dist/source/session-registry.ts +62 -0
- package/dist/source/session-update.ts +88 -0
- package/dist/source/sessionProcess.ts +29 -0
- package/dist/source/start-abort.ts +19 -0
- package/dist/source/thread-operations.ts +145 -0
- package/dist/source/tool-call-state.ts +322 -0
- package/dist/source/tool-presentation.ts +20 -0
- package/dist/source/tool-subagents.ts +491 -0
- package/dist/source/turn-usage.ts +78 -0
- package/dist/source/types.ts +146 -0
- package/dist/source/user-input-pending.ts +31 -0
- package/dist/source/util.ts +38 -0
- package/dist/source/vendor-hooks.ts +394 -0
- package/dist/start-abort.d.ts.map +1 -1
- package/dist/start-abort.js.map +1 -1
- package/dist/thread-operations.d.ts.map +1 -1
- package/dist/thread-operations.js.map +1 -1
- package/dist/tool-call-state.d.ts.map +1 -1
- package/dist/tool-call-state.js.map +1 -1
- package/dist/tool-presentation.d.ts.map +1 -1
- package/dist/tool-presentation.js.map +1 -1
- package/dist/tool-subagents.d.ts +1 -0
- package/dist/tool-subagents.d.ts.map +1 -1
- package/dist/tool-subagents.js +2 -0
- package/dist/tool-subagents.js.map +1 -1
- package/dist/turn-usage.d.ts.map +1 -1
- package/dist/turn-usage.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-input-pending.d.ts.map +1 -1
- package/dist/user-input-pending.js.map +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js.map +1 -1
- package/dist/vendor-hooks.d.ts +9 -0
- package/dist/vendor-hooks.d.ts.map +1 -1
- package/dist/vendor-hooks.js.map +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { AcpApprovalDecision, AcpRequestPermissionParams } from "./types.ts";
|
|
2
|
+
import type { AcpPermissionRequest } from "./runtime-model.ts";
|
|
3
|
+
|
|
4
|
+
export type PermissionOutcome =
|
|
5
|
+
| { readonly outcome: "cancelled" }
|
|
6
|
+
| { readonly outcome: "selected"; readonly optionId: string };
|
|
7
|
+
|
|
8
|
+
export type PendingApproval = {
|
|
9
|
+
readonly requestId: string;
|
|
10
|
+
readonly request: AcpRequestPermissionParams;
|
|
11
|
+
readonly permissionRequest: AcpPermissionRequest;
|
|
12
|
+
readonly turnId: string | undefined;
|
|
13
|
+
settled: boolean;
|
|
14
|
+
readonly resolve: (outcome: PermissionOutcome) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 按 requestId 分开的审批门。不是全会话一个 resolver。
|
|
19
|
+
* 答复 / 取消 / 断连三者竞争只完成一次。
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* 审批闸:每个请求一份记录,不是全会话一个 resolver。
|
|
23
|
+
*
|
|
24
|
+
* `singleResolver` 只给测试用——把闸退回「全会话一个 resolver」的错误实现,好证明
|
|
25
|
+
* 那条测试确实测得着。生产路径不传它。它是显式参数而不是环境变量,正因为环境变量
|
|
26
|
+
* 在任何地方被设都会生效,而参数只有调用点能给。
|
|
27
|
+
*/
|
|
28
|
+
export function createApprovalGate(input?: { readonly singleResolver?: boolean }) {
|
|
29
|
+
const pending = new Map<string, PendingApproval>();
|
|
30
|
+
let single: PendingApproval | undefined;
|
|
31
|
+
|
|
32
|
+
const list = (): PendingApproval[] => {
|
|
33
|
+
if (input?.singleResolver) {
|
|
34
|
+
return single ? [single] : [];
|
|
35
|
+
}
|
|
36
|
+
return [...pending.values()];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const get = (requestId: string): PendingApproval | undefined => {
|
|
40
|
+
if (input?.singleResolver) {
|
|
41
|
+
return single;
|
|
42
|
+
}
|
|
43
|
+
return pending.get(requestId);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const add = (entry: PendingApproval): void => {
|
|
47
|
+
if (input?.singleResolver) {
|
|
48
|
+
single = entry;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
pending.set(entry.requestId, entry);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const settle = (entry: PendingApproval, outcome: PermissionOutcome): boolean => {
|
|
55
|
+
if (entry.settled) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
entry.settled = true;
|
|
59
|
+
pending.delete(entry.requestId);
|
|
60
|
+
if (single?.requestId === entry.requestId) {
|
|
61
|
+
single = undefined;
|
|
62
|
+
}
|
|
63
|
+
entry.resolve(outcome);
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const settleAll = (outcome: PermissionOutcome): ReadonlyArray<PendingApproval> => {
|
|
68
|
+
const entries = list();
|
|
69
|
+
const settled: PendingApproval[] = [];
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
if (settle(entry, outcome)) {
|
|
72
|
+
settled.push(entry);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return settled;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
add,
|
|
80
|
+
get,
|
|
81
|
+
list,
|
|
82
|
+
settle,
|
|
83
|
+
settleAll,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function approvalOutcomeForDecision(
|
|
88
|
+
decision: AcpApprovalDecision,
|
|
89
|
+
optionId: string | undefined,
|
|
90
|
+
): PermissionOutcome {
|
|
91
|
+
return decision !== "cancel" && optionId !== undefined
|
|
92
|
+
? { outcome: "selected", optionId }
|
|
93
|
+
: { outcome: "cancelled" };
|
|
94
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @effect-diagnostics nodeBuiltinImport:off
|
|
2
|
+
/**
|
|
3
|
+
* agent 产出的文件(0059):ACP 的 `resource_link` 内容块与厂商钩子从工具结果里认出的产物,
|
|
4
|
+
* 一律报成 `assistant.artifact.produced`,读、查、落盘交给宿主。
|
|
5
|
+
*/
|
|
6
|
+
import * as NodePath from "node:path";
|
|
7
|
+
import * as NodeURL from "node:url";
|
|
8
|
+
|
|
9
|
+
import type { ExecutorEvent, ExecutorEventBase } from "./types.ts";
|
|
10
|
+
|
|
11
|
+
/** 一个产物。`linkBase` 是回复里相对链接的基准目录,由厂商从结构化结果得出,不靠猜。 */
|
|
12
|
+
export type AcpArtifact = {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly name?: string;
|
|
15
|
+
readonly mimeType?: string;
|
|
16
|
+
readonly linkBase?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 标准 ACP 的 `resource_link` 块指向本机文件时的产物。`file:` 协议的 URI 按 URL 解码;裸的绝对路径原样用
|
|
21
|
+
* ——目录名里的 `%2F`、`%3A%5C` 是字面名字,不能解码。http 之类的远端链接不取。
|
|
22
|
+
*/
|
|
23
|
+
export function resourceLinkArtifacts(content: Record<string, unknown>): AcpArtifact[] {
|
|
24
|
+
if (content["type"] !== "resource_link" || typeof content["uri"] !== "string") return [];
|
|
25
|
+
const uri = content["uri"].trim();
|
|
26
|
+
let path: string;
|
|
27
|
+
try {
|
|
28
|
+
path = uri.toLowerCase().startsWith("file:") ? NodeURL.fileURLToPath(uri) : uri;
|
|
29
|
+
} catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
// 执行器所在机器的本地路径:按本机规则判(Windows 上含 UNC)。
|
|
33
|
+
if (!NodePath.isAbsolute(path)) return [];
|
|
34
|
+
const name = typeof content["name"] === "string" ? content["name"].trim() : "";
|
|
35
|
+
const mimeType = typeof content["mimeType"] === "string" ? content["mimeType"].trim() : "";
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
path,
|
|
39
|
+
...(name.length > 0 ? { name } : {}),
|
|
40
|
+
...(mimeType.length > 0 ? { mimeType } : {}),
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 一组产物换成一条事件;空的不发。 */
|
|
46
|
+
function acpArtifactEvent(input: {
|
|
47
|
+
readonly artifacts: ReadonlyArray<AcpArtifact>;
|
|
48
|
+
readonly toolCallId?: string | undefined;
|
|
49
|
+
readonly base: ExecutorEventBase;
|
|
50
|
+
}): ExecutorEvent | undefined {
|
|
51
|
+
if (input.artifacts.length === 0) return undefined;
|
|
52
|
+
const { toolCallId } = input;
|
|
53
|
+
return {
|
|
54
|
+
...input.base,
|
|
55
|
+
type: "assistant.artifact.produced",
|
|
56
|
+
payload: {
|
|
57
|
+
artifacts: input.artifacts.map((artifact) => ({
|
|
58
|
+
...artifact,
|
|
59
|
+
...(toolCallId !== undefined ? { toolCallId } : {}),
|
|
60
|
+
})),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 执行器发产物用的小闭包:读、查、落盘在宿主,这里只报路径;事件归发出时的那一轮。
|
|
67
|
+
*/
|
|
68
|
+
export function makeArtifactEmitter(input: {
|
|
69
|
+
readonly emit: (event: ExecutorEvent) => void;
|
|
70
|
+
readonly stamp: () => { readonly eventId: string; readonly createdAt: string };
|
|
71
|
+
readonly options: { readonly provider: string; readonly threadId: string };
|
|
72
|
+
readonly turnId: () => string | undefined;
|
|
73
|
+
}) {
|
|
74
|
+
return (artifacts: ReadonlyArray<AcpArtifact>, toolCallId?: string): void => {
|
|
75
|
+
const turnId = input.turnId();
|
|
76
|
+
const event = acpArtifactEvent({
|
|
77
|
+
artifacts,
|
|
78
|
+
toolCallId,
|
|
79
|
+
base: {
|
|
80
|
+
...input.stamp(),
|
|
81
|
+
provider: input.options.provider,
|
|
82
|
+
threadId: input.options.threadId,
|
|
83
|
+
...(turnId === undefined ? {} : { turnId }),
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
if (event !== undefined) input.emit(event);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插件自管 ACP 手的名片空字段:安装、登录、文档、默认型号都由探测或设置表单填,名片上先留空。
|
|
3
|
+
* acp 与 antigravity 共用这一份,各家只覆盖真正不同的格子。
|
|
4
|
+
*/
|
|
5
|
+
export const PLUGIN_MANAGED_ACP_CARD_DEFAULTS = {
|
|
6
|
+
commandName: "",
|
|
7
|
+
launchArgs: "",
|
|
8
|
+
homeEnvVar: "",
|
|
9
|
+
environment: [] as ReadonlyArray<{ readonly name: string; readonly sensitive: boolean }>,
|
|
10
|
+
install: null,
|
|
11
|
+
signIn: [] as const,
|
|
12
|
+
deviceCodeSignInArgs: [] as const,
|
|
13
|
+
npmPackage: "",
|
|
14
|
+
homebrewFormula: "",
|
|
15
|
+
selfUpdateArgs: [] as const,
|
|
16
|
+
docsUrl: "",
|
|
17
|
+
setupNote: "",
|
|
18
|
+
defaultModel: "",
|
|
19
|
+
customModelIdExample: "",
|
|
20
|
+
modelSlugAliases: null,
|
|
21
|
+
mcpTransports: ["stdio", "http", "sse"] as const,
|
|
22
|
+
pluginManaged: true,
|
|
23
|
+
verifiedSkills: false,
|
|
24
|
+
everydayHarness: false,
|
|
25
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP 会话报回来的 `configOptions`,这只手对每一类的处置登记。
|
|
3
|
+
*
|
|
4
|
+
* **这张表为什么是三态,不是编译期穷尽**:`category` 是**开放联合**——协议原文
|
|
5
|
+
* "Clients MUST handle missing or unknown categories gracefully",且 `_` 开头留给厂商
|
|
6
|
+
* 自定义。开放集做不了穷尽检查,所以:
|
|
7
|
+
*
|
|
8
|
+
* - `consumed: true` —— 已经接到生效点,`via` 写明接在哪。
|
|
9
|
+
* - `consumed: false` —— **知道有、还没接**,`note` 写明为什么。
|
|
10
|
+
* - 表外 —— 上游或厂商报了从没见过的一类,`unhandledConfigCategories` 挑出来记一条诊断。
|
|
11
|
+
*
|
|
12
|
+
* 第三态是这张表存在的理由。在此之前只挑 `model` 一项,其余整个丢掉、零痕迹:
|
|
13
|
+
* 2026-09-19 实测 `@agentclientprotocol/claude-agent-acp@0.79.0` 同时报了
|
|
14
|
+
* `mode` / `model` / `thought_level` 三项,接了两项,力度档那一整格因此在界面上缺席,
|
|
15
|
+
* 而没有任何日志说过这件事——只有手工连一次协议才看得见。
|
|
16
|
+
*
|
|
17
|
+
* **2026-09-20 从 `apps/server/src/provider/acp/configOptionWiring.ts` 搬来,三行处置
|
|
18
|
+
* 跟着变了**:宿主那份记的是宿主消费点,而宿主的 ACP 路本来就是留给 cursor 的,
|
|
19
|
+
* cursor 废弃删除之后整片成了孤儿。搬过来必须按**这只手**的实情重填——
|
|
20
|
+
* `thought_level` / `model_option` 在这里是接了的(`findAcpEffortConfig` 两处都认),
|
|
21
|
+
* `model_config` 原来只有 CursorProvider 消费,现在没有消费点。
|
|
22
|
+
*
|
|
23
|
+
* @module @ycodium/acp-executor/config-option-wiring
|
|
24
|
+
*/
|
|
25
|
+
import type { AcpSessionConfigOption } from "./runtime-model.ts";
|
|
26
|
+
|
|
27
|
+
/** 协议给厂商自定义留的前缀。这类不算「上游新增」,诊断里分开说。 */
|
|
28
|
+
const VENDOR_CATEGORY_PREFIX = "_";
|
|
29
|
+
|
|
30
|
+
type CategoryHandling =
|
|
31
|
+
| {
|
|
32
|
+
readonly consumed: true;
|
|
33
|
+
/** 接在哪。改接法先改这里。 */
|
|
34
|
+
readonly via: string;
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
readonly consumed: false;
|
|
38
|
+
/** 为什么还没接。留空等于没登记。 */
|
|
39
|
+
readonly note: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 今天见过的几类。
|
|
44
|
+
*
|
|
45
|
+
* 加一类到这里不会自动接上任何东西——`consumed: true` 必须同时有真的接线,
|
|
46
|
+
* 配套测试钉着这一点。
|
|
47
|
+
*/
|
|
48
|
+
export const ACP_CONFIG_CATEGORY_HANDLING = {
|
|
49
|
+
mode: {
|
|
50
|
+
consumed: true,
|
|
51
|
+
via: "runtime-mode.ts:acpAvailableModes / acpCurrentModeId / acpModeConfigId",
|
|
52
|
+
},
|
|
53
|
+
model: {
|
|
54
|
+
consumed: true,
|
|
55
|
+
via: "runtime-model.ts:extractModelConfigId → executor.ts:applyRequestedModel",
|
|
56
|
+
},
|
|
57
|
+
thought_level: {
|
|
58
|
+
consumed: true,
|
|
59
|
+
via: "config-options.ts:findAcpEffortConfig → apply-effort.ts:alignRequestedEffort",
|
|
60
|
+
},
|
|
61
|
+
model_option: {
|
|
62
|
+
consumed: true,
|
|
63
|
+
// 精确说法:它不是**识别器**,是**优先级**。`looksLikeEffortOption` 先筛出候选,
|
|
64
|
+
// 标了 `model_option` 的在候选里排第一(厂商自己标的最准),排在 id 叫 `effort`
|
|
65
|
+
// 的和标 `thought_level` 的前面。光有这个 category 而 id/name 不像力度档的,
|
|
66
|
+
// 压根进不了候选。
|
|
67
|
+
via: "config-options.ts:findAcpEffortConfig(候选里的最高优先级,压过 thought_level)",
|
|
68
|
+
},
|
|
69
|
+
model_config: {
|
|
70
|
+
consumed: false,
|
|
71
|
+
note: "只有宿主的 CursorProvider 消费过(context / fast / thinking 三个开关)。Cursor 2026-09-20 废弃删除,这一类现在没有消费点;没见过别家的真实载荷,先记账不猜形状。",
|
|
72
|
+
},
|
|
73
|
+
} as const satisfies Record<string, CategoryHandling>;
|
|
74
|
+
|
|
75
|
+
/** 登记在表里的 category 名单。 */
|
|
76
|
+
const KNOWN_CATEGORIES: ReadonlySet<string> = new Set(Object.keys(ACP_CONFIG_CATEGORY_HANDLING));
|
|
77
|
+
|
|
78
|
+
/** 一条表外 category 的诊断材料。 */
|
|
79
|
+
export type UnhandledConfigCategory = {
|
|
80
|
+
readonly category: string;
|
|
81
|
+
/** 报出它的那个选项 id,方便直接去 CLI 那边对。 */
|
|
82
|
+
readonly optionId: string;
|
|
83
|
+
/** `_` 开头是厂商扩展,不是 ACP spec 新增。两者处置不同,所以分开标。 */
|
|
84
|
+
readonly vendorExtension: boolean;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 挑出这次会话里从没登记过的 category。
|
|
89
|
+
*
|
|
90
|
+
* 缺席 `category` 的选项不算漏接——协议明说它是 UX 提示、可以没有,按 id 用的那些
|
|
91
|
+
* (`findSessionConfigOption`)不依赖它。
|
|
92
|
+
*/
|
|
93
|
+
export function unhandledConfigCategories(
|
|
94
|
+
configOptions: ReadonlyArray<AcpSessionConfigOption> | null | undefined,
|
|
95
|
+
): ReadonlyArray<UnhandledConfigCategory> {
|
|
96
|
+
if (!configOptions) return [];
|
|
97
|
+
const seen = new Set<string>();
|
|
98
|
+
const out: UnhandledConfigCategory[] = [];
|
|
99
|
+
for (const option of configOptions) {
|
|
100
|
+
const category = option.category?.trim();
|
|
101
|
+
if (!category) continue;
|
|
102
|
+
if (KNOWN_CATEGORIES.has(category)) continue;
|
|
103
|
+
if (seen.has(category)) continue;
|
|
104
|
+
seen.add(category);
|
|
105
|
+
out.push({
|
|
106
|
+
category,
|
|
107
|
+
optionId: option.id.trim(),
|
|
108
|
+
vendorExtension: category.startsWith(VENDOR_CATEGORY_PREFIX),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 表里登记了、但还没接到生效点的 category。界面缺一格的已知来源。 */
|
|
115
|
+
export function declaredButUnconsumedCategories(): ReadonlyArray<string> {
|
|
116
|
+
return Object.entries(ACP_CONFIG_CATEGORY_HANDLING)
|
|
117
|
+
.filter(([, handling]) => !handling.consumed)
|
|
118
|
+
.map(([category]) => category);
|
|
119
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从 ACP 会话回包的 `configOptions` 里认出思考档位(力度档)。
|
|
3
|
+
*
|
|
4
|
+
* **为什么住在这个包**:认法与翻法此前有两份,互不知道——`CursorProvider` 能把
|
|
5
|
+
* configOptions 里的力度档翻成界面画得出的 optionDescriptor;`agent-dsh` 的探测建了
|
|
6
|
+
* 会话、却只从同一份回包里取模型清单。结果同一种数据在 Cursor 上有力度档,在别的
|
|
7
|
+
* ACP 手上整格缺席。插件 import 不到宿主,所以通用那半只能落在这个两边都够得着的包里。
|
|
8
|
+
*
|
|
9
|
+
* **不归一化档位值**:Cursor 那份把 `extra-high` 折成 `xhigh`、认不出的一律丢掉,那是
|
|
10
|
+
* 它对齐自身固定集合的需要,留在 `CursorProvider`。通用这份照 agent 报什么算什么——
|
|
11
|
+
* 宿主 `ProviderOptionDescriptor` 的 option id 是自由字符串,归一化只会把 agent 真能收
|
|
12
|
+
* 的档位吃掉(`claude-agent-acp` 报的 `default` 就会中招),而写回时原样发回去才自洽。
|
|
13
|
+
*
|
|
14
|
+
* 入参收 `unknown`:插件侧拿到的是 raw JSON,宿主侧拿到的是 schema 类型,两边结构相同,
|
|
15
|
+
* 在这里各自不用先转一道。
|
|
16
|
+
*
|
|
17
|
+
* @module config-options
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** 力度档里的一个可选值。 */
|
|
21
|
+
export type AcpConfigChoice = {
|
|
22
|
+
readonly value: string;
|
|
23
|
+
/**
|
|
24
|
+
* agent 给的名字,**缺席就是缺席**——模型清单那边名字没报时不设 `name`,不拿 slug
|
|
25
|
+
* 冒充(宿主拿它当「CLI 说得出的名字」)。要给人看的那一行用 {@link label}。
|
|
26
|
+
*/
|
|
27
|
+
readonly name?: string;
|
|
28
|
+
/** 给人看的一行:`name` 有就是它,没有退回 `value`。力度档那一格用这个。 */
|
|
29
|
+
readonly label: string;
|
|
30
|
+
/** agent 给这一档写的说明,有就带上(dsh 每档都有)。 */
|
|
31
|
+
readonly description?: string;
|
|
32
|
+
/** agent 报的 `currentValue` 命中这一档。 */
|
|
33
|
+
readonly isDefault?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** 认出来的力度档。 */
|
|
37
|
+
export type AcpEffortConfig = {
|
|
38
|
+
/**
|
|
39
|
+
* 报出它的那个 configOption id。写回走 `session/set_config_option` 时用的是它,
|
|
40
|
+
* 不是我们自己起的名字——各家 id 不同(`effort` / `reasoning` / 厂商自定义)。
|
|
41
|
+
*/
|
|
42
|
+
readonly configId: string;
|
|
43
|
+
/** agent 自己给的标题,当界面那一格的 label;空就由调用方兜底。 */
|
|
44
|
+
readonly label: string;
|
|
45
|
+
readonly choices: ReadonlyArray<AcpConfigChoice>;
|
|
46
|
+
/** agent 报的当前档;可能不在 `choices` 里(grok 切型号后把旧档原样带着)。 */
|
|
47
|
+
readonly currentValue?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
51
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function asString(value: unknown): string | undefined {
|
|
55
|
+
return typeof value === "string" ? value : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function normalizedField(option: Record<string, unknown>, key: string): string {
|
|
59
|
+
return asString(option[key])?.trim().toLowerCase() ?? "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 长得像力度档吗。
|
|
64
|
+
*
|
|
65
|
+
* id 与 name 都看:`category` 是协议明说的 UX 提示、可以缺席,只靠它会漏掉没标 category
|
|
66
|
+
* 的那几家;只靠 id 又会漏掉把它叫 `thinking_level` 的。
|
|
67
|
+
*/
|
|
68
|
+
function looksLikeEffortOption(option: Record<string, unknown>): boolean {
|
|
69
|
+
const id = normalizedField(option, "id");
|
|
70
|
+
const name = normalizedField(option, "name");
|
|
71
|
+
return (
|
|
72
|
+
id === "effort" ||
|
|
73
|
+
id === "reasoning" ||
|
|
74
|
+
name === "effort" ||
|
|
75
|
+
name === "reasoning" ||
|
|
76
|
+
name.includes("effort") ||
|
|
77
|
+
name.includes("reasoning") ||
|
|
78
|
+
normalizedField(option, "category") === "thought_level"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 展平选项。两种长相都认:平的 `{value,name}` 与按组分的 `{group,name,options:[…]}`
|
|
84
|
+
* (dsh 今天发分组那种)。
|
|
85
|
+
*/
|
|
86
|
+
function flattenChoices(rawOptions: unknown, currentValue: string | undefined): AcpConfigChoice[] {
|
|
87
|
+
if (!Array.isArray(rawOptions)) return [];
|
|
88
|
+
const out: AcpConfigChoice[] = [];
|
|
89
|
+
const seen = new Set<string>();
|
|
90
|
+
const push = (entry: unknown): void => {
|
|
91
|
+
if (!isRecord(entry)) return;
|
|
92
|
+
const value = asString(entry["value"]);
|
|
93
|
+
if (value === undefined || seen.has(value)) return;
|
|
94
|
+
seen.add(value);
|
|
95
|
+
const description = asString(entry["description"])?.trim();
|
|
96
|
+
const name = asString(entry["name"])?.trim();
|
|
97
|
+
out.push({
|
|
98
|
+
value,
|
|
99
|
+
...(name ? { name } : {}),
|
|
100
|
+
label: name || value,
|
|
101
|
+
...(description ? { description } : {}),
|
|
102
|
+
...(currentValue !== undefined && currentValue === value ? { isDefault: true } : {}),
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
for (const entry of rawOptions) {
|
|
106
|
+
if (isRecord(entry) && Array.isArray(entry["options"])) {
|
|
107
|
+
for (const nested of entry["options"]) push(nested);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
push(entry);
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 这一项是不是 `configId`:id 前后的空白不算(各处认配置项都用这一条)。 */
|
|
116
|
+
function isConfigOption(entry: unknown, configId: string): entry is Record<string, unknown> {
|
|
117
|
+
return isRecord(entry) && asString(entry["id"])?.trim() === configId.trim();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** `configId` 那一项;不认得的条目跳过,空 id 不认(各处找配置项都走这一条)。 */
|
|
121
|
+
export function findConfigOptionEntry(
|
|
122
|
+
configOptions: unknown,
|
|
123
|
+
configId: string,
|
|
124
|
+
): Record<string, unknown> | undefined {
|
|
125
|
+
return Array.isArray(configOptions) && configId.trim() !== ""
|
|
126
|
+
? configOptions.find((entry): entry is Record<string, unknown> =>
|
|
127
|
+
isConfigOption(entry, configId),
|
|
128
|
+
)
|
|
129
|
+
: undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 在原表上把 `configId` 那一项的当前值改成 `value`(回包没带整份表时用)。 */
|
|
133
|
+
export function withConfigOptionValue(
|
|
134
|
+
configOptions: unknown,
|
|
135
|
+
configId: string,
|
|
136
|
+
value: string,
|
|
137
|
+
): unknown {
|
|
138
|
+
if (!Array.isArray(configOptions)) return configOptions;
|
|
139
|
+
return configOptions.map((option: unknown) =>
|
|
140
|
+
isConfigOption(option, configId) ? { ...option, currentValue: value } : option,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 挑出力度档那一项。
|
|
146
|
+
*
|
|
147
|
+
* 优先级照 `CursorProvider` 既有那套:厂商自己标的 `model_option` 最准,其次是 id 就叫
|
|
148
|
+
* `effort` 的,再次是标了 `thought_level` 的,最后退回第一个长得像的。多家同时命中时
|
|
149
|
+
* 这个顺序决定谁赢,改它会改掉 Cursor 今天的行为。
|
|
150
|
+
*/
|
|
151
|
+
/** 认出力度档那一项(几种报法按优先级挑一个);没有就是 undefined。 */
|
|
152
|
+
function pickEffortOption(configOptions: unknown): Record<string, unknown> | undefined {
|
|
153
|
+
if (!Array.isArray(configOptions)) return undefined;
|
|
154
|
+
const candidates = configOptions
|
|
155
|
+
.filter(isRecord)
|
|
156
|
+
.filter((option) => normalizedField(option, "type") === "select")
|
|
157
|
+
.filter(looksLikeEffortOption);
|
|
158
|
+
return (
|
|
159
|
+
candidates.find((option) => normalizedField(option, "category") === "model_option") ??
|
|
160
|
+
candidates.find((option) => normalizedField(option, "id") === "effort") ??
|
|
161
|
+
candidates.find((option) => normalizedField(option, "category") === "thought_level") ??
|
|
162
|
+
candidates[0]
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function findAcpEffortConfig(configOptions: unknown): AcpEffortConfig | undefined {
|
|
167
|
+
const picked = pickEffortOption(configOptions);
|
|
168
|
+
if (picked === undefined) return undefined;
|
|
169
|
+
|
|
170
|
+
const configId = asString(picked["id"])?.trim();
|
|
171
|
+
if (!configId) return undefined;
|
|
172
|
+
|
|
173
|
+
const currentValue = asString(picked["currentValue"])?.trim() || undefined;
|
|
174
|
+
const choices = flattenChoices(picked["options"], currentValue);
|
|
175
|
+
if (choices.length === 0) return undefined;
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
configId,
|
|
179
|
+
label: asString(picked["name"])?.trim() ?? "",
|
|
180
|
+
choices,
|
|
181
|
+
...(currentValue === undefined ? {} : { currentValue }),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 每一个选项(平的,或分组里的)都是带非空 `value` 的对象;有一条读不懂就不算完整。 */
|
|
186
|
+
function choicesComplete(rawOptions: readonly unknown[]): boolean {
|
|
187
|
+
const leafOk = (entry: unknown): boolean =>
|
|
188
|
+
isRecord(entry) && (asString(entry["value"])?.trim() ?? "") !== "";
|
|
189
|
+
return rawOptions.every((entry) =>
|
|
190
|
+
isRecord(entry) && Array.isArray(entry["options"])
|
|
191
|
+
? entry["options"].every(leafOk)
|
|
192
|
+
: leafOk(entry),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 探测时力度档答过没有:没报这一项、id 不对、选项表不是数组、有读不懂的选项 → `unknown`(不报
|
|
198
|
+
* capabilities,宿主沿用上次);认出这一项且选项表明确为空 → `none`(报空描述符);其余 → `listed`。
|
|
199
|
+
* 会话中途的读法照旧宽松(`findAcpEffortConfig`);只有探测要用它区分「没有」与「说不出」。
|
|
200
|
+
*/
|
|
201
|
+
export function acpEffortConfigState(configOptions: unknown): "unknown" | "none" | "listed" {
|
|
202
|
+
const picked = pickEffortOption(configOptions);
|
|
203
|
+
if (picked === undefined || !asString(picked["id"])?.trim()) return "unknown";
|
|
204
|
+
const options = picked["options"];
|
|
205
|
+
if (!Array.isArray(options)) return "unknown";
|
|
206
|
+
if (options.length === 0) return "none";
|
|
207
|
+
return choicesComplete(options) ? "listed" : "unknown";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 从同一份 `configOptions` 里认出模型清单那一项,展平成可选值。
|
|
212
|
+
*
|
|
213
|
+
* 认法与力度档那边共用一套展平(平的 `{value,name}` 与按组分的
|
|
214
|
+
* `{group,name,options:[…]}` 都认,`currentValue` 标成默认)。此前这段只活在
|
|
215
|
+
* `agent-dsh` 的 `dshProbeModels` 里——`agent-acp` 要报清单时照抄一份就是第二个答案,
|
|
216
|
+
* 所以搬来这里,两条路读同一份。
|
|
217
|
+
*
|
|
218
|
+
* 返回 `undefined` 与空数组不是一回事:前者是「这份回包里认不出模型那一项」,后者是
|
|
219
|
+
* 「认出来了但一个选项都没有」。调用方据此决定报不报 `models`。
|
|
220
|
+
*/
|
|
221
|
+
export function acpModelChoicesFromConfigOptions(
|
|
222
|
+
configOptions: unknown,
|
|
223
|
+
): ReadonlyArray<AcpConfigChoice> | undefined {
|
|
224
|
+
if (!Array.isArray(configOptions)) return undefined;
|
|
225
|
+
const records = configOptions.filter(isRecord);
|
|
226
|
+
// 与 extractModelConfigId 同一条规则:先认 category,没有再认 id 为 `model` 的下拉项。
|
|
227
|
+
const modelOption =
|
|
228
|
+
records.find((option) => normalizedField(option, "category") === "model") ??
|
|
229
|
+
records.find(
|
|
230
|
+
(option) =>
|
|
231
|
+
normalizedField(option, "id") === "model" && normalizedField(option, "type") === "select",
|
|
232
|
+
);
|
|
233
|
+
if (modelOption === undefined) return undefined;
|
|
234
|
+
if (!asString(modelOption["id"])?.trim()) return undefined;
|
|
235
|
+
return flattenChoices(modelOption["options"], asString(modelOption["currentValue"])?.trim());
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 另一种报法:`session/new` 回包的 `models.availableModels`(ACP 的 UNSTABLE 那一位)。
|
|
240
|
+
*
|
|
241
|
+
* 两种报法都是标准的,各家挑一种——`claude-agent-acp` 与 dsh 走 `configOptions`,也有
|
|
242
|
+
* 走这一位的。只认一种就会对另一半的手整个报不出清单,所以两种都认,由调用方按顺序试。
|
|
243
|
+
*
|
|
244
|
+
* `collectSessionModelIds` 只取 id(够 `session/set_model` 用),这里要连名字和默认一起,
|
|
245
|
+
* 所以另起一个而不是改它——那个的调用方不需要多余字段。
|
|
246
|
+
*/
|
|
247
|
+
export function acpModelChoicesFromSessionModels(
|
|
248
|
+
models: unknown,
|
|
249
|
+
): ReadonlyArray<AcpConfigChoice> | undefined {
|
|
250
|
+
if (!isRecord(models) || !Array.isArray(models["availableModels"])) return undefined;
|
|
251
|
+
const currentModelId = asString(models["currentModelId"])?.trim();
|
|
252
|
+
const out: AcpConfigChoice[] = [];
|
|
253
|
+
const seen = new Set<string>();
|
|
254
|
+
for (const entry of models["availableModels"]) {
|
|
255
|
+
if (!isRecord(entry)) continue;
|
|
256
|
+
const value = asString(entry["modelId"])?.trim();
|
|
257
|
+
if (!value || seen.has(value)) continue;
|
|
258
|
+
seen.add(value);
|
|
259
|
+
const name = asString(entry["name"])?.trim();
|
|
260
|
+
const description = asString(entry["description"])?.trim();
|
|
261
|
+
out.push({
|
|
262
|
+
value,
|
|
263
|
+
...(name ? { name } : {}),
|
|
264
|
+
label: name || value,
|
|
265
|
+
...(description ? { description } : {}),
|
|
266
|
+
...(currentModelId !== undefined && currentModelId === value ? { isDefault: true } : {}),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|