@nextclaw/kernel 0.19.0 → 0.19.2-beta.0

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 (62) hide show
  1. package/dist/agent-model-input-budget.utils-tw9zs9WM.js +26 -0
  2. package/dist/agent-model-input-budget.utils-tw9zs9WM.js.map +1 -0
  3. package/dist/agent-run-context-compaction.manager-BV6tB0wL.d.ts +28 -0
  4. package/dist/agent-run-context-compaction.manager-BV6tB0wL.d.ts.map +1 -0
  5. package/dist/agent-run-model-input-builder.service-C3ydUx3d.js +320 -0
  6. package/dist/agent-run-model-input-builder.service-C3ydUx3d.js.map +1 -0
  7. package/dist/agent-run.types-CNVBBJnd.d.ts +71 -0
  8. package/dist/agent-run.types-CNVBBJnd.d.ts.map +1 -0
  9. package/dist/context-compaction-preflight.service-ClJEGWKS.d.ts +97 -0
  10. package/dist/context-compaction-preflight.service-ClJEGWKS.d.ts.map +1 -0
  11. package/dist/context-compaction-preflight.service-K0tE34Oz.js +689 -0
  12. package/dist/context-compaction-preflight.service-K0tE34Oz.js.map +1 -0
  13. package/dist/context-compaction.utils-Csf80mdq.d.ts +42 -0
  14. package/dist/context-compaction.utils-Csf80mdq.d.ts.map +1 -0
  15. package/dist/features/context-compaction/services/context-compaction-preflight.service.d.ts +2 -0
  16. package/dist/features/context-compaction/services/context-compaction-preflight.service.js +2 -0
  17. package/dist/features/context-compaction/utils/context-compaction.utils.d.ts +2 -0
  18. package/dist/features/context-compaction/utils/context-compaction.utils.js +202 -0
  19. package/dist/features/context-compaction/utils/context-compaction.utils.js.map +1 -0
  20. package/dist/index.d.ts +136 -1247
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +770 -1837
  23. package/dist/index.js.map +1 -1
  24. package/dist/managers/agent-run-context-compaction.manager.d.ts +2 -0
  25. package/dist/managers/agent-run-context-compaction.manager.js +68 -0
  26. package/dist/managers/agent-run-context-compaction.manager.js.map +1 -0
  27. package/dist/request-context-tail.manager-DXC4rdAP.d.ts +22 -0
  28. package/dist/request-context-tail.manager-DXC4rdAP.d.ts.map +1 -0
  29. package/dist/services/agent-run-model-input-builder.service.d.ts +58 -0
  30. package/dist/services/agent-run-model-input-builder.service.d.ts.map +1 -0
  31. package/dist/services/agent-run-model-input-builder.service.js +2 -0
  32. package/dist/tool-schema.tools-CtZEKWeY.js +75 -0
  33. package/dist/tool-schema.tools-CtZEKWeY.js.map +1 -0
  34. package/dist/tools/show-content.tools.d.ts +10 -0
  35. package/dist/tools/show-content.tools.d.ts.map +1 -0
  36. package/dist/tools/show-content.tools.js +294 -0
  37. package/dist/tools/show-content.tools.js.map +1 -0
  38. package/dist/tools/tool-schema.tools.d.ts +29 -0
  39. package/dist/tools/tool-schema.tools.d.ts.map +1 -0
  40. package/dist/tools/tool-schema.tools.js +2 -0
  41. package/dist/tools/user-question.tools.d.ts +63 -0
  42. package/dist/tools/user-question.tools.d.ts.map +1 -0
  43. package/dist/tools/user-question.tools.js +77 -0
  44. package/dist/tools/user-question.tools.js.map +1 -0
  45. package/dist/types/update-contract.types.d.ts +1 -1
  46. package/dist/types/update-contract.types.js +1 -1
  47. package/dist/{update-manifest.types-CQpbURTE.d.ts → update-manifest.types-Dl4B87Pa.d.ts} +1 -1
  48. package/dist/{update-manifest.types-CQpbURTE.d.ts.map → update-manifest.types-Dl4B87Pa.d.ts.map} +1 -1
  49. package/dist/{update-manifest.types-C0qPrjGQ.js → update-manifest.types-eSil_QH0.js} +1 -1
  50. package/dist/{update-manifest.types-C0qPrjGQ.js.map → update-manifest.types-eSil_QH0.js.map} +1 -1
  51. package/dist/user-question.manager-38KBgZCg.d.ts +1038 -0
  52. package/dist/user-question.manager-38KBgZCg.d.ts.map +1 -0
  53. package/dist/user-question.utils-DWVtPv4S.d.ts +27 -0
  54. package/dist/user-question.utils-DWVtPv4S.d.ts.map +1 -0
  55. package/dist/utils/agent-onboarding-context.utils.d.ts +6 -0
  56. package/dist/utils/agent-onboarding-context.utils.d.ts.map +1 -0
  57. package/dist/utils/agent-onboarding-context.utils.js +39 -0
  58. package/dist/utils/agent-onboarding-context.utils.js.map +1 -0
  59. package/dist/utils/user-question.utils.d.ts +2 -0
  60. package/dist/utils/user-question.utils.js +105 -0
  61. package/dist/utils/user-question.utils.js.map +1 -0
  62. package/package.json +61 -16
@@ -0,0 +1,2 @@
1
+ import { n as AgentRunContextCompactionManager, t as AgentRunContextCompactionInput } from "../agent-run-context-compaction.manager-BV6tB0wL.js";
2
+ export { AgentRunContextCompactionInput, AgentRunContextCompactionManager };
@@ -0,0 +1,68 @@
1
+ import { t as ContextCompactionPreflightService } from "../context-compaction-preflight.service-K0tE34Oz.js";
2
+ import { buildContextCompactionTimelineNcpMessage } from "../features/context-compaction/utils/context-compaction.utils.js";
3
+ import { NcpEventType } from "@nextclaw/ncp";
4
+ //#region src/managers/agent-run-context-compaction.manager.ts
5
+ var AgentRunContextCompactionManager = class {
6
+ preflightService;
7
+ constructor(agentManager, providerManager, assetStore = null) {
8
+ this.preflightService = new ContextCompactionPreflightService(agentManager, providerManager, assetStore);
9
+ }
10
+ runPreflight = (input) => {
11
+ return this.run(input, "automatic", input.phase ?? "pre-run");
12
+ };
13
+ runManual = async (input) => {
14
+ const events = [];
15
+ for await (const event of this.run(input, "manual", "pre-run")) events.push(event);
16
+ return events;
17
+ };
18
+ run = async function* (input, trigger, phase) {
19
+ const beginResult = this.preflightService.begin({
20
+ contextBlocks: input.contextBlocks,
21
+ inputMessages: [],
22
+ model: input.model,
23
+ phase,
24
+ requestMetadata: input.metadata,
25
+ sessionId: input.sessionId,
26
+ sessionMessages: input.messages,
27
+ storedAgentId: input.agentId,
28
+ storedMetadata: input.metadata,
29
+ tools: input.tools,
30
+ trigger
31
+ });
32
+ if (!beginResult.pendingCompaction) return;
33
+ const pending = beginResult.pendingCompaction;
34
+ yield this.toEvent(input.sessionId, buildContextCompactionTimelineNcpMessage({
35
+ checkpoint: pending.checkpoint,
36
+ messageId: pending.serviceMessageId,
37
+ sessionId: input.sessionId
38
+ }));
39
+ try {
40
+ const finishResult = await this.preflightService.finish(pending, input.signal);
41
+ if (finishResult.timelineMessage) yield this.toEvent(input.sessionId, finishResult.timelineMessage);
42
+ } catch (error) {
43
+ yield this.toEvent(input.sessionId, buildContextCompactionTimelineNcpMessage({
44
+ checkpoint: {
45
+ ...pending.checkpoint,
46
+ status: input.signal?.aborted ? "cancelled" : "failed",
47
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
48
+ },
49
+ messageId: pending.serviceMessageId,
50
+ sessionId: input.sessionId
51
+ }));
52
+ if (input.signal?.aborted) return;
53
+ throw error;
54
+ }
55
+ };
56
+ toEvent = (sessionId, message) => ({
57
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
58
+ type: NcpEventType.MessageSent,
59
+ payload: {
60
+ sessionId,
61
+ message
62
+ }
63
+ });
64
+ };
65
+ //#endregion
66
+ export { AgentRunContextCompactionManager };
67
+
68
+ //# sourceMappingURL=agent-run-context-compaction.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-run-context-compaction.manager.js","names":[],"sources":["../../src/managers/agent-run-context-compaction.manager.ts"],"sourcesContent":["import type { ContextCompactionPhase } from \"@nextclaw/core/context-compaction\";\nimport type { LocalAssetStore } from \"@nextclaw/ncp-agent-runtime\";\nimport {\n buildContextCompactionTimelineNcpMessage,\n} from \"@kernel/features/context-compaction/utils/context-compaction.utils.js\";\nimport {\n ContextCompactionPreflightService,\n type CompactionProfileResolver,\n type CompactionSummaryProvider,\n type ContextCompactionPreflightResult,\n} from \"@kernel/features/context-compaction/services/context-compaction-preflight.service.js\";\nimport {\n NcpEventType,\n type NcpEndpointEvent,\n type NcpMessage,\n type NcpTool,\n} from \"@nextclaw/ncp\";\n\nexport type AgentRunContextCompactionInput = {\n sessionId: string;\n agentId: string;\n contextBlocks: readonly string[];\n messages: readonly NcpMessage[];\n metadata: Record<string, unknown>;\n model: string;\n phase?: ContextCompactionPhase;\n signal?: AbortSignal;\n tools?: readonly NcpTool[];\n};\n\nexport class AgentRunContextCompactionManager {\n private readonly preflightService: ContextCompactionPreflightService;\n\n constructor(\n agentManager: CompactionProfileResolver,\n providerManager: CompactionSummaryProvider,\n assetStore: LocalAssetStore | null = null,\n ) {\n this.preflightService = new ContextCompactionPreflightService(\n agentManager,\n providerManager,\n assetStore,\n );\n }\n\n runPreflight = (\n input: AgentRunContextCompactionInput,\n ): AsyncIterable<NcpEndpointEvent> => {\n return this.run(input, \"automatic\", input.phase ?? \"pre-run\");\n };\n\n runManual = async (\n input: AgentRunContextCompactionInput,\n ): Promise<readonly NcpEndpointEvent[]> => {\n const events: NcpEndpointEvent[] = [];\n for await (const event of this.run(input, \"manual\", \"pre-run\")) {\n events.push(event);\n }\n return events;\n };\n\n private run = async function* (\n this: AgentRunContextCompactionManager,\n input: AgentRunContextCompactionInput,\n trigger: \"automatic\" | \"manual\",\n phase: ContextCompactionPhase,\n ): AsyncIterable<NcpEndpointEvent> {\n const beginResult = this.preflightService.begin({\n contextBlocks: input.contextBlocks,\n inputMessages: [],\n model: input.model,\n phase,\n requestMetadata: input.metadata,\n sessionId: input.sessionId,\n sessionMessages: input.messages,\n storedAgentId: input.agentId,\n storedMetadata: input.metadata,\n tools: input.tools,\n trigger,\n });\n if (!beginResult.pendingCompaction) {\n return;\n }\n const pending = beginResult.pendingCompaction;\n yield this.toEvent(input.sessionId, buildContextCompactionTimelineNcpMessage({\n checkpoint: pending.checkpoint,\n messageId: pending.serviceMessageId,\n sessionId: input.sessionId,\n }));\n try {\n const finishResult = await this.preflightService.finish(pending, input.signal);\n if (finishResult.timelineMessage) {\n yield this.toEvent(input.sessionId, finishResult.timelineMessage);\n }\n } catch (error) {\n yield this.toEvent(input.sessionId, buildContextCompactionTimelineNcpMessage({\n checkpoint: {\n ...pending.checkpoint,\n status: input.signal?.aborted ? \"cancelled\" : \"failed\",\n updatedAt: new Date().toISOString(),\n },\n messageId: pending.serviceMessageId,\n sessionId: input.sessionId,\n }));\n if (input.signal?.aborted) {\n return;\n }\n throw error;\n }\n };\n\n private toEvent = (\n sessionId: string,\n message: NonNullable<ContextCompactionPreflightResult[\"timelineMessage\"]>,\n ): NcpEndpointEvent => ({\n occurredAt: new Date().toISOString(),\n type: NcpEventType.MessageSent,\n payload: {\n sessionId,\n message,\n },\n });\n}\n"],"mappings":";;;;AA8BA,IAAa,mCAAb,MAA8C;CAC5C;CAEA,YACE,cACA,iBACA,aAAqC,MACrC;AACA,OAAK,mBAAmB,IAAI,kCAC1B,cACA,iBACA,WACD;;CAGH,gBACE,UACoC;AACpC,SAAO,KAAK,IAAI,OAAO,aAAa,MAAM,SAAS,UAAU;;CAG/D,YAAY,OACV,UACyC;EACzC,MAAM,SAA6B,EAAE;AACrC,aAAW,MAAM,SAAS,KAAK,IAAI,OAAO,UAAU,UAAU,CAC5D,QAAO,KAAK,MAAM;AAEpB,SAAO;;CAGT,MAAc,iBAEZ,OACA,SACA,OACiC;EACjC,MAAM,cAAc,KAAK,iBAAiB,MAAM;GAC9C,eAAe,MAAM;GACrB,eAAe,EAAE;GACjB,OAAO,MAAM;GACb;GACA,iBAAiB,MAAM;GACvB,WAAW,MAAM;GACjB,iBAAiB,MAAM;GACvB,eAAe,MAAM;GACrB,gBAAgB,MAAM;GACtB,OAAO,MAAM;GACb;GACD,CAAC;AACF,MAAI,CAAC,YAAY,kBACf;EAEF,MAAM,UAAU,YAAY;AAC5B,QAAM,KAAK,QAAQ,MAAM,WAAW,yCAAyC;GAC3E,YAAY,QAAQ;GACpB,WAAW,QAAQ;GACnB,WAAW,MAAM;GAClB,CAAC,CAAC;AACH,MAAI;GACF,MAAM,eAAe,MAAM,KAAK,iBAAiB,OAAO,SAAS,MAAM,OAAO;AAC9E,OAAI,aAAa,gBACf,OAAM,KAAK,QAAQ,MAAM,WAAW,aAAa,gBAAgB;WAE5D,OAAO;AACd,SAAM,KAAK,QAAQ,MAAM,WAAW,yCAAyC;IAC3E,YAAY;KACV,GAAG,QAAQ;KACX,QAAQ,MAAM,QAAQ,UAAU,cAAc;KAC9C,4BAAW,IAAI,MAAM,EAAC,aAAa;KACpC;IACD,WAAW,QAAQ;IACnB,WAAW,MAAM;IAClB,CAAC,CAAC;AACH,OAAI,MAAM,QAAQ,QAChB;AAEF,SAAM;;;CAIV,WACE,WACA,aACsB;EACtB,6BAAY,IAAI,MAAM,EAAC,aAAa;EACpC,MAAM,aAAa;EACnB,SAAS;GACP;GACA;GACD;EACF"}
@@ -0,0 +1,22 @@
1
+ import { ModelInputTail, ModelInputTailSection } from "@nextclaw/ncp";
2
+
3
+ //#region src/managers/request-context-tail.manager.d.ts
4
+ type RequestContextTailRequest = {
5
+ sessionId: string;
6
+ runId: string;
7
+ agentId: string;
8
+ model: string;
9
+ signal?: AbortSignal;
10
+ };
11
+ type RequestContextTailProvider = {
12
+ provide: (request: RequestContextTailRequest) => Promise<readonly ModelInputTailSection[]> | readonly ModelInputTailSection[];
13
+ };
14
+ declare class RequestContextTailManager {
15
+ private readonly providers;
16
+ register: (provider: RequestContextTailProvider) => (() => void);
17
+ build: (request: RequestContextTailRequest) => Promise<ModelInputTail | undefined>;
18
+ dispose: () => void;
19
+ }
20
+ //#endregion
21
+ export { RequestContextTailManager as t };
22
+ //# sourceMappingURL=request-context-tail.manager-DXC4rdAP.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context-tail.manager-DXC4rdAP.d.ts","names":[],"sources":["../src/managers/request-context-tail.manager.ts"],"mappings":";;;KAEY,yBAAA;EACV,SAAA;EACA,KAAA;EACA,OAAA;EACA,KAAA;EACA,MAAA,GAAS,WAAA;AAAA;AAAA,KAGC,0BAAA;EACV,OAAA,GACE,OAAA,EAAS,yBAAA,KAEP,OAAA,UAAiB,qBAAA,eACR,qBAAA;AAAA;AAAA,cAGF,yBAAA;EAAA,iBACM,SAAA;EAEjB,QAAA,GAAY,QAAA,EAAU,0BAAA;EAOtB,KAAA,GACE,OAAA,EAAS,yBAAA,KACR,OAAA,CAAQ,cAAA;EAUX,OAAA;AAAA"}
@@ -0,0 +1,58 @@
1
+ import { s as ContextCompactionModelProjection } from "../context-compaction.utils-Csf80mdq.js";
2
+ import { i as AgentRunSpec } from "../agent-run.types-CNVBBJnd.js";
3
+ import { t as RequestContextTailManager } from "../request-context-tail.manager-DXC4rdAP.js";
4
+ import { LocalAssetStore } from "@nextclaw/ncp-agent-runtime";
5
+ import { ModelInputTail, NcpLLMApiInput, NcpMessage, OpenAIChatMessage } from "@nextclaw/ncp";
6
+ import { InputBudgetPruneResult } from "@nextclaw/core/model-input-budget";
7
+ import { AgentModelInputBuildRequest, AgentModelInputBuilder } from "@nextclaw/ncp-agent-runtime-next";
8
+
9
+ //#region src/services/agent-run-message-projector.service.d.ts
10
+ type AgentRunMessageProjectParams = {
11
+ sessionId: string;
12
+ messages: readonly NcpMessage[];
13
+ };
14
+ declare class AgentRunMessageProjector {
15
+ project: (params: AgentRunMessageProjectParams) => ContextCompactionModelProjection;
16
+ }
17
+ //#endregion
18
+ //#region src/services/agent-run-model-input-budgeter.service.d.ts
19
+ type AgentRunModelInputBudgeterPruneParams = {
20
+ spec: AgentRunSpec;
21
+ messages: readonly OpenAIChatMessage[];
22
+ fixedInputTokens?: number;
23
+ protectedPrefixMessageCount?: number;
24
+ protectedSystemContentChars?: number;
25
+ };
26
+ type AgentRunModelInputBudgeterPruneResult = Omit<InputBudgetPruneResult, "messages"> & {
27
+ messages: OpenAIChatMessage[];
28
+ };
29
+ type AgentModelInputBudgetProfileResolver = {
30
+ resolveAgentProfile(agentId: string): {
31
+ contextTokens: number;
32
+ reservedContextTokens: number;
33
+ };
34
+ };
35
+ declare class AgentRunModelInputBudgeter {
36
+ private readonly agentManager;
37
+ private readonly inputBudgetPruner;
38
+ constructor(agentManager: AgentModelInputBudgetProfileResolver);
39
+ prune: (params: AgentRunModelInputBudgeterPruneParams) => Promise<AgentRunModelInputBudgeterPruneResult>;
40
+ }
41
+ //#endregion
42
+ //#region src/utils/agent-model-input-tail.utils.d.ts
43
+ /** Sample per send; never store this transient section in conversation history. */
44
+ declare function appendCurrentTimeContextTail(tail?: ModelInputTail): ModelInputTail;
45
+ declare function serializeModelInputTail(tail: ModelInputTail): string;
46
+ //#endregion
47
+ //#region src/services/agent-run-model-input-builder.service.d.ts
48
+ declare class AgentRunModelInputBuilder implements AgentModelInputBuilder {
49
+ private readonly messageProjector;
50
+ private readonly modelInputBudgeter;
51
+ private readonly assetStore;
52
+ private readonly requestContextTailManager;
53
+ constructor(messageProjector: AgentRunMessageProjector, modelInputBudgeter: AgentRunModelInputBudgeter, assetStore?: LocalAssetStore | null, requestContextTailManager?: Pick<RequestContextTailManager, "build"> | null);
54
+ build: (request: AgentModelInputBuildRequest) => Promise<NcpLLMApiInput>;
55
+ }
56
+ //#endregion
57
+ export { type AgentModelInputBudgetProfileResolver, AgentRunMessageProjector, AgentRunModelInputBudgeter, AgentRunModelInputBuilder, appendCurrentTimeContextTail, serializeModelInputTail };
58
+ //# sourceMappingURL=agent-run-model-input-builder.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-run-model-input-builder.service.d.ts","names":[],"sources":["../../src/services/agent-run-message-projector.service.ts","../../src/services/agent-run-model-input-budgeter.service.ts","../../src/utils/agent-model-input-tail.utils.ts","../../src/services/agent-run-model-input-builder.service.ts"],"mappings":";;;;;;;;;KAMY,4BAAA;EACV,SAAA;EACA,QAAA,WAAmB,UAAA;AAAA;AAAA,cAGR,wBAAA;EACX,OAAA,GAAW,MAAA,EAAQ,4BAAA,KAA+B,gCAAA;AAAA;;;KCLxC,qCAAA;EACV,IAAA,EAAM,YAAA;EACN,QAAA,WAAmB,iBAAA;EACnB,gBAAA;EACA,2BAAA;EACA,2BAAA;AAAA;AAAA,KAGU,qCAAA,GAAwC,IAAA,CAClD,sBAAA;EAGA,QAAA,EAAU,iBAAA;AAAA;AAAA,KAGA,oCAAA;EACV,mBAAA,CAAoB,OAAA;IAAoB,aAAA;IAAuB,qBAAA;EAAA;AAAA;AAAA,cAGpD,0BAAA;EAAA,iBAGkB,YAAA;EAAA,iBAFZ,iBAAA;cAEY,YAAA,EAAc,oCAAA;EAE3C,KAAA,GACE,MAAA,EAAQ,qCAAA,KACP,OAAA,CAAQ,qCAAA;AAAA;;;;iBC9BG,4BAAA,CAA6B,IAAA,GAAO,cAAA,GAAiB,cAAA;AAAA,iBAsBrD,uBAAA,CAAwB,IAAA,EAAM,cAAA;;;cC+BjC,yBAAA,YAAqC,sBAAA;EAAA,iBAE7B,gBAAA;EAAA,iBACA,kBAAA;EAAA,iBACA,UAAA;EAAA,iBACA,yBAAA;cAHA,gBAAA,EAAkB,wBAAA,EAClB,kBAAA,EAAoB,0BAAA,EACpB,UAAA,GAAY,eAAA,SACZ,yBAAA,GAA2B,IAAA,CAC1C,yBAAA;EAKJ,KAAA,GACE,OAAA,EAAS,2BAAA,KACR,OAAA,CAAQ,cAAA;AAAA"}
@@ -0,0 +1,2 @@
1
+ import { a as serializeModelInputTail, i as appendCurrentTimeContextTail, n as AgentRunModelInputBudgeter, r as AgentRunMessageProjector, t as AgentRunModelInputBuilder } from "../agent-run-model-input-builder.service-C3ydUx3d.js";
2
+ export { AgentRunMessageProjector, AgentRunModelInputBudgeter, AgentRunModelInputBuilder, appendCurrentTimeContextTail, serializeModelInputTail };
@@ -0,0 +1,75 @@
1
+ import { validateToolArgs } from "@nextclaw/ncp-agent-runtime";
2
+ //#region src/tools/structured-result.tools.ts
3
+ const STRUCTURED_RESULT_TOOL_NAME = "nextclaw_submit_result";
4
+ var StructuredResultSubmitTool = class {
5
+ name = STRUCTURED_RESULT_TOOL_NAME;
6
+ description = "Submit the structured object result for this request.";
7
+ constructor(contract) {
8
+ this.contract = contract;
9
+ }
10
+ get parameters() {
11
+ return this.contract.schema;
12
+ }
13
+ validateArgs = (args) => validateToolArgs(args, this.contract.schema);
14
+ execute = async (args) => args;
15
+ };
16
+ //#endregion
17
+ //#region src/tools/tool-schema.tools.ts
18
+ const TOOL_SCHEMA_NAME = "tool_schema";
19
+ const EAGER_TOOL_NAMES = new Set([
20
+ TOOL_SCHEMA_NAME,
21
+ STRUCTURED_RESULT_TOOL_NAME,
22
+ "node_repl",
23
+ "read_file",
24
+ "write_file",
25
+ "edit_file",
26
+ "list_dir",
27
+ "exec",
28
+ "web_search",
29
+ "web_fetch",
30
+ "view_image",
31
+ "memory_search",
32
+ "memory_get"
33
+ ]);
34
+ /** Model-facing disclosure only; execution continues to validate the original schema. */
35
+ function selectToolModelParameters(tool) {
36
+ const parameters = tool.modelParameters ?? tool.parameters;
37
+ return EAGER_TOOL_NAMES.has(tool.name) || !parameters || JSON.stringify(parameters).length <= 160 ? parameters : { type: "object" };
38
+ }
39
+ var ToolSchemaTool = class {
40
+ name = TOOL_SCHEMA_NAME;
41
+ description = "Read full parameters for an available tool. Before first using a tool whose object schema has no properties field, query its exact name here, then call the original tool with the returned parameter shape.";
42
+ parameters = {
43
+ type: "object",
44
+ properties: { name: {
45
+ type: "string",
46
+ minLength: 1
47
+ } },
48
+ required: ["name"],
49
+ additionalProperties: false
50
+ };
51
+ modelParameters;
52
+ validateArgs;
53
+ constructor(readTools, portableValidation = false) {
54
+ this.readTools = readTools;
55
+ if (portableValidation) {
56
+ this.modelParameters = this.parameters;
57
+ this.validateArgs = (value) => typeof value.name === "string" && value.name.trim() ? [] : ["name is required"];
58
+ }
59
+ }
60
+ execute = async (args) => {
61
+ const name = args && typeof args === "object" && "name" in args ? args.name : null;
62
+ if (typeof name !== "string" || !name.trim()) throw new Error("Tool name is required.");
63
+ const tool = this.readTools().find((candidate) => candidate.name === name.trim());
64
+ if (!tool) throw new Error(`Tool is not in the current allowed catalog: ${name}`);
65
+ return structuredClone({
66
+ name: tool.name,
67
+ description: tool.description,
68
+ parameters: tool.modelParameters ?? tool.parameters
69
+ });
70
+ };
71
+ };
72
+ //#endregion
73
+ export { StructuredResultSubmitTool as a, STRUCTURED_RESULT_TOOL_NAME as i, ToolSchemaTool as n, selectToolModelParameters as r, TOOL_SCHEMA_NAME as t };
74
+
75
+ //# sourceMappingURL=tool-schema.tools-CtZEKWeY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-schema.tools-CtZEKWeY.js","names":[],"sources":["../src/tools/structured-result.tools.ts","../src/tools/tool-schema.tools.ts"],"sourcesContent":["import { validateToolArgs } from \"@nextclaw/ncp-agent-runtime\";\nimport type { NcpTool } from \"@nextclaw/ncp\";\n\nexport const STRUCTURED_RESULT_TOOL_NAME = \"nextclaw_submit_result\";\n\nexport type StructuredResultContract = {\n requestId: string;\n schema: Record<string, unknown>;\n toolName: typeof STRUCTURED_RESULT_TOOL_NAME;\n};\n\nexport class StructuredResultSubmitTool implements NcpTool {\n readonly name = STRUCTURED_RESULT_TOOL_NAME;\n readonly description = \"Submit the structured object result for this request.\";\n\n constructor(private readonly contract: StructuredResultContract) {}\n\n get parameters(): Record<string, unknown> {\n return this.contract.schema;\n }\n\n validateArgs = (args: Record<string, unknown>): string[] =>\n validateToolArgs(args, this.contract.schema);\n\n execute = async (args: Record<string, unknown>): Promise<unknown> => args;\n}\n","import type { NcpTool } from \"@nextclaw/ncp\";\nimport { STRUCTURED_RESULT_TOOL_NAME } from \"./structured-result.tools.js\";\n\nexport const TOOL_SCHEMA_NAME = \"tool_schema\";\nconst EAGER_TOOL_NAMES = new Set([\n TOOL_SCHEMA_NAME, STRUCTURED_RESULT_TOOL_NAME, \"node_repl\",\n \"read_file\", \"write_file\", \"edit_file\", \"list_dir\", \"exec\", \"web_search\", \"web_fetch\", \"view_image\",\n \"memory_search\", \"memory_get\",\n]);\n\n/** Model-facing disclosure only; execution continues to validate the original schema. */\nexport function selectToolModelParameters(tool: NcpTool): NcpTool[\"parameters\"] {\n const parameters = tool.modelParameters ?? tool.parameters;\n return EAGER_TOOL_NAMES.has(tool.name) || !parameters || JSON.stringify(parameters).length <= 160\n ? parameters : { type: \"object\" };\n}\n\nexport class ToolSchemaTool implements NcpTool {\n readonly name = TOOL_SCHEMA_NAME;\n readonly description = \"Read full parameters for an available tool. Before first using a tool whose object schema has no properties field, query its exact name here, then call the original tool with the returned parameter shape.\";\n readonly parameters = {\n type: \"object\",\n properties: { name: { type: \"string\", minLength: 1 } },\n required: [\"name\"],\n additionalProperties: false,\n };\n\n readonly modelParameters?: NcpTool[\"parameters\"];\n readonly validateArgs?: (value: Record<string, unknown>) => string[];\n\n constructor(private readonly readTools: () => readonly NcpTool[], portableValidation = false) {\n if (portableValidation) {\n this.modelParameters = this.parameters;\n this.validateArgs = (value) => typeof value.name === \"string\" && value.name.trim() ? [] : [\"name is required\"];\n }\n }\n\n execute = async (args: unknown): Promise<unknown> => {\n const name = args && typeof args === \"object\" && \"name\" in args ? args.name : null;\n if (typeof name !== \"string\" || !name.trim()) throw new Error(\"Tool name is required.\");\n const tool = this.readTools().find((candidate) => candidate.name === name.trim());\n if (!tool) throw new Error(`Tool is not in the current allowed catalog: ${name}`);\n return structuredClone({ name: tool.name, description: tool.description, parameters: tool.modelParameters ?? tool.parameters });\n };\n}\n"],"mappings":";;AAGA,MAAa,8BAA8B;AAQ3C,IAAa,6BAAb,MAA2D;CACzD,OAAgB;CAChB,cAAuB;CAEvB,YAAY,UAAqD;AAApC,OAAA,WAAA;;CAE7B,IAAI,aAAsC;AACxC,SAAO,KAAK,SAAS;;CAGvB,gBAAgB,SACd,iBAAiB,MAAM,KAAK,SAAS,OAAO;CAE9C,UAAU,OAAO,SAAoD;;;;ACrBvE,MAAa,mBAAmB;AAChC,MAAM,mBAAmB,IAAI,IAAI;CAC/B;CAAkB;CAA6B;CAC/C;CAAa;CAAc;CAAa;CAAY;CAAQ;CAAc;CAAa;CACvF;CAAiB;CAClB,CAAC;;AAGF,SAAgB,0BAA0B,MAAsC;CAC9E,MAAM,aAAa,KAAK,mBAAmB,KAAK;AAChD,QAAO,iBAAiB,IAAI,KAAK,KAAK,IAAI,CAAC,cAAc,KAAK,UAAU,WAAW,CAAC,UAAU,MAC1F,aAAa,EAAE,MAAM,UAAU;;AAGrC,IAAa,iBAAb,MAA+C;CAC7C,OAAgB;CAChB,cAAuB;CACvB,aAAsB;EACpB,MAAM;EACN,YAAY,EAAE,MAAM;GAAE,MAAM;GAAU,WAAW;GAAG,EAAE;EACtD,UAAU,CAAC,OAAO;EAClB,sBAAsB;EACvB;CAED;CACA;CAEA,YAAY,WAAsD,qBAAqB,OAAO;AAAjE,OAAA,YAAA;AAC3B,MAAI,oBAAoB;AACtB,QAAK,kBAAkB,KAAK;AAC5B,QAAK,gBAAgB,UAAU,OAAO,MAAM,SAAS,YAAY,MAAM,KAAK,MAAM,GAAG,EAAE,GAAG,CAAC,mBAAmB;;;CAIlH,UAAU,OAAO,SAAoC;EACnD,MAAM,OAAO,QAAQ,OAAO,SAAS,YAAY,UAAU,OAAO,KAAK,OAAO;AAC9E,MAAI,OAAO,SAAS,YAAY,CAAC,KAAK,MAAM,CAAE,OAAM,IAAI,MAAM,yBAAyB;EACvF,MAAM,OAAO,KAAK,WAAW,CAAC,MAAM,cAAc,UAAU,SAAS,KAAK,MAAM,CAAC;AACjF,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,+CAA+C,OAAO;AACjF,SAAO,gBAAgB;GAAE,MAAM,KAAK;GAAM,aAAa,KAAK;GAAa,YAAY,KAAK,mBAAmB,KAAK;GAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { EventBus } from "@nextclaw/shared";
2
+ import { NcpTool } from "@nextclaw/ncp";
3
+
4
+ //#region src/tools/show-content.tools.d.ts
5
+ type ShowContentEventBus = Pick<EventBus, "emit">;
6
+ type ResolvePanelAppDisplayTarget = (id: string) => Promise<string | undefined>;
7
+ declare function createShowContentTools(eventBus: ShowContentEventBus, resolvePanelAppDisplayTarget?: ResolvePanelAppDisplayTarget, portableValidation?: boolean): readonly NcpTool[];
8
+ //#endregion
9
+ export { createShowContentTools };
10
+ //# sourceMappingURL=show-content.tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-content.tools.d.ts","names":[],"sources":["../../src/tools/show-content.tools.ts"],"mappings":";;;;KAoBK,mBAAA,GAAsB,IAAA,CAAK,QAAA;AAAA,KAC3B,4BAAA,IAAgC,EAAA,aAAe,OAAA;AAAA,iBAsQpC,sBAAA,CACd,QAAA,EAAU,mBAAA,EACV,4BAAA,GAA+B,4BAAA,EAC/B,kBAAA,sBACU,OAAA"}
@@ -0,0 +1,294 @@
1
+ import { createPanelAppResourceUri, eventKeys, readUiContentParams } from "@nextclaw/shared";
2
+ import { isAbsolute } from "node:path";
3
+ import { normalizeToolParams } from "@nextclaw/core/tool-base";
4
+ //#region src/tools/show-content.tools.ts
5
+ const FILE_PURPOSES = [
6
+ "read",
7
+ "preview",
8
+ "edit"
9
+ ];
10
+ const URL_PURPOSES = ["read", "preview"];
11
+ const PANEL_APP_PURPOSES = ["preview", "interact"];
12
+ const FILE_VIEWERS = [
13
+ "auto",
14
+ "source",
15
+ "rendered"
16
+ ];
17
+ function readRequiredString(value, key) {
18
+ if (typeof value !== "string" || value.trim().length === 0) throw new Error(`${key} must be a non-empty string.`);
19
+ return value.trim();
20
+ }
21
+ function readOptionalString(value) {
22
+ if (typeof value !== "string") return;
23
+ return value.trim() || void 0;
24
+ }
25
+ function readOptionalPositiveInteger(value, key) {
26
+ if (typeof value === "undefined") return;
27
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1) throw new Error(`${key} must be a positive integer.`);
28
+ return value;
29
+ }
30
+ function readOptionalEnum(value, key, allowed) {
31
+ const normalized = readOptionalString(value);
32
+ if (!normalized) return;
33
+ if (allowed.includes(normalized)) return normalized;
34
+ const expected = allowed.map((item) => `"${item}"`).join(", ");
35
+ throw new Error(`${key} must be ${expected}.`);
36
+ }
37
+ function readUrl(value) {
38
+ const url = readRequiredString(value, "url");
39
+ let parsed;
40
+ try {
41
+ parsed = new URL(url);
42
+ } catch {
43
+ throw new Error("url must be a valid URL.");
44
+ }
45
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("url must use http or https.");
46
+ return parsed.toString();
47
+ }
48
+ function readCommonRequestFields(params, allowedPurposes) {
49
+ return {
50
+ title: readOptionalString(params.title),
51
+ purpose: readOptionalEnum(params.purpose, "purpose", allowedPurposes)
52
+ };
53
+ }
54
+ function normalizeShowFileArgs(args) {
55
+ const params = normalizeToolParams(args);
56
+ const path = readRequiredString(params.path, "path");
57
+ const viewer = readOptionalEnum(params.viewer, "viewer", FILE_VIEWERS) ?? "auto";
58
+ const contentParams = readUiContentParams(params.params);
59
+ if (contentParams && (viewer === "source" || !/\.html?$/i.test(path))) throw new Error("params are supported only for rendered HTML file previews.");
60
+ return {
61
+ target: {
62
+ type: "file",
63
+ payload: {
64
+ path,
65
+ line: readOptionalPositiveInteger(params.line, "line"),
66
+ column: readOptionalPositiveInteger(params.column, "column"),
67
+ viewer,
68
+ params: contentParams
69
+ }
70
+ },
71
+ ...readCommonRequestFields(params, FILE_PURPOSES)
72
+ };
73
+ }
74
+ function normalizeShowUrlArgs(args) {
75
+ const params = normalizeToolParams(args);
76
+ return {
77
+ target: {
78
+ type: "url",
79
+ payload: { url: readUrl(params.url) }
80
+ },
81
+ ...readCommonRequestFields(params, URL_PURPOSES)
82
+ };
83
+ }
84
+ function normalizeShowPanelAppArgs(args) {
85
+ const params = normalizeToolParams(args);
86
+ const path = readOptionalString(params.path);
87
+ const contentParams = readUiContentParams(params.params);
88
+ if (path && !isAbsolute(path)) throw new Error("path must be an absolute path.");
89
+ return {
90
+ target: {
91
+ type: "panel_app",
92
+ payload: {
93
+ appId: readRequiredString(params.appId, "appId"),
94
+ path,
95
+ params: contentParams
96
+ }
97
+ },
98
+ ...readCommonRequestFields(params, PANEL_APP_PURPOSES)
99
+ };
100
+ }
101
+ function summarizeTarget(target) {
102
+ if (target.type === "file") return target.payload.path;
103
+ if (target.type === "url") return target.payload.url;
104
+ return target.payload.appId;
105
+ }
106
+ function createShowContentEventPayload(request, context) {
107
+ const toolCallId = readOptionalString(context?.toolCallId);
108
+ return {
109
+ id: toolCallId ? `tool:${toolCallId}:show-content` : `show-content:${request.target.type}:${summarizeTarget(request.target)}`,
110
+ toolCallId,
111
+ target: request.target,
112
+ title: request.title,
113
+ purpose: request.purpose,
114
+ placement: "side_panel"
115
+ };
116
+ }
117
+ var ShowContentDisplayTool = class {
118
+ constructor(eventBus, spec, resolvePanelAppDisplayTarget) {
119
+ this.eventBus = eventBus;
120
+ this.spec = spec;
121
+ this.resolvePanelAppDisplayTarget = resolvePanelAppDisplayTarget;
122
+ }
123
+ get name() {
124
+ return this.spec.name;
125
+ }
126
+ get description() {
127
+ return this.spec.description;
128
+ }
129
+ get parameters() {
130
+ return this.spec.parameters;
131
+ }
132
+ execute = async (args, context) => {
133
+ let request = this.spec.normalize(args);
134
+ if (request.target.type === "panel_app" && !request.target.payload.path && this.resolvePanelAppDisplayTarget) {
135
+ const appId = await this.resolvePanelAppDisplayTarget(request.target.payload.appId);
136
+ if (!appId) return {
137
+ ok: false,
138
+ error: {
139
+ code: "PANEL_APP_NOT_FOUND",
140
+ message: "panel app not found"
141
+ }
142
+ };
143
+ request = {
144
+ ...request,
145
+ target: {
146
+ ...request.target,
147
+ payload: {
148
+ ...request.target.payload,
149
+ appId
150
+ }
151
+ }
152
+ };
153
+ }
154
+ this.eventBus.emit(eventKeys.uiShowContent, createShowContentEventPayload(request, context), { source: "kernel" });
155
+ const resourceUri = request.target.type === "panel_app" ? createPanelAppResourceUri(request.target.payload.appId, request.target.payload.path) : void 0;
156
+ return {
157
+ ok: true,
158
+ action: "showContent",
159
+ request,
160
+ ...resourceUri ? { resourceUri } : {}
161
+ };
162
+ };
163
+ };
164
+ const SHOW_CONTENT_TOOL_SPECS = [
165
+ {
166
+ name: "show_file",
167
+ description: "Show a local file in the current chat UI. The automatic viewer displays images (including SVG), PDF, media, and supported documents, while text remains source. Use viewer=\"rendered\" for HTML/page previews or viewer=\"source\" to force source text.",
168
+ parameters: {
169
+ type: "object",
170
+ properties: {
171
+ path: {
172
+ type: "string",
173
+ description: "Local file path to show."
174
+ },
175
+ title: {
176
+ type: "string",
177
+ description: "Optional title for the shown content."
178
+ },
179
+ purpose: {
180
+ type: "string",
181
+ enum: FILE_PURPOSES,
182
+ description: "Optional user intent."
183
+ },
184
+ line: {
185
+ type: "integer",
186
+ minimum: 1,
187
+ description: "Optional 1-based line number."
188
+ },
189
+ column: {
190
+ type: "integer",
191
+ minimum: 1,
192
+ description: "Optional 1-based column number."
193
+ },
194
+ viewer: {
195
+ type: "string",
196
+ enum: FILE_VIEWERS,
197
+ description: "Optional file viewer mode."
198
+ },
199
+ params: {
200
+ type: "object",
201
+ description: "Optional JSON object exposed as window.nextclaw.params for rendered HTML."
202
+ }
203
+ },
204
+ required: ["path"],
205
+ additionalProperties: false
206
+ },
207
+ normalize: normalizeShowFileArgs
208
+ },
209
+ {
210
+ name: "show_url",
211
+ description: "Show an http or https URL in the current chat UI browser. Use this for local development servers such as Vite, Next.js, Storybook, or any running web app URL.",
212
+ parameters: {
213
+ type: "object",
214
+ properties: {
215
+ url: {
216
+ type: "string",
217
+ description: "HTTP or HTTPS URL to show."
218
+ },
219
+ title: {
220
+ type: "string",
221
+ description: "Optional title for the shown content."
222
+ },
223
+ purpose: {
224
+ type: "string",
225
+ enum: URL_PURPOSES,
226
+ description: "Optional user intent."
227
+ }
228
+ },
229
+ required: ["url"],
230
+ additionalProperties: false
231
+ },
232
+ normalize: normalizeShowUrlArgs
233
+ },
234
+ {
235
+ name: "show_panel_app",
236
+ description: "Open a Panel App in the current chat UI as an immediate tool-driven preview. This tool is side-panel only. The result resourceUri is a NextClaw Resource Protocol URI usable in an ordinary Markdown link; linking alone needs no tool call. For inline Panel App display in a final reply, do not call this tool; output a Markdown nextclaw-inline fenced JSON block instead.",
237
+ parameters: {
238
+ type: "object",
239
+ properties: {
240
+ appId: {
241
+ type: "string",
242
+ description: "Installed App id or Panel component id to show. An App id opens its primary Panel."
243
+ },
244
+ path: {
245
+ type: "string",
246
+ description: "Optional absolute path to a .panel.html file or .panel directory outside the standard panels directory."
247
+ },
248
+ params: {
249
+ type: "object",
250
+ description: "Optional JSON object exposed synchronously as window.nextclaw.params."
251
+ },
252
+ title: {
253
+ type: "string",
254
+ description: "Optional title for the shown content."
255
+ },
256
+ purpose: {
257
+ type: "string",
258
+ enum: PANEL_APP_PURPOSES,
259
+ description: "Optional user intent."
260
+ }
261
+ },
262
+ required: ["appId"],
263
+ additionalProperties: false
264
+ },
265
+ normalize: normalizeShowPanelAppArgs
266
+ }
267
+ ];
268
+ function createShowContentTools(eventBus, resolvePanelAppDisplayTarget, portableValidation = false) {
269
+ return SHOW_CONTENT_TOOL_SPECS.map((spec) => {
270
+ const tool = new ShowContentDisplayTool(eventBus, spec, resolvePanelAppDisplayTarget);
271
+ if (!portableValidation) return tool;
272
+ return {
273
+ name: tool.name,
274
+ description: tool.description,
275
+ modelParameters: spec.parameters,
276
+ validateArgs: (args) => {
277
+ const properties = spec.parameters?.properties ?? {};
278
+ const unknown = Object.keys(args).filter((key) => !(key in properties));
279
+ if (unknown.length > 0) return unknown.map((key) => `${key} is not allowed`);
280
+ try {
281
+ spec.normalize(args);
282
+ return [];
283
+ } catch (error) {
284
+ return [error instanceof Error ? error.message : String(error)];
285
+ }
286
+ },
287
+ execute: tool.execute
288
+ };
289
+ });
290
+ }
291
+ //#endregion
292
+ export { createShowContentTools };
293
+
294
+ //# sourceMappingURL=show-content.tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"show-content.tools.js","names":[],"sources":["../../src/tools/show-content.tools.ts"],"sourcesContent":["import { isAbsolute } from \"node:path\";\nimport { normalizeToolParams, type ToolExecutionContext } from \"@nextclaw/core/tool-base\";\nimport type { NcpTool } from \"@nextclaw/ncp\";\nimport {\n createPanelAppResourceUri,\n eventKeys,\n readUiContentParams,\n type EventBus,\n type UiShowContentEventPayload,\n type UiShowContentFileViewer,\n type UiShowContentPurpose,\n type UiShowContentTarget,\n} from \"@nextclaw/shared\";\n\ntype ShowContentRequest = {\n target: UiShowContentTarget;\n title: string | undefined;\n purpose: UiShowContentPurpose | undefined;\n};\n\ntype ShowContentEventBus = Pick<EventBus, \"emit\">;\ntype ResolvePanelAppDisplayTarget = (id: string) => Promise<string | undefined>;\ntype ShowContentToolSpec = {\n name: string;\n description: string;\n parameters: NcpTool[\"parameters\"];\n normalize: (args: unknown) => ShowContentRequest;\n};\n\nconst FILE_PURPOSES: readonly UiShowContentPurpose[] = [\"read\", \"preview\", \"edit\"];\nconst URL_PURPOSES: readonly UiShowContentPurpose[] = [\"read\", \"preview\"];\nconst PANEL_APP_PURPOSES: readonly UiShowContentPurpose[] = [\"preview\", \"interact\"];\nconst FILE_VIEWERS: readonly UiShowContentFileViewer[] = [\"auto\", \"source\", \"rendered\"];\n\nfunction readRequiredString(value: unknown, key: string): string {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new Error(`${key} must be a non-empty string.`);\n }\n return value.trim();\n}\n\nfunction readOptionalString(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n return value.trim() || undefined;\n}\n\nfunction readOptionalPositiveInteger(value: unknown, key: string): number | undefined {\n if (typeof value === \"undefined\") {\n return undefined;\n }\n if (typeof value !== \"number\" || !Number.isInteger(value) || value < 1) {\n throw new Error(`${key} must be a positive integer.`);\n }\n return value;\n}\n\nfunction readOptionalEnum<T extends string>(\n value: unknown,\n key: string,\n allowed: readonly T[],\n): T | undefined {\n const normalized = readOptionalString(value);\n if (!normalized) {\n return undefined;\n }\n if ((allowed as readonly string[]).includes(normalized)) {\n return normalized as T;\n }\n const expected = allowed.map((item) => `\"${item}\"`).join(\", \");\n throw new Error(`${key} must be ${expected}.`);\n}\n\nfunction readUrl(value: unknown): string {\n const url = readRequiredString(value, \"url\");\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw new Error(\"url must be a valid URL.\");\n }\n if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n throw new Error(\"url must use http or https.\");\n }\n return parsed.toString();\n}\n\nfunction readCommonRequestFields(\n params: Record<string, unknown>,\n allowedPurposes: readonly UiShowContentPurpose[],\n): Pick<ShowContentRequest, \"title\" | \"purpose\"> {\n return {\n title: readOptionalString(params.title),\n purpose: readOptionalEnum(params.purpose, \"purpose\", allowedPurposes),\n };\n}\n\nfunction normalizeShowFileArgs(args: unknown): ShowContentRequest {\n const params = normalizeToolParams(args);\n const path = readRequiredString(params.path, \"path\");\n const viewer = readOptionalEnum(params.viewer, \"viewer\", FILE_VIEWERS) ?? \"auto\";\n const contentParams = readUiContentParams(params.params);\n if (contentParams && (viewer === \"source\" || !/\\.html?$/i.test(path))) {\n throw new Error(\"params are supported only for rendered HTML file previews.\");\n }\n return {\n target: {\n type: \"file\",\n payload: {\n path,\n line: readOptionalPositiveInteger(params.line, \"line\"),\n column: readOptionalPositiveInteger(params.column, \"column\"),\n viewer,\n params: contentParams,\n },\n },\n ...readCommonRequestFields(params, FILE_PURPOSES),\n };\n}\n\nfunction normalizeShowUrlArgs(args: unknown): ShowContentRequest {\n const params = normalizeToolParams(args);\n return {\n target: {\n type: \"url\",\n payload: {\n url: readUrl(params.url),\n },\n },\n ...readCommonRequestFields(params, URL_PURPOSES),\n };\n}\n\nfunction normalizeShowPanelAppArgs(args: unknown): ShowContentRequest {\n const params = normalizeToolParams(args);\n const path = readOptionalString(params.path);\n const contentParams = readUiContentParams(params.params);\n if (path && !isAbsolute(path)) {\n throw new Error(\"path must be an absolute path.\");\n }\n return {\n target: {\n type: \"panel_app\",\n payload: {\n appId: readRequiredString(params.appId, \"appId\"),\n path,\n params: contentParams,\n },\n },\n ...readCommonRequestFields(params, PANEL_APP_PURPOSES),\n };\n}\n\nfunction summarizeTarget(target: UiShowContentTarget): string {\n if (target.type === \"file\") {\n return target.payload.path;\n }\n if (target.type === \"url\") {\n return target.payload.url;\n }\n return target.payload.appId;\n}\n\nfunction createShowContentEventPayload(\n request: ShowContentRequest,\n context: ToolExecutionContext | undefined,\n): UiShowContentEventPayload {\n const toolCallId = readOptionalString(context?.toolCallId);\n return {\n id: toolCallId\n ? `tool:${toolCallId}:show-content`\n : `show-content:${request.target.type}:${summarizeTarget(request.target)}`,\n toolCallId,\n target: request.target,\n title: request.title,\n purpose: request.purpose,\n placement: \"side_panel\",\n };\n}\n\nclass ShowContentDisplayTool implements NcpTool {\n constructor(\n private readonly eventBus: ShowContentEventBus,\n private readonly spec: ShowContentToolSpec,\n private readonly resolvePanelAppDisplayTarget?: ResolvePanelAppDisplayTarget,\n ) {}\n\n get name(): string { return this.spec.name; }\n get description(): string { return this.spec.description; }\n get parameters(): NcpTool[\"parameters\"] { return this.spec.parameters; }\n\n execute = async (args: unknown, context?: ToolExecutionContext): Promise<unknown> => {\n let request = this.spec.normalize(args);\n if (\n request.target.type === \"panel_app\" &&\n !request.target.payload.path &&\n this.resolvePanelAppDisplayTarget\n ) {\n const appId = await this.resolvePanelAppDisplayTarget(request.target.payload.appId);\n if (!appId) {\n return {\n ok: false,\n error: {\n code: \"PANEL_APP_NOT_FOUND\",\n message: \"panel app not found\",\n },\n };\n }\n request = {\n ...request,\n target: {\n ...request.target,\n payload: { ...request.target.payload, appId },\n },\n };\n }\n this.eventBus.emit(\n eventKeys.uiShowContent,\n createShowContentEventPayload(request, context),\n { source: \"kernel\" },\n );\n const resourceUri = request.target.type === \"panel_app\"\n ? createPanelAppResourceUri(request.target.payload.appId, request.target.payload.path)\n : undefined;\n return { ok: true, action: \"showContent\", request, ...(resourceUri ? { resourceUri } : {}) };\n };\n}\n\nconst SHOW_CONTENT_TOOL_SPECS: readonly ShowContentToolSpec[] = [\n {\n name: \"show_file\",\n description: 'Show a local file in the current chat UI. The automatic viewer displays images (including SVG), PDF, media, and supported documents, while text remains source. Use viewer=\"rendered\" for HTML/page previews or viewer=\"source\" to force source text.',\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Local file path to show.\" },\n title: { type: \"string\", description: \"Optional title for the shown content.\" },\n purpose: { type: \"string\", enum: FILE_PURPOSES, description: \"Optional user intent.\" },\n line: { type: \"integer\", minimum: 1, description: \"Optional 1-based line number.\" },\n column: { type: \"integer\", minimum: 1, description: \"Optional 1-based column number.\" },\n viewer: { type: \"string\", enum: FILE_VIEWERS, description: \"Optional file viewer mode.\" },\n params: { type: \"object\", description: \"Optional JSON object exposed as window.nextclaw.params for rendered HTML.\" },\n },\n required: [\"path\"],\n additionalProperties: false,\n },\n normalize: normalizeShowFileArgs,\n },\n {\n name: \"show_url\",\n description: \"Show an http or https URL in the current chat UI browser. Use this for local development servers such as Vite, Next.js, Storybook, or any running web app URL.\",\n parameters: {\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"HTTP or HTTPS URL to show.\" },\n title: { type: \"string\", description: \"Optional title for the shown content.\" },\n purpose: { type: \"string\", enum: URL_PURPOSES, description: \"Optional user intent.\" },\n },\n required: [\"url\"],\n additionalProperties: false,\n },\n normalize: normalizeShowUrlArgs,\n },\n {\n name: \"show_panel_app\",\n description: 'Open a Panel App in the current chat UI as an immediate tool-driven preview. This tool is side-panel only. The result resourceUri is a NextClaw Resource Protocol URI usable in an ordinary Markdown link; linking alone needs no tool call. For inline Panel App display in a final reply, do not call this tool; output a Markdown nextclaw-inline fenced JSON block instead.',\n parameters: {\n type: \"object\",\n properties: {\n appId: { type: \"string\", description: \"Installed App id or Panel component id to show. An App id opens its primary Panel.\" },\n path: { type: \"string\", description: \"Optional absolute path to a .panel.html file or .panel directory outside the standard panels directory.\" },\n params: { type: \"object\", description: \"Optional JSON object exposed synchronously as window.nextclaw.params.\" },\n title: { type: \"string\", description: \"Optional title for the shown content.\" },\n purpose: { type: \"string\", enum: PANEL_APP_PURPOSES, description: \"Optional user intent.\" },\n },\n required: [\"appId\"],\n additionalProperties: false,\n },\n normalize: normalizeShowPanelAppArgs,\n },\n];\n\nexport function createShowContentTools(\n eventBus: ShowContentEventBus,\n resolvePanelAppDisplayTarget?: ResolvePanelAppDisplayTarget,\n portableValidation = false,\n): readonly NcpTool[] {\n return SHOW_CONTENT_TOOL_SPECS.map(\n (spec) => {\n const tool = new ShowContentDisplayTool(eventBus, spec, resolvePanelAppDisplayTarget);\n if (!portableValidation) return tool;\n return {\n name: tool.name,\n description: tool.description,\n modelParameters: spec.parameters,\n validateArgs: (args: Record<string, unknown>) => {\n const properties = (spec.parameters as { properties?: Record<string, unknown> })?.properties ?? {};\n const unknown = Object.keys(args).filter((key) => !(key in properties));\n if (unknown.length > 0) return unknown.map((key) => `${key} is not allowed`);\n try { spec.normalize(args); return []; }\n catch (error) { return [error instanceof Error ? error.message : String(error)]; }\n },\n execute: tool.execute,\n } satisfies NcpTool;\n },\n );\n}\n"],"mappings":";;;;AA6BA,MAAM,gBAAiD;CAAC;CAAQ;CAAW;CAAO;AAClF,MAAM,eAAgD,CAAC,QAAQ,UAAU;AACzE,MAAM,qBAAsD,CAAC,WAAW,WAAW;AACnF,MAAM,eAAmD;CAAC;CAAQ;CAAU;CAAW;AAEvF,SAAS,mBAAmB,OAAgB,KAAqB;AAC/D,KAAI,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,WAAW,EACvD,OAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAEvD,QAAO,MAAM,MAAM;;AAGrB,SAAS,mBAAmB,OAAoC;AAC9D,KAAI,OAAO,UAAU,SACnB;AAEF,QAAO,MAAM,MAAM,IAAI,KAAA;;AAGzB,SAAS,4BAA4B,OAAgB,KAAiC;AACpF,KAAI,OAAO,UAAU,YACnB;AAEF,KAAI,OAAO,UAAU,YAAY,CAAC,OAAO,UAAU,MAAM,IAAI,QAAQ,EACnE,OAAM,IAAI,MAAM,GAAG,IAAI,8BAA8B;AAEvD,QAAO;;AAGT,SAAS,iBACP,OACA,KACA,SACe;CACf,MAAM,aAAa,mBAAmB,MAAM;AAC5C,KAAI,CAAC,WACH;AAEF,KAAK,QAA8B,SAAS,WAAW,CACrD,QAAO;CAET,MAAM,WAAW,QAAQ,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC,KAAK,KAAK;AAC9D,OAAM,IAAI,MAAM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KAAU,aAAa;KAAsF;IAC5H,MAAM;KAAE,MAAM;KAAU,aAAa;KAA2G;IAChJ,QAAQ;KAAE,MAAM;KAAU,aAAa;KAAyE;IAChH,OAAO;KAAE,MAAM;KAAU,aAAa;KAAyC;IAC/E,SAAS;KAAE,MAAM;KAAU,MAAM;KAAoB,aAAa;KAAyB;IAC5F;GACD,UAAU,CAAC,QAAQ;GACnB,sBAAsB;GACvB;EACD,WAAW;EACZ;CACF;AAED,SAAgB,uBACd,UACA,8BACA,qBAAqB,OACD;AACpB,QAAO,wBAAwB,KAC5B,SAAS;EACR,MAAM,OAAO,IAAI,uBAAuB,UAAU,MAAM,6BAA6B;AACrF,MAAI,CAAC,mBAAoB,QAAO;AAChC,SAAO;GACL,MAAM,KAAK;GACX,aAAa,KAAK;GAClB,iBAAiB,KAAK;GACtB,eAAe,SAAkC;IAC/C,MAAM,aAAc,KAAK,YAAyD,cAAc,EAAE;IAClG,MAAM,UAAU,OAAO,KAAK,KAAK,CAAC,QAAQ,QAAQ,EAAE,OAAO,YAAY;AACvE,QAAI,QAAQ,SAAS,EAAG,QAAO,QAAQ,KAAK,QAAQ,GAAG,IAAI,iBAAiB;AAC5E,QAAI;AAAE,UAAK,UAAU,KAAK;AAAE,YAAO,EAAE;aAC9B,OAAO;AAAE,YAAO,CAAC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,CAAC;;;GAEjF,SAAS,KAAK;GACf;GAEJ"}
@@ -0,0 +1,29 @@
1
+ import { NcpTool } from "@nextclaw/ncp";
2
+
3
+ //#region src/tools/tool-schema.tools.d.ts
4
+ declare const TOOL_SCHEMA_NAME = "tool_schema";
5
+ /** Model-facing disclosure only; execution continues to validate the original schema. */
6
+ declare function selectToolModelParameters(tool: NcpTool): NcpTool["parameters"];
7
+ declare class ToolSchemaTool implements NcpTool {
8
+ private readonly readTools;
9
+ readonly name = "tool_schema";
10
+ readonly description = "Read full parameters for an available tool. Before first using a tool whose object schema has no properties field, query its exact name here, then call the original tool with the returned parameter shape.";
11
+ readonly parameters: {
12
+ type: string;
13
+ properties: {
14
+ name: {
15
+ type: string;
16
+ minLength: number;
17
+ };
18
+ };
19
+ required: string[];
20
+ additionalProperties: boolean;
21
+ };
22
+ readonly modelParameters?: NcpTool["parameters"];
23
+ readonly validateArgs?: (value: Record<string, unknown>) => string[];
24
+ constructor(readTools: () => readonly NcpTool[], portableValidation?: boolean);
25
+ execute: (args: unknown) => Promise<unknown>;
26
+ }
27
+ //#endregion
28
+ export { TOOL_SCHEMA_NAME, ToolSchemaTool, selectToolModelParameters };
29
+ //# sourceMappingURL=tool-schema.tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-schema.tools.d.ts","names":[],"sources":["../../src/tools/tool-schema.tools.ts"],"mappings":";;;cAGa,gBAAA;;iBAQG,yBAAA,CAA0B,IAAA,EAAM,OAAA,GAAU,OAAA;AAAA,cAM7C,cAAA,YAA0B,OAAA;EAAA,iBAaR,SAAA;EAAA,SAZpB,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;;;;;;;;;;;WAOA,eAAA,GAAkB,OAAA;EAAA,SAClB,YAAA,IAAgB,KAAA,EAAO,MAAA;cAEH,SAAA,iBAA0B,OAAA,IAAW,kBAAA;EAOlE,OAAA,GAAiB,IAAA,cAAgB,OAAA;AAAA"}
@@ -0,0 +1,2 @@
1
+ import { n as ToolSchemaTool, r as selectToolModelParameters, t as TOOL_SCHEMA_NAME } from "../tool-schema.tools-CtZEKWeY.js";
2
+ export { TOOL_SCHEMA_NAME, ToolSchemaTool, selectToolModelParameters };