@nextclaw/ncp 0.5.0 → 0.5.1

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 +565 -575
  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,47 @@ 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/types/events.d.ts
255
234
  /**
256
235
  * NCP event and payload definitions.
257
236
  *
@@ -260,329 +239,327 @@ interface NcpSessionApi {
260
239
  * instead; endpoints or upper layers choose as needed.
261
240
  */
262
241
  type NcpRequestEnvelope = {
263
- sessionId: string;
264
- message: NcpMessage;
265
- correlationId?: string;
266
- metadata?: Record<string, unknown>;
242
+ sessionId: string;
243
+ message: NcpMessage;
244
+ correlationId?: string;
245
+ metadata?: Record<string, unknown>;
267
246
  };
268
247
  /** Payload for message.incoming: message content from the other peer (partial or full). */
269
248
  type NcpResponseEnvelope = {
270
- sessionId: string;
271
- message: NcpMessage;
272
- correlationId?: string;
273
- metadata?: Record<string, unknown>;
249
+ sessionId: string;
250
+ message: NcpMessage;
251
+ correlationId?: string;
252
+ metadata?: Record<string, unknown>;
274
253
  };
275
254
  type NcpCompletedEnvelope = {
276
- sessionId: string;
277
- message: NcpMessage;
278
- correlationId?: string;
279
- metadata?: Record<string, unknown>;
255
+ sessionId: string;
256
+ message: NcpMessage;
257
+ correlationId?: string;
258
+ metadata?: Record<string, unknown>;
280
259
  };
281
260
  type NcpFailedEnvelope = {
282
- sessionId: string;
283
- messageId?: string;
284
- error: NcpError;
285
- correlationId?: string;
286
- metadata?: Record<string, unknown>;
261
+ sessionId: string;
262
+ messageId?: string;
263
+ error: NcpError;
264
+ correlationId?: string;
265
+ metadata?: Record<string, unknown>;
287
266
  };
288
267
  type NcpMessageAcceptedPayload = {
289
- messageId: string;
290
- correlationId?: string;
291
- transportId?: string;
268
+ messageId: string;
269
+ correlationId?: string;
270
+ transportId?: string;
292
271
  };
293
272
  /** Payload for message.abort: identifies which session's active execution to cancel. */
294
273
  type NcpMessageAbortPayload = {
295
- sessionId: string;
296
- messageId?: string;
274
+ sessionId: string;
275
+ messageId?: string;
297
276
  };
298
277
  /**
299
278
  * Payload for message.stream-request: attach to the live event stream of a session.
300
279
  * Used when reconnecting during an active response or attaching another live reader.
301
280
  */
302
281
  type NcpStreamRequestPayload = {
303
- sessionId: string;
304
- metadata?: Record<string, unknown>;
282
+ sessionId: string;
283
+ metadata?: Record<string, unknown>;
305
284
  };
306
285
  /**
307
286
  * Payload for message.sent: the local peer has sent a message (outbound).
308
287
  * Typically non-streaming; add the message to the local conversation state.
309
288
  */
310
289
  type NcpMessageSentPayload = {
311
- sessionId: string;
312
- message: NcpMessage;
313
- metadata?: Record<string, unknown>;
290
+ sessionId: string;
291
+ message: NcpMessage;
292
+ metadata?: Record<string, unknown>;
314
293
  };
315
294
  type NcpTypingStartPayload = {
316
- sessionId: string;
317
- /** Participant who is typing (human user or bot/assistant). */
318
- userId?: string;
295
+ sessionId: string; /** Participant who is typing (human user or bot/assistant). */
296
+ userId?: string;
319
297
  };
320
298
  type NcpTypingEndPayload = {
321
- sessionId: string;
322
- /** Participant who stopped typing (human user or bot/assistant). */
323
- userId?: string;
299
+ sessionId: string; /** Participant who stopped typing (human user or bot/assistant). */
300
+ userId?: string;
324
301
  };
325
302
  type NcpPresenceUpdatedPayload = {
326
- sessionId: string;
327
- /** Participant this presence applies to (human user or bot/assistant). */
328
- userId?: string;
329
- status: "online" | "offline" | "away";
303
+ sessionId: string; /** Participant this presence applies to (human user or bot/assistant). */
304
+ userId?: string;
305
+ status: "online" | "offline" | "away";
330
306
  };
331
307
  type NcpMessageReadPayload = {
332
- sessionId: string;
333
- messageId: string;
334
- readAt?: string;
335
- readerId?: string;
308
+ sessionId: string;
309
+ messageId: string;
310
+ readAt?: string;
311
+ readerId?: string;
336
312
  };
337
313
  type NcpMessageDeliveredPayload = {
338
- sessionId: string;
339
- messageId: string;
314
+ sessionId: string;
315
+ messageId: string;
340
316
  };
341
317
  type NcpMessageRecalledPayload = {
342
- sessionId: string;
343
- messageId: string;
318
+ sessionId: string;
319
+ messageId: string;
344
320
  };
345
321
  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;
322
+ sessionId: string;
323
+ messageId: string;
324
+ reaction: string;
325
+ added: boolean; /** Participant who added or removed the reaction (human user or bot/assistant). */
326
+ userId?: string;
352
327
  };
353
328
  type NcpRunStartedPayload = {
354
- sessionId?: string;
355
- messageId?: string;
356
- threadId?: string;
357
- runId?: string;
329
+ sessionId?: string;
330
+ messageId?: string;
331
+ threadId?: string;
332
+ runId?: string;
358
333
  };
359
334
  type NcpRunFinishedPayload = {
360
- sessionId?: string;
361
- messageId?: string;
362
- threadId?: string;
363
- runId?: string;
335
+ sessionId?: string;
336
+ messageId?: string;
337
+ threadId?: string;
338
+ runId?: string;
364
339
  };
365
340
  type NcpRunErrorPayload = {
366
- sessionId?: string;
367
- messageId?: string;
368
- error?: string;
369
- threadId?: string;
370
- runId?: string;
341
+ sessionId?: string;
342
+ messageId?: string;
343
+ error?: string;
344
+ threadId?: string;
345
+ runId?: string;
371
346
  };
372
347
  type NcpRunMetadataPayload = {
373
- sessionId?: string;
374
- messageId?: string;
375
- runId?: string;
376
- metadata: Record<string, unknown>;
348
+ sessionId?: string;
349
+ messageId?: string;
350
+ runId?: string;
351
+ metadata: Record<string, unknown>;
377
352
  };
378
353
  type NcpTextStartPayload = {
379
- sessionId: string;
380
- messageId: string;
354
+ sessionId: string;
355
+ messageId: string;
381
356
  };
382
357
  type NcpTextDeltaPayload = {
383
- sessionId: string;
384
- messageId: string;
385
- delta: string;
358
+ sessionId: string;
359
+ messageId: string;
360
+ delta: string;
386
361
  };
387
362
  type NcpTextEndPayload = {
388
- sessionId: string;
389
- messageId: string;
363
+ sessionId: string;
364
+ messageId: string;
390
365
  };
391
366
  type NcpReasoningStartPayload = {
392
- sessionId: string;
393
- messageId: string;
367
+ sessionId: string;
368
+ messageId: string;
394
369
  };
395
370
  type NcpReasoningDeltaPayload = {
396
- sessionId: string;
397
- messageId: string;
398
- delta: string;
371
+ sessionId: string;
372
+ messageId: string;
373
+ delta: string;
399
374
  };
400
375
  type NcpReasoningEndPayload = {
401
- sessionId: string;
402
- messageId: string;
376
+ sessionId: string;
377
+ messageId: string;
403
378
  };
404
379
  type NcpToolCallStartPayload = {
405
- sessionId: string;
406
- messageId?: string;
407
- toolCallId: string;
408
- toolName: string;
380
+ sessionId: string;
381
+ messageId?: string;
382
+ toolCallId: string;
383
+ toolName: string;
409
384
  };
410
385
  type NcpToolCallArgsPayload = {
411
- sessionId: string;
412
- toolCallId: string;
413
- args: string;
386
+ sessionId: string;
387
+ toolCallId: string;
388
+ args: string;
414
389
  };
415
390
  type NcpToolCallArgsDeltaPayload = {
416
- sessionId: string;
417
- messageId?: string;
418
- toolCallId: string;
419
- delta: string;
391
+ sessionId: string;
392
+ messageId?: string;
393
+ toolCallId: string;
394
+ delta: string;
420
395
  };
421
396
  type NcpToolCallEndPayload = {
422
- sessionId: string;
423
- toolCallId: string;
397
+ sessionId: string;
398
+ toolCallId: string;
424
399
  };
425
400
  type NcpToolCallResultPayload = {
426
- sessionId: string;
427
- toolCallId: string;
428
- content: unknown;
401
+ sessionId: string;
402
+ toolCallId: string;
403
+ content: unknown;
429
404
  };
430
405
  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"
406
+ EndpointReady = "endpoint.ready",
407
+ EndpointError = "endpoint.error",
408
+ MessageRequest = "message.request",
409
+ MessageStreamRequest = "message.stream-request",
410
+ MessageSent = "message.sent",
411
+ MessageAccepted = "message.accepted",
412
+ MessageIncoming = "message.incoming",
413
+ MessageCompleted = "message.completed",
414
+ MessageFailed = "message.failed",
415
+ MessageAbort = "message.abort",
416
+ MessageTextStart = "message.text-start",
417
+ MessageTextDelta = "message.text-delta",
418
+ MessageTextEnd = "message.text-end",
419
+ MessageReasoningStart = "message.reasoning-start",
420
+ MessageReasoningDelta = "message.reasoning-delta",
421
+ MessageReasoningEnd = "message.reasoning-end",
422
+ MessageToolCallStart = "message.tool-call-start",
423
+ MessageToolCallArgs = "message.tool-call-args",
424
+ MessageToolCallArgsDelta = "message.tool-call-args-delta",
425
+ MessageToolCallEnd = "message.tool-call-end",
426
+ MessageToolCallResult = "message.tool-call-result",
427
+ MessageRead = "message.read",
428
+ MessageDelivered = "message.delivered",
429
+ MessageRecalled = "message.recalled",
430
+ MessageReaction = "message.reaction",
431
+ RunStarted = "run.started",
432
+ RunFinished = "run.finished",
433
+ RunError = "run.error",
434
+ RunMetadata = "run.metadata",
435
+ TypingStart = "typing.start",
436
+ TypingEnd = "typing.end",
437
+ PresenceUpdated = "presence.updated"
463
438
  }
464
439
  type NcpEndpointEvent = {
465
- type: NcpEventType.EndpointReady;
440
+ type: NcpEventType.EndpointReady;
466
441
  } | {
467
- type: NcpEventType.MessageRequest;
468
- payload: NcpRequestEnvelope;
442
+ type: NcpEventType.MessageRequest;
443
+ payload: NcpRequestEnvelope;
469
444
  } | {
470
- type: NcpEventType.MessageStreamRequest;
471
- payload: NcpStreamRequestPayload;
445
+ type: NcpEventType.MessageStreamRequest;
446
+ payload: NcpStreamRequestPayload;
472
447
  } | {
473
- type: NcpEventType.MessageSent;
474
- payload: NcpMessageSentPayload;
448
+ type: NcpEventType.MessageSent;
449
+ payload: NcpMessageSentPayload;
475
450
  } | {
476
- type: NcpEventType.MessageAccepted;
477
- payload: NcpMessageAcceptedPayload;
451
+ type: NcpEventType.MessageAccepted;
452
+ payload: NcpMessageAcceptedPayload;
478
453
  } | {
479
- type: NcpEventType.MessageIncoming;
480
- payload: NcpResponseEnvelope;
454
+ type: NcpEventType.MessageIncoming;
455
+ payload: NcpResponseEnvelope;
481
456
  } | {
482
- type: NcpEventType.MessageCompleted;
483
- payload: NcpCompletedEnvelope;
457
+ type: NcpEventType.MessageCompleted;
458
+ payload: NcpCompletedEnvelope;
484
459
  } | {
485
- type: NcpEventType.MessageFailed;
486
- payload: NcpFailedEnvelope;
460
+ type: NcpEventType.MessageFailed;
461
+ payload: NcpFailedEnvelope;
487
462
  } | {
488
- type: NcpEventType.MessageAbort;
489
- payload: NcpMessageAbortPayload;
463
+ type: NcpEventType.MessageAbort;
464
+ payload: NcpMessageAbortPayload;
490
465
  } | {
491
- type: NcpEventType.EndpointError;
492
- payload: NcpError;
466
+ type: NcpEventType.EndpointError;
467
+ payload: NcpError;
493
468
  } | {
494
- type: NcpEventType.RunStarted;
495
- payload: NcpRunStartedPayload;
469
+ type: NcpEventType.RunStarted;
470
+ payload: NcpRunStartedPayload;
496
471
  } | {
497
- type: NcpEventType.RunFinished;
498
- payload: NcpRunFinishedPayload;
472
+ type: NcpEventType.RunFinished;
473
+ payload: NcpRunFinishedPayload;
499
474
  } | {
500
- type: NcpEventType.RunError;
501
- payload: NcpRunErrorPayload;
475
+ type: NcpEventType.RunError;
476
+ payload: NcpRunErrorPayload;
502
477
  } | {
503
- type: NcpEventType.RunMetadata;
504
- payload: NcpRunMetadataPayload;
478
+ type: NcpEventType.RunMetadata;
479
+ payload: NcpRunMetadataPayload;
505
480
  } | {
506
- type: NcpEventType.MessageTextStart;
507
- payload: NcpTextStartPayload;
481
+ type: NcpEventType.MessageTextStart;
482
+ payload: NcpTextStartPayload;
508
483
  } | {
509
- type: NcpEventType.MessageTextDelta;
510
- payload: NcpTextDeltaPayload;
484
+ type: NcpEventType.MessageTextDelta;
485
+ payload: NcpTextDeltaPayload;
511
486
  } | {
512
- type: NcpEventType.MessageTextEnd;
513
- payload: NcpTextEndPayload;
487
+ type: NcpEventType.MessageTextEnd;
488
+ payload: NcpTextEndPayload;
514
489
  } | {
515
- type: NcpEventType.MessageReasoningStart;
516
- payload: NcpReasoningStartPayload;
490
+ type: NcpEventType.MessageReasoningStart;
491
+ payload: NcpReasoningStartPayload;
517
492
  } | {
518
- type: NcpEventType.MessageReasoningDelta;
519
- payload: NcpReasoningDeltaPayload;
493
+ type: NcpEventType.MessageReasoningDelta;
494
+ payload: NcpReasoningDeltaPayload;
520
495
  } | {
521
- type: NcpEventType.MessageReasoningEnd;
522
- payload: NcpReasoningEndPayload;
496
+ type: NcpEventType.MessageReasoningEnd;
497
+ payload: NcpReasoningEndPayload;
523
498
  } | {
524
- type: NcpEventType.MessageToolCallStart;
525
- payload: NcpToolCallStartPayload;
499
+ type: NcpEventType.MessageToolCallStart;
500
+ payload: NcpToolCallStartPayload;
526
501
  } | {
527
- type: NcpEventType.MessageToolCallArgs;
528
- payload: NcpToolCallArgsPayload;
502
+ type: NcpEventType.MessageToolCallArgs;
503
+ payload: NcpToolCallArgsPayload;
529
504
  } | {
530
- type: NcpEventType.MessageToolCallArgsDelta;
531
- payload: NcpToolCallArgsDeltaPayload;
505
+ type: NcpEventType.MessageToolCallArgsDelta;
506
+ payload: NcpToolCallArgsDeltaPayload;
532
507
  } | {
533
- type: NcpEventType.MessageToolCallEnd;
534
- payload: NcpToolCallEndPayload;
508
+ type: NcpEventType.MessageToolCallEnd;
509
+ payload: NcpToolCallEndPayload;
535
510
  } | {
536
- type: NcpEventType.MessageToolCallResult;
537
- payload: NcpToolCallResultPayload;
511
+ type: NcpEventType.MessageToolCallResult;
512
+ payload: NcpToolCallResultPayload;
538
513
  } | {
539
- type: NcpEventType.TypingStart;
540
- payload: NcpTypingStartPayload;
514
+ type: NcpEventType.TypingStart;
515
+ payload: NcpTypingStartPayload;
541
516
  } | {
542
- type: NcpEventType.TypingEnd;
543
- payload: NcpTypingEndPayload;
517
+ type: NcpEventType.TypingEnd;
518
+ payload: NcpTypingEndPayload;
544
519
  } | {
545
- type: NcpEventType.PresenceUpdated;
546
- payload: NcpPresenceUpdatedPayload;
520
+ type: NcpEventType.PresenceUpdated;
521
+ payload: NcpPresenceUpdatedPayload;
547
522
  } | {
548
- type: NcpEventType.MessageRead;
549
- payload: NcpMessageReadPayload;
523
+ type: NcpEventType.MessageRead;
524
+ payload: NcpMessageReadPayload;
550
525
  } | {
551
- type: NcpEventType.MessageDelivered;
552
- payload: NcpMessageDeliveredPayload;
526
+ type: NcpEventType.MessageDelivered;
527
+ payload: NcpMessageDeliveredPayload;
553
528
  } | {
554
- type: NcpEventType.MessageRecalled;
555
- payload: NcpMessageRecalledPayload;
529
+ type: NcpEventType.MessageRecalled;
530
+ payload: NcpMessageRecalledPayload;
556
531
  } | {
557
- type: NcpEventType.MessageReaction;
558
- payload: NcpMessageReactionPayload;
532
+ type: NcpEventType.MessageReaction;
533
+ payload: NcpMessageReactionPayload;
559
534
  };
560
535
  type NcpEndpointSubscriber = (event: NcpEndpointEvent) => void;
561
-
536
+ //#endregion
537
+ //#region src/types/run.d.ts
562
538
  /**
563
539
  * Run-related types: snapshot state and run.metadata schema conventions.
564
540
  * Not event payloads — event payloads live in events.ts.
565
541
  */
566
542
  /** Current run state for agent snapshot. Used by UI for run status and abort. */
567
543
  type NcpRunContext = {
568
- runId: string | null;
569
- sessionId?: string;
570
- abortDisabledReason?: string | null;
544
+ runId: string | null;
545
+ sessionId?: string;
546
+ abortDisabledReason?: string | null;
571
547
  };
572
548
  /** Schema for run.metadata.metadata when kind is "ready" (run started, backend ready). */
573
549
  type NcpRunReadyMetadata = {
574
- kind: "ready";
575
- runId?: string;
576
- sessionId?: string;
577
- supportsAbort?: boolean;
578
- abortDisabledReason?: string;
550
+ kind: "ready";
551
+ runId?: string;
552
+ sessionId?: string;
553
+ supportsAbort?: boolean;
554
+ abortDisabledReason?: string;
579
555
  };
580
556
  /** Schema for run.metadata.metadata when kind is "final" (run finished). */
581
557
  type NcpRunFinalMetadata = {
582
- kind: "final";
583
- sessionId?: string;
558
+ kind: "final";
559
+ sessionId?: string;
584
560
  };
585
-
561
+ //#endregion
562
+ //#region src/types/endpoint.d.ts
586
563
  /**
587
564
  * Core interface every NCP endpoint adapter must implement.
588
565
  *
@@ -597,40 +574,41 @@ type NcpRunFinalMetadata = {
597
574
  * await endpoint.emit({ type: NcpEventType.MessageRequest, payload: envelope });
598
575
  */
599
576
  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;
577
+ /** Static capability declaration — available before `start()` is called. */
578
+ readonly manifest: NcpEndpointManifest;
579
+ /**
580
+ * Initializes the endpoint (opens connections, authenticates, etc.).
581
+ * Must be called before `emit`. Idempotent — safe to call more than once.
582
+ */
583
+ start(): Promise<void>;
584
+ /**
585
+ * Gracefully shuts down the endpoint and releases resources.
586
+ * Idempotent — safe to call more than once.
587
+ */
588
+ stop(): Promise<void>;
589
+ /**
590
+ * Sends an event to the remote participant (or broadcasts to local subscribers).
591
+ *
592
+ * For outbound events (e.g. message.request, message.abort), the implementation
593
+ * forwards to the wire. For symmetric in-process setups, it may broadcast locally.
594
+ */
595
+ emit(event: NcpEndpointEvent): Promise<void>;
596
+ /**
597
+ * Subscribes to endpoint events.
598
+ *
599
+ * @param listener - Called for every event emitted by this endpoint.
600
+ * @returns An unsubscribe function. Call it to stop receiving events.
601
+ *
602
+ * @example
603
+ * const unsubscribe = endpoint.subscribe((event) => {
604
+ * if (event.type === NcpEventType.MessageCompleted) handleReply(event.payload);
605
+ * });
606
+ * unsubscribe();
607
+ */
608
+ subscribe(listener: NcpEndpointSubscriber): () => void;
632
609
  }
633
-
610
+ //#endregion
611
+ //#region src/endpoint/agent-client-endpoint.d.ts
634
612
  /**
635
613
  * Client-side endpoint for agent chat: initiates requests and can cancel in-flight runs.
636
614
  *
@@ -638,14 +616,15 @@ interface NcpEndpoint {
638
616
  * (e.g. frontend, CLI) that sends user messages and receives agent responses.
639
617
  */
640
618
  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>;
619
+ /** Sends a new message request to the agent. Emits `message.request`. */
620
+ send(envelope: NcpRequestEnvelope): Promise<void>;
621
+ /** Attaches to the live event stream of a session. Emits `message.stream-request`. */
622
+ stream(payload: NcpStreamRequestPayload): Promise<void>;
623
+ /** Aborts the active execution of a session. Emits `message.abort`. */
624
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
647
625
  }
648
-
626
+ //#endregion
627
+ //#region src/endpoint/agent-server-endpoint.d.ts
649
628
  /**
650
629
  * Agent server-side endpoint: receives requests and produces downstream events.
651
630
  *
@@ -654,235 +633,243 @@ interface NcpAgentClientEndpoint extends NcpEndpoint {
654
633
  * downstream events (`message.incoming`, streaming deltas, `message.completed`, etc.).
655
634
  */
656
635
  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>;
636
+ readonly manifest: NcpEndpointManifest & {
637
+ endpointKind: "agent";
638
+ };
639
+ /** Handles a new message request from client side and yields produced events. */
640
+ send(envelope: NcpRequestEnvelope, options?: {
641
+ signal?: AbortSignal;
642
+ }): AsyncIterable<NcpEndpointEvent>;
643
+ /** Streams live events for an active session and yields produced events. */
644
+ stream(payload: NcpStreamRequestPayload, options?: {
645
+ signal?: AbortSignal;
646
+ }): AsyncIterable<NcpEndpointEvent>;
647
+ /** Aborts the active execution of a session on server side. */
648
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
649
+ /**
650
+ * Publishes server-downstream events (typically sent to frontend subscribers/transports).
651
+ * For handling client requests, prefer `send` / `stream` / `abort`.
652
+ */
653
+ emit(event: NcpEndpointEvent): Promise<void>;
675
654
  }
676
-
655
+ //#endregion
656
+ //#region src/agent-runtime/runtime.d.ts
677
657
  type NcpAgentRunInput = {
678
- sessionId: string;
679
- messages: ReadonlyArray<NcpMessage>;
680
- correlationId?: string;
681
- metadata?: Record<string, unknown>;
658
+ sessionId: string;
659
+ messages: ReadonlyArray<NcpMessage>;
660
+ correlationId?: string;
661
+ metadata?: Record<string, unknown>;
682
662
  };
683
663
  type NcpAgentRunOptions = {
684
- signal?: AbortSignal;
664
+ signal?: AbortSignal;
685
665
  };
686
666
  interface NcpAgentRuntime {
687
- run(input: NcpAgentRunInput, options?: NcpAgentRunOptions): AsyncIterable<NcpEndpointEvent>;
667
+ run(input: NcpAgentRunInput, options?: NcpAgentRunOptions): AsyncIterable<NcpEndpointEvent>;
688
668
  }
689
-
669
+ //#endregion
670
+ //#region src/agent-runtime/llm-api.d.ts
690
671
  type OpenAIContentPart = {
691
- type: "text";
692
- text: string;
672
+ type: "text";
673
+ text: string;
693
674
  } | {
694
- type: "image_url";
695
- image_url: {
696
- url: string;
697
- detail?: "low" | "high" | "auto";
698
- };
675
+ type: "image_url";
676
+ image_url: {
677
+ url: string;
678
+ detail?: "low" | "high" | "auto";
679
+ };
699
680
  };
700
681
  type OpenAIToolCall = {
701
- id: string;
702
- type: "function";
703
- function: {
704
- name: string;
705
- arguments: string;
706
- };
682
+ id: string;
683
+ type: "function";
684
+ function: {
685
+ name: string;
686
+ arguments: string;
687
+ };
707
688
  };
708
689
  type OpenAIChatMessage = {
709
- role: "system";
710
- content: string;
690
+ role: "system";
691
+ content: string;
711
692
  } | {
712
- role: "user";
713
- content: string | OpenAIContentPart[];
693
+ role: "user";
694
+ content: string | OpenAIContentPart[];
714
695
  } | {
715
- role: "assistant";
716
- content?: string | null;
717
- reasoning_content?: string;
718
- tool_calls?: OpenAIToolCall[];
696
+ role: "assistant";
697
+ content?: string | null;
698
+ reasoning_content?: string;
699
+ tool_calls?: OpenAIToolCall[];
719
700
  } | {
720
- role: "tool";
721
- content: string;
722
- tool_call_id: string;
701
+ role: "tool";
702
+ content: string;
703
+ tool_call_id: string;
723
704
  };
724
705
  type OpenAITool = {
725
- type: "function";
726
- function: {
727
- name: string;
728
- description?: string;
729
- parameters?: Record<string, unknown>;
730
- };
706
+ type: "function";
707
+ function: {
708
+ name: string;
709
+ description?: string;
710
+ parameters?: Record<string, unknown>;
711
+ };
731
712
  };
732
713
  type OpenAIToolCallDelta = {
733
- index?: number;
734
- id?: string;
735
- type?: "function";
736
- function?: {
737
- name?: string;
738
- arguments?: string;
739
- };
714
+ index?: number;
715
+ id?: string;
716
+ type?: "function";
717
+ function?: {
718
+ name?: string;
719
+ arguments?: string;
720
+ };
740
721
  };
741
722
  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;
723
+ id?: string;
724
+ choices?: Array<{
725
+ index?: number;
726
+ delta?: {
727
+ content?: string | null;
728
+ tool_calls?: OpenAIToolCallDelta[];
729
+ reasoning_content?: string;
730
+ reasoning?: string;
757
731
  };
732
+ finish_reason?: string | null;
733
+ }>;
734
+ usage?: {
735
+ prompt_tokens?: number;
736
+ completion_tokens?: number;
737
+ total_tokens?: number;
738
+ };
758
739
  };
759
740
  type NcpLLMApiInput = {
760
- messages: OpenAIChatMessage[];
761
- tools?: OpenAITool[];
762
- model?: string;
763
- thinkingLevel?: string | null;
764
- max_tokens?: number;
741
+ messages: OpenAIChatMessage[];
742
+ tools?: OpenAITool[];
743
+ model?: string;
744
+ thinkingLevel?: string | null;
745
+ max_tokens?: number;
765
746
  };
766
747
  type NcpLLMApiOptions = {
767
- signal?: AbortSignal;
768
- temperature?: number;
748
+ signal?: AbortSignal;
749
+ temperature?: number;
769
750
  };
770
751
  interface NcpLLMApi {
771
- generate(input: NcpLLMApiInput, options?: NcpLLMApiOptions): AsyncIterable<OpenAIChatChunk>;
752
+ generate(input: NcpLLMApiInput, options?: NcpLLMApiOptions): AsyncIterable<OpenAIChatChunk>;
772
753
  }
773
-
754
+ //#endregion
755
+ //#region src/agent-runtime/context-builder.d.ts
774
756
  type NcpContextPrepareOptions = {
775
- sessionMessages?: ReadonlyArray<NcpMessage>;
776
- systemPrompt?: string;
777
- maxMessages?: number;
757
+ sessionMessages?: ReadonlyArray<NcpMessage>;
758
+ systemPrompt?: string;
759
+ maxMessages?: number;
778
760
  };
779
761
  interface NcpContextBuilder {
780
- prepare(input: NcpAgentRunInput, options?: NcpContextPrepareOptions): NcpLLMApiInput;
762
+ prepare(input: NcpAgentRunInput, options?: NcpContextPrepareOptions): NcpLLMApiInput;
781
763
  }
782
-
764
+ //#endregion
765
+ //#region src/agent-runtime/tool.d.ts
783
766
  type NcpToolDefinition = {
784
- name: string;
785
- description?: string;
786
- parameters?: Record<string, unknown>;
767
+ name: string;
768
+ description?: string;
769
+ parameters?: Record<string, unknown>;
787
770
  };
788
771
  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>;
772
+ readonly name: string;
773
+ readonly description?: string;
774
+ readonly parameters?: Record<string, unknown>;
775
+ validateArgs?(args: Record<string, unknown>): string[];
776
+ execute(args: unknown): Promise<unknown>;
794
777
  }
795
778
  type NcpToolCallResult = {
796
- toolCallId: string;
797
- toolName: string;
798
- args: Record<string, unknown> | null;
799
- rawArgsText: string;
800
- result: unknown;
779
+ toolCallId: string;
780
+ toolName: string;
781
+ args: Record<string, unknown> | null;
782
+ rawArgsText: string;
783
+ result: unknown;
801
784
  };
802
785
  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
- };
786
+ ok: false;
787
+ error: {
788
+ code: "invalid_tool_arguments";
789
+ message: string;
790
+ toolCallId: string;
791
+ toolName: string;
792
+ rawArgumentsText: string;
793
+ issues: string[];
794
+ };
812
795
  };
813
796
  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>;
797
+ listTools(): ReadonlyArray<NcpTool>;
798
+ getTool(name: string): NcpTool | undefined;
799
+ getToolDefinitions(): ReadonlyArray<NcpToolDefinition>;
800
+ execute(toolCallId: string, toolName: string, args: unknown): Promise<unknown>;
818
801
  }
819
-
802
+ //#endregion
803
+ //#region src/agent-runtime/stream-encoder.d.ts
820
804
  type NcpEncodeContext = {
821
- sessionId: string;
822
- messageId: string;
823
- runId: string;
824
- correlationId?: string;
805
+ sessionId: string;
806
+ messageId: string;
807
+ runId: string;
808
+ correlationId?: string;
825
809
  };
826
810
  interface NcpStreamEncoder {
827
- encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncIterable<NcpEndpointEvent>;
811
+ encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncIterable<NcpEndpointEvent>;
828
812
  }
829
-
813
+ //#endregion
814
+ //#region src/agent-runtime/round-buffer.d.ts
830
815
  type NcpPendingToolCall = {
831
- toolCallId: string;
832
- toolName: string;
833
- args: unknown;
816
+ toolCallId: string;
817
+ toolName: string;
818
+ args: unknown;
834
819
  };
835
820
  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;
821
+ appendText(delta: string): void;
822
+ getText(): string;
823
+ appendToolCall(result: NcpToolCallResult): void;
824
+ getToolCalls(): ReadonlyArray<NcpToolCallResult>;
825
+ startToolCall(toolCallId: string, toolName: string): void;
826
+ appendToolCallArgs(args: unknown): void;
827
+ consumePendingToolCall(): NcpPendingToolCall | null;
828
+ clear(): void;
844
829
  }
845
-
830
+ //#endregion
831
+ //#region src/agent-backend/controller.d.ts
846
832
  type NcpAgentRunSendOptions = {
847
- signal?: AbortSignal;
833
+ signal?: AbortSignal;
848
834
  };
849
835
  type NcpAgentRunStreamOptions = {
850
- signal?: AbortSignal;
836
+ signal?: AbortSignal;
851
837
  };
852
838
  interface NcpAgentRunApi {
853
- send(envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions): AsyncIterable<NcpEndpointEvent>;
854
- stream(payload: NcpStreamRequestPayload, options?: NcpAgentRunStreamOptions): AsyncIterable<NcpEndpointEvent>;
855
- abort(payload: NcpMessageAbortPayload): Promise<void>;
839
+ send(envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions): AsyncIterable<NcpEndpointEvent>;
840
+ stream(payload: NcpStreamRequestPayload, options?: NcpAgentRunStreamOptions): AsyncIterable<NcpEndpointEvent>;
841
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
856
842
  }
857
843
  type NcpAgentStreamProvider = {
858
- stream(params: {
859
- payload: NcpStreamRequestPayload;
860
- signal: AbortSignal;
861
- }): AsyncIterable<NcpEndpointEvent>;
844
+ stream(params: {
845
+ payload: NcpStreamRequestPayload;
846
+ signal: AbortSignal;
847
+ }): AsyncIterable<NcpEndpointEvent>;
862
848
  };
863
-
849
+ //#endregion
850
+ //#region src/toolkit/conversation-state.d.ts
864
851
  /**
865
852
  * Read-only snapshot of conversation state maintained by a state manager.
866
853
  *
867
854
  * Consumed by UI or other layers; all updates flow through dispatch(event).
868
855
  */
869
856
  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;
857
+ /** Ordered list of finalized messages. */
858
+ readonly messages: ReadonlyArray<NcpMessage>;
859
+ /**
860
+ * Message currently being streamed (deltas apply here); null when idle.
861
+ * When message.completed is dispatched, this is appended to messages and cleared.
862
+ */
863
+ readonly streamingMessage: NcpMessage | null;
864
+ /** Latest error, if any (e.g. from message.failed or endpoint.error). */
865
+ readonly error: NcpError | null;
879
866
  }
880
867
  /**
881
868
  * Agent snapshot: extends base snapshot with active run state.
882
869
  * Use for UI run status, abort button enable/disable, and abort payload.
883
870
  */
884
871
  interface NcpAgentConversationSnapshot extends NcpConversationSnapshot {
885
- readonly activeRun: NcpRunContext | null;
872
+ readonly activeRun: NcpRunContext | null;
886
873
  }
887
874
  /**
888
875
  * State manager that holds conversation state and updates it from NCP events.
@@ -891,29 +878,30 @@ interface NcpAgentConversationSnapshot extends NcpConversationSnapshot {
891
878
  * Typically used by agent UIs or runtimes to keep a single source of truth for messages.
892
879
  */
893
880
  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;
881
+ /** Returns the current snapshot. Call after dispatch or in subscribe callback. */
882
+ getSnapshot(): NcpConversationSnapshot;
883
+ /**
884
+ * Applies an NCP event to internal state (messages, streamingMessage, error).
885
+ * Notifies subscribers after the update.
886
+ */
887
+ dispatch(event: NcpEndpointEvent): Promise<void>;
888
+ /**
889
+ * Applies multiple NCP events in order and notifies subscribers once after
890
+ * the batch finishes mutating state.
891
+ */
892
+ dispatchBatch(events: readonly NcpEndpointEvent[]): Promise<void>;
893
+ /**
894
+ * Subscribes to state changes. Listener is called after each dispatch that mutates state.
895
+ * Returns an unsubscribe function.
896
+ */
897
+ subscribe(listener: (snapshot: NcpConversationSnapshot) => void): () => void;
911
898
  }
912
-
899
+ //#endregion
900
+ //#region src/toolkit/agent/agent-conversation-state-manager.d.ts
913
901
  type NcpAgentConversationHydrationParams = {
914
- sessionId: string;
915
- messages: ReadonlyArray<NcpMessage>;
916
- activeRun?: NcpRunContext | null;
902
+ sessionId: string;
903
+ messages: ReadonlyArray<NcpMessage>;
904
+ activeRun?: NcpRunContext | null;
917
905
  };
918
906
  /**
919
907
  * Agent-scenario state manager: extends the generic conversation state manager
@@ -923,59 +911,61 @@ type NcpAgentConversationHydrationParams = {
923
911
  * and use these handlers to update messages, streamingMessage, and error.
924
912
  */
925
913
  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;
914
+ getSnapshot(): NcpAgentConversationSnapshot;
915
+ reset(): void;
916
+ hydrate(payload: NcpAgentConversationHydrationParams): void;
917
+ /** Local peer sent a message (outbound); typically non-streaming. Add to messages. */
918
+ handleMessageSent(payload: NcpMessageSentPayload): void;
919
+ handleMessageAbort(payload: NcpMessageAbortPayload): void;
920
+ handleMessageTextStart(payload: NcpTextStartPayload): void;
921
+ handleMessageTextDelta(payload: NcpTextDeltaPayload): void;
922
+ handleMessageTextEnd(payload: NcpTextEndPayload): void;
923
+ handleMessageReasoningStart(payload: NcpReasoningStartPayload): void;
924
+ handleMessageReasoningDelta(payload: NcpReasoningDeltaPayload): void;
925
+ handleMessageReasoningEnd(payload: NcpReasoningEndPayload): void;
926
+ handleMessageToolCallStart(payload: NcpToolCallStartPayload): void;
927
+ handleMessageToolCallArgs(payload: NcpToolCallArgsPayload): void;
928
+ handleMessageToolCallArgsDelta(payload: NcpToolCallArgsDeltaPayload): void;
929
+ handleMessageToolCallEnd(payload: NcpToolCallEndPayload): void;
930
+ handleMessageToolCallResult(payload: NcpToolCallResultPayload): void;
931
+ handleRunStarted(payload: NcpRunStartedPayload): void;
932
+ handleRunFinished(payload: NcpRunFinishedPayload): void;
933
+ handleRunError(payload: NcpRunErrorPayload): void;
934
+ handleRunMetadata(payload: NcpRunMetadataPayload): void;
935
+ handleEndpointError(payload: NcpError): void;
948
936
  }
949
-
937
+ //#endregion
938
+ //#region src/toolkit/reply-tags.d.ts
950
939
  type NcpReplyTagParseResult = {
951
- content: string;
952
- replyTo?: string;
940
+ content: string;
941
+ replyTo?: string;
953
942
  };
954
943
  declare function stripReplyTagsFromText(content: string, currentMessageId?: string): NcpReplyTagParseResult;
955
944
  declare function sanitizeAssistantReplyTags(message: NcpMessage, currentMessageId?: string): NcpMessage;
956
-
945
+ //#endregion
946
+ //#region src/toolkit/reasoning-normalization.d.ts
957
947
  type NcpAssistantReasoningNormalizationMode = "off" | "think-tags";
958
948
  type NcpAssistantReasoningSegment = {
959
- type: "text" | "reasoning";
960
- text: string;
949
+ type: "text" | "reasoning";
950
+ text: string;
961
951
  };
962
952
  declare function readAssistantReasoningNormalizationMode(value: unknown): NcpAssistantReasoningNormalizationMode | null;
963
953
  declare function readAssistantReasoningNormalizationModeFromMetadata(metadata: Record<string, unknown> | null | undefined): NcpAssistantReasoningNormalizationMode | null;
964
954
  declare function writeAssistantReasoningNormalizationModeToMetadata(metadata: Record<string, unknown>, mode: NcpAssistantReasoningNormalizationMode): Record<string, unknown>;
965
955
  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;
956
+ private readonly mode;
957
+ private buffer;
958
+ private phase;
959
+ private stripLeadingTextControlTags;
960
+ constructor(mode?: NcpAssistantReasoningNormalizationMode);
961
+ push(delta: string): NcpAssistantReasoningSegment[];
962
+ finish(): NcpAssistantReasoningSegment[];
963
+ private flush;
974
964
  }
975
965
  declare function normalizeAssistantText(text: string, mode: NcpAssistantReasoningNormalizationMode): {
976
- text: string;
977
- reasoning: string;
978
- parts: NcpAssistantReasoningSegment[];
966
+ text: string;
967
+ reasoning: string;
968
+ parts: NcpAssistantReasoningSegment[];
979
969
  };
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 };
970
+ //#endregion
971
+ 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, 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 };