@1agents/acp-service 0.8.1 → 0.8.2

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.
Files changed (103) hide show
  1. package/README.md +37 -2
  2. package/dist/bin/a2a.js +3 -2
  3. package/dist/src/a2a/executor.d.ts +2 -0
  4. package/dist/src/a2a/executor.js +63 -10
  5. package/dist/src/a2a/gateway.d.ts +407 -14
  6. package/dist/src/a2a/gateway.js +719 -37
  7. package/dist/src/a2a/index.d.ts +8 -1
  8. package/dist/src/a2a/index.js +4 -0
  9. package/dist/src/a2a/notices.d.ts +24 -0
  10. package/dist/src/a2a/notices.js +56 -0
  11. package/dist/src/a2a/preflight.d.ts +52 -0
  12. package/dist/src/a2a/preflight.js +153 -0
  13. package/dist/src/a2a/result-metadata.d.ts +59 -0
  14. package/dist/src/a2a/result-metadata.js +156 -0
  15. package/dist/src/a2a/server.js +30 -0
  16. package/dist/src/a2a/session-delivery.d.ts +69 -0
  17. package/dist/src/a2a/session-delivery.js +260 -0
  18. package/dist/src/a2a/session-hosts.d.ts +34 -0
  19. package/dist/src/a2a/session-hosts.js +211 -0
  20. package/dist/src/a2a/store.js +3 -1
  21. package/dist/src/a2a/types.d.ts +33 -0
  22. package/dist/src/execution/delivery-progress.d.ts +108 -0
  23. package/dist/src/execution/delivery-progress.js +57 -0
  24. package/dist/src/execution/ledger.d.ts +235 -0
  25. package/dist/src/execution/ledger.js +396 -0
  26. package/dist/src/execution/ppt-delivery.d.ts +231 -0
  27. package/dist/src/execution/ppt-delivery.js +625 -0
  28. package/dist/src/execution/targets.d.ts +349 -0
  29. package/dist/src/execution/targets.js +428 -0
  30. package/package.json +11 -12
  31. package/skills/acp-service/SKILL.md +9 -2
  32. package/skills/acp-service/references/a2a.md +72 -4
  33. package/vendor/dsh/a2a-executor.d.ts +2 -1
  34. package/vendor/dsh/a2a-executor.js +28 -1
  35. package/vendor/dsh/a2a.js +1 -0
  36. package/vendor/dsh/client.js +11 -3
  37. package/vendor/runtime/dist/{agent-registry-CMg8LHKY.js → agent-registry-R7A3MSpr.js} +9 -1
  38. package/vendor/runtime/dist/agent-registry-R7A3MSpr.js.map +1 -0
  39. package/vendor/runtime/dist/agent-registry.d.ts +1 -0
  40. package/vendor/runtime/dist/agent-registry.d.ts.map +1 -1
  41. package/vendor/runtime/dist/agent-registry.js +1 -2
  42. package/vendor/runtime/dist/{cli-Bdzplbpj.js → cli-DeOpE2Xz.js} +4 -4
  43. package/vendor/runtime/dist/{cli-Bdzplbpj.js.map → cli-DeOpE2Xz.js.map} +1 -1
  44. package/vendor/runtime/dist/cli.d.ts +2 -1
  45. package/vendor/runtime/dist/cli.js +10 -10
  46. package/vendor/runtime/dist/cli.js.map +1 -1
  47. package/vendor/runtime/dist/{client-BXOiB0ND.d.ts → client-VQsqcIOJ.d.ts} +2 -2
  48. package/vendor/runtime/dist/{client-BXOiB0ND.d.ts.map → client-VQsqcIOJ.d.ts.map} +1 -1
  49. package/vendor/runtime/dist/docs-site/.nojekyll +0 -0
  50. package/vendor/runtime/dist/docs-site/CLI.html +833 -0
  51. package/vendor/runtime/dist/docs-site/VISION.html +415 -0
  52. package/vendor/runtime/dist/docs-site/agents.html +391 -0
  53. package/vendor/runtime/dist/docs-site/compare.html +359 -0
  54. package/vendor/runtime/dist/docs-site/config.html +450 -0
  55. package/vendor/runtime/dist/docs-site/custom-agents.html +408 -0
  56. package/vendor/runtime/dist/docs-site/exit-codes.html +347 -0
  57. package/vendor/runtime/dist/docs-site/favicon.svg +21 -0
  58. package/vendor/runtime/dist/docs-site/flows.html +498 -0
  59. package/vendor/runtime/dist/docs-site/index.html +367 -0
  60. package/vendor/runtime/dist/docs-site/install.html +386 -0
  61. package/vendor/runtime/dist/docs-site/llms.txt +36 -0
  62. package/vendor/runtime/dist/docs-site/output-formats.html +407 -0
  63. package/vendor/runtime/dist/docs-site/permissions.html +422 -0
  64. package/vendor/runtime/dist/docs-site/prompting.html +460 -0
  65. package/vendor/runtime/dist/docs-site/quickstart.html +382 -0
  66. package/vendor/runtime/dist/docs-site/releasing.html +341 -0
  67. package/vendor/runtime/dist/docs-site/runtime-environment.html +329 -0
  68. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +335 -0
  69. package/vendor/runtime/dist/docs-site/safe-errors.html +323 -0
  70. package/vendor/runtime/dist/docs-site/session-control.html +408 -0
  71. package/vendor/runtime/dist/docs-site/session-watch.html +354 -0
  72. package/vendor/runtime/dist/docs-site/sessions.html +488 -0
  73. package/vendor/runtime/dist/docs-site/shared-sessions.html +377 -0
  74. package/vendor/runtime/dist/{flows-BKlAuzM8.js → flows-oaBGn31w.js} +5 -5
  75. package/vendor/runtime/dist/{flows-BKlAuzM8.js.map → flows-oaBGn31w.js.map} +1 -1
  76. package/vendor/runtime/dist/flows.d.ts +2 -2
  77. package/vendor/runtime/dist/flows.d.ts.map +1 -1
  78. package/vendor/runtime/dist/flows.js +1 -2
  79. package/vendor/runtime/dist/{invocation-options-DMy77sEU.js → invocation-options-CUDEE8vW.js} +5 -5
  80. package/vendor/runtime/dist/{invocation-options-DMy77sEU.js.map → invocation-options-CUDEE8vW.js.map} +1 -1
  81. package/vendor/runtime/dist/{ipc-CLv2iL89.js → ipc-BQQpcEdP.js} +98 -20
  82. package/vendor/runtime/dist/ipc-BQQpcEdP.js.map +1 -0
  83. package/vendor/runtime/dist/{output-I-t-v55D.js → output-CFv3jcOQ.js} +86 -22
  84. package/vendor/runtime/dist/output-CFv3jcOQ.js.map +1 -0
  85. package/vendor/runtime/dist/{queue-owner-runtime-RN3uSid0.js → queue-owner-runtime-DvMJiGbP.js} +86 -27
  86. package/vendor/runtime/dist/queue-owner-runtime-DvMJiGbP.js.map +1 -0
  87. package/vendor/runtime/dist/runtime.d.ts +5 -2
  88. package/vendor/runtime/dist/runtime.d.ts.map +1 -1
  89. package/vendor/runtime/dist/runtime.js +77 -29
  90. package/vendor/runtime/dist/runtime.js.map +1 -1
  91. package/vendor/runtime/dist/{session-options-DNnDfiUt.d.ts → session-options-NjpFwf-c.d.ts} +5 -1
  92. package/vendor/runtime/dist/session-options-NjpFwf-c.d.ts.map +1 -0
  93. package/vendor/runtime/dist/{session-watch-CmHbH0jS.js → session-watch-Di-wIdCH.js} +4 -4
  94. package/vendor/runtime/dist/{session-watch-CmHbH0jS.js.map → session-watch-Di-wIdCH.js.map} +1 -1
  95. package/vendor/runtime/dist/{watch-BE-kKa7o.js → watch-CIpoMaWD.js} +2 -2
  96. package/vendor/runtime/dist/{watch-BE-kKa7o.js.map → watch-CIpoMaWD.js.map} +1 -1
  97. package/vendor/runtime/package.json +1 -1
  98. package/vendor/runtime/skills/acpx/SKILL.md +7 -2
  99. package/vendor/runtime/dist/agent-registry-CMg8LHKY.js.map +0 -1
  100. package/vendor/runtime/dist/ipc-CLv2iL89.js.map +0 -1
  101. package/vendor/runtime/dist/output-I-t-v55D.js.map +0 -1
  102. package/vendor/runtime/dist/queue-owner-runtime-RN3uSid0.js.map +0 -1
  103. package/vendor/runtime/dist/session-options-DNnDfiUt.d.ts.map +0 -1
@@ -0,0 +1,428 @@
1
+ /** Manually maintained execution targets. This directory never starts an agent or a workflow. */
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { z } from 'zod';
6
+ const id = z.string().trim().min(1).max(256).regex(/^[A-Za-z0-9][A-Za-z0-9.:_-]*$/);
7
+ const text = z.string().trim().min(1).max(4096);
8
+ const version = z.number().int().positive();
9
+ const absolutePath = text.refine(value => path.posix.isAbsolute(value), 'Expected an absolute remote path');
10
+ const jsonObject = z.record(z.string(), z.unknown());
11
+ const endpoint = z.string().url().refine(value => {
12
+ const url = new URL(value);
13
+ return ['http:', 'https:'].includes(url.protocol) && !url.username && !url.password;
14
+ }, 'Expected an HTTP(S) endpoint without embedded credentials');
15
+ // Credentials remain in gateway remotes. Only the alias and derived non-secret URL are retained.
16
+ export const executionConnectionConfigSchema = z.object({
17
+ connectionId: id, provider: z.enum(['a2a', 'activepieces']).default('a2a'), remote: id,
18
+ enabled: z.boolean().default(true), description: text.optional(),
19
+ probePolicy: z.object({ ttlMs: z.number().int().min(100).max(3_600_000).default(60_000),
20
+ timeoutMs: z.number().int().min(100).max(60_000).default(5000) }).strict().optional(),
21
+ }).strict();
22
+ export const executionConnectionSchema = executionConnectionConfigSchema.extend({
23
+ connectionVersion: version, createdAt: z.string().datetime(), updatedAt: z.string().datetime(),
24
+ endpoint: endpoint.optional(), endpointFingerprint: z.string().regex(/^[a-f0-9]{64}$/).optional(),
25
+ }).strict();
26
+ export const executionTargetBindingSchema = z.object({
27
+ remote: id.optional(), cwd: absolutePath.optional(), agentPreset: id.optional(),
28
+ roleId: id.optional(), skillRefs: z.array(text).max(100).optional(),
29
+ allowedDirectories: z.array(absolutePath).min(1).max(100).optional(),
30
+ allowedPresets: z.array(id).min(1).max(100).optional(),
31
+ flowId: id.optional(), flowVersion: text.optional(), driver: z.literal('ppt_delivery').optional(),
32
+ }).strict();
33
+ export const executionTargetConfigSchema = z.object({
34
+ targetId: id, kind: z.enum(['agent_host', 'resident_agent', 'workflow']), name: text,
35
+ description: text.optional(), connectionId: id, enabled: z.boolean().default(true),
36
+ inputSchema: jsonObject.optional(), outputSchema: jsonObject.optional(),
37
+ capabilities: z.object({ query: z.boolean().default(true), cancel: z.boolean().default(true),
38
+ continue: z.boolean().default(true), reconcile: z.boolean().default(false) }).strict().optional(),
39
+ binding: executionTargetBindingSchema.default({}),
40
+ }).strict();
41
+ export const executionTargetSchema = executionTargetConfigSchema.extend({
42
+ configVersion: version, createdAt: z.string().datetime(), updatedAt: z.string().datetime(),
43
+ }).strict();
44
+ export const targetHealthSchema = z.object({
45
+ targetId: id, configVersion: version, connectionId: id, connectionVersion: version,
46
+ connectionStatus: z.enum(['unknown', 'reachable', 'unreachable', 'auth_required']),
47
+ targetStatus: z.enum(['unknown', 'ready', 'misconfigured', 'unavailable']),
48
+ checkedAt: z.string().datetime(), validUntil: z.string().datetime(), checkedScope: z.array(text).max(100),
49
+ lastSuccessAt: z.string().datetime().optional(), reasonCode: text.optional(),
50
+ failureCount: z.number().int().nonnegative(), nextCheckAt: z.string().datetime().optional(),
51
+ capacity: z.enum(['busy', 'available', 'unknown']).optional(),
52
+ }).strict().superRefine((health, ctx) => {
53
+ if (Date.parse(health.validUntil) <= Date.parse(health.checkedAt))
54
+ ctx.addIssue({ code: 'custom', message: 'Probe expiry must follow checkedAt' });
55
+ if (health.targetStatus === 'ready' && (health.connectionStatus !== 'reachable' || !health.checkedScope.length))
56
+ ctx.addIssue({ code: 'custom', message: 'ready requires a reachable connection and explicit checked scope' });
57
+ });
58
+ const targetRef = z.object({ targetId: id }).strict();
59
+ const connectionRef = z.object({ connectionId: id }).strict();
60
+ const empty = z.object({}).strict();
61
+ const targetUpdate = z.object({ targetId: id, expectedConfigVersion: version.optional(),
62
+ patch: executionTargetConfigSchema.omit({ targetId: true }).partial().extend({
63
+ enabled: z.boolean().optional(), binding: executionTargetBindingSchema.optional(),
64
+ }).strict() }).strict();
65
+ const connectionUpdate = z.object({ connectionId: id, expectedConnectionVersion: version.optional(),
66
+ patch: executionConnectionConfigSchema.omit({ connectionId: true }).partial().extend({
67
+ provider: z.enum(['a2a', 'activepieces']).optional(), enabled: z.boolean().optional(),
68
+ }).strict() }).strict();
69
+ const targetDelete = targetRef.extend({ expectedConfigVersion: version.optional() });
70
+ const connectionDelete = connectionRef.extend({ expectedConnectionVersion: version.optional() });
71
+ export const TARGET_METHODS = {
72
+ execution_connection_list: { description: '列出人工登记的执行连接及派生端点,不返回凭据。', parameters: z.toJSONSchema(empty) },
73
+ execution_connection_get: { description: '读取执行连接配置与版本。', parameters: z.toJSONSchema(connectionRef) },
74
+ execution_connection_create: { description: '登记连接,仅引用已有 remote 别名,不启动后端。仅可信本机管理入口可调用。', parameters: z.toJSONSchema(executionConnectionConfigSchema) },
75
+ execution_connection_update: { description: '修改或启停连接并递增配置版本。仅可信本机管理入口可调用。', parameters: z.toJSONSchema(connectionUpdate) },
76
+ execution_connection_delete: { description: '删除未被目标引用的连接,编号永久保留。仅可信本机管理入口可调用。', parameters: z.toJSONSchema(connectionDelete) },
77
+ execution_target_list: { description: '列出已登记执行目标及独立健康视图,不创建任务。', parameters: z.toJSONSchema(empty) },
78
+ execution_target_get: { description: '读取执行目标、配置版本及探测范围。', parameters: z.toJSONSchema(targetRef) },
79
+ execution_target_create: { description: '登记通用宿主、固定角色或工作流,不部署或运行能力。仅可信本机管理入口可调用。', parameters: z.toJSONSchema(executionTargetConfigSchema) },
80
+ execution_target_update: { description: '修改或启停执行目标并递增配置版本。仅可信本机管理入口可调用。', parameters: z.toJSONSchema(targetUpdate) },
81
+ execution_target_delete: { description: '删除目标且不取消历史任务,编号永久保留。仅可信本机管理入口可调用。', parameters: z.toJSONSchema(targetDelete) },
82
+ execution_target_probe: { description: '读取只读探测要求和当前健康视图;调用方适配器可执行 agent-card/preflight 检查,目录自身不调用模型。', parameters: z.toJSONSchema(targetRef) },
83
+ };
84
+ const stateSchema = z.object({ version: z.literal(1), connections: z.array(executionConnectionSchema),
85
+ targets: z.array(executionTargetSchema), usedConnectionIds: z.array(id), usedTargetIds: z.array(id) }).strict();
86
+ const clone = (value) => structuredClone(value);
87
+ /** Use inside the gateway's single-owner lease; targets.json is not a transaction with gateway.json. */
88
+ export class TargetDirectory {
89
+ remotes;
90
+ file;
91
+ state;
92
+ health = new Map();
93
+ constructor(stateDirectory, remotes) {
94
+ this.remotes = remotes;
95
+ if (!path.isAbsolute(stateDirectory))
96
+ throw new Error('stateDirectory must be absolute');
97
+ mkdirSync(stateDirectory, { recursive: true, mode: 0o700 });
98
+ this.file = path.join(stateDirectory, 'targets.json');
99
+ try {
100
+ this.state = stateSchema.parse(JSON.parse(readFileSync(this.file, 'utf8')));
101
+ }
102
+ catch (error) {
103
+ if (error.code !== 'ENOENT')
104
+ throw error;
105
+ this.state = { version: 1, connections: [], targets: [], usedConnectionIds: [], usedTargetIds: [] };
106
+ }
107
+ for (const key of ['connections', 'targets']) {
108
+ const values = this.state[key].map(item => key === 'connections' ? item.connectionId : item.targetId);
109
+ if (new Set(values).size !== values.length)
110
+ throw new Error('Duplicate persistent execution directory ID');
111
+ }
112
+ for (const connection of this.state.connections) {
113
+ if (!this.state.usedConnectionIds.includes(connection.connectionId))
114
+ throw new Error('Missing connection ID reservation');
115
+ }
116
+ for (const target of this.state.targets) {
117
+ if (!this.state.usedTargetIds.includes(target.targetId))
118
+ throw new Error('Missing target ID reservation');
119
+ // Offline/removed remotes are diagnostics, not a reason to discard the registered target.
120
+ this.validateTarget(target, this.getConnection(target.connectionId));
121
+ }
122
+ this.reloadRemoteEndpoints();
123
+ }
124
+ commit(next) {
125
+ const temp = `${this.file}.${randomUUID()}.tmp`;
126
+ const fd = openSync(temp, 'wx', 0o600);
127
+ try {
128
+ try {
129
+ writeFileSync(fd, JSON.stringify(next));
130
+ fsyncSync(fd);
131
+ }
132
+ finally {
133
+ closeSync(fd);
134
+ }
135
+ renameSync(temp, this.file);
136
+ const dir = openSync(path.dirname(this.file), 'r');
137
+ try {
138
+ fsyncSync(dir);
139
+ }
140
+ finally {
141
+ closeSync(dir);
142
+ }
143
+ this.state = next;
144
+ }
145
+ catch (error) {
146
+ try {
147
+ unlinkSync(temp);
148
+ }
149
+ catch { }
150
+ throw error;
151
+ }
152
+ }
153
+ getConnection(connectionId) {
154
+ const item = this.state.connections.find(value => value.connectionId === connectionId);
155
+ if (!item)
156
+ throw new Error(`Execution connection not found: ${connectionId}`);
157
+ return clone(item);
158
+ }
159
+ getTarget(targetId) {
160
+ const item = this.state.targets.find(value => value.targetId === targetId);
161
+ if (!item)
162
+ throw new Error(`Execution target not found: ${targetId}`);
163
+ return clone(item);
164
+ }
165
+ listConnections() { return clone(this.state.connections); }
166
+ listTargets() { return clone(this.state.targets); }
167
+ withEndpoint(connection) {
168
+ const { endpoint: _oldEndpoint, endpointFingerprint: _oldFingerprint, ...base } = connection;
169
+ if (connection.provider !== 'a2a' || !Object.hasOwn(this.remotes, connection.remote))
170
+ return base;
171
+ // Deliberately never access remotes[alias].token, including for fingerprinting.
172
+ const value = new URL(endpoint.parse(this.remotes[connection.remote].url)).href;
173
+ return { ...base, endpoint: value, endpointFingerprint: createHash('sha256').update(value).digest('hex') };
174
+ }
175
+ /** Controlled remote-config reload. A URL change creates a new connection version, never a new target. */
176
+ reloadRemoteEndpoints() {
177
+ const next = clone(this.state), changed = [];
178
+ let dirty = false;
179
+ for (let index = 0; index < next.connections.length; index++) {
180
+ const previous = next.connections[index];
181
+ if (previous.provider !== 'a2a' || !Object.hasOwn(this.remotes, previous.remote))
182
+ continue;
183
+ const current = this.withEndpoint(previous);
184
+ if (previous.endpoint === current.endpoint && previous.endpointFingerprint === current.endpointFingerprint)
185
+ continue;
186
+ // Older targets.json has no URL baseline; recording its first fingerprint is not evidence of a URL change.
187
+ if (previous.endpoint !== undefined || previous.endpointFingerprint !== undefined) {
188
+ current.connectionVersion = previous.connectionVersion + 1;
189
+ current.updatedAt = new Date().toISOString();
190
+ changed.push(current.connectionId);
191
+ }
192
+ next.connections[index] = current;
193
+ dirty = true;
194
+ }
195
+ if (dirty)
196
+ this.commit(next);
197
+ return changed;
198
+ }
199
+ /** Explicit compatibility import of configured aliases only; never discovers presets or remote roles. */
200
+ ensureLegacyRemotes() {
201
+ const next = clone(this.state), importedConnections = [], importedTargets = [];
202
+ const now = new Date().toISOString();
203
+ for (const remote of Object.keys(this.remotes)) {
204
+ const connectionId = id.parse(`remote:${remote}`), targetId = id.parse(`legacy:${remote}`);
205
+ const connection = next.connections.find(item => item.connectionId === connectionId);
206
+ if (connection && (connection.provider !== 'a2a' || connection.remote !== remote))
207
+ throw new Error('Legacy connection ID conflicts with configured remote');
208
+ if (!connection && !next.usedConnectionIds.includes(connectionId)) {
209
+ next.connections.push(this.withEndpoint({ connectionId, provider: 'a2a', remote, enabled: true, connectionVersion: 1, createdAt: now, updatedAt: now }));
210
+ next.usedConnectionIds.push(connectionId);
211
+ importedConnections.push(connectionId);
212
+ }
213
+ const target = next.targets.find(item => item.targetId === targetId);
214
+ if (target && (target.kind !== 'agent_host' || target.connectionId !== connectionId))
215
+ throw new Error('Legacy target ID conflicts with configured remote');
216
+ if (!target && !next.usedTargetIds.includes(targetId) && next.connections.some(item => item.connectionId === connectionId)) {
217
+ next.targets.push({ targetId, kind: 'agent_host', name: `Legacy A2A ${remote}`, connectionId, enabled: true,
218
+ binding: {}, configVersion: 1, createdAt: now, updatedAt: now });
219
+ next.usedTargetIds.push(targetId);
220
+ importedTargets.push(targetId);
221
+ }
222
+ }
223
+ if (importedConnections.length || importedTargets.length)
224
+ this.commit(next);
225
+ return { importedConnections, importedTargets };
226
+ }
227
+ validateConnection(connection) {
228
+ if (connection.provider === 'a2a' && !Object.hasOwn(this.remotes, connection.remote))
229
+ throw new Error(`Unknown configured remote: ${connection.remote}`);
230
+ }
231
+ validateTarget(target, connection) {
232
+ const binding = target.binding;
233
+ if (binding.remote && binding.remote !== connection.remote)
234
+ throw new Error('Target remote must match its connection');
235
+ if (target.kind === 'workflow') {
236
+ if (connection.provider !== 'activepieces' || !binding.flowId)
237
+ throw new Error('workflow requires an activepieces connection and flowId');
238
+ if (binding.cwd || binding.agentPreset || binding.roleId || binding.driver || binding.allowedDirectories || binding.allowedPresets)
239
+ throw new Error('workflow cannot bind Agent execution fields');
240
+ }
241
+ else {
242
+ if (connection.provider !== 'a2a')
243
+ throw new Error('Agent targets require an a2a connection');
244
+ if (binding.flowId || binding.flowVersion)
245
+ throw new Error('Agent targets cannot bind a workflow');
246
+ if (target.kind === 'resident_agent' && (!binding.cwd || !binding.agentPreset || !binding.roleId))
247
+ throw new Error('resident_agent requires fixed cwd, agentPreset and roleId');
248
+ if (target.kind === 'agent_host' && (binding.cwd || binding.agentPreset || binding.roleId || binding.driver))
249
+ throw new Error('agent_host takes cwd and preset per task, not a fixed role binding');
250
+ if (binding.cwd && binding.allowedDirectories)
251
+ this.checkDirectory(binding.cwd, binding.allowedDirectories);
252
+ if (binding.agentPreset && binding.allowedPresets && !binding.allowedPresets.includes(binding.agentPreset))
253
+ throw new Error('Fixed preset is outside the allowed preset scope');
254
+ }
255
+ }
256
+ checkDirectory(cwd, allowed) {
257
+ const normalized = path.posix.normalize(cwd);
258
+ if (!allowed.some(root => {
259
+ const relative = path.posix.relative(path.posix.normalize(root), normalized);
260
+ return relative === '' || (!relative.startsWith('../') && relative !== '..' && !path.posix.isAbsolute(relative));
261
+ }))
262
+ throw new Error('cwd is outside allowedDirectories; remote realpath verification is also required');
263
+ }
264
+ /** Resolve configuration only. The actual executor must still validate realpath, permissions and dependencies. */
265
+ resolve(targetId, input) {
266
+ const target = this.getTarget(targetId), connection = this.getConnection(target.connectionId);
267
+ if (!target.enabled || !connection.enabled)
268
+ throw new Error('Execution target or connection is disabled');
269
+ if (target.kind === 'workflow')
270
+ throw new Error('unsupported_provider: workflow execution is not available in P1');
271
+ this.validateConnection(connection);
272
+ const health = this.getHealth(targetId);
273
+ if (health && ['unavailable', 'misconfigured'].includes(health.targetStatus))
274
+ throw new Error(`Execution target unavailable: ${health.reasonCode ?? health.targetStatus}`);
275
+ if (health && ['unreachable', 'auth_required'].includes(health.connectionStatus))
276
+ throw new Error(`Execution connection unavailable: ${health.connectionStatus}`);
277
+ const resolvedInput = jsonObject.parse(input);
278
+ if (resolvedInput.remote !== undefined || resolvedInput.connectionId !== undefined || resolvedInput.targetId !== undefined)
279
+ throw new Error('Input cannot override target or connection binding');
280
+ let cwd, agentPreset;
281
+ if (target.kind === 'resident_agent') {
282
+ // Even an identical value is not an allowed caller override; the binding is authoritative.
283
+ if (resolvedInput.cwd !== undefined || resolvedInput.agentPreset !== undefined || resolvedInput.roleId !== undefined || resolvedInput.driver !== undefined)
284
+ throw new Error('resident_agent input cannot override its fixed cwd, preset, role or driver');
285
+ cwd = target.binding.cwd;
286
+ agentPreset = target.binding.agentPreset;
287
+ }
288
+ else {
289
+ cwd = absolutePath.parse(resolvedInput.cwd);
290
+ agentPreset = resolvedInput.agentPreset === undefined ? undefined : id.parse(resolvedInput.agentPreset);
291
+ }
292
+ if (!text.safeParse(resolvedInput.prompt).success && target.binding.driver !== 'ppt_delivery') {
293
+ // Prompts are intentionally larger than a display/configuration string.
294
+ const prompt = z.string().min(1).max(256 * 1024).refine(value => Boolean(value.trim()));
295
+ prompt.parse(resolvedInput.prompt);
296
+ }
297
+ if (target.binding.allowedDirectories)
298
+ this.checkDirectory(cwd, target.binding.allowedDirectories);
299
+ if (target.binding.allowedPresets && !agentPreset)
300
+ throw new Error('An explicit preset is required for this restricted host');
301
+ if (agentPreset && target.binding.allowedPresets && !target.binding.allowedPresets.includes(agentPreset))
302
+ throw new Error('Requested preset is outside allowedPresets');
303
+ return clone({ target, connection, configVersion: target.configVersion, connectionVersion: connection.connectionVersion,
304
+ remote: connection.remote, endpoint: connection.endpoint, cwd, agentPreset, input: resolvedInput,
305
+ ...(target.binding.allowedDirectories ? { directoryPolicy: { allowedDirectories: target.binding.allowedDirectories, executorVerificationRequired: true } } : {}) });
306
+ }
307
+ getHealth(targetId) {
308
+ const target = this.getTarget(targetId), connection = this.getConnection(target.connectionId);
309
+ const current = this.health.get(targetId);
310
+ if (!current || current.configVersion !== target.configVersion || current.connectionVersion !== connection.connectionVersion ||
311
+ current.connectionId !== connection.connectionId || !target.enabled || !connection.enabled || Date.parse(current.validUntil) <= Date.now())
312
+ return undefined;
313
+ return clone(current);
314
+ }
315
+ /** Only a trusted read-only probe adapter calls this; never exposed as an agent tool. */
316
+ recordProbe(input) {
317
+ const health = targetHealthSchema.parse(input);
318
+ const target = this.state.targets.find(item => item.targetId === health.targetId);
319
+ if (!target || !target.enabled || target.configVersion !== health.configVersion || target.connectionId !== health.connectionId)
320
+ return false;
321
+ const connection = this.getConnection(target.connectionId);
322
+ if (!connection.enabled || connection.connectionVersion !== health.connectionVersion)
323
+ return false;
324
+ const old = this.health.get(target.targetId);
325
+ if (old && Date.parse(old.checkedAt) > Date.parse(health.checkedAt))
326
+ return false;
327
+ if (Date.parse(health.checkedAt) > Date.now() + 5000 || Date.parse(health.validUntil) <= Date.now())
328
+ return false;
329
+ this.health.set(target.targetId, clone(health));
330
+ return true;
331
+ }
332
+ invoke(method, params) {
333
+ if (method === 'execution_connection_list') {
334
+ empty.parse(params);
335
+ return { connections: this.listConnections() };
336
+ }
337
+ if (method === 'execution_connection_get')
338
+ return this.getConnection(connectionRef.parse(params).connectionId);
339
+ if (method === 'execution_target_list') {
340
+ empty.parse(params);
341
+ return { targets: this.listTargets().map(target => this.describe(target.targetId)) };
342
+ }
343
+ if (method === 'execution_target_get')
344
+ return this.describe(targetRef.parse(params).targetId);
345
+ if (method === 'execution_target_probe') {
346
+ const { targetId } = targetRef.parse(params), target = this.getTarget(targetId), connection = this.getConnection(target.connectionId);
347
+ return { ...this.describe(targetId), performed: false, probeRequired: !this.getHealth(targetId),
348
+ checks: target.kind === 'workflow' ? ['provider_unsupported_in_p1'] : ['agent_card', ...(target.binding.cwd ? ['executor_fixed_cwd', 'executor_preset'] : [])],
349
+ connectionVersion: connection.connectionVersion, remote: connection.remote };
350
+ }
351
+ const now = new Date().toISOString(), next = clone(this.state);
352
+ if (method === 'execution_connection_create') {
353
+ const config = executionConnectionConfigSchema.parse(params);
354
+ if (next.usedConnectionIds.includes(config.connectionId))
355
+ throw new Error('Connection ID already used; deleted IDs cannot be reused');
356
+ const connection = this.withEndpoint({ ...config, connectionVersion: 1, createdAt: now, updatedAt: now });
357
+ this.validateConnection(connection);
358
+ next.connections.push(connection);
359
+ next.usedConnectionIds.push(connection.connectionId);
360
+ this.commit(next);
361
+ return clone(connection);
362
+ }
363
+ if (method === 'execution_connection_update') {
364
+ const { connectionId, patch, expectedConnectionVersion } = connectionUpdate.parse(params), previous = this.getConnection(connectionId);
365
+ if (expectedConnectionVersion !== undefined && previous.connectionVersion !== expectedConnectionVersion)
366
+ throw new Error('Connection version conflict');
367
+ const candidate = this.withEndpoint(executionConnectionSchema.parse({ ...previous, ...patch, connectionVersion: previous.connectionVersion + 1, updatedAt: now }));
368
+ this.validateConnection(candidate);
369
+ for (const target of next.targets.filter(item => item.connectionId === connectionId))
370
+ this.validateTarget(target, candidate);
371
+ if (Object.entries(patch).every(([key, value]) => JSON.stringify(previous[key]) === JSON.stringify(value)))
372
+ return previous;
373
+ next.connections[next.connections.findIndex(item => item.connectionId === connectionId)] = candidate;
374
+ this.commit(next);
375
+ return clone(candidate);
376
+ }
377
+ if (method === 'execution_connection_delete') {
378
+ const { connectionId, expectedConnectionVersion } = connectionDelete.parse(params), previous = this.getConnection(connectionId);
379
+ if (expectedConnectionVersion !== undefined && previous.connectionVersion !== expectedConnectionVersion)
380
+ throw new Error('Connection version conflict');
381
+ if (next.targets.some(target => target.connectionId === connectionId))
382
+ throw new Error('Connection is referenced by an execution target');
383
+ next.connections = next.connections.filter(item => item.connectionId !== connectionId);
384
+ this.commit(next);
385
+ return { deleted: true, connectionId };
386
+ }
387
+ if (method === 'execution_target_create') {
388
+ const config = executionTargetConfigSchema.parse(params);
389
+ if (next.usedTargetIds.includes(config.targetId))
390
+ throw new Error('Target ID already used; deleted IDs cannot be reused');
391
+ const target = { ...config, configVersion: 1, createdAt: now, updatedAt: now };
392
+ this.validateTarget(target, this.getConnection(target.connectionId));
393
+ next.targets.push(target);
394
+ next.usedTargetIds.push(target.targetId);
395
+ this.commit(next);
396
+ return clone(target);
397
+ }
398
+ if (method === 'execution_target_update') {
399
+ const { targetId, patch, expectedConfigVersion } = targetUpdate.parse(params), previous = this.getTarget(targetId);
400
+ if (expectedConfigVersion !== undefined && previous.configVersion !== expectedConfigVersion)
401
+ throw new Error('Target version conflict');
402
+ const candidate = executionTargetSchema.parse({ ...previous, ...patch, configVersion: previous.configVersion + 1, updatedAt: now });
403
+ this.validateTarget(candidate, this.getConnection(candidate.connectionId));
404
+ if (Object.entries(patch).every(([key, value]) => JSON.stringify(previous[key]) === JSON.stringify(value)))
405
+ return previous;
406
+ next.targets[next.targets.findIndex(item => item.targetId === targetId)] = candidate;
407
+ this.commit(next);
408
+ return clone(candidate);
409
+ }
410
+ if (method === 'execution_target_delete') {
411
+ const { targetId, expectedConfigVersion } = targetDelete.parse(params), previous = this.getTarget(targetId);
412
+ if (expectedConfigVersion !== undefined && previous.configVersion !== expectedConfigVersion)
413
+ throw new Error('Target version conflict');
414
+ next.targets = next.targets.filter(item => item.targetId !== targetId);
415
+ this.commit(next);
416
+ this.health.delete(targetId);
417
+ return { deleted: true, targetId };
418
+ }
419
+ throw new Error(`Unknown execution target method: ${method}`);
420
+ }
421
+ describe(targetId) {
422
+ const target = this.getTarget(targetId), connection = this.getConnection(target.connectionId), health = this.getHealth(targetId);
423
+ return { ...target, connectionVersion: connection.connectionVersion, providerSupported: target.kind !== 'workflow',
424
+ health: health ?? { targetId, configVersion: target.configVersion, connectionId: target.connectionId,
425
+ connectionVersion: connection.connectionVersion, connectionStatus: 'unknown', targetStatus: 'unknown', checkedScope: [] },
426
+ enabled: target.enabled, connectionEnabled: connection.enabled };
427
+ }
428
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/acp-service",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "ACP runtime, CLI, HTTP/WebSocket service and DeepSeek Harness ACP/A2A plugins in one package.",
5
5
  "keywords": [
6
6
  "dreammate",
@@ -75,14 +75,6 @@
75
75
  "skills",
76
76
  "vendor"
77
77
  ],
78
- "scripts": {
79
- "build": "node ../../scripts/embed-runtime.mjs && tsc -p tsconfig.build.json",
80
- "typecheck": "tsc -p tsconfig.json --noEmit",
81
- "test": "npm run build && npm run test:only",
82
- "prepack": "node ../../scripts/verify-package-build.mjs",
83
- "start": "tsx bin/acp-service.ts",
84
- "test:only": "node --import tsx --test test/*.test.ts"
85
- },
86
78
  "engines": {
87
79
  "node": ">=22.13.0"
88
80
  },
@@ -92,7 +84,7 @@
92
84
  "@1agents/dreammate-node": "^0.15.0",
93
85
  "@a2a-js/sdk": "1.3.0",
94
86
  "@agentclientprotocol/sdk": "1.4.0",
95
- "@openclaw/fs-safe": "^0.20.0",
87
+ "@openclaw/fs-safe": "^0.26.7",
96
88
  "commander": "^15.0.0",
97
89
  "skillflag": "^0.2.1",
98
90
  "tsx": "^4.23.15",
@@ -101,7 +93,7 @@
101
93
  "dsh-zod": "npm:zod@4.4.3"
102
94
  },
103
95
  "devDependencies": {
104
- "@scottzx/1acp": "workspace:*",
96
+ "@scottzx/1acp": "0.16.0",
105
97
  "@types/node": "^22.10.2",
106
98
  "@types/ws": "^8.5.14",
107
99
  "typescript": "^5.7.2"
@@ -121,5 +113,12 @@
121
113
  "@deepseek-ai/dsh-api-remotes"
122
114
  ]
123
115
  }
116
+ },
117
+ "scripts": {
118
+ "build": "node ../../scripts/embed-runtime.mjs && tsc -p tsconfig.build.json",
119
+ "typecheck": "tsc -p tsconfig.json --noEmit",
120
+ "test": "npm run build && npm run test:only",
121
+ "start": "tsx bin/acp-service.ts",
122
+ "test:only": "node --import tsx --test test/*.test.ts"
124
123
  }
125
- }
124
+ }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: acp-service
3
- description: 使用 @1agents/acp-service 的 ACP CLI、HTTP/WebSocket 服务和 DSH 插件,或通过 A2A 向远端 DSH 派发任务、查询进度、继续会话及处理完成收件箱。适用于接入和使用这些能力;不用于一般系统巡检或与该包无关的模型配置。
3
+ description: 使用 @1agents/acp-service 的 ACP CLI、HTTP/WebSocket 服务和 DSH 插件,通过 A2A 向远端 DSH 派发任务、查询状态及处理完成收件箱,或经 gateway 将消息排队投递到已绑定的 Codex/DSH 原会话。适用于接入和使用这些能力;不用于一般系统巡检或与该包无关的模型配置。
4
4
  ---
5
5
 
6
6
  # ACP Service
@@ -15,6 +15,7 @@ description: 使用 @1agents/acp-service 的 ACP CLI、HTTP/WebSocket 服务和
15
15
  | 从客户端连接常驻 Agent 服务,使用标准会话与流式交互 | `acp-service serve`,ACP over WebSocket | [ACP CLI 与服务](references/acp.md) |
16
16
  | 在 DSH 界面使用外部 Agent、原生模型和模式控制 | DSH 中安装同一个包,选择 `ACP · Agent` 预设 | [DSH 插件](references/dsh.md) |
17
17
  | 像远端子任务一样调用 WSL/其他主机上的 DSH,立即取回任务 ID | A2A gateway 的 `remote_agent_*` 工具 | [A2A 调度与收件箱](references/a2a.md) |
18
+ | 把消息或 A2A 完成通知送回已存在的 Codex/DSH 主会话 | 配置 gateway `sessionHosts`,使用 `session_bind`、`session_send` 和投递查询工具 | [原会话排队投递](references/a2a.md#原会话排队投递本次新增) |
18
19
  | 为其他 A2A 客户端开放 DSH 能力 | DSH `a2a` 配置、Agent Card、标准 JSON-RPC/SSE | [A2A 调度与收件箱](references/a2a.md) |
19
20
 
20
21
  先检查现有服务和安装版本;服务已经可用时直接复用。需要哪种入口就读对应引用文件。不要为了派发一次远端任务重新安装或重启正常运行的服务。
@@ -49,6 +50,7 @@ acp-service --skill install acp-service --agent codex --scope repo
49
50
  如果宿主已有 DreamMate 工具,检索服务 `a2a-gateway`,按需查看方法契约,再通过 `dreammate_invoke` 调用。没有 DreamMate 时,使用同名 CLI `a2a invoke`;两者调用同一个 gateway。
50
51
 
51
52
  1. 取得当前主会话的稳定 ID,作为 `originSessionId`;保留真实会话归属,不使用每次随机生成的 ID。
53
+ 如需自动回投,先将该 ID 用 `session_bind` 绑定到已配置宿主和真实原会话 ID;未绑定时保留原收件箱/webhook 路径。
52
54
  2. 明确远端节点名、远端绝对目录、预设和完整任务说明。远端会话不会自动继承主会话上下文。
53
55
  3. 调用 `remote_agent_spawn`,记录返回的 `taskId`、`contextId`、`sessionId` 和实际 `agentPreset`。取到 ID 只表示已受理;仍要检查状态和结果。
54
56
  4. 查询 `remote_agent_get` 或读取 `remote_agent_inbox`。处理报告或所需输入后,按 `noticeId` 调用 `remote_agent_ack`。读取通知本身不会删除或确认它。
@@ -84,7 +86,12 @@ acp-service --skill install acp-service --agent codex --scope repo
84
86
  - gateway 重启可恢复任务记录和未确认通知;DSH 执行主机重启会将被中断的非终态任务标为失败,不能承诺自动续跑。
85
87
  - 网络离线可能返回缓存与 `stale: true`,不等于远端任务失败。SendMessage 响应不明确时先核对,不盲目重发。
86
88
  - DSH 的直接 webhook 为尽力投递;gateway 的持久收件箱和后台查询负责补齐,配置宿主通知接收端后还能重试投递。
87
- - 完成通知到达收件箱不等于主模型被唤醒。接收宿主须实现去重、路由和会话注入;普通 MCP 连接本身不提供自动新一轮执行。此包没有接管 Codex 原生 `spawn_subagent`。
89
+ - 本次源码新增的 `session_*` 工具通过 Codex 原生 `queue` 或 DSH 宿主 `queue` 投递到原会话;需先配置和绑定,不能假设已安装旧版本或现有部署包含它。普通 MCP 连接本身不提供回投,且此包没有接管 Codex 原生 `spawn_subagent`。
90
+ - 投递 `accepted` 只代表宿主接受排队,不代表模型执行、业务处理或 A2A 通知已确认。处理完结果后才调用 `remote_agent_ack`,自动回投不自动业务 ack。
91
+ - `session_delivery_get` 返回 `unknown` 时先核对宿主是否已入队;`rejected` 表示已明确拒绝,需要先排除阻碍。两者均不自动重发,并阻塞同一 origin 后续投递。`session_delivery_resolve` 只处理这两种状态;`accepted: false` 必须表示确认未受理且可重新尝试,不能表示“还没处理”。
92
+ - 同一 `originSessionId/messageId` 只能对应同一正文;重试复用原 ID。公开 `session_send` 禁止使用保留前缀 `a2a-notice:`。DSH 的稳定 requestId 有助于幂等,不能据此承诺 exactly-once 或跨重启无重复。
93
+ - 宿主传输 ID 稳定派生自 `sha256([originSessionId, messageId])`,隔离不同 origin 的同名消息;工具仍使用原 messageId,`hostReceiptId` 由宿主回执决定。
94
+ - 投递记录写盘失败会停止继续投递并使健康检查返回 503。先修复存储再重启 gateway,按已持久化记录恢复;不要依赖失败后的内存状态继续发送或解除阻塞。
88
95
  - 任务权限取决于用户授权、执行主机、DSH/原生 Agent 策略;“只读”任务应在 prompt 中写明动作边界。不要默认启用 `--approve-all` 或将凭据放进 prompt、结果和工具参数。
89
96
 
90
97
  报告时说明受理、执行、完成和通知处理各阶段的实际状态,给出真实任务 ID及关键结果;无法验证的硬件或模型能力应明确标注。
@@ -72,13 +72,14 @@ callback 可选;不配置也会由后台 GetTask 查询补齐状态。需要 p
72
72
 
73
73
  替换可绑定的 IP 与 DSH 可达的 URL,并将 URL 的精确 origin 加入远端 `pushNotificationOrigins`。回调监听器只开放配置的事件路径,不开放工具 `/invoke`;本地工具端口拒绝浏览器 Origin 调用。`originSessionId` 是可信本地调用端使用的通知路由 ID,不是认证凭据。
74
74
 
75
- ## 七个调度工具
75
+ ## 远端任务工具
76
76
 
77
77
  DreamMate 调用参数为 `service_id: "a2a-gateway"`、`method: 方法名`、`params: 参数对象`;先查询服务和方法契约。CLI 则从 stdin 读取同一参数 JSON:
78
78
 
79
79
  | 方法 | 参数与用途 |
80
80
  | --- | --- |
81
- | `remote_agent_spawn` | 必填 `remote, originSessionId, cwd, prompt`;可选 `agentPreset, title, notificationTarget`;新建远端任务/上下文/DSH 会话 |
81
+ | `remote_agent_preflight` | `remote, originSessionId, cwd`;可选任务目录、必需输入和运行时依赖,仅检查、不创建会话 |
82
+ | `remote_agent_spawn` | 必填 `remote, originSessionId, cwd, prompt`;可选 `agentPreset, title, notificationTarget, preflight, resultContract`;新建远端任务/上下文/DSH 会话 |
82
83
  | `remote_agent_get` | `remote, originSessionId, taskId`;当前状态、结果;离线返回缓存与 stale |
83
84
  | `remote_agent_message` | 上述任务定位字段加 `prompt`;复用远端会话,创建新 taskId |
84
85
  | `remote_agent_cancel` | 任务定位字段;取消这项任务自己的执行 |
@@ -114,7 +115,48 @@ acp-service a2a invoke remote_agent_ack <<'JSON'
114
115
  JSON
115
116
  ```
116
117
 
117
- 每次 spawn 都创建新会话,即使 cwd 相同。message 复用原 context/cwd/preset,创建新任务;可排队,但不是对当前轮的原生 interrupt/steer。当前 gateway 没有 `modelId`、`modeId` 或显式恢复任意 DSH session ID 的参数。
118
+ 每次 spawn 都创建新会话,即使 cwd 相同。message 复用原 context/cwd/preset,创建新任务;可排队,但不是对当前轮的原生 interrupt/steer。`remote_agent_*` 没有 `modelId`、`modeId` 或显式恢复任意 DSH session ID 的参数。投递到已存在的主会话使用下面新增的 `session_*` 工具,两类 API 的任务 ID 和会话 ID 不可混用。
119
+
120
+ ## 原会话排队投递(本次新增)
121
+
122
+ 这是本次源码新增的可选 gateway 能力,尚未实际部署,也未用真实会话发送消息。旧部署必须先更新并核对工具契约;没有 `sessionHosts` 和绑定时,既有七个任务工具、webhook 和收件箱行为保持兼容。
123
+
124
+ gateway 配置中的 `sessionHosts` 按名称定义宿主。`kind: "codex"` 使用原生 `codex queue --thread=<UUID> --message=<原文>`,可配置 `executable`、`remote`、`cwd`、`timeoutMs` 和 `remoteAuthTokenEnv`;进程参数不经 shell。`kind: "dsh"` 使用宿主 origin 的 `/api/session/prompt`,按其 Web Remote envelope 发送 `mode: "queue"` 和稳定 requestId,可配置 `url`、`headers`、`timeoutMs`。这条路径直接使用已有宿主队列,无需另设通知 receiver。
125
+
126
+ DSH `headers` 是部署所需的 Cookie/Authorization 等受保护配置,不是工具参数;不要把真实值放入 prompt、receipt、日志或文档。DSH UI/宿主凭据与远端 A2A bearer token 是不同用途,不能混用。Codex 的远端认证同样通过配置的环境变量提供。
127
+
128
+ 宿主传输 ID 使用 `sha256([originSessionId, messageId])` 稳定派生,避免不同 origin 的同名消息在宿主发生冲突。DSH requestId/rpcId 使用该派生 ID;外部工具仍用原 messageId 查询和恢复,`hostReceiptId` 以宿主实际回执为准。
129
+
130
+ | 新增方法 | 参数与用途 |
131
+ | --- | --- |
132
+ | `session_bind` | `originSessionId, host, sessionId`;将 origin 绑定到命名宿主的已有会话。重复同一绑定安全,不能静默换成另一目标 |
133
+ | `session_send` | `originSessionId, messageId, text`;持久化后立即返回投递 receipt。同一 ID 重复正文安全,改正文冲突;禁止保留前缀 `a2a-notice:` |
134
+ | `session_delivery_get` | `originSessionId, messageId`;查询投递状态,不等同于模型执行状态 |
135
+ | `session_delivery_resolve` | `originSessionId, messageId, accepted, note`,可选 `hostReceiptId`;只解决 `unknown/rejected`。确认已受理填 true;有证据确认未入队且已处理阻碍才填 false,使其回到 pending |
136
+
137
+ CLI 复用现有 `a2a invoke`,DreamMate 使用同名 gateway 方法:
138
+
139
+ ```sh
140
+ acp-service a2a invoke session_bind <<'JSON'
141
+ {"originSessionId":"actual-parent-session-id","host":"codex-local","sessionId":"actual-codex-thread-uuid"}
142
+ JSON
143
+ acp-service a2a invoke session_send <<'JSON'
144
+ {"originSessionId":"actual-parent-session-id","messageId":"handoff-result-001","text":"任务结果已就绪,请核对报告后继续原任务。"}
145
+ JSON
146
+ acp-service a2a invoke session_delivery_get <<'JSON'
147
+ {"originSessionId":"actual-parent-session-id","messageId":"handoff-result-001"}
148
+ JSON
149
+ ```
150
+
151
+ 示例需要真实配置和用户授权,文档中的命令未执行。receipt 含 `originSessionId/messageId/host/sessionId/status/attempts/createdAt/updatedAt`,可含 `nextAttemptAt/hostReceiptId/error/processedAt/resolutionNote`。状态为 `pending → dispatching → accepted`,确定未受理的可恢复失败进入 `retrying`;明确拒绝且不可自动恢复进入 `rejected`;超时、断线或崩溃后无法确认受理时进入 `unknown`。DSH 裸 HTTP 429/503 不能证明未受理;仅匹配 rpcId、`result.ok: false` 的明确 RPC 拒绝才可按可恢复错误重试。Codex 与 DSH 均不会盲目重发受理不明的消息。每个 origin 按 FIFO 投递,unknown/rejected 阻塞后续消息。`session_delivery_resolve` 的 note 应记录核对与修复依据。
152
+
153
+ 投递记录写盘失败时停止继续投递,健康检查返回 503。先修复磁盘或目录问题,再重启 gateway,按磁盘中已保存记录恢复;不在不可靠的内存状态上自动续投。重启时,持久化为 dispatching 的消息仍需按 unknown 核对,不能直接重发。
154
+
155
+ `accepted` 只证明宿主接受排队,不证明模型已运行或完成业务。DSH 的稳定 requestId 不构成 exactly-once 保证。A2A notice 在新建时若 origin 已绑定,会冻结 session 投递路由,使用 `messageId: "a2a-notice:<noticeId>"` 自动进入该层,优先于原 notificationTarget;未绑定的 notice 仍走旧 webhook/inbox,后来绑定不会自动迁移旧 notice。
156
+
157
+ 自动消息先展示最终答复正文及其中的 Markdown 产物链接,随后列出 A2A artifact 明确提供的 HTTP(S) URL,末尾附 notice/task 定位 JSON。任务查询返回 `result` 与 `artifactLinks`,主 Agent 仍可使用 `remote_agent_get` 或 `remote_agent_inbox` 核验完整结果。超过 48 KiB 的正文显示有明确标注的节选,独立产物链接列表最多 8 KiB;完整内容通过查询获取。已持久化的旧通知保留原正文,不因格式升级重发。
158
+
159
+ notice 继续保留在 inbox;主 Agent 真正处理结果后才调用 `remote_agent_ack`。ack 会记录对应 delivery 的 `processedAt`,并阻止尚未发出的通知再次触发。手工 `session_send` 没有自动业务 ack。`processedAt` 表示调用者确认已处理,不能当作独立验证的模型运行证据。完整配置、状态和恢复步骤见仓库 `docs/session-delivery.md`。
118
160
 
119
161
  ## 直接使用标准 A2A
120
162
 
@@ -174,10 +216,36 @@ gateway 将状态、任务归属和通知原子落盘;通知有稳定 `noticeI
174
216
 
175
217
  若要通知主 Agent 宿主,在 gateway 配置中增加 `notificationTargets` 名称映射,每项为 `{ "url": "http://host/notice", "token": "protected-token" }`,spawn 时传 `notificationTarget` 名称。这里接收的是 gateway notice(含 originSessionId/taskId/contextId/state/result),不是原始 A2A StreamResponse。
176
218
 
177
- 宿主通知使用 Bearer 与稳定 `Idempotency-Key`;失败或 gateway 重启后重试,直到接收端接受或通知被 ack。宿主须先持久化/去重,再注入对应主会话并触发模型执行。HTTP 成功只代表接收,不证明主模型已运行;当前包没有自动唤醒 Codex 下一轮的宿主适配器。
219
+ 旧宿主通知使用 Bearer 与稳定 `Idempotency-Key`;失败或 gateway 重启后重试,直到接收端接受或通知被 ack。HTTP 2xx 后停止 HTTP 重投,但通知仍留在 inbox;接收宿主须先持久化/去重,再负责注入与恢复。HTTP 成功只代表接收,不证明主模型已运行。上面的新增 session 绑定提供 Codex/DSH 原会话队列适配;未绑定 origin 继续使用此旧路径。
178
220
 
179
221
  执行端和 gateway 状态目录各由单个活跃实例拥有,不应手工删除运行中实例的 lock。gateway 重启不取消远端任务;DSH 重启会将中断任务标为 failed,保留已完成结果和 context 映射,新任务可用 context 恢复 DSH 会话,不自动重放中断工作。
180
222
 
181
223
  ## 共享实现
182
224
 
183
225
  `@1agents/acp-service/a2a` 导出 `createA2AServer`、`FileA2AStore`、`RemoteAgentGateway`、`serveA2AGateway` 及类型。server 接收 `A2ABackend`,核心不依赖 DSH,工厂本身不创建网络 listener;DSH 通过公开 session-controller API 提供 backend 并挂载路由,独立入口可复用这套实现。
226
+
227
+
228
+ ## 派单前预检和系统结果元数据
229
+
230
+ `remote_agent_preflight` 在真实执行宿主完成检查,经 Agent Card 的同源 JSONRPC 地址调用认证的 `/preflight` 扩展。参数除 remote/originSessionId/cwd 外,可含:
231
+
232
+ ```json
233
+ {
234
+ "jobDirectory": "/tmp/actual-job",
235
+ "requiredFiles": ["/absolute/input.md"],
236
+ "python": {"executable": "/absolute/python3", "modules": ["defusedxml"]},
237
+ "node": {"executable": "/absolute/node", "modules": ["@oai/artifact-tool"], "moduleRoot": "/absolute/node_modules"}
238
+ }
239
+ ```
240
+
241
+ 目录须已存在;预检核验真实路径、任务目录属于项目或平台临时目录,并创建随后删除的小文件确认可写。Python/Node 使用指定解释器检查依赖,有超时且不经过 shell。返回 `ok, checkedAt, cwd, jobDirectory, checks`;ok=false 时不得派单。spawn/message 的可选 `preflight` 接收同一检查要求(不带 cwd/remote/originSessionId),gateway 在创建 A2A 任务前检查,DSH backend 在创建原生会话前重检。旧调用保持兼容,DSH 至少检查 cwd。预检是一时刻的检查,无法保证后续磁盘和依赖永不变化。
242
+
243
+ spawn/message 可传 `resultContract: {jobId, parentTaskId?, parentSessionId?, originSessionId?, artifactManifestPath?}`。身份不由模型填入:get/list 的 `resultMetadata` 来自执行宿主,包含真实 task/context/session/request ID、cwd/preset、起止时间、outcome、预检和验证后的产物。lineage 明确标为调用方声明。manifest 路径及所列文件均须在已通过预检的 jobDirectory 内,严格格式:
244
+
245
+ ```json
246
+ {"artifacts":[{"path":"/tmp/actual-job/final.pptx","url":"http://actual-host/artifacts/job/final.pptx","mediaType":"application/vnd.openxmlformats-officedocument.presentationml.presentation"}]}
247
+ ```
248
+
249
+ 宿主计算文件大小和 SHA256,拒绝越界、符号链接和伪造字段;manifest 校验失败会使该轮任务失败,不将模型声称的交付当作成功。公开副本的 URL 由调用方/worker 提供,业务验收仍需下载对比。系统在任务目录写 `result-metadata.<taskId>.json`,已验证 URL 同时进入 A2A artifactLinks。续派返回新 taskId,每轮均有独立系统记录;不改变父任务覆盖范围、通知格式或 ack 机制。
250
+
251
+ 本机完整安装包的来源、校验、离线重装及回滚见工程 `docs/local-reproducible-deployment.md`,不再以单个编译文件的临时替换作为部署来源。