@arbol-ai/maximus 8.5.2 → 8.7.0

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.
Files changed (56) hide show
  1. package/dist/analytics/analytics.d.ts +1 -1
  2. package/dist/analytics/analytics.js +1 -1
  3. package/dist/body.d.ts +1 -1
  4. package/dist/body.js +1 -1
  5. package/dist/capture/index.d.ts +1 -1
  6. package/dist/capture/index.js +2 -2
  7. package/dist/chunks/{define-app-CvTei9a8.js → define-app-CRKaiTzi.js} +46 -5
  8. package/dist/chunks/{http-layout-pnmGxDOY.js → http-layout-CB6MdZOO.js} +4 -5
  9. package/dist/chunks/{execution-BJGx5Kxb.js → meter-Mddtgv9_.js} +64 -3
  10. package/dist/chunks/{openapi-file-Crm9fT4U.js → openapi-file-D1Fz9-oO.js} +2 -2
  11. package/dist/chunks/{openapi-CoKhMm1C.js → openapi-tJeJfq1G.js} +7 -5
  12. package/dist/chunks/{pages-D0zdaO0w.js → pages-DzAPVx2p.js} +1 -1
  13. package/dist/chunks/{runtime-CUhyce4d.js → runtime-D-yNrgEP.js} +18 -6
  14. package/dist/chunks/{scaffold-DZD6dfoZ.js → scaffold-BfrJN0Yk.js} +1 -1
  15. package/dist/chunks/{scaffold-DGrcjR3h.js → scaffold-C16tbL7M.js} +1 -1
  16. package/dist/chunks/{server-tygU8dw_.js → server-D49V-Sd4.js} +5 -5
  17. package/dist/chunks/{src-DfMzoKE_.js → src-DPB9t4u0.js} +17 -10
  18. package/dist/chunks/{tasks-DYdY-dBI.js → tasks-CD-B6_nv.js} +2 -2
  19. package/dist/chunks/{tasks-C873C3le.js → tasks-DELqUSq8.js} +1 -1
  20. package/dist/chunks/{tokens-D4gRyyPu.js → tokens-CS3E9OGg.js} +83 -2
  21. package/dist/chunks/{types-BfGa2aJT.d.ts → types-hP7p4Rsp.d.ts} +233 -9
  22. package/dist/chunks/{workers-types-Cxf-5cH7.d.ts → workers-types-qWuu8LZ0.d.ts} +1 -1
  23. package/dist/client.d.ts +1 -1
  24. package/dist/diagnostics.d.ts +1 -1
  25. package/dist/diagnostics.js +1 -1
  26. package/dist/errors.d.ts +1 -1
  27. package/dist/http-paths.d.ts +1 -1
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +5 -5
  30. package/dist/internals.d.ts +2 -2
  31. package/dist/internals.js +5 -5
  32. package/dist/mcp/index.d.ts +1 -1
  33. package/dist/mcp/index.js +1 -1
  34. package/dist/mcp/tasks.d.ts +1 -1
  35. package/dist/mcp/tasks.js +1 -1
  36. package/dist/project/config.d.ts +5 -3
  37. package/dist/project/config.js +1 -1
  38. package/dist/project/index.d.ts +2 -2
  39. package/dist/project/index.js +2 -2
  40. package/dist/schemas.d.ts +1 -1
  41. package/dist/standard-failures.d.ts +1 -1
  42. package/dist/tooling/cli.js +2 -2
  43. package/dist/vite/index.d.ts +17 -2
  44. package/dist/vite/index.js +22 -10
  45. package/dist/webhooks.d.ts +1 -1
  46. package/dist/workers/runtime.d.ts +1 -1
  47. package/dist/workers/runtime.js +1 -1
  48. package/package.json +10 -10
  49. package/skills/maximus/SKILL.md +9 -7
  50. package/skills/maximus/references/project.md +6 -4
  51. package/skills/maximus/references/routes-and-tools.md +22 -0
  52. package/skills/maximus/references/testing.md +1 -1
  53. package/templates/project/.github/workflows/ci.yml.template +23 -2
  54. package/templates/project/CLAUDE.md.template +1 -1
  55. package/templates/project/README.md.template +3 -3
  56. package/templates/project/package.json.template +13 -13
@@ -98,7 +98,7 @@ async function run() {
98
98
  case "init": {
99
99
  const [target] = rest;
100
100
  if (!target) throw new TypeError("Use maximus init <new-directory> [--name <name>].");
101
- const { scaffold } = await import("../chunks/scaffold-DGrcjR3h.js");
101
+ const { scaffold } = await import("../chunks/scaffold-C16tbL7M.js");
102
102
  const name = values.name ?? basename(resolve(target));
103
103
  const created = scaffold(target, name, {
104
104
  mcp: values.mcp,
@@ -139,7 +139,7 @@ async function run() {
139
139
  return;
140
140
  }
141
141
  case "openapi": {
142
- const { writeOpenApi } = await import("../chunks/openapi-file-Crm9fT4U.js");
142
+ const { writeOpenApi } = await import("../chunks/openapi-file-D1Fz9-oO.js");
143
143
  const written = await writeOpenApi(rest[0] ?? ".", {
144
144
  ...values.out === void 0 ? {} : { out: values.out },
145
145
  check: values.check
@@ -1,4 +1,4 @@
1
- import { $n as TokenPolicy, Qn as TokenDevelopment, Xn as TokenAlgorithm } from "../chunks/types-BfGa2aJT.js";
1
+ import { Mn as RoleDefinitions, dr as TokenAlgorithm, mr as TokenPolicy, pr as TokenDevelopment } from "../chunks/types-hP7p4Rsp.js";
2
2
  import { WorkerConfig } from "cf/config";
3
3
  import { Plugin } from "vite";
4
4
  /** Where the Worker runs: `development` under `vp dev`, `production` in every build. */
@@ -55,6 +55,12 @@ interface MaximusOptions extends Omit<WorkerConfig, 'name' | 'entrypoint' | 'env
55
55
  * after the version, in words, unless its contract declares one.
56
56
  */
57
57
  groups?: Readonly<Record<string, string>>;
58
+ /**
59
+ * The service's roles, from `defineRoles()`: at most three, each saying what it may do with the service's
60
+ * resources. The build refuses a role that names a scope no public route takes and a public route no role
61
+ * may call; OpenAPI publishes each role with the scopes it holds.
62
+ */
63
+ roles?: RoleDefinitions;
58
64
  /** The version OpenAPI, the MCP server and `/health` report; by default, the package's version. */
59
65
  version?: string;
60
66
  /**
@@ -93,6 +99,13 @@ interface MaximusOptions extends Omit<WorkerConfig, 'name' | 'entrypoint' | 'env
93
99
  binding: string;
94
100
  retryAfter?: number;
95
101
  };
102
+ /**
103
+ * The billing service the routes that declare `meter` report to: the binding `env` gives its entrypoint,
104
+ * such as `{ binding: 'BILLING' }`, whose type `BillingService` names the facts it takes.
105
+ */
106
+ meter?: {
107
+ binding: string;
108
+ };
96
109
  /** The Worker's bindings, from `cf/config`'s `bindings`; the generated `Env` is inferred from them. */
97
110
  env?: WorkerConfig['env'];
98
111
  /** What a web app answers with besides its build: its response headers. */
@@ -118,6 +131,8 @@ interface CloudflareAccessOptions {
118
131
  team: string;
119
132
  /** The Access application's Application Audience (AUD) tag, from its overview in the dashboard. */
120
133
  aud: string;
134
+ /** Allow MCP when Cloudflare Access serves Managed OAuth on this application. Off by default. */
135
+ managedOAuth?: boolean;
121
136
  /**
122
137
  * The organization every caller acts in. Leave it out to read each caller's from a claim, named as
123
138
  * `claims.organization` beside the preset, such as `custom.org_id` for a custom OIDC claim.
@@ -147,7 +162,7 @@ export declare function auth0({ domain, audience, algorithms }: Auth0Options): T
147
162
  * for a team that is not a team name, such as the team's domain, and an AUD tag that is not 64 lowercase
148
163
  * hexadecimal characters.
149
164
  */
150
- export declare function cloudflareAccess({ team, aud, organizationId, scopes }: CloudflareAccessOptions): TokenOptions;
165
+ export declare function cloudflareAccess({ team, aud, managedOAuth, organizationId, scopes }: CloudflareAccessOptions): TokenOptions;
151
166
  /**
152
167
  * Maximus in Vite+: prepares the project from its files before every build and source change, brings the
153
168
  * Maximus lint and format presets, and builds, runs and deploys the Worker these options describe through
@@ -1,9 +1,9 @@
1
- import { t as checkMcpResourceNames } from "../chunks/define-app-CvTei9a8.js";
2
1
  import { a as operationPathParameters } from "../chunks/http-paths-D043DkJv.js";
3
- import { a as ownsPrefix, t as VERSIONED_PATH } from "../chunks/http-layout-pnmGxDOY.js";
4
- import { t as checkPagePaths } from "../chunks/pages-D0zdaO0w.js";
2
+ import { a as ownsPrefix, t as VERSIONED_PATH } from "../chunks/http-layout-CB6MdZOO.js";
5
3
  import { t as routeName } from "../chunks/names-ncD7A3DV.js";
4
+ import { t as checkPagePaths } from "../chunks/pages-DzAPVx2p.js";
6
5
  import { a as projectPath, i as projectFiles, o as publicFiles, r as compareNames, s as routeShape, t as PROJECT_DIRECTORIES } from "../chunks/project-files-C0OX7MQQ.js";
6
+ import { t as checkMcpResourceNames } from "../chunks/define-app-CRKaiTzi.js";
7
7
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
8
8
  import { dirname, join, posix, relative, resolve, sep } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
@@ -44,7 +44,7 @@ const SERVICE_NAME = /^(?=.{2,63}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
44
44
  /** The application's options and the Worker's settings, apart. `assets` is maximus()'s own. */
45
45
  function split(options) {
46
46
  if ("assets" in options) throw new TypeError("maximus() configures the assets: index.html at the root makes the project a web app.");
47
- const { name, namespace, title, description, groups, version, origin, tokens, rpc, http, maxBodyBytes, maxOutputBytes, rateLimit, env, services, webApp, ...worker } = options;
47
+ const { name, namespace, title, description, groups, roles, version, origin, tokens, rpc, http, maxBodyBytes, maxOutputBytes, rateLimit, meter, env, services, webApp, ...worker } = options;
48
48
  return {
49
49
  application: {
50
50
  name,
@@ -52,6 +52,7 @@ function split(options) {
52
52
  title,
53
53
  description,
54
54
  groups,
55
+ roles,
55
56
  version,
56
57
  origin,
57
58
  tokens,
@@ -59,7 +60,8 @@ function split(options) {
59
60
  http,
60
61
  maxBodyBytes,
61
62
  maxOutputBytes,
62
- rateLimit
63
+ rateLimit,
64
+ meter
63
65
  },
64
66
  env,
65
67
  services,
@@ -207,6 +209,7 @@ function projectOptions(root, options, phase = "production") {
207
209
  title: application.title ?? name,
208
210
  ...application.description === void 0 ? {} : { description: application.description },
209
211
  ...application.groups === void 0 ? {} : { groups: application.groups },
212
+ ...application.roles === void 0 ? {} : { roles: application.roles },
210
213
  version,
211
214
  origin: application.origin,
212
215
  tokens: {
@@ -217,7 +220,8 @@ function projectOptions(root, options, phase = "production") {
217
220
  rpc: application.rpc ?? { callers: [] },
218
221
  ...application.maxBodyBytes === void 0 ? {} : { maxBodyBytes: application.maxBodyBytes },
219
222
  ...application.maxOutputBytes === void 0 ? {} : { maxOutputBytes: application.maxOutputBytes },
220
- ...application.rateLimit === void 0 ? {} : { rateLimit: application.rateLimit }
223
+ ...application.rateLimit === void 0 ? {} : { rateLimit: application.rateLimit },
224
+ ...application.meter === void 0 ? {} : { meter: application.meter }
221
225
  },
222
226
  worker: {
223
227
  http: {
@@ -1103,7 +1107,8 @@ function prepareProject(directory, mode, project) {
1103
1107
  const routes = discoverRoutes(root, files.routes, application);
1104
1108
  const tools = discoverTools(root, files.mcp, application);
1105
1109
  const servesMcp = routes.mcp || tools.length > 0 || described !== void 0;
1106
- if (servesMcp && project.application.tokens.source === "cloudflare-access") throw new TypeError("A project behind Cloudflare Access serves no MCP, whose clients sign in through OAuth: remove mcp from its routes, and the mcp/ folder.");
1110
+ const { tokens } = project.application;
1111
+ if (servesMcp && tokens.source === "cloudflare-access" && tokens.access?.managedOAuth !== true) throw new TypeError("A project behind Cloudflare Access serves no MCP, whose clients sign in through OAuth: remove mcp from its routes, and the mcp/ folder.");
1107
1112
  const binders = [
1108
1113
  ...files.routes.length ? ["bindRoute"] : [],
1109
1114
  ...tools.length ? ["bindTool"] : [],
@@ -1186,6 +1191,7 @@ function prepareProject(directory, mode, project) {
1186
1191
  " base: typeof base;",
1187
1192
  ...catalog ? [" errors: typeof errors;"] : [],
1188
1193
  " env: Env;",
1194
+ ...project.application.meter ? [` meter: Env[${JSON.stringify(project.application.meter.binding)}];`] : [],
1189
1195
  " }",
1190
1196
  "}"
1191
1197
  ]),
@@ -1378,7 +1384,7 @@ function auth0({ domain, audience, algorithms = ["RS256"] }) {
1378
1384
  * for a team that is not a team name, such as the team's domain, and an AUD tag that is not 64 lowercase
1379
1385
  * hexadecimal characters.
1380
1386
  */
1381
- function cloudflareAccess({ team, aud, organizationId, scopes }) {
1387
+ function cloudflareAccess({ team, aud, managedOAuth, organizationId, scopes }) {
1382
1388
  if (typeof team !== "string" || !TEAM_NAME.test(team)) throw new TypeError("cloudflareAccess() takes the Zero Trust team name, such as acme for acme.cloudflareaccess.com.");
1383
1389
  if (typeof aud !== "string" || !AUD_TAG.test(aud)) throw new TypeError("cloudflareAccess() takes the Access application's AUD tag: 64 lowercase hexadecimal characters.");
1384
1390
  const issuer = `https://${team}.cloudflareaccess.com`;
@@ -1389,6 +1395,7 @@ function cloudflareAccess({ team, aud, organizationId, scopes }) {
1389
1395
  audience: [aud],
1390
1396
  algorithms: ["RS256"],
1391
1397
  access: {
1398
+ ...managedOAuth === void 0 ? {} : { managedOAuth },
1392
1399
  ...organizationId === void 0 ? {} : { organizationId },
1393
1400
  people: scopes.people,
1394
1401
  ...scopes.services === void 0 ? {} : { services: scopes.services }
@@ -1453,11 +1460,16 @@ function maximus(options) {
1453
1460
  project,
1454
1461
  testing()
1455
1462
  ];
1456
- const customize = () => worker;
1457
1463
  return [
1458
1464
  configure,
1459
1465
  project,
1460
- ...cloudflare({ config: customize })
1466
+ ...cloudflare({ config(loaded) {
1467
+ if (!worker) throw new TypeError("Maximus has not prepared its Worker configuration.");
1468
+ return "worker" in loaded ? {
1469
+ ...loaded,
1470
+ worker
1471
+ } : worker;
1472
+ } })
1461
1473
  ];
1462
1474
  }
1463
1475
  /** The path of this package's stand-in for `cloudflare:workers`, with this extension. */
@@ -1,4 +1,4 @@
1
- import { jr as Failure, yr as Result } from "./chunks/types-BfGa2aJT.js";
1
+ import { Kr as Failure, Pr as Result } from "./chunks/types-hP7p4Rsp.js";
2
2
  /** Why a webhook signature was refused: absent, malformed, outside the time tolerance, or not matching. */
3
3
  export declare const WEBHOOK_SIGNATURE_FAILURES: readonly ['missing', 'malformed', 'expired', 'mismatch'];
4
4
  /** Why a webhook signature was refused. */
@@ -1,2 +1,2 @@
1
- import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-Cxf-5cH7.js";
1
+ import { a as credentials, i as createWorker, n as WorkerOptions, o as WorkerAssetsOptions, r as WorkerRuntime, t as RpcMethods } from "../chunks/workers-types-qWuu8LZ0.js";
2
2
  export { RpcMethods, type WorkerAssetsOptions, WorkerOptions, WorkerRuntime, createWorker, credentials };
@@ -1,3 +1,3 @@
1
- import { n as credentials, t as createWorker } from "../chunks/runtime-CUhyce4d.js";
1
+ import { n as credentials, t as createWorker } from "../chunks/runtime-D-yNrgEP.js";
2
2
 
3
3
  export { createWorker, credentials };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arbol-ai/maximus",
3
- "version": "8.5.2",
3
+ "version": "8.7.0",
4
4
  "description": "Maximus: define a service once and serve it over HTTP, MCP and Worker RPC on Cloudflare Workers, configured in vite.config.ts, with its OpenAPI and CLI.",
5
5
  "keywords": [
6
6
  "api",
@@ -142,23 +142,23 @@
142
142
  },
143
143
  "dependencies": {
144
144
  "@modelcontextprotocol/server": "2.4.0",
145
- "@scalar/openapi-parser": "0.29.20",
145
+ "@scalar/openapi-parser": "0.29.29",
146
146
  "ajv-formats": "3.0.1",
147
- "jose": "6.2.13",
147
+ "jose": "6.2.18",
148
148
  "rou3": "1.0.0",
149
- "standardwebhooks": "1.1.1",
150
- "typebox": "1.4.5"
149
+ "standardwebhooks": "1.3.0",
150
+ "typebox": "1.4.7"
151
151
  },
152
152
  "devDependencies": {
153
- "@cloudflare/vite-plugin": "2.0.0-beta.v.5",
153
+ "@cloudflare/vite-plugin": "2.0.0-rc.7",
154
154
  "@modelcontextprotocol/ext-tasks": "0.2.3",
155
155
  "@types/pg": "8.23.1",
156
156
  "ajv": "8.20.0",
157
- "cf": "1.0.0-beta.27",
158
- "miniflare": "5.20261023.0-beta",
157
+ "cf": "1.0.0-rc.6",
158
+ "miniflare": "5.20261127.1-beta",
159
159
  "pg": "8.23.1",
160
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
161
- "vite-plus": "1.4.0",
160
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
161
+ "vite-plus": "1.8.0",
162
162
  "yaml": "2.9.1"
163
163
  },
164
164
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: maximus
3
- description: Build, extend, test, upgrade and deploy services with the Maximus framework (@arbol-ai/maximus, whose /vite entry configures a project), organization-scoped APIs on Cloudflare Workers whose route files declare each contract once and are served over HTTP with OpenAPI, as MCP tools and over Worker RPC. Use when a project configures maximus() in vite.config.ts or imports @arbol-ai/maximus, or a task involves Maximus routes, MCP tools, scopes, error catalogs, context.ts, middleware, bindings, Worker RPC, OpenAPI, tests, the maximus CLI or deploying with cf.
3
+ description: Build, extend, test, upgrade and deploy services with the Maximus framework (@arbol-ai/maximus, whose /vite entry configures a project), organization-scoped APIs on Cloudflare Workers whose route files declare each contract once and are served over HTTP with OpenAPI, as MCP tools and over Worker RPC. Use when a project configures maximus() in vite.config.ts or imports @arbol-ai/maximus, or a task involves Maximus routes, MCP tools, scopes, error catalogs, context.ts, middleware, bindings, Worker RPC, metering billable calls, OpenAPI, tests, the maximus CLI or deploying with cf.
4
4
  ---
5
5
 
6
6
  # Maximus
@@ -70,7 +70,7 @@ each one.
70
70
  | `bun run test` | `vp test run`: the tests, in Node. |
71
71
  | `bun run typecheck` | `maximus prepare`, then `tsc`, which also checks type tests. |
72
72
  | `bun run check`, `bun run fix` | Lint and format; with fixes. |
73
- | `bun run verify` | Types, lint and format, tests and the build. CI runs it. |
73
+ | `bun run verify` | Types, lint and format, and the build. CI runs it. |
74
74
  | `bun run deploy` | `bun run verify`, then `cf deploy --prebuilt --mode production`. |
75
75
  | `bunx maximus skills` | Links this skill into the project's `.agents/skills`, `.claude/skills` and `.codex/skills`. |
76
76
 
@@ -90,13 +90,14 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
90
90
  | A rule for every operation, on every transport | `defineOperationMiddleware` in `middleware/`. |
91
91
  | Headers or an early answer around every request | `defineMiddleware` in `middleware/`. It runs before admission and sees no principal. |
92
92
  | Access tokens Auth0 issues | `tokens: auth0({ domain, audience })` from `@arbol-ai/maximus/vite`, with RBAC and permissions in the access token turned on. See [references/project.md](references/project.md#tokens). |
93
- | An application behind Cloudflare Access | `tokens: cloudflareAccess({ team, aud, organizationId, scopes })` from `@arbol-ai/maximus/vite`. It serves no MCP and no OAuth discovery. See [references/project.md](references/project.md#tokens). |
93
+ | An application behind Cloudflare Access | `tokens: cloudflareAccess({ team, aud, organizationId, scopes })` from `@arbol-ai/maximus/vite`. MCP needs `managedOAuth: true` and Managed OAuth at the edge. See [references/project.md](references/project.md#tokens). |
94
94
  | Tokens your authorization server does not issue | `auth.ts` with `defineAuth({ resolve })`, which verifies cryptographically. |
95
95
  | A provider's webhook, without a token | A page named for its method, `pages/webhooks/<provider>.post.ts`, which verifies the signature on the exact bytes with `@arbol-ai/maximus/webhooks`. See [references/project.md](references/project.md). |
96
96
  | Many items in one answer | `output: Page(Item, { $id: 'ItemPage' })` with `input: PageQueryFields`. |
97
97
  | A file upload or download | `http: { body: 'bytes' }` with `body.read()`; `output: AttachmentOutputSchema` with `http: { response: 'attachment' }`. |
98
98
  | Data in Postgres | `withTenantTransaction` from `@arbol-ai/maximus/postgres`. |
99
99
  | A record of every call, for audit or a lake | `capture.ts` with `defineCapture` from `@arbol-ai/maximus/capture`; mark credential fields `secret: true`. See [Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md). |
100
+ | Charge for a call | `meter: { feature, when }` in its contract, and `meter: { binding }` in `maximus()`, typed by `BillingService`. See [Metering](https://github.com/getarbol/maximus/blob/main/docs/guides/metering.md). |
100
101
  | Guidance agents read over MCP | `mcp/instructions.md`, `mcp/guides/<name>.md`, `mcp/skills/<name>.md`: static text for every caller, never tenant data. |
101
102
  | A service on 8.2 or earlier | [Upgrading to 8.3](https://github.com/getarbol/maximus/blob/main/docs/upgrading-to-8.3.md): TypeBox 1.x. |
102
103
  | A 7.x service | [Upgrading to 8.0](https://github.com/getarbol/maximus/blob/main/docs/upgrading-to-8.md), then to 8.3. |
@@ -119,9 +120,9 @@ Every `maximus` command says what it did in a sentence; `--json` prints it as JS
119
120
  - **Exposure is explicit.** A route is a tool only with `mcp` and an RPC method only with `rpc`. Effects,
120
121
  `visibility`, descriptions and MCP hints never authorize: scopes and your own checks do.
121
122
  - **No private data in logs or errors.** Request bodies, input values, credentials, tokens, personal or
122
- clinical data never go in a log line, a failure's `data` or message, a refinement message, an MCP guide or
123
- skill, or an example. Report a caught error with `reportUnexpected(error, surface)`, which keeps its name
124
- and drops its message.
123
+ clinical data never go in a log line, a failure's `data` or message, a refinement message, a meter's
124
+ label, an MCP guide or skill, or an example. Report a caught error with `reportUnexpected(error, surface)`,
125
+ which keeps its name and drops its message.
125
126
  - **Content leaves only through capture.** Observers still receive metadata alone, never input, output or
126
127
  credentials. Capture (`capture.ts`) is a separate, declared destination, which the owner authorized on 3
127
128
  November 2026: content reaches a store through it, never through a log line, an observer or a failure. Mark
@@ -144,7 +145,7 @@ Load the one the task needs:
144
145
  the root modules, bindings and `Env`, the development token, what `prepare` generates, pages, background
145
146
  work, Durable Objects and web apps.
146
147
  - [references/routes-and-tools.md](references/routes-and-tools.md): file names and what they derive, every
147
- contract field, input, schemas and codecs, lists, byte bodies, tools, context and middleware.
148
+ contract field, input, schemas and codecs, lists, byte bodies, metering, tools, context and middleware.
148
149
  - [references/errors-and-results.md](references/errors-and-results.md): the catalog, `fail`, declared
149
150
  failures, the standard failures, uncertain outcomes and other services' failures.
150
151
  - [references/transports.md](references/transports.md): HTTP and OpenAPI, MCP, Worker RPC, and Workers
@@ -181,6 +182,7 @@ The documentation is in the Maximus repository, indexed by
181
182
  - Ship it: [Testing](https://github.com/getarbol/maximus/blob/main/docs/guides/testing.md),
182
183
  [Observability](https://github.com/getarbol/maximus/blob/main/docs/guides/observability.md),
183
184
  [Capture](https://github.com/getarbol/maximus/blob/main/docs/guides/capture.md),
185
+ [Metering](https://github.com/getarbol/maximus/blob/main/docs/guides/metering.md),
184
186
  [Deploying](https://github.com/getarbol/maximus/blob/main/docs/guides/deploying.md),
185
187
  [Lint and format](https://github.com/getarbol/maximus/blob/main/docs/guides/lint-and-format.md).
186
188
  - Reference: [Configuration](https://github.com/getarbol/maximus/blob/main/docs/reference/configuration.md),
@@ -29,11 +29,13 @@ export default defineConfig({
29
29
  | `name` | The Worker's name, the MCP server's and the scopes' prefix: lowercase letters, digits and single hyphens. By default, the package's name without its scope. |
30
30
  | `namespace`, `title`, `version` | The scopes' prefix (the name), the human name (the name), the version `/health` reports (the package's). |
31
31
  | `description`, `groups` | The OpenAPI document's description of the service, and of each group of routes by its name: `{ Notes: "The notes of the caller's organization." }`. |
32
+ | `roles` | The service's roles, from `defineRoles()`: at most three, each `{ description, can?, extends?, all? }`. `can: { read: ['notes'] }` holds `notes:notes:read`; `all: true` holds every public scope. The build refuses a scope no public route takes and a public route no role may call; OpenAPI publishes them as `x-maximus-roles`. Only a service people hold roles in declares them. |
32
33
  | `rpc` | `{ callers: ['example-orders'] }`: the services allowed to call RPC methods, by the `caller` their binding's props name, which is the calling service's `name`. None by default. |
33
34
  | `services` | `{ PRICING: { worker: 'example-pricing', openapi: '../pricing/openapi.rpc.json' } }`: other Maximus services this one calls over RPC, each bound to its Worker's `Service` entrypoint with this service as the caller, and typed from the RPC document it publishes. See [transports.md](transports.md#worker-rpc). |
34
35
  | `http` | `{ basePath, healthPath }`: `/api` and `/health` by default. |
35
36
  | `maxBodyBytes`, `maxOutputBytes` | The limits of every operation that sets none: 32 KiB and 256 KiB. |
36
37
  | `rateLimit` | `{ binding, retryAfter }`: a rate limiting binding every HTTP and MCP call passes, per organization and actor. |
38
+ | `meter` | `{ binding }`: the binding of the billing service that routes and tools declaring `meter` report to. Type it with `BillingService<Feature>` from `@arbol-ai/maximus`, whose `Feature` names the facts they may report. See [Metering](https://github.com/getarbol/maximus/blob/main/docs/guides/metering.md). |
37
39
  | `env` | The Worker's bindings, from `cf/config`'s `bindings`. |
38
40
  | `webApp` | `{ headers }` for a web app's pages and files. |
39
41
  | Any other key | A Worker setting as Cloudflare names it: `compatibilityDate`, `compatibilityFlags`, `triggers`, `exports`, `observability`, `placement`, `limits`, `domains`, `workersDev`, `previewUrls`. |
@@ -84,9 +86,9 @@ tokens: cloudflareAccess({
84
86
  that holds each caller's in `claims.organization`, beside the spread preset. The Worker then reads the
85
87
  token from `cf-access-jwt-assertion` alone and verifies it against the team's keys; a production build
86
88
  answers `404` to any host but `origin`; a write another site's page sends answers `403`; `authority.token`
87
- is absent; and the Worker serves no OAuth discovery and no MCP, so `prepare` refuses a route or a file of
88
- `mcp/` that declares MCP. Under `vp dev` and in tests, the development token still signs in as a bearer
89
- token.
89
+ is absent. The Worker serves no OAuth discovery. If Cloudflare Access serves Managed OAuth at the edge,
90
+ set `managedOAuth: true` in `cloudflareAccess()` to serve MCP with the same verified assertions and
91
+ scopes. Under `vp dev` and in tests, the development token still signs in as a bearer token.
90
92
  - Spread a preset to add what it leaves out: `tokens: { ...auth0({ domain, audience }), development: false }`.
91
93
 
92
94
  Tokens that no issuer signs, such as keys the service issues itself, are verified by `auth.ts`. See
@@ -170,7 +172,7 @@ every change), `vp build`, `vp test` and `bun run typecheck` run it. It parses m
170
172
  | `env.d.ts` | `Env`. |
171
173
  | `middleware.ts` | The modules of `middleware/`, apart by phase. |
172
174
  | `base.ts` | The application builder: configuration, `errors.ts`, `auth.ts`, `context.ts`, `telemetry.ts`, MCP Markdown, operation middleware. |
173
- | `register.d.ts` | `MaximusRegister`: types every handler's context, failures and `Env`. |
175
+ | `register.d.ts` | `MaximusRegister`: types every handler's context, failures and `Env`, and the facts a `meter` names. |
174
176
  | `app.ts` | `app`: every route and tool, built. |
175
177
  | `worker.ts`, `entry.ts` | The Worker: `export default` its handler, `export const Service` its RPC entrypoint, and the Durable Object classes. |
176
178
  | `http.ts` | `handler`: the API as the Worker serves it, for tests in Node. |
@@ -103,6 +103,7 @@ object, and its handler may return nothing.
103
103
  | `rpc` | `true` for every caller in `rpc.callers`, or `{ callers }` for some of them. |
104
104
  | `task` | `true` or `{ ttlMs }`: a call that outlasts one second answers a task (MCP Tasks, or `Prefer: respond-async`); needs `MAXIMUS_TASKS`. |
105
105
  | `maxBodyBytes`, `maxOutputBytes` | Its own limits, up to 16 MiB; the application's (32 KiB and 256 KiB) otherwise. |
106
+ | `meter` | `{ feature, when?, value?, properties? }`: the fact a billable call is, reported after the answer; see below. |
106
107
 
107
108
  A field no operation has does not compile, and `.build()` refuses it. A contract kept in a `const` keeps
108
109
  its types with `satisfies HandlerOptions`.
@@ -201,6 +202,27 @@ async ({ input, body, documents }) => {
201
202
  A download declares `output: AttachmentOutputSchema` and `http: { response: 'attachment' }`, and answers
202
203
  `{ body, contentType, filename, byteLength }`. Both are HTTP alone: never an MCP tool or an RPC method.
203
204
 
205
+ ## Metering
206
+
207
+ A route or tool that is charged for declares the fact a billable call is, and `maximus()` names the billing
208
+ service's binding, `meter: { binding: 'BILLING' }`, typed in `Env` with `BillingService<Feature>` from
209
+ `@arbol-ai/maximus`, whose `Feature` lists the facts the service reports:
210
+
211
+ ```ts
212
+ // In the contract: a lookup the source answered is one `lookups`.
213
+ meter: { feature: 'lookups', when: (output) => output.verification === 'source_report' },
214
+ ```
215
+
216
+ - `when(output, input)` says whether this answer is billable, every success when omitted; `value(output,
217
+ input)` gives its units, 1 by default; `properties(output, input)` its labels, ids and short codes alone.
218
+ - The fact is reported for `principal.organizationId`, after the answer, once, over HTTP, MCP, RPC and as a
219
+ task. A failure reports nothing, and a report that fails is logged and never fails the call.
220
+ - What happens inside the work is the handler's own call to the same binding: a cost paid on the way, whether
221
+ or not the call then succeeds, `background?.waitUntil(env.BILLING.reportUsage(principal.organizationId,
222
+ { feature: 'provider_cost', value: cost }))`, and a check before spending, `env.BILLING.canSpend(…)`.
223
+
224
+ See [Metering](https://github.com/getarbol/maximus/blob/main/docs/guides/metering.md).
225
+
204
226
  ## Tools only agents call
205
227
 
206
228
  A file of `mcp/tools/`, named in kebab-case, default-exports `defineTool(handler, contract)`:
@@ -9,7 +9,7 @@ one organization never reaches another's data, how it handles other services' fa
9
9
  - `bun run test`: `vp test run`, in Node. `vp test` prepares the project as `vp dev` does, and leaves
10
10
  Cloudflare's plugin out.
11
11
  - `bun run typecheck`: `maximus prepare && tsc`, which checks the type tests; `vp test run` does not.
12
- - `bun run verify`: types, lint and format, tests and the build.
12
+ - `bun run verify` checks types, lint and format, and builds.
13
13
 
14
14
  ## Call the API
15
15
 
@@ -2,7 +2,22 @@ name: Verify and deploy
2
2
  on:
3
3
  push:
4
4
  branches: [main]
5
+ paths-ignore: &documentation
6
+ - '**/*.md'
7
+ - '**/*.mdx'
8
+ - '**/*.rst'
9
+ - '**/*.txt'
10
+ - '**/LICENSE'
11
+ - '**/LICENSE.*'
12
+ - '**/NOTICE'
13
+ - '**/NOTICE.*'
14
+ - .github/ISSUE_TEMPLATE/**
15
+ - .github/PULL_REQUEST_TEMPLATE/**
16
+ - .github/PULL_REQUEST_TEMPLATE
17
+ - .github/CODEOWNERS
5
18
  pull_request:
19
+ paths-ignore: *documentation
20
+ types: [opened, synchronize, reopened, ready_for_review, converted_to_draft, edited, labeled, unlabeled]
6
21
  workflow_dispatch:
7
22
  permissions:
8
23
  contents: read
@@ -11,6 +26,12 @@ concurrency:
11
26
  cancel-in-progress: false
12
27
  jobs:
13
28
  deploy:
29
+ if: >-
30
+ github.event_name != 'pull_request' || (!github.event.pull_request.draft
31
+ && !startsWith(github.event.pull_request.title, 'WIP') && !startsWith(github.event.pull_request.title, '[WIP]')
32
+ && !contains(github.event.pull_request.labels.*.name, 'wip')
33
+ && !contains(github.event.pull_request.labels.*.name, 'work-in-progress')
34
+ && !contains(github.event.pull_request.labels.*.name, 'status: wip'))
14
35
  runs-on: ubuntu-latest
15
36
  timeout-minutes: 15
16
37
  env:
@@ -26,9 +47,9 @@ jobs:
26
47
  # Bun runs every command; Vite+ and Cloudflare's local runtime run on Node.js underneath.
27
48
  - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
28
49
  with:
29
- node-version: '24'
50
+ node-version: '24.22.x'
30
51
  - run: bun install --frozen-lockfile --ignore-scripts
31
- # Types, lint and format, the tests and the build.
52
+ # Types, lint, format and the build.
32
53
  - run: bun run verify
33
54
  - run: bunx cf deploy --prebuilt --mode production --dry-run
34
55
  - name: Deploy main
@@ -47,7 +47,7 @@ of tokens.issuer, so set it to the real authorization server before deploying.
47
47
  ## Workflows
48
48
 
49
49
  `bun run dev` runs the Worker locally and `bun run test` runs the tests. `bun run verify` runs type
50
- generation, TypeScript, lint and format, the tests and the build; CI runs it on every pull request. Use
50
+ generation, TypeScript, lint and format, and the build. CI runs it on ready pull requests with code changes. Use
51
51
  `cf` for Cloudflare: discover commands with `cf cli search` and inspect a command's API request with
52
52
  `cf schema` before running it. Deploy with `bun run deploy` or the GitHub workflow. Preserve unrelated work
53
53
  and Git identity configuration, and add no assistant attribution to commits.
@@ -40,8 +40,8 @@ maps every file and folder a project can hold.
40
40
 
41
41
  ## Test, verify and deploy
42
42
 
43
- `bun run test` runs the tests in `tests/` in Node, and `bun run verify` runs the types, lint and format,
44
- the tests and the build. Before the first deployment, set `origin` in `vite.config.ts` to the Worker's
43
+ `bun run test` runs the tests in `tests/` in Node. `bun run verify` checks types, lint and format, and
44
+ builds the Worker. Before the first deployment, set `origin` in `vite.config.ts` to the Worker's
45
45
  HTTPS URL (its workers.dev URL or a custom domain you own) and `tokens.issuer` to your authorization server.
46
46
  Then:
47
47
 
@@ -50,6 +50,6 @@ bunx cf auth login
50
50
  bun run deploy
51
51
  ```
52
52
 
53
- The GitHub workflow verifies every pull request and deploys `main`, given the repository secrets
53
+ The GitHub workflow verifies ready pull requests with code changes and deploys `main`, given the repository secrets
54
54
  `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The
55
55
  [Maximus documentation](https://github.com/getarbol/maximus/blob/main/docs/README.md) covers the rest.
@@ -16,31 +16,31 @@
16
16
  "typecheck": "maximus prepare && tsc",
17
17
  "check": "vp check",
18
18
  "fix": "vp check --fix",
19
- "verify": "bun run typecheck && bun run check && bun run test && bun run build",
19
+ "verify": "bun run typecheck && bun run check && bun run build",
20
20
  "deploy": "bun run verify && cf deploy --prebuilt --mode production"
21
21
  },
22
22
  "dependencies": {
23
23
  "@arbol-ai/maximus": "__MAXIMUS_VERSION__"
24
24
  },
25
25
  "devDependencies": {
26
- "@cloudflare/vite-plugin": "2.0.0-beta.v.5",
27
- "@cloudflare/workers-types": "5.20261027.1",
28
- "@types/node": "26.6.5",
29
- "cf": "1.0.0-beta.23",
30
- "oxfmt": "0.74.0",
31
- "oxlint": "1.89.0",
26
+ "@cloudflare/vite-plugin": "2.0.0-rc.5",
27
+ "@cloudflare/workers-types": "5.20261125.1",
28
+ "@types/node": "26.6.11",
29
+ "cf": "1.0.0-rc.6",
30
+ "oxfmt": "0.80.0",
31
+ "oxlint": "1.95.0",
32
32
  "typescript": "7.0.2",
33
- "ultracite": "8.1.0",
34
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
35
- "vite-plus": "1.4.0"
33
+ "ultracite": "8.3.1",
34
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
35
+ "vite-plus": "1.8.0"
36
36
  },
37
37
  "overrides": {
38
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
39
- "vitest": "5.0.5"
38
+ "vite": "npm:@voidzero-dev/vite-plus-core@8.3.8001",
39
+ "vitest": "5.1.1"
40
40
  },
41
41
  "engines": {
42
42
  "bun": ">=1.4.4",
43
- "node": ">=22.18"
43
+ "node": "^22.23.0 || ^24.22.0 || ^26.12.0"
44
44
  },
45
45
  "packageManager": "bun@1.4.4"
46
46
  }