@arnilo/prism-supervisor 0.0.6 → 0.0.8

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.
@@ -36,19 +36,51 @@ export interface A2AAgentCard {
36
36
  readonly security?: readonly Readonly<Record<string, readonly string[]>>[];
37
37
  readonly signatures?: readonly A2AAgentCardSignature[];
38
38
  }
39
- export interface A2ATextPart {
40
- readonly text: string;
39
+ interface A2APartBase {
40
+ readonly mediaType?: string;
41
+ readonly filename?: string;
41
42
  readonly metadata?: Readonly<Record<string, unknown>>;
42
43
  }
44
+ export type A2APart = (A2APartBase & {
45
+ readonly text: string;
46
+ readonly raw?: never;
47
+ readonly url?: never;
48
+ readonly data?: never;
49
+ }) | (A2APartBase & {
50
+ readonly raw: string;
51
+ readonly text?: never;
52
+ readonly url?: never;
53
+ readonly data?: never;
54
+ }) | (A2APartBase & {
55
+ readonly url: string;
56
+ readonly text?: never;
57
+ readonly raw?: never;
58
+ readonly data?: never;
59
+ }) | (A2APartBase & {
60
+ readonly data: unknown;
61
+ readonly text?: never;
62
+ readonly raw?: never;
63
+ readonly url?: never;
64
+ });
65
+ export type A2ATextPart = Extract<A2APart, {
66
+ readonly text: string;
67
+ }>;
43
68
  export interface A2AMessage {
44
69
  readonly role: "user" | "agent" | "ROLE_USER" | "ROLE_AGENT";
45
- readonly parts: readonly A2ATextPart[];
70
+ readonly parts: readonly A2APart[];
46
71
  readonly messageId: string;
47
72
  readonly contextId?: string;
48
73
  readonly taskId?: string;
49
74
  readonly metadata?: Readonly<Record<string, unknown>>;
50
75
  }
51
- export type A2ATaskState = "TASK_STATE_SUBMITTED" | "TASK_STATE_WORKING" | "TASK_STATE_COMPLETED" | "TASK_STATE_FAILED" | "TASK_STATE_CANCELED";
76
+ export interface A2AArtifact {
77
+ readonly artifactId: string;
78
+ readonly parts: readonly A2APart[];
79
+ readonly name?: string;
80
+ readonly description?: string;
81
+ readonly metadata?: Readonly<Record<string, unknown>>;
82
+ }
83
+ export type A2ATaskState = "TASK_STATE_SUBMITTED" | "TASK_STATE_WORKING" | "TASK_STATE_COMPLETED" | "TASK_STATE_FAILED" | "TASK_STATE_CANCELED" | "TASK_STATE_INPUT_REQUIRED" | "TASK_STATE_REJECTED" | "TASK_STATE_AUTH_REQUIRED";
52
84
  export interface A2ATask {
53
85
  readonly id: string;
54
86
  readonly contextId: string;
@@ -57,16 +89,35 @@ export interface A2ATask {
57
89
  readonly timestamp: string;
58
90
  readonly message?: A2AMessage;
59
91
  };
60
- readonly artifacts?: readonly {
61
- readonly artifactId: string;
62
- readonly parts: readonly A2ATextPart[];
63
- }[];
92
+ readonly artifacts?: readonly A2AArtifact[];
93
+ readonly history?: readonly A2AMessage[];
94
+ readonly metadata?: Readonly<Record<string, unknown>>;
64
95
  }
96
+ export type A2ATaskEvent = {
97
+ readonly eventId: string;
98
+ readonly task: A2ATask;
99
+ } | {
100
+ readonly eventId: string;
101
+ readonly statusUpdate: {
102
+ readonly taskId: string;
103
+ readonly contextId: string;
104
+ readonly status: A2ATask["status"];
105
+ };
106
+ } | {
107
+ readonly eventId: string;
108
+ readonly artifactUpdate: {
109
+ readonly taskId: string;
110
+ readonly contextId: string;
111
+ readonly artifact: A2AArtifact;
112
+ readonly append?: boolean;
113
+ readonly lastChunk?: boolean;
114
+ };
115
+ };
65
116
  export type A2ARequestId = string | number | null;
66
117
  export interface A2AJsonRpcRequest {
67
118
  readonly jsonrpc: "2.0";
68
119
  readonly id: A2ARequestId;
69
- readonly method: "SendMessage" | "SendStreamingMessage" | "GetExtendedAgentCard" | string;
120
+ readonly method: string;
70
121
  readonly params?: Readonly<Record<string, unknown>>;
71
122
  }
72
123
  export interface A2AJsonRpcResponse {
@@ -91,6 +142,88 @@ export type A2AAuthorizer = (input: {
91
142
  export interface A2AAgentExposure {
92
143
  readonly sessionFactory: (authorization: A2AAuthorization) => AgentSession | Promise<AgentSession>;
93
144
  }
145
+ export interface A2ATaskPage {
146
+ readonly tasks: readonly A2ATask[];
147
+ readonly nextPageToken?: string;
148
+ readonly totalSize?: number;
149
+ }
150
+ export interface A2ATaskLifecycle {
151
+ start(input: {
152
+ readonly message: A2AMessage;
153
+ readonly authorization: A2AAuthorization;
154
+ readonly signal: AbortSignal;
155
+ readonly returnImmediately?: boolean;
156
+ }): Promise<A2ATask>;
157
+ get(input: {
158
+ readonly id: string;
159
+ readonly historyLength: number;
160
+ readonly authorization: A2AAuthorization;
161
+ readonly signal: AbortSignal;
162
+ }): Promise<A2ATask | undefined>;
163
+ list(input: {
164
+ readonly pageSize: number;
165
+ readonly pageToken?: string;
166
+ readonly contextId?: string;
167
+ readonly authorization: A2AAuthorization;
168
+ readonly signal: AbortSignal;
169
+ }): Promise<A2ATaskPage>;
170
+ cancel(input: {
171
+ readonly id: string;
172
+ readonly authorization: A2AAuthorization;
173
+ readonly signal: AbortSignal;
174
+ }): Promise<A2ATask | undefined>;
175
+ subscribe(input: {
176
+ readonly id: string;
177
+ readonly afterEventId?: string;
178
+ readonly authorization: A2AAuthorization;
179
+ readonly signal: AbortSignal;
180
+ }): AsyncIterable<A2ATaskEvent>;
181
+ }
182
+ export interface A2APushConfig {
183
+ readonly id: string;
184
+ readonly taskId: string;
185
+ readonly url: string;
186
+ readonly token?: string;
187
+ readonly authentication?: {
188
+ readonly scheme: string;
189
+ readonly credentials?: string;
190
+ };
191
+ }
192
+ export interface A2APushProvider {
193
+ create(input: {
194
+ readonly config: A2APushConfig;
195
+ readonly authorization: A2AAuthorization;
196
+ readonly signal: AbortSignal;
197
+ }): Promise<A2APushConfig>;
198
+ get(input: {
199
+ readonly taskId: string;
200
+ readonly id: string;
201
+ readonly authorization: A2AAuthorization;
202
+ readonly signal: AbortSignal;
203
+ }): Promise<A2APushConfig | undefined>;
204
+ list(input: {
205
+ readonly taskId: string;
206
+ readonly pageSize: number;
207
+ readonly pageToken?: string;
208
+ readonly authorization: A2AAuthorization;
209
+ readonly signal: AbortSignal;
210
+ }): Promise<{
211
+ readonly configs: readonly A2APushConfig[];
212
+ readonly nextPageToken?: string;
213
+ }>;
214
+ delete(input: {
215
+ readonly taskId: string;
216
+ readonly id: string;
217
+ readonly authorization: A2AAuthorization;
218
+ readonly signal: AbortSignal;
219
+ }): Promise<boolean>;
220
+ }
221
+ export interface A2APartPolicy {
222
+ readonly allowRaw?: boolean;
223
+ readonly allowUrl?: boolean;
224
+ readonly allowData?: boolean;
225
+ readonly validateUrl?: (url: URL) => void | Promise<void>;
226
+ }
94
227
  export interface A2ALimits {
95
228
  readonly maxRequestBytes?: number;
96
229
  readonly maxResponseBytes?: number;
@@ -100,11 +233,25 @@ export interface A2ALimits {
100
233
  readonly maxConcurrentRequests?: number;
101
234
  readonly timeoutMs?: number;
102
235
  readonly maxCardBytes?: number;
236
+ readonly maxIdBytes?: number;
237
+ readonly maxParts?: number;
238
+ readonly maxPartBytes?: number;
239
+ readonly maxRawBytes?: number;
240
+ readonly maxDataBytes?: number;
241
+ readonly maxArtifacts?: number;
242
+ readonly maxHistory?: number;
243
+ readonly maxPageSize?: number;
244
+ readonly maxCursorBytes?: number;
245
+ readonly maxReplayEvents?: number;
246
+ readonly maxPushConfigs?: number;
103
247
  }
104
248
  export interface CreateA2AHandlerOptions {
105
249
  readonly card: A2AAgentCard;
106
250
  readonly exposure: A2AAgentExposure;
107
251
  readonly authorize: A2AAuthorizer;
252
+ readonly tasks?: A2ATaskLifecycle;
253
+ readonly push?: A2APushProvider;
254
+ readonly parts?: A2APartPolicy;
108
255
  readonly endpointPath?: string;
109
256
  readonly redactor?: SecretRedactor;
110
257
  readonly limits?: A2ALimits;
@@ -121,6 +268,7 @@ export interface A2AClientOptions {
121
268
  readonly cardUrl?: string;
122
269
  readonly limits?: A2ALimits;
123
270
  readonly redactor?: SecretRedactor;
271
+ readonly parts?: A2APartPolicy;
124
272
  }
125
273
  export interface A2AClient {
126
274
  getCard(options?: {
@@ -129,7 +277,46 @@ export interface A2AClient {
129
277
  send(input: string, options?: {
130
278
  readonly signal?: AbortSignal;
131
279
  }): Promise<AgentRunResult>;
280
+ sendMessage(message: A2AMessage, options?: {
281
+ readonly signal?: AbortSignal;
282
+ readonly returnImmediately?: boolean;
283
+ }): Promise<A2ATask>;
132
284
  stream(input: string, options?: {
133
285
  readonly signal?: AbortSignal;
134
286
  }): AsyncIterable<string>;
287
+ getTask(id: string, options?: {
288
+ readonly signal?: AbortSignal;
289
+ readonly historyLength?: number;
290
+ }): Promise<A2ATask>;
291
+ listTasks(options?: {
292
+ readonly signal?: AbortSignal;
293
+ readonly pageSize?: number;
294
+ readonly pageToken?: string;
295
+ readonly contextId?: string;
296
+ }): Promise<A2ATaskPage>;
297
+ cancelTask(id: string, options?: {
298
+ readonly signal?: AbortSignal;
299
+ }): Promise<A2ATask>;
300
+ subscribeToTask(id: string, options?: {
301
+ readonly signal?: AbortSignal;
302
+ readonly afterEventId?: string;
303
+ }): AsyncIterable<A2ATaskEvent>;
304
+ createPushConfig(config: A2APushConfig, options?: {
305
+ readonly signal?: AbortSignal;
306
+ }): Promise<A2APushConfig>;
307
+ getPushConfig(taskId: string, id: string, options?: {
308
+ readonly signal?: AbortSignal;
309
+ }): Promise<A2APushConfig>;
310
+ listPushConfigs(taskId: string, options?: {
311
+ readonly signal?: AbortSignal;
312
+ readonly pageSize?: number;
313
+ readonly pageToken?: string;
314
+ }): Promise<{
315
+ readonly configs: readonly A2APushConfig[];
316
+ readonly nextPageToken?: string;
317
+ }>;
318
+ deletePushConfig(taskId: string, id: string, options?: {
319
+ readonly signal?: AbortSignal;
320
+ }): Promise<void>;
135
321
  }
322
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./a2a-card.js";
2
2
  export * from "./a2a-client.js";
3
+ export * from "./a2a-parts.js";
4
+ export * from "./a2a-push.js";
3
5
  export * from "./a2a-server.js";
4
6
  export type * from "./a2a-types.js";
5
7
  export * from "./errors.js";
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export * from "./a2a-card.js";
2
2
  export * from "./a2a-client.js";
3
+ export * from "./a2a-parts.js";
4
+ export * from "./a2a-push.js";
3
5
  export * from "./a2a-server.js";
4
6
  export * from "./errors.js";
5
7
  export * from "./limits.js";
@@ -93,16 +93,32 @@ export function createSupervisor(options) {
93
93
  redactor: options.redactor ?? childAgent.config.redactor,
94
94
  });
95
95
  const session = agent.createSession({ id: `${delegationId}-session`, metadata: { supervisorId: id, delegationId, resourceId, threadId } });
96
- const result = await abortable(session.run(input, {
97
- signal: controller.signal,
98
- maxToolRounds: limits.maxSteps,
99
- ownership: options.ownership,
100
- redactor: options.redactor,
101
- metadata: { ...request.metadata, supervisorId: id, delegationId, resourceId, threadId, depth },
102
- }), controller.signal);
96
+ let result;
97
+ try {
98
+ result = await abortable(session.run(input, {
99
+ signal: controller.signal,
100
+ limits: {
101
+ maxToolRounds: limits.maxSteps,
102
+ maxToolCalls: limits.maxToolCalls,
103
+ maxTotalTokens: limits.maxTokens,
104
+ maxWallTimeMs: limits.timeoutMs,
105
+ },
106
+ ownership: options.ownership,
107
+ redactor: options.redactor,
108
+ metadata: { ...request.metadata, supervisorId: id, delegationId, resourceId, threadId, depth },
109
+ }), controller.signal);
110
+ }
111
+ catch (error) {
112
+ if (error instanceof AgentRunError && error.result.limit) {
113
+ const label = error.result.limit.limit === "maxTotalTokens" ? "token"
114
+ : error.result.limit.limit === "maxToolCalls" ? "tool-call"
115
+ : error.result.limit.limit === "maxWallTimeMs" ? "timeout"
116
+ : "run";
117
+ throw new SupervisorLimitError(`Delegation ${label} limit exceeded`);
118
+ }
119
+ throw error;
120
+ }
103
121
  const totalTokens = result.usage?.totalTokens ?? ((result.usage?.inputTokens ?? 0) + (result.usage?.outputTokens ?? 0));
104
- if (totalTokens > limits.maxTokens)
105
- throw new SupervisorLimitError("Delegation token limit exceeded");
106
122
  events.publish({ type: "delegation_finished", childId: request.childId, delegationId, depth, status: result.status, totalTokens });
107
123
  await complete(toCompletion(result, request.childId, delegationId, depth, options));
108
124
  completionSent = true;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arnilo/prism-supervisor",
3
- "version": "0.0.6",
4
- "description": "Optional bounded local supervisor delegation and A2A 1.0 interoperability.",
3
+ "version": "0.0.8",
4
+ "description": "Bounded supervisor delegation and A2A 1.0 durable task, rich-part, reconnect, and push interoperability.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "pack:dry-run": "npm pack --dry-run"
26
26
  },
27
27
  "peerDependencies": {
28
- "@arnilo/prism": "0.0.6"
28
+ "@arnilo/prism": "0.0.8"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@arnilo/prism": "file:../.."