@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.
Files changed (3) hide show
  1. package/dist/index.d.ts +135 -124
  2. package/dist/index.js +1105 -1109
  3. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1,164 +1,175 @@
1
- import { NcpContextBuilder, NcpToolRegistry, NcpAgentRunInput, NcpContextPrepareOptions, NcpLLMApiInput, NcpMessagePart, OpenAIContentPart, NcpRoundBuffer, NcpToolCallResult, NcpStreamEncoder, NcpAssistantReasoningNormalizationMode, OpenAIChatChunk, NcpEncodeContext, NcpEndpointEvent, NcpTool, NcpToolDefinition, NcpLLMApi, NcpLLMApiOptions, NcpAgentRuntime, NcpAgentConversationStateManager, NcpAgentRunOptions } from '@nextclaw/ncp';
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
- id: string;
5
- uri: string;
6
- storageKey: string;
7
- fileName: string;
8
- storedName: string;
9
- mimeType: string;
10
- sizeBytes: number;
11
- createdAt: string;
12
- sha256: string;
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
- uri: string;
16
+ uri: string;
16
17
  };
17
18
  type AssetMeta = {
18
- uri: string;
19
- fileName: string;
20
- mimeType: string;
21
- sizeBytes: number;
22
- createdAt: string;
19
+ uri: string;
20
+ fileName: string;
21
+ mimeType: string;
22
+ sizeBytes: number;
23
+ createdAt: string;
23
24
  };
24
25
  type AssetPutInput = {
25
- kind: "path";
26
- path: string;
27
- fileName?: string;
28
- mimeType?: string | null;
29
- createdAt?: Date;
26
+ kind: "path";
27
+ path: string;
28
+ fileName?: string;
29
+ mimeType?: string | null;
30
+ createdAt?: Date;
30
31
  } | {
31
- kind: "bytes";
32
- bytes: Uint8Array;
33
- fileName: string;
34
- mimeType?: string | null;
35
- createdAt?: Date;
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
- mimeType?: string | null;
39
- fileName?: string | null;
39
+ mimeType?: string | null;
40
+ fileName?: string | null;
40
41
  }): boolean;
41
42
  declare class LocalAssetStore {
42
- readonly rootDir: string;
43
- constructor(options: {
44
- rootDir: string;
45
- });
46
- put(input: AssetPutInput): Promise<AssetRef>;
47
- putBytes(params: {
48
- fileName: string;
49
- mimeType?: string | null;
50
- bytes: Uint8Array;
51
- createdAt?: Date;
52
- }): Promise<StoredAssetRecord>;
53
- putPath(params: {
54
- path: string;
55
- fileName?: string;
56
- mimeType?: string | null;
57
- createdAt?: Date;
58
- }): Promise<StoredAssetRecord>;
59
- export(ref: AssetRef, targetPath: string): Promise<string>;
60
- stat(ref: AssetRef): Promise<AssetMeta | null>;
61
- getByUri(uri: string): StoredAssetRecord | null;
62
- statRecord(uri: string): Promise<StoredAssetRecord | null>;
63
- readAssetBytes(uri: string): Promise<Buffer | null>;
64
- resolveContentPath(uri: string): string | null;
65
- private putFromPath;
66
- private putFromBytes;
67
- private buildRecord;
68
- private writeMeta;
69
- private resolveContentPathOrThrow;
70
- private resolveStorageKeyDirectory;
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
- basePath: string;
74
- assetUri: string;
74
+ basePath: string;
75
+ assetUri: string;
75
76
  }): string;
76
-
77
+ //#endregion
78
+ //#region src/context-builder.d.ts
77
79
  type DefaultNcpContextBuilderOptions = {
78
- toolRegistry?: NcpToolRegistry;
79
- assetStore?: LocalAssetStore | null;
80
+ toolRegistry?: NcpToolRegistry;
81
+ assetStore?: LocalAssetStore | null;
80
82
  };
81
83
  declare class DefaultNcpContextBuilder implements NcpContextBuilder {
82
- private readonly toolRegistry?;
83
- private readonly assetStore?;
84
- constructor(toolRegistry?: NcpToolRegistry);
85
- constructor(options?: DefaultNcpContextBuilderOptions);
86
- prepare: (input: NcpAgentRunInput, options?: NcpContextPrepareOptions) => NcpLLMApiInput;
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
- assetStore?: LocalAssetStore | null;
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
- private text;
95
- private readonly toolCalls;
96
- private pending;
97
- appendText: (delta: string) => void;
98
- getText: () => string;
99
- appendToolCall: (result: NcpToolCallResult) => void;
100
- getToolCalls: () => ReadonlyArray<NcpToolCallResult>;
101
- startToolCall: (toolCallId: string, toolName: string) => void;
102
- appendToolCallArgs: (args: unknown) => void;
103
- consumePendingToolCall: () => {
104
- toolCallId: string;
105
- toolName: string;
106
- args: unknown;
107
- } | null;
108
- clear: () => void;
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
- reasoningNormalizationMode?: NcpAssistantReasoningNormalizationMode;
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
- private readonly reasoningNormalizationMode;
120
- constructor(config?: DefaultNcpStreamEncoderConfig);
121
- encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncGenerator<NcpEndpointEvent>;
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
- private readonly tools;
126
- constructor(tools?: ReadonlyArray<NcpTool>);
127
- register: (tool: NcpTool) => void;
128
- listTools: () => ReadonlyArray<NcpTool>;
129
- getTool: (name: string) => NcpTool | undefined;
130
- getToolDefinitions: () => ReadonlyArray<NcpToolDefinition>;
131
- execute: (_toolCallId: string, toolName: string, args: unknown) => Promise<unknown>;
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
- generate: (input: NcpLLMApiInput, options?: NcpLLMApiOptions) => AsyncGenerator<OpenAIChatChunk>;
142
+ generate: (input: NcpLLMApiInput, options?: NcpLLMApiOptions) => AsyncGenerator<OpenAIChatChunk>;
136
143
  }
137
-
144
+ //#endregion
145
+ //#region src/runtime.d.ts
138
146
  type DefaultNcpAgentRuntimeConfig = {
139
- contextBuilder: NcpContextBuilder;
140
- llmApi: NcpLLMApi;
141
- toolRegistry: NcpToolRegistry;
142
- stateManager: NcpAgentConversationStateManager;
143
- streamEncoder?: NcpStreamEncoder;
144
- reasoningNormalizationMode?: NcpAssistantReasoningNormalizationMode;
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
- private readonly contextBuilder;
148
- private readonly llmApi;
149
- private readonly toolRegistry;
150
- private readonly stateManager;
151
- private readonly streamEncoder;
152
- private readonly reasoningNormalizationMode;
153
- constructor(config: DefaultNcpAgentRuntimeConfig);
154
- run: (this: DefaultNcpAgentRuntime, input: NcpAgentRunInput, options?: NcpAgentRunOptions) => AsyncGenerator<NcpEndpointEvent>;
155
- /**
156
- * Agent loop: LLM stream → encoder events → tool execution (if any) → next round or finish.
157
- * RunFinished is emitted only when the entire loop completes (no more tool calls).
158
- * The stream encoder does not emit RunFinished; it only converts chunks to NCP events.
159
- */
160
- private runLoop;
161
- private tapStream;
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 };