@winmatrix/protocol 1.0.4 → 1.0.6
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/dist/agent-engine-host-wire-fixtures.json +95 -0
- package/dist/agent-engine-host-wire-schema.json +1063 -0
- package/dist/agentEngine.d.ts +7771 -0
- package/dist/agentEngine.d.ts.map +1 -0
- package/dist/agentEngine.js +679 -0
- package/dist/agentEngine.js.map +1 -0
- package/dist/chatPresentation.d.ts +548 -0
- package/dist/chatPresentation.d.ts.map +1 -0
- package/dist/chatPresentation.js +118 -0
- package/dist/chatPresentation.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -1
- package/dist/helpers.d.ts +20 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +64 -0
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/mcpUrl.d.ts +19 -0
- package/dist/mcpUrl.d.ts.map +1 -0
- package/dist/mcpUrl.js +51 -0
- package/dist/mcpUrl.js.map +1 -0
- package/dist/messageView.d.ts +156 -0
- package/dist/messageView.d.ts.map +1 -0
- package/dist/messageView.js +29 -0
- package/dist/messageView.js.map +1 -0
- package/dist/schemas.d.ts +654 -37
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +121 -1
- package/dist/schemas.js.map +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @winmatrix/protocol — 统一 Agent Engine Runtime Gateway DTO。
|
|
3
|
+
*
|
|
4
|
+
* 本文件是 server-pod 与 external-computer 共用的 Agent Engine 调用契约:
|
|
5
|
+
* V1/V2 调用计划、canonical LaunchSpec、Run/Session/Event Subscription 资源模型、
|
|
6
|
+
* 可重连事件 Envelope、交互回复、Engine/模型/option 发现与 Host wire DTO。
|
|
7
|
+
*
|
|
8
|
+
* 安全边界:
|
|
9
|
+
* - EngineInvocationPlan / EngineLaunchSpec / EngineOptionCatalog 属于公共 DTO,
|
|
10
|
+
* MUST NOT 包含 callback token、credential、dynamic secret、Hook ID/config、
|
|
11
|
+
* command、modulePath、script 或远程 URL。
|
|
12
|
+
* - ExternalTaskSecretBindings 是协议显式定义的 sensitive envelope,
|
|
13
|
+
* 其字段值禁止进入日志、持久化 metadata、trace、fingerprint 与事件。
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { EngineFinalResultSchema, EngineHookProfileDescriptorSchema, EngineHookProfileRefSchema, EngineIdSchema, EngineInteractionOptionSchema, EngineInvocationPlanV1Schema, EngineProgressEventSchema, EngineToolNameSchema, EventRetentionSchema, EventStreamModeSchema, ExecutionDurabilitySchema, HostKindSchema, HostProfileSchema, TaskAssignParamsSchema, } from './schemas.js';
|
|
17
|
+
/* ── 结构化输入 ── */
|
|
18
|
+
/**
|
|
19
|
+
* startRun() 的初始输入 block。image/file 必须使用经授权的 artifact/resource
|
|
20
|
+
* reference,不得接受调用方机器的任意绝对路径。
|
|
21
|
+
*/
|
|
22
|
+
export const EngineContentBlockSchema = z.discriminatedUnion('kind', [
|
|
23
|
+
z.object({
|
|
24
|
+
kind: z.literal('text'),
|
|
25
|
+
text: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
z.object({
|
|
28
|
+
kind: z.literal('image_ref'),
|
|
29
|
+
artifactRef: z.string().min(1),
|
|
30
|
+
mimeType: z.string().min(1),
|
|
31
|
+
}),
|
|
32
|
+
z.object({
|
|
33
|
+
kind: z.literal('file_ref'),
|
|
34
|
+
artifactRef: z.string().min(1),
|
|
35
|
+
name: z.string().optional(),
|
|
36
|
+
mimeType: z.string().optional(),
|
|
37
|
+
}),
|
|
38
|
+
z.object({
|
|
39
|
+
kind: z.literal('resource_ref'),
|
|
40
|
+
uri: z.string().min(1),
|
|
41
|
+
mimeType: z.string().optional(),
|
|
42
|
+
}),
|
|
43
|
+
]);
|
|
44
|
+
/** 调用方选择的 Engine mode/config;随 startRun() 原子提交。不得包含敏感配置键。 */
|
|
45
|
+
export const EngineOptionSelectionSchema = z.object({
|
|
46
|
+
modeId: z.string().min(1).optional(),
|
|
47
|
+
values: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(),
|
|
48
|
+
});
|
|
49
|
+
/* ── 稳定身份:Instance / Session / Run ── */
|
|
50
|
+
/** 跨 Run 稳定的执行实例引用。 */
|
|
51
|
+
export const ExecutionInstanceRefSchema = z.object({
|
|
52
|
+
instanceId: z.string().min(1),
|
|
53
|
+
hostKind: HostKindSchema,
|
|
54
|
+
});
|
|
55
|
+
/** Run provenance:冻结本次执行环境版本,用于历史解释、漂移检测与计量归因。 */
|
|
56
|
+
export const RunExecutionSnapshotSchema = z.object({
|
|
57
|
+
hostProfile: HostProfileSchema.optional(),
|
|
58
|
+
digitalEmployeeId: z.string().optional(),
|
|
59
|
+
projectId: z.string().optional(),
|
|
60
|
+
configurationRevision: z.string().optional(),
|
|
61
|
+
imageDigest: z.string().optional(),
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Engine 原生 Session 稳定身份。只使用 stable instance + engineId + sessionId;
|
|
65
|
+
* configurationRevision、imageDigest、项目和员工归属属于 Run provenance 或授权范围,
|
|
66
|
+
* 不进入 Session 身份。
|
|
67
|
+
*/
|
|
68
|
+
export const AgentEngineSessionRefSchema = z.object({
|
|
69
|
+
instance: ExecutionInstanceRefSchema,
|
|
70
|
+
engineId: EngineIdSchema,
|
|
71
|
+
sessionId: z.string().min(1),
|
|
72
|
+
});
|
|
73
|
+
/** Session binding:继续历史会话 SHALL 通过 startRun() 的 resume/fork 创建新 Run。 */
|
|
74
|
+
export const EngineSessionBindingSchema = z.discriminatedUnion('mode', [
|
|
75
|
+
z.object({ mode: z.literal('ephemeral') }),
|
|
76
|
+
z.object({ mode: z.literal('new') }),
|
|
77
|
+
z.object({
|
|
78
|
+
mode: z.literal('resume'),
|
|
79
|
+
session: AgentEngineSessionRefSchema,
|
|
80
|
+
}),
|
|
81
|
+
z.object({
|
|
82
|
+
mode: z.literal('fork'),
|
|
83
|
+
session: AgentEngineSessionRefSchema,
|
|
84
|
+
}),
|
|
85
|
+
]);
|
|
86
|
+
/** 一次不可变执行的稳定身份;Server 重启后仅凭该 Ref 恢复 getRunStatus/watchRun/cancelRun。 */
|
|
87
|
+
export const AgentEngineRunRefSchema = z.object({
|
|
88
|
+
instance: ExecutionInstanceRefSchema,
|
|
89
|
+
executionSnapshot: RunExecutionSnapshotSchema,
|
|
90
|
+
runKey: z.string().min(1),
|
|
91
|
+
engineId: EngineIdSchema,
|
|
92
|
+
invocationFingerprint: z.string().min(1),
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* 两阶段启动的持久化记录:只包含完整 RunRef、launchSpecRef 与 preparedAt,
|
|
96
|
+
* 不得包含 prompt 副本或 control binding secret。
|
|
97
|
+
*/
|
|
98
|
+
export const PreparedRunRecordSchema = z.object({
|
|
99
|
+
ref: AgentEngineRunRefSchema,
|
|
100
|
+
launchSpecRef: z.string().min(1),
|
|
101
|
+
preparedAt: z.string().min(1),
|
|
102
|
+
});
|
|
103
|
+
/* ── Context budget(adapter 入口 last-mile 压缩配置) ── */
|
|
104
|
+
export const ContextCompressionModeSchema = z.enum(['none', 'truncate_head', 'truncate_tail']);
|
|
105
|
+
export const ContextBudgetSchema = z.object({
|
|
106
|
+
/** 当前 turn 输入文本的最大字符数(不含 systemPrompt)。 */
|
|
107
|
+
maxInputChars: z.number().int().positive().optional(),
|
|
108
|
+
/** systemPrompt 的最大字符数。 */
|
|
109
|
+
maxSystemChars: z.number().int().positive().optional(),
|
|
110
|
+
/** input + systemPrompt 的总字符数上限;优先压缩 input,必要时再压缩 systemPrompt。 */
|
|
111
|
+
maxContextChars: z.number().int().positive().optional(),
|
|
112
|
+
/** 压缩/截断模式;缺省由 adapter 按 'truncate_head' 处理(body-first)。 */
|
|
113
|
+
compression: ContextCompressionModeSchema.optional(),
|
|
114
|
+
});
|
|
115
|
+
/* ── V2 调用计划与 canonical LaunchSpec ── */
|
|
116
|
+
/**
|
|
117
|
+
* V2 调用计划:结构化 blocks、model、permission、engineOptions 与 Session binding。
|
|
118
|
+
* 公共请求 DTO,MUST NOT 包含 Hook 字段、callback 或 secret。
|
|
119
|
+
*/
|
|
120
|
+
export const EngineInvocationPlanV2Schema = z.object({
|
|
121
|
+
schemaVersion: z.literal(2),
|
|
122
|
+
taskId: z.string().min(1),
|
|
123
|
+
engineId: EngineIdSchema,
|
|
124
|
+
hostKind: HostKindSchema,
|
|
125
|
+
hostProfile: HostProfileSchema.optional(),
|
|
126
|
+
toolName: EngineToolNameSchema,
|
|
127
|
+
input: z.object({
|
|
128
|
+
blocks: z.array(EngineContentBlockSchema).min(1),
|
|
129
|
+
}),
|
|
130
|
+
model: z
|
|
131
|
+
.object({
|
|
132
|
+
modelId: z.string().min(1),
|
|
133
|
+
reasoningEffort: z.string().min(1).optional(),
|
|
134
|
+
})
|
|
135
|
+
.optional(),
|
|
136
|
+
permissionMode: z.string().min(1).optional(),
|
|
137
|
+
engineOptions: EngineOptionSelectionSchema.optional(),
|
|
138
|
+
/** 非敏感系统提示词(每次 Run 随 plan 原子提交);secret 走 Host 私有 binding。 */
|
|
139
|
+
systemPrompt: z.string().optional(),
|
|
140
|
+
workDir: z.string().optional(),
|
|
141
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
142
|
+
/** 仅允许非敏感、可序列化配置;secret 走 Host 私有 binding。 */
|
|
143
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
144
|
+
allowedTools: z.array(z.string()).optional(),
|
|
145
|
+
session: EngineSessionBindingSchema.optional(),
|
|
146
|
+
artifactPolicy: z.record(z.string(), z.unknown()).optional(),
|
|
147
|
+
/** 当前 turn 上下文预算;adapter 在入口对 input + systemPrompt 做 last-mile 截断。 */
|
|
148
|
+
contextBudget: ContextBudgetSchema.optional(),
|
|
149
|
+
});
|
|
150
|
+
/** V1/V2 compatibility union parser;Gateway canonicalizer 统一输出 V2。 */
|
|
151
|
+
export const EngineInvocationPlanSchema = z.union([
|
|
152
|
+
EngineInvocationPlanV2Schema,
|
|
153
|
+
EngineInvocationPlanV1Schema,
|
|
154
|
+
]);
|
|
155
|
+
/** 边界兼容 parser:接受 V1 或 V2,不做语义重解释。 */
|
|
156
|
+
export function parseEngineInvocationPlan(input) {
|
|
157
|
+
return EngineInvocationPlanSchema.parse(input);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* V1→V2 canonicalizer:字符串 input 确定性转换为单个 text block;
|
|
161
|
+
* V1 sessionId+resume 映射为 resume/fork 之外的 Session binding 需要 instance 上下文。
|
|
162
|
+
*/
|
|
163
|
+
export function normalizeEngineInvocationPlanToV2(plan, context = {}) {
|
|
164
|
+
if ('schemaVersion' in plan && plan.schemaVersion === 2) {
|
|
165
|
+
return plan;
|
|
166
|
+
}
|
|
167
|
+
const v1 = plan;
|
|
168
|
+
let session;
|
|
169
|
+
if (v1.sessionId) {
|
|
170
|
+
if (!context.instance) {
|
|
171
|
+
throw new Error('normalizeEngineInvocationPlanToV2: V1 sessionId 需要 instance 上下文才能构造 SessionRef');
|
|
172
|
+
}
|
|
173
|
+
session = {
|
|
174
|
+
mode: 'resume',
|
|
175
|
+
session: {
|
|
176
|
+
instance: context.instance,
|
|
177
|
+
engineId: v1.engineId,
|
|
178
|
+
sessionId: v1.sessionId,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
schemaVersion: 2,
|
|
184
|
+
taskId: v1.taskId,
|
|
185
|
+
engineId: v1.engineId,
|
|
186
|
+
hostKind: v1.hostKind,
|
|
187
|
+
...(v1.hostProfile ? { hostProfile: v1.hostProfile } : {}),
|
|
188
|
+
toolName: v1.toolName,
|
|
189
|
+
input: { blocks: [{ kind: 'text', text: v1.input }] },
|
|
190
|
+
...(v1.workDir ? { workDir: v1.workDir } : {}),
|
|
191
|
+
...(v1.timeoutMs != null ? { timeoutMs: v1.timeoutMs } : {}),
|
|
192
|
+
...(v1.env ? { env: v1.env } : {}),
|
|
193
|
+
...(v1.allowedTools ? { allowedTools: v1.allowedTools } : {}),
|
|
194
|
+
...(session ? { session } : {}),
|
|
195
|
+
...(v1.artifactPolicy ? { artifactPolicy: v1.artifactPolicy } : {}),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Host-neutral canonical 启动描述:默认值已展开、确定性排序/去重、
|
|
200
|
+
* 剥离仅用于业务审计的字段。fingerprint 只对该 spec 的非敏感字段计算。
|
|
201
|
+
* MUST NOT 包含 Pod argv、Sandbox command、External RPC frame、callback 或 secret。
|
|
202
|
+
*/
|
|
203
|
+
export const EngineLaunchSpecSchema = z.object({
|
|
204
|
+
schemaVersion: z.number().int().positive(),
|
|
205
|
+
engineId: EngineIdSchema,
|
|
206
|
+
hostKind: HostKindSchema,
|
|
207
|
+
input: z.object({
|
|
208
|
+
blocks: z.array(EngineContentBlockSchema).min(1),
|
|
209
|
+
}),
|
|
210
|
+
model: z
|
|
211
|
+
.object({
|
|
212
|
+
modelId: z.string().min(1),
|
|
213
|
+
reasoningEffort: z.string().min(1).optional(),
|
|
214
|
+
})
|
|
215
|
+
.optional(),
|
|
216
|
+
permissionMode: z.string().min(1).optional(),
|
|
217
|
+
engineOptions: EngineOptionSelectionSchema.optional(),
|
|
218
|
+
/** 非敏感系统提示词;参与 fingerprint,fingerprint 后不得修改。 */
|
|
219
|
+
systemPrompt: z.string().optional(),
|
|
220
|
+
workDir: z.string().optional(),
|
|
221
|
+
timeoutMs: z.number().int().positive(),
|
|
222
|
+
allowedTools: z.array(z.string()),
|
|
223
|
+
session: EngineSessionBindingSchema,
|
|
224
|
+
/** 内部受治理 Profile;按 profileId/version 确定性排序去重,参与 fingerprint。 */
|
|
225
|
+
engineHookProfiles: z.array(EngineHookProfileRefSchema),
|
|
226
|
+
nonSensitiveEnv: z.record(z.string(), z.string()),
|
|
227
|
+
artifactPolicy: z.record(z.string(), z.unknown()),
|
|
228
|
+
/** 当前 turn 上下文预算;参与 fingerprint,fingerprint 后不得修改。 */
|
|
229
|
+
contextBudget: ContextBudgetSchema.optional(),
|
|
230
|
+
});
|
|
231
|
+
/* ── Sensitive Run control bindings(external-computer) ── */
|
|
232
|
+
/**
|
|
233
|
+
* SENSITIVE:external-computer 只允许短期、Run-scoped 的 capability token 与
|
|
234
|
+
* 无明文 credential reference;禁止任意 secret map。
|
|
235
|
+
* 字段值禁止进入日志、持久化 metadata、trace、fingerprint、事件与 Run 文件。
|
|
236
|
+
*/
|
|
237
|
+
export const ExternalTaskSecretBindingsSchema = z.object({
|
|
238
|
+
mcpCapabilityToken: z.string().min(1).optional(),
|
|
239
|
+
credentialReferences: z.array(z.string().min(1)).optional(),
|
|
240
|
+
});
|
|
241
|
+
/* ── 交互与取消 DTO ── */
|
|
242
|
+
export const EngineRunErrorSchema = z.object({
|
|
243
|
+
code: z.string().min(1),
|
|
244
|
+
message: z.string(),
|
|
245
|
+
retryable: z.boolean().optional(),
|
|
246
|
+
});
|
|
247
|
+
export const EngineInteractionRequestSchema = z.object({
|
|
248
|
+
interactionId: z.string().min(1),
|
|
249
|
+
interactionType: z.enum(['permission', 'confirmation', 'question', 'selection']),
|
|
250
|
+
/** 最小必要的用户决策说明;权限请求只传用户决策所需的摘要。 */
|
|
251
|
+
prompt: z.string(),
|
|
252
|
+
options: z.array(EngineInteractionOptionSchema),
|
|
253
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
254
|
+
});
|
|
255
|
+
/** 交互回复:responseId 幂等,interactionId 关联请求;不重复携带 instance/runKey。 */
|
|
256
|
+
export const EngineInteractionResponseSchema = z.object({
|
|
257
|
+
responseId: z.string().min(1),
|
|
258
|
+
interactionId: z.string().min(1),
|
|
259
|
+
answer: z.discriminatedUnion('kind', [
|
|
260
|
+
z.object({
|
|
261
|
+
kind: z.literal('option'),
|
|
262
|
+
optionId: z.string().min(1),
|
|
263
|
+
}),
|
|
264
|
+
z.object({
|
|
265
|
+
kind: z.literal('text'),
|
|
266
|
+
text: z.string(),
|
|
267
|
+
}),
|
|
268
|
+
]),
|
|
269
|
+
});
|
|
270
|
+
export const EngineInteractionReceiptSchema = z.object({
|
|
271
|
+
status: z.enum(['accepted', 'duplicate', 'rejected']),
|
|
272
|
+
responseId: z.string().min(1),
|
|
273
|
+
interactionId: z.string().min(1),
|
|
274
|
+
error: EngineRunErrorSchema.optional(),
|
|
275
|
+
});
|
|
276
|
+
export const EngineCancelRequestSchema = z.object({
|
|
277
|
+
requestId: z.string().min(1).optional(),
|
|
278
|
+
reason: z.string().optional(),
|
|
279
|
+
});
|
|
280
|
+
export const EngineCancelReceiptSchema = z.object({
|
|
281
|
+
status: z.enum(['accepted', 'duplicate', 'already_terminal', 'rejected']),
|
|
282
|
+
error: EngineRunErrorSchema.optional(),
|
|
283
|
+
});
|
|
284
|
+
/* ── 事件 Envelope 与 Run 快照 ── */
|
|
285
|
+
/**
|
|
286
|
+
* Host 标准化后的统一事件 Envelope。Supervisor 或 daemon Run Registry 分配
|
|
287
|
+
* 单调递增 sequence;Gateway 只校验 runKey/engineId/fingerprint/sequence,
|
|
288
|
+
* 不解释 Engine 私有 frame。
|
|
289
|
+
*/
|
|
290
|
+
export const EngineEventEnvelopeSchema = z.object({
|
|
291
|
+
runKey: z.string().min(1),
|
|
292
|
+
engineId: EngineIdSchema,
|
|
293
|
+
invocationFingerprint: z.string().min(1),
|
|
294
|
+
sequence: z.number().int().positive(),
|
|
295
|
+
timestamp: z.string().min(1),
|
|
296
|
+
event: EngineProgressEventSchema,
|
|
297
|
+
});
|
|
298
|
+
export const EngineRunStatusSchema = z.enum([
|
|
299
|
+
'accepted',
|
|
300
|
+
'starting',
|
|
301
|
+
'running',
|
|
302
|
+
'waiting_interaction',
|
|
303
|
+
'cancel_requested',
|
|
304
|
+
'completed',
|
|
305
|
+
'failed',
|
|
306
|
+
'cancelled',
|
|
307
|
+
'interrupted',
|
|
308
|
+
]);
|
|
309
|
+
/** Host launch ack:只表达 accepted/existing,并返回本次实际协商的运行属性。 */
|
|
310
|
+
export const HostLaunchAckSchema = z.object({
|
|
311
|
+
disposition: z.enum(['accepted', 'existing']),
|
|
312
|
+
ref: AgentEngineRunRefSchema,
|
|
313
|
+
sessionRef: AgentEngineSessionRefSchema.optional(),
|
|
314
|
+
executionDurability: ExecutionDurabilitySchema,
|
|
315
|
+
eventStreamMode: EventStreamModeSchema,
|
|
316
|
+
eventRetention: EventRetentionSchema.optional(),
|
|
317
|
+
runtimeVersion: z.string().optional(),
|
|
318
|
+
protocolVersion: z.string().optional(),
|
|
319
|
+
});
|
|
320
|
+
/** 单次 Run 的一致快照;业务恢复语义只能使用该 Run 级快照。 */
|
|
321
|
+
export const EngineRunSnapshotSchema = z.object({
|
|
322
|
+
ref: AgentEngineRunRefSchema,
|
|
323
|
+
sessionRef: AgentEngineSessionRefSchema.optional(),
|
|
324
|
+
status: EngineRunStatusSchema,
|
|
325
|
+
executionDurability: ExecutionDurabilitySchema,
|
|
326
|
+
eventStreamMode: EventStreamModeSchema,
|
|
327
|
+
eventRetention: EventRetentionSchema.optional(),
|
|
328
|
+
lastSequence: z.number().int().nonnegative(),
|
|
329
|
+
pendingInteractions: z.array(EngineInteractionRequestSchema),
|
|
330
|
+
result: EngineFinalResultSchema.optional(),
|
|
331
|
+
recoverable: z.boolean(),
|
|
332
|
+
runtimeVersion: z.string().optional(),
|
|
333
|
+
protocolVersion: z.string().optional(),
|
|
334
|
+
});
|
|
335
|
+
/** Host wire:活动 Run 分页。 */
|
|
336
|
+
export const ActiveRunListQuerySchema = z.object({
|
|
337
|
+
cursor: z.string().optional(),
|
|
338
|
+
limit: z.number().int().positive(),
|
|
339
|
+
engineId: EngineIdSchema.optional(),
|
|
340
|
+
});
|
|
341
|
+
export const ActiveRunSummarySchema = z.object({
|
|
342
|
+
ref: AgentEngineRunRefSchema,
|
|
343
|
+
sessionRef: AgentEngineSessionRefSchema.optional(),
|
|
344
|
+
status: z.enum(['accepted', 'starting', 'running', 'waiting_interaction', 'cancel_requested']),
|
|
345
|
+
startedAt: z.string().optional(),
|
|
346
|
+
lastSequence: z.number().int().nonnegative(),
|
|
347
|
+
pendingInteractionCount: z.number().int().nonnegative(),
|
|
348
|
+
});
|
|
349
|
+
export const ActiveRunPageSchema = z.object({
|
|
350
|
+
runs: z.array(ActiveRunSummarySchema),
|
|
351
|
+
nextCursor: z.string().optional(),
|
|
352
|
+
});
|
|
353
|
+
/* ── Engine 原生 Session 数据面 ── */
|
|
354
|
+
export const EngineSessionProjectScopeSchema = z.object({
|
|
355
|
+
projectId: z.string().optional(),
|
|
356
|
+
normalizedWorkDir: z.string().optional(),
|
|
357
|
+
});
|
|
358
|
+
export const EngineSessionListQuerySchema = z.object({
|
|
359
|
+
cursor: z.string().optional(),
|
|
360
|
+
limit: z.number().int().positive(),
|
|
361
|
+
projectScope: EngineSessionProjectScopeSchema.optional(),
|
|
362
|
+
});
|
|
363
|
+
export const EngineSessionHistoryQuerySchema = z.object({
|
|
364
|
+
cursor: z.string().optional(),
|
|
365
|
+
limit: z.number().int().positive(),
|
|
366
|
+
/** 定位 Engine 原生 Session 所需的项目/工作目录范围(语义=SDK 的 dir=projectPath,非 HOME)。 */
|
|
367
|
+
projectScope: EngineSessionProjectScopeSchema.optional(),
|
|
368
|
+
/** 需要额外授权与显式 opt-in;响应仍必须深度 redaction。 */
|
|
369
|
+
includeRawMessages: z.boolean().optional(),
|
|
370
|
+
/**
|
|
371
|
+
* 以下两项为 workstation-only 诊断选项(task 7.15):external Host 忽略,
|
|
372
|
+
* workstation Host 透传给 Pod CLI 用于富诊断输出。
|
|
373
|
+
* - includeSystem:是否纳入 system/summary 消息。
|
|
374
|
+
* - noTruncate:是否禁止截断长消息(用于 diagnostics 全量回放)。
|
|
375
|
+
*/
|
|
376
|
+
includeSystem: z.boolean().optional(),
|
|
377
|
+
noTruncate: z.boolean().optional(),
|
|
378
|
+
/** 是否只返回 session 元数据,跳过消息体(用于初始详情加载,避免大 payload 触发 sandbox stdout 截断)。 */
|
|
379
|
+
noMessages: z.boolean().optional(),
|
|
380
|
+
/**
|
|
381
|
+
* 是否返回拼接文本格式的消息(user/assistant 交替文本),替代结构化 messages[]。
|
|
382
|
+
* 体积远小于结构化 messages[],可避免大会话触发 sandbox stdout 截断,
|
|
383
|
+
* 同时前端仍能获得完整对话文本。
|
|
384
|
+
*/
|
|
385
|
+
joinedMessages: z.boolean().optional(),
|
|
386
|
+
});
|
|
387
|
+
export const EngineSessionSearchQuerySchema = z.object({
|
|
388
|
+
text: z.string().min(1),
|
|
389
|
+
cursor: z.string().optional(),
|
|
390
|
+
limit: z.number().int().positive(),
|
|
391
|
+
projectScope: EngineSessionProjectScopeSchema.optional(),
|
|
392
|
+
});
|
|
393
|
+
export const EngineSessionMessageSchema = z.object({
|
|
394
|
+
messageId: z.string().optional(),
|
|
395
|
+
role: z.enum(['user', 'assistant', 'system', 'tool', 'unknown']),
|
|
396
|
+
content: z.array(EngineContentBlockSchema),
|
|
397
|
+
timestamp: z.string().optional(),
|
|
398
|
+
redacted: z.boolean(),
|
|
399
|
+
});
|
|
400
|
+
export const EngineSessionSummarySchema = z.object({
|
|
401
|
+
ref: AgentEngineSessionRefSchema,
|
|
402
|
+
/** Engine 原生 Session 与 WinMatrix 产品会话使用不同身份与来源标识。 */
|
|
403
|
+
source: z.literal('engine_native'),
|
|
404
|
+
title: z.string().optional(),
|
|
405
|
+
projectId: z.string().optional(),
|
|
406
|
+
workDir: z.string().optional(),
|
|
407
|
+
createdAt: z.string().optional(),
|
|
408
|
+
lastActivityAt: z.string().optional(),
|
|
409
|
+
messageCount: z.number().int().nonnegative().optional(),
|
|
410
|
+
});
|
|
411
|
+
export const EngineSessionPageSchema = z.object({
|
|
412
|
+
sessions: z.array(EngineSessionSummarySchema),
|
|
413
|
+
nextCursor: z.string().optional(),
|
|
414
|
+
});
|
|
415
|
+
export const EngineSessionDetailSchema = z.object({
|
|
416
|
+
session: EngineSessionSummarySchema,
|
|
417
|
+
messages: z.array(EngineSessionMessageSchema),
|
|
418
|
+
/**
|
|
419
|
+
* 拼接文本格式的消息正文(user/assistant 交替文本)。
|
|
420
|
+
* 仅当 history query 的 joinedMessages=true 时由 Pod CLI 返回,
|
|
421
|
+
* 此时 messages 为空数组(schema 必填),正文走本字段以规避 stdout 截断。
|
|
422
|
+
*/
|
|
423
|
+
joinedMessages: z.string().optional(),
|
|
424
|
+
nextCursor: z.string().optional(),
|
|
425
|
+
rawMessagesIncluded: z.boolean(),
|
|
426
|
+
});
|
|
427
|
+
export const EngineSessionSearchHitSchema = z.object({
|
|
428
|
+
session: EngineSessionSummarySchema,
|
|
429
|
+
matches: z.array(z.object({
|
|
430
|
+
messageId: z.string().optional(),
|
|
431
|
+
snippet: z.string(),
|
|
432
|
+
timestamp: z.string().optional(),
|
|
433
|
+
})),
|
|
434
|
+
});
|
|
435
|
+
export const EngineSessionSearchPageSchema = z.object({
|
|
436
|
+
hits: z.array(EngineSessionSearchHitSchema),
|
|
437
|
+
nextCursor: z.string().optional(),
|
|
438
|
+
});
|
|
439
|
+
export const EngineSessionDeleteRequestSchema = z.object({
|
|
440
|
+
requestId: z.string().min(1),
|
|
441
|
+
});
|
|
442
|
+
export const EngineSessionDeleteReceiptSchema = z.object({
|
|
443
|
+
status: z.enum(['deleted', 'already_deleted', 'rejected']),
|
|
444
|
+
error: EngineRunErrorSchema.optional(),
|
|
445
|
+
});
|
|
446
|
+
/* ── Engine / 模型 / option 发现 ── */
|
|
447
|
+
export const EngineListQuerySchema = z.object({
|
|
448
|
+
cursor: z.string().optional(),
|
|
449
|
+
limit: z.number().int().positive(),
|
|
450
|
+
});
|
|
451
|
+
export const EngineInstanceSummarySchema = z.object({
|
|
452
|
+
engineId: EngineIdSchema,
|
|
453
|
+
label: z.string().optional(),
|
|
454
|
+
availability: z.enum(['ready', 'unavailable', 'unknown']),
|
|
455
|
+
version: z.string().optional(),
|
|
456
|
+
});
|
|
457
|
+
export const EnginePageSchema = z.object({
|
|
458
|
+
engines: z.array(EngineInstanceSummarySchema),
|
|
459
|
+
nextCursor: z.string().optional(),
|
|
460
|
+
});
|
|
461
|
+
export const EngineModelListQuerySchema = z.object({
|
|
462
|
+
cursor: z.string().optional(),
|
|
463
|
+
limit: z.number().int().positive(),
|
|
464
|
+
});
|
|
465
|
+
export const EngineModelDescriptorSchema = z.object({
|
|
466
|
+
modelId: z.string().min(1),
|
|
467
|
+
label: z.string().optional(),
|
|
468
|
+
isDefault: z.boolean(),
|
|
469
|
+
reasoningEfforts: z.array(z.string()).optional(),
|
|
470
|
+
contextWindow: z.number().int().positive().optional(),
|
|
471
|
+
});
|
|
472
|
+
export const EngineModelPageSchema = z.object({
|
|
473
|
+
models: z.array(EngineModelDescriptorSchema),
|
|
474
|
+
nextCursor: z.string().optional(),
|
|
475
|
+
});
|
|
476
|
+
/**
|
|
477
|
+
* Engine 实际提供的 mode、config options 与 slash commands。
|
|
478
|
+
* MUST NOT 暴露系统 Hook Profile、Hook config 或 Hook 实现。
|
|
479
|
+
*/
|
|
480
|
+
export const EngineOptionCatalogSchema = z.object({
|
|
481
|
+
engineId: EngineIdSchema,
|
|
482
|
+
modes: z.array(z.object({
|
|
483
|
+
modeId: z.string().min(1),
|
|
484
|
+
label: z.string(),
|
|
485
|
+
description: z.string().optional(),
|
|
486
|
+
isDefault: z.boolean(),
|
|
487
|
+
})),
|
|
488
|
+
configOptions: z.array(z.object({
|
|
489
|
+
optionId: z.string().min(1),
|
|
490
|
+
label: z.string(),
|
|
491
|
+
valueType: z.enum(['select', 'boolean', 'string', 'number']),
|
|
492
|
+
currentValue: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
|
493
|
+
allowedValues: z
|
|
494
|
+
.array(z.object({
|
|
495
|
+
value: z.string(),
|
|
496
|
+
label: z.string(),
|
|
497
|
+
}))
|
|
498
|
+
.optional(),
|
|
499
|
+
})),
|
|
500
|
+
commands: z.array(z.object({
|
|
501
|
+
command: z.string().min(1),
|
|
502
|
+
description: z.string().optional(),
|
|
503
|
+
inputHint: z.string().optional(),
|
|
504
|
+
})),
|
|
505
|
+
checkedAt: z.string().min(1),
|
|
506
|
+
});
|
|
507
|
+
/* ── 分层运行诊断 ── */
|
|
508
|
+
export const EngineReadinessIssueSchema = z.object({
|
|
509
|
+
code: z.string().min(1),
|
|
510
|
+
message: z.string(),
|
|
511
|
+
});
|
|
512
|
+
export const EngineReadinessSnapshotSchema = z.object({
|
|
513
|
+
engineId: EngineIdSchema,
|
|
514
|
+
instanceId: z.string().min(1),
|
|
515
|
+
hostKind: HostKindSchema,
|
|
516
|
+
checkedAt: z.string().min(1),
|
|
517
|
+
status: z.enum(['ready', 'degraded', 'unavailable']),
|
|
518
|
+
binaryStatus: z.enum(['found', 'missing', 'unsupported_version']),
|
|
519
|
+
credentialStatus: z.enum(['ready', 'missing', 'invalid', 'not_required', 'unknown']),
|
|
520
|
+
version: z.string().optional(),
|
|
521
|
+
issues: z.array(EngineReadinessIssueSchema),
|
|
522
|
+
});
|
|
523
|
+
export const HostHealthIssueSchema = z.object({
|
|
524
|
+
code: z.string().min(1),
|
|
525
|
+
message: z.string(),
|
|
526
|
+
});
|
|
527
|
+
const HostHealthSnapshotBaseSchema = z.object({
|
|
528
|
+
instanceId: z.string().min(1),
|
|
529
|
+
checkedAt: z.string().min(1),
|
|
530
|
+
status: z.enum(['healthy', 'degraded', 'unreachable']),
|
|
531
|
+
transportReady: z.boolean(),
|
|
532
|
+
latencyMs: z.number().nonnegative().optional(),
|
|
533
|
+
runtimeVersion: z.string().optional(),
|
|
534
|
+
protocolVersion: z.string().optional(),
|
|
535
|
+
configurationRevision: z.string().optional(),
|
|
536
|
+
imageDigest: z.string().optional(),
|
|
537
|
+
issues: z.array(HostHealthIssueSchema),
|
|
538
|
+
});
|
|
539
|
+
export const HostHealthSnapshotSchema = z.discriminatedUnion('hostKind', [
|
|
540
|
+
HostHealthSnapshotBaseSchema.extend({
|
|
541
|
+
hostKind: z.literal('workstation'),
|
|
542
|
+
sandboxApiReachable: z.boolean(),
|
|
543
|
+
podReady: z.boolean(),
|
|
544
|
+
supervisorReachable: z.boolean(),
|
|
545
|
+
mountReady: z.boolean().optional(),
|
|
546
|
+
}),
|
|
547
|
+
HostHealthSnapshotBaseSchema.extend({
|
|
548
|
+
hostKind: z.literal('external_computer'),
|
|
549
|
+
ownerResolved: z.boolean(),
|
|
550
|
+
connectionReady: z.boolean(),
|
|
551
|
+
heartbeatFresh: z.boolean(),
|
|
552
|
+
daemonReady: z.boolean(),
|
|
553
|
+
}),
|
|
554
|
+
]);
|
|
555
|
+
/* ── Host wire DTO(Server ↔ Sandbox API / daemon) ── */
|
|
556
|
+
/** SENSITIVE:server-pod 私有 binding;callback token/dynamic secret 禁止日志与持久化。 */
|
|
557
|
+
export const WorkstationRunPrivateBindingsSchema = z.object({
|
|
558
|
+
hostKind: z.literal('workstation'),
|
|
559
|
+
callback: z
|
|
560
|
+
.object({
|
|
561
|
+
url: z.string().min(1),
|
|
562
|
+
token: z.string().min(1),
|
|
563
|
+
})
|
|
564
|
+
.optional(),
|
|
565
|
+
dynamicSecrets: z.record(z.string(), z.string()).optional(),
|
|
566
|
+
});
|
|
567
|
+
/** SENSITIVE:external-computer 私有 binding;只允许协议定义的 sensitive envelope。 */
|
|
568
|
+
export const ExternalRunPrivateBindingsSchema = z.object({
|
|
569
|
+
hostKind: z.literal('external_computer'),
|
|
570
|
+
secrets: ExternalTaskSecretBindingsSchema.optional(),
|
|
571
|
+
});
|
|
572
|
+
export const EngineRunPrivateBindingsSchema = z.discriminatedUnion('hostKind', [
|
|
573
|
+
WorkstationRunPrivateBindingsSchema,
|
|
574
|
+
ExternalRunPrivateBindingsSchema,
|
|
575
|
+
]);
|
|
576
|
+
/**
|
|
577
|
+
* Host launch request:canonical LaunchSpec 与本次 Run 的私有 binding 分字段承载。
|
|
578
|
+
* 非敏感 payload 走 argv/结构化字段;sensitive binding 走 stdin/Unix socket frame
|
|
579
|
+
* 或协议 sensitive envelope,禁止写入 argv、普通事件或临时文件。
|
|
580
|
+
*/
|
|
581
|
+
export const HostLaunchRequestSchema = z.object({
|
|
582
|
+
runKey: z.string().min(1),
|
|
583
|
+
invocationFingerprint: z.string().min(1),
|
|
584
|
+
launchSpec: EngineLaunchSpecSchema,
|
|
585
|
+
privateBindings: EngineRunPrivateBindingsSchema.optional(),
|
|
586
|
+
});
|
|
587
|
+
/* ── External Agent 新版 method params / event payload ── */
|
|
588
|
+
/** task.assign additive 扩展:runKey/fingerprint/Host-neutral LaunchSpec/sensitive envelope。 */
|
|
589
|
+
export const TaskAssignParamsV2Schema = TaskAssignParamsSchema.extend({
|
|
590
|
+
runKey: z.string().min(1).optional(),
|
|
591
|
+
invocationFingerprint: z.string().min(1).optional(),
|
|
592
|
+
launchSpec: EngineLaunchSpecSchema.optional(),
|
|
593
|
+
/** SENSITIVE:旧 mcpToken 仅兼容映射到 secretBindings.mcpCapabilityToken。 */
|
|
594
|
+
secretBindings: ExternalTaskSecretBindingsSchema.optional(),
|
|
595
|
+
});
|
|
596
|
+
export const TaskEventsSubscribeParamsSchema = z.object({
|
|
597
|
+
runKey: z.string().min(1),
|
|
598
|
+
afterSequence: z.number().int().nonnegative().optional(),
|
|
599
|
+
});
|
|
600
|
+
export const TaskInspectParamsSchema = z.object({
|
|
601
|
+
runKey: z.string().min(1),
|
|
602
|
+
});
|
|
603
|
+
export const TaskInteractionRespondParamsSchema = z.object({
|
|
604
|
+
runKey: z.string().min(1),
|
|
605
|
+
response: EngineInteractionResponseSchema,
|
|
606
|
+
});
|
|
607
|
+
export const TaskCancelRunParamsSchema = z.object({
|
|
608
|
+
runKey: z.string().min(1),
|
|
609
|
+
reason: z.string().optional(),
|
|
610
|
+
});
|
|
611
|
+
export const TaskActiveListParamsSchema = ActiveRunListQuerySchema.partial();
|
|
612
|
+
export const TaskResultEventSchema = z.object({
|
|
613
|
+
runKey: z.string().min(1),
|
|
614
|
+
result: EngineFinalResultSchema,
|
|
615
|
+
});
|
|
616
|
+
export const AgentEngineModelsParamsSchema = z.object({
|
|
617
|
+
engineId: EngineIdSchema,
|
|
618
|
+
cursor: z.string().optional(),
|
|
619
|
+
limit: z.number().int().positive().optional(),
|
|
620
|
+
});
|
|
621
|
+
export const AgentEngineOptionsParamsSchema = z.object({
|
|
622
|
+
engineId: EngineIdSchema,
|
|
623
|
+
});
|
|
624
|
+
export const AgentEngineProbeParamsSchema = z.object({
|
|
625
|
+
engineId: EngineIdSchema,
|
|
626
|
+
});
|
|
627
|
+
export const AgentEngineListParamsSchema = z.object({
|
|
628
|
+
cursor: z.string().optional(),
|
|
629
|
+
limit: z.number().int().positive().optional(),
|
|
630
|
+
});
|
|
631
|
+
/** 统一 session.* wire params:完整 SessionRef,禁止外部传 HOME/store path。 */
|
|
632
|
+
export const SessionListParamsV2Schema = z.object({
|
|
633
|
+
engineId: EngineIdSchema,
|
|
634
|
+
projectScope: EngineSessionProjectScopeSchema.optional(),
|
|
635
|
+
cursor: z.string().optional(),
|
|
636
|
+
limit: z.number().int().positive().optional(),
|
|
637
|
+
});
|
|
638
|
+
export const SessionGetParamsV2Schema = z.object({
|
|
639
|
+
session: AgentEngineSessionRefSchema,
|
|
640
|
+
cursor: z.string().optional(),
|
|
641
|
+
limit: z.number().int().positive().optional(),
|
|
642
|
+
includeRawMessages: z.boolean().optional(),
|
|
643
|
+
});
|
|
644
|
+
export const SessionSearchParamsSchema = z.object({
|
|
645
|
+
engineId: EngineIdSchema,
|
|
646
|
+
projectScope: EngineSessionProjectScopeSchema.optional(),
|
|
647
|
+
text: z.string().min(1),
|
|
648
|
+
cursor: z.string().optional(),
|
|
649
|
+
limit: z.number().int().positive().optional(),
|
|
650
|
+
});
|
|
651
|
+
export const SessionDeleteParamsSchema = z.object({
|
|
652
|
+
session: AgentEngineSessionRefSchema,
|
|
653
|
+
requestId: z.string().min(1),
|
|
654
|
+
});
|
|
655
|
+
/** task.event payload:daemon 已标准化的 EngineEventEnvelope。 */
|
|
656
|
+
export const TaskEventPayloadSchema = EngineEventEnvelopeSchema;
|
|
657
|
+
/* ── Hook 协商(Host wire 内部) ── */
|
|
658
|
+
export const HookProfileSupportRequestSchema = z.object({
|
|
659
|
+
required: z.array(EngineHookProfileRefSchema),
|
|
660
|
+
});
|
|
661
|
+
export const HookProfileSupportResponseSchema = z.object({
|
|
662
|
+
supported: z.array(EngineHookProfileDescriptorSchema),
|
|
663
|
+
unsupported: z.array(EngineHookProfileRefSchema),
|
|
664
|
+
});
|
|
665
|
+
/* ── Gateway protocol 版本协商 ── */
|
|
666
|
+
/** daemon/agent-sdk 宣告支持的统一 Gateway protocol version;新 method/event 需先协商。 */
|
|
667
|
+
export const AGENT_ENGINE_GATEWAY_PROTOCOL_VERSION = 1;
|
|
668
|
+
export const AGENT_ENGINE_GATEWAY_MIN_PROTOCOL_VERSION = 1;
|
|
669
|
+
export const GatewayProtocolCapabilitySchema = z.object({
|
|
670
|
+
gatewayProtocolVersion: z.number().int().positive(),
|
|
671
|
+
eventStreamMode: EventStreamModeSchema.optional(),
|
|
672
|
+
supportedEngineHookProfiles: z.array(EngineHookProfileDescriptorSchema).optional(),
|
|
673
|
+
});
|
|
674
|
+
/** Server 只有在 daemon 声明满足最低版本时才启用 ExternalComputerExecutionHost。 */
|
|
675
|
+
export function supportsGatewayProtocol(declaredVersion) {
|
|
676
|
+
return (typeof declaredVersion === 'number' &&
|
|
677
|
+
declaredVersion >= AGENT_ENGINE_GATEWAY_MIN_PROTOCOL_VERSION);
|
|
678
|
+
}
|
|
679
|
+
//# sourceMappingURL=agentEngine.js.map
|