@nextclaw/ncp-agent-runtime 0.3.16 → 0.3.18

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NcpAgentConversationStateManager, NcpAgentRunInput, NcpAgentRunOptions, NcpAgentRuntime, NcpAssistantReasoningNormalizationMode, NcpContextBuilder, NcpContextPrepareOptions, NcpEncodeContext, NcpEndpointEvent, NcpInvalidToolArgumentsResult, NcpLLMApi, NcpLLMApiInput, NcpLLMApiOptions, NcpMessagePart, NcpRoundBuffer, NcpStreamEncoder, NcpTool, NcpToolCallResult, NcpToolDefinition, NcpToolRegistry, OpenAIChatChunk, OpenAIChatMessage, OpenAIContentPart, OpenAITool } from "@nextclaw/ncp";
2
2
 
3
- //#region src/asset-store.d.ts
3
+ //#region src/assets/asset-store.d.ts
4
4
  type StoredAssetRecord = {
5
5
  id: string;
6
6
  uri: string;
@@ -75,7 +75,7 @@ declare function buildAssetContentPath(params: {
75
75
  assetUri: string;
76
76
  }): string;
77
77
  //#endregion
78
- //#region src/context-builder.d.ts
78
+ //#region src/runtime/context-builder.d.ts
79
79
  type DefaultNcpContextBuilderOptions = {
80
80
  toolRegistry?: NcpToolRegistry;
81
81
  assetStore?: LocalAssetStore | null;
@@ -88,12 +88,12 @@ declare class DefaultNcpContextBuilder implements NcpContextBuilder {
88
88
  prepare: (input: NcpAgentRunInput, options?: NcpContextPrepareOptions) => NcpLLMApiInput;
89
89
  }
90
90
  //#endregion
91
- //#region src/user-content.d.ts
91
+ //#region src/runtime/user-content.d.ts
92
92
  declare function buildNcpUserContent(parts: NcpMessagePart[], options?: {
93
93
  assetStore?: LocalAssetStore | null;
94
94
  }): string | OpenAIContentPart[];
95
95
  //#endregion
96
- //#region src/round-buffer.d.ts
96
+ //#region src/runtime/round-buffer.d.ts
97
97
  declare class DefaultNcpRoundBuffer implements NcpRoundBuffer {
98
98
  private text;
99
99
  private readonly toolCalls;
@@ -112,7 +112,7 @@ declare class DefaultNcpRoundBuffer implements NcpRoundBuffer {
112
112
  clear: () => void;
113
113
  }
114
114
  //#endregion
115
- //#region src/stream-encoder.d.ts
115
+ //#region src/runtime/stream-encoder.d.ts
116
116
  type DefaultNcpStreamEncoderConfig = {
117
117
  reasoningNormalizationMode?: NcpAssistantReasoningNormalizationMode;
118
118
  };
@@ -126,7 +126,7 @@ declare class DefaultNcpStreamEncoder implements NcpStreamEncoder {
126
126
  encode(stream: AsyncIterable<OpenAIChatChunk>, context: NcpEncodeContext): AsyncGenerator<NcpEndpointEvent>;
127
127
  }
128
128
  //#endregion
129
- //#region src/tool-registry.d.ts
129
+ //#region src/runtime/tool-registry.d.ts
130
130
  declare class DefaultNcpToolRegistry implements NcpToolRegistry {
131
131
  private readonly tools;
132
132
  constructor(tools?: ReadonlyArray<NcpTool>);
@@ -137,12 +137,12 @@ declare class DefaultNcpToolRegistry implements NcpToolRegistry {
137
137
  execute: (_toolCallId: string, toolName: string, args: unknown) => Promise<unknown>;
138
138
  }
139
139
  //#endregion
140
- //#region src/llm-api-echo.d.ts
140
+ //#region src/runtime/llm-api-echo.d.ts
141
141
  declare class EchoNcpLLMApi implements NcpLLMApi {
142
142
  generate: (input: NcpLLMApiInput, options?: NcpLLMApiOptions) => AsyncGenerator<OpenAIChatChunk>;
143
143
  }
144
144
  //#endregion
145
- //#region src/tool-result-content.manager.d.ts
145
+ //#region src/tool-result/tool-result-content.manager.d.ts
146
146
  type ToolResultContentContext = {
147
147
  toolCallId?: string;
148
148
  toolName?: string;
@@ -190,7 +190,7 @@ declare class ToolResultContentManager {
190
190
  }
191
191
  declare const defaultToolResultContentManager: ToolResultContentManager;
192
192
  //#endregion
193
- //#region src/agent-runtime.service.d.ts
193
+ //#region src/runtime/agent-runtime.service.d.ts
194
194
  type DefaultNcpAgentRuntimeConfig = {
195
195
  contextBuilder: NcpContextBuilder;
196
196
  llmApi: NcpLLMApi;
@@ -222,7 +222,7 @@ declare class DefaultNcpAgentRuntime implements NcpAgentRuntime {
222
222
  private tapStream;
223
223
  }
224
224
  //#endregion
225
- //#region src/utils.d.ts
225
+ //#region src/runtime/utils.d.ts
226
226
  type ParsedToolArgs = {
227
227
  ok: true;
228
228
  rawText: string;
package/dist/index.js CHANGED
@@ -4,18 +4,19 @@ import { createHash, randomUUID } from "node:crypto";
4
4
  import { copyFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
5
5
  import { basename, dirname, join, resolve } from "node:path";
6
6
  import { NcpAssistantTextStreamNormalizer, NcpEventType, isHiddenNcpMessage, normalizeAssistantText } from "@nextclaw/ncp";
7
- //#region src/user-content.ts
7
+ //#region src/runtime/user-content.ts
8
8
  function readOptionalString$1(value) {
9
9
  if (typeof value !== "string") return null;
10
10
  const trimmed = value.trim();
11
11
  return trimmed.length > 0 ? trimmed : null;
12
12
  }
13
13
  function formatAssetReferenceBlock(params) {
14
- const fileName = readOptionalString$1(params.fileName) ?? "asset";
15
- const mimeType = readOptionalString$1(params.mimeType) ?? "application/octet-stream";
16
- const assetUri = readOptionalString$1(params.assetUri);
17
- const url = readOptionalString$1(params.url);
18
- const sizeText = typeof params.sizeBytes === "number" && Number.isFinite(params.sizeBytes) ? String(params.sizeBytes) : null;
14
+ const { fileName: rawFileName, mimeType: rawMimeType, assetUri: rawAssetUri, url: rawUrl, sizeBytes } = params;
15
+ const fileName = readOptionalString$1(rawFileName) ?? "asset";
16
+ const mimeType = readOptionalString$1(rawMimeType) ?? "application/octet-stream";
17
+ const assetUri = readOptionalString$1(rawAssetUri);
18
+ const url = readOptionalString$1(rawUrl);
19
+ const sizeText = typeof sizeBytes === "number" && Number.isFinite(sizeBytes) ? String(sizeBytes) : null;
19
20
  return [
20
21
  `[Asset: ${fileName}]`,
21
22
  `[MIME: ${mimeType}]`,
@@ -147,7 +148,7 @@ function buildNcpUserContent(parts, options = {}) {
147
148
  return content;
148
149
  }
149
150
  //#endregion
150
- //#region src/tool-result-content.utils.ts
151
+ //#region src/tool-result/tool-result-content.utils.ts
151
152
  const LARGE_INLINE_PAYLOAD_CHARS$1 = 2048;
152
153
  function sanitizePositiveInt(value, fallback) {
153
154
  if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
@@ -205,7 +206,7 @@ function readStringField(value, key) {
205
206
  return typeof field === "string" && field.length > 0 ? field : null;
206
207
  }
207
208
  //#endregion
208
- //#region src/tool-result-image.service.ts
209
+ //#region src/tool-result/tool-result-image.service.ts
209
210
  const LARGE_INLINE_PAYLOAD_CHARS = 2048;
210
211
  const DEFAULT_MAX_MODEL_VISIBLE_IMAGES$1 = 4;
211
212
  const DEFAULT_MAX_ARRAY_ITEMS$1 = 50;
@@ -338,7 +339,7 @@ function redactImageUrl(value) {
338
339
  return value.length > LARGE_INLINE_PAYLOAD_CHARS ? truncateMiddle(value, LARGE_INLINE_PAYLOAD_CHARS) : value;
339
340
  }
340
341
  //#endregion
341
- //#region src/tool-result-content.manager.ts
342
+ //#region src/tool-result/tool-result-content.manager.ts
342
343
  const DEFAULT_MAX_MODEL_VISIBLE_CHARS = 1e4;
343
344
  const DEFAULT_MAX_TOOL_MESSAGES_CHARS = 6e4;
344
345
  const DEFAULT_MAX_STRING_VALUE_CHARS = 4e3;
@@ -564,7 +565,7 @@ var ToolResultContentManager = class {
564
565
  };
565
566
  const defaultToolResultContentManager = new ToolResultContentManager();
566
567
  //#endregion
567
- //#region src/utils.ts
568
+ //#region src/runtime/utils.ts
568
569
  const toolSchemaValidator = new AjvPkg({
569
570
  allErrors: true,
570
571
  strict: false,
@@ -740,7 +741,7 @@ function appendToolRoundToInput(input, reasoning, text, toolResults, toolResultC
740
741
  });
741
742
  }
742
743
  //#endregion
743
- //#region src/context-builder.ts
744
+ //#region src/runtime/context-builder.ts
744
745
  function isRecord(value) {
745
746
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
746
747
  }
@@ -874,7 +875,7 @@ var DefaultNcpContextBuilder = class {
874
875
  };
875
876
  };
876
877
  //#endregion
877
- //#region src/asset-store.ts
878
+ //#region src/assets/asset-store.ts
878
879
  const ASSET_URI_SCHEME = "asset://store/";
879
880
  function normalizeSegment(value) {
880
881
  return value.replace(/[^\w.-]+/g, "_").replace(/^_+|_+$/g, "") || "asset.bin";
@@ -1128,7 +1129,7 @@ async function ensureParentDirectory(filePath) {
1128
1129
  await mkdir(dirname(filePath), { recursive: true });
1129
1130
  }
1130
1131
  //#endregion
1131
- //#region src/round-buffer.ts
1132
+ //#region src/runtime/round-buffer.ts
1132
1133
  var DefaultNcpRoundBuffer = class {
1133
1134
  text = "";
1134
1135
  toolCalls = [];
@@ -1167,7 +1168,7 @@ var DefaultNcpRoundBuffer = class {
1167
1168
  };
1168
1169
  };
1169
1170
  //#endregion
1170
- //#region src/stream-encoder.utils.ts
1171
+ //#region src/runtime/stream-encoder.utils.ts
1171
1172
  function getToolCallIndex(toolDelta, fallback) {
1172
1173
  const idx = toolDelta.index;
1173
1174
  return typeof idx === "number" && Number.isFinite(idx) ? idx : fallback;
@@ -1383,7 +1384,7 @@ function createStreamContentState(reasoningNormalizationMode) {
1383
1384
  };
1384
1385
  }
1385
1386
  //#endregion
1386
- //#region src/stream-encoder.ts
1387
+ //#region src/runtime/stream-encoder.ts
1387
1388
  /**
1388
1389
  * Converts LLM stream chunks to NCP events (text, reasoning, tool calls).
1389
1390
  * Does not emit RunFinished; that is the runtime's responsibility after the loop completes.
@@ -1441,7 +1442,7 @@ var DefaultNcpStreamEncoder = class {
1441
1442
  }
1442
1443
  };
1443
1444
  //#endregion
1444
- //#region src/tool-registry.ts
1445
+ //#region src/runtime/tool-registry.ts
1445
1446
  var DefaultNcpToolRegistry = class {
1446
1447
  tools = /* @__PURE__ */ new Map();
1447
1448
  constructor(tools = []) {
@@ -1469,7 +1470,7 @@ var DefaultNcpToolRegistry = class {
1469
1470
  };
1470
1471
  };
1471
1472
  //#endregion
1472
- //#region src/llm-api-echo.ts
1473
+ //#region src/runtime/llm-api-echo.ts
1473
1474
  function getLastUserContent(messages) {
1474
1475
  for (let i = messages.length - 1; i >= 0; i--) {
1475
1476
  const m = messages[i];
@@ -1505,7 +1506,7 @@ var EchoNcpLLMApi = class {
1505
1506
  };
1506
1507
  };
1507
1508
  //#endregion
1508
- //#region src/round-collector.ts
1509
+ //#region src/runtime/round-collector.ts
1509
1510
  var DefaultNcpRoundCollector = class {
1510
1511
  rawText = "";
1511
1512
  explicitReasoning = "";
@@ -1558,7 +1559,7 @@ var DefaultNcpRoundCollector = class {
1558
1559
  }
1559
1560
  };
1560
1561
  //#endregion
1561
- //#region src/agent-runtime.service.ts
1562
+ //#region src/runtime/agent-runtime.service.ts
1562
1563
  var DefaultNcpAgentRuntime = class {
1563
1564
  contextBuilder;
1564
1565
  llmApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-agent-runtime",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
4
4
  "private": false,
5
5
  "description": "Default agent runtime implementation built on NCP interfaces.",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "ajv": "^8.17.1",
19
- "@nextclaw/ncp": "0.5.6"
19
+ "@nextclaw/ncp": "0.5.8"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^20.17.6",