@raybase/openai-subscription 0.0.2 → 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.
- package/ARCHITECTURE.md +80 -0
- package/LICENSE +21 -0
- package/README.md +198 -2
- package/compatibility/fixtures/device-usercode.json +5 -0
- package/compatibility/fixtures/responses-function-call.sse +23 -0
- package/compatibility/fixtures/responses-image-input.sse +15 -0
- package/compatibility/fixtures/responses-image-request.json +32 -0
- package/compatibility/fixtures/responses-invalid-function-parameters.json +8 -0
- package/compatibility/fixtures/responses-invalid-json-schema.json +8 -0
- package/compatibility/fixtures/responses-mixed.sse +41 -0
- package/compatibility/fixtures/responses-multi-tool.sse +35 -0
- package/compatibility/fixtures/responses.sse +26 -0
- package/compatibility/manifest.json +50 -0
- package/dist/crypto.d.ts +12 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +86 -0
- package/dist/crypto.js.map +1 -0
- package/dist/health.d.ts +9 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +22 -0
- package/dist/health.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +6 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +341 -0
- package/dist/module.js.map +1 -0
- package/dist/provider.d.ts +8 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +361 -0
- package/dist/provider.js.map +1 -0
- package/dist/store.d.ts +51 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +342 -0
- package/dist/store.js.map +1 -0
- package/dist/system-tables.d.ts +7 -0
- package/dist/system-tables.d.ts.map +1 -0
- package/dist/system-tables.js +59 -0
- package/dist/system-tables.js.map +1 -0
- package/dist/testing.d.ts +4 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +4 -0
- package/dist/testing.js.map +1 -0
- package/dist/transport.d.ts +104 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +1115 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +29 -0
- package/dist/types.js.map +1 -0
- package/package.json +39 -8
- package/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/templates/astro-emdash/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/templates/astro-emdash/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/templates/astro-emdash/src/openai-subscription.ts +11 -0
- package/templates/react-router/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/templates/react-router/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/templates/react-router/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/templates/react-router/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/templates/react-router/app/openai-subscription.ts +11 -0
- package/templates/tanstack-start/.agents/skills/raybase-openai-subscription/SKILL.md +57 -0
- package/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/compatibility-and-testing.md +129 -0
- package/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/module-contract.md +133 -0
- package/templates/tanstack-start/.agents/skills/raybase-openai-subscription/references/structured-outputs.md +159 -0
- package/templates/tanstack-start/src/openai-subscription.ts +11 -0
package/dist/store.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { nowIso, q, randomId } from "@raybase/core";
|
|
2
|
+
import { decryptOpenAISubscriptionEnvelope, encryptOpenAISubscriptionEnvelope, openAISubscriptionScopeKey } from "./crypto.js";
|
|
3
|
+
import { openaiSubscriptionCredentialsTable, openaiSubscriptionHealthTable, openaiSubscriptionIncidentsTable, openaiSubscriptionPendingTable } from "./system-tables.js";
|
|
4
|
+
export class OpenAISubscriptionCredentialStore {
|
|
5
|
+
control;
|
|
6
|
+
secret;
|
|
7
|
+
#flights = new Map();
|
|
8
|
+
constructor(control, secret) {
|
|
9
|
+
this.control = control;
|
|
10
|
+
this.secret = secret;
|
|
11
|
+
}
|
|
12
|
+
async read(scope) {
|
|
13
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
14
|
+
const row = await this.control.first(`SELECT "id", "envelopeJson", "revision", "generation", "refreshLeaseOwner", "refreshLeaseExpiresAt"
|
|
15
|
+
FROM ${q(openaiSubscriptionCredentialsTable)} WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
16
|
+
if (!row)
|
|
17
|
+
return null;
|
|
18
|
+
return {
|
|
19
|
+
tokens: await decryptOpenAISubscriptionEnvelope(this.secret, scope, JSON.parse(row.envelopeJson)),
|
|
20
|
+
revision: Number(row.revision),
|
|
21
|
+
generation: Number(row.generation)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async write(scope, tokens, options = {}) {
|
|
25
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
26
|
+
const current = await this.control.first(`SELECT "id", "revision", "generation", "envelopeJson", "refreshLeaseOwner", "refreshLeaseExpiresAt"
|
|
27
|
+
FROM ${q(openaiSubscriptionCredentialsTable)} WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
28
|
+
if (options.expectedRevision !== undefined && Number(current?.revision ?? 0) !== options.expectedRevision) {
|
|
29
|
+
throw new Error("OpenAI subscription credential revision changed");
|
|
30
|
+
}
|
|
31
|
+
const revision = Number(current?.revision ?? 0) + 1;
|
|
32
|
+
const generation = options.generation ?? Number(current?.generation ?? 0) + (current ? 0 : 1);
|
|
33
|
+
const envelope = await encryptOpenAISubscriptionEnvelope(this.secret, scope, tokens);
|
|
34
|
+
const now = nowIso();
|
|
35
|
+
if (current) {
|
|
36
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionCredentialsTable)}
|
|
37
|
+
SET "envelopeJson" = ?, "revision" = ?, "generation" = ?, "refreshLeaseOwner" = NULL,
|
|
38
|
+
"refreshLeaseExpiresAt" = NULL, "updatedAt" = ?
|
|
39
|
+
WHERE "scopeKey" = ? AND "revision" = ?`, [JSON.stringify(envelope), revision, generation, now, scopeKey, current.revision]);
|
|
40
|
+
const committed = await this.control.first(`SELECT "revision" FROM ${q(openaiSubscriptionCredentialsTable)} WHERE "scopeKey" = ?`, [scopeKey]);
|
|
41
|
+
if (Number(committed?.revision) !== revision)
|
|
42
|
+
throw new Error("OpenAI subscription credential compare-and-swap failed");
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
await this.control.run(`INSERT INTO ${q(openaiSubscriptionCredentialsTable)}
|
|
46
|
+
("id", "scopeKey", "mode", "envelopeJson", "revision", "generation", "createdAt", "updatedAt")
|
|
47
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [randomId("oai_cred"), scopeKey, scope.mode, JSON.stringify(envelope), revision, generation, now, now]);
|
|
48
|
+
}
|
|
49
|
+
return { revision, generation };
|
|
50
|
+
}
|
|
51
|
+
async acquireRefreshLease(scope, revision, owner, leaseMs = 15_000) {
|
|
52
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
53
|
+
const now = nowIso();
|
|
54
|
+
const expiresAt = new Date(Date.now() + leaseMs).toISOString();
|
|
55
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionCredentialsTable)}
|
|
56
|
+
SET "refreshLeaseOwner" = ?, "refreshLeaseExpiresAt" = ?, "updatedAt" = ?
|
|
57
|
+
WHERE "scopeKey" = ? AND "revision" = ?
|
|
58
|
+
AND ("refreshLeaseOwner" IS NULL OR "refreshLeaseExpiresAt" IS NULL OR "refreshLeaseExpiresAt" <= ?)`, [owner, expiresAt, now, scopeKey, revision, now]);
|
|
59
|
+
const row = await this.control.first(`SELECT "refreshLeaseOwner", "revision" FROM ${q(openaiSubscriptionCredentialsTable)}
|
|
60
|
+
WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
61
|
+
return row?.refreshLeaseOwner === owner && Number(row.revision) === revision;
|
|
62
|
+
}
|
|
63
|
+
async releaseRefreshLease(scope, revision, owner) {
|
|
64
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
65
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionCredentialsTable)}
|
|
66
|
+
SET "refreshLeaseOwner" = NULL, "refreshLeaseExpiresAt" = NULL, "updatedAt" = ?
|
|
67
|
+
WHERE "scopeKey" = ? AND "revision" = ? AND "refreshLeaseOwner" = ?`, [nowIso(), scopeKey, revision, owner]);
|
|
68
|
+
}
|
|
69
|
+
async waitForRevisionChange(scope, revision, options = {}) {
|
|
70
|
+
const attempts = options.attempts ?? 40;
|
|
71
|
+
const intervalMs = options.intervalMs ?? 50;
|
|
72
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
73
|
+
const credential = await this.read(scope);
|
|
74
|
+
if (!credential || credential.revision !== revision)
|
|
75
|
+
return credential;
|
|
76
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
77
|
+
}
|
|
78
|
+
return this.read(scope);
|
|
79
|
+
}
|
|
80
|
+
async disconnect(scope) {
|
|
81
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
82
|
+
const current = await this.control.first(`SELECT "generation" FROM ${q(openaiSubscriptionCredentialsTable)} WHERE "scopeKey" = ?`, [scopeKey]);
|
|
83
|
+
const generation = Number(current?.generation ?? 0) + 1;
|
|
84
|
+
await (this.control.runTransaction?.([
|
|
85
|
+
{ sql: `DELETE FROM ${q(openaiSubscriptionCredentialsTable)} WHERE "scopeKey" = ?`, params: [scopeKey] },
|
|
86
|
+
{ sql: `DELETE FROM ${q(openaiSubscriptionPendingTable)} WHERE "scopeKey" = ?`, params: [scopeKey] }
|
|
87
|
+
]) ?? Promise.all([
|
|
88
|
+
this.control.run(`DELETE FROM ${q(openaiSubscriptionCredentialsTable)} WHERE "scopeKey" = ?`, [scopeKey]),
|
|
89
|
+
this.control.run(`DELETE FROM ${q(openaiSubscriptionPendingTable)} WHERE "scopeKey" = ?`, [scopeKey])
|
|
90
|
+
]).then(() => undefined));
|
|
91
|
+
await this.writeStatus(scope, {
|
|
92
|
+
state: "disconnected",
|
|
93
|
+
stateSince: nowIso(),
|
|
94
|
+
credentialMode: scope.mode,
|
|
95
|
+
compatibilityVersion: "codex-subscription-2026-07-29",
|
|
96
|
+
actionHref: "/admin/openai-subscription",
|
|
97
|
+
generation
|
|
98
|
+
});
|
|
99
|
+
return generation;
|
|
100
|
+
}
|
|
101
|
+
async writePending(scope, pending) {
|
|
102
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
103
|
+
const envelope = await encryptOpenAISubscriptionEnvelope(this.secret, scope, pending);
|
|
104
|
+
const now = nowIso();
|
|
105
|
+
await this.control.run(`DELETE FROM ${q(openaiSubscriptionPendingTable)} WHERE "scopeKey" = ?`, [scopeKey]);
|
|
106
|
+
await this.control.run(`INSERT INTO ${q(openaiSubscriptionPendingTable)}
|
|
107
|
+
("id", "scopeKey", "mode", "envelopeJson", "generation", "nextPollAt", "expiresAt", "createdAt", "updatedAt")
|
|
108
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [randomId("oai_pending"), scopeKey, scope.mode, JSON.stringify(envelope), pending.generation, pending.nextPollAt, pending.expiresAt, now, now]);
|
|
109
|
+
}
|
|
110
|
+
async commitPendingPoll(scope, pending, leaseOwner) {
|
|
111
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
112
|
+
const envelopeJson = JSON.stringify(await encryptOpenAISubscriptionEnvelope(this.secret, scope, pending));
|
|
113
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionPendingTable)}
|
|
114
|
+
SET "envelopeJson" = ?, "nextPollAt" = ?, "expiresAt" = ?, "updatedAt" = ?
|
|
115
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "pollLeaseOwner" = ?`, [
|
|
116
|
+
envelopeJson,
|
|
117
|
+
pending.nextPollAt,
|
|
118
|
+
pending.expiresAt,
|
|
119
|
+
nowIso(),
|
|
120
|
+
scopeKey,
|
|
121
|
+
pending.generation,
|
|
122
|
+
leaseOwner
|
|
123
|
+
]);
|
|
124
|
+
const committed = await this.control.first(`SELECT "envelopeJson", "generation", "pollLeaseOwner"
|
|
125
|
+
FROM ${q(openaiSubscriptionPendingTable)} WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
126
|
+
return committed?.envelopeJson === envelopeJson
|
|
127
|
+
&& Number(committed.generation) === pending.generation
|
|
128
|
+
&& committed.pollLeaseOwner === leaseOwner;
|
|
129
|
+
}
|
|
130
|
+
async commitPendingAuthorization(scope, pending, leaseOwner, tokens) {
|
|
131
|
+
if (!this.control.runTransaction) {
|
|
132
|
+
throw new Error("OpenAI subscription authorization requires atomic storage");
|
|
133
|
+
}
|
|
134
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
135
|
+
const envelopeJson = JSON.stringify(await encryptOpenAISubscriptionEnvelope(this.secret, scope, tokens));
|
|
136
|
+
const now = nowIso();
|
|
137
|
+
const credentialId = randomId("oai_cred");
|
|
138
|
+
const healthId = randomId("oai_health");
|
|
139
|
+
await this.control.runTransaction([
|
|
140
|
+
{
|
|
141
|
+
sql: `INSERT INTO ${q(openaiSubscriptionCredentialsTable)}
|
|
142
|
+
("id", "scopeKey", "mode", "envelopeJson", "revision", "generation", "createdAt", "updatedAt")
|
|
143
|
+
SELECT ?, ?, ?, ?, 1, ?, ?, ?
|
|
144
|
+
WHERE EXISTS (
|
|
145
|
+
SELECT 1 FROM ${q(openaiSubscriptionPendingTable)}
|
|
146
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "pollLeaseOwner" = ?
|
|
147
|
+
)
|
|
148
|
+
ON CONFLICT("scopeKey") DO UPDATE SET
|
|
149
|
+
"envelopeJson" = excluded."envelopeJson",
|
|
150
|
+
"revision" = "revision" + 1,
|
|
151
|
+
"generation" = excluded."generation",
|
|
152
|
+
"refreshLeaseOwner" = NULL,
|
|
153
|
+
"refreshLeaseExpiresAt" = NULL,
|
|
154
|
+
"updatedAt" = excluded."updatedAt"`,
|
|
155
|
+
params: [
|
|
156
|
+
credentialId,
|
|
157
|
+
scopeKey,
|
|
158
|
+
scope.mode,
|
|
159
|
+
envelopeJson,
|
|
160
|
+
pending.generation,
|
|
161
|
+
now,
|
|
162
|
+
now,
|
|
163
|
+
scopeKey,
|
|
164
|
+
pending.generation,
|
|
165
|
+
leaseOwner
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
sql: `INSERT INTO ${q(openaiSubscriptionHealthTable)}
|
|
170
|
+
("id", "scopeKey", "mode", "state", "stateSince", "accountId", "workspaceId", "plan",
|
|
171
|
+
"lastSuccessAt", "compatibilityVersion", "actionHref", "generation", "updatedAt")
|
|
172
|
+
SELECT ?, ?, ?, 'connected', ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
173
|
+
WHERE EXISTS (
|
|
174
|
+
SELECT 1 FROM ${q(openaiSubscriptionCredentialsTable)}
|
|
175
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "envelopeJson" = ?
|
|
176
|
+
)
|
|
177
|
+
ON CONFLICT("scopeKey") DO UPDATE SET
|
|
178
|
+
"mode" = excluded."mode",
|
|
179
|
+
"state" = excluded."state",
|
|
180
|
+
"stateSince" = excluded."stateSince",
|
|
181
|
+
"accountId" = excluded."accountId",
|
|
182
|
+
"workspaceId" = excluded."workspaceId",
|
|
183
|
+
"plan" = excluded."plan",
|
|
184
|
+
"retryAt" = NULL,
|
|
185
|
+
"lastSuccessAt" = excluded."lastSuccessAt",
|
|
186
|
+
"compatibilityVersion" = excluded."compatibilityVersion",
|
|
187
|
+
"actionHref" = excluded."actionHref",
|
|
188
|
+
"generation" = excluded."generation",
|
|
189
|
+
"updatedAt" = excluded."updatedAt"`,
|
|
190
|
+
params: [
|
|
191
|
+
healthId,
|
|
192
|
+
scopeKey,
|
|
193
|
+
scope.mode,
|
|
194
|
+
now,
|
|
195
|
+
tokens.accountId ?? null,
|
|
196
|
+
tokens.workspaceId ?? null,
|
|
197
|
+
tokens.plan ?? null,
|
|
198
|
+
now,
|
|
199
|
+
"codex-subscription-2026-07-29",
|
|
200
|
+
"/admin/openai-subscription",
|
|
201
|
+
pending.generation,
|
|
202
|
+
now,
|
|
203
|
+
scopeKey,
|
|
204
|
+
pending.generation,
|
|
205
|
+
envelopeJson
|
|
206
|
+
]
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
sql: `DELETE FROM ${q(openaiSubscriptionPendingTable)}
|
|
210
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "pollLeaseOwner" = ?`,
|
|
211
|
+
params: [scopeKey, pending.generation, leaseOwner]
|
|
212
|
+
}
|
|
213
|
+
]);
|
|
214
|
+
const committed = await this.control.first(`SELECT "envelopeJson", "generation" FROM ${q(openaiSubscriptionCredentialsTable)}
|
|
215
|
+
WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
216
|
+
return committed?.envelopeJson === envelopeJson
|
|
217
|
+
&& Number(committed.generation) === pending.generation;
|
|
218
|
+
}
|
|
219
|
+
async readPending(scope) {
|
|
220
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
221
|
+
const row = await this.control.first(`SELECT "envelopeJson" FROM ${q(openaiSubscriptionPendingTable)} WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
222
|
+
return row
|
|
223
|
+
? decryptOpenAISubscriptionEnvelope(this.secret, scope, JSON.parse(row.envelopeJson))
|
|
224
|
+
: null;
|
|
225
|
+
}
|
|
226
|
+
async deletePending(scope, expected = {}) {
|
|
227
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
228
|
+
const predicates = [`"scopeKey" = ?`];
|
|
229
|
+
const params = [scopeKey];
|
|
230
|
+
if (expected.generation !== undefined) {
|
|
231
|
+
predicates.push(`"generation" = ?`);
|
|
232
|
+
params.push(expected.generation);
|
|
233
|
+
}
|
|
234
|
+
if (expected.leaseOwner !== undefined) {
|
|
235
|
+
predicates.push(`"pollLeaseOwner" = ?`);
|
|
236
|
+
params.push(expected.leaseOwner);
|
|
237
|
+
}
|
|
238
|
+
await this.control.run(`DELETE FROM ${q(openaiSubscriptionPendingTable)} WHERE ${predicates.join(" AND ")}`, params);
|
|
239
|
+
}
|
|
240
|
+
async acquirePendingPollLease(scope, generation, owner, leaseMs = 15_000) {
|
|
241
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
242
|
+
const now = nowIso();
|
|
243
|
+
const expiresAt = new Date(Date.now() + leaseMs).toISOString();
|
|
244
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionPendingTable)}
|
|
245
|
+
SET "pollLeaseOwner" = ?, "pollLeaseExpiresAt" = ?, "updatedAt" = ?
|
|
246
|
+
WHERE "scopeKey" = ? AND "generation" = ?
|
|
247
|
+
AND ("pollLeaseOwner" IS NULL OR "pollLeaseExpiresAt" IS NULL OR "pollLeaseExpiresAt" <= ?)`, [owner, expiresAt, now, scopeKey, generation, now]);
|
|
248
|
+
const row = await this.control.first(`SELECT "pollLeaseOwner", "generation" FROM ${q(openaiSubscriptionPendingTable)}
|
|
249
|
+
WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
250
|
+
return row?.pollLeaseOwner === owner && Number(row.generation) === generation;
|
|
251
|
+
}
|
|
252
|
+
async releasePendingPollLease(scope, generation, owner) {
|
|
253
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
254
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionPendingTable)}
|
|
255
|
+
SET "pollLeaseOwner" = NULL, "pollLeaseExpiresAt" = NULL, "updatedAt" = ?
|
|
256
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "pollLeaseOwner" = ?`, [nowIso(), scopeKey, generation, owner]);
|
|
257
|
+
}
|
|
258
|
+
async status(scope) {
|
|
259
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
260
|
+
const row = await this.control.first(`SELECT "state", "stateSince", "mode", "ownerLabel", "accountId", "workspaceId", "plan",
|
|
261
|
+
"retryAt", "lastSuccessAt", "compatibilityVersion", "actionHref", "generation"
|
|
262
|
+
FROM ${q(openaiSubscriptionHealthTable)} WHERE "scopeKey" = ? LIMIT 1`, [scopeKey]);
|
|
263
|
+
if (!row) {
|
|
264
|
+
return {
|
|
265
|
+
state: "disconnected",
|
|
266
|
+
stateSince: nowIso(),
|
|
267
|
+
credentialMode: scope.mode,
|
|
268
|
+
compatibilityVersion: "codex-subscription-2026-07-29",
|
|
269
|
+
actionHref: "/admin/openai-subscription",
|
|
270
|
+
generation: 0
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
state: String(row.state),
|
|
275
|
+
stateSince: String(row.stateSince),
|
|
276
|
+
credentialMode: String(row.mode),
|
|
277
|
+
...(row.ownerLabel ? { ownerLabel: String(row.ownerLabel) } : {}),
|
|
278
|
+
...(row.accountId ? { accountId: String(row.accountId) } : {}),
|
|
279
|
+
...(row.workspaceId ? { workspaceId: String(row.workspaceId) } : {}),
|
|
280
|
+
...(row.plan ? { plan: String(row.plan) } : {}),
|
|
281
|
+
...(row.retryAt ? { retryAt: String(row.retryAt) } : {}),
|
|
282
|
+
...(row.lastSuccessAt ? { lastSuccessAt: String(row.lastSuccessAt) } : {}),
|
|
283
|
+
compatibilityVersion: String(row.compatibilityVersion),
|
|
284
|
+
...(row.actionHref ? { actionHref: String(row.actionHref) } : {}),
|
|
285
|
+
generation: Number(row.generation)
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
async writeStatus(scope, status) {
|
|
289
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
290
|
+
const now = nowIso();
|
|
291
|
+
await this.control.run(`DELETE FROM ${q(openaiSubscriptionHealthTable)} WHERE "scopeKey" = ?`, [scopeKey]);
|
|
292
|
+
await this.control.run(`INSERT INTO ${q(openaiSubscriptionHealthTable)}
|
|
293
|
+
("id", "scopeKey", "mode", "state", "stateSince", "ownerLabel", "accountId", "workspaceId", "plan",
|
|
294
|
+
"retryAt", "lastSuccessAt", "compatibilityVersion", "actionHref", "generation", "updatedAt")
|
|
295
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
296
|
+
randomId("oai_health"), scopeKey, scope.mode, status.state, status.stateSince,
|
|
297
|
+
status.ownerLabel ?? null, status.accountId ?? null, status.workspaceId ?? null, status.plan ?? null,
|
|
298
|
+
status.retryAt ?? null, status.lastSuccessAt ?? null, status.compatibilityVersion, status.actionHref ?? null,
|
|
299
|
+
status.generation, now
|
|
300
|
+
]);
|
|
301
|
+
}
|
|
302
|
+
async openIncident(scope, generation, kind) {
|
|
303
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
304
|
+
const existing = await this.control.first(`SELECT "id" FROM ${q(openaiSubscriptionIncidentsTable)}
|
|
305
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "kind" = ? LIMIT 1`, [scopeKey, generation, kind]);
|
|
306
|
+
if (existing)
|
|
307
|
+
return { created: false, id: existing.id };
|
|
308
|
+
const id = randomId("oai_incident");
|
|
309
|
+
try {
|
|
310
|
+
await this.control.run(`INSERT INTO ${q(openaiSubscriptionIncidentsTable)}
|
|
311
|
+
("id", "scopeKey", "generation", "kind", "createdAt")
|
|
312
|
+
VALUES (?, ?, ?, ?, ?)`, [id, scopeKey, generation, kind, nowIso()]);
|
|
313
|
+
return { created: true, id };
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
const committed = await this.control.first(`SELECT "id" FROM ${q(openaiSubscriptionIncidentsTable)}
|
|
317
|
+
WHERE "scopeKey" = ? AND "generation" = ? AND "kind" = ? LIMIT 1`, [scopeKey, generation, kind]);
|
|
318
|
+
if (committed)
|
|
319
|
+
return { created: false, id: committed.id };
|
|
320
|
+
throw new Error("OpenAI subscription incident could not be recorded");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async markIncidentNotified(id) {
|
|
324
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionIncidentsTable)}
|
|
325
|
+
SET "notifiedAt" = COALESCE("notifiedAt", ?) WHERE "id" = ?`, [nowIso(), id]);
|
|
326
|
+
}
|
|
327
|
+
async resolveIncidents(scope) {
|
|
328
|
+
const scopeKey = await openAISubscriptionScopeKey(scope);
|
|
329
|
+
await this.control.run(`UPDATE ${q(openaiSubscriptionIncidentsTable)}
|
|
330
|
+
SET "resolvedAt" = COALESCE("resolvedAt", ?) WHERE "scopeKey" = ? AND "resolvedAt" IS NULL`, [nowIso(), scopeKey]);
|
|
331
|
+
}
|
|
332
|
+
refreshSingleFlight(scopeKey, revision, refresh) {
|
|
333
|
+
const key = `${scopeKey}:${revision}`;
|
|
334
|
+
const existing = this.#flights.get(key);
|
|
335
|
+
if (existing)
|
|
336
|
+
return existing;
|
|
337
|
+
const flight = refresh().finally(() => this.#flights.delete(key));
|
|
338
|
+
this.#flights.set(key, flight);
|
|
339
|
+
return flight;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AACtE,OAAO,EACL,iCAAiC,EACjC,iCAAiC,EACjC,0BAA0B,EAE3B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kCAAkC,EAClC,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,EAC/B,MAAM,oBAAoB,CAAC;AAiB5B,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nC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CACpB,UAAU,CAAC,CAAC,gCAAgC,CAAC;mEACgB,EAC7D,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CACf,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,KAAwC;QAC7D,MAAM,QAAQ,GAAG,MAAM,0BAA0B,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CACpB,UAAU,CAAC,CAAC,gCAAgC,CAAC;kGAC+C,EAC5F,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CACrB,CAAC;IACJ,CAAC;IAED,mBAAmB,CACjB,QAAgB,EAChB,QAAgB,EAChB,OAAgD;QAEhD,MAAM,GAAG,GAAG,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC;QAC9B,MAAM,MAAM,GAAG,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC/B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type RaybaseSystemTable } from "@raybase/core";
|
|
2
|
+
export declare const openaiSubscriptionCredentialsTable = "_openai_subscription_credentials";
|
|
3
|
+
export declare const openaiSubscriptionPendingTable = "_openai_subscription_pending";
|
|
4
|
+
export declare const openaiSubscriptionHealthTable = "_openai_subscription_health";
|
|
5
|
+
export declare const openaiSubscriptionIncidentsTable = "_openai_subscription_incidents";
|
|
6
|
+
export declare const openaiSubscriptionSystemTables: RaybaseSystemTable[];
|
|
7
|
+
//# sourceMappingURL=system-tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-tables.d.ts","sourceRoot":"","sources":["../src/system-tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErG,eAAO,MAAM,kCAAkC,qCAAqC,CAAC;AACrF,eAAO,MAAM,8BAA8B,iCAAiC,CAAC;AAC7E,eAAO,MAAM,6BAA6B,gCAAgC,CAAC;AAC3E,eAAO,MAAM,gCAAgC,mCAAmC,CAAC;AAEjF,eAAO,MAAM,8BAA8B,EAAE,kBAAkB,EAoD9D,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { integer, longText, raybaseSystemTable, text } from "@raybase/core";
|
|
2
|
+
export const openaiSubscriptionCredentialsTable = "_openai_subscription_credentials";
|
|
3
|
+
export const openaiSubscriptionPendingTable = "_openai_subscription_pending";
|
|
4
|
+
export const openaiSubscriptionHealthTable = "_openai_subscription_health";
|
|
5
|
+
export const openaiSubscriptionIncidentsTable = "_openai_subscription_incidents";
|
|
6
|
+
export const openaiSubscriptionSystemTables = [
|
|
7
|
+
raybaseSystemTable(openaiSubscriptionCredentialsTable, {
|
|
8
|
+
id: text({ required: true }),
|
|
9
|
+
scopeKey: text({ required: true, unique: true }),
|
|
10
|
+
mode: text({ required: true }),
|
|
11
|
+
envelopeJson: longText({ required: true }),
|
|
12
|
+
revision: integer({ required: true }),
|
|
13
|
+
generation: integer({ required: true }),
|
|
14
|
+
refreshLeaseOwner: text(),
|
|
15
|
+
refreshLeaseExpiresAt: text(),
|
|
16
|
+
createdAt: text({ required: true }),
|
|
17
|
+
updatedAt: text({ required: true })
|
|
18
|
+
}, { indexes: [{ columns: ["scopeKey"], unique: true }, ["mode", "updatedAt"]], operatorVisible: false }),
|
|
19
|
+
raybaseSystemTable(openaiSubscriptionPendingTable, {
|
|
20
|
+
id: text({ required: true }),
|
|
21
|
+
scopeKey: text({ required: true, unique: true }),
|
|
22
|
+
mode: text({ required: true }),
|
|
23
|
+
envelopeJson: longText({ required: true }),
|
|
24
|
+
generation: integer({ required: true }),
|
|
25
|
+
nextPollAt: text({ required: true }),
|
|
26
|
+
expiresAt: text({ required: true }),
|
|
27
|
+
pollLeaseOwner: text(),
|
|
28
|
+
pollLeaseExpiresAt: text(),
|
|
29
|
+
createdAt: text({ required: true }),
|
|
30
|
+
updatedAt: text({ required: true })
|
|
31
|
+
}, { indexes: [{ columns: ["scopeKey"], unique: true }, ["expiresAt"]], operatorVisible: false }),
|
|
32
|
+
raybaseSystemTable(openaiSubscriptionHealthTable, {
|
|
33
|
+
id: text({ required: true }),
|
|
34
|
+
scopeKey: text({ required: true, unique: true }),
|
|
35
|
+
mode: text({ required: true }),
|
|
36
|
+
state: text({ required: true }),
|
|
37
|
+
stateSince: text({ required: true }),
|
|
38
|
+
ownerLabel: text(),
|
|
39
|
+
accountId: text(),
|
|
40
|
+
workspaceId: text(),
|
|
41
|
+
plan: text(),
|
|
42
|
+
retryAt: text(),
|
|
43
|
+
lastSuccessAt: text(),
|
|
44
|
+
compatibilityVersion: text({ required: true }),
|
|
45
|
+
actionHref: text(),
|
|
46
|
+
generation: integer({ required: true }),
|
|
47
|
+
updatedAt: text({ required: true })
|
|
48
|
+
}, { indexes: [{ columns: ["scopeKey"], unique: true }, ["state", "updatedAt"]], operatorVisible: false }),
|
|
49
|
+
raybaseSystemTable(openaiSubscriptionIncidentsTable, {
|
|
50
|
+
id: text({ required: true }),
|
|
51
|
+
scopeKey: text({ required: true }),
|
|
52
|
+
generation: integer({ required: true }),
|
|
53
|
+
kind: text({ required: true }),
|
|
54
|
+
notifiedAt: text(),
|
|
55
|
+
resolvedAt: text(),
|
|
56
|
+
createdAt: text({ required: true })
|
|
57
|
+
}, { indexes: [{ columns: ["scopeKey", "generation", "kind"], unique: true }, ["resolvedAt"]], operatorVisible: false })
|
|
58
|
+
];
|
|
59
|
+
//# sourceM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,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;CACzH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CodexSubscriptionTransport, OpenAISubscriptionCodexRequestError, OpenAISubscriptionTransportHttpError, assertOpenAISubscriptionUrlForTesting, normalizeOrigin, parseResponsesSse, toResponsesRequest, type OpenAISubscriptionTransportOptions } from "./transport.js";
|
|
2
|
+
export { createOpenAISubscriptionModuleForTesting } from "./module.js";
|
|
3
|
+
export { createOpenAISubscriptionProviderFactoryForTesting } from "./provider.js";
|
|
4
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,mCAAmC,EACnC,oCAAoC,EACpC,qCAAqC,EACrC,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,kCAAkC,EACxC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,iDAAiD,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CodexSubscriptionTransport, OpenAISubscriptionCodexRequestError, OpenAISubscriptionTransportHttpError, assertOpenAISubscriptionUrlForTesting, normalizeOrigin, parseResponsesSse, toResponsesRequest } from "./transport.js";
|
|
2
|
+
export { createOpenAISubscriptionModuleForTesting } from "./module.js";
|
|
3
|
+
export { createOpenAISubscriptionProviderFactoryForTesting } from "./provider.js";
|
|
4
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,mCAAmC,EACnC,oCAAoC,EACpC,qCAAqC,EACrC,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wCAAwC,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,iDAAiD,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { RaybaseInferenceProviderError, type RaybaseChatRequest, type RaybaseChatResult, type RaybaseChatStreamEvent } from "@raybase/core";
|
|
2
|
+
import type { OpenAISubscriptionEnv, OpenAISubscriptionFetcher, OpenAISubscriptionModuleOptions, OpenAISubscriptionTokens } from "./types.js";
|
|
3
|
+
export type OpenAISubscriptionTransportOptions = {
|
|
4
|
+
/** @deprecated Test-only shared fetch injection. Prefer authFetch/codexFetch. */
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
authFetch?: OpenAISubscriptionFetcher["fetch"];
|
|
7
|
+
codexFetch?: OpenAISubscriptionFetcher["fetch"];
|
|
8
|
+
now?: () => Date;
|
|
9
|
+
requestTimeoutMs?: number;
|
|
10
|
+
endpoints?: {
|
|
11
|
+
authOrigin?: string;
|
|
12
|
+
codexOrigin?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type DeviceStartResult = {
|
|
16
|
+
deviceAuthId: string;
|
|
17
|
+
userCode: string;
|
|
18
|
+
verificationUrl: string;
|
|
19
|
+
intervalSeconds: number;
|
|
20
|
+
expiresAt: string;
|
|
21
|
+
};
|
|
22
|
+
export type DevicePollResult = {
|
|
23
|
+
status: "pending";
|
|
24
|
+
intervalSeconds: number;
|
|
25
|
+
} | {
|
|
26
|
+
status: "authorized";
|
|
27
|
+
authorizationCode: string;
|
|
28
|
+
codeVerifier: string;
|
|
29
|
+
codeChallenge: string;
|
|
30
|
+
};
|
|
31
|
+
export declare class OpenAISubscriptionTransportHttpError extends Error {
|
|
32
|
+
readonly status: number;
|
|
33
|
+
readonly code: string;
|
|
34
|
+
readonly retryAt?: string | undefined;
|
|
35
|
+
readonly contentType?: string | undefined;
|
|
36
|
+
readonly cfRay?: string | undefined;
|
|
37
|
+
readonly oaiRequestId?: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* The upstream `error.param` when it names a structural part of the request
|
|
40
|
+
* the app itself controls — `tools[7].parameters.draft`. It is the app's own
|
|
41
|
+
* schema path, never user or account data, and it is the difference between
|
|
42
|
+
* "one of your tools is wrong" and knowing which one.
|
|
43
|
+
*/
|
|
44
|
+
readonly param?: string | undefined;
|
|
45
|
+
constructor(status: number, code: string, retryAt?: string | undefined, contentType?: string | undefined, cfRay?: string | undefined, oaiRequestId?: string | undefined,
|
|
46
|
+
/**
|
|
47
|
+
* The upstream `error.param` when it names a structural part of the request
|
|
48
|
+
* the app itself controls — `tools[7].parameters.draft`. It is the app's own
|
|
49
|
+
* schema path, never user or account data, and it is the difference between
|
|
50
|
+
* "one of your tools is wrong" and knowing which one.
|
|
51
|
+
*/
|
|
52
|
+
param?: string | undefined);
|
|
53
|
+
}
|
|
54
|
+
export declare class OpenAISubscriptionCodexRequestError extends RaybaseInferenceProviderError {
|
|
55
|
+
readonly status = 400;
|
|
56
|
+
readonly contentType?: string;
|
|
57
|
+
readonly oaiRequestId?: string;
|
|
58
|
+
constructor(token: string, metadata?: {
|
|
59
|
+
contentType?: string;
|
|
60
|
+
oaiRequestId?: string;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export declare class OpenAISubscriptionTransportProtocolError extends RaybaseInferenceProviderError {
|
|
64
|
+
readonly status?: number;
|
|
65
|
+
readonly contentType?: string;
|
|
66
|
+
readonly cfRayPresent?: boolean;
|
|
67
|
+
readonly redirected?: boolean;
|
|
68
|
+
readonly oaiRequestId?: string;
|
|
69
|
+
constructor(fingerprint: string, metadata?: {
|
|
70
|
+
status?: number;
|
|
71
|
+
contentType?: string;
|
|
72
|
+
cfRayPresent?: boolean;
|
|
73
|
+
redirected?: boolean;
|
|
74
|
+
oaiRequestId?: string;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export declare class CodexSubscriptionTransport {
|
|
78
|
+
#private;
|
|
79
|
+
constructor(options?: OpenAISubscriptionTransportOptions);
|
|
80
|
+
startDeviceAuth(signal?: AbortSignal): Promise<DeviceStartResult>;
|
|
81
|
+
pollDeviceAuth(deviceAuthId: string, userCode: string, intervalSeconds: number, signal?: AbortSignal): Promise<DevicePollResult>;
|
|
82
|
+
exchangeDeviceCode(result: Extract<DevicePollResult, {
|
|
83
|
+
status: "authorized";
|
|
84
|
+
}>, signal?: AbortSignal): Promise<OpenAISubscriptionTokens>;
|
|
85
|
+
refresh(refreshToken: string, signal?: AbortSignal): Promise<OpenAISubscriptionTokens>;
|
|
86
|
+
chat(tokens: OpenAISubscriptionTokens, input: RaybaseChatRequest, signal?: AbortSignal): Promise<RaybaseChatResult>;
|
|
87
|
+
chatStream(tokens: OpenAISubscriptionTokens, input: RaybaseChatRequest, signal?: AbortSignal): Promise<AsyncIterable<RaybaseChatStreamEvent>>;
|
|
88
|
+
}
|
|
89
|
+
export declare function createOpenAISubscriptionTransport<Env extends OpenAISubscriptionEnv>(options: Pick<OpenAISubscriptionModuleOptions, "codexEgress">, env: Env): CodexSubscriptionTransport;
|
|
90
|
+
export declare function createOpenAISubscriptionTransportInternal<Env extends OpenAISubscriptionEnv>(options: Pick<OpenAISubscriptionModuleOptions, "codexEgress">, env: Env, testingOptions?: OpenAISubscriptionTransportOptions): CodexSubscriptionTransport;
|
|
91
|
+
/**
|
|
92
|
+
* Drops rather than throws: an unexpected header is a module-side mistake that
|
|
93
|
+
* tests catch, and a live subscription lane should not fail closed over one.
|
|
94
|
+
* Any header the module genuinely needs must be added to the allowlist above.
|
|
95
|
+
*/
|
|
96
|
+
export declare function allowlistedOutboundHeaders(source: Record<string, string>): Record<string, string>;
|
|
97
|
+
export declare function toResponsesRequest(input: RaybaseChatRequest): Record<string, unknown>;
|
|
98
|
+
export declare function parseResponsesSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal, cleanup?: () => void): AsyncIterable<RaybaseChatStreamEvent>;
|
|
99
|
+
export declare function normalizeOrigin(value: string, label?: string): string;
|
|
100
|
+
export declare function assertOpenAISubscriptionUrlForTesting(value: string, origins?: {
|
|
101
|
+
authOrigin?: string;
|
|
102
|
+
codexOrigin?: string;
|
|
103
|
+
}, method?: string): "auth" | "codex";
|
|
104
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAE7B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAE5B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,qBAAqB,EACrB,yBAAyB,EACzB,+BAA+B,EAC/B,wBAAwB,EACzB,MAAM,YAAY,CAAC;AA0CpB,MAAM,MAAM,kCAAkC,GAAG;IAC/C,iFAAiF;IACjF,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,SAAS,CAAC,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAC/C,UAAU,CAAC,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAChD,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE;QACV,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAA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