@sundaeswap/sprinkles 0.7.0 → 0.8.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/README.md +178 -181
- package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js +4 -4
- package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js.map +1 -1
- package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js +25 -3
- package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js.map +1 -1
- package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
- package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
- package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js +7 -9
- package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -1
- package/dist/cjs/Sprinkle/__tests__/native-script.test.js +390 -0
- package/dist/cjs/Sprinkle/__tests__/native-script.test.js.map +1 -0
- package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js +367 -0
- package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
- package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js +164 -0
- package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
- package/dist/cjs/Sprinkle/actions/builtin/index.js +60 -3
- package/dist/cjs/Sprinkle/actions/builtin/index.js.map +1 -1
- package/dist/cjs/Sprinkle/actions/builtin/native-script.js +139 -0
- package/dist/cjs/Sprinkle/actions/builtin/native-script.js.map +1 -0
- package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js +218 -0
- package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
- package/dist/cjs/Sprinkle/actions/cli-adapter.js +20 -2
- package/dist/cjs/Sprinkle/actions/cli-adapter.js.map +1 -1
- package/dist/cjs/Sprinkle/actions/index.js +12 -0
- package/dist/cjs/Sprinkle/actions/index.js.map +1 -1
- package/dist/cjs/Sprinkle/actions/mcp-adapter.js +146 -4
- package/dist/cjs/Sprinkle/actions/mcp-adapter.js.map +1 -1
- package/dist/cjs/Sprinkle/index.js +282 -6
- package/dist/cjs/Sprinkle/index.js.map +1 -1
- package/dist/cjs/Sprinkle/schemas.js +17 -1
- package/dist/cjs/Sprinkle/schemas.js.map +1 -1
- package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js +4 -4
- package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js.map +1 -1
- package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js +25 -3
- package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js.map +1 -1
- package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
- package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
- package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js +7 -9
- package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -1
- package/dist/esm/Sprinkle/__tests__/native-script.test.js +388 -0
- package/dist/esm/Sprinkle/__tests__/native-script.test.js.map +1 -0
- package/dist/esm/Sprinkle/__tests__/utility-actions.test.js +365 -0
- package/dist/esm/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
- package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js +159 -0
- package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
- package/dist/esm/Sprinkle/actions/builtin/index.js +8 -3
- package/dist/esm/Sprinkle/actions/builtin/index.js.map +1 -1
- package/dist/esm/Sprinkle/actions/builtin/native-script.js +133 -0
- package/dist/esm/Sprinkle/actions/builtin/native-script.js.map +1 -0
- package/dist/esm/Sprinkle/actions/builtin/utility-actions.js +213 -0
- package/dist/esm/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
- package/dist/esm/Sprinkle/actions/cli-adapter.js +20 -2
- package/dist/esm/Sprinkle/actions/cli-adapter.js.map +1 -1
- package/dist/esm/Sprinkle/actions/index.js +1 -1
- package/dist/esm/Sprinkle/actions/index.js.map +1 -1
- package/dist/esm/Sprinkle/actions/mcp-adapter.js +145 -5
- package/dist/esm/Sprinkle/actions/mcp-adapter.js.map +1 -1
- package/dist/esm/Sprinkle/index.js +260 -9
- package/dist/esm/Sprinkle/index.js.map +1 -1
- package/dist/esm/Sprinkle/schemas.js +16 -0
- package/dist/esm/Sprinkle/schemas.js.map +1 -1
- package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts +50 -0
- package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts.map +1 -0
- package/dist/types/Sprinkle/actions/builtin/index.d.ts +6 -2
- package/dist/types/Sprinkle/actions/builtin/index.d.ts.map +1 -1
- package/dist/types/Sprinkle/actions/builtin/native-script.d.ts +27 -0
- package/dist/types/Sprinkle/actions/builtin/native-script.d.ts.map +1 -0
- package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts +48 -0
- package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts.map +1 -0
- package/dist/types/Sprinkle/actions/cli-adapter.d.ts.map +1 -1
- package/dist/types/Sprinkle/actions/index.d.ts +2 -1
- package/dist/types/Sprinkle/actions/index.d.ts.map +1 -1
- package/dist/types/Sprinkle/actions/mcp-adapter.d.ts +24 -0
- package/dist/types/Sprinkle/actions/mcp-adapter.d.ts.map +1 -1
- package/dist/types/Sprinkle/index.d.ts +5 -2
- package/dist/types/Sprinkle/index.d.ts.map +1 -1
- package/dist/types/Sprinkle/schemas.d.ts +72 -0
- package/dist/types/Sprinkle/schemas.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Sprinkle/__tests__/builtin-actions.test.ts +4 -4
- package/src/Sprinkle/__tests__/cli-adapter.test.ts +24 -3
- package/src/Sprinkle/__tests__/fill-in-struct.test.ts +23 -1
- package/src/Sprinkle/__tests__/mcp-adapter.test.ts +7 -5
- package/src/Sprinkle/__tests__/native-script.test.ts +341 -0
- package/src/Sprinkle/__tests__/utility-actions.test.ts +348 -0
- package/src/Sprinkle/actions/builtin/addressbook-actions.ts +168 -0
- package/src/Sprinkle/actions/builtin/index.ts +41 -2
- package/src/Sprinkle/actions/builtin/native-script.ts +165 -0
- package/src/Sprinkle/actions/builtin/utility-actions.ts +285 -0
- package/src/Sprinkle/actions/cli-adapter.ts +18 -2
- package/src/Sprinkle/actions/index.ts +2 -1
- package/src/Sprinkle/actions/mcp-adapter.ts +179 -4
- package/src/Sprinkle/index.ts +264 -3
- package/src/Sprinkle/schemas.ts +20 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-adapter.js","names":["_encryption","require","_typeGuards","_runner","camelToKebab","str","replace","match","toLowerCase","kebabToCamel","_","char","toUpperCase","coerceValue","raw","schema","undefined","isNumber","n","parseFloat","isNaN","isInteger","Math","trunc","parseInt","isBoolean","isBigInt","BigInt","isArray","itemSchema","items","Array","map","item","singleValue","isObject","trimmed","trim","startsWith","JSON","parse","isString","String","parseArgvWithSchema","rawArgs","result","properties","propName","propSchema","Object","entries","kebabName","rawValue","hasDefault","getDefault","describeType","itemType","isUnion","generateActionHelp","action","appName","app","lines","name","description","inputSchema","required","flagName","typeLabel","isReq","includes","defaultVal","requiredLabel","defaultLabel","descPart","push","join","generateAppHelp","actions","length","byCategory","Map","cat","category","bucket","get","set","categoryActions","padEnd","runCli","sprinkle","actionName","context","getAction","available","listActions","a","errorOutput","stringify","success","error","code","message","bigIntReplacer","console","process","exit","log","coercedInput","executeAction","data","details"],"sources":["../../../../src/Sprinkle/actions/cli-adapter.ts"],"sourcesContent":["/**\n * CLI adapter for Sprinkles actions.\n *\n * Provides:\n * - Case-conversion helpers (camelToKebab / kebabToCamel)\n * - Schema-driven type coercion (coerceValue / parseArgvWithSchema)\n * - Help text generation (generateActionHelp / generateAppHelp)\n * - CLI orchestrator (runCli)\n */\n\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { bigIntReplacer } from \"../encryption.js\";\nimport {\n isArray,\n isBigInt,\n isBoolean,\n isInteger,\n isNumber,\n isObject,\n isString,\n isUnion,\n hasDefault,\n getDefault,\n} from \"../type-guards.js\";\nimport type { AnyAction, IActionContext } from \"./types.js\";\nimport { executeAction } from \"./runner.js\";\n\n// Re-import Sprinkle as a type only to avoid circular deps\nimport type { Sprinkle } from \"../index.js\";\n\n// ---------------------------------------------------------------------------\n// Case conversion helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Convert a camelCase string to kebab-case.\n * Examples:\n * \"myFlagName\" -> \"my-flag-name\"\n * \"getBalance\" -> \"get-balance\"\n * \"URL\" -> \"u-r-l\" (each uppercase letter gets a dash)\n */\nexport function camelToKebab(str: string): string {\n if (!str) return str;\n return str\n .replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`)\n .replace(/^-/, \"\");\n}\n\n/**\n * Convert a kebab-case string to camelCase.\n * Examples:\n * \"my-flag-name\" -> \"myFlagName\"\n * \"get-balance\" -> \"getBalance\"\n */\nexport function kebabToCamel(str: string): string {\n if (!str) return str;\n return str.replace(/-([a-z0-9])/g, (_, char: string) => char.toUpperCase());\n}\n\n// ---------------------------------------------------------------------------\n// Schema-driven type coercion\n// ---------------------------------------------------------------------------\n\n/**\n * Coerce a raw CLI string value to the type expected by a TypeBox schema.\n *\n * Handles:\n * - Number / Integer: parseFloat / parseInt\n * - Boolean: \"true\"/\"false\" strings, or passthrough if already boolean\n * - BigInt: BigInt() constructor\n * - Array: already-array passthrough; single value wrapped in array\n * - Object: JSON string parse\n * - String: passthrough\n * - Optional: unwrap and recurse on inner schema\n * - Union: passthrough (caller should supply JSON; no schema-level heuristics)\n */\nexport function coerceValue(raw: unknown, schema: TSchema): unknown {\n // Note: TypeBox Optional<T> adds an [OptionalKind] marker but does not\n // change the schema Kind. The guards below work correctly on Optional types.\n\n // If the raw value is null or undefined, return as-is\n if (raw === null || raw === undefined) return raw;\n\n if (isNumber(schema)) {\n if (typeof raw === \"number\") return raw;\n if (typeof raw === \"string\") {\n const n = parseFloat(raw);\n return isNaN(n) ? raw : n;\n }\n return raw;\n }\n\n if (isInteger(schema)) {\n if (typeof raw === \"number\") return Math.trunc(raw);\n if (typeof raw === \"string\") {\n const n = parseInt(raw, 10);\n return isNaN(n) ? raw : n;\n }\n return raw;\n }\n\n if (isBoolean(schema)) {\n if (typeof raw === \"boolean\") return raw;\n if (raw === \"true\") return true;\n if (raw === \"false\") return false;\n return raw;\n }\n\n if (isBigInt(schema)) {\n if (typeof raw === \"bigint\") return raw;\n if (typeof raw === \"string\" || typeof raw === \"number\") {\n try {\n return BigInt(raw);\n } catch {\n return raw;\n }\n }\n return raw;\n }\n\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n if (Array.isArray(raw)) {\n if (itemSchema) {\n return raw.map((item) => coerceValue(item, itemSchema));\n }\n return raw;\n }\n // Single value: wrap in array\n const singleValue = itemSchema ? coerceValue(raw, itemSchema) : raw;\n return [singleValue];\n }\n\n if (isObject(schema)) {\n // If it's a JSON string, parse it\n if (typeof raw === \"string\") {\n const trimmed = raw.trim();\n if (trimmed.startsWith(\"{\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return raw;\n }\n }\n }\n return raw;\n }\n\n if (isString(schema)) {\n if (typeof raw === \"string\") return raw;\n return String(raw);\n }\n\n // Union / unknown / other: return as-is (caller provides JSON)\n return raw;\n}\n\n/**\n * Walk a TypeBox object schema and coerce each property value from raw CLI args.\n *\n * - Handles kebab-case -> camelCase property name mapping\n * - Applies coerceValue for each property\n * - Applies TypeBox defaults for omitted optional fields\n *\n * @param rawArgs - Key/value record from parseCliArgs (keys may be kebab-case)\n * @param schema - A TypeBox TObject schema\n * @returns A new record with coerced values\n */\nexport function parseArgvWithSchema(\n rawArgs: Record<string, unknown>,\n schema: TSchema,\n): Record<string, unknown> {\n if (!isObject(schema)) {\n // Non-object schema: return args as-is (best-effort)\n return rawArgs;\n }\n\n const result: Record<string, unknown> = {};\n const properties = schema.properties as Record<string, TSchema>;\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n // Look up both camelCase and kebab-case versions in rawArgs\n const kebabName = camelToKebab(propName);\n\n let rawValue: unknown = undefined;\n if (propName in rawArgs) {\n rawValue = rawArgs[propName];\n } else if (kebabName !== propName && kebabName in rawArgs) {\n rawValue = rawArgs[kebabName];\n }\n\n if (rawValue === undefined) {\n // Apply default if defined on schema\n if (hasDefault(propSchema)) {\n result[propName] = getDefault(propSchema);\n }\n // Else omit: Value.Check will handle required/optional enforcement\n continue;\n }\n\n result[propName] = coerceValue(rawValue, propSchema);\n }\n\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Help text generation\n// ---------------------------------------------------------------------------\n\n/**\n * Describe a single TypeBox schema in a human-readable CLI type label.\n */\nfunction describeType(schema: TSchema): string {\n // Note: isOptional() only checks the OptionalKind marker; the other guards\n // still work correctly on Optional-wrapped schemas.\n if (isString(schema)) return \"<string>\";\n if (isNumber(schema)) return \"<number>\";\n if (isInteger(schema)) return \"<integer>\";\n if (isBoolean(schema)) return \"<boolean>\";\n if (isBigInt(schema)) return \"<bigint>\";\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n const itemType = itemSchema ? describeType(itemSchema) : \"<value>\";\n return `${itemType}... (repeatable)`;\n }\n if (isObject(schema)) return \"<json>\";\n if (isUnion(schema)) return \"<json>\";\n return \"<value>\";\n}\n\n/**\n * Generate action-specific help text.\n *\n * Format:\n * ```\n * Usage: <appName> <action-name> [options]\n *\n * Description\n *\n * Options:\n * --flag-name <type> Description [default: x] (required/optional)\n * ...\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateActionHelp(\n action: AnyAction<any>,\n appName?: string,\n): string {\n const app = appName ?? \"app\";\n const lines: string[] = [\n `Usage: ${app} ${action.name} [options]`,\n \"\",\n action.description,\n \"\",\n \"Options:\",\n ];\n\n const schema = action.inputSchema;\n if (isObject(schema)) {\n const properties = schema.properties as Record<string, TSchema>;\n const required = (schema.required as string[] | undefined) ?? [];\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n const flagName = camelToKebab(propName);\n const typeLabel = describeType(propSchema);\n const isReq = required.includes(propName);\n const defaultVal = hasDefault(propSchema) ? getDefault(propSchema) : undefined;\n const description = (propSchema as { description?: string }).description ?? \"\";\n\n const requiredLabel = isReq ? \"(required)\" : \"(optional)\";\n const defaultLabel =\n defaultVal !== undefined ? ` [default: ${String(defaultVal)}]` : \"\";\n\n const descPart = description ? ` ${description}` : \"\";\n lines.push(\n ` --${flagName} ${typeLabel}${descPart}${defaultLabel} ${requiredLabel}`,\n );\n }\n }\n\n lines.push(\"\");\n lines.push(\" --help Show this help message\");\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generate application-level help listing all registered actions.\n *\n * Format:\n * ```\n * Usage: <appName> <action> [options]\n *\n * Available actions:\n *\n * category:\n * action-name Description\n *\n * Global options:\n * --help Show this help message\n * --profile <n> Use profile by name\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateAppHelp(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n actions: AnyAction<any>[],\n appName?: string,\n): string {\n const app = appName ?? \"app\";\n const lines: string[] = [`Usage: ${app} <action> [options]`, \"\"];\n\n if (actions.length === 0) {\n lines.push(\"No actions registered.\");\n } else {\n lines.push(\"Available actions:\");\n\n // Group by category\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const byCategory = new Map<string, AnyAction<any>[]>();\n for (const action of actions) {\n const cat = action.category ?? \"default\";\n const bucket = byCategory.get(cat);\n if (bucket) {\n bucket.push(action);\n } else {\n byCategory.set(cat, [action]);\n }\n }\n\n for (const [category, categoryActions] of byCategory) {\n if (category !== \"default\") {\n lines.push(\"\");\n lines.push(` ${category}:`);\n }\n for (const action of categoryActions) {\n lines.push(` ${action.name.padEnd(30)} ${action.description}`);\n }\n }\n }\n\n lines.push(\"\");\n lines.push(\"Global options:\");\n lines.push(\" --help Show this help message\");\n lines.push(\" --profile <n> Use profile by name\");\n\n return lines.join(\"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// CLI orchestrator\n// ---------------------------------------------------------------------------\n\n/**\n * Run an action from CLI arguments, writing JSON output to stdout/stderr.\n *\n * Handles:\n * - Action not found: JSON error to stderr, process.exit(1)\n * - Action help (`--help` in rawArgs): prints action help to stdout\n * - Schema-driven argument coercion via parseArgvWithSchema\n * - Success: `{\"success\":true,\"data\":...}` JSON to stdout\n * - Failure: `{\"success\":false,\"error\":...}` JSON to stderr, process.exit(1)\n *\n * @param sprinkle - Fully-initialized Sprinkle instance\n * @param actionName - The action to invoke\n * @param rawArgs - Pre-parsed key/value args from parseCliArgs (profile already removed)\n * @param context - The action execution context\n * @param appName - Optional app name for help text\n */\nexport async function runCli<S extends TSchema>(\n sprinkle: Sprinkle<S>,\n actionName: string,\n rawArgs: Record<string, unknown>,\n context: IActionContext<S>,\n appName?: string,\n): Promise<void> {\n const action = sprinkle.getAction(actionName);\n\n if (!action) {\n const available = sprinkle\n .listActions()\n .map((a) => a.name)\n .join(\", \");\n const errorOutput = JSON.stringify(\n {\n success: false,\n error: {\n code: \"ACTION_NOT_FOUND\",\n message: `Action \"${actionName}\" not found. Available actions: ${available || \"(none)\"}`,\n },\n },\n bigIntReplacer,\n );\n console.error(errorOutput);\n process.exit(1);\n }\n\n // Handle --help flag for action-specific help\n if (rawArgs[\"help\"] === true) {\n console.log(generateActionHelp(action, appName));\n return;\n }\n\n // Coerce raw string args using the action's input schema\n const coercedInput = parseArgvWithSchema(rawArgs, action.inputSchema);\n\n // Execute and output result\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = await executeAction(action as any, coercedInput, context as any);\n\n if (result.success) {\n console.log(JSON.stringify({ success: true, data: result.data }, bigIntReplacer));\n } else {\n const errorOutput = JSON.stringify(\n {\n success: false,\n error: {\n code: result.error.code,\n message: result.error.message,\n details: result.error.details,\n },\n },\n bigIntReplacer,\n );\n console.error(errorOutput);\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAAA,WAAA,GAAAC,O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MAAM,CAAC,KAAK,IAAI,EAAE;IAC5B4D,OAAO,CAACG,GAAG,CAACjD,kBAAkB,CAACC,MAAM,EAAEC,OAAO,CAAC,CAAC;IAChD;EACF;;EAEA;EACA,MAAMgD,YAAY,GAAGjE,mBAAmB,CAACC,OAAO,EAAEe,MAAM,CAACM,WAAW,CAAC;;EAErE;EACA;EACA,MAAMpB,MAAM,GAAG,MAAM,IAAAgE,qBAAa,EAAClD,MAAM,EAASiD,YAAY,EAAEhB,OAAc,CAAC;EAE/E,IAAI/C,MAAM,CAACsD,OAAO,EAAE;IAClBK,OAAO,CAACG,GAAG,CAACpE,IAAI,CAAC2D,SAAS,CAAC;MAAEC,OAAO,EAAE,IAAI;MAAEW,IAAI,EAAEjE,MAAM,CAACiE;IAAK,CAAC,EAAEP,0BAAc,CAAC,CAAC;EACnF,CAAC,MAAM;IACL,MAAMN,WAAW,GAAG1D,IAAI,CAAC2D,SAAS,CAChC;MACEC,OAAO,EAAE,KAAK;MACdC,KAAK,EAAE;QACLC,IAAI,EAAExD,MAAM,CAACuD,KAAK,CAACC,IAAI;QACvBC,OAAO,EAAEzD,MAAM,CAACuD,KAAK,CAACE,OAAO;QAC7BS,OAAO,EAAElE,MAAM,CAACuD,KAAK,CAACW;MACxB;IACF,CAAC,EACDR,0BACF,CAAC;IACDC,OAAO,CAACJ,KAAK,CAACH,WAAW,CAAC;IAC1BQ,OAAO,CAACC,IAAI,CAAC,CAAC,CAAC;EACjB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"cli-adapter.js","names":["_encryption","require","_typeGuards","_runner","camelToKebab","str","replace","match","toLowerCase","kebabToCamel","_","char","toUpperCase","coerceValue","raw","schema","undefined","isNumber","n","parseFloat","isNaN","isInteger","Math","trunc","parseInt","isBoolean","isBigInt","BigInt","isArray","itemSchema","items","Array","map","item","singleValue","isObject","obj","trimmed","trim","startsWith","JSON","parse","props","properties","result","key","propSchema","Object","entries","isString","String","parseArgvWithSchema","rawArgs","propName","kebabName","rawValue","hasDefault","getDefault","describeType","itemType","isUnion","generateActionHelp","action","appName","app","lines","name","description","inputSchema","required","flagName","typeLabel","isReq","includes","defaultVal","requiredLabel","defaultLabel","descPart","push","join","generateAppHelp","actions","length","byCategory","Map","cat","category","bucket","get","set","categoryActions","padEnd","runCli","sprinkle","actionName","context","getAction","available","listActions","a","errorOutput","stringify","success","error","code","message","bigIntReplacer","console","process","exit","log","coercedInput","executeAction","data","details"],"sources":["../../../../src/Sprinkle/actions/cli-adapter.ts"],"sourcesContent":["/**\n * CLI adapter for Sprinkles actions.\n *\n * Provides:\n * - Case-conversion helpers (camelToKebab / kebabToCamel)\n * - Schema-driven type coercion (coerceValue / parseArgvWithSchema)\n * - Help text generation (generateActionHelp / generateAppHelp)\n * - CLI orchestrator (runCli)\n */\n\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { bigIntReplacer } from \"../encryption.js\";\nimport {\n isArray,\n isBigInt,\n isBoolean,\n isInteger,\n isNumber,\n isObject,\n isString,\n isUnion,\n hasDefault,\n getDefault,\n} from \"../type-guards.js\";\nimport type { AnyAction, IActionContext } from \"./types.js\";\nimport { executeAction } from \"./runner.js\";\n\n// Re-import Sprinkle as a type only to avoid circular deps\nimport type { Sprinkle } from \"../index.js\";\n\n// ---------------------------------------------------------------------------\n// Case conversion helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Convert a camelCase string to kebab-case.\n * Examples:\n * \"myFlagName\" -> \"my-flag-name\"\n * \"getBalance\" -> \"get-balance\"\n * \"URL\" -> \"u-r-l\" (each uppercase letter gets a dash)\n */\nexport function camelToKebab(str: string): string {\n if (!str) return str;\n return str\n .replace(/([A-Z])/g, (match) => `-${match.toLowerCase()}`)\n .replace(/^-/, \"\");\n}\n\n/**\n * Convert a kebab-case string to camelCase.\n * Examples:\n * \"my-flag-name\" -> \"myFlagName\"\n * \"get-balance\" -> \"getBalance\"\n */\nexport function kebabToCamel(str: string): string {\n if (!str) return str;\n return str.replace(/-([a-z0-9])/g, (_, char: string) => char.toUpperCase());\n}\n\n// ---------------------------------------------------------------------------\n// Schema-driven type coercion\n// ---------------------------------------------------------------------------\n\n/**\n * Coerce a raw CLI string value to the type expected by a TypeBox schema.\n *\n * Handles:\n * - Number / Integer: parseFloat / parseInt\n * - Boolean: \"true\"/\"false\" strings, or passthrough if already boolean\n * - BigInt: BigInt() constructor\n * - Array: already-array passthrough; single value wrapped in array\n * - Object: JSON string parse\n * - String: passthrough\n * - Optional: unwrap and recurse on inner schema\n * - Union: passthrough (caller should supply JSON; no schema-level heuristics)\n */\nexport function coerceValue(raw: unknown, schema: TSchema): unknown {\n // Note: TypeBox Optional<T> adds an [OptionalKind] marker but does not\n // change the schema Kind. The guards below work correctly on Optional types.\n\n // If the raw value is null or undefined, return as-is\n if (raw === null || raw === undefined) return raw;\n\n if (isNumber(schema)) {\n if (typeof raw === \"number\") return raw;\n if (typeof raw === \"string\") {\n const n = parseFloat(raw);\n return isNaN(n) ? raw : n;\n }\n return raw;\n }\n\n if (isInteger(schema)) {\n if (typeof raw === \"number\") return Math.trunc(raw);\n if (typeof raw === \"string\") {\n const n = parseInt(raw, 10);\n return isNaN(n) ? raw : n;\n }\n return raw;\n }\n\n if (isBoolean(schema)) {\n if (typeof raw === \"boolean\") return raw;\n if (raw === \"true\") return true;\n if (raw === \"false\") return false;\n return raw;\n }\n\n if (isBigInt(schema)) {\n if (typeof raw === \"bigint\") return raw;\n if (typeof raw === \"string\" || typeof raw === \"number\") {\n try {\n return BigInt(raw);\n } catch {\n return raw;\n }\n }\n return raw;\n }\n\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n if (Array.isArray(raw)) {\n if (itemSchema) {\n return raw.map((item) => coerceValue(item, itemSchema));\n }\n return raw;\n }\n // Single value: wrap in array\n const singleValue = itemSchema ? coerceValue(raw, itemSchema) : raw;\n return [singleValue];\n }\n\n if (isObject(schema)) {\n let obj = raw;\n // If it's a JSON string, parse it\n if (typeof raw === \"string\") {\n const trimmed = raw.trim();\n if (trimmed.startsWith(\"{\")) {\n try {\n obj = JSON.parse(trimmed);\n } catch {\n return raw;\n }\n } else {\n return raw;\n }\n }\n // Recurse into properties to coerce nested values\n if (typeof obj === \"object\" && obj !== null && !Array.isArray(obj)) {\n const props = schema.properties as Record<string, TSchema> | undefined;\n if (props) {\n const result: Record<string, unknown> = { ...(obj as Record<string, unknown>) };\n for (const [key, propSchema] of Object.entries(props)) {\n if (key in result) {\n result[key] = coerceValue(result[key], propSchema);\n }\n }\n return result;\n }\n }\n return obj;\n }\n\n if (isString(schema)) {\n if (typeof raw === \"string\") return raw;\n return String(raw);\n }\n\n // Union / unknown / other: return as-is (caller provides JSON)\n return raw;\n}\n\n/**\n * Walk a TypeBox object schema and coerce each property value from raw CLI args.\n *\n * - Handles kebab-case -> camelCase property name mapping\n * - Applies coerceValue for each property\n * - Applies TypeBox defaults for omitted optional fields\n *\n * @param rawArgs - Key/value record from parseCliArgs (keys may be kebab-case)\n * @param schema - A TypeBox TObject schema\n * @returns A new record with coerced values\n */\nexport function parseArgvWithSchema(\n rawArgs: Record<string, unknown>,\n schema: TSchema,\n): Record<string, unknown> {\n if (!isObject(schema)) {\n // Non-object schema: return args as-is (best-effort)\n return rawArgs;\n }\n\n const result: Record<string, unknown> = {};\n const properties = schema.properties as Record<string, TSchema>;\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n // Look up both camelCase and kebab-case versions in rawArgs\n const kebabName = camelToKebab(propName);\n\n let rawValue: unknown = undefined;\n if (propName in rawArgs) {\n rawValue = rawArgs[propName];\n } else if (kebabName !== propName && kebabName in rawArgs) {\n rawValue = rawArgs[kebabName];\n }\n\n if (rawValue === undefined) {\n // Apply default if defined on schema\n if (hasDefault(propSchema)) {\n result[propName] = getDefault(propSchema);\n }\n // Else omit: Value.Check will handle required/optional enforcement\n continue;\n }\n\n result[propName] = coerceValue(rawValue, propSchema);\n }\n\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Help text generation\n// ---------------------------------------------------------------------------\n\n/**\n * Describe a single TypeBox schema in a human-readable CLI type label.\n */\nfunction describeType(schema: TSchema): string {\n // Note: isOptional() only checks the OptionalKind marker; the other guards\n // still work correctly on Optional-wrapped schemas.\n if (isString(schema)) return \"<string>\";\n if (isNumber(schema)) return \"<number>\";\n if (isInteger(schema)) return \"<integer>\";\n if (isBoolean(schema)) return \"<boolean>\";\n if (isBigInt(schema)) return \"<bigint>\";\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n const itemType = itemSchema ? describeType(itemSchema) : \"<value>\";\n return `${itemType}... (repeatable)`;\n }\n if (isObject(schema)) return \"<json>\";\n if (isUnion(schema)) return \"<json>\";\n return \"<value>\";\n}\n\n/**\n * Generate action-specific help text.\n *\n * Format:\n * ```\n * Usage: <appName> <action-name> [options]\n *\n * Description\n *\n * Options:\n * --flag-name <type> Description [default: x] (required/optional)\n * ...\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateActionHelp(\n action: AnyAction<any>,\n appName?: string,\n): string {\n const app = appName ?? \"app\";\n const lines: string[] = [\n `Usage: ${app} ${action.name} [options]`,\n \"\",\n action.description,\n \"\",\n \"Options:\",\n ];\n\n const schema = action.inputSchema;\n if (isObject(schema)) {\n const properties = schema.properties as Record<string, TSchema>;\n const required = (schema.required as string[] | undefined) ?? [];\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n const flagName = camelToKebab(propName);\n const typeLabel = describeType(propSchema);\n const isReq = required.includes(propName);\n const defaultVal = hasDefault(propSchema) ? getDefault(propSchema) : undefined;\n const description = (propSchema as { description?: string }).description ?? \"\";\n\n const requiredLabel = isReq ? \"(required)\" : \"(optional)\";\n const defaultLabel =\n defaultVal !== undefined ? ` [default: ${String(defaultVal)}]` : \"\";\n\n const descPart = description ? ` ${description}` : \"\";\n lines.push(\n ` --${flagName} ${typeLabel}${descPart}${defaultLabel} ${requiredLabel}`,\n );\n }\n }\n\n lines.push(\"\");\n lines.push(\" --help Show this help message\");\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generate application-level help listing all registered actions.\n *\n * Format:\n * ```\n * Usage: <appName> <action> [options]\n *\n * Available actions:\n *\n * category:\n * action-name Description\n *\n * Global options:\n * --help Show this help message\n * --profile <n> Use profile by name\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function generateAppHelp(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n actions: AnyAction<any>[],\n appName?: string,\n): string {\n const app = appName ?? \"app\";\n const lines: string[] = [`Usage: ${app} <action> [options]`, \"\"];\n\n if (actions.length === 0) {\n lines.push(\"No actions registered.\");\n } else {\n lines.push(\"Available actions:\");\n\n // Group by category\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const byCategory = new Map<string, AnyAction<any>[]>();\n for (const action of actions) {\n const cat = action.category ?? \"default\";\n const bucket = byCategory.get(cat);\n if (bucket) {\n bucket.push(action);\n } else {\n byCategory.set(cat, [action]);\n }\n }\n\n for (const [category, categoryActions] of byCategory) {\n if (category !== \"default\") {\n lines.push(\"\");\n lines.push(` ${category}:`);\n }\n for (const action of categoryActions) {\n lines.push(` ${action.name.padEnd(30)} ${action.description}`);\n }\n }\n }\n\n lines.push(\"\");\n lines.push(\"Global options:\");\n lines.push(\" --help Show this help message\");\n lines.push(\" --profile <n> Use profile by name\");\n\n return lines.join(\"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// CLI orchestrator\n// ---------------------------------------------------------------------------\n\n/**\n * Run an action from CLI arguments, writing JSON output to stdout/stderr.\n *\n * Handles:\n * - Action not found: JSON error to stderr, process.exit(1)\n * - Action help (`--help` in rawArgs): prints action help to stdout\n * - Schema-driven argument coercion via parseArgvWithSchema\n * - Success: `{\"success\":true,\"data\":...}` JSON to stdout\n * - Failure: `{\"success\":false,\"error\":...}` JSON to stderr, process.exit(1)\n *\n * @param sprinkle - Fully-initialized Sprinkle instance\n * @param actionName - The action to invoke\n * @param rawArgs - Pre-parsed key/value args from parseCliArgs (profile already removed)\n * @param context - The action execution context\n * @param appName - Optional app name for help text\n */\nexport async function runCli<S extends TSchema>(\n sprinkle: Sprinkle<S>,\n actionName: string,\n rawArgs: Record<string, unknown>,\n context: IActionContext<S>,\n appName?: string,\n): Promise<void> {\n const action = sprinkle.getAction(actionName);\n\n if (!action) {\n const available = sprinkle\n .listActions()\n .map((a) => a.name)\n .join(\", \");\n const errorOutput = JSON.stringify(\n {\n success: false,\n error: {\n code: \"ACTION_NOT_FOUND\",\n message: `Action \"${actionName}\" not found. Available actions: ${available || \"(none)\"}`,\n },\n },\n bigIntReplacer,\n );\n console.error(errorOutput);\n process.exit(1);\n }\n\n // Handle --help flag for action-specific help\n if (rawArgs[\"help\"] === true) {\n console.log(generateActionHelp(action, appName));\n return;\n }\n\n // Coerce raw string args using the action's input schema\n const coercedInput = parseArgvWithSchema(rawArgs, action.inputSchema);\n\n // Execute and output result\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = await executeAction(action as any, coercedInput, context as any);\n\n if (result.success) {\n console.log(JSON.stringify({ success: true, data: result.data }, bigIntReplacer));\n } else {\n const errorOutput = JSON.stringify(\n {\n success: false,\n error: {\n code: result.error.code,\n message: result.error.message,\n details: result.error.details,\n },\n },\n bigIntReplacer,\n );\n console.error(errorOutput);\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAaA,IAAAE,OAAA,GAAAF,OAAA;AAzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,YAAYA,CAACC,GAAW,EAAU;EAChD,IAAI,CAACA,GAAG,EAAE,OAAOA,GAAG;EACpB,OAAOA,GAAG,CACPC,OAAO,CAAC,UAAU,EAAGC,KAAK,IAAK,IAAIA,KAAK,CAACC,WAAW,CAAC,CAAC,EAAE,CAAC,C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
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "completeWithScripts", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _index.completeWithScripts;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
Object.defineProperty(exports, "createMcpServer", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function () {
|
|
@@ -111,6 +117,12 @@ Object.defineProperty(exports, "runMcp", {
|
|
|
111
117
|
return _mcpAdapter.runMcp;
|
|
112
118
|
}
|
|
113
119
|
});
|
|
120
|
+
Object.defineProperty(exports, "toNativeScript", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _index.toNativeScript;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
114
126
|
Object.defineProperty(exports, "typeboxToJsonSchema", {
|
|
115
127
|
enumerable: true,
|
|
116
128
|
get: function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_types","require","_registry","_runner","_cliAdapter","_mcpAdapter","_index","_tuiHelpers"],"sources":["../../../../src/Sprinkle/actions/index.ts"],"sourcesContent":["/**\n * Barrel export for the actions subsystem.\n */\n\nexport type { IAction, IActionContext, IActionResult, IActionSuccess, IActionFailure, AnyAction } from \"./types.js\";\nexport { ActionError } from \"./types.js\";\n\nexport { ActionRegistry } from \"./registry.js\";\n\nexport { executeAction, detectMode, parseCliArgs } from \"./runner.js\";\n\nexport {\n camelToKebab,\n kebabToCamel,\n coerceValue,\n parseArgvWithSchema,\n generateActionHelp,\n generateAppHelp,\n runCli,\n} from \"./cli-adapter.js\";\n\nexport {\n typeboxToJsonSchema,\n coerceMcpInput,\n getMcpSdk,\n createMcpServer,\n runMcp,\n} from \"./mcp-adapter.js\";\n\nexport { getBuiltinActions } from \"./builtin/index.js\";\n\nexport { promptAndExecute } from \"./tui-helpers.js\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["_types","require","_registry","_runner","_cliAdapter","_mcpAdapter","_index","_tuiHelpers"],"sources":["../../../../src/Sprinkle/actions/index.ts"],"sourcesContent":["/**\n * Barrel export for the actions subsystem.\n */\n\nexport type { IAction, IActionContext, IActionResult, IActionSuccess, IActionFailure, AnyAction } from \"./types.js\";\nexport { ActionError } from \"./types.js\";\n\nexport { ActionRegistry } from \"./registry.js\";\n\nexport { executeAction, detectMode, parseCliArgs } from \"./runner.js\";\n\nexport {\n camelToKebab,\n kebabToCamel,\n coerceValue,\n parseArgvWithSchema,\n generateActionHelp,\n generateAppHelp,\n runCli,\n} from \"./cli-adapter.js\";\n\nexport {\n typeboxToJsonSchema,\n coerceMcpInput,\n getMcpSdk,\n createMcpServer,\n runMcp,\n} from \"./mcp-adapter.js\";\n\nexport { getBuiltinActions, toNativeScript, completeWithScripts } from \"./builtin/index.js\";\nexport type { NativeScriptInput } from \"./builtin/index.js\";\n\nexport { promptAndExecute } from \"./tui-helpers.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AAUA,IAAAI,WAAA,GAAAJ,OAAA;AAQA,IAAAK,MAAA,GAAAL,OAAA;AAGA,IAAAM,WAAA,GAAAN,OAAA","ignoreList":[]}
|
|
@@ -8,6 +8,8 @@ exports.createMcpServer = createMcpServer;
|
|
|
8
8
|
exports.getMcpSdk = getMcpSdk;
|
|
9
9
|
exports.runMcp = runMcp;
|
|
10
10
|
exports.typeboxToJsonSchema = typeboxToJsonSchema;
|
|
11
|
+
exports.typeboxToZod = typeboxToZod;
|
|
12
|
+
exports.typeboxToZodShape = typeboxToZodShape;
|
|
11
13
|
var _module = require("module");
|
|
12
14
|
var _url = require("url");
|
|
13
15
|
var _path = require("path");
|
|
@@ -19,6 +21,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
19
21
|
*
|
|
20
22
|
* Provides:
|
|
21
23
|
* - TypeBox to JSON Schema conversion (typeboxToJsonSchema)
|
|
24
|
+
* - TypeBox to Zod conversion for MCP SDK compatibility (typeboxToZod)
|
|
22
25
|
* - BigInt string coercion for MCP input (coerceMcpInput)
|
|
23
26
|
* - Lazy MCP SDK import with graceful error (getMcpSdk)
|
|
24
27
|
* - MCP server creation from registered actions (createMcpServer)
|
|
@@ -265,6 +268,145 @@ function coerceMcpInput(input, schema) {
|
|
|
265
268
|
return input;
|
|
266
269
|
}
|
|
267
270
|
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// TypeBox to Zod conversion
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Zod module shape (the parts we use from zod).
|
|
277
|
+
* Typed loosely since zod is a transitive dependency of @modelcontextprotocol/sdk,
|
|
278
|
+
* not a direct dependency of Sprinkles.
|
|
279
|
+
*/
|
|
280
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
|
+
|
|
282
|
+
let _zod;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Lazily import the Zod module.
|
|
286
|
+
* Zod is a transitive dependency of @modelcontextprotocol/sdk, so it's
|
|
287
|
+
* guaranteed to be available when MCP mode is used.
|
|
288
|
+
*/
|
|
289
|
+
async function getZod() {
|
|
290
|
+
if (_zod) return _zod;
|
|
291
|
+
try {
|
|
292
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
293
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("zod")));
|
|
294
|
+
_zod = {
|
|
295
|
+
string: () => mod.string(),
|
|
296
|
+
number: () => mod.number(),
|
|
297
|
+
boolean: () => mod.boolean(),
|
|
298
|
+
literal: v => mod.literal(v),
|
|
299
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
300
|
+
object: shape => mod.object(shape),
|
|
301
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
302
|
+
array: item => mod.array(item),
|
|
303
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
304
|
+
union: members => mod.union(members),
|
|
305
|
+
nullType: () => mod.nullType(),
|
|
306
|
+
any: () => mod.any()
|
|
307
|
+
};
|
|
308
|
+
return _zod;
|
|
309
|
+
} catch {
|
|
310
|
+
throw new Error("MCP mode requires zod (via @modelcontextprotocol/sdk). Install @modelcontextprotocol/sdk.");
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Convert a TypeBox schema to a Zod schema for MCP SDK compatibility.
|
|
316
|
+
*
|
|
317
|
+
* The MCP SDK (v1.27+) expects Zod schemas for tool input validation,
|
|
318
|
+
* not plain JSON Schema objects. This function converts TypeBox schemas
|
|
319
|
+
* to their Zod equivalents so the SDK correctly registers tool parameters.
|
|
320
|
+
*
|
|
321
|
+
* BigInt fields are represented as z.string() with a regex pattern since
|
|
322
|
+
* JSON (and thus MCP) has no BigInt type. The coerceMcpInput function
|
|
323
|
+
* handles converting these string values back to BigInt at call time.
|
|
324
|
+
*/
|
|
325
|
+
async function typeboxToZod(schema) {
|
|
326
|
+
const z = await getZod();
|
|
327
|
+
return _typeboxToZod(schema, z);
|
|
328
|
+
}
|
|
329
|
+
function _typeboxToZod(schema, z) {
|
|
330
|
+
if ((0, _typeGuards.isBigInt)(schema)) {
|
|
331
|
+
// BigInt -> string with regex pattern (JSON has no BigInt)
|
|
332
|
+
return z.string().regex(/^-?[0-9]+$/);
|
|
333
|
+
}
|
|
334
|
+
if ((0, _typeGuards.isString)(schema)) {
|
|
335
|
+
let s = z.string();
|
|
336
|
+
if (schema.description) s = s.describe(schema.description);
|
|
337
|
+
return s;
|
|
338
|
+
}
|
|
339
|
+
if ((0, _typeGuards.isNumber)(schema) || (0, _typeGuards.isInteger)(schema)) {
|
|
340
|
+
let n = z.number();
|
|
341
|
+
if (schema.description) n = n.describe(schema.description);
|
|
342
|
+
return n;
|
|
343
|
+
}
|
|
344
|
+
if ((0, _typeGuards.isBoolean)(schema)) {
|
|
345
|
+
let b = z.boolean();
|
|
346
|
+
if (schema.description) b = b.describe(schema.description);
|
|
347
|
+
return b;
|
|
348
|
+
}
|
|
349
|
+
if ((0, _typeGuards.isNull)(schema)) {
|
|
350
|
+
return z.nullType();
|
|
351
|
+
}
|
|
352
|
+
if ((0, _typeGuards.isLiteral)(schema)) {
|
|
353
|
+
return z.literal(schema.const);
|
|
354
|
+
}
|
|
355
|
+
if ((0, _typeGuards.isArray)(schema)) {
|
|
356
|
+
const itemSchema = schema.items;
|
|
357
|
+
if (itemSchema) {
|
|
358
|
+
return z.array(_typeboxToZod(itemSchema, z));
|
|
359
|
+
}
|
|
360
|
+
return z.array(z.any());
|
|
361
|
+
}
|
|
362
|
+
if ((0, _typeGuards.isObject)(schema)) {
|
|
363
|
+
const properties = schema.properties;
|
|
364
|
+
const shape = {};
|
|
365
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
366
|
+
let zodProp = _typeboxToZod(propSchema, z);
|
|
367
|
+
if ((0, _typeGuards.isOptional)(propSchema)) {
|
|
368
|
+
zodProp = zodProp.optional();
|
|
369
|
+
}
|
|
370
|
+
shape[propName] = zodProp;
|
|
371
|
+
}
|
|
372
|
+
return z.object(shape);
|
|
373
|
+
}
|
|
374
|
+
if ((0, _typeGuards.isUnion)(schema)) {
|
|
375
|
+
const members = schema.anyOf.map(member => _typeboxToZod(member, z));
|
|
376
|
+
if (members.length >= 2) {
|
|
377
|
+
return z.union(members);
|
|
378
|
+
}
|
|
379
|
+
return members[0] ?? z.any();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Fallback: accept anything
|
|
383
|
+
return z.any();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Convert a TypeBox object schema to a Zod "raw shape" (Record<string, ZodType>).
|
|
388
|
+
* This is the format expected by the MCP SDK's tool() API.
|
|
389
|
+
*/
|
|
390
|
+
async function typeboxToZodShape(schema) {
|
|
391
|
+
const z = await getZod();
|
|
392
|
+
if (!(0, _typeGuards.isObject)(schema)) {
|
|
393
|
+
// Non-object input schemas get wrapped as { input: zodSchema }
|
|
394
|
+
return {
|
|
395
|
+
input: _typeboxToZod(schema, z)
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const properties = schema.properties;
|
|
399
|
+
const shape = {};
|
|
400
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
401
|
+
let zodProp = _typeboxToZod(propSchema, z);
|
|
402
|
+
if ((0, _typeGuards.isOptional)(propSchema)) {
|
|
403
|
+
zodProp = zodProp.optional();
|
|
404
|
+
}
|
|
405
|
+
shape[propName] = zodProp;
|
|
406
|
+
}
|
|
407
|
+
return shape;
|
|
408
|
+
}
|
|
409
|
+
|
|
268
410
|
// ---------------------------------------------------------------------------
|
|
269
411
|
// Lazy MCP SDK import
|
|
270
412
|
// ---------------------------------------------------------------------------
|
|
@@ -334,12 +476,12 @@ async function createMcpServer(sprinkle, serverName
|
|
|
334
476
|
});
|
|
335
477
|
const actions = sprinkle.listActions();
|
|
336
478
|
for (const action of actions) {
|
|
337
|
-
const
|
|
479
|
+
const zodShape = await typeboxToZodShape(action.inputSchema);
|
|
338
480
|
|
|
339
481
|
// Register the action as an MCP tool.
|
|
340
|
-
// The high-level McpServer.tool() API accepts
|
|
341
|
-
//
|
|
342
|
-
server.tool(action.name, action.description,
|
|
482
|
+
// The high-level McpServer.tool() API accepts a Zod raw shape
|
|
483
|
+
// (Record<string, ZodType>) for input validation.
|
|
484
|
+
server.tool(action.name, action.description, zodShape,
|
|
343
485
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
486
|
async input => {
|
|
345
487
|
const coercedInput = coerceMcpInput(input, action.inputSchema);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-adapter.js","names":["_module","require","_url","_path","_encryption","_typeGuards","_runner","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","loadPackageVersion","createRequire","import","meta","url","__filename","fileURLToPath","__dirname","dirname","candidates","resolve","candidate","pkg","version","PACKAGE_VERSION","typeboxToJsonSchema","schema","isBigInt","type","pattern","description","isString","result","undefined","title","examples","minLength","maxLength","isSensitive","writeOnly","isNumber","minimum","maximum","isInteger","isBoolean","isNull","isArray","itemSchema","items","minItems","maxItems","isObject","properties","required","convertedProperties","propName","propSchema","entries","length","isUnion","anyOf","map","member","isLiteral","value","const","console","warn","coerceMcpInput","input","test","BigInt","Math","trunc","Array","item","getMcpSdk","Promise","then","Error","getMcpStdioTransport","createMcpServer","sprinkle","serverName","McpServer","server","name","actions","listActions","action","inputSchema","tool","coercedInput","context","settings","executeAction","success","content","text","JSON","stringify","data","bigIntReplacer","error","code","message","details","isError","runMcp","StdioServerTransport","transport","connect","err","process","stderr","write","String"],"sources":["../../../../src/Sprinkle/actions/mcp-adapter.ts"],"sourcesContent":["/**\n * MCP adapter for Sprinkles actions.\n *\n * Provides:\n * - TypeBox to JSON Schema conversion (typeboxToJsonSchema)\n * - BigInt string coercion for MCP input (coerceMcpInput)\n * - Lazy MCP SDK import with graceful error (getMcpSdk)\n * - MCP server creation from registered actions (createMcpServer)\n * - MCP orchestrator that starts a stdio server (runMcp)\n */\n\nimport { createRequire } from \"module\";\nimport { fileURLToPath } from \"url\";\nimport { dirname, resolve } from \"path\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { bigIntReplacer } from \"../encryption.js\";\nimport {\n isArray,\n isBigInt,\n isBoolean,\n isInteger,\n isLiteral,\n isNull,\n isNumber,\n isObject,\n isOptional,\n isString,\n isUnion,\n isSensitive,\n} from \"../type-guards.js\";\nimport type { AnyAction } from \"./types.js\";\nimport { executeAction } from \"./runner.js\";\n\n// Re-import Sprinkle as a type only to avoid circular deps\nimport type { Sprinkle } from \"../index.js\";\n\n// Load package version for MCP server identification\n// Robustly find package.json - works from both src and dist directories\nfunction loadPackageVersion(): string {\n const require = createRequire(import.meta.url);\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n \n // Try multiple possible paths (handles src vs dist/esm vs dist/cjs)\n const candidates = [\n resolve(__dirname, \"../../../package.json\"), // from src/Sprinkle/actions\n resolve(__dirname, \"../../../../package.json\"), // from dist/*/Sprinkle/actions\n ];\n \n for (const candidate of candidates) {\n try {\n const pkg = require(candidate) as { version: string };\n return pkg.version;\n } catch {\n // Try next candidate\n }\n }\n \n return \"0.0.0\"; // Fallback if package.json not found\n}\n\nconst PACKAGE_VERSION: string = loadPackageVersion();\n\n// ---------------------------------------------------------------------------\n// TypeBox to JSON Schema conversion\n// ---------------------------------------------------------------------------\n\n/**\n * Convert a TypeBox schema to a plain JSON Schema object.\n *\n * Strips TypeBox-internal symbols and properties (Kind, OptionalKind, $id)\n * and maps TypeBox-specific types to their JSON Schema equivalents:\n * - BigInt -> { type: \"string\", pattern: \"^-?[0-9]+$\" } (JSON has no BigInt)\n * - Sensitive string fields -> add writeOnly: true\n * - Optional -> recurse on inner schema (Optional does not change Kind)\n * - Union -> { anyOf: [...] }\n * - Literal -> { type, const }\n * - Null -> { type: \"null\" }\n * - Unknown/unsupported -> {} (accepts anything)\n */\nexport function typeboxToJsonSchema(schema: TSchema): Record<string, unknown> {\n // Optional in TypeBox doesn't change the Kind, but marks the schema with\n // OptionalKind. We can check for it and recurse transparently since all\n // other guards still work correctly on optional-wrapped schemas.\n //\n // We intentionally do NOT strip optional here -- the containing Object\n // converter decides whether to include a property in `required` based\n // on the isOptional guard applied to the property schema.\n\n if (isBigInt(schema)) {\n return {\n type: \"string\",\n pattern: \"^-?[0-9]+$\",\n description: \"BigInt value as string\",\n };\n }\n\n if (isString(schema)) {\n const result: Record<string, unknown> = { type: \"string\" };\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.title !== undefined) result.title = schema.title;\n if (schema.examples !== undefined) result.examples = schema.examples;\n if (schema.pattern !== undefined) result.pattern = schema.pattern;\n if (schema.minLength !== undefined) result.minLength = schema.minLength;\n if (schema.maxLength !== undefined) result.maxLength = schema.maxLength;\n if (schema.default !== undefined) result.default = schema.default;\n // Sensitive fields are write-only (never returned in responses)\n if (isSensitive(schema)) result.writeOnly = true;\n return result;\n }\n\n if (isNumber(schema)) {\n const result: Record<string, unknown> = { type: \"number\" };\n if (schema.minimum !== undefined) result.minimum = schema.minimum;\n if (schema.maximum !== undefined) result.maximum = schema.maximum;\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.default !== undefined) result.default = schema.default;\n return result;\n }\n\n if (isInteger(schema)) {\n const result: Record<string, unknown> = { type: \"integer\" };\n if (schema.minimum !== undefined) result.minimum = schema.minimum;\n if (schema.maximum !== undefined) result.maximum = schema.maximum;\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.default !== undefined) result.default = schema.default;\n return result;\n }\n\n if (isBoolean(schema)) {\n const result: Record<string, unknown> = { type: \"boolean\" };\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.default !== undefined) result.default = schema.default;\n return result;\n }\n\n if (isNull(schema)) {\n return { type: \"null\" };\n }\n\n if (isArray(schema)) {\n const result: Record<string, unknown> = { type: \"array\" };\n const itemSchema = (schema as { items?: TSchema }).items;\n if (itemSchema) {\n result.items = typeboxToJsonSchema(itemSchema);\n }\n if (schema.minItems !== undefined) result.minItems = schema.minItems;\n if (schema.maxItems !== undefined) result.maxItems = schema.maxItems;\n if (schema.description !== undefined) result.description = schema.description;\n return result;\n }\n\n if (isObject(schema)) {\n const properties = schema.properties as Record<string, TSchema>;\n const required: string[] = schema.required as string[] ?? [];\n const convertedProperties: Record<string, unknown> = {};\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n convertedProperties[propName] = typeboxToJsonSchema(propSchema);\n }\n\n const result: Record<string, unknown> = {\n type: \"object\",\n properties: convertedProperties,\n };\n\n if (required.length > 0) {\n result.required = required;\n }\n\n if (schema.description !== undefined) result.description = schema.description;\n\n return result;\n }\n\n if (isUnion(schema)) {\n return {\n anyOf: schema.anyOf.map((member: TSchema) => typeboxToJsonSchema(member)),\n };\n }\n\n if (isLiteral(schema)) {\n const value = schema.const;\n let type: string;\n if (typeof value === \"string\") {\n type = \"string\";\n } else if (typeof value === \"number\") {\n type = \"number\";\n } else if (typeof value === \"boolean\") {\n type = \"boolean\";\n } else {\n // Fallback for unexpected literal types\n return {};\n }\n return { type, const: value };\n }\n\n // Unknown / unsupported TypeBox type: emit empty schema (accepts anything)\n // This is a safe fallback that allows the MCP tool to still receive input.\n console.warn(\n `[mcp-adapter] Unsupported TypeBox kind: ${(schema as Record<string, unknown>)[\"[Kind]\"] ?? \"(unknown)\"}. Emitting empty schema.`,\n );\n return {};\n}\n\n// ---------------------------------------------------------------------------\n// Input coercion: BigInt string -> BigInt\n// ---------------------------------------------------------------------------\n\n/**\n * Coerce MCP JSON input values to the types expected by a TypeBox schema.\n *\n * MCP transmits all values as JSON, which has no BigInt type. When the schema\n * expects a BigInt, the value arrives as a numeric string (e.g. \"12345678\").\n * This function recursively walks the schema and input, converting BigInt\n * string values to actual BigInt where needed.\n *\n * For all other types the value is passed through unchanged.\n */\nexport function coerceMcpInput(input: unknown, schema: TSchema): unknown {\n if (input === null || input === undefined) return input;\n\n if (isBigInt(schema)) {\n if (typeof input === \"bigint\") return input;\n if (typeof input === \"string\" && /^-?[0-9]+$/.test(input)) {\n try {\n return BigInt(input);\n } catch {\n return input;\n }\n }\n if (typeof input === \"number\") {\n try {\n return BigInt(Math.trunc(input));\n } catch {\n return input;\n }\n }\n return input;\n }\n\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n if (Array.isArray(input) && itemSchema) {\n return input.map((item) => coerceMcpInput(item, itemSchema));\n }\n return input;\n }\n\n if (isObject(schema)) {\n if (typeof input !== \"object\" || Array.isArray(input)) return input;\n const properties = schema.properties as Record<string, TSchema>;\n const result: Record<string, unknown> = { ...(input as Record<string, unknown>) };\n for (const [propName, propSchema] of Object.entries(properties)) {\n if (propName in result) {\n result[propName] = coerceMcpInput(result[propName], propSchema);\n }\n }\n return result;\n }\n\n if (isUnion(schema)) {\n // For unions, we try each member schema in order and return the first\n // successful coercion. BigInt members take priority over string members\n // since they have a narrower, unambiguous pattern.\n for (const member of schema.anyOf) {\n if (isBigInt(member)) {\n if (typeof input === \"string\" && /^-?[0-9]+$/.test(input)) {\n return coerceMcpInput(input, member);\n }\n }\n }\n // No BigInt match; return as-is for other union members\n return input;\n }\n\n // For all other types (String, Number, Integer, Boolean, Literal, Null):\n // pass through unchanged -- MCP JSON already represents them correctly\n return input;\n}\n\n// ---------------------------------------------------------------------------\n// Lazy MCP SDK import\n// ---------------------------------------------------------------------------\n\n/**\n * MCP SDK module shape (the parts we use from @modelcontextprotocol/sdk).\n * Typed loosely to avoid a hard dependency at compile time.\n */\ninterface IMcpSdkModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n McpServer: new (opts: { name: string; version: string }) => any;\n}\n\ninterface IStdioTransportModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StdioServerTransport: new () => any;\n}\n\n/**\n * Lazily import the MCP SDK server module.\n *\n * Throws a clear, actionable error if the SDK is not installed, rather than\n * a cryptic \"Cannot find module\" Node error.\n */\nexport async function getMcpSdk(): Promise<IMcpSdkModule> {\n try {\n return (await import(\n \"@modelcontextprotocol/sdk/server/mcp.js\"\n )) as IMcpSdkModule;\n } catch {\n throw new Error(\n \"MCP mode requires @modelcontextprotocol/sdk. Install it with: npm install @modelcontextprotocol/sdk\",\n );\n }\n}\n\n/**\n * Lazily import the MCP SDK stdio transport module.\n */\nasync function getMcpStdioTransport(): Promise<IStdioTransportModule> {\n try {\n return (await import(\n \"@modelcontextprotocol/sdk/server/stdio.js\"\n )) as IStdioTransportModule;\n } catch {\n throw new Error(\n \"MCP mode requires @modelcontextprotocol/sdk. Install it with: npm install @modelcontextprotocol/sdk\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// MCP server creation\n// ---------------------------------------------------------------------------\n\n/**\n * Create an MCP server and register all actions from a Sprinkle instance as\n * MCP tools.\n *\n * Each action becomes a tool with:\n * - name: action.name\n * - description: action.description\n * - input schema: typeboxToJsonSchema(action.inputSchema)\n * - handler: coerces input, executes action, returns JSON result\n *\n * The Sprinkle instance must already be initialized with a profile before\n * this function is called.\n *\n * @param sprinkle - Fully-initialized Sprinkle instance\n * @param serverName - Name to use for the MCP server\n * @returns The configured McpServer instance (not yet connected)\n */\nexport async function createMcpServer<S extends TSchema>(\n sprinkle: Sprinkle<S>,\n serverName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Promise<any> {\n const { McpServer } = await getMcpSdk();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const server = new McpServer({ name: serverName, version: PACKAGE_VERSION });\n\n const actions = sprinkle.listActions() as AnyAction<S>[];\n\n for (const action of actions) {\n const inputSchema = typeboxToJsonSchema(action.inputSchema);\n\n // Register the action as an MCP tool.\n // The high-level McpServer.tool() API accepts:\n // tool(name, description, schema, handler)\n server.tool(\n action.name,\n action.description,\n inputSchema,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (input: unknown): Promise<any> => {\n const coercedInput = coerceMcpInput(input, action.inputSchema);\n\n const context = {\n sprinkle,\n settings: sprinkle.settings,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = await executeAction(action as any, coercedInput, context as any);\n\n if (result.success) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(result.data, bigIntReplacer),\n },\n ],\n };\n } else {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(\n {\n error: {\n code: result.error.code,\n message: result.error.message,\n details: result.error.details,\n },\n },\n bigIntReplacer,\n ),\n },\n ],\n isError: true,\n };\n }\n },\n );\n }\n\n return server;\n}\n\n// ---------------------------------------------------------------------------\n// MCP orchestrator\n// ---------------------------------------------------------------------------\n\n/**\n * Start an MCP server on stdio transport.\n *\n * This function:\n * 1. Creates the MCP server and registers all actions as tools\n * 2. Creates a StdioServerTransport\n * 3. Connects the server to the transport\n *\n * IMPORTANT: All logging in this function goes to stderr. stdout is reserved\n * for the MCP protocol messages.\n *\n * The Sprinkle instance must already be initialized with a profile. Profile\n * initialization is the responsibility of the caller (Sprinkle.Run()).\n *\n * @param sprinkle - Fully-initialized Sprinkle instance\n * @param serverName - Name to use for the MCP server\n */\nexport async function runMcp<S extends TSchema>(\n sprinkle: Sprinkle<S>,\n serverName: string,\n): Promise<void> {\n const { StdioServerTransport } = await getMcpStdioTransport();\n\n const server = await createMcpServer(sprinkle, serverName);\n const transport = new StdioServerTransport();\n\n try {\n await server.connect(transport);\n } catch (err) {\n // Log errors to stderr only -- stdout is the MCP transport channel\n process.stderr.write(\n `[sprinkle-mcp] Failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n throw err;\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAeA,IAAAK,OAAA,GAAAL,OAAA;AAA4C,SAAAM,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,CAAAC,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA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;YACZsE,IAAI,EAAEC,IAAI,CAACC,SAAS,CAClB;cACEG,KAAK,EAAE;gBACLC,IAAI,EAAExE,MAAM,CAACuE,KAAK,CAACC,IAAI;gBACvBC,OAAO,EAAEzE,MAAM,CAACuE,KAAK,CAACE,OAAO;gBAC7BC,OAAO,EAAE1E,MAAM,CAACuE,KAAK,CAACG;cACxB;YACF,CAAC,EACDJ,0BACF;UACF,CAAC,CACF;UACDK,OAAO,EAAE;QACX,CAAC;MACH;IACF,CACF,CAAC;EACH;EAEA,OAAOtB,MAAM;AACf;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeuB,MAAMA,CAC1B1B,QAAqB,EACrBC,UAAkB,EACH;EACf,MAAM;IAAE0B;EAAqB,CAAC,GAAG,MAAM7B,oBAAoB,CAAC,CAAC;EAE7D,MAAMK,MAAM,GAAG,MAAMJ,eAAe,CAACC,QAAQ,EAAEC,UAAU,CAAC;EAC1D,MAAM2B,SAAS,GAAG,IAAID,oBAAoB,CAAC,CAAC;EAE5C,IAAI;IACF,MAAMxB,MAAM,CAAC0B,OAAO,CAACD,SAAS,CAAC;EACjC,CAAC,CAAC,OAAOE,GAAG,EAAE;IACZ;IACAC,OAAO,CAACC,MAAM,CAACC,KAAK,CAClB,8CAA8CH,GAAG,YAAYjC,KAAK,GAAGiC,GAAG,CAACP,OAAO,GAAGW,MAAM,CAACJ,GAAG,CAAC,IAChG,CAAC;IACD,MAAMA,GAAG;EACX;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"mcp-adapter.js","names":["_module","require","_url","_path","_encryption","_typeGuards","_runner","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","loadPackageVersion","createRequire","import","meta","url","__filename","fileURLToPath","__dirname","dirname","candidates","resolve","candidate","pkg","version","PACKAGE_VERSION","typeboxToJsonSchema","schema","isBigInt","type","pattern","description","isString","result","undefined","title","examples","minLength","maxLength","isSensitive","writeOnly","isNumber","minimum","maximum","isInteger","isBoolean","isNull","isArray","itemSchema","items","minItems","maxItems","isObject","properties","required","convertedProperties","propName","propSchema","entries","length","isUnion","anyOf","map","member","isLiteral","value","const","console","warn","coerceMcpInput","input","test","BigInt","Math","trunc","Array","item","_zod","getZod","mod","Promise","then","string","number","boolean","literal","v","object","shape","array","union","members","nullType","any","Error","typeboxToZod","z","_typeboxToZod","regex","s","describe","b","zodProp","isOptional","optional","typeboxToZodShape","getMcpSdk","getMcpStdioTransport","createMcpServer","sprinkle","serverName","McpServer","server","name","actions","listActions","action","zodShape","inputSchema","tool","coercedInput","context","settings","executeAction","success","content","text","JSON","stringify","data","bigIntReplacer","error","code","message","details","isError","runMcp","StdioServerTransport","transport","connect","err","process","stderr","write","String"],"sources":["../../../../src/Sprinkle/actions/mcp-adapter.ts"],"sourcesContent":["/**\n * MCP adapter for Sprinkles actions.\n *\n * Provides:\n * - TypeBox to JSON Schema conversion (typeboxToJsonSchema)\n * - TypeBox to Zod conversion for MCP SDK compatibility (typeboxToZod)\n * - BigInt string coercion for MCP input (coerceMcpInput)\n * - Lazy MCP SDK import with graceful error (getMcpSdk)\n * - MCP server creation from registered actions (createMcpServer)\n * - MCP orchestrator that starts a stdio server (runMcp)\n */\n\nimport { createRequire } from \"module\";\nimport { fileURLToPath } from \"url\";\nimport { dirname, resolve } from \"path\";\nimport type { TSchema } from \"@sinclair/typebox\";\nimport { bigIntReplacer } from \"../encryption.js\";\nimport {\n isArray,\n isBigInt,\n isBoolean,\n isInteger,\n isLiteral,\n isNull,\n isNumber,\n isObject,\n isOptional,\n isString,\n isUnion,\n isSensitive,\n} from \"../type-guards.js\";\nimport type { AnyAction } from \"./types.js\";\nimport { executeAction } from \"./runner.js\";\n\n// Re-import Sprinkle as a type only to avoid circular deps\nimport type { Sprinkle } from \"../index.js\";\n\n// Load package version for MCP server identification\n// Robustly find package.json - works from both src and dist directories\nfunction loadPackageVersion(): string {\n const require = createRequire(import.meta.url);\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n \n // Try multiple possible paths (handles src vs dist/esm vs dist/cjs)\n const candidates = [\n resolve(__dirname, \"../../../package.json\"), // from src/Sprinkle/actions\n resolve(__dirname, \"../../../../package.json\"), // from dist/*/Sprinkle/actions\n ];\n \n for (const candidate of candidates) {\n try {\n const pkg = require(candidate) as { version: string };\n return pkg.version;\n } catch {\n // Try next candidate\n }\n }\n \n return \"0.0.0\"; // Fallback if package.json not found\n}\n\nconst PACKAGE_VERSION: string = loadPackageVersion();\n\n// ---------------------------------------------------------------------------\n// TypeBox to JSON Schema conversion\n// ---------------------------------------------------------------------------\n\n/**\n * Convert a TypeBox schema to a plain JSON Schema object.\n *\n * Strips TypeBox-internal symbols and properties (Kind, OptionalKind, $id)\n * and maps TypeBox-specific types to their JSON Schema equivalents:\n * - BigInt -> { type: \"string\", pattern: \"^-?[0-9]+$\" } (JSON has no BigInt)\n * - Sensitive string fields -> add writeOnly: true\n * - Optional -> recurse on inner schema (Optional does not change Kind)\n * - Union -> { anyOf: [...] }\n * - Literal -> { type, const }\n * - Null -> { type: \"null\" }\n * - Unknown/unsupported -> {} (accepts anything)\n */\nexport function typeboxToJsonSchema(schema: TSchema): Record<string, unknown> {\n // Optional in TypeBox doesn't change the Kind, but marks the schema with\n // OptionalKind. We can check for it and recurse transparently since all\n // other guards still work correctly on optional-wrapped schemas.\n //\n // We intentionally do NOT strip optional here -- the containing Object\n // converter decides whether to include a property in `required` based\n // on the isOptional guard applied to the property schema.\n\n if (isBigInt(schema)) {\n return {\n type: \"string\",\n pattern: \"^-?[0-9]+$\",\n description: \"BigInt value as string\",\n };\n }\n\n if (isString(schema)) {\n const result: Record<string, unknown> = { type: \"string\" };\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.title !== undefined) result.title = schema.title;\n if (schema.examples !== undefined) result.examples = schema.examples;\n if (schema.pattern !== undefined) result.pattern = schema.pattern;\n if (schema.minLength !== undefined) result.minLength = schema.minLength;\n if (schema.maxLength !== undefined) result.maxLength = schema.maxLength;\n if (schema.default !== undefined) result.default = schema.default;\n // Sensitive fields are write-only (never returned in responses)\n if (isSensitive(schema)) result.writeOnly = true;\n return result;\n }\n\n if (isNumber(schema)) {\n const result: Record<string, unknown> = { type: \"number\" };\n if (schema.minimum !== undefined) result.minimum = schema.minimum;\n if (schema.maximum !== undefined) result.maximum = schema.maximum;\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.default !== undefined) result.default = schema.default;\n return result;\n }\n\n if (isInteger(schema)) {\n const result: Record<string, unknown> = { type: \"integer\" };\n if (schema.minimum !== undefined) result.minimum = schema.minimum;\n if (schema.maximum !== undefined) result.maximum = schema.maximum;\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.default !== undefined) result.default = schema.default;\n return result;\n }\n\n if (isBoolean(schema)) {\n const result: Record<string, unknown> = { type: \"boolean\" };\n if (schema.description !== undefined) result.description = schema.description;\n if (schema.default !== undefined) result.default = schema.default;\n return result;\n }\n\n if (isNull(schema)) {\n return { type: \"null\" };\n }\n\n if (isArray(schema)) {\n const result: Record<string, unknown> = { type: \"array\" };\n const itemSchema = (schema as { items?: TSchema }).items;\n if (itemSchema) {\n result.items = typeboxToJsonSchema(itemSchema);\n }\n if (schema.minItems !== undefined) result.minItems = schema.minItems;\n if (schema.maxItems !== undefined) result.maxItems = schema.maxItems;\n if (schema.description !== undefined) result.description = schema.description;\n return result;\n }\n\n if (isObject(schema)) {\n const properties = schema.properties as Record<string, TSchema>;\n const required: string[] = schema.required as string[] ?? [];\n const convertedProperties: Record<string, unknown> = {};\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n convertedProperties[propName] = typeboxToJsonSchema(propSchema);\n }\n\n const result: Record<string, unknown> = {\n type: \"object\",\n properties: convertedProperties,\n };\n\n if (required.length > 0) {\n result.required = required;\n }\n\n if (schema.description !== undefined) result.description = schema.description;\n\n return result;\n }\n\n if (isUnion(schema)) {\n return {\n anyOf: schema.anyOf.map((member: TSchema) => typeboxToJsonSchema(member)),\n };\n }\n\n if (isLiteral(schema)) {\n const value = schema.const;\n let type: string;\n if (typeof value === \"string\") {\n type = \"string\";\n } else if (typeof value === \"number\") {\n type = \"number\";\n } else if (typeof value === \"boolean\") {\n type = \"boolean\";\n } else {\n // Fallback for unexpected literal types\n return {};\n }\n return { type, const: value };\n }\n\n // Unknown / unsupported TypeBox type: emit empty schema (accepts anything)\n // This is a safe fallback that allows the MCP tool to still receive input.\n console.warn(\n `[mcp-adapter] Unsupported TypeBox kind: ${(schema as Record<string, unknown>)[\"[Kind]\"] ?? \"(unknown)\"}. Emitting empty schema.`,\n );\n return {};\n}\n\n// ---------------------------------------------------------------------------\n// Input coercion: BigInt string -> BigInt\n// ---------------------------------------------------------------------------\n\n/**\n * Coerce MCP JSON input values to the types expected by a TypeBox schema.\n *\n * MCP transmits all values as JSON, which has no BigInt type. When the schema\n * expects a BigInt, the value arrives as a numeric string (e.g. \"12345678\").\n * This function recursively walks the schema and input, converting BigInt\n * string values to actual BigInt where needed.\n *\n * For all other types the value is passed through unchanged.\n */\nexport function coerceMcpInput(input: unknown, schema: TSchema): unknown {\n if (input === null || input === undefined) return input;\n\n if (isBigInt(schema)) {\n if (typeof input === \"bigint\") return input;\n if (typeof input === \"string\" && /^-?[0-9]+$/.test(input)) {\n try {\n return BigInt(input);\n } catch {\n return input;\n }\n }\n if (typeof input === \"number\") {\n try {\n return BigInt(Math.trunc(input));\n } catch {\n return input;\n }\n }\n return input;\n }\n\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n if (Array.isArray(input) && itemSchema) {\n return input.map((item) => coerceMcpInput(item, itemSchema));\n }\n return input;\n }\n\n if (isObject(schema)) {\n if (typeof input !== \"object\" || Array.isArray(input)) return input;\n const properties = schema.properties as Record<string, TSchema>;\n const result: Record<string, unknown> = { ...(input as Record<string, unknown>) };\n for (const [propName, propSchema] of Object.entries(properties)) {\n if (propName in result) {\n result[propName] = coerceMcpInput(result[propName], propSchema);\n }\n }\n return result;\n }\n\n if (isUnion(schema)) {\n // For unions, we try each member schema in order and return the first\n // successful coercion. BigInt members take priority over string members\n // since they have a narrower, unambiguous pattern.\n for (const member of schema.anyOf) {\n if (isBigInt(member)) {\n if (typeof input === \"string\" && /^-?[0-9]+$/.test(input)) {\n return coerceMcpInput(input, member);\n }\n }\n }\n // No BigInt match; return as-is for other union members\n return input;\n }\n\n // For all other types (String, Number, Integer, Boolean, Literal, Null):\n // pass through unchanged -- MCP JSON already represents them correctly\n return input;\n}\n\n// ---------------------------------------------------------------------------\n// TypeBox to Zod conversion\n// ---------------------------------------------------------------------------\n\n/**\n * Zod module shape (the parts we use from zod).\n * Typed loosely since zod is a transitive dependency of @modelcontextprotocol/sdk,\n * not a direct dependency of Sprinkles.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ZodType = any;\ninterface IZodModule {\n string: () => ZodType;\n number: () => ZodType;\n boolean: () => ZodType;\n literal: (value: unknown) => ZodType;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n object: (shape: Record<string, any>) => ZodType;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n array: (item: any) => ZodType;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n union: (members: any[]) => ZodType;\n nullType: () => ZodType;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any: () => any;\n}\n\nlet _zod: IZodModule | undefined;\n\n/**\n * Lazily import the Zod module.\n * Zod is a transitive dependency of @modelcontextprotocol/sdk, so it's\n * guaranteed to be available when MCP mode is used.\n */\nasync function getZod(): Promise<IZodModule> {\n if (_zod) return _zod;\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const mod = (await import(\"zod\")) as any;\n _zod = {\n string: () => mod.string(),\n number: () => mod.number(),\n boolean: () => mod.boolean(),\n literal: (v: unknown) => mod.literal(v),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n object: (shape: Record<string, any>) => mod.object(shape),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n array: (item: any) => mod.array(item),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n union: (members: any[]) => mod.union(members),\n nullType: () => mod.nullType(),\n any: () => mod.any(),\n };\n return _zod;\n } catch {\n throw new Error(\n \"MCP mode requires zod (via @modelcontextprotocol/sdk). Install @modelcontextprotocol/sdk.\",\n );\n }\n}\n\n/**\n * Convert a TypeBox schema to a Zod schema for MCP SDK compatibility.\n *\n * The MCP SDK (v1.27+) expects Zod schemas for tool input validation,\n * not plain JSON Schema objects. This function converts TypeBox schemas\n * to their Zod equivalents so the SDK correctly registers tool parameters.\n *\n * BigInt fields are represented as z.string() with a regex pattern since\n * JSON (and thus MCP) has no BigInt type. The coerceMcpInput function\n * handles converting these string values back to BigInt at call time.\n */\nexport async function typeboxToZod(schema: TSchema): Promise<ZodType> {\n const z = await getZod();\n return _typeboxToZod(schema, z);\n}\n\nfunction _typeboxToZod(schema: TSchema, z: IZodModule): ZodType {\n if (isBigInt(schema)) {\n // BigInt -> string with regex pattern (JSON has no BigInt)\n return z.string().regex(/^-?[0-9]+$/);\n }\n\n if (isString(schema)) {\n let s = z.string();\n if (schema.description) s = s.describe(schema.description);\n return s;\n }\n\n if (isNumber(schema) || isInteger(schema)) {\n let n = z.number();\n if (schema.description) n = n.describe(schema.description);\n return n;\n }\n\n if (isBoolean(schema)) {\n let b = z.boolean();\n if (schema.description) b = b.describe(schema.description);\n return b;\n }\n\n if (isNull(schema)) {\n return z.nullType();\n }\n\n if (isLiteral(schema)) {\n return z.literal(schema.const);\n }\n\n if (isArray(schema)) {\n const itemSchema = (schema as { items?: TSchema }).items;\n if (itemSchema) {\n return z.array(_typeboxToZod(itemSchema, z));\n }\n return z.array(z.any());\n }\n\n if (isObject(schema)) {\n const properties = schema.properties as Record<string, TSchema>;\n const shape: Record<string, ZodType> = {};\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n let zodProp = _typeboxToZod(propSchema, z);\n if (isOptional(propSchema)) {\n zodProp = zodProp.optional();\n }\n shape[propName] = zodProp;\n }\n\n return z.object(shape);\n }\n\n if (isUnion(schema)) {\n const members = schema.anyOf.map((member: TSchema) =>\n _typeboxToZod(member, z),\n );\n if (members.length >= 2) {\n return z.union(members);\n }\n return members[0] ?? z.any();\n }\n\n // Fallback: accept anything\n return z.any();\n}\n\n/**\n * Convert a TypeBox object schema to a Zod \"raw shape\" (Record<string, ZodType>).\n * This is the format expected by the MCP SDK's tool() API.\n */\nexport async function typeboxToZodShape(\n schema: TSchema,\n): Promise<Record<string, ZodType>> {\n const z = await getZod();\n\n if (!isObject(schema)) {\n // Non-object input schemas get wrapped as { input: zodSchema }\n return { input: _typeboxToZod(schema, z) };\n }\n\n const properties = schema.properties as Record<string, TSchema>;\n const shape: Record<string, ZodType> = {};\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n let zodProp = _typeboxToZod(propSchema, z);\n if (isOptional(propSchema)) {\n zodProp = zodProp.optional();\n }\n shape[propName] = zodProp;\n }\n\n return shape;\n}\n\n// ---------------------------------------------------------------------------\n// Lazy MCP SDK import\n// ---------------------------------------------------------------------------\n\n/**\n * MCP SDK module shape (the parts we use from @modelcontextprotocol/sdk).\n * Typed loosely to avoid a hard dependency at compile time.\n */\ninterface IMcpSdkModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n McpServer: new (opts: { name: string; version: string }) => any;\n}\n\ninterface IStdioTransportModule {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StdioServerTransport: new () => any;\n}\n\n/**\n * Lazily import the MCP SDK server module.\n *\n * Throws a clear, actionable error if the SDK is not installed, rather than\n * a cryptic \"Cannot find module\" Node error.\n */\nexport async function getMcpSdk(): Promise<IMcpSdkModule> {\n try {\n return (await import(\n \"@modelcontextprotocol/sdk/server/mcp.js\"\n )) as IMcpSdkModule;\n } catch {\n throw new Error(\n \"MCP mode requires @modelcontextprotocol/sdk. Install it with: npm install @modelcontextprotocol/sdk\",\n );\n }\n}\n\n/**\n * Lazily import the MCP SDK stdio transport module.\n */\nasync function getMcpStdioTransport(): Promise<IStdioTransportModule> {\n try {\n return (await import(\n \"@modelcontextprotocol/sdk/server/stdio.js\"\n )) as IStdioTransportModule;\n } catch {\n throw new Error(\n \"MCP mode requires @modelcontextprotocol/sdk. Install it with: npm install @modelcontextprotocol/sdk\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// MCP server creation\n// ---------------------------------------------------------------------------\n\n/**\n * Create an MCP server and register all actions from a Sprinkle instance as\n * MCP tools.\n *\n * Each action becomes a tool with:\n * - name: action.name\n * - description: action.description\n * - input schema: typeboxToJsonSchema(action.inputSchema)\n * - handler: coerces input, executes action, returns JSON result\n *\n * The Sprinkle instance must already be initialized with a profile before\n * this function is called.\n *\n * @param sprinkle - Fully-initialized Sprinkle instance\n * @param serverName - Name to use for the MCP server\n * @returns The configured McpServer instance (not yet connected)\n */\nexport async function createMcpServer<S extends TSchema>(\n sprinkle: Sprinkle<S>,\n serverName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Promise<any> {\n const { McpServer } = await getMcpSdk();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const server = new McpServer({ name: serverName, version: PACKAGE_VERSION });\n\n const actions = sprinkle.listActions() as AnyAction<S>[];\n\n for (const action of actions) {\n const zodShape = await typeboxToZodShape(action.inputSchema);\n\n // Register the action as an MCP tool.\n // The high-level McpServer.tool() API accepts a Zod raw shape\n // (Record<string, ZodType>) for input validation.\n server.tool(\n action.name,\n action.description,\n zodShape,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (input: unknown): Promise<any> => {\n const coercedInput = coerceMcpInput(input, action.inputSchema);\n\n const context = {\n sprinkle,\n settings: sprinkle.settings,\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = await executeAction(action as any, coercedInput, context as any);\n\n if (result.success) {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(result.data, bigIntReplacer),\n },\n ],\n };\n } else {\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify(\n {\n error: {\n code: result.error.code,\n message: result.error.message,\n details: result.error.details,\n },\n },\n bigIntReplacer,\n ),\n },\n ],\n isError: true,\n };\n }\n },\n );\n }\n\n return server;\n}\n\n// ---------------------------------------------------------------------------\n// MCP orchestrator\n// ---------------------------------------------------------------------------\n\n/**\n * Start an MCP server on stdio transport.\n *\n * This function:\n * 1. Creates the MCP server and registers all actions as tools\n * 2. Creates a StdioServerTransport\n * 3. Connects the server to the transport\n *\n * IMPORTANT: All logging in this function goes to stderr. stdout is reserved\n * for the MCP protocol messages.\n *\n * The Sprinkle instance must already be initialized with a profile. Profile\n * initialization is the responsibility of the caller (Sprinkle.Run()).\n *\n * @param sprinkle - Fully-initialized Sprinkle instance\n * @param serverName - Name to use for the MCP server\n */\nexport async function runMcp<S extends TSchema>(\n sprinkle: Sprinkle<S>,\n serverName: string,\n): Promise<void> {\n const { StdioServerTransport } = await getMcpStdioTransport();\n\n const server = await createMcpServer(sprinkle, serverName);\n const transport = new StdioServerTransport();\n\n try {\n await server.connect(transport);\n } catch (err) {\n // Log errors to stderr only -- stdout is the MCP transport channel\n process.stderr.write(\n `[sprinkle-mcp] Failed to start MCP server: ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n throw err;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAeA,IAAAK,OAAA,GAAAL,OAAA;AAA4C,SAAAM,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,CAAAC,CAAA,E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