{"version":3,"file":"adapter.mjs","names":[],"sources":["../../../src/services/hosting/adapter.ts"],"sourcesContent":["import { Context, type Effect, Schema } from \"effect\";\n\n/**\n * The deploy console's single substrate coupling (ADR 0035): operating a\n * runtime instance — boot an image with identity env, observe it, restart it,\n * stop it — expressed in platform vocabulary only. No substrate resource\n * types, ports, networks, or machine ids cross this seam; implementations\n * return a URL and keep the derivation private.\n */\n\nexport interface RuntimeDescriptor {\n  /** Stable logical instance name, unique per hosting namespace. */\n  readonly instance: string;\n  /** OCI image reference, digest-pinned in production. */\n  readonly image: string;\n  /**\n   * Identity env forwarded verbatim (BOS_ACCOUNT / BOS_GATEWAY today). The\n   * adapter never interprets these values.\n   */\n  readonly identityEnv: Readonly<Record<string, string>>;\n}\n\nexport interface DeployedInstance {\n  readonly instance: string;\n  /** Where the instance serves traffic after a health-gated boot. */\n  readonly url: string;\n}\n\nexport interface InstanceSnapshot {\n  readonly instance: string;\n  readonly running: boolean;\n  /** Present only while the instance is running and health-known. */\n  readonly url: string | undefined;\n  readonly image: string | undefined;\n}\n\nexport class DeployFailed extends Schema.TaggedError<DeployFailed>()(\"DeployFailed\", {\n  instance: Schema.String,\n  reason: Schema.String,\n}) {}\n\nexport class HealthTimeout extends Schema.TaggedError<HealthTimeout>()(\"HealthTimeout\", {\n  instance: Schema.String,\n  url: Schema.String,\n  attempts: Schema.Finite,\n}) {}\n\nexport class InstanceNotFound extends Schema.TaggedError<InstanceNotFound>()(\"InstanceNotFound\", {\n  instance: Schema.String,\n}) {}\n\nexport class HostingOperationFailed extends Schema.TaggedError<HostingOperationFailed>()(\n  \"HostingOperationFailed\",\n  {\n    instance: Schema.String,\n    operation: Schema.String,\n    reason: Schema.String,\n  },\n) {}\n\nexport class HostingAdapter extends Context.Service<\n  HostingAdapter,\n  {\n    /**\n     * Converge the instance to the descriptor (idempotent for an unchanged\n     * descriptor), then health-gate before returning its URL.\n     */\n    deploy(\n      descriptor: RuntimeDescriptor,\n    ): Effect.Effect<DeployedInstance, DeployFailed | HealthTimeout>;\n    /** Observe the instance without mutating it. Unknown instances report `running: false`. */\n    current(instance: string): Effect.Effect<InstanceSnapshot, HostingOperationFailed>;\n    /**\n     * Restart the instance (starting it when stopped) and health-gate again.\n     * Fails for an instance that has never been deployed.\n     */\n    restart(\n      instance: string,\n    ): Effect.Effect<DeployedInstance, InstanceNotFound | HealthTimeout | HostingOperationFailed>;\n    /** Stop the instance. Fails for an instance that has never been deployed. */\n    stop(instance: string): Effect.Effect<void, InstanceNotFound | HostingOperationFailed>;\n  }\n>()(\"hosting/HostingAdapter\") {}\n\nexport type HostingAdapterService = HostingAdapter[\"Service\"];\n"],"mappings":";;;AAoCA,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAAC,gBAAgB;CACnF,UAAU,OAAO;CACjB,QAAQ,OAAO;AACjB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,gBAAb,cAAmC,OAAO,YAA2B,CAAC,CAAC,iBAAiB;CACtF,UAAU,OAAO;CACjB,KAAK,OAAO;CACZ,UAAU,OAAO;AACnB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAAC,oBAAoB,EAC/F,UAAU,OAAO,OACnB,CAAC,CAAC,CAAC,CAAC;AAEJ,IAAa,yBAAb,cAA4C,OAAO,YAAoC,CAAC,CACtF,0BACA;CACE,UAAU,OAAO;CACjB,WAAW,OAAO;CAClB,QAAQ,OAAO;AACjB,CACF,CAAC,CAAC,CAAC;AAEH,IAAa,iBAAb,cAAoC,QAAQ,QAsB1C,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC"}