@ktkid/kmh-codex-cli 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +296 -2
- package/bin/README.md +25 -0
- package/bin/codex +36 -0
- package/bin/runtime-receipt.json +9 -0
- package/bin/version +1 -0
- package/cordis.patch.yml +7 -0
- package/lib/browser-types/src/account-status.d.ts +9 -0
- package/lib/browser-types/src/client/ComposerQuota.d.ts +10 -0
- package/lib/browser-types/src/client/DetailCard.d.ts +12 -0
- package/lib/browser-types/src/client/LiveBall.d.ts +19 -0
- package/lib/browser-types/src/client/QuotaCard.d.ts +20 -0
- package/lib/browser-types/src/client/QuotaDisplaySettings.d.ts +6 -0
- package/lib/browser-types/src/client/index.d.ts +18 -0
- package/lib/browser-types/src/client/locales.d.ts +54 -0
- package/lib/browser-types/src/client/quota-store.d.ts +56 -0
- package/lib/browser-types/src/live-state.d.ts +31 -0
- package/lib/browser-types/src/quota-protocol.d.ts +135 -0
- package/lib/browser-types/src/quota-rules.d.ts +18 -0
- package/lib/browser-types/src/tool-switches.d.ts +63 -0
- package/lib/client.js +16193 -0
- package/lib/src/account-status.d.ts +9 -0
- package/lib/src/account-status.js +1 -0
- package/lib/src/account.d.ts +35 -0
- package/lib/src/account.js +173 -0
- package/lib/src/adapter.d.ts +22 -0
- package/lib/src/adapter.js +222 -0
- package/lib/src/approval.d.ts +48 -0
- package/lib/src/approval.js +235 -0
- package/lib/src/capabilities.d.ts +40 -0
- package/lib/src/capabilities.js +85 -0
- package/lib/src/config.d.ts +69 -0
- package/lib/src/config.js +75 -0
- package/lib/src/connection.d.ts +65 -0
- package/lib/src/connection.js +178 -0
- package/lib/src/cursor.d.ts +61 -0
- package/lib/src/cursor.js +339 -0
- package/lib/src/image-delivery.d.ts +36 -0
- package/lib/src/image-delivery.js +65 -0
- package/lib/src/imagegen.d.ts +21 -0
- package/lib/src/imagegen.js +132 -0
- package/lib/src/index.d.ts +146 -0
- package/lib/src/index.js +551 -0
- package/lib/src/isolation.d.ts +61 -0
- package/lib/src/isolation.js +298 -0
- package/lib/src/live-state.d.ts +31 -0
- package/lib/src/live-state.js +14 -0
- package/lib/src/models.d.ts +24 -0
- package/lib/src/models.js +98 -0
- package/lib/src/native-items.d.ts +59 -0
- package/lib/src/native-items.js +122 -0
- package/lib/src/native-tools/catalog.d.ts +29 -0
- package/lib/src/native-tools/catalog.js +197 -0
- package/lib/src/probe.d.ts +17 -0
- package/lib/src/probe.js +54 -0
- package/lib/src/protocol.d.ts +508 -0
- package/lib/src/protocol.js +511 -0
- package/lib/src/quota-protocol.d.ts +135 -0
- package/lib/src/quota-protocol.js +97 -0
- package/lib/src/quota-rules.d.ts +18 -0
- package/lib/src/quota-rules.js +49 -0
- package/lib/src/quota.d.ts +32 -0
- package/lib/src/quota.js +227 -0
- package/lib/src/session-history.d.ts +18 -0
- package/lib/src/session-history.js +113 -0
- package/lib/src/session-store.d.ts +592 -0
- package/lib/src/session-store.js +275 -0
- package/lib/src/status.d.ts +19 -0
- package/lib/src/status.js +69 -0
- package/lib/src/tool-policy.d.ts +47 -0
- package/lib/src/tool-policy.js +454 -0
- package/lib/src/tool-registry.d.ts +42 -0
- package/lib/src/tool-registry.js +70 -0
- package/lib/src/tool-selection.d.ts +88 -0
- package/lib/src/tool-selection.js +60 -0
- package/lib/src/tool-switches-service.d.ts +24 -0
- package/lib/src/tool-switches-service.js +129 -0
- package/lib/src/tool-switches.d.ts +63 -0
- package/lib/src/tool-switches.js +43 -0
- package/lib/src/turn.d.ts +200 -0
- package/lib/src/turn.js +1012 -0
- package/lib/src/web.d.ts +9 -0
- package/lib/src/web.js +143 -0
- package/package.json +172 -4
- package/vendor/codex/LICENSE +201 -0
- package/vendor/codex/NOTICE +4 -0
- package/vendor/codex/models.json +1613 -0
- package/vendor/native-tools/0.162.0-alpha.17.2.json +143 -0
- package/vendor/native-tools/0.163.0-alpha.10.2.json +128 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/** Codex app-server 行协议的帧编码与 v2 方法、通知的输入输出类型。 */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { Writable } from "node:stream";
|
|
4
|
+
/**
|
|
5
|
+
* 官方 CLI 行协议不携带 `jsonrpc` 字段:发送方向经本 bridge 剥除后再写出。
|
|
6
|
+
* @param output - 进程标准输入流。
|
|
7
|
+
* @param options - 透传的 Writable 构造参数。
|
|
8
|
+
* @returns 写入端接 JsonRpcLineTransport 的桥接流。
|
|
9
|
+
*/
|
|
10
|
+
export function createFrameBridge(output, options) {
|
|
11
|
+
return new Writable({
|
|
12
|
+
...options,
|
|
13
|
+
write(chunk, _encoding, callback) {
|
|
14
|
+
let rest;
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(chunk.toString("utf8"));
|
|
17
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
18
|
+
throw new Error("CODEX_FRAME_INVALID");
|
|
19
|
+
rest = {};
|
|
20
|
+
for (const [key, value] of Object.entries(parsed))
|
|
21
|
+
if (key !== "jsonrpc")
|
|
22
|
+
rest[key] = value;
|
|
23
|
+
output.write(JSON.stringify(rest) + "\n", callback);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
callback(error instanceof Error ? error : new Error("CODEX_FRAME_INVALID"));
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** 从 unknown 对象安全取一个字段;无该字段或非对象时返回 undefined。 */
|
|
32
|
+
export function fieldOf(value, key) {
|
|
33
|
+
if (value === null || typeof value !== "object")
|
|
34
|
+
return undefined;
|
|
35
|
+
for (const [name, item] of Object.entries(value))
|
|
36
|
+
if (name === key)
|
|
37
|
+
return item;
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
/** 浅拷贝 unknown 对象为可写字段表;非对象时抛错。 */
|
|
41
|
+
export function shallowCopy(value, code) {
|
|
42
|
+
if (value === null || typeof value !== "object")
|
|
43
|
+
throw new Error(code);
|
|
44
|
+
const copy = {};
|
|
45
|
+
for (const [key, item] of Object.entries(value))
|
|
46
|
+
copy[key] = item;
|
|
47
|
+
return copy;
|
|
48
|
+
}
|
|
49
|
+
/** 方法名常量:集中一处,避免字符串散落。 */
|
|
50
|
+
export const Method = {
|
|
51
|
+
initialize: "initialize",
|
|
52
|
+
modelList: "model/list",
|
|
53
|
+
threadStart: "thread/start",
|
|
54
|
+
threadResume: "thread/resume",
|
|
55
|
+
turnStart: "turn/start",
|
|
56
|
+
turnInterrupt: "turn/interrupt",
|
|
57
|
+
accountLoginStart: "account/login/start",
|
|
58
|
+
accountLoginCancel: "account/login/cancel",
|
|
59
|
+
accountLogout: "account/logout",
|
|
60
|
+
accountStatus: "account/status",
|
|
61
|
+
accountRead: "account/read",
|
|
62
|
+
accountRateLimitsRead: "account/rateLimits/read",
|
|
63
|
+
};
|
|
64
|
+
/** 官方 0.162 v2 生成协议的本功能消费字段;分区校验使合法周期独立保留。 */
|
|
65
|
+
export const QuotaAccountResult = z.object({
|
|
66
|
+
account: z
|
|
67
|
+
.discriminatedUnion("type", [
|
|
68
|
+
z.object({
|
|
69
|
+
type: z.literal("chatgpt"),
|
|
70
|
+
email: z.string().nullable(),
|
|
71
|
+
planType: z.string(),
|
|
72
|
+
}),
|
|
73
|
+
z.object({ type: z.literal("apiKey") }),
|
|
74
|
+
z.object({
|
|
75
|
+
type: z.literal("amazonBedrock"),
|
|
76
|
+
usesCodexManagedCredentials: z.boolean(),
|
|
77
|
+
}),
|
|
78
|
+
])
|
|
79
|
+
.nullable(),
|
|
80
|
+
});
|
|
81
|
+
export const NativeQuotaWindow = z.object({
|
|
82
|
+
usedPercent: z.number().min(0).max(100),
|
|
83
|
+
windowDurationMins: z.number().int().positive().nullable(),
|
|
84
|
+
resetsAt: z.number().int().nonnegative().max(8640000000000).nullable(),
|
|
85
|
+
});
|
|
86
|
+
export const NativeCredits = z.object({
|
|
87
|
+
hasCredits: z.boolean(),
|
|
88
|
+
unlimited: z.boolean(),
|
|
89
|
+
balance: z.string().nullable(),
|
|
90
|
+
});
|
|
91
|
+
export const NativeSpendLimit = z.object({
|
|
92
|
+
limit: z.string(),
|
|
93
|
+
used: z.string(),
|
|
94
|
+
remainingPercent: z.number().min(0).max(100),
|
|
95
|
+
resetsAt: z.number().int().nonnegative().max(8640000000000),
|
|
96
|
+
});
|
|
97
|
+
export const NativeResetCredits = z.object({
|
|
98
|
+
availableCount: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
99
|
+
credits: z
|
|
100
|
+
.array(z.object({
|
|
101
|
+
id: z.string(),
|
|
102
|
+
title: z.string().nullable(),
|
|
103
|
+
description: z.string().nullable(),
|
|
104
|
+
resetType: z.string(),
|
|
105
|
+
status: z.string(),
|
|
106
|
+
grantedAt: z.number().int().nonnegative(),
|
|
107
|
+
expiresAt: z.number().int().nonnegative().max(8640000000000).nullable(),
|
|
108
|
+
}))
|
|
109
|
+
.nullable(),
|
|
110
|
+
});
|
|
111
|
+
export const NativeQuotaSnapshot = z.object({
|
|
112
|
+
limitId: z.string().nullable().optional(),
|
|
113
|
+
limitName: z.string().nullable().optional(),
|
|
114
|
+
primary: z.unknown().optional(),
|
|
115
|
+
secondary: z.unknown().optional(),
|
|
116
|
+
credits: z.unknown().optional(),
|
|
117
|
+
individualLimit: z.unknown().optional(),
|
|
118
|
+
});
|
|
119
|
+
export const NativeQuotaResult = z.object({
|
|
120
|
+
rateLimits: z.unknown(),
|
|
121
|
+
rateLimitsByLimitId: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
122
|
+
rateLimitResetCredits: z.unknown().optional(),
|
|
123
|
+
accountId: z.string().nullable().optional(),
|
|
124
|
+
});
|
|
125
|
+
/** 服务端请求与通知的方法名。 */
|
|
126
|
+
export const Incoming = {
|
|
127
|
+
itemToolCall: "item/tool/call",
|
|
128
|
+
itemDynamicToolCall: "item/dynamicTool/call",
|
|
129
|
+
itemCommandExecutionRequestApproval: "item/commandExecution/requestApproval",
|
|
130
|
+
itemFileChangeRequestApproval: "item/fileChange/requestApproval",
|
|
131
|
+
itemPermissionsRequestApproval: "item/permissions/requestApproval",
|
|
132
|
+
itemToolRequestUserInput: "item/tool/requestUserInput",
|
|
133
|
+
mcpServerElicitationRequest: "mcpServer/elicitation/request",
|
|
134
|
+
turnStarted: "turn/started",
|
|
135
|
+
turnCompleted: "turn/completed",
|
|
136
|
+
itemStarted: "item/started",
|
|
137
|
+
itemCompleted: "item/completed",
|
|
138
|
+
commandExecutionOutputDelta: "item/commandExecution/outputDelta",
|
|
139
|
+
mcpToolCallProgress: "item/mcpToolCall/progress",
|
|
140
|
+
turnDiffUpdated: "turn/diff/updated",
|
|
141
|
+
agentMessageDelta: "item/agentMessage/delta",
|
|
142
|
+
reasoningTextDelta: "item/reasoning/textDelta",
|
|
143
|
+
reasoningSummaryTextDelta: "item/reasoning/summaryTextDelta",
|
|
144
|
+
threadCompacted: "thread/compacted",
|
|
145
|
+
tokenUsageUpdated: "thread/tokenUsage/updated",
|
|
146
|
+
accountUpdated: "account/updated",
|
|
147
|
+
accountLoginCompleted: "account/login/completed",
|
|
148
|
+
error: "error",
|
|
149
|
+
};
|
|
150
|
+
const clientInfo = z.object({
|
|
151
|
+
name: z.string().min(1),
|
|
152
|
+
title: z.string().min(1),
|
|
153
|
+
version: z.string().min(1),
|
|
154
|
+
});
|
|
155
|
+
/** initialize 请求参数。 */
|
|
156
|
+
export const InitializeParams = z.object({
|
|
157
|
+
clientInfo,
|
|
158
|
+
capabilities: z.object({ experimentalApi: z.boolean() }).passthrough(),
|
|
159
|
+
});
|
|
160
|
+
/** initialize 响应。 */
|
|
161
|
+
export const InitializeResult = z
|
|
162
|
+
.object({
|
|
163
|
+
userAgent: z.string().optional(),
|
|
164
|
+
permissions: z.unknown().optional(),
|
|
165
|
+
})
|
|
166
|
+
.passthrough();
|
|
167
|
+
/** model/list 请求参数。 */
|
|
168
|
+
export const ModelListParams = z.object({ includeHidden: z.boolean() });
|
|
169
|
+
/** 模型目录条目(字段按 0.160.0 验证实测收敛,未知字段容忍)。 */
|
|
170
|
+
export const ModelEntry = z
|
|
171
|
+
.object({
|
|
172
|
+
id: z.string().min(1),
|
|
173
|
+
displayName: z.string().optional(),
|
|
174
|
+
inputModalities: z.array(z.string()).optional().catch(undefined),
|
|
175
|
+
// 推理等级原值:wire 键为 supportedReasoningEfforts,值为
|
|
176
|
+
// {reasoningEffort, description} 对象数组,以 unknown 接住由调用方归一;
|
|
177
|
+
// 缺失表示该模型不支持调节。
|
|
178
|
+
supportedReasoningEfforts: z.array(z.unknown()).optional(),
|
|
179
|
+
defaultReasoningEffort: z.string().optional(),
|
|
180
|
+
supportsReasoningSummaries: z.boolean().optional(),
|
|
181
|
+
})
|
|
182
|
+
.passthrough();
|
|
183
|
+
/** model/list 响应。 */
|
|
184
|
+
export const ModelListResult = z.object({
|
|
185
|
+
data: z.array(ModelEntry),
|
|
186
|
+
nextPageCursor: z.string().optional(),
|
|
187
|
+
});
|
|
188
|
+
/** thread/start 的动态工具声明(单函数形态)。 */
|
|
189
|
+
export const DynamicToolSpec = z.object({
|
|
190
|
+
name: z.string().min(1),
|
|
191
|
+
description: z.string(),
|
|
192
|
+
inputSchema: z.record(z.string(), z.unknown()),
|
|
193
|
+
deferLoading: z.boolean().optional(),
|
|
194
|
+
});
|
|
195
|
+
/** KMH 工具的稳定挂载命名空间:thread 重建前后形态不变。 */
|
|
196
|
+
export const KMH_TOOL_NAMESPACE = "kmh";
|
|
197
|
+
/** namespace 形态的动态工具声明。 */
|
|
198
|
+
export const DynamicNamespaceSpec = z.object({
|
|
199
|
+
type: z.literal("namespace"),
|
|
200
|
+
name: z.literal(KMH_TOOL_NAMESPACE),
|
|
201
|
+
description: z.string(),
|
|
202
|
+
tools: z.array(DynamicToolSpec),
|
|
203
|
+
});
|
|
204
|
+
/** thread/start 请求参数。 */
|
|
205
|
+
export const ThreadStartParams = z.object({
|
|
206
|
+
experimentalRawEvents: z.boolean().optional(),
|
|
207
|
+
model: z.string().optional(),
|
|
208
|
+
ephemeral: z.boolean().optional(),
|
|
209
|
+
cwd: z.string().optional(),
|
|
210
|
+
baseInstructions: z.string().optional(),
|
|
211
|
+
developerInstructions: z.string().optional(),
|
|
212
|
+
dynamicTools: z.array(DynamicToolSpec).optional(),
|
|
213
|
+
});
|
|
214
|
+
/** thread/start 与 thread/resume 的响应。 */
|
|
215
|
+
export const ThreadResult = z.object({
|
|
216
|
+
thread: z.object({ id: z.string().min(1) }).passthrough(),
|
|
217
|
+
});
|
|
218
|
+
/** turn/start 的用户输入。 */
|
|
219
|
+
export const UserTextInput = z.object({
|
|
220
|
+
type: z.literal("text"),
|
|
221
|
+
text: z.string(),
|
|
222
|
+
});
|
|
223
|
+
export const UserInput = z.discriminatedUnion("type", [
|
|
224
|
+
UserTextInput,
|
|
225
|
+
z.object({ type: z.literal("image"), url: z.string() }),
|
|
226
|
+
]);
|
|
227
|
+
/** turn/start 请求参数。 */
|
|
228
|
+
export const TurnStartParams = z.object({
|
|
229
|
+
threadId: z.string().min(1),
|
|
230
|
+
input: z.array(UserInput).min(1),
|
|
231
|
+
model: z.string().optional(),
|
|
232
|
+
effort: z.string().optional(),
|
|
233
|
+
summary: z.enum(["auto", "concise", "detailed", "none"]).optional(),
|
|
234
|
+
});
|
|
235
|
+
/** turn/start 响应。 */
|
|
236
|
+
export const TurnResult = z.object({
|
|
237
|
+
turn: z.object({ id: z.string().min(1) }).passthrough(),
|
|
238
|
+
});
|
|
239
|
+
/** turn/steer 在指定的活跃回合中接纳追加输入。 */
|
|
240
|
+
export const TurnSteerParams = z.object({
|
|
241
|
+
threadId: z.string().min(1),
|
|
242
|
+
expectedTurnId: z.string().min(1),
|
|
243
|
+
input: z.array(UserInput).min(1),
|
|
244
|
+
});
|
|
245
|
+
export const TurnSteerResult = z.object({ turnId: z.string().min(1) });
|
|
246
|
+
/** turn/interrupt 请求参数。 */
|
|
247
|
+
export const TurnInterruptParams = z.object({
|
|
248
|
+
threadId: z.string().min(1),
|
|
249
|
+
turnId: z.string().min(1),
|
|
250
|
+
});
|
|
251
|
+
/** item/tool/call 服务端请求参数(动态工具执行请求)。 */
|
|
252
|
+
export const DynamicToolCallParams = z.object({
|
|
253
|
+
threadId: z.string().min(1),
|
|
254
|
+
turnId: z.string().min(1),
|
|
255
|
+
callId: z.string().min(1),
|
|
256
|
+
namespace: z.string().nullable().optional(),
|
|
257
|
+
tool: z.string().min(1),
|
|
258
|
+
arguments: z.unknown(),
|
|
259
|
+
});
|
|
260
|
+
/** item/tool/call 的回执内容项。 */
|
|
261
|
+
export const ToolCallContentItem = z.discriminatedUnion("type", [
|
|
262
|
+
z.object({ type: z.literal("inputText"), text: z.string() }),
|
|
263
|
+
z.object({ type: z.literal("inputImage"), imageUrl: z.string() }),
|
|
264
|
+
]);
|
|
265
|
+
/** item/tool/call 回执。 */
|
|
266
|
+
export const DynamicToolCallResponse = z.object({
|
|
267
|
+
success: z.boolean(),
|
|
268
|
+
contentItems: z.array(ToolCallContentItem),
|
|
269
|
+
});
|
|
270
|
+
/** turn/completed 通知参数。 */
|
|
271
|
+
export const TurnCompletedParams = z.object({
|
|
272
|
+
threadId: z.string().min(1),
|
|
273
|
+
turn: z.object({ id: z.string().min(1), status: z.string() }).passthrough(),
|
|
274
|
+
});
|
|
275
|
+
/** item/agentMessage/delta 通知参数。 */
|
|
276
|
+
export const AgentMessageDeltaParams = z
|
|
277
|
+
.object({
|
|
278
|
+
threadId: z.string().min(1),
|
|
279
|
+
itemId: z.string().min(1),
|
|
280
|
+
delta: z.string(),
|
|
281
|
+
})
|
|
282
|
+
.passthrough();
|
|
283
|
+
/** item/reasoning/textDelta 通知参数。 */
|
|
284
|
+
export const ReasoningDeltaParams = z
|
|
285
|
+
.object({
|
|
286
|
+
threadId: z.string().min(1),
|
|
287
|
+
itemId: z.string().min(1),
|
|
288
|
+
delta: z.string(),
|
|
289
|
+
})
|
|
290
|
+
.passthrough();
|
|
291
|
+
/** item/completed 的生图项(app-server ThreadItem::ImageGeneration 的 wire 形态)。 */
|
|
292
|
+
export const ImageGenerationItemParams = z
|
|
293
|
+
.object({
|
|
294
|
+
type: z.literal("imageGeneration"),
|
|
295
|
+
id: z.string().min(1),
|
|
296
|
+
status: z.string(),
|
|
297
|
+
revisedPrompt: z.string().nullable().optional(),
|
|
298
|
+
savedPath: z.string().optional(),
|
|
299
|
+
})
|
|
300
|
+
.passthrough();
|
|
301
|
+
/**
|
|
302
|
+
* 从 item/completed 的生图项提取可投影产物。
|
|
303
|
+
* @param item - ThreadItem::ImageGeneration 的原始对象。
|
|
304
|
+
* @returns 已完成且已落盘时返回 id、路径与展示名;否则 undefined(不构成错误)。
|
|
305
|
+
*/
|
|
306
|
+
export function imageProjectionOf(item) {
|
|
307
|
+
const parsed = ImageGenerationItemParams.safeParse(item);
|
|
308
|
+
if (!parsed.success)
|
|
309
|
+
return undefined;
|
|
310
|
+
const { id, status, revisedPrompt, savedPath } = parsed.data;
|
|
311
|
+
if (status !== "completed" || savedPath === undefined)
|
|
312
|
+
return undefined;
|
|
313
|
+
const prompt = revisedPrompt?.trim();
|
|
314
|
+
return {
|
|
315
|
+
id,
|
|
316
|
+
path: savedPath,
|
|
317
|
+
name: prompt === undefined || prompt === "" ? undefined : prompt.slice(0, 60),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/** app-server ThreadItem::Reasoning 的可见文本;摘要与原始内容均为字符串数组。 */
|
|
321
|
+
export const ReasoningItemContent = z.object({
|
|
322
|
+
summary: z.array(z.string()).default([]),
|
|
323
|
+
content: z.array(z.string()).default([]),
|
|
324
|
+
});
|
|
325
|
+
/**
|
|
326
|
+
* 从 app-server 完成项提取摘要,摘要为空时读取原始内容。
|
|
327
|
+
* @param item - item/completed 的 reasoning 对象。
|
|
328
|
+
* @returns 非空文本;两个数组皆空时返回 undefined。
|
|
329
|
+
* @throws ZodError 文本数组包含非法元素。
|
|
330
|
+
*/
|
|
331
|
+
export function reasoningItemText(item) {
|
|
332
|
+
const parsed = ReasoningItemContent.parse(item);
|
|
333
|
+
const summaryTexts = parsed.summary.filter((text) => text !== "");
|
|
334
|
+
if (summaryTexts.length > 0)
|
|
335
|
+
return summaryTexts.join("\n\n");
|
|
336
|
+
const contentTexts = parsed.content.filter((text) => text !== "");
|
|
337
|
+
return contentTexts.length > 0 ? contentTexts.join("") : undefined;
|
|
338
|
+
}
|
|
339
|
+
/** item/started、item/completed 通知参数:item 形态留由消费方判别。 */
|
|
340
|
+
export const ItemEventParams = z
|
|
341
|
+
.object({
|
|
342
|
+
threadId: z.string().min(1),
|
|
343
|
+
turnId: z.string().optional(),
|
|
344
|
+
item: z.unknown(),
|
|
345
|
+
})
|
|
346
|
+
.passthrough();
|
|
347
|
+
/** item/commandExecution/outputDelta 通知参数(feat08)。 */
|
|
348
|
+
export const CommandExecutionOutputDeltaParams = z.object({
|
|
349
|
+
threadId: z.string().min(1),
|
|
350
|
+
turnId: z.string().min(1),
|
|
351
|
+
itemId: z.string().min(1),
|
|
352
|
+
delta: z.string(),
|
|
353
|
+
});
|
|
354
|
+
/** item/mcpToolCall/progress 通知参数。 */
|
|
355
|
+
export const McpToolCallProgressParams = z.object({
|
|
356
|
+
threadId: z.string().min(1),
|
|
357
|
+
turnId: z.string().min(1),
|
|
358
|
+
itemId: z.string().min(1),
|
|
359
|
+
message: z.string(),
|
|
360
|
+
});
|
|
361
|
+
/** turn/diff/updated 通知参数。 */
|
|
362
|
+
export const TurnDiffUpdatedParams = z.object({
|
|
363
|
+
threadId: z.string().min(1),
|
|
364
|
+
turnId: z.string().min(1),
|
|
365
|
+
diff: z.string(),
|
|
366
|
+
});
|
|
367
|
+
/** 审批类服务端请求的公共定位字段。 */
|
|
368
|
+
const approvalLocator = {
|
|
369
|
+
threadId: z.string().min(1),
|
|
370
|
+
turnId: z.string().min(1),
|
|
371
|
+
itemId: z.string().min(1),
|
|
372
|
+
};
|
|
373
|
+
/** item/commandExecution/requestApproval 请求参数(0.160.0 生成 schema 收敛)。 */
|
|
374
|
+
export const CommandExecutionRequestApprovalParams = z
|
|
375
|
+
.object({
|
|
376
|
+
...approvalLocator,
|
|
377
|
+
startedAtMs: z.number(),
|
|
378
|
+
kind: z.string().optional(),
|
|
379
|
+
approvalId: z.string().nullable().optional(),
|
|
380
|
+
reason: z.string().nullable().optional(),
|
|
381
|
+
command: z.string().nullable().optional(),
|
|
382
|
+
cwd: z.string().nullable().optional(),
|
|
383
|
+
})
|
|
384
|
+
.passthrough();
|
|
385
|
+
/** 桥发出的命令审批决定值(枚举全集见 decisions D18,桥只发三种)。 */
|
|
386
|
+
export const CommandExecutionRequestApprovalResponse = z.object({
|
|
387
|
+
decision: z.enum(["accept", "acceptForSession", "decline", "cancel"]),
|
|
388
|
+
});
|
|
389
|
+
/** item/fileChange/requestApproval 请求参数。 */
|
|
390
|
+
export const FileChangeRequestApprovalParams = z
|
|
391
|
+
.object({
|
|
392
|
+
...approvalLocator,
|
|
393
|
+
startedAtMs: z.number(),
|
|
394
|
+
reason: z.string().nullable().optional(),
|
|
395
|
+
grantRoot: z.string().nullable().optional(),
|
|
396
|
+
})
|
|
397
|
+
.passthrough();
|
|
398
|
+
export const FileChangeRequestApprovalResponse = z.object({
|
|
399
|
+
decision: z.enum(["accept", "acceptForSession", "decline", "cancel"]),
|
|
400
|
+
});
|
|
401
|
+
/** item/permissions/requestApproval 请求参数(授权范围原样透传给用户审阅)。 */
|
|
402
|
+
export const PermissionsRequestApprovalParams = z
|
|
403
|
+
.object({
|
|
404
|
+
...approvalLocator,
|
|
405
|
+
startedAtMs: z.number(),
|
|
406
|
+
cwd: z.string(),
|
|
407
|
+
reason: z.string().nullable().optional(),
|
|
408
|
+
permissions: z.unknown(),
|
|
409
|
+
})
|
|
410
|
+
.passthrough();
|
|
411
|
+
/** 权限审批回执:批准=请求声明的范围、scope 取 turn;拒绝=空授权。 */
|
|
412
|
+
export const PermissionsRequestApprovalResponse = z.object({
|
|
413
|
+
permissions: z.record(z.string(), z.unknown()),
|
|
414
|
+
scope: z.enum(["turn", "session"]),
|
|
415
|
+
});
|
|
416
|
+
/** item/tool/requestUserInput 请求参数(EXPERIMENTAL)。 */
|
|
417
|
+
export const ToolRequestUserInputParams = z
|
|
418
|
+
.object({
|
|
419
|
+
...approvalLocator,
|
|
420
|
+
isBlocking: z.boolean().optional(),
|
|
421
|
+
questions: z.array(z
|
|
422
|
+
.object({
|
|
423
|
+
id: z.string().min(1),
|
|
424
|
+
header: z.string(),
|
|
425
|
+
question: z.string(),
|
|
426
|
+
isOther: z.boolean().optional(),
|
|
427
|
+
isSecret: z.boolean().optional(),
|
|
428
|
+
options: z
|
|
429
|
+
.array(z.object({
|
|
430
|
+
label: z.string(),
|
|
431
|
+
description: z.string().optional(),
|
|
432
|
+
}))
|
|
433
|
+
.nullable()
|
|
434
|
+
.optional(),
|
|
435
|
+
})
|
|
436
|
+
.passthrough()),
|
|
437
|
+
})
|
|
438
|
+
.passthrough();
|
|
439
|
+
/** 用户输入回执:问题 id → 答案串数组。 */
|
|
440
|
+
export const ToolRequestUserInputResponse = z.object({
|
|
441
|
+
answers: z.record(z.string(), z.object({ answers: z.array(z.string()) })),
|
|
442
|
+
});
|
|
443
|
+
/** mcpServer/elicitation/request 请求参数(request 扁平字段按 mode 判别)。 */
|
|
444
|
+
export const McpServerElicitationRequestParams = z
|
|
445
|
+
.object({
|
|
446
|
+
threadId: z.string().min(1),
|
|
447
|
+
turnId: z.string().nullable().optional(),
|
|
448
|
+
serverName: z.string().min(1),
|
|
449
|
+
mode: z.string().optional(),
|
|
450
|
+
message: z.string().optional(),
|
|
451
|
+
url: z.string().optional(),
|
|
452
|
+
requestedSchema: z.unknown().optional(),
|
|
453
|
+
})
|
|
454
|
+
.passthrough();
|
|
455
|
+
/** elicitation 回执。 */
|
|
456
|
+
export const McpServerElicitationRequestResponse = z.object({
|
|
457
|
+
action: z.enum(["accept", "decline", "cancel"]),
|
|
458
|
+
content: z.unknown().optional(),
|
|
459
|
+
});
|
|
460
|
+
/** thread/compacted 通知参数:压缩后上下文全量回传的载体。 */
|
|
461
|
+
export const ThreadCompactedParams = z
|
|
462
|
+
.object({
|
|
463
|
+
threadId: z.string().min(1),
|
|
464
|
+
// 0.160.0 实测字段留待桥接验证收敛,此处先保留原始对象。
|
|
465
|
+
})
|
|
466
|
+
.passthrough();
|
|
467
|
+
/** 单次上游响应/累计的用量明细(TokenUsageBreakdown,camelCase)。 */
|
|
468
|
+
export const TokenUsageBreakdownParams = z.object({
|
|
469
|
+
totalTokens: z.number(),
|
|
470
|
+
inputTokens: z.number(),
|
|
471
|
+
cachedInputTokens: z.number(),
|
|
472
|
+
cacheWriteInputTokens: z.number(),
|
|
473
|
+
outputTokens: z.number(),
|
|
474
|
+
reasoningOutputTokens: z.number(),
|
|
475
|
+
});
|
|
476
|
+
/** thread/tokenUsage/updated 通知参数(0.162 wire 实测:last=最近一次响应)。 */
|
|
477
|
+
export const TokenUsageParams = z
|
|
478
|
+
.object({
|
|
479
|
+
threadId: z.string().min(1),
|
|
480
|
+
turnId: z.string().min(1),
|
|
481
|
+
tokenUsage: z.object({
|
|
482
|
+
total: TokenUsageBreakdownParams,
|
|
483
|
+
last: TokenUsageBreakdownParams,
|
|
484
|
+
}),
|
|
485
|
+
})
|
|
486
|
+
.passthrough();
|
|
487
|
+
/** account/updated 通知参数。 */
|
|
488
|
+
export const AccountUpdatedParams = z.object({}).passthrough();
|
|
489
|
+
/** 顶层 error 通知参数。 */
|
|
490
|
+
export const ErrorNotificationParams = z
|
|
491
|
+
.object({
|
|
492
|
+
message: z.string().optional(),
|
|
493
|
+
error: z
|
|
494
|
+
.object({
|
|
495
|
+
message: z.string(),
|
|
496
|
+
additionalDetails: z.string().nullish(),
|
|
497
|
+
})
|
|
498
|
+
.passthrough()
|
|
499
|
+
.optional(),
|
|
500
|
+
willRetry: z.boolean().optional(),
|
|
501
|
+
turnId: z.string().optional(),
|
|
502
|
+
})
|
|
503
|
+
.passthrough();
|
|
504
|
+
/** 官方 thread/fork 的回合位置;两个切点字段互斥。 */
|
|
505
|
+
export const ThreadForkParams = z
|
|
506
|
+
.object({
|
|
507
|
+
threadId: z.string(),
|
|
508
|
+
lastTurnId: z.string().optional(),
|
|
509
|
+
beforeTurnId: z.string().optional(),
|
|
510
|
+
})
|
|
511
|
+
.refine((value) => value.lastTurnId === undefined || value.beforeTurnId === undefined, "fork positions are mutually exclusive");
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/** 浏览器与宿主共用的只读额度协议;时间统一为毫秒。 */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** 传输层校验字段类型,范围与默认值由宿主 Config 定义。 */
|
|
4
|
+
export declare const QuotaPreferences: z.ZodObject<{
|
|
5
|
+
quotaDisplayMode: z.ZodEnum<{
|
|
6
|
+
percent: "percent";
|
|
7
|
+
bar: "bar";
|
|
8
|
+
off: "off";
|
|
9
|
+
}>;
|
|
10
|
+
quotaAlertsEnabled: z.ZodBoolean;
|
|
11
|
+
quotaShortThresholdPercent: z.ZodNumber;
|
|
12
|
+
quotaWeeklyThresholdPercent: z.ZodNumber;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
export type QuotaPreferences = z.infer<typeof QuotaPreferences>;
|
|
15
|
+
export declare const QuotaContext: z.ZodObject<{
|
|
16
|
+
settingsNamespace: z.ZodNullable<z.ZodString>;
|
|
17
|
+
preferences: z.ZodObject<{
|
|
18
|
+
quotaDisplayMode: z.ZodEnum<{
|
|
19
|
+
percent: "percent";
|
|
20
|
+
bar: "bar";
|
|
21
|
+
off: "off";
|
|
22
|
+
}>;
|
|
23
|
+
quotaAlertsEnabled: z.ZodBoolean;
|
|
24
|
+
quotaShortThresholdPercent: z.ZodNumber;
|
|
25
|
+
quotaWeeklyThresholdPercent: z.ZodNumber;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export declare const QuotaQuery: z.ZodObject<{
|
|
29
|
+
detail: z.ZodDefault<z.ZodEnum<{
|
|
30
|
+
summary: "summary";
|
|
31
|
+
full: "full";
|
|
32
|
+
}>>;
|
|
33
|
+
force: z.ZodDefault<z.ZodEnum<{
|
|
34
|
+
0: "0";
|
|
35
|
+
1: "1";
|
|
36
|
+
}>>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export declare const QuotaWindow: z.ZodObject<{
|
|
39
|
+
usedPercent: z.ZodNumber;
|
|
40
|
+
remainingPercent: z.ZodNumber;
|
|
41
|
+
windowMinutes: z.ZodNullable<z.ZodNumber>;
|
|
42
|
+
resetsAtMs: z.ZodNullable<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type QuotaWindow = z.infer<typeof QuotaWindow>;
|
|
45
|
+
export declare const QuotaGroup: z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
name: z.ZodNullable<z.ZodString>;
|
|
48
|
+
windows: z.ZodArray<z.ZodObject<{
|
|
49
|
+
usedPercent: z.ZodNumber;
|
|
50
|
+
remainingPercent: z.ZodNumber;
|
|
51
|
+
windowMinutes: z.ZodNullable<z.ZodNumber>;
|
|
52
|
+
resetsAtMs: z.ZodNullable<z.ZodNumber>;
|
|
53
|
+
}, z.core.$strip>>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type QuotaGroup = z.infer<typeof QuotaGroup>;
|
|
56
|
+
export declare const QuotaError: z.ZodObject<{
|
|
57
|
+
area: z.ZodEnum<{
|
|
58
|
+
account: "account";
|
|
59
|
+
credits: "credits";
|
|
60
|
+
windows: "windows";
|
|
61
|
+
spend: "spend";
|
|
62
|
+
resets: "resets";
|
|
63
|
+
}>;
|
|
64
|
+
code: z.ZodEnum<{
|
|
65
|
+
"read-failed": "read-failed";
|
|
66
|
+
"invalid-data": "invalid-data";
|
|
67
|
+
unsupported: "unsupported";
|
|
68
|
+
}>;
|
|
69
|
+
message: z.ZodString;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
export type QuotaError = z.infer<typeof QuotaError>;
|
|
72
|
+
export declare const QuotaView: z.ZodObject<{
|
|
73
|
+
accountEpoch: z.ZodNumber;
|
|
74
|
+
state: z.ZodEnum<{
|
|
75
|
+
error: "error";
|
|
76
|
+
unsupported: "unsupported";
|
|
77
|
+
loading: "loading";
|
|
78
|
+
ready: "ready";
|
|
79
|
+
"signed-out": "signed-out";
|
|
80
|
+
}>;
|
|
81
|
+
fetchedAtMs: z.ZodNullable<z.ZodNumber>;
|
|
82
|
+
nextRefreshAtMs: z.ZodNumber;
|
|
83
|
+
groups: z.ZodArray<z.ZodObject<{
|
|
84
|
+
id: z.ZodString;
|
|
85
|
+
name: z.ZodNullable<z.ZodString>;
|
|
86
|
+
windows: z.ZodArray<z.ZodObject<{
|
|
87
|
+
usedPercent: z.ZodNumber;
|
|
88
|
+
remainingPercent: z.ZodNumber;
|
|
89
|
+
windowMinutes: z.ZodNullable<z.ZodNumber>;
|
|
90
|
+
resetsAtMs: z.ZodNullable<z.ZodNumber>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
}, z.core.$strip>>;
|
|
93
|
+
credits: z.ZodNullable<z.ZodObject<{
|
|
94
|
+
hasCredits: z.ZodBoolean;
|
|
95
|
+
unlimited: z.ZodBoolean;
|
|
96
|
+
balance: z.ZodNullable<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
creditsAtMs: z.ZodNullable<z.ZodNumber>;
|
|
99
|
+
spend: z.ZodNullable<z.ZodObject<{
|
|
100
|
+
limit: z.ZodString;
|
|
101
|
+
used: z.ZodString;
|
|
102
|
+
remainingPercent: z.ZodNumber;
|
|
103
|
+
resetsAtMs: z.ZodNumber;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
spendAtMs: z.ZodNullable<z.ZodNumber>;
|
|
106
|
+
resets: z.ZodNullable<z.ZodObject<{
|
|
107
|
+
availableCount: z.ZodNumber;
|
|
108
|
+
cards: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
109
|
+
id: z.ZodString;
|
|
110
|
+
title: z.ZodNullable<z.ZodString>;
|
|
111
|
+
description: z.ZodNullable<z.ZodString>;
|
|
112
|
+
status: z.ZodString;
|
|
113
|
+
expiresAtMs: z.ZodNullable<z.ZodNumber>;
|
|
114
|
+
}, z.core.$strip>>>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
resetsAtMs: z.ZodNullable<z.ZodNumber>;
|
|
117
|
+
errors: z.ZodArray<z.ZodObject<{
|
|
118
|
+
area: z.ZodEnum<{
|
|
119
|
+
account: "account";
|
|
120
|
+
credits: "credits";
|
|
121
|
+
windows: "windows";
|
|
122
|
+
spend: "spend";
|
|
123
|
+
resets: "resets";
|
|
124
|
+
}>;
|
|
125
|
+
code: z.ZodEnum<{
|
|
126
|
+
"read-failed": "read-failed";
|
|
127
|
+
"invalid-data": "invalid-data";
|
|
128
|
+
unsupported: "unsupported";
|
|
129
|
+
}>;
|
|
130
|
+
message: z.ZodString;
|
|
131
|
+
}, z.core.$strip>>;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
export type QuotaView = z.infer<typeof QuotaView>;
|
|
134
|
+
/** 初始化或账号失效时清空所有区域,保留共享冷却时间。 */
|
|
135
|
+
export declare function emptyQuota(accountEpoch?: number, nextRefreshAtMs?: number): QuotaView;
|