@hivemagnus/ardent 3.1.4 → 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 +475 -4
- 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/store.d.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import Database from './sqlite.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { CatchupJournal } from './channel-catchup.js';
|
|
4
|
+
import { TaskExecutions, type ExecutionContext, type TaskExecution } from './execution.js';
|
|
5
|
+
import { ExecutionStates } from './execution-state.js';
|
|
6
|
+
import { type RecoveryPlanOptions } from './recovery.js';
|
|
3
7
|
export declare const TaskState: z.ZodEnum<{
|
|
4
8
|
unknown: "unknown";
|
|
5
9
|
queued: "queued";
|
|
6
10
|
failed: "failed";
|
|
7
11
|
completed: "completed";
|
|
12
|
+
cancelled: "cancelled";
|
|
8
13
|
running: "running";
|
|
9
14
|
input_required: "input_required";
|
|
10
15
|
partial: "partial";
|
|
11
|
-
cancelled: "cancelled";
|
|
12
16
|
}>;
|
|
13
17
|
export type TaskState = z.infer<typeof TaskState>;
|
|
14
18
|
/** Execution scope of a task. It selects tools and memory; a session belongs to exactly one context. */
|
|
15
19
|
export declare const TaskContext: z.ZodEnum<{
|
|
20
|
+
mission: "mission";
|
|
16
21
|
direct: "direct";
|
|
17
22
|
peer: "peer";
|
|
18
23
|
scheduled: "scheduled";
|
|
19
|
-
mission: "mission";
|
|
20
24
|
preview: "preview";
|
|
21
25
|
}>;
|
|
22
26
|
export type TaskContext = z.infer<typeof TaskContext>;
|
|
@@ -24,10 +28,10 @@ export declare const TaskSchema: z.ZodObject<{
|
|
|
24
28
|
id: z.ZodString;
|
|
25
29
|
caller: z.ZodString;
|
|
26
30
|
context: z.ZodEnum<{
|
|
31
|
+
mission: "mission";
|
|
27
32
|
direct: "direct";
|
|
28
33
|
peer: "peer";
|
|
29
34
|
scheduled: "scheduled";
|
|
30
|
-
mission: "mission";
|
|
31
35
|
preview: "preview";
|
|
32
36
|
}>;
|
|
33
37
|
session_id: z.ZodNullable<z.ZodString>;
|
|
@@ -43,10 +47,10 @@ export declare const TaskSchema: z.ZodObject<{
|
|
|
43
47
|
queued: "queued";
|
|
44
48
|
failed: "failed";
|
|
45
49
|
completed: "completed";
|
|
50
|
+
cancelled: "cancelled";
|
|
46
51
|
running: "running";
|
|
47
52
|
input_required: "input_required";
|
|
48
53
|
partial: "partial";
|
|
49
|
-
cancelled: "cancelled";
|
|
50
54
|
}>;
|
|
51
55
|
result: z.ZodNullable<z.ZodString>;
|
|
52
56
|
error: z.ZodNullable<z.ZodString>;
|
|
@@ -59,10 +63,10 @@ export declare const SessionSchema: z.ZodObject<{
|
|
|
59
63
|
id: z.ZodString;
|
|
60
64
|
caller: z.ZodString;
|
|
61
65
|
context: z.ZodEnum<{
|
|
66
|
+
mission: "mission";
|
|
62
67
|
direct: "direct";
|
|
63
68
|
peer: "peer";
|
|
64
69
|
scheduled: "scheduled";
|
|
65
|
-
mission: "mission";
|
|
66
70
|
preview: "preview";
|
|
67
71
|
}>;
|
|
68
72
|
key: z.ZodString;
|
|
@@ -92,9 +96,19 @@ export declare const EventSchema: z.ZodObject<{
|
|
|
92
96
|
export type TaskEvent = z.infer<typeof EventSchema>;
|
|
93
97
|
/** Historical transport labels remain distinct; adapters must retain their original identity. */
|
|
94
98
|
export type InboundChannelType = 'unknown' | 'telegram_private' | 'telegram_group' | 'telegram_supergroup' | 'mattermost_dm' | 'mattermost_channel' | 'chattermost_dm' | 'chattermost_channel';
|
|
99
|
+
/** How a claimed inbound post was settled: admitted to the normal channel path, or claimed by catch-up as too old to answer. */
|
|
100
|
+
export type InboundDisposition = 'admitted' | 'skipped_stale';
|
|
95
101
|
export declare class TaskStore {
|
|
96
102
|
readonly db: Database;
|
|
103
|
+
readonly catchup: CatchupJournal;
|
|
104
|
+
/** Execution ancestry (attribution only; never read for tool, memory or mission scope). */
|
|
105
|
+
readonly executions: TaskExecutions;
|
|
106
|
+
/** Execution checkpoints, tool invocations and recovery status (`execution-state.ts`). */
|
|
107
|
+
readonly executionState: ExecutionStates;
|
|
97
108
|
constructor(path: string);
|
|
109
|
+
parseTask(row: unknown): Task;
|
|
110
|
+
/** The execution context a task was accepted with, if it has one (attribution only). */
|
|
111
|
+
executionFor(taskId: string): ExecutionContext | undefined;
|
|
98
112
|
close(): void;
|
|
99
113
|
admissionFence(): {
|
|
100
114
|
release_id: string;
|
|
@@ -117,6 +131,10 @@ export declare class TaskStore {
|
|
|
117
131
|
* Record a new task, or return the task already accepted for the same idempotency key.
|
|
118
132
|
* `content` adds structured input (a mission, context items) to the idempotency digest;
|
|
119
133
|
* `onAccepted` journals it in the same transaction, only for a newly accepted task.
|
|
134
|
+
* `execution` builds the task's execution context; it is recorded in
|
|
135
|
+
* `task_execution` and in the `accepted` event, and never enters the digest.
|
|
136
|
+
* `suppressSessionUserMessage` keeps the prompt out of the session, for a
|
|
137
|
+
* recovery continuation whose prompt the session already holds.
|
|
120
138
|
*/
|
|
121
139
|
accept(input: {
|
|
122
140
|
caller: string;
|
|
@@ -128,13 +146,15 @@ export declare class TaskStore {
|
|
|
128
146
|
deadlineMs: number;
|
|
129
147
|
content?: unknown;
|
|
130
148
|
onAccepted?: (task: Task) => void;
|
|
149
|
+
execution?: (task: Task) => TaskExecution;
|
|
150
|
+
suppressSessionUserMessage?: boolean;
|
|
131
151
|
}): Task;
|
|
132
152
|
appendAssistant(task: Task, content: string): void;
|
|
133
153
|
/** Settle a task with its result. The session records `sessionContent`, the conversational form of the result. */
|
|
134
154
|
finishWithAssistant(id: string, state: 'completed' | 'partial', content: string, sessionContent?: string): void;
|
|
135
155
|
latestSessionTask(sessionId: string, caller: string): Task | undefined;
|
|
136
156
|
hasInbound(platform: string, account: string, updateId: string): boolean;
|
|
137
|
-
claimInbound(platform: string, account: string, updateId: string, channelType?: InboundChannelType): {
|
|
157
|
+
claimInbound(platform: string, account: string, updateId: string, channelType?: InboundChannelType, disposition?: InboundDisposition, replyTarget?: unknown): {
|
|
138
158
|
claimed: boolean;
|
|
139
159
|
taskId: string | null;
|
|
140
160
|
};
|
|
@@ -150,6 +170,17 @@ export declare class TaskStore {
|
|
|
150
170
|
externalId: string | null;
|
|
151
171
|
} | undefined;
|
|
152
172
|
queueDelivery(platform: string, account: string, updateId: string, taskId: string | null): string;
|
|
173
|
+
/**
|
|
174
|
+
* Record a delivery before it is sent, only if none exists for the update.
|
|
175
|
+
* `created` is false when a delivery (queued, sent, failed or unknown) was
|
|
176
|
+
* already recorded: the caller must not send again.
|
|
177
|
+
*/
|
|
178
|
+
claimDelivery(platform: string, account: string, updateId: string, taskId: string | null): {
|
|
179
|
+
id: string;
|
|
180
|
+
created: boolean;
|
|
181
|
+
};
|
|
182
|
+
/** Provider requests a channel delivery made, retries included. */
|
|
183
|
+
recordDeliveryAttempts(platform: string, account: string, updateId: string, attempts: number): void;
|
|
153
184
|
setDelivery(id: string, state: 'sent' | 'failed' | 'unknown', externalId?: string | null, error?: string | null): void;
|
|
154
185
|
/** Whether an operator paused the task. A paused task waits at its next step boundary. */
|
|
155
186
|
taskAdmission(id: string): 'open' | 'paused';
|
|
@@ -164,10 +195,34 @@ export declare class TaskStore {
|
|
|
164
195
|
listByCaller(caller: string, limit?: number): Task[];
|
|
165
196
|
setState(id: string, state: TaskState, result?: string | null, error?: string | null): void;
|
|
166
197
|
startQueued(id: string): void;
|
|
198
|
+
/**
|
|
199
|
+
* Record a failed plugin lifecycle hook: a `plugin_hook_failed` task event,
|
|
200
|
+
* or, for a channel message that has no task, a row keyed by the message.
|
|
201
|
+
*/
|
|
202
|
+
recordPluginHookFailure(plugin: string, hook: string, target: {
|
|
203
|
+
taskId: string;
|
|
204
|
+
} | {
|
|
205
|
+
platform: string;
|
|
206
|
+
account: string;
|
|
207
|
+
updateId: string;
|
|
208
|
+
}): void;
|
|
209
|
+
/** Hook failures recorded for a channel message that had no task. */
|
|
210
|
+
pluginHookFailures(platform: string, account: string, updateId: string): {
|
|
211
|
+
plugin: string;
|
|
212
|
+
hook: string;
|
|
213
|
+
}[];
|
|
167
214
|
append(id: string, kind: string, detail: unknown): void;
|
|
168
215
|
events(id: string, after?: number, limit?: number): TaskEvent[];
|
|
169
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Startup recovery, before any queued work is admitted. Each `running` task
|
|
218
|
+
* is planned by the execution recovery rules (`recovery.ts`): resumed under
|
|
219
|
+
* the same id (it stays `running`), settled, or held as `unknown`. A queued
|
|
220
|
+
* channel delivery's send outcome is uncertain, so it becomes `unknown`.
|
|
221
|
+
*/
|
|
222
|
+
recover(options?: RecoveryPlanOptions): {
|
|
170
223
|
queued: Task[];
|
|
171
224
|
interrupted: number;
|
|
225
|
+
resumed: string[];
|
|
226
|
+
held: string[];
|
|
172
227
|
};
|
|
173
228
|
}
|
package/dist/store.js
CHANGED
|
@@ -3,6 +3,10 @@ import { mkdirSync } from 'node:fs';
|
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
import Database from './sqlite.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import { CatchupJournal } from './channel-catchup.js';
|
|
7
|
+
import { TaskExecutions } from './execution.js';
|
|
8
|
+
import { ExecutionStates } from './execution-state.js';
|
|
9
|
+
import { planRecovery } from './recovery.js';
|
|
6
10
|
export const TaskState = z.enum(['queued', 'running', 'input_required', 'completed', 'partial', 'failed', 'cancelled', 'unknown']);
|
|
7
11
|
/** Execution scope of a task. It selects tools and memory; a session belongs to exactly one context. */
|
|
8
12
|
export const TaskContext = z.enum(['direct', 'peer', 'scheduled', 'mission', 'preview']);
|
|
@@ -12,6 +16,11 @@ export const SessionMessageSchema = z.object({ sequence: z.number().int(), sessi
|
|
|
12
16
|
export const EventSchema = z.object({ sequence: z.number().int(), task_id: z.string(), kind: z.string(), detail: z.unknown().optional(), created_ms: z.number().int() });
|
|
13
17
|
export class TaskStore {
|
|
14
18
|
db;
|
|
19
|
+
catchup;
|
|
20
|
+
/** Execution ancestry (attribution only; never read for tool, memory or mission scope). */
|
|
21
|
+
executions;
|
|
22
|
+
/** Execution checkpoints, tool invocations and recovery status (`execution-state.ts`). */
|
|
23
|
+
executionState;
|
|
15
24
|
constructor(path) {
|
|
16
25
|
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
17
26
|
this.db = new Database(path);
|
|
@@ -73,7 +82,10 @@ export class TaskStore {
|
|
|
73
82
|
CREATE INDEX IF NOT EXISTS context_attempts_session ON context_compaction_attempts(session_id,created_ms);
|
|
74
83
|
CREATE TABLE IF NOT EXISTS task_admission (
|
|
75
84
|
task_id TEXT PRIMARY KEY REFERENCES tasks(id), admission TEXT NOT NULL CHECK(admission IN ('open','paused')),
|
|
76
|
-
updated_ms INTEGER NOT NULL)
|
|
85
|
+
updated_ms INTEGER NOT NULL);
|
|
86
|
+
CREATE TABLE IF NOT EXISTS plugin_hook_failures (
|
|
87
|
+
sequence INTEGER PRIMARY KEY AUTOINCREMENT, plugin TEXT NOT NULL, hook TEXT NOT NULL,
|
|
88
|
+
platform TEXT NOT NULL, account TEXT NOT NULL, update_id TEXT NOT NULL, created_ms INTEGER NOT NULL);`);
|
|
77
89
|
const columns = z.array(z.object({ name: z.string() })).parse(this.db.pragma('table_info(tasks)'));
|
|
78
90
|
if (!columns.some(column => column.name === 'session_id'))
|
|
79
91
|
this.db.exec('ALTER TABLE tasks ADD COLUMN session_id TEXT');
|
|
@@ -82,12 +94,22 @@ export class TaskStore {
|
|
|
82
94
|
this.db.exec(`CREATE INDEX IF NOT EXISTS tasks_caller_created ON tasks(caller, created_ms);
|
|
83
95
|
CREATE INDEX IF NOT EXISTS tasks_session_created ON tasks(session_id, created_ms);
|
|
84
96
|
CREATE INDEX IF NOT EXISTS tasks_state ON tasks(state);`);
|
|
97
|
+
const deliveryColumns = z.array(z.object({ name: z.string() })).parse(this.db.pragma('table_info(channel_deliveries)'));
|
|
98
|
+
if (!deliveryColumns.some(column => column.name === 'attempts'))
|
|
99
|
+
this.db.exec('ALTER TABLE channel_deliveries ADD COLUMN attempts INTEGER');
|
|
85
100
|
const inboundColumns = z.array(z.object({ name: z.string() })).parse(this.db.pragma('table_info(channel_inbound)'));
|
|
86
101
|
if (!inboundColumns.some(column => column.name === 'channel_type'))
|
|
87
102
|
this.db.exec(`ALTER TABLE channel_inbound ADD COLUMN
|
|
88
103
|
channel_type TEXT NOT NULL DEFAULT 'unknown' CHECK(channel_type IN
|
|
89
104
|
('unknown','telegram_private','telegram_group','telegram_supergroup',
|
|
90
105
|
'mattermost_dm','mattermost_channel','chattermost_dm','chattermost_channel'))`);
|
|
106
|
+
if (!inboundColumns.some(column => column.name === 'disposition'))
|
|
107
|
+
this.db.exec(`ALTER TABLE channel_inbound ADD COLUMN
|
|
108
|
+
disposition TEXT NOT NULL DEFAULT 'admitted' CHECK(disposition IN ('admitted','skipped_stale'))`);
|
|
109
|
+
// Where a reply goes (conversation, thread, the message replied to), so a
|
|
110
|
+
// task that execution recovery resumes or continues can still answer it.
|
|
111
|
+
if (!inboundColumns.some(column => column.name === 'reply_target_json'))
|
|
112
|
+
this.db.exec('ALTER TABLE channel_inbound ADD COLUMN reply_target_json TEXT');
|
|
91
113
|
this.db.exec(`CREATE TRIGGER IF NOT EXISTS channel_inbound_type_immutable
|
|
92
114
|
BEFORE UPDATE OF channel_type ON channel_inbound
|
|
93
115
|
WHEN OLD.channel_type != NEW.channel_type
|
|
@@ -96,7 +118,13 @@ export class TaskStore {
|
|
|
96
118
|
BEFORE UPDATE ON session_messages BEGIN SELECT RAISE(ABORT, 'Session messages are immutable'); END;
|
|
97
119
|
CREATE TRIGGER IF NOT EXISTS session_messages_immutable_delete
|
|
98
120
|
BEFORE DELETE ON session_messages BEGIN SELECT RAISE(ABORT, 'Session messages are immutable'); END;`);
|
|
121
|
+
this.catchup = new CatchupJournal(this.db);
|
|
122
|
+
this.executions = new TaskExecutions(this.db);
|
|
123
|
+
this.executionState = new ExecutionStates(this.db);
|
|
99
124
|
}
|
|
125
|
+
parseTask(row) { return TaskSchema.parse(row); }
|
|
126
|
+
/** The execution context a task was accepted with, if it has one (attribution only). */
|
|
127
|
+
executionFor(taskId) { return this.executions.get(taskId)?.context; }
|
|
100
128
|
close() { this.db.close(); }
|
|
101
129
|
admissionFence() {
|
|
102
130
|
const row = this.db.prepare('SELECT release_id,closed_ms FROM admission_fence WHERE singleton=1').get();
|
|
@@ -120,7 +148,7 @@ export class TaskStore {
|
|
|
120
148
|
inbound_unbound: count(`SELECT count(*) AS count FROM channel_inbound AS inbound
|
|
121
149
|
LEFT JOIN channel_deliveries AS delivery ON delivery.platform=inbound.platform
|
|
122
150
|
AND delivery.account=inbound.account AND delivery.update_id=inbound.update_id
|
|
123
|
-
WHERE inbound.task_id IS NULL AND (delivery.id IS NULL OR delivery.state IN ('queued','unknown'))`) };
|
|
151
|
+
WHERE inbound.task_id IS NULL AND inbound.disposition='admitted' AND (delivery.id IS NULL OR delivery.state IN ('queued','unknown'))`) };
|
|
124
152
|
})();
|
|
125
153
|
}
|
|
126
154
|
session(caller, context, key) {
|
|
@@ -157,6 +185,10 @@ export class TaskStore {
|
|
|
157
185
|
* Record a new task, or return the task already accepted for the same idempotency key.
|
|
158
186
|
* `content` adds structured input (a mission, context items) to the idempotency digest;
|
|
159
187
|
* `onAccepted` journals it in the same transaction, only for a newly accepted task.
|
|
188
|
+
* `execution` builds the task's execution context; it is recorded in
|
|
189
|
+
* `task_execution` and in the `accepted` event, and never enters the digest.
|
|
190
|
+
* `suppressSessionUserMessage` keeps the prompt out of the session, for a
|
|
191
|
+
* recovery continuation whose prompt the session already holds.
|
|
160
192
|
*/
|
|
161
193
|
accept(input) {
|
|
162
194
|
if (!input.caller || input.caller.length > 128 || !input.prompt.trim() || input.prompt.length > 16000 || (input.idempotencyKey && input.idempotencyKey.length > 128))
|
|
@@ -186,9 +218,12 @@ export class TaskStore {
|
|
|
186
218
|
const task = { id: randomUUID(), caller: input.caller, context: input.context, session_id: input.sessionId ?? null, prompt: input.prompt, content_hash: hash, idempotency_key: input.idempotencyKey ?? null, backend: input.backend, state: 'queued', result: null, error: null, deadline_ms: input.deadlineMs, created_ms: now, updated_ms: now };
|
|
187
219
|
this.db.prepare(`INSERT INTO tasks (id,caller,context,session_id,prompt,content_hash,idempotency_key,backend,state,result,error,deadline_ms,created_ms,updated_ms)
|
|
188
220
|
VALUES (@id,@caller,@context,@session_id,@prompt,@content_hash,@idempotency_key,@backend,@state,@result,@error,@deadline_ms,@created_ms,@updated_ms)`).run(task);
|
|
189
|
-
if (task.session_id)
|
|
221
|
+
if (task.session_id && !input.suppressSessionUserMessage)
|
|
190
222
|
this.db.prepare('INSERT INTO session_messages(session_id,task_id,role,content,created_ms) VALUES (?,?,?,?,?)').run(task.session_id, task.id, 'user', task.prompt, now);
|
|
191
|
-
|
|
223
|
+
const execution = input.execution?.(task);
|
|
224
|
+
if (execution)
|
|
225
|
+
this.executions.insert(execution);
|
|
226
|
+
this.append(task.id, 'accepted', { caller: input.caller, context: input.context, backend: input.backend, ...(execution ? { execution: execution.context } : {}) });
|
|
192
227
|
input.onAccepted?.(task);
|
|
193
228
|
return task;
|
|
194
229
|
})();
|
|
@@ -225,7 +260,7 @@ export class TaskStore {
|
|
|
225
260
|
return this.db.prepare('SELECT 1 FROM channel_inbound WHERE platform=? AND account=? AND update_id=?')
|
|
226
261
|
.get(platform, account, updateId) !== undefined;
|
|
227
262
|
}
|
|
228
|
-
claimInbound(platform, account, updateId, channelType = 'unknown') {
|
|
263
|
+
claimInbound(platform, account, updateId, channelType = 'unknown', disposition = 'admitted', replyTarget) {
|
|
229
264
|
if (!platform || !account || !updateId || updateId.length > 256)
|
|
230
265
|
throw new Error('Invalid channel update identity');
|
|
231
266
|
if ((platform === 'telegram' && (channelType.startsWith('mattermost_') || channelType.startsWith('chattermost_'))) ||
|
|
@@ -245,8 +280,8 @@ export class TaskStore {
|
|
|
245
280
|
return { claimed: false, taskId: prior.task_id };
|
|
246
281
|
}
|
|
247
282
|
this.db.prepare(`INSERT INTO channel_inbound
|
|
248
|
-
(platform,account,update_id,task_id,created_ms,channel_type) VALUES (
|
|
249
|
-
.run(platform, account, updateId, null, Date.now(), channelType);
|
|
283
|
+
(platform,account,update_id,task_id,created_ms,channel_type,disposition,reply_target_json) VALUES (?,?,?,?,?,?,?,?)`)
|
|
284
|
+
.run(platform, account, updateId, null, Date.now(), channelType, disposition, replyTarget === undefined ? null : JSON.stringify(replyTarget));
|
|
250
285
|
return { claimed: true, taskId: null };
|
|
251
286
|
})();
|
|
252
287
|
}
|
|
@@ -276,6 +311,21 @@ export class TaskStore {
|
|
|
276
311
|
this.db.prepare('INSERT OR IGNORE INTO channel_deliveries(id,platform,account,update_id,task_id,state,external_id,error,created_ms,updated_ms) VALUES (?,?,?,?,?,?,?,?,?,?)').run(id, platform, account, updateId, taskId, 'queued', null, null, Date.now(), Date.now());
|
|
277
312
|
return this.delivery(platform, account, updateId)?.id ?? id;
|
|
278
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Record a delivery before it is sent, only if none exists for the update.
|
|
316
|
+
* `created` is false when a delivery (queued, sent, failed or unknown) was
|
|
317
|
+
* already recorded: the caller must not send again.
|
|
318
|
+
*/
|
|
319
|
+
claimDelivery(platform, account, updateId, taskId) {
|
|
320
|
+
const id = randomUUID();
|
|
321
|
+
const result = this.db.prepare('INSERT OR IGNORE INTO channel_deliveries(id,platform,account,update_id,task_id,state,external_id,error,created_ms,updated_ms) VALUES (?,?,?,?,?,?,?,?,?,?)')
|
|
322
|
+
.run(id, platform, account, updateId, taskId, 'queued', null, null, Date.now(), Date.now());
|
|
323
|
+
return { id: result.changes === 1 ? id : this.delivery(platform, account, updateId)?.id ?? id, created: result.changes === 1 };
|
|
324
|
+
}
|
|
325
|
+
/** Provider requests a channel delivery made, retries included. */
|
|
326
|
+
recordDeliveryAttempts(platform, account, updateId, attempts) {
|
|
327
|
+
this.db.prepare('UPDATE channel_deliveries SET attempts=? WHERE platform=? AND account=? AND update_id=?').run(attempts, platform, account, updateId);
|
|
328
|
+
}
|
|
279
329
|
setDelivery(id, state, externalId = null, error = null) {
|
|
280
330
|
this.db.prepare('UPDATE channel_deliveries SET state=?,external_id=?,error=?,updated_ms=? WHERE id=?').run(state, externalId, error, Date.now(), id);
|
|
281
331
|
}
|
|
@@ -337,6 +387,23 @@ export class TaskStore {
|
|
|
337
387
|
this.append(id, 'state', { from: 'queued', to: 'running', error: null });
|
|
338
388
|
})();
|
|
339
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* Record a failed plugin lifecycle hook: a `plugin_hook_failed` task event,
|
|
392
|
+
* or, for a channel message that has no task, a row keyed by the message.
|
|
393
|
+
*/
|
|
394
|
+
recordPluginHookFailure(plugin, hook, target) {
|
|
395
|
+
if ('taskId' in target) {
|
|
396
|
+
this.append(target.taskId, 'plugin_hook_failed', { plugin, hook });
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
this.db.prepare('INSERT INTO plugin_hook_failures(plugin,hook,platform,account,update_id,created_ms) VALUES (?,?,?,?,?,?)')
|
|
400
|
+
.run(plugin, hook, target.platform, target.account, target.updateId, Date.now());
|
|
401
|
+
}
|
|
402
|
+
/** Hook failures recorded for a channel message that had no task. */
|
|
403
|
+
pluginHookFailures(platform, account, updateId) {
|
|
404
|
+
return this.db.prepare('SELECT plugin,hook FROM plugin_hook_failures WHERE platform=? AND account=? AND update_id=? ORDER BY sequence')
|
|
405
|
+
.all(platform, account, updateId).map(row => z.object({ plugin: z.string(), hook: z.string() }).parse(row));
|
|
406
|
+
}
|
|
340
407
|
append(id, kind, detail) {
|
|
341
408
|
this.db.prepare('INSERT INTO events(task_id,kind,detail_json,created_ms) VALUES (?,?,?,?)').run(id, kind, JSON.stringify(detail), Date.now());
|
|
342
409
|
}
|
|
@@ -347,13 +414,17 @@ export class TaskStore {
|
|
|
347
414
|
return EventSchema.parse({ sequence: value.sequence, task_id: value.task_id, kind: value.kind, detail: JSON.parse(value.detail_json), created_ms: value.created_ms });
|
|
348
415
|
});
|
|
349
416
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
417
|
+
/**
|
|
418
|
+
* Startup recovery, before any queued work is admitted. Each `running` task
|
|
419
|
+
* is planned by the execution recovery rules (`recovery.ts`): resumed under
|
|
420
|
+
* the same id (it stays `running`), settled, or held as `unknown`. A queued
|
|
421
|
+
* channel delivery's send outcome is uncertain, so it becomes `unknown`.
|
|
422
|
+
*/
|
|
423
|
+
recover(options = {}) {
|
|
424
|
+
const interrupted = z.object({ count: z.number().int() }).parse(this.db.prepare("SELECT count(*) AS count FROM tasks WHERE state='running'").get()).count;
|
|
425
|
+
const planned = planRecovery(this, options);
|
|
426
|
+
this.db.prepare("UPDATE channel_deliveries SET state='unknown',error='Process stopped during a queued delivery; send outcome is uncertain',updated_ms=? WHERE state='queued'").run(Date.now());
|
|
427
|
+
return { queued: this.db.prepare("SELECT * FROM tasks WHERE state='queued' ORDER BY created_ms").all().map(row => TaskSchema.parse(row)), interrupted,
|
|
428
|
+
resumed: planned.resumed, held: planned.held };
|
|
358
429
|
}
|
|
359
430
|
}
|
package/dist/team-artifacts.d.ts
CHANGED
|
@@ -1,100 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ArdentRuntime } from './runtime.js';
|
|
3
3
|
import type { ArdentConfig } from './config.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
source_revision: z.ZodString;
|
|
8
|
-
visibility: z.ZodEnum<{
|
|
9
|
-
private: "private";
|
|
10
|
-
gm: "gm";
|
|
11
|
-
player: "player";
|
|
12
|
-
}>;
|
|
13
|
-
license: z.ZodString;
|
|
14
|
-
preview: z.ZodObject<{
|
|
15
|
-
mode: z.ZodEnum<{
|
|
16
|
-
none: "none";
|
|
17
|
-
inline: "inline";
|
|
18
|
-
thumbnail: "thumbnail";
|
|
19
|
-
download_only: "download_only";
|
|
20
|
-
}>;
|
|
21
|
-
mime: z.ZodString;
|
|
22
|
-
}, z.core.$strict>;
|
|
23
|
-
supersedes_sha256: z.ZodNullable<z.ZodString>;
|
|
24
|
-
acceptance_status: z.ZodEnum<{
|
|
25
|
-
partial: "partial";
|
|
26
|
-
rejected: "rejected";
|
|
27
|
-
unreviewed: "unreviewed";
|
|
28
|
-
approved: "approved";
|
|
29
|
-
}>;
|
|
30
|
-
name: z.ZodString;
|
|
31
|
-
mime: z.ZodString;
|
|
32
|
-
sha256: z.ZodString;
|
|
33
|
-
size: z.ZodNumber;
|
|
34
|
-
created_at: z.ZodNumber;
|
|
35
|
-
expires_at: z.ZodNumber;
|
|
36
|
-
provenance: z.ZodObject<{
|
|
37
|
-
producer: z.ZodString;
|
|
38
|
-
source_id: z.ZodString;
|
|
39
|
-
producer_task_id: z.ZodString;
|
|
40
|
-
lineage: z.ZodArray<z.ZodObject<{
|
|
41
|
-
producer: z.ZodString;
|
|
42
|
-
source_id: z.ZodString;
|
|
43
|
-
}, z.core.$strict>>;
|
|
44
|
-
}, z.core.$strict>;
|
|
45
|
-
recovery: z.ZodObject<{
|
|
46
|
-
on_expiry: z.ZodLiteral<"request_verified_reexport">;
|
|
47
|
-
}, z.core.$strict>;
|
|
48
|
-
artifact_id: z.ZodString;
|
|
49
|
-
}, z.core.$strict>;
|
|
50
|
-
export type TeamArtifactManifest = z.infer<typeof Manifest>;
|
|
51
|
-
/** Artifact manifest schema shared by peer exports and the local artifact registry. */
|
|
52
|
-
export declare const TeamArtifactManifestSchema: z.ZodObject<{
|
|
53
|
-
schema_version: z.ZodLiteral<"1.0">;
|
|
54
|
-
revision: z.ZodNumber;
|
|
55
|
-
source_revision: z.ZodString;
|
|
56
|
-
visibility: z.ZodEnum<{
|
|
57
|
-
private: "private";
|
|
58
|
-
gm: "gm";
|
|
59
|
-
player: "player";
|
|
60
|
-
}>;
|
|
61
|
-
license: z.ZodString;
|
|
62
|
-
preview: z.ZodObject<{
|
|
63
|
-
mode: z.ZodEnum<{
|
|
64
|
-
none: "none";
|
|
65
|
-
inline: "inline";
|
|
66
|
-
thumbnail: "thumbnail";
|
|
67
|
-
download_only: "download_only";
|
|
68
|
-
}>;
|
|
69
|
-
mime: z.ZodString;
|
|
70
|
-
}, z.core.$strict>;
|
|
71
|
-
supersedes_sha256: z.ZodNullable<z.ZodString>;
|
|
72
|
-
acceptance_status: z.ZodEnum<{
|
|
73
|
-
partial: "partial";
|
|
74
|
-
rejected: "rejected";
|
|
75
|
-
unreviewed: "unreviewed";
|
|
76
|
-
approved: "approved";
|
|
77
|
-
}>;
|
|
78
|
-
name: z.ZodString;
|
|
79
|
-
mime: z.ZodString;
|
|
80
|
-
sha256: z.ZodString;
|
|
81
|
-
size: z.ZodNumber;
|
|
82
|
-
created_at: z.ZodNumber;
|
|
83
|
-
expires_at: z.ZodNumber;
|
|
84
|
-
provenance: z.ZodObject<{
|
|
85
|
-
producer: z.ZodString;
|
|
86
|
-
source_id: z.ZodString;
|
|
87
|
-
producer_task_id: z.ZodString;
|
|
88
|
-
lineage: z.ZodArray<z.ZodObject<{
|
|
89
|
-
producer: z.ZodString;
|
|
90
|
-
source_id: z.ZodString;
|
|
91
|
-
}, z.core.$strict>>;
|
|
92
|
-
}, z.core.$strict>;
|
|
93
|
-
recovery: z.ZodObject<{
|
|
94
|
-
on_expiry: z.ZodLiteral<"request_verified_reexport">;
|
|
95
|
-
}, z.core.$strict>;
|
|
96
|
-
artifact_id: z.ZodString;
|
|
97
|
-
}, z.core.$strict>;
|
|
4
|
+
import { type ArtifactManifest11, type ArtifactRendition, type TeamArtifactManifest } from './artifact-manifests.js';
|
|
5
|
+
export { TeamArtifactManifestSchema, type TeamArtifactManifest } from './artifact-manifests.js';
|
|
6
|
+
/** The v1 transfer descriptor: one A2A text part, at most 2 MiB. Unchanged by transfer v2. */
|
|
98
7
|
export declare const TeamArtifactDescriptorSchema: z.ZodObject<{
|
|
99
8
|
artifact_id: z.ZodString;
|
|
100
9
|
name: z.ZodString;
|
|
@@ -123,8 +32,8 @@ export declare const TeamArtifactDescriptorSchema: z.ZodObject<{
|
|
|
123
32
|
}, z.core.$strict>;
|
|
124
33
|
supersedes_sha256: z.ZodNullable<z.ZodString>;
|
|
125
34
|
acceptance_status: z.ZodEnum<{
|
|
126
|
-
partial: "partial";
|
|
127
35
|
rejected: "rejected";
|
|
36
|
+
partial: "partial";
|
|
128
37
|
unreviewed: "unreviewed";
|
|
129
38
|
approved: "approved";
|
|
130
39
|
}>;
|
|
@@ -150,30 +59,140 @@ export declare const TeamArtifactDescriptorSchema: z.ZodObject<{
|
|
|
150
59
|
}, z.core.$strict>;
|
|
151
60
|
}, z.core.$strict>;
|
|
152
61
|
export type TeamArtifactDescriptor = z.infer<typeof TeamArtifactDescriptorSchema>;
|
|
62
|
+
/**
|
|
63
|
+
* The transfer-v2 descriptor: an A2A data part with media type
|
|
64
|
+
* `ARTIFACT_TRANSFER_V2_MEDIA_TYPE`. Paths resolve against the exporting
|
|
65
|
+
* peer's pinned A2A origin.
|
|
66
|
+
*/
|
|
67
|
+
export declare const TeamArtifactDescriptorV2Schema: z.ZodObject<{
|
|
68
|
+
manifest_1_1: z.ZodObject<{
|
|
69
|
+
revision: z.ZodNumber;
|
|
70
|
+
source_revision: z.ZodString;
|
|
71
|
+
visibility: z.ZodEnum<{
|
|
72
|
+
private: "private";
|
|
73
|
+
gm: "gm";
|
|
74
|
+
player: "player";
|
|
75
|
+
}>;
|
|
76
|
+
license: z.ZodString;
|
|
77
|
+
preview: z.ZodObject<{
|
|
78
|
+
mode: z.ZodEnum<{
|
|
79
|
+
none: "none";
|
|
80
|
+
inline: "inline";
|
|
81
|
+
thumbnail: "thumbnail";
|
|
82
|
+
download_only: "download_only";
|
|
83
|
+
}>;
|
|
84
|
+
mime: z.ZodString;
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
supersedes_sha256: z.ZodNullable<z.ZodString>;
|
|
87
|
+
acceptance_status: z.ZodEnum<{
|
|
88
|
+
rejected: "rejected";
|
|
89
|
+
partial: "partial";
|
|
90
|
+
unreviewed: "unreviewed";
|
|
91
|
+
approved: "approved";
|
|
92
|
+
}>;
|
|
93
|
+
name: z.ZodString;
|
|
94
|
+
mime: z.ZodString;
|
|
95
|
+
sha256: z.ZodString;
|
|
96
|
+
created_at: z.ZodNumber;
|
|
97
|
+
expires_at: z.ZodNumber;
|
|
98
|
+
recovery: z.ZodObject<{
|
|
99
|
+
on_expiry: z.ZodLiteral<"request_verified_reexport">;
|
|
100
|
+
}, z.core.$strict>;
|
|
101
|
+
artifact_id: z.ZodString;
|
|
102
|
+
size: z.ZodNumber;
|
|
103
|
+
schema_version: z.ZodLiteral<"1.1">;
|
|
104
|
+
provenance: z.ZodObject<{
|
|
105
|
+
producer: z.ZodString;
|
|
106
|
+
source_id: z.ZodString;
|
|
107
|
+
producer_task_id: z.ZodString;
|
|
108
|
+
lineage: z.ZodArray<z.ZodObject<{
|
|
109
|
+
producer: z.ZodString;
|
|
110
|
+
source_id: z.ZodString;
|
|
111
|
+
}, z.core.$strict>>;
|
|
112
|
+
execution: z.ZodOptional<z.ZodObject<{
|
|
113
|
+
root: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
114
|
+
task: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
115
|
+
step: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
116
|
+
}, z.core.$strict>>;
|
|
117
|
+
}, z.core.$strict>;
|
|
118
|
+
rendition: z.ZodOptional<z.ZodObject<{
|
|
119
|
+
role: z.ZodEnum<{
|
|
120
|
+
preview: "preview";
|
|
121
|
+
original: "original";
|
|
122
|
+
model_input: "model_input";
|
|
123
|
+
}>;
|
|
124
|
+
of_sha256: z.ZodString;
|
|
125
|
+
purpose: z.ZodString;
|
|
126
|
+
transform: z.ZodObject<{
|
|
127
|
+
name: z.ZodString;
|
|
128
|
+
version: z.ZodString;
|
|
129
|
+
params: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
|
|
130
|
+
}, z.core.$strict>;
|
|
131
|
+
}, z.core.$strict>>;
|
|
132
|
+
}, z.core.$strict>;
|
|
133
|
+
content_path: z.ZodString;
|
|
134
|
+
renditions_path: z.ZodString;
|
|
135
|
+
size: z.ZodNumber;
|
|
136
|
+
sha256: z.ZodString;
|
|
137
|
+
}, z.core.$strict>;
|
|
138
|
+
export type TeamArtifactDescriptorV2 = z.infer<typeof TeamArtifactDescriptorV2Schema>;
|
|
139
|
+
/** The explicit result a v1 consumer receives for an export larger than the v1 limit. */
|
|
140
|
+
export declare const TeamArtifactRequiresV2Schema: z.ZodObject<{
|
|
141
|
+
error: z.ZodLiteral<"TRANSFER_REQUIRES_V2">;
|
|
142
|
+
capability: z.ZodLiteral<"urn:hive:artifact-transfer:2">;
|
|
143
|
+
message: z.ZodString;
|
|
144
|
+
artifact_id: z.ZodString;
|
|
145
|
+
name: z.ZodString;
|
|
146
|
+
mime: z.ZodString;
|
|
147
|
+
sha256: z.ZodString;
|
|
148
|
+
size: z.ZodNumber;
|
|
149
|
+
producer_task_id: z.ZodString;
|
|
150
|
+
}, z.core.$strict>;
|
|
151
|
+
export type TeamArtifactRequiresV2 = z.infer<typeof TeamArtifactRequiresV2Schema>;
|
|
152
|
+
/** One export: the v2 descriptor always, and either the v1 descriptor (at most 2 MiB) or the explicit v2 requirement. */
|
|
153
|
+
export type TeamArtifactExport = {
|
|
154
|
+
v2: TeamArtifactDescriptorV2;
|
|
155
|
+
} & ({
|
|
156
|
+
v1: TeamArtifactDescriptor;
|
|
157
|
+
requires_v2?: never;
|
|
158
|
+
} | {
|
|
159
|
+
v1?: never;
|
|
160
|
+
requires_v2: TeamArtifactRequiresV2;
|
|
161
|
+
});
|
|
162
|
+
/** An export a peer may fetch: its stored manifest in both views. `manifest_1_0` is absent above 2 MiB or for a rendition. */
|
|
163
|
+
export type ResolvedTeamArtifact = {
|
|
164
|
+
status: 200;
|
|
165
|
+
id: string;
|
|
166
|
+
peer: string;
|
|
167
|
+
context_id: string;
|
|
168
|
+
a2a_task_id: string;
|
|
169
|
+
manifest: ArtifactManifest11;
|
|
170
|
+
manifest_1_0?: TeamArtifactManifest;
|
|
171
|
+
};
|
|
153
172
|
/** Peer artifact receipts. A transfer is retained evidence, never a delivery claim. */
|
|
154
173
|
export declare class TeamArtifacts {
|
|
174
|
+
#private;
|
|
155
175
|
readonly runtime: ArdentRuntime;
|
|
156
176
|
readonly config: ArdentConfig;
|
|
157
177
|
readonly env: NodeJS.ProcessEnv;
|
|
158
178
|
constructor(runtime: ArdentRuntime, config?: ArdentConfig, env?: NodeJS.ProcessEnv);
|
|
159
|
-
registerResearch(a2aTaskId: string): Promise<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
179
|
+
registerResearch(a2aTaskId: string): Promise<TeamArtifactExport[]>;
|
|
180
|
+
/**
|
|
181
|
+
* The export a peer may fetch in a context, checked against its stored
|
|
182
|
+
* manifest and the size of the stored bytes. Bytes are read by the caller.
|
|
183
|
+
*/
|
|
184
|
+
resolve(peer: string, id: string, contextId: string): Promise<ResolvedTeamArtifact | {
|
|
185
|
+
status: 404 | 409 | 410;
|
|
164
186
|
}>;
|
|
187
|
+
/**
|
|
188
|
+
* The exported forms of an export's artifact in the same task and context,
|
|
189
|
+
* the original first, each with the export ID and path that serves it.
|
|
190
|
+
*/
|
|
191
|
+
renditions(resolved: ResolvedTeamArtifact): Promise<Array<ArtifactRendition & {
|
|
192
|
+
artifact_id: string;
|
|
193
|
+
content_path: string;
|
|
194
|
+
}>>;
|
|
165
195
|
revokeLocal(peer: string, a2aTaskId: string, id: string): void;
|
|
166
|
-
fetchHermes(input: {
|
|
167
|
-
owner: string;
|
|
168
|
-
localTaskId: string;
|
|
169
|
-
peer: string;
|
|
170
|
-
remoteTaskId: string;
|
|
171
|
-
remoteContextId: string;
|
|
172
|
-
artifactId: string;
|
|
173
|
-
sha256: string;
|
|
174
|
-
}): Promise<TeamArtifactDescriptor & {
|
|
175
|
-
local_artifact_id: string;
|
|
176
|
-
}>;
|
|
177
196
|
project(owner: string, localTaskId: string): Array<{
|
|
178
197
|
local_artifact_id: string;
|
|
179
198
|
peer: string;
|
|
@@ -182,4 +201,3 @@ export declare class TeamArtifacts {
|
|
|
182
201
|
delivery: 'unverified';
|
|
183
202
|
}>;
|
|
184
203
|
}
|
|
185
|
-
export {};
|