@nixet/contracts 0.0.0-stage → 0.1.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 (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/cjs/domains/agents.d.ts +284 -0
  4. package/dist/cjs/domains/agents.js +244 -0
  5. package/dist/cjs/domains/api-keys.d.ts +265 -0
  6. package/dist/cjs/domains/api-keys.js +87 -0
  7. package/dist/cjs/domains/billing.d.ts +98 -0
  8. package/dist/cjs/domains/billing.js +122 -0
  9. package/dist/cjs/domains/connections.d.ts +101 -0
  10. package/dist/cjs/domains/connections.js +130 -0
  11. package/dist/cjs/domains/conversations.d.ts +113 -0
  12. package/dist/cjs/domains/conversations.js +85 -0
  13. package/dist/cjs/domains/documents.d.ts +48 -0
  14. package/dist/cjs/domains/documents.js +64 -0
  15. package/dist/cjs/domains/guardrails.d.ts +211 -0
  16. package/dist/cjs/domains/guardrails.js +206 -0
  17. package/dist/cjs/domains/identity.d.ts +55 -0
  18. package/dist/cjs/domains/identity.js +26 -0
  19. package/dist/cjs/domains/knowledge.d.ts +167 -0
  20. package/dist/cjs/domains/knowledge.js +174 -0
  21. package/dist/cjs/domains/mcp.d.ts +189 -0
  22. package/dist/cjs/domains/mcp.js +183 -0
  23. package/dist/cjs/domains/memory.d.ts +109 -0
  24. package/dist/cjs/domains/memory.js +92 -0
  25. package/dist/cjs/domains/redaction.d.ts +181 -0
  26. package/dist/cjs/domains/redaction.js +166 -0
  27. package/dist/cjs/domains/runs.d.ts +260 -0
  28. package/dist/cjs/domains/runs.js +260 -0
  29. package/dist/cjs/domains/secrets.d.ts +56 -0
  30. package/dist/cjs/domains/secrets.js +72 -0
  31. package/dist/cjs/domains/skills.d.ts +70 -0
  32. package/dist/cjs/domains/skills.js +82 -0
  33. package/dist/cjs/domains/tasks.d.ts +111 -0
  34. package/dist/cjs/domains/tasks.js +113 -0
  35. package/dist/cjs/domains/tools.d.ts +159 -0
  36. package/dist/cjs/domains/tools.js +203 -0
  37. package/dist/cjs/domains/users.d.ts +40 -0
  38. package/dist/cjs/domains/users.js +48 -0
  39. package/dist/cjs/index.d.ts +25 -0
  40. package/dist/cjs/index.js +41 -0
  41. package/dist/cjs/primitives.d.ts +75 -0
  42. package/dist/cjs/primitives.js +117 -0
  43. package/dist/esm/domains/agents.js +239 -0
  44. package/dist/esm/domains/api-keys.js +83 -0
  45. package/dist/esm/domains/billing.js +116 -0
  46. package/dist/esm/domains/connections.js +127 -0
  47. package/dist/esm/domains/conversations.js +82 -0
  48. package/dist/esm/domains/documents.js +61 -0
  49. package/dist/esm/domains/guardrails.js +202 -0
  50. package/dist/esm/domains/identity.js +23 -0
  51. package/dist/esm/domains/knowledge.js +170 -0
  52. package/dist/esm/domains/mcp.js +178 -0
  53. package/dist/esm/domains/memory.js +89 -0
  54. package/dist/esm/domains/redaction.js +162 -0
  55. package/dist/esm/domains/runs.js +256 -0
  56. package/dist/esm/domains/secrets.js +68 -0
  57. package/dist/esm/domains/skills.js +79 -0
  58. package/dist/esm/domains/tasks.js +109 -0
  59. package/dist/esm/domains/tools.js +196 -0
  60. package/dist/esm/domains/users.js +45 -0
  61. package/dist/esm/index.js +25 -0
  62. package/dist/esm/package.json +1 -0
  63. package/dist/esm/primitives.js +114 -0
  64. package/package.json +38 -4
@@ -0,0 +1,265 @@
1
+ import { z } from "zod";
2
+ import { type Environment } from "../primitives.js";
3
+ export declare const apiKeyStatusSchema: z.ZodEnum<{
4
+ active: "active";
5
+ revoked: "revoked";
6
+ expired: "expired";
7
+ }>;
8
+ export type ApiKeyStatus = z.infer<typeof apiKeyStatusSchema>;
9
+ /** Key metadata. Safe to list, cache and render. Carries no secret material. */
10
+ export declare const apiKeySchema: z.ZodObject<{
11
+ id: z.ZodString;
12
+ name: z.ZodString;
13
+ prefix: z.ZodString;
14
+ status: z.ZodEnum<{
15
+ active: "active";
16
+ revoked: "revoked";
17
+ expired: "expired";
18
+ }>;
19
+ permissions: z.ZodArray<z.ZodEnum<{
20
+ "api_keys:read": "api_keys:read";
21
+ "agents:read": "agents:read";
22
+ "agents:write": "agents:write";
23
+ "runs:read": "runs:read";
24
+ "runs:write": "runs:write";
25
+ "users:read": "users:read";
26
+ "users:write": "users:write";
27
+ "conversations:read": "conversations:read";
28
+ "conversations:write": "conversations:write";
29
+ "memory:read": "memory:read";
30
+ "memory:write": "memory:write";
31
+ "secrets:read": "secrets:read";
32
+ "secrets:write": "secrets:write";
33
+ "mcp:read": "mcp:read";
34
+ "mcp:write": "mcp:write";
35
+ "connections:read": "connections:read";
36
+ "connections:write": "connections:write";
37
+ "knowledge:read": "knowledge:read";
38
+ "knowledge:write": "knowledge:write";
39
+ "billing:read": "billing:read";
40
+ }>>;
41
+ scope: z.ZodObject<{
42
+ organization_id: z.ZodString;
43
+ project_id: z.ZodString;
44
+ environment_id: z.ZodEnum<{
45
+ development: "development";
46
+ production: "production";
47
+ }>;
48
+ }, z.core.$strip>;
49
+ created_at: z.ZodString;
50
+ expires_at: z.ZodString;
51
+ last_used_at: z.ZodNullable<z.ZodString>;
52
+ revoked_at: z.ZodNullable<z.ZodString>;
53
+ }, z.core.$strip>;
54
+ export type ApiKey = z.infer<typeof apiKeySchema>;
55
+ export declare const MAX_KEY_NAME_LENGTH = 80;
56
+ export declare const MIN_EXPIRY_DAYS = 1;
57
+ export declare const MAX_EXPIRY_DAYS = 365;
58
+ export declare const DEFAULT_EXPIRY_DAYS = 90;
59
+ /**
60
+ * Creation request. Ownership is never accepted from the body: scope comes from
61
+ * verified session context and scope headers, so `strict()` rejects any attempt
62
+ * to smuggle `organization_id` or a status field through creation.
63
+ */
64
+ export declare const createApiKeySchema: z.ZodObject<{
65
+ name: z.ZodString;
66
+ permissions: z.ZodArray<z.ZodEnum<{
67
+ "api_keys:read": "api_keys:read";
68
+ "agents:read": "agents:read";
69
+ "agents:write": "agents:write";
70
+ "runs:read": "runs:read";
71
+ "runs:write": "runs:write";
72
+ "users:read": "users:read";
73
+ "users:write": "users:write";
74
+ "conversations:read": "conversations:read";
75
+ "conversations:write": "conversations:write";
76
+ "memory:read": "memory:read";
77
+ "memory:write": "memory:write";
78
+ "secrets:read": "secrets:read";
79
+ "secrets:write": "secrets:write";
80
+ "mcp:read": "mcp:read";
81
+ "mcp:write": "mcp:write";
82
+ "connections:read": "connections:read";
83
+ "connections:write": "connections:write";
84
+ "knowledge:read": "knowledge:read";
85
+ "knowledge:write": "knowledge:write";
86
+ "billing:read": "billing:read";
87
+ }>>;
88
+ expires_in_days: z.ZodDefault<z.ZodNumber>;
89
+ }, z.core.$strict>;
90
+ export type CreateApiKeyRequest = z.infer<typeof createApiKeySchema>;
91
+ export declare const DEFAULT_PAGE_SIZE = 25;
92
+ export declare const MAX_PAGE_SIZE = 100;
93
+ /**
94
+ * List query, paginated with `$limit` and `$offset`.
95
+ */
96
+ export declare const listApiKeysQuerySchema: z.ZodObject<{
97
+ $limit: z.ZodDefault<z.ZodNumber>;
98
+ $offset: z.ZodDefault<z.ZodNumber>;
99
+ status: z.ZodOptional<z.ZodEnum<{
100
+ active: "active";
101
+ revoked: "revoked";
102
+ expired: "expired";
103
+ }>>;
104
+ }, z.core.$strict>;
105
+ export type ListApiKeysQuery = z.infer<typeof listApiKeysQuerySchema>;
106
+ /**
107
+ * List envelope. Matches the framework response shape `{ message, data, count }`,
108
+ * where `count` is the total number of scoped rows.
109
+ */
110
+ export declare const apiKeyListResponseSchema: z.ZodObject<{
111
+ message: z.ZodString;
112
+ data: z.ZodArray<z.ZodObject<{
113
+ id: z.ZodString;
114
+ name: z.ZodString;
115
+ prefix: z.ZodString;
116
+ status: z.ZodEnum<{
117
+ active: "active";
118
+ revoked: "revoked";
119
+ expired: "expired";
120
+ }>;
121
+ permissions: z.ZodArray<z.ZodEnum<{
122
+ "api_keys:read": "api_keys:read";
123
+ "agents:read": "agents:read";
124
+ "agents:write": "agents:write";
125
+ "runs:read": "runs:read";
126
+ "runs:write": "runs:write";
127
+ "users:read": "users:read";
128
+ "users:write": "users:write";
129
+ "conversations:read": "conversations:read";
130
+ "conversations:write": "conversations:write";
131
+ "memory:read": "memory:read";
132
+ "memory:write": "memory:write";
133
+ "secrets:read": "secrets:read";
134
+ "secrets:write": "secrets:write";
135
+ "mcp:read": "mcp:read";
136
+ "mcp:write": "mcp:write";
137
+ "connections:read": "connections:read";
138
+ "connections:write": "connections:write";
139
+ "knowledge:read": "knowledge:read";
140
+ "knowledge:write": "knowledge:write";
141
+ "billing:read": "billing:read";
142
+ }>>;
143
+ scope: z.ZodObject<{
144
+ organization_id: z.ZodString;
145
+ project_id: z.ZodString;
146
+ environment_id: z.ZodEnum<{
147
+ development: "development";
148
+ production: "production";
149
+ }>;
150
+ }, z.core.$strip>;
151
+ created_at: z.ZodString;
152
+ expires_at: z.ZodString;
153
+ last_used_at: z.ZodNullable<z.ZodString>;
154
+ revoked_at: z.ZodNullable<z.ZodString>;
155
+ }, z.core.$strip>>;
156
+ count: z.ZodNumber;
157
+ }, z.core.$strip>;
158
+ export type ApiKeyListResponse = z.infer<typeof apiKeyListResponseSchema>;
159
+ export declare const apiKeyResponseSchema: z.ZodObject<{
160
+ message: z.ZodString;
161
+ data: z.ZodObject<{
162
+ id: z.ZodString;
163
+ name: z.ZodString;
164
+ prefix: z.ZodString;
165
+ status: z.ZodEnum<{
166
+ active: "active";
167
+ revoked: "revoked";
168
+ expired: "expired";
169
+ }>;
170
+ permissions: z.ZodArray<z.ZodEnum<{
171
+ "api_keys:read": "api_keys:read";
172
+ "agents:read": "agents:read";
173
+ "agents:write": "agents:write";
174
+ "runs:read": "runs:read";
175
+ "runs:write": "runs:write";
176
+ "users:read": "users:read";
177
+ "users:write": "users:write";
178
+ "conversations:read": "conversations:read";
179
+ "conversations:write": "conversations:write";
180
+ "memory:read": "memory:read";
181
+ "memory:write": "memory:write";
182
+ "secrets:read": "secrets:read";
183
+ "secrets:write": "secrets:write";
184
+ "mcp:read": "mcp:read";
185
+ "mcp:write": "mcp:write";
186
+ "connections:read": "connections:read";
187
+ "connections:write": "connections:write";
188
+ "knowledge:read": "knowledge:read";
189
+ "knowledge:write": "knowledge:write";
190
+ "billing:read": "billing:read";
191
+ }>>;
192
+ scope: z.ZodObject<{
193
+ organization_id: z.ZodString;
194
+ project_id: z.ZodString;
195
+ environment_id: z.ZodEnum<{
196
+ development: "development";
197
+ production: "production";
198
+ }>;
199
+ }, z.core.$strip>;
200
+ created_at: z.ZodString;
201
+ expires_at: z.ZodString;
202
+ last_used_at: z.ZodNullable<z.ZodString>;
203
+ revoked_at: z.ZodNullable<z.ZodString>;
204
+ }, z.core.$strip>;
205
+ }, z.core.$strip>;
206
+ /**
207
+ * Creation response. `secret` is present exactly once, on the original 201.
208
+ * A replayed idempotent request returns `replayed: true` with no secret,
209
+ * because the plaintext is unrecoverable by design.
210
+ */
211
+ export declare const createApiKeyResponseSchema: z.ZodObject<{
212
+ message: z.ZodString;
213
+ data: z.ZodObject<{
214
+ key: z.ZodObject<{
215
+ id: z.ZodString;
216
+ name: z.ZodString;
217
+ prefix: z.ZodString;
218
+ status: z.ZodEnum<{
219
+ active: "active";
220
+ revoked: "revoked";
221
+ expired: "expired";
222
+ }>;
223
+ permissions: z.ZodArray<z.ZodEnum<{
224
+ "api_keys:read": "api_keys:read";
225
+ "agents:read": "agents:read";
226
+ "agents:write": "agents:write";
227
+ "runs:read": "runs:read";
228
+ "runs:write": "runs:write";
229
+ "users:read": "users:read";
230
+ "users:write": "users:write";
231
+ "conversations:read": "conversations:read";
232
+ "conversations:write": "conversations:write";
233
+ "memory:read": "memory:read";
234
+ "memory:write": "memory:write";
235
+ "secrets:read": "secrets:read";
236
+ "secrets:write": "secrets:write";
237
+ "mcp:read": "mcp:read";
238
+ "mcp:write": "mcp:write";
239
+ "connections:read": "connections:read";
240
+ "connections:write": "connections:write";
241
+ "knowledge:read": "knowledge:read";
242
+ "knowledge:write": "knowledge:write";
243
+ "billing:read": "billing:read";
244
+ }>>;
245
+ scope: z.ZodObject<{
246
+ organization_id: z.ZodString;
247
+ project_id: z.ZodString;
248
+ environment_id: z.ZodEnum<{
249
+ development: "development";
250
+ production: "production";
251
+ }>;
252
+ }, z.core.$strip>;
253
+ created_at: z.ZodString;
254
+ expires_at: z.ZodString;
255
+ last_used_at: z.ZodNullable<z.ZodString>;
256
+ revoked_at: z.ZodNullable<z.ZodString>;
257
+ }, z.core.$strip>;
258
+ secret: z.ZodOptional<z.ZodString>;
259
+ replayed: z.ZodBoolean;
260
+ }, z.core.$strip>;
261
+ }, z.core.$strip>;
262
+ export type CreateApiKeyResponse = z.infer<typeof createApiKeyResponseSchema>;
263
+ export declare const KEY_PREFIX = "nxt";
264
+ /** `nxt_<env>_<random>` — the prefix is stored, the random tail never is. */
265
+ export declare const keyPrefixFor: (environment: Environment) => string;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keyPrefixFor = exports.KEY_PREFIX = exports.createApiKeyResponseSchema = exports.apiKeyResponseSchema = exports.apiKeyListResponseSchema = exports.listApiKeysQuerySchema = exports.MAX_PAGE_SIZE = exports.DEFAULT_PAGE_SIZE = exports.createApiKeySchema = exports.DEFAULT_EXPIRY_DAYS = exports.MAX_EXPIRY_DAYS = exports.MIN_EXPIRY_DAYS = exports.MAX_KEY_NAME_LENGTH = exports.apiKeySchema = exports.apiKeyStatusSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const primitives_js_1 = require("../primitives.js");
6
+ exports.apiKeyStatusSchema = zod_1.z.enum(["active", "revoked", "expired"]);
7
+ /** Key metadata. Safe to list, cache and render. Carries no secret material. */
8
+ exports.apiKeySchema = zod_1.z.object({
9
+ id: zod_1.z.string(),
10
+ name: zod_1.z.string(),
11
+ prefix: zod_1.z.string(),
12
+ status: exports.apiKeyStatusSchema,
13
+ permissions: zod_1.z.array(primitives_js_1.permissionSchema),
14
+ scope: primitives_js_1.scopeSchema,
15
+ created_at: zod_1.z.string(),
16
+ expires_at: zod_1.z.string(),
17
+ last_used_at: zod_1.z.string().nullable(),
18
+ revoked_at: zod_1.z.string().nullable(),
19
+ });
20
+ exports.MAX_KEY_NAME_LENGTH = 80;
21
+ exports.MIN_EXPIRY_DAYS = 1;
22
+ exports.MAX_EXPIRY_DAYS = 365;
23
+ exports.DEFAULT_EXPIRY_DAYS = 90;
24
+ /**
25
+ * Creation request. Ownership is never accepted from the body: scope comes from
26
+ * verified session context and scope headers, so `strict()` rejects any attempt
27
+ * to smuggle `organization_id` or a status field through creation.
28
+ */
29
+ exports.createApiKeySchema = zod_1.z
30
+ .object({
31
+ name: zod_1.z.string().trim().min(1).max(exports.MAX_KEY_NAME_LENGTH),
32
+ // Derived, not a literal: a hardcoded cap silently rejects every key once
33
+ // a new permission is added.
34
+ permissions: zod_1.z
35
+ .array(primitives_js_1.permissionSchema)
36
+ .min(1)
37
+ .max(primitives_js_1.permissionSchema.options.length),
38
+ expires_in_days: zod_1.z
39
+ .number()
40
+ .int()
41
+ .min(exports.MIN_EXPIRY_DAYS)
42
+ .max(exports.MAX_EXPIRY_DAYS)
43
+ .default(exports.DEFAULT_EXPIRY_DAYS),
44
+ })
45
+ .strict();
46
+ exports.DEFAULT_PAGE_SIZE = 25;
47
+ exports.MAX_PAGE_SIZE = 100;
48
+ /**
49
+ * List query, paginated with `$limit` and `$offset`.
50
+ */
51
+ exports.listApiKeysQuerySchema = zod_1.z
52
+ .object({
53
+ $limit: zod_1.z.number().int().min(1).max(exports.MAX_PAGE_SIZE).default(exports.DEFAULT_PAGE_SIZE),
54
+ $offset: zod_1.z.number().int().min(0).default(0),
55
+ status: exports.apiKeyStatusSchema.optional(),
56
+ })
57
+ .strict();
58
+ /**
59
+ * List envelope. Matches the framework response shape `{ message, data, count }`,
60
+ * where `count` is the total number of scoped rows.
61
+ */
62
+ exports.apiKeyListResponseSchema = zod_1.z.object({
63
+ message: zod_1.z.string(),
64
+ data: zod_1.z.array(exports.apiKeySchema),
65
+ count: zod_1.z.number().int().nonnegative(),
66
+ });
67
+ exports.apiKeyResponseSchema = zod_1.z.object({
68
+ message: zod_1.z.string(),
69
+ data: exports.apiKeySchema,
70
+ });
71
+ /**
72
+ * Creation response. `secret` is present exactly once, on the original 201.
73
+ * A replayed idempotent request returns `replayed: true` with no secret,
74
+ * because the plaintext is unrecoverable by design.
75
+ */
76
+ exports.createApiKeyResponseSchema = zod_1.z.object({
77
+ message: zod_1.z.string(),
78
+ data: zod_1.z.object({
79
+ key: exports.apiKeySchema,
80
+ secret: zod_1.z.string().optional(),
81
+ replayed: zod_1.z.boolean(),
82
+ }),
83
+ });
84
+ exports.KEY_PREFIX = "nxt";
85
+ /** `nxt_<env>_<random>` — the prefix is stored, the random tail never is. */
86
+ const keyPrefixFor = (environment) => `${exports.KEY_PREFIX}_${environment === "production" ? "live" : "dev"}`;
87
+ exports.keyPrefixFor = keyPrefixFor;
@@ -0,0 +1,98 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Billing: what a workspace is allowed, and what it has used.
4
+ *
5
+ * An organization exists in the identity provider, which owns identity. The row here is the
6
+ * part that is ours — a plan, a counter, and eventually a Stripe customer —
7
+ * created the first time we see a workspace rather than at signup, because
8
+ * signup is a flow we do not own.
9
+ *
10
+ * A run is the billable unit. Not tokens, which are the provider's unit, and
11
+ * not seats, which would charge for the second person to look at a failure.
12
+ */
13
+ export declare const planSchema: z.ZodEnum<{
14
+ free: "free";
15
+ pro: "pro";
16
+ scale: "scale";
17
+ enterprise: "enterprise";
18
+ }>;
19
+ export type Plan = z.infer<typeof planSchema>;
20
+ /**
21
+ * What each plan includes.
22
+ *
23
+ * `runsIncluded` is copied onto the organization when the plan is set, so a
24
+ * negotiated enterprise allowance is a column rather than a special case in
25
+ * code. These are the defaults, not the authority.
26
+ *
27
+ * `overage` is null where there is none: Free is a wall, Enterprise is a
28
+ * committed rate with no wall at all. Stopping an enterprise customer's
29
+ * production traffic over a counter is a support incident, not a control.
30
+ */
31
+ export declare const PLANS: Record<Plan, {
32
+ runsIncluded: number;
33
+ /** USD per thousand runs beyond the allowance, or null for no overage. */
34
+ overagePerThousand: number | null;
35
+ /** Days a trace is kept. */
36
+ retentionDays: number;
37
+ /** What managed inference is marked up by. BYO key is never marked up. */
38
+ inferenceMarkup: number;
39
+ monthlyUsd: number | null;
40
+ }>;
41
+ /** Whether a plan stops at its allowance or bills past it. */
42
+ export declare function isHardLimit(plan: Plan): boolean;
43
+ export declare const organizationSchema: z.ZodObject<{
44
+ id: z.ZodString;
45
+ plan: z.ZodEnum<{
46
+ free: "free";
47
+ pro: "pro";
48
+ scale: "scale";
49
+ enterprise: "enterprise";
50
+ }>;
51
+ runs_included: z.ZodNumber;
52
+ period_start: z.ZodString;
53
+ period_end: z.ZodString;
54
+ stripe_customer_id: z.ZodNullable<z.ZodString>;
55
+ stripe_subscription_id: z.ZodNullable<z.ZodString>;
56
+ created_at: z.ZodString;
57
+ updated_at: z.ZodString;
58
+ }, z.core.$strip>;
59
+ export type Organization = z.infer<typeof organizationSchema>;
60
+ /**
61
+ * What a workspace has used this period.
62
+ *
63
+ * `runs_used` is incremented as runs finish rather than counted on demand:
64
+ * admission has to answer on every request, and a count over the runs table is
65
+ * a scan of the busiest thing we have. `usage_events` is what makes that
66
+ * honest — the counter is a cache of a sum that can always be rebuilt.
67
+ */
68
+ export declare const periodUsageSchema: z.ZodObject<{
69
+ plan: z.ZodEnum<{
70
+ free: "free";
71
+ pro: "pro";
72
+ scale: "scale";
73
+ enterprise: "enterprise";
74
+ }>;
75
+ period_start: z.ZodString;
76
+ period_end: z.ZodString;
77
+ runs_used: z.ZodNumber;
78
+ runs_included: z.ZodNumber;
79
+ cost_usd: z.ZodNumber;
80
+ overage_runs: z.ZodNumber;
81
+ overage_usd: z.ZodNumber;
82
+ at_limit: z.ZodBoolean;
83
+ }, z.core.$strip>;
84
+ export type PeriodUsage = z.infer<typeof periodUsageSchema>;
85
+ /**
86
+ * What the overage costs, given a plan and how many runs were used.
87
+ *
88
+ * Charged per thousand and rounded up, which is how the plans are written: a
89
+ * single run past the allowance costs the first thousand's price. Returns zero
90
+ * where the plan has no overage, because there the answer is a refusal rather
91
+ * than a charge.
92
+ */
93
+ export declare function overageFor(plan: Plan, runsUsed: number, runsIncluded: number): {
94
+ runs: number;
95
+ usd: number;
96
+ };
97
+ /** Whether another run may start. */
98
+ export declare function withinAllowance(plan: Plan, runsUsed: number, runsIncluded: number): boolean;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.periodUsageSchema = exports.organizationSchema = exports.PLANS = exports.planSchema = void 0;
4
+ exports.isHardLimit = isHardLimit;
5
+ exports.overageFor = overageFor;
6
+ exports.withinAllowance = withinAllowance;
7
+ const zod_1 = require("zod");
8
+ /**
9
+ * Billing: what a workspace is allowed, and what it has used.
10
+ *
11
+ * An organization exists in the identity provider, which owns identity. The row here is the
12
+ * part that is ours — a plan, a counter, and eventually a Stripe customer —
13
+ * created the first time we see a workspace rather than at signup, because
14
+ * signup is a flow we do not own.
15
+ *
16
+ * A run is the billable unit. Not tokens, which are the provider's unit, and
17
+ * not seats, which would charge for the second person to look at a failure.
18
+ */
19
+ exports.planSchema = zod_1.z.enum(["free", "pro", "scale", "enterprise"]);
20
+ /**
21
+ * What each plan includes.
22
+ *
23
+ * `runsIncluded` is copied onto the organization when the plan is set, so a
24
+ * negotiated enterprise allowance is a column rather than a special case in
25
+ * code. These are the defaults, not the authority.
26
+ *
27
+ * `overage` is null where there is none: Free is a wall, Enterprise is a
28
+ * committed rate with no wall at all. Stopping an enterprise customer's
29
+ * production traffic over a counter is a support incident, not a control.
30
+ */
31
+ exports.PLANS = {
32
+ free: {
33
+ runsIncluded: 1_000,
34
+ overagePerThousand: null,
35
+ retentionDays: 7,
36
+ inferenceMarkup: 0,
37
+ monthlyUsd: 0,
38
+ },
39
+ pro: {
40
+ runsIncluded: 25_000,
41
+ overagePerThousand: 2,
42
+ retentionDays: 90,
43
+ inferenceMarkup: 0.15,
44
+ monthlyUsd: 29,
45
+ },
46
+ scale: {
47
+ runsIncluded: 500_000,
48
+ overagePerThousand: 1.2,
49
+ retentionDays: 365,
50
+ inferenceMarkup: 0.08,
51
+ monthlyUsd: 249,
52
+ },
53
+ enterprise: {
54
+ runsIncluded: Number.MAX_SAFE_INTEGER,
55
+ overagePerThousand: null,
56
+ retentionDays: 365,
57
+ inferenceMarkup: 0,
58
+ monthlyUsd: null,
59
+ },
60
+ };
61
+ /** Whether a plan stops at its allowance or bills past it. */
62
+ function isHardLimit(plan) {
63
+ return exports.PLANS[plan].overagePerThousand === null && plan !== "enterprise";
64
+ }
65
+ exports.organizationSchema = zod_1.z.object({
66
+ id: zod_1.z.string().describe("The workspace identifier, as identity reports it."),
67
+ plan: exports.planSchema,
68
+ /** Copied from the plan when it is set, so a negotiated rate is a value. */
69
+ runs_included: zod_1.z.number(),
70
+ /** When the current period began. Not a calendar month: the plan's own date. */
71
+ period_start: zod_1.z.string(),
72
+ period_end: zod_1.z.string(),
73
+ /** Null until they pay. */
74
+ stripe_customer_id: zod_1.z.string().nullable(),
75
+ stripe_subscription_id: zod_1.z.string().nullable(),
76
+ created_at: zod_1.z.string(),
77
+ updated_at: zod_1.z.string(),
78
+ });
79
+ /**
80
+ * What a workspace has used this period.
81
+ *
82
+ * `runs_used` is incremented as runs finish rather than counted on demand:
83
+ * admission has to answer on every request, and a count over the runs table is
84
+ * a scan of the busiest thing we have. `usage_events` is what makes that
85
+ * honest — the counter is a cache of a sum that can always be rebuilt.
86
+ */
87
+ exports.periodUsageSchema = zod_1.z.object({
88
+ plan: exports.planSchema,
89
+ period_start: zod_1.z.string(),
90
+ period_end: zod_1.z.string(),
91
+ runs_used: zod_1.z.number(),
92
+ runs_included: zod_1.z.number(),
93
+ /** What the runs cost us in inference, before any markup. */
94
+ cost_usd: zod_1.z.number(),
95
+ /** Runs past the allowance, zero when within it. */
96
+ overage_runs: zod_1.z.number(),
97
+ /** What the overage will add to the invoice. */
98
+ overage_usd: zod_1.z.number(),
99
+ /** Whether a further run would be refused. */
100
+ at_limit: zod_1.z.boolean(),
101
+ });
102
+ /**
103
+ * What the overage costs, given a plan and how many runs were used.
104
+ *
105
+ * Charged per thousand and rounded up, which is how the plans are written: a
106
+ * single run past the allowance costs the first thousand's price. Returns zero
107
+ * where the plan has no overage, because there the answer is a refusal rather
108
+ * than a charge.
109
+ */
110
+ function overageFor(plan, runsUsed, runsIncluded) {
111
+ const over = Math.max(0, runsUsed - runsIncluded);
112
+ const rate = exports.PLANS[plan].overagePerThousand;
113
+ if (over === 0 || rate === null)
114
+ return { runs: over, usd: 0 };
115
+ return { runs: over, usd: Math.ceil(over / 1_000) * rate };
116
+ }
117
+ /** Whether another run may start. */
118
+ function withinAllowance(plan, runsUsed, runsIncluded) {
119
+ if (!isHardLimit(plan))
120
+ return true;
121
+ return runsUsed < runsIncluded;
122
+ }
@@ -0,0 +1,101 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * An end user's credential for one MCP server.
4
+ *
5
+ * The catalog and the connection are deliberately separate. A server is
6
+ * registered once — `https://broker.example.com/mcp` is the same URL for every user, and
7
+ * only the token differs — and a connection binds one user to one credential
8
+ * for it. That split is what keeps an agent version about behaviour: the
9
+ * version names which servers it may reach, and a connection decides whose
10
+ * account it reaches them as.
11
+ *
12
+ * A stored value is write-only. Nothing here returns it over HTTP; it is
13
+ * decrypted only when a run is dispatched, into a header the runtime receives.
14
+ */
15
+ export declare const MAX_CONNECTION_VALUE = 8192;
16
+ /**
17
+ * Whether a connection can currently authenticate a run.
18
+ *
19
+ * `pending` exists because an OAuth connection is created before the user has
20
+ * consented: the row is the thing the callback completes. A run naming a
21
+ * pending or expired connection fails rather than calling the server without
22
+ * a credential — the server would answer as an anonymous caller, and for a
23
+ * broker that is a worse outcome than a refused run.
24
+ */
25
+ export declare const connectionStatusSchema: z.ZodEnum<{
26
+ active: "active";
27
+ revoked: "revoked";
28
+ expired: "expired";
29
+ pending: "pending";
30
+ }>;
31
+ export type ConnectionStatus = z.infer<typeof connectionStatusSchema>;
32
+ export declare const connectionSchema: z.ZodObject<{
33
+ id: z.ZodString;
34
+ user_id: z.ZodString;
35
+ server: z.ZodString;
36
+ scheme: z.ZodEnum<{
37
+ session: "session";
38
+ api_key: "api_key";
39
+ oauth2: "oauth2";
40
+ }>;
41
+ status: z.ZodEnum<{
42
+ active: "active";
43
+ revoked: "revoked";
44
+ expired: "expired";
45
+ pending: "pending";
46
+ }>;
47
+ expires_at: z.ZodNullable<z.ZodString>;
48
+ last_used_at: z.ZodNullable<z.ZodString>;
49
+ created_at: z.ZodString;
50
+ updated_at: z.ZodString;
51
+ }, z.core.$strip>;
52
+ export type Connection = z.infer<typeof connectionSchema>;
53
+ /**
54
+ * Supply a credential directly.
55
+ *
56
+ * For `api_key`, where the user already holds the value and there is nothing
57
+ * to redirect them through. Also the path a platform uses to push a token it
58
+ * obtained itself, which is how refresh works until Nixet performs it.
59
+ */
60
+ export declare const createConnectionSchema: z.ZodObject<{
61
+ user_id: z.ZodString;
62
+ server: z.ZodString;
63
+ value: z.ZodString;
64
+ expires_at: z.ZodOptional<z.ZodString>;
65
+ refresh_value: z.ZodOptional<z.ZodString>;
66
+ }, z.core.$strict>;
67
+ export type CreateConnectionRequest = z.infer<typeof createConnectionSchema>;
68
+ /**
69
+ * Begin a scheme that cannot be completed in one request.
70
+ *
71
+ * `oauth2` needs the user at the provider's consent screen, and `session`
72
+ * needs them at a sign-in page whose URL the server itself returns. Both answer
73
+ * with somewhere to send the user, and both leave a `pending` connection that
74
+ * the callback completes.
75
+ */
76
+ export declare const authorizeConnectionSchema: z.ZodObject<{
77
+ user_id: z.ZodString;
78
+ server: z.ZodString;
79
+ return_url: z.ZodString;
80
+ }, z.core.$strict>;
81
+ export type AuthorizeConnectionRequest = z.infer<typeof authorizeConnectionSchema>;
82
+ export declare const authorizationSchema: z.ZodObject<{
83
+ connection_id: z.ZodString;
84
+ redirect_url: z.ZodString;
85
+ expires_at: z.ZodString;
86
+ }, z.core.$strip>;
87
+ export type Authorization = z.infer<typeof authorizationSchema>;
88
+ /** Filters for listing a user's connections. */
89
+ export declare const findConnectionsSchema: z.ZodObject<{
90
+ user_id: z.ZodOptional<z.ZodString>;
91
+ server: z.ZodOptional<z.ZodString>;
92
+ status: z.ZodOptional<z.ZodEnum<{
93
+ active: "active";
94
+ revoked: "revoked";
95
+ expired: "expired";
96
+ pending: "pending";
97
+ }>>;
98
+ $limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
99
+ $offset: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
100
+ }, z.core.$strict>;
101
+ export type FindConnectionsRequest = z.infer<typeof findConnectionsSchema>;