@kanyun-ai-infra/agenthub 0.2.0 → 0.3.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 CHANGED
@@ -3,7 +3,7 @@
3
3
  用于 **agenthub Control Plane API** 的类型化 TypeScript 客户端。
4
4
 
5
5
  它直接调用 agenthub Control Plane,适合后端服务、CI 和工具以编程方式驱动
6
- `project -> workload -> revision -> session` 生命周期。
6
+ `project → agent → version → session` 生命周期。
7
7
 
8
8
  接入时会遇到两个入口:
9
9
 
@@ -38,16 +38,14 @@ const agenthub = new PilotPlatformClient({
38
38
  token: process.env.PILOT_TOKEN, // 管理门户签发的 platform-api token
39
39
  });
40
40
 
41
- // 1. Project:租户 / 根分组。默认 runtime template 让调用方发布
42
- // Revision 时不必每次手选模板。
41
+ // 1. Project:租户 / 根分组。默认 runtime template 让发布 Version 时不必每次手选模板。
43
42
  const project = await agenthub.projects.create({
44
43
  slug: "acme",
45
44
  displayName: "Acme",
46
45
  defaultRuntimeTemplateRefName: "pilot-v2-pod-agent",
47
46
  });
48
47
 
49
- // 2. Agent:Project 下一个可运行的 agent/app
50
- // (`agents` 是 `workloads` 的别名,下文「术语别名」有说明)
48
+ // 2. Agent:Project 下一个可运行的 agent。
51
49
  await agenthub.agents.create({
52
50
  projectId: project.id,
53
51
  slug: "support-bot",
@@ -59,9 +57,7 @@ await agenthub.agents.create({
59
57
  },
60
58
  });
61
59
 
62
- // 3. Version:Agent 的不可变发布版本(`publishVersion` 是 `publishRevision`
63
- // 的别名)。Runtime source 默认继承 Project default;要按版本覆盖传
64
- // `runtime.profileRef`。
60
+ // 3. Version:Agent 的不可变发布版本。Runtime source 默认继承 Project default。
65
61
  const version = await agenthub.agents.publishVersion({
66
62
  projectId: project.id,
67
63
  agentSlug: "support-bot",
@@ -74,79 +70,52 @@ const version = await agenthub.agents.publishVersion({
74
70
  },
75
71
  });
76
72
 
77
- // 4. Session:基于默认 Version 或指定 Version 分配一次运行时
78
- // (Session 接口仍用 `workloadId` 字段 —— 核心模型保持 workload 命名)
73
+ // 4. Session:基于默认 Version(或指定 Version)分配一次运行时。
79
74
  const session = await agenthub.sessions.create({
80
75
  projectId: project.id,
81
- workloadId: version.workloadId,
76
+ agentId: version.agentId, // 用默认 Version;指定版本传 versionId
82
77
  });
83
78
 
84
79
  const ready = await agenthub.sessions.wait(session.sessionId); // status === "ready" 时返回
85
80
  ```
86
81
 
87
- ## Client 配置
88
-
89
- `new PilotPlatformClient(config)`
90
-
91
- | 选项 | 必填 | 说明 |
92
- | --- | --- | --- |
93
- | `controlPlaneUrl` | 是¹ | Control Plane 源地址。相对路径会拼到它下面;跨 origin 路径会在发 token 前被拒绝。 |
94
- | `token` | 是¹ | Platform-api token。每个请求都会作为 `Authorization: Bearer <token>` 发送。 |
95
- | `fetch` | 否 | 自定义 `fetch` 实现,默认使用全局 `fetch`。 |
96
- | `signal` | 否 | 应用于每个请求的默认 `AbortSignal`。 |
97
- | `defaultHeaders` | 否 | 合并到每个请求的额外 header。 |
98
- | `userAgent` | 否 | 覆盖默认 `@kanyun-ai-infra/agenthub/<version>` UA。 |
99
- | `pilotApiVersion` | 否 | 固定 `x-pilot-api-version` header,默认使用 v2 wire version。 |
100
-
101
- ¹ `controlPlaneUrl` 会依次回退到 `PILOT_CONTROL_PLANE_URL`、
102
- `KANYUN_PILOT_CONTROL_PLANE_URL`;`token` 会回退到 `PILOT_TOKEN`。任意一项缺失时,
103
- SDK 会在发送请求前抛出类型化错误。
104
-
105
- ### 获取 token
106
-
107
- 登录 **管理门户** <https://agenthub.zhenguanyu.com> 并签发 **platform-api token**。
108
- 该 token 的作用域是 Control Plane API(`agenthub-plane.zhenguanyu.com`);可以存为
109
- `PILOT_TOKEN`,也可以显式传给 `token`。Token 是 Bearer 凭据,请不要提交到代码仓库;
110
- 泄露后需要在门户里轮换。
111
-
112
82
  ## 核心模型
113
83
 
114
84
  ```text
115
- Project -> Workload -> Revision -> Session
85
+ Project → Agent → Version → Session
116
86
  ```
117
87
 
118
- - **Project**:租户 / 根分组,拥有 workloads 和 runtime templates。
119
- - **Workload**:一个逻辑可运行应用。`kind` 是 `"managed_agent"`(平台基于
88
+ - **Project**:租户 / 根分组,拥有 agents 和 runtime templates。
89
+ - **Agent**:一个逻辑可运行应用。`kind` 是 `"managed_agent"`(平台基于
120
90
  `model` + `systemPrompt` 运行 agent loop)或 `"self_managed"`(你自己提供 worker)。
121
- - **Revision**:Workload 的不可变发布版本,绑定一个 runtime source。用 `setDefault`
122
- 标记 project/workload 默认版本。
123
- - **Session**:基于某个 Revision 发起的一次 startup/runtime allocation。
91
+ - **Version**:Agent 的不可变发布版本,绑定一个 runtime source。用 `setDefault`
92
+ 标记 project/agent 默认版本。
93
+ - **Session**:基于某个 Version 发起的一次 startup/runtime allocation。
124
94
 
125
- Workloads 和 runtime templates 都是 **project-scoped**。Revision 必须在同一个 Project
126
- 内解析到 Workload 和 runtime source;唯一例外是下文的 platform-shared templates。
95
+ Agents 和 runtime templates 都是 **project-scoped**。Version 必须在同一个 Project
96
+ 内解析到 Agent 和 runtime source;唯一例外是下文的 platform-shared templates。
127
97
 
128
- ### 术语别名(agent / version)
98
+ > 本文一律用主词汇 **agent / version**;它们是底层 wire 名 `workload` / `revision`
99
+ > 的别名,SDK 两套都接受,细节见 [术语别名](#术语别名agent--version)。
129
100
 
130
- 为降低理解成本,SDK 为核心概念提供了一组**别名**——语义完全一致,只是更口语化:
101
+ ### 术语别名(agent / version)
131
102
 
132
- | 规范名(核心模型) | 友好别名 | 说明 |
103
+ | 主词汇(推荐) | 等价的底层名 | 说明 |
133
104
  | --- | --- | --- |
134
- | `agenthub.workloads` | `agenthub.agents` | **同一个资源实例**,方法完全一致。 |
135
- | `workloads.publishRevision({ workloadSlug })` | `agents.publishVersion({ agentSlug })` | 同一个调用;友好版用 `agentSlug`,内部映射回 `workloadSlug` 后发出,wire body 完全一致。 |
136
- | 概念 “Workload” / “Revision” | “Agent” / “Version” | 仅命名差异。 |
105
+ | `agenthub.agents` | `agenthub.workloads` | **同一个资源实例**(`agents === workloads`),方法两边都能调。 |
106
+ | `agents.publishVersion({ agentSlug })` | `workloads.publishRevision({ workloadSlug })` | 同一个调用;wire body 完全一致。 |
107
+ | `sessions.create({ agentId, versionId })` | `sessions.create({ workloadId, revisionId })` | 入参别名,内部映射回规范名后再发出。 |
108
+ | 返回字段 `result.agentId` / `result.versionId` | `result.workloadId` / `result.revisionId` | 返回对象**同时带**两套字段(别名 = 规范值)。 |
137
109
 
138
- `agentSlug` 仅在 `publishVersion` 上;`publishRevision` 仍用 `workloadSlug`。
139
- `applyRevisionManifest` 两个拼写都接受(同时给出时 `workloadSlug` 优先)。
110
+ 规则:
140
111
 
141
- 别名是**附加糖**:`workloads` / `publishRevision` / `workloadSlug` 一直保留,行为不变;
142
- 返回结果的字段名(`workloadId` / `revisionId`)以及 `sessions.create({ workloadId })`
143
- 仍沿用核心模型命名。挑读起来顺的那套写即可。
144
-
145
- ```ts
146
- // 下面两段完全等价
147
- await agenthub.agents.publishVersion({ projectId, agentSlug: "support-bot", version: "v1", workerContract: { kind: "managed_agent" } });
148
- await agenthub.workloads.publishRevision({ projectId, workloadSlug: "support-bot", version: "v1", workerContract: { kind: "managed_agent" } });
149
- ```
112
+ - **互斥**:一对里只能传一个,规范名和别名同传会抛 `ALIAS_CONFLICT`,避免笔误被静默忽略
113
+ (`sessions.create` 的 `agentId`/`workloadId`、`versionId`/`revisionId`,
114
+ `applyRevisionManifest` 的 `agentSlug`/`workloadSlug`)。
115
+ - 入参别名**不进 wire**:发请求前映射回 `workloadId`/`revisionId`,body 永远是规范名。
116
+ - 返回别名是 SDK 派生的可枚举字段(`JSON.stringify` / 日志都带得上),不回传服务端。
117
+ - 底层名(`workloads` / `publishRevision` / `workloadId`)一直保留、行为不变,挑读着顺的那套写即可。
118
+ - 异步事件 payload、日志 / Trace 里的关联 ID 仍是 `workloadId`/`revisionId`(属 control-plane 范畴,不在 SDK 改名范围内)。
150
119
 
151
120
  ## API 参考
152
121
 
@@ -158,119 +127,35 @@ await agenthub.workloads.publishRevision({ projectId, workloadSlug: "support-bot
158
127
  | `list()` | 列出 token 有效 scope 内的 Project。 |
159
128
  | `get(projectId)` | 查询单个 Project。 |
160
129
 
161
- ### `agenthub.workloads`(别名 `agenthub.agents`)
162
-
163
- > `agenthub.agents` 与 `agenthub.workloads` 是同一个对象,下表方法两边都能调。
130
+ ### `agenthub.agents`(别名 `agenthub.workloads`)
164
131
 
165
132
  | 方法 | 说明 |
166
133
  | --- | --- |
167
- | `create(req, { dryRun? })` | 用结构化输入创建 Workload。返回 `{ mode, status, workloadId?, workload }`。 |
168
- | `publishRevision(req, { dryRun? })` | 发布 Revision。返回 `{ mode, status, workloadId, revisionId?, runtimeTemplateId, resolved }`。 |
169
- | `publishVersion(req, { dryRun? })` | `publishRevision` 的友好别名;`req` 用 `agentSlug` 代替 `workloadSlug`。返回结构与 `publishRevision` **完全相同**(字段仍是 `workloadId` / `revisionId`,不会改名为 `agentId` / `versionId`)。 |
170
- | `applyManifest({ projectId, manifest, dryRun? })` | 高级 / GitOps:apply raw workload manifest。 |
171
- | `applyRevisionManifest({ projectId, workloadSlug \| agentSlug, manifest, dryRun? })` | 高级 / GitOps:apply raw revision manifest。两个 slug 拼写都接受,同时给出时 `workloadSlug` 优先。 |
172
-
173
- `create` 的 `req`:
174
-
175
- ```ts
176
- {
177
- projectId: string;
178
- slug: string;
179
- displayName: string;
180
- kind: "managed_agent" | "self_managed";
181
- defaults?: {
182
- model?: string;
183
- systemPrompt?: string;
184
- workerContract?: { name?: string; version?: string };
185
- configValues?: Record<string, string>;
186
- enabledSkills?: EnabledSkill[];
187
- enabledMcpServers?: EnabledMcpServer[];
188
- };
189
- ui?: { /* Default-UI hints */ };
190
- }
191
- ```
192
-
193
- `publishRevision` 的 `req`:
194
-
195
- ```ts
196
- {
197
- projectId: string;
198
- workloadSlug: string;
199
- version: string;
200
- workerContract: { kind: "managed_agent" | "self_managed"; name?: string; version?: string };
201
- runtime?: { profileRef?: { name: string }; environment?: ...; overrides?: ... };
202
- setDefault?: boolean;
203
- startup?: { requiredGates?: string[]; optionalGates?: string[] };
204
- configValues?: Record<string, string>;
205
- managedAgentProfileSnapshot?: { model?: string; systemPrompt?: string; enabledSkills?: ...; enabledMcpServers?: ... };
206
- }
207
- ```
134
+ | `create(req, { dryRun? })` | 创建 Agent。返回 `{ mode, status, agentId?/workloadId?, workload }`。 |
135
+ | `publishVersion(req, { dryRun? })` | 发布 Version(别名 `publishRevision`,用 `workloadSlug`)。返回 `{ mode, status, agentId/workloadId, versionId?/revisionId?, runtimeTemplateId, resolved }`。 |
136
+ | `applyManifest({ projectId, manifest, dryRun? })` | 高级 / GitOps:apply raw agent manifest。 |
137
+ | `applyRevisionManifest({ projectId, agentSlug \| workloadSlug, manifest, dryRun? })` | 高级 / GitOps:apply raw version manifest。两个 slug 拼写都接受(互斥)。 |
138
+
139
+ `create` / `publishVersion` 的 `req` 结构和 managed-agent 全部配置项(`model` /
140
+ `systemPrompt` / `enabledSkills` / `enabledMcpServers` / `agentOptions` 安全约束 /
141
+ `runtime` / `startup` 等),见
142
+ [`specs/features/agenthub-sdk.md`](../../specs/features/agenthub-sdk.md)
143
+ 的 "Managed-Agent Configuration"、"Workload API Contract"、"Revision Publish Contract" 章节。
144
+
145
+ > **`agentOptions` 安全约束(高频踩坑)**:`agentOptions` **只能收紧 / 限额**,不能放宽。
146
+ > `allowedTools` 与平台基线**取交集**(只会更窄)、`disallowedTools` 叠加平台黑名单且
147
+ > **不能移除**平台守卫工具;`permissionMode` / `env` / `mcpServers` / `hooks` /
148
+ > `plugins` / 原始 `sdkOptions` 等可能越权或逃逸 sandbox 的字段**一律不开放**(见 issue #840)。
149
+ > 字段全表见上述 spec。
208
150
 
209
151
  `apply*` 方法里的 `manifest` 可以是 manifest 对象、`{ yaml }` 或 `{ json }`。
210
152
 
211
- ### Agent 配置项总览
212
-
213
- managed_agent 的配置可写在两处,语义不同(**Version 快照优先级高于 Workload 默认**):
214
-
215
- | 写在哪 | 字段入口 | 性质 |
216
- | --- | --- | --- |
217
- | `agents.create({ defaults })` | Workload 级默认 | 可变;作为新版本的起始模板,也是没快照时的兜底。 |
218
- | `agents.publishVersion({ managedAgentProfileSnapshot })` | Version 级不可变快照 | **session 运行时实际解析的值**;按版本钉死,隔离后续对 defaults 的修改。 |
219
-
220
- > 想要「版本钉死 + 隔离」的真实 agent 配置就写在 `managedAgentProfileSnapshot`;
221
- > `defaults` 当作 workload 级默认模板。两层字段基本一致(下表)。
222
-
223
- #### 画像字段(`defaults` 与 `managedAgentProfileSnapshot` 通用)
224
-
225
- | 字段 | 类型 | 说明 |
226
- | --- | --- | --- |
227
- | `model` | `string` | 模型 id 或别名(见 [模型](#模型))。 |
228
- | `systemPrompt` | `string` | 系统提示词,≤ 32768 字符。 |
229
- | `enabledSkills` | `EnabledSkillEntry[]` | 启用的 Rush skills。 |
230
- | `enabledMcpServers` | `EnabledMcpEntry[]` | 启用的 MCP server,每个可带 `toolFilter` / `extraConfigValues` / `disabled`。 |
231
- | `configValues` | `Record<string, string>` | 配置 / env 键值(有保留 key 与长度限制)。 |
232
- | `agentOptions` | `AgentOptions` | 高级运行选项,见下表。 |
233
-
234
- `defaults` 额外接受 `workerContract`(workload 级默认 worker 契约);
235
- `managedAgentProfileSnapshot` 仅当 `workerContract.kind === "managed_agent"` 时允许。
236
-
237
- #### `agentOptions`(仅 managed_agent;**只能收紧 / 限额**)
238
-
239
- | 字段 | 约束 | 说明 |
240
- | --- | --- | --- |
241
- | `maxTurns` | 整数 1–200 | 最大 agentic 轮次。 |
242
- | `maxThinkingTokens` | 整数 1–60000 | 扩展思考 token 预算。 |
243
- | `maxBudgetUsd` | 0–50 | 单次运行花费上限(USD)。 |
244
- | `effort` | `"low"|"medium"|"high"|"max"` | 推理强度。 |
245
- | `allowedTools` | `string[]`,≤ 64 | 工具白名单;与平台基线**取交集**(只会更窄)。 |
246
- | `disallowedTools` | `string[]`,≤ 64 | 工具黑名单;叠加平台黑名单,**不能移除**平台守卫工具。支持有界 arg matcher(如 `Bash(rm:*)`),禁止全通配 `(*)` / `(*:*)`。 |
247
-
248
- 出于跨租户安全,`agentOptions` 故意**不开放** `permissionMode` / `env` / `mcpServers` / `systemPrompt`
249
- 替换 / `hooks` / `plugins` / 原始 `sdkOptions` 等可能越权或逃逸 sandbox 的字段(见 issue #840)。
250
-
251
- #### Version 级其他字段(`publishVersion` / `publishRevision`,非画像)
252
-
253
- | 字段 | 说明 |
254
- | --- | --- |
255
- | `workerContract` | `{ kind: "managed_agent" | "self_managed"; name?; version? }`,必填。 |
256
- | `setDefault` | 是否设为默认版本,默认 `true`。 |
257
- | `startup` | 启动门禁 `{ requiredGates?: string[]; optionalGates?: string[] }`。 |
258
- | `runtime` | 运行时环境 `{ profileRef?; environment?; overrides? }`,省略则继承 project 默认。 |
259
- | `configValues` | version 级配置 / env 键值。 |
260
-
261
- #### Workload 级其他字段(`create`)
262
-
263
- | 字段 | 说明 |
264
- | --- | --- |
265
- | `ui` | Default-UI 展示提示(`WorkloadManifestUiHint`)。 |
266
- | `defaults.workerContract` | workload 级默认 worker 契约。 |
267
-
268
153
  ### `agenthub.sessions`
269
154
 
270
155
  | 方法 | 说明 |
271
156
  | --- | --- |
272
- | `create({ projectId, workloadId, revisionId?, configValues?, metadata?, idempotencyKey?, resources?, ... })` | 启动 Session。省略 `revisionId` 时使用 Workload 默认 Revision。`resources` 注入 Model A 只读输入文件(见下)。返回 `{ sessionId, status }`。 |
273
- | `get(sessionId)` | 读取 Session 快照(`{ session: { id, status, ... } }`)。 |
157
+ | `create({ projectId, agentId, versionId?, configValues?, metadata?, idempotencyKey?, resources?, ... })` | 启动 Session。省略 `versionId` 时使用 Agent 默认 Version。`agentId`/`versionId` 也可写成 `workloadId`/`revisionId`(互斥)。`resources` 注入 Model A 只读输入文件(见下)。返回 `{ sessionId, status }`。 |
158
+ | `get(sessionId)` | 读取 Session 快照(`{ session: { id, status, ... } }`,字段为服务端原样返回)。 |
274
159
  | `wait(sessionId, { intervalMs?, timeoutMs?, signal? })` | 轮询到 `status === "ready"`;遇到 `failed` 或超时会抛错。 |
275
160
 
276
161
  Session `status` 取值为 `created`、`provisioning`、`starting`、`ready`、`failed`。
@@ -303,7 +188,7 @@ const { url, ...meta } = up;
303
188
 
304
189
  const { sessionId } = await agenthub.sessions.create({
305
190
  projectId,
306
- workloadId,
191
+ agentId,
307
192
  resources: {
308
193
  version: "v1",
309
194
  files: [{ ...meta, mountPath: "docs/spec.md" }], // mountPath 可省略 → 用文件名
@@ -315,20 +200,45 @@ const { sessionId } = await agenthub.sessions.create({
315
200
  约束:每 Session ≤ 20 个文件;`mountPath` 必须是 `.session/inputs/` 下的相对子路径
316
201
  (拒绝绝对路径与 `..`);只读。
317
202
 
203
+ ## Client 配置
204
+
205
+ `new PilotPlatformClient(config)`
206
+
207
+ | 选项 | 必填 | 说明 |
208
+ | --- | --- | --- |
209
+ | `controlPlaneUrl` | 是¹ | Control Plane 源地址。相对路径会拼到它下面;跨 origin 路径会在发 token 前被拒绝。 |
210
+ | `token` | 是¹ | Platform-api token。每个请求都会作为 `Authorization: Bearer <token>` 发送。 |
211
+ | `fetch` | 否 | 自定义 `fetch` 实现,默认使用全局 `fetch`。 |
212
+ | `signal` | 否 | 应用于每个请求的默认 `AbortSignal`。 |
213
+ | `defaultHeaders` | 否 | 合并到每个请求的额外 header。 |
214
+ | `userAgent` | 否 | 覆盖默认 `@kanyun-ai-infra/agenthub/<version>` UA。 |
215
+ | `pilotApiVersion` | 否 | 固定 `x-pilot-api-version` header,默认使用 v2 wire version。 |
216
+
217
+ ¹ `controlPlaneUrl` 会依次回退到 `PILOT_CONTROL_PLANE_URL`、
218
+ `KANYUN_PILOT_CONTROL_PLANE_URL`;`token` 会回退到 `PILOT_TOKEN`。任意一项缺失时,
219
+ SDK 会在发送请求前抛出类型化错误。
220
+
221
+ ### 获取 token
222
+
223
+ 登录 **管理门户** <https://agenthub.zhenguanyu.com> 并签发 **platform-api token**。
224
+ 该 token 的作用域是 Control Plane API(`agenthub-plane.zhenguanyu.com`);可以存为
225
+ `PILOT_TOKEN`,也可以显式传给 `token`。Token 是 Bearer 凭据,请不要提交到代码仓库;
226
+ 泄露后需要在门户里轮换。
227
+
318
228
  ## Runtime template
319
229
 
320
- managed-agent Revision 运行在一个 **runtime template**(已注册的 runtime source)上。
230
+ managed-agent Version 运行在一个 **runtime template**(已注册的 runtime source)上。
321
231
  Control Plane 按以下顺序解析:
322
232
 
323
- 1. revision `runtime.profileRef`(structured)/ `spec.runtime.profileRef`
324
- 2. revision `spec.runtimeTemplateRef`(manifest)
325
- 3. workload defaults `spec.defaults.runtimeTemplateRef`(manifest)
233
+ 1. version `runtime.profileRef`(structured)/ `spec.runtime.profileRef`
234
+ 2. version `spec.runtimeTemplateRef`(manifest)
235
+ 3. agent defaults `spec.defaults.runtimeTemplateRef`(manifest)
326
236
  4. project `defaultRuntimeTemplateRefName`
327
237
 
328
238
  如果都解析不到,返回 `PROJECT_DEFAULT_RUNTIME_MISSING`。如果指定模板在当前 Project
329
239
  或 platform-shared templates 中不存在,返回 `RUNTIME_TEMPLATE_NOT_FOUND`。
330
240
 
331
- 主路径建议在创建 Project 时设置默认模板,这样调用方发布 Revision 时不需要手选:
241
+ 主路径建议在创建 Project 时设置默认模板,这样发布 Version 时不需要手选:
332
242
 
333
243
  ```ts
334
244
  await agenthub.projects.create({
@@ -338,12 +248,11 @@ await agenthub.projects.create({
338
248
  });
339
249
  ```
340
250
 
341
- 否则需要在每个 Revision 上显式指定:
342
- `runtime: { profileRef: { name: "..." } }`。
251
+ 否则需要在每个 Version 上显式指定:`runtime: { profileRef: { name: "..." } }`。
343
252
 
344
253
  **Platform-shared templates。** Platform Default project 拥有的模板(例如
345
254
  `pilot-v2-pod-agent`)是共享基础设施:当调用方 Project 内找不到同名模板时,解析会回退到
346
- Platform Default,因此任意 Project 的 Revision 都可以按名称引用它们。`echo-bot`
255
+ Platform Default,因此任意 Project 的 Version 都可以按名称引用它们。`echo-bot`
347
256
  是内置 echo-only 模板,适合 smoke test;它**不会**运行 LLM。
348
257
 
349
258
  ## 模型
@@ -359,9 +268,9 @@ Platform Default,因此任意 Project 的 Revision 都可以按名称引用它
359
268
 
360
269
  ## Dry runs
361
270
 
362
- `workloads.create`、`publishRevision` 和 `apply*` 方法都接受 `{ dryRun: true }`。
271
+ `agents.create`、`publishVersion` 和 `apply*` 方法都接受 `{ dryRun: true }`。
363
272
  dry run 会校验并解析请求,但不持久化;返回 `mode: "dry_run"` 和
364
- `would_create` / `would_update` 状态;Revision 已存在且内容一致时可能返回
273
+ `would_create` / `would_update` 状态;Version 已存在且内容一致时可能返回
365
274
  `existing`。正式发布前可以用它确认 runtime template 能正确解析。
366
275
 
367
276
  ## 错误
package/dist/index.cjs CHANGED
@@ -991,6 +991,7 @@ var ManagedAgentProfileSnapshotSchema = import_zod4.z.object({
991
991
  enabledSkills: EnabledSkillEntryListSchema.optional(),
992
992
  enabledMcpServers: EnabledMcpEntryListSchema.optional(),
993
993
  configValues: SessionConfigValuesSchema.optional(),
994
+ resources: SessionResourcesSchema.optional(),
994
995
  agentOptions: AgentOptionsSchema.optional()
995
996
  }).strict();
996
997
  var ManagedAgentOverridesSchema = import_zod4.z.object({
@@ -1053,6 +1054,15 @@ var WorkloadManifestDefaultsSchema = import_zod4.z.object({
1053
1054
  * `specs/features/pilot-v2-managed-agent-profile.md` §"Phase C".
1054
1055
  */
1055
1056
  enabledMcpServers: EnabledMcpEntryListSchema.optional(),
1057
+ /**
1058
+ * Workload-level **default session resources** for managed_agent runtime
1059
+ * files. Persisted into `workloads.manifest_defaults_json`, frozen onto
1060
+ * `revisions.managed_agent_profile_snapshot_json` at publish time, then
1061
+ * copied to `sessions.session_resources_json` when the caller does not
1062
+ * supply explicit session resources. The agent runtime receives paths to
1063
+ * mounted files; file content is not injected into the prompt.
1064
+ */
1065
+ resources: SessionResourcesSchema.optional(),
1056
1066
  /**
1057
1067
  * Workload-level **default agent options** (managed_agent profile
1058
1068
  * "Phase E1"). A flat, only-tighten / bounded-resource subset of the
@@ -3910,7 +3920,11 @@ var ManagedAgentProfileSpecSchema = import_zod41.z.object({
3910
3920
  // `PilotCoderRunConfigV1.systemPrompt`. agent-worker uses it instead of
3911
3921
  // the platform-level `SYSTEM_PROMPT` fallback. See
3912
3922
  // `specs/features/pilot-v2-managed-agent-profile.md` §"Phase D".
3913
- systemPrompt: WorkloadManifestSystemPromptSchema.optional()
3923
+ systemPrompt: WorkloadManifestSystemPromptSchema.optional(),
3924
+ // Agent-level default runtime files. The envelope is exactly the session
3925
+ // resources contract so the same mount/download path handles both default
3926
+ // files and caller-supplied per-session files.
3927
+ resources: SessionResourcesSchema.optional()
3914
3928
  }).strict();
3915
3929
  var ManagedAgentProfileSchema = import_zod41.z.object({
3916
3930
  apiVersion: PilotWorkloadManifestApiVersionSchema,
@@ -4613,13 +4627,51 @@ var ProjectsResource = class {
4613
4627
  }
4614
4628
  };
4615
4629
 
4630
+ // src/agent-vocab.ts
4631
+ function resolveExclusiveAlias(canonicalKey, canonicalValue, aliasKey, aliasValue) {
4632
+ if (canonicalValue !== void 0 && aliasValue !== void 0) {
4633
+ throw new PilotPlatformApiError({
4634
+ status: 0,
4635
+ code: "ALIAS_CONFLICT",
4636
+ message: `Provide either \`${canonicalKey}\` or its alias \`${aliasKey}\`, not both \u2014 they name the same value.`
4637
+ });
4638
+ }
4639
+ return canonicalValue ?? aliasValue;
4640
+ }
4641
+ function attachAgentAliases(data) {
4642
+ const agentId = typeof data.workloadId === "string" ? data.workloadId : void 0;
4643
+ const versionId = typeof data.revisionId === "string" ? data.revisionId : void 0;
4644
+ return {
4645
+ ...data,
4646
+ ...agentId !== void 0 && data.agentId === void 0 ? { agentId } : {},
4647
+ ...versionId !== void 0 && data.versionId === void 0 ? { versionId } : {}
4648
+ };
4649
+ }
4650
+
4616
4651
  // src/resources/sessions.ts
4652
+ function normalizeSessionRequest(request) {
4653
+ const { agentId, versionId, ...rest } = request;
4654
+ const workloadId = resolveExclusiveAlias("workloadId", rest.workloadId, "agentId", agentId);
4655
+ const revisionId = resolveExclusiveAlias("revisionId", rest.revisionId, "versionId", versionId);
4656
+ if (workloadId === void 0) {
4657
+ throw new PilotPlatformApiError({
4658
+ status: 0,
4659
+ code: "WORKLOAD_ID_REQUIRED",
4660
+ message: "sessions.create requires `agentId` (or `workloadId`)."
4661
+ });
4662
+ }
4663
+ return {
4664
+ ...rest,
4665
+ workloadId,
4666
+ ...revisionId !== void 0 ? { revisionId } : {}
4667
+ };
4668
+ }
4617
4669
  var SessionsResource = class {
4618
4670
  constructor(client) {
4619
4671
  this.client = client;
4620
4672
  }
4621
4673
  async create(request, options = {}) {
4622
- const body = CreatePlatformSessionRequestSchema.parse(request);
4674
+ const body = CreatePlatformSessionRequestSchema.parse(normalizeSessionRequest(request));
4623
4675
  const envelope = await this.client.request("/api/sessions", {
4624
4676
  method: "POST",
4625
4677
  body,
@@ -4740,7 +4792,12 @@ var WorkloadsResource = class {
4740
4792
  return unwrapEnvelope(envelope, "POST /api/workloads", ["status", "workload"]);
4741
4793
  }
4742
4794
  async applyRevisionManifest(options) {
4743
- const slug = options.workloadSlug ?? options.agentSlug;
4795
+ const slug = resolveExclusiveAlias(
4796
+ "workloadSlug",
4797
+ options.workloadSlug,
4798
+ "agentSlug",
4799
+ options.agentSlug
4800
+ );
4744
4801
  if (!slug) {
4745
4802
  throw new PilotPlatformApiError({
4746
4803
  status: 0,
@@ -4805,7 +4862,7 @@ function unwrapEnvelope(envelope, routeLabel, requiredKeys) {
4805
4862
  });
4806
4863
  }
4807
4864
  }
4808
- return data;
4865
+ return attachAgentAliases(data);
4809
4866
  }
4810
4867
 
4811
4868
  // src/client.ts