@nextclaw/ncp-toolkit 0.4.17 → 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 -144
  2. package/dist/index.js +1213 -1443
  3. package/package.json +4 -5
package/dist/index.d.ts CHANGED
@@ -1,178 +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
- stateManager: NcpAgentConversationStateManager;
73
- sessionMetadata: Record<string, unknown>;
74
- 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;
75
80
  };
76
81
  type CreateRuntimeFn = (params: RuntimeFactoryParams) => NcpAgentRuntime;
77
82
  type AgentSessionRecord = {
78
- sessionId: string;
79
- messages: NcpMessage[];
80
- updatedAt: string;
81
- metadata?: Record<string, unknown>;
83
+ sessionId: string;
84
+ agentId?: string;
85
+ messages: NcpMessage[];
86
+ updatedAt: string;
87
+ metadata?: Record<string, unknown>;
82
88
  };
83
89
  type LiveSessionExecution = {
84
- controller: AbortController;
85
- requestEnvelope: NcpRequestEnvelope;
86
- abortHandled: boolean;
87
- closed: boolean;
90
+ controller: AbortController;
91
+ requestEnvelope: NcpRequestEnvelope;
92
+ abortHandled: boolean;
93
+ closed: boolean;
88
94
  };
89
95
  type LiveSessionState = {
90
- sessionId: string;
91
- runtime: NcpAgentRuntime;
92
- stateManager: NcpAgentConversationStateManager;
93
- metadata: Record<string, unknown>;
94
- publisher: EventPublisher;
95
- 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;
96
103
  };
97
104
  interface AgentSessionStore {
98
- getSession(sessionId: string): Promise<AgentSessionRecord | null>;
99
- listSessions(): Promise<AgentSessionRecord[]>;
100
- saveSession(session: AgentSessionRecord): Promise<void>;
101
- replaceSession(session: AgentSessionRecord): Promise<void>;
102
- 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>;
103
110
  }
104
-
111
+ //#endregion
112
+ //#region src/agent/agent-backend/agent-backend.d.ts
105
113
  type DefaultNcpAgentBackendConfig = {
106
- createRuntime: CreateRuntimeFn;
107
- sessionStore: AgentSessionStore;
108
- onSessionRunStatusChanged?: (payload: {
109
- sessionKey: string;
110
- status: "running" | "idle";
111
- }) => void;
112
- endpointId?: string;
113
- version?: string;
114
- metadata?: Record<string, unknown>;
115
- supportedPartTypes?: NcpEndpointManifest["supportedPartTypes"];
116
- 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"];
117
125
  };
118
126
  declare class DefaultNcpAgentBackend implements NcpAgentServerEndpoint, NcpSessionApi, NcpAgentStreamProvider, NcpAgentRunApi {
119
- readonly manifest: NcpEndpointManifest & {
120
- endpointKind: "agent";
121
- };
122
- private readonly sessionStore;
123
- private readonly onSessionRunStatusChanged;
124
- private readonly sessionRegistry;
125
- private readonly executor;
126
- private readonly publisher;
127
- private readonly sessionRealtime;
128
- private started;
129
- constructor(config: DefaultNcpAgentBackendConfig);
130
- start: () => Promise<void>;
131
- stop: () => Promise<void>;
132
- emit: (event: NcpEndpointEvent) => Promise<void>;
133
- subscribe: (listener: (event: NcpEndpointEvent) => void) => (() => void);
134
- send: (envelope: NcpRequestEnvelope, options?: NcpAgentRunSendOptions) => AsyncIterable<NcpEndpointEvent>;
135
- abort: (payload: NcpMessageAbortPayload) => Promise<void>;
136
- stream: (payloadOrParams: NcpStreamRequestPayload | {
137
- payload: NcpStreamRequestPayload;
138
- signal: AbortSignal;
139
- }, opts?: NcpAgentRunStreamOptions) => AsyncIterable<NcpEndpointEvent>;
140
- listSessions: () => Promise<NcpSessionSummary[]>;
141
- listSessionMessages: (sessionId: string) => Promise<NcpMessage[]>;
142
- getSession: (sessionId: string) => Promise<NcpSessionSummary | null>;
143
- appendMessage: (sessionId: string, message: NcpMessage) => Promise<NcpSessionSummary | null>;
144
- updateToolCallResult: (sessionId: string, toolCallId: string, content: unknown) => Promise<NcpSessionSummary | null>;
145
- updateSession: (sessionId: string, patch: NcpSessionPatch) => Promise<NcpSessionSummary | null>;
146
- deleteSession: (sessionId: string) => Promise<void>;
147
- private ensureStarted;
148
- private startSessionExecution;
149
- private finishSessionExecution;
150
- private publishEndpointEvent;
151
- private handleAbort;
152
- 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;
153
160
  }
154
-
161
+ //#endregion
162
+ //#region src/agent/agent-backend/agent-run-executor.d.ts
155
163
  declare class AgentRunExecutor {
156
- executeRun(session: LiveSessionState, envelope: NcpRequestEnvelope, controller: AbortController): AsyncGenerator<NcpEndpointEvent>;
157
- private publishFailure;
164
+ executeRun(session: LiveSessionState, envelope: NcpRequestEnvelope, controller: AbortController): AsyncGenerator<NcpEndpointEvent>;
165
+ private publishFailure;
158
166
  }
159
-
167
+ //#endregion
168
+ //#region src/agent/agent-backend/in-memory-agent-session-store.d.ts
160
169
  declare class InMemoryAgentSessionStore implements AgentSessionStore {
161
- private readonly sessions;
162
- getSession: (sessionId: string) => Promise<AgentSessionRecord | null>;
163
- listSessions: () => Promise<AgentSessionRecord[]>;
164
- saveSession: (session: AgentSessionRecord) => Promise<void>;
165
- replaceSession: (session: AgentSessionRecord) => Promise<void>;
166
- 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>;
167
176
  }
168
-
177
+ //#endregion
178
+ //#region src/errors/ncp-error-exception.d.ts
169
179
  /**
170
180
  * Throwable form of protocol error for exception-based control flows.
171
181
  */
172
182
  declare class NcpErrorException extends Error {
173
- readonly code: NcpErrorCode;
174
- readonly details?: Record<string, unknown>;
175
- 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>);
176
186
  }
177
-
178
- 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 };