{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/extension/utils.ts"],"sourcesContent":["import type { AnyPadroneCommand, PadroneSchema } from '../types/index.ts';\n\ntype SchemaShape = Record<string, 'string' | 'string[]' | 'boolean'>;\n\ntype InferPassthroughSchema<T extends SchemaShape> = {\n  [K in keyof T]: T[K] extends 'string' ? string : T[K] extends 'string[]' ? string[] : T[K] extends 'boolean' ? boolean : never;\n};\n\n/** Minimal Standard Schema that passes through known fields, ignoring unknown ones. */\nexport function passthroughSchema<TShape extends SchemaShape>(fields: TShape): PadroneSchema<InferPassthroughSchema<TShape>> {\n  return {\n    '~standard': {\n      version: 1 as const,\n      vendor: 'padrone' as const,\n      jsonSchema: {\n        input: () => ({}),\n        output: () => ({}),\n      },\n      validate: (value) => {\n        const input = value && typeof value === 'object' ? (value as Record<string, unknown>) : {};\n        const result: Record<string, unknown> = {};\n        for (const [name, type] of Object.entries(fields)) {\n          const v = input[name];\n          if (v === undefined) continue;\n          if (type === 'string[]') {\n            if (Array.isArray(v)) result[name] = v.map(String);\n            else if (typeof v === 'string') result[name] = [v];\n          } else if (type === 'string') {\n            if (typeof v === 'string') result[name] = v;\n            else if (Array.isArray(v) && v.length > 0) result[name] = String(v[0]);\n          } else if (type === 'boolean') {\n            result[name] = v === true || v === 'true';\n          }\n        }\n        return { value: result as InferPassthroughSchema<TShape> };\n      },\n    },\n  };\n}\n\n/** Find a command by space-separated name in the command tree. */\nexport function findCommandInTree(name: string, rootCommand: AnyPadroneCommand): AnyPadroneCommand | undefined {\n  const parts = name.split(' ').filter(Boolean);\n  let current = rootCommand;\n  for (const part of parts) {\n    const found = current.commands?.find((c) => c.name === part || c.aliases?.includes(part));\n    if (!found) return undefined;\n    current = found;\n  }\n  return current;\n}\n"],"mappings":";;AASA,SAAgB,kBAA8C,QAA+D;CAC3H,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,YAAY;GACV,cAAc,CAAC;GACf,eAAe,CAAC;EAClB;EACA,WAAW,UAAU;GACnB,MAAM,QAAQ,SAAS,OAAO,UAAU,WAAY,QAAoC,CAAC;GACzF,MAAM,SAAkC,CAAC;GACzC,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,MAAM,GAAG;IACjD,MAAM,IAAI,MAAM;IAChB,IAAI,MAAM,KAAA,GAAW;IACrB,IAAI,SAAS;SACP,MAAM,QAAQ,CAAC,GAAG,OAAO,QAAQ,EAAE,IAAI,MAAM;UAC5C,IAAI,OAAO,MAAM,UAAU,OAAO,QAAQ,CAAC,CAAC;IAAA,OAC5C,IAAI,SAAS;SACd,OAAO,MAAM,UAAU,OAAO,QAAQ;UACrC,IAAI,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,QAAQ,OAAO,EAAE,EAAE;IAAA,OAChE,IAAI,SAAS,WAClB,OAAO,QAAQ,MAAM,QAAQ,MAAM;GAEvC;GACA,OAAO,EAAE,OAAO,OAAyC;EAC3D;CACF,EACF;AACF;;AAGA,SAAgB,kBAAkB,MAAc,aAA+D;CAC7G,MAAM,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC5C,IAAI,UAAU;CACd,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,QAAQ,UAAU,MAAM,MAAM,EAAE,SAAS,QAAQ,EAAE,SAAS,SAAS,IAAI,CAAC;EACxF,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,UAAU;CACZ;CACA,OAAO;AACT"}