@byollm/server 0.1.0-alpha.7 → 0.1.0-alpha.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/app.ts","../src/cloud.ts","../src/keys.ts","../src/memory.ts"],"sourcesContent":["import {\n ENVELOPE_MAX_AGE_MS,\n KindedPayload,\n keyId,\n payloadTextLength,\n publicIdentityOf,\n seal,\n sizeClassOf,\n type StoredKeys,\n backendDescriptor,\n matchAudience,\n type DeliveredResult,\n type JobKind,\n} from \"@byollm/protocol\";\nimport {\n PollingDelivery,\n type PollingDeliveryDeps,\n type ResultDelivery,\n type WaitOptions,\n} from \"./delivery.js\";\nimport {\n generateJobId,\n generateRunnerId,\n generateRunnerToken,\n hashSecret,\n} from \"./ids.js\";\nimport { CloudLane, type CloudLaneOptions } from \"./cloud.js\";\nimport type { EnqueueInput, JobRecord, RunnerRecord } from \"./records.js\";\nimport type { ByollmStore } from \"./store.js\";\n\n/**\n * How long since a runner's last heartbeat before it stops counting as live.\n * Three heartbeats of slack at the daemon's ~10s cadence.\n */\nconst DEFAULT_LIVENESS_MS = 35_000;\n\n/** Why a job cannot presently run. */\nexport type NoRunnerReason =\n | \"no-runner-paired\"\n | \"no-runner-online\"\n | \"no-matching-capability\"\n | \"audience-admits-nobody\";\n\n/**\n * The no-runner signal (byollm_001 Rev 1 §D).\n *\n * `available: false` means an app should fall back — hosted model, \"start\n * your runner\" prompt — rather than awaiting something that will never\n * resolve. A job still blocked on dependencies is **not** unavailable; it is\n * waiting, and saying otherwise would make every multi-job flow look broken\n * ({@link MUSTS.NO_RUNNER_SIGNAL}).\n */\nexport interface RunnerAvailability {\n readonly available: boolean;\n readonly reason?: NoRunnerReason;\n /** Live runners that could take work of this shape. */\n readonly candidates: number;\n}\n\nexport interface AvailabilityQuery {\n readonly kind: JobKind;\n readonly owner: string;\n readonly audience?: \"self\" | \"named\" | \"public\";\n readonly audienceAllow?: readonly string[];\n}\n\nexport interface ByollmAppOptions {\n readonly store: ByollmStore;\n /** Injectable clock. */\n readonly now?: () => number;\n /** Liveness window for the no-runner signal. */\n readonly livenessMs?: number;\n /**\n * How the app learns a job finished. Defaults to polling the store, which\n * is correct everywhere; the Supabase adapter substitutes Realtime.\n */\n readonly delivery?: (deps: PollingDeliveryDeps) => ResultDelivery;\n /**\n * How long a sustained no-runner signal must persist before `result()`\n * gives up. Longer tolerates a daemon restarting; shorter fails faster.\n */\n readonly noRunnerGraceMs?: number;\n /**\n * This site's keypairs — the same ones the handlers use.\n *\n * The app needs them because it is the *endpoint*: it seals work on the way\n * in and opens results on the way out. Nothing between those two points\n * holds plaintext (byollm_009 §10).\n */\n readonly siteKeys: StoredKeys;\n /**\n * Which connection plane this site uses — cloud_004 §9.4.\n *\n * Omitted means `direct`: a daemon reaches this site's own handlers, and\n * everything works as it always has. Supplying a relay switches the plane\n * and nothing else — `enqueue` is identical in every lane, which is the\n * property that lets the same app move between them by config.\n */\n readonly lane?: CloudLaneOptions;\n}\n\n/**\n * An enqueued job, with the delivery channel attached.\n *\n * `result()` is sugar over the channel — with a timeout and a\n * `noRunnerAvailable` path — never a bare promise that can hang forever\n * (byollm_003 Rev 1).\n */\nexport interface JobHandle {\n readonly id: string;\n /** The job as stored at enqueue time. */\n readonly record: JobRecord;\n /** Wait for a terminal outcome. */\n result(options?: WaitOptions): Promise<DeliveredResult>;\n /** Ask the runner to stop. */\n cancel(): Promise<void>;\n}\n\n/**\n * The app-facing half of `@byollm/server`.\n *\n * The daemon talks to {@link ByollmHandlers}; the app talks to this. Keeping\n * them separate is what makes \"one door per state write\" hold — an app\n * enqueues and cancels through these methods and never writes job rows by\n * hand.\n */\nexport class ByollmApp {\n readonly #store: ByollmStore;\n readonly #siteKeys: StoredKeys;\n readonly #now: () => number;\n readonly #livenessMs: number;\n readonly #delivery: ResultDelivery;\n /** Present only in the cloud lane; the site's side of the relay. */\n readonly cloud: CloudLane | undefined;\n\n constructor(options: ByollmAppOptions) {\n this.#store = options.store;\n this.#siteKeys = options.siteKeys;\n this.#now = options.now ?? Date.now;\n this.#livenessMs = options.livenessMs ?? DEFAULT_LIVENESS_MS;\n this.cloud =\n options.lane === undefined\n ? undefined\n : new CloudLane({\n options: options.lane,\n store: options.store,\n siteKeys: options.siteKeys,\n now: this.#now,\n });\n\n const deps: PollingDeliveryDeps = {\n ...(options.noRunnerGraceMs === undefined\n ? {}\n : { graceMs: options.noRunnerGraceMs }),\n read: (jobId) => this.result(jobId),\n availability: async (jobId) => {\n const job = await this.#store.get(jobId);\n if (!job)\n return { available: false, reason: \"unknown-job\", blocked: false };\n // A job waiting on a dependency is waiting, not unavailable.\n if (job.claimableAt === null) {\n return { available: true, blocked: true };\n }\n const availability = await this.runnerAvailability({\n kind: job.kind,\n owner: job.owner,\n audience: job.audience,\n ...(job.audienceAllow === undefined\n ? {}\n : { audienceAllow: job.audienceAllow }),\n });\n return {\n available: availability.available,\n ...(availability.reason === undefined\n ? {}\n : { reason: availability.reason }),\n blocked: false,\n };\n },\n };\n this.#delivery = options.delivery?.(deps) ?? new PollingDelivery(deps);\n }\n\n /**\n * Enqueue a job.\n *\n * `audience` defaults to `self` — the safe direction. Widening it means the\n * result comes back marked untrusted (see {@link ByollmApp.result}), and\n * the app is obliged to disclose that to whoever reads it.\n */\n async enqueue(input: EnqueueInput): Promise<JobHandle> {\n // Validate the payload against its kind before anything stores it.\n //\n // The schemas are `.strict()`, so this drops a payload carrying fields\n // the kind does not define — `command`, `argv`, `model`, `baseUrl`. Types\n // do not survive a JSON boundary, and an app assembling a payload from\n // user input is the ordinary case, so \"the caller is typed\" is not a\n // check ({@link MUSTS.KIND_NO_CODE}, {@link MUSTS.NO_PAYLOAD_ROUTING}).\n //\n // Refusing here rather than relying on the daemon is deliberate. The\n // daemon does re-validate and would reject this — but it parses a whole\n // claim response at once, so one malformed job would fail the batch it\n // arrived in and stall unrelated work. Rejecting at enqueue puts the\n // error where the app can act on it.\n const parsed = KindedPayload.safeParse({\n kind: input.kind,\n payload: input.payload,\n });\n if (!parsed.success) {\n const detail = parsed.error.issues\n .map((issue) => `${issue.path.join(\".\") || \"(root)\"}: ${issue.message}`)\n .join(\"; \");\n throw new Error(`invalid ${input.kind} payload — ${detail}`);\n }\n\n // Sealed before it is stored, to this site's own key. The app is the\n // endpoint, so it can open its own work later; the store, its backups and\n // anything reading them cannot.\n // Two different deadlines, deliberately not conflated:\n //\n // - the *job's* deadline is the app's business, may be absent, and for a\n // dependent job its TTL clock does not even start until the job becomes\n // claimable (`TTL_EXPIRY`). Setting one here broke exactly that.\n // - the *envelope's* deadline bounds how long a captured ciphertext is\n // worth keeping. It is bound into the signature, so it has to be\n // recomputable at open time from what the record stores — hence\n // creation plus TTL, which never moves.\n // Resolved *here*, once, and passed to the store — because the envelope\n // binds it. Letting the app default one value and the store default\n // another produced a job whose seal and record disagreed, and therefore\n // work nobody could open.\n // One reading of the clock, used for both the seal and the record.\n //\n // Two readings passed every fake-clock test and failed against a real\n // one: the envelope bound `createdAt + ttlMs` from the first call and the\n // record stored `createdAt` from the second, a millisecond later, so\n // nothing could be opened. A fixed clock returns the same number twice\n // and hides it completely.\n const createdAt = this.#now();\n // Independent of the job's TTL, deliberately. Binding the envelope to\n // `createdAt + ttl` meant the app had to decide a TTL in order to seal —\n // which overrode the store's own default and broke every expiry test.\n // The two answer different questions: how long the work is worth doing,\n // and how long the ciphertext is worth keeping.\n const envelopeDeadlineAt = createdAt + ENVELOPE_MAX_AGE_MS;\n const jobId = input.id ?? generateJobId();\n const senderKeyId = keyId(publicIdentityOf(this.#siteKeys).identity);\n const envelope = await seal({\n plaintext: JSON.stringify(parsed.data.payload),\n senderKeys: this.#siteKeys,\n recipientEncryptionPublic: this.#siteKeys.encryptionPublic,\n context: {\n jobId,\n senderKeyId,\n recipientKeyId: senderKeyId,\n deadlineAt: envelopeDeadlineAt,\n direction: \"payload\",\n },\n });\n\n const record = await this.#store.create(\n {\n ...input,\n id: jobId,\n envelope,\n sizeClass: sizeClassOf(\n payloadTextLength({\n kind: input.kind,\n payload: parsed.data.payload,\n } as Parameters<typeof payloadTextLength>[0]),\n ),\n },\n createdAt,\n );\n // The lane's only intrusion into enqueue, and it is additive: the record\n // is already stored and sealed at rest before anything is published, so a\n // relay that is down costs a routing delay rather than a lost job.\n await this.cloud?.publish(record);\n\n return {\n id: record.id,\n record,\n result: (options?: WaitOptions) =>\n this.#delivery.waitFor(record.id, options),\n cancel: async () => {\n await this.cancel(record.id);\n },\n };\n }\n\n /** Read a job's current state. */\n async job(jobId: string): Promise<JobRecord | null> {\n await this.#store.expireDue(this.#now());\n return this.#store.get(jobId);\n }\n\n /**\n * A job's result with its provenance attached.\n *\n * Check `provenance.untrusted` before rendering. It is true for every\n * `named`/`public` job, because that text came from someone else's machine\n * and the app must not present it as its own AI's answer\n * ({@link MUSTS.RESULT_PROVENANCE}).\n */\n async result(jobId: string): Promise<DeliveredResult | null> {\n const job = await this.job(jobId);\n if (!job) return null;\n return {\n jobId: job.id,\n state: job.state,\n ...(job.outcome === null ? {} : { outcome: job.outcome }),\n ...(job.provenance === null ? {} : { provenance: job.provenance }),\n };\n }\n\n /** Ask a runner to stop. Queued jobs cancel at once; held jobs at the next heartbeat. */\n async cancel(jobId: string): Promise<JobRecord | null> {\n return this.#store.cancel(jobId, this.#now());\n }\n\n /**\n * Is there a live runner that could take a job of this shape?\n *\n * Runs the identical {@link matchAudience} rule the claim path uses, so the\n * signal cannot promise a runner the claim would then refuse.\n */\n async runnerAvailability(\n query: AvailabilityQuery,\n ): Promise<RunnerAvailability> {\n const now = this.#now();\n const all = await this.#store.listRunners();\n const live = all.filter(\n (runner) =>\n runner.revokedAt === null &&\n !runner.paused &&\n now - runner.lastHeartbeatAt <= this.#livenessMs,\n );\n\n if (all.length === 0) {\n return { available: false, reason: \"no-runner-paired\", candidates: 0 };\n }\n if (live.length === 0) {\n return { available: false, reason: \"no-runner-online\", candidates: 0 };\n }\n\n let capable = 0;\n let admitted = 0;\n for (const runner of live) {\n const capability = runner.capabilities.find((c) => c.kind === query.kind);\n if (!capability) continue;\n capable += 1;\n\n const match = matchAudience(\n {\n owner: query.owner,\n audience: query.audience ?? \"self\",\n audienceAllow: query.audienceAllow,\n },\n {\n owner: runner.owner,\n offerScope: capability.offerScope,\n // A generic backend's cost depends on its base URL, which the\n // server never sees; assume the expensive reading (byollm_007 §4).\n cost: backendDescriptor(capability.backendId).cost ?? \"metered\",\n // Consent is the daemon's to hold, and it has already applied it:\n // the offer scope arriving here is the *effective* one, so a\n // metered backend nobody agreed to share advertises `self` and is\n // refused by the scope rule above. Re-deriving consent from\n // `false` here would instead refuse every backend an owner\n // deliberately shared, because the server has no way to learn they\n // did — the signal would be wrong in the direction that breaks\n // working setups.\n spend: { acknowledged: true },\n // Same conservative assumption the claim path makes: the server\n // cannot see a remote daemon's local allowlist (protocol §4.2).\n locallyAllows: () => true,\n },\n );\n if (match.ok) admitted += 1;\n }\n\n if (capable === 0) {\n return {\n available: false,\n reason: \"no-matching-capability\",\n candidates: 0,\n };\n }\n if (admitted === 0) {\n return {\n available: false,\n reason: \"audience-admits-nobody\",\n candidates: 0,\n };\n }\n return { available: true, candidates: admitted };\n }\n\n /**\n * Approve a pairing on behalf of an authenticated user.\n *\n * `owner` MUST come from the approving user's own session. A daemon can\n * never assert who it is — that is the whole reason pairing is interactive\n * ({@link MUSTS.PAIR_ONE_USER}, {@link MUSTS.PAIR_INTERACTIVE}).\n */\n async approvePairing(args: {\n userCode: string;\n owner: string;\n }): Promise<RunnerRecord> {\n const token = generateRunnerToken();\n return this.#store.approvePairing({\n userCode: normalizeUserCode(args.userCode),\n owner: args.owner,\n runnerId: generateRunnerId(),\n runnerToken: token,\n tokenHash: hashSecret(token),\n now: this.#now(),\n });\n }\n\n /** Deny a pairing the user did not initiate. */\n async denyPairing(userCode: string): Promise<void> {\n return this.#store.denyPairing(normalizeUserCode(userCode), this.#now());\n }\n\n /** What a pairing code refers to, for the approval page to show. */\n async pendingPairing(userCode: string): Promise<{\n label: string;\n platform: string;\n daemonVersion: string;\n capabilities: readonly { kind: string; model: string }[];\n expiresAt: number;\n } | null> {\n const pairing = await this.#store.getPairingByUserCode(\n normalizeUserCode(userCode),\n );\n if (pairing?.state !== \"pending\") return null;\n if (pairing.expiresAt <= this.#now()) return null;\n return {\n label: pairing.label,\n platform: pairing.platform,\n daemonVersion: pairing.daemonVersion,\n capabilities: pairing.capabilities.map((c) => ({\n kind: c.kind,\n model: c.model,\n })),\n expiresAt: pairing.expiresAt,\n };\n }\n\n /** The user's paired runners, for a settings page. */\n async runners(owner: string): Promise<RunnerRecord[]> {\n return this.#store.listRunners(owner);\n }\n\n /** Revoke a runner. It stops at its next heartbeat, mid-queue. */\n async revokeRunner(runnerId: string): Promise<void> {\n return this.#store.revokeRunner(runnerId, this.#now());\n }\n\n /** Run the expiry sweep. Idempotent; safe to call on a timer or a request. */\n async sweep(): Promise<JobRecord[]> {\n return this.#store.expireDue(this.#now());\n }\n}\n\n/**\n * Accept a pairing code however the user typed it — lowercase, spaces, no\n * dash. The code is displayed as `XXXX-XXXX`; refusing `xxxxxxxx` would fail\n * a user for a formatting detail they were never told mattered.\n */\nexport function normalizeUserCode(input: string): string {\n const bare = input.toUpperCase().replace(/[^A-Z0-9]/g, \"\");\n return bare.length === 8 ? `${bare.slice(0, 4)}-${bare.slice(4)}` : bare;\n}\n","import {\n JobOutcome,\n type SealedEnvelope,\n keyId,\n open,\n publicIdentityOf,\n provenanceFor,\n type JobStub,\n type PublicIdentity,\n type StoredKeys,\n} from \"@byollm/protocol\";\nimport type { JobRecord } from \"./records.js\";\nimport { resealForDevice } from \"./reseal.js\";\nimport type { ByollmStore } from \"./store.js\";\n\n/**\n * The cloud lane — cloud_004 §9.4.\n *\n * `app.enqueue(...)` is identical in every lane; the lane picks the connection\n * plane. In `direct` mode a daemon reaches the site's own handlers. In `cloud`\n * mode it reaches a relay instead, and the site's side of that is this file.\n *\n * ## What actually changes, and what deliberately does not\n *\n * Enqueue does not change at all. The job is validated, sealed at rest to the\n * site's own key and stored, exactly as before — jobs-at-rest encryption is a\n * direct-mode property that the cloud lane inherits rather than replaces.\n *\n * What changes is *who asks for the payload and when*. On the direct plane the\n * daemon asks, and the site answers synchronously because it is the upstream.\n * Through a relay the site is not the upstream, so nobody asks: the site has to\n * find out that a device claimed its job, and seal to that device. Hence a\n * pump rather than a handler.\n *\n * ```\n * enqueue ──stub──▶ relay (payload stays here, sealed at rest)\n * │\n * pump ◀──who claimed it, and what key?\n * ──payload sealed to that device──▶\n * pump ◀──sealed result── ──▶ store.complete → the app's delivery channel\n * ```\n *\n * ## Why the site polls\n *\n * Everything in this product is outbound. A relay that called site webhooks\n * would need every site publicly reachable, which is the connectivity problem\n * the hub exists to remove — and a serverless site has nowhere to receive a\n * webhook anyway. So the site polls, exactly as a daemon does.\n */\n\nexport interface CloudLaneOptions {\n /** Where the relay lives, e.g. `https://relay.byollm.cloud`. */\n readonly relayOrigin: string;\n /** This site's id at the relay. */\n readonly siteId: string;\n /** Injectable fetch, for tests and for proxies. */\n readonly fetch?: typeof fetch;\n}\n\n/** What one pump cycle did, for logging and for tests. */\nexport interface PumpReport {\n /** Jobs sealed to a claiming device this cycle. */\n readonly sealed: string[];\n /** Results opened, verified and written to the store. */\n readonly completed: string[];\n /**\n * Jobs the relay offered that this site refused to seal for.\n *\n * Never silent: a site that cannot open its own at-rest envelope has a key\n * problem, and a device waiting on a payload that will never come is\n * exactly the case `awaiting-payload` exists to bound.\n */\n readonly refused: string[];\n}\n\nexport class CloudLane {\n readonly #options: CloudLaneOptions;\n readonly #store: ByollmStore;\n readonly #siteKeys: StoredKeys;\n readonly #now: () => number;\n readonly #fetch: typeof fetch;\n\n constructor(deps: {\n options: CloudLaneOptions;\n store: ByollmStore;\n siteKeys: StoredKeys;\n now: () => number;\n }) {\n this.#options = deps.options;\n this.#store = deps.store;\n this.#siteKeys = deps.siteKeys;\n this.#now = deps.now;\n this.#fetch = deps.options.fetch ?? globalThis.fetch;\n }\n\n /**\n * Publish a job's stub for routing.\n *\n * The stub and nothing else — byollm_009 §6 makes that exhaustive by\n * construction, so this cannot leak a payload even by mistake: there is no\n * field on `JobStub` to put one in.\n */\n async publish(record: JobRecord): Promise<void> {\n const stub: JobStub = {\n id: record.id,\n kind: record.kind,\n owner: record.owner,\n audience: record.audience,\n ...(record.audienceAllow === undefined\n ? {}\n : { audienceAllow: [...record.audienceAllow] }),\n sizeClass: record.sizeClass,\n streaming: false,\n // The relay needs *a* deadline to bound routing. A job without one gets\n // the envelope's, which is the outer bound on how long the ciphertext\n // is worth carrying — never longer than the work could possibly matter.\n deadlineAt: record.deadlineAt ?? record.createdAt + ENVELOPE_TTL_FALLBACK,\n };\n await this.#post(\"/relay/site/enqueue\", {\n siteId: this.#options.siteId,\n stub,\n });\n }\n\n /**\n * One cycle: seal for anything claimed, collect anything finished.\n *\n * Idempotent and safe to call as often as you like. Exposed as a single\n * cycle rather than hidden behind a timer so a caller decides its own\n * cadence — a serverless site runs it on a cron, a long-lived one on an\n * interval, and a test runs it exactly when it means to.\n */\n async pump(): Promise<PumpReport> {\n const sealed: string[] = [];\n const refused: string[] = [];\n const completed: string[] = [];\n\n const pending = (await this.#get(\"/relay/site/pending\")) as {\n jobs: {\n jobId: string;\n device: PublicIdentity;\n runnerId: string;\n leaseId: string;\n awaitingUntil: number;\n }[];\n };\n for (const claim of pending.jobs) {\n const record = await this.#store.get(claim.jobId);\n if (!record) continue;\n const resealed = await resealForDevice({\n siteKeys: this.#siteKeys,\n job: {\n id: record.id,\n envelope: record.envelope,\n createdAt: record.createdAt,\n },\n device: claim.device,\n });\n if (!resealed.ok) {\n refused.push(claim.jobId);\n continue;\n }\n // Record the lease the relay granted, before handing over the work.\n //\n // The site is not the upstream here and does not decide who holds what\n // — but its own row has to know, or two things break that are not\n // cosmetic: `complete` refuses the result for want of a matching lease,\n // and the expiry sweep expires a job a device is in the middle of.\n // Adopting first means the worst case is a lease recorded for work that\n // never gets sealed, which the relay's own timeout already resolves.\n await this.#store.adopt({\n jobId: claim.jobId,\n leaseId: claim.leaseId,\n expiresAt: claim.awaitingUntil,\n now: this.#now(),\n });\n await this.#post(\"/relay/site/payload\", {\n siteId: this.#options.siteId,\n jobId: claim.jobId,\n envelope: resealed.envelope,\n });\n sealed.push(claim.jobId);\n }\n\n const finished = (await this.#get(\"/relay/site/results\")) as {\n jobs: {\n jobId: string;\n envelope: SealedEnvelope;\n disposition: string;\n runnerId: string;\n leaseId: string;\n device: PublicIdentity;\n }[];\n };\n for (const done of finished.jobs) {\n const record = await this.#store.get(done.jobId);\n if (!record || record.state === \"ok\" || record.state === \"error\") {\n continue;\n }\n const outcome = await this.#openResult(done);\n if (!outcome) {\n refused.push(done.jobId);\n continue;\n }\n // Provenance is built here, from the job's audience and the device the\n // relay named — never from anything the daemon asserted. Identical to\n // the direct plane's rule, and it has to be: a result arriving via a\n // relay is not more trustworthy for having travelled further.\n await this.#store.complete({\n jobId: done.jobId,\n // The grant, not the machine: this site never paired with the device\n // that ran it, and the signature it verified above is the stronger\n // claim about who did.\n holder: { by: \"lease\", leaseId: done.leaseId },\n outcome,\n provenance: provenanceFor({\n audience: record.audience,\n runnerId: done.runnerId,\n runnerOwner: keyId(done.device.identity),\n backendClass: \"http\",\n model: \"unknown\",\n }),\n now: this.#now(),\n });\n completed.push(done.jobId);\n }\n\n return { sealed, completed, refused };\n }\n\n /**\n * Open a sealed result and verify it came from the device that claimed it.\n *\n * The relay says which device ran the job; this checks that claim against a\n * signature the relay cannot produce. A relay that named the wrong device\n * gets a refusal, not a stored result — which is what keeps `RELAY_BLIND`\n * from quietly becoming `RELAY_TRUSTED`.\n */\n async #openResult(done: {\n jobId: string;\n envelope: SealedEnvelope;\n disposition: string;\n device: PublicIdentity;\n }): Promise<JobOutcome | null> {\n const opened = await open({\n envelope: done.envelope,\n recipientKeys: this.#siteKeys,\n senderIdentityPublic: done.device.identity,\n expected: {\n jobId: done.jobId,\n senderKeyId: keyId(done.device.identity),\n recipientKeyId: keyId(publicIdentityOf(this.#siteKeys).identity),\n direction: \"result\",\n },\n });\n if (!opened.ok) return null;\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(opened.plaintext);\n } catch {\n return null;\n }\n const outcome = JobOutcome.safeParse(parsed);\n if (!outcome.success) return null;\n // The clear-text disposition is a routing hint the relay acted on. This\n // is the only place it can be checked, because this is the only party\n // that can open the envelope (byollm_009 §6.1).\n if (outcome.data.outcome !== done.disposition) return null;\n return outcome.data;\n }\n\n async #post(path: string, body: unknown): Promise<unknown> {\n const response = await this.#fetch(`${this.#options.relayOrigin}${path}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n return response.json();\n }\n\n async #get(path: string): Promise<unknown> {\n const url = `${this.#options.relayOrigin}${path}?siteId=${encodeURIComponent(this.#options.siteId)}`;\n const response = await this.#fetch(url);\n return response.json();\n }\n}\n\n/** Only used when a job carries no deadline of its own. */\nconst ENVELOPE_TTL_FALLBACK = 24 * 60 * 60_000;\n","import { StoredKeys, generateKeys, publicIdentityOf } from \"@byollm/protocol\";\nimport { fingerprint } from \"@byollm/protocol\";\n\n/**\n * A site's keypairs — byollm_009 §5.\n *\n * **Generate once, store, supply.** Not at startup, and not per process.\n *\n * A site is usually more than one process: several instances behind a load\n * balancer, or a serverless function whose module is evaluated per cold\n * start. Keys generated at startup would give each of those a different\n * identity. A daemon pins whichever one approved its pairing, and then every\n * request routed to a different instance fails a signature check with nothing\n * in the error explaining why — a failure that appears only under\n * horizontal scale, which is to say only in production.\n *\n * So the library takes keys as an input and never invents them. That is the\n * whole reason this module is three functions rather than a lazy singleton.\n */\n\n/** Make a fresh site identity. Call this once, ever, and keep the result. */\nexport const generateSiteKeys = (now: number = Date.now()): StoredKeys =>\n generateKeys(now);\n\n/**\n * Read site keys from an environment variable holding base64 JSON.\n *\n * The shape a deployment actually wants: one opaque secret, set the way every\n * other secret is set, with no file to mount and no key material in the\n * repository.\n *\n * @throws with a message naming the variable and the fix, because this fails\n * at boot and the person reading the log is the person who can fix it.\n */\nexport function siteKeysFromEnv(\n variable = \"BYOLLM_SITE_KEYS\",\n env: NodeJS.ProcessEnv = process.env,\n): StoredKeys {\n const raw = env[variable];\n if (raw === undefined || raw === \"\") {\n throw new Error(\n `${variable} is not set. Generate a site identity once with ` +\n `\\`npx @byollm/server keygen\\` and set it as ${variable}. ` +\n `Do not generate keys at startup: every instance would get a ` +\n `different identity and daemons would pin one and be refused by ` +\n `another.`,\n );\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(Buffer.from(raw, \"base64\").toString(\"utf8\"));\n } catch {\n throw new Error(\n `${variable} is not base64-encoded JSON. It should be exactly what ` +\n `\\`npx @byollm/server keygen\\` printed.`,\n );\n }\n\n const result = StoredKeys.safeParse(parsed);\n if (!result.success) {\n throw new Error(\n `${variable} does not contain a valid site identity. Regenerate it ` +\n `with \\`npx @byollm/server keygen\\` — and if this site has already ` +\n `paired daemons, they will need to pair again.`,\n );\n }\n return result.data;\n}\n\n/** What to print from `keygen`: the secret to store, and how to check it. */\nexport function formatSiteKeys(keys: StoredKeys): string {\n const encoded = Buffer.from(JSON.stringify(keys)).toString(\"base64\");\n return (\n `# Set this as BYOLLM_SITE_KEYS. It is a secret: it is this site's\\n` +\n `# identity, and anything holding it can be this site.\\n` +\n `BYOLLM_SITE_KEYS=${encoded}\\n` +\n `\\n` +\n `# Fingerprint (not secret — show it to users so they can check what\\n` +\n `# their daemon pinned):\\n` +\n `# ${fingerprint(publicIdentityOf(keys).identity)}\\n`\n );\n}\n","import {\n backendDescriptor,\n matchAudience,\n type Capability,\n} from \"@byollm/protocol\";\nimport { generateLeaseId } from \"./ids.js\";\nimport type {\n StoredJobInput,\n JobRecord,\n PairingRecord,\n RunnerRecord,\n} from \"./records.js\";\nimport type {\n ApproveArgs,\n ByollmStore,\n ClaimArgs,\n AdoptArgs,\n CompleteArgs,\n CompleteResult,\n ReleaseArgs,\n RenewArgs,\n RenewResult,\n TouchArgs,\n} from \"./store.js\";\n\n/** Tunables an embedder may want to override in tests. */\nexport interface MemoryStoreOptions {\n /** Default TTL for a job once claimable. */\n readonly defaultTtlMs?: number;\n}\n\nconst DEFAULT_TTL_MS = 15 * 60_000;\n\n/**\n * The reference store: everything in one process, no persistence.\n *\n * This is not a toy — it is the implementation the conformance kit certifies\n * first, so its semantics *are* the specification's semantics for anything\n * the prose leaves implicit. A SQL adapter is correct when the same kit\n * passes against it.\n *\n * Concurrency: JavaScript's single-threaded turn is the atomicity primitive.\n * `claim` performs its read-decide-write with no `await` inside the critical\n * section, which is what makes {@link MUSTS.CLAIM_ATOMIC} hold here. A SQL\n * adapter gets the same property from `FOR UPDATE SKIP LOCKED`.\n */\nexport class MemoryStore implements ByollmStore {\n readonly #jobs = new Map<string, JobRecord>();\n readonly #runners = new Map<string, RunnerRecord>();\n readonly #pairings = new Map<string, PairingRecord>();\n /** Job ids the app has asked to cancel, not yet acknowledged by a runner. */\n readonly #cancelRequests = new Set<string>();\n readonly #defaultTtlMs: number;\n\n constructor(options: MemoryStoreOptions = {}) {\n this.#defaultTtlMs = options.defaultTtlMs ?? DEFAULT_TTL_MS;\n }\n\n // -- jobs ---------------------------------------------------------------\n\n create(input: StoredJobInput, now: number): Promise<JobRecord> {\n // Required now: the app mints the id before sealing, because the\n // envelope binds it.\n const id = input.id;\n const existing = this.#jobs.get(id);\n // Idempotent by caller-supplied id: re-enqueueing the same id is a no-op,\n // so an app's retry cannot duplicate work (the house \"one door\" rule).\n if (existing) return Promise.resolve(existing);\n\n const dependsOn = [...(input.dependsOn ?? [])];\n const blocked = dependsOn.some(\n (depId) => this.#jobs.get(depId)?.state !== \"ok\",\n );\n\n const job: JobRecord = {\n id,\n kind: input.kind,\n envelope: input.envelope,\n sizeClass: input.sizeClass,\n audience: input.audience ?? \"self\",\n owner: input.owner,\n audienceAllow: input.audienceAllow ? [...input.audienceAllow] : undefined,\n dependsOn,\n state: \"queued\",\n lease: null,\n createdAt: now,\n // The TTL clock starts here only if nothing blocks the job.\n claimableAt: blocked ? null : now,\n ttlMs: input.ttlMs ?? this.#defaultTtlMs,\n deadlineAt: input.deadlineAt ?? null,\n refusedBy: [],\n attempts: 0,\n outcome: null,\n provenance: null,\n updatedAt: now,\n };\n this.#write(id, job);\n return Promise.resolve(job);\n }\n\n get(jobId: string): Promise<JobRecord | null> {\n return Promise.resolve(this.#jobs.get(jobId) ?? null);\n }\n\n claim(args: ClaimArgs): Promise<JobRecord[]> {\n // Sweep first so an expired job is never handed out.\n this.#expireDueSync(args.now);\n\n const claimed: JobRecord[] = [];\n // Oldest-claimable first: a job that has waited longest goes next.\n const candidates = [...this.#jobs.values()].sort(\n (a, b) => (a.claimableAt ?? Infinity) - (b.claimableAt ?? Infinity),\n );\n\n for (const job of candidates) {\n if (claimed.length >= args.max) break;\n if (!this.#isClaimable(job, args)) continue;\n\n const updated: JobRecord = {\n ...job,\n state: \"claimed\",\n lease: {\n // A fresh id per grant. Two claims of the same job by the same\n // runner are two different leases, and must be distinguishable.\n id: generateLeaseId(),\n runnerId: args.runnerId,\n expiresAt: args.now + args.leaseMs,\n },\n attempts: job.attempts + 1,\n updatedAt: args.now,\n };\n this.#write(job.id, updated);\n claimed.push(updated);\n }\n return Promise.resolve(claimed);\n }\n\n /**\n * The claim predicate, shared by `claim` and the no-runner signal so the\n * two can never disagree about what \"a runner that could take this\" means.\n */\n #isClaimable(\n job: JobRecord,\n args: Pick<ClaimArgs, \"runnerId\" | \"runnerOwner\" | \"capabilities\" | \"now\">,\n ): boolean {\n if (job.state !== \"queued\") return false;\n if (job.claimableAt === null || job.claimableAt > args.now) return false;\n if (job.refusedBy.includes(args.runnerId)) return false;\n\n const capability = capabilityFor(args.capabilities, job.kind);\n if (!capability) return false;\n\n const match = matchAudience(\n {\n owner: job.owner,\n audience: job.audience,\n audienceAllow: job.audienceAllow,\n },\n {\n owner: args.runnerOwner,\n offerScope: capability.offerScope,\n // From the registry, not a local guess — the cost rules must mean the\n // same thing on both sides of the wire. The server cannot see a\n // remote daemon's base URL, so a generic backend with no declared\n // cost is treated as metered: the expensive side, and the daemon\n // refuses anyway if it disagrees (byollm_007 §2).\n cost: backendDescriptor(capability.backendId).cost ?? \"metered\",\n // Nor can it see the owner's spend consent. It offers; the daemon is\n // the enforcing side and releases with `refused` if its own rules say\n // no — the same shape as the `named` allowlist.\n spend: { acknowledged: true },\n // The server cannot see a remote daemon's local allowlist and must\n // not pretend to (protocol §4.2). It admits the job here; the daemon\n // is the enforcing side and releases with `refused` if its own list\n // says no.\n locallyAllows: () => true,\n },\n );\n return match.ok;\n }\n\n renewLeases(args: RenewArgs): Promise<RenewResult> {\n this.#expireDueSync(args.now);\n\n const renewed: { jobId: string; expiresAt: number }[] = [];\n const lost: string[] = [];\n\n for (const { jobId, leaseId } of args.leases) {\n const job = this.#jobs.get(jobId);\n if (\n !job ||\n job.lease?.runnerId !== args.runnerId ||\n job.lease.id !== leaseId\n ) {\n // Reclaimed by someone else, terminal, or a different grant than the\n // one being renewed — either way this runner must stop.\n lost.push(jobId);\n continue;\n }\n if (job.state !== \"claimed\" && job.state !== \"running\") {\n lost.push(jobId);\n continue;\n }\n const expiresAt = args.now + args.leaseMs;\n this.#write(jobId, {\n ...job,\n state: \"running\",\n // Renewal extends the existing grant; it does not mint a new one.\n lease: { ...job.lease, expiresAt },\n updatedAt: args.now,\n });\n renewed.push({ jobId, expiresAt });\n }\n return Promise.resolve({ renewed, lost });\n }\n\n adopt(args: AdoptArgs): Promise<JobRecord | null> {\n const job = this.#jobs.get(args.jobId);\n if (!job) return Promise.resolve(null);\n // Only a job that is genuinely available can be adopted. A terminal or\n // already-leased job means the relay and this store disagree about\n // reality, and the store's row is not the place to resolve that.\n if (job.state !== \"queued\" && job.state !== \"claimed\") {\n return Promise.resolve(null);\n }\n if (job.lease && job.lease.id !== args.leaseId) {\n return Promise.resolve(null);\n }\n const updated: JobRecord = {\n ...job,\n state: \"claimed\",\n lease: {\n id: args.leaseId,\n // No runner: this site never paired with the machine holding it.\n runnerId: \"\",\n expiresAt: args.expiresAt,\n },\n updatedAt: args.now,\n };\n this.#write(updated.id, updated);\n return Promise.resolve(updated);\n }\n\n complete(args: CompleteArgs): Promise<CompleteResult> {\n const job = this.#jobs.get(args.jobId);\n if (!job) return Promise.resolve({ accepted: false, job: null });\n\n // First terminal outcome wins; a later submission is discarded, not\n // applied ({@link MUSTS.RESULT_IDEMPOTENT}).\n if (\n job.state === \"ok\" ||\n job.state === \"error\" ||\n job.state === \"canceled\"\n ) {\n return Promise.resolve({ accepted: false, job });\n }\n if (job.state === \"expired\") {\n return Promise.resolve({ accepted: false, job });\n }\n // A runner that lost its lease may not write a result\n // ({@link MUSTS.LEASE_HONORED}). Named by lease id when the caller has\n // one — off the direct plane there is no runner this site knows.\n const holds =\n args.holder.by === \"runner\"\n ? job.lease?.runnerId === args.holder.runnerId\n : job.lease?.id === args.holder.leaseId;\n if (!holds) {\n return Promise.resolve({ accepted: false, job });\n }\n\n const state =\n args.outcome.outcome === \"ok\"\n ? \"ok\"\n : args.outcome.outcome === \"canceled\"\n ? \"canceled\"\n : \"error\";\n\n const updated: JobRecord = {\n ...job,\n state,\n lease: null,\n outcome: args.outcome,\n provenance: args.provenance,\n updatedAt: args.now,\n };\n this.#write(job.id, updated);\n this.#cancelRequests.delete(job.id);\n\n if (state === \"ok\") this.#unblockDependents(job.id, args.now);\n\n return Promise.resolve({ accepted: true, job: updated });\n }\n\n /**\n * Start the TTL clock on anything this job was blocking.\n *\n * Deliberately only on `ok`: a dependency that errored leaves its dependents\n * blocked forever rather than releasing them into a run whose input never\n * arrived. They expire at their absolute deadline if one was set, and the\n * app sees a chain that stopped where it broke.\n */\n #unblockDependents(completedId: string, now: number): void {\n for (const job of this.#jobs.values()) {\n if (job.claimableAt !== null) continue;\n if (!job.dependsOn.includes(completedId)) continue;\n const ready = job.dependsOn.every(\n (depId) => this.#jobs.get(depId)?.state === \"ok\",\n );\n if (ready) {\n this.#write(job.id, { ...job, claimableAt: now, updatedAt: now });\n }\n }\n }\n\n /**\n * Watchers, by job id (byollm_009 §8.3).\n *\n * A `Set` per job so an unsubscribe removes exactly the handler it\n * registered — two waiters on the same job are ordinary, and removing by\n * job id alone would silently cancel someone else's wait.\n */\n readonly #watchers = new Map<string, Set<() => void>>();\n\n subscribe(jobId: string, onChange: () => void): () => void {\n const existing = this.#watchers.get(jobId) ?? new Set<() => void>();\n existing.add(onChange);\n this.#watchers.set(jobId, existing);\n let live = true;\n return () => {\n // Idempotent: the contract says calling twice is safe, and a `finally`\n // that unsubscribes after an error path already did is the normal way\n // this gets called twice.\n if (!live) return;\n live = false;\n const set = this.#watchers.get(jobId);\n set?.delete(onChange);\n if (set?.size === 0) this.#watchers.delete(jobId);\n };\n }\n\n /**\n * The single write path for a job.\n *\n * Every mutation goes through here so notification cannot be forgotten by\n * a future one. Nine call sites existed when the push seam was added, and\n * \"remember to notify\" is not a property nine call sites keep.\n */\n #write(jobId: string, record: JobRecord): void {\n this.#jobs.set(jobId, record);\n this.#notify(jobId);\n }\n\n /**\n * Tell anyone watching that a job changed.\n *\n * A throwing watcher must not corrupt the store's own bookkeeping, so each\n * is isolated: this runs inside write paths, and one bad listener taking\n * out an unrelated write would be a far worse failure than a missed\n * notification.\n */\n #notify(jobId: string): void {\n for (const watcher of this.#watchers.get(jobId) ?? []) {\n try {\n watcher();\n } catch {\n // A watcher is a signal handler; the caller re-reads regardless.\n }\n }\n }\n\n release(args: ReleaseArgs): Promise<string[]> {\n const released: string[] = [];\n for (const { jobId, leaseId } of args.leases) {\n const job = this.#jobs.get(jobId);\n // The *grant*, not just its holder. Matching on runner id alone let a\n // replayed release from an earlier lease drop a later one, returning a\n // job to the queue while the daemon was still executing it.\n if (\n !job ||\n job.lease?.runnerId !== args.runnerId ||\n job.lease.id !== leaseId\n ) {\n continue;\n }\n\n this.#write(jobId, {\n ...job,\n state: \"queued\",\n lease: null,\n // Newly available again, so the TTL clock restarts here too.\n claimableAt: args.now,\n // A refusal is remembered, or the pair spins between claim and\n // release forever ({@link MUSTS.REFUSAL_NOT_REOFFERED}).\n refusedBy:\n args.reason === \"refused\"\n ? [...new Set([...job.refusedBy, args.runnerId])]\n : job.refusedBy,\n updatedAt: args.now,\n });\n released.push(jobId);\n }\n return Promise.resolve(released);\n }\n\n expireDue(now: number): Promise<JobRecord[]> {\n return Promise.resolve(this.#expireDueSync(now));\n }\n\n /**\n * Lease expiry and TTL expiry in one idempotent sweep.\n *\n * Order matters: a lease is reclaimed *before* the TTL is judged, so a job\n * whose runner died is offered again rather than being expired for having\n * sat in `claimed` too long.\n */\n #expireDueSync(now: number): JobRecord[] {\n const changed: JobRecord[] = [];\n\n for (const job of this.#jobs.values()) {\n if (\n (job.state === \"claimed\" || job.state === \"running\") &&\n job.lease !== null &&\n job.lease.expiresAt <= now\n ) {\n const requeued: JobRecord = {\n ...job,\n state: \"queued\",\n lease: null,\n // The TTL clock restarts: it measures how long a job has waited\n // *unclaimed*, and this job has just become available again. Without\n // this, a job whose runner died would expire for time it spent being\n // actively worked on — losing exactly the work `kill -9` recovery\n // exists to save. Total lifetime is bounded by `deadlineAt`, which\n // is absolute and unaffected by reclaim.\n claimableAt: now,\n updatedAt: now,\n };\n this.#write(job.id, requeued);\n changed.push(requeued);\n }\n }\n\n for (const job of this.#jobs.values()) {\n if (job.state !== \"queued\") continue;\n const pastDeadline = job.deadlineAt !== null && job.deadlineAt <= now;\n const pastTtl =\n job.claimableAt !== null && job.claimableAt + job.ttlMs <= now;\n if (!pastDeadline && !pastTtl) continue;\n\n const expired: JobRecord = {\n ...job,\n state: \"expired\",\n lease: null,\n updatedAt: now,\n };\n this.#write(job.id, expired);\n changed.push(expired);\n }\n return changed;\n }\n\n cancel(jobId: string, now: number): Promise<JobRecord | null> {\n const job = this.#jobs.get(jobId);\n if (!job) return Promise.resolve(null);\n if (job.state === \"queued\") {\n const canceled: JobRecord = {\n ...job,\n state: \"canceled\",\n lease: null,\n updatedAt: now,\n };\n this.#write(jobId, canceled);\n return Promise.resolve(canceled);\n }\n if (job.state === \"claimed\" || job.state === \"running\") {\n // Held by a runner: the cancel travels on the next heartbeat and the\n // runner reports `canceled` itself, so the job's own state waits.\n this.#cancelRequests.add(jobId);\n return Promise.resolve(job);\n }\n return Promise.resolve(job);\n }\n\n listClaimedBy(runnerId: string): Promise<JobRecord[]> {\n return Promise.resolve(\n [...this.#jobs.values()].filter(\n (job) => job.lease?.runnerId === runnerId,\n ),\n );\n }\n\n listCancelRequests(runnerId: string): Promise<string[]> {\n return Promise.resolve(\n [...this.#cancelRequests].filter(\n (jobId) => this.#jobs.get(jobId)?.lease?.runnerId === runnerId,\n ),\n );\n }\n\n // -- pairing and runners -------------------------------------------------\n\n createPairing(record: PairingRecord): Promise<void> {\n this.#pairings.set(record.deviceCodeHash, record);\n return Promise.resolve();\n }\n\n getPairingByDeviceCodeHash(hash: string): Promise<PairingRecord | null> {\n return Promise.resolve(this.#pairings.get(hash) ?? null);\n }\n\n getPairingByUserCode(userCode: string): Promise<PairingRecord | null> {\n for (const pairing of this.#pairings.values()) {\n if (pairing.userCode === userCode) return Promise.resolve(pairing);\n }\n return Promise.resolve(null);\n }\n\n approvePairing(args: ApproveArgs): Promise<RunnerRecord> {\n const pairing = [...this.#pairings.values()].find(\n (p) => p.userCode === args.userCode,\n );\n if (!pairing) throw new Error(`unknown pairing code: ${args.userCode}`);\n if (pairing.expiresAt <= args.now) {\n throw new Error(\"pairing code has expired\");\n }\n if (pairing.state !== \"pending\") {\n throw new Error(`pairing is already ${pairing.state}`);\n }\n\n const runner: RunnerRecord = {\n id: args.runnerId,\n owner: args.owner,\n tokenHash: args.tokenHash,\n // Carried from the pairing, not re-supplied at approval: the user\n // approved a specific machine, and the runner must be that machine.\n device: pairing.device,\n label: pairing.label,\n platform: pairing.platform,\n daemonVersion: pairing.daemonVersion,\n capabilities: pairing.capabilities,\n paused: false,\n revokedAt: null,\n lastHeartbeatAt: args.now,\n createdAt: args.now,\n };\n this.#runners.set(runner.id, runner);\n this.#pairings.set(pairing.deviceCodeHash, {\n ...pairing,\n state: \"approved\",\n owner: args.owner,\n runnerId: runner.id,\n runnerTokenOnce: args.runnerToken,\n });\n return Promise.resolve(runner);\n }\n\n denyPairing(userCode: string, _now: number): Promise<void> {\n const pairing = [...this.#pairings.values()].find(\n (p) => p.userCode === userCode,\n );\n if (pairing) {\n this.#pairings.set(pairing.deviceCodeHash, {\n ...pairing,\n state: \"denied\",\n });\n }\n return Promise.resolve();\n }\n\n consumePairingToken(deviceCodeHash: string): Promise<void> {\n const pairing = this.#pairings.get(deviceCodeHash);\n if (pairing) {\n this.#pairings.set(deviceCodeHash, {\n ...pairing,\n runnerTokenOnce: null,\n });\n }\n return Promise.resolve();\n }\n\n getRunnerByTokenHash(hash: string): Promise<RunnerRecord | null> {\n for (const runner of this.#runners.values()) {\n if (runner.tokenHash === hash) return Promise.resolve(runner);\n }\n return Promise.resolve(null);\n }\n\n getRunner(runnerId: string): Promise<RunnerRecord | null> {\n return Promise.resolve(this.#runners.get(runnerId) ?? null);\n }\n\n touchRunner(args: TouchArgs): Promise<RunnerRecord | null> {\n const runner = this.#runners.get(args.runnerId);\n if (!runner) return Promise.resolve(null);\n const updated: RunnerRecord = {\n ...runner,\n capabilities: args.capabilities,\n daemonVersion: args.daemonVersion,\n paused: args.paused,\n lastHeartbeatAt: args.now,\n };\n this.#runners.set(runner.id, updated);\n return Promise.resolve(updated);\n }\n\n revokeRunner(runnerId: string, now: number): Promise<void> {\n const runner = this.#runners.get(runnerId);\n // Revocation is one-way: an already-revoked runner keeps its first\n // revocation time rather than being re-stamped.\n if (runner?.revokedAt === null) {\n this.#runners.set(runnerId, { ...runner, revokedAt: now });\n }\n return Promise.resolve();\n }\n\n listRunners(owner?: string): Promise<RunnerRecord[]> {\n const all = [...this.#runners.values()];\n return Promise.resolve(\n owner === undefined ? all : all.filter((r) => r.owner === owner),\n );\n }\n\n // -- test/demo helpers ---------------------------------------------------\n\n /** All jobs, for demos and assertions. Not part of the store interface. */\n allJobs(): JobRecord[] {\n return [...this.#jobs.values()];\n }\n}\n\n/** The capability that would serve a kind, if any. */\nexport function capabilityFor(\n capabilities: readonly Capability[],\n kind: string,\n): Capability | undefined {\n return capabilities.find((c) => c.kind === kind);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA,SAAAA;AAAA,EACA;AAAA,EACA,oBAAAC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAGK;;;ACbP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAiEA,IAAM,YAAN,MAAgB;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAKT;AACD,SAAK,WAAW,KAAK;AACrB,SAAK,SAAS,KAAK;AACnB,SAAK,YAAY,KAAK;AACtB,SAAK,OAAO,KAAK;AACjB,SAAK,SAAS,KAAK,QAAQ,SAAS,WAAW;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,QAAQ,QAAkC;AAC9C,UAAM,OAAgB;AAAA,MACpB,IAAI,OAAO;AAAA,MACX,MAAM,OAAO;AAAA,MACb,OAAO,OAAO;AAAA,MACd,UAAU,OAAO;AAAA,MACjB,GAAI,OAAO,kBAAkB,SACzB,CAAC,IACD,EAAE,eAAe,CAAC,GAAG,OAAO,aAAa,EAAE;AAAA,MAC/C,WAAW,OAAO;AAAA,MAClB,WAAW;AAAA;AAAA;AAAA;AAAA,MAIX,YAAY,OAAO,cAAc,OAAO,YAAY;AAAA,IACtD;AACA,UAAM,KAAK,MAAM,uBAAuB;AAAA,MACtC,QAAQ,KAAK,SAAS;AAAA,MACtB;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,OA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SAAS,IAAI,UAAU,EAAE,GAAG,QAAQ,WAAW,IAAI,CAAC;AAAA,IAC3D;AACA,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,YAAY,OAAyC;AACnD,UAAM,MAAM,CAAC,GAAG,KAAK,SAAS,OAAO,CAAC;AACtC,WAAO,QAAQ;AAAA,MACb,UAAU,SAAY,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,UAAU,KAAK;AAAA,IACjE;AAAA,EACF;AAAA;AAAA;AAAA,EAKA,UAAuB;AACrB,WAAO,CAAC,GAAG,KAAK,MAAM,OAAO,CAAC;AAAA,EAChC;AACF;AAGO,SAAS,cACd,cACA,MACwB;AACxB,SAAO,aAAa,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AACjD;","names":["keyId","publicIdentityOf","keyId","publicIdentityOf","publicIdentityOf","backendDescriptor","matchAudience","matchAudience","backendDescriptor"]}
1
+ {"version":3,"sources":["../src/app.ts","../src/cloud.ts","../src/keys.ts","../src/memory.ts"],"sourcesContent":["import {\n ENVELOPE_MAX_AGE_MS,\n KindedPayload,\n keyId,\n payloadTextLength,\n publicIdentityOf,\n seal,\n sizeClassOf,\n type StoredKeys,\n backendDescriptor,\n matchAudience,\n type Audience,\n type DeliveredResult,\n type JobKind,\n type MatchRefusal,\n} from \"@byollm/protocol\";\nimport {\n PollingDelivery,\n type PollingDeliveryDeps,\n type ResultDelivery,\n type WaitOptions,\n} from \"./delivery.js\";\nimport { generateJobId, generateRunnerId } from \"./ids.js\";\nimport { CloudLane, type CloudLaneOptions } from \"./cloud.js\";\nimport type { EnqueueInput, JobRecord, RunnerRecord } from \"./records.js\";\nimport type { ByollmStore } from \"./store.js\";\n\n/**\n * How long since a runner's last heartbeat before it stops counting as live.\n * Three heartbeats of slack at the daemon's ~10s cadence.\n */\nconst DEFAULT_LIVENESS_MS = 35_000;\n\n/** Why a job cannot presently run. */\nexport type NoRunnerReason =\n | \"no-runner-paired\"\n | \"no-runner-online\"\n | \"no-matching-capability\"\n | \"audience-admits-nobody\"\n /**\n * The owner's default for this kind can never serve *this* requester —\n * byollm_016's defaults-meet-audiences corner.\n *\n * The specimen: a default of `claude-cli`, self-locked by\n * `SUBSCRIPTION_SELF_LOCK`, and a team member's unselected job. It resolves\n * to something that will never run it. Reported rather than left to time\n * out, because a wait that can never end is indistinguishable from one that\n * has not ended yet, and only one of them is worth waiting through.\n */\n | \"default-unusable\";\n\n/**\n * The no-runner signal (byollm_001 Rev 1 §D).\n *\n * `available: false` means an app should fall back — hosted model, \"start\n * your runner\" prompt — rather than awaiting something that will never\n * resolve. A job still blocked on dependencies is **not** unavailable; it is\n * waiting, and saying otherwise would make every multi-job flow look broken\n * ({@link MUSTS.NO_RUNNER_SIGNAL}).\n */\nexport interface RunnerAvailability {\n readonly available: boolean;\n readonly reason?: NoRunnerReason;\n /** Live runners that could take work of this shape. */\n readonly candidates: number;\n}\n\nexport interface AvailabilityQuery {\n readonly kind: JobKind;\n readonly owner: string;\n readonly audience?: Audience;\n readonly audienceAllow?: readonly string[];\n}\n\nexport interface ByollmAppOptions {\n readonly store: ByollmStore;\n /** Injectable clock. */\n readonly now?: () => number;\n /** Liveness window for the no-runner signal. */\n readonly livenessMs?: number;\n /**\n * How the app learns a job finished. Defaults to polling the store, which\n * is correct everywhere; the Supabase adapter substitutes Realtime.\n */\n readonly delivery?: (deps: PollingDeliveryDeps) => ResultDelivery;\n /**\n * How long a sustained no-runner signal must persist before `result()`\n * gives up. Longer tolerates a daemon restarting; shorter fails faster.\n */\n readonly noRunnerGraceMs?: number;\n /**\n * This site's keypairs — the same ones the handlers use.\n *\n * The app needs them because it is the *endpoint*: it seals work on the way\n * in and opens results on the way out. Nothing between those two points\n * holds plaintext (byollm_009 §10).\n */\n readonly siteKeys: StoredKeys;\n /**\n * Which connection plane this site uses — cloud_004 §9.4.\n *\n * Omitted means `direct`: a daemon reaches this site's own handlers, and\n * everything works as it always has. Supplying a relay switches the plane\n * and nothing else — `enqueue` is identical in every lane, which is the\n * property that lets the same app move between them by config.\n */\n readonly lane?: CloudLaneOptions;\n}\n\n/**\n * An enqueued job, with the delivery channel attached.\n *\n * `result()` is sugar over the channel — with a timeout and a\n * `noRunnerAvailable` path — never a bare promise that can hang forever\n * (byollm_003 Rev 1).\n */\nexport interface JobHandle {\n readonly id: string;\n /** The job as stored at enqueue time. */\n readonly record: JobRecord;\n /** Wait for a terminal outcome. */\n result(options?: WaitOptions): Promise<DeliveredResult>;\n /** Ask the runner to stop. */\n cancel(): Promise<void>;\n}\n\n/**\n * The app-facing half of `@byollm/server`.\n *\n * The daemon talks to {@link ByollmHandlers}; the app talks to this. Keeping\n * them separate is what makes \"one door per state write\" hold — an app\n * enqueues and cancels through these methods and never writes job rows by\n * hand.\n */\n/**\n * Every option `enqueue` accepts, as data.\n *\n * `Record<keyof EnqueueInput, true>` rather than a hand-kept array, so the\n * compiler refuses this file when a field is added to `EnqueueInput` and not\n * to this list. An allowlist that silently falls behind the type it guards is\n * worse than none: it would start rejecting the very field somebody just\n * added, in the name of catching typos.\n */\nconst ENQUEUE_OPTIONS: Readonly<Record<keyof EnqueueInput, true>> =\n Object.freeze({\n kind: true,\n payload: true,\n owner: true,\n audience: true,\n purpose: true,\n audienceAllow: true,\n dependsOn: true,\n ttlMs: true,\n deadlineAt: true,\n id: true,\n });\n\nexport class ByollmApp {\n readonly #store: ByollmStore;\n readonly #siteKeys: StoredKeys;\n readonly #now: () => number;\n readonly #livenessMs: number;\n readonly #delivery: ResultDelivery;\n /** Present only in the cloud lane; the site's side of the relay. */\n readonly cloud: CloudLane | undefined;\n\n constructor(options: ByollmAppOptions) {\n this.#store = options.store;\n this.#siteKeys = options.siteKeys;\n this.#now = options.now ?? Date.now;\n this.#livenessMs = options.livenessMs ?? DEFAULT_LIVENESS_MS;\n this.cloud =\n options.lane === undefined\n ? undefined\n : new CloudLane({\n options: options.lane,\n store: options.store,\n siteKeys: options.siteKeys,\n now: this.#now,\n });\n\n /**\n * The delivery's dependencies — and on the cloud lane, one fewer.\n *\n * `runnerAvailability` refuses on the cloud lane, deliberately: it counts\n * runners in this site's own store, devices there pair with the relay\n * instead, and it spent a release reporting `no-runner-paired` with\n * confidence for every cloud-lane app that asked.\n *\n * The refusal shipped and this wrapper kept calling it. Delivery asks\n * every 500ms, so `job.result()` threw on its first poll for every\n * cloud-lane site — found by Kevin, on the ordinary consumer loop that\n * none of our own proofs ran.\n *\n * **The law it earned: when you make a function refuse, grep its callers\n * first.** We audited what branched on the untrusted flag and never\n * audited this method's internal callers. A refusal aimed at outsiders\n * that your own loop trips over is a crash wearing a principle.\n *\n * So the question is not asked. Delivery gets no availability instrument\n * on a lane where nothing can answer, rather than an instrument that\n * throws and a `catch` upstream pretending that means \"keep waiting\".\n */\n const deps: PollingDeliveryDeps = {\n ...(options.noRunnerGraceMs === undefined\n ? {}\n : { graceMs: options.noRunnerGraceMs }),\n read: (jobId) => this.result(jobId),\n ...(this.cloud !== undefined\n ? {}\n : { availability: this.#availabilityFor() }),\n };\n this.#delivery = options.delivery?.(deps) ?? new PollingDelivery(deps);\n }\n\n /**\n * The no-runner instrument, for a lane that can actually see runners.\n *\n * A method rather than an inline closure so the branch above reads as one\n * decision — whether this deployment has the instrument at all — instead of\n * a conditional wrapped around thirty lines of body.\n */\n #availabilityFor() {\n return async (jobId: string) => {\n const job = await this.#store.get(jobId);\n if (!job)\n return { available: false, reason: \"unknown-job\", blocked: false };\n // A job waiting on a dependency is waiting, not unavailable.\n if (job.claimableAt === null) {\n return { available: true, blocked: true };\n }\n const availability = await this.runnerAvailability({\n kind: job.kind,\n owner: job.owner,\n audience: job.audience,\n ...(job.audienceAllow === undefined\n ? {}\n : { audienceAllow: job.audienceAllow }),\n });\n return {\n available: availability.available,\n ...(availability.reason === undefined\n ? {}\n : { reason: availability.reason }),\n blocked: false,\n };\n };\n }\n\n /**\n * Enqueue a job.\n *\n * `audience` defaults to `self` — the safe direction. Widening it means the\n * result comes back marked untrusted (see {@link ByollmApp.result}), and\n * the app is obliged to disclose that to whoever reads it.\n */\n async enqueue<K extends JobKind>(input: EnqueueInput<K>): Promise<JobHandle> {\n // An option this SDK does not know is refused, never ignored.\n //\n // A caller newer than its SDK is the ordinary way this happens, and the\n // case that produced the rule: a site called `enqueue({ service })`\n // against a version that predated the field, the key went nowhere, and\n // nothing said so. The app believed it was selecting a service, was not,\n // and the only symptom was work running on one nobody chose. Silence is\n // the hazard rather than the missing feature.\n const unknown = Object.keys(input).filter(\n (key) => !(key in ENQUEUE_OPTIONS),\n );\n if (unknown.length > 0) {\n throw new Error(\n `enqueue does not understand ${unknown.map((k) => `\\`${k}\\``).join(\", \")}. ` +\n `An option this @byollm/server does not know is refused rather than ` +\n `ignored, because an ignored option is a job that runs differently ` +\n `than you asked with nothing to see — most often an SDK older than ` +\n `the code calling it. Upgrade @byollm/server, or remove the option.`,\n );\n }\n\n /**\n * `audience` is not a fact a cloud-lane site holds — so it may not state\n * one.\n *\n * Who may serve a job is decided by the person: their mapping names a\n * service and its owner, that owner's offer scope says who the service\n * serves, and the hub holds both at claim. The site's declaration was a\n * third vote cast by the one party the disclosure fence forbids from\n * knowing the answer.\n *\n * Which is exactly how its default came to disable the headline feature\n * in silence. It defaults to `private` — own devices only — so a site that\n * simply never mentioned it broke team sharing for every user who had a\n * team, while working perfectly for everyone testing alone. **A\n * declaration required from the party that cannot know is a default in\n * disguise.**\n *\n * Refused rather than ignored, by this method's own rule two paragraphs\n * up: an ignored option is a job that runs differently than asked with\n * nothing to see. The remedy travels with the refusal, because a caller\n * who set it was trying to express something real and deserves to know\n * where that decision now lives.\n */\n if (this.cloud !== undefined && input.audience !== undefined) {\n throw new Error(\n \"enqueue does not take `audience` on the cloud lane. Who may serve a \" +\n \"job is derived from the person's own mapping — the service they \" +\n \"chose, its owner, and that owner's sharing — which your site is \" +\n \"not told and cannot compute. Remove `audience`; ask for the kind \" +\n \"and the purpose, and their decision does the rest.\",\n );\n }\n\n // Validate the payload against its kind before anything stores it.\n //\n // The schemas are `.strict()`, so this drops a payload carrying fields\n // the kind does not define — `command`, `argv`, `model`, `baseUrl`. Types\n // do not survive a JSON boundary, and an app assembling a payload from\n // user input is the ordinary case, so \"the caller is typed\" is not a\n // check ({@link MUSTS.KIND_NO_CODE}, {@link MUSTS.NO_PAYLOAD_ROUTING}).\n //\n // Refusing here rather than relying on the daemon is deliberate. The\n // daemon does re-validate and would reject this — but it parses a whole\n // claim response at once, so one malformed job would fail the batch it\n // arrived in and stall unrelated work. Rejecting at enqueue puts the\n // error where the app can act on it.\n const parsed = KindedPayload.safeParse({\n kind: input.kind,\n payload: input.payload,\n });\n if (!parsed.success) {\n const detail = parsed.error.issues\n .map((issue) => `${issue.path.join(\".\") || \"(root)\"}: ${issue.message}`)\n .join(\"; \");\n throw new Error(`invalid ${input.kind} payload — ${detail}`);\n }\n\n // Sealed before it is stored, to this site's own key. The app is the\n // endpoint, so it can open its own work later; the store, its backups and\n // anything reading them cannot.\n // Two different deadlines, deliberately not conflated:\n //\n // - the *job's* deadline is the app's business, may be absent, and for a\n // dependent job its TTL clock does not even start until the job becomes\n // claimable (`TTL_EXPIRY`). Setting one here broke exactly that.\n // - the *envelope's* deadline bounds how long a captured ciphertext is\n // worth keeping. It is bound into the signature, so it has to be\n // recomputable at open time from what the record stores — hence\n // creation plus TTL, which never moves.\n // Resolved *here*, once, and passed to the store — because the envelope\n // binds it. Letting the app default one value and the store default\n // another produced a job whose seal and record disagreed, and therefore\n // work nobody could open.\n // One reading of the clock, used for both the seal and the record.\n //\n // Two readings passed every fake-clock test and failed against a real\n // one: the envelope bound `createdAt + ttlMs` from the first call and the\n // record stored `createdAt` from the second, a millisecond later, so\n // nothing could be opened. A fixed clock returns the same number twice\n // and hides it completely.\n const createdAt = this.#now();\n // Independent of the job's TTL, deliberately. Binding the envelope to\n // `createdAt + ttl` meant the app had to decide a TTL in order to seal —\n // which overrode the store's own default and broke every expiry test.\n // The two answer different questions: how long the work is worth doing,\n // and how long the ciphertext is worth keeping.\n const envelopeDeadlineAt = createdAt + ENVELOPE_MAX_AGE_MS;\n const jobId = input.id ?? generateJobId();\n const senderKeyId = keyId(publicIdentityOf(this.#siteKeys).identity);\n const envelope = await seal({\n plaintext: JSON.stringify(parsed.data.payload),\n senderKeys: this.#siteKeys,\n recipientEncryptionPublic: this.#siteKeys.encryptionPublic,\n context: {\n jobId,\n senderKeyId,\n recipientKeyId: senderKeyId,\n deadlineAt: envelopeDeadlineAt,\n direction: \"payload\",\n },\n });\n\n const record = await this.#store.create(\n {\n ...input,\n /**\n * Derived here, because on the cloud lane it is derivable and nowhere\n * else knows the lane.\n *\n * Refusing the site's declaration is only half of \"derived, never\n * declared\" — the stub still carries an audience to the relay, and a\n * store that defaults it to `private` would keep every cloud job\n * private no matter who was forbidden from saying so. The half that\n * fixes anything is this one.\n *\n * `team` is the value that defers: it says a device whose owner\n * admits this person may serve, and the hub then decides whether one\n * does, from the mapping the person authored, its service's owner,\n * that owner's offer scope, and the roster. Nothing is widened by\n * saying it — both axes still have to agree, and the owner's scope is\n * the other axis.\n *\n * Direct mode keeps the store's `private` default: there is no\n * control plane there to derive from, and owner-only is the ruling.\n */\n ...(this.cloud === undefined ? {} : { audience: \"team\" as const }),\n id: jobId,\n envelope,\n sizeClass: sizeClassOf(\n payloadTextLength({\n kind: input.kind,\n payload: parsed.data.payload,\n } as Parameters<typeof payloadTextLength>[0]),\n ),\n },\n createdAt,\n );\n // The lane's only intrusion into enqueue, and it is additive: the record\n // is already stored and sealed at rest before anything is published, so a\n // relay that is down costs a routing delay rather than a lost job.\n await this.cloud?.publish(record);\n\n return {\n id: record.id,\n record,\n result: (options?: WaitOptions) =>\n this.#delivery.waitFor(record.id, options),\n cancel: async () => {\n await this.cancel(record.id);\n },\n };\n }\n\n /** Read a job's current state. */\n async job(jobId: string): Promise<JobRecord | null> {\n await this.#store.expireDue(this.#now());\n return this.#store.get(jobId);\n }\n\n /**\n * A job's result with its provenance attached.\n *\n * Check `provenance.untrusted` before rendering. It is true for every\n * `named`/`public` job, because that text came from someone else's machine\n * and the app must not present it as its own AI's answer\n * ({@link MUSTS.PROVENANCE_NAMES_DEVICE}).\n */\n async result(jobId: string): Promise<DeliveredResult | null> {\n const job = await this.job(jobId);\n if (!job) return null;\n return {\n jobId: job.id,\n state: job.state,\n ...(job.outcome === null ? {} : { outcome: job.outcome }),\n ...(job.provenance === null ? {} : { provenance: job.provenance }),\n };\n }\n\n /** Ask a runner to stop. Queued jobs cancel at once; held jobs at the next heartbeat. */\n async cancel(jobId: string): Promise<JobRecord | null> {\n const cancelled = await this.#store.cancel(jobId, this.#now());\n // On the cloud lane the relay is the only party talking to the daemon, so\n // a cancellation that stops at this store stops a *future* seal and\n // nothing else — cloud_008 §2.2. Told after the row is terminal, so the\n // two can only disagree in the safe direction: the relay may briefly\n // still offer a job this site will now refuse to seal for.\n //\n // Not awaited into the caller's error path: an app cancelling a job has\n // cancelled it, and a relay that is unreachable must not turn that into a\n // thrown error. The relay's own deadline sweep is the backstop.\n if (cancelled && this.cloud) {\n await this.cloud.cancel(jobId).catch(() => undefined);\n }\n return cancelled;\n }\n\n /**\n * Is there a live runner that could take a job of this shape?\n *\n * Runs the identical {@link matchAudience} rule the claim path uses, so the\n * signal cannot promise a runner the claim would then refuse.\n */\n async runnerAvailability(\n query: AvailabilityQuery,\n ): Promise<RunnerAvailability> {\n /**\n * On the cloud lane this cannot see, so it does not answer.\n *\n * It counts runners in *this site's own store*. In direct mode that is\n * the whole world — devices pair with the site. On the cloud lane they\n * pair with the relay, nothing ever writes a runner here, and the honest\n * count is not zero but unknown.\n *\n * It reported zero, as `no-runner-paired` with `candidates: 0`, for every\n * cloud-lane app that ever called it. A teammate using a shared device\n * was told no device was paired to her account — true, irrelevant, and\n * rendered as advice to go and install software she did not need.\n *\n * **An instrument that cannot see must refuse, not report zero.** A wrong\n * answer given confidently is worse than no answer, and this one was\n * confident, specific and false all at once.\n */\n if (this.cloud !== undefined) {\n throw new Error(\n \"runnerAvailability cannot answer on the cloud lane. It counts \" +\n \"runners this site knows about, and on the cloud lane devices pair \" +\n \"with the relay rather than with you — so the answer would be \" +\n \"`none` whatever the truth is. Enqueue the job: the result says \" +\n \"whether it ran, and the person's own dashboard says why not.\",\n );\n }\n\n const now = this.#now();\n const all = await this.#store.listRunners();\n const live = all.filter(\n (runner) =>\n runner.revokedAt === null &&\n !runner.paused &&\n now - runner.lastHeartbeatAt <= this.#livenessMs,\n );\n\n if (all.length === 0) {\n return { available: false, reason: \"no-runner-paired\", candidates: 0 };\n }\n if (live.length === 0) {\n return { available: false, reason: \"no-runner-online\", candidates: 0 };\n }\n\n let capable = 0;\n let admitted = 0;\n let lastRefusal: MatchRefusal | undefined;\n /**\n * Every advertised service for this kind, not one chosen here.\n *\n * This used to pick a single row — the one a job named, or the one the\n * owner had made the default — because a site could name a service and a\n * router matched on the name. Amendment L removed the naming, so there is\n * no row to prefer: availability is now \"does *anything* this device\n * offers for this kind admit this person\", which is also the honest\n * question, since which service actually answers is resolved from the\n * person's own mapping at claim.\n */\n for (const runner of live) {\n for (const capability of runner.capabilities.filter(\n (c) => c.kind === query.kind,\n )) {\n capable += 1;\n\n const match = matchAudience(\n {\n owner: query.owner,\n audience: query.audience ?? \"private\",\n audienceAllow: query.audienceAllow,\n },\n {\n owner: runner.owner,\n offerScope: capability.offerScope,\n // A generic backend's cost depends on its base URL, which the\n // server never sees; assume the expensive reading (byollm_007 §4).\n cost: backendDescriptor(capability.backendId).cost ?? \"metered\",\n // Consent is the daemon's to hold, and it has already applied it:\n // the offer scope arriving here is the *effective* one, so a\n // metered backend nobody agreed to share advertises `self` and is\n // refused by the scope rule above. Re-deriving consent from\n // `false` here would instead refuse every backend an owner\n // deliberately shared, because the server has no way to learn they\n // did — the signal would be wrong in the direction that breaks\n // working setups.\n spend: { acknowledged: true },\n // Same conservative assumption the claim path makes: the server\n // cannot see a remote daemon's local allowlist (protocol §4.2).\n admits: () => true,\n },\n );\n if (match.ok) admitted += 1;\n else lastRefusal = match.refusal;\n }\n }\n\n if (capable === 0) {\n // Ordered most specific first, because each sends the reader somewhere\n // different: a name that cannot serve them, a decision the device's\n // owner has not made, or nothing installed at all.\n return {\n available: false,\n reason: \"no-matching-capability\",\n candidates: 0,\n };\n }\n if (admitted === 0) {\n // Something serves it and nothing may serve *this requester*. When the\n // block is the device owner's own setting, that is the\n // defaults-meet-audiences corner — every service for this kind is one\n // this person can never use — and it is worth its own word, because\n // \"nobody is admitted\" reads as a\n // permissions problem the requester could ask to have fixed, while this\n // one is fixed by the device's owner choosing differently.\n // Whose decision blocked it, not merely that something did. The first\n // draft asked \"did the job name a service\", which reclassified a job\n // whose *own* audience was `private` and whose only device belonged to\n // somebody else — telling that caller \"the owner's default cannot serve\n // you\" when the exclusion was their own choice. An existing test caught\n // it, which is the argument for keeping the older reason rather than\n // widening the new one.\n //\n // So it splits on the refusal `matchAudience` already produced: a scope\n // or billing refusal is the *device owner's* setting, which only they\n // can change; an audience refusal is the *caller's*, which they can.\n const ownersDoing =\n lastRefusal === \"offer-scope-too-narrow\" ||\n lastRefusal === \"subscription-self-lock\" ||\n lastRefusal === \"metered-no-spend-consent\" ||\n lastRefusal === \"metered-ceiling-reached\";\n return {\n available: false,\n reason: ownersDoing ? \"default-unusable\" : \"audience-admits-nobody\",\n candidates: 0,\n };\n }\n return { available: true, candidates: admitted };\n }\n\n /**\n * Approve a pairing on behalf of an authenticated user.\n *\n * `owner` MUST come from the approving user's own session. A daemon can\n * never assert who it is — that is the whole reason pairing is interactive\n * ({@link MUSTS.PAIR_ONE_USER}, {@link MUSTS.PAIR_INTERACTIVE}).\n */\n async approvePairing(args: {\n userCode: string;\n owner: string;\n }): Promise<RunnerRecord> {\n return this.#store.approvePairing({\n userCode: normalizeUserCode(args.userCode),\n owner: args.owner,\n runnerId: generateRunnerId(),\n now: this.#now(),\n });\n }\n\n /** Deny a pairing the user did not initiate. */\n async denyPairing(userCode: string): Promise<void> {\n return this.#store.denyPairing(normalizeUserCode(userCode), this.#now());\n }\n\n /** What a pairing code refers to, for the approval page to show. */\n async pendingPairing(userCode: string): Promise<{\n label: string;\n platform: string;\n daemonVersion: string;\n capabilities: readonly { kind: string; model: string }[];\n expiresAt: number;\n } | null> {\n const pairing = await this.#store.getPairingByUserCode(\n normalizeUserCode(userCode),\n );\n if (pairing?.state !== \"pending\") return null;\n if (pairing.expiresAt <= this.#now()) return null;\n return {\n label: pairing.label,\n platform: pairing.platform,\n daemonVersion: pairing.daemonVersion,\n capabilities: pairing.capabilities.map((c) => ({\n kind: c.kind,\n model: c.model,\n })),\n expiresAt: pairing.expiresAt,\n };\n }\n\n /** The user's paired runners, for a settings page. */\n async runners(owner: string): Promise<RunnerRecord[]> {\n return this.#store.listRunners(owner);\n }\n\n /** Revoke a runner. It stops at its next heartbeat, mid-queue. */\n async revokeRunner(runnerId: string): Promise<void> {\n return this.#store.revokeRunner(runnerId, this.#now());\n }\n\n /** Run the expiry sweep. Idempotent; safe to call on a timer or a request. */\n async sweep(): Promise<JobRecord[]> {\n return this.#store.expireDue(this.#now());\n }\n}\n\n/**\n * Accept a pairing code however the user typed it — lowercase, spaces, no\n * dash. The code is displayed as `XXXX-XXXX`; refusing `xxxxxxxx` would fail\n * a user for a formatting detail they were never told mattered.\n */\nexport function normalizeUserCode(input: string): string {\n const bare = input.toUpperCase().replace(/[^A-Z0-9]/g, \"\");\n return bare.length === 8 ? `${bare.slice(0, 4)}-${bare.slice(4)}` : bare;\n}\n","import {\n PROTOCOL_VERSION,\n SealedOutcome,\n type SealedEnvelope,\n keyId,\n open,\n publicIdentityOf,\n provenanceFor,\n signSiteRequest,\n type JobStub,\n type PublicIdentity,\n type StoredKeys,\n} from \"@byollm/protocol\";\nimport { deadlineFor } from \"./records.js\";\nimport type { JobRecord } from \"./records.js\";\nimport { resealForDevice } from \"./reseal.js\";\nimport type { ByollmStore } from \"./store.js\";\n\n/**\n * The cloud lane — cloud_004 §9.4.\n *\n * `app.enqueue(...)` is identical in every lane; the lane picks the connection\n * plane. In `direct` mode a daemon reaches the site's own handlers. In `cloud`\n * mode it reaches a relay instead, and the site's side of that is this file.\n *\n * ## What actually changes, and what deliberately does not\n *\n * Enqueue does not change at all. The job is validated, sealed at rest to the\n * site's own key and stored, exactly as before — jobs-at-rest encryption is a\n * direct-mode property that the cloud lane inherits rather than replaces.\n *\n * What changes is *who asks for the payload and when*. On the direct plane the\n * daemon asks, and the site answers synchronously because it is the upstream.\n * Through a relay the site is not the upstream, so nobody asks: the site has to\n * find out that a device claimed its job, and seal to that device. Hence a\n * pump rather than a handler.\n *\n * ```\n * enqueue ──stub──▶ relay (payload stays here, sealed at rest)\n * │\n * pump ◀──who claimed it, and what key?\n * ──payload sealed to that device──▶\n * pump ◀──sealed result── ──▶ store.complete → the app's delivery channel\n * ```\n *\n * ## Why the site polls\n *\n * Everything in this product is outbound. A relay that called site webhooks\n * would need every site publicly reachable, which is the connectivity problem\n * the hub exists to remove — and a serverless site has nowhere to receive a\n * webhook anyway. So the site polls, exactly as a daemon does.\n */\n\nexport interface CloudLaneOptions {\n /** Where the relay lives, e.g. `https://relay.byollm.cloud`. */\n readonly relayOrigin: string;\n /** This site's id at the relay. */\n readonly siteId: string;\n /** Injectable fetch, for tests and for proxies. */\n readonly fetch?: typeof fetch;\n}\n\n/** What one pump cycle did, for logging and for tests. */\n/**\n * A relay that could not answer this request — alpha.31.\n *\n * `retryable` is the whole point: a draining pod and a bad signature are both\n * failures, and treating them alike is how a site either falls over on every\n * deploy or stays silently disconnected for a week.\n */\nexport class RelayUnavailable extends Error {\n readonly retryable: boolean;\n /** The protocol's own code, when the relay sent one. */\n readonly code: string;\n\n constructor(message: string, retryable: boolean, code: string) {\n super(message);\n this.name = \"RelayUnavailable\";\n this.retryable = retryable;\n this.code = code;\n }\n}\n\n/**\n * The job was not queued, and waiting will not change that.\n *\n * Distinct from {@link RelayUnavailable} because it is the opposite situation:\n * the relay answered, promptly and correctly, and the answer is that this job\n * has nowhere to go. Catching \"the relay is down\" to handle \"nobody has chosen\n * a model\" would retry forever against a fact.\n *\n * Two codes, and they belong to two different people.\n *\n * `purpose-not-declared` is the site's own manifest. It names the purpose and\n * the remedy, because a developer reading their own logs is entitled to both\n * and neither says anything about a person.\n *\n * `slot-unsatisfiable` is the person's own dashboard, and says only that.\n * Which service, whose device, whether one exists at all — none of it travels,\n * and the sentence is the same for everybody. A site learns *that* a slot\n * cannot be satisfied, which is exactly what the README has always promised\n * and what this class finally delivers.\n */\nexport class EnqueueRefused extends Error {\n /** `purpose-not-declared` or `slot-unsatisfiable`. */\n readonly code: string;\n\n constructor(message: string, code: string) {\n super(message);\n this.name = \"EnqueueRefused\";\n this.code = code;\n }\n}\n\n/**\n * The one code that means \"ask me later\" on the enqueue endpoint.\n *\n * Inverted on 2026-09-02, and the inversion is the point. This was an\n * allowlist of *refusals* — `purpose-not-declared` and `slot-unsatisfiable` —\n * which made every refusal code the relay might add next a breaking change\n * for every client already deployed: an unknown code fell through to\n * `RelayUnavailable`, so a site's `catch (error instanceof EnqueueRefused)`\n * silently stopped matching and a permanent refusal was retried forever.\n *\n * The status class is the key; a list of codes is a description of it. A 409\n * on enqueue means the relay declined to queue the job, and there is nothing\n * to await and nothing to retry — whatever the code turns out to be.\n *\n * `409` alone is not the key, which is why this is not simply deleted: the\n * protocol overloads it. `not-ready` is a draining pod saying come back, and\n * `too-late` is about a job that already exists. Neither can reach the\n * enqueue endpoint as a refusal, so the discriminator is the class *on this\n * endpoint*, with the retryable code named because it is the exception.\n *\n * The direction of the default is deliberate. An unknown code treated as a\n * refusal surfaces as an error somebody can see; treated as unavailable it\n * becomes a silent retry against a condition that will never change — which\n * is the shape of the afternoon Kevin lost.\n */\nconst RETRYABLE_AT_ENQUEUE = new Set([\"not-ready\"]);\n\n/** The endpoint where a decline means the job was never queued. */\nconst ENQUEUE_ENDPOINT = \"enqueue\";\n\nexport interface PumpReport {\n /** Jobs sealed to a claiming device this cycle. */\n readonly sealed: string[];\n /** Results opened, verified and written to the store. */\n readonly completed: string[];\n /**\n * Jobs the relay offered that this site refused to seal for.\n *\n * Never silent: a site that cannot open its own at-rest envelope has a key\n * problem, and a device waiting on a payload that will never come is\n * exactly the case `awaiting-payload` exists to bound.\n */\n readonly refused: string[];\n /**\n * Why this cycle stopped early, when it did — alpha.31.\n *\n * A relay can legitimately say \"ask me later\": a pod draining through its\n * `preStop` window answers `503 not-ready` to every routed call, and that\n * happens on **every deploy**. Before this existed the lane read the body\n * of that answer, found no `jobs` in it, and threw `TypeError: finished.jobs\n * is not iterable` — a site falling over because its relay was polite.\n *\n * Absent on an ordinary cycle. Present, with the reason, when the lane\n * deferred: a site that quietly did nothing and a site that was told to wait\n * must not look the same in a log.\n */\n readonly deferred?: string;\n}\n\nexport class CloudLane {\n readonly #options: CloudLaneOptions;\n readonly #store: ByollmStore;\n readonly #siteKeys: StoredKeys;\n readonly #now: () => number;\n readonly #fetch: typeof fetch;\n\n constructor(deps: {\n options: CloudLaneOptions;\n store: ByollmStore;\n siteKeys: StoredKeys;\n now: () => number;\n }) {\n this.#options = deps.options;\n this.#store = deps.store;\n this.#siteKeys = deps.siteKeys;\n this.#now = deps.now;\n this.#fetch = deps.options.fetch ?? globalThis.fetch;\n }\n\n /**\n * Publish a job's stub for routing.\n *\n * The stub and nothing else — byollm_009 §6 makes that exhaustive by\n * construction, so this cannot leak a payload even by mistake: there is no\n * field on `JobStub` to put one in.\n */\n async publish(record: JobRecord): Promise<void> {\n const stub: JobStub = {\n id: record.id,\n kind: record.kind,\n owner: record.owner,\n // This site, by its identity key id — Amendment A §A.3. The relay\n // already knows which site it is routing for, so this discloses nothing\n // new to it; what it adds is that the *daemon* can check the stub\n // against the envelope's `senderKeyId` without asking the relay.\n site: keyId(publicIdentityOf(this.#siteKeys).identity),\n audience: record.audience,\n // `audienceAllow` is deliberately **not** published — cloud_008 §0.2.\n //\n // It is a list of the people who may run this job, and on the direct\n // plane that is unremarkable: the site authored the list and the site is\n // the upstream, so the party receiving it already has it. Through a\n // relay it is a third party, and byollm_009 §6's enumerated metadata —\n // \"exhaustive and normative… what an upstream can see, stated as a\n // commitment\" — does not include it. It was reaching the relay on every\n // named-audience job.\n //\n // Nothing is lost by withholding it, which is why this is a Tier 0 fix\n // rather than a trade. `matchAudience` treats it as a *narrowing*:\n // `job.audienceAllow !== undefined && !includes(daemon.owner)` refuses,\n // and its absence simply falls through to the checks that actually\n // enforce — the daemon's own allowlist (`NAMED_LOCAL_ALLOWLIST`) and the\n // backend's offer scope. On this lane the relay narrows too, from the\n // control plane's rosters. The enforcement was never here.\n ...(record.purpose === undefined ? {} : { purpose: record.purpose }),\n sizeClass: record.sizeClass,\n streaming: false,\n // The relay needs *a* deadline to bound routing. A job without one gets\n // the envelope's, which is the outer bound on how long the ciphertext\n // is worth carrying — never longer than the work could possibly matter.\n // The same fallback the direct plane uses — cloud_008 Tier 4, finding\n // 31. This said `createdAt + ENVELOPE_TTL_FALLBACK`, a local constant\n // whose value happened to equal `ENVELOPE_MAX_AGE_MS`; the direct plane\n // said `(claimableAt ?? now) + ttlMs`. One field, two meanings, and a\n // job that was blocked on a dependency got a deadline measured from\n // when it was *created* on one lane and from when it became *claimable*\n // on the other.\n deadlineAt: deadlineFor(record, this.#now()),\n };\n await this.#post(\"enqueue\", {\n siteId: this.#options.siteId,\n stub,\n });\n }\n\n /**\n * Withdraw a job at the relay — cloud_008 §2.2.\n *\n * `app.cancel()` marks the site's own row terminal, which stops the *next*\n * seal. It cannot stop a device that is already running the work, because\n * on this lane the site is not the upstream: only the relay talks to the\n * daemon, and it answered `cancel: []` unconditionally.\n *\n * So the cancellation has to travel. The relay marks the job, stops\n * offering it, and names it to the holding device at its next heartbeat —\n * the same path the direct plane has always had, arriving one hop later.\n */\n async cancel(jobId: string): Promise<void> {\n await this.#post(\"cancel\", { siteId: this.#options.siteId, jobId });\n }\n\n /**\n * One cycle: seal for anything claimed, collect anything finished.\n *\n * Idempotent and safe to call as often as you like. Exposed as a single\n * cycle rather than hidden behind a timer so a caller decides its own\n * cadence — a serverless site runs it on a cron, a long-lived one on an\n * interval, and a test runs it exactly when it means to.\n */\n async pump(): Promise<PumpReport> {\n const sealed: string[] = [];\n const refused: string[] = [];\n const completed: string[] = [];\n\n try {\n return await this.#cycle(sealed, refused, completed);\n } catch (error) {\n // Retryable: end the cycle, keep what was done, say why. Anything else\n // is a fact about this site's configuration and belongs to the caller —\n // a swallowed 401 is a site disconnected from its users with nothing in\n // any log to say so.\n if (error instanceof RelayUnavailable && error.retryable) {\n return { sealed, completed, refused, deferred: error.message };\n }\n throw error;\n }\n }\n\n async #cycle(\n sealed: string[],\n refused: string[],\n completed: string[],\n ): Promise<PumpReport> {\n const pending = (await this.#get(\"pending\")) as {\n jobs: {\n jobId: string;\n device: PublicIdentity;\n runnerId: string;\n leaseId: string;\n awaitingUntil: number;\n leaseExpiresAt: number;\n }[];\n };\n for (const claim of pending.jobs) {\n const record = await this.#store.get(claim.jobId);\n if (!record) continue;\n const resealed = await resealForDevice({\n siteKeys: this.#siteKeys,\n job: {\n id: record.id,\n envelope: record.envelope,\n createdAt: record.createdAt,\n },\n device: claim.device,\n });\n if (!resealed.ok) {\n refused.push(claim.jobId);\n continue;\n }\n // Record the lease the relay granted, before handing over the work.\n //\n // The site is not the upstream here and does not decide who holds what\n // — but its own row has to know, or two things break that are not\n // cosmetic: `complete` refuses the result for want of a matching lease,\n // and the expiry sweep expires a job a device is in the middle of.\n // Adopting first means the worst case is a lease recorded for work that\n // never gets sealed, which the relay's own timeout already resolves.\n //\n // **The lease's clock, not the payload's** — cloud_008 §0.6. This\n // adopted `awaitingUntil`, which is how long the relay waits for *this\n // site to seal* (byollm_009 §7.1's third clock, ten seconds), and used\n // it as the expiry of a grant the device holds for a minute and renews\n // for as long as it works. Both of the breakages listed above then\n // happened to every job slower than the shorter clock — the site expired\n // the lease, the device finished anyway, and `complete` refused the\n // result the device had correctly produced.\n const adopted = await this.#store.adopt({\n jobId: claim.jobId,\n leaseId: claim.leaseId,\n expiresAt: claim.leaseExpiresAt,\n now: this.#now(),\n });\n // `null` means this store will not lend the job out — cloud_008 §2.2.\n //\n // Its own comment says why it refuses: a terminal or already-leased job\n // means the relay and this store disagree about reality. **And the\n // return value was being discarded**, so the site went on to seal the\n // payload to the claiming device anyway — for a job the app had already\n // cancelled, or whose deadline had passed, or that another lease\n // already owned.\n //\n // Sealing is the irreversible half: once the ciphertext is with the\n // relay, a device can fetch and run it. Refusing here is what makes\n // `adopt` a decision rather than a formality, and the job is reported\n // as refused so a site operator sees it rather than a device waiting\n // for work that will never be sealed.\n if (!adopted) {\n refused.push(claim.jobId);\n continue;\n }\n await this.#post(\"payload\", {\n siteId: this.#options.siteId,\n jobId: claim.jobId,\n envelope: resealed.envelope,\n });\n sealed.push(claim.jobId);\n }\n\n const finished = (await this.#get(\"results\")) as {\n jobs: {\n jobId: string;\n envelope: SealedEnvelope;\n disposition: string;\n runnerId: string;\n leaseId: string;\n device: PublicIdentity;\n runnerOwner: string;\n }[];\n };\n for (const done of finished.jobs) {\n const record = await this.#store.get(done.jobId);\n if (!record || record.state === \"ok\" || record.state === \"error\") {\n continue;\n }\n const outcome = await this.#openResult(done);\n if (!outcome) {\n refused.push(done.jobId);\n continue;\n }\n // Provenance is built here, from the job's audience and the device the\n // relay named — never from anything the daemon asserted. Identical to\n // the direct plane's rule, and it has to be: a result arriving via a\n // relay is not more trustworthy for having travelled further.\n await this.#store.complete({\n jobId: done.jobId,\n // The relay named the device; the signature above proved it — §3.6.\n runnerId: done.runnerId,\n // The grant, not the machine: this site never paired with the device\n // that ran it, and the signature it verified above is the stronger\n // claim about who did.\n holder: { by: \"lease\", leaseId: done.leaseId },\n outcome: outcome.outcome,\n provenance: provenanceFor({\n audience: record.audience,\n runnerId: done.runnerId,\n // The owner, from the relay's own record of who claimed it — not a\n // key id. cloud_008 §2.5: this said `keyId(device.identity)`, which\n // put a key id where the direct plane puts a user id, so an app\n // comparing provenance across lanes compared two namespaces and got\n // `false` for the same person. The device's key is still what the\n // signature was verified against, above; that is a different\n // question from whose machine it is.\n runnerOwner: done.runnerOwner,\n // From the envelope, not invented — cloud_008 §2.5. These were\n // hardcoded `\"http\"` and `\"unknown\"` because the daemon's declared\n // values stopped at the relay, which is right: a blind relay acts\n // on neither. Sealing them carries them past it untouched.\n backendClass: outcome.ran.backendClass,\n model: outcome.ran.model,\n }),\n now: this.#now(),\n });\n completed.push(done.jobId);\n }\n\n return { sealed, completed, refused };\n }\n\n /**\n * Open a sealed result and verify it came from the device that claimed it.\n *\n * The relay says which device ran the job; this checks that claim against a\n * signature the relay cannot produce. A relay that named the wrong device\n * gets a refusal, not a stored result — which is what keeps `RELAY_BLIND`\n * from quietly becoming `RELAY_TRUSTED`.\n */\n async #openResult(done: {\n jobId: string;\n envelope: SealedEnvelope;\n disposition: string;\n device: PublicIdentity;\n }): Promise<SealedOutcome | null> {\n const opened = await open({\n envelope: done.envelope,\n recipientKeys: this.#siteKeys,\n senderIdentityPublic: done.device.identity,\n expected: {\n jobId: done.jobId,\n senderKeyId: keyId(done.device.identity),\n recipientKeyId: keyId(publicIdentityOf(this.#siteKeys).identity),\n direction: \"result\",\n },\n });\n if (!opened.ok) return null;\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(opened.plaintext);\n } catch {\n return null;\n }\n const sealed = SealedOutcome.safeParse(parsed);\n if (!sealed.success) return null;\n // The clear-text disposition is a routing hint the relay acted on. This\n // is the only place it can be checked, because this is the only party\n // that can open the envelope (byollm_009 §6.1).\n if (sealed.data.outcome.outcome !== done.disposition) return null;\n return sealed.data;\n }\n\n /**\n * Sign a site-plane call with this site's identity key.\n *\n * The same scheme the daemon uses against an upstream, because the site is\n * in the same position: an outbound caller whose key the relay already holds\n * for other reasons. Nothing else authenticates this plane — a relay that\n * took the `siteId` in a body at face value would let anyone enqueue work in\n * a site's name and read who claimed it.\n */\n #headers(endpoint: string, rawBody: string): Record<string, string> {\n const signature = signSiteRequest(this.#siteKeys, {\n endpoint,\n siteId: this.#options.siteId,\n issuedAt: this.#now(),\n body: rawBody,\n });\n return {\n \"x-byollm-site\": this.#options.siteId,\n \"x-byollm-issued-at\": String(signature.issuedAt),\n \"x-byollm-signature\": signature.signature,\n };\n }\n\n /**\n * A relay answer, checked before it is believed — alpha.31.\n *\n * The bug this closes is one line long and its shape is general: a response\n * body used without looking at the status. The daemon's client has always\n * done this properly (`client.ts` maps every status to a typed refusal); the\n * site's lane parsed JSON and hoped.\n *\n * Two classes, because they need opposite handling. **Retryable** — 503 from\n * a draining pod, 429, 5xx, and the protocol's own `not-ready` — means the\n * work is still there and this cycle should end quietly. **Refused** — a bad\n * signature, an unknown site, a version this relay does not speak — will\n * still be true in five seconds, and swallowing it would leave a site\n * silently disconnected from its own users.\n */\n async #answer(response: Response, endpoint: string): Promise<unknown> {\n if (response.ok) return response.json();\n\n let code = \"\";\n let message: string;\n try {\n const body = (await response.json()) as {\n error?: string;\n message?: string;\n };\n code = body.error ?? \"\";\n message = body.message ?? \"\";\n } catch {\n // A body that is not JSON is an intermediary answering, not the relay.\n message = `HTTP ${String(response.status)}`;\n }\n\n const retryable =\n response.status >= 500 ||\n response.status === 429 ||\n code === \"not-ready\" ||\n code === \"server-error\";\n\n if (\n endpoint === ENQUEUE_ENDPOINT &&\n response.status === 409 &&\n !RETRYABLE_AT_ENQUEUE.has(code)\n ) {\n // No job exists, so there is nothing to await and nothing to retry.\n // The code travels unread: a site branching on one it does not know\n // still learns that its job was refused, which is the fact it needs.\n throw new EnqueueRefused(message, code);\n }\n\n throw new RelayUnavailable(\n `${endpoint}: ${code || \"refused\"} — ${message}`,\n retryable,\n code,\n );\n }\n\n async #post(endpoint: string, body: unknown): Promise<unknown> {\n // The version travels in the body, as it does on the daemon plane — §B.4.\n // Added here rather than at each call site so a new site-plane call cannot\n // be written without it, which is how the site plane came to be outside\n // the handshake in the first place.\n const rawBody = JSON.stringify({\n protocolVersion: PROTOCOL_VERSION,\n ...(body as Record<string, unknown>),\n });\n const response = await this.#fetch(\n `${this.#options.relayOrigin}/relay/site/${endpoint}`,\n {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...this.#headers(endpoint, rawBody),\n },\n body: rawBody,\n },\n );\n return this.#answer(response, endpoint);\n }\n\n async #get(endpoint: string): Promise<unknown> {\n // A GET has no body, so the version rides in the query — the other half\n // of `declaredVersion`, and the reason that helper takes both.\n const url =\n `${this.#options.relayOrigin}/relay/site/${endpoint}` +\n `?siteId=${encodeURIComponent(this.#options.siteId)}` +\n `&protocolVersion=${encodeURIComponent(PROTOCOL_VERSION)}`;\n // A read signs an empty body: the site id is in the query and in the\n // signed caller slot, and the relay refuses the request unless they agree.\n const response = await this.#fetch(url, {\n headers: this.#headers(endpoint, \"\"),\n });\n return this.#answer(response, endpoint);\n }\n}\n","import { StoredKeys, generateKeys, publicIdentityOf } from \"@byollm/protocol\";\nimport { fingerprint } from \"@byollm/protocol\";\n\n/**\n * A site's keypairs — byollm_009 §5.\n *\n * **Generate once, store, supply.** Not at startup, and not per process.\n *\n * A site is usually more than one process: several instances behind a load\n * balancer, or a serverless function whose module is evaluated per cold\n * start. Keys generated at startup would give each of those a different\n * identity. A daemon pins whichever one approved its pairing, and then every\n * request routed to a different instance fails a signature check with nothing\n * in the error explaining why — a failure that appears only under\n * horizontal scale, which is to say only in production.\n *\n * So the library takes keys as an input and never invents them. That is the\n * whole reason this module is three functions rather than a lazy singleton.\n */\n\n/** Make a fresh site identity. Call this once, ever, and keep the result. */\nexport const generateSiteKeys = (now: number = Date.now()): StoredKeys =>\n generateKeys(now);\n\n/**\n * Read site keys from an environment variable holding base64 JSON.\n *\n * The shape a deployment actually wants: one opaque secret, set the way every\n * other secret is set, with no file to mount and no key material in the\n * repository.\n *\n * @throws with a message naming the variable and the fix, because this fails\n * at boot and the person reading the log is the person who can fix it.\n */\nexport function siteKeysFromEnv(\n variable = \"BYOLLM_SITE_KEYS\",\n env: NodeJS.ProcessEnv = process.env,\n): StoredKeys {\n const raw = env[variable];\n if (raw === undefined || raw === \"\") {\n throw new Error(\n `${variable} is not set. Generate a site identity once with ` +\n `\\`npx @byollm/server keygen\\` and set it as ${variable}. ` +\n `Do not generate keys at startup: every instance would get a ` +\n `different identity and daemons would pin one and be refused by ` +\n `another.`,\n );\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(Buffer.from(raw, \"base64\").toString(\"utf8\"));\n } catch {\n throw new Error(\n `${variable} is not base64-encoded JSON. It should be exactly what ` +\n `\\`npx @byollm/server keygen\\` printed.`,\n );\n }\n\n const result = StoredKeys.safeParse(parsed);\n if (!result.success) {\n throw new Error(\n `${variable} does not contain a valid site identity. Regenerate it ` +\n `with \\`npx @byollm/server keygen\\` — and if this site has already ` +\n `paired daemons, they will need to pair again.`,\n );\n }\n return result.data;\n}\n\n/** What to print from `keygen`: the secret to store, and how to check it. */\nexport function formatSiteKeys(keys: StoredKeys): string {\n const encoded = Buffer.from(JSON.stringify(keys)).toString(\"base64\");\n const pub = publicIdentityOf(keys);\n return (\n `# ── 1. SECRET — set this on your server, and nowhere else ────────────\\n` +\n `#\\n` +\n `# This is the site's identity. Anything holding it can *be* this site,\\n` +\n `# so it goes wherever your deployment keeps secrets — never in a repo,\\n` +\n `# never in a browser, never pasted into a dashboard.\\n` +\n `BYOLLM_SITE_KEYS=${encoded}\\n` +\n `\\n` +\n `# ── 2. PUBLIC — paste this line into the byollm dashboard ────────────\\n` +\n `#\\n` +\n `# The public half. It proves signatures and seals nothing, so it is\\n` +\n `# safe to publish — which is the point: users pin it, and the relay\\n` +\n `# cannot forge work without the secret above.\\n` +\n `${JSON.stringify(pub)}\\n` +\n `\\n` +\n `# ── 3. Fingerprint — what a person compares by eye ───────────────────\\n` +\n `#\\n` +\n `# A fingerprint is not secret. Show it on your site so somebody\\n` +\n `# connecting can check it against what their daemon printed.\\n` +\n `# The dashboard derives this itself, so there is nothing to paste.\\n` +\n `# ${fingerprint(pub.identity)}\\n`\n );\n}\n","import {\n backendDescriptor,\n matchAudience,\n type Capability,\n} from \"@byollm/protocol\";\nimport { generateLeaseId } from \"./ids.js\";\nimport type {\n StoredJobInput,\n JobRecord,\n PairingRecord,\n RunnerRecord,\n} from \"./records.js\";\nimport type {\n ApproveArgs,\n ByollmStore,\n ClaimArgs,\n AdoptArgs,\n CompleteArgs,\n CompleteResult,\n ReleaseArgs,\n RenewArgs,\n RenewResult,\n TouchArgs,\n} from \"./store.js\";\n\n/** Tunables an embedder may want to override in tests. */\nexport interface MemoryStoreOptions {\n /** Default TTL for a job once claimable. */\n readonly defaultTtlMs?: number;\n}\n\nconst DEFAULT_TTL_MS = 15 * 60_000;\n\n/**\n * The reference store: everything in one process, no persistence.\n *\n * This is not a toy — it is the implementation the conformance kit certifies\n * first, so its semantics *are* the specification's semantics for anything\n * the prose leaves implicit. A SQL adapter is correct when the same kit\n * passes against it.\n *\n * Concurrency: JavaScript's single-threaded turn is the atomicity primitive.\n * `claim` performs its read-decide-write with no `await` inside the critical\n * section, which is what makes {@link MUSTS.CLAIM_ATOMIC} hold here. A SQL\n * adapter gets the same property from `FOR UPDATE SKIP LOCKED`.\n */\nexport class MemoryStore implements ByollmStore {\n readonly #jobs = new Map<string, JobRecord>();\n readonly #runners = new Map<string, RunnerRecord>();\n readonly #pairings = new Map<string, PairingRecord>();\n /** Job ids the app has asked to cancel, not yet acknowledged by a runner. */\n readonly #cancelRequests = new Set<string>();\n readonly #defaultTtlMs: number;\n\n constructor(options: MemoryStoreOptions = {}) {\n this.#defaultTtlMs = options.defaultTtlMs ?? DEFAULT_TTL_MS;\n }\n\n // -- jobs ---------------------------------------------------------------\n\n create(input: StoredJobInput, now: number): Promise<JobRecord> {\n // Required now: the app mints the id before sealing, because the\n // envelope binds it.\n const id = input.id;\n const existing = this.#jobs.get(id);\n // Idempotent by caller-supplied id: re-enqueueing the same id is a no-op,\n // so an app's retry cannot duplicate work (the house \"one door\" rule).\n if (existing) return Promise.resolve(existing);\n\n const dependsOn = [...(input.dependsOn ?? [])];\n const blocked = dependsOn.some(\n (depId) => this.#jobs.get(depId)?.state !== \"ok\",\n );\n\n const job: JobRecord = {\n id,\n kind: input.kind,\n envelope: input.envelope,\n sizeClass: input.sizeClass,\n audience: input.audience ?? \"private\",\n purpose: input.purpose,\n owner: input.owner,\n audienceAllow: input.audienceAllow ? [...input.audienceAllow] : undefined,\n dependsOn,\n state: \"queued\",\n lease: null,\n completedByLeaseId: null,\n createdAt: now,\n // The TTL clock starts here only if nothing blocks the job.\n claimableAt: blocked ? null : now,\n ttlMs: input.ttlMs ?? this.#defaultTtlMs,\n deadlineAt: input.deadlineAt ?? null,\n refusedBy: [],\n attempts: 0,\n outcome: null,\n provenance: null,\n updatedAt: now,\n };\n this.#write(id, job);\n return Promise.resolve(job);\n }\n\n get(jobId: string): Promise<JobRecord | null> {\n return Promise.resolve(this.#jobs.get(jobId) ?? null);\n }\n\n claim(args: ClaimArgs): Promise<JobRecord[]> {\n // Sweep first so an expired job is never handed out.\n this.#expireDueSync(args.now);\n\n const claimed: JobRecord[] = [];\n // Oldest-claimable first: a job that has waited longest goes next.\n const candidates = [...this.#jobs.values()].sort(\n (a, b) => (a.claimableAt ?? Infinity) - (b.claimableAt ?? Infinity),\n );\n\n for (const job of candidates) {\n if (claimed.length >= args.max) break;\n if (!this.#isClaimable(job, args)) continue;\n\n const updated: JobRecord = {\n ...job,\n state: \"claimed\",\n lease: {\n // A fresh id per grant. Two claims of the same job by the same\n // runner are two different leases, and must be distinguishable.\n id: generateLeaseId(),\n runnerId: args.runnerId,\n expiresAt: args.now + args.leaseMs,\n },\n attempts: job.attempts + 1,\n updatedAt: args.now,\n };\n this.#write(job.id, updated);\n claimed.push(updated);\n }\n return Promise.resolve(claimed);\n }\n\n /**\n * The claim predicate, shared by `claim` and the no-runner signal so the\n * two can never disagree about what \"a runner that could take this\" means.\n */\n #isClaimable(\n job: JobRecord,\n args: Pick<ClaimArgs, \"runnerId\" | \"runnerOwner\" | \"capabilities\" | \"now\">,\n ): boolean {\n if (job.state !== \"queued\") return false;\n if (job.claimableAt === null || job.claimableAt > args.now) return false;\n if (job.refusedBy.includes(args.runnerId)) return false;\n\n const capability = capabilityFor(args.capabilities, job.kind);\n if (!capability) return false;\n\n const match = matchAudience(\n {\n owner: job.owner,\n audience: job.audience,\n audienceAllow: job.audienceAllow,\n },\n {\n owner: args.runnerOwner,\n offerScope: capability.offerScope,\n // From the registry, not a local guess — the cost rules must mean the\n // same thing on both sides of the wire. The server cannot see a\n // remote daemon's base URL, so a generic backend with no declared\n // cost is treated as metered: the expensive side, and the daemon\n // refuses anyway if it disagrees (byollm_007 §2).\n cost: backendDescriptor(capability.backendId).cost ?? \"metered\",\n // Nor can it see the owner's spend consent. It offers; the daemon is\n // the enforcing side and releases with `refused` if its own rules say\n // no — the same shape as the `named` allowlist.\n spend: { acknowledged: true },\n // The server cannot see a remote daemon's local allowlist and must\n // not pretend to (protocol §4.2). It admits the job here; the daemon\n // is the enforcing side and releases with `refused` if its own list\n // says no.\n admits: () => true,\n },\n );\n return match.ok;\n }\n\n renewLeases(args: RenewArgs): Promise<RenewResult> {\n this.#expireDueSync(args.now);\n\n const renewed: { jobId: string; expiresAt: number }[] = [];\n const lost: { jobId: string; leaseId: string }[] = [];\n\n for (const { jobId, leaseId } of args.leases) {\n const job = this.#jobs.get(jobId);\n if (\n !job ||\n job.lease?.runnerId !== args.runnerId ||\n job.lease.id !== leaseId\n ) {\n // Reclaimed by someone else, terminal, or a different grant than the\n // one being renewed — either way this runner must stop. Named by the\n // grant the daemon asked about, which is the one it must abandon.\n lost.push({ jobId, leaseId });\n continue;\n }\n if (job.state !== \"claimed\" && job.state !== \"running\") {\n lost.push({ jobId, leaseId });\n continue;\n }\n const expiresAt = args.now + args.leaseMs;\n this.#write(jobId, {\n ...job,\n state: \"running\",\n // Renewal extends the existing grant; it does not mint a new one.\n lease: { ...job.lease, expiresAt },\n updatedAt: args.now,\n });\n renewed.push({ jobId, expiresAt });\n }\n return Promise.resolve({ renewed, lost });\n }\n\n adopt(args: AdoptArgs): Promise<JobRecord | null> {\n const job = this.#jobs.get(args.jobId);\n if (!job) return Promise.resolve(null);\n // Only a job that is genuinely available can be adopted. A terminal or\n // already-leased job means the relay and this store disagree about\n // reality, and the store's row is not the place to resolve that.\n if (job.state !== \"queued\" && job.state !== \"claimed\") {\n return Promise.resolve(null);\n }\n if (job.lease && job.lease.id !== args.leaseId) {\n return Promise.resolve(null);\n }\n const updated: JobRecord = {\n ...job,\n state: \"claimed\",\n lease: {\n id: args.leaseId,\n // No runner: this site never paired with the machine holding it.\n runnerId: \"\",\n expiresAt: args.expiresAt,\n },\n updatedAt: args.now,\n };\n this.#write(updated.id, updated);\n return Promise.resolve(updated);\n }\n\n complete(args: CompleteArgs): Promise<CompleteResult> {\n const job = this.#jobs.get(args.jobId);\n if (!job) return Promise.resolve({ accepted: false, job: null });\n\n // First terminal outcome wins; a later submission is discarded, not\n // applied ({@link MUSTS.RESULT_IDEMPOTENT}).\n // Terminal before holder — cloud_008 §3.6, and the same order in all four\n // stores. `RESULT_IDEMPOTENT` used to hold only because `complete` nulls\n // the lease, so a replay tripped the holder check first and the branch\n // named after the MUST was never reached. A MUST that byollm_009 §4's\n // case for signed requests leans on cannot hold by coincidence.\n //\n // **Scoped to the device that finished it.** A replay from that grant is\n // a duplicate and is told so; anyone else falls through to the holder\n // check and gets exactly the refusal they would get for a job that is not\n // terminal. Answering them differently would make a job id a terminality\n // probe.\n if (\n job.state === \"ok\" ||\n job.state === \"error\" ||\n job.state === \"canceled\"\n ) {\n // The same device *and* the same grant. Either alone is not the\n // device that finished the job: a lease id can be presented by whoever\n // learned it, and a device can hold a later grant on a job it never\n // completed.\n const sameDevice =\n job.provenance?.runnerId !== undefined &&\n job.provenance.runnerId === args.runnerId;\n const sameGrant =\n args.holder.by === \"lease\" &&\n job.completedByLeaseId !== null &&\n job.completedByLeaseId === args.holder.leaseId;\n if (sameDevice && sameGrant) {\n return Promise.resolve({ accepted: false, duplicate: true, job });\n }\n return Promise.resolve({ accepted: false, job });\n }\n if (job.state === \"expired\") {\n return Promise.resolve({ accepted: false, job });\n }\n // A runner that lost its lease may not write a result\n // ({@link MUSTS.LEASE_HONORED}). Named by lease id when the caller has\n // one — off the direct plane there is no runner this site knows.\n const holds =\n args.holder.by === \"runner\"\n ? job.lease?.runnerId === args.holder.runnerId\n : job.lease?.id === args.holder.leaseId;\n if (!holds) {\n return Promise.resolve({ accepted: false, job });\n }\n\n const state =\n args.outcome.outcome === \"ok\"\n ? \"ok\"\n : args.outcome.outcome === \"canceled\"\n ? \"canceled\"\n : \"error\";\n\n const updated: JobRecord = {\n ...job,\n state,\n lease: null,\n // The grant that recorded it, kept after the lease is dropped — §3.6.\n completedByLeaseId:\n args.holder.by === \"lease\"\n ? args.holder.leaseId\n : (job.lease?.id ?? null),\n outcome: args.outcome,\n provenance: args.provenance,\n updatedAt: args.now,\n };\n this.#write(job.id, updated);\n this.#cancelRequests.delete(job.id);\n\n if (state === \"ok\") this.#unblockDependents(job.id, args.now);\n\n return Promise.resolve({ accepted: true, job: updated });\n }\n\n /**\n * Start the TTL clock on anything this job was blocking.\n *\n * Deliberately only on `ok`: a dependency that errored leaves its dependents\n * blocked forever rather than releasing them into a run whose input never\n * arrived. They expire at their absolute deadline if one was set, and the\n * app sees a chain that stopped where it broke.\n */\n #unblockDependents(completedId: string, now: number): void {\n for (const job of this.#jobs.values()) {\n if (job.claimableAt !== null) continue;\n if (!job.dependsOn.includes(completedId)) continue;\n const ready = job.dependsOn.every(\n (depId) => this.#jobs.get(depId)?.state === \"ok\",\n );\n if (ready) {\n this.#write(job.id, { ...job, claimableAt: now, updatedAt: now });\n }\n }\n }\n\n /**\n * Watchers, by job id (byollm_009 §8.3).\n *\n * A `Set` per job so an unsubscribe removes exactly the handler it\n * registered — two waiters on the same job are ordinary, and removing by\n * job id alone would silently cancel someone else's wait.\n */\n readonly #watchers = new Map<string, Set<() => void>>();\n\n subscribe(jobId: string, onChange: () => void): () => void {\n const existing = this.#watchers.get(jobId) ?? new Set<() => void>();\n existing.add(onChange);\n this.#watchers.set(jobId, existing);\n let live = true;\n return () => {\n // Idempotent: the contract says calling twice is safe, and a `finally`\n // that unsubscribes after an error path already did is the normal way\n // this gets called twice.\n if (!live) return;\n live = false;\n const set = this.#watchers.get(jobId);\n set?.delete(onChange);\n if (set?.size === 0) this.#watchers.delete(jobId);\n };\n }\n\n /**\n * The single write path for a job.\n *\n * Every mutation goes through here so notification cannot be forgotten by\n * a future one. Nine call sites existed when the push seam was added, and\n * \"remember to notify\" is not a property nine call sites keep.\n */\n #write(jobId: string, record: JobRecord): void {\n this.#jobs.set(jobId, record);\n this.#notify(jobId);\n }\n\n /**\n * Tell anyone watching that a job changed.\n *\n * A throwing watcher must not corrupt the store's own bookkeeping, so each\n * is isolated: this runs inside write paths, and one bad listener taking\n * out an unrelated write would be a far worse failure than a missed\n * notification.\n */\n #notify(jobId: string): void {\n for (const watcher of this.#watchers.get(jobId) ?? []) {\n try {\n watcher();\n } catch {\n // A watcher is a signal handler; the caller re-reads regardless.\n }\n }\n }\n\n release(args: ReleaseArgs): Promise<string[]> {\n const released: string[] = [];\n for (const { jobId, leaseId } of args.leases) {\n const job = this.#jobs.get(jobId);\n // The *grant*, not just its holder. Matching on runner id alone let a\n // replayed release from an earlier lease drop a later one, returning a\n // job to the queue while the daemon was still executing it.\n if (\n !job ||\n job.lease?.runnerId !== args.runnerId ||\n job.lease.id !== leaseId\n ) {\n continue;\n }\n\n this.#write(jobId, {\n ...job,\n state: \"queued\",\n lease: null,\n completedByLeaseId: null,\n // Newly available again, so the TTL clock restarts here too.\n claimableAt: args.now,\n // A refusal is remembered, or the pair spins between claim and\n // release forever ({@link MUSTS.REFUSAL_NOT_REOFFERED}).\n refusedBy:\n args.reason === \"refused\"\n ? [...new Set([...job.refusedBy, args.runnerId])]\n : job.refusedBy,\n updatedAt: args.now,\n });\n released.push(jobId);\n }\n return Promise.resolve(released);\n }\n\n expireDue(now: number): Promise<JobRecord[]> {\n return Promise.resolve(this.#expireDueSync(now));\n }\n\n /**\n * Lease expiry and TTL expiry in one idempotent sweep.\n *\n * Order matters: a lease is reclaimed *before* the TTL is judged, so a job\n * whose runner died is offered again rather than being expired for having\n * sat in `claimed` too long.\n */\n #expireDueSync(now: number): JobRecord[] {\n const changed: JobRecord[] = [];\n\n for (const job of this.#jobs.values()) {\n if (\n (job.state === \"claimed\" || job.state === \"running\") &&\n job.lease !== null &&\n job.lease.expiresAt <= now\n ) {\n const requeued: JobRecord = {\n ...job,\n state: \"queued\",\n lease: null,\n completedByLeaseId: null,\n // The TTL clock restarts: it measures how long a job has waited\n // *unclaimed*, and this job has just become available again. Without\n // this, a job whose runner died would expire for time it spent being\n // actively worked on — losing exactly the work `kill -9` recovery\n // exists to save. Total lifetime is bounded by `deadlineAt`, which\n // is absolute and unaffected by reclaim.\n claimableAt: now,\n updatedAt: now,\n };\n this.#write(job.id, requeued);\n changed.push(requeued);\n }\n }\n\n for (const job of this.#jobs.values()) {\n if (job.state !== \"queued\") continue;\n const pastDeadline = job.deadlineAt !== null && job.deadlineAt <= now;\n const pastTtl =\n job.claimableAt !== null && job.claimableAt + job.ttlMs <= now;\n if (!pastDeadline && !pastTtl) continue;\n\n const expired: JobRecord = {\n ...job,\n state: \"expired\",\n lease: null,\n completedByLeaseId: null,\n updatedAt: now,\n };\n this.#write(job.id, expired);\n changed.push(expired);\n }\n return changed;\n }\n\n cancel(jobId: string, now: number): Promise<JobRecord | null> {\n const job = this.#jobs.get(jobId);\n if (!job) return Promise.resolve(null);\n if (job.state === \"queued\") {\n const canceled: JobRecord = {\n ...job,\n state: \"canceled\",\n lease: null,\n completedByLeaseId: null,\n updatedAt: now,\n };\n this.#write(jobId, canceled);\n return Promise.resolve(canceled);\n }\n if (job.state === \"claimed\" || job.state === \"running\") {\n // Held by a runner: the cancel travels on the next heartbeat and the\n // runner reports `canceled` itself, so the job's own state waits.\n this.#cancelRequests.add(jobId);\n return Promise.resolve(job);\n }\n return Promise.resolve(job);\n }\n\n listClaimedBy(runnerId: string): Promise<JobRecord[]> {\n return Promise.resolve(\n [...this.#jobs.values()].filter(\n (job) => job.lease?.runnerId === runnerId,\n ),\n );\n }\n\n listCancelRequests(\n runnerId: string,\n ): Promise<{ jobId: string; leaseId: string }[]> {\n return Promise.resolve(\n [...this.#cancelRequests]\n .map((jobId) => ({ jobId, lease: this.#jobs.get(jobId)?.lease }))\n .filter((row) => row.lease?.runnerId === runnerId)\n // The grant, not the id — V1-3.\n .map((row) => ({ jobId: row.jobId, leaseId: row.lease?.id ?? \"\" })),\n );\n }\n\n // -- pairing and runners -------------------------------------------------\n\n createPairing(record: PairingRecord): Promise<void> {\n this.#pairings.set(record.deviceCodeHash, record);\n return Promise.resolve();\n }\n\n getPairingByDeviceCodeHash(hash: string): Promise<PairingRecord | null> {\n return Promise.resolve(this.#pairings.get(hash) ?? null);\n }\n\n getPairingByUserCode(userCode: string): Promise<PairingRecord | null> {\n for (const pairing of this.#pairings.values()) {\n if (pairing.userCode === userCode) return Promise.resolve(pairing);\n }\n return Promise.resolve(null);\n }\n\n approvePairing(args: ApproveArgs): Promise<RunnerRecord> {\n const pairing = [...this.#pairings.values()].find(\n (p) => p.userCode === args.userCode,\n );\n if (!pairing) throw new Error(`unknown pairing code: ${args.userCode}`);\n if (pairing.expiresAt <= args.now) {\n throw new Error(\"pairing code has expired\");\n }\n if (pairing.state !== \"pending\") {\n throw new Error(`pairing is already ${pairing.state}`);\n }\n\n const runner: RunnerRecord = {\n id: args.runnerId,\n owner: args.owner,\n // Carried from the pairing, not re-supplied at approval: the user\n // approved a specific machine, and the runner must be that machine.\n device: pairing.device,\n label: pairing.label,\n platform: pairing.platform,\n daemonVersion: pairing.daemonVersion,\n capabilities: pairing.capabilities,\n paused: false,\n revokedAt: null,\n lastHeartbeatAt: args.now,\n createdAt: args.now,\n };\n this.#runners.set(runner.id, runner);\n this.#pairings.set(pairing.deviceCodeHash, {\n ...pairing,\n state: \"approved\",\n owner: args.owner,\n runnerId: runner.id,\n collected: false,\n });\n return Promise.resolve(runner);\n }\n\n denyPairing(userCode: string, _now: number): Promise<void> {\n const pairing = [...this.#pairings.values()].find(\n (p) => p.userCode === userCode,\n );\n if (pairing) {\n this.#pairings.set(pairing.deviceCodeHash, {\n ...pairing,\n state: \"denied\",\n });\n }\n return Promise.resolve();\n }\n\n consumePairingToken(deviceCodeHash: string): Promise<void> {\n const pairing = this.#pairings.get(deviceCodeHash);\n if (pairing) {\n this.#pairings.set(deviceCodeHash, {\n ...pairing,\n collected: true,\n });\n }\n return Promise.resolve();\n }\n\n getRunner(runnerId: string): Promise<RunnerRecord | null> {\n return Promise.resolve(this.#runners.get(runnerId) ?? null);\n }\n\n touchRunner(args: TouchArgs): Promise<RunnerRecord | null> {\n const runner = this.#runners.get(args.runnerId);\n if (!runner) return Promise.resolve(null);\n const updated: RunnerRecord = {\n ...runner,\n capabilities: args.capabilities,\n daemonVersion: args.daemonVersion,\n paused: args.paused,\n lastHeartbeatAt: args.now,\n };\n this.#runners.set(runner.id, updated);\n return Promise.resolve(updated);\n }\n\n revokeRunner(runnerId: string, now: number): Promise<void> {\n const runner = this.#runners.get(runnerId);\n // Revocation is one-way: an already-revoked runner keeps its first\n // revocation time rather than being re-stamped.\n if (runner?.revokedAt === null) {\n this.#runners.set(runnerId, { ...runner, revokedAt: now });\n }\n return Promise.resolve();\n }\n\n listRunners(owner?: string): Promise<RunnerRecord[]> {\n const all = [...this.#runners.values()];\n return Promise.resolve(\n owner === undefined ? all : all.filter((r) => r.owner === owner),\n );\n }\n\n // -- test/demo helpers ---------------------------------------------------\n\n /** All jobs, for demos and assertions. Not part of the store interface. */\n allJobs(): JobRecord[] {\n return [...this.#jobs.values()];\n }\n}\n\n/** The capability that would serve a kind, if any. */\nexport function capabilityFor(\n capabilities: readonly Capability[],\n kind: string,\n): Capability | undefined {\n return capabilities.find((c) => c.kind === kind);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA,SAAAA;AAAA,EACA;AAAA,EACA,oBAAAC;AAAA,EACA;AAAA,EACA;AA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AAwB;AAAA,MAC5B,GAAG;AAAA,MACH,cAAc,KAAK;AAAA,MACnB,eAAe,KAAK;AAAA,MACpB,QAAQ,KAAK;AAAA,MACb,iBAAiB,KAAK;AAAA,IACxB;AACA,SAAK,SAAS,IAAI,OAAO,IAAI,OAAO;AACpC,WAAO,QAAQ,QAAQ,OAAO;AAAA,EAChC;AAAA,EAEA,aAAa,UAAkB,KAA4B;AACzD,UAAM,SAAS,KAAK,SAAS,IAAI,QAAQ;AAGzC,QAAI,QAAQ,cAAc,MAAM;AAC9B,WAAK,SAAS,IAAI,UAAU,EAAE,GAAG,QAAQ,WAAW,IAAI,CAAC;AAAA,IAC3D;AACA,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,YAAY,OAAyC;AACnD,UAAM,MAAM,CAAC,GAAG,KAAK,SAAS,OAAO,CAAC;AACtC,WAAO,QAAQ;AAAA,MACb,UAAU,SAAY,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,UAAU,KAAK;AAAA,IACjE;AAAA,EACF;AAAA;AAAA;AAAA,EAKA,UAAuB;AACrB,WAAO,CAAC,GAAG,KAAK,MAAM,OAAO,CAAC;AAAA,EAChC;AACF;AAGO,SAAS,cACd,cACA,MACwB;AACxB,SAAO,aAAa,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AACjD;","names":["keyId","publicIdentityOf","keyId","publicIdentityOf","publicIdentityOf","backendDescriptor","matchAudience","matchAudience","backendDescriptor"]}
package/dist/next.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { H as HandlerConfig } from './handlers-DgW0QNTf.js';
1
+ import { H as HandlerConfig } from './handlers-CTV3Jc6Q.js';
2
2
  import '@byollm/protocol';
3
- import './store-Cj5b6A9j.js';
3
+ import './store-Cx2_bck1.js';
4
4
 
5
5
  /**
6
6
  * `@byollm/server/next` — the one-file Next.js mount.
package/dist/next.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createFetchHandler
3
- } from "./chunk-4NIHWQAT.js";
3
+ } from "./chunk-DG6XZQU3.js";
4
4
 
5
5
  // src/next.ts
6
6
  function createHandler(config) {