@soiljs/spi 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +110 -2
- package/dist/chunk-22LK3R2V.js +81 -0
- package/dist/chunk-22LK3R2V.js.map +1 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.js +345 -0
- package/dist/index.js.map +1 -0
- package/dist/storage-DfHSUuQH.d.ts +619 -0
- package/dist/testing/index.d.ts +30 -0
- package/dist/testing/index.js +899 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +38 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ximing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,111 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @soiljs/spi
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Soil 的 Layer 0 扩展契约:让 Runtime、工具与存储实现共享同一套类型、原子操作和错误语义。**零运行依赖**,主入口不导入 `node:` 模块,可用于 Node、Edge 与浏览器;适合编写扩展与兼容存储,不包含执行循环或数据库后端。
|
|
4
|
+
|
|
5
|
+
## 安装与入口
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @soiljs/spi
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
| 导出入口 | 用途 |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `@soiljs/spi` | 工具、存储、压缩、事件与命令契约,状态常量、校验、错误、用量聚合 |
|
|
14
|
+
| `@soiljs/spi/testing` | `runStorageContractTests`;通过结构化参数注入测试框架,无测试运行时依赖 |
|
|
15
|
+
|
|
16
|
+
## 最小可运行示例
|
|
17
|
+
|
|
18
|
+
在业务调用前验证输入,并按统一错误体系处理不合法数据:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { ToolValidationError, validateSchemaInput } from "@soiljs/spi";
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const input = await validateSchemaInput<{ orderId: string }>(
|
|
25
|
+
{
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: { orderId: { type: "string", minLength: 1 } },
|
|
28
|
+
required: ["orderId"],
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
},
|
|
31
|
+
{ orderId: "order-42" },
|
|
32
|
+
);
|
|
33
|
+
console.log(input.orderId);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error instanceof ToolValidationError) console.error(error.code, error.issues);
|
|
36
|
+
else throw error;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 核心契约与配置速查
|
|
41
|
+
|
|
42
|
+
| 契约 | 负责什么 |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `StorageAdapter` | 组合 `ledger`、`outbox`、`artifacts`,以及 `kind`、`open()`、`close()` |
|
|
45
|
+
| `LedgerStore` | Session/Turn/Step/Attempt、租约、T1–T7 领域原子操作、恢复查询 |
|
|
46
|
+
| `OutboxStore` | 持久事件读取、消费者确认游标、裁剪与缺口 |
|
|
47
|
+
| `ArtifactStore` | 不可变内容寻址产物、读取与可选 `pruneUnreferenced` 回收 |
|
|
48
|
+
| `ToolDefinition` / `ToolkitProvider` | 输入、执行、审批、对账;工具包生命周期与发现 |
|
|
49
|
+
| `ContextStrategy<TModel>` | 已提交历史视图、压缩与宿主注入的模型调用桥梁 |
|
|
50
|
+
| 事件与观测钩子 | 区分持久事实与内存实时事件 |
|
|
51
|
+
| 命令信封、回执、授权钩子 | actor、scope、幂等命令与状态校验 |
|
|
52
|
+
|
|
53
|
+
`ToolEffect = "none" | "external"`,`ApprovalDecision = "none" | "required"`。`ReconcileResult` 包含 `completed`、`failed`、`not_executed` 与 `unknown`,不能用幂等键替代对账证据。本包没有环境变量配置。
|
|
54
|
+
|
|
55
|
+
### 错误体系
|
|
56
|
+
|
|
57
|
+
所有标准错误继承 `SoilError`,保留 `code` 与 `retryable`:
|
|
58
|
+
|
|
59
|
+
| 错误 | 业务含义 |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `SessionBusyError` | Session 已有活跃 Turn,附带 `activeTurnId` |
|
|
62
|
+
| `LeaseLostError` | holder、epoch 或有效期不匹配,禁止继续写入 |
|
|
63
|
+
| `ConcurrencyConflictError` | 版本/状态竞争,可重试标记为 true |
|
|
64
|
+
| `IdempotencyConflictError` | 同一键复用时载荷不同 |
|
|
65
|
+
| `CommandRejectedError` | 未授权、scope 不符、未找到或状态不允许 |
|
|
66
|
+
| `ToolValidationError` | 输入不合法,携带结构化 issues |
|
|
67
|
+
| `AgentNotRegisteredError` | 恢复需要的 Agent/版本未注册 |
|
|
68
|
+
|
|
69
|
+
### Schema 与用量
|
|
70
|
+
|
|
71
|
+
`validateSchemaInput` 支持同步/异步 Standard Schema v1,保留其转换结果。内置 JSON Schema 子集支持类型、对象属性、必填项、枚举、数组、唯一性、字符串/数值边界,以及 `allOf/anyOf/oneOf/not`;不做类型强转、默认值注入或远程引用解析。包括 `$ref`、`format` 在内的不支持关键字与畸形 Schema 会拒绝,未命中的分支也要有效。完整方言请接入 Standard Schema 校验器。
|
|
72
|
+
|
|
73
|
+
`UsageMetrics` 的四个 token 字段均必填但可为 `null`,`completeness` 为 `complete | partial | unknown`,`costMicros` 可选且可空。`aggregateUsageTotals(usages)` 只累计完整记录,并返回 `completeCount`、`incompleteCount` 与 `hasIncompleteUsage`。未知值不转换成零。
|
|
74
|
+
|
|
75
|
+
模型 Step 可携带 `protocolId`、`modelId`、不透明 `continuation` 或 `continuationArtifact`;SPI 不依赖 models,也不解释供应商数据。产物必须先写字节再提交引用。
|
|
76
|
+
|
|
77
|
+
## 九组存储契约测试
|
|
78
|
+
|
|
79
|
+
用 `@soiljs/spi/testing` 验证新后端。工厂需为每个测试创建隔离存储,并在 `close` 时清理文件/连接;完整接线可参考 [本地存储契约测试](../storage-local/src/__tests__/storage-local.contract.test.ts)。
|
|
80
|
+
|
|
81
|
+
| 组 | 覆盖行为 |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| 1 | 并发准入与 FIFO 排队 |
|
|
84
|
+
| 2 | 租约与 epoch 栅栏 |
|
|
85
|
+
| 3 | Steering 与原子兜底 |
|
|
86
|
+
| 4 | 派发、兄弟 Step 独立提交、Attempt 历史与用量/续接 |
|
|
87
|
+
| 5 | 子 Turn 派发与父级唤醒 |
|
|
88
|
+
| 6 | 幂等命令与作用域 |
|
|
89
|
+
| 7 | 终态提交与队列激活 |
|
|
90
|
+
| 8 | Outbox 游标与缺口 |
|
|
91
|
+
| 9 | 内容寻址产物与引用保护回收 |
|
|
92
|
+
|
|
93
|
+
调用形式为 `runStorageContractTests(name, factory, { describe, it, expect, beforeEach, afterEach })`;可用第四个参数 `{ advanceTime(ms) }` 注入时钟,默认使用短暂真实延迟。第九组完整合规需要可选的 `pruneUnreferenced`。
|
|
94
|
+
|
|
95
|
+
## 关键边界
|
|
96
|
+
|
|
97
|
+
领域写入必须原子校验租约/版本、更新状态并追加 Outbox;过期租约在任何修改前失败。完成的 Attempt 历史不可覆盖,兄弟 Step 独立提交,等待态释放租约。`listSessionTurns` 按账本顺序返回脱离存储的快照,不依赖 Outbox 留存;成功完成才自动激活 Follow-up。
|
|
98
|
+
|
|
99
|
+
`applyCommand` 在 Runtime 授权后仍需校验作用域与状态;相同命令 ID/指纹返回 `duplicate`,不同载荷抛幂等冲突。外部效果未决保持 `unknown`,只有证实未执行才能走相应恢复重试,没有 exactly-once。实时事件永不入 Outbox。Console DTO 属于工作区私有协议包。
|
|
100
|
+
|
|
101
|
+
## 深入阅读与本地校验
|
|
102
|
+
|
|
103
|
+
[在线 API](https://ximing.github.io/agent-foundation/#/api/spi) · [存储契约](../../docs/03-spi-storage-contracts.md) · [根目录示例](../../README.md)
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
pnpm --filter @soiljs/spi typecheck
|
|
107
|
+
pnpm --filter @soiljs/spi exec tsup
|
|
108
|
+
pnpm exec vitest run packages/spi/src/__tests__
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
包导出均指向 `dist`,两个入口共享错误类身份;使用前先构建。
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var SOIL_ERROR_CODES = [
|
|
3
|
+
"SESSION_BUSY",
|
|
4
|
+
"LEASE_LOST",
|
|
5
|
+
"CONCURRENCY_CONFLICT",
|
|
6
|
+
"IDEMPOTENCY_CONFLICT",
|
|
7
|
+
"COMMAND_REJECTED",
|
|
8
|
+
"TOOL_VALIDATION_FAILED",
|
|
9
|
+
"AGENT_NOT_REGISTERED"
|
|
10
|
+
];
|
|
11
|
+
var COMMAND_REJECTION_REASONS = [
|
|
12
|
+
"unauthorized",
|
|
13
|
+
"scope_mismatch",
|
|
14
|
+
"not_found",
|
|
15
|
+
"invalid_state",
|
|
16
|
+
"turn_already_terminal"
|
|
17
|
+
];
|
|
18
|
+
var SoilError = class extends Error {
|
|
19
|
+
constructor(message, code, retryable = false, options) {
|
|
20
|
+
super(message, options);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.retryable = retryable;
|
|
23
|
+
this.name = new.target.name;
|
|
24
|
+
}
|
|
25
|
+
code;
|
|
26
|
+
retryable;
|
|
27
|
+
};
|
|
28
|
+
var SessionBusyError = class extends SoilError {
|
|
29
|
+
constructor(activeTurnId, options) {
|
|
30
|
+
super(`Session has active Turn ${activeTurnId}.`, "SESSION_BUSY", false, options);
|
|
31
|
+
this.activeTurnId = activeTurnId;
|
|
32
|
+
}
|
|
33
|
+
activeTurnId;
|
|
34
|
+
};
|
|
35
|
+
var LeaseLostError = class extends SoilError {
|
|
36
|
+
constructor(message = "The execution lease is no longer valid.", options) {
|
|
37
|
+
super(message, "LEASE_LOST", false, options);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var ConcurrencyConflictError = class extends SoilError {
|
|
41
|
+
constructor(message = "The expected ledger version no longer matches.", options) {
|
|
42
|
+
super(message, "CONCURRENCY_CONFLICT", true, options);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var IdempotencyConflictError = class extends SoilError {
|
|
46
|
+
constructor(message = "The idempotency key was reused with a different payload.", options) {
|
|
47
|
+
super(message, "IDEMPOTENCY_CONFLICT", false, options);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var CommandRejectedError = class extends SoilError {
|
|
51
|
+
constructor(rejectionReason, options) {
|
|
52
|
+
super(`Command rejected: ${rejectionReason}.`, "COMMAND_REJECTED", false, options);
|
|
53
|
+
this.rejectionReason = rejectionReason;
|
|
54
|
+
}
|
|
55
|
+
rejectionReason;
|
|
56
|
+
};
|
|
57
|
+
var ToolValidationError = class extends SoilError {
|
|
58
|
+
constructor(issues, options) {
|
|
59
|
+
super("Tool input failed schema validation.", "TOOL_VALIDATION_FAILED", false, options);
|
|
60
|
+
this.issues = issues;
|
|
61
|
+
}
|
|
62
|
+
issues;
|
|
63
|
+
};
|
|
64
|
+
var AgentNotRegisteredError = class extends SoilError {
|
|
65
|
+
constructor(agentId, agentVersion, options) {
|
|
66
|
+
super(
|
|
67
|
+
`Agent ${agentId} is not registered at the required version.`,
|
|
68
|
+
"AGENT_NOT_REGISTERED",
|
|
69
|
+
false,
|
|
70
|
+
options
|
|
71
|
+
);
|
|
72
|
+
this.agentId = agentId;
|
|
73
|
+
this.agentVersion = agentVersion;
|
|
74
|
+
}
|
|
75
|
+
agentId;
|
|
76
|
+
agentVersion;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { AgentNotRegisteredError, COMMAND_REJECTION_REASONS, CommandRejectedError, ConcurrencyConflictError, IdempotencyConflictError, LeaseLostError, SOIL_ERROR_CODES, SessionBusyError, SoilError, ToolValidationError };
|
|
80
|
+
//# sourceMappingURL=chunk-22LK3R2V.js.map
|
|
81
|
+
//# sourceMappingURL=chunk-22LK3R2V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";AAAO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,cAAA;AAAA,EACA,YAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA,kBAAA;AAAA,EACA,wBAAA;AAAA,EACA;AACF;AAEO,IAAM,yBAAA,GAA4B;AAAA,EACvC,cAAA;AAAA,EACA,gBAAA;AAAA,EACA,WAAA;AAAA,EACA,eAAA;AAAA,EACA;AACF;AAGO,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EACnC,WAAA,CACE,OAAA,EACS,IAAA,EACA,SAAA,GAAqB,OAC9B,OAAA,EACA;AACA,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAJb,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAIT,IAAA,IAAA,CAAK,OAAO,GAAA,CAAA,MAAA,CAAW,IAAA;AAAA,EACzB;AAAA,EANW,IAAA;AAAA,EACA,SAAA;AAMb;AAEO,IAAM,gBAAA,GAAN,cAA+B,SAAA,CAAU;AAAA,EAC9C,WAAA,CACW,cACT,OAAA,EACA;AACA,IAAA,KAAA,CAAM,CAAA,wBAAA,EAA2B,YAAY,CAAA,CAAA,CAAA,EAAK,cAAA,EAAgB,OAAO,OAAO,CAAA;AAHvE,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AAAA,EAIX;AAAA,EAJW,YAAA;AAKb;AACO,IAAM,cAAA,GAAN,cAA6B,SAAA,CAAU;AAAA,EAC5C,WAAA,CAAY,OAAA,GAAU,yCAAA,EAA2C,OAAA,EAAwB;AACvF,IAAA,KAAA,CAAM,OAAA,EAAS,YAAA,EAAc,KAAA,EAAO,OAAO,CAAA;AAAA,EAC7C;AACF;AACO,IAAM,wBAAA,GAAN,cAAuC,SAAA,CAAU;AAAA,EACtD,WAAA,CAAY,OAAA,GAAU,gDAAA,EAAkD,OAAA,EAAwB;AAC9F,IAAA,KAAA,CAAM,OAAA,EAAS,sBAAA,EAAwB,IAAA,EAAM,OAAO,CAAA;AAAA,EACtD;AACF;AACO,IAAM,wBAAA,GAAN,cAAuC,SAAA,CAAU;AAAA,EACtD,WAAA,CACE,OAAA,GAAU,0DAAA,EACV,OAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,sBAAA,EAAwB,KAAA,EAAO,OAAO,CAAA;AAAA,EACvD;AACF;AACO,IAAM,oBAAA,GAAN,cAAmC,SAAA,CAAU;AAAA,EAClD,WAAA,CACW,iBACT,OAAA,EACA;AACA,IAAA,KAAA,CAAM,CAAA,kBAAA,EAAqB,eAAe,CAAA,CAAA,CAAA,EAAK,kBAAA,EAAoB,OAAO,OAAO,CAAA;AAHxE,IAAA,IAAA,CAAA,eAAA,GAAA,eAAA;AAAA,EAIX;AAAA,EAJW,eAAA;AAKb;AAKO,IAAM,mBAAA,GAAN,cAAkC,SAAA,CAAU;AAAA,EACjD,WAAA,CACW,QACT,OAAA,EACA;AACA,IAAA,KAAA,CAAM,sCAAA,EAAwC,wBAAA,EAA0B,KAAA,EAAO,OAAO,CAAA;AAH7E,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAIX;AAAA,EAJW,MAAA;AAKb;AACO,IAAM,uBAAA,GAAN,cAAsC,SAAA,CAAU;AAAA,EACrD,WAAA,CACW,OAAA,EACA,YAAA,EACT,OAAA,EACA;AACA,IAAA,KAAA;AAAA,MACE,SAAS,OAAO,CAAA,2CAAA,CAAA;AAAA,MAChB,sBAAA;AAAA,MACA,KAAA;AAAA,MACA;AAAA,KACF;AATS,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA;AAAA,EASX;AAAA,EAVW,OAAA;AAAA,EACA,YAAA;AAUb","file":"chunk-22LK3R2V.js","sourcesContent":["export const SOIL_ERROR_CODES = [\n \"SESSION_BUSY\",\n \"LEASE_LOST\",\n \"CONCURRENCY_CONFLICT\",\n \"IDEMPOTENCY_CONFLICT\",\n \"COMMAND_REJECTED\",\n \"TOOL_VALIDATION_FAILED\",\n \"AGENT_NOT_REGISTERED\",\n] as const;\nexport type SoilErrorCode = (typeof SOIL_ERROR_CODES)[number];\nexport const COMMAND_REJECTION_REASONS = [\n \"unauthorized\",\n \"scope_mismatch\",\n \"not_found\",\n \"invalid_state\",\n \"turn_already_terminal\",\n] as const;\nexport type CommandRejectionReason = (typeof COMMAND_REJECTION_REASONS)[number];\n\nexport class SoilError extends Error {\n constructor(\n message: string,\n readonly code: SoilErrorCode,\n readonly retryable: boolean = false,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\nexport class SessionBusyError extends SoilError {\n constructor(\n readonly activeTurnId: string,\n options?: ErrorOptions,\n ) {\n super(`Session has active Turn ${activeTurnId}.`, \"SESSION_BUSY\", false, options);\n }\n}\nexport class LeaseLostError extends SoilError {\n constructor(message = \"The execution lease is no longer valid.\", options?: ErrorOptions) {\n super(message, \"LEASE_LOST\", false, options);\n }\n}\nexport class ConcurrencyConflictError extends SoilError {\n constructor(message = \"The expected ledger version no longer matches.\", options?: ErrorOptions) {\n super(message, \"CONCURRENCY_CONFLICT\", true, options);\n }\n}\nexport class IdempotencyConflictError extends SoilError {\n constructor(\n message = \"The idempotency key was reused with a different payload.\",\n options?: ErrorOptions,\n ) {\n super(message, \"IDEMPOTENCY_CONFLICT\", false, options);\n }\n}\nexport class CommandRejectedError extends SoilError {\n constructor(\n readonly rejectionReason: CommandRejectionReason,\n options?: ErrorOptions,\n ) {\n super(`Command rejected: ${rejectionReason}.`, \"COMMAND_REJECTED\", false, options);\n }\n}\nexport interface SchemaIssue {\n readonly message: string;\n readonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[];\n}\nexport class ToolValidationError extends SoilError {\n constructor(\n readonly issues: readonly SchemaIssue[],\n options?: ErrorOptions,\n ) {\n super(\"Tool input failed schema validation.\", \"TOOL_VALIDATION_FAILED\", false, options);\n }\n}\nexport class AgentNotRegisteredError extends SoilError {\n constructor(\n readonly agentId: string,\n readonly agentVersion?: string,\n options?: ErrorOptions,\n ) {\n super(\n `Agent ${agentId} is not registered at the required version.`,\n \"AGENT_NOT_REGISTERED\",\n false,\n options,\n );\n }\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { S as SchemaIssue, A as ArtifactRef, T as ToolEffect, a as ScopeRef, b as ArtifactStore, c as Step, d as TerminalStepStatus, U as UsageMetrics } from './storage-DfHSUuQH.js';
|
|
2
|
+
export { e as APPROVAL_STATUSES, f as ATTEMPT_KINDS, g as ATTEMPT_STATUSES, h as AdmitTurnInput, i as AdmitTurnResult, j as AgentNotRegisteredError, k as ApprovalRecord, l as ApprovalRecordSnapshot, m as ApprovalStatus, n as Attempt, o as AttemptKind, p as AttemptSnapshot, q as AttemptStatus, C as COMMAND_KINDS, r as COMMAND_REJECTION_REASONS, s as CommandActor, t as CommandAuthorizer, u as CommandEnvelope, v as CommandKind, w as CommandPayload, x as CommandReceipt, y as CommandRejectedError, z as CommandRejectionReason, B as CompleteStepInput, D as CompletedStepInput, E as ConcurrencyConflictError, F as CreateSessionInput, G as DURABLE_EVENT_TYPES, H as DurableEventType, I as DurableRuntimeEvent, J as EnqueueSteeringInput, K as EnqueueSteeringResult, L as ErrorRecord, M as EventCorrelation, N as FinishTurnInput, O as FinishTurnResult, P as IdempotencyConflictError, Q as LeaseLostError, R as LeaseRequest, V as LeaseToken, W as LedgerStore, X as ModelDispatchInput, Y as NewStep, Z as ObservabilityHook, _ as OutboxBatch, $ as OutboxStore, a0 as REALTIME_EVENT_TYPES, a1 as RealtimeEvent, a2 as RealtimeEventType, a3 as SOIL_ERROR_CODES, a4 as STEERING_STATUSES, a5 as STEP_KINDS, a6 as STEP_STATUSES, a7 as Session, a8 as SessionBusyError, a9 as SessionSnapshot, aa as SoilError, ab as SoilErrorCode, ac as SpanRecord, ad as SteeringEntry, ae as SteeringEntrySnapshot, af as SteeringStatus, ag as StepKind, ah as StepSnapshot, ai as StepStatus, aj as StorageAdapter, ak as TERMINAL_STEP_STATUSES, al as TERMINAL_TURN_STATUSES, am as TOOL_EFFECTS, an as TURN_STATUSES, ao as TerminalTurnStatus, ap as ToolValidationError, aq as Turn, ar as TurnSnapshot, as as TurnStatus, at as TurnWrite, au as UsageCompleteness, av as UsageTotals, aw as aggregateUsageTotals, ax as isApprovalStatus, ay as isAttemptKind, az as isAttemptStatus, aA as isCommandKind, aB as isDurableEventType, aC as isRealtimeEventType, aD as isSteeringStatus, aE as isStepKind, aF as isStepStatus, aG as isTerminalStepStatus, aH as isTerminalTurnStatus, aI as isToolEffect, aJ as isTurnStatus } from './storage-DfHSUuQH.js';
|
|
3
|
+
|
|
4
|
+
/** Structural Standard Schema v1; works without importing a validator library. */
|
|
5
|
+
interface StandardSchemaV1<TOutput = unknown, TInput = unknown> {
|
|
6
|
+
readonly "~standard": {
|
|
7
|
+
readonly version: 1;
|
|
8
|
+
readonly vendor: string;
|
|
9
|
+
readonly validate: (value: unknown) => StandardSchemaResult<TOutput> | Promise<StandardSchemaResult<TOutput>>;
|
|
10
|
+
readonly types?: {
|
|
11
|
+
readonly input: TInput;
|
|
12
|
+
readonly output: TOutput;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
type StandardSchemaResult<T> = {
|
|
17
|
+
readonly value: T;
|
|
18
|
+
readonly issues?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
readonly issues: readonly SchemaIssue[];
|
|
21
|
+
};
|
|
22
|
+
type JsonSchema = Readonly<Record<string, unknown>>;
|
|
23
|
+
type SchemaInput<T = unknown> = StandardSchemaV1<T> | JsonSchema;
|
|
24
|
+
/**
|
|
25
|
+
* Returns validated/transformed input or throws ToolValidationError.
|
|
26
|
+
* JSON Schema supports the documented local assertion subset. Unsupported
|
|
27
|
+
* keywords and malformed schemas fail closed; use Standard Schema for a full
|
|
28
|
+
* dialect implementation. No defaults, coercion, network or filesystem access.
|
|
29
|
+
*/
|
|
30
|
+
declare function validateSchemaInput<T>(schema: SchemaInput<T>, input: unknown): Promise<T>;
|
|
31
|
+
|
|
32
|
+
type ApprovalDecision = "none" | "required";
|
|
33
|
+
type ReconcileResult = {
|
|
34
|
+
status: "completed";
|
|
35
|
+
output: unknown;
|
|
36
|
+
artifacts?: ArtifactRef[];
|
|
37
|
+
} | {
|
|
38
|
+
status: "failed";
|
|
39
|
+
reason: string;
|
|
40
|
+
} | {
|
|
41
|
+
status: "not_executed";
|
|
42
|
+
} | {
|
|
43
|
+
status: "unknown";
|
|
44
|
+
reason?: string;
|
|
45
|
+
};
|
|
46
|
+
interface ToolExecutionContext<TServices = Record<string, unknown>, TContext = Record<string, unknown>> {
|
|
47
|
+
readonly sessionId: string;
|
|
48
|
+
readonly turnId: string;
|
|
49
|
+
readonly stepId: string;
|
|
50
|
+
readonly attemptNo: number;
|
|
51
|
+
/** Stable across Attempts, distinct from toolCallId and business dedup identity. */
|
|
52
|
+
readonly operationKey: string;
|
|
53
|
+
readonly scope?: ScopeRef;
|
|
54
|
+
readonly context: Readonly<TContext>;
|
|
55
|
+
readonly services: Readonly<TServices>;
|
|
56
|
+
readonly signal: AbortSignal;
|
|
57
|
+
readonly artifacts: ArtifactStore;
|
|
58
|
+
reportProgress(message: string, data?: Record<string, unknown>): void;
|
|
59
|
+
}
|
|
60
|
+
interface ToolDefinition<TInput = unknown, TOutput = unknown, TServices = Record<string, unknown>, TContext = Record<string, unknown>> {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly version: string;
|
|
63
|
+
readonly description: string;
|
|
64
|
+
readonly inputSchema: SchemaInput<TInput>;
|
|
65
|
+
readonly effect: ToolEffect;
|
|
66
|
+
readonly approval?: ApprovalDecision | ((arg: {
|
|
67
|
+
input: TInput;
|
|
68
|
+
context: Readonly<TContext>;
|
|
69
|
+
scope?: ScopeRef;
|
|
70
|
+
}) => ApprovalDecision | Promise<ApprovalDecision>);
|
|
71
|
+
readonly retryPolicy?: {
|
|
72
|
+
maxAttempts: number;
|
|
73
|
+
backoffMs?: number;
|
|
74
|
+
};
|
|
75
|
+
execute(input: TInput, ctx: ToolExecutionContext<TServices, TContext>): Promise<TOutput>;
|
|
76
|
+
reconcile?(input: TInput, ctx: ToolExecutionContext<TServices, TContext>): Promise<ReconcileResult>;
|
|
77
|
+
}
|
|
78
|
+
interface ToolkitProvider<TServices = Record<string, unknown>, TContext = Record<string, unknown>> {
|
|
79
|
+
open(services: Readonly<TServices>): Promise<void>;
|
|
80
|
+
listTools(): Promise<readonly ToolDefinition<unknown, unknown, TServices, TContext>[]>;
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface ContextMessage {
|
|
85
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
86
|
+
content: unknown;
|
|
87
|
+
toolCallId?: string;
|
|
88
|
+
continuation?: unknown;
|
|
89
|
+
}
|
|
90
|
+
interface CommittedStepView extends Omit<Step, "status"> {
|
|
91
|
+
readonly status: TerminalStepStatus;
|
|
92
|
+
}
|
|
93
|
+
interface ContextView {
|
|
94
|
+
readonly sessionId: string;
|
|
95
|
+
readonly turnId: string;
|
|
96
|
+
readonly iteration: number;
|
|
97
|
+
readonly estimatedTokens: number;
|
|
98
|
+
readonly systemPrompt: string;
|
|
99
|
+
/** Plain dialogue for summarization by a potentially different model/protocol. */
|
|
100
|
+
readonly messagesToCompact: readonly ContextMessage[];
|
|
101
|
+
readonly latestCompaction?: {
|
|
102
|
+
stepId: string;
|
|
103
|
+
compactedUpToStepId: string;
|
|
104
|
+
summary: string;
|
|
105
|
+
metadata?: Record<string, unknown>;
|
|
106
|
+
};
|
|
107
|
+
readonly uncompactedSteps: readonly CommittedStepView[];
|
|
108
|
+
readonly cutPointStepId: string;
|
|
109
|
+
}
|
|
110
|
+
interface CompactionContext<TModel = string> {
|
|
111
|
+
readonly signal: AbortSignal;
|
|
112
|
+
readonly artifacts: ArtifactStore;
|
|
113
|
+
callModel(request: {
|
|
114
|
+
model?: TModel;
|
|
115
|
+
messages: readonly ContextMessage[];
|
|
116
|
+
maxOutputTokens?: number;
|
|
117
|
+
}): Promise<{
|
|
118
|
+
text: string;
|
|
119
|
+
usage: UsageMetrics;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
interface CompactionOutput {
|
|
123
|
+
readonly compactedUpToStepId: string;
|
|
124
|
+
readonly summary: string;
|
|
125
|
+
readonly metadata?: Record<string, unknown>;
|
|
126
|
+
readonly artifactRef?: ArtifactRef;
|
|
127
|
+
}
|
|
128
|
+
interface ContextStrategy<TModel = string> {
|
|
129
|
+
readonly id: string;
|
|
130
|
+
readonly version: string;
|
|
131
|
+
shouldCompact(view: ContextView): boolean;
|
|
132
|
+
compact(view: ContextView, ctx: CompactionContext<TModel>): Promise<CompactionOutput>;
|
|
133
|
+
/** Pure projection; committed prefixes must remain byte-for-byte stable. */
|
|
134
|
+
project?(view: ContextView): readonly ContextMessage[];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { type ApprovalDecision, ArtifactRef, ArtifactStore, type CommittedStepView, type CompactionContext, type CompactionOutput, type ContextMessage, type ContextStrategy, type ContextView, type JsonSchema, type ReconcileResult, type SchemaInput, SchemaIssue, ScopeRef, type StandardSchemaResult, type StandardSchemaV1, Step, TerminalStepStatus, type ToolDefinition, ToolEffect, type ToolExecutionContext, type ToolkitProvider, UsageMetrics, validateSchemaInput };
|