refactor: 拆分 claude-dev-stack 为 windows-dev-stack 和 wsl-dev-stack
将原 claude-dev-stack 目录拆分为独立的 Windows 和 WSL 部署栈,便于分别维护和使用。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
13
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/errors.d.ts
vendored
Normal file
13
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/errors.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export declare class GodotConnectionError extends Error {
|
||||
constructor(message: string);
|
||||
}
|
||||
export declare class GodotCommandError extends Error {
|
||||
code: number;
|
||||
data?: Record<string, unknown>;
|
||||
constructor(code: number, message: string, data?: Record<string, unknown>);
|
||||
}
|
||||
export declare class TimeoutError extends Error {
|
||||
constructor(method: string, timeoutMs: number);
|
||||
}
|
||||
export declare function formatErrorForMcp(error: unknown): string;
|
||||
//# sourceMappingURL=errors.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAE1B,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAM1E;AAED,qBAAa,YAAa,SAAQ,KAAK;gBACzB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAI9C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBxD"}
|
||||
@@ -0,0 +1,42 @@
|
||||
export class GodotConnectionError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "GodotConnectionError";
|
||||
}
|
||||
}
|
||||
export class GodotCommandError extends Error {
|
||||
code;
|
||||
data;
|
||||
constructor(code, message, data) {
|
||||
super(message);
|
||||
this.name = "GodotCommandError";
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
export class TimeoutError extends Error {
|
||||
constructor(method, timeoutMs) {
|
||||
super(`Command '${method}' timed out after ${timeoutMs}ms`);
|
||||
this.name = "TimeoutError";
|
||||
}
|
||||
}
|
||||
export function formatErrorForMcp(error) {
|
||||
if (error instanceof GodotCommandError) {
|
||||
let msg = `Godot error (${error.code}): ${error.message}`;
|
||||
if (error.data?.suggestion) {
|
||||
msg += `\nSuggestion: ${error.data.suggestion}`;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
if (error instanceof GodotConnectionError) {
|
||||
return `Connection error: ${error.message}. Make sure the Godot MCP Pro plugin is enabled in your Godot editor.`;
|
||||
}
|
||||
if (error instanceof TimeoutError) {
|
||||
return error.message;
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
return String(error);
|
||||
}
|
||||
//# sourceMappingURL=errors.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACnC,IAAI,CAAS;IACb,IAAI,CAA2B;IAEtC,YAAY,IAAY,EAAE,OAAe,EAAE,IAA8B;QACvE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,MAAc,EAAE,SAAiB;QAC3C,KAAK,CAAC,YAAY,MAAM,qBAAqB,SAAS,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,KAAK,YAAY,iBAAiB,EAAE,CAAC;QACvC,IAAI,GAAG,GAAG,gBAAgB,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QAC1D,IAAI,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC;YAC3B,GAAG,IAAI,iBAAiB,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;QAC1C,OAAO,qBAAqB,KAAK,CAAC,OAAO,uEAAuE,CAAC;IACnH,CAAC;IACD,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
||||
7
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/load-instructions.d.ts
vendored
Normal file
7
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/load-instructions.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Loads CLAUDE.md from the shipped `instructions/` directory so Claude has
|
||||
* the essential usage guide from message #1 of every session. Falls back to
|
||||
* a terse built-in string if the file can't be located (e.g. custom layouts).
|
||||
*/
|
||||
export declare function loadInstructions(): string;
|
||||
//# sourceMappingURL=load-instructions.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"load-instructions.d.ts","sourceRoot":"","sources":["../../src/utils/load-instructions.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAmBzC"}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, resolve } from "node:path";
|
||||
const FALLBACK_INSTRUCTIONS = `# Godot MCP Pro
|
||||
|
||||
You have access to the Godot MCP Pro toolset for building and testing Godot games through the editor.
|
||||
|
||||
## Critical rules
|
||||
- Tools are split into **editor** (always available) and **runtime** (require \`play_scene\` first).
|
||||
- Never edit \`project.godot\` directly — use \`set_project_setting\`.
|
||||
- For input simulation, use short \`simulate_key\` durations (0.3–0.5s), not integer seconds.
|
||||
- \`execute_editor_script\` / \`execute_game_script\` must be valid GDScript; use \`_mcp_print(value)\` to return output.
|
||||
|
||||
## Getting oriented
|
||||
- \`get_project_info\` — project overview
|
||||
- \`get_scene_tree\` — current scene structure
|
||||
- For a full usage guide, see \`instructions/CLAUDE.md\` in the installed package.
|
||||
`;
|
||||
/**
|
||||
* Loads CLAUDE.md from the shipped `instructions/` directory so Claude has
|
||||
* the essential usage guide from message #1 of every session. Falls back to
|
||||
* a terse built-in string if the file can't be located (e.g. custom layouts).
|
||||
*/
|
||||
export function loadInstructions() {
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const candidates = [
|
||||
resolve(here, "../../instructions/CLAUDE.md"),
|
||||
resolve(here, "../../../instructions/CLAUDE.md"),
|
||||
resolve(here, "../../../../instructions/CLAUDE.md"),
|
||||
];
|
||||
for (const path of candidates) {
|
||||
try {
|
||||
const content = readFileSync(path, "utf8");
|
||||
if (content.trim().length > 0)
|
||||
return content;
|
||||
}
|
||||
catch {
|
||||
// try next
|
||||
}
|
||||
}
|
||||
return FALLBACK_INSTRUCTIONS;
|
||||
}
|
||||
//# sourceMappingURL=load-instructions.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"load-instructions.js","sourceRoot":"","sources":["../../src/utils/load-instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;CAc7B,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAErD,MAAM,UAAU,GAAG;QACjB,OAAO,CAAC,IAAI,EAAE,8BAA8B,CAAC;QAC7C,OAAO,CAAC,IAAI,EAAE,iCAAiC,CAAC;QAChD,OAAO,CAAC,IAAI,EAAE,oCAAoC,CAAC;KACpD,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC3C,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,OAAO,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACP,WAAW;QACb,CAAC;IACH,CAAC;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
||||
12
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/tool-filter.d.ts
vendored
Normal file
12
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/tool-filter.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
/**
|
||||
* Minimal mode: only these tools are registered (~35 tools).
|
||||
* Designed for clients with tight tool limits (Cursor: 40, local LLMs with small context).
|
||||
*/
|
||||
export declare const MINIMAL_TOOLS: Set<string>;
|
||||
/**
|
||||
* Creates a proxy around McpServer that filters tool registrations.
|
||||
* Only tools in the allowSet will be registered; others are silently skipped.
|
||||
*/
|
||||
export declare function createFilteredServer(server: McpServer, allowSet: Set<string>): McpServer;
|
||||
//# sourceMappingURL=tool-filter.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"tool-filter.d.ts","sourceRoot":"","sources":["../../src/utils/tool-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,aAAa,aA4CxB,CAAC;AAEH;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GACpB,SAAS,CAaX"}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Minimal mode: only these tools are registered (~35 tools).
|
||||
* Designed for clients with tight tool limits (Cursor: 40, local LLMs with small context).
|
||||
*/
|
||||
export const MINIMAL_TOOLS = new Set([
|
||||
// project (5)
|
||||
"get_project_info",
|
||||
"get_filesystem_tree",
|
||||
"search_files",
|
||||
"search_in_files",
|
||||
"set_project_setting",
|
||||
// scene (6)
|
||||
"get_scene_tree",
|
||||
"create_scene",
|
||||
"open_scene",
|
||||
"play_scene",
|
||||
"stop_scene",
|
||||
"save_scene",
|
||||
// node (5)
|
||||
"add_node",
|
||||
"delete_node",
|
||||
"update_property",
|
||||
"get_node_properties",
|
||||
"connect_signal",
|
||||
// script (5)
|
||||
"read_script",
|
||||
"create_script",
|
||||
"edit_script",
|
||||
"attach_script",
|
||||
"validate_script",
|
||||
// editor (5)
|
||||
"get_editor_errors",
|
||||
"get_output_log",
|
||||
"get_game_screenshot",
|
||||
"execute_editor_script",
|
||||
"reload_project",
|
||||
// input (3)
|
||||
"simulate_key",
|
||||
"simulate_mouse_click",
|
||||
"simulate_action",
|
||||
// runtime (5)
|
||||
"get_game_scene_tree",
|
||||
"get_game_node_properties",
|
||||
"set_game_node_property",
|
||||
"execute_game_script",
|
||||
"find_ui_elements",
|
||||
// input-map (1)
|
||||
"get_input_actions",
|
||||
]);
|
||||
/**
|
||||
* Creates a proxy around McpServer that filters tool registrations.
|
||||
* Only tools in the allowSet will be registered; others are silently skipped.
|
||||
*/
|
||||
export function createFilteredServer(server, allowSet) {
|
||||
return new Proxy(server, {
|
||||
get(target, prop, receiver) {
|
||||
if (prop === "tool") {
|
||||
const originalTool = target.tool.bind(target);
|
||||
return function filteredTool(name, ...args) {
|
||||
if (!allowSet.has(name))
|
||||
return;
|
||||
return originalTool(name, ...args);
|
||||
};
|
||||
}
|
||||
return Reflect.get(target, prop, receiver);
|
||||
},
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=tool-filter.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"tool-filter.js","sourceRoot":"","sources":["../../src/utils/tool-filter.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IACnC,cAAc;IACd,kBAAkB;IAClB,qBAAqB;IACrB,cAAc;IACd,iBAAiB;IACjB,qBAAqB;IACrB,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,UAAU;IACV,aAAa;IACb,iBAAiB;IACjB,qBAAqB;IACrB,gBAAgB;IAChB,aAAa;IACb,aAAa;IACb,eAAe;IACf,aAAa;IACb,eAAe;IACf,iBAAiB;IACjB,aAAa;IACb,mBAAmB;IACnB,gBAAgB;IAChB,qBAAqB;IACrB,uBAAuB;IACvB,gBAAgB;IAChB,YAAY;IACZ,cAAc;IACd,sBAAsB;IACtB,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,0BAA0B;IAC1B,wBAAwB;IACxB,qBAAqB;IACrB,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;CACpB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAiB,EACjB,QAAqB;IAErB,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC9C,OAAO,SAAS,YAAY,CAAC,IAAY,EAAE,GAAG,IAAe;oBAC3D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;wBAAE,OAAO;oBAChC,OAAQ,YAAyB,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;gBACnD,CAAC,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
||||
32
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/types.d.ts
vendored
Normal file
32
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/types.d.ts
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
export interface JsonRpcRequest {
|
||||
jsonrpc: "2.0";
|
||||
method: string;
|
||||
params: Record<string, unknown>;
|
||||
id: string;
|
||||
}
|
||||
export interface JsonRpcResponse {
|
||||
jsonrpc: "2.0";
|
||||
result?: unknown;
|
||||
error?: JsonRpcError;
|
||||
id: string | null;
|
||||
}
|
||||
export interface JsonRpcError {
|
||||
code: number;
|
||||
message: string;
|
||||
data?: Record<string, unknown>;
|
||||
}
|
||||
export interface ToolDefinition {
|
||||
name: string;
|
||||
description: string;
|
||||
inputSchema: {
|
||||
type: "object";
|
||||
properties: Record<string, unknown>;
|
||||
required?: string[];
|
||||
};
|
||||
}
|
||||
export interface PendingRequest {
|
||||
resolve: (value: JsonRpcResponse) => void;
|
||||
reject: (reason: Error) => void;
|
||||
timer: ReturnType<typeof setTimeout>;
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,KAAK,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;CACtC"}
|
||||
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=types.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
|
||||
12
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/zod-coerce.d.ts
vendored
Normal file
12
windows-dev-stack/godot-mcp-pro-v1.14.1/server/build/utils/zod-coerce.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { z } from "zod";
|
||||
/**
|
||||
* Coerce a value that might be a JSON string into a string array.
|
||||
* LLMs sometimes pass arrays as stringified JSON (e.g. '["a","b"]' instead of ["a","b"]).
|
||||
*/
|
||||
export declare function coerceStringArray(): z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodArray<z.ZodString>>;
|
||||
/**
|
||||
* Coerce a value that might be a numeric string into a number.
|
||||
* LLMs sometimes pass numbers as strings (e.g. "30" instead of 30).
|
||||
*/
|
||||
export declare function coerceNumber(): z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodNumber>;
|
||||
//# sourceMappingURL=zod-coerce.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"zod-coerce.d.ts","sourceRoot":"","sources":["../../src/utils/zod-coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,wBAAgB,iBAAiB,yEAYhC;AAED;;;GAGG;AACH,wBAAgB,YAAY,6DAQ3B"}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { z } from "zod";
|
||||
/**
|
||||
* Coerce a value that might be a JSON string into a string array.
|
||||
* LLMs sometimes pass arrays as stringified JSON (e.g. '["a","b"]' instead of ["a","b"]).
|
||||
*/
|
||||
export function coerceStringArray() {
|
||||
return z.preprocess((val) => {
|
||||
if (typeof val === "string") {
|
||||
try {
|
||||
const parsed = JSON.parse(val);
|
||||
if (Array.isArray(parsed))
|
||||
return parsed;
|
||||
}
|
||||
catch {
|
||||
// not JSON, return as-is for zod to validate
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}, z.array(z.string()));
|
||||
}
|
||||
/**
|
||||
* Coerce a value that might be a numeric string into a number.
|
||||
* LLMs sometimes pass numbers as strings (e.g. "30" instead of 30).
|
||||
*/
|
||||
export function coerceNumber() {
|
||||
return z.preprocess((val) => {
|
||||
if (typeof val === "string") {
|
||||
const n = Number(val);
|
||||
if (!isNaN(n))
|
||||
return n;
|
||||
}
|
||||
return val;
|
||||
}, z.number());
|
||||
}
|
||||
//# sourceMappingURL=zod-coerce.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"zod-coerce.js","sourceRoot":"","sources":["../../src/utils/zod-coerce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;oBAAE,OAAO,MAAM,CAAC;YAC3C,CAAC;YAAC,MAAM,CAAC;gBACP,6CAA6C;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE;QAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACjB,CAAC"}
|
||||
Reference in New Issue
Block a user