@opengeni/sdk 3.3.2-canary.0 → 3.3.2-canary.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/dist/artifacts.js +6 -6
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +6 -4
- package/dist/{chunk-C2H7HBNP.js → chunk-6NEPJ7NC.js} +2 -2
- package/dist/{chunk-YXQX7RQT.js → chunk-BESZFWMU.js} +2 -2
- package/dist/{chunk-JUS2UYRP.js → chunk-E5BNEG2D.js} +1 -1
- package/dist/chunk-E5BNEG2D.js.map +1 -0
- package/dist/{chunk-TRNI7KEO.js → chunk-GY6RQPCG.js} +72 -4
- package/dist/chunk-GY6RQPCG.js.map +1 -0
- package/dist/{chunk-C4DJPZRU.js → chunk-OO5LPTO7.js} +14 -1
- package/dist/chunk-OO5LPTO7.js.map +1 -0
- package/dist/{chunk-KKRO2VCP.js → chunk-QTBAMHEF.js} +2 -2
- package/dist/{chunk-QT3KFVDP.js → chunk-TFCLHRZK.js} +2 -2
- package/dist/client.d.ts +13 -1
- package/dist/codex-realtime-controller.js +2 -2
- package/dist/core.d.ts +2 -1
- package/dist/core.js +7 -5
- package/dist/document-authority.js +5 -5
- package/dist/editable-artifacts.js +1 -1
- package/dist/errors.d.ts +12 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/interaction.js +2 -2
- package/dist/model-picker-order.d.ts +1 -0
- package/dist/model-picker-order.js +10 -0
- package/dist/model-picker-order.js.map +1 -0
- package/dist/realtime.js +2 -2
- package/dist/types.d.ts +32 -1
- package/package.json +6 -2
- package/src/browser.ts +2 -0
- package/src/client.ts +116 -0
- package/src/core.ts +2 -0
- package/src/errors.ts +23 -0
- package/src/index.ts +11 -0
- package/src/model-picker-order.ts +6 -0
- package/src/types.ts +41 -1
- package/dist/chunk-C4DJPZRU.js.map +0 -1
- package/dist/chunk-JUS2UYRP.js.map +0 -1
- package/dist/chunk-TRNI7KEO.js.map +0 -1
- /package/dist/{chunk-C2H7HBNP.js.map → chunk-6NEPJ7NC.js.map} +0 -0
- /package/dist/{chunk-YXQX7RQT.js.map → chunk-BESZFWMU.js.map} +0 -0
- /package/dist/{chunk-KKRO2VCP.js.map → chunk-QTBAMHEF.js.map} +0 -0
- /package/dist/{chunk-QT3KFVDP.js.map → chunk-TFCLHRZK.js.map} +0 -0
package/src/client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniApiContractMismatchError,
|
|
3
3
|
OpenGeniApiError,
|
|
4
|
+
OpenGeniSecureContextRequiredError,
|
|
4
5
|
OpenGeniSessionListCursorError,
|
|
5
6
|
} from "./errors";
|
|
6
7
|
import {
|
|
@@ -169,6 +170,14 @@ import type {
|
|
|
169
170
|
ClientConfig,
|
|
170
171
|
WorkspaceModelAccessPolicy,
|
|
171
172
|
WorkspaceModelCatalogResponse,
|
|
173
|
+
WorkspaceGatewayCustomModel,
|
|
174
|
+
WorkspaceGatewayCustomModelsResponse,
|
|
175
|
+
CreateWorkspaceGatewayCustomModelRequest,
|
|
176
|
+
DeleteWorkspaceGatewayCustomModelRequest,
|
|
177
|
+
WorkspaceOpenRouterCustomModel,
|
|
178
|
+
WorkspaceOpenRouterCustomModelsResponse,
|
|
179
|
+
CreateWorkspaceOpenRouterCustomModelRequest,
|
|
180
|
+
DeleteWorkspaceOpenRouterCustomModelRequest,
|
|
172
181
|
WorkspaceRealtimeModelCatalogResponse,
|
|
173
182
|
ClientSessionEventInput,
|
|
174
183
|
UserMessageEventInput,
|
|
@@ -4045,6 +4054,90 @@ export class OpenGeniClient {
|
|
|
4045
4054
|
);
|
|
4046
4055
|
}
|
|
4047
4056
|
|
|
4057
|
+
/** List workspace-owned unpinned Vercel AI Gateway model slugs. */
|
|
4058
|
+
async listWorkspaceGatewayCustomModels(
|
|
4059
|
+
workspaceId: string,
|
|
4060
|
+
): Promise<WorkspaceGatewayCustomModelsResponse> {
|
|
4061
|
+
return await this.requestJson<WorkspaceGatewayCustomModelsResponse>(
|
|
4062
|
+
"GET",
|
|
4063
|
+
`/v1/workspaces/${workspaceId}/gateway-custom-models`,
|
|
4064
|
+
);
|
|
4065
|
+
}
|
|
4066
|
+
|
|
4067
|
+
/** Add one exact upstream Vercel AI Gateway slug. */
|
|
4068
|
+
async createWorkspaceGatewayCustomModel(
|
|
4069
|
+
workspaceId: string,
|
|
4070
|
+
request: CreateWorkspaceGatewayCustomModelRequest,
|
|
4071
|
+
): Promise<WorkspaceGatewayCustomModel> {
|
|
4072
|
+
return await this.requestJson<WorkspaceGatewayCustomModel>(
|
|
4073
|
+
"POST",
|
|
4074
|
+
`/v1/workspaces/${workspaceId}/gateway-custom-models`,
|
|
4075
|
+
request,
|
|
4076
|
+
);
|
|
4077
|
+
}
|
|
4078
|
+
|
|
4079
|
+
/** Remove one workspace custom Gateway model by its stable row id. */
|
|
4080
|
+
async deleteWorkspaceGatewayCustomModel(
|
|
4081
|
+
workspaceId: string,
|
|
4082
|
+
customModelId: string,
|
|
4083
|
+
request: DeleteWorkspaceGatewayCustomModelRequest,
|
|
4084
|
+
): Promise<void> {
|
|
4085
|
+
if (
|
|
4086
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(
|
|
4087
|
+
customModelId,
|
|
4088
|
+
)
|
|
4089
|
+
) {
|
|
4090
|
+
throw new TypeError("customModelId must be a UUID");
|
|
4091
|
+
}
|
|
4092
|
+
await this.requestVoid(
|
|
4093
|
+
"DELETE",
|
|
4094
|
+
`/v1/workspaces/${workspaceId}/gateway-custom-models/${encodeURIComponent(customModelId)}`,
|
|
4095
|
+
request,
|
|
4096
|
+
);
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
/** List workspace-owned unpinned OpenRouter model slugs. */
|
|
4100
|
+
async listWorkspaceOpenRouterCustomModels(
|
|
4101
|
+
workspaceId: string,
|
|
4102
|
+
): Promise<WorkspaceOpenRouterCustomModelsResponse> {
|
|
4103
|
+
return await this.requestJson<WorkspaceOpenRouterCustomModelsResponse>(
|
|
4104
|
+
"GET",
|
|
4105
|
+
`/v1/workspaces/${workspaceId}/openrouter-custom-models`,
|
|
4106
|
+
);
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
/** Add one exact upstream OpenRouter slug. */
|
|
4110
|
+
async createWorkspaceOpenRouterCustomModel(
|
|
4111
|
+
workspaceId: string,
|
|
4112
|
+
request: CreateWorkspaceOpenRouterCustomModelRequest,
|
|
4113
|
+
): Promise<WorkspaceOpenRouterCustomModel> {
|
|
4114
|
+
return await this.requestJson<WorkspaceOpenRouterCustomModel>(
|
|
4115
|
+
"POST",
|
|
4116
|
+
`/v1/workspaces/${workspaceId}/openrouter-custom-models`,
|
|
4117
|
+
request,
|
|
4118
|
+
);
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4121
|
+
/** Remove one workspace custom OpenRouter model by its stable row id. */
|
|
4122
|
+
async deleteWorkspaceOpenRouterCustomModel(
|
|
4123
|
+
workspaceId: string,
|
|
4124
|
+
customModelId: string,
|
|
4125
|
+
request: DeleteWorkspaceOpenRouterCustomModelRequest,
|
|
4126
|
+
): Promise<void> {
|
|
4127
|
+
if (
|
|
4128
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(
|
|
4129
|
+
customModelId,
|
|
4130
|
+
)
|
|
4131
|
+
) {
|
|
4132
|
+
throw new TypeError("customModelId must be a UUID");
|
|
4133
|
+
}
|
|
4134
|
+
await this.requestVoid(
|
|
4135
|
+
"DELETE",
|
|
4136
|
+
`/v1/workspaces/${workspaceId}/openrouter-custom-models/${encodeURIComponent(customModelId)}`,
|
|
4137
|
+
request,
|
|
4138
|
+
);
|
|
4139
|
+
}
|
|
4140
|
+
|
|
4048
4141
|
/** Read the workspace's hard provider/model allowlist. */
|
|
4049
4142
|
async getWorkspaceModelAccessPolicy(workspaceId: string): Promise<WorkspaceModelAccessPolicy> {
|
|
4050
4143
|
return await this.requestJson<WorkspaceModelAccessPolicy>(
|
|
@@ -5478,6 +5571,7 @@ export class OpenGeniClient {
|
|
|
5478
5571
|
) {
|
|
5479
5572
|
throw new Error("File upload timeout must be a positive number");
|
|
5480
5573
|
}
|
|
5574
|
+
assertBrowserFileUploadSecureContext();
|
|
5481
5575
|
const withTimeout = async <T>(
|
|
5482
5576
|
timeoutMs: number,
|
|
5483
5577
|
operation: (signal: AbortSignal) => Promise<T>,
|
|
@@ -7701,6 +7795,28 @@ function mutationTransportError(correlationId: string): OpenGeniApiError {
|
|
|
7701
7795
|
});
|
|
7702
7796
|
}
|
|
7703
7797
|
|
|
7798
|
+
function assertBrowserFileUploadSecureContext(): void {
|
|
7799
|
+
const secureContext =
|
|
7800
|
+
typeof window !== "undefined"
|
|
7801
|
+
? window.isSecureContext
|
|
7802
|
+
: typeof globalThis.isSecureContext === "boolean"
|
|
7803
|
+
? globalThis.isSecureContext
|
|
7804
|
+
: undefined;
|
|
7805
|
+
// The framework-agnostic SDK also runs in Node, Bun, Deno, and edge
|
|
7806
|
+
// runtimes. Preserve their existing upload behavior; this typed HTTPS error
|
|
7807
|
+
// is only meaningful where the browser exposes a secure-context state.
|
|
7808
|
+
if (secureContext === undefined) return;
|
|
7809
|
+
if (!secureContext) {
|
|
7810
|
+
throw new OpenGeniSecureContextRequiredError("insecure_context");
|
|
7811
|
+
}
|
|
7812
|
+
if (
|
|
7813
|
+
typeof globalThis.crypto === "undefined" ||
|
|
7814
|
+
typeof globalThis.crypto.subtle?.digest !== "function"
|
|
7815
|
+
) {
|
|
7816
|
+
throw new OpenGeniSecureContextRequiredError("web_crypto_unavailable");
|
|
7817
|
+
}
|
|
7818
|
+
}
|
|
7819
|
+
|
|
7704
7820
|
async function sha256ForUpload(body: Blob | ArrayBuffer | string): Promise<string> {
|
|
7705
7821
|
const bytes =
|
|
7706
7822
|
typeof body === "string"
|
package/src/core.ts
CHANGED
|
@@ -13,9 +13,11 @@ export type {
|
|
|
13
13
|
export {
|
|
14
14
|
OpenGeniApiContractMismatchError,
|
|
15
15
|
OpenGeniApiError,
|
|
16
|
+
OpenGeniSecureContextRequiredError,
|
|
16
17
|
OpenGeniSessionListCursorError,
|
|
17
18
|
OpenGeniStreamError,
|
|
18
19
|
isRetryableStreamError,
|
|
19
20
|
} from "./errors";
|
|
21
|
+
export type { OpenGeniSecureContextRequiredReason } from "./errors";
|
|
20
22
|
export { resolveWorkspaceVoiceInputEnabled } from "./transcription";
|
|
21
23
|
export { OPENGENI_API_CONTRACT_HEADER, OPENGENI_API_CONTRACT_REVISION } from "./types";
|
package/src/errors.ts
CHANGED
|
@@ -49,6 +49,29 @@ export class OpenGeniApiError extends Error {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
export type OpenGeniSecureContextRequiredReason = "insecure_context" | "web_crypto_unavailable";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A browser operation requires secure-context-only platform capabilities.
|
|
56
|
+
* Callers may key UI behavior on the stable `secure_context_required` code;
|
|
57
|
+
* `reason` exists only to keep the human guidance truthful.
|
|
58
|
+
*/
|
|
59
|
+
export class OpenGeniSecureContextRequiredError extends Error {
|
|
60
|
+
readonly code = "secure_context_required" as const;
|
|
61
|
+
readonly retryable = false;
|
|
62
|
+
readonly reason: OpenGeniSecureContextRequiredReason;
|
|
63
|
+
|
|
64
|
+
constructor(reason: OpenGeniSecureContextRequiredReason) {
|
|
65
|
+
super(
|
|
66
|
+
reason === "insecure_context"
|
|
67
|
+
? "Couldn’t attach this file because OpenGeni is open over HTTP. Attachments require a secure HTTPS connection. Open the secure site or configure HTTPS for this deployment."
|
|
68
|
+
: "Couldn’t attach this file because secure browser cryptography is unavailable. Attachments require HTTPS and Web Crypto support. Open a secure site in a supported browser or configure HTTPS for this deployment.",
|
|
69
|
+
);
|
|
70
|
+
this.name = "OpenGeniSecureContextRequiredError";
|
|
71
|
+
this.reason = reason;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
52
75
|
function decodeApiErrorBody(body: string): {
|
|
53
76
|
code: string | undefined;
|
|
54
77
|
message: string | undefined;
|
package/src/index.ts
CHANGED
|
@@ -26,10 +26,12 @@ export type {
|
|
|
26
26
|
export {
|
|
27
27
|
OpenGeniApiContractMismatchError,
|
|
28
28
|
OpenGeniApiError,
|
|
29
|
+
OpenGeniSecureContextRequiredError,
|
|
29
30
|
OpenGeniSessionListCursorError,
|
|
30
31
|
OpenGeniStreamError,
|
|
31
32
|
isRetryableStreamError,
|
|
32
33
|
} from "./errors";
|
|
34
|
+
export type { OpenGeniSecureContextRequiredReason } from "./errors";
|
|
33
35
|
export {
|
|
34
36
|
AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
35
37
|
deriveSessionDisplayTitle,
|
|
@@ -478,6 +480,7 @@ export type {
|
|
|
478
480
|
EndSessionRealtimeRequest,
|
|
479
481
|
ModelAvailabilityV1,
|
|
480
482
|
ModelBillingAttributionV1,
|
|
483
|
+
ModelCostClassV1,
|
|
481
484
|
ModelCapabilitiesV1,
|
|
482
485
|
ModelCapabilityStateV1,
|
|
483
486
|
ModelCapabilitySupportV1,
|
|
@@ -493,6 +496,14 @@ export type {
|
|
|
493
496
|
SessionRealtimeState,
|
|
494
497
|
WorkspaceModelCatalogModel,
|
|
495
498
|
WorkspaceModelCatalogResponse,
|
|
499
|
+
WorkspaceGatewayCustomModel,
|
|
500
|
+
WorkspaceGatewayCustomModelsResponse,
|
|
501
|
+
CreateWorkspaceGatewayCustomModelRequest,
|
|
502
|
+
DeleteWorkspaceGatewayCustomModelRequest,
|
|
503
|
+
WorkspaceOpenRouterCustomModel,
|
|
504
|
+
WorkspaceOpenRouterCustomModelsResponse,
|
|
505
|
+
CreateWorkspaceOpenRouterCustomModelRequest,
|
|
506
|
+
DeleteWorkspaceOpenRouterCustomModelRequest,
|
|
496
507
|
WorkspaceModelAccessPolicy,
|
|
497
508
|
WorkspaceRealtimeModelCatalogItem,
|
|
498
509
|
WorkspaceRealtimeModelCatalogResponse,
|
package/src/types.ts
CHANGED
|
@@ -671,6 +671,7 @@ export type CreateConnectionRequest = {
|
|
|
671
671
|
grantedScopes?: string[] | undefined;
|
|
672
672
|
expiresAt?: string | null | undefined;
|
|
673
673
|
metadata?: Record<string, unknown> | undefined;
|
|
674
|
+
operationId?: string | undefined;
|
|
674
675
|
};
|
|
675
676
|
|
|
676
677
|
export type PersonalGitHubConnectionMetadata = {
|
|
@@ -1072,6 +1073,8 @@ export type UpdateConnectionRequest = {
|
|
|
1072
1073
|
grantedScopes?: string[] | undefined;
|
|
1073
1074
|
expiresAt?: string | null | undefined;
|
|
1074
1075
|
metadata?: Record<string, unknown> | undefined;
|
|
1076
|
+
expectedVersion?: number | undefined;
|
|
1077
|
+
operationId?: string | undefined;
|
|
1075
1078
|
};
|
|
1076
1079
|
|
|
1077
1080
|
export type ConnectionResponse = {
|
|
@@ -3030,6 +3033,8 @@ export type ModelBillingAttributionV1 = {
|
|
|
3030
3033
|
metering: "opengeni_credits" | "external";
|
|
3031
3034
|
};
|
|
3032
3035
|
|
|
3036
|
+
export type ModelCostClassV1 = "free" | "credits" | "subscription" | "workspace";
|
|
3037
|
+
|
|
3033
3038
|
export type ModelPricingV1 = {
|
|
3034
3039
|
inputMicrosPerMillionTokens: number;
|
|
3035
3040
|
cachedInputMicrosPerMillionTokens?: number | undefined;
|
|
@@ -3062,7 +3067,7 @@ export type ClientModel = {
|
|
|
3062
3067
|
provider: string;
|
|
3063
3068
|
providerLabel: string;
|
|
3064
3069
|
api: "responses" | "chat";
|
|
3065
|
-
source?: "opengeni" | "codex" | "supergrok" | "workspace_gateway" | undefined;
|
|
3070
|
+
source?: "opengeni" | "codex" | "supergrok" | "workspace_gateway" | "openrouter" | undefined;
|
|
3066
3071
|
contextWindowTokens?: number | undefined;
|
|
3067
3072
|
schemaVersion?: 1 | undefined;
|
|
3068
3073
|
aliases?: string[] | undefined;
|
|
@@ -3082,6 +3087,7 @@ export type ClientModel = {
|
|
|
3082
3087
|
| undefined;
|
|
3083
3088
|
credentialSource?: ModelCredentialSourceV1 | undefined;
|
|
3084
3089
|
billing?: ModelBillingAttributionV1 | undefined;
|
|
3090
|
+
cost?: ModelCostClassV1 | undefined;
|
|
3085
3091
|
capabilities?: ModelCapabilitiesV1 | undefined;
|
|
3086
3092
|
pricing?: ModelPricingScheduleV1 | undefined;
|
|
3087
3093
|
definitionVersion?: string | undefined;
|
|
@@ -3126,6 +3132,40 @@ export type WorkspaceModelCatalogResponse = {
|
|
|
3126
3132
|
models: WorkspaceModelCatalogModel[];
|
|
3127
3133
|
};
|
|
3128
3134
|
|
|
3135
|
+
export type WorkspaceGatewayCustomModel = {
|
|
3136
|
+
id: string;
|
|
3137
|
+
upstreamModelId: string;
|
|
3138
|
+
label: string | null;
|
|
3139
|
+
version: number;
|
|
3140
|
+
createdAt: string;
|
|
3141
|
+
updatedAt: string;
|
|
3142
|
+
};
|
|
3143
|
+
|
|
3144
|
+
export type WorkspaceGatewayCustomModelsResponse = {
|
|
3145
|
+
models: WorkspaceGatewayCustomModel[];
|
|
3146
|
+
};
|
|
3147
|
+
|
|
3148
|
+
export type CreateWorkspaceGatewayCustomModelRequest = {
|
|
3149
|
+
operationId: string;
|
|
3150
|
+
upstreamModelId: string;
|
|
3151
|
+
label?: string | undefined;
|
|
3152
|
+
};
|
|
3153
|
+
|
|
3154
|
+
export type DeleteWorkspaceGatewayCustomModelRequest = {
|
|
3155
|
+
expectedVersion: number;
|
|
3156
|
+
operationId: string;
|
|
3157
|
+
};
|
|
3158
|
+
|
|
3159
|
+
export type WorkspaceOpenRouterCustomModel = WorkspaceGatewayCustomModel;
|
|
3160
|
+
|
|
3161
|
+
export type WorkspaceOpenRouterCustomModelsResponse = {
|
|
3162
|
+
models: WorkspaceOpenRouterCustomModel[];
|
|
3163
|
+
};
|
|
3164
|
+
|
|
3165
|
+
export type CreateWorkspaceOpenRouterCustomModelRequest = CreateWorkspaceGatewayCustomModelRequest;
|
|
3166
|
+
|
|
3167
|
+
export type DeleteWorkspaceOpenRouterCustomModelRequest = DeleteWorkspaceGatewayCustomModelRequest;
|
|
3168
|
+
|
|
3129
3169
|
/**
|
|
3130
3170
|
* The workspace's hard model/provider allowlist. `null` means unrestricted for
|
|
3131
3171
|
* that dimension; an empty array is an explicit total block.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["/** Error for a non-2xx OpenGeni API response. */\nexport class OpenGeniApiError extends Error {\n readonly status: number;\n readonly code: string | undefined;\n readonly retryable: boolean;\n readonly correlationId: string | undefined;\n /** True only when an uncontrolled transport failed after a mutation may have been accepted. */\n readonly outcomeUnknown: boolean;\n readonly body: string;\n readonly details: Record<string, unknown> | undefined;\n\n constructor(\n status: number,\n body: string,\n options: {\n code?: string | undefined;\n retryable?: boolean | undefined;\n correlationId?: string | undefined;\n outcomeUnknown?: boolean | undefined;\n displayMessage?: string | undefined;\n mutation?: boolean | undefined;\n } = {},\n ) {\n const decoded = decodeApiErrorBody(body);\n const correlationId = decoded?.requestId ?? boundedCorrelationId(options.correlationId);\n const gatewayFailure = status >= 502 && status <= 504;\n const fromResponse = options.mutation !== undefined;\n const message = decoded?.message ?? (fromResponse ? \"Request failed.\" : body || \"(empty body)\");\n const displayMessage =\n options.displayMessage ??\n (gatewayFailure && fromResponse\n ? (decoded?.message ?? \"OpenGeni is temporarily unavailable — retry.\")\n : `OpenGeni API ${status}: ${message}`);\n super(correlationId ? `${displayMessage} Reference: ${correlationId}.` : displayMessage);\n this.name = \"OpenGeniApiError\";\n this.status = status;\n this.code =\n options.code ??\n decoded?.code ??\n (gatewayFailure && fromResponse ? \"upstream_unavailable\" : undefined);\n this.retryable = options.retryable ?? decoded?.retryable ?? retryableApiStatus(status);\n this.correlationId = correlationId;\n this.outcomeUnknown =\n options.outcomeUnknown ??\n decoded?.outcomeUnknown ??\n (gatewayFailure && !!options.mutation && !decoded);\n this.body = !fromResponse || decoded ? body : \"\";\n this.details = decoded?.details;\n }\n}\n\nfunction decodeApiErrorBody(body: string): {\n code: string | undefined;\n message: string | undefined;\n requestId: string | undefined;\n retryable: boolean | undefined;\n outcomeUnknown: boolean | undefined;\n details: Record<string, unknown> | undefined;\n} | null {\n if (!body) return null;\n try {\n const decoded: unknown = JSON.parse(body);\n if (!decoded || typeof decoded !== \"object\" || Array.isArray(decoded)) return null;\n const record = decoded as Record<string, unknown>;\n const nested =\n record.error && typeof record.error === \"object\" && !Array.isArray(record.error)\n ? (record.error as Record<string, unknown>)\n : record;\n const code = boundedApiField(nested.code);\n const message = boundedApiField(nested.message);\n const requestId = boundedCorrelationId(nested.requestId);\n const retryable = typeof nested.retryable === \"boolean\" ? nested.retryable : undefined;\n const outcomeUnknown =\n typeof nested.outcomeUnknown === \"boolean\" ? nested.outcomeUnknown : undefined;\n const details = boundedApiDetails(nested.details);\n if (\n !code &&\n !message &&\n !requestId &&\n retryable === undefined &&\n outcomeUnknown === undefined &&\n !details\n )\n return null;\n return {\n code,\n message,\n requestId,\n retryable,\n outcomeUnknown,\n details,\n };\n } catch {\n return null;\n }\n}\n\nfunction boundedApiDetails(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return;\n const entries = Object.entries(value as Record<string, unknown>).slice(0, 16);\n const details: Record<string, unknown> = {};\n for (const [key, entry] of entries) {\n if (!/^[a-zA-Z][\\w.-]{0,63}$/.test(key)) continue;\n if (typeof entry === \"string\") {\n const bounded = boundedApiField(entry);\n if (bounded !== undefined) details[key] = bounded;\n } else if (typeof entry === \"number\" || typeof entry === \"boolean\" || entry === null) {\n details[key] = entry;\n }\n }\n return Object.keys(details).length > 0 ? details : undefined;\n}\n\nfunction boundedApiField(value: unknown): string | undefined {\n if (typeof value !== \"string\") return;\n const bytes = new TextEncoder().encode(value);\n return bytes.byteLength <= 512 ? value : new TextDecoder().decode(bytes.slice(0, 512));\n}\n\nfunction retryableApiStatus(status: number): boolean {\n return status === 408 || status === 409 || status === 425 || status === 429 || status >= 500;\n}\n\nfunction boundedCorrelationId(value: unknown): string | undefined {\n if (typeof value !== \"string\" || value.length > 128 || !/^[\\w.:-]+$/.test(value)) {\n return;\n }\n return value;\n}\n\n/** A legacy short-lived session-list snapshot cursor can no longer be continued. */\nexport class OpenGeniSessionListCursorError extends OpenGeniApiError {}\n\n/** The browser bundle and API disagree about their state-changing wire contract. */\nexport class OpenGeniApiContractMismatchError extends Error {\n readonly expected: string;\n readonly actual: string;\n\n constructor(expected: string, actual: string) {\n super(`OpenGeni API contract mismatch: client expects ${expected}, API serves ${actual}`);\n this.name = \"OpenGeniApiContractMismatchError\";\n this.expected = expected;\n this.actual = actual;\n }\n}\n\n/** Error for an unrecoverable event-stream condition (not a transient drop). */\nexport class OpenGeniStreamError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"OpenGeniStreamError\";\n }\n}\n\nexport function isAbortError(error: unknown): boolean {\n return (\n (error instanceof DOMException && error.name === \"AbortError\") ||\n (error instanceof Error && error.name === \"AbortError\")\n );\n}\n\n/**\n * Transient conditions worth a reconnect: network-level failures (`fetch`\n * rejects with `TypeError`) and HTTP statuses that signal a temporary server\n * or contention condition. Auth/validation failures (401/403/404/...) are\n * permanent and surface to the caller instead.\n */\nexport function isRetryableStreamError(error: unknown): boolean {\n if (error instanceof OpenGeniApiError) return error.retryable;\n return error instanceof TypeError;\n}\n"],"mappings":";AACO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,QACA,MACA,UAOI,CAAC,GACL;AACA,UAAM,UAAU,mBAAmB,IAAI;AACvC,UAAM,gBAAgB,SAAS,aAAa,qBAAqB,QAAQ,aAAa;AACtF,UAAM,iBAAiB,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