{"version":3,"sources":["../src/errors.ts","../src/tool-authorization-internal.ts"],"names":["DOCS_BASE","formatError","code","message","hint","docsUrl","lines","AgentsKitError","options","ToolError","ErrorCodes","authorize","fn","call","context","decision"],"mappings":"aAIA,IAAMA,CAAAA,CAAY,+BAAA,CAalB,SAASC,CAAAA,CAAYC,EAAcC,CAAAA,CAAiBC,CAAAA,CAAeC,CAAAA,CAA0B,CAC3F,IAAMC,CAAAA,CAAkB,CAAC,CAAA,MAAA,EAASJ,CAAI,MAAMC,CAAO,CAAA,CAAE,CAAA,CACrD,OAAIC,CAAAA,EAAME,CAAAA,CAAM,IAAA,CAAK,CAAA,YAAA,EAAeF,CAAI,CAAA,CAAE,CAAA,CACtCC,CAAAA,EAASC,CAAAA,CAAM,KAAK,CAAA,YAAA,EAAeD,CAAO,CAAA,CAAE,CAAA,CACzCC,EAAM,IAAA,CAAK;AAAA,CAAI,CACxB,CAMO,IAAMC,CAAAA,CAAN,cAA6B,KAAM,CAMxC,WAAA,CAAYC,CAAAA,CAMT,CACD,MAAMA,CAAAA,CAAQ,OAAO,CAAA,CACrB,IAAA,CAAK,KAAO,gBAAA,CACZ,IAAA,CAAK,IAAA,CAAOA,CAAAA,CAAQ,KACpB,IAAA,CAAK,IAAA,CAAOA,CAAAA,CAAQ,IAAA,CACpB,KAAK,OAAA,CAAUA,CAAAA,CAAQ,OAAA,CACvB,IAAA,CAAK,MAAQA,CAAAA,CAAQ,MACvB,CAES,QAAA,EAAmB,CAC1B,OAAOP,CAAAA,CAAY,IAAA,CAAK,IAAA,CAAM,IAAA,CAAK,QAAS,IAAA,CAAK,IAAA,CAAM,IAAA,CAAK,OAAO,CACrE,CACF,CAAA,CAmBO,IAAMQ,CAAAA,CAAN,cAAwBF,CAAe,CAC5C,YAAYC,CAAAA,CAMT,CACD,MAAM,CAAE,OAAA,CAAS,CAAA,EAAGR,CAAS,gBAAiB,GAAGQ,CAAQ,CAAC,CAAA,CAC1D,KAAK,IAAA,CAAO,YACd,CACF,CAAA,CAuEO,IAAME,CAAAA,CAAa,CAWxB,iBAAA,CAAmB,mBA0BrB,CAAA,CC3LA,eAAsBC,CAAAA,CAAUC,EAAoBC,CAAAA,CAAgBC,CAAAA,CAAkD,CACpH,IAAIC,EACJ,GAAI,CAAEA,CAAAA,CAAW,MAAMH,EAAGC,CAAAA,CAAMC,CAAO,EAAE,CAAA,KAAQ,CAAEC,EAAW,OAAU,CACxE,GAAI,CAACA,GAAU,OAAA,CAAS,MAAM,IAAIN,CAAAA,CAAU,CAC1C,IAAA,CAAMC,CAAAA,CAAW,iBAAA,CACjB,OAAA,CAASK,GAAU,MAAA,EAAU,CAAA,MAAA,EAASF,EAAK,IAAI,CAAA,mBAAA,CACjD,CAAC,CACH","file":"tool-authorization-internal.cjs","sourcesContent":["// ---------------------------------------------------------------------------\n// AgentsKit didactic error system — Rust-compiler-style helpful errors\n// ---------------------------------------------------------------------------\n\nconst DOCS_BASE = 'https://www.agentskit.io/docs'\n\n/**\n * Format an error for display, Rust-compiler style.\n *\n * Example output:\n * ```\n * error[AK_ADAPTER_MISSING]: No adapter provided\n *   --> Hint: Pass an adapter when creating the chat controller, e.g.\n *             createChatController({ adapter: openai({ apiKey, model: 'gpt-4o' }) })\n *   --> Docs: https://www.agentskit.io/docs/data/providers\n * ```\n */\nfunction formatError(code: string, message: string, hint?: string, docsUrl?: string): string {\n  const lines: string[] = [`error[${code}]: ${message}`]\n  if (hint) lines.push(`  --> Hint: ${hint}`)\n  if (docsUrl) lines.push(`  --> Docs: ${docsUrl}`)\n  return lines.join('\\n')\n}\n\n// ---------------------------------------------------------------------------\n// Base class\n// ---------------------------------------------------------------------------\n\nexport class AgentsKitError extends Error {\n  readonly code: string\n  readonly hint: string | undefined\n  readonly docsUrl: string | undefined\n  readonly cause: unknown\n\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super(options.message)\n    this.name = 'AgentsKitError'\n    this.code = options.code\n    this.hint = options.hint\n    this.docsUrl = options.docsUrl\n    this.cause = options.cause\n  }\n\n  override toString(): string {\n    return formatError(this.code, this.message, this.hint, this.docsUrl)\n  }\n}\n\n// ---------------------------------------------------------------------------\n// Subclasses\n// ---------------------------------------------------------------------------\n\nexport class AdapterError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/data/providers`, ...options })\n    this.name = 'AdapterError'\n  }\n}\n\nexport class ToolError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/agents/tools`, ...options })\n    this.name = 'ToolError'\n  }\n}\n\nexport class MemoryError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/data/memory`, ...options })\n    this.name = 'MemoryError'\n  }\n}\n\nexport class ConfigError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/get-started/concepts/errors`, ...options })\n    this.name = 'ConfigError'\n  }\n}\n\nexport class RuntimeError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/agents/runtime`, ...options })\n    this.name = 'RuntimeError'\n  }\n}\n\nexport class SandboxError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/production/security/mandatory-sandbox`, ...options })\n    this.name = 'SandboxError'\n  }\n}\n\nexport class SkillError extends AgentsKitError {\n  constructor(options: {\n    code: string\n    message: string\n    hint?: string\n    docsUrl?: string\n    cause?: unknown\n  }) {\n    super({ docsUrl: `${DOCS_BASE}/agents/skills`, ...options })\n    this.name = 'SkillError'\n  }\n}\n\n// ---------------------------------------------------------------------------\n// Error code constants\n// ---------------------------------------------------------------------------\n\nexport const ErrorCodes = {\n  // Adapter errors\n  AK_ADAPTER_MISSING: 'AK_ADAPTER_MISSING',\n  AK_ADAPTER_STREAM_FAILED: 'AK_ADAPTER_STREAM_FAILED',\n\n  // Tool errors\n  AK_TOOL_NOT_FOUND: 'AK_TOOL_NOT_FOUND',\n  AK_TOOL_EXEC_FAILED: 'AK_TOOL_EXEC_FAILED',\n  AK_TOOL_PEER_MISSING: 'AK_TOOL_PEER_MISSING',\n  AK_TOOL_INVALID_INPUT: 'AK_TOOL_INVALID_INPUT',\n  AK_TOOL_QUOTA_EXCEEDED: 'AK_TOOL_QUOTA_EXCEEDED',\n  AK_TOOL_FORBIDDEN: 'AK_TOOL_FORBIDDEN',\n\n  // Memory errors\n  AK_MEMORY_LOAD_FAILED: 'AK_MEMORY_LOAD_FAILED',\n  AK_MEMORY_SAVE_FAILED: 'AK_MEMORY_SAVE_FAILED',\n  AK_MEMORY_DESERIALIZE_FAILED: 'AK_MEMORY_DESERIALIZE_FAILED',\n  AK_MEMORY_PEER_MISSING: 'AK_MEMORY_PEER_MISSING',\n  AK_MEMORY_REMOTE_HTTP: 'AK_MEMORY_REMOTE_HTTP',\n\n  // Config errors\n  AK_CONFIG_INVALID: 'AK_CONFIG_INVALID',\n\n  // Runtime errors\n  AK_RUNTIME_INVALID_INPUT: 'AK_RUNTIME_INVALID_INPUT',\n  AK_RUNTIME_STEP_FAILED: 'AK_RUNTIME_STEP_FAILED',\n  AK_RUNTIME_DELEGATE_FAILED: 'AK_RUNTIME_DELEGATE_FAILED',\n\n  // Sandbox errors\n  AK_SANDBOX_DENIED: 'AK_SANDBOX_DENIED',\n  AK_SANDBOX_INVALID_TOOL: 'AK_SANDBOX_INVALID_TOOL',\n  AK_SANDBOX_PEER_MISSING: 'AK_SANDBOX_PEER_MISSING',\n  AK_SANDBOX_BACKEND_FAILED: 'AK_SANDBOX_BACKEND_FAILED',\n\n  // Skill errors\n  AK_SKILL_INVALID: 'AK_SKILL_INVALID',\n  AK_SKILL_DUPLICATE: 'AK_SKILL_DUPLICATE',\n} as const\n","import { ErrorCodes, ToolError } from './errors'\nimport type { ToolAuthorizationContext, ToolAuthorizer, ToolCall } from './types'\n\nexport async function authorize(fn: ToolAuthorizer, call: ToolCall, context: ToolAuthorizationContext): Promise<void> {\n  let decision\n  try { decision = await fn(call, context) } catch { decision = undefined }\n  if (!decision?.allowed) throw new ToolError({\n    code: ErrorCodes.AK_TOOL_FORBIDDEN,\n    message: decision?.reason ?? `Tool \"${call.name}\" is not authorized`,\n  })\n}\n"]}