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