@hivemagnus/ardent 3.1.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +504 -16
- 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 +16 -9
- package/profiles/assistant/config.yaml +2 -1
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
2
3
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { formatExecutionRef, isExecutionRef, parseExecutionRef } from '@hivemagnus/hive-common/execution';
|
|
5
|
+
import { ARTIFACT_MAX_BYTES_LIMIT, ArtifactStoreError, formatBytes } from './artifacts.js';
|
|
5
6
|
import { ProvenNoEffectError } from './tools.js';
|
|
6
7
|
const digest = z.string().regex(/^[a-f0-9]{64}$/);
|
|
8
|
+
const identifier = z.string().regex(/^[a-f0-9]{32}$/);
|
|
9
|
+
const safeName = z.string().regex(/^[A-Za-z0-9._-]{1,128}$/);
|
|
10
|
+
/**
|
|
11
|
+
* Manifest 1.0, as peers exchange it over the v1 (single-response) team
|
|
12
|
+
* transfer. Its size bound is that transfer's 2 MiB limit.
|
|
13
|
+
*/
|
|
14
|
+
export const TeamArtifactManifestSchema = z.object({
|
|
15
|
+
schema_version: z.literal('1.0'), revision: z.number().int().min(1), source_revision: z.string().min(1),
|
|
16
|
+
visibility: z.enum(['private', 'gm', 'player']), license: z.string().min(1),
|
|
17
|
+
preview: z.object({ mode: z.enum(['inline', 'thumbnail', 'download_only', 'none']), mime: z.string().min(1) }).strict(),
|
|
18
|
+
supersedes_sha256: digest.nullable(), acceptance_status: z.enum(['unreviewed', 'approved', 'partial', 'rejected']),
|
|
19
|
+
name: safeName, mime: z.string().min(1), sha256: digest, size: z.number().int().min(0).max(2 * 1024 * 1024),
|
|
20
|
+
created_at: z.number().finite(), expires_at: z.number().finite(),
|
|
21
|
+
provenance: z.object({ producer: z.string().min(1), source_id: z.string(), producer_task_id: z.string().min(1),
|
|
22
|
+
lineage: z.array(z.object({ producer: z.string().min(1), source_id: z.string() }).strict()).min(1).max(4) }).strict(),
|
|
23
|
+
recovery: z.object({ on_expiry: z.literal('request_verified_reexport') }).strict(), artifact_id: identifier
|
|
24
|
+
}).strict();
|
|
7
25
|
/** Media types an agent may register, with the bytes each must start with (binary) or the text it must hold. */
|
|
8
26
|
export const ARTIFACT_MIME_TYPES = {
|
|
9
27
|
'text/markdown': 'text', 'text/plain': 'text', 'application/json': 'json', 'text/csv': 'text', 'image/svg+xml': 'svg',
|
|
@@ -18,7 +36,56 @@ export const NO_EXPIRY_SECONDS = 253402300799;
|
|
|
18
36
|
export const ArtifactManifestSchema = TeamArtifactManifestSchema.extend({ size: z.number().int().min(0).max(ARTIFACT_MAX_BYTES_LIMIT) }).strict();
|
|
19
37
|
/** A manifest with the task that produced it and the artifact that later revised it, if any. */
|
|
20
38
|
export const ArtifactRecordSchema = z.object({ task_id: z.string(), superseded_by_sha256: digest.nullable(), manifest: ArtifactManifestSchema }).strict();
|
|
39
|
+
const ExecutionRef = z.string().max(256).refine(isExecutionRef, 'Invalid execution reference');
|
|
40
|
+
/** Execution ancestry of an artifact: attribution only, never an authority. */
|
|
41
|
+
export const ArtifactExecutionSchema = z.object({ root: ExecutionRef, task: ExecutionRef.optional(), step: ExecutionRef.optional() }).strict();
|
|
42
|
+
export const RenditionRoleSchema = z.enum(['original', 'preview', 'model_input']);
|
|
43
|
+
const TransformParam = z.union([z.string().max(256), z.number().finite(), z.boolean(), z.null()]);
|
|
44
|
+
/** How a rendition was derived from its original. */
|
|
45
|
+
export const ArtifactTransformSchema = z.object({
|
|
46
|
+
name: z.string().regex(/^[a-z0-9][a-z0-9._-]{0,63}$/), version: z.string().min(1).max(64),
|
|
47
|
+
params: z.record(z.string().regex(/^[A-Za-z0-9_.-]{1,64}$/), TransformParam).refine(value => Object.keys(value).length <= 32, 'At most 32 transform parameters')
|
|
48
|
+
}).strict();
|
|
49
|
+
const Purpose = z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/);
|
|
50
|
+
export const ArtifactRenditionInfoSchema = z.object({ role: RenditionRoleSchema, of_sha256: digest, purpose: Purpose, transform: ArtifactTransformSchema }).strict();
|
|
51
|
+
/**
|
|
52
|
+
* Manifest 1.1: a strict superset of 1.0 that may name the original a
|
|
53
|
+
* rendition derives from and the execution that produced it. It is as
|
|
54
|
+
* immutable as 1.0 and is shown only to transfer-v2 consumers.
|
|
55
|
+
*/
|
|
56
|
+
export const ArtifactManifest11Schema = ArtifactManifestSchema.extend({
|
|
57
|
+
schema_version: z.literal('1.1'),
|
|
58
|
+
provenance: ArtifactManifestSchema.shape.provenance.extend({ execution: ArtifactExecutionSchema.optional() }).strict(),
|
|
59
|
+
rendition: ArtifactRenditionInfoSchema.optional()
|
|
60
|
+
}).strict();
|
|
61
|
+
/** A manifest 1.1 record, as transfer-v2 routes return it. */
|
|
62
|
+
export const ArtifactRecordV2Schema = z.object({ task_id: z.string(), superseded_by_sha256: digest.nullable(), manifest: ArtifactManifest11Schema }).strict();
|
|
63
|
+
/** One available form of an artifact (the HiveCommon `Rendition` shape plus its purpose). */
|
|
64
|
+
export const ArtifactRenditionSchema = z.object({ sha256: digest, role: RenditionRoleSchema, mime: z.string(), size: z.number().int().min(0),
|
|
65
|
+
purpose: z.string(), width: z.number().int().positive().optional(), height: z.number().int().positive().optional(), has_alpha: z.boolean().optional() }).strict();
|
|
66
|
+
const StoredManifest = z.discriminatedUnion('schema_version', [ArtifactManifestSchema, ArtifactManifest11Schema]);
|
|
67
|
+
/** The 1.0 view of a stored manifest: the fields 1.1 added are left out. A 1.0 manifest is returned as it is. */
|
|
68
|
+
export function manifestV10(manifest) {
|
|
69
|
+
if (manifest.schema_version === '1.0')
|
|
70
|
+
return manifest;
|
|
71
|
+
const provenance = { producer: manifest.provenance.producer, source_id: manifest.provenance.source_id,
|
|
72
|
+
producer_task_id: manifest.provenance.producer_task_id, lineage: manifest.provenance.lineage };
|
|
73
|
+
const copy = { ...manifest, schema_version: '1.0', provenance };
|
|
74
|
+
delete copy.rendition;
|
|
75
|
+
return ArtifactManifestSchema.parse(copy);
|
|
76
|
+
}
|
|
77
|
+
/** The 1.1 view of a stored manifest. A 1.0 manifest needs none of the optional 1.1 fields. */
|
|
78
|
+
export function manifestV11(manifest) {
|
|
79
|
+
return manifest.schema_version === '1.1' ? manifest : ArtifactManifest11Schema.parse({ ...manifest, schema_version: '1.1' });
|
|
80
|
+
}
|
|
21
81
|
const Row = z.object({ artifact_id: z.string(), task_id: z.string(), sha256: digest, manifest_json: z.string(), superseded_by: digest.nullable() });
|
|
82
|
+
const RenditionRow = z.object({ sha256: digest, role: RenditionRoleSchema, purpose: z.string(), mime: z.string(), size: z.number().int(),
|
|
83
|
+
width: z.number().int().nullable(), height: z.number().int().nullable(), has_alpha: z.number().int().nullable() });
|
|
84
|
+
/** JSON artifacts registered from a stream are parsed whole; larger ones are refused. */
|
|
85
|
+
const JSON_STREAM_LIMIT = 8 * 1024 * 1024;
|
|
86
|
+
const EXTENSIONS = { 'text/markdown': 'md', 'text/plain': 'txt', 'application/json': 'json', 'text/csv': 'csv',
|
|
87
|
+
'image/svg+xml': 'svg', 'image/png': 'png', 'image/jpeg': 'jpg', 'image/webp': 'webp', 'application/pdf': 'pdf',
|
|
88
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx' };
|
|
22
89
|
function startsWith(bytes, ...prefix) { return prefix.every((value, index) => bytes[index] === value); }
|
|
23
90
|
/** Reject bytes that are not what their declared media type says. Text must be valid UTF-8. */
|
|
24
91
|
export function checkArtifactContent(mime, bytes) {
|
|
@@ -67,6 +134,74 @@ export function checkArtifactContent(mime, bytes) {
|
|
|
67
134
|
if (kind === 'svg' && !/<svg[\s>]/i.test(text.slice(0, 4096)))
|
|
68
135
|
fail();
|
|
69
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Check streamed bytes against their declared media type as they arrive, with
|
|
139
|
+
* the same rules as `checkArtifactContent`, without holding binary content.
|
|
140
|
+
*/
|
|
141
|
+
export function artifactContentInspector(mime) {
|
|
142
|
+
const kind = ARTIFACT_MIME_TYPES[mime];
|
|
143
|
+
const fail = () => { throw new ProvenNoEffectError(`Artifact content is not valid ${mime}`, 'INVALID_ARTIFACT'); };
|
|
144
|
+
if (kind === 'png' || kind === 'jpeg' || kind === 'webp' || kind === 'pdf' || kind === 'docx') {
|
|
145
|
+
let head = Buffer.alloc(0);
|
|
146
|
+
return { write(chunk) { if (head.byteLength < 16)
|
|
147
|
+
head = Buffer.concat([head, chunk.subarray(0, 16 - head.byteLength)]); },
|
|
148
|
+
end() { checkArtifactContent(mime, head); } };
|
|
149
|
+
}
|
|
150
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
151
|
+
let text = '';
|
|
152
|
+
let length = 0;
|
|
153
|
+
return {
|
|
154
|
+
write(chunk) {
|
|
155
|
+
length += chunk.byteLength;
|
|
156
|
+
let decoded = '';
|
|
157
|
+
try {
|
|
158
|
+
decoded = decoder.decode(chunk, { stream: true });
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
fail();
|
|
162
|
+
}
|
|
163
|
+
if (kind === 'json') {
|
|
164
|
+
if (length > JSON_STREAM_LIMIT)
|
|
165
|
+
throw new ProvenNoEffectError('Streamed JSON artifacts are limited to 8 MiB', 'ARTIFACT_TOO_LARGE');
|
|
166
|
+
text += decoded;
|
|
167
|
+
}
|
|
168
|
+
else if (kind === 'svg' && text.length < 4096)
|
|
169
|
+
text += decoded.slice(0, 4096 - text.length);
|
|
170
|
+
},
|
|
171
|
+
end() {
|
|
172
|
+
let rest = '';
|
|
173
|
+
try {
|
|
174
|
+
rest = decoder.decode();
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
fail();
|
|
178
|
+
}
|
|
179
|
+
if (kind === 'json') {
|
|
180
|
+
try {
|
|
181
|
+
JSON.parse(text + rest);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
fail();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (kind === 'svg' && !/<svg[\s>]/i.test((text + rest).slice(0, 4096)))
|
|
188
|
+
fail();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** Width, height and transparency of a PNG from its IHDR chunk, when the header is well formed. */
|
|
193
|
+
export function pngInfo(head) {
|
|
194
|
+
const bytes = Buffer.from(head.buffer, head.byteOffset, head.byteLength);
|
|
195
|
+
if (bytes.byteLength < 26 || !startsWith(bytes, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a) || bytes.toString('latin1', 12, 16) !== 'IHDR')
|
|
196
|
+
return undefined;
|
|
197
|
+
const width = bytes.readUInt32BE(16), height = bytes.readUInt32BE(20), colorType = bytes[25];
|
|
198
|
+
if (!width || !height || colorType === undefined)
|
|
199
|
+
return undefined;
|
|
200
|
+
return { width, height, has_alpha: colorType === 4 || colorType === 6 };
|
|
201
|
+
}
|
|
202
|
+
function storeRefusal(error) {
|
|
203
|
+
return error instanceof ArtifactStoreError ? new ProvenNoEffectError(error.message, error.code === 'SIZE_MISMATCH' ? 'DIGEST_MISMATCH' : error.code) : error;
|
|
204
|
+
}
|
|
70
205
|
/**
|
|
71
206
|
* Registered artifacts with their manifests. A manifest is an immutable producer
|
|
72
207
|
* record; a later artifact may revise (supersede) an earlier one by digest.
|
|
@@ -88,44 +223,215 @@ export class ArtifactManifests {
|
|
|
88
223
|
CREATE INDEX IF NOT EXISTS artifact_manifests_supersedes ON artifact_manifests(supersedes_sha256);
|
|
89
224
|
CREATE TRIGGER IF NOT EXISTS artifact_manifests_immutable BEFORE UPDATE ON artifact_manifests
|
|
90
225
|
BEGIN SELECT RAISE(ABORT, 'Artifact manifests are immutable'); END;
|
|
91
|
-
CREATE TABLE IF NOT EXISTS artifact_sweeps (sha256 TEXT PRIMARY KEY, outcome TEXT NOT NULL, swept_ms INTEGER NOT NULL)
|
|
226
|
+
CREATE TABLE IF NOT EXISTS artifact_sweeps (sha256 TEXT PRIMARY KEY, outcome TEXT NOT NULL, swept_ms INTEGER NOT NULL);
|
|
227
|
+
CREATE TABLE IF NOT EXISTS artifact_renditions (
|
|
228
|
+
original_sha256 TEXT NOT NULL, rendition_sha256 TEXT NOT NULL, role TEXT NOT NULL, purpose TEXT NOT NULL,
|
|
229
|
+
rendition_artifact_id TEXT NOT NULL REFERENCES artifact_manifests(artifact_id),
|
|
230
|
+
width INTEGER, height INTEGER, has_alpha INTEGER, created_ms INTEGER NOT NULL,
|
|
231
|
+
PRIMARY KEY(original_sha256, rendition_sha256));
|
|
232
|
+
CREATE INDEX IF NOT EXISTS artifact_renditions_rendition ON artifact_renditions(rendition_sha256);
|
|
233
|
+
CREATE TRIGGER IF NOT EXISTS artifact_renditions_immutable BEFORE UPDATE ON artifact_renditions
|
|
234
|
+
BEGIN SELECT RAISE(ABORT, 'Artifact renditions are immutable'); END;`);
|
|
235
|
+
// Additive: the tool-call idempotency key that registered an artifact, so a
|
|
236
|
+
// re-dispatched or reconciled call finds its registration instead of adding one.
|
|
237
|
+
const columns = z.array(z.object({ name: z.string() })).parse(store.db.pragma('table_info(artifact_manifests)'));
|
|
238
|
+
if (!columns.some(column => column.name === 'idempotency_key'))
|
|
239
|
+
store.db.exec('ALTER TABLE artifact_manifests ADD COLUMN idempotency_key TEXT');
|
|
240
|
+
store.db.exec('CREATE INDEX IF NOT EXISTS artifact_manifests_idempotency ON artifact_manifests(task_id, idempotency_key)');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The artifact a task registered under a tool-call idempotency key, as 1.0.
|
|
244
|
+
* `artifact_write` and `document_render` use it to stay idempotent and to
|
|
245
|
+
* reconcile an interrupted call from the manifest row.
|
|
246
|
+
*/
|
|
247
|
+
registeredFor(taskId, idempotencyKey) {
|
|
248
|
+
const raw = this.store.db.prepare(`${this.#select} WHERE m.task_id=? AND m.idempotency_key=? ORDER BY m.created_ms, m.artifact_id LIMIT 1`).get(taskId, idempotencyKey);
|
|
249
|
+
return raw ? this.#v10(this.#record(raw)) : undefined;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The execution provenance of an artifact a task produces: the task's root,
|
|
253
|
+
* the task, and, while the task runs, the model step it is in. Undefined
|
|
254
|
+
* for a task with no recorded execution context. Attribution only.
|
|
255
|
+
*/
|
|
256
|
+
executionProvenance(taskId) {
|
|
257
|
+
const record = this.store.executions.get(taskId);
|
|
258
|
+
if (!record)
|
|
259
|
+
return undefined;
|
|
260
|
+
// The step is known only while the task runs: a later registration names the task alone.
|
|
261
|
+
const raw = this.store.get(taskId)?.state !== 'running' ? undefined
|
|
262
|
+
: this.store.db.prepare("SELECT json_extract(detail_json,'$.step') AS step FROM events WHERE task_id=? AND kind='model_started' ORDER BY sequence DESC LIMIT 1").get(taskId);
|
|
263
|
+
const step = z.object({ step: z.number().int().min(0).nullable() }).safeParse(raw).data?.step;
|
|
264
|
+
const instance = parseExecutionRef(record.self_ref)?.instance;
|
|
265
|
+
const stepRef = step === undefined || step === null || !instance ? undefined
|
|
266
|
+
: formatExecutionRef({ product: 'ardent', instance, kind: 'step', id: `${taskId}/${step}` });
|
|
267
|
+
return ArtifactExecutionSchema.parse({ root: record.root_ref, task: record.self_ref, ...(stepRef ? { step: stepRef } : {}) });
|
|
92
268
|
}
|
|
93
269
|
/**
|
|
94
270
|
* Store bytes for a task and record their manifest and an `artifact_registered`
|
|
95
271
|
* journal event. `revisesSha256` must name a current registered artifact.
|
|
272
|
+
* When the task has an execution context the stored manifest is 1.1 with
|
|
273
|
+
* `provenance.execution`; the returned record, like every 1.0 view, is 1.0.
|
|
96
274
|
*/
|
|
97
275
|
async register(input) {
|
|
276
|
+
// A repeated tool call (same idempotency key) returns its registration instead of adding another.
|
|
277
|
+
const prior = input.idempotencyKey ? this.registeredFor(input.taskId, input.idempotencyKey) : undefined;
|
|
278
|
+
if (prior)
|
|
279
|
+
return prior;
|
|
98
280
|
// Every check that can refuse the artifact runs before any byte is stored.
|
|
99
281
|
if (!/^[A-Za-z0-9._-]{1,128}$/.test(input.name))
|
|
100
282
|
throw new ProvenNoEffectError('Invalid artifact name', 'INVALID_ARTIFACT');
|
|
101
283
|
if (input.bytes.length > this.artifacts.maxBytes)
|
|
102
284
|
throw new ProvenNoEffectError(`Artifact exceeds ${formatBytes(this.artifacts.maxBytes)}`, 'ARTIFACT_TOO_LARGE');
|
|
103
285
|
checkArtifactContent(input.mime, input.bytes);
|
|
104
|
-
const
|
|
105
|
-
if (input.
|
|
286
|
+
const execution = input.execution === undefined ? this.executionProvenance(input.taskId) : ArtifactExecutionSchema.safeParse(input.execution).data;
|
|
287
|
+
if (input.execution !== undefined && !execution)
|
|
288
|
+
throw new ProvenNoEffectError('Invalid execution provenance', 'INVALID_ARTIFACT');
|
|
289
|
+
const revised = input.revisesSha256 ? this.manifest(input.revisesSha256) : undefined;
|
|
290
|
+
if (input.revisesSha256 && !revised)
|
|
106
291
|
throw new ProvenNoEffectError('revises_sha256 does not name a current artifact', 'NOT_FOUND');
|
|
107
|
-
if (
|
|
292
|
+
if (revised && revised.manifest.sha256 === createHash('sha256').update(input.bytes).digest('hex'))
|
|
108
293
|
throw new ProvenNoEffectError('Revision content is identical to the revised artifact', 'INVALID_ARTIFACT');
|
|
109
294
|
const stored = await this.artifacts.put(input.name, input.mime, input.bytes);
|
|
110
295
|
const created = Date.now();
|
|
111
296
|
const id = randomBytes(16).toString('hex');
|
|
112
297
|
const manifest = ArtifactManifestSchema.parse({
|
|
113
|
-
schema_version: '1.0', revision:
|
|
298
|
+
schema_version: '1.0', revision: revised ? revised.manifest.revision + 1 : 1, source_revision: stored.sha256,
|
|
114
299
|
visibility: 'private', license: 'NOASSERTION',
|
|
115
300
|
preview: { mode: input.mime === 'application/pdf' || ARTIFACT_MIME_TYPES[input.mime] === 'docx' ? 'download_only' : 'inline', mime: input.mime },
|
|
116
|
-
supersedes_sha256:
|
|
301
|
+
supersedes_sha256: revised?.manifest.sha256 ?? null, acceptance_status: 'unreviewed', name: input.name, mime: input.mime,
|
|
117
302
|
sha256: stored.sha256, size: stored.bytes, created_at: created / 1000,
|
|
118
303
|
expires_at: input.ttlSeconds ? created / 1000 + input.ttlSeconds : NO_EXPIRY_SECONDS,
|
|
119
304
|
provenance: { producer: this.producer, source_id: input.source, producer_task_id: input.taskId,
|
|
120
305
|
lineage: [{ producer: this.producer, source_id: input.source }] },
|
|
121
306
|
recovery: { on_expiry: 'request_verified_reexport' }, artifact_id: id
|
|
122
307
|
});
|
|
308
|
+
const stored11 = execution ? ArtifactManifest11Schema.parse({ ...manifest, schema_version: '1.1',
|
|
309
|
+
provenance: { ...manifest.provenance, execution } }) : undefined;
|
|
310
|
+
this.store.db.transaction(() => this.#insert(input.taskId, stored11 ?? manifest, created, 'artifact_registered', input.idempotencyKey))();
|
|
311
|
+
return { task_id: input.taskId, superseded_by_sha256: null, manifest };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Stream bytes into the store for a task and record a manifest 1.1 for them.
|
|
315
|
+
* The content check, size bound and any expected digest are applied while the
|
|
316
|
+
* bytes arrive; a refusal stores nothing. `execution` is attribution only;
|
|
317
|
+
* without it, the task's own execution provenance is recorded when it has one.
|
|
318
|
+
*/
|
|
319
|
+
async registerStream(input) {
|
|
320
|
+
if (!safeName.safeParse(input.name).success)
|
|
321
|
+
throw new ProvenNoEffectError('Invalid artifact name', 'INVALID_ARTIFACT');
|
|
322
|
+
const mime = ArtifactMimeSchema.safeParse(input.mime);
|
|
323
|
+
if (!mime.success)
|
|
324
|
+
throw new ProvenNoEffectError('Unsupported artifact media type', 'INVALID_ARTIFACT');
|
|
325
|
+
const execution = input.execution === undefined ? undefined : ArtifactExecutionSchema.safeParse(input.execution);
|
|
326
|
+
if (execution && !execution.success)
|
|
327
|
+
throw new ProvenNoEffectError('Invalid execution provenance', 'INVALID_ARTIFACT');
|
|
328
|
+
if (!this.store.get(input.taskId))
|
|
329
|
+
throw new ProvenNoEffectError('Task not found', 'NOT_FOUND');
|
|
330
|
+
const derived = execution ? undefined : this.executionProvenance(input.taskId);
|
|
331
|
+
const prior = input.revisesSha256 ? this.manifest(input.revisesSha256) : undefined;
|
|
332
|
+
if (input.revisesSha256 && !prior)
|
|
333
|
+
throw new ProvenNoEffectError('revises_sha256 does not name a current artifact', 'NOT_FOUND');
|
|
334
|
+
const stored = await this.#putStream(input.stream, input.name, mime.data, input);
|
|
335
|
+
if (prior && prior.manifest.sha256 === stored.sha256)
|
|
336
|
+
throw new ProvenNoEffectError('Revision content is identical to the revised artifact', 'INVALID_ARTIFACT');
|
|
337
|
+
const created = Date.now();
|
|
338
|
+
const manifest = ArtifactManifest11Schema.parse({
|
|
339
|
+
...this.#baseManifest(stored, mime.data, created, input.ttlSeconds), schema_version: '1.1',
|
|
340
|
+
revision: prior ? prior.manifest.revision + 1 : 1, supersedes_sha256: prior?.manifest.sha256 ?? null,
|
|
341
|
+
provenance: { producer: this.producer, source_id: input.source, producer_task_id: input.taskId,
|
|
342
|
+
lineage: [{ producer: this.producer, source_id: input.source }], ...(execution?.data ?? derived ? { execution: execution?.data ?? derived } : {}) }
|
|
343
|
+
});
|
|
344
|
+
this.store.db.transaction(() => this.#insert(input.taskId, manifest, created))();
|
|
345
|
+
return { task_id: input.taskId, superseded_by_sha256: null, manifest };
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Register a preview or model-input rendition of a current original. The
|
|
349
|
+
* rendition is a separate artifact with its own digest and a manifest 1.1
|
|
350
|
+
* that names the original; the original is never changed. Registering the
|
|
351
|
+
* same bytes for the same original again returns the existing record.
|
|
352
|
+
*/
|
|
353
|
+
async registerRendition(input) {
|
|
354
|
+
if ((input.bytes === undefined) === (input.stream === undefined))
|
|
355
|
+
throw new ProvenNoEffectError('Give exactly one of bytes or stream', 'INVALID_ARTIFACT');
|
|
356
|
+
const mime = ArtifactMimeSchema.safeParse(input.mime);
|
|
357
|
+
const info = z.object({ role: z.enum(['preview', 'model_input']), purpose: Purpose, transform: ArtifactTransformSchema,
|
|
358
|
+
width: z.number().int().positive().optional(), height: z.number().int().positive().optional(), has_alpha: z.boolean().optional(),
|
|
359
|
+
producer: z.string().min(1).max(128).optional() }).safeParse({ role: input.role, purpose: input.purpose, transform: input.transform,
|
|
360
|
+
width: input.width, height: input.height, has_alpha: input.has_alpha, producer: input.producer });
|
|
361
|
+
if (!mime.success || !info.success)
|
|
362
|
+
throw new ProvenNoEffectError('Invalid rendition', 'INVALID_ARTIFACT');
|
|
363
|
+
const original = this.manifestV2(input.originalSha256);
|
|
364
|
+
if (!original)
|
|
365
|
+
throw new ProvenNoEffectError('Original artifact has no current manifest', 'NOT_FOUND');
|
|
366
|
+
if (original.manifest.rendition && original.manifest.rendition.role !== 'original')
|
|
367
|
+
throw new ProvenNoEffectError('A rendition derives from an original, not from another rendition', 'INVALID_ARTIFACT');
|
|
368
|
+
const stem = original.manifest.name.replace(/\.[A-Za-z0-9]{1,8}$/, '').slice(0, 100);
|
|
369
|
+
const name = input.name ?? `${stem}.${input.role === 'preview' ? 'preview' : 'model-input'}.${EXTENSIONS[mime.data]}`;
|
|
370
|
+
if (!safeName.safeParse(name).success)
|
|
371
|
+
throw new ProvenNoEffectError('Invalid artifact name', 'INVALID_ARTIFACT');
|
|
372
|
+
const stored = await this.#putStream(input.stream ?? Readable.from([input.bytes ?? new Uint8Array()]), name, mime.data, input);
|
|
373
|
+
if (stored.sha256 === original.manifest.sha256)
|
|
374
|
+
throw new ProvenNoEffectError('A rendition must differ from its original', 'INVALID_ARTIFACT');
|
|
375
|
+
const existing = this.store.db.prepare('SELECT rendition_artifact_id FROM artifact_renditions WHERE original_sha256=? AND rendition_sha256=?')
|
|
376
|
+
.get(original.manifest.sha256, stored.sha256);
|
|
377
|
+
if (existing) {
|
|
378
|
+
const prior = this.#byId(z.object({ rendition_artifact_id: identifier }).parse(existing).rendition_artifact_id);
|
|
379
|
+
if (prior)
|
|
380
|
+
return prior;
|
|
381
|
+
}
|
|
382
|
+
const producer = info.data.producer ?? this.producer;
|
|
383
|
+
const created = Date.now();
|
|
384
|
+
const sourceId = `ardent-artifact:${original.manifest.sha256}`;
|
|
385
|
+
const manifest = ArtifactManifest11Schema.parse({
|
|
386
|
+
...this.#baseManifest(stored, mime.data, created, undefined), schema_version: '1.1',
|
|
387
|
+
visibility: original.manifest.visibility, license: original.manifest.license, expires_at: original.manifest.expires_at,
|
|
388
|
+
provenance: { producer, source_id: sourceId, producer_task_id: original.task_id,
|
|
389
|
+
lineage: [...original.manifest.provenance.lineage.slice(-3), { producer, source_id: sourceId }],
|
|
390
|
+
...(original.manifest.provenance.execution ? { execution: original.manifest.provenance.execution } : {}) },
|
|
391
|
+
rendition: { role: info.data.role, of_sha256: original.manifest.sha256, purpose: info.data.purpose, transform: info.data.transform }
|
|
392
|
+
});
|
|
123
393
|
this.store.db.transaction(() => {
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
sha256: manifest.sha256, size: manifest.size, revision: manifest.revision, supersedes_sha256: manifest.supersedes_sha256, manifest });
|
|
394
|
+
this.#insert(original.task_id, manifest, created, 'artifact_rendition_registered');
|
|
395
|
+
this.store.db.prepare(`INSERT INTO artifact_renditions(original_sha256,rendition_sha256,role,purpose,rendition_artifact_id,width,height,has_alpha,created_ms)
|
|
396
|
+
VALUES (?,?,?,?,?,?,?,?,?)`).run(original.manifest.sha256, stored.sha256, info.data.role, info.data.purpose, manifest.artifact_id, info.data.width ?? null, info.data.height ?? null, info.data.has_alpha === undefined ? null : info.data.has_alpha ? 1 : 0, created);
|
|
128
397
|
})();
|
|
398
|
+
return { task_id: original.task_id, superseded_by_sha256: null, manifest };
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Record a manifest 1.1 for bytes already in the store, received from a peer.
|
|
402
|
+
* The peer's manifest supplies name, media type, revision and provenance; the
|
|
403
|
+
* local record adds the peer hop to the lineage and does not expire.
|
|
404
|
+
*/
|
|
405
|
+
async registerImported(input) {
|
|
406
|
+
if (input.artifactId !== undefined && !identifier.safeParse(input.artifactId).success)
|
|
407
|
+
throw new ProvenNoEffectError('Invalid artifact ID', 'INVALID_ARTIFACT');
|
|
408
|
+
const already = input.artifactId === undefined ? undefined : this.#byId(input.artifactId);
|
|
409
|
+
if (already) {
|
|
410
|
+
this.store.db.transaction(() => input.onRegistered?.())();
|
|
411
|
+
return already;
|
|
412
|
+
}
|
|
413
|
+
const remote = ArtifactManifest11Schema.parse(input.manifest);
|
|
414
|
+
const mime = ArtifactMimeSchema.safeParse(remote.mime);
|
|
415
|
+
if (!mime.success)
|
|
416
|
+
throw new ProvenNoEffectError('Unsupported artifact media type', 'INVALID_ARTIFACT');
|
|
417
|
+
// The store is content-addressed and its writers verify digests; check the size and the content rules.
|
|
418
|
+
const stored = await this.artifacts.stat(remote.sha256);
|
|
419
|
+
if (!stored || stored.size !== remote.size)
|
|
420
|
+
throw new ProvenNoEffectError('Stored artifact size differs from its manifest', 'DIGEST_MISMATCH');
|
|
421
|
+
const binary = ['png', 'jpeg', 'webp', 'pdf', 'docx'].includes(ARTIFACT_MIME_TYPES[mime.data]);
|
|
422
|
+
const read = await this.artifacts.openRead(remote.sha256, binary && stored.size > 0 ? { start: 0, end: Math.min(15, stored.size - 1) } : {});
|
|
423
|
+
const inspector = artifactContentInspector(mime.data);
|
|
424
|
+
for await (const chunk of read.stream)
|
|
425
|
+
inspector.write(z.instanceof(Buffer).parse(chunk));
|
|
426
|
+
inspector.end();
|
|
427
|
+
const created = Date.now();
|
|
428
|
+
const hop = { producer: `a2a:${input.peer}`.slice(0, 200), source_id: `a2a-task:${input.remoteTaskId}`.slice(0, 300) };
|
|
429
|
+
const manifest = ArtifactManifest11Schema.parse({ ...remote, created_at: created / 1000, expires_at: NO_EXPIRY_SECONDS,
|
|
430
|
+
artifact_id: input.artifactId ?? randomBytes(16).toString('hex'),
|
|
431
|
+
// The producer's execution stays; a manifest without one gets the importing task's.
|
|
432
|
+
provenance: { ...remote.provenance, producer_task_id: input.remoteTaskId, lineage: [...remote.provenance.lineage.slice(-3), hop],
|
|
433
|
+
...(remote.provenance.execution ? {} : (() => { const local = this.executionProvenance(input.taskId); return local ? { execution: local } : {}; })()) } });
|
|
434
|
+
this.store.db.transaction(() => { this.#insert(input.taskId, manifest, created); input.onRegistered?.(); })();
|
|
129
435
|
return { task_id: input.taskId, superseded_by_sha256: null, manifest };
|
|
130
436
|
}
|
|
131
437
|
/**
|
|
@@ -148,25 +454,112 @@ export class ArtifactManifests {
|
|
|
148
454
|
}
|
|
149
455
|
return result;
|
|
150
456
|
}
|
|
151
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* Current (unexpired) manifests a task registered, oldest first, as 1.0.
|
|
459
|
+
* Renditions are listed with their original (`renditions`), not here.
|
|
460
|
+
*/
|
|
152
461
|
forTask(taskId, limit = 100) {
|
|
153
|
-
return this.store.db.prepare(`${this.#select} WHERE m.task_id=? AND m.expires_ms>?
|
|
154
|
-
|
|
462
|
+
return this.store.db.prepare(`${this.#select} WHERE m.task_id=? AND m.expires_ms>?
|
|
463
|
+
AND NOT EXISTS (SELECT 1 FROM artifact_renditions r WHERE r.rendition_artifact_id=m.artifact_id)
|
|
464
|
+
ORDER BY m.created_ms, m.artifact_id LIMIT ?`)
|
|
465
|
+
.all(taskId, Date.now(), Math.max(1, Math.min(limit, 500))).map(raw => this.#v10(this.#record(raw)));
|
|
155
466
|
}
|
|
156
|
-
/** The newest current manifest for a digest. */
|
|
467
|
+
/** The newest current manifest for a digest, as 1.0. */
|
|
157
468
|
manifest(sha256) {
|
|
469
|
+
const record = this.#newest(sha256);
|
|
470
|
+
return record ? this.#v10(record) : undefined;
|
|
471
|
+
}
|
|
472
|
+
/** The newest current manifest for a digest, as 1.1 (for transfer-v2 consumers). */
|
|
473
|
+
manifestV2(sha256) {
|
|
474
|
+
const record = this.#newest(sha256);
|
|
475
|
+
return record ? { ...record, manifest: manifestV11(record.manifest) } : undefined;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Every current form of an artifact, the original first: given an original or
|
|
479
|
+
* any of its renditions, the same list. Undefined when the digest has no
|
|
480
|
+
* current manifest.
|
|
481
|
+
*/
|
|
482
|
+
async renditions(sha256) {
|
|
483
|
+
const record = this.manifestV2(sha256);
|
|
484
|
+
if (!record)
|
|
485
|
+
return undefined;
|
|
486
|
+
const ofSha = record.manifest.rendition && record.manifest.rendition.role !== 'original' ? record.manifest.rendition.of_sha256 : record.manifest.sha256;
|
|
487
|
+
const original = ofSha === record.manifest.sha256 ? record : this.manifestV2(ofSha);
|
|
488
|
+
const list = [];
|
|
489
|
+
if (original) {
|
|
490
|
+
let dimensions;
|
|
491
|
+
if (original.manifest.mime === 'image/png') {
|
|
492
|
+
try {
|
|
493
|
+
const head = await this.artifacts.openRead(original.manifest.sha256, { start: 0, end: Math.min(31, original.manifest.size - 1) });
|
|
494
|
+
const chunks = [];
|
|
495
|
+
for await (const chunk of head.stream)
|
|
496
|
+
chunks.push(z.instanceof(Buffer).parse(chunk));
|
|
497
|
+
dimensions = pngInfo(Buffer.concat(chunks));
|
|
498
|
+
}
|
|
499
|
+
catch {
|
|
500
|
+
dimensions = undefined;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
list.push(ArtifactRenditionSchema.parse({ sha256: original.manifest.sha256, role: 'original', mime: original.manifest.mime,
|
|
504
|
+
size: original.manifest.size, purpose: 'download', ...(dimensions ?? {}) }));
|
|
505
|
+
}
|
|
506
|
+
const rows = this.store.db.prepare(`SELECT r.rendition_sha256 AS sha256, r.role, r.purpose, m.mime, m.size, r.width, r.height, r.has_alpha
|
|
507
|
+
FROM artifact_renditions r JOIN artifact_manifests m ON m.artifact_id=r.rendition_artifact_id
|
|
508
|
+
WHERE r.original_sha256=? AND m.expires_ms>? ORDER BY r.created_ms, r.rendition_sha256`).all(ofSha, Date.now());
|
|
509
|
+
for (const raw of rows) {
|
|
510
|
+
const row = RenditionRow.parse(raw);
|
|
511
|
+
list.push(ArtifactRenditionSchema.parse({ sha256: row.sha256, role: row.role, mime: row.mime, size: row.size, purpose: row.purpose,
|
|
512
|
+
...(row.width === null ? {} : { width: row.width }), ...(row.height === null ? {} : { height: row.height }),
|
|
513
|
+
...(row.has_alpha === null ? {} : { has_alpha: row.has_alpha === 1 }) }));
|
|
514
|
+
}
|
|
515
|
+
return list;
|
|
516
|
+
}
|
|
517
|
+
#select = `SELECT m.artifact_id, m.task_id, m.sha256, m.manifest_json,
|
|
518
|
+
(SELECT n.sha256 FROM artifact_manifests n WHERE n.supersedes_sha256=m.sha256 ORDER BY n.created_ms DESC LIMIT 1) AS superseded_by
|
|
519
|
+
FROM artifact_manifests m`;
|
|
520
|
+
#newest(sha256) {
|
|
158
521
|
if (!digest.safeParse(sha256).success)
|
|
159
522
|
return undefined;
|
|
160
523
|
const raw = this.store.db.prepare(`${this.#select} WHERE m.sha256=? AND m.expires_ms>? ORDER BY m.created_ms DESC, m.artifact_id DESC LIMIT 1`)
|
|
161
524
|
.get(sha256, Date.now());
|
|
162
525
|
return raw ? this.#record(raw) : undefined;
|
|
163
526
|
}
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
527
|
+
#byId(id) {
|
|
528
|
+
const raw = this.store.db.prepare(`${this.#select} WHERE m.artifact_id=?`).get(id);
|
|
529
|
+
if (!raw)
|
|
530
|
+
return undefined;
|
|
531
|
+
const record = this.#record(raw);
|
|
532
|
+
return { ...record, manifest: manifestV11(record.manifest) };
|
|
533
|
+
}
|
|
167
534
|
#record(raw) {
|
|
168
535
|
const row = Row.parse(raw);
|
|
169
536
|
return { task_id: row.task_id, superseded_by_sha256: row.superseded_by,
|
|
170
|
-
manifest:
|
|
537
|
+
manifest: StoredManifest.parse(JSON.parse(row.manifest_json)) };
|
|
538
|
+
}
|
|
539
|
+
#v10(record) {
|
|
540
|
+
return { ...record, manifest: manifestV10(record.manifest) };
|
|
541
|
+
}
|
|
542
|
+
#baseManifest(stored, mime, created, ttlSeconds) {
|
|
543
|
+
return { revision: 1, source_revision: stored.sha256, visibility: 'private', license: 'NOASSERTION',
|
|
544
|
+
preview: { mode: mime === 'application/pdf' || ARTIFACT_MIME_TYPES[mime] === 'docx' ? 'download_only' : 'inline', mime },
|
|
545
|
+
supersedes_sha256: null, acceptance_status: 'unreviewed', name: stored.name, mime, sha256: stored.sha256, size: stored.bytes,
|
|
546
|
+
created_at: created / 1000, expires_at: ttlSeconds ? created / 1000 + ttlSeconds : NO_EXPIRY_SECONDS,
|
|
547
|
+
recovery: { on_expiry: 'request_verified_reexport' }, artifact_id: randomBytes(16).toString('hex') };
|
|
548
|
+
}
|
|
549
|
+
async #putStream(stream, name, mime, options) {
|
|
550
|
+
try {
|
|
551
|
+
return await this.artifacts.putStream(stream, { name, mediaType: mime, expectedSha256: options.expectedSha256,
|
|
552
|
+
expectedSize: options.expectedSize, inspect: artifactContentInspector(mime), signal: options.signal });
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
throw storeRefusal(error);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
/** Insert a manifest and journal it on its task. Call inside a transaction. */
|
|
559
|
+
#insert(taskId, manifest, created, kind = 'artifact_registered', idempotencyKey) {
|
|
560
|
+
this.store.db.prepare(`INSERT INTO artifact_manifests(artifact_id,task_id,sha256,name,mime,size,revision,supersedes_sha256,manifest_json,created_ms,expires_ms,idempotency_key)
|
|
561
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)`).run(manifest.artifact_id, taskId, manifest.sha256, manifest.name, manifest.mime, manifest.size, manifest.revision, manifest.supersedes_sha256, JSON.stringify(manifest), created, Math.floor(manifest.expires_at * 1000), idempotencyKey ?? null);
|
|
562
|
+
this.store.append(taskId, kind, { artifact_id: manifest.artifact_id, name: manifest.name, mime: manifest.mime,
|
|
563
|
+
sha256: manifest.sha256, size: manifest.size, revision: manifest.revision, supersedes_sha256: manifest.supersedes_sha256, manifest });
|
|
171
564
|
}
|
|
172
565
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type AgentCard } from '@a2a-js/sdk';
|
|
3
|
+
import type { RetryPolicy } from '@hivemagnus/hive-common/retry';
|
|
4
|
+
import { type AttemptFailure } from './retry.js';
|
|
5
|
+
import type { ArdentRuntime } from './runtime.js';
|
|
6
|
+
export declare const ArtifactImportStateSchema: z.ZodEnum<{
|
|
7
|
+
queued: "queued";
|
|
8
|
+
failed: "failed";
|
|
9
|
+
completed: "completed";
|
|
10
|
+
transferring: "transferring";
|
|
11
|
+
verifying: "verifying";
|
|
12
|
+
}>;
|
|
13
|
+
export type ArtifactImportState = z.infer<typeof ArtifactImportStateSchema>;
|
|
14
|
+
/** Ask this profile to pull one artifact a peer exported from one of its A2A tasks. */
|
|
15
|
+
export declare const ArtifactImportRequestSchema: z.ZodObject<{
|
|
16
|
+
peer_id: z.ZodString;
|
|
17
|
+
a2a_task_id: z.ZodString;
|
|
18
|
+
artifact_id: z.ZodString;
|
|
19
|
+
task_id: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
export type ArtifactImportRequest = z.infer<typeof ArtifactImportRequestSchema>;
|
|
22
|
+
export declare const ArtifactImportSchema: z.ZodObject<{
|
|
23
|
+
import_id: z.ZodString;
|
|
24
|
+
peer_id: z.ZodString;
|
|
25
|
+
a2a_task_id: z.ZodString;
|
|
26
|
+
artifact_id: z.ZodString;
|
|
27
|
+
state: z.ZodEnum<{
|
|
28
|
+
queued: "queued";
|
|
29
|
+
failed: "failed";
|
|
30
|
+
completed: "completed";
|
|
31
|
+
transferring: "transferring";
|
|
32
|
+
verifying: "verifying";
|
|
33
|
+
}>;
|
|
34
|
+
received_bytes: z.ZodNumber;
|
|
35
|
+
size: z.ZodNullable<z.ZodNumber>;
|
|
36
|
+
sha256: z.ZodNullable<z.ZodString>;
|
|
37
|
+
mime: z.ZodNullable<z.ZodString>;
|
|
38
|
+
name: z.ZodNullable<z.ZodString>;
|
|
39
|
+
protocol: z.ZodNullable<z.ZodEnum<{
|
|
40
|
+
v2: "v2";
|
|
41
|
+
v1: "v1";
|
|
42
|
+
}>>;
|
|
43
|
+
attempts: z.ZodNumber;
|
|
44
|
+
local_task_id: z.ZodNullable<z.ZodString>;
|
|
45
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
46
|
+
code: z.ZodString;
|
|
47
|
+
message: z.ZodString;
|
|
48
|
+
}, z.core.$strict>>;
|
|
49
|
+
created_ms: z.ZodNumber;
|
|
50
|
+
updated_ms: z.ZodNumber;
|
|
51
|
+
}, z.core.$strict>;
|
|
52
|
+
export type ArtifactImport = z.infer<typeof ArtifactImportSchema>;
|
|
53
|
+
/** A transfer outcome. `retryable` failures are transport problems a resumed attempt may get past. */
|
|
54
|
+
export declare class ArtifactTransferError extends Error {
|
|
55
|
+
readonly code: string;
|
|
56
|
+
/** What a retryable failure tells the retry policy (a transport error unless a response said otherwise). */
|
|
57
|
+
readonly failure: AttemptFailure | undefined;
|
|
58
|
+
constructor(message: string, code: string, retryable?: boolean | AttemptFailure);
|
|
59
|
+
get retryable(): boolean;
|
|
60
|
+
}
|
|
61
|
+
export type ArtifactTransferOptions = {
|
|
62
|
+
fetch?: typeof fetch;
|
|
63
|
+
/** Commit `received_bytes` (after an fsync) at least this often. Default 4 MiB. */
|
|
64
|
+
commitBytes?: number;
|
|
65
|
+
/** Abort a response that delivers no byte for this long. Default 60 s. */
|
|
66
|
+
idleTimeoutMs?: number;
|
|
67
|
+
/** Total time one run may spend retrying transport failures. Default 30 min. */
|
|
68
|
+
deadlineMs?: number;
|
|
69
|
+
/** Defaults to the named `artifact_transfer` policy in `src/retry.ts`. */
|
|
70
|
+
retryPolicy?: RetryPolicy;
|
|
71
|
+
/** Observe progress, for example to report it. Never called with more than `size`. */
|
|
72
|
+
onProgress?: (progress: {
|
|
73
|
+
import_id: string;
|
|
74
|
+
received_bytes: number;
|
|
75
|
+
size: number;
|
|
76
|
+
}) => void;
|
|
77
|
+
};
|
|
78
|
+
/** The transfer-v2 parameters a peer card advertises, or undefined. */
|
|
79
|
+
export declare function peerTransferV2(card: AgentCard): {
|
|
80
|
+
max_bytes?: number;
|
|
81
|
+
} | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Resumable pulls of peer artifacts (transfer v2, with the v1 path for older
|
|
84
|
+
* peers up to 2 MiB). Progress lives in `artifact_transfers` and a partial file
|
|
85
|
+
* under `<profile>/artifacts/.partial/<import id>`; a restart re-hashes the
|
|
86
|
+
* retained bytes as a stream and asks the peer for the rest with Range and
|
|
87
|
+
* If-Range. The finished file is verified, renamed into the content store and
|
|
88
|
+
* registered with a manifest 1.1 that records the peer hop.
|
|
89
|
+
*/
|
|
90
|
+
export declare class ArtifactTransfers {
|
|
91
|
+
#private;
|
|
92
|
+
readonly runtime: ArdentRuntime;
|
|
93
|
+
readonly env: NodeJS.ProcessEnv;
|
|
94
|
+
readonly options: ArtifactTransferOptions;
|
|
95
|
+
constructor(runtime: ArdentRuntime, env?: NodeJS.ProcessEnv, options?: ArtifactTransferOptions);
|
|
96
|
+
/**
|
|
97
|
+
* Record an import, or return the existing one for the same peer, task and
|
|
98
|
+
* artifact. A failed import is queued again from what it retained: that is
|
|
99
|
+
* the operator's explicit reissue.
|
|
100
|
+
*/
|
|
101
|
+
request(input: ArtifactImportRequest, caller?: string): ArtifactImport;
|
|
102
|
+
/** Record an import and run it in the background. */
|
|
103
|
+
start(input: ArtifactImportRequest, caller?: string): ArtifactImport;
|
|
104
|
+
/** Resume every import a previous process left unfinished. */
|
|
105
|
+
resumePending(): string[];
|
|
106
|
+
get(id: string): ArtifactImport | undefined;
|
|
107
|
+
list(limit?: number): ArtifactImport[];
|
|
108
|
+
/**
|
|
109
|
+
* Run (or resume) an import to its outcome. An abort leaves it resumable.
|
|
110
|
+
* Concurrent calls for one import share a single run.
|
|
111
|
+
*/
|
|
112
|
+
run(id: string, signal?: AbortSignal): Promise<ArtifactImport>;
|
|
113
|
+
}
|