@nextclaw/ncp 0.1.1 → 0.2.0
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/README.md +1 -1
- package/dist/index.d.ts +258 -93
- package/dist/index.js +37 -29
- package/package.json +1 -5
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -163,7 +163,7 @@ type NcpEndpointLatency = "realtime" | "seconds" | "minutes" | "hours" | "days";
|
|
|
163
163
|
*
|
|
164
164
|
* Consumers use the manifest for runtime capability discovery —
|
|
165
165
|
* e.g. whether to show a typing indicator, whether to offer file uploads,
|
|
166
|
-
* or whether
|
|
166
|
+
* or whether an existing run can be streamed again.
|
|
167
167
|
*/
|
|
168
168
|
type NcpEndpointManifest = {
|
|
169
169
|
/** Category of this endpoint. */
|
|
@@ -178,8 +178,8 @@ type NcpEndpointManifest = {
|
|
|
178
178
|
supportsAbort: boolean;
|
|
179
179
|
/** Whether this endpoint can push messages without a prior user request. */
|
|
180
180
|
supportsProactiveMessages: boolean;
|
|
181
|
-
/** Whether
|
|
182
|
-
|
|
181
|
+
/** Whether this endpoint can stream the live events of an active session by `sessionId`. */
|
|
182
|
+
supportsLiveSessionStream: boolean;
|
|
183
183
|
/**
|
|
184
184
|
* The subset of `NcpMessagePart` types this endpoint can send or receive.
|
|
185
185
|
* Using the literal union from `NcpMessagePart["type"]` prevents typos
|
|
@@ -215,20 +215,6 @@ type NcpError = {
|
|
|
215
215
|
/** Original cause — preserved for debugging but not guaranteed serializable. */
|
|
216
216
|
cause?: unknown;
|
|
217
217
|
};
|
|
218
|
-
/**
|
|
219
|
-
* Throwable form of `NcpError` for use in exception-based control flows.
|
|
220
|
-
*
|
|
221
|
-
* Bridges typed protocol errors with standard JS `Error` hierarchies so that
|
|
222
|
-
* `instanceof` checks and stack traces work as expected.
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* throw new NcpErrorException("auth-error", "Missing API key");
|
|
226
|
-
*/
|
|
227
|
-
declare class NcpErrorException extends Error {
|
|
228
|
-
readonly code: NcpErrorCode;
|
|
229
|
-
readonly details?: Record<string, unknown>;
|
|
230
|
-
constructor(code: NcpErrorCode, message: string, details?: Record<string, unknown>);
|
|
231
|
-
}
|
|
232
218
|
|
|
233
219
|
type NcpSessionStatus = "idle" | "running";
|
|
234
220
|
type NcpSessionSummary = {
|
|
@@ -236,7 +222,6 @@ type NcpSessionSummary = {
|
|
|
236
222
|
messageCount: number;
|
|
237
223
|
updatedAt: string;
|
|
238
224
|
status?: NcpSessionStatus;
|
|
239
|
-
activeRunId?: string;
|
|
240
225
|
};
|
|
241
226
|
type ListSessionsOptions = {
|
|
242
227
|
limit?: number;
|
|
@@ -295,20 +280,17 @@ type NcpMessageAcceptedPayload = {
|
|
|
295
280
|
correlationId?: string;
|
|
296
281
|
transportId?: string;
|
|
297
282
|
};
|
|
298
|
-
/** Payload for message.abort: identifies which
|
|
283
|
+
/** Payload for message.abort: identifies which session's active execution to cancel. */
|
|
299
284
|
type NcpMessageAbortPayload = {
|
|
285
|
+
sessionId: string;
|
|
300
286
|
messageId?: string;
|
|
301
|
-
correlationId?: string;
|
|
302
|
-
runId?: string;
|
|
303
287
|
};
|
|
304
288
|
/**
|
|
305
|
-
* Payload for message.
|
|
306
|
-
* Used when reconnecting
|
|
289
|
+
* Payload for message.stream-request: attach to the live event stream of a session.
|
|
290
|
+
* Used when reconnecting during an active response or attaching another live reader.
|
|
307
291
|
*/
|
|
308
|
-
type
|
|
292
|
+
type NcpStreamRequestPayload = {
|
|
309
293
|
sessionId: string;
|
|
310
|
-
remoteRunId: string;
|
|
311
|
-
fromEventIndex?: number;
|
|
312
294
|
metadata?: Record<string, unknown>;
|
|
313
295
|
};
|
|
314
296
|
/**
|
|
@@ -435,100 +417,134 @@ type NcpToolCallResultPayload = {
|
|
|
435
417
|
toolCallId: string;
|
|
436
418
|
content: unknown;
|
|
437
419
|
};
|
|
420
|
+
declare enum NcpEventType {
|
|
421
|
+
EndpointReady = "endpoint.ready",
|
|
422
|
+
EndpointError = "endpoint.error",
|
|
423
|
+
MessageRequest = "message.request",
|
|
424
|
+
MessageStreamRequest = "message.stream-request",
|
|
425
|
+
MessageSent = "message.sent",
|
|
426
|
+
MessageAccepted = "message.accepted",
|
|
427
|
+
MessageIncoming = "message.incoming",
|
|
428
|
+
MessageCompleted = "message.completed",
|
|
429
|
+
MessageFailed = "message.failed",
|
|
430
|
+
MessageAbort = "message.abort",
|
|
431
|
+
MessageTextStart = "message.text-start",
|
|
432
|
+
MessageTextDelta = "message.text-delta",
|
|
433
|
+
MessageTextEnd = "message.text-end",
|
|
434
|
+
MessageReasoningStart = "message.reasoning-start",
|
|
435
|
+
MessageReasoningDelta = "message.reasoning-delta",
|
|
436
|
+
MessageReasoningEnd = "message.reasoning-end",
|
|
437
|
+
MessageToolCallStart = "message.tool-call-start",
|
|
438
|
+
MessageToolCallArgs = "message.tool-call-args",
|
|
439
|
+
MessageToolCallArgsDelta = "message.tool-call-args-delta",
|
|
440
|
+
MessageToolCallEnd = "message.tool-call-end",
|
|
441
|
+
MessageToolCallResult = "message.tool-call-result",
|
|
442
|
+
MessageRead = "message.read",
|
|
443
|
+
MessageDelivered = "message.delivered",
|
|
444
|
+
MessageRecalled = "message.recalled",
|
|
445
|
+
MessageReaction = "message.reaction",
|
|
446
|
+
RunStarted = "run.started",
|
|
447
|
+
RunFinished = "run.finished",
|
|
448
|
+
RunError = "run.error",
|
|
449
|
+
RunMetadata = "run.metadata",
|
|
450
|
+
TypingStart = "typing.start",
|
|
451
|
+
TypingEnd = "typing.end",
|
|
452
|
+
PresenceUpdated = "presence.updated"
|
|
453
|
+
}
|
|
438
454
|
type NcpEndpointEvent = {
|
|
439
|
-
type:
|
|
455
|
+
type: NcpEventType.EndpointReady;
|
|
440
456
|
} | {
|
|
441
|
-
type:
|
|
457
|
+
type: NcpEventType.MessageRequest;
|
|
442
458
|
payload: NcpRequestEnvelope;
|
|
443
459
|
} | {
|
|
444
|
-
type:
|
|
445
|
-
payload:
|
|
460
|
+
type: NcpEventType.MessageStreamRequest;
|
|
461
|
+
payload: NcpStreamRequestPayload;
|
|
446
462
|
} | {
|
|
447
|
-
type:
|
|
463
|
+
type: NcpEventType.MessageSent;
|
|
448
464
|
payload: NcpMessageSentPayload;
|
|
449
465
|
} | {
|
|
450
|
-
type:
|
|
466
|
+
type: NcpEventType.MessageAccepted;
|
|
451
467
|
payload: NcpMessageAcceptedPayload;
|
|
452
468
|
} | {
|
|
453
|
-
type:
|
|
469
|
+
type: NcpEventType.MessageIncoming;
|
|
454
470
|
payload: NcpResponseEnvelope;
|
|
455
471
|
} | {
|
|
456
|
-
type:
|
|
472
|
+
type: NcpEventType.MessageCompleted;
|
|
457
473
|
payload: NcpCompletedEnvelope;
|
|
458
474
|
} | {
|
|
459
|
-
type:
|
|
475
|
+
type: NcpEventType.MessageFailed;
|
|
460
476
|
payload: NcpFailedEnvelope;
|
|
461
477
|
} | {
|
|
462
|
-
type:
|
|
478
|
+
type: NcpEventType.MessageAbort;
|
|
463
479
|
payload: NcpMessageAbortPayload;
|
|
464
480
|
} | {
|
|
465
|
-
type:
|
|
481
|
+
type: NcpEventType.EndpointError;
|
|
466
482
|
payload: NcpError;
|
|
467
483
|
} | {
|
|
468
|
-
type:
|
|
484
|
+
type: NcpEventType.RunStarted;
|
|
469
485
|
payload: NcpRunStartedPayload;
|
|
470
486
|
} | {
|
|
471
|
-
type:
|
|
487
|
+
type: NcpEventType.RunFinished;
|
|
472
488
|
payload: NcpRunFinishedPayload;
|
|
473
489
|
} | {
|
|
474
|
-
type:
|
|
490
|
+
type: NcpEventType.RunError;
|
|
475
491
|
payload: NcpRunErrorPayload;
|
|
476
492
|
} | {
|
|
477
|
-
type:
|
|
493
|
+
type: NcpEventType.RunMetadata;
|
|
478
494
|
payload: NcpRunMetadataPayload;
|
|
479
495
|
} | {
|
|
480
|
-
type:
|
|
496
|
+
type: NcpEventType.MessageTextStart;
|
|
481
497
|
payload: NcpTextStartPayload;
|
|
482
498
|
} | {
|
|
483
|
-
type:
|
|
499
|
+
type: NcpEventType.MessageTextDelta;
|
|
484
500
|
payload: NcpTextDeltaPayload;
|
|
485
501
|
} | {
|
|
486
|
-
type:
|
|
502
|
+
type: NcpEventType.MessageTextEnd;
|
|
487
503
|
payload: NcpTextEndPayload;
|
|
488
504
|
} | {
|
|
489
|
-
type:
|
|
505
|
+
type: NcpEventType.MessageReasoningStart;
|
|
490
506
|
payload: NcpReasoningStartPayload;
|
|
491
507
|
} | {
|
|
492
|
-
type:
|
|
508
|
+
type: NcpEventType.MessageReasoningDelta;
|
|
493
509
|
payload: NcpReasoningDeltaPayload;
|
|
494
510
|
} | {
|
|
495
|
-
type:
|
|
511
|
+
type: NcpEventType.MessageReasoningEnd;
|
|
496
512
|
payload: NcpReasoningEndPayload;
|
|
497
513
|
} | {
|
|
498
|
-
type:
|
|
514
|
+
type: NcpEventType.MessageToolCallStart;
|
|
499
515
|
payload: NcpToolCallStartPayload;
|
|
500
516
|
} | {
|
|
501
|
-
type:
|
|
517
|
+
type: NcpEventType.MessageToolCallArgs;
|
|
502
518
|
payload: NcpToolCallArgsPayload;
|
|
503
519
|
} | {
|
|
504
|
-
type:
|
|
520
|
+
type: NcpEventType.MessageToolCallArgsDelta;
|
|
505
521
|
payload: NcpToolCallArgsDeltaPayload;
|
|
506
522
|
} | {
|
|
507
|
-
type:
|
|
523
|
+
type: NcpEventType.MessageToolCallEnd;
|
|
508
524
|
payload: NcpToolCallEndPayload;
|
|
509
525
|
} | {
|
|
510
|
-
type:
|
|
526
|
+
type: NcpEventType.MessageToolCallResult;
|
|
511
527
|
payload: NcpToolCallResultPayload;
|
|
512
528
|
} | {
|
|
513
|
-
type:
|
|
529
|
+
type: NcpEventType.TypingStart;
|
|
514
530
|
payload: NcpTypingStartPayload;
|
|
515
531
|
} | {
|
|
516
|
-
type:
|
|
532
|
+
type: NcpEventType.TypingEnd;
|
|
517
533
|
payload: NcpTypingEndPayload;
|
|
518
534
|
} | {
|
|
519
|
-
type:
|
|
535
|
+
type: NcpEventType.PresenceUpdated;
|
|
520
536
|
payload: NcpPresenceUpdatedPayload;
|
|
521
537
|
} | {
|
|
522
|
-
type:
|
|
538
|
+
type: NcpEventType.MessageRead;
|
|
523
539
|
payload: NcpMessageReadPayload;
|
|
524
540
|
} | {
|
|
525
|
-
type:
|
|
541
|
+
type: NcpEventType.MessageDelivered;
|
|
526
542
|
payload: NcpMessageDeliveredPayload;
|
|
527
543
|
} | {
|
|
528
|
-
type:
|
|
544
|
+
type: NcpEventType.MessageRecalled;
|
|
529
545
|
payload: NcpMessageRecalledPayload;
|
|
530
546
|
} | {
|
|
531
|
-
type:
|
|
547
|
+
type: NcpEventType.MessageReaction;
|
|
532
548
|
payload: NcpMessageReactionPayload;
|
|
533
549
|
};
|
|
534
550
|
type NcpEndpointSubscriber = (event: NcpEndpointEvent) => void;
|
|
@@ -568,7 +584,7 @@ type NcpRunFinalMetadata = {
|
|
|
568
584
|
* const endpoint: NcpEndpoint = new MyAgentEndpoint(options);
|
|
569
585
|
* await endpoint.start();
|
|
570
586
|
* endpoint.subscribe((event) => { ... });
|
|
571
|
-
* await endpoint.emit({ type:
|
|
587
|
+
* await endpoint.emit({ type: NcpEventType.MessageRequest, payload: envelope });
|
|
572
588
|
*/
|
|
573
589
|
interface NcpEndpoint {
|
|
574
590
|
/** Static capability declaration — available before `start()` is called. */
|
|
@@ -598,7 +614,7 @@ interface NcpEndpoint {
|
|
|
598
614
|
*
|
|
599
615
|
* @example
|
|
600
616
|
* const unsubscribe = endpoint.subscribe((event) => {
|
|
601
|
-
* if (event.type ===
|
|
617
|
+
* if (event.type === NcpEventType.MessageCompleted) handleReply(event.payload);
|
|
602
618
|
* });
|
|
603
619
|
* unsubscribe();
|
|
604
620
|
*/
|
|
@@ -614,60 +630,207 @@ interface NcpEndpoint {
|
|
|
614
630
|
interface NcpAgentClientEndpoint extends NcpEndpoint {
|
|
615
631
|
/** Sends a new message request to the agent. Emits `message.request`. */
|
|
616
632
|
send(envelope: NcpRequestEnvelope): Promise<void>;
|
|
617
|
-
/**
|
|
618
|
-
|
|
619
|
-
/** Aborts the
|
|
620
|
-
abort(payload
|
|
633
|
+
/** Attaches to the live event stream of a session. Emits `message.stream-request`. */
|
|
634
|
+
stream(payload: NcpStreamRequestPayload): Promise<void>;
|
|
635
|
+
/** Aborts the active execution of a session. Emits `message.abort`. */
|
|
636
|
+
abort(payload: NcpMessageAbortPayload): Promise<void>;
|
|
621
637
|
}
|
|
622
638
|
|
|
623
639
|
/**
|
|
624
|
-
* Agent server-side endpoint: receives requests and
|
|
640
|
+
* Agent server-side endpoint: receives requests and produces downstream events.
|
|
625
641
|
*
|
|
626
642
|
* Extends `NcpEndpoint` with a manifest constraint (`endpointKind: "agent"`).
|
|
627
|
-
* Use this on the server side that
|
|
628
|
-
*
|
|
643
|
+
* Use this on the server side that handles send/stream/abort requests and emits
|
|
644
|
+
* downstream events (`message.incoming`, streaming deltas, `message.completed`, etc.).
|
|
629
645
|
*/
|
|
630
646
|
interface NcpAgentServerEndpoint extends NcpEndpoint {
|
|
631
647
|
readonly manifest: NcpEndpointManifest & {
|
|
632
648
|
endpointKind: "agent";
|
|
633
649
|
};
|
|
650
|
+
/** Handles a new message request from client side and yields produced events. */
|
|
651
|
+
send(envelope: NcpRequestEnvelope, options?: {
|
|
652
|
+
signal?: AbortSignal;
|
|
653
|
+
}): AsyncIterable<NcpEndpointEvent>;
|
|
654
|
+
/** Streams live events for an active session and yields produced events. */
|
|
655
|
+
stream(payload: NcpStreamRequestPayload, options?: {
|
|
656
|
+
signal?: AbortSignal;
|
|
657
|
+
}): AsyncIterable<NcpEndpointEvent>;
|
|
658
|
+
/** Aborts the active execution of a session on server side. */
|
|
659
|
+
abort(payload: NcpMessageAbortPayload): Promise<void>;
|
|
660
|
+
/**
|
|
661
|
+
* Publishes server-downstream events (typically sent to frontend subscribers/transports).
|
|
662
|
+
* For handling client requests, prefer `send` / `stream` / `abort`.
|
|
663
|
+
*/
|
|
664
|
+
emit(event: NcpEndpointEvent): Promise<void>;
|
|
634
665
|
}
|
|
635
666
|
|
|
636
|
-
/**
|
|
637
|
-
* Creates an NcpAgentClientEndpoint that forwards to an in-process NcpAgentServerEndpoint.
|
|
638
|
-
* Use when the agent runs in-process and you need to pass a client endpoint to the HTTP server.
|
|
639
|
-
*/
|
|
640
|
-
declare function createAgentClientFromServer(server: NcpAgentServerEndpoint): NcpAgentClientEndpoint;
|
|
641
|
-
|
|
642
667
|
type NcpAgentRunInput = {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
kind: "resume";
|
|
647
|
-
payload: NcpResumeRequestPayload;
|
|
668
|
+
sessionId: string;
|
|
669
|
+
messages: ReadonlyArray<NcpMessage>;
|
|
670
|
+
correlationId?: string;
|
|
648
671
|
};
|
|
649
672
|
type NcpAgentRunOptions = {
|
|
650
673
|
signal?: AbortSignal;
|
|
651
|
-
sessionMessages?: ReadonlyArray<NcpMessage>;
|
|
652
674
|
};
|
|
653
675
|
interface NcpAgentRuntime {
|
|
654
676
|
run(input: NcpAgentRunInput, options?: NcpAgentRunOptions): AsyncIterable<NcpEndpointEvent>;
|
|
655
677
|
}
|
|
656
678
|
|
|
657
|
-
type
|
|
679
|
+
type OpenAIContentPart = {
|
|
680
|
+
type: "text";
|
|
681
|
+
text: string;
|
|
682
|
+
} | {
|
|
683
|
+
type: "image_url";
|
|
684
|
+
image_url: {
|
|
685
|
+
url: string;
|
|
686
|
+
detail?: "low" | "high" | "auto";
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
type OpenAIToolCall = {
|
|
690
|
+
id: string;
|
|
691
|
+
type: "function";
|
|
692
|
+
function: {
|
|
693
|
+
name: string;
|
|
694
|
+
arguments: string;
|
|
695
|
+
};
|
|
696
|
+
};
|
|
697
|
+
type OpenAIChatMessage = {
|
|
698
|
+
role: "system";
|
|
699
|
+
content: string;
|
|
700
|
+
} | {
|
|
701
|
+
role: "user";
|
|
702
|
+
content: string | OpenAIContentPart[];
|
|
703
|
+
} | {
|
|
704
|
+
role: "assistant";
|
|
705
|
+
content?: string | null;
|
|
706
|
+
tool_calls?: OpenAIToolCall[];
|
|
707
|
+
} | {
|
|
708
|
+
role: "tool";
|
|
709
|
+
content: string;
|
|
710
|
+
tool_call_id: string;
|
|
711
|
+
};
|
|
712
|
+
type OpenAITool = {
|
|
713
|
+
type: "function";
|
|
714
|
+
function: {
|
|
715
|
+
name: string;
|
|
716
|
+
description?: string;
|
|
717
|
+
parameters?: Record<string, unknown>;
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
type OpenAIToolCallDelta = {
|
|
721
|
+
index?: number;
|
|
722
|
+
id?: string;
|
|
723
|
+
type?: "function";
|
|
724
|
+
function?: {
|
|
725
|
+
name?: string;
|
|
726
|
+
arguments?: string;
|
|
727
|
+
};
|
|
728
|
+
};
|
|
729
|
+
type OpenAIChatChunk = {
|
|
730
|
+
id?: string;
|
|
731
|
+
choices?: Array<{
|
|
732
|
+
index?: number;
|
|
733
|
+
delta?: {
|
|
734
|
+
content?: string | null;
|
|
735
|
+
tool_calls?: OpenAIToolCallDelta[];
|
|
736
|
+
reasoning_content?: string;
|
|
737
|
+
reasoning?: string;
|
|
738
|
+
};
|
|
739
|
+
finish_reason?: string | null;
|
|
740
|
+
}>;
|
|
741
|
+
usage?: {
|
|
742
|
+
prompt_tokens?: number;
|
|
743
|
+
completion_tokens?: number;
|
|
744
|
+
total_tokens?: number;
|
|
745
|
+
};
|
|
746
|
+
};
|
|
747
|
+
type NcpLLMApiInput = {
|
|
748
|
+
messages: OpenAIChatMessage[];
|
|
749
|
+
tools?: OpenAITool[];
|
|
750
|
+
model?: string;
|
|
751
|
+
max_tokens?: number;
|
|
752
|
+
};
|
|
753
|
+
type NcpLLMApiOptions = {
|
|
754
|
+
signal?: AbortSignal;
|
|
755
|
+
temperature?: number;
|
|
756
|
+
};
|
|
757
|
+
interface NcpLLMApi {
|
|
758
|
+
generate(input: NcpLLMApiInput, options?: NcpLLMApiOptions): AsyncIterable<OpenAIChatChunk>;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
type NcpContextPrepareOptions = {
|
|
762
|
+
sessionMessages?: ReadonlyArray<NcpMessage>;
|
|
763
|
+
systemPrompt?: string;
|
|
764
|
+
maxMessages?: number;
|
|
765
|
+
};
|
|
766
|
+
interface NcpContextBuilder {
|
|
767
|
+
prepare(input: NcpAgentRunInput, options?: NcpContextPrepareOptions): NcpLLMApiInput;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
type NcpToolDefinition = {
|
|
771
|
+
name: string;
|
|
772
|
+
description?: string;
|
|
773
|
+
parameters?: Record<string, unknown>;
|
|
774
|
+
};
|
|
775
|
+
interface NcpTool {
|
|
776
|
+
readonly name: string;
|
|
777
|
+
readonly description?: string;
|
|
778
|
+
readonly parameters?: Record<string, unknown>;
|
|
779
|
+
execute(args: unknown): Promise<unknown>;
|
|
780
|
+
}
|
|
781
|
+
type NcpToolCallResult = {
|
|
782
|
+
toolCallId: string;
|
|
783
|
+
toolName: string;
|
|
784
|
+
args: unknown;
|
|
785
|
+
result: unknown;
|
|
786
|
+
};
|
|
787
|
+
interface NcpToolRegistry {
|
|
788
|
+
listTools(): ReadonlyArray<NcpTool>;
|
|
789
|
+
getTool(name: string): NcpTool | undefined;
|
|
790
|
+
getToolDefinitions(): ReadonlyArray<NcpToolDefinition>;
|
|
791
|
+
execute(toolCallId: string, toolName: string, args: unknown): Promise<unknown>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
type NcpEncodeContext = {
|
|
795
|
+
sessionId: string;
|
|
796
|
+
messageId: string;
|
|
797
|
+
runId: string;
|
|
798
|
+
correlationId?: string;
|
|
799
|
+
};
|
|
800
|
+
interface NcpStreamEncoder {
|
|
801
|
+
encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncIterable<NcpEndpointEvent>;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
type NcpPendingToolCall = {
|
|
805
|
+
toolCallId: string;
|
|
806
|
+
toolName: string;
|
|
807
|
+
args: unknown;
|
|
808
|
+
};
|
|
809
|
+
interface NcpRoundBuffer {
|
|
810
|
+
appendText(delta: string): void;
|
|
811
|
+
getText(): string;
|
|
812
|
+
appendToolCall(result: NcpToolCallResult): void;
|
|
813
|
+
getToolCalls(): ReadonlyArray<NcpToolCallResult>;
|
|
814
|
+
startToolCall(toolCallId: string, toolName: string): void;
|
|
815
|
+
appendToolCallArgs(args: unknown): void;
|
|
816
|
+
consumePendingToolCall(): NcpPendingToolCall | null;
|
|
817
|
+
clear(): void;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
type NcpAgentRunSendOptions = {
|
|
658
821
|
signal?: AbortSignal;
|
|
659
822
|
};
|
|
660
|
-
type
|
|
823
|
+
type NcpAgentRunStreamOptions = {
|
|
661
824
|
signal?: AbortSignal;
|
|
662
825
|
};
|
|
663
|
-
interface
|
|
664
|
-
send(envelope: NcpRequestEnvelope, options?:
|
|
665
|
-
|
|
826
|
+
interface NcpAgentRunApi {
|
|
827
|
+
send(envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions): AsyncIterable<NcpEndpointEvent>;
|
|
828
|
+
stream(payload: NcpStreamRequestPayload, options?: NcpAgentRunStreamOptions): AsyncIterable<NcpEndpointEvent>;
|
|
666
829
|
abort(payload: NcpMessageAbortPayload): Promise<void>;
|
|
667
830
|
}
|
|
668
|
-
type
|
|
831
|
+
type NcpAgentStreamProvider = {
|
|
669
832
|
stream(params: {
|
|
670
|
-
payload:
|
|
833
|
+
payload: NcpStreamRequestPayload;
|
|
671
834
|
signal: AbortSignal;
|
|
672
835
|
}): AsyncIterable<NcpEndpointEvent>;
|
|
673
836
|
};
|
|
@@ -716,6 +879,11 @@ interface NcpConversationStateManager {
|
|
|
716
879
|
subscribe(listener: (snapshot: NcpConversationSnapshot) => void): () => void;
|
|
717
880
|
}
|
|
718
881
|
|
|
882
|
+
type NcpAgentConversationHydrationParams = {
|
|
883
|
+
sessionId: string;
|
|
884
|
+
messages: ReadonlyArray<NcpMessage>;
|
|
885
|
+
activeRun?: NcpRunContext | null;
|
|
886
|
+
};
|
|
719
887
|
/**
|
|
720
888
|
* Agent-scenario state manager: extends the generic conversation state manager
|
|
721
889
|
* with explicit handle methods for each NCP event type that affects agent conversation state.
|
|
@@ -725,13 +893,10 @@ interface NcpConversationStateManager {
|
|
|
725
893
|
*/
|
|
726
894
|
interface NcpAgentConversationStateManager extends NcpConversationStateManager {
|
|
727
895
|
getSnapshot(): NcpAgentConversationSnapshot;
|
|
728
|
-
|
|
896
|
+
reset(): void;
|
|
897
|
+
hydrate(payload: NcpAgentConversationHydrationParams): void;
|
|
729
898
|
/** Local peer sent a message (outbound); typically non-streaming. Add to messages. */
|
|
730
899
|
handleMessageSent(payload: NcpMessageSentPayload): void;
|
|
731
|
-
handleMessageAccepted(payload: NcpMessageAcceptedPayload): void;
|
|
732
|
-
handleMessageIncoming(payload: NcpResponseEnvelope): void;
|
|
733
|
-
handleMessageCompleted(payload: NcpCompletedEnvelope): void;
|
|
734
|
-
handleMessageFailed(payload: NcpFailedEnvelope): void;
|
|
735
900
|
handleMessageAbort(payload: NcpMessageAbortPayload): void;
|
|
736
901
|
handleMessageTextStart(payload: NcpTextStartPayload): void;
|
|
737
902
|
handleMessageTextDelta(payload: NcpTextDeltaPayload): void;
|
|
@@ -751,4 +916,4 @@ interface NcpAgentConversationStateManager extends NcpConversationStateManager {
|
|
|
751
916
|
handleEndpointError(payload: NcpError): void;
|
|
752
917
|
}
|
|
753
918
|
|
|
754
|
-
export { type ListMessagesOptions, type ListSessionsOptions, type NcpActionPart, type
|
|
919
|
+
export { type ListMessagesOptions, type ListSessionsOptions, type NcpActionPart, type NcpAgentClientEndpoint, type NcpAgentConversationHydrationParams, type NcpAgentConversationSnapshot, type NcpAgentConversationStateManager, type NcpAgentRunApi, type NcpAgentRunInput, type NcpAgentRunOptions, type NcpAgentRunSendOptions, type NcpAgentRunStreamOptions, type NcpAgentRuntime, type NcpAgentServerEndpoint, type NcpAgentStreamProvider, type NcpCardPart, type NcpCompletedEnvelope, type NcpContextBuilder, type NcpContextPrepareOptions, type NcpConversationSnapshot, type NcpConversationStateManager, type NcpEncodeContext, type NcpEndpoint, type NcpEndpointEvent, type NcpEndpointKind, type NcpEndpointLatency, type NcpEndpointManifest, type NcpEndpointSubscriber, type NcpError, type NcpErrorCode, NcpEventType, type NcpExtensionPart, type NcpFailedEnvelope, type NcpFilePart, type NcpLLMApi, type NcpLLMApiInput, type NcpLLMApiOptions, type NcpMessage, type NcpMessageAbortPayload, type NcpMessageAcceptedPayload, type NcpMessageDeliveredPayload, type NcpMessagePart, type NcpMessageReactionPayload, type NcpMessageReadPayload, type NcpMessageRecalledPayload, type NcpMessageRole, type NcpMessageSentPayload, type NcpMessageStatus, type NcpPendingToolCall, type NcpPresenceUpdatedPayload, type NcpReasoningDeltaPayload, type NcpReasoningEndPayload, type NcpReasoningPart, type NcpReasoningStartPayload, type NcpRequestEnvelope, type NcpResponseEnvelope, type NcpRichTextPart, type NcpRoundBuffer, type NcpRunContext, type NcpRunErrorPayload, type NcpRunFinalMetadata, type NcpRunFinishedPayload, type NcpRunMetadataPayload, type NcpRunReadyMetadata, type NcpRunStartedPayload, type NcpSessionApi, type NcpSessionStatus, type NcpSessionSummary, type NcpSourcePart, type NcpStepStartPart, type NcpStreamEncoder, type NcpStreamRequestPayload, type NcpTextDeltaPayload, type NcpTextEndPayload, type NcpTextPart, type NcpTextStartPayload, type NcpTool, type NcpToolCallArgsDeltaPayload, type NcpToolCallArgsPayload, type NcpToolCallEndPayload, type NcpToolCallResult, type NcpToolCallResultPayload, type NcpToolCallStartPayload, type NcpToolDefinition, type NcpToolInvocationPart, type NcpToolRegistry, type NcpTypingEndPayload, type NcpTypingStartPayload, type OpenAIChatChunk, type OpenAIChatMessage, type OpenAIContentPart, type OpenAITool, type OpenAIToolCall, type OpenAIToolCallDelta };
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
|
-
// src/types/
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
// src/types/events.ts
|
|
2
|
+
var NcpEventType = /* @__PURE__ */ ((NcpEventType2) => {
|
|
3
|
+
NcpEventType2["EndpointReady"] = "endpoint.ready";
|
|
4
|
+
NcpEventType2["EndpointError"] = "endpoint.error";
|
|
5
|
+
NcpEventType2["MessageRequest"] = "message.request";
|
|
6
|
+
NcpEventType2["MessageStreamRequest"] = "message.stream-request";
|
|
7
|
+
NcpEventType2["MessageSent"] = "message.sent";
|
|
8
|
+
NcpEventType2["MessageAccepted"] = "message.accepted";
|
|
9
|
+
NcpEventType2["MessageIncoming"] = "message.incoming";
|
|
10
|
+
NcpEventType2["MessageCompleted"] = "message.completed";
|
|
11
|
+
NcpEventType2["MessageFailed"] = "message.failed";
|
|
12
|
+
NcpEventType2["MessageAbort"] = "message.abort";
|
|
13
|
+
NcpEventType2["MessageTextStart"] = "message.text-start";
|
|
14
|
+
NcpEventType2["MessageTextDelta"] = "message.text-delta";
|
|
15
|
+
NcpEventType2["MessageTextEnd"] = "message.text-end";
|
|
16
|
+
NcpEventType2["MessageReasoningStart"] = "message.reasoning-start";
|
|
17
|
+
NcpEventType2["MessageReasoningDelta"] = "message.reasoning-delta";
|
|
18
|
+
NcpEventType2["MessageReasoningEnd"] = "message.reasoning-end";
|
|
19
|
+
NcpEventType2["MessageToolCallStart"] = "message.tool-call-start";
|
|
20
|
+
NcpEventType2["MessageToolCallArgs"] = "message.tool-call-args";
|
|
21
|
+
NcpEventType2["MessageToolCallArgsDelta"] = "message.tool-call-args-delta";
|
|
22
|
+
NcpEventType2["MessageToolCallEnd"] = "message.tool-call-end";
|
|
23
|
+
NcpEventType2["MessageToolCallResult"] = "message.tool-call-result";
|
|
24
|
+
NcpEventType2["MessageRead"] = "message.read";
|
|
25
|
+
NcpEventType2["MessageDelivered"] = "message.delivered";
|
|
26
|
+
NcpEventType2["MessageRecalled"] = "message.recalled";
|
|
27
|
+
NcpEventType2["MessageReaction"] = "message.reaction";
|
|
28
|
+
NcpEventType2["RunStarted"] = "run.started";
|
|
29
|
+
NcpEventType2["RunFinished"] = "run.finished";
|
|
30
|
+
NcpEventType2["RunError"] = "run.error";
|
|
31
|
+
NcpEventType2["RunMetadata"] = "run.metadata";
|
|
32
|
+
NcpEventType2["TypingStart"] = "typing.start";
|
|
33
|
+
NcpEventType2["TypingEnd"] = "typing.end";
|
|
34
|
+
NcpEventType2["PresenceUpdated"] = "presence.updated";
|
|
35
|
+
return NcpEventType2;
|
|
36
|
+
})(NcpEventType || {});
|
|
28
37
|
export {
|
|
29
|
-
|
|
30
|
-
createAgentClientFromServer
|
|
38
|
+
NcpEventType
|
|
31
39
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextclaw/ncp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NextClaw Communication Protocol core abstractions and types.",
|
|
6
6
|
"type": "module",
|
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "^20.17.6",
|
|
19
|
-
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
20
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
21
|
-
"eslint": "^8.57.1",
|
|
22
|
-
"eslint-config-prettier": "^9.1.0",
|
|
23
19
|
"prettier": "^3.3.3",
|
|
24
20
|
"tsup": "^8.3.5",
|
|
25
21
|
"typescript": "^5.6.3"
|