@tansr/protocol 0.2.0 → 0.4.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/README.md +1 -0
- package/dist/canonical/encode.js +81 -55
- package/dist/events.d.ts +25 -19
- package/dist/events.js +10 -3
- package/dist/headless.d.ts +3 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -0
- package/dist/persistence-custody.d.ts +13 -0
- package/dist/persistence-custody.generated.d.ts +568 -0
- package/dist/persistence-custody.generated.js +8 -0
- package/dist/persistence-custody.js +28 -0
- package/dist/storage.d.ts +1047 -5
- package/dist/storage.js +69 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,7 @@ toHex(digest as Uint8Array);
|
|
|
67
67
|
- `contract-v0` 自 W0 末冻结,任何形的变更走 RFC(`doc/rfc/`),修订号 `contract-v0.x` 与同名 git tag 对应;事件包络 `v` 维持 `v0`。
|
|
68
68
|
- 包版本遵「**0.x 期 minor = breaking**」(doc/89 §3.3):导出集任何增 / 删 / 签名变至少 minor,patch 不得携新导出;发版门 ④ 以 `exports.snapshot.json` + `exports.subpaths.snapshot.json` 与上一 tag 比对强制执行。
|
|
69
69
|
- 预发布 `X.Y.Z-rc.N` 走 dist-tag `next`,`-beta.N` 走 `beta`,正式版 `latest`;变更记录见 [`CHANGELOG.md`](./CHANGELOG.md),每版发布回执落仓内 `doc/release/protocol-<version>.md`,无回执无 tag(tag 形 `@tansr/protocol@<version>`)。
|
|
70
|
+
- 发行链(仓内):`pnpm build` 串本包 `tsc -p tsconfig.build.json`;`pnpm release:pack-protocol` 在独立合成目录真 `tsc` 后 `npm pack` 出 `dist/release/tansr-protocol-<version>.tgz`(白名单 `package.json` / `LICENSE` / `README.md` / `dist/**`,入口 `.` 与 `./canonical` 经 `publishConfig` 镜像到 dist,仅 `zod` 一个外部依赖、零 `@tansr/*`),只打包不发布;正式发布恒走 `scripts/release/publish.mjs`(`PUBLISH_ORDER` 首位 protocol → sdk → serve → cli → api-client),逐包过六步门。首次公开发行 **0.2.0**(2026-10-02,`latest`),回执 `doc/release/protocol-0.2.0.md`。
|
|
70
71
|
- canonical 规则与错误码表的规范文本:[RFC-UAPI-1 统一信封与 canonical 单模块](../../doc/rfc/RFC-UAPI-1-统一信封与canonical单模块.md) §4;统一 API 合同的结构 schema:`doc/rfc/unified-v1.schema.json`。
|
|
71
72
|
|
|
72
73
|
## 许可
|
package/dist/canonical/encode.js
CHANGED
|
@@ -11,145 +11,171 @@
|
|
|
11
11
|
import { CANONICAL_KEY_PATTERN, normalizeOptions, utf8Length, wellFormed } from './common.js';
|
|
12
12
|
import { CanonicalError, childPointer } from './errors.js';
|
|
13
13
|
const encoder = new TextEncoder();
|
|
14
|
+
const ASCII_ONLY = /^[\x00-\x7f]*$/;
|
|
15
|
+
/** 已通过 `CANONICAL_KEY_PATTERN` 的短键 → `"key":`;纯函数记忆,满即清空。 */
|
|
16
|
+
const quotedKeys = new Map();
|
|
17
|
+
const QUOTED_KEYS_MAX = 4096, QUOTED_KEY_MAX_LENGTH = 64;
|
|
14
18
|
class Writer {
|
|
15
19
|
maxBytes;
|
|
16
20
|
maxDepth;
|
|
17
21
|
maxNodes;
|
|
18
22
|
isProxy;
|
|
19
|
-
|
|
23
|
+
text = '';
|
|
20
24
|
used = 0;
|
|
21
25
|
nodes = 0;
|
|
22
26
|
ancestors = new Set();
|
|
27
|
+
/** 从根到当前值的键 / 下标;只在报错时拼成 JSON Pointer。 */
|
|
28
|
+
keys = [];
|
|
23
29
|
constructor({ maxBytes, maxDepth, maxNodes, isProxy }) {
|
|
24
30
|
this.maxBytes = maxBytes;
|
|
25
31
|
this.maxDepth = maxDepth;
|
|
26
32
|
this.maxNodes = maxNodes;
|
|
27
33
|
this.isProxy = isProxy;
|
|
28
34
|
}
|
|
29
|
-
|
|
35
|
+
/** `up`:报错位置在当前值之上几层(元素之间的逗号属于容器,`up = 1`)。 */
|
|
36
|
+
fail(code, message, up = 0) {
|
|
37
|
+
let path = '';
|
|
38
|
+
for (let index = 0; index < this.keys.length - up; index++)
|
|
39
|
+
path = childPointer(path, this.keys[index]);
|
|
30
40
|
throw new CanonicalError(code, message, { path });
|
|
31
41
|
}
|
|
32
42
|
/** 结构符 / 数字 / 字面量 / ASCII 键:字节数 = 码元数。 */
|
|
33
|
-
ascii(part,
|
|
43
|
+
ascii(part, up = 0) {
|
|
34
44
|
this.used += part.length;
|
|
35
45
|
if (this.used > this.maxBytes)
|
|
36
|
-
this.fail('bytes_exceeded', `encoded bytes exceed maxBytes ${this.maxBytes}`,
|
|
37
|
-
this.
|
|
46
|
+
this.fail('bytes_exceeded', `encoded bytes exceed maxBytes ${this.maxBytes}`, up);
|
|
47
|
+
this.text += part;
|
|
38
48
|
}
|
|
39
49
|
/** 已加引号的字符串:先以码元数快速否决(UTF-8 字节 ≥ 码元数),再精确累计。 */
|
|
40
|
-
quoted(part
|
|
50
|
+
quoted(part) {
|
|
41
51
|
if (part.length > this.maxBytes - this.used)
|
|
42
|
-
this.fail('bytes_exceeded', `encoded bytes exceed maxBytes ${this.maxBytes}
|
|
52
|
+
this.fail('bytes_exceeded', `encoded bytes exceed maxBytes ${this.maxBytes}`);
|
|
43
53
|
this.used += utf8Length(part);
|
|
44
54
|
if (this.used > this.maxBytes)
|
|
45
|
-
this.fail('bytes_exceeded', `encoded bytes exceed maxBytes ${this.maxBytes}
|
|
46
|
-
this.
|
|
55
|
+
this.fail('bytes_exceeded', `encoded bytes exceed maxBytes ${this.maxBytes}`);
|
|
56
|
+
this.text += part;
|
|
47
57
|
}
|
|
48
|
-
number(value
|
|
58
|
+
number(value) {
|
|
49
59
|
if (!Number.isInteger(value))
|
|
50
|
-
this.fail('invalid_number', 'number must be an integer (no fraction, NaN or Infinity)'
|
|
60
|
+
this.fail('invalid_number', 'number must be an integer (no fraction, NaN or Infinity)');
|
|
51
61
|
if (!Number.isSafeInteger(value))
|
|
52
|
-
this.fail('unsafe_integer', 'integer exceeds 2^53-1'
|
|
62
|
+
this.fail('unsafe_integer', 'integer exceeds 2^53-1');
|
|
53
63
|
if (value < 0 || Object.is(value, -0))
|
|
54
|
-
this.fail('invalid_number', 'number must be nonnegative (no -0)'
|
|
55
|
-
this.ascii(String(value)
|
|
64
|
+
this.fail('invalid_number', 'number must be nonnegative (no -0)');
|
|
65
|
+
this.ascii(String(value));
|
|
56
66
|
}
|
|
57
|
-
string(value
|
|
67
|
+
string(value) {
|
|
68
|
+
// 纯 ASCII 串无代理项,转义后仍是 ASCII:字节数 = 码元数,与 quoted 两道检查同一结论、同一路径。
|
|
69
|
+
if (ASCII_ONLY.test(value)) {
|
|
70
|
+
this.ascii(JSON.stringify(value));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
58
73
|
if (!wellFormed(value))
|
|
59
|
-
this.fail('lone_surrogate', 'string contains an unpaired surrogate'
|
|
60
|
-
this.quoted(JSON.stringify(value)
|
|
74
|
+
this.fail('lone_surrogate', 'string contains an unpaired surrogate');
|
|
75
|
+
this.quoted(JSON.stringify(value));
|
|
61
76
|
}
|
|
62
|
-
dataDescriptor(target, key
|
|
77
|
+
dataDescriptor(target, key) {
|
|
63
78
|
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
64
79
|
if (descriptor === undefined || !Object.hasOwn(descriptor, 'value') || !descriptor.enumerable) {
|
|
65
|
-
this.fail('invalid_property', 'properties must be enumerable own data properties (no accessor / hole)'
|
|
80
|
+
this.fail('invalid_property', 'properties must be enumerable own data properties (no accessor / hole)');
|
|
66
81
|
}
|
|
67
82
|
return descriptor.value;
|
|
68
83
|
}
|
|
69
|
-
array(value, depth
|
|
84
|
+
array(value, depth) {
|
|
70
85
|
// `length` 是不可枚举的自有数据属性:直接读描述符的值,不经访问器。
|
|
71
86
|
const length = Object.getOwnPropertyDescriptor(value, 'length')?.value;
|
|
72
87
|
if (typeof length !== 'number' || !Number.isSafeInteger(length))
|
|
73
|
-
this.fail('invalid_property', 'array length is not an integer'
|
|
88
|
+
this.fail('invalid_property', 'array length is not an integer');
|
|
74
89
|
// 每个元素至少一个节点:越界必然发生,提前否决,避免先遍历再失败。
|
|
75
90
|
if (this.nodes + length > this.maxNodes)
|
|
76
|
-
this.fail('nodes_exceeded', `node count exceeds maxNodes ${this.maxNodes}
|
|
91
|
+
this.fail('nodes_exceeded', `node count exceeds maxNodes ${this.maxNodes}`);
|
|
77
92
|
const keys = Reflect.ownKeys(value);
|
|
78
93
|
if (keys.length !== length + 1)
|
|
79
|
-
this.fail('invalid_property', 'array must be dense without extra own properties'
|
|
80
|
-
this.ascii('['
|
|
94
|
+
this.fail('invalid_property', 'array must be dense without extra own properties');
|
|
95
|
+
this.ascii('[');
|
|
81
96
|
for (let index = 0; index < length; index++) {
|
|
82
|
-
|
|
83
|
-
const element = this.dataDescriptor(value, String(index)
|
|
97
|
+
this.keys.push(index);
|
|
98
|
+
const element = this.dataDescriptor(value, String(index));
|
|
84
99
|
if (index > 0)
|
|
85
|
-
this.ascii(',',
|
|
86
|
-
this.write(element, depth + 1
|
|
100
|
+
this.ascii(',', 1);
|
|
101
|
+
this.write(element, depth + 1);
|
|
102
|
+
this.keys.pop();
|
|
87
103
|
}
|
|
88
|
-
this.ascii(']'
|
|
104
|
+
this.ascii(']');
|
|
89
105
|
}
|
|
90
|
-
object(value, depth
|
|
106
|
+
object(value, depth) {
|
|
91
107
|
const prototype = Object.getPrototypeOf(value);
|
|
92
108
|
if (prototype !== Object.prototype && prototype !== null)
|
|
93
|
-
this.fail('unsupported_value', 'objects must be plain (Object.prototype or null prototype)'
|
|
109
|
+
this.fail('unsupported_value', 'objects must be plain (Object.prototype or null prototype)');
|
|
94
110
|
const ownKeys = Reflect.ownKeys(value);
|
|
95
111
|
for (const key of ownKeys)
|
|
96
112
|
if (typeof key !== 'string')
|
|
97
|
-
this.fail('invalid_property', 'symbol keys are not representable'
|
|
113
|
+
this.fail('invalid_property', 'symbol keys are not representable');
|
|
98
114
|
const keys = ownKeys.sort();
|
|
99
|
-
this.ascii('{'
|
|
115
|
+
this.ascii('{');
|
|
100
116
|
for (let index = 0; index < keys.length; index++) {
|
|
101
117
|
const key = keys[index];
|
|
102
|
-
|
|
103
|
-
const element = this.dataDescriptor(value, key
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
this.keys.push(key);
|
|
119
|
+
const element = this.dataDescriptor(value, key);
|
|
120
|
+
let quoted = quotedKeys.get(key);
|
|
121
|
+
if (quoted === undefined) {
|
|
122
|
+
if (!CANONICAL_KEY_PATTERN.test(key))
|
|
123
|
+
this.fail('invalid_key', 'keys must be nonempty printable ASCII (0x21-0x7e)');
|
|
124
|
+
quoted = JSON.stringify(key) + ':';
|
|
125
|
+
if (key.length <= QUOTED_KEY_MAX_LENGTH) {
|
|
126
|
+
if (quotedKeys.size >= QUOTED_KEYS_MAX)
|
|
127
|
+
quotedKeys.clear();
|
|
128
|
+
quotedKeys.set(key, quoted);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
106
131
|
if (index > 0)
|
|
107
|
-
this.ascii(',',
|
|
108
|
-
this.ascii(
|
|
109
|
-
this.write(element, depth + 1
|
|
132
|
+
this.ascii(',', 1);
|
|
133
|
+
this.ascii(quoted);
|
|
134
|
+
this.write(element, depth + 1);
|
|
135
|
+
this.keys.pop();
|
|
110
136
|
}
|
|
111
|
-
this.ascii('}'
|
|
137
|
+
this.ascii('}');
|
|
112
138
|
}
|
|
113
|
-
write(value, depth
|
|
139
|
+
write(value, depth) {
|
|
114
140
|
if (depth > this.maxDepth)
|
|
115
|
-
this.fail('depth_exceeded', `nesting depth exceeds maxDepth ${this.maxDepth}
|
|
141
|
+
this.fail('depth_exceeded', `nesting depth exceeds maxDepth ${this.maxDepth}`);
|
|
116
142
|
if (++this.nodes > this.maxNodes)
|
|
117
|
-
this.fail('nodes_exceeded', `node count exceeds maxNodes ${this.maxNodes}
|
|
143
|
+
this.fail('nodes_exceeded', `node count exceeds maxNodes ${this.maxNodes}`);
|
|
118
144
|
if (value === null) {
|
|
119
|
-
this.ascii('null'
|
|
145
|
+
this.ascii('null');
|
|
120
146
|
return;
|
|
121
147
|
}
|
|
122
148
|
switch (typeof value) {
|
|
123
149
|
case 'string':
|
|
124
|
-
this.string(value
|
|
150
|
+
this.string(value);
|
|
125
151
|
return;
|
|
126
152
|
case 'boolean':
|
|
127
|
-
this.ascii(value ? 'true' : 'false'
|
|
153
|
+
this.ascii(value ? 'true' : 'false');
|
|
128
154
|
return;
|
|
129
155
|
case 'number':
|
|
130
|
-
this.number(value
|
|
156
|
+
this.number(value);
|
|
131
157
|
return;
|
|
132
158
|
case 'object': break;
|
|
133
|
-
default: this.fail('unsupported_value', `${typeof value} is not representable
|
|
159
|
+
default: this.fail('unsupported_value', `${typeof value} is not representable`);
|
|
134
160
|
}
|
|
135
161
|
const target = value;
|
|
136
162
|
if (this.isProxy !== null && this.isProxy(target))
|
|
137
|
-
this.fail('unsupported_value', 'Proxy objects are not representable'
|
|
163
|
+
this.fail('unsupported_value', 'Proxy objects are not representable');
|
|
138
164
|
if (this.ancestors.has(target))
|
|
139
|
-
this.fail('cyclic_reference', 'value contains itself'
|
|
165
|
+
this.fail('cyclic_reference', 'value contains itself');
|
|
140
166
|
this.ancestors.add(target);
|
|
141
167
|
if (Array.isArray(target))
|
|
142
|
-
this.array(target, depth
|
|
168
|
+
this.array(target, depth);
|
|
143
169
|
else
|
|
144
|
-
this.object(target, depth
|
|
170
|
+
this.object(target, depth);
|
|
145
171
|
this.ancestors.delete(target);
|
|
146
172
|
}
|
|
147
173
|
}
|
|
148
174
|
/** canonical 文本(UTF-16 字符串形态;与 `encodeCanonical` 同字节,供宿主内部比较免去编码 / 解码往返)。 */
|
|
149
175
|
export function encodeCanonicalText(value, options) {
|
|
150
176
|
const writer = new Writer(normalizeOptions(options, 'encode'));
|
|
151
|
-
writer.write(value, 0
|
|
152
|
-
return writer.
|
|
177
|
+
writer.write(value, 0);
|
|
178
|
+
return writer.text;
|
|
153
179
|
}
|
|
154
180
|
/** canonical 字节(UTF-8 Uint8Array)。`options.maxBytes` 必填;`maxDepth` / `maxNodes` 只可收紧。 */
|
|
155
181
|
export function encodeCanonical(value, options) {
|
package/dist/events.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare const EventEnvelopeSchema: z.ZodObject<{
|
|
|
39
39
|
/** 事件包络(EventEnvelopeSchema 推导)。 */
|
|
40
40
|
export type EventEnvelope = z.infer<typeof EventEnvelopeSchema>;
|
|
41
41
|
/** 一轮查询的终止原因词表:正常完成、各类上限触顶、模型错误、中断 / 超时 / 关停、hook 阻断等。 */
|
|
42
|
-
export declare const TerminalReasonSchema: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
|
|
42
|
+
export declare const TerminalReasonSchema: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone", "overloaded"]>;
|
|
43
43
|
/** 一轮查询的终止原因(TerminalReasonSchema 推导)。 */
|
|
44
44
|
export type TerminalReason = z.infer<typeof TerminalReasonSchema>;
|
|
45
45
|
/**
|
|
@@ -330,22 +330,22 @@ export declare const EventBodySchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
|
|
|
330
330
|
type: "turn.started";
|
|
331
331
|
}>, z.ZodObject<{
|
|
332
332
|
type: z.ZodLiteral<"turn.completed">;
|
|
333
|
-
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
|
|
333
|
+
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone", "overloaded"]>;
|
|
334
334
|
}, "strip", z.ZodTypeAny, {
|
|
335
335
|
type: "turn.completed";
|
|
336
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
336
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
337
337
|
}, {
|
|
338
338
|
type: "turn.completed";
|
|
339
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
339
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
340
340
|
}>, z.ZodObject<{
|
|
341
341
|
type: z.ZodLiteral<"turn.aborted">;
|
|
342
|
-
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
|
|
342
|
+
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone", "overloaded"]>;
|
|
343
343
|
}, "strip", z.ZodTypeAny, {
|
|
344
344
|
type: "turn.aborted";
|
|
345
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
345
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
346
346
|
}, {
|
|
347
347
|
type: "turn.aborted";
|
|
348
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
348
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
349
349
|
}>, z.ZodObject<{
|
|
350
350
|
type: z.ZodLiteral<"turn.error">;
|
|
351
351
|
scope: z.ZodString;
|
|
@@ -363,9 +363,12 @@ export declare const EventBodySchema: z.ZodDiscriminatedUnion<"type", [z.ZodObje
|
|
|
363
363
|
* 结构化事实位(contract-v0.26;加法可选键):scope='model' 时
|
|
364
364
|
* = IR error 事件 `detail` 透传(providers 自服务端信封带出的机器可判事实;首个取值
|
|
365
365
|
* `{ scope: 'plan' }` = 平台套餐配额拒绝,与 HTTP 面 `error.detail.scope`
|
|
366
|
-
* 同键同值)
|
|
367
|
-
* `
|
|
368
|
-
*
|
|
366
|
+
* 同键同值);scope='kernel' 且 errorKind='overloaded' 时(contract-v0.31 / P-K17-4)
|
|
367
|
+
* = 轮内确定未执行的容量拒绝事实(RFC-CONC-1 登记白名单 `{ scope, reason }`,如
|
|
368
|
+
* `{ scope: 'storage', reason: 'storage_capacity_exceeded' }`)。三端 reducer 归约:
|
|
369
|
+
* `recoverable:true` → `SessionNotice.detail`,失败形 → `ErrorView.detail`;端侧
|
|
370
|
+
* `ErrorEnvelope.scope` 取值器同一读法。缺席 = 无附加事实(既有事件体字节零变)。
|
|
371
|
+
* 值恒不含 endUser 身份 / 令牌 / 内部 id。
|
|
369
372
|
*/
|
|
370
373
|
detail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
371
374
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -1378,22 +1381,22 @@ export declare const KernelEventSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
1378
1381
|
type: "turn.started";
|
|
1379
1382
|
}>, z.ZodObject<{
|
|
1380
1383
|
type: z.ZodLiteral<"turn.completed">;
|
|
1381
|
-
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
|
|
1384
|
+
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone", "overloaded"]>;
|
|
1382
1385
|
}, "strip", z.ZodTypeAny, {
|
|
1383
1386
|
type: "turn.completed";
|
|
1384
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
1387
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
1385
1388
|
}, {
|
|
1386
1389
|
type: "turn.completed";
|
|
1387
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
1390
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
1388
1391
|
}>, z.ZodObject<{
|
|
1389
1392
|
type: z.ZodLiteral<"turn.aborted">;
|
|
1390
|
-
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>;
|
|
1393
|
+
reason: z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone", "overloaded"]>;
|
|
1391
1394
|
}, "strip", z.ZodTypeAny, {
|
|
1392
1395
|
type: "turn.aborted";
|
|
1393
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
1396
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
1394
1397
|
}, {
|
|
1395
1398
|
type: "turn.aborted";
|
|
1396
|
-
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone";
|
|
1399
|
+
reason: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded";
|
|
1397
1400
|
}>, z.ZodObject<{
|
|
1398
1401
|
type: z.ZodLiteral<"turn.error">;
|
|
1399
1402
|
scope: z.ZodString;
|
|
@@ -1411,9 +1414,12 @@ export declare const KernelEventSchema: z.ZodIntersection<z.ZodObject<{
|
|
|
1411
1414
|
* 结构化事实位(contract-v0.26;加法可选键):scope='model' 时
|
|
1412
1415
|
* = IR error 事件 `detail` 透传(providers 自服务端信封带出的机器可判事实;首个取值
|
|
1413
1416
|
* `{ scope: 'plan' }` = 平台套餐配额拒绝,与 HTTP 面 `error.detail.scope`
|
|
1414
|
-
* 同键同值)
|
|
1415
|
-
* `
|
|
1416
|
-
*
|
|
1417
|
+
* 同键同值);scope='kernel' 且 errorKind='overloaded' 时(contract-v0.31 / P-K17-4)
|
|
1418
|
+
* = 轮内确定未执行的容量拒绝事实(RFC-CONC-1 登记白名单 `{ scope, reason }`,如
|
|
1419
|
+
* `{ scope: 'storage', reason: 'storage_capacity_exceeded' }`)。三端 reducer 归约:
|
|
1420
|
+
* `recoverable:true` → `SessionNotice.detail`,失败形 → `ErrorView.detail`;端侧
|
|
1421
|
+
* `ErrorEnvelope.scope` 取值器同一读法。缺席 = 无附加事实(既有事件体字节零变)。
|
|
1422
|
+
* 值恒不含 endUser 身份 / 令牌 / 内部 id。
|
|
1417
1423
|
*/
|
|
1418
1424
|
detail: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1419
1425
|
}, "strip", z.ZodTypeAny, {
|
package/dist/events.js
CHANGED
|
@@ -58,6 +58,10 @@ export const TerminalReasonSchema = z.enum([
|
|
|
58
58
|
// 孤儿策略 / 宿主 onSubscribersGone 钩子裁 interrupt);签发方为驱动层按
|
|
59
59
|
// 中止来源标记,内核 abortReason() 恒不主动产出;用户 ④interrupt 仍走 aborted_*
|
|
60
60
|
'client_gone',
|
|
61
|
+
// contract-v0.31(RFC P-K17-4):轮内确定未执行的容量拒绝专属值——与请求级 503
|
|
62
|
+
// overloaded 同源,细因(RFC-CONC-1 白名单 scope/reason)放前置 turn.error.detail;
|
|
63
|
+
// 签发方唯一 = kernel run-query(beforeModel 失败与 events() 隔离层)
|
|
64
|
+
'overloaded',
|
|
61
65
|
]);
|
|
62
66
|
/**
|
|
63
67
|
* tool.failed 的错误分类(contract-v0.2:由宽 string 收窄)。
|
|
@@ -300,9 +304,12 @@ export const EventBodySchema = z.discriminatedUnion('type', [
|
|
|
300
304
|
* 结构化事实位(contract-v0.26;加法可选键):scope='model' 时
|
|
301
305
|
* = IR error 事件 `detail` 透传(providers 自服务端信封带出的机器可判事实;首个取值
|
|
302
306
|
* `{ scope: 'plan' }` = 平台套餐配额拒绝,与 HTTP 面 `error.detail.scope`
|
|
303
|
-
* 同键同值)
|
|
304
|
-
* `
|
|
305
|
-
*
|
|
307
|
+
* 同键同值);scope='kernel' 且 errorKind='overloaded' 时(contract-v0.31 / P-K17-4)
|
|
308
|
+
* = 轮内确定未执行的容量拒绝事实(RFC-CONC-1 登记白名单 `{ scope, reason }`,如
|
|
309
|
+
* `{ scope: 'storage', reason: 'storage_capacity_exceeded' }`)。三端 reducer 归约:
|
|
310
|
+
* `recoverable:true` → `SessionNotice.detail`,失败形 → `ErrorView.detail`;端侧
|
|
311
|
+
* `ErrorEnvelope.scope` 取值器同一读法。缺席 = 无附加事实(既有事件体字节零变)。
|
|
312
|
+
* 值恒不含 endUser 身份 / 令牌 / 内部 id。
|
|
306
313
|
*/
|
|
307
314
|
detail: z.record(z.string(), z.unknown()).optional(),
|
|
308
315
|
}),
|
package/dist/headless.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare const HeadlessResultRecordSchema: z.ZodObject<{
|
|
|
27
27
|
*/
|
|
28
28
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
29
29
|
/** 终止原因;内部异常路径(无终态)缺省 */
|
|
30
|
-
reason: z.ZodOptional<z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone"]>>;
|
|
30
|
+
reason: z.ZodOptional<z.ZodEnum<["completed", "blocking_limit", "aborted_streaming", "aborted_tools", "model_error", "prompt_too_long", "max_turns", "max_tool_rounds", "injection_limit", "hook_stopped", "structured_output", "timeout", "shutdown", "budget_exceeded", "stop_hook_limit", "internal_error", "client_gone", "overloaded"]>>;
|
|
31
31
|
/** 进程退出码;词表见头注(cli exit-code.ts 为映射事实源) */
|
|
32
32
|
exitCode: z.ZodNumber;
|
|
33
33
|
/** 全程 usage 聚合;无 cost.usage.updated 事件时缺省 */
|
|
@@ -76,7 +76,7 @@ export declare const HeadlessResultRecordSchema: z.ZodObject<{
|
|
|
76
76
|
} | undefined;
|
|
77
77
|
error?: string | undefined;
|
|
78
78
|
sessionId?: string | undefined;
|
|
79
|
-
reason?: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | undefined;
|
|
79
|
+
reason?: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded" | undefined;
|
|
80
80
|
}, {
|
|
81
81
|
type: "result";
|
|
82
82
|
exitCode: number;
|
|
@@ -92,6 +92,6 @@ export declare const HeadlessResultRecordSchema: z.ZodObject<{
|
|
|
92
92
|
} | undefined;
|
|
93
93
|
error?: string | undefined;
|
|
94
94
|
sessionId?: string | undefined;
|
|
95
|
-
reason?: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | undefined;
|
|
95
|
+
reason?: "completed" | "blocking_limit" | "aborted_streaming" | "aborted_tools" | "model_error" | "prompt_too_long" | "max_turns" | "max_tool_rounds" | "injection_limit" | "hook_stopped" | "structured_output" | "timeout" | "shutdown" | "budget_exceeded" | "stop_hook_limit" | "internal_error" | "client_gone" | "overloaded" | undefined;
|
|
96
96
|
}>;
|
|
97
97
|
export type HeadlessResultRecord = z.infer<typeof HeadlessResultRecordSchema>;
|
package/dist/index.d.ts
CHANGED
|
@@ -502,6 +502,15 @@
|
|
|
502
502
|
* 配套严格校验 schema;旧 maxChars 加权语义不变。API 按 tts-input-limit-v1 做新旧投影,
|
|
503
503
|
* SDK/kernel/serve 和示例同源消费;计费量、事件包络和 agent wire revision 不因此改变。
|
|
504
504
|
* API/管理端会签及用户明确批准后实施,tag 待主线收编,不提前发布。
|
|
505
|
+
* - contract-v0.30(STO-01,2026-10-28 用户会签文件日志冷归档格式5最小增量):
|
|
506
|
+
* SessionLogFileManifest 独立描述 session-log-file-v2 的存储身份、提交锚、恢复头及分页材料目录;
|
|
507
|
+
* ColdStorageManifest 为新共同读取入口。SegmentManifest 继续仅表示格式1—4,不改变旧写者;
|
|
508
|
+
* 最高支持版本5与原段合同最高版本4分离。原 owner/lease 不成为恢复授权,wire 包络保持 v0。
|
|
509
|
+
* 新 schema/golden 与出口同步冻结;本笔不发布,后续发布须符合0.x minor门。
|
|
510
|
+
* - contract-v0.31(CONC-01 P-K17-4,2026-11-09 用户会签、2026-11-28 实施;材料:doc/rfc/CONC-01-轮内容量拒绝终止原因草案-2026-11-09.md):
|
|
511
|
+
* ① TerminalReason 加法增 'overloaded',用于轮内确定未执行的容量拒绝(签发方唯一 = kernel run-query);
|
|
512
|
+
* ② turn.error{scope:'kernel', errorKind:'overloaded', recoverable:false, detail:{scope,reason}} 复原既有可选位;
|
|
513
|
+
* ③ schema golden(kernel-event) 与协议导出快照同步再生,会话 MANIFEST / API manifest 随之 bump;不门控,不提前发布。
|
|
505
514
|
*/
|
|
506
515
|
/** contract-v0.28(MEDIA-03,用户授权 2026-09-14):tool_result.artifact 原值保全,
|
|
507
516
|
* 新产物受限 v1 分类;含扩展的存储格式提升 v2,旧 writer 拒绝写入。
|
|
@@ -520,6 +529,8 @@ export * from './metering.js';
|
|
|
520
529
|
export * from './identity.js';
|
|
521
530
|
export * from './daemon.js';
|
|
522
531
|
export * from './storage.js';
|
|
532
|
+
export * from './persistence-custody.generated.js';
|
|
533
|
+
export * from './persistence-custody.js';
|
|
523
534
|
export * from './media.js';
|
|
524
535
|
export * from './tool-result-artifact.js';
|
|
525
536
|
export * from './redact-patterns.js';
|
package/dist/index.js
CHANGED
|
@@ -502,6 +502,15 @@
|
|
|
502
502
|
* 配套严格校验 schema;旧 maxChars 加权语义不变。API 按 tts-input-limit-v1 做新旧投影,
|
|
503
503
|
* SDK/kernel/serve 和示例同源消费;计费量、事件包络和 agent wire revision 不因此改变。
|
|
504
504
|
* API/管理端会签及用户明确批准后实施,tag 待主线收编,不提前发布。
|
|
505
|
+
* - contract-v0.30(STO-01,2026-10-28 用户会签文件日志冷归档格式5最小增量):
|
|
506
|
+
* SessionLogFileManifest 独立描述 session-log-file-v2 的存储身份、提交锚、恢复头及分页材料目录;
|
|
507
|
+
* ColdStorageManifest 为新共同读取入口。SegmentManifest 继续仅表示格式1—4,不改变旧写者;
|
|
508
|
+
* 最高支持版本5与原段合同最高版本4分离。原 owner/lease 不成为恢复授权,wire 包络保持 v0。
|
|
509
|
+
* 新 schema/golden 与出口同步冻结;本笔不发布,后续发布须符合0.x minor门。
|
|
510
|
+
* - contract-v0.31(CONC-01 P-K17-4,2026-11-09 用户会签、2026-11-28 实施;材料:doc/rfc/CONC-01-轮内容量拒绝终止原因草案-2026-11-09.md):
|
|
511
|
+
* ① TerminalReason 加法增 'overloaded',用于轮内确定未执行的容量拒绝(签发方唯一 = kernel run-query);
|
|
512
|
+
* ② turn.error{scope:'kernel', errorKind:'overloaded', recoverable:false, detail:{scope,reason}} 复原既有可选位;
|
|
513
|
+
* ③ schema golden(kernel-event) 与协议导出快照同步再生,会话 MANIFEST / API manifest 随之 bump;不门控,不提前发布。
|
|
505
514
|
*/
|
|
506
515
|
/** contract-v0.28(MEDIA-03,用户授权 2026-09-14):tool_result.artifact 原值保全,
|
|
507
516
|
* 新产物受限 v1 分类;含扩展的存储格式提升 v2,旧 writer 拒绝写入。
|
|
@@ -520,6 +529,9 @@ export * from './metering.js';
|
|
|
520
529
|
export * from './identity.js';
|
|
521
530
|
export * from './daemon.js';
|
|
522
531
|
export * from './storage.js';
|
|
532
|
+
// PST-SERVE-01 已会签:可选托管交接合同及跨语言摘要字节;原业务存储合同不变。
|
|
533
|
+
export * from './persistence-custody.generated.js';
|
|
534
|
+
export * from './persistence-custody.js';
|
|
523
535
|
// 媒体能力内核化 K-1(doc/128 §3.1;加法模块不占号):四媒体产物形单源 + 授权模型描述子 +
|
|
524
536
|
// parseMediaArtifact 三端形状判别参考实现
|
|
525
537
|
export * from './media.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PersistenceCustodyIdentity, PersistenceCustodyRecord, PersistenceCustodyRootRecord, PersistenceCustodyLegacyRootRecord, PersistenceCustodyRootProof, PersistenceCustodyPrepareRequest } from './persistence-custody.generated.js';
|
|
2
|
+
/** 原业务根与控制摘要固定一个快照;源/目的托管位置不参与业务身份。 */
|
|
3
|
+
export declare function persistenceCustodySnapshotBytes(identity: PersistenceCustodyIdentity, root: PersistenceCustodyRootRecord | PersistenceCustodyLegacyRootRecord): Uint8Array;
|
|
4
|
+
/** 空目录初值。目录非空,第一项必须为与 fixedRoot 相符的原根描述。 */
|
|
5
|
+
export declare function persistenceCustodyInventorySeedBytes(identity: PersistenceCustodyIdentity, originFormat: PersistenceCustodyRootProof['originFormat'], fixedRoot: string): Uint8Array;
|
|
6
|
+
/** 每项链式摘要;index 为全目录原序号,从 "0" 开始,与分页大小无关。 */
|
|
7
|
+
export declare function persistenceCustodyRecordBytes(index: string, previousDigest: string, record: PersistenceCustodyRecord): Uint8Array;
|
|
8
|
+
/** 管理意图摘要排除传输 envelope 与 operationId,本键重试不得换意图。 */
|
|
9
|
+
export declare function persistenceCustodyPrepareIntentBytes(request: PersistenceCustodyPrepareRequest): Uint8Array;
|
|
10
|
+
/** 原 PST 请求本身定义 intentSha256;原字节不受托管迁移改写。 */
|
|
11
|
+
export declare function persistenceCustodyWriterIntentBytes(originalRequest: unknown): Uint8Array;
|
|
12
|
+
/** 写者认领 operationId = SHA256(本函数返回的 canonical 字节)。 */
|
|
13
|
+
export declare function persistenceCustodyWriterOperationBytes(originalRequest: unknown): Uint8Array;
|