@raybase/openai-subscription 0.0.2 → 0.1.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.
- 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/provider.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { createNotificationsRuntime, recordAudit, RaybaseInferenceProviderError } from "@raybase/core";
|
|
2
|
+
import { openAISubscriptionScopeKey } from "./crypto.js";
|
|
3
|
+
import { transitionOpenAISubscriptionHealth } from "./health.js";
|
|
4
|
+
import { OpenAISubscriptionCredentialStore } from "./store.js";
|
|
5
|
+
import { createOpenAISubscriptionTransportInternal, OpenAISubscriptionTransportHttpError } from "./transport.js";
|
|
6
|
+
import { openaiSubscriptionProviderId } from "./types.js";
|
|
7
|
+
const expirySkewMs = 60_000;
|
|
8
|
+
export function createOpenAISubscriptionProviderFactory(options) {
|
|
9
|
+
return createOpenAISubscriptionProviderFactoryInternal(options);
|
|
10
|
+
}
|
|
11
|
+
export function createOpenAISubscriptionProviderFactoryForTesting(options, transportOptions) {
|
|
12
|
+
return createOpenAISubscriptionProviderFactoryInternal(options, transportOptions);
|
|
13
|
+
}
|
|
14
|
+
export function createOpenAISubscriptionProviderFactoryInternal(options, transportOptions) {
|
|
15
|
+
return async (context) => {
|
|
16
|
+
const secret = context.env.RAYBASE_OPENAI_SUBSCRIPTION_KEY;
|
|
17
|
+
if (!secret) {
|
|
18
|
+
throw new RaybaseInferenceProviderError({
|
|
19
|
+
code: "encryption_key_missing",
|
|
20
|
+
health: "reauth_required",
|
|
21
|
+
actionHref: "/admin/openai-subscription"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const scope = resolveOpenAISubscriptionCredentialScope(options, context);
|
|
25
|
+
const store = new OpenAISubscriptionCredentialStore(context.control, secret);
|
|
26
|
+
const transport = createOpenAISubscriptionTransportInternal(options, context.env, transportOptions);
|
|
27
|
+
return createProvider({
|
|
28
|
+
scope,
|
|
29
|
+
store,
|
|
30
|
+
transport,
|
|
31
|
+
onIncident: async (state, generation, incidentId) => {
|
|
32
|
+
const actionHref = "/admin/openai-subscription";
|
|
33
|
+
await recordAudit(context.control, {
|
|
34
|
+
actor: context.principal,
|
|
35
|
+
action: `openai-subscription.${state}`,
|
|
36
|
+
target: { type: "openai_subscription_connection", id: scope.mode },
|
|
37
|
+
metadata: { state, credentialMode: scope.mode, generation, actionHref },
|
|
38
|
+
source: {
|
|
39
|
+
surface: context.surface,
|
|
40
|
+
requestId: context.requestId,
|
|
41
|
+
moduleId: "openai-subscription",
|
|
42
|
+
organizationId: scope.organizationId
|
|
43
|
+
}
|
|
44
|
+
}).catch(() => undefined);
|
|
45
|
+
const currentUser = context.principal.kind === "user" ? context.principal.user : undefined;
|
|
46
|
+
const notifications = createNotificationsRuntime({
|
|
47
|
+
env: context.env,
|
|
48
|
+
config: context.config,
|
|
49
|
+
notifications: { feed: { enabled: true } },
|
|
50
|
+
db: context.control,
|
|
51
|
+
currentUser,
|
|
52
|
+
actor: { kind: "service", id: "openai-subscription" },
|
|
53
|
+
source: { type: "openai_subscription_incident", id: incidentId }
|
|
54
|
+
});
|
|
55
|
+
await notifications.send({
|
|
56
|
+
to: scope.mode === "user" ? [{ kind: "current-user" }] : [{ kind: "operator" }],
|
|
57
|
+
title: state === "reauth_required"
|
|
58
|
+
? "Reconnect OpenAI subscription"
|
|
59
|
+
: "Update OpenAI subscription module",
|
|
60
|
+
body: state === "reauth_required"
|
|
61
|
+
? "The selected subscription credential needs to be reconnected."
|
|
62
|
+
: "The pinned Codex compatibility protocol changed. Install a reviewed module update.",
|
|
63
|
+
kind: `openai-subscription.${state}`,
|
|
64
|
+
severity: "warning",
|
|
65
|
+
target: { href: actionHref },
|
|
66
|
+
channels: ["feed"],
|
|
67
|
+
dedupeKey: `openai-subscription:${incidentId}`,
|
|
68
|
+
metadata: { state, credentialMode: scope.mode, generation }
|
|
69
|
+
}).then(() => store.markIncidentNotified(incidentId)).catch(() => undefined);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function resolveOpenAISubscriptionCredentialScope(options, context) {
|
|
75
|
+
const applicationScope = options.applicationScope?.trim() || context.config.appName;
|
|
76
|
+
const organizationId = context.organizationId ?? context.principal.organizationId ?? null;
|
|
77
|
+
const background = context.surface === "job" || context.surface === "scheduled" || context.surface === "maintenance";
|
|
78
|
+
if (background && options.background.strategy === "disabled") {
|
|
79
|
+
throw new RaybaseInferenceProviderError({ code: "background_credentials_disabled", health: "disconnected" });
|
|
80
|
+
}
|
|
81
|
+
if (options.credentialMode === "operator") {
|
|
82
|
+
if (background && options.background.strategy !== "run-as-operator") {
|
|
83
|
+
throw new RaybaseInferenceProviderError({ code: "background_scope_mismatch", health: "disconnected" });
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
applicationScope,
|
|
87
|
+
organizationId,
|
|
88
|
+
mode: "operator",
|
|
89
|
+
subjectId: options.operatorSubjectId
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (options.credentialMode === "organization") {
|
|
93
|
+
if (!organizationId)
|
|
94
|
+
throw new RaybaseInferenceProviderError({ code: "organization_scope_missing", health: "disconnected" });
|
|
95
|
+
if (background && options.background.strategy !== "organization") {
|
|
96
|
+
throw new RaybaseInferenceProviderError({ code: "background_scope_mismatch", health: "disconnected" });
|
|
97
|
+
}
|
|
98
|
+
return { applicationScope, organizationId, mode: "organization", subjectId: null };
|
|
99
|
+
}
|
|
100
|
+
if (context.principal.kind !== "user") {
|
|
101
|
+
throw new RaybaseInferenceProviderError({ code: "user_scope_missing", health: "disconnected" });
|
|
102
|
+
}
|
|
103
|
+
if (background && options.background.strategy !== "run-as-user") {
|
|
104
|
+
throw new RaybaseInferenceProviderError({ code: "background_scope_mismatch", health: "disconnected" });
|
|
105
|
+
}
|
|
106
|
+
const subjectId = context.principal.membershipId
|
|
107
|
+
?? context.principal.user.membershipId
|
|
108
|
+
?? context.principal.user.id;
|
|
109
|
+
if (!subjectId)
|
|
110
|
+
throw new RaybaseInferenceProviderError({ code: "user_scope_missing", health: "disconnected" });
|
|
111
|
+
return { applicationScope, organizationId, mode: "user", subjectId };
|
|
112
|
+
}
|
|
113
|
+
function createProvider(input) {
|
|
114
|
+
const load = async (signal) => {
|
|
115
|
+
const credential = await input.store.read(input.scope);
|
|
116
|
+
if (!credential) {
|
|
117
|
+
throw new RaybaseInferenceProviderError({
|
|
118
|
+
code: "credential_missing",
|
|
119
|
+
health: "reauth_required",
|
|
120
|
+
actionHref: "/admin/openai-subscription"
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (new Date(credential.tokens.expiresAt).getTime() - Date.now() <= expirySkewMs) {
|
|
124
|
+
await refresh(credential.tokens, credential.revision, credential.generation, signal);
|
|
125
|
+
const refreshed = await input.store.read(input.scope);
|
|
126
|
+
if (!refreshed) {
|
|
127
|
+
throw new RaybaseInferenceProviderError({
|
|
128
|
+
code: "credential_missing",
|
|
129
|
+
health: "reauth_required",
|
|
130
|
+
actionHref: "/admin/openai-subscription"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return refreshed;
|
|
134
|
+
}
|
|
135
|
+
return credential;
|
|
136
|
+
};
|
|
137
|
+
const refresh = async (current, revision, generation, signal) => {
|
|
138
|
+
throwIfAborted(signal);
|
|
139
|
+
const scopeKey = await openAISubscriptionScopeKey(input.scope);
|
|
140
|
+
const sharedRefresh = input.store.refreshSingleFlight(scopeKey, revision, async () => {
|
|
141
|
+
const leaseOwner = `refresh_${crypto.randomUUID()}`;
|
|
142
|
+
const acquired = await input.store.acquireRefreshLease(input.scope, revision, leaseOwner);
|
|
143
|
+
if (!acquired) {
|
|
144
|
+
const updated = await input.store.waitForRevisionChange(input.scope, revision);
|
|
145
|
+
if (!updated) {
|
|
146
|
+
throw new RaybaseInferenceProviderError({
|
|
147
|
+
code: "credential_missing",
|
|
148
|
+
health: "reauth_required",
|
|
149
|
+
actionHref: "/admin/openai-subscription"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (updated.revision === revision) {
|
|
153
|
+
throw new RaybaseInferenceProviderError({
|
|
154
|
+
code: "refresh_in_progress",
|
|
155
|
+
health: "rate_limited",
|
|
156
|
+
retryAt: new Date(Date.now() + 1_000).toISOString(),
|
|
157
|
+
actionHref: "/admin/openai-subscription"
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return updated.tokens;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const rotated = await input.transport.refresh(current.refreshToken);
|
|
164
|
+
// The transport builds its result from the refresh answer alone, and
|
|
165
|
+
// the answer is allowed to say less than the connection knows: no
|
|
166
|
+
// rotated refresh_token means "keep yours", and no id_token means the
|
|
167
|
+
// identity projection (accountId, workspaceId, plan) comes back empty.
|
|
168
|
+
// Identity is established at connect and bound to the refresh-token
|
|
169
|
+
// lineage — a refresh cannot move the credential to another account,
|
|
170
|
+
// and a genuine identity change arrives as a reconnect under a new
|
|
171
|
+
// generation. So absence in the answer is omission, never removal:
|
|
172
|
+
// carry the held values forward, letting a fresh id_token's claims win
|
|
173
|
+
// (a plan can legitimately change mid-connection). Dropping them here
|
|
174
|
+
// is silent, delayed data loss — accountId rides every Codex request
|
|
175
|
+
// as the chatgpt-account-id header, and the next call after the wipe
|
|
176
|
+
// fails upstream far from the refresh that caused it.
|
|
177
|
+
const next = {
|
|
178
|
+
...rotated,
|
|
179
|
+
refreshToken: rotated.refreshToken || current.refreshToken,
|
|
180
|
+
...(rotated.accountId ?? current.accountId
|
|
181
|
+
? { accountId: rotated.accountId ?? current.accountId }
|
|
182
|
+
: {}),
|
|
183
|
+
...(rotated.workspaceId ?? current.workspaceId
|
|
184
|
+
? { workspaceId: rotated.workspaceId ?? current.workspaceId }
|
|
185
|
+
: {}),
|
|
186
|
+
...(rotated.plan ?? current.plan ? { plan: rotated.plan ?? current.plan } : {})
|
|
187
|
+
};
|
|
188
|
+
await input.store.write(input.scope, next, { expectedRevision: revision, generation });
|
|
189
|
+
return next;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (error instanceof OpenAISubscriptionTransportHttpError && error.code === "invalid_grant") {
|
|
193
|
+
await transitionOpenAISubscriptionHealth(input, "reauth_required", generation);
|
|
194
|
+
throw new RaybaseInferenceProviderError({
|
|
195
|
+
code: "invalid_grant",
|
|
196
|
+
health: "reauth_required",
|
|
197
|
+
actionHref: "/admin/openai-subscription"
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
throw await mapTransportError(error, generation, input);
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
await input.store.releaseRefreshLease(input.scope, revision, leaseOwner);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
// Refreshes are shared by credential revision. A caller may stop waiting
|
|
207
|
+
// without cancelling work that another invocation already depends on.
|
|
208
|
+
return awaitWithCallerAbort(sharedRefresh, signal);
|
|
209
|
+
};
|
|
210
|
+
const withAuthRetry = async (run, signal) => {
|
|
211
|
+
const credential = await load(signal);
|
|
212
|
+
try {
|
|
213
|
+
return await run(credential.tokens);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (!(error instanceof OpenAISubscriptionTransportHttpError) || error.status !== 401) {
|
|
217
|
+
throw await mapTransportError(error, credential.generation, input);
|
|
218
|
+
}
|
|
219
|
+
const rotated = await refresh(credential.tokens, credential.revision, credential.generation, signal);
|
|
220
|
+
try {
|
|
221
|
+
return await run(rotated);
|
|
222
|
+
}
|
|
223
|
+
catch (retryError) {
|
|
224
|
+
if (retryError instanceof OpenAISubscriptionTransportHttpError && retryError.status === 401) {
|
|
225
|
+
await transitionOpenAISubscriptionHealth(input, "reauth_required", credential.generation);
|
|
226
|
+
throw new RaybaseInferenceProviderError({
|
|
227
|
+
code: "unauthorized_after_refresh",
|
|
228
|
+
health: "reauth_required",
|
|
229
|
+
actionHref: "/admin/openai-subscription"
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
throw await mapTransportError(retryError, credential.generation, input);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
return {
|
|
237
|
+
id: openaiSubscriptionProviderId,
|
|
238
|
+
async chat(request, context) {
|
|
239
|
+
const result = await withAuthRetry((tokens) => input.transport.chat(tokens, request, context.signal), context.signal);
|
|
240
|
+
const credential = await input.store.read(input.scope);
|
|
241
|
+
await transitionOpenAISubscriptionHealth(input, "connected", credential?.generation ?? 0, {
|
|
242
|
+
lastSuccessAt: new Date().toISOString(),
|
|
243
|
+
accountId: credential?.tokens.accountId,
|
|
244
|
+
workspaceId: credential?.tokens.workspaceId,
|
|
245
|
+
plan: credential?.tokens.plan
|
|
246
|
+
});
|
|
247
|
+
return { ...result, provider: { ...result.provider, id: openaiSubscriptionProviderId } };
|
|
248
|
+
},
|
|
249
|
+
async chatStream(request, context) {
|
|
250
|
+
const source = await withAuthRetry((tokens) => input.transport.chatStream(tokens, request, context.signal), context.signal);
|
|
251
|
+
return streamWithHealth(source, input);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function abortedProviderError() {
|
|
256
|
+
return new RaybaseInferenceProviderError({
|
|
257
|
+
code: "aborted",
|
|
258
|
+
message: "OpenAI subscription request was cancelled."
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function throwIfAborted(signal) {
|
|
262
|
+
if (signal?.aborted)
|
|
263
|
+
throw abortedProviderError();
|
|
264
|
+
}
|
|
265
|
+
async function awaitWithCallerAbort(operation, signal) {
|
|
266
|
+
if (!signal)
|
|
267
|
+
return operation;
|
|
268
|
+
throwIfAborted(signal);
|
|
269
|
+
let onAbort;
|
|
270
|
+
const aborted = new Promise((_resolve, reject) => {
|
|
271
|
+
onAbort = () => reject(abortedProviderError());
|
|
272
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
273
|
+
});
|
|
274
|
+
try {
|
|
275
|
+
return await Promise.race([operation, aborted]);
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
if (onAbort)
|
|
279
|
+
signal.removeEventListener("abort", onAbort);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async function* streamWithHealth(source, input) {
|
|
283
|
+
let emitted = false;
|
|
284
|
+
try {
|
|
285
|
+
for await (const event of source) {
|
|
286
|
+
if (event.type === "text-delta" || event.type === "tool-call")
|
|
287
|
+
emitted = true;
|
|
288
|
+
yield event;
|
|
289
|
+
}
|
|
290
|
+
const credential = await input.store.read(input.scope);
|
|
291
|
+
await transitionOpenAISubscriptionHealth(input, "connected", credential?.generation ?? 0, {
|
|
292
|
+
lastSuccessAt: new Date().toISOString(),
|
|
293
|
+
accountId: credential?.tokens.accountId,
|
|
294
|
+
workspaceId: credential?.tokens.workspaceId,
|
|
295
|
+
plan: credential?.tokens.plan
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
const credential = await input.store.read(input.scope);
|
|
300
|
+
const mapped = await mapTransportError(error, credential?.generation ?? 0, input);
|
|
301
|
+
if (emitted && mapped instanceof RaybaseInferenceProviderError) {
|
|
302
|
+
throw new RaybaseInferenceProviderError({
|
|
303
|
+
code: mapped.code,
|
|
304
|
+
health: mapped.health,
|
|
305
|
+
retryAt: mapped.retryAt,
|
|
306
|
+
actionHref: mapped.actionHref,
|
|
307
|
+
message: "The OpenAI subscription stream ended safely after partial output."
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
throw mapped;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
async function mapTransportError(error, generation, input) {
|
|
314
|
+
if (error instanceof OpenAISubscriptionTransportHttpError && error.status === 429) {
|
|
315
|
+
await transitionOpenAISubscriptionHealth(input, "rate_limited", generation, { retryAt: error.retryAt });
|
|
316
|
+
return new RaybaseInferenceProviderError({
|
|
317
|
+
code: "rate_limited",
|
|
318
|
+
health: "rate_limited",
|
|
319
|
+
retryAt: error.retryAt,
|
|
320
|
+
actionHref: "/admin/openai-subscription"
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (error instanceof OpenAISubscriptionTransportHttpError && error.code === "egress_forbidden") {
|
|
324
|
+
await transitionOpenAISubscriptionHealth(input, "disconnected", generation);
|
|
325
|
+
return new RaybaseInferenceProviderError({
|
|
326
|
+
code: "codex_egress_forbidden",
|
|
327
|
+
health: "disconnected",
|
|
328
|
+
actionHref: "/admin/openai-subscription",
|
|
329
|
+
message: "Cloudflare's front door blocked this request before it reached the Codex API, so the credential is not the problem. This is the Codex egress path: check that no Cloudflare hop headers (cf-worker, cf-connecting-ip, cf-visitor) are reaching chatgpt.com."
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (error instanceof OpenAISubscriptionTransportHttpError && error.code === "account_forbidden") {
|
|
333
|
+
await transitionOpenAISubscriptionHealth(input, "reauth_required", generation);
|
|
334
|
+
return new RaybaseInferenceProviderError({
|
|
335
|
+
code: "codex_account_forbidden",
|
|
336
|
+
health: "reauth_required",
|
|
337
|
+
actionHref: "/admin/openai-subscription",
|
|
338
|
+
message: "The Codex API refused this account. Reconnect the subscription, or check that the linked plan still covers Codex."
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (error instanceof OpenAISubscriptionTransportHttpError && error.code === "invalid_function_parameters") {
|
|
342
|
+
// Name the tool. The API tells us exactly which one, as a path into the
|
|
343
|
+
// request the app itself built (`tools[7].parameters.draft`), and a
|
|
344
|
+
// developer who is told only "one of them" has to bisect sixteen schemas by
|
|
345
|
+
// hand. The path holds no user or account data.
|
|
346
|
+
return new RaybaseInferenceProviderError({
|
|
347
|
+
code: "invalid_function_parameters",
|
|
348
|
+
message: error.param
|
|
349
|
+
? `The AI tool at ${error.param} is not a valid strict JSON Schema, so the provider refused the whole request and named no tool. Every object must set additionalProperties:false, list every property in required (optional ones as a null union), and drop validation keywords the strict subset does not support.`
|
|
350
|
+
: "One of the app's AI tools has an invalid strict JSON Schema."
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
if (error instanceof RaybaseInferenceProviderError && error.health === "protocol_update_required") {
|
|
354
|
+
await transitionOpenAISubscriptionHealth(input, "protocol_update_required", generation);
|
|
355
|
+
return error;
|
|
356
|
+
}
|
|
357
|
+
if (error instanceof RaybaseInferenceProviderError)
|
|
358
|
+
return error;
|
|
359
|
+
return new RaybaseInferenceProviderError({ code: "transport_error" });
|
|
360
|
+
}
|
|
361
|
+
//# sourceMappingURL=provider.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ISubscriptionPendingDevice, OpenAISubscriptionSafeStatus, OpenAISubscriptionTokens } from "./types.js";
|
|
3
|
+
export declare class OpenAISubscriptionCredentialStore {
|
|
4
|
+
#private;
|
|
5
|
+
private readonly control;
|
|
6
|
+
private readonly secret;
|
|
7
|
+
constructor(control: SqlExecutor, secret: string);
|
|
8
|
+
read(scope: OpenAISubscriptionCredentialScope): Promise<{
|
|
9
|
+
tokens: OpenAISubscriptionTokens;
|
|
10
|
+
revision: number;
|
|
11
|
+
generation: number;
|
|
12
|
+
} | null>;
|
|
13
|
+
write(scope: OpenAISubscriptionCredentialScope, tokens: OpenAISubscriptionTokens, options?: {
|
|
14
|
+
expectedRevision?: number;
|
|
15
|
+
generation?: number;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
revision: number;
|
|
18
|
+
generation: number;
|
|
19
|
+
}>;
|
|
20
|
+
acquireRefreshLease(scope: OpenAISubscriptionCredentialScope, revision: number, owner: string, leaseMs?: number): Promise<boolean>;
|
|
21
|
+
releaseRefreshLease(scope: OpenAISubscriptionCredentialScope, revision: number, owner: string): Promise<void>;
|
|
22
|
+
waitForRevisionChange(scope: OpenAISubscriptionCredentialScope, revision: number, options?: {
|
|
23
|
+
attempts?: number;
|
|
24
|
+
intervalMs?: number;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
tokens: OpenAISubscriptionTokens;
|
|
27
|
+
revision: number;
|
|
28
|
+
generation: number;
|
|
29
|
+
} | null>;
|
|
30
|
+
disconnect(scope: OpenAISubscriptionCredentialScope): Promise<number>;
|
|
31
|
+
writePending(scope: OpenAISubscriptionCredentialScope, pending: OpenAISubscriptionPendingDevice): Promise<void>;
|
|
32
|
+
commitPendingPoll(scope: OpenAISubscriptionCredentialScope, pending: OpenAISubscriptionPendingDevice, leaseOwner: string): Promise<boolean>;
|
|
33
|
+
commitPendingAuthorization(scope: OpenAISubscriptionCredentialScope, pending: OpenAISubscriptionPendingDevice, leaseOwner: string, tokens: OpenAISubscriptionTokens): Promise<boolean>;
|
|
34
|
+
readPending(scope: OpenAISubscriptionCredentialScope): Promise<OpenAISubscriptionPendingDevice | null>;
|
|
35
|
+
deletePending(scope: OpenAISubscriptionCredentialScope, expected?: {
|
|
36
|
+
generation?: number;
|
|
37
|
+
leaseOwner?: string;
|
|
38
|
+
}): Promise<void>;
|
|
39
|
+
acquirePendingPollLease(scope: OpenAISubscriptionCredentialScope, generation: number, owner: string, leaseMs?: number): Promise<boolean>;
|
|
40
|
+
releasePendingPollLease(scope: OpenAISubscriptionCredentialScope, generation: number, owner: string): Promise<void>;
|
|
41
|
+
status(scope: OpenAISubscriptionCredentialScope): Promise<OpenAISubscriptionSafeStatus>;
|
|
42
|
+
writeStatus(scope: OpenAISubscriptionCredentialScope, status: OpenAISubscriptionSafeStatus): Promise<void>;
|
|
43
|
+
openIncident(scope: OpenAISubscriptionCredentialScope, generation: number, kind: "reauth_required" | "protocol_update_required"): Promise<{
|
|
44
|
+
created: boolean;
|
|
45
|
+
id: string;
|
|
46
|
+
}>;
|
|
47
|
+
markIncidentNotified(id: string): Promise<void>;
|
|
48
|
+
resolveIncidents(scope: OpenAISubscriptionCredentialScope): Promise<void>;
|
|
49
|
+
refreshSingleFlight(scopeKey: string, revision: number, refresh: () => Promise<OpenAISubscriptionTokens>): Promise<OpenAISubscriptionTokens>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAatE,OAAO,KAAK,EACV,iCAAiC,EACjC,+BAA+B,EAC/B,4BAA4B,EAC5B,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAWpB,qBAAa,iCAAiC;;IAI1C,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,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