@zhushanwen/subagent-engine-sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/best-effort.cjs +88 -0
- package/dist/best-effort.d.cts +14 -0
- package/dist/best-effort.d.ts +14 -0
- package/dist/best-effort.js +8 -0
- package/dist/chunk-2DIMPZCQ.js +0 -0
- package/dist/chunk-365AUV6N.js +67 -0
- package/dist/chunk-3K2P2CM2.js +127 -0
- package/dist/chunk-75QEMUGV.js +58 -0
- package/dist/chunk-7I4XGL5J.js +95 -0
- package/dist/chunk-A75XDJIC.js +227 -0
- package/dist/chunk-DSQ7JQKM.js +39 -0
- package/dist/chunk-EJMF63R5.js +19 -0
- package/dist/chunk-GT6YLLN4.js +46 -0
- package/dist/chunk-HYES77BR.js +109 -0
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/chunk-LEOBWKRM.js +128 -0
- package/dist/chunk-N3RL6OVM.js +38 -0
- package/dist/chunk-OPMY4G4M.js +27 -0
- package/dist/chunk-PPEPBVCC.js +120 -0
- package/dist/chunk-PYO3YR7W.js +16 -0
- package/dist/chunk-RDH3ZOV6.js +46 -0
- package/dist/chunk-RULLX6C6.js +11 -0
- package/dist/chunk-X24SFZYW.js +6646 -0
- package/dist/chunk-YFSN3D5N.js +216 -0
- package/dist/chunk-ZOFFJNJD.js +136 -0
- package/dist/chunk-ZXEAW25V.js +132 -0
- package/dist/cli-entry.cjs +119 -0
- package/dist/cli-entry.d.cts +24 -0
- package/dist/cli-entry.d.ts +24 -0
- package/dist/cli-entry.js +8 -0
- package/dist/contract-types-sSlgppBC.d.cts +352 -0
- package/dist/contract-types-sSlgppBC.d.ts +352 -0
- package/dist/data-dir.cjs +117 -0
- package/dist/data-dir.d.cts +20 -0
- package/dist/data-dir.d.ts +20 -0
- package/dist/data-dir.js +12 -0
- package/dist/env.cjs +205 -0
- package/dist/env.d.cts +73 -0
- package/dist/env.d.ts +73 -0
- package/dist/env.js +16 -0
- package/dist/error-codes-DHco5-i_.d.cts +118 -0
- package/dist/error-codes-Dhss2Kmk.d.ts +118 -0
- package/dist/error-message.cjs +40 -0
- package/dist/error-message.d.cts +3 -0
- package/dist/error-message.d.ts +3 -0
- package/dist/error-message.js +7 -0
- package/dist/index.cjs +8375 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +268 -0
- package/dist/journal-io.cjs +70 -0
- package/dist/journal-io.d.cts +12 -0
- package/dist/journal-io.d.ts +12 -0
- package/dist/journal-io.js +7 -0
- package/dist/journal-replay.cjs +256 -0
- package/dist/journal-replay.d.cts +45 -0
- package/dist/journal-replay.d.ts +45 -0
- package/dist/journal-replay.js +17 -0
- package/dist/kill-chain.cjs +221 -0
- package/dist/kill-chain.d.cts +74 -0
- package/dist/kill-chain.d.ts +74 -0
- package/dist/kill-chain.js +23 -0
- package/dist/logger.cjs +84 -0
- package/dist/logger.d.cts +24 -0
- package/dist/logger.d.ts +24 -0
- package/dist/logger.js +11 -0
- package/dist/logs/stderr-rotation.cjs +151 -0
- package/dist/logs/stderr-rotation.d.cts +37 -0
- package/dist/logs/stderr-rotation.d.ts +37 -0
- package/dist/logs/stderr-rotation.js +23 -0
- package/dist/nesting-guard.cjs +95 -0
- package/dist/nesting-guard.d.cts +65 -0
- package/dist/nesting-guard.d.ts +65 -0
- package/dist/nesting-guard.js +15 -0
- package/dist/node-executor.cjs +180 -0
- package/dist/node-executor.d.cts +63 -0
- package/dist/node-executor.d.ts +63 -0
- package/dist/node-executor.js +16 -0
- package/dist/paths.cjs +55 -0
- package/dist/paths.d.cts +8 -0
- package/dist/paths.d.ts +8 -0
- package/dist/paths.js +15 -0
- package/dist/port-contract.cjs +35 -0
- package/dist/port-contract.d.cts +88 -0
- package/dist/port-contract.d.ts +88 -0
- package/dist/port-contract.js +7 -0
- package/dist/protocol/index.cjs +400 -0
- package/dist/protocol/index.d.cts +685 -0
- package/dist/protocol/index.d.ts +685 -0
- package/dist/protocol/index.js +89 -0
- package/dist/relay-env.cjs +71 -0
- package/dist/relay-env.d.cts +37 -0
- package/dist/relay-env.d.ts +37 -0
- package/dist/relay-env.js +23 -0
- package/dist/schema-emulation.cjs +6680 -0
- package/dist/schema-emulation.d.cts +39 -0
- package/dist/schema-emulation.d.ts +39 -0
- package/dist/schema-emulation.js +11 -0
- package/dist/spawn.cjs +200 -0
- package/dist/spawn.d.cts +80 -0
- package/dist/spawn.d.ts +80 -0
- package/dist/spawn.js +16 -0
- package/dist/ui-channels.cjs +120 -0
- package/dist/ui-channels.d.cts +60 -0
- package/dist/ui-channels.d.ts +60 -0
- package/dist/ui-channels.js +9 -0
- package/dist/ui-types.cjs +18 -0
- package/dist/ui-types.d.cts +62 -0
- package/dist/ui-types.d.ts +62 -0
- package/dist/ui-types.js +1 -0
- package/package.json +58 -0
- package/src/best-effort.ts +37 -0
- package/src/cli-entry.ts +77 -0
- package/src/data-dir.ts +88 -0
- package/src/env.ts +265 -0
- package/src/error-message.ts +22 -0
- package/src/index.ts +63 -0
- package/src/journal-io.ts +82 -0
- package/src/journal-replay.ts +432 -0
- package/src/kill-chain.ts +265 -0
- package/src/logger.ts +105 -0
- package/src/logs/stderr-rotation.ts +166 -0
- package/src/nesting-guard.ts +140 -0
- package/src/node-executor.ts +272 -0
- package/src/paths.ts +48 -0
- package/src/port-contract.ts +117 -0
- package/src/protocol/contract-types.ts +378 -0
- package/src/protocol/engine-protocol.ts +81 -0
- package/src/protocol/error-codes.ts +179 -0
- package/src/protocol/frames.ts +145 -0
- package/src/protocol/index.ts +12 -0
- package/src/protocol/methods.ts +229 -0
- package/src/protocol/reverse-channels.ts +274 -0
- package/src/protocol/schema.ts +154 -0
- package/src/relay-env.ts +60 -0
- package/src/schema-emulation.ts +192 -0
- package/src/spawn.ts +246 -0
- package/src/ui-channels.ts +219 -0
- package/src/ui-types.ts +84 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/protocol/index.ts
|
|
21
|
+
var protocol_exports = {};
|
|
22
|
+
__export(protocol_exports, {
|
|
23
|
+
CANCEL_SETTLE_GRACE_MS: () => CANCEL_SETTLE_GRACE_MS,
|
|
24
|
+
CRASH_REBUILD_BACKOFF_MS: () => CRASH_REBUILD_BACKOFF_MS,
|
|
25
|
+
CRASH_REBUILD_MAX_ATTEMPTS: () => CRASH_REBUILD_MAX_ATTEMPTS,
|
|
26
|
+
ENGINE_ERROR_CODE_PREFIX: () => ENGINE_ERROR_CODE_PREFIX,
|
|
27
|
+
ENGINE_EVENT_COALESCE_DEFAULT: () => ENGINE_EVENT_COALESCE_DEFAULT,
|
|
28
|
+
ENGINE_EVENT_COALESCE_ENV: () => ENGINE_EVENT_COALESCE_ENV,
|
|
29
|
+
ENGINE_PROTOCOL_ERROR_CODES: () => ENGINE_PROTOCOL_ERROR_CODES,
|
|
30
|
+
ENGINE_PROTOCOL_SCHEMAS: () => ENGINE_PROTOCOL_SCHEMAS,
|
|
31
|
+
ENGINE_PROTOCOL_VERSION: () => ENGINE_PROTOCOL_VERSION,
|
|
32
|
+
ENGINE_TIMEOUT_RECOVERY: () => ENGINE_TIMEOUT_RECOVERY,
|
|
33
|
+
EngineSdkError: () => EngineSdkError,
|
|
34
|
+
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS: () => FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
35
|
+
HANDSHAKE_TIMEOUT_MS: () => HANDSHAKE_TIMEOUT_MS,
|
|
36
|
+
PROTOCOL_METHODS: () => PROTOCOL_METHODS,
|
|
37
|
+
REVERSE_CHANNELS: () => REVERSE_CHANNELS,
|
|
38
|
+
REVERSE_CHANNEL_NAMES: () => REVERSE_CHANNEL_NAMES,
|
|
39
|
+
REVERSE_CHANNEL_TIMEOUT_CLASS: () => REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
40
|
+
REVERSE_REQUEST_TIMEOUT_MS: () => REVERSE_REQUEST_TIMEOUT_MS,
|
|
41
|
+
STDERR_TAIL_CHARS: () => STDERR_TAIL_CHARS,
|
|
42
|
+
STDOUT_TAIL_ECHO_CHARS: () => STDOUT_TAIL_ECHO_CHARS,
|
|
43
|
+
SUPPORTED_PROTOCOL_RANGE: () => SUPPORTED_PROTOCOL_RANGE,
|
|
44
|
+
assertChatConversationSupported: () => assertChatConversationSupported,
|
|
45
|
+
engineConversationUnsupportedError: () => engineConversationUnsupportedError,
|
|
46
|
+
engineProtocolMismatchError: () => engineProtocolMismatchError,
|
|
47
|
+
engineTimeoutDetail: () => engineTimeoutDetail,
|
|
48
|
+
errorResponseFrameSchema: () => errorResponseFrameSchema,
|
|
49
|
+
isEngineErrorPassthroughCode: () => isEngineErrorPassthroughCode,
|
|
50
|
+
isEngineProtocolErrorCode: () => isEngineProtocolErrorCode,
|
|
51
|
+
isHostRoundLifecycleParams: () => isHostRoundLifecycleParams,
|
|
52
|
+
isHostStreamDeltaParams: () => isHostStreamDeltaParams,
|
|
53
|
+
isNotificationFrame: () => isNotificationFrame,
|
|
54
|
+
isProtocolVersionCompatible: () => isProtocolVersionCompatible,
|
|
55
|
+
isRequestFrame: () => isRequestFrame,
|
|
56
|
+
isResponseFrame: () => isResponseFrame,
|
|
57
|
+
isReverseRequestFrame: () => isReverseRequestFrame,
|
|
58
|
+
notificationFrameSchema: () => notificationFrameSchema,
|
|
59
|
+
protocolErrorSchema: () => protocolErrorSchema,
|
|
60
|
+
requestFrameSchema: () => requestFrameSchema,
|
|
61
|
+
reverseRequestFrameSchema: () => reverseRequestFrameSchema,
|
|
62
|
+
schemaEmulationFailedDetail: () => schemaEmulationFailedDetail,
|
|
63
|
+
successResponseFrameSchema: () => successResponseFrameSchema
|
|
64
|
+
});
|
|
65
|
+
module.exports = __toCommonJS(protocol_exports);
|
|
66
|
+
|
|
67
|
+
// src/protocol/engine-protocol.ts
|
|
68
|
+
var ENGINE_PROTOCOL_VERSION = 1;
|
|
69
|
+
var SUPPORTED_PROTOCOL_RANGE = { min: 1, max: 2 };
|
|
70
|
+
function isProtocolVersionCompatible(version) {
|
|
71
|
+
return Number.isInteger(version) && version >= SUPPORTED_PROTOCOL_RANGE.min && version < SUPPORTED_PROTOCOL_RANGE.max;
|
|
72
|
+
}
|
|
73
|
+
var REVERSE_REQUEST_TIMEOUT_MS = 1e4;
|
|
74
|
+
var HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
75
|
+
var CANCEL_SETTLE_GRACE_MS = 3e3;
|
|
76
|
+
var CRASH_REBUILD_MAX_ATTEMPTS = 3;
|
|
77
|
+
var CRASH_REBUILD_BACKOFF_STEP_1_MS = 1e3;
|
|
78
|
+
var CRASH_REBUILD_BACKOFF_STEP_2_MS = 2e3;
|
|
79
|
+
var CRASH_REBUILD_BACKOFF_STEP_3_MS = 4e3;
|
|
80
|
+
var CRASH_REBUILD_BACKOFF_MS = [
|
|
81
|
+
CRASH_REBUILD_BACKOFF_STEP_1_MS,
|
|
82
|
+
CRASH_REBUILD_BACKOFF_STEP_2_MS,
|
|
83
|
+
CRASH_REBUILD_BACKOFF_STEP_3_MS
|
|
84
|
+
];
|
|
85
|
+
var STDERR_TAIL_CHARS = 400;
|
|
86
|
+
var ENGINE_EVENT_COALESCE_ENV = "XYZ_ENGINE_EVENT_COALESCE";
|
|
87
|
+
var ENGINE_EVENT_COALESCE_DEFAULT = "0";
|
|
88
|
+
|
|
89
|
+
// src/protocol/frames.ts
|
|
90
|
+
function isRecord(v) {
|
|
91
|
+
return typeof v === "object" && v !== null;
|
|
92
|
+
}
|
|
93
|
+
function isRequestFrame(frame) {
|
|
94
|
+
return isRecord(frame) && typeof frame.id === "number" && typeof frame.method === "string" && "params" in frame && !("result" in frame) && !("error" in frame);
|
|
95
|
+
}
|
|
96
|
+
function isResponseFrame(frame) {
|
|
97
|
+
if (!isRecord(frame) || !("id" in frame)) return false;
|
|
98
|
+
const idOk = typeof frame.id === "number" || typeof frame.id === "string";
|
|
99
|
+
if (!idOk) return false;
|
|
100
|
+
const hasResult = "result" in frame;
|
|
101
|
+
const hasError = "error" in frame;
|
|
102
|
+
return hasResult !== hasError;
|
|
103
|
+
}
|
|
104
|
+
function isNotificationFrame(frame) {
|
|
105
|
+
return isRecord(frame) && !("id" in frame) && frame.method === "event" && isRecord(frame.params) && typeof frame.params.runId === "string" && typeof frame.params.seq === "number" && isRecord(frame.params.event) && typeof frame.params.event.type === "string";
|
|
106
|
+
}
|
|
107
|
+
function isReverseRequestFrame(frame) {
|
|
108
|
+
return isRecord(frame) && typeof frame.id === "string" && typeof frame.method === "string" && frame.method.startsWith("host/") && "params" in frame;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/protocol/methods.ts
|
|
112
|
+
var PROTOCOL_METHODS = [
|
|
113
|
+
"initialize",
|
|
114
|
+
"probe",
|
|
115
|
+
"run",
|
|
116
|
+
"cancel",
|
|
117
|
+
"interact",
|
|
118
|
+
"read",
|
|
119
|
+
"listModels",
|
|
120
|
+
"validateModel",
|
|
121
|
+
"dispose",
|
|
122
|
+
"ping"
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
// src/protocol/reverse-channels.ts
|
|
126
|
+
var REVERSE_CHANNELS = [
|
|
127
|
+
"host/log",
|
|
128
|
+
"host/askUser",
|
|
129
|
+
"host/permission",
|
|
130
|
+
"host/streamDelta",
|
|
131
|
+
"host/poolResolved",
|
|
132
|
+
"host/handleReady",
|
|
133
|
+
"host/childSpawned",
|
|
134
|
+
"host/childStateChanged",
|
|
135
|
+
"host/roundLifecycle"
|
|
136
|
+
];
|
|
137
|
+
var REVERSE_CHANNEL_TIMEOUT_CLASS = {
|
|
138
|
+
"host/log": "data-plane",
|
|
139
|
+
"host/streamDelta": "data-plane",
|
|
140
|
+
"host/poolResolved": "data-plane",
|
|
141
|
+
"host/handleReady": "data-plane",
|
|
142
|
+
"host/childSpawned": "data-plane",
|
|
143
|
+
"host/childStateChanged": "data-plane",
|
|
144
|
+
"host/roundLifecycle": "data-plane",
|
|
145
|
+
"host/askUser": "interaction",
|
|
146
|
+
"host/permission": "interaction"
|
|
147
|
+
};
|
|
148
|
+
function isHostStreamDeltaParams(value) {
|
|
149
|
+
if (typeof value !== "object" || value === null) return false;
|
|
150
|
+
const v = value;
|
|
151
|
+
const hasRunId = typeof v.runId === "string";
|
|
152
|
+
const hasRecordId = typeof v.recordId === "string";
|
|
153
|
+
if (hasRunId === hasRecordId) return false;
|
|
154
|
+
return typeof v.delta === "string";
|
|
155
|
+
}
|
|
156
|
+
function isHostRoundLifecycleParams(value) {
|
|
157
|
+
if (typeof value !== "object" || value === null) return false;
|
|
158
|
+
const v = value;
|
|
159
|
+
const hasRunId = typeof v.runId === "string";
|
|
160
|
+
const hasRecordId = typeof v.recordId === "string";
|
|
161
|
+
if (hasRunId === hasRecordId) return false;
|
|
162
|
+
if (v.phase === "settled" || v.phase === "idle") return true;
|
|
163
|
+
if (v.phase !== "failed") return false;
|
|
164
|
+
const err = v.error;
|
|
165
|
+
return typeof err === "object" && err !== null && typeof err.code === "string" && typeof err.message === "string";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/protocol/error-codes.ts
|
|
169
|
+
var ENGINE_PROTOCOL_ERROR_CODES = [
|
|
170
|
+
"engine_not_found",
|
|
171
|
+
"engine_protocol_mismatch",
|
|
172
|
+
"engine_capability_unsupported",
|
|
173
|
+
"engine_capability_mismatch",
|
|
174
|
+
"engine_model_unknown",
|
|
175
|
+
"engine_model_mismatch",
|
|
176
|
+
"engine_handshake_timeout",
|
|
177
|
+
"engine_crashed",
|
|
178
|
+
"engine_probe_failed"
|
|
179
|
+
];
|
|
180
|
+
function isEngineProtocolErrorCode(value) {
|
|
181
|
+
return typeof value === "string" && ENGINE_PROTOCOL_ERROR_CODES.includes(value);
|
|
182
|
+
}
|
|
183
|
+
var ENGINE_ERROR_CODE_PREFIX = "engine_";
|
|
184
|
+
function isEngineErrorPassthroughCode(value) {
|
|
185
|
+
return !isEngineProtocolErrorCode(value) && value.startsWith(ENGINE_ERROR_CODE_PREFIX);
|
|
186
|
+
}
|
|
187
|
+
var EngineSdkError = class extends Error {
|
|
188
|
+
code;
|
|
189
|
+
recovery;
|
|
190
|
+
data;
|
|
191
|
+
constructor(code, detail, recovery, data) {
|
|
192
|
+
super(`${code}: ${detail}`);
|
|
193
|
+
this.name = "EngineSdkError";
|
|
194
|
+
this.code = code;
|
|
195
|
+
this.recovery = recovery;
|
|
196
|
+
this.data = data;
|
|
197
|
+
}
|
|
198
|
+
/** 协议 error 帧载荷投影。 */
|
|
199
|
+
toStructured() {
|
|
200
|
+
return { code: this.code, message: this.message, recovery: this.recovery, data: this.data };
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
function engineProtocolMismatchError(engineVersion) {
|
|
204
|
+
return new EngineSdkError(
|
|
205
|
+
"engine_protocol_mismatch",
|
|
206
|
+
`engine speaks protocol v${engineVersion}, host supports [${SUPPORTED_PROTOCOL_RANGE.min}, ${SUPPORTED_PROTOCOL_RANGE.max})`,
|
|
207
|
+
"Upgrade the engine package (or the host) so both sides speak a protocol version in the supported range, then re-run the task. The engine is marked unavailable until then.",
|
|
208
|
+
{
|
|
209
|
+
engineProtocolVersion: engineVersion,
|
|
210
|
+
supportedMin: SUPPORTED_PROTOCOL_RANGE.min,
|
|
211
|
+
supportedMaxExclusive: SUPPORTED_PROTOCOL_RANGE.max
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
function engineConversationUnsupportedError(engineId) {
|
|
216
|
+
return new EngineSdkError(
|
|
217
|
+
"engine_capability_unsupported",
|
|
218
|
+
`engine '${engineId}' \u4E0D\u652F\u6301 conversation\uFF08capabilities.conversation = 'unsupported'\uFF0Cmanifest \u65E0 conversation gate \u4F4D\u2014\u2014\u65E0\u540C\u8FDB\u7A0B idle \u590D\u7528\uFF0Cmessage/close \u4EA4\u4E92\u63A7\u5236\u9762\u4E0D\u53EF\u7528\uFF09`,
|
|
219
|
+
`\u53BB\u6389 conversation \u53C2\u6570\uFF08\u4E00\u6B21\u6027\u4EFB\u52A1\u9ED8\u8BA4\u5F62\u6001\uFF09\uFF0C\u6216\u4FEE manifest capabilities / \u5347\u7EA7\u5F15\u64CE\u5305\uFF08\u82E5\u5F15\u64CE\u5B9E\u9645\u652F\u6301\u8BE5\u80FD\u529B\uFF09`,
|
|
220
|
+
{ engineId, capability: "conversation", declared: "unsupported" }
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
function assertChatConversationSupported(engineId, capabilities) {
|
|
224
|
+
if (capabilities.conversation === "unsupported") {
|
|
225
|
+
throw engineConversationUnsupportedError(engineId);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
var DETAIL_ECHO_MAX_CHARS = 200;
|
|
229
|
+
var STDOUT_TAIL_ECHO_CHARS = 2e3;
|
|
230
|
+
function truncate(text, max) {
|
|
231
|
+
return text.length <= max ? text : `${text.slice(0, max)}...`;
|
|
232
|
+
}
|
|
233
|
+
var ENGINE_TIMEOUT_RECOVERY = "The engine was killed by the host timeout chain. Inspect the captured stdout tail, then re-run with a larger timeout, a narrower task, or `engine: pi`.";
|
|
234
|
+
function engineTimeoutDetail(stdoutTail) {
|
|
235
|
+
return `host timeout chain exhausted (SIGTERM -> grace -> SIGKILL). Stdout tail (last ${STDOUT_TAIL_ECHO_CHARS} chars): ${truncate(stdoutTail, STDOUT_TAIL_ECHO_CHARS)}. Recovery: ${ENGINE_TIMEOUT_RECOVERY}`;
|
|
236
|
+
}
|
|
237
|
+
function schemaEmulationFailedDetail(error, tail) {
|
|
238
|
+
return `structured output emulation failed after tolerant extraction and one host-side retry: ${error}. Raw output tail: ${truncate(tail, DETAIL_ECHO_MAX_CHARS)}. Recovery: retry with a strengthened prompt or relax the schema; if it still fails switch to a schema-native engine (engine: pi).`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/protocol/schema.ts
|
|
242
|
+
var ANY_JSON = {};
|
|
243
|
+
var protocolErrorSchema = {
|
|
244
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
245
|
+
title: "EngineProtocolError",
|
|
246
|
+
type: "object",
|
|
247
|
+
additionalProperties: false,
|
|
248
|
+
required: ["code", "message", "recovery"],
|
|
249
|
+
properties: {
|
|
250
|
+
code: { type: "string", pattern: "^engine_" },
|
|
251
|
+
message: { type: "string" },
|
|
252
|
+
recovery: { type: "string" },
|
|
253
|
+
data: { type: "object" }
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var requestFrameSchema = {
|
|
257
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
258
|
+
title: "EngineProtocolRequestFrame",
|
|
259
|
+
type: "object",
|
|
260
|
+
additionalProperties: false,
|
|
261
|
+
required: ["id", "method", "params"],
|
|
262
|
+
properties: {
|
|
263
|
+
id: { type: "number" },
|
|
264
|
+
method: { type: "string", enum: [...PROTOCOL_METHODS] },
|
|
265
|
+
params: ANY_JSON
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var successResponseFrameSchema = {
|
|
269
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
270
|
+
title: "EngineProtocolSuccessResponseFrame",
|
|
271
|
+
type: "object",
|
|
272
|
+
additionalProperties: false,
|
|
273
|
+
required: ["id", "result"],
|
|
274
|
+
properties: {
|
|
275
|
+
id: { type: ["number", "string"] },
|
|
276
|
+
result: ANY_JSON
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
var errorResponseFrameSchema = {
|
|
280
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
281
|
+
title: "EngineProtocolErrorResponseFrame",
|
|
282
|
+
type: "object",
|
|
283
|
+
additionalProperties: false,
|
|
284
|
+
required: ["id", "error"],
|
|
285
|
+
properties: {
|
|
286
|
+
id: { type: ["number", "string"] },
|
|
287
|
+
error: protocolErrorSchema
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var notificationFrameSchema = {
|
|
291
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
292
|
+
title: "EngineProtocolNotificationFrame",
|
|
293
|
+
type: "object",
|
|
294
|
+
additionalProperties: false,
|
|
295
|
+
required: ["method", "params"],
|
|
296
|
+
properties: {
|
|
297
|
+
method: { type: "string", const: "event" },
|
|
298
|
+
params: {
|
|
299
|
+
type: "object",
|
|
300
|
+
additionalProperties: false,
|
|
301
|
+
required: ["runId", "seq", "event"],
|
|
302
|
+
properties: {
|
|
303
|
+
runId: { type: "string" },
|
|
304
|
+
seq: { type: "number" },
|
|
305
|
+
event: {
|
|
306
|
+
type: "object",
|
|
307
|
+
required: ["type"],
|
|
308
|
+
properties: {
|
|
309
|
+
type: {
|
|
310
|
+
type: "string",
|
|
311
|
+
enum: [
|
|
312
|
+
"tool_start",
|
|
313
|
+
"tool_end",
|
|
314
|
+
"text_delta",
|
|
315
|
+
"thinking_delta",
|
|
316
|
+
"turn_end",
|
|
317
|
+
"message_end",
|
|
318
|
+
"compaction",
|
|
319
|
+
"error"
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var reverseRequestFrameSchema = {
|
|
329
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
330
|
+
title: "EngineProtocolReverseRequestFrame",
|
|
331
|
+
type: "object",
|
|
332
|
+
additionalProperties: false,
|
|
333
|
+
required: ["id", "method", "params"],
|
|
334
|
+
properties: {
|
|
335
|
+
id: { type: "string" },
|
|
336
|
+
method: { type: "string", enum: [...REVERSE_CHANNELS] },
|
|
337
|
+
params: ANY_JSON
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
var ENGINE_PROTOCOL_SCHEMAS = {
|
|
341
|
+
request: requestFrameSchema,
|
|
342
|
+
successResponse: successResponseFrameSchema,
|
|
343
|
+
errorResponse: errorResponseFrameSchema,
|
|
344
|
+
notification: notificationFrameSchema,
|
|
345
|
+
reverseRequest: reverseRequestFrameSchema,
|
|
346
|
+
protocolError: protocolErrorSchema
|
|
347
|
+
};
|
|
348
|
+
var FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS = [
|
|
349
|
+
"apikey",
|
|
350
|
+
"api_key",
|
|
351
|
+
"token",
|
|
352
|
+
"credential",
|
|
353
|
+
"password",
|
|
354
|
+
"secret"
|
|
355
|
+
];
|
|
356
|
+
var REVERSE_CHANNEL_NAMES = REVERSE_CHANNELS;
|
|
357
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
358
|
+
0 && (module.exports = {
|
|
359
|
+
CANCEL_SETTLE_GRACE_MS,
|
|
360
|
+
CRASH_REBUILD_BACKOFF_MS,
|
|
361
|
+
CRASH_REBUILD_MAX_ATTEMPTS,
|
|
362
|
+
ENGINE_ERROR_CODE_PREFIX,
|
|
363
|
+
ENGINE_EVENT_COALESCE_DEFAULT,
|
|
364
|
+
ENGINE_EVENT_COALESCE_ENV,
|
|
365
|
+
ENGINE_PROTOCOL_ERROR_CODES,
|
|
366
|
+
ENGINE_PROTOCOL_SCHEMAS,
|
|
367
|
+
ENGINE_PROTOCOL_VERSION,
|
|
368
|
+
ENGINE_TIMEOUT_RECOVERY,
|
|
369
|
+
EngineSdkError,
|
|
370
|
+
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
371
|
+
HANDSHAKE_TIMEOUT_MS,
|
|
372
|
+
PROTOCOL_METHODS,
|
|
373
|
+
REVERSE_CHANNELS,
|
|
374
|
+
REVERSE_CHANNEL_NAMES,
|
|
375
|
+
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
376
|
+
REVERSE_REQUEST_TIMEOUT_MS,
|
|
377
|
+
STDERR_TAIL_CHARS,
|
|
378
|
+
STDOUT_TAIL_ECHO_CHARS,
|
|
379
|
+
SUPPORTED_PROTOCOL_RANGE,
|
|
380
|
+
assertChatConversationSupported,
|
|
381
|
+
engineConversationUnsupportedError,
|
|
382
|
+
engineProtocolMismatchError,
|
|
383
|
+
engineTimeoutDetail,
|
|
384
|
+
errorResponseFrameSchema,
|
|
385
|
+
isEngineErrorPassthroughCode,
|
|
386
|
+
isEngineProtocolErrorCode,
|
|
387
|
+
isHostRoundLifecycleParams,
|
|
388
|
+
isHostStreamDeltaParams,
|
|
389
|
+
isNotificationFrame,
|
|
390
|
+
isProtocolVersionCompatible,
|
|
391
|
+
isRequestFrame,
|
|
392
|
+
isResponseFrame,
|
|
393
|
+
isReverseRequestFrame,
|
|
394
|
+
notificationFrameSchema,
|
|
395
|
+
protocolErrorSchema,
|
|
396
|
+
requestFrameSchema,
|
|
397
|
+
reverseRequestFrameSchema,
|
|
398
|
+
schemaEmulationFailedDetail,
|
|
399
|
+
successResponseFrameSchema
|
|
400
|
+
});
|