{"version":3,"file":"tool-schemas.mjs","names":[],"sources":["../../src/tool-schemas.ts"],"sourcesContent":["/**\n * Tool parameter schemas shared by every surface (MCP server, Pi and OMP\n * extensions). Each surface owns a different TypeBox build (the extensions\n * must use their host's facade), so the schemas are a factory over a minimal\n * structural builder instead of importing typebox here.\n */\n\n/**\n * The subset of the TypeBox builder the tool schemas need. `I` is the schema\n * type the builder accepts as input, `S` the (possibly narrower) type it\n * returns; OMP's facade accepts its own `AnySchema` while producing schemas\n * that satisfy the host's stricter `TSchema`.\n */\nexport interface McpSchemaBuilder<I, S> {\n  Object(properties: Readonly<Record<string, I>>, options?: object): S;\n  String(options?: object): I;\n  Integer(options?: object): I;\n  Boolean(options?: object): I;\n  Array(item: I, options?: object): I;\n  Record(key: I, value: I, options?: object): I;\n  Union(schemas: readonly I[], options?: object): I;\n  Literal(value: string, options?: object): I;\n  Optional(schema: I): I;\n}\n\nexport const HARNESS_INFO_MAX_ITEMS = 20;\nexport const RUN_TIMEOUT_DEFAULT_SECONDS = 600;\n\n/**\n * Builds the parameter schemas for all harness tools with the host's TypeBox.\n *\n * @param Type - Host-provided TypeBox-compatible schema builder.\n * @returns {Record<string, S>} Schemas keyed by harness tool operation.\n */\nexport function harnessToolSchemas<I, S>(Type: McpSchemaBuilder<I, S>) {\n  const harnessId = (description: string) =>\n    Type.String({ description, minLength: 1, maxLength: 50, pattern: \"^[a-z][a-z0-9-]*$\" });\n\n  const stringRecord = (description: string) =>\n    Type.Record(Type.String({ maxLength: 256 }), Type.String({ maxLength: 4096 }), {\n      description,\n    });\n\n  /**\n   * A closed object rejects a stray `read_only` instead of quietly running with every tool.\n   *\n   * @param properties - Declared tool arguments.\n   * @returns {S} An object schema that refuses undeclared keys.\n   */\n  const closed = (properties: Readonly<Record<string, I>>) =>\n    Type.Object(properties, { additionalProperties: false });\n\n  const scope = Type.Optional(\n    Type.Union([Type.Literal(\"user\"), Type.Literal(\"project\")], {\n      description: \"Which config file to target (default user)\",\n    }),\n  );\n\n  return {\n    /** Open on purpose: nothing to misread, and some models send a placeholder `_` here. */\n    detect: Type.Object({}),\n    info: closed({\n      id: Type.Union(\n        [\n          harnessId(\"Harness id\"),\n          Type.Array(harnessId(\"Harness id\"), {\n            minItems: 1,\n            maxItems: HARNESS_INFO_MAX_ITEMS,\n          }),\n        ],\n        { description: \"Harness id, or a list of ids to inspect in one call\" },\n      ),\n    }),\n    models: closed({\n      id: harnessId(\"Harness id\"),\n      search: Type.Optional(\n        Type.String({\n          description:\n            \"Optional model search filter; without a native one, ids match ignoring case\",\n          minLength: 1,\n          maxLength: 1024,\n        }),\n      ),\n      cwd: Type.Optional(\n        Type.String({\n          description: \"Working directory used while loading harness configuration\",\n          minLength: 1,\n          maxLength: 4096,\n        }),\n      ),\n      timeoutSeconds: Type.Optional(\n        Type.Integer({\n          description: `Wall-clock budget in seconds (default ${RUN_TIMEOUT_DEFAULT_SECONDS})`,\n          minimum: 1,\n          maximum: 3600,\n        }),\n      ),\n    }),\n    run: closed({\n      id: harnessId(\"Harness id\"),\n      prompt: Type.String({\n        description: \"Prompt to send to the harness\",\n        minLength: 1,\n        maxLength: 100000,\n      }),\n      cwd: Type.Optional(\n        Type.String({\n          description: \"Working directory for the run\",\n          minLength: 1,\n          maxLength: 4096,\n        }),\n      ),\n      model: Type.Optional(\n        Type.String({\n          description: \"Harness-native model id or selector\",\n          minLength: 1,\n          maxLength: 512,\n        }),\n      ),\n      effort: Type.Optional(\n        Type.String({\n          description:\n            \"Reasoning effort in the harness's own words, such as low or high. Harnesses without effortSelection in harnesses_info reject it.\",\n          minLength: 1,\n          maxLength: 32,\n          pattern: \"^[a-z]+$\",\n        }),\n      ),\n      timeoutSeconds: Type.Optional(\n        Type.Integer({\n          description: `Wall-clock budget in seconds (default ${RUN_TIMEOUT_DEFAULT_SECONDS})`,\n          minimum: 1,\n          maximum: 3600,\n        }),\n      ),\n      structured: Type.Optional(\n        Type.Boolean({\n          description: \"Use the harness's structured (JSON) output mode instead of plain text\",\n        }),\n      ),\n      tools: Type.Boolean({\n        description:\n          \"Explicit execution mode. Set true when the task needs any harness tools, including Grok native X search. Set false only for an advisor without tools.\",\n      }),\n      readOnly: Type.Optional(\n        Type.Boolean({\n          description:\n            \"Set with tools=true to require native read-only tool enforcement. Unsupported harnesses reject the run instead of widening access. The sandbox can also cut the network of what the harness starts, MCP servers included: when readOnlyNetwork in harnesses_info is false, MCP tools that need the web fail in that run.\",\n        }),\n      ),\n    }),\n    mcpList: closed({\n      id: Type.Optional(harnessId(\"Harness id; omit to list every harness\")),\n    }),\n    mcpSync: closed({\n      id: Type.Optional(harnessId(\"Harness id; omit to sync every harness\")),\n    }),\n    agentsSync: closed({\n      id: Type.Optional(harnessId(\"Harness id; omit to sync every harness\")),\n      check: Type.Optional(\n        Type.Boolean({ description: \"Report what would change without writing anything\" }),\n      ),\n    }),\n    promptsSync: closed({\n      id: Type.Optional(harnessId(\"Harness id; omit to sync every harness\")),\n      check: Type.Optional(\n        Type.Boolean({ description: \"Report what would change without writing anything\" }),\n      ),\n    }),\n    skillsSync: closed({\n      id: Type.Optional(harnessId(\"Harness id; omit to sync every harness\")),\n      check: Type.Optional(\n        Type.Boolean({ description: \"Report what would change without writing anything\" }),\n      ),\n    }),\n    mcpAdd: closed({\n      id: harnessId(\"Harness id\"),\n      name: Type.String({\n        description: \"Server name\",\n        minLength: 1,\n        maxLength: 100,\n        pattern: \"^[A-Za-z0-9][A-Za-z0-9_-]*$\",\n      }),\n      command: Type.Optional(\n        Type.String({ description: \"Binary for a stdio server\", minLength: 1, maxLength: 4096 }),\n      ),\n      args: Type.Optional(\n        Type.Array(Type.String({ maxLength: 4096 }), {\n          description: \"Arguments for a stdio server\",\n          maxItems: 64,\n        }),\n      ),\n      env: Type.Optional(stringRecord(\"Environment variables for a stdio server\")),\n      url: Type.Optional(\n        Type.String({ description: \"URL for an http/sse server\", minLength: 1, maxLength: 4096 }),\n      ),\n      transport: Type.Optional(\n        Type.Union([Type.Literal(\"stdio\"), Type.Literal(\"http\"), Type.Literal(\"sse\")], {\n          description: \"Transport; inferred from url/command when omitted\",\n        }),\n      ),\n      headers: Type.Optional(stringRecord(\"Headers for an http/sse server\")),\n      scope,\n    }),\n    mcpRemove: closed({\n      id: harnessId(\"Harness id\"),\n      name: Type.String({\n        description: \"Server name\",\n        minLength: 1,\n        maxLength: 100,\n      }),\n      scope,\n    }),\n  };\n}\n\n/**\n * Parameter types matching the schemas above. The generic factory erases the\n * builders' literal types, so hosts annotate their execute callbacks with\n * these instead of TypeBox Static inference.\n */\nexport interface InfoParams {\n  id: string | string[];\n}\n\nexport interface ModelsParams {\n  id: string;\n  search?: string;\n  cwd?: string;\n  timeoutSeconds?: number;\n}\n\nexport interface RunParams {\n  id: string;\n  prompt: string;\n  cwd?: string;\n  model?: string;\n  effort?: string;\n  timeoutSeconds?: number;\n  structured?: boolean;\n  tools: boolean;\n  readOnly?: boolean;\n}\n\nexport interface McpListParams {\n  id?: string;\n}\n\nexport interface McpSyncParams {\n  id?: string;\n}\n\nexport interface AgentsSyncParams {\n  id?: string;\n  check?: boolean;\n}\n\nexport interface PromptsSyncParams {\n  id?: string;\n  check?: boolean;\n}\n\nexport interface SkillsSyncParams {\n  id?: string;\n  check?: boolean;\n}\n\nexport interface McpAddParams {\n  id: string;\n  name: string;\n  command?: string;\n  args?: string[];\n  env?: Record<string, string>;\n  url?: string;\n  transport?: \"stdio\" | \"http\" | \"sse\";\n  headers?: Record<string, string>;\n  scope?: \"user\" | \"project\";\n}\n\nexport interface McpRemoveParams {\n  id: string;\n  name: string;\n  scope?: \"user\" | \"project\";\n}\n"],"mappings":";AAyBA,MAAa,yBAAyB;AACtC,MAAa,8BAA8B;AAQ3C,SAAgB,mBAAyB,MAA8B;CACrE,MAAM,aAAa,gBACjB,KAAK,OAAO;EAAE;EAAa,WAAW;EAAG,WAAW;EAAI,SAAS;CAAoB,CAAC;CAExF,MAAM,gBAAgB,gBACpB,KAAK,OAAO,KAAK,OAAO,EAAE,WAAW,IAAI,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