@nextclaw/ncp-agent-runtime 0.3.7 → 0.3.9
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 +135 -124
- package/dist/index.js +1105 -1109
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,164 +1,175 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NcpAgentConversationStateManager, NcpAgentRunInput, NcpAgentRunOptions, NcpAgentRuntime, NcpAssistantReasoningNormalizationMode, NcpContextBuilder, NcpContextPrepareOptions, NcpEncodeContext, NcpEndpointEvent, NcpLLMApi, NcpLLMApiInput, NcpLLMApiOptions, NcpMessagePart, NcpRoundBuffer, NcpStreamEncoder, NcpTool, NcpToolCallResult, NcpToolDefinition, NcpToolRegistry, OpenAIChatChunk, OpenAIContentPart } from "@nextclaw/ncp";
|
|
2
2
|
|
|
3
|
+
//#region src/asset-store.d.ts
|
|
3
4
|
type StoredAssetRecord = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
id: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
storageKey: string;
|
|
8
|
+
fileName: string;
|
|
9
|
+
storedName: string;
|
|
10
|
+
mimeType: string;
|
|
11
|
+
sizeBytes: number;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
sha256: string;
|
|
13
14
|
};
|
|
14
15
|
type AssetRef = {
|
|
15
|
-
|
|
16
|
+
uri: string;
|
|
16
17
|
};
|
|
17
18
|
type AssetMeta = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
uri: string;
|
|
20
|
+
fileName: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
sizeBytes: number;
|
|
23
|
+
createdAt: string;
|
|
23
24
|
};
|
|
24
25
|
type AssetPutInput = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
kind: "path";
|
|
27
|
+
path: string;
|
|
28
|
+
fileName?: string;
|
|
29
|
+
mimeType?: string | null;
|
|
30
|
+
createdAt?: Date;
|
|
30
31
|
} | {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
kind: "bytes";
|
|
33
|
+
bytes: Uint8Array;
|
|
34
|
+
fileName: string;
|
|
35
|
+
mimeType?: string | null;
|
|
36
|
+
createdAt?: Date;
|
|
36
37
|
};
|
|
37
38
|
declare function isTextLikeAsset(params: {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
mimeType?: string | null;
|
|
40
|
+
fileName?: string | null;
|
|
40
41
|
}): boolean;
|
|
41
42
|
declare class LocalAssetStore {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
43
|
+
readonly rootDir: string;
|
|
44
|
+
constructor(options: {
|
|
45
|
+
rootDir: string;
|
|
46
|
+
});
|
|
47
|
+
put(input: AssetPutInput): Promise<AssetRef>;
|
|
48
|
+
putBytes(params: {
|
|
49
|
+
fileName: string;
|
|
50
|
+
mimeType?: string | null;
|
|
51
|
+
bytes: Uint8Array;
|
|
52
|
+
createdAt?: Date;
|
|
53
|
+
}): Promise<StoredAssetRecord>;
|
|
54
|
+
putPath(params: {
|
|
55
|
+
path: string;
|
|
56
|
+
fileName?: string;
|
|
57
|
+
mimeType?: string | null;
|
|
58
|
+
createdAt?: Date;
|
|
59
|
+
}): Promise<StoredAssetRecord>;
|
|
60
|
+
export(ref: AssetRef, targetPath: string): Promise<string>;
|
|
61
|
+
stat(ref: AssetRef): Promise<AssetMeta | null>;
|
|
62
|
+
getByUri(uri: string): StoredAssetRecord | null;
|
|
63
|
+
statRecord(uri: string): Promise<StoredAssetRecord | null>;
|
|
64
|
+
readAssetBytes(uri: string): Promise<Buffer | null>;
|
|
65
|
+
resolveContentPath(uri: string): string | null;
|
|
66
|
+
private putFromPath;
|
|
67
|
+
private putFromBytes;
|
|
68
|
+
private buildRecord;
|
|
69
|
+
private writeMeta;
|
|
70
|
+
private resolveContentPathOrThrow;
|
|
71
|
+
private resolveStorageKeyDirectory;
|
|
71
72
|
}
|
|
72
73
|
declare function buildAssetContentPath(params: {
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
basePath: string;
|
|
75
|
+
assetUri: string;
|
|
75
76
|
}): string;
|
|
76
|
-
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/context-builder.d.ts
|
|
77
79
|
type DefaultNcpContextBuilderOptions = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
toolRegistry?: NcpToolRegistry;
|
|
81
|
+
assetStore?: LocalAssetStore | null;
|
|
80
82
|
};
|
|
81
83
|
declare class DefaultNcpContextBuilder implements NcpContextBuilder {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
private readonly toolRegistry?;
|
|
85
|
+
private readonly assetStore?;
|
|
86
|
+
constructor(toolRegistry?: NcpToolRegistry);
|
|
87
|
+
constructor(options?: DefaultNcpContextBuilderOptions);
|
|
88
|
+
prepare: (input: NcpAgentRunInput, options?: NcpContextPrepareOptions) => NcpLLMApiInput;
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/user-content.d.ts
|
|
89
92
|
declare function buildNcpUserContent(parts: NcpMessagePart[], options?: {
|
|
90
|
-
|
|
93
|
+
assetStore?: LocalAssetStore | null;
|
|
91
94
|
}): string | OpenAIContentPart[];
|
|
92
|
-
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/round-buffer.d.ts
|
|
93
97
|
declare class DefaultNcpRoundBuffer implements NcpRoundBuffer {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
private text;
|
|
99
|
+
private readonly toolCalls;
|
|
100
|
+
private pending;
|
|
101
|
+
appendText: (delta: string) => void;
|
|
102
|
+
getText: () => string;
|
|
103
|
+
appendToolCall: (result: NcpToolCallResult) => void;
|
|
104
|
+
getToolCalls: () => ReadonlyArray<NcpToolCallResult>;
|
|
105
|
+
startToolCall: (toolCallId: string, toolName: string) => void;
|
|
106
|
+
appendToolCallArgs: (args: unknown) => void;
|
|
107
|
+
consumePendingToolCall: () => {
|
|
108
|
+
toolCallId: string;
|
|
109
|
+
toolName: string;
|
|
110
|
+
args: unknown;
|
|
111
|
+
} | null;
|
|
112
|
+
clear: () => void;
|
|
109
113
|
}
|
|
110
|
-
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/stream-encoder.d.ts
|
|
111
116
|
type DefaultNcpStreamEncoderConfig = {
|
|
112
|
-
|
|
117
|
+
reasoningNormalizationMode?: NcpAssistantReasoningNormalizationMode;
|
|
113
118
|
};
|
|
114
119
|
/**
|
|
115
120
|
* Converts LLM stream chunks to NCP events (text, reasoning, tool calls).
|
|
116
121
|
* Does not emit RunFinished; that is the runtime's responsibility after the loop completes.
|
|
117
122
|
*/
|
|
118
123
|
declare class DefaultNcpStreamEncoder implements NcpStreamEncoder {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
private readonly reasoningNormalizationMode;
|
|
125
|
+
constructor(config?: DefaultNcpStreamEncoderConfig);
|
|
126
|
+
encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncGenerator<NcpEndpointEvent>;
|
|
122
127
|
}
|
|
123
|
-
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/tool-registry.d.ts
|
|
124
130
|
declare class DefaultNcpToolRegistry implements NcpToolRegistry {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
private readonly tools;
|
|
132
|
+
constructor(tools?: ReadonlyArray<NcpTool>);
|
|
133
|
+
register: (tool: NcpTool) => void;
|
|
134
|
+
listTools: () => ReadonlyArray<NcpTool>;
|
|
135
|
+
getTool: (name: string) => NcpTool | undefined;
|
|
136
|
+
getToolDefinitions: () => ReadonlyArray<NcpToolDefinition>;
|
|
137
|
+
execute: (_toolCallId: string, toolName: string, args: unknown) => Promise<unknown>;
|
|
132
138
|
}
|
|
133
|
-
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/llm-api-echo.d.ts
|
|
134
141
|
declare class EchoNcpLLMApi implements NcpLLMApi {
|
|
135
|
-
|
|
142
|
+
generate: (input: NcpLLMApiInput, options?: NcpLLMApiOptions) => AsyncGenerator<OpenAIChatChunk>;
|
|
136
143
|
}
|
|
137
|
-
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/runtime.d.ts
|
|
138
146
|
type DefaultNcpAgentRuntimeConfig = {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
contextBuilder: NcpContextBuilder;
|
|
148
|
+
llmApi: NcpLLMApi;
|
|
149
|
+
toolRegistry: NcpToolRegistry;
|
|
150
|
+
stateManager: NcpAgentConversationStateManager;
|
|
151
|
+
streamEncoder?: NcpStreamEncoder;
|
|
152
|
+
reasoningNormalizationMode?: NcpAssistantReasoningNormalizationMode;
|
|
145
153
|
};
|
|
146
154
|
declare class DefaultNcpAgentRuntime implements NcpAgentRuntime {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
155
|
+
private readonly contextBuilder;
|
|
156
|
+
private readonly llmApi;
|
|
157
|
+
private readonly toolRegistry;
|
|
158
|
+
private readonly stateManager;
|
|
159
|
+
private readonly streamEncoder;
|
|
160
|
+
private readonly reasoningNormalizationMode;
|
|
161
|
+
constructor(config: DefaultNcpAgentRuntimeConfig);
|
|
162
|
+
run: (this: DefaultNcpAgentRuntime, input: NcpAgentRunInput, options?: NcpAgentRunOptions) => AsyncGenerator<NcpEndpointEvent>;
|
|
163
|
+
/**
|
|
164
|
+
* Agent loop: LLM stream → encoder events → tool execution (if any) → next round or finish.
|
|
165
|
+
* RunFinished is emitted only when the entire loop completes (no more tool calls).
|
|
166
|
+
* The stream encoder does not emit RunFinished; it only converts chunks to NCP events.
|
|
167
|
+
*/
|
|
168
|
+
private runLoop;
|
|
169
|
+
private executeToolCall;
|
|
170
|
+
private resolveValidationIssues;
|
|
171
|
+
private executeValidatedToolCall;
|
|
172
|
+
private tapStream;
|
|
162
173
|
}
|
|
163
|
-
|
|
164
|
-
export { type AssetMeta, type AssetPutInput, type AssetRef, DefaultNcpAgentRuntime, type DefaultNcpAgentRuntimeConfig, DefaultNcpContextBuilder, DefaultNcpRoundBuffer, DefaultNcpStreamEncoder, DefaultNcpToolRegistry, EchoNcpLLMApi, LocalAssetStore, type StoredAssetRecord, buildAssetContentPath, buildNcpUserContent, isTextLikeAsset };
|
|
174
|
+
//#endregion
|
|
175
|
+
export { type AssetMeta, type AssetPutInput, type AssetRef, DefaultNcpAgentRuntime, type DefaultNcpAgentRuntimeConfig, DefaultNcpContextBuilder, DefaultNcpRoundBuffer, DefaultNcpStreamEncoder, DefaultNcpToolRegistry, EchoNcpLLMApi, LocalAssetStore, type StoredAssetRecord, buildAssetContentPath, buildNcpUserContent, isTextLikeAsset };
|