@nextclaw/ncp-toolkit 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.
Files changed (3) hide show
  1. package/dist/index.d.ts +154 -147
  2. package/dist/index.js +1206 -1486
  3. package/package.json +2 -3
package/dist/index.d.ts CHANGED
@@ -1,181 +1,188 @@
1
- import { NcpAgentConversationStateManager, NcpAgentConversationSnapshot, NcpAgentConversationHydrationParams, NcpEndpointEvent, NcpMessageSentPayload, NcpMessageAbortPayload, NcpTextStartPayload, NcpTextDeltaPayload, NcpTextEndPayload, NcpReasoningStartPayload, NcpReasoningDeltaPayload, NcpReasoningEndPayload, NcpToolCallStartPayload, NcpToolCallArgsPayload, NcpToolCallArgsDeltaPayload, NcpToolCallEndPayload, NcpToolCallResultPayload, NcpRunStartedPayload, NcpRunFinishedPayload, NcpRunErrorPayload, NcpRunMetadataPayload, NcpError, NcpAgentServerEndpoint, NcpAgentClientEndpoint, NcpEndpointSubscriber, NcpAgentRuntime, NcpRequestEnvelope, NcpMessage, NcpSessionApi, NcpAgentStreamProvider, NcpAgentRunApi, NcpEndpointManifest, NcpAgentRunSendOptions, NcpStreamRequestPayload, NcpAgentRunStreamOptions, NcpSessionSummary, NcpSessionPatch, NcpErrorCode } from '@nextclaw/ncp';
1
+ import { NcpAgentClientEndpoint, NcpAgentConversationHydrationParams, NcpAgentConversationSnapshot, NcpAgentConversationStateManager, NcpAgentRunApi, NcpAgentRunSendOptions, NcpAgentRunStreamOptions, NcpAgentRuntime, NcpAgentServerEndpoint, NcpAgentStreamProvider, NcpEndpointEvent, NcpEndpointManifest, NcpEndpointSubscriber, NcpError, NcpErrorCode, NcpMessage, NcpMessageAbortPayload, NcpMessageSentPayload, NcpReasoningDeltaPayload, NcpReasoningEndPayload, NcpReasoningStartPayload, NcpRequestEnvelope, NcpRunErrorPayload, NcpRunFinishedPayload, NcpRunMetadataPayload, NcpRunStartedPayload, NcpSessionApi, NcpSessionPatch, NcpSessionSummary, NcpStreamRequestPayload, NcpTextDeltaPayload, NcpTextEndPayload, NcpTextStartPayload, NcpToolCallArgsDeltaPayload, NcpToolCallArgsPayload, NcpToolCallEndPayload, NcpToolCallResultPayload, NcpToolCallStartPayload } from "@nextclaw/ncp";
2
2
 
3
+ //#region src/agent/agent-conversation-state-manager.d.ts
3
4
  declare class DefaultNcpAgentConversationStateManager implements NcpAgentConversationStateManager {
4
- private messages;
5
- private streamingMessage;
6
- private error;
7
- private activeRun;
8
- private readonly listeners;
9
- private readonly toolCallMessageIdByCallId;
10
- private readonly toolCallArgsRawByCallId;
11
- private lastSettledRunId;
12
- private snapshotCache;
13
- private snapshotVersion;
14
- private stateVersion;
15
- getSnapshot: () => NcpAgentConversationSnapshot;
16
- subscribe: (listener: (snapshot: NcpAgentConversationSnapshot) => void) => () => boolean;
17
- reset: () => void;
18
- hydrate: (payload: NcpAgentConversationHydrationParams) => void;
19
- dispatch: (event: NcpEndpointEvent) => Promise<void>;
20
- dispatchBatch: (events: readonly NcpEndpointEvent[]) => Promise<void>;
21
- private applyEvent;
22
- handleMessageSent: (payload: NcpMessageSentPayload) => void;
23
- handleMessageAbort: (payload: NcpMessageAbortPayload) => void;
24
- handleMessageTextStart: (payload: NcpTextStartPayload) => void;
25
- handleMessageTextDelta: (payload: NcpTextDeltaPayload) => void;
26
- handleMessageTextEnd: (payload: NcpTextEndPayload) => void;
27
- handleMessageReasoningStart: (payload: NcpReasoningStartPayload) => void;
28
- handleMessageReasoningDelta: (payload: NcpReasoningDeltaPayload) => void;
29
- handleMessageReasoningEnd: (payload: NcpReasoningEndPayload) => void;
30
- handleMessageToolCallStart: (payload: NcpToolCallStartPayload) => void;
31
- handleMessageToolCallArgs: (payload: NcpToolCallArgsPayload) => void;
32
- handleMessageToolCallArgsDelta: (payload: NcpToolCallArgsDeltaPayload) => void;
33
- handleMessageToolCallEnd: (payload: NcpToolCallEndPayload) => void;
34
- handleMessageToolCallResult: (payload: NcpToolCallResultPayload) => void;
35
- handleRunStarted: (payload: NcpRunStartedPayload) => void;
36
- handleRunFinished: (payload: NcpRunFinishedPayload) => void;
37
- handleRunError: (payload: NcpRunErrorPayload) => void;
38
- handleRunMetadata: (payload: NcpRunMetadataPayload) => void;
39
- handleEndpointError: (payload: NcpError) => void;
40
- private applyToolCallArgs;
41
- private ensureStreamingMessage;
42
- private resolveToolCallTargetMessage;
43
- private updateMessageContainingToolCall;
44
- private upsertMessage;
45
- private replaceStreamingMessage;
46
- private setError;
47
- private clearActiveRun;
48
- private isSettledRunId;
49
- private markRunAsSettled;
50
- private settleStreamingMessage;
51
- private notifyListeners;
5
+ private messages;
6
+ private streamingMessage;
7
+ private error;
8
+ private activeRun;
9
+ private readonly listeners;
10
+ private readonly toolCallMessageIdByCallId;
11
+ private readonly toolCallArgsRawByCallId;
12
+ private lastSettledRunId;
13
+ private snapshotCache;
14
+ private snapshotVersion;
15
+ private stateVersion;
16
+ getSnapshot: () => NcpAgentConversationSnapshot;
17
+ subscribe: (listener: (snapshot: NcpAgentConversationSnapshot) => void) => () => boolean;
18
+ reset: () => void;
19
+ hydrate: (payload: NcpAgentConversationHydrationParams) => void;
20
+ dispatch: (event: NcpEndpointEvent) => Promise<void>;
21
+ dispatchBatch: (events: readonly NcpEndpointEvent[]) => Promise<void>;
22
+ private applyEvent;
23
+ handleMessageSent: (payload: NcpMessageSentPayload) => void;
24
+ handleMessageAbort: (payload: NcpMessageAbortPayload) => void;
25
+ handleMessageTextStart: (payload: NcpTextStartPayload) => void;
26
+ handleMessageTextDelta: (payload: NcpTextDeltaPayload) => void;
27
+ handleMessageTextEnd: (payload: NcpTextEndPayload) => void;
28
+ handleMessageReasoningStart: (payload: NcpReasoningStartPayload) => void;
29
+ handleMessageReasoningDelta: (payload: NcpReasoningDeltaPayload) => void;
30
+ handleMessageReasoningEnd: (payload: NcpReasoningEndPayload) => void;
31
+ handleMessageToolCallStart: (payload: NcpToolCallStartPayload) => void;
32
+ handleMessageToolCallArgs: (payload: NcpToolCallArgsPayload) => void;
33
+ handleMessageToolCallArgsDelta: (payload: NcpToolCallArgsDeltaPayload) => void;
34
+ handleMessageToolCallEnd: (payload: NcpToolCallEndPayload) => void;
35
+ handleMessageToolCallResult: (payload: NcpToolCallResultPayload) => void;
36
+ handleRunStarted: (payload: NcpRunStartedPayload) => void;
37
+ handleRunFinished: (payload: NcpRunFinishedPayload) => void;
38
+ handleRunError: (payload: NcpRunErrorPayload) => void;
39
+ handleRunMetadata: (payload: NcpRunMetadataPayload) => void;
40
+ handleEndpointError: (payload: NcpError) => void;
41
+ private applyToolCallArgs;
42
+ private ensureStreamingMessage;
43
+ private resolveToolCallTargetMessage;
44
+ private updateMessageContainingToolCall;
45
+ private upsertMessage;
46
+ private replaceStreamingMessage;
47
+ private setError;
48
+ private clearActiveRun;
49
+ private isSettledRunId;
50
+ private markRunAsSettled;
51
+ private settleStreamingMessage;
52
+ private notifyListeners;
52
53
  }
53
-
54
+ //#endregion
55
+ //#region src/agent/agent-client-from-server.d.ts
54
56
  /**
55
57
  * Creates an NcpAgentClientEndpoint that forwards to an in-process NcpAgentServerEndpoint.
56
58
  * Use when the agent runs in-process and you need to pass a client endpoint to the HTTP server.
57
59
  */
58
60
  declare function createAgentClientFromServer(server: NcpAgentServerEndpoint): NcpAgentClientEndpoint;
59
-
61
+ //#endregion
62
+ //#region src/agent/agent-backend/event-publisher.d.ts
60
63
  declare class EventPublisher {
61
- private readonly listeners;
62
- private readonly closeListeners;
63
- private closed;
64
- subscribe(listener: NcpEndpointSubscriber): () => void;
65
- onClose(listener: () => void): () => void;
66
- publish(event: NcpEndpointEvent): void;
67
- close(): void;
64
+ private readonly listeners;
65
+ private readonly closeListeners;
66
+ private closed;
67
+ subscribe(listener: NcpEndpointSubscriber): () => void;
68
+ onClose(listener: () => void): () => void;
69
+ publish(event: NcpEndpointEvent): void;
70
+ close(): void;
68
71
  }
69
-
72
+ //#endregion
73
+ //#region src/agent/agent-backend/agent-backend-types.d.ts
70
74
  type RuntimeFactoryParams = {
71
- sessionId: string;
72
- agentId?: string;
73
- stateManager: NcpAgentConversationStateManager;
74
- sessionMetadata: Record<string, unknown>;
75
- setSessionMetadata: (nextMetadata: Record<string, unknown>) => void;
75
+ sessionId: string;
76
+ agentId?: string;
77
+ stateManager: NcpAgentConversationStateManager;
78
+ sessionMetadata: Record<string, unknown>;
79
+ setSessionMetadata: (nextMetadata: Record<string, unknown>) => void;
76
80
  };
77
81
  type CreateRuntimeFn = (params: RuntimeFactoryParams) => NcpAgentRuntime;
78
82
  type AgentSessionRecord = {
79
- sessionId: string;
80
- agentId?: string;
81
- messages: NcpMessage[];
82
- updatedAt: string;
83
- metadata?: Record<string, unknown>;
83
+ sessionId: string;
84
+ agentId?: string;
85
+ messages: NcpMessage[];
86
+ updatedAt: string;
87
+ metadata?: Record<string, unknown>;
84
88
  };
85
89
  type LiveSessionExecution = {
86
- controller: AbortController;
87
- requestEnvelope: NcpRequestEnvelope;
88
- abortHandled: boolean;
89
- closed: boolean;
90
+ controller: AbortController;
91
+ requestEnvelope: NcpRequestEnvelope;
92
+ abortHandled: boolean;
93
+ closed: boolean;
90
94
  };
91
95
  type LiveSessionState = {
92
- sessionId: string;
93
- agentId?: string;
94
- runtime: NcpAgentRuntime;
95
- stateManager: NcpAgentConversationStateManager;
96
- metadata: Record<string, unknown>;
97
- publisher: EventPublisher;
98
- activeExecution: LiveSessionExecution | null;
96
+ sessionId: string;
97
+ agentId?: string;
98
+ runtime: NcpAgentRuntime;
99
+ stateManager: NcpAgentConversationStateManager;
100
+ metadata: Record<string, unknown>;
101
+ publisher: EventPublisher;
102
+ activeExecution: LiveSessionExecution | null;
99
103
  };
100
104
  interface AgentSessionStore {
101
- getSession(sessionId: string): Promise<AgentSessionRecord | null>;
102
- listSessions(): Promise<AgentSessionRecord[]>;
103
- saveSession(session: AgentSessionRecord): Promise<void>;
104
- replaceSession(session: AgentSessionRecord): Promise<void>;
105
- deleteSession(sessionId: string): Promise<AgentSessionRecord | null>;
105
+ getSession(sessionId: string): Promise<AgentSessionRecord | null>;
106
+ listSessions(): Promise<AgentSessionRecord[]>;
107
+ saveSession(session: AgentSessionRecord): Promise<void>;
108
+ replaceSession(session: AgentSessionRecord): Promise<void>;
109
+ deleteSession(sessionId: string): Promise<AgentSessionRecord | null>;
106
110
  }
107
-
111
+ //#endregion
112
+ //#region src/agent/agent-backend/agent-backend.d.ts
108
113
  type DefaultNcpAgentBackendConfig = {
109
- createRuntime: CreateRuntimeFn;
110
- sessionStore: AgentSessionStore;
111
- onSessionRunStatusChanged?: (payload: {
112
- sessionKey: string;
113
- status: "running" | "idle";
114
- }) => void;
115
- endpointId?: string;
116
- version?: string;
117
- metadata?: Record<string, unknown>;
118
- supportedPartTypes?: NcpEndpointManifest["supportedPartTypes"];
119
- expectedLatency?: NcpEndpointManifest["expectedLatency"];
114
+ createRuntime: CreateRuntimeFn;
115
+ sessionStore: AgentSessionStore;
116
+ onSessionRunStatusChanged?: (payload: {
117
+ sessionKey: string;
118
+ status: "running" | "idle";
119
+ }) => void;
120
+ endpointId?: string;
121
+ version?: string;
122
+ metadata?: Record<string, unknown>;
123
+ supportedPartTypes?: NcpEndpointManifest["supportedPartTypes"];
124
+ expectedLatency?: NcpEndpointManifest["expectedLatency"];
120
125
  };
121
126
  declare class DefaultNcpAgentBackend implements NcpAgentServerEndpoint, NcpSessionApi, NcpAgentStreamProvider, NcpAgentRunApi {
122
- readonly manifest: NcpEndpointManifest & {
123
- endpointKind: "agent";
124
- };
125
- private readonly sessionStore;
126
- private readonly onSessionRunStatusChanged;
127
- private readonly sessionRegistry;
128
- private readonly executor;
129
- private readonly publisher;
130
- private readonly sessionRealtime;
131
- private started;
132
- constructor(config: DefaultNcpAgentBackendConfig);
133
- start: () => Promise<void>;
134
- stop: () => Promise<void>;
135
- emit: (event: NcpEndpointEvent) => Promise<void>;
136
- subscribe: (listener: (event: NcpEndpointEvent) => void) => (() => void);
137
- send: (envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions) => AsyncIterable<NcpEndpointEvent>;
138
- abort: (payload: NcpMessageAbortPayload) => Promise<void>;
139
- stream: (payloadOrParams: NcpStreamRequestPayload | {
140
- payload: NcpStreamRequestPayload;
141
- signal: AbortSignal;
142
- }, opts?: NcpAgentRunStreamOptions) => AsyncIterable<NcpEndpointEvent>;
143
- listSessions: () => Promise<NcpSessionSummary[]>;
144
- listSessionMessages: (sessionId: string) => Promise<NcpMessage[]>;
145
- getSession: (sessionId: string) => Promise<NcpSessionSummary | null>;
146
- appendMessage: (sessionId: string, message: NcpMessage) => Promise<NcpSessionSummary | null>;
147
- updateToolCallResult: (sessionId: string, toolCallId: string, content: unknown) => Promise<NcpSessionSummary | null>;
148
- updateSession: (sessionId: string, patch: NcpSessionPatch) => Promise<NcpSessionSummary | null>;
149
- deleteSession: (sessionId: string) => Promise<void>;
150
- private ensureStarted;
151
- private startSessionExecution;
152
- private finishSessionExecution;
153
- private publishEndpointEvent;
154
- private handleAbort;
155
- private persistSession;
127
+ readonly manifest: NcpEndpointManifest & {
128
+ endpointKind: "agent";
129
+ };
130
+ private readonly sessionStore;
131
+ private readonly onSessionRunStatusChanged;
132
+ private readonly sessionRegistry;
133
+ private readonly executor;
134
+ private readonly publisher;
135
+ private readonly sessionRealtime;
136
+ private started;
137
+ constructor(config: DefaultNcpAgentBackendConfig);
138
+ start: () => Promise<void>;
139
+ stop: () => Promise<void>;
140
+ emit: (event: NcpEndpointEvent) => Promise<void>;
141
+ subscribe: (listener: (event: NcpEndpointEvent) => void) => (() => void);
142
+ send: (envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions) => AsyncIterable<NcpEndpointEvent>;
143
+ abort: (payload: NcpMessageAbortPayload) => Promise<void>;
144
+ stream: (payloadOrParams: NcpStreamRequestPayload | {
145
+ payload: NcpStreamRequestPayload;
146
+ signal: AbortSignal;
147
+ }, opts?: NcpAgentRunStreamOptions) => AsyncIterable<NcpEndpointEvent>;
148
+ listSessions: () => Promise<NcpSessionSummary[]>;
149
+ listSessionMessages: (sessionId: string) => Promise<NcpMessage[]>;
150
+ getSession: (sessionId: string) => Promise<NcpSessionSummary | null>;
151
+ appendMessage: (sessionId: string, message: NcpMessage) => Promise<NcpSessionSummary | null>;
152
+ updateToolCallResult: (sessionId: string, toolCallId: string, content: unknown) => Promise<NcpSessionSummary | null>;
153
+ updateSession: (sessionId: string, patch: NcpSessionPatch) => Promise<NcpSessionSummary | null>;
154
+ deleteSession: (sessionId: string) => Promise<void>;
155
+ private ensureStarted;
156
+ private startSessionExecution;
157
+ private finishSessionExecution;
158
+ private handleAbort;
159
+ private persistSession;
156
160
  }
157
-
161
+ //#endregion
162
+ //#region src/agent/agent-backend/agent-run-executor.d.ts
158
163
  declare class AgentRunExecutor {
159
- executeRun(session: LiveSessionState, envelope: NcpRequestEnvelope, controller: AbortController): AsyncGenerator<NcpEndpointEvent>;
160
- private publishFailure;
164
+ executeRun(session: LiveSessionState, envelope: NcpRequestEnvelope, controller: AbortController): AsyncGenerator<NcpEndpointEvent>;
165
+ private publishFailure;
161
166
  }
162
-
167
+ //#endregion
168
+ //#region src/agent/agent-backend/in-memory-agent-session-store.d.ts
163
169
  declare class InMemoryAgentSessionStore implements AgentSessionStore {
164
- private readonly sessions;
165
- getSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
166
- listSessions: () => Promise<AgentSessionRecord[]>;
167
- saveSession: (session: AgentSessionRecord) => Promise<void>;
168
- replaceSession: (session: AgentSessionRecord) => Promise<void>;
169
- deleteSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
170
+ private readonly sessions;
171
+ getSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
172
+ listSessions: () => Promise<AgentSessionRecord[]>;
173
+ saveSession: (session: AgentSessionRecord) => Promise<void>;
174
+ replaceSession: (session: AgentSessionRecord) => Promise<void>;
175
+ deleteSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
170
176
  }
171
-
177
+ //#endregion
178
+ //#region src/errors/ncp-error-exception.d.ts
172
179
  /**
173
180
  * Throwable form of protocol error for exception-based control flows.
174
181
  */
175
182
  declare class NcpErrorException extends Error {
176
- readonly code: NcpErrorCode;
177
- readonly details?: Record<string, unknown>;
178
- constructor(code: NcpErrorCode, message: string, details?: Record<string, unknown>);
183
+ readonly code: NcpErrorCode;
184
+ readonly details?: Record<string, unknown>;
185
+ constructor(code: NcpErrorCode, message: string, details?: Record<string, unknown>);
179
186
  }
180
-
181
- export { AgentRunExecutor, type AgentSessionRecord, type AgentSessionStore, type CreateRuntimeFn, DefaultNcpAgentBackend, type DefaultNcpAgentBackendConfig, DefaultNcpAgentConversationStateManager, EventPublisher, InMemoryAgentSessionStore, type LiveSessionExecution, type LiveSessionState, NcpErrorException, type RuntimeFactoryParams, createAgentClientFromServer };
187
+ //#endregion
188
+ export { AgentRunExecutor, type AgentSessionRecord, type AgentSessionStore, type CreateRuntimeFn, DefaultNcpAgentBackend, type DefaultNcpAgentBackendConfig, DefaultNcpAgentConversationStateManager, EventPublisher, InMemoryAgentSessionStore, type LiveSessionExecution, type LiveSessionState, NcpErrorException, type RuntimeFactoryParams, createAgentClientFromServer };