nexus-ai-pro 2.5.0 → 2.6.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/API_STABILITY.md +36 -0
- package/CHANGELOG.md +102 -1
- package/README.md +9 -3
- package/dist/agent/create-agent.d.ts +37 -2
- package/dist/agent/create-agent.js +62 -4
- package/dist/agent/index.d.ts +2 -1
- package/dist/agent/tool.d.ts +19 -4
- package/dist/agent/tool.js +27 -4
- package/dist/graph/event-stream.js +2 -0
- package/dist/graph/graph.js +4 -1
- package/dist/mcp/client.d.ts +9 -1
- package/dist/mcp/client.js +38 -8
- package/dist/mcp/server.js +42 -2
- package/dist/protocols/a2a.d.ts +166 -1
- package/dist/protocols/a2a.js +499 -132
- package/dist/protocols/acp-editor.d.ts +43 -0
- package/dist/protocols/acp-editor.js +164 -0
- package/dist/protocols/acp.d.ts +76 -3
- package/dist/protocols/acp.js +180 -7
- package/dist/protocols/ag-ui.d.ts +23 -0
- package/dist/protocols/ag-ui.js +128 -8
- package/dist/tracing/instrument.js +14 -3
- package/dist/types/graph.d.ts +7 -0
- package/dist/types/messages.d.ts +12 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist-cjs/agent/create-agent.d.ts +37 -2
- package/dist-cjs/agent/create-agent.js +62 -4
- package/dist-cjs/agent/index.d.ts +2 -1
- package/dist-cjs/agent/tool.d.ts +19 -4
- package/dist-cjs/agent/tool.js +27 -4
- package/dist-cjs/graph/event-stream.js +2 -0
- package/dist-cjs/graph/graph.js +4 -1
- package/dist-cjs/mcp/client.d.ts +9 -1
- package/dist-cjs/mcp/client.js +37 -7
- package/dist-cjs/mcp/server.js +42 -2
- package/dist-cjs/protocols/a2a.d.ts +166 -1
- package/dist-cjs/protocols/a2a.js +501 -132
- package/dist-cjs/protocols/acp-editor.d.ts +43 -0
- package/dist-cjs/protocols/acp-editor.js +167 -0
- package/dist-cjs/protocols/acp.d.ts +76 -3
- package/dist-cjs/protocols/acp.js +183 -8
- package/dist-cjs/protocols/ag-ui.d.ts +23 -0
- package/dist-cjs/protocols/ag-ui.js +127 -7
- package/dist-cjs/tracing/instrument.js +14 -3
- package/dist-cjs/types/graph.d.ts +7 -0
- package/dist-cjs/types/messages.d.ts +12 -0
- package/dist-cjs/version.d.ts +1 -1
- package/dist-cjs/version.js +1 -1
- package/llms.txt +1 -1
- package/package.json +17 -2
package/dist/mcp/server.js
CHANGED
|
@@ -66,10 +66,37 @@ export class McpServer {
|
|
|
66
66
|
case 'tools/call': {
|
|
67
67
|
const name = String(params.name ?? '');
|
|
68
68
|
const tool = this.tools.get(name);
|
|
69
|
-
if (!tool?.execute)
|
|
69
|
+
if (!tool?.execute && !tool?.stream)
|
|
70
70
|
return { content: textContent(`Unknown tool "${name}"`), isError: true };
|
|
71
|
+
const args = (params.arguments ?? {});
|
|
72
|
+
const token = params._meta?.progressToken;
|
|
73
|
+
let reports = 0;
|
|
74
|
+
const progress = typeof token === 'string' || typeof token === 'number'
|
|
75
|
+
? (value) => {
|
|
76
|
+
reports += 1;
|
|
77
|
+
void this.transport?.send({
|
|
78
|
+
jsonrpc: '2.0',
|
|
79
|
+
method: 'notifications/progress',
|
|
80
|
+
params: { progressToken: token, ...progressParams(value, reports) },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
: undefined;
|
|
71
84
|
try {
|
|
72
|
-
|
|
85
|
+
let output;
|
|
86
|
+
if (tool.stream) {
|
|
87
|
+
const generator = tool.stream(args, progress ? { progress } : {});
|
|
88
|
+
for (;;) {
|
|
89
|
+
const step = await generator.next();
|
|
90
|
+
if (step.done) {
|
|
91
|
+
output = step.value;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
progress?.(step.value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
output = await tool.execute(args, progress ? { progress } : {});
|
|
99
|
+
}
|
|
73
100
|
return { content: textContent(output) };
|
|
74
101
|
}
|
|
75
102
|
catch (error) {
|
|
@@ -136,3 +163,16 @@ export function createStdioServerTransport(streams) {
|
|
|
136
163
|
},
|
|
137
164
|
};
|
|
138
165
|
}
|
|
166
|
+
function progressParams(value, position) {
|
|
167
|
+
if (typeof value === 'number')
|
|
168
|
+
return { progress: value };
|
|
169
|
+
if (value && typeof value === 'object') {
|
|
170
|
+
const report = value;
|
|
171
|
+
return {
|
|
172
|
+
progress: typeof report.progress === 'number' ? report.progress : position,
|
|
173
|
+
...(typeof report.total === 'number' ? { total: report.total } : {}),
|
|
174
|
+
message: typeof report.message === 'string' ? report.message : JSON.stringify(value),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return { progress: position, message: String(value) };
|
|
178
|
+
}
|
package/dist/protocols/a2a.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Message, ToolDefinition } from '../types/messages.js';
|
|
2
2
|
import type { Principal } from '../types/principal.js';
|
|
3
|
+
import type { Store } from '../types/store.js';
|
|
3
4
|
import { type ProtocolGraph, type ProtocolInterrupt } from './shared.js';
|
|
4
5
|
export type { ProtocolGraph, ProtocolInterrupt, ProtocolResult, ProtocolRunOptions } from './shared.js';
|
|
5
6
|
/** The protocol version this module speaks. */
|
|
@@ -137,7 +138,9 @@ export type A2aStreamEvent = {
|
|
|
137
138
|
export declare const A2A_ERRORS: {
|
|
138
139
|
readonly taskNotFound: -32001;
|
|
139
140
|
readonly taskNotCancelable: -32002;
|
|
141
|
+
readonly pushNotificationNotSupported: -32003;
|
|
140
142
|
readonly unsupportedOperation: -32004;
|
|
143
|
+
readonly extendedCardNotConfigured: -32007;
|
|
141
144
|
readonly versionNotSupported: -32009;
|
|
142
145
|
};
|
|
143
146
|
/** Raised by the client when an agent answers with a JSON-RPC error. */
|
|
@@ -152,6 +155,109 @@ export declare class A2aError extends Error {
|
|
|
152
155
|
/** The error's data, when the agent sent any. */
|
|
153
156
|
data?: unknown | undefined);
|
|
154
157
|
}
|
|
158
|
+
/** Where a task's updates are pushed: a webhook the calling agent gave. */
|
|
159
|
+
export interface A2aPushNotificationConfig {
|
|
160
|
+
/** Its id, unique within the task. Given one when it has none. */
|
|
161
|
+
id?: string;
|
|
162
|
+
/** Where each update is POSTed. */
|
|
163
|
+
url: string;
|
|
164
|
+
/** Sent back as the `X-A2A-Notification-Token` header, so the receiver knows the update is its own. */
|
|
165
|
+
token?: string;
|
|
166
|
+
}
|
|
167
|
+
/** A task as a store keeps it: the task, its messages, the questions it waits on, and its webhooks. */
|
|
168
|
+
export interface A2aTaskRecord {
|
|
169
|
+
/** The task. */
|
|
170
|
+
task: A2aTask;
|
|
171
|
+
/** Every message of the task, the caller's and the agent's. */
|
|
172
|
+
history: A2aMessage[];
|
|
173
|
+
/** The questions the paused run asked, which the next message answers. */
|
|
174
|
+
interrupts?: ProtocolInterrupt[];
|
|
175
|
+
/** Where its updates are pushed. */
|
|
176
|
+
push?: A2aPushNotificationConfig[];
|
|
177
|
+
/** ISO-8601 time it was last written. */
|
|
178
|
+
updatedAt: string;
|
|
179
|
+
}
|
|
180
|
+
/** Which tasks `A2aTaskStore.list()` returns. */
|
|
181
|
+
export interface A2aTaskQuery {
|
|
182
|
+
/** Only this conversation's. */
|
|
183
|
+
contextId?: string;
|
|
184
|
+
/** Only those in this state. */
|
|
185
|
+
state?: A2aTaskState;
|
|
186
|
+
/** Most returned. */
|
|
187
|
+
limit: number;
|
|
188
|
+
/** Skipped first, for paging. */
|
|
189
|
+
offset: number;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Where an A2A agent keeps its tasks and conversations. A store outside the process lets a restart, or
|
|
193
|
+
* another replica, pick a task up: answer a task's question, read it, list it, or cancel it.
|
|
194
|
+
*/
|
|
195
|
+
export interface A2aTaskStore {
|
|
196
|
+
/** A task's record. */
|
|
197
|
+
get(taskId: string): Promise<A2aTaskRecord | undefined> | A2aTaskRecord | undefined;
|
|
198
|
+
/** Writes a task's record. */
|
|
199
|
+
put(record: A2aTaskRecord): Promise<void> | void;
|
|
200
|
+
/** Tasks, most recently written first, and how many match when the store knows. */
|
|
201
|
+
list(query: A2aTaskQuery): Promise<{
|
|
202
|
+
records: A2aTaskRecord[];
|
|
203
|
+
total?: number;
|
|
204
|
+
}> | {
|
|
205
|
+
records: A2aTaskRecord[];
|
|
206
|
+
total?: number;
|
|
207
|
+
};
|
|
208
|
+
/** A conversation's transcript, as the agent last left it. */
|
|
209
|
+
conversation(contextId: string): Promise<Message[] | undefined> | Message[] | undefined;
|
|
210
|
+
/** Writes a conversation's transcript. */
|
|
211
|
+
saveConversation(contextId: string, messages: Message[]): Promise<void> | void;
|
|
212
|
+
}
|
|
213
|
+
/** Tasks and conversations in this process: the default, for one replica. */
|
|
214
|
+
export declare class MemoryA2aTaskStore implements A2aTaskStore {
|
|
215
|
+
private readonly tasks;
|
|
216
|
+
private readonly conversations;
|
|
217
|
+
private readonly max;
|
|
218
|
+
constructor(options?: {
|
|
219
|
+
maxTasks?: number;
|
|
220
|
+
});
|
|
221
|
+
/** A task's record, as a copy. */
|
|
222
|
+
get(taskId: string): A2aTaskRecord | undefined;
|
|
223
|
+
/** Writes a task's record, dropping the least recently written beyond `maxTasks`. */
|
|
224
|
+
put(record: A2aTaskRecord): void;
|
|
225
|
+
/** Tasks, most recently written first, with how many match. */
|
|
226
|
+
list(query: A2aTaskQuery): {
|
|
227
|
+
records: A2aTaskRecord[];
|
|
228
|
+
total: number;
|
|
229
|
+
};
|
|
230
|
+
/** A conversation's transcript. */
|
|
231
|
+
conversation(contextId: string): Message[] | undefined;
|
|
232
|
+
/** Writes a conversation's transcript. */
|
|
233
|
+
saveConversation(contextId: string, messages: Message[]): void;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Tasks and conversations in any long-term `Store`: the memory, Redis, Postgres, or SQLite store, so
|
|
237
|
+
* every replica sees one set. Listing filters on the task's fields in the store; it does not count
|
|
238
|
+
* all matches, so `total` is unknown.
|
|
239
|
+
*/
|
|
240
|
+
export declare function storeA2aTasks(store: Store, options?: {
|
|
241
|
+
namespace?: readonly string[];
|
|
242
|
+
}): A2aTaskStore;
|
|
243
|
+
/** Options for pushing task updates to the webhooks callers give. */
|
|
244
|
+
export interface A2aPushOptions {
|
|
245
|
+
/**
|
|
246
|
+
* Signs every delivery with an \`x-nexus-signature\` header, as the server's operation webhooks are,
|
|
247
|
+
* so a receiver checks it with \`verifyOperationWebhook()\` from \`nexus-ai-pro/operations\`.
|
|
248
|
+
*/
|
|
249
|
+
secret?: string;
|
|
250
|
+
/**
|
|
251
|
+
* Allows webhooks on loopback, private, and link-local addresses, and plain \`http\`. Off by default,
|
|
252
|
+
* so a caller cannot make the agent reach into its own network. Turn it on for tests, or when every
|
|
253
|
+
* caller is trusted.
|
|
254
|
+
*/
|
|
255
|
+
allowPrivateNetworks?: boolean;
|
|
256
|
+
/** Replaces \`fetch\` for deliveries: a client with its own address checks, a proxy, or a test. */
|
|
257
|
+
fetch?: typeof globalThis.fetch;
|
|
258
|
+
/** How long one delivery may take, in milliseconds. Defaults to 5 seconds. */
|
|
259
|
+
timeoutMs?: number;
|
|
260
|
+
}
|
|
155
261
|
/** Options for `a2aHandler()`. */
|
|
156
262
|
export interface A2aServerOptions {
|
|
157
263
|
/** The card's content: the endpoint `url` is where this handler is mounted. */
|
|
@@ -170,8 +276,25 @@ export interface A2aServerOptions {
|
|
|
170
276
|
answer?: (message: A2aMessage, interrupt: ProtocolInterrupt) => unknown;
|
|
171
277
|
/** Who the task is for, from the request: the place to authenticate the calling agent. */
|
|
172
278
|
principal?: (request: Request) => Principal | undefined | Promise<Principal | undefined>;
|
|
173
|
-
/**
|
|
279
|
+
/**
|
|
280
|
+
* Where tasks and conversations are kept. Defaults to memory, for one replica; \`storeA2aTasks()\`
|
|
281
|
+
* keeps them in a shared store. A task resumed elsewhere needs the graph's own checkpointer to be
|
|
282
|
+
* shared too.
|
|
283
|
+
*/
|
|
284
|
+
store?: A2aTaskStore;
|
|
285
|
+
/** Most tasks and contexts the default memory store keeps. Defaults to 10,000 each. */
|
|
174
286
|
maxTasks?: number;
|
|
287
|
+
/** Pushes each task's updates to the webhooks callers give. Without it, push notifications are not offered. */
|
|
288
|
+
pushNotifications?: A2aPushOptions;
|
|
289
|
+
/**
|
|
290
|
+
* The extended card an authenticated caller may read with `GetExtendedAgentCard`: more skills, or
|
|
291
|
+
* anything else this caller may see. Without it, there is no extended card.
|
|
292
|
+
*/
|
|
293
|
+
extendedCard?: (principal: Principal) => Partial<A2aAgentCard> | Promise<Partial<A2aAgentCard>>;
|
|
294
|
+
/** How often `SubscribeToTask` reads a task another replica runs, in milliseconds. Defaults to 1 second. */
|
|
295
|
+
pollMs?: number;
|
|
296
|
+
/** Receives push delivery failures, which never fail a task. */
|
|
297
|
+
onError?: (error: unknown) => void;
|
|
175
298
|
}
|
|
176
299
|
/**
|
|
177
300
|
* An HTTP handler that serves a graph as an A2A agent: `GET` the card, `POST` JSON-RPC. Mount it
|
|
@@ -201,21 +324,63 @@ export interface A2aSendOptions {
|
|
|
201
324
|
taskId?: string;
|
|
202
325
|
/** Structured data sent beside the text, such as `{ approved: true }`. */
|
|
203
326
|
data?: unknown;
|
|
327
|
+
/** A webhook for this task's updates, when the agent pushes them. */
|
|
328
|
+
push?: A2aPushNotificationConfig;
|
|
329
|
+
/** Returns the task while it runs, instead of when it is done. */
|
|
330
|
+
returnImmediately?: boolean;
|
|
204
331
|
/** Cancels the request. */
|
|
205
332
|
signal?: AbortSignal;
|
|
206
333
|
}
|
|
334
|
+
/** Which tasks `A2aClient.listTasks()` asks for. */
|
|
335
|
+
export interface A2aListTasksOptions {
|
|
336
|
+
/** Only this conversation's. */
|
|
337
|
+
contextId?: string;
|
|
338
|
+
/** Only those in this state. */
|
|
339
|
+
status?: A2aTaskState;
|
|
340
|
+
/** Tasks per page, up to 100. Defaults to 50. */
|
|
341
|
+
pageSize?: number;
|
|
342
|
+
/** The `nextPageToken` of the page before. */
|
|
343
|
+
pageToken?: string;
|
|
344
|
+
/** Messages of each task's history to include. */
|
|
345
|
+
historyLength?: number;
|
|
346
|
+
}
|
|
347
|
+
/** A page of tasks. */
|
|
348
|
+
export interface A2aTaskPage {
|
|
349
|
+
/** The tasks. */
|
|
350
|
+
tasks: A2aTask[];
|
|
351
|
+
/** The token for the next page, or empty when this is the last. */
|
|
352
|
+
nextPageToken: string;
|
|
353
|
+
/** The page size used. */
|
|
354
|
+
pageSize: number;
|
|
355
|
+
/** How many tasks match, when the agent's store counts them. */
|
|
356
|
+
totalSize?: number;
|
|
357
|
+
}
|
|
207
358
|
/** A client for one A2A agent. */
|
|
208
359
|
export interface A2aClient {
|
|
209
360
|
/** The agent's card, fetched once. */
|
|
210
361
|
card(): Promise<A2aAgentCard>;
|
|
362
|
+
/** The card for an authenticated caller, as `GetExtendedAgentCard` returns it. */
|
|
363
|
+
extendedCard(): Promise<A2aAgentCard>;
|
|
211
364
|
/** Sends a message and waits for the task it starts or continues. */
|
|
212
365
|
send(text: string, options?: A2aSendOptions): Promise<A2aTask>;
|
|
213
366
|
/** Sends a message and reads the task's events as they arrive. */
|
|
214
367
|
stream(text: string, options?: A2aSendOptions): AsyncGenerator<A2aStreamEvent>;
|
|
215
368
|
/** Reads a task. */
|
|
216
369
|
getTask(taskId: string, historyLength?: number): Promise<A2aTask>;
|
|
370
|
+
/** Lists tasks, a page at a time. */
|
|
371
|
+
listTasks(options?: A2aListTasksOptions): Promise<A2aTaskPage>;
|
|
372
|
+
/** Follows a task that is still running, from now until it finishes or waits. */
|
|
373
|
+
subscribe(taskId: string, options?: {
|
|
374
|
+
signal?: AbortSignal;
|
|
375
|
+
}): AsyncGenerator<A2aStreamEvent>;
|
|
217
376
|
/** Cancels a task. */
|
|
218
377
|
cancel(taskId: string): Promise<A2aTask>;
|
|
378
|
+
/** Adds a webhook for a task's updates. */
|
|
379
|
+
setPushNotification(taskId: string, config: A2aPushNotificationConfig): Promise<A2aPushNotificationConfig>;
|
|
380
|
+
/** A task's webhooks. */
|
|
381
|
+
listPushNotifications(taskId: string): Promise<A2aPushNotificationConfig[]>;
|
|
382
|
+
/** Removes one of a task's webhooks. */
|
|
383
|
+
deletePushNotification(taskId: string, configId: string): Promise<void>;
|
|
219
384
|
}
|
|
220
385
|
/** A client for an A2A agent, by its card or endpoint URL. */
|
|
221
386
|
export declare function a2aClient(options: A2aClientOptions): A2aClient;
|