@openlimiter/core 0.4.0 → 1.3.1

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 (68) hide show
  1. package/dist/acquire/antigravity-probe.d.ts +139 -0
  2. package/dist/acquire/antigravity-probe.d.ts.map +1 -0
  3. package/dist/acquire/antigravity-probe.js +599 -0
  4. package/dist/acquire/antigravity-probe.js.map +1 -0
  5. package/dist/acquire/cadence.d.ts +74 -0
  6. package/dist/acquire/cadence.d.ts.map +1 -0
  7. package/dist/acquire/cadence.js +171 -0
  8. package/dist/acquire/cadence.js.map +1 -0
  9. package/dist/acquire/coordination.d.ts +157 -0
  10. package/dist/acquire/coordination.d.ts.map +1 -0
  11. package/dist/acquire/coordination.js +292 -0
  12. package/dist/acquire/coordination.js.map +1 -0
  13. package/dist/acquire/credentials.d.ts +113 -0
  14. package/dist/acquire/credentials.d.ts.map +1 -0
  15. package/dist/acquire/credentials.js +316 -0
  16. package/dist/acquire/credentials.js.map +1 -0
  17. package/dist/acquire/identity.d.ts +20 -0
  18. package/dist/acquire/identity.d.ts.map +1 -0
  19. package/dist/acquire/identity.js +20 -0
  20. package/dist/acquire/identity.js.map +1 -0
  21. package/dist/acquire/index.d.ts +10 -0
  22. package/dist/acquire/index.d.ts.map +1 -0
  23. package/dist/acquire/index.js +10 -0
  24. package/dist/acquire/index.js.map +1 -0
  25. package/dist/acquire/providers.d.ts +86 -0
  26. package/dist/acquire/providers.d.ts.map +1 -0
  27. package/dist/acquire/providers.js +175 -0
  28. package/dist/acquire/providers.js.map +1 -0
  29. package/dist/acquire/runner.d.ts +146 -0
  30. package/dist/acquire/runner.d.ts.map +1 -0
  31. package/dist/acquire/runner.js +345 -0
  32. package/dist/acquire/runner.js.map +1 -0
  33. package/dist/acquire/transport.d.ts +194 -0
  34. package/dist/acquire/transport.d.ts.map +1 -0
  35. package/dist/acquire/transport.js +434 -0
  36. package/dist/acquire/transport.js.map +1 -0
  37. package/dist/acquire/windows-credential.d.ts +74 -0
  38. package/dist/acquire/windows-credential.d.ts.map +1 -0
  39. package/dist/acquire/windows-credential.js +124 -0
  40. package/dist/acquire/windows-credential.js.map +1 -0
  41. package/dist/cache.d.ts +28 -0
  42. package/dist/cache.d.ts.map +1 -1
  43. package/dist/cache.js +179 -25
  44. package/dist/cache.js.map +1 -1
  45. package/dist/connection-state.d.ts +53 -2
  46. package/dist/connection-state.d.ts.map +1 -1
  47. package/dist/connection-state.js +98 -9
  48. package/dist/connection-state.js.map +1 -1
  49. package/dist/failures.d.ts +2 -1
  50. package/dist/failures.d.ts.map +1 -1
  51. package/dist/failures.js +7 -3
  52. package/dist/failures.js.map +1 -1
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +1 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/merge.d.ts.map +1 -1
  58. package/dist/merge.js +17 -1
  59. package/dist/merge.js.map +1 -1
  60. package/dist/normalizer.d.ts +2 -0
  61. package/dist/normalizer.d.ts.map +1 -1
  62. package/dist/normalizer.js +39 -4
  63. package/dist/normalizer.js.map +1 -1
  64. package/dist/types.d.ts +63 -1
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/types.js +22 -0
  67. package/dist/types.js.map +1 -1
  68. package/package.json +3 -2
@@ -0,0 +1,345 @@
1
+ import { normalizeMeters } from "../normalizer.js";
2
+ import { ACQUISITION_OUTCOME_SENTENCE, isProviderDue, nextAttemptInstant } from "./cadence.js";
3
+ import { CREDENTIAL_FAILURE_SENTENCE, readAcquisitionCredential } from "./credentials.js";
4
+ import { outcomeForStatus } from "./transport.js";
5
+ import { AGY_NOT_RUNNING_SENTENCE } from "./antigravity-probe.js";
6
+ import { isSharedCodeAssist } from "./providers.js";
7
+ /**
8
+ * The failure vocabulary the cache understands, from ours.
9
+ *
10
+ * Drift is deliberately NOT mapped through. In this codebase a drift report
11
+ * suppresses every cached row for that provider, and the command line tool is
12
+ * a second reader beside a status line that already writes Claude rows. A free
13
+ * account whose usage document carries no windows would parse to nothing and
14
+ * would then withdraw rows another source had every right to write. A failed
15
+ * read leaves the cache exactly as it was and the row says what happened; only
16
+ * a successful read changes anything.
17
+ */
18
+ export function collectionReasonFor(outcome) {
19
+ if (outcome === "unauthorized")
20
+ return "authentication";
21
+ if (outcome === "rate_limited")
22
+ return "rate_limited";
23
+ if (outcome === "transport")
24
+ return "network";
25
+ return "remote_error";
26
+ }
27
+ async function attempt(spec, credential, options) {
28
+ const previous = [];
29
+ let retryAfter = null;
30
+ for (const step of spec.steps) {
31
+ const decided = step({ credential, previous });
32
+ if (decided === null) {
33
+ return { outcome: "drift", meters: [], retryAfterSeconds: null };
34
+ }
35
+ if ("stop" in decided) {
36
+ return { outcome: decided.stop, meters: [], retryAfterSeconds: retryAfter };
37
+ }
38
+ const request = decided;
39
+ let reply;
40
+ try {
41
+ reply = await options.transport(request);
42
+ }
43
+ catch {
44
+ /* The error object is never inspected and never formatted. A transport
45
+ failure carries a URL and sometimes a header, and neither belongs
46
+ anywhere near a row a person reads. */
47
+ return { outcome: "transport", meters: [], retryAfterSeconds: null };
48
+ }
49
+ retryAfter = reply.retryAfterSeconds;
50
+ if (reply.status === 0) {
51
+ return { outcome: "too_large", meters: [], retryAfterSeconds: retryAfter };
52
+ }
53
+ const outcome = outcomeForStatus(reply.status);
54
+ if (outcome !== "ok")
55
+ return { outcome, meters: [], retryAfterSeconds: retryAfter };
56
+ let body;
57
+ try {
58
+ body = JSON.parse(reply.body);
59
+ }
60
+ catch {
61
+ return { outcome: "drift", meters: [], retryAfterSeconds: retryAfter };
62
+ }
63
+ previous.push(body);
64
+ }
65
+ const payload = previous[previous.length - 1];
66
+ /*
67
+ * A parser is a pure function that should answer null rather than throw, and
68
+ * every one of ours does. This catch is here because ONE of them throwing
69
+ * used to end the whole round: six healthy providers would go unread because
70
+ * a seventh got a response nobody anticipated. A throw is that provider's
71
+ * drift and nobody else's.
72
+ */
73
+ let meters;
74
+ try {
75
+ meters = spec.parse(payload, options.now);
76
+ }
77
+ catch {
78
+ return { outcome: "drift", meters: [], retryAfterSeconds: retryAfter };
79
+ }
80
+ if (meters === null || meters.length === 0) {
81
+ return { outcome: "drift", meters: [], retryAfterSeconds: retryAfter };
82
+ }
83
+ return { outcome: "ok", meters, retryAfterSeconds: retryAfter };
84
+ }
85
+ /**
86
+ * Run every spec once, honouring the schedule.
87
+ *
88
+ * The returned schedule is the one to persist. A provider that was not asked,
89
+ * because it is off or because nothing on this machine belongs to it, keeps the
90
+ * schedule it had: a person who installs Codex this afternoon should not have
91
+ * to wait out a backoff that was recorded before Codex existed here.
92
+ */
93
+ export async function runAcquisition(specs, options) {
94
+ const rows = [];
95
+ const reports = [];
96
+ const schedule = {
97
+ ...options.schedule
98
+ };
99
+ const stamp = options.stamp ?? ((meters) => meters);
100
+ const readCredential = options.readCredential ??
101
+ ((provider) => readAcquisitionCredential(provider, {
102
+ ...options.lookup,
103
+ now: options.now
104
+ }));
105
+ /**
106
+ * One provider, start to finish.
107
+ *
108
+ * Split out of the loop so the loop can wrap it. Everything in here can
109
+ * throw: a credential reader, an injected transport, a parser, a clock. Six
110
+ * healthy providers must not go unread because a seventh surprised us.
111
+ */
112
+ const readOne = async (spec) => {
113
+ const existing = schedule[spec.provider];
114
+ if (spec.enabled === false) {
115
+ rows.push({
116
+ provider: spec.provider,
117
+ detected: false,
118
+ status: "off",
119
+ reason: spec.disabledReason ?? "this provider's poll is off",
120
+ nextAttemptAt: null,
121
+ disclosure: spec.disclosure
122
+ });
123
+ return;
124
+ }
125
+ if (!isProviderDue(existing, options.now)) {
126
+ rows.push({
127
+ provider: spec.provider,
128
+ detected: true,
129
+ status: "waiting",
130
+ reason: existing === undefined
131
+ ? null
132
+ : ACQUISITION_OUTCOME_SENTENCE[existing.outcome],
133
+ nextAttemptAt: existing?.nextAttemptAt ?? null,
134
+ disclosure: spec.disclosure
135
+ });
136
+ return;
137
+ }
138
+ if (spec.provider === "ANTIGRAVITY" && options.probeAntigravity !== undefined) {
139
+ let probeResult;
140
+ try {
141
+ probeResult = await options.probeAntigravity({
142
+ now: options.now,
143
+ ...(options.lookup !== undefined ? { lookup: options.lookup } : {}),
144
+ ...(options.resolveExecutablePath !== undefined
145
+ ? { resolveExecutablePath: options.resolveExecutablePath }
146
+ : {})
147
+ });
148
+ }
149
+ catch {
150
+ probeResult = { ok: false, reason: "unreachable" };
151
+ }
152
+ if (probeResult.ok && probeResult.meters.length > 0) {
153
+ const nextAttemptAt = nextAttemptInstant("ok", options.now);
154
+ schedule[spec.provider] = {
155
+ lastAttemptAt: options.now,
156
+ nextAttemptAt: nextAttemptAt ?? options.now,
157
+ outcome: "ok"
158
+ };
159
+ const snapshots = normalizeMeters(stamp(probeResult.meters, {
160
+ secret: "",
161
+ accountId: null,
162
+ expiresAtMilliseconds: null,
163
+ origin: "vendor_store"
164
+ }));
165
+ if (snapshots.length > 0) {
166
+ rows.push({
167
+ provider: spec.provider,
168
+ detected: true,
169
+ status: "read",
170
+ reason: null,
171
+ nextAttemptAt,
172
+ disclosure: spec.disclosure
173
+ });
174
+ reports.push({
175
+ ok: true,
176
+ provider: spec.provider,
177
+ observedAt: options.now,
178
+ snapshots
179
+ });
180
+ return;
181
+ }
182
+ }
183
+ if (!probeResult.ok && probeResult.reason === "not_running") {
184
+ const credential = await readCredential(spec.credentialProvider);
185
+ if (credential.ok && isSharedCodeAssist(credential.credential)) {
186
+ const fallbackResult = await attempt(spec, credential.credential, options);
187
+ if (fallbackResult.outcome === "ok" && fallbackResult.meters.length > 0) {
188
+ const accountId = spec.accountIdFor?.(credential.credential) ?? null;
189
+ const accountLabel = spec.accountLabelFor?.(credential.credential) ?? null;
190
+ const disclosure = spec.disclosureFor?.(credential.credential) ?? spec.disclosure;
191
+ const nextAttemptAt = nextAttemptInstant("ok", options.now);
192
+ schedule[spec.provider] = {
193
+ lastAttemptAt: options.now,
194
+ nextAttemptAt: nextAttemptAt ?? options.now,
195
+ outcome: "ok"
196
+ };
197
+ const snapshots = normalizeMeters(stamp(fallbackResult.meters, credential.credential).map((entry) => ({
198
+ ...entry,
199
+ ...(accountId === null ? {} : { accountId }),
200
+ ...(accountLabel === null ? {} : { accountLabel })
201
+ })));
202
+ if (snapshots.length > 0) {
203
+ rows.push({
204
+ provider: spec.provider,
205
+ ...(accountId === null ? {} : { accountId }),
206
+ detected: true,
207
+ status: "read",
208
+ reason: null,
209
+ nextAttemptAt,
210
+ disclosure
211
+ });
212
+ reports.push({
213
+ ok: true,
214
+ provider: spec.provider,
215
+ ...(accountId === null ? {} : { accountId }),
216
+ observedAt: options.now,
217
+ snapshots
218
+ });
219
+ return;
220
+ }
221
+ }
222
+ }
223
+ const nextAttemptAt = nextAttemptInstant("ok", options.now);
224
+ schedule[spec.provider] = {
225
+ lastAttemptAt: options.now,
226
+ nextAttemptAt: nextAttemptAt ?? options.now,
227
+ outcome: "drift"
228
+ };
229
+ rows.push({
230
+ provider: spec.provider,
231
+ detected: true,
232
+ status: "stale",
233
+ reason: AGY_NOT_RUNNING_SENTENCE,
234
+ nextAttemptAt,
235
+ disclosure: spec.disclosure
236
+ });
237
+ return;
238
+ }
239
+ }
240
+ const credential = await readCredential(spec.credentialProvider);
241
+ if (!credential.ok) {
242
+ const absent = credential.reason === "absent";
243
+ rows.push({
244
+ provider: spec.provider,
245
+ detected: !absent,
246
+ status: absent ? "not_detected" : "stale",
247
+ reason: CREDENTIAL_FAILURE_SENTENCE[credential.reason],
248
+ nextAttemptAt: null,
249
+ disclosure: spec.disclosure
250
+ });
251
+ /* A local credential problem does not earn a network backoff. Nothing was
252
+ asked of the provider, and the fix is on this machine. */
253
+ return;
254
+ }
255
+ const held = credential.credential;
256
+ const accountId = spec.accountIdFor?.(held) ?? null;
257
+ const accountLabel = spec.accountLabelFor?.(held) ?? null;
258
+ const disclosure = spec.disclosureFor?.(held) ?? spec.disclosure;
259
+ const sentence = (outcome) => spec.outcomeSentence?.[outcome] ?? ACQUISITION_OUTCOME_SENTENCE[outcome];
260
+ const result = await attempt(spec, held, options);
261
+ const nextAttemptAt = nextAttemptInstant(result.outcome, options.now, result.retryAfterSeconds);
262
+ schedule[spec.provider] = {
263
+ lastAttemptAt: options.now,
264
+ nextAttemptAt: nextAttemptAt ?? options.now,
265
+ outcome: result.outcome
266
+ };
267
+ const snapshots = result.outcome === "ok"
268
+ ? normalizeMeters(accountId === null
269
+ ? stamp(result.meters, held)
270
+ : stamp(result.meters, held).map((entry) => ({
271
+ ...entry,
272
+ accountId,
273
+ /* A surface that would otherwise print the identifier gets a
274
+ sentence a person can read instead. */
275
+ ...(accountLabel === null ? {} : { accountLabel })
276
+ })))
277
+ : [];
278
+ /* A read that parsed and then lost every row to validation has produced no
279
+ reading, and saying otherwise would put an empty success on the row. */
280
+ const believed = result.outcome === "ok" && snapshots.length > 0;
281
+ if (believed) {
282
+ rows.push({
283
+ provider: spec.provider,
284
+ ...(accountId === null ? {} : { accountId }),
285
+ detected: true,
286
+ status: "read",
287
+ reason: null,
288
+ nextAttemptAt,
289
+ disclosure
290
+ });
291
+ reports.push({
292
+ ok: true,
293
+ provider: spec.provider,
294
+ ...(accountId === null ? {} : { accountId }),
295
+ observedAt: options.now,
296
+ snapshots
297
+ });
298
+ return;
299
+ }
300
+ const outcome = result.outcome === "ok"
301
+ ? "drift"
302
+ : result.outcome;
303
+ schedule[spec.provider] = {
304
+ lastAttemptAt: options.now,
305
+ nextAttemptAt: nextAttemptAt ?? options.now,
306
+ outcome
307
+ };
308
+ rows.push({
309
+ provider: spec.provider,
310
+ ...(accountId === null ? {} : { accountId }),
311
+ detected: true,
312
+ status: "stale",
313
+ reason: sentence(outcome),
314
+ nextAttemptAt,
315
+ disclosure
316
+ });
317
+ };
318
+ for (const spec of specs) {
319
+ try {
320
+ await readOne(spec);
321
+ }
322
+ catch {
323
+ /*
324
+ * The last line of defence. A provider that threw where nothing was
325
+ * supposed to throw is that provider's drift, recorded on the ordinary
326
+ * cadence, and the round carries on to everybody else.
327
+ */
328
+ schedule[spec.provider] = {
329
+ lastAttemptAt: options.now,
330
+ nextAttemptAt: nextAttemptInstant("drift", options.now) ?? options.now,
331
+ outcome: "drift"
332
+ };
333
+ rows.push({
334
+ provider: spec.provider,
335
+ detected: true,
336
+ status: "stale",
337
+ reason: ACQUISITION_OUTCOME_SENTENCE.drift,
338
+ nextAttemptAt: null,
339
+ disclosure: spec.disclosure
340
+ });
341
+ }
342
+ }
343
+ return { rows, reports, schedule };
344
+ }
345
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/acquire/runner.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EACL,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,EAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EAK1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAIjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EAGzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAgIpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA2B;IAE3B,IAAI,OAAO,KAAK,cAAc;QAAE,OAAO,gBAAgB,CAAC;IACxD,IAAI,OAAO,KAAK,cAAc;QAAE,OAAO,cAAc,CAAC;IACtD,IAAI,OAAO,KAAK,WAAW;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,cAAc,CAAC;AACxB,CAAC;AAQD,KAAK,UAAU,OAAO,CACpB,IAAqB,EACrB,UAA8B,EAC9B,OAA8B;IAE9B,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,IAAI,UAAU,GAAkB,IAAI,CAAC;IACrC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9B,MAAM,OAA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IG;YACH,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG;gBACxB,aAAa,EAAE,OAAO,CAAC,GAAG;gBAC1B,aAAa,EAAE,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG;gBACtE,OAAO,EAAE,OAAO;aACjB,CAAC;YACF,IAAI,CAAC,IAAI,CAAC;gBACR,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,4BAA4B,CAAC,KAAK;gBAC1C,aAAa,EAAE,IAAI;gBACnB,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}
@@ -0,0 +1,194 @@
1
+ /** One request's total budget, connect to last body byte. */
2
+ export declare const ACQUISITION_TIMEOUT_MILLISECONDS = 15000;
3
+ /** Largest response body accepted, the bound every state file already uses. */
4
+ export declare const MAX_ACQUISITION_RESPONSE_BYTES = 1048576;
5
+ /** The Claude account usage report, read with Claude Code's own OAuth token. */
6
+ export declare const CLAUDE_OAUTH_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
7
+ /** The Codex usage report, read with the session the Codex CLI holds. */
8
+ export declare const CODEX_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
9
+ /** Gemini CLI's Code Assist account bootstrap, which names the project. */
10
+ export declare const GEMINI_CLI_LOAD_URL = "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist";
11
+ /** Gemini CLI's per model quota report. */
12
+ export declare const GEMINI_CLI_QUOTA_URL = "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota";
13
+ /** The Grok Build billing report the official Grok CLI reads. */
14
+ export declare const GROK_USAGE_URL = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
15
+ /** The Kimi Code usage report the official Kimi CLI reads. */
16
+ export declare const KIMI_USAGE_URL = "https://api.kimi.com/coding/v1/usages";
17
+ /** The OpenRouter inference key report: limit, remaining and usage. */
18
+ export declare const OPENROUTER_KEY_URL = "https://openrouter.ai/api/v1/key";
19
+ /**
20
+ * Every address this path may speak to.
21
+ *
22
+ * Adding a provider means adding an entry here, in code, in review. Antigravity
23
+ * has no entry of its own: it reads the same Code Assist pair as Gemini CLI
24
+ * with the credential the Antigravity client stored, which is why this table is
25
+ * shorter than the provider list.
26
+ */
27
+ export declare const ACQUISITION_ENDPOINTS: {
28
+ readonly claude_usage: {
29
+ readonly url: "https://api.anthropic.com/api/oauth/usage";
30
+ readonly method: "GET";
31
+ };
32
+ readonly codex_usage: {
33
+ readonly url: "https://chatgpt.com/backend-api/wham/usage";
34
+ readonly method: "GET";
35
+ };
36
+ readonly code_assist_load: {
37
+ readonly url: "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist";
38
+ readonly method: "POST";
39
+ };
40
+ readonly code_assist_quota: {
41
+ readonly url: "https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota";
42
+ readonly method: "POST";
43
+ };
44
+ readonly grok_billing: {
45
+ readonly url: "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
46
+ readonly method: "GET";
47
+ };
48
+ readonly kimi_usage: {
49
+ readonly url: "https://api.kimi.com/coding/v1/usages";
50
+ readonly method: "GET";
51
+ };
52
+ readonly openrouter_key: {
53
+ readonly url: "https://openrouter.ai/api/v1/key";
54
+ readonly method: "GET";
55
+ };
56
+ };
57
+ export type AcquisitionEndpointId = keyof typeof ACQUISITION_ENDPOINTS;
58
+ /** The beta contract the OAuth usage route answers. */
59
+ export declare const CLAUDE_OAUTH_BETA_HEADER = "anthropic-beta";
60
+ export declare const CLAUDE_OAUTH_BETA_VALUE = "oauth-2025-04-20";
61
+ /** The account header the ChatGPT backend reads beside the bearer token. */
62
+ export declare const CODEX_ACCOUNT_HEADER = "chatgpt-account-id";
63
+ /** The account identity the Grok billing service reads beside the token. */
64
+ export declare const GROK_ACCOUNT_HEADER = "x-userid";
65
+ /**
66
+ * The Code Assist bootstrap body, the same metadata the maintained client
67
+ * sends for an account that is already onboarded. Undefined project fields are
68
+ * omitted exactly as that client omits them.
69
+ */
70
+ export declare const CODE_ASSIST_LOAD_BODY: string;
71
+ export interface AcquisitionRequest {
72
+ readonly endpoint: AcquisitionEndpointId;
73
+ readonly url: string;
74
+ readonly method: "GET" | "POST";
75
+ readonly headers: Readonly<Record<string, string>>;
76
+ readonly body: string | null;
77
+ }
78
+ /**
79
+ * Whether a secret may be written into a header at all.
80
+ *
81
+ * The value is read off disk from a file this process does not own. A control
82
+ * character in it would let a hostile credential file inject a second header,
83
+ * so anything that is not bounded printable ASCII is refused before it can
84
+ * reach a request. Nothing about the refusal names the value.
85
+ */
86
+ export declare function usableHeaderSecret(value: string): boolean;
87
+ /**
88
+ * Whether an account identifier may be written into a header.
89
+ *
90
+ * Narrower than a secret, because this one is an opaque identifier rather than
91
+ * a token: letters, digits and the three separators the observed identifiers
92
+ * use, and nothing else.
93
+ */
94
+ export declare function usableHeaderAccountId(value: string): boolean;
95
+ /** The Claude usage request. Our identity, and the documented beta contract. */
96
+ export declare function claudeUsageRequest(secret: string): AcquisitionRequest | null;
97
+ /** The Codex usage request, with the account header the backend requires. */
98
+ export declare function codexUsageRequest(secret: string, accountId: string): AcquisitionRequest | null;
99
+ /** The Code Assist bootstrap, which answers with the companion project. */
100
+ export declare function codeAssistLoadRequest(secret: string): AcquisitionRequest | null;
101
+ /**
102
+ * Shape of a companion project identifier, and the reason there is one.
103
+ *
104
+ * The value arrives in a provider response body and is then written into the
105
+ * body of our next request. That is the one place a provider gets to influence
106
+ * what we send, so it is held to an opaque identifier and nothing else.
107
+ */
108
+ export declare const CODE_ASSIST_PROJECT_PATTERN: RegExp;
109
+ /** The per model quota request, scoped to a validated companion project. */
110
+ export declare function codeAssistQuotaRequest(secret: string, project: string): AcquisitionRequest | null;
111
+ /**
112
+ * The Grok billing request.
113
+ *
114
+ * The account header is an identifier for the person's own account and is sent
115
+ * when the credential names one. Nothing else is: the desktop sends xAI's
116
+ * `x-xai-token-auth: xai-grok-cli` marker beside it, and that value NAMES THE
117
+ * VENDOR'S OWN TOOL, which is the same claim a copied user agent makes. Rule 1
118
+ * says we identify as OpenLimiter and take whatever that costs us, so the
119
+ * marker is not sent here and no client version is invented either.
120
+ *
121
+ * The consequence is honestly unknown rather than assumed: no Grok login exists
122
+ * on the machine this was written on, so whether the billing route answers a
123
+ * request that does not claim to be the Grok CLI is verified on the first
124
+ * install that has one, and the row says so until then.
125
+ */
126
+ export declare function grokBillingRequest(secret: string, accountId: string | null): AcquisitionRequest | null;
127
+ /** The Kimi Code usage request. */
128
+ export declare function kimiUsageRequest(secret: string): AcquisitionRequest | null;
129
+ /** The OpenRouter key report, the one documented interface in this table. */
130
+ export declare function openrouterKeyRequest(secret: string): AcquisitionRequest | null;
131
+ /**
132
+ * What one request achieved, in words this product owns.
133
+ *
134
+ * Every value here is a decision about what to do next, never a description of
135
+ * a response body. `blocked` and `rate_limited` are separated because they earn
136
+ * different backoffs, and `drift` is separated from `remote_error` because only
137
+ * drift says the meaning of a stored reading is in doubt.
138
+ *
139
+ * `identity_refused` is the one that cost the most to learn. A provider can
140
+ * answer 200 to an honest client and still leave out the field the next request
141
+ * needs, which reads exactly like drift and is not: nothing changed shape, the
142
+ * provider simply serves that field to its own tools. Measured on 2026-09-07
143
+ * against Code Assist, which answered 200 with tier information and no
144
+ * companion project. Calling it drift would have had this build retry every
145
+ * fifteen minutes forever against an answer that will never differ.
146
+ */
147
+ export declare const ACQUISITION_OUTCOMES: readonly ["ok", "unauthorized", "rate_limited", "blocked", "remote_error", "transport", "too_large", "drift", "identity_refused"];
148
+ export type AcquisitionOutcome = (typeof ACQUISITION_OUTCOMES)[number];
149
+ export interface AcquisitionReply {
150
+ readonly status: number;
151
+ readonly body: string;
152
+ /** Retry-After in seconds when the provider stated one, otherwise null. */
153
+ readonly retryAfterSeconds: number | null;
154
+ }
155
+ export type AcquisitionTransport = (request: AcquisitionRequest) => Promise<AcquisitionReply>;
156
+ /**
157
+ * Turn a status into a decision.
158
+ *
159
+ * 401 and 403 are told apart on purpose. A lapsed token is a person's next
160
+ * step, and a refusal to serve this client at all is a reason to stay away for
161
+ * a day. Everything from 500 up is the provider having a bad minute and is
162
+ * retried on the ordinary interval.
163
+ */
164
+ export declare function outcomeForStatus(status: number): AcquisitionOutcome;
165
+ /** Retry-After in seconds, when the header is a count of seconds we believe. */
166
+ export declare function retryAfterSeconds(value: string | null): number | null;
167
+ /**
168
+ * The header names an acquisition request may carry.
169
+ *
170
+ * Closed, and checked at the boundary below rather than trusted from the
171
+ * builders above. The builders are the only callers today, but the transport is
172
+ * exported and a future caller that assembled a request by hand would otherwise
173
+ * be able to put anything on the wire under this product's name.
174
+ */
175
+ export declare const ALLOWED_REQUEST_HEADERS: readonly string[];
176
+ /**
177
+ * Whether a request may leave this process.
178
+ *
179
+ * Address, method, every header name, every header VALUE and the body, all
180
+ * answered against constants in this file. A request that fails any of them
181
+ * never reaches the network.
182
+ */
183
+ export declare function validAcquisitionRequest(request: AcquisitionRequest): boolean;
184
+ /**
185
+ * The transport the product uses, built on the runtime's own fetch.
186
+ *
187
+ * Redirects are refused rather than followed: a redirect on any of these
188
+ * addresses would carry the bearer token somewhere the closed table above never
189
+ * named. The body is bounded before it is decoded, and the whole request lives
190
+ * under one deadline. A transport level failure is an exception, which the
191
+ * runner turns into the `transport` outcome without ever formatting it.
192
+ */
193
+ export declare function createFetchTransport(fetchImplementation?: typeof globalThis.fetch): AcquisitionTransport;
194
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/acquire/transport.ts"],"names":[],"mappings":"AAgBA,6DAA6D;AAC7D,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,+EAA+E;AAC/E,eAAO,MAAM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