@1agents/acp-service 0.10.5 → 0.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/a2a/gateway.d.ts +75 -0
- package/dist/src/a2a/gateway.js +54 -7
- package/dist/src/a2a/job-directory.d.ts +9 -0
- package/dist/src/a2a/job-directory.js +14 -1
- package/dist/src/a2a/preflight.d.ts +6 -0
- package/dist/src/a2a/preflight.js +46 -0
- package/dist/src/a2a/result-metadata.js +18 -7
- package/dist/src/a2a/types.d.ts +6 -0
- package/dist/src/execution/handoff.d.ts +141 -0
- package/dist/src/execution/handoff.js +193 -0
- package/dist/src/execution/ledger.d.ts +18 -0
- package/dist/src/execution/ledger.js +95 -3
- package/dist/src/execution/spaces.d.ts +13 -0
- package/dist/src/execution/spaces.js +32 -0
- package/dist/src/execution/workbench.d.ts +8 -2
- package/dist/src/execution/workbench.js +24 -3
- package/package.json +13 -12
- package/skills/acp-service/SKILL.md +4 -1
- package/skills/acp-service/references/a2a.md +1 -0
- package/skills/acp-service/references/roles-and-tasks.md +89 -1
- package/vendor/dsh/README.md +1 -1
- package/vendor/dsh/a2a-executor.d.ts +2 -2
- package/vendor/dsh/a2a.d.ts +2 -2
- package/vendor/dsh/a2a.js +4 -1
- package/vendor/dsh/adapter.d.ts +2 -2
- package/vendor/dsh/client.js +9 -33
- package/vendor/dsh/cordis.patch.yml +4 -2
- package/vendor/dsh/diagnostics.d.ts +14 -2
- package/vendor/dsh/diagnostics.js +79 -4
- package/vendor/dsh/index.js +3 -4
- package/vendor/dsh/service-process.js +3 -1
- package/vendor/runtime/dist/cli.js +0 -0
- package/vendor/dsh/workbench.d.ts +0 -18
- package/vendor/dsh/workbench.js +0 -91
|
@@ -119,6 +119,8 @@ export declare const REMOTE_AGENT_METHODS: {
|
|
|
119
119
|
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
120
120
|
allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
121
121
|
jobDirectory: z.ZodOptional<z.ZodString>;
|
|
122
|
+
artifactSpace: z.ZodOptional<z.ZodString>;
|
|
123
|
+
rolePublication: z.ZodOptional<z.ZodString>;
|
|
122
124
|
requiredFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
123
125
|
python: z.ZodOptional<z.ZodObject<{
|
|
124
126
|
executable: z.ZodString;
|
|
@@ -147,6 +149,8 @@ export declare const REMOTE_AGENT_METHODS: {
|
|
|
147
149
|
preflight: z.ZodOptional<z.ZodObject<{
|
|
148
150
|
allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
149
151
|
jobDirectory: z.ZodOptional<z.ZodString>;
|
|
152
|
+
artifactSpace: z.ZodOptional<z.ZodString>;
|
|
153
|
+
rolePublication: z.ZodOptional<z.ZodString>;
|
|
150
154
|
requiredFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
151
155
|
python: z.ZodOptional<z.ZodObject<{
|
|
152
156
|
executable: z.ZodString;
|
|
@@ -223,6 +227,8 @@ export declare const REMOTE_AGENT_METHODS: {
|
|
|
223
227
|
preflight: z.ZodOptional<z.ZodObject<{
|
|
224
228
|
allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
225
229
|
jobDirectory: z.ZodOptional<z.ZodString>;
|
|
230
|
+
artifactSpace: z.ZodOptional<z.ZodString>;
|
|
231
|
+
rolePublication: z.ZodOptional<z.ZodString>;
|
|
226
232
|
requiredFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
227
233
|
python: z.ZodOptional<z.ZodObject<{
|
|
228
234
|
executable: z.ZodString;
|
|
@@ -332,6 +338,73 @@ export declare const REMOTE_AGENT_METHODS: {
|
|
|
332
338
|
hostReceiptId: z.ZodOptional<z.ZodString>;
|
|
333
339
|
}, z.core.$strict>>;
|
|
334
340
|
};
|
|
341
|
+
handoff_propose: {
|
|
342
|
+
description: string;
|
|
343
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
344
|
+
caseId: z.ZodString;
|
|
345
|
+
toTargetId: z.ZodString;
|
|
346
|
+
purpose: z.ZodString;
|
|
347
|
+
artifactRevision: z.ZodString;
|
|
348
|
+
artifactDigest: z.ZodString;
|
|
349
|
+
reason: z.ZodString;
|
|
350
|
+
clientRequestId: z.ZodOptional<z.ZodString>;
|
|
351
|
+
originSessionId: z.ZodString;
|
|
352
|
+
jobId: z.ZodString;
|
|
353
|
+
attemptId: z.ZodString;
|
|
354
|
+
}, z.core.$strict>>;
|
|
355
|
+
};
|
|
356
|
+
handoff_decide: {
|
|
357
|
+
description: string;
|
|
358
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
359
|
+
originSessionId: z.ZodString;
|
|
360
|
+
handoffId: z.ZodString;
|
|
361
|
+
decision: z.ZodEnum<{
|
|
362
|
+
accept: "accept";
|
|
363
|
+
reject: "reject";
|
|
364
|
+
}>;
|
|
365
|
+
note: z.ZodOptional<z.ZodString>;
|
|
366
|
+
decidedBy: z.ZodObject<{
|
|
367
|
+
kind: z.ZodEnum<{
|
|
368
|
+
person: "person";
|
|
369
|
+
coach: "coach";
|
|
370
|
+
}>;
|
|
371
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
372
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
373
|
+
}, z.core.$strict>;
|
|
374
|
+
}, z.core.$strict>>;
|
|
375
|
+
};
|
|
376
|
+
handoff_offer: {
|
|
377
|
+
description: string;
|
|
378
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
379
|
+
originSessionId: z.ZodString;
|
|
380
|
+
caseId: z.ZodString;
|
|
381
|
+
fromPurpose: z.ZodOptional<z.ZodString>;
|
|
382
|
+
fromTargetId: z.ZodOptional<z.ZodString>;
|
|
383
|
+
toTargetId: z.ZodString;
|
|
384
|
+
toPurpose: z.ZodString;
|
|
385
|
+
when: z.ZodEnum<{
|
|
386
|
+
acceptance_accepted: "acceptance_accepted";
|
|
387
|
+
ticket_closed: "ticket_closed";
|
|
388
|
+
}>;
|
|
389
|
+
requireHuman: z.ZodOptional<z.ZodBoolean>;
|
|
390
|
+
clientRequestId: z.ZodOptional<z.ZodString>;
|
|
391
|
+
}, z.core.$strict>>;
|
|
392
|
+
};
|
|
393
|
+
handoff_space: {
|
|
394
|
+
description: string;
|
|
395
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
396
|
+
originSessionId: z.ZodString;
|
|
397
|
+
caseId: z.ZodString;
|
|
398
|
+
root: z.ZodString;
|
|
399
|
+
}, z.core.$strict>>;
|
|
400
|
+
};
|
|
401
|
+
handoff_get: {
|
|
402
|
+
description: string;
|
|
403
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
404
|
+
originSessionId: z.ZodString;
|
|
405
|
+
jobId: z.ZodString;
|
|
406
|
+
}, z.core.$strict>>;
|
|
407
|
+
};
|
|
335
408
|
ticket_get: {
|
|
336
409
|
description: string;
|
|
337
410
|
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
@@ -514,6 +587,8 @@ export declare const REMOTE_AGENT_METHODS: {
|
|
|
514
587
|
parentAttemptId: z.ZodOptional<z.ZodString>;
|
|
515
588
|
purpose: z.ZodOptional<z.ZodString>;
|
|
516
589
|
resultRevision: z.ZodOptional<z.ZodString>;
|
|
590
|
+
caseId: z.ZodOptional<z.ZodString>;
|
|
591
|
+
handoffId: z.ZodOptional<z.ZodString>;
|
|
517
592
|
replacesJobRef: z.ZodOptional<z.ZodObject<{
|
|
518
593
|
sourceId: z.ZodString;
|
|
519
594
|
jobId: z.ZodString;
|
package/dist/src/a2a/gateway.js
CHANGED
|
@@ -16,7 +16,7 @@ import { artifactLinks, formatNotice } from './notices.js';
|
|
|
16
16
|
import { a2aPreflightInputSchema, a2aPreflightRequirementsSchema, a2aPreflightReportSchema } from './preflight.js';
|
|
17
17
|
import { a2aResultContractSchema } from './result-metadata.js';
|
|
18
18
|
import { ARTIFACT_CONTENT_LIMIT } from './artifact-content.js';
|
|
19
|
-
import { artifactInstructions, defaultJobDirectory, defaultManifestPath } from './job-directory.js';
|
|
19
|
+
import { artifactInstructions, defaultJobDirectory, defaultManifestPath, spaceInstructions } from './job-directory.js';
|
|
20
20
|
import { WORKBENCH_UI_PATH, WorkbenchUi } from './workbench-ui.js';
|
|
21
21
|
import { notifyDesktop } from './desktop-notify.js';
|
|
22
22
|
import { isAcpAgentPreset, legacyLifecycle, normalizeLifecycle, oneShotShouldClose, sessionLifecycleSchema } from './session-lifecycle.js';
|
|
@@ -27,6 +27,8 @@ import { ProjectRoleDiscovery, DISCOVERY_METHODS, projectDiscoveryConfigSchema }
|
|
|
27
27
|
import { deliveryProgress, deliveryException } from '../execution/delivery-progress.js';
|
|
28
28
|
import { JobLedger } from '../execution/ledger.js';
|
|
29
29
|
import { invokeTicket, reopenForContinue, TICKET_METHODS } from '../execution/ticket.js';
|
|
30
|
+
import { continueByConvention, HANDOFF_METHODS, invokeHandoff } from '../execution/handoff.js';
|
|
31
|
+
import { rolePublicationDirectory } from '../execution/spaces.js';
|
|
30
32
|
import { decideHumanReview, HumanReviewError, humanReviewDecisionSchema } from '../execution/human-review.js';
|
|
31
33
|
import { answerProcessRequest, createProcessRequest, expireProcessRequest, processRequestAnswerSchema, processRequestCreateSchema, processRequestSchema, ProcessRequestError, projectProcessRequest, sameProcessRequest } from '../execution/process-request.js';
|
|
32
34
|
import { chatItems, pageChat } from '../execution/workbench-chat.js';
|
|
@@ -105,7 +107,8 @@ const inboxSchema = z.object(originFields).strict();
|
|
|
105
107
|
const ackSchema = z.object({ ...originFields, noticeId: string }).strict();
|
|
106
108
|
const executionSubmitSchema = z.object({ ...originFields, targetId: string, input: z.record(z.string(), z.unknown()),
|
|
107
109
|
clientRequestId: string.optional(), title: string.optional(), parentJobRef: z.object({ sourceId: string, jobId: string }).strict().optional(),
|
|
108
|
-
parentAttemptId: string.optional(), purpose: string.optional(), resultRevision: string.optional(),
|
|
110
|
+
parentAttemptId: string.optional(), purpose: string.optional(), resultRevision: string.optional(), caseId: string.optional(),
|
|
111
|
+
handoffId: string.optional(),
|
|
109
112
|
replacesJobRef: z.object({ sourceId: string, jobId: string }).strict().optional(), initiatedBy: actorSchema.optional() }).strict();
|
|
110
113
|
const executionJobSchema = z.object({ ...originFields, jobId: string }).strict();
|
|
111
114
|
const executionCancelSchema = executionJobSchema.extend({ cascade: z.boolean().optional() }).strict();
|
|
@@ -140,6 +143,7 @@ const EXECUTION_METHODS = {
|
|
|
140
143
|
execution_inbox: { description: '读取领域交付任务的完成/需决策通知;旧A2A收件箱保持原合同。', parameters: z.toJSONSchema(inboxSchema) },
|
|
141
144
|
execution_ack: { description: '确认已处理领域交付通知,不修改业务验收或执行状态。', parameters: z.toJSONSchema(ackSchema) },
|
|
142
145
|
...TICKET_METHODS,
|
|
146
|
+
...HANDOFF_METHODS,
|
|
143
147
|
};
|
|
144
148
|
export const REMOTE_AGENT_METHODS = {
|
|
145
149
|
...EXECUTION_METHODS,
|
|
@@ -371,6 +375,21 @@ export class RemoteAgentGateway {
|
|
|
371
375
|
resultMetadata: Task.fromJSON(raw.task).metadata?.['1agents']?.result } : {}) };
|
|
372
376
|
}
|
|
373
377
|
async submitExecution(input, options = {}) {
|
|
378
|
+
if (input.handoffId) {
|
|
379
|
+
const handoff = this.ledger.findHandoff(input.originSessionId, input.handoffId);
|
|
380
|
+
if (!handoff || handoff.status === 'rejected' || handoff.status === 'proposed')
|
|
381
|
+
throw new Error('Handoff must be accepted before it opens a job');
|
|
382
|
+
if (input.targetId !== handoff.toTargetId)
|
|
383
|
+
throw new Error('Handoff target does not match');
|
|
384
|
+
if (input.purpose && input.purpose !== handoff.purpose)
|
|
385
|
+
throw new Error('Handoff purpose does not match');
|
|
386
|
+
if (input.caseId && input.caseId !== handoff.caseId)
|
|
387
|
+
throw new Error('Handoff case does not match');
|
|
388
|
+
if (handoff.status === 'taken' && handoff.childJobId)
|
|
389
|
+
return this.ledgerView(input.originSessionId, handoff.childJobId);
|
|
390
|
+
input = { ...input, purpose: handoff.purpose, caseId: handoff.caseId, resultRevision: input.resultRevision ?? handoff.artifactRevision,
|
|
391
|
+
parentJobRef: { sourceId: this.ledger.sourceId, jobId: handoff.fromJobId }, parentAttemptId: handoff.fromAttemptId };
|
|
392
|
+
}
|
|
374
393
|
const replay = this.ledger.replay({ ...input, requestDigestInput: options.requestDigestInput, jobId: options.jobId, operation: options.jobId ? 'continue' : 'submit', targetSnapshot: { targetId: input.targetId } });
|
|
375
394
|
if (replay)
|
|
376
395
|
return { ...this.ledgerView(input.originSessionId, replay.job.jobId), attemptId: replay.attempt.attemptId, requestedAttempt: replay.attempt };
|
|
@@ -387,9 +406,14 @@ export class RemoteAgentGateway {
|
|
|
387
406
|
const development = this.developmentFor(resolved.target, options.jobId);
|
|
388
407
|
const prepared = this.ledger.prepare({ ...input, requestDigestInput: options.requestDigestInput, jobId: options.jobId, targetSnapshot: { ...this.targetSnapshot(resolved), ...(development ? { development } : {}), ...(reportRequest !== undefined ? { provider: 'report_review', targetKind: 'workflow', driver: 'report_review' } : {}) },
|
|
389
408
|
operation: options.jobId ? 'continue' : 'submit' });
|
|
390
|
-
if (prepared.idempotent)
|
|
409
|
+
if (prepared.idempotent) {
|
|
410
|
+
if (input.handoffId)
|
|
411
|
+
this.ledger.markHandoffTaken(input.originSessionId, input.handoffId, prepared.job.jobId);
|
|
391
412
|
return this.ledgerView(input.originSessionId, prepared.job.jobId);
|
|
413
|
+
}
|
|
392
414
|
const { job, attempt } = prepared;
|
|
415
|
+
if (input.handoffId)
|
|
416
|
+
this.ledger.markHandoffTaken(input.originSessionId, input.handoffId, job.jobId);
|
|
393
417
|
let sent = false;
|
|
394
418
|
try {
|
|
395
419
|
if (reportRequest !== undefined) {
|
|
@@ -451,6 +475,17 @@ export class RemoteAgentGateway {
|
|
|
451
475
|
resultContract = declaredResult;
|
|
452
476
|
await this.checkDispatch(resolved.remote, resolved.cwd, requirements, resolved.endpoint);
|
|
453
477
|
}
|
|
478
|
+
const publicationRole = boundRole ?? explicitRole ?? job.roleId;
|
|
479
|
+
const publication = publicationRole && resolved.cwd ? rolePublicationDirectory(resolved.cwd, publicationRole) : undefined;
|
|
480
|
+
const caseSpace = job.caseId && resolved.cwd ? this.ledger.artifactSpace(input.originSessionId, job.caseId) : undefined;
|
|
481
|
+
const optional = { ...(caseSpace ? { artifactSpace: caseSpace.root } : {}), ...(publication ? { rolePublication: publication } : {}) };
|
|
482
|
+
if (Object.keys(optional).length && resolved.cwd) {
|
|
483
|
+
try {
|
|
484
|
+
await this.checkDispatch(resolved.remote, resolved.cwd, { ...requirements, ...optional }, resolved.endpoint);
|
|
485
|
+
requirements = { ...requirements, ...optional };
|
|
486
|
+
}
|
|
487
|
+
catch { /* A refused shared space or role directory does not block the task's own job directory. */ }
|
|
488
|
+
}
|
|
454
489
|
const client = await this.client(resolved.remote, resolved.endpoint);
|
|
455
490
|
// Target changes/disable during asynchronous preflight must win before sending.
|
|
456
491
|
const fresh = this.targets.resolve(input.targetId, input.input);
|
|
@@ -461,7 +496,9 @@ export class RemoteAgentGateway {
|
|
|
461
496
|
sent = true;
|
|
462
497
|
const lifecycle = this.jobLifecycle(fields.lifecycle, options.previous?.lifecycle);
|
|
463
498
|
const task = await client.sendMessage(SendMessageRequest.fromJSON({ message: { messageId: attempt.attemptId, role: 'ROLE_USER',
|
|
464
|
-
...(options.previous ? { contextId: options.previous.contextId } : {}), parts: [{ text: prompt.parse(fields.prompt) + (artifacts ? artifactInstructions(artifacts.directory, artifacts.manifest) : '')
|
|
499
|
+
...(options.previous ? { contextId: options.previous.contextId } : {}), parts: [{ text: prompt.parse(fields.prompt) + (artifacts ? artifactInstructions(artifacts.directory, artifacts.manifest) : '')
|
|
500
|
+
+ spaceInstructions({ originSessionId: input.originSessionId, jobId: job.jobId, attemptId: attempt.attemptId, caseId: job.caseId,
|
|
501
|
+
artifactSpace: requirements?.artifactSpace, rolePublication: requirements?.rolePublication }) }] },
|
|
465
502
|
metadata: { '1agents': { ...(!options.previous ? { cwd: resolved.cwd, ...(resolved.agentPreset ? { agentPreset: resolved.agentPreset } : {}),
|
|
466
503
|
...(resolved.target.binding.agentFile ? { agentFile: resolved.target.binding.agentFile } : {}) } : {}),
|
|
467
504
|
...(explicitRole ? { roleId: explicitRole } : !options.previous && boundRole ? { roleId: boundRole } : {}),
|
|
@@ -1331,10 +1368,20 @@ export class RemoteAgentGateway {
|
|
|
1331
1368
|
}
|
|
1332
1369
|
if (method === 'execution_review') {
|
|
1333
1370
|
const { originSessionId, jobId, ...review } = executionReviewSchema.parse(params);
|
|
1334
|
-
|
|
1371
|
+
const recorded = this.ledger.acceptance(originSessionId, jobId, review);
|
|
1372
|
+
if (review.reviewStatus === 'accepted')
|
|
1373
|
+
continueByConvention(this.ledger, originSessionId, jobId);
|
|
1374
|
+
return recorded;
|
|
1375
|
+
}
|
|
1376
|
+
if (Object.hasOwn(HANDOFF_METHODS, method))
|
|
1377
|
+
return invokeHandoff(this.ledger, method, params);
|
|
1378
|
+
if (Object.hasOwn(TICKET_METHODS, method)) {
|
|
1379
|
+
const ticket = invokeTicket(this.ledger, method, params);
|
|
1380
|
+
const body = params && typeof params === 'object' ? params : {};
|
|
1381
|
+
if (method === 'ticket_close' && body.status === 'closed' && body.originSessionId && body.jobId)
|
|
1382
|
+
continueByConvention(this.ledger, body.originSessionId, body.jobId);
|
|
1383
|
+
return ticket;
|
|
1335
1384
|
}
|
|
1336
|
-
if (Object.hasOwn(TICKET_METHODS, method))
|
|
1337
|
-
return invokeTicket(this.ledger, method, params);
|
|
1338
1385
|
if (method === 'execution_unwatch') {
|
|
1339
1386
|
const input = executionUnwatchSchema.parse(params);
|
|
1340
1387
|
this.ledger.unwatch(input.originSessionId, input.jobId, input.reason);
|
|
@@ -4,3 +4,12 @@ export declare const defaultManifestPath: (cwd: string, jobId: string, attemptId
|
|
|
4
4
|
export declare function isDefaultJobDirectory(cwd: string, directory: string): boolean;
|
|
5
5
|
/** The agent-facing contract, appended to the task prompt. */
|
|
6
6
|
export declare function artifactInstructions(directory: string, manifest: string): string;
|
|
7
|
+
/** Names the three directories when a case has them. Does not authorize a path the host refused. */
|
|
8
|
+
export declare function spaceInstructions(input: {
|
|
9
|
+
originSessionId: string;
|
|
10
|
+
jobId: string;
|
|
11
|
+
attemptId: string;
|
|
12
|
+
caseId?: string;
|
|
13
|
+
artifactSpace?: string;
|
|
14
|
+
rolePublication?: string;
|
|
15
|
+
}): string;
|
|
@@ -15,5 +15,18 @@ export function isDefaultJobDirectory(cwd, directory) {
|
|
|
15
15
|
export function artifactInstructions(directory, manifest) {
|
|
16
16
|
return `\n\n---\n[产物约定] 如果本任务产生了需要交付或审核的文件,请把它们写到目录 ${directory}/ 下(目录已创建),\n`
|
|
17
17
|
+ `并在结束前写入清单 ${manifest},格式:{"artifacts":[{"path":"<文件绝对路径>","mediaType":"<可选>"}]}。\n`
|
|
18
|
-
+ '
|
|
18
|
+
+ '清单里的文件必须在该任务目录或已告知的共享产物空间内;只有登记在清单里、并通过校验的文件才会作为产物展示。没有交付文件时不要创建清单。';
|
|
19
|
+
}
|
|
20
|
+
/** Names the three directories when a case has them. Does not authorize a path the host refused. */
|
|
21
|
+
export function spaceInstructions(input) {
|
|
22
|
+
if (!input.caseId && !input.artifactSpace && !input.rolePublication)
|
|
23
|
+
return '';
|
|
24
|
+
const lines = [`任务目录只属于这一轮。`];
|
|
25
|
+
if (input.artifactSpace)
|
|
26
|
+
lines.push(`共享产物空间 ${input.artifactSpace}/:同一件事的其他任务可以读写。要交接的文件写在这里,并登记进任务清单。`);
|
|
27
|
+
if (input.rolePublication)
|
|
28
|
+
lines.push(`角色公开目录 ${input.rolePublication}/:给其他角色看的成品。它不是任务目录,也不是共享产物空间。`);
|
|
29
|
+
if (input.caseId)
|
|
30
|
+
lines.push(`这件事的 caseId 是 ${input.caseId}。交给另一个角色时调用 handoff_propose(originSessionId=${input.originSessionId},jobId=${input.jobId},attemptId=${input.attemptId}),只提议,不派下一单。`);
|
|
31
|
+
return `\n\n---\n[空间]\n${lines.join('\n')}`;
|
|
19
32
|
}
|
|
@@ -3,6 +3,8 @@ import type { A2APreflightInput, A2APreflightReport } from './types.js';
|
|
|
3
3
|
export declare const a2aPreflightRequirementsSchema: z.ZodObject<{
|
|
4
4
|
allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
5
5
|
jobDirectory: z.ZodOptional<z.ZodString>;
|
|
6
|
+
artifactSpace: z.ZodOptional<z.ZodString>;
|
|
7
|
+
rolePublication: z.ZodOptional<z.ZodString>;
|
|
6
8
|
requiredFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
7
9
|
python: z.ZodOptional<z.ZodObject<{
|
|
8
10
|
executable: z.ZodString;
|
|
@@ -17,6 +19,8 @@ export declare const a2aPreflightRequirementsSchema: z.ZodObject<{
|
|
|
17
19
|
export declare const a2aPreflightInputSchema: z.ZodObject<{
|
|
18
20
|
allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
19
21
|
jobDirectory: z.ZodOptional<z.ZodString>;
|
|
22
|
+
artifactSpace: z.ZodOptional<z.ZodString>;
|
|
23
|
+
rolePublication: z.ZodOptional<z.ZodString>;
|
|
20
24
|
requiredFiles: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
25
|
python: z.ZodOptional<z.ZodObject<{
|
|
22
26
|
executable: z.ZodString;
|
|
@@ -34,6 +38,8 @@ export declare const a2aPreflightReportSchema: z.ZodObject<{
|
|
|
34
38
|
checkedAt: z.ZodString;
|
|
35
39
|
cwd: z.ZodString;
|
|
36
40
|
jobDirectory: z.ZodOptional<z.ZodString>;
|
|
41
|
+
artifactSpace: z.ZodOptional<z.ZodString>;
|
|
42
|
+
rolePublication: z.ZodOptional<z.ZodString>;
|
|
37
43
|
checks: z.ZodArray<z.ZodObject<{
|
|
38
44
|
id: z.ZodString;
|
|
39
45
|
ok: z.ZodBoolean;
|
|
@@ -8,12 +8,15 @@ import { isAbsolute, join, relative, sep } from 'node:path';
|
|
|
8
8
|
import { promisify } from 'node:util';
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
import { isDefaultJobDirectory } from './job-directory.js';
|
|
11
|
+
import { roleIdFromPublication } from '../execution/spaces.js';
|
|
11
12
|
const absolutePath = z.string().min(1).max(4096).refine(value => isAbsolute(value) && !value.includes('\0'), 'Expected an absolute host path');
|
|
12
13
|
const pythonModule = z.string().regex(/^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*$/).max(200);
|
|
13
14
|
const nodeModule = z.string().regex(/^(?:@[A-Za-z0-9_.-]+\/)?[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/).max(200);
|
|
14
15
|
export const a2aPreflightRequirementsSchema = z.object({
|
|
15
16
|
allowedDirectories: z.array(absolutePath).min(1).max(100).optional(),
|
|
16
17
|
jobDirectory: absolutePath.optional(),
|
|
18
|
+
artifactSpace: absolutePath.optional(),
|
|
19
|
+
rolePublication: absolutePath.optional(),
|
|
17
20
|
requiredFiles: z.array(absolutePath).max(64).optional(),
|
|
18
21
|
python: z.object({ executable: absolutePath, modules: z.array(pythonModule).max(32) }).strict().optional(),
|
|
19
22
|
node: z.object({ executable: absolutePath, modules: z.array(nodeModule).max(32).optional(), moduleRoot: absolutePath.optional() }).strict().optional(),
|
|
@@ -21,6 +24,7 @@ export const a2aPreflightRequirementsSchema = z.object({
|
|
|
21
24
|
export const a2aPreflightInputSchema = a2aPreflightRequirementsSchema.extend({ cwd: absolutePath }).strict();
|
|
22
25
|
export const a2aPreflightReportSchema = z.object({
|
|
23
26
|
ok: z.boolean(), checkedAt: z.string(), cwd: absolutePath, jobDirectory: absolutePath.optional(),
|
|
27
|
+
artifactSpace: absolutePath.optional(), rolePublication: absolutePath.optional(),
|
|
24
28
|
checks: z.array(z.object({ id: z.string(), ok: z.boolean(), detail: z.string().optional() }).strict()),
|
|
25
29
|
}).strict();
|
|
26
30
|
export class A2APreflightError extends Error {
|
|
@@ -130,6 +134,48 @@ export async function runA2APreflight(raw) {
|
|
|
130
134
|
report.jobDirectory = directory;
|
|
131
135
|
return directory;
|
|
132
136
|
});
|
|
137
|
+
if (input.rolePublication)
|
|
138
|
+
await check('rolePublication', async () => {
|
|
139
|
+
if (!cwdOk)
|
|
140
|
+
throw new Error('Cannot create a role publication directory without a cwd');
|
|
141
|
+
const roleId = roleIdFromPublication(input.cwd, input.rolePublication) ?? roleIdFromPublication(report.cwd, input.rolePublication);
|
|
142
|
+
if (!roleId)
|
|
143
|
+
throw new Error('rolePublication must be <cwd>/.1agents/roles/<roleId>/published');
|
|
144
|
+
const expected = join(report.cwd, '.1agents', 'roles', roleId, 'published');
|
|
145
|
+
await ensureDefaultJobDirectory(report.cwd, expected);
|
|
146
|
+
report.rolePublication = await realpath(expected);
|
|
147
|
+
return report.rolePublication;
|
|
148
|
+
});
|
|
149
|
+
if (input.artifactSpace)
|
|
150
|
+
await check('artifactSpace', async () => {
|
|
151
|
+
if (!cwdOk)
|
|
152
|
+
throw new Error('Cannot admit an artifact space without a cwd');
|
|
153
|
+
const directory = await realpath(input.artifactSpace);
|
|
154
|
+
if (!(await stat(directory)).isDirectory())
|
|
155
|
+
throw new Error('artifact space must already exist and be a directory');
|
|
156
|
+
if (report.jobDirectory && directory === report.jobDirectory)
|
|
157
|
+
throw new Error('artifact space must not be the job directory');
|
|
158
|
+
const roleMarker = `${sep}.1agents${sep}roles${sep}`;
|
|
159
|
+
if (directory.includes(roleMarker) || directory.endsWith(`${sep}.1agents${sep}roles`))
|
|
160
|
+
throw new Error('artifact space must not be a role directory');
|
|
161
|
+
const temporaryRoots = await Promise.all(['/tmp', tmpdir()].map(path => realpath(path).catch(() => undefined)));
|
|
162
|
+
const allowed = input.allowedDirectories ? await Promise.all(input.allowedDirectories.map(root => realpath(root).catch(() => undefined))) : [];
|
|
163
|
+
if (![report.cwd, ...temporaryRoots, ...allowed].filter((path) => path !== undefined).some(root => within(root, directory))) {
|
|
164
|
+
throw new Error('artifact space is outside the admitted roots');
|
|
165
|
+
}
|
|
166
|
+
const probe = join(directory, `.a2a-preflight-${randomUUID()}`);
|
|
167
|
+
const handle = await open(probe, 'wx', 0o600);
|
|
168
|
+
try {
|
|
169
|
+
await handle.writeFile('a2a preflight\n');
|
|
170
|
+
await handle.sync();
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await handle.close();
|
|
174
|
+
await unlink(probe);
|
|
175
|
+
}
|
|
176
|
+
report.artifactSpace = directory;
|
|
177
|
+
return directory;
|
|
178
|
+
});
|
|
133
179
|
for (const [index, file] of (input.requiredFiles ?? []).entries())
|
|
134
180
|
await check(`requiredFile.${index}`, async () => {
|
|
135
181
|
const actual = await realpath(file);
|
|
@@ -34,10 +34,11 @@ function within(root, path) {
|
|
|
34
34
|
const rel = relative(root, path);
|
|
35
35
|
return rel !== '' && !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`);
|
|
36
36
|
}
|
|
37
|
-
/** Resolve aliases such as /tmp once, then reject symlinks below
|
|
38
|
-
async function scopedFile(
|
|
37
|
+
/** Resolve aliases such as /tmp once, then reject symlinks below an admitted root. The manifest itself stays in the job root. */
|
|
38
|
+
async function scopedFile(roots, path) {
|
|
39
39
|
const canonical = await realpath(path);
|
|
40
|
-
|
|
40
|
+
const root = roots.find(item => within(item, canonical));
|
|
41
|
+
if (!root)
|
|
41
42
|
throw new A2AResultValidationError('artifact-outside-job-directory');
|
|
42
43
|
// A symlink pointing back into the scope is rejected too: the receipt describes a real file.
|
|
43
44
|
let current = path;
|
|
@@ -53,8 +54,8 @@ async function scopedFile(root, path) {
|
|
|
53
54
|
}
|
|
54
55
|
return canonical;
|
|
55
56
|
}
|
|
56
|
-
async function verifiedArtifacts(root, manifestPath) {
|
|
57
|
-
const manifestFile = await scopedFile(root, manifestPath);
|
|
57
|
+
async function verifiedArtifacts(root, extraRoots, manifestPath) {
|
|
58
|
+
const manifestFile = await scopedFile([root], manifestPath);
|
|
58
59
|
const manifest = await open(manifestFile, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
59
60
|
let source;
|
|
60
61
|
try {
|
|
@@ -72,7 +73,7 @@ async function verifiedArtifacts(root, manifestPath) {
|
|
|
72
73
|
const output = [];
|
|
73
74
|
const seen = new Set();
|
|
74
75
|
for (const item of parsed.data.artifacts) {
|
|
75
|
-
const path = await scopedFile(root, item.path);
|
|
76
|
+
const path = await scopedFile([root, ...extraRoots], item.path);
|
|
76
77
|
if (seen.has(path))
|
|
77
78
|
throw new A2AResultValidationError('duplicate-artifact');
|
|
78
79
|
seen.add(path);
|
|
@@ -134,8 +135,18 @@ export async function createA2AResultMetadata(input) {
|
|
|
134
135
|
}
|
|
135
136
|
if (implicit && !(await lstat(contract.artifactManifestPath).catch(() => undefined)))
|
|
136
137
|
return metadata;
|
|
138
|
+
const admittedSpace = target?.preflight?.artifactSpace;
|
|
139
|
+
const extraRoots = admittedSpace && await realpath(admittedSpace) === admittedSpace ? [admittedSpace] : [];
|
|
140
|
+
if (admittedSpace && !extraRoots.length) {
|
|
141
|
+
const code = 'artifact-space-changed';
|
|
142
|
+
if (implicit) {
|
|
143
|
+
metadata.validation = { status: 'failed', code };
|
|
144
|
+
return metadata;
|
|
145
|
+
}
|
|
146
|
+
throw new A2AResultValidationError(code);
|
|
147
|
+
}
|
|
137
148
|
try {
|
|
138
|
-
metadata.artifacts = await verifiedArtifacts(root, contract.artifactManifestPath);
|
|
149
|
+
metadata.artifacts = await verifiedArtifacts(root, extraRoots, contract.artifactManifestPath);
|
|
139
150
|
}
|
|
140
151
|
catch (error) {
|
|
141
152
|
const code = error instanceof A2AResultValidationError ? error.code : 'artifact-manifest-or-file-unavailable';
|
package/dist/src/a2a/types.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export type A2ARoleSkills = z.infer<typeof a2aRoleSkillsSchema>;
|
|
|
20
20
|
export interface A2APreflightRequirements {
|
|
21
21
|
allowedDirectories?: string[];
|
|
22
22
|
jobDirectory?: string;
|
|
23
|
+
/** Shared deliverable directory for one case. Must already exist; never a role or job directory. */
|
|
24
|
+
artifactSpace?: string;
|
|
25
|
+
/** `<cwd>/.1agents/roles/<roleId>/published`. The host may create this exact path. */
|
|
26
|
+
rolePublication?: string;
|
|
23
27
|
requiredFiles?: string[];
|
|
24
28
|
python?: {
|
|
25
29
|
executable: string;
|
|
@@ -39,6 +43,8 @@ export interface A2APreflightReport {
|
|
|
39
43
|
checkedAt: string;
|
|
40
44
|
cwd: string;
|
|
41
45
|
jobDirectory?: string;
|
|
46
|
+
artifactSpace?: string;
|
|
47
|
+
rolePublication?: string;
|
|
42
48
|
checks: {
|
|
43
49
|
id: string;
|
|
44
50
|
ok: boolean;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { LedgerActor } from './ledger.js';
|
|
3
|
+
import { JobLedger } from './ledger.js';
|
|
4
|
+
export declare const handoffWhenSchema: z.ZodEnum<{
|
|
5
|
+
acceptance_accepted: "acceptance_accepted";
|
|
6
|
+
ticket_closed: "ticket_closed";
|
|
7
|
+
}>;
|
|
8
|
+
export type HandoffWhen = z.infer<typeof handoffWhenSchema>;
|
|
9
|
+
export type HandoffStatus = 'proposed' | 'accepted' | 'taken' | 'rejected';
|
|
10
|
+
export interface Handoff {
|
|
11
|
+
handoffId: string;
|
|
12
|
+
caseId: string;
|
|
13
|
+
fromJobId: string;
|
|
14
|
+
fromAttemptId: string;
|
|
15
|
+
toTargetId: string;
|
|
16
|
+
purpose: string;
|
|
17
|
+
artifactRevision: string;
|
|
18
|
+
artifactDigest: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
status: HandoffStatus;
|
|
21
|
+
clientRequestId?: string;
|
|
22
|
+
conventionId?: string;
|
|
23
|
+
childJobId?: string;
|
|
24
|
+
decidedBy?: LedgerActor;
|
|
25
|
+
note?: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
}
|
|
29
|
+
/** One implication, not a graph. Several may match; more than one match never auto-picks. */
|
|
30
|
+
export interface HandoffConvention {
|
|
31
|
+
conventionId: string;
|
|
32
|
+
originSessionId: string;
|
|
33
|
+
caseId: string;
|
|
34
|
+
fromPurpose?: string;
|
|
35
|
+
fromTargetId?: string;
|
|
36
|
+
toTargetId: string;
|
|
37
|
+
toPurpose: string;
|
|
38
|
+
when: HandoffWhen;
|
|
39
|
+
requireHuman: boolean;
|
|
40
|
+
clientRequestId?: string;
|
|
41
|
+
recordedAt: string;
|
|
42
|
+
}
|
|
43
|
+
export declare class HandoffError extends Error {
|
|
44
|
+
}
|
|
45
|
+
export interface LegalNext {
|
|
46
|
+
conventionId: string;
|
|
47
|
+
toTargetId: string;
|
|
48
|
+
purpose: string;
|
|
49
|
+
requireHuman: boolean;
|
|
50
|
+
when: HandoffWhen;
|
|
51
|
+
/** True when the convention's predicate already holds for the current result. */
|
|
52
|
+
achieved: boolean;
|
|
53
|
+
}
|
|
54
|
+
export declare function legalNextFor(ledger: JobLedger, originSessionId: string, jobId: string): LegalNext[];
|
|
55
|
+
/** Record a proposal. A single matching convention with requireHuman false accepts it. Nothing here opens a job. */
|
|
56
|
+
export declare function proposeHandoff(ledger: JobLedger, originSessionId: string, raw: unknown): Handoff;
|
|
57
|
+
export declare function decideHandoff(ledger: JobLedger, raw: unknown): Handoff;
|
|
58
|
+
/**
|
|
59
|
+
* When exactly one convention's predicate holds and it does not ask for a person, record an accepted handoff.
|
|
60
|
+
* Zero or several matches record nothing. This does not submit the next job.
|
|
61
|
+
*/
|
|
62
|
+
export declare function continueByConvention(ledger: JobLedger, originSessionId: string, jobId: string): Handoff | undefined;
|
|
63
|
+
export declare function offerConvention(ledger: JobLedger, raw: unknown): HandoffConvention;
|
|
64
|
+
export declare function grantArtifactSpace(ledger: JobLedger, raw: unknown): import("./spaces.js").ArtifactSpace;
|
|
65
|
+
export declare function readHandoff(ledger: JobLedger, raw: unknown): {
|
|
66
|
+
artifactSpace?: string | undefined;
|
|
67
|
+
caseId: string | undefined;
|
|
68
|
+
handoffs: Handoff[];
|
|
69
|
+
legalNext: LegalNext[];
|
|
70
|
+
};
|
|
71
|
+
export declare const HANDOFF_METHODS: {
|
|
72
|
+
handoff_propose: {
|
|
73
|
+
description: string;
|
|
74
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
75
|
+
caseId: z.ZodString;
|
|
76
|
+
toTargetId: z.ZodString;
|
|
77
|
+
purpose: z.ZodString;
|
|
78
|
+
artifactRevision: z.ZodString;
|
|
79
|
+
artifactDigest: z.ZodString;
|
|
80
|
+
reason: z.ZodString;
|
|
81
|
+
clientRequestId: z.ZodOptional<z.ZodString>;
|
|
82
|
+
originSessionId: z.ZodString;
|
|
83
|
+
jobId: z.ZodString;
|
|
84
|
+
attemptId: z.ZodString;
|
|
85
|
+
}, z.core.$strict>>;
|
|
86
|
+
};
|
|
87
|
+
handoff_decide: {
|
|
88
|
+
description: string;
|
|
89
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
90
|
+
originSessionId: z.ZodString;
|
|
91
|
+
handoffId: z.ZodString;
|
|
92
|
+
decision: z.ZodEnum<{
|
|
93
|
+
accept: "accept";
|
|
94
|
+
reject: "reject";
|
|
95
|
+
}>;
|
|
96
|
+
note: z.ZodOptional<z.ZodString>;
|
|
97
|
+
decidedBy: z.ZodObject<{
|
|
98
|
+
kind: z.ZodEnum<{
|
|
99
|
+
person: "person";
|
|
100
|
+
coach: "coach";
|
|
101
|
+
}>;
|
|
102
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
103
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
104
|
+
}, z.core.$strict>;
|
|
105
|
+
}, z.core.$strict>>;
|
|
106
|
+
};
|
|
107
|
+
handoff_offer: {
|
|
108
|
+
description: string;
|
|
109
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
110
|
+
originSessionId: z.ZodString;
|
|
111
|
+
caseId: z.ZodString;
|
|
112
|
+
fromPurpose: z.ZodOptional<z.ZodString>;
|
|
113
|
+
fromTargetId: z.ZodOptional<z.ZodString>;
|
|
114
|
+
toTargetId: z.ZodString;
|
|
115
|
+
toPurpose: z.ZodString;
|
|
116
|
+
when: z.ZodEnum<{
|
|
117
|
+
acceptance_accepted: "acceptance_accepted";
|
|
118
|
+
ticket_closed: "ticket_closed";
|
|
119
|
+
}>;
|
|
120
|
+
requireHuman: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
+
clientRequestId: z.ZodOptional<z.ZodString>;
|
|
122
|
+
}, z.core.$strict>>;
|
|
123
|
+
};
|
|
124
|
+
handoff_space: {
|
|
125
|
+
description: string;
|
|
126
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
127
|
+
originSessionId: z.ZodString;
|
|
128
|
+
caseId: z.ZodString;
|
|
129
|
+
root: z.ZodString;
|
|
130
|
+
}, z.core.$strict>>;
|
|
131
|
+
};
|
|
132
|
+
handoff_get: {
|
|
133
|
+
description: string;
|
|
134
|
+
parameters: z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
|
|
135
|
+
originSessionId: z.ZodString;
|
|
136
|
+
jobId: z.ZodString;
|
|
137
|
+
}, z.core.$strict>>;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
/** Gateway entry. An executor may omit originSessionId; the current attempt's session identifies the job. */
|
|
141
|
+
export declare function invokeHandoff(ledger: JobLedger, method: string, params: unknown): unknown;
|