@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.
- package/dist/index.d.ts +565 -574
- package/dist/index.js +254 -291
- 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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
233
|
-
|
|
211
|
+
limit?: number;
|
|
212
|
+
cursor?: string;
|
|
234
213
|
};
|
|
235
214
|
type ListMessagesOptions = {
|
|
236
|
-
|
|
237
|
-
|
|
215
|
+
limit?: number;
|
|
216
|
+
cursor?: string;
|
|
238
217
|
};
|
|
239
218
|
type NcpSessionPatch = {
|
|
240
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
249
|
+
sessionId: string;
|
|
250
|
+
message: NcpMessage;
|
|
251
|
+
correlationId?: string;
|
|
252
|
+
metadata?: Record<string, unknown>;
|
|
273
253
|
};
|
|
274
254
|
type NcpCompletedEnvelope = {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
255
|
+
sessionId: string;
|
|
256
|
+
message: NcpMessage;
|
|
257
|
+
correlationId?: string;
|
|
258
|
+
metadata?: Record<string, unknown>;
|
|
279
259
|
};
|
|
280
260
|
type NcpFailedEnvelope = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
261
|
+
sessionId: string;
|
|
262
|
+
messageId?: string;
|
|
263
|
+
error: NcpError;
|
|
264
|
+
correlationId?: string;
|
|
265
|
+
metadata?: Record<string, unknown>;
|
|
286
266
|
};
|
|
287
267
|
type NcpMessageAcceptedPayload = {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
295
|
-
|
|
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
|
-
|
|
303
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
290
|
+
sessionId: string;
|
|
291
|
+
message: NcpMessage;
|
|
292
|
+
metadata?: Record<string, unknown>;
|
|
313
293
|
};
|
|
314
294
|
type NcpTypingStartPayload = {
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
321
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
308
|
+
sessionId: string;
|
|
309
|
+
messageId: string;
|
|
310
|
+
readAt?: string;
|
|
311
|
+
readerId?: string;
|
|
335
312
|
};
|
|
336
313
|
type NcpMessageDeliveredPayload = {
|
|
337
|
-
|
|
338
|
-
|
|
314
|
+
sessionId: string;
|
|
315
|
+
messageId: string;
|
|
339
316
|
};
|
|
340
317
|
type NcpMessageRecalledPayload = {
|
|
341
|
-
|
|
342
|
-
|
|
318
|
+
sessionId: string;
|
|
319
|
+
messageId: string;
|
|
343
320
|
};
|
|
344
321
|
type NcpMessageReactionPayload = {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
329
|
+
sessionId?: string;
|
|
330
|
+
messageId?: string;
|
|
331
|
+
threadId?: string;
|
|
332
|
+
runId?: string;
|
|
357
333
|
};
|
|
358
334
|
type NcpRunFinishedPayload = {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
335
|
+
sessionId?: string;
|
|
336
|
+
messageId?: string;
|
|
337
|
+
threadId?: string;
|
|
338
|
+
runId?: string;
|
|
363
339
|
};
|
|
364
340
|
type NcpRunErrorPayload = {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
341
|
+
sessionId?: string;
|
|
342
|
+
messageId?: string;
|
|
343
|
+
error?: string;
|
|
344
|
+
threadId?: string;
|
|
345
|
+
runId?: string;
|
|
370
346
|
};
|
|
371
347
|
type NcpRunMetadataPayload = {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
348
|
+
sessionId?: string;
|
|
349
|
+
messageId?: string;
|
|
350
|
+
runId?: string;
|
|
351
|
+
metadata: Record<string, unknown>;
|
|
376
352
|
};
|
|
377
353
|
type NcpTextStartPayload = {
|
|
378
|
-
|
|
379
|
-
|
|
354
|
+
sessionId: string;
|
|
355
|
+
messageId: string;
|
|
380
356
|
};
|
|
381
357
|
type NcpTextDeltaPayload = {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
358
|
+
sessionId: string;
|
|
359
|
+
messageId: string;
|
|
360
|
+
delta: string;
|
|
385
361
|
};
|
|
386
362
|
type NcpTextEndPayload = {
|
|
387
|
-
|
|
388
|
-
|
|
363
|
+
sessionId: string;
|
|
364
|
+
messageId: string;
|
|
389
365
|
};
|
|
390
366
|
type NcpReasoningStartPayload = {
|
|
391
|
-
|
|
392
|
-
|
|
367
|
+
sessionId: string;
|
|
368
|
+
messageId: string;
|
|
393
369
|
};
|
|
394
370
|
type NcpReasoningDeltaPayload = {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
371
|
+
sessionId: string;
|
|
372
|
+
messageId: string;
|
|
373
|
+
delta: string;
|
|
398
374
|
};
|
|
399
375
|
type NcpReasoningEndPayload = {
|
|
400
|
-
|
|
401
|
-
|
|
376
|
+
sessionId: string;
|
|
377
|
+
messageId: string;
|
|
402
378
|
};
|
|
403
379
|
type NcpToolCallStartPayload = {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
380
|
+
sessionId: string;
|
|
381
|
+
messageId?: string;
|
|
382
|
+
toolCallId: string;
|
|
383
|
+
toolName: string;
|
|
408
384
|
};
|
|
409
385
|
type NcpToolCallArgsPayload = {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
386
|
+
sessionId: string;
|
|
387
|
+
toolCallId: string;
|
|
388
|
+
args: string;
|
|
413
389
|
};
|
|
414
390
|
type NcpToolCallArgsDeltaPayload = {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
391
|
+
sessionId: string;
|
|
392
|
+
messageId?: string;
|
|
393
|
+
toolCallId: string;
|
|
394
|
+
delta: string;
|
|
419
395
|
};
|
|
420
396
|
type NcpToolCallEndPayload = {
|
|
421
|
-
|
|
422
|
-
|
|
397
|
+
sessionId: string;
|
|
398
|
+
toolCallId: string;
|
|
423
399
|
};
|
|
424
400
|
type NcpToolCallResultPayload = {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
401
|
+
sessionId: string;
|
|
402
|
+
toolCallId: string;
|
|
403
|
+
content: unknown;
|
|
428
404
|
};
|
|
429
405
|
declare enum NcpEventType {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
440
|
+
type: NcpEventType.EndpointReady;
|
|
465
441
|
} | {
|
|
466
|
-
|
|
467
|
-
|
|
442
|
+
type: NcpEventType.MessageRequest;
|
|
443
|
+
payload: NcpRequestEnvelope;
|
|
468
444
|
} | {
|
|
469
|
-
|
|
470
|
-
|
|
445
|
+
type: NcpEventType.MessageStreamRequest;
|
|
446
|
+
payload: NcpStreamRequestPayload;
|
|
471
447
|
} | {
|
|
472
|
-
|
|
473
|
-
|
|
448
|
+
type: NcpEventType.MessageSent;
|
|
449
|
+
payload: NcpMessageSentPayload;
|
|
474
450
|
} | {
|
|
475
|
-
|
|
476
|
-
|
|
451
|
+
type: NcpEventType.MessageAccepted;
|
|
452
|
+
payload: NcpMessageAcceptedPayload;
|
|
477
453
|
} | {
|
|
478
|
-
|
|
479
|
-
|
|
454
|
+
type: NcpEventType.MessageIncoming;
|
|
455
|
+
payload: NcpResponseEnvelope;
|
|
480
456
|
} | {
|
|
481
|
-
|
|
482
|
-
|
|
457
|
+
type: NcpEventType.MessageCompleted;
|
|
458
|
+
payload: NcpCompletedEnvelope;
|
|
483
459
|
} | {
|
|
484
|
-
|
|
485
|
-
|
|
460
|
+
type: NcpEventType.MessageFailed;
|
|
461
|
+
payload: NcpFailedEnvelope;
|
|
486
462
|
} | {
|
|
487
|
-
|
|
488
|
-
|
|
463
|
+
type: NcpEventType.MessageAbort;
|
|
464
|
+
payload: NcpMessageAbortPayload;
|
|
489
465
|
} | {
|
|
490
|
-
|
|
491
|
-
|
|
466
|
+
type: NcpEventType.EndpointError;
|
|
467
|
+
payload: NcpError;
|
|
492
468
|
} | {
|
|
493
|
-
|
|
494
|
-
|
|
469
|
+
type: NcpEventType.RunStarted;
|
|
470
|
+
payload: NcpRunStartedPayload;
|
|
495
471
|
} | {
|
|
496
|
-
|
|
497
|
-
|
|
472
|
+
type: NcpEventType.RunFinished;
|
|
473
|
+
payload: NcpRunFinishedPayload;
|
|
498
474
|
} | {
|
|
499
|
-
|
|
500
|
-
|
|
475
|
+
type: NcpEventType.RunError;
|
|
476
|
+
payload: NcpRunErrorPayload;
|
|
501
477
|
} | {
|
|
502
|
-
|
|
503
|
-
|
|
478
|
+
type: NcpEventType.RunMetadata;
|
|
479
|
+
payload: NcpRunMetadataPayload;
|
|
504
480
|
} | {
|
|
505
|
-
|
|
506
|
-
|
|
481
|
+
type: NcpEventType.MessageTextStart;
|
|
482
|
+
payload: NcpTextStartPayload;
|
|
507
483
|
} | {
|
|
508
|
-
|
|
509
|
-
|
|
484
|
+
type: NcpEventType.MessageTextDelta;
|
|
485
|
+
payload: NcpTextDeltaPayload;
|
|
510
486
|
} | {
|
|
511
|
-
|
|
512
|
-
|
|
487
|
+
type: NcpEventType.MessageTextEnd;
|
|
488
|
+
payload: NcpTextEndPayload;
|
|
513
489
|
} | {
|
|
514
|
-
|
|
515
|
-
|
|
490
|
+
type: NcpEventType.MessageReasoningStart;
|
|
491
|
+
payload: NcpReasoningStartPayload;
|
|
516
492
|
} | {
|
|
517
|
-
|
|
518
|
-
|
|
493
|
+
type: NcpEventType.MessageReasoningDelta;
|
|
494
|
+
payload: NcpReasoningDeltaPayload;
|
|
519
495
|
} | {
|
|
520
|
-
|
|
521
|
-
|
|
496
|
+
type: NcpEventType.MessageReasoningEnd;
|
|
497
|
+
payload: NcpReasoningEndPayload;
|
|
522
498
|
} | {
|
|
523
|
-
|
|
524
|
-
|
|
499
|
+
type: NcpEventType.MessageToolCallStart;
|
|
500
|
+
payload: NcpToolCallStartPayload;
|
|
525
501
|
} | {
|
|
526
|
-
|
|
527
|
-
|
|
502
|
+
type: NcpEventType.MessageToolCallArgs;
|
|
503
|
+
payload: NcpToolCallArgsPayload;
|
|
528
504
|
} | {
|
|
529
|
-
|
|
530
|
-
|
|
505
|
+
type: NcpEventType.MessageToolCallArgsDelta;
|
|
506
|
+
payload: NcpToolCallArgsDeltaPayload;
|
|
531
507
|
} | {
|
|
532
|
-
|
|
533
|
-
|
|
508
|
+
type: NcpEventType.MessageToolCallEnd;
|
|
509
|
+
payload: NcpToolCallEndPayload;
|
|
534
510
|
} | {
|
|
535
|
-
|
|
536
|
-
|
|
511
|
+
type: NcpEventType.MessageToolCallResult;
|
|
512
|
+
payload: NcpToolCallResultPayload;
|
|
537
513
|
} | {
|
|
538
|
-
|
|
539
|
-
|
|
514
|
+
type: NcpEventType.TypingStart;
|
|
515
|
+
payload: NcpTypingStartPayload;
|
|
540
516
|
} | {
|
|
541
|
-
|
|
542
|
-
|
|
517
|
+
type: NcpEventType.TypingEnd;
|
|
518
|
+
payload: NcpTypingEndPayload;
|
|
543
519
|
} | {
|
|
544
|
-
|
|
545
|
-
|
|
520
|
+
type: NcpEventType.PresenceUpdated;
|
|
521
|
+
payload: NcpPresenceUpdatedPayload;
|
|
546
522
|
} | {
|
|
547
|
-
|
|
548
|
-
|
|
523
|
+
type: NcpEventType.MessageRead;
|
|
524
|
+
payload: NcpMessageReadPayload;
|
|
549
525
|
} | {
|
|
550
|
-
|
|
551
|
-
|
|
526
|
+
type: NcpEventType.MessageDelivered;
|
|
527
|
+
payload: NcpMessageDeliveredPayload;
|
|
552
528
|
} | {
|
|
553
|
-
|
|
554
|
-
|
|
529
|
+
type: NcpEventType.MessageRecalled;
|
|
530
|
+
payload: NcpMessageRecalledPayload;
|
|
555
531
|
} | {
|
|
556
|
-
|
|
557
|
-
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
-
|
|
582
|
-
|
|
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
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
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
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
658
|
+
sessionId: string;
|
|
659
|
+
messages: ReadonlyArray<NcpMessage>;
|
|
660
|
+
correlationId?: string;
|
|
661
|
+
metadata?: Record<string, unknown>;
|
|
681
662
|
};
|
|
682
663
|
type NcpAgentRunOptions = {
|
|
683
|
-
|
|
664
|
+
signal?: AbortSignal;
|
|
684
665
|
};
|
|
685
666
|
interface NcpAgentRuntime {
|
|
686
|
-
|
|
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
|
-
|
|
691
|
-
|
|
672
|
+
type: "text";
|
|
673
|
+
text: string;
|
|
692
674
|
} | {
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
675
|
+
type: "image_url";
|
|
676
|
+
image_url: {
|
|
677
|
+
url: string;
|
|
678
|
+
detail?: "low" | "high" | "auto";
|
|
679
|
+
};
|
|
698
680
|
};
|
|
699
681
|
type OpenAIToolCall = {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
682
|
+
id: string;
|
|
683
|
+
type: "function";
|
|
684
|
+
function: {
|
|
685
|
+
name: string;
|
|
686
|
+
arguments: string;
|
|
687
|
+
};
|
|
706
688
|
};
|
|
707
689
|
type OpenAIChatMessage = {
|
|
708
|
-
|
|
709
|
-
|
|
690
|
+
role: "system";
|
|
691
|
+
content: string;
|
|
710
692
|
} | {
|
|
711
|
-
|
|
712
|
-
|
|
693
|
+
role: "user";
|
|
694
|
+
content: string | OpenAIContentPart[];
|
|
713
695
|
} | {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
696
|
+
role: "assistant";
|
|
697
|
+
content?: string | null;
|
|
698
|
+
reasoning_content?: string;
|
|
699
|
+
tool_calls?: OpenAIToolCall[];
|
|
718
700
|
} | {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
701
|
+
role: "tool";
|
|
702
|
+
content: string;
|
|
703
|
+
tool_call_id: string;
|
|
722
704
|
};
|
|
723
705
|
type OpenAITool = {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
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
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
741
|
+
messages: OpenAIChatMessage[];
|
|
742
|
+
tools?: OpenAITool[];
|
|
743
|
+
model?: string;
|
|
744
|
+
thinkingLevel?: string | null;
|
|
745
|
+
max_tokens?: number;
|
|
764
746
|
};
|
|
765
747
|
type NcpLLMApiOptions = {
|
|
766
|
-
|
|
767
|
-
|
|
748
|
+
signal?: AbortSignal;
|
|
749
|
+
temperature?: number;
|
|
768
750
|
};
|
|
769
751
|
interface NcpLLMApi {
|
|
770
|
-
|
|
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
|
-
|
|
775
|
-
|
|
776
|
-
|
|
757
|
+
sessionMessages?: ReadonlyArray<NcpMessage>;
|
|
758
|
+
systemPrompt?: string;
|
|
759
|
+
maxMessages?: number;
|
|
777
760
|
};
|
|
778
761
|
interface NcpContextBuilder {
|
|
779
|
-
|
|
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
|
-
|
|
784
|
-
|
|
785
|
-
|
|
767
|
+
name: string;
|
|
768
|
+
description?: string;
|
|
769
|
+
parameters?: Record<string, unknown>;
|
|
786
770
|
};
|
|
787
771
|
interface NcpTool {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
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
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
805
|
+
sessionId: string;
|
|
806
|
+
messageId: string;
|
|
807
|
+
runId: string;
|
|
808
|
+
correlationId?: string;
|
|
824
809
|
};
|
|
825
810
|
interface NcpStreamEncoder {
|
|
826
|
-
|
|
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
|
-
|
|
831
|
-
|
|
832
|
-
|
|
816
|
+
toolCallId: string;
|
|
817
|
+
toolName: string;
|
|
818
|
+
args: unknown;
|
|
833
819
|
};
|
|
834
820
|
interface NcpRoundBuffer {
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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
|
-
|
|
833
|
+
signal?: AbortSignal;
|
|
847
834
|
};
|
|
848
835
|
type NcpAgentRunStreamOptions = {
|
|
849
|
-
|
|
836
|
+
signal?: AbortSignal;
|
|
850
837
|
};
|
|
851
838
|
interface NcpAgentRunApi {
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
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
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
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
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
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
|
-
|
|
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
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
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
|
-
|
|
914
|
-
|
|
915
|
-
|
|
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
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
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
|
-
|
|
951
|
-
|
|
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
|
-
|
|
959
|
-
|
|
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
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
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
|
-
|
|
976
|
-
|
|
977
|
-
|
|
966
|
+
text: string;
|
|
967
|
+
reasoning: string;
|
|
968
|
+
parts: NcpAssistantReasoningSegment[];
|
|
978
969
|
};
|
|
979
|
-
|
|
980
|
-
export {
|
|
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 };
|