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