{"version":3,"file":"engine-BsCuBFKx.mjs","names":["wasmVerify","wasmVerifyDelegation","wasmRender","engineInfo","wasmEngineInfo","wasmVerifyStatusList","wasmRootNeeds","wasmApplyRuleBundle","wasmFeedDemand","wasmFeedAttemptFinished","wasmFeedStatus","wasmFeedNoteMiss","wasmVendorKeys"],"sources":["../src/engine/render-types.ts","../src/engine/index.ts"],"sourcesContent":["/**\n * Types and the envelope unwrap for the engine's kya-os/http renderer\n * (`render` / `engine_render_json` in `rust/crates/kya-os-engine/src/render`).\n *\n * The engine renders a `VerifyResult` into status, ordered headers and body.\n * Every binding (wasm, WASI, uniffi) returns the same `{ success, result |\n * error }` envelope; the bridges in `./index.ts`, `./node.ts` and `./edge.ts`\n * unwrap it and throw {@link EngineRenderError} on failure.\n *\n * The Node and bundler orchestrator builds export `renderDecisionAsResponse`\n * bound to these bridges (`./orchestrator/render-engine.ts`).\n */\n\nimport type { ChallengeWireErrorCode, ChallengeWireInput } from '@kya-os/checkpoint-shared';\n\nimport type { EngineInfo } from './types';\n\n/** Per-request host settings for the engine renderer. */\nexport interface EngineRenderOptions {\n  /** Serve the body-readable HTTP 200 for Challenge / Instruct (negotiated mode). */\n  bodyReadable200?: boolean;\n  /** Registered context for a canonical Delegation challenge. */\n  delegationChallenge?: ChallengeWireInput;\n  /** The host tried to resolve registered context and got none. */\n  challengeContextRequested?: boolean;\n}\n\n/** The rendered answer. `status: null` passes the request through. */\nexport interface EngineRenderedResponse {\n  status: number | null;\n  /** Ordered `[name, value]` pairs, applied in order. Names may repeat. */\n  headers: [name: string, value: string][];\n  body?: unknown;\n}\n\n/** The TS challenge-wire codes plus `invalid-input` for an unparseable input. */\nexport type EngineRenderErrorCode = ChallengeWireErrorCode | 'invalid-input';\n\n/** What every binding returns. */\nexport interface EngineRenderEnvelope {\n  success: boolean;\n  result?: EngineRenderedResponse;\n  error?: { code: EngineRenderErrorCode; message: string };\n}\n\n/** One control the engine enforces, and the engine version it arrived in. */\nexport interface EngineCapability {\n  id: string;\n  since: string;\n}\n\n/** The engine's self-description: attribution stamp plus capabilities. */\nexport interface EngineManifest {\n  manifestVersion: number;\n  engine: EngineInfo;\n  capabilities: EngineCapability[];\n}\n\n/** A typed render failure, with the same codes as `ChallengeWireError`. */\nexport class EngineRenderError extends TypeError {\n  readonly code: EngineRenderErrorCode;\n\n  constructor(code: EngineRenderErrorCode, message: string) {\n    super(message);\n    this.name = 'EngineRenderError';\n    this.code = code;\n  }\n}\n\n/** Unwrap a binding's envelope, throwing {@link EngineRenderError} on failure. */\nexport function unwrapRenderEnvelope(envelope: EngineRenderEnvelope): EngineRenderedResponse {\n  if (envelope.success && envelope.result) return envelope.result;\n  const error = envelope.error ?? {\n    code: 'invalid-input' as const,\n    message: 'engine returned no render result',\n  };\n  throw new EngineRenderError(error.code, error.message);\n}\n","/**\n * `kya-os-engine` WASM bridge — E-1 (#2486 follow-up).\n *\n * Loads the Rust `kya-os-engine` WASM artifact and surfaces a typed\n * `engineVerify(input, ctx)` wrapper around its single `verify` export.\n *\n * The engine is **synchronous** by contract. Host wrappers pre-fetch\n * every async dependency (DID document, status list, reputation,\n * tenant policy) and ship the results as a plain-data\n * [`ContextSpec`] (see `./types`). The WASM glue on the Rust side\n * builds in-memory lookup-table adapters that satisfy the engine's\n * five sync DI traits — no JS callbacks cross the boundary.\n *\n * ## Bundler-target import (SDK-Next.js-Integration-Audit-1 / #2618)\n *\n * This module imports the wasm-bindgen `--target bundler` output —\n * the artifact's entry does `import * as wasm from \"./*.wasm\"`, which\n * every modern bundler (Turbopack, Webpack 5 w/ asyncWebAssembly,\n * Vite, esbuild) handles natively. Switching from `--target nodejs`\n * obviates four prior workarounds:\n *\n *   1. The `(void 0)` esbuild tree-shake fix (read `.verify` at call\n *      time, not module-load) — bundler entry uses real ESM `export`,\n *      no CJS `exports.verify` to misread.\n *   2. The nodejs glue's `\"type\": \"commonjs\"` package.json pin\n *      — bundler entry is ESM by design.\n *   3. The tsup `onSuccess` copy of `.wasm` next to `dist/` — bundler\n *      entry's direct `import * as wasm from \"./*.wasm\"` lets the\n *      consumer's bundler resolve the artifact from `node_modules/`.\n *   4. The dynamic-loader `eval('typeof import.meta…')` runtime\n *      detection probes — bundler entry runs the same JS in every\n *      runtime; no detection needed.\n *\n * Node consumers are routed to the Node-safe bridge via the package\n * exports `\"node\"` condition on `./engine`; the generic bundler bridge\n * remains the default for bundlers that do not request Node resolution.\n */\n\n// Package self-import (resolved via this package's exports map\n// `./wasm/*` pattern). Using a self-import — rather than a path-\n// relative `../../wasm/…` — keeps the import string stable across\n// the source-vs-dist location boundary: when tsup bundles this file\n// into `dist/`, esbuild leaves the self-import literal in place\n// instead of trying to rewrite a relative path that no longer\n// resolves from the new output location.\nimport {\n  verify as wasmVerify,\n  verifyDelegation as wasmVerifyDelegation,\n  applyRuleBundle as wasmApplyRuleBundle,\n  feedDemand as wasmFeedDemand,\n  feedAttemptFinished as wasmFeedAttemptFinished,\n  feedStatus as wasmFeedStatus,\n  feedNoteMiss as wasmFeedNoteMiss,\n  vendorKeys as wasmVendorKeys,\n  render as wasmRender,\n  engineInfo as wasmEngineInfo,\n  verifyStatusList as wasmVerifyStatusList,\n  rootNeeds as wasmRootNeeds,\n} from '@kya-os/checkpoint-wasm-runtime/wasm/kya-os-engine-bundler/kya_os_engine.js';\nimport type { StatusListVerification } from './adapters/status-list-cache';\nimport type {\n  AdoptedVendorKeys,\n  AgentRequest,\n  ContextSpec,\n  DelegationVerifyInput,\n  FeedAttemptOutcome,\n  FeedDemandReason,\n  RootNeedsResult,\n  RuleBundleReport,\n  VendorKeyFeedStatus,\n  VendorKeyMissReason,\n  VerifyResult,\n} from './types';\nimport {\n  unwrapRenderEnvelope,\n  type EngineManifest,\n  type EngineRenderEnvelope,\n  type EngineRenderOptions,\n  type EngineRenderedResponse,\n} from './render-types';\n\n/**\n * Verify an AgentRequest synchronously against a pre-fetched\n * [`ContextSpec`].\n *\n * @throws {Error} if the WASM glue rejects the input (deserialisation\n *   failure) or the engine returns a `VerifyError` (resolver /\n *   status-list / reputation / policy infrastructure failure). Engine\n *   *verdicts* (Block / Challenge / etc.) DO NOT throw — they surface\n *   inside the returned [`VerifyResult`].\n */\nexport function engineVerify(input: AgentRequest, ctx: ContextSpec): VerifyResult {\n  return (wasmVerify as unknown as (i: AgentRequest, c: ContextSpec) => VerifyResult)(input, ctx);\n}\n\n/**\n * Verify a standalone delegation credential (VC-JWT) with **no request\n * signature** — the `Authorization: Bearer <DelegationCredential>` path,\n * `draft-kya-http-02` §4.3. The credential is passed explicitly (the engine\n * reads no transport header); the resource server's own org DID rides on\n * `ctx.resourceOrgDid`. Same throw semantics as [`engineVerify`].\n */\nexport function engineVerifyDelegation(\n  input: DelegationVerifyInput,\n  ctx: ContextSpec\n): VerifyResult {\n  return (\n    wasmVerifyDelegation as unknown as (i: DelegationVerifyInput, c: ContextSpec) => VerifyResult\n  )(input, ctx);\n}\n\n/**\n * Render the kya-os/http answer (status, ordered headers, body) for a\n * `VerifyResult`, in the engine. Same output on every runtime; see\n * `rust/crates/kya-os-engine/src/render`.\n *\n * @throws {EngineRenderError} when the registered challenge context fails\n *   validation (same codes as `ChallengeWireError`).\n */\nexport function engineRender(\n  result: VerifyResult,\n  options: EngineRenderOptions = {}\n): EngineRenderedResponse {\n  const envelope = (wasmRender as unknown as (input: unknown) => EngineRenderEnvelope)({\n    result,\n    options,\n  });\n  return unwrapRenderEnvelope(envelope);\n}\n\n/** This engine build's capability manifest. */\nexport function engineInfo(): EngineManifest {\n  return (wasmEngineInfo as unknown as () => EngineManifest)();\n}\n\nexport {\n  EngineRenderError,\n  type EngineCapability,\n  type EngineManifest,\n  type EngineRenderEnvelope,\n  type EngineRenderErrorCode,\n  type EngineRenderOptions,\n  type EngineRenderedResponse,\n} from './render-types';\n\nexport type {\n  ReinstateOutcome,\n  AdoptedVendorKey,\n  AdoptedVendorKeys,\n  AgentCard,\n  AgentCardSecurityScheme,\n  AgentRequest,\n  A2ARequest,\n  A2PRequest,\n  BehaviouralSignals,\n  BlockReason,\n  CalibrationCurve,\n  ChallengeParams,\n  ClientSignalAttribute,\n  ClientIntegrityInput,\n  ClientSignals,\n  ContextSpec,\n  Decision,\n  DelegationVerifyInput,\n  DetectionDetail,\n  DidDocument,\n  EngineConfig,\n  EngineInfo,\n  EnforcementMode,\n  FeedAttemptOutcome,\n  FeedDemandReason,\n  HttpSignedRequest,\n  InstructPayload,\n  IpReputation,\n  IsotonicCurve,\n  KeySetOutcome,\n  KeyType,\n  McpIPayload,\n  McpIRequest,\n  NetworkContext,\n  NoisyOrShadowMode,\n  PlainHttpRequest,\n  PlattCurve,\n  ProxyInfo,\n  ProxyType,\n  RedirectTarget,\n  RoutingType,\n  RuleBundleApplied,\n  RuleBundleRejected,\n  RuleBundleRejectionCode,\n  RuleBundleReport,\n  SessionVelocitySignal,\n  SignalsEnvelope,\n  StabilityTier,\n  SuggestedAction,\n  Tier1PolicyMode,\n  Tier3Action,\n  TransportSignals,\n  VendorKeyFeedKeyStatus,\n  VendorKeyFeedStatus,\n  VendorKeyMissReason,\n  VerificationMethod,\n  VerifyResult,\n} from './types';\n\n/**\n * Verify a fetched status list against its issuer's DID document, in the\n * engine (`verify_status_list`, design §3.5). `requestJson` is\n * `{ envelope: <body text>, url, issuer, didDocument: <did.json text> | null,\n * nowUnix }`. Never throws: a rejection is `{ ok: false, code, message }`.\n */\nexport function engineVerifyStatusList(requestJson: string): StatusListVerification {\n  return (wasmVerifyStatusList as unknown as (json: string) => StatusListVerification)(requestJson);\n}\n\n/**\n * The DID-document needs of the trusted roots in `contextJson` (only\n * `trustedDelegationRoots` is read), which a host that warms a cache\n * registers at startup. Never throws: bad input is `{ error }`.\n */\nexport function engineRootNeeds(contextJson: string): RootNeedsResult {\n  return (wasmRootNeeds as unknown as (json: string) => RootNeedsResult)(contextJson);\n}\n\nexport function engineApplyRuleBundle(bundleJson: string, nowUnix: number): RuleBundleReport {\n  return (wasmApplyRuleBundle as unknown as (json: string, now: number) => RuleBundleReport)(\n    bundleJson,\n    nowUnix\n  );\n}\n\nexport function engineFeedDemand(nowUnix: number): FeedDemandReason | undefined {\n  return (wasmFeedDemand as unknown as (now: number) => FeedDemandReason | undefined)(nowUnix);\n}\n\nexport function engineFeedAttemptFinished(outcome: FeedAttemptOutcome): boolean {\n  return (wasmFeedAttemptFinished as unknown as (outcome: string) => boolean)(outcome);\n}\n\nexport function engineFeedStatus(nowUnix: number): VendorKeyFeedStatus | null {\n  return (wasmFeedStatus as unknown as (now: number) => VendorKeyFeedStatus | null)(nowUnix);\n}\n\nexport function engineFeedNoteMiss(keyid: string, reason: VendorKeyMissReason): boolean {\n  return (wasmFeedNoteMiss as unknown as (keyid: string, reason: string) => boolean)(keyid, reason);\n}\n\nexport function engineVendorKeys(): AdoptedVendorKeys {\n  return (wasmVendorKeys as unknown as () => AdoptedVendorKeys)();\n}\n"],"mappings":";;;AA2DA,IAAa,oBAAb,cAAuC,UAAU;CAC/C;CAEA,YAAY,MAA6B,SAAiB;EACxD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;AAGA,SAAgB,qBAAqB,UAAwD;CAC3F,IAAI,SAAS,WAAW,SAAS,QAAQ,OAAO,SAAS;CACzD,MAAM,QAAQ,SAAS,SAAS;EAC9B,MAAM;EACN,SAAS;CACX;CACA,MAAM,IAAI,kBAAkB,MAAM,MAAM,MAAM,OAAO;AACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACcA,SAAgB,aAAa,OAAqB,KAAgC;CAChF,OAAQA,OAA4E,OAAO,GAAG;AAChG;;;;;;;;AASA,SAAgB,uBACd,OACA,KACc;CACd,OACEC,iBACA,OAAO,GAAG;AACd;;;;;;;;;AAUA,SAAgB,aACd,QACA,UAA+B,CAAC,GACR;CAKxB,OAAO,qBAJWC,OAAmE;EACnF;EACA;CACF,CAC4B,CAAQ;AACtC;;AAGA,SAAgBC,eAA6B;CAC3C,OAAQC,WAAmD;AAC7D;;;;;;;AA8EA,SAAgB,uBAAuB,aAA6C;CAClF,OAAQC,iBAA6E,WAAW;AAClG;;;;;;AAOA,SAAgB,gBAAgB,aAAsC;CACpE,OAAQC,UAA+D,WAAW;AACpF;AAEA,SAAgB,sBAAsB,YAAoB,SAAmC;CAC3F,OAAQC,gBACN,YACA,OACF;AACF;AAEA,SAAgB,iBAAiB,SAA+C;CAC9E,OAAQC,WAA4E,OAAO;AAC7F;AAEA,SAAgB,0BAA0B,SAAsC;CAC9E,OAAQC,oBAAoE,OAAO;AACrF;AAEA,SAAgB,iBAAiB,SAA6C;CAC5E,OAAQC,WAA0E,OAAO;AAC3F;AAEA,SAAgB,mBAAmB,OAAe,QAAsC;CACtF,OAAQC,aAA2E,OAAO,MAAM;AAClG;AAEA,SAAgB,mBAAsC;CACpD,OAAQC,WAAsD;AAChE"}