@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/crypto.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const encoder = new TextEncoder();
|
|
2
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
3
|
+
export function validateOpenAISubscriptionSecret(secret) {
|
|
4
|
+
if (!secret?.trim())
|
|
5
|
+
throw new Error("RAYBASE_OPENAI_SUBSCRIPTION_KEY is not configured");
|
|
6
|
+
const normalized = secret.trim().replace(/-/g, "+").replace(/_/g, "/");
|
|
7
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(normalized)) {
|
|
8
|
+
throw new Error("RAYBASE_OPENAI_SUBSCRIPTION_KEY must be base64 or base64url encoded");
|
|
9
|
+
}
|
|
10
|
+
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
|
|
11
|
+
let bytes;
|
|
12
|
+
try {
|
|
13
|
+
bytes = Uint8Array.from(atob(padded), (value) => value.charCodeAt(0));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new Error("RAYBASE_OPENAI_SUBSCRIPTION_KEY is not valid base64");
|
|
17
|
+
}
|
|
18
|
+
if (bytes.byteLength < 32)
|
|
19
|
+
throw new Error("RAYBASE_OPENAI_SUBSCRIPTION_KEY must contain at least 256 bits of random key material");
|
|
20
|
+
if (new Set(bytes).size < 16)
|
|
21
|
+
throw new Error("RAYBASE_OPENAI_SUBSCRIPTION_KEY does not contain enough entropy");
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
24
|
+
export async function encryptOpenAISubscriptionEnvelope(secret, scope, value) {
|
|
25
|
+
const key = await deriveKey(validateOpenAISubscriptionSecret(secret));
|
|
26
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
27
|
+
const ciphertext = await crypto.subtle.encrypt({ name: "AES-GCM", iv: bufferSource(nonce), additionalData: bufferSource(aad(scope)) }, key, bufferSource(encoder.encode(JSON.stringify(value))));
|
|
28
|
+
return {
|
|
29
|
+
version: 1,
|
|
30
|
+
keyVersion: 1,
|
|
31
|
+
nonce: base64Url(nonce),
|
|
32
|
+
ciphertext: base64Url(new Uint8Array(ciphertext))
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export async function decryptOpenAISubscriptionEnvelope(secret, scope, envelope) {
|
|
36
|
+
if (envelope.version !== 1 || envelope.keyVersion !== 1)
|
|
37
|
+
throw new Error("Unsupported OpenAI subscription credential envelope version");
|
|
38
|
+
try {
|
|
39
|
+
const plaintext = await crypto.subtle.decrypt({
|
|
40
|
+
name: "AES-GCM",
|
|
41
|
+
iv: bufferSource(fromBase64Url(envelope.nonce)),
|
|
42
|
+
additionalData: bufferSource(aad(scope))
|
|
43
|
+
}, await deriveKey(validateOpenAISubscriptionSecret(secret)), bufferSource(fromBase64Url(envelope.ciphertext)));
|
|
44
|
+
return JSON.parse(decoder.decode(plaintext));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error("OpenAI subscription credential could not be decrypted for this scope");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function openAISubscriptionScopeKey(scope) {
|
|
51
|
+
const digest = await crypto.subtle.digest("SHA-256", bufferSource(aad(scope)));
|
|
52
|
+
return base64Url(new Uint8Array(digest));
|
|
53
|
+
}
|
|
54
|
+
function aad(scope) {
|
|
55
|
+
return encoder.encode(JSON.stringify({
|
|
56
|
+
moduleId: "openai-subscription",
|
|
57
|
+
applicationScope: scope.applicationScope,
|
|
58
|
+
organizationId: scope.organizationId,
|
|
59
|
+
credentialMode: scope.mode,
|
|
60
|
+
subjectId: scope.subjectId,
|
|
61
|
+
envelopeVersion: 1
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
async function deriveKey(secret) {
|
|
65
|
+
const source = await crypto.subtle.importKey("raw", bufferSource(secret), "HKDF", false, ["deriveKey"]);
|
|
66
|
+
return crypto.subtle.deriveKey({
|
|
67
|
+
name: "HKDF",
|
|
68
|
+
hash: "SHA-256",
|
|
69
|
+
salt: bufferSource(encoder.encode("raybase/openai-subscription/aes-256-gcm/v1")),
|
|
70
|
+
info: bufferSource(encoder.encode("credential-envelope"))
|
|
71
|
+
}, source, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
72
|
+
}
|
|
73
|
+
function base64Url(bytes) {
|
|
74
|
+
let binary = "";
|
|
75
|
+
for (const byte of bytes)
|
|
76
|
+
binary += String.fromCharCode(byte);
|
|
77
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
78
|
+
}
|
|
79
|
+
function fromBase64Url(value) {
|
|
80
|
+
const base64 = value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=");
|
|
81
|
+
return Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
|
|
82
|
+
}
|
|
83
|
+
function bufferSource(bytes) {
|
|
84
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D,MAAM,UAAU,gCAAgC,CAAC,MAA0B;IACzE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAC1F,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACvE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,C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AI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IACxG,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,YAAY,CAAC,KAAiB;IACrC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAgB,CAAC;AAClG,CAAC"}
|
package/dist/health.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OpenAISubscriptionCredentialStore } from "./store.js";
|
|
2
|
+
import type { OpenAISubscriptionCredentialScope, OpenAISubscriptionHealth, OpenAISubscriptionSafeStatus } from "./types.js";
|
|
3
|
+
export type OpenAISubscriptionHealthTransitionContext = {
|
|
4
|
+
scope: OpenAISubscriptionCredentialScope;
|
|
5
|
+
store: OpenAISubscriptionCredentialStore;
|
|
6
|
+
onIncident?: (state: "reauth_required" | "protocol_update_required", generation: number, incidentId: string) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare function transitionOpenAISubscriptionHealth(input: OpenAISubscriptionHealthTransitionContext, state: OpenAISubscriptionHealth, generation: number, extra?: Partial<OpenAISubscriptionSafeStatus>): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EACV,iCAAiC,EACjC,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,yCAAyC,GAAG;IACtD,KAAK,EAAE,iCAAiC,CAAC;IACzC,KAAK,EAAE,iCAAiC,CAAC;IACzC,UAAU,CAAC,EAAE,CACX,KAAK,EAAE,iBAAiB,GAAG,0BAA0B,EACrD,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAsB,kCAAkC,CACtD,KAAK,EAAE,yCAAyC,EAChD,KAAK,EAAE,wBAAwB,EAC/B,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,OAAO,CAAC,4BAA4B,CAAM,GAChD,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
package/dist/health.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export async function transitionOpenAISubscriptionHealth(input, state, generation, extra = {}) {
|
|
2
|
+
const previous = await input.store.status(input.scope);
|
|
3
|
+
await input.store.writeStatus(input.scope, {
|
|
4
|
+
...previous,
|
|
5
|
+
...extra,
|
|
6
|
+
state,
|
|
7
|
+
stateSince: previous.state === state ? previous.stateSince : new Date().toISOString(),
|
|
8
|
+
credentialMode: input.scope.mode,
|
|
9
|
+
compatibilityVersion: "codex-subscription-2026-07-29",
|
|
10
|
+
actionHref: "/admin/openai-subscription",
|
|
11
|
+
generation
|
|
12
|
+
});
|
|
13
|
+
if (state === "connected") {
|
|
14
|
+
await input.store.resolveIncidents(input.scope);
|
|
15
|
+
}
|
|
16
|
+
else if (state === "reauth_required" || state === "protocol_update_required") {
|
|
17
|
+
const incident = await input.store.openIncident(input.scope, generation, state);
|
|
18
|
+
if (incident.created)
|
|
19
|
+
await input.onIncident?.(state, generation, incident.id);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,KAAgD,EAChD,KAA+B,EAC/B,UAAkB,EAClB,QAA+C,EAAE;IAEjD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE;QACzC,GAAG,QAAQ;QACX,GAAG,KAAK;QACR,KAAK;QACL,UAAU,EAAE,QAAQ,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACrF,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI;QAChC,oBAAoB,EAAE,+BAA+B;QACrD,UAAU,EAAE,4BAA4B;QACxC,UAAU;KACX,CAAC,CAAC;IACH,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QAC1B,MAAM,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;SAAM,IAAI,KAAK,KAAK,iBAAiB,IAAI,KAAK,KAAK,0BAA0B,EAAE,CAAC;QAC/E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAChF,IAAI,QAAQ,CAAC,OAAO;YAAE,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjF,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./crypto.js";
|
|
2
|
+
export { openaiSubscriptionModule } from "./module.js";
|
|
3
|
+
export { createOpenAISubscriptionProviderFactory, resolveOpenAISubscriptionCredentialScope } from "./provider.js";
|
|
4
|
+
export * from "./store.js";
|
|
5
|
+
export * from "./system-tables.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export { OpenAISubscriptionTransportHttpError, createOpenAISubscriptionTransport } from "./transport.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,uCAAuC,EACvC,wCAAwC,EACzC,MAAM,eAAe,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./crypto.js";
|
|
2
|
+
export { openaiSubscriptionModule } from "./module.js";
|
|
3
|
+
export { createOpenAISubscriptionProviderFactory, resolveOpenAISubscriptionCredentialScope } from "./provider.js";
|
|
4
|
+
export * from "./store.js";
|
|
5
|
+
export * from "./system-tables.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export { OpenAISubscriptionTransportHttpError, createOpenAISubscriptionTransport } from "./transport.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,uCAAuC,EACvC,wCAAwC,EACzC,MAAM,eAAe,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,gBAAgB,CAAC"}
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RaybaseModule } from "@raybase/core";
|
|
2
|
+
import { type OpenAISubscriptionTransportOptions } from "./transport.js";
|
|
3
|
+
import { type OpenAISubscriptionEnv, type OpenAISubscriptionModuleOptions } from "./types.js";
|
|
4
|
+
export declare function openaiSubscriptionModule<Env extends OpenAISubscriptionEnv>(options: OpenAISubscriptionModuleOptions): RaybaseModule<Env>;
|
|
5
|
+
export declare function createOpenAISubscriptionModuleForTesting<Env extends OpenAISubscriptionEnv>(options: OpenAISubscriptionModuleOptions, transport: OpenAISubscriptionTransportOptions): RaybaseModule<Env>;
|
|
6
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,aAAa,EAGnB,MAAM,eAAe,CAAC;AAQvB,OAAO,EAEL,KAAK,kCAAkC,EACxC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAKL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,YAAY,CAAC;AAEpB,wBAAgB,wBAAwB,CAAC,GAAG,SAAS,qBAAqB,EACxE,OAAO,EAAE,+BAA+B,GACvC,aAAa,CAAC,GAAG,CAAC,CAEpB;AAED,wBAAgB,wCAAwC,CAAC,GAAG,SAAS,qBAAqB,EACxF,OAAO,EAAE,+BAA+B,EACxC,SAAS,EAAE,kCAAkC,GAC5C,aAAa,CAAC,GAAG,CAAC,CAEpB"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { defineRaybaseModule, nowIso, RaybaseInferenceProviderError } from "@raybase/core";
|
|
2
|
+
import { createOpenAISubscriptionProviderFactoryInternal, resolveOpenAISubscriptionCredentialScope } from "./provider.js";
|
|
3
|
+
import { transitionOpenAISubscriptionHealth } from "./health.js";
|
|
4
|
+
import { OpenAISubscriptionCredentialStore } from "./store.js";
|
|
5
|
+
import { openaiSubscriptionSystemTables } from "./system-tables.js";
|
|
6
|
+
import { createOpenAISubscriptionTransportInternal } from "./transport.js";
|
|
7
|
+
import { openaiSubscriptionModuleId, openaiSubscriptionProviderId, validateOpenAISubscriptionOptions } from "./types.js";
|
|
8
|
+
export function openaiSubscriptionModule(options) {
|
|
9
|
+
return createModule(options);
|
|
10
|
+
}
|
|
11
|
+
export function createOpenAISubscriptionModuleForTesting(options, transport) {
|
|
12
|
+
return createModule(options, transport);
|
|
13
|
+
}
|
|
14
|
+
function createModule(options, transportOptions) {
|
|
15
|
+
validateOpenAISubscriptionOptions(options);
|
|
16
|
+
const providerFactory = createOpenAISubscriptionProviderFactoryInternal(options, transportOptions);
|
|
17
|
+
const routes = createOpenAISubscriptionRoutes(options, transportOptions);
|
|
18
|
+
const adminRoutes = options.credentialMode === "user" ? [] : routes;
|
|
19
|
+
const userRoutes = options.credentialMode === "user" ? routes : [];
|
|
20
|
+
return defineRaybaseModule({
|
|
21
|
+
id: openaiSubscriptionModuleId,
|
|
22
|
+
packageName: "@raybase/openai-subscription",
|
|
23
|
+
version: "0.1.0",
|
|
24
|
+
runtime: () => ({
|
|
25
|
+
systemTables: openaiSubscriptionSystemTables,
|
|
26
|
+
notifications: { feed: { enabled: true } },
|
|
27
|
+
inferenceProviders: {
|
|
28
|
+
[openaiSubscriptionProviderId]: {
|
|
29
|
+
id: openaiSubscriptionProviderId,
|
|
30
|
+
capabilities: { chat: true, stream: true, embed: false },
|
|
31
|
+
factory: providerFactory
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
routes: userRoutes,
|
|
35
|
+
adminRoutes,
|
|
36
|
+
manifest: {
|
|
37
|
+
id: openaiSubscriptionModuleId,
|
|
38
|
+
packageName: "@raybase/openai-subscription",
|
|
39
|
+
inferenceProviders: [{
|
|
40
|
+
id: openaiSubscriptionProviderId,
|
|
41
|
+
capabilities: { chat: true, stream: true, embed: false }
|
|
42
|
+
}]
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function createOpenAISubscriptionRoutes(options, transportOptions) {
|
|
48
|
+
const auth = options.credentialMode === "user" ? "user" : "admin";
|
|
49
|
+
const api = "/api/admin/openai-subscription";
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: "/admin/openai-subscription",
|
|
54
|
+
auth,
|
|
55
|
+
handle: () => adminPage(options.label ?? "OpenAI subscription (Codex)")
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
method: "GET",
|
|
59
|
+
path: `${api}/status`,
|
|
60
|
+
auth,
|
|
61
|
+
handle: async (ctx) => {
|
|
62
|
+
const { store, scope } = routeState(ctx, options);
|
|
63
|
+
return ctx.json({ status: await store.status(scope) });
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
method: "POST",
|
|
68
|
+
path: `${api}/connect`,
|
|
69
|
+
auth,
|
|
70
|
+
handle: async (ctx) => {
|
|
71
|
+
assertSmallRequest(ctx.request);
|
|
72
|
+
const { store, scope } = routeState(ctx, options);
|
|
73
|
+
const status = await store.status(scope);
|
|
74
|
+
const transport = createOpenAISubscriptionTransportInternal(options, ctx.env, transportOptions);
|
|
75
|
+
const started = await transport.startDeviceAuth(ctx.request.signal).catch((error) => persistAuthProtocolFailure(ctx, store, scope, status.generation, error));
|
|
76
|
+
const generation = status.generation + 1;
|
|
77
|
+
await store.writePending(scope, {
|
|
78
|
+
deviceAuthId: started.deviceAuthId,
|
|
79
|
+
userCode: started.userCode,
|
|
80
|
+
verificationUrl: started.verificationUrl,
|
|
81
|
+
expiresAt: started.expiresAt,
|
|
82
|
+
intervalSeconds: started.intervalSeconds,
|
|
83
|
+
nextPollAt: new Date(Date.now() + started.intervalSeconds * 1000).toISOString(),
|
|
84
|
+
generation
|
|
85
|
+
});
|
|
86
|
+
await store.writeStatus(scope, {
|
|
87
|
+
...status,
|
|
88
|
+
state: "connecting",
|
|
89
|
+
stateSince: nowIso(),
|
|
90
|
+
credentialMode: scope.mode,
|
|
91
|
+
compatibilityVersion: "codex-subscription-2026-07-29",
|
|
92
|
+
actionHref: "/admin/openai-subscription",
|
|
93
|
+
generation
|
|
94
|
+
});
|
|
95
|
+
await ctx.audit({
|
|
96
|
+
action: "openai-subscription.connect.started",
|
|
97
|
+
target: { type: "openai_subscription_connection", id: scope.mode },
|
|
98
|
+
metadata: { mode: scope.mode, generation }
|
|
99
|
+
});
|
|
100
|
+
return ctx.json({
|
|
101
|
+
verificationUrl: started.verificationUrl,
|
|
102
|
+
userCode: started.userCode,
|
|
103
|
+
expiresAt: started.expiresAt,
|
|
104
|
+
intervalSeconds: started.intervalSeconds,
|
|
105
|
+
generation
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
method: "POST",
|
|
111
|
+
path: `${api}/poll`,
|
|
112
|
+
auth,
|
|
113
|
+
handle: async (ctx) => {
|
|
114
|
+
assertSmallRequest(ctx.request);
|
|
115
|
+
const { store, scope } = routeState(ctx, options);
|
|
116
|
+
const pending = await store.readPending(scope);
|
|
117
|
+
if (!pending)
|
|
118
|
+
return ctx.json({ error: "No pending connection." }, 404);
|
|
119
|
+
if (Date.now() >= new Date(pending.expiresAt).getTime()) {
|
|
120
|
+
await store.deletePending(scope, { generation: pending.generation });
|
|
121
|
+
return ctx.json({ status: "expired" }, 410);
|
|
122
|
+
}
|
|
123
|
+
if (Date.now() < new Date(pending.nextPollAt).getTime()) {
|
|
124
|
+
return ctx.json({
|
|
125
|
+
status: "pending",
|
|
126
|
+
retryAt: pending.nextPollAt,
|
|
127
|
+
intervalSeconds: pending.intervalSeconds
|
|
128
|
+
}, 429);
|
|
129
|
+
}
|
|
130
|
+
const pollLeaseOwner = `poll_${crypto.randomUUID()}`;
|
|
131
|
+
if (!await store.acquirePendingPollLease(scope, pending.generation, pollLeaseOwner)) {
|
|
132
|
+
return ctx.json({
|
|
133
|
+
status: "pending",
|
|
134
|
+
retryAt: new Date(Date.now() + 1_000).toISOString(),
|
|
135
|
+
intervalSeconds: pending.intervalSeconds
|
|
136
|
+
}, 429);
|
|
137
|
+
}
|
|
138
|
+
const transport = createOpenAISubscriptionTransportInternal(options, ctx.env, transportOptions);
|
|
139
|
+
try {
|
|
140
|
+
const result = await transport.pollDeviceAuth(pending.deviceAuthId, pending.userCode, pending.intervalSeconds, ctx.request.signal);
|
|
141
|
+
if (result.status === "pending") {
|
|
142
|
+
const nextPollAt = new Date(Date.now() + result.intervalSeconds * 1000).toISOString();
|
|
143
|
+
const committed = await store.commitPendingPoll(scope, { ...pending, intervalSeconds: result.intervalSeconds, nextPollAt }, pollLeaseOwner);
|
|
144
|
+
if (!committed) {
|
|
145
|
+
return ctx.json({ error: "Connection was cancelled or replaced." }, 409);
|
|
146
|
+
}
|
|
147
|
+
return ctx.json({ status: "pending", intervalSeconds: result.intervalSeconds, retryAt: nextPollAt });
|
|
148
|
+
}
|
|
149
|
+
const tokens = await transport.exchangeDeviceCode(result, ctx.request.signal);
|
|
150
|
+
const committed = await store.commitPendingAuthorization(scope, pending, pollLeaseOwner, tokens);
|
|
151
|
+
if (!committed) {
|
|
152
|
+
return ctx.json({ error: "Connection was cancelled or replaced." }, 409);
|
|
153
|
+
}
|
|
154
|
+
await store.resolveIncidents(scope);
|
|
155
|
+
await ctx.audit({
|
|
156
|
+
action: "openai-subscription.connect.completed",
|
|
157
|
+
target: { type: "openai_subscription_connection", id: scope.mode },
|
|
158
|
+
metadata: { mode: scope.mode, generation: pending.generation }
|
|
159
|
+
});
|
|
160
|
+
return ctx.json({ status: await store.status(scope) });
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
return persistAuthProtocolFailure(ctx, store, scope, pending.generation, error);
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
await store.releasePendingPollLease(scope, pending.generation, pollLeaseOwner);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
method: "POST",
|
|
172
|
+
path: `${api}/cancel`,
|
|
173
|
+
auth,
|
|
174
|
+
handle: async (ctx) => {
|
|
175
|
+
assertSmallRequest(ctx.request);
|
|
176
|
+
const { store, scope } = routeState(ctx, options);
|
|
177
|
+
const status = await store.status(scope);
|
|
178
|
+
await store.deletePending(scope);
|
|
179
|
+
const existing = await store.read(scope);
|
|
180
|
+
const generation = status.generation + 1;
|
|
181
|
+
await store.writeStatus(scope, {
|
|
182
|
+
...status,
|
|
183
|
+
state: existing ? "connected" : "disconnected",
|
|
184
|
+
stateSince: nowIso(),
|
|
185
|
+
credentialMode: scope.mode,
|
|
186
|
+
compatibilityVersion: "codex-subscription-2026-07-29",
|
|
187
|
+
actionHref: "/admin/openai-subscription",
|
|
188
|
+
generation
|
|
189
|
+
});
|
|
190
|
+
return ctx.json({ status: await store.status(scope) });
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
method: "POST",
|
|
195
|
+
path: `${api}/reconnect`,
|
|
196
|
+
auth,
|
|
197
|
+
handle: async (ctx) => {
|
|
198
|
+
assertSmallRequest(ctx.request);
|
|
199
|
+
const { store, scope } = routeState(ctx, options);
|
|
200
|
+
const status = await store.status(scope);
|
|
201
|
+
await store.deletePending(scope);
|
|
202
|
+
const transport = createOpenAISubscriptionTransportInternal(options, ctx.env, transportOptions);
|
|
203
|
+
const started = await transport.startDeviceAuth(ctx.request.signal).catch((error) => persistAuthProtocolFailure(ctx, store, scope, status.generation, error));
|
|
204
|
+
const generation = status.generation + 1;
|
|
205
|
+
await store.writePending(scope, {
|
|
206
|
+
deviceAuthId: started.deviceAuthId,
|
|
207
|
+
userCode: started.userCode,
|
|
208
|
+
verificationUrl: started.verificationUrl,
|
|
209
|
+
expiresAt: started.expiresAt,
|
|
210
|
+
intervalSeconds: started.intervalSeconds,
|
|
211
|
+
nextPollAt: new Date(Date.now() + started.intervalSeconds * 1000).toISOString(),
|
|
212
|
+
generation
|
|
213
|
+
});
|
|
214
|
+
await store.writeStatus(scope, {
|
|
215
|
+
...status,
|
|
216
|
+
state: "connecting",
|
|
217
|
+
stateSince: nowIso(),
|
|
218
|
+
credentialMode: scope.mode,
|
|
219
|
+
compatibilityVersion: "codex-subscription-2026-07-29",
|
|
220
|
+
actionHref: "/admin/openai-subscription",
|
|
221
|
+
generation
|
|
222
|
+
});
|
|
223
|
+
return ctx.json({
|
|
224
|
+
verificationUrl: started.verificationUrl,
|
|
225
|
+
userCode: started.userCode,
|
|
226
|
+
expiresAt: started.expiresAt,
|
|
227
|
+
intervalSeconds: started.intervalSeconds,
|
|
228
|
+
generation
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
method: "POST",
|
|
234
|
+
path: `${api}/disconnect`,
|
|
235
|
+
auth,
|
|
236
|
+
handle: async (ctx) => {
|
|
237
|
+
assertSmallRequest(ctx.request);
|
|
238
|
+
const { store, scope } = routeState(ctx, options);
|
|
239
|
+
const generation = await store.disconnect(scope);
|
|
240
|
+
await ctx.audit({
|
|
241
|
+
action: "openai-subscription.disconnect",
|
|
242
|
+
target: { type: "openai_subscription_connection", id: scope.mode },
|
|
243
|
+
metadata: { mode: scope.mode, generation }
|
|
244
|
+
});
|
|
245
|
+
return ctx.json({ status: await store.status(scope) });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
function routeState(ctx, options) {
|
|
251
|
+
const user = options.credentialMode === "user" ? ctx.requireUser() : ctx.requireAdmin();
|
|
252
|
+
const secret = ctx.env.RAYBASE_OPENAI_SUBSCRIPTION_KEY;
|
|
253
|
+
if (!secret)
|
|
254
|
+
throw new Error("RAYBASE_OPENAI_SUBSCRIPTION_KEY is not configured");
|
|
255
|
+
const principal = {
|
|
256
|
+
kind: "user",
|
|
257
|
+
user,
|
|
258
|
+
userId: user.identityId ?? user.id,
|
|
259
|
+
membershipId: user.membershipId ?? null,
|
|
260
|
+
organizationId: ctx.organizationId ?? user.organizationId ?? null,
|
|
261
|
+
roles: user.appRoles
|
|
262
|
+
};
|
|
263
|
+
const factoryContext = {
|
|
264
|
+
config: ctx.config,
|
|
265
|
+
principal,
|
|
266
|
+
organizationId: ctx.organizationId ?? undefined,
|
|
267
|
+
surface: "http"
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
store: new OpenAISubscriptionCredentialStore(ctx.control, secret),
|
|
271
|
+
scope: resolveOpenAISubscriptionCredentialScope(options, factoryContext)
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
async function persistAuthProtocolFailure(ctx, store, scope, generation, error) {
|
|
275
|
+
if (error instanceof RaybaseInferenceProviderError && error.health === "protocol_update_required") {
|
|
276
|
+
await transitionOpenAISubscriptionHealth({
|
|
277
|
+
scope,
|
|
278
|
+
store,
|
|
279
|
+
onIncident: async (state, incidentGeneration, incidentId) => {
|
|
280
|
+
const actionHref = "/admin/openai-subscription";
|
|
281
|
+
await ctx.audit({
|
|
282
|
+
action: `openai-subscription.${state}`,
|
|
283
|
+
target: { type: "openai_subscription_connection", id: scope.mode },
|
|
284
|
+
metadata: {
|
|
285
|
+
state,
|
|
286
|
+
credentialMode: scope.mode,
|
|
287
|
+
generation: incidentGeneration,
|
|
288
|
+
actionHref
|
|
289
|
+
}
|
|
290
|
+
}).catch(() => undefined);
|
|
291
|
+
await ctx.notifications.send({
|
|
292
|
+
to: scope.mode === "user" ? [{ kind: "current-user" }] : [{ kind: "operator" }],
|
|
293
|
+
title: "Update OpenAI subscription module",
|
|
294
|
+
body: "The pinned Codex compatibility protocol changed. Install a reviewed module update.",
|
|
295
|
+
kind: "openai-subscription.protocol_update_required",
|
|
296
|
+
severity: "warning",
|
|
297
|
+
target: { href: actionHref },
|
|
298
|
+
channels: ["feed"],
|
|
299
|
+
dedupeKey: `openai-subscription:${incidentId}`,
|
|
300
|
+
metadata: {
|
|
301
|
+
state,
|
|
302
|
+
credentialMode: scope.mode,
|
|
303
|
+
generation: incidentGeneration
|
|
304
|
+
}
|
|
305
|
+
}).then(() => store.markIncidentNotified(incidentId)).catch(() => undefined);
|
|
306
|
+
}
|
|
307
|
+
}, "protocol_update_required", generation);
|
|
308
|
+
}
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
function assertSmallRequest(request) {
|
|
312
|
+
const length = Number(request.headers.get("content-length") ?? "0");
|
|
313
|
+
if (length > 4096)
|
|
314
|
+
throw new Error("OpenAI subscription request body is too large");
|
|
315
|
+
const origin = request.headers.get("origin");
|
|
316
|
+
if (origin && origin !== new URL(request.url).origin)
|
|
317
|
+
throw new Error("OpenAI subscription request origin is not allowed");
|
|
318
|
+
}
|
|
319
|
+
function adminPage(title) {
|
|
320
|
+
const safeTitle = escapeHtml(title);
|
|
321
|
+
return new Response(`<!doctype html>
|
|
322
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
323
|
+
<title>${safeTitle}</title>
|
|
324
|
+
<style>body{font:15px system-ui;max-width:720px;margin:3rem auto;padding:0 1rem;color:#18181b}button{padding:.55rem .8rem;margin:.25rem}code{font-size:1.25rem}#status{padding:1rem;background:#f4f4f5;border-radius:.5rem}</style></head>
|
|
325
|
+
<body><h1>${safeTitle}</h1><p>Experimental, compatibility-sensitive ChatGPT/Codex subscription inference.</p>
|
|
326
|
+
<div id="status" aria-live="polite">Loading safe connection status…</div>
|
|
327
|
+
<p><button id="connect">Connect or reconnect</button><button id="poll" hidden>Check connection</button><button id="cancel" hidden>Cancel</button><button id="disconnect">Disconnect</button></p>
|
|
328
|
+
<script type="module">
|
|
329
|
+
const api="/api/admin/openai-subscription";
|
|
330
|
+
const status=document.querySelector("#status"),poll=document.querySelector("#poll"),cancel=document.querySelector("#cancel");
|
|
331
|
+
async function call(path){const r=await fetch(api+path,{method:path==="/status"?"GET":"POST",headers:{"accept":"application/json"}});const v=await r.json();render(v);return v}
|
|
332
|
+
function render(v){const s=v.status??v;status.textContent="State: "+(s.state??s.status??"unknown")+(s.plan?" · Plan: "+s.plan:"");if(v.userCode){status.replaceChildren(document.createTextNode("Open "),Object.assign(document.createElement("a"),{href:v.verificationUrl,target:"_blank",rel:"noopener",textContent:v.verificationUrl}),document.createTextNode(" and enter "),Object.assign(document.createElement("code"),{textContent:v.userCode}));poll.hidden=false;cancel.hidden=false}}
|
|
333
|
+
document.querySelector("#connect").onclick=()=>call("/reconnect");poll.onclick=()=>call("/poll");cancel.onclick=()=>call("/cancel");document.querySelector("#disconnect").onclick=()=>call("/disconnect");call("/status");
|
|
334
|
+
</script></body></html>`, { headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" } });
|
|
335
|
+
}
|
|
336
|
+
function escapeHtml(value) {
|
|
337
|
+
return value.replace(/[&<>"']/g, (character) => ({
|
|
338
|
+
"&": "&", "<": "<", ">": ">", "\"": """, "'": "'"
|
|
339
|
+
})[character] ?? character);
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,MAAM,EACN,6BAA6B,EAK9B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,+CAA+C,EAC/C,wCAAwC,EACzC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EACL,yCAAyC,EAE1C,MAAM,gBAAgB,CAAC;AACxB,OA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AgB,CAAC,IAAI,GAAG,CAAC,CAAC;IACpE,IAAI,MAAM,GAAG,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACpF,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,MAAM,IAAI,MAAM,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;AAC7H,CAAC;AAED,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,IAAI,QAAQ,CAAC;;SAEb,SAAS;;YAEN,SAAS;;;;;;;;;wBASG,EAAE,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,0BAA0B,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;AACpH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAC/C,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO;KACrE,CAAC,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RaybaseInferenceProviderFactory, type RaybaseInferenceProviderFactoryContext } from "@raybase/core";
|
|
2
|
+
import { type OpenAISubscriptionTransportOptions } from "./transport.js";
|
|
3
|
+
import type { OpenAISubscriptionCredentialScope, OpenAISubscriptionEnv, OpenAISubscriptionModuleOptions } from "./types.js";
|
|
4
|
+
export declare function createOpenAISubscriptionProviderFactory<Env extends OpenAISubscriptionEnv>(options: OpenAISubscriptionModuleOptions): RaybaseInferenceProviderFactory<Env>;
|
|
5
|
+
export declare function createOpenAISubscriptionProviderFactoryForTesting<Env extends OpenAISubscriptionEnv>(options: OpenAISubscriptionModuleOptions, transportOptions: OpenAISubscriptionTransportOptions): RaybaseInferenceProviderFactory<Env>;
|
|
6
|
+
export declare function createOpenAISubscriptionProviderFactoryInternal<Env extends OpenAISubscriptionEnv>(options: OpenAISubscriptionModuleOptions, transportOptions?: OpenAISubscriptionTransportOptions): RaybaseInferenceProviderFactory<Env>;
|
|
7
|
+
export declare function resolveOpenAISubscriptionCredentialScope<Env>(options: OpenAISubscriptionModuleOptions, context: Pick<RaybaseInferenceProviderFactoryContext<Env>, "config" | "principal" | "organizationId" | "surface">): OpenAISubscriptionCredentialScope;
|
|
8
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,+BAA+B,EACpC,KAAK,sCAAsC,EAC5C,MAAM,eAAe,CAAC;AAOvB,OAAO,EAIL,KAAK,kCAAkC,EACxC,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,iCAAiC,EACjC,qBAAqB,EACrB,+BAA+B,EAEhC,MAAM,YAAY,CAAC;AAKpB,wBAAgB,uCAAuC,CAAC,GAAG,SAAS,qBAAqB,EACvF,OAAO,EAAE,+BAA+B,GACvC,+BAA+B,CAAC,GAAG,CAAC,CAEtC;AAED,wBAAgB,iDAAiD,CAAC,GAAG,SAAS,qBAAqB,EACjG,OAAO,EAAE,+BAA+B,EACxC,gBAAgB,EAAE,kCAAkC,GACnD,+BAA+B,CAAC,GAAG,CAAC,CAEtC;AAED,wBAAgB,+CAA+C,CAAC,GAAG,SAAS,qBAAqB,EAC/F,OAAO,EAAE,+BAA+B,EACxC,gBAAgB,CAAC,EAAE,kCAAkC,GACpD,+BAA+B,CAAC,GAAG,CAAC,CA2DtC;AAED,wBAAgB,wCAAwC,CAAC,GAAG,EAC1D,OAAO,EAAE,+BAA+B,EACxC,OAAO,EAAE,IAAI,CACX,sCAAsC,CAAC,GAAG,CAAC,EAC3C,QAAQ,GAAG,WAAW,GAAG,gBAAgB,GAAG,SAAS,CACtD,GACA,iCAAiC,CAoCnC"}
|