@nextclaw/ncp-toolkit 0.5.0 → 0.5.2
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 -147
- package/dist/index.js +1206 -1486
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,181 +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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
sessionId: string;
|
|
84
|
+
agentId?: string;
|
|
85
|
+
messages: NcpMessage[];
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
84
88
|
};
|
|
85
89
|
type LiveSessionExecution = {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
controller: AbortController;
|
|
91
|
+
requestEnvelope: NcpRequestEnvelope;
|
|
92
|
+
abortHandled: boolean;
|
|
93
|
+
closed: boolean;
|
|
90
94
|
};
|
|
91
95
|
type LiveSessionState = {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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 };
|