@substrat-run/contracts 0.204.0 → 0.206.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.
- package/dist/ci.d.ts +46 -0
- package/dist/ci.d.ts.map +1 -1
- package/dist/ci.js +75 -9
- package/dist/ci.js.map +1 -1
- package/dist/commerce-source.d.ts +11 -8
- package/dist/commerce-source.d.ts.map +1 -1
- package/dist/commerce-source.js +16 -10
- package/dist/commerce-source.js.map +1 -1
- package/dist/control-plane.d.ts +188 -0
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/control-plane.js +125 -1
- package/dist/control-plane.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/markup.d.ts +157 -0
- package/dist/markup.d.ts.map +1 -0
- package/dist/markup.js +192 -0
- package/dist/markup.js.map +1 -0
- package/dist/model-usage.d.ts +161 -3
- package/dist/model-usage.d.ts.map +1 -1
- package/dist/model-usage.js +103 -4
- package/dist/model-usage.js.map +1 -1
- package/dist/social-relay.d.ts +36 -3
- package/dist/social-relay.d.ts.map +1 -1
- package/dist/social-relay.js +41 -3
- package/dist/social-relay.js.map +1 -1
- package/dist/subject-access.d.ts +213 -0
- package/dist/subject-access.d.ts.map +1 -0
- package/dist/subject-access.js +98 -0
- package/dist/subject-access.js.map +1 -0
- package/package.json +1 -1
package/dist/markup.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markup schedule (#3316, Pricing): what the platform charges over what a tenant's usage
|
|
3
|
+
* costs it. One mechanism for every priced thing — Cloudflare's billed dimensions, model calls,
|
|
4
|
+
* build time — so the builder's model markup and the ledger's are rows here, not constants.
|
|
5
|
+
*
|
|
6
|
+
* - **Data, not code.** A default plus overrides per tenant, per billed dimension and per kind
|
|
7
|
+
* (live or preview). The most specific row wins: a tenant row over a platform row, then a
|
|
8
|
+
* dimension row over a dimension-wide one, then a kind row over a kind-wide one
|
|
9
|
+
* (`MARKUP_PRECEDENCE`).
|
|
10
|
+
* - **Dated, never edited.** A change is a new row with the UTC day it takes effect. A past day
|
|
11
|
+
* is priced at the row in force on that day, so a change never reprices history. A row with
|
|
12
|
+
* `percent: null` ends an override: that level falls through to the next less specific one,
|
|
13
|
+
* so a tenant once given its own rate is not frozen off every later change to the default.
|
|
14
|
+
* - **Applied at read.** Cost is what is stored; price = cost × (1 + markup), computed here with
|
|
15
|
+
* `mulDecimal`/`marginFactor`, never floated and never stored.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
import { utcDay } from './control-plane.js';
|
|
19
|
+
import { tenantId } from './ids.js';
|
|
20
|
+
import { marginFactor } from './model-usage.js';
|
|
21
|
+
import { mulDecimal } from './money.js';
|
|
22
|
+
/** The dimensions a tenant is billed on: Cloudflare's, plus model calls and build time. */
|
|
23
|
+
export const BILLED_DIMENSIONS = [
|
|
24
|
+
'requests',
|
|
25
|
+
'cpu',
|
|
26
|
+
'do-requests',
|
|
27
|
+
'duration',
|
|
28
|
+
'rows-read',
|
|
29
|
+
'rows-written',
|
|
30
|
+
'storage',
|
|
31
|
+
'model-calls',
|
|
32
|
+
'build-time',
|
|
33
|
+
];
|
|
34
|
+
export const billedDimension = z.enum(BILLED_DIMENSIONS);
|
|
35
|
+
/** Live usage, or a preview's (a fork, a PR version). */
|
|
36
|
+
export const usageKind = z.enum(['live', 'preview']);
|
|
37
|
+
/** The highest markup a row may carry, whole percent: 10× cost. A bound on a typo, not a policy. */
|
|
38
|
+
export const MARKUP_PERCENT_MAX = 1000;
|
|
39
|
+
const markupPercent = z.number().int().min(0).max(MARKUP_PERCENT_MAX);
|
|
40
|
+
/** The fields that name what a row applies to. `null` is "every": every tenant, dimension, kind. */
|
|
41
|
+
const markupTarget = {
|
|
42
|
+
tenantId: tenantId.nullable(),
|
|
43
|
+
dimension: billedDimension.nullable(),
|
|
44
|
+
kind: usageKind.nullable(),
|
|
45
|
+
};
|
|
46
|
+
/** One row of the schedule, as stored. */
|
|
47
|
+
export const markupRow = z
|
|
48
|
+
.object({
|
|
49
|
+
id: z.string().min(1),
|
|
50
|
+
...markupTarget,
|
|
51
|
+
/** The first UTC day the row prices. */
|
|
52
|
+
effectiveFrom: utcDay,
|
|
53
|
+
/** Whole percent over cost; `null` ends an override at this level (it falls through). */
|
|
54
|
+
percent: markupPercent.nullable(),
|
|
55
|
+
/** Why — the admin log carries who; this carries the decision. */
|
|
56
|
+
reason: z.string().min(1).max(500),
|
|
57
|
+
setAt: z.string().min(1),
|
|
58
|
+
setBy: z.string().min(1),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
/**
|
|
62
|
+
* What staff send to add a row. Omitted target fields mean "every". The platform default (no
|
|
63
|
+
* target at all) must carry a percent: it is the floor every other row falls through to.
|
|
64
|
+
*/
|
|
65
|
+
export const markupRowInput = z
|
|
66
|
+
.object({
|
|
67
|
+
tenantId: tenantId.nullable().optional(),
|
|
68
|
+
dimension: billedDimension.nullable().optional(),
|
|
69
|
+
kind: usageKind.nullable().optional(),
|
|
70
|
+
effectiveFrom: utcDay,
|
|
71
|
+
percent: markupPercent.nullable(),
|
|
72
|
+
reason: z.string().trim().min(1).max(500),
|
|
73
|
+
})
|
|
74
|
+
.strict()
|
|
75
|
+
.refine((r) => r.percent !== null || r.tenantId != null || r.dimension != null || r.kind != null, {
|
|
76
|
+
message: 'the platform default must carry a percent',
|
|
77
|
+
path: ['percent'],
|
|
78
|
+
});
|
|
79
|
+
/** Who the seed rows name as their setter: the platform, not a person. */
|
|
80
|
+
export const MARKUP_SEED_ACTOR = 'platform-seed';
|
|
81
|
+
/** The day the seed rows take effect from: before any usage the platform holds, so every day it can price has a row. */
|
|
82
|
+
export const MARKUP_SEED_EFFECTIVE_FROM = '2000-01-01';
|
|
83
|
+
/**
|
|
84
|
+
* The owner's decisions of 2026-11-21 on #3316: the rows every schedule holds beneath what staff
|
|
85
|
+
* add. Read beneath the stored rows rather than inserted (the kernel's `markupScheduleOf`), with
|
|
86
|
+
* fixed ids, so a later row supersedes them and none can be lost or duplicated by a restore.
|
|
87
|
+
*/
|
|
88
|
+
export const MARKUP_SEED = [
|
|
89
|
+
{
|
|
90
|
+
id: '01KAKX00000000000000MARK01',
|
|
91
|
+
tenantId: null,
|
|
92
|
+
dimension: null,
|
|
93
|
+
kind: null,
|
|
94
|
+
effectiveFrom: MARKUP_SEED_EFFECTIVE_FROM,
|
|
95
|
+
percent: 100,
|
|
96
|
+
reason: 'Default markup over attributed cost, owner decision 2026-11-21 (#3316).',
|
|
97
|
+
setAt: '2026-11-21T00:00:00.000Z',
|
|
98
|
+
setBy: MARKUP_SEED_ACTOR,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: '01KAKX00000000000000MARK02',
|
|
102
|
+
tenantId: null,
|
|
103
|
+
dimension: null,
|
|
104
|
+
kind: 'preview',
|
|
105
|
+
effectiveFrom: MARKUP_SEED_EFFECTIVE_FROM,
|
|
106
|
+
percent: 0,
|
|
107
|
+
reason: 'Previews are priced at cost, owner decision 2026-11-21 (#3316).',
|
|
108
|
+
setAt: '2026-11-21T00:00:00.000Z',
|
|
109
|
+
setBy: MARKUP_SEED_ACTOR,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: '01KAKX00000000000000MARK03',
|
|
113
|
+
tenantId: null,
|
|
114
|
+
dimension: 'model-calls',
|
|
115
|
+
kind: null,
|
|
116
|
+
effectiveFrom: MARKUP_SEED_EFFECTIVE_FROM,
|
|
117
|
+
percent: 30,
|
|
118
|
+
reason: 'Model usage markup, owner decision 2026-11-21 (#3316); the builder studio and the model ledger both price at it.',
|
|
119
|
+
setAt: '2026-11-21T00:00:00.000Z',
|
|
120
|
+
setBy: MARKUP_SEED_ACTOR,
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
/**
|
|
124
|
+
* The order rows are tried in, most specific first: tenant, then dimension, then kind. So a
|
|
125
|
+
* tenant's own rate beats every platform row, and a dimension's rate beats a kind's (a model
|
|
126
|
+
* call made by a preview is priced as a model call).
|
|
127
|
+
*/
|
|
128
|
+
export const MARKUP_PRECEDENCE = [
|
|
129
|
+
[true, true, true],
|
|
130
|
+
[true, true, false],
|
|
131
|
+
[true, false, true],
|
|
132
|
+
[true, false, false],
|
|
133
|
+
[false, true, true],
|
|
134
|
+
[false, true, false],
|
|
135
|
+
[false, false, true],
|
|
136
|
+
[false, false, false],
|
|
137
|
+
];
|
|
138
|
+
const levelOf = (r) => `${r.tenantId !== null}${r.dimension !== null}${r.kind !== null}`;
|
|
139
|
+
/** Later wins: the later effective day, then the later setting, then the later id. */
|
|
140
|
+
const later = (a, b) => a.effectiveFrom !== b.effectiveFrom
|
|
141
|
+
? a.effectiveFrom > b.effectiveFrom
|
|
142
|
+
: a.setAt !== b.setAt
|
|
143
|
+
? a.setAt > b.setAt
|
|
144
|
+
: a.id > b.id;
|
|
145
|
+
/**
|
|
146
|
+
* The row in force for one query, or null when the schedule holds none (a price is then unknown,
|
|
147
|
+
* never guessed). At each level the latest row in force on `day` decides; a `null` percent there
|
|
148
|
+
* passes the question to the next level.
|
|
149
|
+
*/
|
|
150
|
+
export function markupInForce(schedule, query) {
|
|
151
|
+
const latest = new Map();
|
|
152
|
+
for (const row of schedule) {
|
|
153
|
+
if (row.effectiveFrom > query.day)
|
|
154
|
+
continue;
|
|
155
|
+
if (row.tenantId !== null && row.tenantId !== query.tenantId)
|
|
156
|
+
continue;
|
|
157
|
+
if (row.dimension !== null && row.dimension !== query.dimension)
|
|
158
|
+
continue;
|
|
159
|
+
if (row.kind !== null && row.kind !== query.kind)
|
|
160
|
+
continue;
|
|
161
|
+
const level = levelOf(row);
|
|
162
|
+
const held = latest.get(level);
|
|
163
|
+
if (!held || later(row, held))
|
|
164
|
+
latest.set(level, row);
|
|
165
|
+
}
|
|
166
|
+
for (const level of MARKUP_PRECEDENCE) {
|
|
167
|
+
const row = latest.get(`${level[0]}${level[1]}${level[2]}`);
|
|
168
|
+
if (row && row.percent !== null)
|
|
169
|
+
return row;
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
/** The percent in force for one query, or null when no row covers it. */
|
|
174
|
+
export function markupPercentFor(schedule, query) {
|
|
175
|
+
return markupInForce(schedule, query)?.percent ?? null;
|
|
176
|
+
}
|
|
177
|
+
/** cost × (1 + percent/100), exact to the decimal scale. */
|
|
178
|
+
export function priceOf(costUsd, percent) {
|
|
179
|
+
return mulDecimal(costUsd, marginFactor(percent));
|
|
180
|
+
}
|
|
181
|
+
/** Price cost rows for staff, each at the markup in force on its own day. */
|
|
182
|
+
export function priceCostRows(rows, schedule) {
|
|
183
|
+
return rows.map((row) => {
|
|
184
|
+
const percent = markupPercentFor(schedule, row);
|
|
185
|
+
return { ...row, markupPercent: percent, priceUsd: percent === null ? null : priceOf(row.costUsd, percent) };
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/** Price cost rows for the tenant: the price only. */
|
|
189
|
+
export function tenantPricedRows(rows, schedule) {
|
|
190
|
+
return priceCostRows(rows, schedule).map(({ day, dimension, kind, priceUsd }) => ({ day, dimension, kind, priceUsd }));
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=markup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markup.js","sourceRoot":"","sources":["../src/markup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,U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elUsageEntry>;
|
|
|
112
112
|
* directory is exactly that fan-in, for this one kind of usage.
|
|
113
113
|
*
|
|
114
114
|
* One row per (tenant, vertical, model). Token sums are integers; money is folded with
|
|
115
|
-
* `addDecimal`, never floated, and `billedUsd` is `listUsd × marginFactor(
|
|
116
|
-
*
|
|
117
|
-
*
|
|
115
|
+
* `addDecimal`, never floated, and `billedUsd` is `listUsd × marginFactor(percent)` applied at
|
|
116
|
+
* READ time. With the markup schedule (#3316) each line is priced at the `model-calls` row in
|
|
117
|
+
* force for its tenant on its own day, so a dated change never reprices the days before it. `unpriced` counts calls whose
|
|
118
118
|
* model the rate card did not know: shown beside the money, never folded into it as $0.
|
|
119
119
|
*/
|
|
120
120
|
export declare const modelUsageSummaryRow: z.ZodObject<{
|
|
@@ -175,4 +175,162 @@ export type ModelUsageSummary = z.infer<typeof modelUsageSummary>;
|
|
|
175
175
|
* a factor the 6-dp decimal scale cannot always carry, and nobody prices at 12.5%.
|
|
176
176
|
*/
|
|
177
177
|
export declare function marginFactor(percent: number): string;
|
|
178
|
+
export declare const modelReconciliationStatus: z.ZodEnum<{
|
|
179
|
+
discrepancy: "discrepancy";
|
|
180
|
+
"gateway-only": "gateway-only";
|
|
181
|
+
"ledger-only": "ledger-only";
|
|
182
|
+
matched: "matched";
|
|
183
|
+
}>;
|
|
184
|
+
export type ModelReconciliationStatus = z.infer<typeof modelReconciliationStatus>;
|
|
185
|
+
export declare const modelReconciliationRow: z.ZodObject<{
|
|
186
|
+
tenantId: z.ZodString;
|
|
187
|
+
scopeId: z.ZodString;
|
|
188
|
+
vertical: z.ZodNullable<z.ZodString>;
|
|
189
|
+
modelId: z.ZodString;
|
|
190
|
+
status: z.ZodEnum<{
|
|
191
|
+
discrepancy: "discrepancy";
|
|
192
|
+
"gateway-only": "gateway-only";
|
|
193
|
+
"ledger-only": "ledger-only";
|
|
194
|
+
matched: "matched";
|
|
195
|
+
}>;
|
|
196
|
+
differs: z.ZodArray<z.ZodEnum<{
|
|
197
|
+
calls: "calls";
|
|
198
|
+
cost: "cost";
|
|
199
|
+
}>>;
|
|
200
|
+
ledger: z.ZodObject<{
|
|
201
|
+
calls: z.ZodNumber;
|
|
202
|
+
inputTokens: z.ZodNumber;
|
|
203
|
+
outputTokens: z.ZodNumber;
|
|
204
|
+
listUsd: z.ZodString;
|
|
205
|
+
unpriced: z.ZodNumber;
|
|
206
|
+
}, z.core.$strip>;
|
|
207
|
+
gateway: z.ZodObject<{
|
|
208
|
+
calls: z.ZodNumber;
|
|
209
|
+
inputTokens: z.ZodNumber;
|
|
210
|
+
outputTokens: z.ZodNumber;
|
|
211
|
+
costUsd: z.ZodString;
|
|
212
|
+
}, z.core.$strip>;
|
|
213
|
+
deltaUsd: z.ZodString;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
export type ModelReconciliationRow = z.infer<typeof modelReconciliationRow>;
|
|
216
|
+
export declare const modelReconciliationDay: z.ZodObject<{
|
|
217
|
+
day: z.ZodString;
|
|
218
|
+
readAt: z.core.$ZodBranded<z.ZodString, "Instant", "out">;
|
|
219
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
220
|
+
tenantId: z.ZodString;
|
|
221
|
+
scopeId: z.ZodString;
|
|
222
|
+
vertical: z.ZodNullable<z.ZodString>;
|
|
223
|
+
modelId: z.ZodString;
|
|
224
|
+
status: z.ZodEnum<{
|
|
225
|
+
discrepancy: "discrepancy";
|
|
226
|
+
"gateway-only": "gateway-only";
|
|
227
|
+
"ledger-only": "ledger-only";
|
|
228
|
+
matched: "matched";
|
|
229
|
+
}>;
|
|
230
|
+
differs: z.ZodArray<z.ZodEnum<{
|
|
231
|
+
calls: "calls";
|
|
232
|
+
cost: "cost";
|
|
233
|
+
}>>;
|
|
234
|
+
ledger: z.ZodObject<{
|
|
235
|
+
calls: z.ZodNumber;
|
|
236
|
+
inputTokens: z.ZodNumber;
|
|
237
|
+
outputTokens: z.ZodNumber;
|
|
238
|
+
listUsd: z.ZodString;
|
|
239
|
+
unpriced: z.ZodNumber;
|
|
240
|
+
}, z.core.$strip>;
|
|
241
|
+
gateway: z.ZodObject<{
|
|
242
|
+
calls: z.ZodNumber;
|
|
243
|
+
inputTokens: z.ZodNumber;
|
|
244
|
+
outputTokens: z.ZodNumber;
|
|
245
|
+
costUsd: z.ZodString;
|
|
246
|
+
}, z.core.$strip>;
|
|
247
|
+
deltaUsd: z.ZodString;
|
|
248
|
+
}, z.core.$strip>>;
|
|
249
|
+
unattributedGateway: z.ZodArray<z.ZodObject<{
|
|
250
|
+
provider: z.ZodString;
|
|
251
|
+
modelId: z.ZodString;
|
|
252
|
+
calls: z.ZodNumber;
|
|
253
|
+
costUsd: z.ZodString;
|
|
254
|
+
}, z.core.$strip>>;
|
|
255
|
+
workersAiWithoutGateway: z.ZodArray<z.ZodObject<{
|
|
256
|
+
modelId: z.ZodString;
|
|
257
|
+
requestSource: z.ZodString;
|
|
258
|
+
calls: z.ZodNumber;
|
|
259
|
+
neurons: z.ZodString;
|
|
260
|
+
estimatedUsd: z.ZodString;
|
|
261
|
+
}, z.core.$strip>>;
|
|
262
|
+
otherDirectoryGateway: z.ZodObject<{
|
|
263
|
+
calls: z.ZodNumber;
|
|
264
|
+
costUsd: z.ZodString;
|
|
265
|
+
}, z.core.$strip>;
|
|
266
|
+
offGatewayLedgerCalls: z.ZodNumber;
|
|
267
|
+
totals: z.ZodObject<{
|
|
268
|
+
ledgerListUsd: z.ZodString;
|
|
269
|
+
gatewayCostUsd: z.ZodString;
|
|
270
|
+
workersAiWithoutGatewayUsd: z.ZodString;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
}, z.core.$strip>;
|
|
273
|
+
export type ModelReconciliationDay = z.infer<typeof modelReconciliationDay>;
|
|
274
|
+
export declare const modelReconciliation: z.ZodObject<{
|
|
275
|
+
since: z.ZodString;
|
|
276
|
+
until: z.ZodString;
|
|
277
|
+
days: z.ZodArray<z.ZodObject<{
|
|
278
|
+
day: z.ZodString;
|
|
279
|
+
readAt: z.core.$ZodBranded<z.ZodString, "Instant", "out">;
|
|
280
|
+
rows: z.ZodArray<z.ZodObject<{
|
|
281
|
+
tenantId: z.ZodString;
|
|
282
|
+
scopeId: z.ZodString;
|
|
283
|
+
vertical: z.ZodNullable<z.ZodString>;
|
|
284
|
+
modelId: z.ZodString;
|
|
285
|
+
status: z.ZodEnum<{
|
|
286
|
+
discrepancy: "discrepancy";
|
|
287
|
+
"gateway-only": "gateway-only";
|
|
288
|
+
"ledger-only": "ledger-only";
|
|
289
|
+
matched: "matched";
|
|
290
|
+
}>;
|
|
291
|
+
differs: z.ZodArray<z.ZodEnum<{
|
|
292
|
+
calls: "calls";
|
|
293
|
+
cost: "cost";
|
|
294
|
+
}>>;
|
|
295
|
+
ledger: z.ZodObject<{
|
|
296
|
+
calls: z.ZodNumber;
|
|
297
|
+
inputTokens: z.ZodNumber;
|
|
298
|
+
outputTokens: z.ZodNumber;
|
|
299
|
+
listUsd: z.ZodString;
|
|
300
|
+
unpriced: z.ZodNumber;
|
|
301
|
+
}, z.core.$strip>;
|
|
302
|
+
gateway: z.ZodObject<{
|
|
303
|
+
calls: z.ZodNumber;
|
|
304
|
+
inputTokens: z.ZodNumber;
|
|
305
|
+
outputTokens: z.ZodNumber;
|
|
306
|
+
costUsd: z.ZodString;
|
|
307
|
+
}, z.core.$strip>;
|
|
308
|
+
deltaUsd: z.ZodString;
|
|
309
|
+
}, z.core.$strip>>;
|
|
310
|
+
unattributedGateway: z.ZodArray<z.ZodObject<{
|
|
311
|
+
provider: z.ZodString;
|
|
312
|
+
modelId: z.ZodString;
|
|
313
|
+
calls: z.ZodNumber;
|
|
314
|
+
costUsd: z.ZodString;
|
|
315
|
+
}, z.core.$strip>>;
|
|
316
|
+
workersAiWithoutGateway: z.ZodArray<z.ZodObject<{
|
|
317
|
+
modelId: z.ZodString;
|
|
318
|
+
requestSource: z.ZodString;
|
|
319
|
+
calls: z.ZodNumber;
|
|
320
|
+
neurons: z.ZodString;
|
|
321
|
+
estimatedUsd: z.ZodString;
|
|
322
|
+
}, z.core.$strip>>;
|
|
323
|
+
otherDirectoryGateway: z.ZodObject<{
|
|
324
|
+
calls: z.ZodNumber;
|
|
325
|
+
costUsd: z.ZodString;
|
|
326
|
+
}, z.core.$strip>;
|
|
327
|
+
offGatewayLedgerCalls: z.ZodNumber;
|
|
328
|
+
totals: z.ZodObject<{
|
|
329
|
+
ledgerListUsd: z.ZodString;
|
|
330
|
+
gatewayCostUsd: z.ZodString;
|
|
331
|
+
workersAiWithoutGatewayUsd: z.ZodString;
|
|
332
|
+
}, z.core.$strip>;
|
|
333
|
+
}, z.core.$strip>>;
|
|
334
|
+
}, z.core.$strip>;
|
|
335
|
+
export type ModelReconciliation = z.infer<typeof modelReconciliation>;
|
|
178
336
|
//# sourceMappingURL=model-usage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-usage.d.ts","sourceRoot":"","sources":["../src/model-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB;;;;;;kBAclB,CAAC;AACZ,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;iBA6BxB,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,SAAU,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,KAAG,OAMrD,CAAC;AAE3B,eAAO,MAAM,kBAAkB,6GACwE,CAAC;AAExG,+FAA+F;AAC/F,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;iBAEzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D;;;;;;GAMG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 export const modelUsageEntry = modelUsageLineFields
|
|
|
105
105
|
* directory is exactly that fan-in, for this one kind of usage.
|
|
106
106
|
*
|
|
107
107
|
* One row per (tenant, vertical, model). Token sums are integers; money is folded with
|
|
108
|
-
* `addDecimal`, never floated, and `billedUsd` is `listUsd × marginFactor(
|
|
109
|
-
*
|
|
110
|
-
*
|
|
108
|
+
* `addDecimal`, never floated, and `billedUsd` is `listUsd × marginFactor(percent)` applied at
|
|
109
|
+
* READ time. With the markup schedule (#3316) each line is priced at the `model-calls` row in
|
|
110
|
+
* force for its tenant on its own day, so a dated change never reprices the days before it. `unpriced` counts calls whose
|
|
111
111
|
* model the rate card did not know: shown beside the money, never folded into it as $0.
|
|
112
112
|
*/
|
|
113
113
|
export const modelUsageSummaryRow = z.object({
|
|
@@ -136,7 +136,10 @@ export const modelUsageSummary = z.object({
|
|
|
136
136
|
readAt: instant,
|
|
137
137
|
since: instant,
|
|
138
138
|
until: instant,
|
|
139
|
-
/**
|
|
139
|
+
/**
|
|
140
|
+
* The platform's margin over list, whole percent, on the window's last day. A tenant's own
|
|
141
|
+
* schedule row, or a change inside the window, prices its lines differently (#3316).
|
|
142
|
+
*/
|
|
140
143
|
marginPercent: z.number().int().nonnegative(),
|
|
141
144
|
rows: z.array(modelUsageSummaryRow),
|
|
142
145
|
totals: z.object({
|
|
@@ -165,4 +168,100 @@ export function marginFactor(percent) {
|
|
|
165
168
|
.replace(/0+$/, '');
|
|
166
169
|
return frac ? `${whole}.${frac}` : String(whole);
|
|
167
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Reconciliation (#1054, #3316): the ledger above against what Cloudflare saw.
|
|
173
|
+
*
|
|
174
|
+
* The ledger is self-reported (D-59): a vertical's own model host builds the line, and only a
|
|
175
|
+
* line raised as a `model-usage` intent reaches it. A call that went through AI Gateway carries
|
|
176
|
+
* the same five attribution keys as gateway metadata, so the gateway's analytics are a second
|
|
177
|
+
* account of the same calls, kept by someone other than the caller. A Workers AI call made
|
|
178
|
+
* through the binding with no gateway carries no script, tenant or scope, so it is counted only
|
|
179
|
+
* as a daily total nobody can attribute.
|
|
180
|
+
*
|
|
181
|
+
* One reconciled UTC day, per (tenant, scope, model id):
|
|
182
|
+
*
|
|
183
|
+
* - `matched`: both sides saw the calls, and the call counts and costs agree within tolerance;
|
|
184
|
+
* - `discrepancy`: both sides saw calls, but the counts differ or the costs differ beyond it;
|
|
185
|
+
* - `ledger-only`: lines for a gateway-routed provider that the gateway never saw — the model
|
|
186
|
+
* host ran through the binding, which bypasses the gateway, or the gateway dropped the call;
|
|
187
|
+
* - `gateway-only`: calls the gateway attributed to a tenant and scope that no ledger line
|
|
188
|
+
* accounts for — the self-report gap: a model host whose `record` never raised the intent.
|
|
189
|
+
*
|
|
190
|
+
* Gateway cost is Cloudflare's own estimate from tokens and its price list, and its analytics are
|
|
191
|
+
* sampled; the ledger prices from OUR rate card (D-59). So a cost difference is a finding to read,
|
|
192
|
+
* not a correction to apply: the ledger stays the ledger.
|
|
193
|
+
*/
|
|
194
|
+
const usd = z.string().regex(/^-?\d+(\.\d{1,6})?$/, 'a decimal string with at most 6 decimal places');
|
|
195
|
+
export const modelReconciliationStatus = z.enum(['matched', 'discrepancy', 'ledger-only', 'gateway-only']);
|
|
196
|
+
export const modelReconciliationRow = z.object({
|
|
197
|
+
tenantId: z.string().min(1),
|
|
198
|
+
scopeId: z.string().min(1),
|
|
199
|
+
/** The ledger's vertical (the scope's slug); the gateway's metadata (the package name) when only it saw the calls. */
|
|
200
|
+
vertical: z.string().nullable(),
|
|
201
|
+
/** The model id both sides share: `@cf/zai-org/glm-5.2`, never the `provider:` prefix. */
|
|
202
|
+
modelId: z.string().min(1),
|
|
203
|
+
status: modelReconciliationStatus,
|
|
204
|
+
/** Why a `discrepancy` is one. Empty otherwise. */
|
|
205
|
+
differs: z.array(z.enum(['calls', 'cost'])),
|
|
206
|
+
ledger: z.object({
|
|
207
|
+
calls: z.number().int().nonnegative(),
|
|
208
|
+
inputTokens: z.number().int().nonnegative(),
|
|
209
|
+
outputTokens: z.number().int().nonnegative(),
|
|
210
|
+
/** Summed list price of the priced lines. */
|
|
211
|
+
listUsd: usd,
|
|
212
|
+
/** Lines the rate card could not price: never folded into `listUsd` as $0. */
|
|
213
|
+
unpriced: z.number().int().nonnegative(),
|
|
214
|
+
}),
|
|
215
|
+
gateway: z.object({
|
|
216
|
+
calls: z.number().int().nonnegative(),
|
|
217
|
+
inputTokens: z.number().int().nonnegative(),
|
|
218
|
+
outputTokens: z.number().int().nonnegative(),
|
|
219
|
+
costUsd: usd,
|
|
220
|
+
}),
|
|
221
|
+
/** `gateway.costUsd − ledger.listUsd`. */
|
|
222
|
+
deltaUsd: usd,
|
|
223
|
+
});
|
|
224
|
+
export const modelReconciliationDay = z.object({
|
|
225
|
+
/** The UTC day, `YYYY-MM-DD`. */
|
|
226
|
+
day: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
227
|
+
readAt: instant,
|
|
228
|
+
rows: z.array(modelReconciliationRow),
|
|
229
|
+
/** Gateway calls with no `tenant` or `scope` metadata: a caller outside the platform's model hosts. */
|
|
230
|
+
unattributedGateway: z.array(z.object({
|
|
231
|
+
provider: z.string(),
|
|
232
|
+
modelId: z.string(),
|
|
233
|
+
calls: z.number().int().nonnegative(),
|
|
234
|
+
costUsd: usd,
|
|
235
|
+
})),
|
|
236
|
+
/**
|
|
237
|
+
* Workers AI calls that never passed through a gateway, by model and Cloudflare's `requestSource`.
|
|
238
|
+
* Nothing names a tenant for them: this is the part of the Workers AI bill only the ledger, if
|
|
239
|
+
* anyone raised it, can attribute. `estimatedUsd` is neurons at Workers AI's list price.
|
|
240
|
+
*/
|
|
241
|
+
workersAiWithoutGateway: z.array(z.object({
|
|
242
|
+
modelId: z.string(),
|
|
243
|
+
requestSource: z.string(),
|
|
244
|
+
calls: z.number().int().nonnegative(),
|
|
245
|
+
neurons: usd,
|
|
246
|
+
estimatedUsd: usd,
|
|
247
|
+
})),
|
|
248
|
+
/**
|
|
249
|
+
* Gateway calls attributed to a tenant this directory does not hold. Environments share one
|
|
250
|
+
* Cloudflare account, so another environment's calls land in the same analytics; they are
|
|
251
|
+
* counted here and never reported as anyone's gap.
|
|
252
|
+
*/
|
|
253
|
+
otherDirectoryGateway: z.object({ calls: z.number().int().nonnegative(), costUsd: usd }),
|
|
254
|
+
/** Ledger lines of the day for a provider that does not route through the gateway: not reconcilable here. */
|
|
255
|
+
offGatewayLedgerCalls: z.number().int().nonnegative(),
|
|
256
|
+
totals: z.object({
|
|
257
|
+
ledgerListUsd: usd,
|
|
258
|
+
gatewayCostUsd: usd,
|
|
259
|
+
workersAiWithoutGatewayUsd: usd,
|
|
260
|
+
}),
|
|
261
|
+
});
|
|
262
|
+
export const modelReconciliation = z.object({
|
|
263
|
+
since: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
264
|
+
until: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
265
|
+
days: z.array(modelReconciliationDay),
|
|
266
|
+
});
|
|
168
267
|
//# sourceMappingURL=model-usage.js.map
|
package/dist/model-usage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-usage.js","sourceRoot":"","sources":["../src/model-usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd;;;OAGG;IACH,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,oFAAoF;IACpF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,6EAA6E;IAC7E,SA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M,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IACxF,6GAA6G;IAC7G,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IACrD,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,aAAa,EAAE,GAAG;QAClB,cAAc,EAAE,GAAG;QACnB,0BAA0B,EAAE,GAAG;KAChC,CAAC;CACH,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC;IAC9C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC;CACtC,CAAC,CAAC"}
|
package/dist/social-relay.d.ts
CHANGED
|
@@ -23,8 +23,24 @@ import { z } from 'zod';
|
|
|
23
23
|
* just created, or its secret just rotated. The relay stores secrets hashed and cannot hand an
|
|
24
24
|
* existing one back, so an ordinary re-delivery carries none and the issuer keeps the one it
|
|
25
25
|
* holds. An issuer that holds none answers `SOCIAL_RELAY_SECRET_NEEDED` (409), and only then
|
|
26
|
-
* does the platform rotate and deliver again.
|
|
27
|
-
*
|
|
26
|
+
* does the platform rotate and deliver again.
|
|
27
|
+
*
|
|
28
|
+
* Every delivery also carries `generation`, the relay's count of the client's secrets (#3275): 1
|
|
29
|
+
* for the secret handed out at creation, one more for each rotation. The relay accepts only the
|
|
30
|
+
* newest, so the generation says which secret is live without anyone reading one back:
|
|
31
|
+
*
|
|
32
|
+
* - with a secret, it is that secret's generation, and an issuer holding a NEWER one refuses the
|
|
33
|
+
* delivery (`SOCIAL_RELAY_DELIVERY_STALE`) — a slow delivery from a run that rotated earlier
|
|
34
|
+
* can never overwrite the secret a later rotation delivered;
|
|
35
|
+
* - without one, it is the relay's current generation, and an issuer holding an OLDER one knows
|
|
36
|
+
* its secret is dead and says so (`SOCIAL_RELAY_SECRET_STALE`), which the platform answers
|
|
37
|
+
* with one rotation — the stuck install heals on its next reconcile.
|
|
38
|
+
*
|
|
39
|
+
* Rotation and its delivery are serialized per client at the relay itself: a rotation is a
|
|
40
|
+
* compare-and-set on the generation the caller saw, and it takes a short lease that refuses any
|
|
41
|
+
* other rotation of that client until the delivery is made (`packages/control-plane-api`,
|
|
42
|
+
* `reconcileSocialRelay`). So two reconciles can never both rotate, and the generation is the
|
|
43
|
+
* guard that holds even if that serialization is ever bypassed.
|
|
28
44
|
*/
|
|
29
45
|
export declare const SOCIAL_RELAY_CONFIG_KEY = "substrat:social-relay";
|
|
30
46
|
/**
|
|
@@ -84,12 +100,29 @@ export declare const socialRelayProviders: z.ZodObject<{
|
|
|
84
100
|
}, z.core.$strip>;
|
|
85
101
|
}, z.core.$strip>>;
|
|
86
102
|
}, z.core.$strip>;
|
|
87
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* What an issuer answers (409, as the `detail`) when a delivery carries no secret and it holds none
|
|
105
|
+
* it can vouch for: none for this client, or one held from before generations were delivered,
|
|
106
|
+
* which may or may not be the live one. A reconcile the install itself asked for never rotates on
|
|
107
|
+
* this answer when the install says it holds a client.
|
|
108
|
+
*/
|
|
88
109
|
export declare const SOCIAL_RELAY_SECRET_NEEDED = "social_relay_secret_needed";
|
|
110
|
+
/**
|
|
111
|
+
* What an issuer answers (409) when a delivery carries no secret and the relay's generation is
|
|
112
|
+
* newer than the secret it holds: that secret was rotated out and cannot work. Rotating replaces
|
|
113
|
+
* nothing that signs anyone in, so every reconcile rotates on it, the install's own included.
|
|
114
|
+
*/
|
|
115
|
+
export declare const SOCIAL_RELAY_SECRET_STALE = "social_relay_secret_stale";
|
|
116
|
+
/**
|
|
117
|
+
* What an issuer answers (409) when a delivery carries a secret OLDER than the one it holds — a
|
|
118
|
+
* run that rotated, then delivered after a later rotation's secret had landed. Nothing is written.
|
|
119
|
+
*/
|
|
120
|
+
export declare const SOCIAL_RELAY_DELIVERY_STALE = "social_relay_delivery_stale";
|
|
89
121
|
/** The delivered value of `substrat:social-relay`. */
|
|
90
122
|
export declare const socialRelayDelivery: z.ZodObject<{
|
|
91
123
|
clientId: z.ZodString;
|
|
92
124
|
clientSecret: z.ZodOptional<z.ZodString>;
|
|
125
|
+
generation: z.ZodOptional<z.ZodNumber>;
|
|
93
126
|
providers: z.ZodArray<z.ZodObject<{
|
|
94
127
|
id: z.ZodString;
|
|
95
128
|
label: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"social-relay.d.ts","sourceRoot":"","sources":["../src/social-relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB
|
|
1
|
+
{"version":3,"file":"social-relay.d.ts","sourceRoot":"","sources":["../src/social-relay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,uBAAuB,0BAA0B,CAAC;AAE/D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAAmD,CAAC;AAExG;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,yFAAyF;AACzF,eAAO,MAAM,oBAAoB;;;;;iBAK/B,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,+FAA+F;AAC/F,eAA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