@nextclaw/ncp 0.1.0 → 0.1.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/README.md CHANGED
@@ -11,7 +11,7 @@ pnpm -C packages/nextclaw-ncp build
11
11
  ## Scope
12
12
 
13
13
  - NCP manifest, message, session, and error definitions
14
- - Generic endpoint base class (`AbstractEndpoint`)
14
+ - Endpoint interfaces (`NcpEndpoint`, `NcpAgentServerEndpoint`, `NcpAgentClientEndpoint`)
15
15
 
16
16
  ## Usage
17
17
 
package/dist/index.d.ts CHANGED
@@ -130,7 +130,7 @@ type NcpMessage = {
130
130
  /** Globally unique message identifier. */
131
131
  id: string;
132
132
  /** The session this message belongs to. */
133
- sessionKey: string;
133
+ sessionId: string;
134
134
  role: NcpMessageRole;
135
135
  status: NcpMessageStatus;
136
136
  parts: NcpMessagePart[];
@@ -178,7 +178,7 @@ 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 a disconnected session can be resumed by the same `sessionKey`. */
181
+ /** Whether a disconnected session can be resumed by the same `sessionId`. */
182
182
  supportsSessionResume: boolean;
183
183
  /**
184
184
  * The subset of `NcpMessagePart` types this endpoint can send or receive.
@@ -230,65 +230,31 @@ declare class NcpErrorException extends Error {
230
230
  constructor(code: NcpErrorCode, message: string, details?: Record<string, unknown>);
231
231
  }
232
232
 
233
- /**
234
- * Stable mapping between an NCP-internal session key and the endpoint's
235
- * native session identifier.
236
- *
237
- * A single NCP session may span multiple endpoint sessions over time
238
- * (e.g. after reconnects). This binding is the source of truth for that mapping.
239
- */
240
- type NcpSessionBinding = {
241
- /** The endpoint that owns this session. */
242
- endpointId: string;
243
- /** NCP-internal session identifier — stable across reconnects. */
244
- sessionKey: string;
245
- /**
246
- * The session identifier used by the endpoint itself (e.g. an OpenAI thread id,
247
- * a Slack channel + thread_ts pair, or a vendor-specific conversation id).
248
- */
249
- endpointSessionId: string;
250
- /** Arbitrary metadata for adapter-specific session context. */
251
- metadata?: Record<string, unknown>;
252
- };
253
- /**
254
- * Lightweight snapshot of session state for orchestration and observability.
255
- *
256
- * Not a full history — use `NcpSessionContract.appendMessage` for the message log.
257
- */
258
- type NcpSessionState = {
259
- sessionKey: string;
260
- endpointId: string;
261
- /** Present once a binding has been established. */
262
- endpointSessionId?: string;
263
- /** Total number of messages appended to this session. */
233
+ type NcpSessionStatus = "idle" | "running";
234
+ type NcpSessionSummary = {
235
+ sessionId: string;
264
236
  messageCount: number;
265
- /** ISO 8601 timestamp of the last state mutation. */
266
237
  updatedAt: string;
238
+ status?: NcpSessionStatus;
239
+ activeRunId?: string;
240
+ };
241
+ type ListSessionsOptions = {
242
+ limit?: number;
243
+ cursor?: string;
244
+ };
245
+ type ListMessagesOptions = {
246
+ limit?: number;
247
+ cursor?: string;
267
248
  };
268
249
  /**
269
- * Minimal storage contract for NCP session management.
270
- *
271
- * Intentionally small for early protocol iterations — implementations can
272
- * extend it with querying, TTL, or event hooks as requirements grow.
250
+ * API for session list, message history, and session lifecycle.
251
+ * Implementations that support persistence can provide this alongside NcpAgentClientEndpoint.
273
252
  */
274
- interface NcpSessionContract {
275
- /**
276
- * Looks up the binding for a given session key.
277
- * Returns `null` if no binding exists yet.
278
- */
279
- resolveBinding(sessionKey: string): Promise<NcpSessionBinding | null>;
280
- /**
281
- * Creates or updates the binding for a session key.
282
- * Implementations should treat this as an upsert (idempotent on `sessionKey`).
283
- */
284
- upsertBinding(binding: NcpSessionBinding): Promise<void>;
285
- /**
286
- * Appends a message to the session's immutable message log.
287
- *
288
- * Implementations MUST treat this as append-only — existing messages
289
- * should never be mutated or deleted through this method.
290
- */
291
- appendMessage(message: NcpMessage): Promise<void>;
253
+ interface NcpSessionApi {
254
+ listSessions(options?: ListSessionsOptions): Promise<NcpSessionSummary[]>;
255
+ listSessionMessages(sessionId: string, options?: ListMessagesOptions): Promise<NcpMessage[]>;
256
+ getSession(sessionId: string): Promise<NcpSessionSummary | null>;
257
+ deleteSession(sessionId: string): Promise<void>;
292
258
  }
293
259
 
294
260
  /**
@@ -299,26 +265,26 @@ interface NcpSessionContract {
299
265
  * instead; endpoints or upper layers choose as needed.
300
266
  */
301
267
  type NcpRequestEnvelope = {
302
- sessionKey: string;
268
+ sessionId: string;
303
269
  message: NcpMessage;
304
270
  correlationId?: string;
305
271
  metadata?: Record<string, unknown>;
306
272
  };
307
273
  /** Payload for message.incoming: message content from the other peer (partial or full). */
308
274
  type NcpResponseEnvelope = {
309
- sessionKey: string;
275
+ sessionId: string;
310
276
  message: NcpMessage;
311
277
  correlationId?: string;
312
278
  metadata?: Record<string, unknown>;
313
279
  };
314
280
  type NcpCompletedEnvelope = {
315
- sessionKey: string;
281
+ sessionId: string;
316
282
  message: NcpMessage;
317
283
  correlationId?: string;
318
284
  metadata?: Record<string, unknown>;
319
285
  };
320
286
  type NcpFailedEnvelope = {
321
- sessionKey: string;
287
+ sessionId: string;
322
288
  messageId?: string;
323
289
  error: NcpError;
324
290
  correlationId?: string;
@@ -329,51 +295,63 @@ type NcpMessageAcceptedPayload = {
329
295
  correlationId?: string;
330
296
  transportId?: string;
331
297
  };
298
+ /** Payload for message.abort: identifies which request or run to cancel. */
332
299
  type NcpMessageAbortPayload = {
333
300
  messageId?: string;
334
301
  correlationId?: string;
302
+ runId?: string;
303
+ };
304
+ /**
305
+ * Payload for message.resume-request: resume an existing run by its remote id.
306
+ * Used when reconnecting to a stream (e.g. after page refresh).
307
+ */
308
+ type NcpResumeRequestPayload = {
309
+ sessionId: string;
310
+ remoteRunId: string;
311
+ fromEventIndex?: number;
312
+ metadata?: Record<string, unknown>;
335
313
  };
336
314
  /**
337
315
  * Payload for message.sent: the local peer has sent a message (outbound).
338
316
  * Typically non-streaming; add the message to the local conversation state.
339
317
  */
340
318
  type NcpMessageSentPayload = {
341
- sessionKey: string;
319
+ sessionId: string;
342
320
  message: NcpMessage;
343
321
  metadata?: Record<string, unknown>;
344
322
  };
345
323
  type NcpTypingStartPayload = {
346
- sessionKey: string;
324
+ sessionId: string;
347
325
  /** Participant who is typing (human user or bot/assistant). */
348
326
  userId?: string;
349
327
  };
350
328
  type NcpTypingEndPayload = {
351
- sessionKey: string;
329
+ sessionId: string;
352
330
  /** Participant who stopped typing (human user or bot/assistant). */
353
331
  userId?: string;
354
332
  };
355
333
  type NcpPresenceUpdatedPayload = {
356
- sessionKey: string;
334
+ sessionId: string;
357
335
  /** Participant this presence applies to (human user or bot/assistant). */
358
336
  userId?: string;
359
337
  status: "online" | "offline" | "away";
360
338
  };
361
339
  type NcpMessageReadPayload = {
362
- sessionKey: string;
340
+ sessionId: string;
363
341
  messageId: string;
364
342
  readAt?: string;
365
343
  readerId?: string;
366
344
  };
367
345
  type NcpMessageDeliveredPayload = {
368
- sessionKey: string;
346
+ sessionId: string;
369
347
  messageId: string;
370
348
  };
371
349
  type NcpMessageRecalledPayload = {
372
- sessionKey: string;
350
+ sessionId: string;
373
351
  messageId: string;
374
352
  };
375
353
  type NcpMessageReactionPayload = {
376
- sessionKey: string;
354
+ sessionId: string;
377
355
  messageId: string;
378
356
  reaction: string;
379
357
  added: boolean;
@@ -381,79 +359,79 @@ type NcpMessageReactionPayload = {
381
359
  userId?: string;
382
360
  };
383
361
  type NcpRunStartedPayload = {
384
- sessionKey?: string;
362
+ sessionId?: string;
385
363
  messageId?: string;
386
364
  threadId?: string;
387
365
  runId?: string;
388
366
  };
389
367
  type NcpRunFinishedPayload = {
390
- sessionKey?: string;
368
+ sessionId?: string;
391
369
  messageId?: string;
392
370
  threadId?: string;
393
371
  runId?: string;
394
372
  };
395
373
  type NcpRunErrorPayload = {
396
- sessionKey?: string;
374
+ sessionId?: string;
397
375
  messageId?: string;
398
376
  error?: string;
399
377
  threadId?: string;
400
378
  runId?: string;
401
379
  };
402
380
  type NcpRunMetadataPayload = {
403
- sessionKey?: string;
381
+ sessionId?: string;
404
382
  messageId?: string;
405
383
  runId?: string;
406
384
  metadata: Record<string, unknown>;
407
385
  };
408
386
  type NcpTextStartPayload = {
409
- sessionKey: string;
387
+ sessionId: string;
410
388
  messageId: string;
411
389
  };
412
390
  type NcpTextDeltaPayload = {
413
- sessionKey: string;
391
+ sessionId: string;
414
392
  messageId: string;
415
393
  delta: string;
416
394
  };
417
395
  type NcpTextEndPayload = {
418
- sessionKey: string;
396
+ sessionId: string;
419
397
  messageId: string;
420
398
  };
421
399
  type NcpReasoningStartPayload = {
422
- sessionKey: string;
400
+ sessionId: string;
423
401
  messageId: string;
424
402
  };
425
403
  type NcpReasoningDeltaPayload = {
426
- sessionKey: string;
404
+ sessionId: string;
427
405
  messageId: string;
428
406
  delta: string;
429
407
  };
430
408
  type NcpReasoningEndPayload = {
431
- sessionKey: string;
409
+ sessionId: string;
432
410
  messageId: string;
433
411
  };
434
412
  type NcpToolCallStartPayload = {
435
- sessionKey: string;
413
+ sessionId: string;
436
414
  messageId?: string;
437
415
  toolCallId: string;
438
416
  toolName: string;
439
417
  };
440
418
  type NcpToolCallArgsPayload = {
441
- sessionKey: string;
419
+ sessionId: string;
442
420
  toolCallId: string;
443
421
  args: string;
444
422
  };
445
423
  type NcpToolCallArgsDeltaPayload = {
446
- sessionKey: string;
424
+ sessionId: string;
447
425
  messageId?: string;
448
426
  toolCallId: string;
449
427
  delta: string;
450
428
  };
451
429
  type NcpToolCallEndPayload = {
452
- sessionKey: string;
430
+ sessionId: string;
453
431
  toolCallId: string;
454
432
  };
455
433
  type NcpToolCallResultPayload = {
456
- sessionKey: string;
434
+ sessionId: string;
457
435
  toolCallId: string;
458
436
  content: unknown;
459
437
  };
@@ -462,6 +440,9 @@ type NcpEndpointEvent = {
462
440
  } | {
463
441
  type: "message.request";
464
442
  payload: NcpRequestEnvelope;
443
+ } | {
444
+ type: "message.resume-request";
445
+ payload: NcpResumeRequestPayload;
465
446
  } | {
466
447
  type: "message.sent";
467
448
  payload: NcpMessageSentPayload;
@@ -552,43 +533,145 @@ type NcpEndpointEvent = {
552
533
  };
553
534
  type NcpEndpointSubscriber = (event: NcpEndpointEvent) => void;
554
535
 
536
+ /**
537
+ * Run-related types: snapshot state and run.metadata schema conventions.
538
+ * Not event payloads — event payloads live in events.ts.
539
+ */
540
+ /** Current run state for agent snapshot. Used by UI for run status and abort. */
541
+ type NcpRunContext = {
542
+ runId: string | null;
543
+ sessionId?: string;
544
+ abortDisabledReason?: string | null;
545
+ };
546
+ /** Schema for run.metadata.metadata when kind is "ready" (run started, backend ready). */
547
+ type NcpRunReadyMetadata = {
548
+ kind: "ready";
549
+ runId?: string;
550
+ sessionId?: string;
551
+ supportsAbort?: boolean;
552
+ abortDisabledReason?: string;
553
+ };
554
+ /** Schema for run.metadata.metadata when kind is "final" (run finished). */
555
+ type NcpRunFinalMetadata = {
556
+ kind: "final";
557
+ sessionId?: string;
558
+ };
559
+
555
560
  /**
556
561
  * Core interface every NCP endpoint adapter must implement.
557
562
  *
563
+ * An endpoint is a named, lifecycle-managed communication channel.
558
564
  * Single primitive: emit(event) to send, subscribe(listener) to receive.
559
565
  * Event types and payloads are defined in events.ts (aligned with agent-chat).
566
+ *
567
+ * @example
568
+ * const endpoint: NcpEndpoint = new MyAgentEndpoint(options);
569
+ * await endpoint.start();
570
+ * endpoint.subscribe((event) => { ... });
571
+ * await endpoint.emit({ type: "message.request", payload: envelope });
560
572
  */
561
573
  interface NcpEndpoint {
574
+ /** Static capability declaration — available before `start()` is called. */
562
575
  readonly manifest: NcpEndpointManifest;
576
+ /**
577
+ * Initializes the endpoint (opens connections, authenticates, etc.).
578
+ * Must be called before `emit`. Idempotent — safe to call more than once.
579
+ */
563
580
  start(): Promise<void>;
581
+ /**
582
+ * Gracefully shuts down the endpoint and releases resources.
583
+ * Idempotent — safe to call more than once.
584
+ */
564
585
  stop(): Promise<void>;
565
- emit(event: NcpEndpointEvent): void | Promise<void>;
566
- subscribe(listener: (event: NcpEndpointEvent) => void): () => void;
586
+ /**
587
+ * Sends an event to the remote participant (or broadcasts to local subscribers).
588
+ *
589
+ * For outbound events (e.g. message.request, message.abort), the implementation
590
+ * forwards to the wire. For symmetric in-process setups, it may broadcast locally.
591
+ */
592
+ emit(event: NcpEndpointEvent): Promise<void>;
593
+ /**
594
+ * Subscribes to endpoint events.
595
+ *
596
+ * @param listener - Called for every event emitted by this endpoint.
597
+ * @returns An unsubscribe function. Call it to stop receiving events.
598
+ *
599
+ * @example
600
+ * const unsubscribe = endpoint.subscribe((event) => {
601
+ * if (event.type === "message.completed") handleReply(event.payload);
602
+ * });
603
+ * unsubscribe();
604
+ */
605
+ subscribe(listener: NcpEndpointSubscriber): () => void;
567
606
  }
568
607
 
569
608
  /**
570
- * Base class for NCP endpoint adapters.
609
+ * Client-side endpoint for agent chat: initiates requests and can cancel in-flight runs.
571
610
  *
572
- * Lifecycle (start/stop) and subscribe/broadcast. Subclass must implement
573
- * onStart, onStop, emit(); call broadcast() when an event is received from
574
- * the transport. When the endpoint is ready to send/receive, call
575
- * broadcast({ type: "endpoint.ready" }) — base class does not emit it.
611
+ * Extends `NcpEndpoint` with role-specific methods. Use this on the caller side
612
+ * (e.g. frontend, CLI) that sends user messages and receives agent responses.
576
613
  */
577
- declare abstract class AbstractEndpoint implements NcpEndpoint {
578
- abstract readonly manifest: NcpEndpointManifest;
579
- private started;
580
- private readonly listeners;
581
- start(): Promise<void>;
582
- stop(): Promise<void>;
583
- /** Subclass must implement: send event to the other peer (wire, queue, or in-process broadcast). */
584
- abstract emit(event: NcpEndpointEvent): void | Promise<void>;
585
- subscribe(listener: NcpEndpointSubscriber): () => void;
586
- /** Call when an event is received from the transport; delivers to local subscribers. */
587
- protected broadcast(event: NcpEndpointEvent): void;
588
- protected abstract onStart(): Promise<void>;
589
- protected abstract onStop(): Promise<void>;
614
+ interface NcpAgentClientEndpoint extends NcpEndpoint {
615
+ /** Sends a new message request to the agent. Emits `message.request`. */
616
+ send(envelope: NcpRequestEnvelope): Promise<void>;
617
+ /** Resumes an existing run by remote run id. Emits `message.resume-request`. */
618
+ resume(payload: NcpResumeRequestPayload): Promise<void>;
619
+ /** Aborts the current or specified run. Emits `message.abort`. */
620
+ abort(payload?: NcpMessageAbortPayload): Promise<void>;
621
+ }
622
+
623
+ /**
624
+ * Agent server-side endpoint: receives requests and emits responses.
625
+ *
626
+ * Extends `NcpEndpoint` with a manifest constraint (`endpointKind: "agent"`).
627
+ * Use this on the server side that processes `message.request` / `message.resume-request`
628
+ * and emits `message.incoming`, streaming deltas, `message.completed`, etc.
629
+ */
630
+ interface NcpAgentServerEndpoint extends NcpEndpoint {
631
+ readonly manifest: NcpEndpointManifest & {
632
+ endpointKind: "agent";
633
+ };
634
+ }
635
+
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
+ type NcpAgentRunInput = {
643
+ kind: "request";
644
+ payload: NcpRequestEnvelope;
645
+ } | {
646
+ kind: "resume";
647
+ payload: NcpResumeRequestPayload;
648
+ };
649
+ type NcpAgentRunOptions = {
650
+ signal?: AbortSignal;
651
+ sessionMessages?: ReadonlyArray<NcpMessage>;
652
+ };
653
+ interface NcpAgentRuntime {
654
+ run(input: NcpAgentRunInput, options?: NcpAgentRunOptions): AsyncIterable<NcpEndpointEvent>;
590
655
  }
591
656
 
657
+ type NcpAgentBackendSendOptions = {
658
+ signal?: AbortSignal;
659
+ };
660
+ type NcpAgentBackendReconnectOptions = {
661
+ signal?: AbortSignal;
662
+ };
663
+ interface NcpAgentBackendController extends NcpSessionApi {
664
+ send(envelope: NcpRequestEnvelope, options?: NcpAgentBackendSendOptions): AsyncIterable<NcpEndpointEvent>;
665
+ reconnect(payload: NcpResumeRequestPayload, options?: NcpAgentBackendReconnectOptions): AsyncIterable<NcpEndpointEvent>;
666
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
667
+ }
668
+ type NcpAgentReplayProvider = {
669
+ stream(params: {
670
+ payload: NcpResumeRequestPayload;
671
+ signal: AbortSignal;
672
+ }): AsyncIterable<NcpEndpointEvent>;
673
+ };
674
+
592
675
  /**
593
676
  * Read-only snapshot of conversation state maintained by a state manager.
594
677
  *
@@ -605,6 +688,13 @@ interface NcpConversationSnapshot {
605
688
  /** Latest error, if any (e.g. from message.failed or endpoint.error). */
606
689
  readonly error: NcpError | null;
607
690
  }
691
+ /**
692
+ * Agent snapshot: extends base snapshot with active run state.
693
+ * Use for UI run status, abort button enable/disable, and abort payload.
694
+ */
695
+ interface NcpAgentConversationSnapshot extends NcpConversationSnapshot {
696
+ readonly activeRun: NcpRunContext | null;
697
+ }
608
698
  /**
609
699
  * State manager that holds conversation state and updates it from NCP events.
610
700
  *
@@ -618,7 +708,7 @@ interface NcpConversationStateManager {
618
708
  * Applies an NCP event to internal state (messages, streamingMessage, error).
619
709
  * Notifies subscribers after the update.
620
710
  */
621
- dispatch(event: NcpEndpointEvent): void;
711
+ dispatch(event: NcpEndpointEvent): Promise<void>;
622
712
  /**
623
713
  * Subscribes to state changes. Listener is called after each dispatch that mutates state.
624
714
  * Returns an unsubscribe function.
@@ -634,6 +724,7 @@ interface NcpConversationStateManager {
634
724
  * and use these handlers to update messages, streamingMessage, and error.
635
725
  */
636
726
  interface NcpAgentConversationStateManager extends NcpConversationStateManager {
727
+ getSnapshot(): NcpAgentConversationSnapshot;
637
728
  handleMessageRequest(payload: NcpRequestEnvelope): void;
638
729
  /** Local peer sent a message (outbound); typically non-streaming. Add to messages. */
639
730
  handleMessageSent(payload: NcpMessageSentPayload): void;
@@ -660,4 +751,4 @@ interface NcpAgentConversationStateManager extends NcpConversationStateManager {
660
751
  handleEndpointError(payload: NcpError): void;
661
752
  }
662
753
 
663
- export { AbstractEndpoint, type NcpActionPart, type NcpAgentConversationStateManager, type NcpCardPart, type NcpCompletedEnvelope, type NcpConversationSnapshot, type NcpConversationStateManager, type NcpEndpoint, type NcpEndpointEvent, type NcpEndpointKind, type NcpEndpointLatency, type NcpEndpointManifest, type NcpEndpointSubscriber, type NcpError, type NcpErrorCode, NcpErrorException, type NcpExtensionPart, type NcpFailedEnvelope, type NcpFilePart, type NcpMessage, type NcpMessageAbortPayload, type NcpMessageAcceptedPayload, type NcpMessageDeliveredPayload, type NcpMessagePart, type NcpMessageReactionPayload, type NcpMessageReadPayload, type NcpMessageRecalledPayload, type NcpMessageRole, type NcpMessageSentPayload, type NcpMessageStatus, type NcpPresenceUpdatedPayload, type NcpReasoningDeltaPayload, type NcpReasoningEndPayload, type NcpReasoningPart, type NcpReasoningStartPayload, type NcpRequestEnvelope, type NcpResponseEnvelope, type NcpRichTextPart, type NcpRunErrorPayload, type NcpRunFinishedPayload, type NcpRunMetadataPayload, type NcpRunStartedPayload, type NcpSessionBinding, type NcpSessionContract, type NcpSessionState, type NcpSourcePart, type NcpStepStartPart, type NcpTextDeltaPayload, type NcpTextEndPayload, type NcpTextPart, type NcpTextStartPayload, type NcpToolCallArgsDeltaPayload, type NcpToolCallArgsPayload, type NcpToolCallEndPayload, type NcpToolCallResultPayload, type NcpToolCallStartPayload, type NcpToolInvocationPart, type NcpTypingEndPayload, type NcpTypingStartPayload };
754
+ export { type ListMessagesOptions, type ListSessionsOptions, type NcpActionPart, type NcpAgentBackendController, type NcpAgentBackendReconnectOptions, type NcpAgentBackendSendOptions, type NcpAgentClientEndpoint, type NcpAgentConversationSnapshot, type NcpAgentConversationStateManager, type NcpAgentReplayProvider, type NcpAgentRunInput, type NcpAgentRunOptions, type NcpAgentRuntime, type NcpAgentServerEndpoint, type NcpCardPart, type NcpCompletedEnvelope, type NcpConversationSnapshot, type NcpConversationStateManager, type NcpEndpoint, type NcpEndpointEvent, type NcpEndpointKind, type NcpEndpointLatency, type NcpEndpointManifest, type NcpEndpointSubscriber, type NcpError, type NcpErrorCode, NcpErrorException, type NcpExtensionPart, type NcpFailedEnvelope, type NcpFilePart, type NcpMessage, type NcpMessageAbortPayload, type NcpMessageAcceptedPayload, type NcpMessageDeliveredPayload, type NcpMessagePart, type NcpMessageReactionPayload, type NcpMessageReadPayload, type NcpMessageRecalledPayload, type NcpMessageRole, type NcpMessageSentPayload, type NcpMessageStatus, type NcpPresenceUpdatedPayload, type NcpReasoningDeltaPayload, type NcpReasoningEndPayload, type NcpReasoningPart, type NcpReasoningStartPayload, type NcpRequestEnvelope, type NcpResponseEnvelope, type NcpResumeRequestPayload, type NcpRichTextPart, 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 NcpTextDeltaPayload, type NcpTextEndPayload, type NcpTextPart, type NcpTextStartPayload, type NcpToolCallArgsDeltaPayload, type NcpToolCallArgsPayload, type NcpToolCallEndPayload, type NcpToolCallResultPayload, type NcpToolCallStartPayload, type NcpToolInvocationPart, type NcpTypingEndPayload, type NcpTypingStartPayload, createAgentClientFromServer };
package/dist/index.js CHANGED
@@ -10,32 +10,22 @@ var NcpErrorException = class extends Error {
10
10
  }
11
11
  };
12
12
 
13
- // src/endpoint/abstract-endpoint.ts
14
- var AbstractEndpoint = class {
15
- started = false;
16
- listeners = /* @__PURE__ */ new Set();
17
- async start() {
18
- if (this.started) return;
19
- await this.onStart();
20
- this.started = true;
21
- }
22
- async stop() {
23
- if (!this.started) return;
24
- await this.onStop();
25
- this.started = false;
26
- }
27
- subscribe(listener) {
28
- this.listeners.add(listener);
29
- return () => this.listeners.delete(listener);
30
- }
31
- /** Call when an event is received from the transport; delivers to local subscribers. */
32
- broadcast(event) {
33
- for (const listener of this.listeners) {
34
- listener(event);
13
+ // src/endpoint/agent-client-from-server.ts
14
+ function createAgentClientFromServer(server) {
15
+ return {
16
+ ...server,
17
+ async send(envelope) {
18
+ await server.emit({ type: "message.request", payload: envelope });
19
+ },
20
+ async resume(payload) {
21
+ await server.emit({ type: "message.resume-request", payload });
22
+ },
23
+ async abort(payload) {
24
+ await server.emit({ type: "message.abort", payload: payload ?? {} });
35
25
  }
36
- }
37
- };
26
+ };
27
+ }
38
28
  export {
39
- AbstractEndpoint,
40
- NcpErrorException
29
+ NcpErrorException,
30
+ createAgentClientFromServer
41
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "NextClaw Communication Protocol core abstractions and types.",
6
6
  "type": "module",