import { z } from "zod"; import { type BillingOrigin } from "@opengeni/contracts"; import { type Database } from "./database.js"; /** * Trusted in-process dispatch only: everything inside `fn` is billed as * `origin`, whatever credential the dispatched request carries. An agent's * organization action runs as its person but keeps its chat's origin; an * outside agent's runs stay API. Never call it with caller-supplied input. */ export declare function withBillingOriginOverride(origin: BillingOrigin, fn: () => Promise): Promise; /** * The origin a trusted in-process dispatcher fixed with * `withBillingOriginOverride`, if any. Unlike `ambientBillingOrigin`, this * ignores the origin a request's own credential installs. */ export declare function billingOriginOverride(): BillingOrigin | null; /** The funding origin a trusted outer scope fixed for this work, if any. */ export declare function ambientBillingOrigin(): BillingOrigin | null; /** * Who pays for a schedule's runs; a task from before origins is app. A task * this caller cannot see is never billed to plan credit. */ export declare function readScheduledTaskBillingOrigin(db: Database, input: { accountId: string; workspaceId: string; taskId: string; }): Promise; /** * Once an API caller edits or triggers a schedule, its runs are billed as API * from then on, so a key cannot spend plan credit through a task set up in * the app. A task is never turned back from API into app. */ export declare function markScheduledTaskApiBilled(db: Database, input: { accountId: string; workspaceId: string; taskId: string; }): Promise; /** * Who pays for a run a caller starts by hand: API when the caller or the * task is API, else the task's app origin. */ export declare function manualScheduledTaskRunBillingOrigin(db: Database, input: { accountId: string; workspaceId: string; taskId: string; callerOrigin: BillingOrigin; }): Promise; /** * The origin a chat's next machine turn (a goal continuation, a resume) * inherits: its latest decided turn's, else its parent chat's, else app. * Mirrors the session_turns insert trigger, so admission and charge agree. */ export declare function readSessionBillingOrigin(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; }): Promise; /** One accepted turn's frozen funding origin; null when it is not visible. */ export declare function readTurnBillingOrigin(db: Database, input: { accountId: string; workspaceId: string; turnId: string; }): Promise; export declare function currentCreditDebitAttribution(): CreditDebitAttribution; /** Scope trusted HTTP/MCP admission facts across nested sandbox calls. */ export declare function withCreditDebitAttribution(attribution: CreditDebitAttribution, fn: () => Promise): Promise; /** Read one immutable turn, rejecting a missing receipt rather than service. */ export declare function creditDebitAttributionForTurn(db: Database, input: { accountId: string; workspaceId: string; turnId: string; }): Promise; export declare const CreditDebitAttribution: z.ZodDiscriminatedUnion<[z.ZodObject<{ kind: z.ZodLiteral<"turn">; turnId: z.ZodUUID; initiatingHumanSubjectId: z.ZodNullable; billingOrigin: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kind: z.ZodLiteral<"human">; initiatingHumanSubjectId: z.ZodString; billingOrigin: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kind: z.ZodLiteral<"service">; billingOrigin: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ kind: z.ZodLiteral<"unknown">; }, z.core.$strip>], "kind">; export type CreditDebitAttribution = z.infer; export declare function creditDebitAttributionMetadata(attribution: CreditDebitAttribution): Record;