@nextclaw/kernel 0.19.2-beta.0 → 0.19.2-beta.1
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/app/worker/index.d.ts +4 -0
- package/dist/app/worker/index.js +3 -0
- package/dist/automatic-update-check.utils-C6lQfErN.d.ts +11 -0
- package/dist/automatic-update-check.utils-C6lQfErN.d.ts.map +1 -0
- package/dist/index.d.ts +4 -4339
- package/dist/index.js +12555 -18773
- package/dist/index.js.map +1 -1
- package/dist/nextclaw-harness.manager-7URpTz3z.js +9030 -0
- package/dist/nextclaw-harness.manager-7URpTz3z.js.map +1 -0
- package/dist/nextclaw-harness.manager-Df5Zagn_.d.ts +6001 -0
- package/dist/nextclaw-harness.manager-Df5Zagn_.d.ts.map +1 -0
- package/dist/types/update-contract.types.d.ts +1 -1
- package/dist/types/update-contract.types.js +1 -1
- package/dist/{update-manifest.types-eSil_QH0.js → update-manifest.types-CBp2VTM1.js} +1 -1
- package/dist/{update-manifest.types-eSil_QH0.js.map → update-manifest.types-CBp2VTM1.js.map} +1 -1
- package/dist/{update-manifest.types-Dl4B87Pa.d.ts → update-manifest.types-C_60CVvw.d.ts} +1 -1
- package/dist/{update-manifest.types-Dl4B87Pa.d.ts.map → update-manifest.types-C_60CVvw.d.ts.map} +1 -1
- package/dist/utils/automatic-update-check.utils.d.ts +2 -11
- package/package.json +17 -57
- package/dist/agent-model-input-budget.utils-tw9zs9WM.js +0 -26
- package/dist/agent-model-input-budget.utils-tw9zs9WM.js.map +0 -1
- package/dist/agent-run-context-compaction.manager-BV6tB0wL.d.ts +0 -28
- package/dist/agent-run-context-compaction.manager-BV6tB0wL.d.ts.map +0 -1
- package/dist/agent-run-model-input-builder.service-C3ydUx3d.js +0 -320
- package/dist/agent-run-model-input-builder.service-C3ydUx3d.js.map +0 -1
- package/dist/agent-run.types-CNVBBJnd.d.ts +0 -71
- package/dist/agent-run.types-CNVBBJnd.d.ts.map +0 -1
- package/dist/context-compaction-preflight.service-ClJEGWKS.d.ts +0 -97
- package/dist/context-compaction-preflight.service-ClJEGWKS.d.ts.map +0 -1
- package/dist/context-compaction-preflight.service-K0tE34Oz.js +0 -689
- package/dist/context-compaction-preflight.service-K0tE34Oz.js.map +0 -1
- package/dist/context-compaction.utils-Csf80mdq.d.ts +0 -42
- package/dist/context-compaction.utils-Csf80mdq.d.ts.map +0 -1
- package/dist/features/context-compaction/services/context-compaction-preflight.service.d.ts +0 -2
- package/dist/features/context-compaction/services/context-compaction-preflight.service.js +0 -2
- package/dist/features/context-compaction/utils/context-compaction.utils.d.ts +0 -2
- package/dist/features/context-compaction/utils/context-compaction.utils.js +0 -202
- package/dist/features/context-compaction/utils/context-compaction.utils.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/managers/agent-run-context-compaction.manager.d.ts +0 -2
- package/dist/managers/agent-run-context-compaction.manager.js +0 -68
- package/dist/managers/agent-run-context-compaction.manager.js.map +0 -1
- package/dist/request-context-tail.manager-DXC4rdAP.d.ts +0 -22
- package/dist/request-context-tail.manager-DXC4rdAP.d.ts.map +0 -1
- package/dist/services/agent-run-model-input-builder.service.d.ts +0 -58
- package/dist/services/agent-run-model-input-builder.service.d.ts.map +0 -1
- package/dist/services/agent-run-model-input-builder.service.js +0 -2
- package/dist/tool-schema.tools-CtZEKWeY.js +0 -75
- package/dist/tool-schema.tools-CtZEKWeY.js.map +0 -1
- package/dist/tools/show-content.tools.d.ts +0 -10
- package/dist/tools/show-content.tools.d.ts.map +0 -1
- package/dist/tools/show-content.tools.js +0 -294
- package/dist/tools/show-content.tools.js.map +0 -1
- package/dist/tools/tool-schema.tools.d.ts +0 -29
- package/dist/tools/tool-schema.tools.d.ts.map +0 -1
- package/dist/tools/tool-schema.tools.js +0 -2
- package/dist/tools/user-question.tools.d.ts +0 -63
- package/dist/tools/user-question.tools.d.ts.map +0 -1
- package/dist/tools/user-question.tools.js +0 -77
- package/dist/tools/user-question.tools.js.map +0 -1
- package/dist/user-question.manager-38KBgZCg.d.ts +0 -1038
- package/dist/user-question.manager-38KBgZCg.d.ts.map +0 -1
- package/dist/user-question.utils-DWVtPv4S.d.ts +0 -27
- package/dist/user-question.utils-DWVtPv4S.d.ts.map +0 -1
- package/dist/utils/agent-onboarding-context.utils.d.ts +0 -6
- package/dist/utils/agent-onboarding-context.utils.d.ts.map +0 -1
- package/dist/utils/agent-onboarding-context.utils.js +0 -39
- package/dist/utils/agent-onboarding-context.utils.js.map +0 -1
- package/dist/utils/automatic-update-check.utils.d.ts.map +0 -1
- package/dist/utils/user-question.utils.d.ts +0 -2
- package/dist/utils/user-question.utils.js +0 -105
- package/dist/utils/user-question.utils.js.map +0 -1
|
@@ -1,294 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAG,IAAI,WAAW,SAAS,GAAG;;AAGhD,SAAS,QAAQ,OAAwB;CACvC,MAAM,MAAM,mBAAmB,OAAO,MAAM;CAC5C,IAAI;AACJ,K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O;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"}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { n as UserQuestionManager } from "../user-question.manager-38KBgZCg.js";
|
|
2
|
-
import { n as UserQuestionPrompt } from "../user-question.utils-DWVtPv4S.js";
|
|
3
|
-
import { NcpTool } from "@nextclaw/ncp";
|
|
4
|
-
|
|
5
|
-
//#region src/tools/user-question.tools.d.ts
|
|
6
|
-
declare class RequestUserInputAsyncTool implements NcpTool {
|
|
7
|
-
private readonly questions;
|
|
8
|
-
private readonly sessionId;
|
|
9
|
-
readonly name = "request_user_input_async";
|
|
10
|
-
readonly description = "Ask the user one to three self-contained questions without pausing this run. Prefer short suggested options when there are clear choices; the user can always enter a custom answer. With suggested options, normally choose one sensible default and set recommendedOption to its exact label; omit it only when recommending a choice would mislead the user. Never append '(recommended)' to an option label. Add optionDescriptions only where a brief explanation helps the user understand a choice or tradeoff. Use a separate question for each decision. The call returns after the questions are saved; continue independent work while waiting. An answer arrives later as user input in this session. Do not treat accepted as an answer or approval.";
|
|
11
|
-
readonly parameters: {
|
|
12
|
-
type: string;
|
|
13
|
-
properties: {
|
|
14
|
-
questions: {
|
|
15
|
-
type: string;
|
|
16
|
-
minItems: number;
|
|
17
|
-
maxItems: number;
|
|
18
|
-
items: {
|
|
19
|
-
type: string;
|
|
20
|
-
properties: {
|
|
21
|
-
title: {
|
|
22
|
-
type: string;
|
|
23
|
-
description: string;
|
|
24
|
-
};
|
|
25
|
-
options: {
|
|
26
|
-
type: string;
|
|
27
|
-
items: {
|
|
28
|
-
type: string;
|
|
29
|
-
};
|
|
30
|
-
description: string;
|
|
31
|
-
};
|
|
32
|
-
recommendedOption: {
|
|
33
|
-
type: string;
|
|
34
|
-
description: string;
|
|
35
|
-
};
|
|
36
|
-
optionDescriptions: {
|
|
37
|
-
type: string;
|
|
38
|
-
additionalProperties: {
|
|
39
|
-
type: string;
|
|
40
|
-
};
|
|
41
|
-
description: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
required: string[];
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
required: string[];
|
|
49
|
-
};
|
|
50
|
-
constructor(questions: Pick<UserQuestionManager, "ask">, sessionId: string);
|
|
51
|
-
execute: (args: unknown) => Promise<{
|
|
52
|
-
accepted: true;
|
|
53
|
-
questionIds: string[];
|
|
54
|
-
}>;
|
|
55
|
-
}
|
|
56
|
-
/** Host-neutral form of the same question tool for runtimes without Node schema compilation. */
|
|
57
|
-
declare function createPortableRequestUserInputAsyncTool(ask: (prompts: readonly UserQuestionPrompt[]) => Promise<{
|
|
58
|
-
accepted: true;
|
|
59
|
-
questionIds: string[];
|
|
60
|
-
}>): NcpTool;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { RequestUserInputAsyncTool, createPortableRequestUserInputAsyncTool };
|
|
63
|
-
//# sourceMappingURL=user-question.tools.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-question.tools.d.ts","names":[],"sources":["../../src/tools/user-question.tools.ts"],"mappings":";;;;;cAIa,yBAAA,YAAqC,OAAA;EAAA,iBAiCnB,SAAA;EAAA,iBAA8D,SAAA;EAAA,SAhClF,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BoB,SAAA,EAAW,IAAA,CAAK,mBAAA,UAA8C,SAAA;EAE3F,OAAA,GAAiB,IAAA,cAAgB,OAAA;IAAU,QAAA;IAAgB,WAAA;EAAA;AAAA;;iBA0B7C,uCAAA,CACd,GAAA,GAAM,OAAA,WAAkB,kBAAA,OAAyB,OAAA;EAAU,QAAA;EAAgB,WAAA;AAAA,KAC1E,OAAA"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { normalizeToolParams } from "@nextclaw/core/tool-base";
|
|
2
|
-
//#region src/tools/user-question.tools.ts
|
|
3
|
-
var RequestUserInputAsyncTool = class {
|
|
4
|
-
name = "request_user_input_async";
|
|
5
|
-
description = "Ask the user one to three self-contained questions without pausing this run. Prefer short suggested options when there are clear choices; the user can always enter a custom answer. With suggested options, normally choose one sensible default and set recommendedOption to its exact label; omit it only when recommending a choice would mislead the user. Never append '(recommended)' to an option label. Add optionDescriptions only where a brief explanation helps the user understand a choice or tradeoff. Use a separate question for each decision. The call returns after the questions are saved; continue independent work while waiting. An answer arrives later as user input in this session. Do not treat accepted as an answer or approval.";
|
|
6
|
-
parameters = {
|
|
7
|
-
type: "object",
|
|
8
|
-
properties: { questions: {
|
|
9
|
-
type: "array",
|
|
10
|
-
minItems: 1,
|
|
11
|
-
maxItems: 3,
|
|
12
|
-
items: {
|
|
13
|
-
type: "object",
|
|
14
|
-
properties: {
|
|
15
|
-
title: {
|
|
16
|
-
type: "string",
|
|
17
|
-
description: "A concise, self-contained question for the user."
|
|
18
|
-
},
|
|
19
|
-
options: {
|
|
20
|
-
type: "array",
|
|
21
|
-
items: { type: "string" },
|
|
22
|
-
description: "Optional suggested answers. The user may also write a custom answer."
|
|
23
|
-
},
|
|
24
|
-
recommendedOption: {
|
|
25
|
-
type: "string",
|
|
26
|
-
description: "Recommended default; must exactly match one option label. Usually provide this when options are present."
|
|
27
|
-
},
|
|
28
|
-
optionDescriptions: {
|
|
29
|
-
type: "object",
|
|
30
|
-
additionalProperties: { type: "string" },
|
|
31
|
-
description: "Optional brief explanations keyed by exact option labels. Include only choices that need explanation."
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
required: ["title"]
|
|
35
|
-
}
|
|
36
|
-
} },
|
|
37
|
-
required: ["questions"]
|
|
38
|
-
};
|
|
39
|
-
constructor(questions, sessionId) {
|
|
40
|
-
this.questions = questions;
|
|
41
|
-
this.sessionId = sessionId;
|
|
42
|
-
}
|
|
43
|
-
execute = async (args) => {
|
|
44
|
-
const params = normalizeToolParams(args);
|
|
45
|
-
if (!Array.isArray(params.questions)) throw new Error("questions must be an array.");
|
|
46
|
-
const prompts = params.questions.map((value) => {
|
|
47
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Each question must be an object.");
|
|
48
|
-
const prompt = value;
|
|
49
|
-
if (typeof prompt.title !== "string") throw new Error("Question title must be a string.");
|
|
50
|
-
if (prompt.options !== void 0 && (!Array.isArray(prompt.options) || !prompt.options.every((option) => typeof option === "string"))) throw new Error("Question options must be strings.");
|
|
51
|
-
if (prompt.recommendedOption !== void 0 && typeof prompt.recommendedOption !== "string") throw new Error("Recommended option must be a string.");
|
|
52
|
-
if (prompt.optionDescriptions !== void 0 && (!prompt.optionDescriptions || typeof prompt.optionDescriptions !== "object" || Array.isArray(prompt.optionDescriptions) || Object.values(prompt.optionDescriptions).some((description) => typeof description !== "string"))) throw new Error("Option descriptions must map option labels to strings.");
|
|
53
|
-
return {
|
|
54
|
-
title: prompt.title,
|
|
55
|
-
...prompt.options ? { options: prompt.options } : {},
|
|
56
|
-
...prompt.recommendedOption !== void 0 ? { recommendedOption: prompt.recommendedOption } : {},
|
|
57
|
-
...prompt.optionDescriptions !== void 0 ? { optionDescriptions: prompt.optionDescriptions } : {}
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
return await this.questions.ask(this.sessionId, prompts);
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
/** Host-neutral form of the same question tool for runtimes without Node schema compilation. */
|
|
64
|
-
function createPortableRequestUserInputAsyncTool(ask) {
|
|
65
|
-
const native = new RequestUserInputAsyncTool({ ask: async (_sessionId, prompts) => ask(prompts) }, "");
|
|
66
|
-
return {
|
|
67
|
-
name: native.name,
|
|
68
|
-
description: native.description,
|
|
69
|
-
modelParameters: native.parameters,
|
|
70
|
-
validateArgs: (value) => value && typeof value === "object" && !Array.isArray(value) && Array.isArray(value.questions) ? [] : ["questions must be an array"],
|
|
71
|
-
execute: native.execute
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
export { RequestUserInputAsyncTool, createPortableRequestUserInputAsyncTool };
|
|
76
|
-
|
|
77
|
-
//# sourceMappingURL=user-question.tools.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-question.tools.js","names":[],"sources":["../../src/tools/user-question.tools.ts"],"sourcesContent":["import { normalizeToolParams } from \"@nextclaw/core/tool-base\";\nimport type { NcpTool } from \"@nextclaw/ncp\";\nimport type { UserQuestionManager, UserQuestionPrompt } from \"@kernel/managers/user-question.manager.js\";\n\nexport class RequestUserInputAsyncTool implements NcpTool {\n readonly name = \"request_user_input_async\";\n readonly description = \"Ask the user one to three self-contained questions without pausing this run. Prefer short suggested options when there are clear choices; the user can always enter a custom answer. With suggested options, normally choose one sensible default and set recommendedOption to its exact label; omit it only when recommending a choice would mislead the user. Never append '(recommended)' to an option label. Add optionDescriptions only where a brief explanation helps the user understand a choice or tradeoff. Use a separate question for each decision. The call returns after the questions are saved; continue independent work while waiting. An answer arrives later as user input in this session. Do not treat accepted as an answer or approval.\";\n readonly parameters = {\n type: \"object\",\n properties: {\n questions: {\n type: \"array\",\n minItems: 1,\n maxItems: 3,\n items: {\n type: \"object\",\n properties: {\n title: { type: \"string\", description: \"A concise, self-contained question for the user.\" },\n options: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Optional suggested answers. The user may also write a custom answer.\",\n },\n recommendedOption: { type: \"string\", description: \"Recommended default; must exactly match one option label. Usually provide this when options are present.\" },\n optionDescriptions: {\n type: \"object\",\n additionalProperties: { type: \"string\" },\n description: \"Optional brief explanations keyed by exact option labels. Include only choices that need explanation.\",\n },\n },\n required: [\"title\"],\n },\n },\n },\n required: [\"questions\"],\n };\n\n constructor(private readonly questions: Pick<UserQuestionManager, \"ask\">, private readonly sessionId: string) {}\n\n execute = async (args: unknown): Promise<{ accepted: true; questionIds: string[] }> => {\n const params = normalizeToolParams(args);\n if (!Array.isArray(params.questions)) throw new Error(\"questions must be an array.\");\n const prompts: UserQuestionPrompt[] = params.questions.map((value) => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(\"Each question must be an object.\");\n const prompt = value as Record<string, unknown>;\n if (typeof prompt.title !== \"string\") throw new Error(\"Question title must be a string.\");\n if (prompt.options !== undefined && (!Array.isArray(prompt.options) || !prompt.options.every((option) => typeof option === \"string\"))) {\n throw new Error(\"Question options must be strings.\");\n }\n if (prompt.recommendedOption !== undefined && typeof prompt.recommendedOption !== \"string\") {\n throw new Error(\"Recommended option must be a string.\");\n }\n if (prompt.optionDescriptions !== undefined && (!prompt.optionDescriptions || typeof prompt.optionDescriptions !== \"object\" ||\n Array.isArray(prompt.optionDescriptions) || Object.values(prompt.optionDescriptions).some((description) => typeof description !== \"string\"))) {\n throw new Error(\"Option descriptions must map option labels to strings.\");\n }\n return { title: prompt.title, ...(prompt.options ? { options: prompt.options as string[] } : {}),\n ...(prompt.recommendedOption !== undefined ? { recommendedOption: prompt.recommendedOption } : {}),\n ...(prompt.optionDescriptions !== undefined ? { optionDescriptions: prompt.optionDescriptions as Record<string, string> } : {}) };\n });\n return await this.questions.ask(this.sessionId, prompts);\n };\n}\n\n/** Host-neutral form of the same question tool for runtimes without Node schema compilation. */\nexport function createPortableRequestUserInputAsyncTool(\n ask: (prompts: readonly UserQuestionPrompt[]) => Promise<{ accepted: true; questionIds: string[] }>,\n): NcpTool {\n const native = new RequestUserInputAsyncTool({ ask: async (_sessionId, prompts) => ask(prompts) }, \"\");\n return {\n name: native.name, description: native.description, modelParameters: native.parameters,\n validateArgs: (value) => value && typeof value === \"object\" && !Array.isArray(value) &&\n Array.isArray((value as { questions?: unknown }).questions) ? [] : [\"questions must be an array\"],\n execute: native.execute,\n };\n}\n"],"mappings":";;AAIA,IAAa,4BAAb,MAA0D;CACxD,OAAgB;CAChB,cAAuB;CACvB,aAAsB;EACpB,MAAM;EACN,YAAY,EACV,WAAW;GACT,MAAM;GACN,UAAU;GACV,UAAU;GACV,OAAO;IACL,MAAM;IACN,YAAY;KACV,OAAO;MAAE,MAAM;MAAU,aAAa;MAAoD;KAC1F,SAAS;MACP,MAAM;MACN,OAAO,EAAE,MAAM,UAAU;MACzB,aAAa;MACd;KACD,mBAAmB;MAAE,MAAM;MAAU,aAAa;MAA4G;KAC9J,oBAAoB;MAClB,MAAM;MACN,sBAAsB,EAAE,MAAM,UAAU;MACxC,aAAa;MACd;KACF;IACD,UAAU,CAAC,QAAQ;IACpB;GACF,EACF;EACD,UAAU,CAAC,YAAY;EACxB;CAED,YAAY,WAA8D,WAAoC;AAAjF,OAAA,YAAA;AAA8D,OAAA,YAAA;;CAE3F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