@hivemagnus/ardent-client 3.3.0 → 3.4.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 CHANGED
@@ -1,10 +1,11 @@
1
1
  # @hivemagnus/ardent-client
2
2
 
3
3
  The supported remote client for [Ardent](https://github.com/ChefTaco/Ardent)
4
- profiles. It submits and follows tasks, reconnects dropped or rotated task
5
- streams from their cursor, cancels, pauses and resumes tasks, drives execution
6
- recovery decisions, reads lineage, and downloads artifacts with resumable,
7
- digest-verified transfers.
4
+ profiles. It submits and follows tasks, team missions and previews, pages
5
+ through filtered task history, reconnects dropped or rotated task streams from
6
+ their cursor, cancels, pauses and resumes tasks, drives execution recovery
7
+ decisions, reads lineage and development history, and downloads artifacts with
8
+ resumable, digest-verified transfers.
8
9
 
9
10
  It talks to a standalone Ardent management API directly, or to a
10
11
  Magnus-managed profile through the Magnus Control API. It runs in Node.js 24+
@@ -74,12 +75,18 @@ viaMagnus({ baseUrl | apiBase, nodeId, profile, getToken, headers?, fetch? }): A
74
75
 
75
76
  ardent.tasks.submit({ prompt, idempotencyKey?, sessionId?, execution?, signal? }): Promise<TaskAccepted>
76
77
  ardent.tasks.get(id, { signal? }): Promise<Task>
77
- ardent.tasks.list({ limit?, signal? }): Promise<Task[]>
78
+ ardent.tasks.list({ limit?, state?, context?, caller?, since?, until?, signal? }): Promise<Task[]>
79
+ ardent.tasks.page({ limit?, after?, state?, context?, caller?, since?, until?, signal? }): Promise<{ tasks, next }>
78
80
  ardent.tasks.events(id, { after?, signal? }): Promise<TaskEvent[]>
79
81
  ardent.tasks.cancel(id, { signal? }): Promise<Task>
80
82
  ardent.tasks.pause(id, { signal? }) / resume(id, { signal? }): Promise<TaskAdmission>
81
83
  ardent.tasks.follow(id, { after?, onEvent?, onText?, onConnect?, signal? }): Promise<Task>
82
84
 
85
+ ardent.missions.submit({ objective, mission, contextItems?, labels?, sessionId?, idempotencyKey?, execution?, signal? }): Promise<TaskAccepted>
86
+ ardent.previews.submit({ prompt, overrides?, sessionId?, idempotencyKey?, execution?, signal? }): Promise<TaskAccepted>
87
+ ardent.development.list({ after?, limit?, kind?, signal? }): Promise<{ records, next }>
88
+ ardent.development.note({ kind, title, body, sources?, author? }, { signal? }): Promise<DevelopmentRecord>
89
+
83
90
  ardent.sessions.list({ context?, signal? }): Promise<Session[]>
84
91
  ardent.sessions.open(key, { context?, reset?, signal? }): Promise<Session>
85
92
  ardent.sessions.messages(id, { signal? }): Promise<SessionMessage[]>
@@ -103,6 +110,33 @@ Response types (`Task`, `Recovery`, `Lineage`, `ArtifactRecord` and the rest)
103
110
  are the documented response bodies, and `paths`, `operations` and
104
111
  `components` are exported for anything else in the API.
105
112
 
113
+ Task filters (`state`, one or several; `context`; `caller`; `since` and
114
+ `until` as epoch milliseconds, a `Date` or ISO 8601) need Ardent 3.4 or later;
115
+ against an older profile, or through a Magnus that does not advertise
116
+ `task_filters` (it would drop them), they raise `UnsupportedCapabilityError`
117
+ instead of returning unfiltered tasks. `tasks.page` returns `next`, the cursor
118
+ to pass as `after`; it is `null` on the last page.
119
+
120
+ Missions and previews stream on `tasks.follow` like any task. A mission or
121
+ preview submission is safe to repeat with the same `idempotencyKey` (one is
122
+ generated when omitted); a development note is never repeated automatically.
123
+
124
+ ### OpenAPI types and the route manifest
125
+
126
+ `@hivemagnus/ardent-client/openapi` exports the generated `paths`,
127
+ `operations` and `components` types and `ARDENT_ROUTES`, one entry per
128
+ management API operation (`operationId`, `method`, `path`, `kind: 'read' |
129
+ 'action'`, `auth: 'bearer' | 'none'`, `stream`), generated from the same
130
+ OpenAPI document. `matchArdentRoute(method, path)` finds the entry for a
131
+ request path. Code that proxies or allowlists Ardent routes, such as Magnus's
132
+ node agent, can use them instead of regenerating its own copy.
133
+
134
+ ```ts
135
+ import { ARDENT_ROUTES, matchArdentRoute, type paths } from '@hivemagnus/ardent-client/openapi';
136
+
137
+ matchArdentRoute('GET', '/api/v1/tasks/1b9d…/events'); // { operationId: 'getTaskEvents', kind: 'read', … }
138
+ ```
139
+
106
140
  ### Following a task
107
141
 
108
142
  `tasks.follow` reads `GET /api/v1/tasks/{id}/stream` until `task.done` and then
@@ -237,6 +271,11 @@ report.
237
271
  | `tasks.follow` | `GET /api/v1/tasks/{id}/stream` | `GET …/tasks/{id}/stream` relay |
238
272
  | `sessions.list`, `messages` | `GET /api/v1/sessions[/{id}/messages]` | read `sessions[/{id}/messages]` |
239
273
  | `sessions.open` | `POST /api/v1/sessions` | action `session-open` |
274
+ | `missions.submit` | `POST /api/v1/missions` | action `mission-submit` |
275
+ | `previews.submit` | `POST /api/v1/preview/tasks` | action `preview-submit` |
276
+ | `development.list` | `GET /api/v1/development` | read `development` |
277
+ | `development.note` | `POST /api/v1/development` | action `development-note` |
278
+ | `tasks.page`, `list` with filters | `GET /api/v1/tasks?state=…&context=…&caller=…&since=…&until=…` | read `tasks`; filters once Magnus advertises `task_filters` (`after` and `limit` always) |
240
279
  | `artifacts.list`, `manifest` | `GET /api/v1/tasks/{id}/artifacts`, `/api/v1/artifacts/{sha}/manifest` | reads |
241
280
  | `recovery.get`, `lineage` | `GET /api/v1/tasks/{id}/recovery\|lineage` | reads, from Magnus 3.3.0 |
242
281
  | `recovery.decide` | `POST /api/v1/tasks/{id}/recovery` | action `task-recovery` (target: task ID, body: the decision), from Magnus 3.3.0 |
@@ -258,8 +297,8 @@ become `UnsupportedCapabilityError`. A linked service identity may need an
258
297
 
259
298
  The A2A protocol (peer agents calling Ardent's A2A surface) is out of scope; use
260
299
  an A2A SDK such as `@a2a-js/sdk` for peer calls. Configuration, identity,
261
- skills, peers, missions and previews are management concerns that Magnus and
262
- the Ardent CLI handle; their routes are in the exported `paths` types.
300
+ skills and peers are management concerns that Magnus and the Ardent CLI
301
+ handle; their routes are in the exported `paths` types and `ARDENT_ROUTES`.
263
302
 
264
303
  ## License
265
304
 
package/dist/client.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { RetryPolicy } from '@hivemagnus/hive-common/retry';
3
3
  import { type ArdentTransport } from './transport.js';
4
4
  import { type FollowOptions } from './follow.js';
5
5
  import { type ArtifactDownload, type DownloadOptions } from './download.js';
6
- import type { ArtifactImport, ArtifactImportAccepted, ArtifactImportRequest, ArtifactRecord, ArtifactRecordV2, ArtifactRendition, Lineage, OperationalStatus, Recovery, RecoveryAction, Session, SessionContext, SessionMessage, Task, TaskAccepted, TaskAdmission, TaskEvent } from './types.js';
6
+ import type { ArtifactImport, ArtifactImportAccepted, ArtifactImportRequest, ArtifactRecord, ArtifactRecordV2, ArtifactRendition, DevelopmentNote, DevelopmentPage, DevelopmentRecord, Lineage, MissionContextItem, OperationalStatus, PreviewOverrides, Recovery, RecoveryAction, Session, SessionContext, SessionMessage, Task, TaskAccepted, TaskAdmission, TaskContext, TaskEvent, TaskPage, TaskState, TeamMission } from './types.js';
7
7
  export interface ArdentClientOptions {
8
8
  /** `direct({ baseUrl, getToken })` or `viaMagnus({ baseUrl | apiBase, nodeId, profile, getToken })`. */
9
9
  readonly transport: ArdentTransport;
@@ -30,6 +30,40 @@ export interface SubmitInput {
30
30
  readonly execution?: ExecutionContext;
31
31
  readonly signal?: AbortSignal;
32
32
  }
33
+ /** Filters of `tasks.list` and `tasks.page`; they combine. Ardent 3.4 or later (through Magnus: when it advertises `task_filters`). */
34
+ export interface TaskFilter {
35
+ /** One state or several. */
36
+ readonly state?: TaskState | readonly TaskState[];
37
+ readonly context?: TaskContext;
38
+ /** The exact caller, for example `management` or a peer ID. */
39
+ readonly caller?: string;
40
+ /** Tasks created at or after this time (epoch milliseconds, a Date or ISO 8601). */
41
+ readonly since?: number | Date | string;
42
+ /** Tasks created before this time. */
43
+ readonly until?: number | Date | string;
44
+ }
45
+ export interface MissionInput {
46
+ readonly objective: string;
47
+ readonly mission: TeamMission;
48
+ readonly contextItems?: readonly MissionContextItem[];
49
+ readonly labels?: Readonly<Record<string, string>>;
50
+ /** A session opened with context `mission`. */
51
+ readonly sessionId?: string;
52
+ /** Makes the submission safe to repeat; one is generated when omitted (a UUID through Magnus, as for `tasks.submit`). */
53
+ readonly idempotencyKey?: string;
54
+ readonly execution?: ExecutionContext;
55
+ readonly signal?: AbortSignal;
56
+ }
57
+ export interface PreviewInput {
58
+ readonly prompt: string;
59
+ /** Unsaved soul, identity, skill selection or model to try. */
60
+ readonly overrides?: PreviewOverrides;
61
+ /** A session opened with context `preview`. */
62
+ readonly sessionId?: string;
63
+ readonly idempotencyKey?: string;
64
+ readonly execution?: ExecutionContext;
65
+ readonly signal?: AbortSignal;
66
+ }
33
67
  export interface RecoveryDecision {
34
68
  readonly action: RecoveryAction;
35
69
  /** The pending tool call the decision is about, when the task has more than one. */
@@ -70,9 +104,15 @@ export interface ArdentClient {
70
104
  readonly tasks: {
71
105
  submit(input: SubmitInput): Promise<TaskAccepted>;
72
106
  get(id: string, options?: CallOptions): Promise<Task>;
73
- list(options?: CallOptions & {
107
+ /** The newest tasks, at most `limit` (default 50, at most 100). */
108
+ list(options?: CallOptions & TaskFilter & {
74
109
  readonly limit?: number;
75
110
  }): Promise<Task[]>;
111
+ /** One page of tasks, newest first. Pass `next` as `after` for the following page; it is null on the last one. */
112
+ page(options?: CallOptions & TaskFilter & {
113
+ readonly limit?: number;
114
+ readonly after?: string;
115
+ }): Promise<TaskPage>;
76
116
  events(id: string, options?: CallOptions & {
77
117
  readonly after?: number;
78
118
  }): Promise<TaskEvent[]>;
@@ -82,6 +122,24 @@ export interface ArdentClient {
82
122
  /** Follow the task's events until it finishes, across the 60 s stream rotation and dropped connections, and return the final task. */
83
123
  follow(id: string, options?: FollowTaskOptions): Promise<Task>;
84
124
  };
125
+ readonly missions: {
126
+ /** Submit a team mission as a durable task in context `mission`; follow it with `tasks.follow`. */
127
+ submit(input: MissionInput): Promise<TaskAccepted>;
128
+ };
129
+ readonly previews: {
130
+ /** Run a prompt with unsaved overrides as a read-only task in context `preview`; follow it with `tasks.follow`. */
131
+ submit(input: PreviewInput): Promise<TaskAccepted>;
132
+ };
133
+ readonly development: {
134
+ /** One page of the agent's development history, oldest first; `next` is null on the last page. */
135
+ list(options?: CallOptions & {
136
+ readonly after?: string;
137
+ readonly limit?: number;
138
+ readonly kind?: string;
139
+ }): Promise<DevelopmentPage>;
140
+ /** Record an operator note (or, with `author: 'agent'`, a relayed agent note). */
141
+ note(note: DevelopmentNote, options?: CallOptions): Promise<DevelopmentRecord>;
142
+ };
85
143
  readonly sessions: {
86
144
  list(options?: CallOptions & {
87
145
  readonly context?: SessionContext;
package/dist/client.js CHANGED
@@ -2,7 +2,7 @@ import { executionHeaders, parseExecutionContext } from '@hivemagnus/hive-common
2
2
  import { Connection } from './transport.js';
3
3
  import { followTask } from './follow.js';
4
4
  import { downloadArtifact } from './download.js';
5
- import { NotFoundError } from './errors.js';
5
+ import { NotFoundError, UnsupportedCapabilityError } from './errors.js';
6
6
  import { uuidFromKey } from './sha256.js';
7
7
  const segment = (value, label) => {
8
8
  if (typeof value !== 'string' || !/^[A-Za-z0-9._:-]{1,128}$/.test(value))
@@ -14,6 +14,14 @@ const digest = (value) => {
14
14
  throw new NotFoundError('NOT_FOUND', 'Invalid artifact digest', { status: 404 });
15
15
  return value;
16
16
  };
17
+ /** The query of a task filter; times become epoch milliseconds. */
18
+ function taskFilterQuery(filter) {
19
+ const time = (value) => typeof value === 'number' ? value : value instanceof Date ? value.getTime() : value;
20
+ const states = filter.state === undefined ? [] : typeof filter.state === 'string' ? [filter.state] : [...filter.state];
21
+ return { ...(states.length ? { state: states.join(',') } : {}), ...(filter.context !== undefined ? { context: filter.context } : {}),
22
+ ...(filter.caller !== undefined ? { caller: filter.caller } : {}), ...(filter.since !== undefined ? { since: time(filter.since) } : {}),
23
+ ...(filter.until !== undefined ? { until: time(filter.until) } : {}) };
24
+ }
17
25
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18
26
  /** A random UUID; `randomUUID` exists only in secure browser contexts, so fall back to random bytes. */
19
27
  const randomKey = () => {
@@ -31,16 +39,31 @@ export function createArdentClient(options) {
31
39
  const magnus = connection.kind === 'magnus';
32
40
  const defaultExecution = options.execution === undefined ? undefined : parseExecutionContext(options.execution);
33
41
  const read = (path, call, extra = {}) => connection.read({ path, ...extra }, call?.signal);
42
+ /** An idempotency key: the caller's, else a new one; through Magnus always a UUID. */
43
+ const keyFor = (key) => { const value = key ?? randomKey(); return magnus && !UUID.test(value) ? uuidFromKey(value) : value; };
44
+ const executionFor = (execution) => execution === undefined ? defaultExecution : parseExecutionContext(execution);
45
+ const page = async (call = {}) => {
46
+ const filter = taskFilterQuery(call);
47
+ const filtered = Object.keys(filter).length > 0;
48
+ // Magnus passes on only the query parameters it knows, so a filter it does not advertise would be dropped silently.
49
+ if (filtered && magnus && !await connection.advertises('task_filters'))
50
+ throw new UnsupportedCapabilityError('ardent.task-filters.v1', 'Magnus does not pass task list filters on yet (task_filters)');
51
+ const result = await read('tasks', call, { query: { limit: call.limit, after: call.after, ...filter } });
52
+ // An Ardent before 3.4 answers without next and ignores the filters.
53
+ if (filtered && !('next' in result))
54
+ throw new UnsupportedCapabilityError('ardent.task-filters.v1', 'The profile runs an Ardent without task list filters (3.4 or later)');
55
+ return { tasks: result.tasks, next: typeof result.next === 'string' ? result.next : null };
56
+ };
34
57
  const tasks = {
35
58
  async submit(input) {
36
- const key = input.idempotencyKey ?? randomKey();
37
- const execution = input.execution === undefined ? defaultExecution : parseExecutionContext(input.execution);
38
- const body = { prompt: input.prompt, idempotency_key: magnus && !UUID.test(key) ? uuidFromKey(key) : key, ...(input.sessionId !== undefined ? { session_id: input.sessionId } : {}) };
59
+ const execution = executionFor(input.execution);
60
+ const body = { prompt: input.prompt, idempotency_key: keyFor(input.idempotencyKey), ...(input.sessionId !== undefined ? { session_id: input.sessionId } : {}) };
39
61
  return connection.action({ path: 'tasks', body, magnus: { action: 'task-submit', body }, execution, effect: 'idempotent',
40
62
  headers: executionHeaders(execution) }, input.signal);
41
63
  },
64
+ page,
42
65
  get: async (id, call) => read(`tasks/${segment(id, 'task ID')}`, call),
43
- list: async (call = {}) => (await read('tasks', call, { query: { limit: call.limit } })).tasks,
66
+ list: async (call = {}) => (await page(call)).tasks,
44
67
  events: async (id, call = {}) => (await read(`tasks/${segment(id, 'task ID')}/events`, call, { query: { after: call.after } })).events,
45
68
  cancel: async (id, call) => connection.action({ path: `tasks/${segment(id, 'task ID')}/cancel`, magnus: { action: 'task-cancel', target: id }, effect: 'idempotent' }, call?.signal),
46
69
  pause: async (id, call) => connection.action({ path: `tasks/${segment(id, 'task ID')}/pause`, magnus: { action: 'task-pause', target: id }, effect: 'idempotent' }, call?.signal),
@@ -51,6 +74,30 @@ export function createArdentClient(options) {
51
74
  return tasks.get(id, follow.signal ? { signal: follow.signal } : {});
52
75
  },
53
76
  };
77
+ const missions = {
78
+ async submit(input) {
79
+ const execution = executionFor(input.execution);
80
+ const body = { objective: input.objective, mission: input.mission, idempotency_key: keyFor(input.idempotencyKey),
81
+ ...(input.contextItems !== undefined ? { context_items: [...input.contextItems] } : {}), ...(input.labels !== undefined ? { labels: { ...input.labels } } : {}),
82
+ ...(input.sessionId !== undefined ? { session_id: input.sessionId } : {}) };
83
+ return connection.action({ path: 'missions', body, magnus: { action: 'mission-submit', body }, execution, effect: 'idempotent',
84
+ headers: executionHeaders(execution) }, input.signal);
85
+ },
86
+ };
87
+ const previews = {
88
+ async submit(input) {
89
+ const execution = executionFor(input.execution);
90
+ const body = { prompt: input.prompt, idempotency_key: keyFor(input.idempotencyKey), ...(input.overrides !== undefined ? { overrides: input.overrides } : {}),
91
+ ...(input.sessionId !== undefined ? { session_id: input.sessionId } : {}) };
92
+ return connection.action({ path: 'preview/tasks', body, magnus: { action: 'preview-submit', body }, execution, effect: 'idempotent',
93
+ headers: executionHeaders(execution) }, input.signal);
94
+ },
95
+ };
96
+ const development = {
97
+ list: async (call = {}) => read('development', call, { query: { after: call.after, limit: call.limit, kind: call.kind } }),
98
+ // A note is not idempotent: it is never repeated automatically.
99
+ note: async (note, call) => connection.action({ path: 'development', body: note, magnus: { action: 'development-note', body: note }, effect: 'unknown' }, call?.signal),
100
+ };
54
101
  const sessions = {
55
102
  list: async (call = {}) => (await read('sessions', call, { query: { context: call.context } })).sessions,
56
103
  async open(key, call = {}) {
@@ -97,7 +144,7 @@ export function createArdentClient(options) {
97
144
  };
98
145
  const status = (call) => read('status', call);
99
146
  return {
100
- tasks, sessions, recovery, artifacts, status,
147
+ tasks, missions, previews, development, sessions, recovery, artifacts, status,
101
148
  lineage: async (id, call) => read(`tasks/${segment(id, 'task ID')}/lineage`, call, { gate: 'lineage' }),
102
149
  async capabilities(call) {
103
150
  const current = await status(call);