@nextclaw/ncp 0.5.0 → 0.5.2

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +596 -598
  2. package/dist/index.js +254 -291
  3. package/package.json +2 -3
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/types/message.d.ts
1
2
  /**
2
3
  * Participants in an NCP conversation.
3
4
  *
@@ -23,8 +24,8 @@ declare function isHiddenNcpMessage(message: Pick<NcpMessage, "metadata"> | null
23
24
  type NcpMessageStatus = "pending" | "streaming" | "final" | "error";
24
25
  /** Plain text content. The most common part type. */
25
26
  type NcpTextPart = {
26
- type: "text";
27
- text: string;
27
+ type: "text";
28
+ text: string;
28
29
  };
29
30
  /**
30
31
  * A file attachment, delivered either as a URL or inline Base64 content.
@@ -32,39 +33,34 @@ type NcpTextPart = {
32
33
  * `url` and `contentBase64` are mutually exclusive — populate exactly one.
33
34
  */
34
35
  type NcpFilePart = {
35
- type: "file";
36
- name?: string;
37
- mimeType?: string;
38
- /** Stable logical asset reference managed by the hosting app. */
39
- assetUri?: string;
40
- /** Remote URL pointing to the file. Mutually exclusive with `contentBase64`. */
41
- url?: string;
42
- /** Inline file content encoded as Base64. Mutually exclusive with `url`. */
43
- contentBase64?: string;
44
- sizeBytes?: number;
36
+ type: "file";
37
+ name?: string;
38
+ mimeType?: string; /** Stable logical asset reference managed by the hosting app. */
39
+ assetUri?: string; /** Remote URL pointing to the file. Mutually exclusive with `contentBase64`. */
40
+ url?: string; /** Inline file content encoded as Base64. Mutually exclusive with `url`. */
41
+ contentBase64?: string;
42
+ sizeBytes?: number;
45
43
  };
46
44
  /** A cited source or reference, typically surfaced alongside AI-generated content. */
47
45
  type NcpSourcePart = {
48
- type: "source";
49
- title?: string;
50
- url?: string;
51
- /** Short excerpt from the source relevant to the message. */
52
- snippet?: string;
46
+ type: "source";
47
+ title?: string;
48
+ url?: string; /** Short excerpt from the source relevant to the message. */
49
+ snippet?: string;
53
50
  };
54
51
  /**
55
52
  * Marks the beginning of a logical reasoning step in a multi-step response.
56
53
  * Used by chain-of-thought or agentic flows to delimit discrete steps.
57
54
  */
58
55
  type NcpStepStartPart = {
59
- type: "step-start";
60
- stepId?: string;
61
- /** Human-readable label for the step (e.g. "Searching the web"). */
62
- title?: string;
56
+ type: "step-start";
57
+ stepId?: string; /** Human-readable label for the step (e.g. "Searching the web"). */
58
+ title?: string;
63
59
  };
64
60
  /** Internal reasoning text produced by the model before its final response. */
65
61
  type NcpReasoningPart = {
66
- type: "reasoning";
67
- text: string;
62
+ type: "reasoning";
63
+ text: string;
68
64
  };
69
65
  /**
70
66
  * Represents a tool call and its lifecycle.
@@ -75,40 +71,36 @@ type NcpReasoningPart = {
75
71
  * - `"result"` — The tool has returned; `result` is populated.
76
72
  */
77
73
  type NcpToolInvocationPart = {
78
- type: "tool-invocation";
79
- toolName: string;
80
- toolCallId?: string;
81
- state?: "call" | "partial-call" | "result";
82
- /** Tool input arguments. May be partial when `state === "partial-call"`. */
83
- args?: unknown;
84
- /** Tool output. Populated when `state === "result"`. */
85
- result?: unknown;
74
+ type: "tool-invocation";
75
+ toolName: string;
76
+ toolCallId?: string;
77
+ state?: "call" | "partial-call" | "result"; /** Tool input arguments. May be partial when `state === "partial-call"`. */
78
+ args?: unknown; /** Tool output. Populated when `state === "result"`. */
79
+ result?: unknown;
86
80
  };
87
81
  /**
88
82
  * A rich card with arbitrary structured data.
89
83
  * Rendering is delegated to the platform (e.g. Slack block kit, Teams card).
90
84
  */
91
85
  type NcpCardPart = {
92
- type: "card";
93
- payload: Record<string, unknown>;
86
+ type: "card";
87
+ payload: Record<string, unknown>;
94
88
  };
95
89
  /** Formatted text with an explicit markup format hint. */
96
90
  type NcpRichTextPart = {
97
- type: "rich-text";
98
- format: "markdown" | "html" | "plain";
99
- text: string;
91
+ type: "rich-text";
92
+ format: "markdown" | "html" | "plain";
93
+ text: string;
100
94
  };
101
95
  /**
102
96
  * An interactive action button or trigger exposed to the user.
103
97
  * The platform is responsible for rendering and routing the action.
104
98
  */
105
99
  type NcpActionPart = {
106
- type: "action";
107
- actionId: string;
108
- /** Display label shown to the user. */
109
- label: string;
110
- /** Arbitrary data forwarded to the action handler. */
111
- payload?: unknown;
100
+ type: "action";
101
+ actionId: string; /** Display label shown to the user. */
102
+ label: string; /** Arbitrary data forwarded to the action handler. */
103
+ payload?: unknown;
112
104
  };
113
105
  /**
114
106
  * Escape hatch for custom or future part types not yet in the NCP spec.
@@ -117,10 +109,9 @@ type NcpActionPart = {
117
109
  * Once a part type stabilizes, promote it to a first-class `NcpXxxPart`.
118
110
  */
119
111
  type NcpExtensionPart = {
120
- type: "extension";
121
- /** Namespaced identifier for the custom part (e.g. `"myapp.highlight"`). */
122
- extensionType: string;
123
- data: unknown;
112
+ type: "extension"; /** Namespaced identifier for the custom part (e.g. `"myapp.highlight"`). */
113
+ extensionType: string;
114
+ data: unknown;
124
115
  };
125
116
  /** Union of all recognized NCP message part types. */
126
117
  type NcpMessagePart = NcpTextPart | NcpFilePart | NcpSourcePart | NcpStepStartPart | NcpReasoningPart | NcpToolInvocationPart | NcpCardPart | NcpRichTextPart | NcpActionPart | NcpExtensionPart;
@@ -131,19 +122,16 @@ type NcpMessagePart = NcpTextPart | NcpFilePart | NcpSourcePart | NcpStepStartPa
131
122
  * heterogeneous content (text, files, tool calls, etc.) in a single message.
132
123
  */
133
124
  type NcpMessage = {
134
- /** Globally unique message identifier. */
135
- id: string;
136
- /** The session this message belongs to. */
137
- sessionId: string;
138
- role: NcpMessageRole;
139
- status: NcpMessageStatus;
140
- parts: NcpMessagePart[];
141
- /** ISO 8601 timestamp (e.g. `"2024-01-15T10:30:00.000Z"`). */
142
- timestamp: string;
143
- /** Arbitrary transport- or application-level metadata. */
144
- metadata?: Record<string, unknown>;
145
- };
146
-
125
+ /** Globally unique message identifier. */id: string; /** The session this message belongs to. */
126
+ sessionId: string;
127
+ role: NcpMessageRole;
128
+ status: NcpMessageStatus;
129
+ parts: NcpMessagePart[]; /** ISO 8601 timestamp (e.g. `"2024-01-15T10:30:00.000Z"`). */
130
+ timestamp: string; /** Arbitrary transport- or application-level metadata. */
131
+ metadata?: Record<string, unknown>;
132
+ };
133
+ //#endregion
134
+ //#region src/types/manifest.d.ts
147
135
  /**
148
136
  * High-level category of an endpoint.
149
137
  *
@@ -170,32 +158,24 @@ type NcpEndpointLatency = "realtime" | "seconds" | "minutes" | "hours" | "days";
170
158
  * or whether an existing run can be streamed again.
171
159
  */
172
160
  type NcpEndpointManifest = {
173
- /** Category of this endpoint. */
174
- endpointKind: NcpEndpointKind;
175
- /** Stable unique identifier for this endpoint instance. */
176
- endpointId: string;
177
- /** SemVer string for the adapter implementation. */
178
- version: string;
179
- /** Whether this endpoint supports incremental streaming of message content. */
180
- supportsStreaming: boolean;
181
- /** Whether in-flight requests can be cancelled via `AbortSignal`. */
182
- supportsAbort: boolean;
183
- /** Whether this endpoint can push messages without a prior user request. */
184
- supportsProactiveMessages: boolean;
185
- /** Whether this endpoint can stream the live events of an active session by `sessionId`. */
186
- supportsLiveSessionStream: boolean;
187
- /**
188
- * The subset of `NcpMessagePart` types this endpoint can send or receive.
189
- * Using the literal union from `NcpMessagePart["type"]` prevents typos
190
- * and keeps the manifest in sync with the protocol definition.
191
- */
192
- supportedPartTypes: ReadonlyArray<NcpMessagePart["type"]>;
193
- /** Expected response latency — informs timeouts and UX treatment. */
194
- expectedLatency: NcpEndpointLatency;
195
- /** Arbitrary adapter- or deployment-specific metadata. */
196
- metadata?: Record<string, unknown>;
197
- };
198
-
161
+ /** Category of this endpoint. */endpointKind: NcpEndpointKind; /** Stable unique identifier for this endpoint instance. */
162
+ endpointId: string; /** SemVer string for the adapter implementation. */
163
+ version: string; /** Whether this endpoint supports incremental streaming of message content. */
164
+ supportsStreaming: boolean; /** Whether in-flight requests can be cancelled via `AbortSignal`. */
165
+ supportsAbort: boolean; /** Whether this endpoint can push messages without a prior user request. */
166
+ supportsProactiveMessages: boolean; /** Whether this endpoint can stream the live events of an active session by `sessionId`. */
167
+ supportsLiveSessionStream: boolean;
168
+ /**
169
+ * The subset of `NcpMessagePart` types this endpoint can send or receive.
170
+ * Using the literal union from `NcpMessagePart["type"]` prevents typos
171
+ * and keeps the manifest in sync with the protocol definition.
172
+ */
173
+ supportedPartTypes: ReadonlyArray<NcpMessagePart["type"]>; /** Expected response latency informs timeouts and UX treatment. */
174
+ expectedLatency: NcpEndpointLatency; /** Arbitrary adapter- or deployment-specific metadata. */
175
+ metadata?: Record<string, unknown>;
176
+ };
177
+ //#endregion
178
+ //#region src/types/errors.d.ts
199
179
  /**
200
180
  * Protocol-level error categories.
201
181
  *
@@ -210,48 +190,132 @@ type NcpErrorCode = "config-error" | "auth-error" | "runtime-error" | "timeout-e
210
190
  * boundaries so that error metadata survives serialization.
211
191
  */
212
192
  type NcpError = {
213
- /** Machine-readable category. */
214
- code: NcpErrorCode;
215
- /** Human-readable description intended for developers, not end-users. */
216
- message: string;
217
- /** Optional structured context (request ids, field paths, etc.). */
218
- details?: Record<string, unknown>;
219
- /** Original cause — preserved for debugging but not guaranteed serializable. */
220
- cause?: unknown;
193
+ /** Machine-readable category. */code: NcpErrorCode; /** Human-readable description intended for developers, not end-users. */
194
+ message: string; /** Optional structured context (request ids, field paths, etc.). */
195
+ details?: Record<string, unknown>; /** Original cause preserved for debugging but not guaranteed serializable. */
196
+ cause?: unknown;
221
197
  };
222
-
198
+ //#endregion
199
+ //#region src/types/session.d.ts
223
200
  type NcpSessionStatus = "idle" | "running";
224
201
  type NcpSessionSummary = {
225
- sessionId: string;
226
- agentId?: string;
227
- messageCount: number;
228
- updatedAt: string;
229
- status?: NcpSessionStatus;
230
- metadata?: Record<string, unknown>;
202
+ sessionId: string;
203
+ agentId?: string;
204
+ messageCount: number;
205
+ updatedAt: string;
206
+ lastMessageAt?: string;
207
+ status?: NcpSessionStatus;
208
+ metadata?: Record<string, unknown>;
231
209
  };
232
210
  type ListSessionsOptions = {
233
- limit?: number;
234
- cursor?: string;
211
+ limit?: number;
212
+ cursor?: string;
235
213
  };
236
214
  type ListMessagesOptions = {
237
- limit?: number;
238
- cursor?: string;
215
+ limit?: number;
216
+ cursor?: string;
239
217
  };
240
218
  type NcpSessionPatch = {
241
- metadata?: Record<string, unknown> | null;
219
+ metadata?: Record<string, unknown> | null;
242
220
  };
243
221
  /**
244
222
  * API for session list, message history, and session lifecycle.
245
223
  * Implementations that support persistence can provide this alongside NcpAgentClientEndpoint.
246
224
  */
247
225
  interface NcpSessionApi {
248
- listSessions(options?: ListSessionsOptions): Promise<NcpSessionSummary[]>;
249
- listSessionMessages(sessionId: string, options?: ListMessagesOptions): Promise<NcpMessage[]>;
250
- getSession(sessionId: string): Promise<NcpSessionSummary | null>;
251
- updateSession(sessionId: string, patch: NcpSessionPatch): Promise<NcpSessionSummary | null>;
252
- deleteSession(sessionId: string): Promise<void>;
226
+ listSessions(options?: ListSessionsOptions): Promise<NcpSessionSummary[]>;
227
+ listSessionMessages(sessionId: string, options?: ListMessagesOptions): Promise<NcpMessage[]>;
228
+ getSession(sessionId: string): Promise<NcpSessionSummary | null>;
229
+ updateSession(sessionId: string, patch: NcpSessionPatch): Promise<NcpSessionSummary | null>;
230
+ deleteSession(sessionId: string): Promise<void>;
253
231
  }
254
-
232
+ //#endregion
233
+ //#region src/agent-runtime/llm-api.d.ts
234
+ type OpenAIContentPart = {
235
+ type: "text";
236
+ text: string;
237
+ } | {
238
+ type: "image_url";
239
+ image_url: {
240
+ url: string;
241
+ detail?: "low" | "high" | "auto";
242
+ };
243
+ };
244
+ type OpenAIToolCall = {
245
+ id: string;
246
+ type: "function";
247
+ function: {
248
+ name: string;
249
+ arguments: string;
250
+ };
251
+ };
252
+ type OpenAIChatMessage = {
253
+ role: "system";
254
+ content: string;
255
+ } | {
256
+ role: "user";
257
+ content: string | OpenAIContentPart[];
258
+ } | {
259
+ role: "assistant";
260
+ content?: string | null;
261
+ reasoning_content?: string;
262
+ tool_calls?: OpenAIToolCall[];
263
+ } | {
264
+ role: "tool";
265
+ content: string;
266
+ tool_call_id: string;
267
+ };
268
+ type OpenAITool = {
269
+ type: "function";
270
+ function: {
271
+ name: string;
272
+ description?: string;
273
+ parameters?: Record<string, unknown>;
274
+ };
275
+ };
276
+ type OpenAIToolCallDelta = {
277
+ index?: number;
278
+ id?: string;
279
+ type?: "function";
280
+ function?: {
281
+ name?: string;
282
+ arguments?: string;
283
+ };
284
+ };
285
+ type OpenAIChatChunk = {
286
+ id?: string;
287
+ choices?: Array<{
288
+ index?: number;
289
+ delta?: {
290
+ content?: string | null;
291
+ tool_calls?: OpenAIToolCallDelta[];
292
+ reasoning_content?: string;
293
+ reasoning?: string;
294
+ };
295
+ finish_reason?: string | null;
296
+ }>;
297
+ usage?: {
298
+ prompt_tokens?: number;
299
+ completion_tokens?: number;
300
+ total_tokens?: number;
301
+ };
302
+ };
303
+ type NcpLLMApiInput = {
304
+ messages: OpenAIChatMessage[];
305
+ tools?: OpenAITool[];
306
+ model?: string;
307
+ thinkingLevel?: string | null;
308
+ max_tokens?: number;
309
+ };
310
+ type NcpLLMApiOptions = {
311
+ signal?: AbortSignal;
312
+ temperature?: number;
313
+ };
314
+ interface NcpLLMApi {
315
+ generate(input: NcpLLMApiInput, options?: NcpLLMApiOptions): AsyncIterable<OpenAIChatChunk>;
316
+ }
317
+ //#endregion
318
+ //#region src/types/events.d.ts
255
319
  /**
256
320
  * NCP event and payload definitions.
257
321
  *
@@ -260,329 +324,335 @@ interface NcpSessionApi {
260
324
  * instead; endpoints or upper layers choose as needed.
261
325
  */
262
326
  type NcpRequestEnvelope = {
263
- sessionId: string;
264
- message: NcpMessage;
265
- correlationId?: string;
266
- metadata?: Record<string, unknown>;
327
+ sessionId: string;
328
+ message: NcpMessage;
329
+ correlationId?: string;
330
+ metadata?: Record<string, unknown>;
331
+ providerRoute?: NcpProviderRuntimeRoute;
332
+ tools?: ReadonlyArray<OpenAITool>;
333
+ };
334
+ type NcpProviderRuntimeRoute = {
335
+ model: string;
336
+ apiKey?: string | null;
337
+ apiBase?: string | null;
338
+ headers: Record<string, string>;
267
339
  };
268
340
  /** Payload for message.incoming: message content from the other peer (partial or full). */
269
341
  type NcpResponseEnvelope = {
270
- sessionId: string;
271
- message: NcpMessage;
272
- correlationId?: string;
273
- metadata?: Record<string, unknown>;
342
+ sessionId: string;
343
+ message: NcpMessage;
344
+ correlationId?: string;
345
+ metadata?: Record<string, unknown>;
274
346
  };
275
347
  type NcpCompletedEnvelope = {
276
- sessionId: string;
277
- message: NcpMessage;
278
- correlationId?: string;
279
- metadata?: Record<string, unknown>;
348
+ sessionId: string;
349
+ message: NcpMessage;
350
+ correlationId?: string;
351
+ metadata?: Record<string, unknown>;
280
352
  };
281
353
  type NcpFailedEnvelope = {
282
- sessionId: string;
283
- messageId?: string;
284
- error: NcpError;
285
- correlationId?: string;
286
- metadata?: Record<string, unknown>;
354
+ sessionId: string;
355
+ messageId?: string;
356
+ error: NcpError;
357
+ correlationId?: string;
358
+ metadata?: Record<string, unknown>;
287
359
  };
288
360
  type NcpMessageAcceptedPayload = {
289
- messageId: string;
290
- correlationId?: string;
291
- transportId?: string;
361
+ messageId: string;
362
+ correlationId?: string;
363
+ transportId?: string;
292
364
  };
293
365
  /** Payload for message.abort: identifies which session's active execution to cancel. */
294
366
  type NcpMessageAbortPayload = {
295
- sessionId: string;
296
- messageId?: string;
367
+ sessionId: string;
368
+ messageId?: string;
297
369
  };
298
370
  /**
299
371
  * Payload for message.stream-request: attach to the live event stream of a session.
300
372
  * Used when reconnecting during an active response or attaching another live reader.
301
373
  */
302
374
  type NcpStreamRequestPayload = {
303
- sessionId: string;
304
- metadata?: Record<string, unknown>;
375
+ sessionId: string;
376
+ metadata?: Record<string, unknown>;
305
377
  };
306
378
  /**
307
379
  * Payload for message.sent: the local peer has sent a message (outbound).
308
380
  * Typically non-streaming; add the message to the local conversation state.
309
381
  */
310
382
  type NcpMessageSentPayload = {
311
- sessionId: string;
312
- message: NcpMessage;
313
- metadata?: Record<string, unknown>;
383
+ sessionId: string;
384
+ message: NcpMessage;
385
+ metadata?: Record<string, unknown>;
314
386
  };
315
387
  type NcpTypingStartPayload = {
316
- sessionId: string;
317
- /** Participant who is typing (human user or bot/assistant). */
318
- userId?: string;
388
+ sessionId: string; /** Participant who is typing (human user or bot/assistant). */
389
+ userId?: string;
319
390
  };
320
391
  type NcpTypingEndPayload = {
321
- sessionId: string;
322
- /** Participant who stopped typing (human user or bot/assistant). */
323
- userId?: string;
392
+ sessionId: string; /** Participant who stopped typing (human user or bot/assistant). */
393
+ userId?: string;
324
394
  };
325
395
  type NcpPresenceUpdatedPayload = {
326
- sessionId: string;
327
- /** Participant this presence applies to (human user or bot/assistant). */
328
- userId?: string;
329
- status: "online" | "offline" | "away";
396
+ sessionId: string; /** Participant this presence applies to (human user or bot/assistant). */
397
+ userId?: string;
398
+ status: "online" | "offline" | "away";
330
399
  };
331
400
  type NcpMessageReadPayload = {
332
- sessionId: string;
333
- messageId: string;
334
- readAt?: string;
335
- readerId?: string;
401
+ sessionId: string;
402
+ messageId: string;
403
+ readAt?: string;
404
+ readerId?: string;
336
405
  };
337
406
  type NcpMessageDeliveredPayload = {
338
- sessionId: string;
339
- messageId: string;
407
+ sessionId: string;
408
+ messageId: string;
340
409
  };
341
410
  type NcpMessageRecalledPayload = {
342
- sessionId: string;
343
- messageId: string;
411
+ sessionId: string;
412
+ messageId: string;
344
413
  };
345
414
  type NcpMessageReactionPayload = {
346
- sessionId: string;
347
- messageId: string;
348
- reaction: string;
349
- added: boolean;
350
- /** Participant who added or removed the reaction (human user or bot/assistant). */
351
- userId?: string;
415
+ sessionId: string;
416
+ messageId: string;
417
+ reaction: string;
418
+ added: boolean; /** Participant who added or removed the reaction (human user or bot/assistant). */
419
+ userId?: string;
352
420
  };
353
421
  type NcpRunStartedPayload = {
354
- sessionId?: string;
355
- messageId?: string;
356
- threadId?: string;
357
- runId?: string;
422
+ sessionId?: string;
423
+ messageId?: string;
424
+ threadId?: string;
425
+ runId?: string;
358
426
  };
359
427
  type NcpRunFinishedPayload = {
360
- sessionId?: string;
361
- messageId?: string;
362
- threadId?: string;
363
- runId?: string;
428
+ sessionId?: string;
429
+ messageId?: string;
430
+ threadId?: string;
431
+ runId?: string;
364
432
  };
365
433
  type NcpRunErrorPayload = {
366
- sessionId?: string;
367
- messageId?: string;
368
- error?: string;
369
- threadId?: string;
370
- runId?: string;
434
+ sessionId?: string;
435
+ messageId?: string;
436
+ error?: string;
437
+ threadId?: string;
438
+ runId?: string;
371
439
  };
372
440
  type NcpRunMetadataPayload = {
373
- sessionId?: string;
374
- messageId?: string;
375
- runId?: string;
376
- metadata: Record<string, unknown>;
441
+ sessionId?: string;
442
+ messageId?: string;
443
+ runId?: string;
444
+ metadata: Record<string, unknown>;
377
445
  };
378
446
  type NcpTextStartPayload = {
379
- sessionId: string;
380
- messageId: string;
447
+ sessionId: string;
448
+ messageId: string;
381
449
  };
382
450
  type NcpTextDeltaPayload = {
383
- sessionId: string;
384
- messageId: string;
385
- delta: string;
451
+ sessionId: string;
452
+ messageId: string;
453
+ delta: string;
386
454
  };
387
455
  type NcpTextEndPayload = {
388
- sessionId: string;
389
- messageId: string;
456
+ sessionId: string;
457
+ messageId: string;
390
458
  };
391
459
  type NcpReasoningStartPayload = {
392
- sessionId: string;
393
- messageId: string;
460
+ sessionId: string;
461
+ messageId: string;
394
462
  };
395
463
  type NcpReasoningDeltaPayload = {
396
- sessionId: string;
397
- messageId: string;
398
- delta: string;
464
+ sessionId: string;
465
+ messageId: string;
466
+ delta: string;
399
467
  };
400
468
  type NcpReasoningEndPayload = {
401
- sessionId: string;
402
- messageId: string;
469
+ sessionId: string;
470
+ messageId: string;
403
471
  };
404
472
  type NcpToolCallStartPayload = {
405
- sessionId: string;
406
- messageId?: string;
407
- toolCallId: string;
408
- toolName: string;
473
+ sessionId: string;
474
+ messageId?: string;
475
+ toolCallId: string;
476
+ toolName: string;
409
477
  };
410
478
  type NcpToolCallArgsPayload = {
411
- sessionId: string;
412
- toolCallId: string;
413
- args: string;
479
+ sessionId: string;
480
+ toolCallId: string;
481
+ args: string;
414
482
  };
415
483
  type NcpToolCallArgsDeltaPayload = {
416
- sessionId: string;
417
- messageId?: string;
418
- toolCallId: string;
419
- delta: string;
484
+ sessionId: string;
485
+ messageId?: string;
486
+ toolCallId: string;
487
+ delta: string;
420
488
  };
421
489
  type NcpToolCallEndPayload = {
422
- sessionId: string;
423
- toolCallId: string;
490
+ sessionId: string;
491
+ toolCallId: string;
424
492
  };
425
493
  type NcpToolCallResultPayload = {
426
- sessionId: string;
427
- toolCallId: string;
428
- content: unknown;
494
+ sessionId: string;
495
+ toolCallId: string;
496
+ content: unknown;
429
497
  };
430
498
  declare enum NcpEventType {
431
- EndpointReady = "endpoint.ready",
432
- EndpointError = "endpoint.error",
433
- MessageRequest = "message.request",
434
- MessageStreamRequest = "message.stream-request",
435
- MessageSent = "message.sent",
436
- MessageAccepted = "message.accepted",
437
- MessageIncoming = "message.incoming",
438
- MessageCompleted = "message.completed",
439
- MessageFailed = "message.failed",
440
- MessageAbort = "message.abort",
441
- MessageTextStart = "message.text-start",
442
- MessageTextDelta = "message.text-delta",
443
- MessageTextEnd = "message.text-end",
444
- MessageReasoningStart = "message.reasoning-start",
445
- MessageReasoningDelta = "message.reasoning-delta",
446
- MessageReasoningEnd = "message.reasoning-end",
447
- MessageToolCallStart = "message.tool-call-start",
448
- MessageToolCallArgs = "message.tool-call-args",
449
- MessageToolCallArgsDelta = "message.tool-call-args-delta",
450
- MessageToolCallEnd = "message.tool-call-end",
451
- MessageToolCallResult = "message.tool-call-result",
452
- MessageRead = "message.read",
453
- MessageDelivered = "message.delivered",
454
- MessageRecalled = "message.recalled",
455
- MessageReaction = "message.reaction",
456
- RunStarted = "run.started",
457
- RunFinished = "run.finished",
458
- RunError = "run.error",
459
- RunMetadata = "run.metadata",
460
- TypingStart = "typing.start",
461
- TypingEnd = "typing.end",
462
- PresenceUpdated = "presence.updated"
499
+ EndpointReady = "endpoint.ready",
500
+ EndpointError = "endpoint.error",
501
+ MessageRequest = "message.request",
502
+ MessageStreamRequest = "message.stream-request",
503
+ MessageSent = "message.sent",
504
+ MessageAccepted = "message.accepted",
505
+ MessageIncoming = "message.incoming",
506
+ MessageCompleted = "message.completed",
507
+ MessageFailed = "message.failed",
508
+ MessageAbort = "message.abort",
509
+ MessageTextStart = "message.text-start",
510
+ MessageTextDelta = "message.text-delta",
511
+ MessageTextEnd = "message.text-end",
512
+ MessageReasoningStart = "message.reasoning-start",
513
+ MessageReasoningDelta = "message.reasoning-delta",
514
+ MessageReasoningEnd = "message.reasoning-end",
515
+ MessageToolCallStart = "message.tool-call-start",
516
+ MessageToolCallArgs = "message.tool-call-args",
517
+ MessageToolCallArgsDelta = "message.tool-call-args-delta",
518
+ MessageToolCallEnd = "message.tool-call-end",
519
+ MessageToolCallResult = "message.tool-call-result",
520
+ MessageRead = "message.read",
521
+ MessageDelivered = "message.delivered",
522
+ MessageRecalled = "message.recalled",
523
+ MessageReaction = "message.reaction",
524
+ RunStarted = "run.started",
525
+ RunFinished = "run.finished",
526
+ RunError = "run.error",
527
+ RunMetadata = "run.metadata",
528
+ TypingStart = "typing.start",
529
+ TypingEnd = "typing.end",
530
+ PresenceUpdated = "presence.updated"
463
531
  }
464
532
  type NcpEndpointEvent = {
465
- type: NcpEventType.EndpointReady;
533
+ type: NcpEventType.EndpointReady;
466
534
  } | {
467
- type: NcpEventType.MessageRequest;
468
- payload: NcpRequestEnvelope;
535
+ type: NcpEventType.MessageRequest;
536
+ payload: NcpRequestEnvelope;
469
537
  } | {
470
- type: NcpEventType.MessageStreamRequest;
471
- payload: NcpStreamRequestPayload;
538
+ type: NcpEventType.MessageStreamRequest;
539
+ payload: NcpStreamRequestPayload;
472
540
  } | {
473
- type: NcpEventType.MessageSent;
474
- payload: NcpMessageSentPayload;
541
+ type: NcpEventType.MessageSent;
542
+ payload: NcpMessageSentPayload;
475
543
  } | {
476
- type: NcpEventType.MessageAccepted;
477
- payload: NcpMessageAcceptedPayload;
544
+ type: NcpEventType.MessageAccepted;
545
+ payload: NcpMessageAcceptedPayload;
478
546
  } | {
479
- type: NcpEventType.MessageIncoming;
480
- payload: NcpResponseEnvelope;
547
+ type: NcpEventType.MessageIncoming;
548
+ payload: NcpResponseEnvelope;
481
549
  } | {
482
- type: NcpEventType.MessageCompleted;
483
- payload: NcpCompletedEnvelope;
550
+ type: NcpEventType.MessageCompleted;
551
+ payload: NcpCompletedEnvelope;
484
552
  } | {
485
- type: NcpEventType.MessageFailed;
486
- payload: NcpFailedEnvelope;
553
+ type: NcpEventType.MessageFailed;
554
+ payload: NcpFailedEnvelope;
487
555
  } | {
488
- type: NcpEventType.MessageAbort;
489
- payload: NcpMessageAbortPayload;
556
+ type: NcpEventType.MessageAbort;
557
+ payload: NcpMessageAbortPayload;
490
558
  } | {
491
- type: NcpEventType.EndpointError;
492
- payload: NcpError;
559
+ type: NcpEventType.EndpointError;
560
+ payload: NcpError;
493
561
  } | {
494
- type: NcpEventType.RunStarted;
495
- payload: NcpRunStartedPayload;
562
+ type: NcpEventType.RunStarted;
563
+ payload: NcpRunStartedPayload;
496
564
  } | {
497
- type: NcpEventType.RunFinished;
498
- payload: NcpRunFinishedPayload;
565
+ type: NcpEventType.RunFinished;
566
+ payload: NcpRunFinishedPayload;
499
567
  } | {
500
- type: NcpEventType.RunError;
501
- payload: NcpRunErrorPayload;
568
+ type: NcpEventType.RunError;
569
+ payload: NcpRunErrorPayload;
502
570
  } | {
503
- type: NcpEventType.RunMetadata;
504
- payload: NcpRunMetadataPayload;
571
+ type: NcpEventType.RunMetadata;
572
+ payload: NcpRunMetadataPayload;
505
573
  } | {
506
- type: NcpEventType.MessageTextStart;
507
- payload: NcpTextStartPayload;
574
+ type: NcpEventType.MessageTextStart;
575
+ payload: NcpTextStartPayload;
508
576
  } | {
509
- type: NcpEventType.MessageTextDelta;
510
- payload: NcpTextDeltaPayload;
577
+ type: NcpEventType.MessageTextDelta;
578
+ payload: NcpTextDeltaPayload;
511
579
  } | {
512
- type: NcpEventType.MessageTextEnd;
513
- payload: NcpTextEndPayload;
580
+ type: NcpEventType.MessageTextEnd;
581
+ payload: NcpTextEndPayload;
514
582
  } | {
515
- type: NcpEventType.MessageReasoningStart;
516
- payload: NcpReasoningStartPayload;
583
+ type: NcpEventType.MessageReasoningStart;
584
+ payload: NcpReasoningStartPayload;
517
585
  } | {
518
- type: NcpEventType.MessageReasoningDelta;
519
- payload: NcpReasoningDeltaPayload;
586
+ type: NcpEventType.MessageReasoningDelta;
587
+ payload: NcpReasoningDeltaPayload;
520
588
  } | {
521
- type: NcpEventType.MessageReasoningEnd;
522
- payload: NcpReasoningEndPayload;
589
+ type: NcpEventType.MessageReasoningEnd;
590
+ payload: NcpReasoningEndPayload;
523
591
  } | {
524
- type: NcpEventType.MessageToolCallStart;
525
- payload: NcpToolCallStartPayload;
592
+ type: NcpEventType.MessageToolCallStart;
593
+ payload: NcpToolCallStartPayload;
526
594
  } | {
527
- type: NcpEventType.MessageToolCallArgs;
528
- payload: NcpToolCallArgsPayload;
595
+ type: NcpEventType.MessageToolCallArgs;
596
+ payload: NcpToolCallArgsPayload;
529
597
  } | {
530
- type: NcpEventType.MessageToolCallArgsDelta;
531
- payload: NcpToolCallArgsDeltaPayload;
598
+ type: NcpEventType.MessageToolCallArgsDelta;
599
+ payload: NcpToolCallArgsDeltaPayload;
532
600
  } | {
533
- type: NcpEventType.MessageToolCallEnd;
534
- payload: NcpToolCallEndPayload;
601
+ type: NcpEventType.MessageToolCallEnd;
602
+ payload: NcpToolCallEndPayload;
535
603
  } | {
536
- type: NcpEventType.MessageToolCallResult;
537
- payload: NcpToolCallResultPayload;
604
+ type: NcpEventType.MessageToolCallResult;
605
+ payload: NcpToolCallResultPayload;
538
606
  } | {
539
- type: NcpEventType.TypingStart;
540
- payload: NcpTypingStartPayload;
607
+ type: NcpEventType.TypingStart;
608
+ payload: NcpTypingStartPayload;
541
609
  } | {
542
- type: NcpEventType.TypingEnd;
543
- payload: NcpTypingEndPayload;
610
+ type: NcpEventType.TypingEnd;
611
+ payload: NcpTypingEndPayload;
544
612
  } | {
545
- type: NcpEventType.PresenceUpdated;
546
- payload: NcpPresenceUpdatedPayload;
613
+ type: NcpEventType.PresenceUpdated;
614
+ payload: NcpPresenceUpdatedPayload;
547
615
  } | {
548
- type: NcpEventType.MessageRead;
549
- payload: NcpMessageReadPayload;
616
+ type: NcpEventType.MessageRead;
617
+ payload: NcpMessageReadPayload;
550
618
  } | {
551
- type: NcpEventType.MessageDelivered;
552
- payload: NcpMessageDeliveredPayload;
619
+ type: NcpEventType.MessageDelivered;
620
+ payload: NcpMessageDeliveredPayload;
553
621
  } | {
554
- type: NcpEventType.MessageRecalled;
555
- payload: NcpMessageRecalledPayload;
622
+ type: NcpEventType.MessageRecalled;
623
+ payload: NcpMessageRecalledPayload;
556
624
  } | {
557
- type: NcpEventType.MessageReaction;
558
- payload: NcpMessageReactionPayload;
625
+ type: NcpEventType.MessageReaction;
626
+ payload: NcpMessageReactionPayload;
559
627
  };
560
628
  type NcpEndpointSubscriber = (event: NcpEndpointEvent) => void;
561
-
629
+ //#endregion
630
+ //#region src/types/run.d.ts
562
631
  /**
563
632
  * Run-related types: snapshot state and run.metadata schema conventions.
564
633
  * Not event payloads — event payloads live in events.ts.
565
634
  */
566
635
  /** Current run state for agent snapshot. Used by UI for run status and abort. */
567
636
  type NcpRunContext = {
568
- runId: string | null;
569
- sessionId?: string;
570
- abortDisabledReason?: string | null;
637
+ runId: string | null;
638
+ sessionId?: string;
639
+ abortDisabledReason?: string | null;
571
640
  };
572
641
  /** Schema for run.metadata.metadata when kind is "ready" (run started, backend ready). */
573
642
  type NcpRunReadyMetadata = {
574
- kind: "ready";
575
- runId?: string;
576
- sessionId?: string;
577
- supportsAbort?: boolean;
578
- abortDisabledReason?: string;
643
+ kind: "ready";
644
+ runId?: string;
645
+ sessionId?: string;
646
+ supportsAbort?: boolean;
647
+ abortDisabledReason?: string;
579
648
  };
580
649
  /** Schema for run.metadata.metadata when kind is "final" (run finished). */
581
650
  type NcpRunFinalMetadata = {
582
- kind: "final";
583
- sessionId?: string;
651
+ kind: "final";
652
+ sessionId?: string;
584
653
  };
585
-
654
+ //#endregion
655
+ //#region src/types/endpoint.d.ts
586
656
  /**
587
657
  * Core interface every NCP endpoint adapter must implement.
588
658
  *
@@ -597,40 +667,41 @@ type NcpRunFinalMetadata = {
597
667
  * await endpoint.emit({ type: NcpEventType.MessageRequest, payload: envelope });
598
668
  */
599
669
  interface NcpEndpoint {
600
- /** Static capability declaration — available before `start()` is called. */
601
- readonly manifest: NcpEndpointManifest;
602
- /**
603
- * Initializes the endpoint (opens connections, authenticates, etc.).
604
- * Must be called before `emit`. Idempotent — safe to call more than once.
605
- */
606
- start(): Promise<void>;
607
- /**
608
- * Gracefully shuts down the endpoint and releases resources.
609
- * Idempotent — safe to call more than once.
610
- */
611
- stop(): Promise<void>;
612
- /**
613
- * Sends an event to the remote participant (or broadcasts to local subscribers).
614
- *
615
- * For outbound events (e.g. message.request, message.abort), the implementation
616
- * forwards to the wire. For symmetric in-process setups, it may broadcast locally.
617
- */
618
- emit(event: NcpEndpointEvent): Promise<void>;
619
- /**
620
- * Subscribes to endpoint events.
621
- *
622
- * @param listener - Called for every event emitted by this endpoint.
623
- * @returns An unsubscribe function. Call it to stop receiving events.
624
- *
625
- * @example
626
- * const unsubscribe = endpoint.subscribe((event) => {
627
- * if (event.type === NcpEventType.MessageCompleted) handleReply(event.payload);
628
- * });
629
- * unsubscribe();
630
- */
631
- subscribe(listener: NcpEndpointSubscriber): () => void;
670
+ /** Static capability declaration — available before `start()` is called. */
671
+ readonly manifest: NcpEndpointManifest;
672
+ /**
673
+ * Initializes the endpoint (opens connections, authenticates, etc.).
674
+ * Must be called before `emit`. Idempotent — safe to call more than once.
675
+ */
676
+ start(): Promise<void>;
677
+ /**
678
+ * Gracefully shuts down the endpoint and releases resources.
679
+ * Idempotent — safe to call more than once.
680
+ */
681
+ stop(): Promise<void>;
682
+ /**
683
+ * Sends an event to the remote participant (or broadcasts to local subscribers).
684
+ *
685
+ * For outbound events (e.g. message.request, message.abort), the implementation
686
+ * forwards to the wire. For symmetric in-process setups, it may broadcast locally.
687
+ */
688
+ emit(event: NcpEndpointEvent): Promise<void>;
689
+ /**
690
+ * Subscribes to endpoint events.
691
+ *
692
+ * @param listener - Called for every event emitted by this endpoint.
693
+ * @returns An unsubscribe function. Call it to stop receiving events.
694
+ *
695
+ * @example
696
+ * const unsubscribe = endpoint.subscribe((event) => {
697
+ * if (event.type === NcpEventType.MessageCompleted) handleReply(event.payload);
698
+ * });
699
+ * unsubscribe();
700
+ */
701
+ subscribe(listener: NcpEndpointSubscriber): () => void;
632
702
  }
633
-
703
+ //#endregion
704
+ //#region src/endpoint/agent-client-endpoint.d.ts
634
705
  /**
635
706
  * Client-side endpoint for agent chat: initiates requests and can cancel in-flight runs.
636
707
  *
@@ -638,14 +709,15 @@ interface NcpEndpoint {
638
709
  * (e.g. frontend, CLI) that sends user messages and receives agent responses.
639
710
  */
640
711
  interface NcpAgentClientEndpoint extends NcpEndpoint {
641
- /** Sends a new message request to the agent. Emits `message.request`. */
642
- send(envelope: NcpRequestEnvelope): Promise<void>;
643
- /** Attaches to the live event stream of a session. Emits `message.stream-request`. */
644
- stream(payload: NcpStreamRequestPayload): Promise<void>;
645
- /** Aborts the active execution of a session. Emits `message.abort`. */
646
- abort(payload: NcpMessageAbortPayload): Promise<void>;
712
+ /** Sends a new message request to the agent. Emits `message.request`. */
713
+ send(envelope: NcpRequestEnvelope): Promise<void>;
714
+ /** Attaches to the live event stream of a session. Emits `message.stream-request`. */
715
+ stream(payload: NcpStreamRequestPayload): Promise<void>;
716
+ /** Aborts the active execution of a session. Emits `message.abort`. */
717
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
647
718
  }
648
-
719
+ //#endregion
720
+ //#region src/endpoint/agent-server-endpoint.d.ts
649
721
  /**
650
722
  * Agent server-side endpoint: receives requests and produces downstream events.
651
723
  *
@@ -654,235 +726,158 @@ interface NcpAgentClientEndpoint extends NcpEndpoint {
654
726
  * downstream events (`message.incoming`, streaming deltas, `message.completed`, etc.).
655
727
  */
656
728
  interface NcpAgentServerEndpoint extends NcpEndpoint {
657
- readonly manifest: NcpEndpointManifest & {
658
- endpointKind: "agent";
659
- };
660
- /** Handles a new message request from client side and yields produced events. */
661
- send(envelope: NcpRequestEnvelope, options?: {
662
- signal?: AbortSignal;
663
- }): AsyncIterable<NcpEndpointEvent>;
664
- /** Streams live events for an active session and yields produced events. */
665
- stream(payload: NcpStreamRequestPayload, options?: {
666
- signal?: AbortSignal;
667
- }): AsyncIterable<NcpEndpointEvent>;
668
- /** Aborts the active execution of a session on server side. */
669
- abort(payload: NcpMessageAbortPayload): Promise<void>;
670
- /**
671
- * Publishes server-downstream events (typically sent to frontend subscribers/transports).
672
- * For handling client requests, prefer `send` / `stream` / `abort`.
673
- */
674
- emit(event: NcpEndpointEvent): Promise<void>;
729
+ readonly manifest: NcpEndpointManifest & {
730
+ endpointKind: "agent";
731
+ };
732
+ /** Handles a new message request from client side and yields produced events. */
733
+ send(envelope: NcpRequestEnvelope, options?: {
734
+ signal?: AbortSignal;
735
+ }): AsyncIterable<NcpEndpointEvent>;
736
+ /** Streams live events for an active session and yields produced events. */
737
+ stream(payload: NcpStreamRequestPayload, options?: {
738
+ signal?: AbortSignal;
739
+ }): AsyncIterable<NcpEndpointEvent>;
740
+ /** Aborts the active execution of a session on server side. */
741
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
742
+ /**
743
+ * Publishes server-downstream events (typically sent to frontend subscribers/transports).
744
+ * For handling client requests, prefer `send` / `stream` / `abort`.
745
+ */
746
+ emit(event: NcpEndpointEvent): Promise<void>;
675
747
  }
676
-
748
+ //#endregion
749
+ //#region src/agent-runtime/runtime.d.ts
677
750
  type NcpAgentRunInput = {
678
- sessionId: string;
679
- messages: ReadonlyArray<NcpMessage>;
680
- correlationId?: string;
681
- metadata?: Record<string, unknown>;
751
+ sessionId: string;
752
+ messages: ReadonlyArray<NcpMessage>;
753
+ correlationId?: string;
754
+ metadata?: Record<string, unknown>;
682
755
  };
683
756
  type NcpAgentRunOptions = {
684
- signal?: AbortSignal;
757
+ signal?: AbortSignal;
685
758
  };
686
759
  interface NcpAgentRuntime {
687
- run(input: NcpAgentRunInput, options?: NcpAgentRunOptions): AsyncIterable<NcpEndpointEvent>;
760
+ run(input: NcpAgentRunInput, options?: NcpAgentRunOptions): AsyncIterable<NcpEndpointEvent>;
688
761
  }
689
-
690
- type OpenAIContentPart = {
691
- type: "text";
692
- text: string;
693
- } | {
694
- type: "image_url";
695
- image_url: {
696
- url: string;
697
- detail?: "low" | "high" | "auto";
698
- };
699
- };
700
- type OpenAIToolCall = {
701
- id: string;
702
- type: "function";
703
- function: {
704
- name: string;
705
- arguments: string;
706
- };
707
- };
708
- type OpenAIChatMessage = {
709
- role: "system";
710
- content: string;
711
- } | {
712
- role: "user";
713
- content: string | OpenAIContentPart[];
714
- } | {
715
- role: "assistant";
716
- content?: string | null;
717
- reasoning_content?: string;
718
- tool_calls?: OpenAIToolCall[];
719
- } | {
720
- role: "tool";
721
- content: string;
722
- tool_call_id: string;
723
- };
724
- type OpenAITool = {
725
- type: "function";
726
- function: {
727
- name: string;
728
- description?: string;
729
- parameters?: Record<string, unknown>;
730
- };
731
- };
732
- type OpenAIToolCallDelta = {
733
- index?: number;
734
- id?: string;
735
- type?: "function";
736
- function?: {
737
- name?: string;
738
- arguments?: string;
739
- };
740
- };
741
- type OpenAIChatChunk = {
742
- id?: string;
743
- choices?: Array<{
744
- index?: number;
745
- delta?: {
746
- content?: string | null;
747
- tool_calls?: OpenAIToolCallDelta[];
748
- reasoning_content?: string;
749
- reasoning?: string;
750
- };
751
- finish_reason?: string | null;
752
- }>;
753
- usage?: {
754
- prompt_tokens?: number;
755
- completion_tokens?: number;
756
- total_tokens?: number;
757
- };
758
- };
759
- type NcpLLMApiInput = {
760
- messages: OpenAIChatMessage[];
761
- tools?: OpenAITool[];
762
- model?: string;
763
- thinkingLevel?: string | null;
764
- max_tokens?: number;
765
- };
766
- type NcpLLMApiOptions = {
767
- signal?: AbortSignal;
768
- temperature?: number;
769
- };
770
- interface NcpLLMApi {
771
- generate(input: NcpLLMApiInput, options?: NcpLLMApiOptions): AsyncIterable<OpenAIChatChunk>;
772
- }
773
-
762
+ //#endregion
763
+ //#region src/agent-runtime/context-builder.d.ts
774
764
  type NcpContextPrepareOptions = {
775
- sessionMessages?: ReadonlyArray<NcpMessage>;
776
- systemPrompt?: string;
777
- maxMessages?: number;
765
+ sessionMessages?: ReadonlyArray<NcpMessage>;
766
+ systemPrompt?: string;
767
+ maxMessages?: number;
778
768
  };
779
769
  interface NcpContextBuilder {
780
- prepare(input: NcpAgentRunInput, options?: NcpContextPrepareOptions): NcpLLMApiInput;
770
+ prepare(input: NcpAgentRunInput, options?: NcpContextPrepareOptions): NcpLLMApiInput;
781
771
  }
782
-
772
+ //#endregion
773
+ //#region src/agent-runtime/tool.d.ts
783
774
  type NcpToolDefinition = {
784
- name: string;
785
- description?: string;
786
- parameters?: Record<string, unknown>;
775
+ name: string;
776
+ description?: string;
777
+ parameters?: Record<string, unknown>;
787
778
  };
788
779
  interface NcpTool {
789
- readonly name: string;
790
- readonly description?: string;
791
- readonly parameters?: Record<string, unknown>;
792
- validateArgs?(args: Record<string, unknown>): string[];
793
- execute(args: unknown): Promise<unknown>;
780
+ readonly name: string;
781
+ readonly description?: string;
782
+ readonly parameters?: Record<string, unknown>;
783
+ validateArgs?(args: Record<string, unknown>): string[];
784
+ execute(args: unknown): Promise<unknown>;
794
785
  }
795
786
  type NcpToolCallResult = {
796
- toolCallId: string;
797
- toolName: string;
798
- args: Record<string, unknown> | null;
799
- rawArgsText: string;
800
- result: unknown;
787
+ toolCallId: string;
788
+ toolName: string;
789
+ args: Record<string, unknown> | null;
790
+ rawArgsText: string;
791
+ result: unknown;
801
792
  };
802
793
  type NcpInvalidToolArgumentsResult = {
803
- ok: false;
804
- error: {
805
- code: "invalid_tool_arguments";
806
- message: string;
807
- toolCallId: string;
808
- toolName: string;
809
- rawArgumentsText: string;
810
- issues: string[];
811
- };
794
+ ok: false;
795
+ error: {
796
+ code: "invalid_tool_arguments";
797
+ message: string;
798
+ toolCallId: string;
799
+ toolName: string;
800
+ rawArgumentsText: string;
801
+ issues: string[];
802
+ };
812
803
  };
813
804
  interface NcpToolRegistry {
814
- listTools(): ReadonlyArray<NcpTool>;
815
- getTool(name: string): NcpTool | undefined;
816
- getToolDefinitions(): ReadonlyArray<NcpToolDefinition>;
817
- execute(toolCallId: string, toolName: string, args: unknown): Promise<unknown>;
805
+ listTools(): ReadonlyArray<NcpTool>;
806
+ getTool(name: string): NcpTool | undefined;
807
+ getToolDefinitions(): ReadonlyArray<NcpToolDefinition>;
808
+ execute(toolCallId: string, toolName: string, args: unknown): Promise<unknown>;
818
809
  }
819
-
810
+ //#endregion
811
+ //#region src/agent-runtime/stream-encoder.d.ts
820
812
  type NcpEncodeContext = {
821
- sessionId: string;
822
- messageId: string;
823
- runId: string;
824
- correlationId?: string;
813
+ sessionId: string;
814
+ messageId: string;
815
+ runId: string;
816
+ correlationId?: string;
825
817
  };
826
818
  interface NcpStreamEncoder {
827
- encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncIterable<NcpEndpointEvent>;
819
+ encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncIterable<NcpEndpointEvent>;
828
820
  }
829
-
821
+ //#endregion
822
+ //#region src/agent-runtime/round-buffer.d.ts
830
823
  type NcpPendingToolCall = {
831
- toolCallId: string;
832
- toolName: string;
833
- args: unknown;
824
+ toolCallId: string;
825
+ toolName: string;
826
+ args: unknown;
834
827
  };
835
828
  interface NcpRoundBuffer {
836
- appendText(delta: string): void;
837
- getText(): string;
838
- appendToolCall(result: NcpToolCallResult): void;
839
- getToolCalls(): ReadonlyArray<NcpToolCallResult>;
840
- startToolCall(toolCallId: string, toolName: string): void;
841
- appendToolCallArgs(args: unknown): void;
842
- consumePendingToolCall(): NcpPendingToolCall | null;
843
- clear(): void;
829
+ appendText(delta: string): void;
830
+ getText(): string;
831
+ appendToolCall(result: NcpToolCallResult): void;
832
+ getToolCalls(): ReadonlyArray<NcpToolCallResult>;
833
+ startToolCall(toolCallId: string, toolName: string): void;
834
+ appendToolCallArgs(args: unknown): void;
835
+ consumePendingToolCall(): NcpPendingToolCall | null;
836
+ clear(): void;
844
837
  }
845
-
838
+ //#endregion
839
+ //#region src/agent-backend/controller.d.ts
846
840
  type NcpAgentRunSendOptions = {
847
- signal?: AbortSignal;
841
+ signal?: AbortSignal;
848
842
  };
849
843
  type NcpAgentRunStreamOptions = {
850
- signal?: AbortSignal;
844
+ signal?: AbortSignal;
851
845
  };
852
846
  interface NcpAgentRunApi {
853
- send(envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions): AsyncIterable<NcpEndpointEvent>;
854
- stream(payload: NcpStreamRequestPayload, options?: NcpAgentRunStreamOptions): AsyncIterable<NcpEndpointEvent>;
855
- abort(payload: NcpMessageAbortPayload): Promise<void>;
847
+ send(envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions): AsyncIterable<NcpEndpointEvent>;
848
+ stream(payload: NcpStreamRequestPayload, options?: NcpAgentRunStreamOptions): AsyncIterable<NcpEndpointEvent>;
849
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
856
850
  }
857
851
  type NcpAgentStreamProvider = {
858
- stream(params: {
859
- payload: NcpStreamRequestPayload;
860
- signal: AbortSignal;
861
- }): AsyncIterable<NcpEndpointEvent>;
852
+ stream(params: {
853
+ payload: NcpStreamRequestPayload;
854
+ signal: AbortSignal;
855
+ }): AsyncIterable<NcpEndpointEvent>;
862
856
  };
863
-
857
+ //#endregion
858
+ //#region src/toolkit/conversation-state.d.ts
864
859
  /**
865
860
  * Read-only snapshot of conversation state maintained by a state manager.
866
861
  *
867
862
  * Consumed by UI or other layers; all updates flow through dispatch(event).
868
863
  */
869
864
  interface NcpConversationSnapshot {
870
- /** Ordered list of finalized messages. */
871
- readonly messages: ReadonlyArray<NcpMessage>;
872
- /**
873
- * Message currently being streamed (deltas apply here); null when idle.
874
- * When message.completed is dispatched, this is appended to messages and cleared.
875
- */
876
- readonly streamingMessage: NcpMessage | null;
877
- /** Latest error, if any (e.g. from message.failed or endpoint.error). */
878
- readonly error: NcpError | null;
865
+ /** Ordered list of finalized messages. */
866
+ readonly messages: ReadonlyArray<NcpMessage>;
867
+ /**
868
+ * Message currently being streamed (deltas apply here); null when idle.
869
+ * When message.completed is dispatched, this is appended to messages and cleared.
870
+ */
871
+ readonly streamingMessage: NcpMessage | null;
872
+ /** Latest error, if any (e.g. from message.failed or endpoint.error). */
873
+ readonly error: NcpError | null;
879
874
  }
880
875
  /**
881
876
  * Agent snapshot: extends base snapshot with active run state.
882
877
  * Use for UI run status, abort button enable/disable, and abort payload.
883
878
  */
884
879
  interface NcpAgentConversationSnapshot extends NcpConversationSnapshot {
885
- readonly activeRun: NcpRunContext | null;
880
+ readonly activeRun: NcpRunContext | null;
886
881
  }
887
882
  /**
888
883
  * State manager that holds conversation state and updates it from NCP events.
@@ -891,29 +886,30 @@ interface NcpAgentConversationSnapshot extends NcpConversationSnapshot {
891
886
  * Typically used by agent UIs or runtimes to keep a single source of truth for messages.
892
887
  */
893
888
  interface NcpConversationStateManager {
894
- /** Returns the current snapshot. Call after dispatch or in subscribe callback. */
895
- getSnapshot(): NcpConversationSnapshot;
896
- /**
897
- * Applies an NCP event to internal state (messages, streamingMessage, error).
898
- * Notifies subscribers after the update.
899
- */
900
- dispatch(event: NcpEndpointEvent): Promise<void>;
901
- /**
902
- * Applies multiple NCP events in order and notifies subscribers once after
903
- * the batch finishes mutating state.
904
- */
905
- dispatchBatch(events: readonly NcpEndpointEvent[]): Promise<void>;
906
- /**
907
- * Subscribes to state changes. Listener is called after each dispatch that mutates state.
908
- * Returns an unsubscribe function.
909
- */
910
- subscribe(listener: (snapshot: NcpConversationSnapshot) => void): () => void;
889
+ /** Returns the current snapshot. Call after dispatch or in subscribe callback. */
890
+ getSnapshot(): NcpConversationSnapshot;
891
+ /**
892
+ * Applies an NCP event to internal state (messages, streamingMessage, error).
893
+ * Notifies subscribers after the update.
894
+ */
895
+ dispatch(event: NcpEndpointEvent): Promise<void>;
896
+ /**
897
+ * Applies multiple NCP events in order and notifies subscribers once after
898
+ * the batch finishes mutating state.
899
+ */
900
+ dispatchBatch(events: readonly NcpEndpointEvent[]): Promise<void>;
901
+ /**
902
+ * Subscribes to state changes. Listener is called after each dispatch that mutates state.
903
+ * Returns an unsubscribe function.
904
+ */
905
+ subscribe(listener: (snapshot: NcpConversationSnapshot) => void): () => void;
911
906
  }
912
-
907
+ //#endregion
908
+ //#region src/toolkit/agent/agent-conversation-state-manager.d.ts
913
909
  type NcpAgentConversationHydrationParams = {
914
- sessionId: string;
915
- messages: ReadonlyArray<NcpMessage>;
916
- activeRun?: NcpRunContext | null;
910
+ sessionId: string;
911
+ messages: ReadonlyArray<NcpMessage>;
912
+ activeRun?: NcpRunContext | null;
917
913
  };
918
914
  /**
919
915
  * Agent-scenario state manager: extends the generic conversation state manager
@@ -923,59 +919,61 @@ type NcpAgentConversationHydrationParams = {
923
919
  * and use these handlers to update messages, streamingMessage, and error.
924
920
  */
925
921
  interface NcpAgentConversationStateManager extends NcpConversationStateManager {
926
- getSnapshot(): NcpAgentConversationSnapshot;
927
- reset(): void;
928
- hydrate(payload: NcpAgentConversationHydrationParams): void;
929
- /** Local peer sent a message (outbound); typically non-streaming. Add to messages. */
930
- handleMessageSent(payload: NcpMessageSentPayload): void;
931
- handleMessageAbort(payload: NcpMessageAbortPayload): void;
932
- handleMessageTextStart(payload: NcpTextStartPayload): void;
933
- handleMessageTextDelta(payload: NcpTextDeltaPayload): void;
934
- handleMessageTextEnd(payload: NcpTextEndPayload): void;
935
- handleMessageReasoningStart(payload: NcpReasoningStartPayload): void;
936
- handleMessageReasoningDelta(payload: NcpReasoningDeltaPayload): void;
937
- handleMessageReasoningEnd(payload: NcpReasoningEndPayload): void;
938
- handleMessageToolCallStart(payload: NcpToolCallStartPayload): void;
939
- handleMessageToolCallArgs(payload: NcpToolCallArgsPayload): void;
940
- handleMessageToolCallArgsDelta(payload: NcpToolCallArgsDeltaPayload): void;
941
- handleMessageToolCallEnd(payload: NcpToolCallEndPayload): void;
942
- handleMessageToolCallResult(payload: NcpToolCallResultPayload): void;
943
- handleRunStarted(payload: NcpRunStartedPayload): void;
944
- handleRunFinished(payload: NcpRunFinishedPayload): void;
945
- handleRunError(payload: NcpRunErrorPayload): void;
946
- handleRunMetadata(payload: NcpRunMetadataPayload): void;
947
- handleEndpointError(payload: NcpError): void;
922
+ getSnapshot(): NcpAgentConversationSnapshot;
923
+ reset(): void;
924
+ hydrate(payload: NcpAgentConversationHydrationParams): void;
925
+ /** Local peer sent a message (outbound); typically non-streaming. Add to messages. */
926
+ handleMessageSent(payload: NcpMessageSentPayload): void;
927
+ handleMessageAbort(payload: NcpMessageAbortPayload): void;
928
+ handleMessageTextStart(payload: NcpTextStartPayload): void;
929
+ handleMessageTextDelta(payload: NcpTextDeltaPayload): void;
930
+ handleMessageTextEnd(payload: NcpTextEndPayload): void;
931
+ handleMessageReasoningStart(payload: NcpReasoningStartPayload): void;
932
+ handleMessageReasoningDelta(payload: NcpReasoningDeltaPayload): void;
933
+ handleMessageReasoningEnd(payload: NcpReasoningEndPayload): void;
934
+ handleMessageToolCallStart(payload: NcpToolCallStartPayload): void;
935
+ handleMessageToolCallArgs(payload: NcpToolCallArgsPayload): void;
936
+ handleMessageToolCallArgsDelta(payload: NcpToolCallArgsDeltaPayload): void;
937
+ handleMessageToolCallEnd(payload: NcpToolCallEndPayload): void;
938
+ handleMessageToolCallResult(payload: NcpToolCallResultPayload): void;
939
+ handleRunStarted(payload: NcpRunStartedPayload): void;
940
+ handleRunFinished(payload: NcpRunFinishedPayload): void;
941
+ handleRunError(payload: NcpRunErrorPayload): void;
942
+ handleRunMetadata(payload: NcpRunMetadataPayload): void;
943
+ handleEndpointError(payload: NcpError): void;
948
944
  }
949
-
945
+ //#endregion
946
+ //#region src/toolkit/reply-tags.d.ts
950
947
  type NcpReplyTagParseResult = {
951
- content: string;
952
- replyTo?: string;
948
+ content: string;
949
+ replyTo?: string;
953
950
  };
954
951
  declare function stripReplyTagsFromText(content: string, currentMessageId?: string): NcpReplyTagParseResult;
955
952
  declare function sanitizeAssistantReplyTags(message: NcpMessage, currentMessageId?: string): NcpMessage;
956
-
953
+ //#endregion
954
+ //#region src/toolkit/reasoning-normalization.d.ts
957
955
  type NcpAssistantReasoningNormalizationMode = "off" | "think-tags";
958
956
  type NcpAssistantReasoningSegment = {
959
- type: "text" | "reasoning";
960
- text: string;
957
+ type: "text" | "reasoning";
958
+ text: string;
961
959
  };
962
960
  declare function readAssistantReasoningNormalizationMode(value: unknown): NcpAssistantReasoningNormalizationMode | null;
963
961
  declare function readAssistantReasoningNormalizationModeFromMetadata(metadata: Record<string, unknown> | null | undefined): NcpAssistantReasoningNormalizationMode | null;
964
962
  declare function writeAssistantReasoningNormalizationModeToMetadata(metadata: Record<string, unknown>, mode: NcpAssistantReasoningNormalizationMode): Record<string, unknown>;
965
963
  declare class NcpAssistantTextStreamNormalizer {
966
- private readonly mode;
967
- private buffer;
968
- private phase;
969
- private stripLeadingTextControlTags;
970
- constructor(mode?: NcpAssistantReasoningNormalizationMode);
971
- push(delta: string): NcpAssistantReasoningSegment[];
972
- finish(): NcpAssistantReasoningSegment[];
973
- private flush;
964
+ private readonly mode;
965
+ private buffer;
966
+ private phase;
967
+ private stripLeadingTextControlTags;
968
+ constructor(mode?: NcpAssistantReasoningNormalizationMode);
969
+ push(delta: string): NcpAssistantReasoningSegment[];
970
+ finish(): NcpAssistantReasoningSegment[];
971
+ private flush;
974
972
  }
975
973
  declare function normalizeAssistantText(text: string, mode: NcpAssistantReasoningNormalizationMode): {
976
- text: string;
977
- reasoning: string;
978
- parts: NcpAssistantReasoningSegment[];
974
+ text: string;
975
+ reasoning: string;
976
+ parts: NcpAssistantReasoningSegment[];
979
977
  };
980
-
981
- export { type ListMessagesOptions, type ListSessionsOptions, NCP_INTERNAL_VISIBILITY_METADATA_KEY, type NcpActionPart, type NcpAgentClientEndpoint, type NcpAgentConversationHydrationParams, type NcpAgentConversationSnapshot, type NcpAgentConversationStateManager, type NcpAgentRunApi, type NcpAgentRunInput, type NcpAgentRunOptions, type NcpAgentRunSendOptions, type NcpAgentRunStreamOptions, type NcpAgentRuntime, type NcpAgentServerEndpoint, type NcpAgentStreamProvider, type NcpAssistantReasoningNormalizationMode, type NcpAssistantReasoningSegment, NcpAssistantTextStreamNormalizer, type NcpCardPart, type NcpCompletedEnvelope, type NcpContextBuilder, type NcpContextPrepareOptions, type NcpConversationSnapshot, type NcpConversationStateManager, type NcpEncodeContext, type NcpEndpoint, type NcpEndpointEvent, type NcpEndpointKind, type NcpEndpointLatency, type NcpEndpointManifest, type NcpEndpointSubscriber, type NcpError, type NcpErrorCode, NcpEventType, type NcpExtensionPart, type NcpFailedEnvelope, type NcpFilePart, type NcpInvalidToolArgumentsResult, type NcpLLMApi, type NcpLLMApiInput, type NcpLLMApiOptions, type NcpMessage, type NcpMessageAbortPayload, type NcpMessageAcceptedPayload, type NcpMessageDeliveredPayload, type NcpMessagePart, type NcpMessageReactionPayload, type NcpMessageReadPayload, type NcpMessageRecalledPayload, type NcpMessageRole, type NcpMessageSentPayload, type NcpMessageStatus, type NcpPendingToolCall, type NcpPresenceUpdatedPayload, type NcpReasoningDeltaPayload, type NcpReasoningEndPayload, type NcpReasoningPart, type NcpReasoningStartPayload, type NcpReplyTagParseResult, type NcpRequestEnvelope, type NcpResponseEnvelope, type NcpRichTextPart, type NcpRoundBuffer, type NcpRunContext, type NcpRunErrorPayload, type NcpRunFinalMetadata, type NcpRunFinishedPayload, type NcpRunMetadataPayload, type NcpRunReadyMetadata, type NcpRunStartedPayload, type NcpSessionApi, type NcpSessionPatch, type NcpSessionStatus, type NcpSessionSummary, type NcpSourcePart, type NcpStepStartPart, type NcpStreamEncoder, type NcpStreamRequestPayload, type NcpTextDeltaPayload, type NcpTextEndPayload, type NcpTextPart, type NcpTextStartPayload, type NcpTool, type NcpToolCallArgsDeltaPayload, type NcpToolCallArgsPayload, type NcpToolCallEndPayload, type NcpToolCallResult, type NcpToolCallResultPayload, type NcpToolCallStartPayload, type NcpToolDefinition, type NcpToolInvocationPart, type NcpToolRegistry, type NcpTypingEndPayload, type NcpTypingStartPayload, type OpenAIChatChunk, type OpenAIChatMessage, type OpenAIContentPart, type OpenAITool, type OpenAIToolCall, type OpenAIToolCallDelta, isHiddenNcpMessage, normalizeAssistantText, readAssistantReasoningNormalizationMode, readAssistantReasoningNormalizationModeFromMetadata, sanitizeAssistantReplyTags, stripReplyTagsFromText, writeAssistantReasoningNormalizationModeToMetadata };
978
+ //#endregion
979
+ export { ListMessagesOptions, ListSessionsOptions, NCP_INTERNAL_VISIBILITY_METADATA_KEY, NcpActionPart, NcpAgentClientEndpoint, NcpAgentConversationHydrationParams, NcpAgentConversationSnapshot, NcpAgentConversationStateManager, NcpAgentRunApi, NcpAgentRunInput, NcpAgentRunOptions, NcpAgentRunSendOptions, NcpAgentRunStreamOptions, NcpAgentRuntime, NcpAgentServerEndpoint, NcpAgentStreamProvider, NcpAssistantReasoningNormalizationMode, NcpAssistantReasoningSegment, NcpAssistantTextStreamNormalizer, NcpCardPart, NcpCompletedEnvelope, NcpContextBuilder, NcpContextPrepareOptions, NcpConversationSnapshot, NcpConversationStateManager, NcpEncodeContext, NcpEndpoint, NcpEndpointEvent, NcpEndpointKind, NcpEndpointLatency, NcpEndpointManifest, NcpEndpointSubscriber, NcpError, NcpErrorCode, NcpEventType, NcpExtensionPart, NcpFailedEnvelope, NcpFilePart, NcpInvalidToolArgumentsResult, NcpLLMApi, NcpLLMApiInput, NcpLLMApiOptions, NcpMessage, NcpMessageAbortPayload, NcpMessageAcceptedPayload, NcpMessageDeliveredPayload, NcpMessagePart, NcpMessageReactionPayload, NcpMessageReadPayload, NcpMessageRecalledPayload, NcpMessageRole, NcpMessageSentPayload, NcpMessageStatus, NcpPendingToolCall, NcpPresenceUpdatedPayload, NcpProviderRuntimeRoute, NcpReasoningDeltaPayload, NcpReasoningEndPayload, NcpReasoningPart, NcpReasoningStartPayload, NcpReplyTagParseResult, NcpRequestEnvelope, NcpResponseEnvelope, NcpRichTextPart, NcpRoundBuffer, NcpRunContext, NcpRunErrorPayload, NcpRunFinalMetadata, NcpRunFinishedPayload, NcpRunMetadataPayload, NcpRunReadyMetadata, NcpRunStartedPayload, NcpSessionApi, NcpSessionPatch, NcpSessionStatus, NcpSessionSummary, NcpSourcePart, NcpStepStartPart, NcpStreamEncoder, NcpStreamRequestPayload, NcpTextDeltaPayload, NcpTextEndPayload, NcpTextPart, NcpTextStartPayload, NcpTool, NcpToolCallArgsDeltaPayload, NcpToolCallArgsPayload, NcpToolCallEndPayload, NcpToolCallResult, NcpToolCallResultPayload, NcpToolCallStartPayload, NcpToolDefinition, NcpToolInvocationPart, NcpToolRegistry, NcpTypingEndPayload, NcpTypingStartPayload, OpenAIChatChunk, OpenAIChatMessage, OpenAIContentPart, OpenAITool, OpenAIToolCall, OpenAIToolCallDelta, isHiddenNcpMessage, normalizeAssistantText, readAssistantReasoningNormalizationMode, readAssistantReasoningNormalizationModeFromMetadata, sanitizeAssistantReplyTags, stripReplyTagsFromText, writeAssistantReasoningNormalizationModeToMetadata };