@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.
- package/dist/index.d.ts +154 -144
- package/dist/index.js +1213 -1443
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,178 +1,188 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
sessionId: string;
|
|
84
|
+
agentId?: string;
|
|
85
|
+
messages: NcpMessage[];
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
82
88
|
};
|
|
83
89
|
type LiveSessionExecution = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
controller: AbortController;
|
|
91
|
+
requestEnvelope: NcpRequestEnvelope;
|
|
92
|
+
abortHandled: boolean;
|
|
93
|
+
closed: boolean;
|
|
88
94
|
};
|
|
89
95
|
type LiveSessionState = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
157
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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 };
|