@hivemagnus/ardent 3.1.4 → 3.2.1
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 +479 -6
- package/dist/a2a-client.d.ts +26 -4
- package/dist/a2a-client.js +91 -23
- package/dist/a2a-push-inbox.d.ts +2 -0
- package/dist/a2a-push-inbox.js +7 -0
- package/dist/a2a-push.d.ts +1 -1
- package/dist/a2a-push.js +26 -18
- package/dist/a2a-server.d.ts +17 -0
- package/dist/a2a-server.js +91 -14
- package/dist/a2a.d.ts +19 -1
- package/dist/a2a.js +197 -27
- package/dist/api.d.ts +2 -0
- package/dist/api.js +160 -22
- package/dist/artifact-manifests.d.ts +344 -5
- package/dist/artifact-manifests.js +413 -20
- package/dist/artifact-transfer.d.ts +113 -0
- package/dist/artifact-transfer.js +517 -0
- package/dist/artifacts.d.ts +86 -0
- package/dist/artifacts.js +249 -1
- package/dist/backend-events.d.ts +2 -1
- package/dist/backend-events.js +1 -1
- package/dist/channel-catchup.d.ts +67 -0
- package/dist/channel-catchup.js +108 -0
- package/dist/channels.d.ts +35 -0
- package/dist/channels.js +152 -4
- package/dist/cli.js +28 -3
- package/dist/codex-protocol.d.ts +22 -0
- package/dist/codex-protocol.js +19 -0
- package/dist/codex.d.ts +32 -3
- package/dist/codex.js +91 -17
- package/dist/config.d.ts +25 -2
- package/dist/config.js +41 -4
- package/dist/development.d.ts +6 -6
- package/dist/execution-state.d.ts +245 -0
- package/dist/execution-state.js +236 -0
- package/dist/execution.d.ts +135 -0
- package/dist/execution.js +178 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -3
- package/dist/job-engine.d.ts +2 -1
- package/dist/job-engine.js +33 -4
- package/dist/lineage.d.ts +106 -0
- package/dist/lineage.js +145 -0
- package/dist/llamacpp.d.ts +32 -2
- package/dist/llamacpp.js +69 -33
- package/dist/mattermost.d.ts +8 -0
- package/dist/mattermost.js +250 -36
- package/dist/mission-tools.js +41 -5
- package/dist/missions.d.ts +5 -1
- package/dist/missions.js +10 -5
- package/dist/plugin-evidence.js +2 -1
- package/dist/plugin-sdk.d.ts +3 -0
- package/dist/plugin-sdk.js +3 -0
- package/dist/plugins.d.ts +108 -2
- package/dist/plugins.js +131 -1
- package/dist/preview.d.ts +1 -0
- package/dist/preview.js +4 -1
- package/dist/recovery.d.ts +155 -0
- package/dist/recovery.js +216 -0
- package/dist/research.d.ts +1 -1
- package/dist/retry.d.ts +143 -0
- package/dist/retry.js +127 -0
- package/dist/runtime.d.ts +56 -4
- package/dist/runtime.js +727 -125
- package/dist/store.d.ts +62 -7
- package/dist/store.js +86 -15
- package/dist/team-artifacts.d.ts +130 -112
- package/dist/team-artifacts.js +123 -151
- package/dist/team-child.d.ts +4 -1
- package/dist/team-child.js +21 -2
- package/dist/team-contract.d.ts +1 -1
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +83 -47
- package/dist/tool-scheduler.d.ts +84 -0
- package/dist/tool-scheduler.js +226 -0
- package/dist/tools.d.ts +78 -4
- package/dist/tools.js +34 -7
- package/package.json +15 -8
- package/profiles/assistant/config.yaml +2 -1
package/dist/a2a.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { collectPluginTeamEvidence } from './plugin-evidence.js';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { Role, TaskState } from '@a2a-js/sdk';
|
|
4
|
-
import { AgentEvent } from '@a2a-js/sdk/server';
|
|
4
|
+
import { AgentEvent, ResultManager, ServerCallContext } from '@a2a-js/sdk/server';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { TEAM_TASK_METADATA_KEY, TEAM_CLARIFICATION_METADATA_KEY, TeamResult as TeamResultSchema, validateTeamEnvelope, validateTeamResult } from './team-contract.js';
|
|
7
7
|
import { TeamControlService } from './team-control.js';
|
|
8
8
|
import { TeamChildService } from './team-child.js';
|
|
9
9
|
import { TeamArtifacts } from './team-artifacts.js';
|
|
10
|
+
import { ARTIFACT_TRANSFER_V2_MEDIA_TYPE, ARTIFACT_TRANSFER_V2_URN } from '@hivemagnus/hive-common/artifact';
|
|
10
11
|
import { CodexHarnessBackend } from './codex.js';
|
|
11
12
|
import { LlamaCppBackend } from './llamacpp.js';
|
|
12
13
|
import { ToolRegistry } from './tools.js';
|
|
14
|
+
import { EXECUTION_METADATA_KEY } from './execution.js';
|
|
13
15
|
const maxPartBytes = 2 * 1024 * 1024;
|
|
14
16
|
/** An extracted article is an owner read when its connector result binds the
|
|
15
17
|
* exact request URL, source URL, retrieval time, and content digest. It remains
|
|
@@ -92,9 +94,162 @@ export class ArdentA2AExecutor {
|
|
|
92
94
|
this.#control = new TeamControlService(runtime);
|
|
93
95
|
this.#children = new TeamChildService(runtime, env);
|
|
94
96
|
this.#artifacts = new TeamArtifacts(runtime, runtime.config, env);
|
|
97
|
+
// What the peer was told about a task execution recovery resumed, held or continued; `final` is set once.
|
|
98
|
+
runtime.store.db.exec(`CREATE TABLE IF NOT EXISTS a2a_recovery_publications (a2a_task_id TEXT PRIMARY KEY, operation_id TEXT NOT NULL,
|
|
99
|
+
state TEXT NOT NULL, final INTEGER NOT NULL, updated_ms INTEGER NOT NULL)`);
|
|
95
100
|
// Unacknowledged settlements stay retained for a later flush; never crash startup.
|
|
96
101
|
void this.#children.flush().catch(() => { });
|
|
97
102
|
}
|
|
103
|
+
#recovering = new Set();
|
|
104
|
+
/**
|
|
105
|
+
* Record what is about to be told to the peer about a recovered task. A final
|
|
106
|
+
* state is claimed once, so its status (and push) is published at most once;
|
|
107
|
+
* a held notice once per held state.
|
|
108
|
+
*/
|
|
109
|
+
#claimPublication(a2aTaskId, operationId, state, final) {
|
|
110
|
+
const db = this.runtime.store.db;
|
|
111
|
+
return db.transaction(() => {
|
|
112
|
+
const prior = z.object({ state: z.string(), final: z.number().int() }).safeParse(db.prepare('SELECT state,final FROM a2a_recovery_publications WHERE a2a_task_id=?').get(a2aTaskId)).data;
|
|
113
|
+
if (prior?.final || (prior && !final && prior.state === state))
|
|
114
|
+
return false;
|
|
115
|
+
db.prepare(`INSERT INTO a2a_recovery_publications(a2a_task_id,operation_id,state,final,updated_ms) VALUES (?,?,?,?,?)
|
|
116
|
+
ON CONFLICT(a2a_task_id) DO UPDATE SET operation_id=excluded.operation_id,state=excluded.state,final=excluded.final,updated_ms=excluded.updated_ms`)
|
|
117
|
+
.run(a2aTaskId, operationId, state, final ? 1 : 0, Date.now());
|
|
118
|
+
return true;
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
121
|
+
/** The task whose outcome answers an operation: itself, or the last continuation an operator decision created for it. */
|
|
122
|
+
#answeringTask(operationId) {
|
|
123
|
+
let task = this.runtime.store.get(operationId);
|
|
124
|
+
for (let hops = 0; task && hops < 16; hops++) {
|
|
125
|
+
const next = this.runtime.store.executionState.recovery(task.id)?.continuation_task_id;
|
|
126
|
+
const continued = next ? this.runtime.store.get(next) : undefined;
|
|
127
|
+
if (!continued)
|
|
128
|
+
break;
|
|
129
|
+
task = continued;
|
|
130
|
+
}
|
|
131
|
+
return task;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Tell peers the outcome of A2A tasks whose operation execution recovery
|
|
135
|
+
* resumed, settled, held or continued after a restart; the in-process
|
|
136
|
+
* request that would have published it is gone. Events go through the same
|
|
137
|
+
* task store (GetTask, ListTasks) and push sender as a live request:
|
|
138
|
+
*
|
|
139
|
+
* - resumed: the operation's answer, artifacts and final state, as live;
|
|
140
|
+
* - held awaiting an operator decision: a non-terminal `working` status
|
|
141
|
+
* whose message and `ardentRecovery` metadata give the reason;
|
|
142
|
+
* - continued after a decision: the continuation's outcome, published for
|
|
143
|
+
* the peer's original task (the A2A operation binding moves to the
|
|
144
|
+
* continuation, and `ardentRecovery.continuation_task_id` names it);
|
|
145
|
+
* - unsupported, or abandoned: `failed` with "Execution outcome is unknown".
|
|
146
|
+
*
|
|
147
|
+
* Each final state is claimed once before it is published, so it (and its
|
|
148
|
+
* push) is never published twice. Returns the tasks given a final state.
|
|
149
|
+
*/
|
|
150
|
+
async publishRecovered(taskStore, push) {
|
|
151
|
+
const db = this.runtime.store.db;
|
|
152
|
+
const rows = z.array(z.object({ a2a_task_id: z.string(), operation_id: z.string(), tenant: z.string(), caller: z.string() })).parse(db.prepare(`SELECT m.a2a_task_id,
|
|
153
|
+
m.operation_id, m.tenant, m.caller FROM a2a_operation_map m WHERE EXISTS (SELECT 1 FROM task_recovery r WHERE r.task_id=m.operation_id)
|
|
154
|
+
AND NOT EXISTS (SELECT 1 FROM a2a_recovery_publications p WHERE p.a2a_task_id=m.a2a_task_id AND p.final=1) LIMIT 100`).all());
|
|
155
|
+
let published = 0;
|
|
156
|
+
await Promise.all(rows.map(async (row) => {
|
|
157
|
+
if (this.#recovering.has(row.a2a_task_id) || this.#operations.has(row.a2a_task_id))
|
|
158
|
+
return;
|
|
159
|
+
this.#recovering.add(row.a2a_task_id);
|
|
160
|
+
try {
|
|
161
|
+
if (await this.#publishRecoveredTask(taskStore, push, row))
|
|
162
|
+
published++;
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
this.#recovering.delete(row.a2a_task_id);
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
return published;
|
|
169
|
+
}
|
|
170
|
+
async #publishRecoveredTask(taskStore, push, row) {
|
|
171
|
+
const context = new ServerCallContext({ tenant: row.tenant, user: { isAuthenticated: true, userName: row.caller }, requestedVersion: '1.0' });
|
|
172
|
+
const stored = await taskStore.load(row.a2a_task_id, context);
|
|
173
|
+
const terminal = [TaskState.TASK_STATE_COMPLETED, TaskState.TASK_STATE_FAILED, TaskState.TASK_STATE_CANCELED, TaskState.TASK_STATE_REJECTED];
|
|
174
|
+
if (!stored || (stored.status && terminal.includes(stored.status.state))) {
|
|
175
|
+
this.#claimPublication(row.a2a_task_id, row.operation_id, 'already_final', true);
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const taskId = row.a2a_task_id;
|
|
179
|
+
const contextId = stored.contextId;
|
|
180
|
+
let task = this.#answeringTask(row.operation_id);
|
|
181
|
+
let result;
|
|
182
|
+
if (task && ['queued', 'running'].includes(task.state)) {
|
|
183
|
+
try {
|
|
184
|
+
result = await this.runtime.run(task.id, this.env);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
result = undefined;
|
|
188
|
+
}
|
|
189
|
+
task = this.#answeringTask(row.operation_id);
|
|
190
|
+
}
|
|
191
|
+
if (!task)
|
|
192
|
+
return false;
|
|
193
|
+
const original = this.runtime.store.executionState.recovery(row.operation_id);
|
|
194
|
+
const recovery = this.runtime.store.executionState.recovery(task.id);
|
|
195
|
+
const metadata = { ardentRecovery: { status: (task.id === row.operation_id ? recovery : original)?.status ?? 'resumed', reason_code: (recovery ?? original)?.reason.code ?? null,
|
|
196
|
+
...(task.id !== row.operation_id ? { continuation_task_id: task.id } : {}) } };
|
|
197
|
+
// Events are applied and pushed in order, exactly as a live request applies them.
|
|
198
|
+
const results = new ResultManager(taskStore, context);
|
|
199
|
+
let chain = Promise.resolve();
|
|
200
|
+
const bus = { publish: (event) => {
|
|
201
|
+
chain = chain.then(async () => {
|
|
202
|
+
await results.processEvent(event);
|
|
203
|
+
const payload = event.kind === 'statusUpdate' ? { $case: 'statusUpdate', value: event.data }
|
|
204
|
+
: event.kind === 'artifactUpdate' ? { $case: 'artifactUpdate', value: event.data } : undefined;
|
|
205
|
+
if (payload && push)
|
|
206
|
+
await push.send({ payload }, context, structuredClone(results.getCurrentTask())).catch(() => undefined);
|
|
207
|
+
});
|
|
208
|
+
} };
|
|
209
|
+
const envelopeRow = this.runtime.store.db.prepare('SELECT envelope_json FROM a2a_team_missions WHERE a2a_task_id=?').get(taskId);
|
|
210
|
+
const envelope = envelopeRow ? this.runtime.decodeTeamEnvelope(JSON.parse(z.object({ envelope_json: z.string() }).parse(envelopeRow).envelope_json)) : undefined;
|
|
211
|
+
const childReference = this.#children.referenceFor(row.operation_id);
|
|
212
|
+
if (task.state === 'completed' || task.state === 'partial') {
|
|
213
|
+
if (!this.#claimPublication(taskId, task.id, task.state, true))
|
|
214
|
+
return false;
|
|
215
|
+
if (task.id !== row.operation_id)
|
|
216
|
+
this.runtime.store.db.transaction(() => {
|
|
217
|
+
// The peer's task now follows the continuation: its exports, admission and cancellation bind to it.
|
|
218
|
+
this.runtime.store.db.prepare('UPDATE a2a_operation_map SET operation_id=? WHERE a2a_task_id=?').run(task.id, taskId);
|
|
219
|
+
if (envelope)
|
|
220
|
+
this.runtime.store.db.prepare('INSERT OR IGNORE INTO a2a_operation_links(a2a_task_id,operation_id) VALUES (?,?)').run(taskId, task.id);
|
|
221
|
+
})();
|
|
222
|
+
result ??= await this.runtime.run(task.id, this.env);
|
|
223
|
+
const teamResult = envelope ? await this.#teamResult(envelope, result, task.id) : undefined;
|
|
224
|
+
await this.#publishResult(bus, taskId, contextId, envelope, childReference, teamResult, result, metadata);
|
|
225
|
+
}
|
|
226
|
+
else if (task.state === 'failed' || task.state === 'cancelled') {
|
|
227
|
+
if (!this.#claimPublication(taskId, task.id, task.state, true))
|
|
228
|
+
return false;
|
|
229
|
+
if (childReference)
|
|
230
|
+
await this.#children.settle(childReference, task.state === 'cancelled' ? 'cancelled' : 'failed', task.error ?? task.state).catch(() => undefined);
|
|
231
|
+
bus.publish(AgentEvent.statusUpdate({ ...status(taskId, contextId, task.state === 'cancelled' ? TaskState.TASK_STATE_CANCELED : TaskState.TASK_STATE_FAILED, task.error ?? undefined), metadata }));
|
|
232
|
+
}
|
|
233
|
+
else if (task.state === 'unknown') {
|
|
234
|
+
const held = recovery?.status === 'awaiting_decision' || (recovery?.status === 'resolved' && recovery.continuation_task_id);
|
|
235
|
+
if (held) {
|
|
236
|
+
if (!this.#claimPublication(taskId, task.id, `held:${task.id}`, false))
|
|
237
|
+
return false;
|
|
238
|
+
bus.publish(AgentEvent.statusUpdate({ ...status(taskId, contextId, TaskState.TASK_STATE_WORKING, `Held for an operator decision: ${recovery?.reason.message ?? 'execution outcome is unknown'}`), metadata }));
|
|
239
|
+
await chain;
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
if (!this.#claimPublication(taskId, task.id, 'unknown', true))
|
|
243
|
+
return false;
|
|
244
|
+
if (childReference)
|
|
245
|
+
await this.#children.settle(childReference, 'unknown', task.error ?? 'Execution outcome is unknown').catch(() => undefined);
|
|
246
|
+
bus.publish(AgentEvent.statusUpdate({ ...status(taskId, contextId, TaskState.TASK_STATE_FAILED, `Execution outcome is unknown: ${recovery?.reason.message ?? task.error ?? 'interrupted'}`), metadata }));
|
|
247
|
+
}
|
|
248
|
+
else
|
|
249
|
+
return false;
|
|
250
|
+
await chain;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
98
253
|
async execute(request, bus) {
|
|
99
254
|
const caller = request.context.user;
|
|
100
255
|
if (!caller?.isAuthenticated || !caller.userName)
|
|
@@ -182,7 +337,8 @@ export class ArdentA2AExecutor {
|
|
|
182
337
|
const session = this.runtime.store.session(owner, 'peer', contextId);
|
|
183
338
|
const deadline = childReference ? this.#children.deadline(childReference) : envelope?.mission.deadline;
|
|
184
339
|
const existedBefore = Boolean(request.userMessage.messageId && this.runtime.store.db.prepare("SELECT 1 FROM tasks WHERE caller=? AND context='peer' AND idempotency_key=?").get(owner, request.userMessage.messageId));
|
|
185
|
-
|
|
340
|
+
// Ancestry from the sender (`hiveExecution`) is attribution only; an invalid value mints a root.
|
|
341
|
+
const operation = this.runtime.accept(prompt, owner, 'peer', request.userMessage.messageId, session.id, deadline ? deadline * 1000 : undefined, undefined, { context: metadata[EXECUTION_METADATA_KEY], source: 'a2a' });
|
|
186
342
|
if (envelope && operation.state === 'queued')
|
|
187
343
|
this.runtime.store.append(operation.id, 'team_envelope', wireEnvelope);
|
|
188
344
|
try {
|
|
@@ -209,7 +365,7 @@ export class ArdentA2AExecutor {
|
|
|
209
365
|
throw error;
|
|
210
366
|
}
|
|
211
367
|
if (childReference)
|
|
212
|
-
this.#children.attach(childReference, operation.id);
|
|
368
|
+
this.#children.attach(childReference, operation.id, this.runtime.executionFor(operation.id));
|
|
213
369
|
this.#operations.set(taskId, operation.id);
|
|
214
370
|
if (this.#cancelled.has(taskId)) {
|
|
215
371
|
this.runtime.cancel(operation.id);
|
|
@@ -229,30 +385,7 @@ export class ArdentA2AExecutor {
|
|
|
229
385
|
bus.publish(AgentEvent.statusUpdate(status(taskId, contextId, TaskState.TASK_STATE_FAILED, 'Cancellation was requested during result validation')));
|
|
230
386
|
return;
|
|
231
387
|
}
|
|
232
|
-
|
|
233
|
-
if (childReference && teamResult) {
|
|
234
|
-
try {
|
|
235
|
-
await this.#children.settle(childReference, teamResult.outcome, answerText);
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
this.runtime.store.append(operation.id, 'team_child_settlement_pending', { reason: error instanceof Error ? error.message : 'Root settlement unavailable' });
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const answer = { artifactId: randomUUID(), name: envelope ? 'Team result' : 'Research answer', description: envelope ? 'Validated team result contract' : 'Ardent answer', parts: [textPart(answerText)], metadata: undefined, extensions: [] };
|
|
242
|
-
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: answer, append: false, lastChunk: true, metadata: undefined }));
|
|
243
|
-
if (result.brief) {
|
|
244
|
-
const packet = { artifactId: randomUUID(), name: 'Evidence packet', description: 'Structured source and claim references', parts: [{ content: { $case: 'data', value: result.brief }, metadata: undefined, filename: 'research-brief.json', mediaType: 'application/json' }], metadata: undefined, extensions: [] };
|
|
245
|
-
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: packet, append: false, lastChunk: true, metadata: undefined }));
|
|
246
|
-
}
|
|
247
|
-
if (envelope)
|
|
248
|
-
for (const exported of await this.#artifacts.registerResearch(taskId)) {
|
|
249
|
-
const transfer = { artifactId: randomUUID(), name: 'Team artifact export',
|
|
250
|
-
description: 'Task-bound peer export; fetch and recipient delivery require separate receipts',
|
|
251
|
-
parts: [textPart(JSON.stringify(exported))], metadata: undefined, extensions: [] };
|
|
252
|
-
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: transfer, append: false,
|
|
253
|
-
lastChunk: true, metadata: undefined }));
|
|
254
|
-
}
|
|
255
|
-
bus.publish(AgentEvent.statusUpdate(status(taskId, contextId, teamResult?.outcome === 'input_required' ? TaskState.TASK_STATE_INPUT_REQUIRED : TaskState.TASK_STATE_COMPLETED)));
|
|
388
|
+
await this.#publishResult(bus, taskId, contextId, envelope, childReference, teamResult, result);
|
|
256
389
|
}
|
|
257
390
|
catch (error) {
|
|
258
391
|
const message = error instanceof Error ? error.message : 'Ardent execution failed';
|
|
@@ -274,6 +407,43 @@ export class ArdentA2AExecutor {
|
|
|
274
407
|
this.#cancelled.delete(taskId);
|
|
275
408
|
}
|
|
276
409
|
}
|
|
410
|
+
/** Publish a finished operation's answer, evidence and artifacts, settle its team child, then its final status. */
|
|
411
|
+
async #publishResult(bus, taskId, contextId, envelope, childReference, teamResult, result, metadata) {
|
|
412
|
+
const answerText = teamResult ? JSON.stringify(teamResult) : result.answer;
|
|
413
|
+
if (childReference && teamResult) {
|
|
414
|
+
try {
|
|
415
|
+
await this.#children.settle(childReference, teamResult.outcome, answerText);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
this.runtime.store.append(result.task.id, 'team_child_settlement_pending', { reason: error instanceof Error ? error.message : 'Root settlement unavailable' });
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const answer = { artifactId: randomUUID(), name: envelope ? 'Team result' : 'Research answer', description: envelope ? 'Validated team result contract' : 'Ardent answer', parts: [textPart(answerText)], metadata: undefined, extensions: [] };
|
|
422
|
+
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: answer, append: false, lastChunk: true, metadata: undefined }));
|
|
423
|
+
if (result.brief) {
|
|
424
|
+
const packet = { artifactId: randomUUID(), name: 'Evidence packet', description: 'Structured source and claim references', parts: [{ content: { $case: 'data', value: result.brief }, metadata: undefined, filename: 'research-brief.json', mediaType: 'application/json' }], metadata: undefined, extensions: [] };
|
|
425
|
+
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: packet, append: false, lastChunk: true, metadata: undefined }));
|
|
426
|
+
}
|
|
427
|
+
if (envelope)
|
|
428
|
+
for (const exported of await this.#artifacts.registerResearch(taskId)) {
|
|
429
|
+
// The v1 descriptor (at most 2 MiB) is unchanged; above that a v1 consumer
|
|
430
|
+
// gets an explicit TRANSFER_REQUIRES_V2 result instead.
|
|
431
|
+
const transfer = exported.v1 ? { artifactId: randomUUID(), name: 'Team artifact export',
|
|
432
|
+
description: 'Task-bound peer export; fetch and recipient delivery require separate receipts',
|
|
433
|
+
parts: [textPart(JSON.stringify(exported.v1))], metadata: undefined, extensions: [] }
|
|
434
|
+
: { artifactId: randomUUID(), name: 'Team artifact export requires v2',
|
|
435
|
+
description: `Task-bound peer export larger than the v1 limit; fetch it with ${ARTIFACT_TRANSFER_V2_URN}`,
|
|
436
|
+
parts: [textPart(JSON.stringify(exported.requires_v2))], metadata: undefined, extensions: [] };
|
|
437
|
+
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: transfer, append: false,
|
|
438
|
+
lastChunk: true, metadata: undefined }));
|
|
439
|
+
const v2 = { artifactId: randomUUID(), name: 'Team artifact export v2',
|
|
440
|
+
description: 'Task-bound peer export for resumable transfer with renditions; fetch and recipient delivery require separate receipts',
|
|
441
|
+
parts: [{ content: { $case: 'data', value: exported.v2 }, metadata: undefined, filename: exported.v2.manifest_1_1.name,
|
|
442
|
+
mediaType: ARTIFACT_TRANSFER_V2_MEDIA_TYPE }], metadata: undefined, extensions: [ARTIFACT_TRANSFER_V2_URN] };
|
|
443
|
+
bus.publish(AgentEvent.artifactUpdate({ taskId, contextId, artifact: v2, append: false, lastChunk: true, metadata: undefined }));
|
|
444
|
+
}
|
|
445
|
+
bus.publish(AgentEvent.statusUpdate({ ...status(taskId, contextId, teamResult?.outcome === 'input_required' ? TaskState.TASK_STATE_INPUT_REQUIRED : TaskState.TASK_STATE_COMPLETED), metadata }));
|
|
446
|
+
}
|
|
277
447
|
async cancelTask(taskId, bus) {
|
|
278
448
|
this.#cancelled.add(taskId);
|
|
279
449
|
const task = this.runtime.store.db.prepare('SELECT context_id FROM a2a_tasks WHERE id=?').get(taskId);
|
package/dist/api.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Hono } from 'hono';
|
|
|
2
2
|
import { type LoadedConfig } from './config.js';
|
|
3
3
|
import type { ArdentRuntime } from './runtime.js';
|
|
4
4
|
import type { JobEngine } from './job-engine.js';
|
|
5
|
+
import { ArtifactTransfers } from './artifact-transfer.js';
|
|
5
6
|
export declare function ardentOpenApi(): object;
|
|
6
7
|
/**
|
|
7
8
|
* `env` is the gateway's one shared environment: the runtime, tools, channels
|
|
@@ -10,4 +11,5 @@ export declare function ardentOpenApi(): object;
|
|
|
10
11
|
*/
|
|
11
12
|
export declare function createArdentApi(runtime: ArdentRuntime, loaded: LoadedConfig, env?: NodeJS.ProcessEnv, jobEngine?: JobEngine, options?: {
|
|
12
13
|
envFile?: string;
|
|
14
|
+
artifactTransfers?: ArtifactTransfers;
|
|
13
15
|
}): Hono;
|