Skip to main content

Variable: SPEND_METER_DDL

const SPEND_METER_DDL: "\nCREATE TABLE IF NOT EXISTS agentos_spend_meter (\n account_id TEXT NOT NULL,\n period TEXT NOT NULL,\n allowance BIGINT NOT NULL,\n used BIGINT NOT NULL DEFAULT 0,\n reserved BIGINT NOT NULL DEFAULT 0,\n updated_at BIGINT NOT NULL,\n PRIMARY KEY (account_id, period),\n CHECK (used >= 0 AND reserved >= 0)\n);\nCREATE TABLE IF NOT EXISTS agentos_spend_reservations (\n operation_id TEXT PRIMARY KEY,\n account_id TEXT NOT NULL,\n period TEXT NOT NULL,\n units BIGINT NOT NULL,\n state TEXT NOT NULL CHECK (state IN ('reserved', 'consumed', 'released')),\n outcome TEXT,\n attempts BIGINT NOT NULL DEFAULT 1,\n reserved_at BIGINT NOT NULL,\n expires_at BIGINT NOT NULL,\n settled_at BIGINT,\n usage_json TEXT\n);\nCREATE INDEX IF NOT EXISTS idx_spend_reservations_due ON agentos_spend_reservations (state, expires_at);\nCREATE INDEX IF NOT EXISTS idx_spend_reservations_account ON agentos_spend_reservations (account_id, reserved_at);\nCREATE INDEX IF NOT EXISTS idx_spend_reservations_settled ON agentos_spend_reservations (settled_at, state);\n"

Defined in: packages/agentos/src/safety/runtime/SqlSpendMeter.ts:49

The meter's two tables and their indexes under the default prefix, agentos_spend: one index the reconciler reads the due reservations through, one a rolling window counts an account's reservations through, and one a purge finds the settled reservations through, by the time they settled. Every time is epoch milliseconds in a BIGINT. There is no literal question mark anywhere in the text: the Postgres adapter rewrites each one to a numbered parameter. A product that runs its own migrations copies this text, or spendMeterDdl's for a prefix of its own, into one of them and passes ensureSchema: false. spendMeterDdl() answers this text word for word.