@bastani/pi-ai 0.9.71 → 0.9.72-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +78 -8
  3. package/dist/api/anthropic-messages.d.ts.map +1 -1
  4. package/dist/api/anthropic-messages.js +50 -10
  5. package/dist/api/anthropic-messages.js.map +1 -1
  6. package/dist/api/azure-openai-responses.d.ts.map +1 -1
  7. package/dist/api/azure-openai-responses.js +7 -2
  8. package/dist/api/azure-openai-responses.js.map +1 -1
  9. package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  10. package/dist/api/bedrock-converse-stream.js +28 -1
  11. package/dist/api/bedrock-converse-stream.js.map +1 -1
  12. package/dist/api/bedrock-converse-stream.lazy.d.ts +7 -0
  13. package/dist/api/bedrock-converse-stream.lazy.d.ts.map +1 -1
  14. package/dist/api/bedrock-converse-stream.lazy.js +18 -5
  15. package/dist/api/bedrock-converse-stream.lazy.js.map +1 -1
  16. package/dist/api/google-generative-ai.d.ts +3 -1
  17. package/dist/api/google-generative-ai.d.ts.map +1 -1
  18. package/dist/api/google-generative-ai.js +4 -2
  19. package/dist/api/google-generative-ai.js.map +1 -1
  20. package/dist/api/google-shared.d.ts +10 -2
  21. package/dist/api/google-shared.d.ts.map +1 -1
  22. package/dist/api/google-shared.js +31 -9
  23. package/dist/api/google-shared.js.map +1 -1
  24. package/dist/api/google-vertex.d.ts +3 -1
  25. package/dist/api/google-vertex.d.ts.map +1 -1
  26. package/dist/api/google-vertex.js +4 -2
  27. package/dist/api/google-vertex.js.map +1 -1
  28. package/dist/api/lazy.d.ts +2 -2
  29. package/dist/api/lazy.d.ts.map +1 -1
  30. package/dist/api/lazy.js +10 -9
  31. package/dist/api/lazy.js.map +1 -1
  32. package/dist/api/mistral-conversations.d.ts.map +1 -1
  33. package/dist/api/mistral-conversations.js +12 -1
  34. package/dist/api/mistral-conversations.js.map +1 -1
  35. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  36. package/dist/api/openai-codex-responses.js +6 -1
  37. package/dist/api/openai-codex-responses.js.map +1 -1
  38. package/dist/api/openai-completions.d.ts +2 -1
  39. package/dist/api/openai-completions.d.ts.map +1 -1
  40. package/dist/api/openai-completions.js +112 -15
  41. package/dist/api/openai-completions.js.map +1 -1
  42. package/dist/api/openai-images-options.d.ts +107 -0
  43. package/dist/api/openai-images-options.d.ts.map +1 -0
  44. package/dist/api/openai-images-options.js +106 -0
  45. package/dist/api/openai-images-options.js.map +1 -0
  46. package/dist/api/openai-images.d.ts +3 -11
  47. package/dist/api/openai-images.d.ts.map +1 -1
  48. package/dist/api/openai-images.js +117 -16
  49. package/dist/api/openai-images.js.map +1 -1
  50. package/dist/api/openai-responses-shared.js +6 -2
  51. package/dist/api/openai-responses-shared.js.map +1 -1
  52. package/dist/api/openai-responses.d.ts.map +1 -1
  53. package/dist/api/openai-responses.js +29 -7
  54. package/dist/api/openai-responses.js.map +1 -1
  55. package/dist/auth/oauth/load.d.ts.map +1 -1
  56. package/dist/auth/oauth/load.js +5 -2
  57. package/dist/auth/oauth/load.js.map +1 -1
  58. package/dist/env-api-keys.d.ts.map +1 -1
  59. package/dist/env-api-keys.js +1 -0
  60. package/dist/env-api-keys.js.map +1 -1
  61. package/dist/image-generation-error.d.ts +203 -0
  62. package/dist/image-generation-error.d.ts.map +1 -0
  63. package/dist/image-generation-error.js +441 -0
  64. package/dist/image-generation-error.js.map +1 -0
  65. package/dist/index.d.ts +4 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +4 -0
  68. package/dist/index.js.map +1 -1
  69. package/dist/lazy-bedrock-provider.d.ts +10 -0
  70. package/dist/lazy-bedrock-provider.d.ts.map +1 -0
  71. package/dist/lazy-bedrock-provider.js +13 -0
  72. package/dist/lazy-bedrock-provider.js.map +1 -0
  73. package/dist/lazy-oauth.d.ts +10 -0
  74. package/dist/lazy-oauth.d.ts.map +1 -0
  75. package/dist/lazy-oauth.js +23 -0
  76. package/dist/lazy-oauth.js.map +1 -0
  77. package/dist/models.d.ts.map +1 -1
  78. package/dist/models.generated.d.ts +4 -0
  79. package/dist/models.generated.d.ts.map +1 -1
  80. package/dist/models.generated.js +4 -0
  81. package/dist/models.generated.js.map +1 -1
  82. package/dist/models.js +8 -8
  83. package/dist/models.js.map +1 -1
  84. package/dist/providers/all.d.ts.map +1 -1
  85. package/dist/providers/all.js +2 -0
  86. package/dist/providers/all.js.map +1 -1
  87. package/dist/providers/azure.d.ts.map +1 -1
  88. package/dist/providers/azure.js +2 -2
  89. package/dist/providers/azure.js.map +1 -1
  90. package/dist/providers/compat-schema.d.ts +15 -0
  91. package/dist/providers/compat-schema.d.ts.map +1 -1
  92. package/dist/providers/compat-schema.js +19 -1
  93. package/dist/providers/compat-schema.js.map +1 -1
  94. package/dist/providers/data/.manifest.json +1 -1
  95. package/dist/providers/data/anthropic.json +1 -1
  96. package/dist/providers/data/azure.json +1 -1
  97. package/dist/providers/data/baseten.json +1 -1
  98. package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  99. package/dist/providers/data/fireworks.json +1 -1
  100. package/dist/providers/data/github-copilot.json +1 -1
  101. package/dist/providers/data/google-vertex.json +1 -1
  102. package/dist/providers/data/google.json +1 -1
  103. package/dist/providers/data/nvidia.json +1 -1
  104. package/dist/providers/data/openai-images.json +1 -1
  105. package/dist/providers/data/opencode-go.json +1 -1
  106. package/dist/providers/data/opencode.json +1 -1
  107. package/dist/providers/data/openrouter.json +1 -1
  108. package/dist/providers/data/qwen-token-plan-individual-cn.json +1 -0
  109. package/dist/providers/data/qwen-token-plan-individual.json +1 -1
  110. package/dist/providers/data/together.json +1 -1
  111. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  112. package/dist/providers/github-copilot-capabilities.d.ts +67 -0
  113. package/dist/providers/github-copilot-capabilities.d.ts.map +1 -0
  114. package/dist/providers/github-copilot-capabilities.js +81 -0
  115. package/dist/providers/github-copilot-capabilities.js.map +1 -0
  116. package/dist/providers/github-copilot-errors.d.ts +243 -0
  117. package/dist/providers/github-copilot-errors.d.ts.map +1 -0
  118. package/dist/providers/github-copilot-errors.js +720 -0
  119. package/dist/providers/github-copilot-errors.js.map +1 -0
  120. package/dist/providers/github-copilot.d.ts +1 -2
  121. package/dist/providers/github-copilot.d.ts.map +1 -1
  122. package/dist/providers/github-copilot.js +29 -4
  123. package/dist/providers/github-copilot.js.map +1 -1
  124. package/dist/providers/openai-codex.js +1 -1
  125. package/dist/providers/openai-codex.js.map +1 -1
  126. package/dist/providers/qwen-token-plan-individual-cn.d.ts +3 -0
  127. package/dist/providers/qwen-token-plan-individual-cn.d.ts.map +1 -0
  128. package/dist/providers/qwen-token-plan-individual-cn.js +15 -0
  129. package/dist/providers/qwen-token-plan-individual-cn.js.map +1 -0
  130. package/dist/providers/qwen-token-plan-individual-cn.models.d.ts +5 -0
  131. package/dist/providers/qwen-token-plan-individual-cn.models.d.ts.map +1 -0
  132. package/dist/providers/qwen-token-plan-individual-cn.models.js +8 -0
  133. package/dist/providers/qwen-token-plan-individual-cn.models.js.map +1 -0
  134. package/dist/types.d.ts +29 -3
  135. package/dist/types.d.ts.map +1 -1
  136. package/dist/types.js.map +1 -1
  137. package/dist/utils/error-body.d.ts +8 -0
  138. package/dist/utils/error-body.d.ts.map +1 -1
  139. package/dist/utils/error-body.js +28 -1
  140. package/dist/utils/error-body.js.map +1 -1
  141. package/dist/utils/model-operations.d.ts.map +1 -1
  142. package/dist/utils/model-operations.js +6 -0
  143. package/dist/utils/model-operations.js.map +1 -1
  144. package/dist/utils/overflow.d.ts +4 -0
  145. package/dist/utils/overflow.d.ts.map +1 -1
  146. package/dist/utils/overflow.js +16 -3
  147. package/dist/utils/overflow.js.map +1 -1
  148. package/dist/utils/provider-retry.d.ts +2 -0
  149. package/dist/utils/provider-retry.d.ts.map +1 -1
  150. package/dist/utils/provider-retry.js +2 -0
  151. package/dist/utils/provider-retry.js.map +1 -1
  152. package/dist/utils/retry.d.ts +3 -1
  153. package/dist/utils/retry.d.ts.map +1 -1
  154. package/dist/utils/retry.js +9 -0
  155. package/dist/utils/retry.js.map +1 -1
  156. package/dist/utils/thinking-off.d.ts +23 -0
  157. package/dist/utils/thinking-off.d.ts.map +1 -0
  158. package/dist/utils/thinking-off.js +51 -0
  159. package/dist/utils/thinking-off.js.map +1 -0
  160. package/dist/utils/version.d.ts +1 -1
  161. package/dist/utils/version.d.ts.map +1 -1
  162. package/dist/utils/version.js +1 -1
  163. package/dist/utils/version.js.map +1 -1
  164. package/package.json +9 -1
@@ -0,0 +1,441 @@
1
+ /**
2
+ * Typed failures of `generateImages()`.
3
+ *
4
+ * One family, {@link ImageGenerationError}, covers every failure the image providers can
5
+ * classify: a rejected request configuration ({@link ImageGenerationConfigError}), an API
6
+ * failure ({@link ImageGenerationApiError} and its subclasses) and a client-side timeout
7
+ * ({@link ImageGenerationTimeoutError}). Branch on the class, its guard or `code`, never on
8
+ * `message`. Cancellation is not a failure: an aborted request resolves with
9
+ * `stopReason: "aborted"` and no error.
10
+ */
11
+ const MAX_CAUSE_DEPTH = 8;
12
+ const FOREIGN_MESSAGE = "[foreign error message omitted]";
13
+ const SAFE_ERRNO_CODES = new Set([
14
+ "EACCES",
15
+ "EADDRINUSE",
16
+ "EADDRNOTAVAIL",
17
+ "EAFNOSUPPORT",
18
+ "EAGAIN",
19
+ "EALREADY",
20
+ "EBADF",
21
+ "EBUSY",
22
+ "ECANCELED",
23
+ "ECONNABORTED",
24
+ "ECONNREFUSED",
25
+ "ECONNRESET",
26
+ "EDESTADDRREQ",
27
+ "EEXIST",
28
+ "EFAULT",
29
+ "EHOSTUNREACH",
30
+ "EINTR",
31
+ "EINVAL",
32
+ "EIO",
33
+ "EISDIR",
34
+ "EMFILE",
35
+ "EMSGSIZE",
36
+ "ENETDOWN",
37
+ "ENETRESET",
38
+ "ENETUNREACH",
39
+ "ENFILE",
40
+ "ENOENT",
41
+ "ENOMEM",
42
+ "ENOSPC",
43
+ "ENOTCONN",
44
+ "ENOTDIR",
45
+ "ENOTFOUND",
46
+ "ENOTSOCK",
47
+ "ENOTSUP",
48
+ "EPIPE",
49
+ "EPERM",
50
+ "EPROTO",
51
+ "EPROTONOSUPPORT",
52
+ "ETIMEDOUT",
53
+ "EAI_AGAIN",
54
+ "EAI_FAIL",
55
+ "EAI_NONAME",
56
+ ]);
57
+ function safeForeignName(name) {
58
+ return typeof name === "string" && /^[A-Za-z][A-Za-z0-9_]{0,79}$/.test(name) ? name : "Error";
59
+ }
60
+ function safeErrno(code) {
61
+ return typeof code === "string" && SAFE_ERRNO_CODES.has(code) ? code : undefined;
62
+ }
63
+ function sanitizeCause(cause, depth) {
64
+ if (depth > MAX_CAUSE_DEPTH || !(cause instanceof Error))
65
+ return undefined;
66
+ if (cause instanceof ImageGenerationError)
67
+ return cause;
68
+ const nested = sanitizeCause(cause.cause, depth + 1);
69
+ const safe = new Error(FOREIGN_MESSAGE, nested ? { cause: nested } : undefined);
70
+ safe.name = safeForeignName(cause.name);
71
+ const code = safeErrno(cause.code);
72
+ if (code)
73
+ Object.assign(safe, { code });
74
+ return safe;
75
+ }
76
+ /** Base of every typed image-generation failure. */
77
+ export class ImageGenerationError extends Error {
78
+ name;
79
+ code;
80
+ /** True when the same request may succeed if sent again unchanged. */
81
+ retryable;
82
+ hint;
83
+ constructor(init) {
84
+ super(init.message, { cause: sanitizeCause(init.cause, 2) });
85
+ this.name = init.name;
86
+ this.code = init.code;
87
+ this.retryable = init.retryable ?? false;
88
+ this.hint = init.hint;
89
+ }
90
+ /** Safe, JSON-serializable context for this failure. Overridden by classes that carry fields. */
91
+ dataFields() {
92
+ return {};
93
+ }
94
+ toData() {
95
+ return this.dataWithCauses(1);
96
+ }
97
+ static causeData(cause, depth) {
98
+ if (depth > MAX_CAUSE_DEPTH || !(cause instanceof Error))
99
+ return undefined;
100
+ if (cause instanceof ImageGenerationError)
101
+ return cause.dataWithCauses(depth);
102
+ const code = safeErrno(cause.code);
103
+ const nested = ImageGenerationError.causeData(cause.cause, depth + 1);
104
+ return {
105
+ name: safeForeignName(cause.name),
106
+ message: FOREIGN_MESSAGE,
107
+ ...(code ? { code } : {}),
108
+ ...(nested ? { cause: nested } : {}),
109
+ };
110
+ }
111
+ dataWithCauses(depth) {
112
+ const causeData = ImageGenerationError.causeData(this.cause, depth + 1);
113
+ return {
114
+ name: this.name,
115
+ code: this.code,
116
+ message: this.message,
117
+ ...(this.hint !== undefined ? { hint: this.hint } : {}),
118
+ retryable: this.retryable,
119
+ fields: this.dataFields(),
120
+ ...(causeData ? { cause: causeData } : {}),
121
+ };
122
+ }
123
+ toJSON() {
124
+ return this.toData();
125
+ }
126
+ }
127
+ /**
128
+ * The request options or input are invalid. Thrown before any request is sent, so nothing was
129
+ * billed and retrying the same request fails the same way.
130
+ */
131
+ export class ImageGenerationConfigError extends ImageGenerationError {
132
+ source = "sdk";
133
+ model;
134
+ field;
135
+ reason;
136
+ related;
137
+ detail;
138
+ constructor(init) {
139
+ super({
140
+ name: "ImageGenerationConfigError",
141
+ code: "invalid-option",
142
+ message: `Invalid image generation option: ${init.field} for ${init.model} (invalid-option). ${init.detail}. ${init.hint}`,
143
+ hint: init.hint,
144
+ cause: init.cause,
145
+ });
146
+ this.model = init.model;
147
+ this.field = init.field;
148
+ this.reason = init.reason;
149
+ this.related = init.related;
150
+ this.detail = init.detail;
151
+ }
152
+ dataFields() {
153
+ return {
154
+ source: this.source,
155
+ model: this.model,
156
+ field: this.field,
157
+ reason: this.reason,
158
+ related: this.related,
159
+ detail: this.detail,
160
+ };
161
+ }
162
+ }
163
+ const API_ERROR_HINTS = {
164
+ "api-error": "Check the status and provider code, then correct the request or credentials.",
165
+ "quota-exceeded": "Add credit or raise the usage limit on the OpenAI account. Retrying will not help.",
166
+ "rate-limited": "Wait and retry, or set maxRetries to retry automatically.",
167
+ "server-error": "The provider failed. Retry later, or set maxRetries to retry automatically.",
168
+ "user-error": "Change the prompt or the input images before sending the request again.",
169
+ "moderation-blocked": "Revise the prompt or input images. Retrying the same request is blocked again.",
170
+ };
171
+ /** The image API answered with a failure. Subclasses name the cases a caller handles differently. */
172
+ export class ImageGenerationApiError extends ImageGenerationError {
173
+ status;
174
+ apiCode;
175
+ apiType;
176
+ requestId;
177
+ detail;
178
+ constructor(init, identity = DEFAULT_API_IDENTITY) {
179
+ super({
180
+ name: identity.name,
181
+ code: identity.code,
182
+ message: `Image generation request failed (${identity.code}): ${init.detail}`,
183
+ hint: API_ERROR_HINTS[identity.code],
184
+ retryable: init.retryable ?? identity.retryable,
185
+ cause: init.cause,
186
+ });
187
+ this.detail = init.detail;
188
+ this.status = init.status;
189
+ this.apiCode = init.apiCode;
190
+ this.apiType = init.apiType;
191
+ this.requestId = init.requestId;
192
+ }
193
+ dataFields() {
194
+ return {
195
+ detail: this.detail,
196
+ status: this.status,
197
+ apiCode: this.apiCode,
198
+ apiType: this.apiType,
199
+ requestId: this.requestId,
200
+ };
201
+ }
202
+ }
203
+ const API_SUBCLASS_NAMES = [
204
+ "ImageGenerationQuotaError",
205
+ "ImageGenerationRateLimitError",
206
+ "ImageGenerationServerError",
207
+ "ImageGenerationUserError",
208
+ "ImageModerationBlockedError",
209
+ ];
210
+ const DEFAULT_API_IDENTITY = { name: "ImageGenerationApiError", code: "api-error", retryable: false };
211
+ /** The account is out of quota or credit. Not retryable, even though it arrives as HTTP 429. */
212
+ export class ImageGenerationQuotaError extends ImageGenerationApiError {
213
+ constructor(init) {
214
+ super(init, { name: "ImageGenerationQuotaError", code: "quota-exceeded", retryable: false });
215
+ }
216
+ }
217
+ /** The request rate limit was hit. Retryable after a delay. */
218
+ export class ImageGenerationRateLimitError extends ImageGenerationApiError {
219
+ constructor(init) {
220
+ super(init, { name: "ImageGenerationRateLimitError", code: "rate-limited", retryable: true });
221
+ }
222
+ }
223
+ /** The provider failed with a 5xx status. Retryable. */
224
+ export class ImageGenerationServerError extends ImageGenerationApiError {
225
+ constructor(init) {
226
+ super(init, { name: "ImageGenerationServerError", code: "server-error", retryable: true });
227
+ }
228
+ }
229
+ /**
230
+ * The provider rejected the request as user-correctable (`error.type` is
231
+ * `image_generation_user_error`). Not retryable until the prompt or the input images change.
232
+ * `apiCode` is the stable discriminator, for example `moderation_blocked`.
233
+ */
234
+ export class ImageGenerationUserError extends ImageGenerationApiError {
235
+ constructor(init, identity) {
236
+ super(init, identity ?? { name: "ImageGenerationUserError", code: "user-error", retryable: false });
237
+ }
238
+ }
239
+ /** Content moderation blocked the prompt, the input images or the generated image. */
240
+ export class ImageModerationBlockedError extends ImageGenerationUserError {
241
+ /** Where the block happened, when the provider says. */
242
+ moderationStage;
243
+ /** Coarse public category labels such as `harassment` or `violence`. */
244
+ categories;
245
+ constructor(init) {
246
+ super(init, { name: "ImageModerationBlockedError", code: "moderation-blocked", retryable: false });
247
+ this.moderationStage = init.moderationStage;
248
+ this.categories = init.categories ?? [];
249
+ }
250
+ dataFields() {
251
+ return { ...super.dataFields(), moderationStage: this.moderationStage, categories: this.categories };
252
+ }
253
+ }
254
+ /** The request did not complete within `timeoutMs`. Retryable. */
255
+ export class ImageGenerationTimeoutError extends ImageGenerationError {
256
+ timeoutMs;
257
+ elapsedMs;
258
+ phase = "request";
259
+ constructor(init) {
260
+ super({
261
+ name: "ImageGenerationTimeoutError",
262
+ code: "timeout",
263
+ message: `Image generation timed out: request after ${init.elapsedMs}ms of ${init.timeoutMs}ms (timeout). Raise timeoutMs or lower the image size, count or quality.`,
264
+ hint: "Raise timeoutMs or lower the image size, count or quality.",
265
+ retryable: true,
266
+ cause: init.cause,
267
+ });
268
+ this.timeoutMs = init.timeoutMs;
269
+ this.elapsedMs = init.elapsedMs;
270
+ }
271
+ dataFields() {
272
+ return { timeoutMs: this.timeoutMs, elapsedMs: this.elapsedMs, phase: this.phase };
273
+ }
274
+ }
275
+ /** The `code` each concrete family class carries. The family base accepts any code. */
276
+ const FAMILY_CODES = {
277
+ ImageGenerationConfigError: "invalid-option",
278
+ ImageGenerationApiError: "api-error",
279
+ ImageGenerationQuotaError: "quota-exceeded",
280
+ ImageGenerationRateLimitError: "rate-limited",
281
+ ImageGenerationServerError: "server-error",
282
+ ImageGenerationUserError: "user-error",
283
+ ImageModerationBlockedError: "moderation-blocked",
284
+ ImageGenerationTimeoutError: "timeout",
285
+ };
286
+ function hasShape(value, names) {
287
+ if (typeof value !== "object" || value === null)
288
+ return false;
289
+ const { name, code } = value;
290
+ if (typeof code !== "string" || !names.includes(name))
291
+ return false;
292
+ return name === "ImageGenerationError" || FAMILY_CODES[name] === code;
293
+ }
294
+ function causeOf(error) {
295
+ return typeof error === "object" && error !== null ? error.cause : undefined;
296
+ }
297
+ /**
298
+ * Guards check the value itself: an instance of the class, or, across processes and realms, an
299
+ * object whose `name` is the class name and whose `code` is that class's code. Use
300
+ * {@link findImageGenerationError} to search a `cause` chain.
301
+ */
302
+ function guard(type, names) {
303
+ return (value) => value instanceof type || hasShape(value, names);
304
+ }
305
+ const API_NAMES = ["ImageGenerationApiError", ...API_SUBCLASS_NAMES];
306
+ const USER_NAMES = ["ImageGenerationUserError", "ImageModerationBlockedError"];
307
+ const FAMILY_NAMES = [
308
+ "ImageGenerationError",
309
+ "ImageGenerationConfigError",
310
+ "ImageGenerationTimeoutError",
311
+ ...API_NAMES,
312
+ ];
313
+ export const isImageGenerationError = guard(ImageGenerationError, FAMILY_NAMES);
314
+ export const isImageGenerationConfigError = guard(ImageGenerationConfigError, ["ImageGenerationConfigError"]);
315
+ export const isImageGenerationApiError = guard(ImageGenerationApiError, API_NAMES);
316
+ export const isImageGenerationQuotaError = guard(ImageGenerationQuotaError, ["ImageGenerationQuotaError"]);
317
+ export const isImageGenerationRateLimitError = guard(ImageGenerationRateLimitError, ["ImageGenerationRateLimitError"]);
318
+ export const isImageGenerationServerError = guard(ImageGenerationServerError, ["ImageGenerationServerError"]);
319
+ export const isImageGenerationUserError = guard(ImageGenerationUserError, USER_NAMES);
320
+ export const isImageModerationBlockedError = guard(ImageModerationBlockedError, ["ImageModerationBlockedError"]);
321
+ export const isImageGenerationTimeoutError = guard(ImageGenerationTimeoutError, ["ImageGenerationTimeoutError"]);
322
+ function isImageGenerationErrorInstance(value) {
323
+ return value instanceof ImageGenerationError;
324
+ }
325
+ export function findImageGenerationError(error, accept = isImageGenerationErrorInstance) {
326
+ let current = error;
327
+ for (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {
328
+ if (accept(current))
329
+ return current;
330
+ current = causeOf(current);
331
+ }
332
+ return undefined;
333
+ }
334
+ /** True when the nearest image-generation error in the `cause` chain says the same request may be retried. */
335
+ export function isRetryableImageGenerationError(error) {
336
+ return findImageGenerationError(error, isImageGenerationError)?.retryable === true;
337
+ }
338
+ function stringField(fields, key) {
339
+ const value = fields[key];
340
+ return typeof value === "string" ? value : undefined;
341
+ }
342
+ function numberField(fields, key) {
343
+ const value = fields[key];
344
+ return typeof value === "number" ? value : undefined;
345
+ }
346
+ function listField(fields, key) {
347
+ const value = fields[key];
348
+ return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
349
+ }
350
+ function apiInit(data, cause) {
351
+ const { fields } = data;
352
+ return {
353
+ detail: stringField(fields, "detail") ?? data.message,
354
+ status: numberField(fields, "status"),
355
+ apiCode: stringField(fields, "apiCode"),
356
+ apiType: stringField(fields, "apiType"),
357
+ requestId: stringField(fields, "requestId"),
358
+ retryable: data.retryable,
359
+ cause,
360
+ };
361
+ }
362
+ function createFromData(data, cause) {
363
+ const { fields } = data;
364
+ switch (data.name) {
365
+ case "ImageGenerationConfigError":
366
+ return new ImageGenerationConfigError({
367
+ model: stringField(fields, "model") ?? "",
368
+ field: stringField(fields, "field") ?? "",
369
+ reason: (stringField(fields, "reason") ?? "out-of-range"),
370
+ related: stringField(fields, "related"),
371
+ detail: stringField(fields, "detail") ?? data.message,
372
+ hint: data.hint ?? "",
373
+ cause,
374
+ });
375
+ case "ImageGenerationTimeoutError":
376
+ return new ImageGenerationTimeoutError({
377
+ timeoutMs: numberField(fields, "timeoutMs") ?? 0,
378
+ elapsedMs: numberField(fields, "elapsedMs") ?? 0,
379
+ cause,
380
+ });
381
+ case "ImageGenerationApiError":
382
+ return new ImageGenerationApiError(apiInit(data, cause));
383
+ case "ImageGenerationQuotaError":
384
+ return new ImageGenerationQuotaError(apiInit(data, cause));
385
+ case "ImageGenerationRateLimitError":
386
+ return new ImageGenerationRateLimitError(apiInit(data, cause));
387
+ case "ImageGenerationServerError":
388
+ return new ImageGenerationServerError(apiInit(data, cause));
389
+ case "ImageGenerationUserError":
390
+ return new ImageGenerationUserError(apiInit(data, cause));
391
+ case "ImageModerationBlockedError": {
392
+ const stage = stringField(fields, "moderationStage");
393
+ return new ImageModerationBlockedError({
394
+ ...apiInit(data, cause),
395
+ moderationStage: stage === "input" || stage === "output" || stage === "unknown" ? stage : undefined,
396
+ categories: listField(fields, "categories"),
397
+ });
398
+ }
399
+ default:
400
+ return new ImageGenerationError({
401
+ name: data.name,
402
+ code: data.code,
403
+ message: data.message,
404
+ hint: data.hint,
405
+ retryable: data.retryable,
406
+ cause,
407
+ });
408
+ }
409
+ }
410
+ function isErrorData(value) {
411
+ const { code, retryable, fields } = value;
412
+ return typeof code === "string" && typeof retryable === "boolean" && typeof fields === "object" && fields !== null;
413
+ }
414
+ function causeFromData(cause, depth) {
415
+ if (cause === undefined || depth > MAX_CAUSE_DEPTH)
416
+ return undefined;
417
+ if (isErrorData(cause))
418
+ return errorFromData(cause, depth);
419
+ const nested = causeFromData(cause.cause, depth + 1);
420
+ const error = new Error(FOREIGN_MESSAGE, nested ? { cause: nested } : undefined);
421
+ error.name = safeForeignName(cause.name);
422
+ const code = safeErrno(cause.code);
423
+ if (code)
424
+ Object.assign(error, { code });
425
+ return error;
426
+ }
427
+ function errorFromData(data, depth) {
428
+ const error = createFromData(data, causeFromData(data.cause, depth + 1));
429
+ error.message = data.message;
430
+ return error;
431
+ }
432
+ /**
433
+ * Rebuild a typed error from {@link ImageGenerationErrorData}, for example after a result crossed a
434
+ * worker or process boundary. Family causes come back as their own classes, other causes as plain
435
+ * errors, at most eight links deep. Unknown names become an {@link ImageGenerationError} that keeps
436
+ * the original `name` and `code`.
437
+ */
438
+ export function imageGenerationErrorFromData(data) {
439
+ return errorFromData(data, 1);
440
+ }
441
+ //# sourceMappingURL=image-generation-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-generation-error.js","sourceRoot":"","sources":["../src/image-generation-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAoCH,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,eAAe,GAAG,iCAAiC,CAAC;AAC1D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAChC,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,cAAc;IACd,QAAQ;IACR,UAAU;IACV,OAAO;IACP,OAAO;IACP,WAAW;IACX,cAAc;IACd,cAAc;IACd,YAAY;IACZ,cAAc;IACd,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,OAAO;IACP,QAAQ;IACR,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,UAAU;IACV,WAAW;IACX,aAAa;IACb,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,SAAS;IACT,WAAW;IACX,UAAU;IACV,SAAS;IACT,OAAO;IACP,OAAO;IACP,QAAQ;IACR,iBAAiB;IACjB,WAAW;IACX,WAAW;IACX,UAAU;IACV,YAAY;CACZ,CAAC,CAAC;AAEH,SAAS,eAAe,CAAC,IAAa;IACrC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;AAC/F,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC/B,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC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CAAC;AAED,SAAS,aAAa,CAAC,KAAwC,EAAE,KAAa;IAC7E,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,GAAG,eAAe;QAAE,OAAO,SAAS,CAAC;IACrE,IAAI,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACjF,KAAK,CAAC,IAAI,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,IAAI;QAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,IAA8B,EAAE,KAAa;IACnE,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IACzE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC7B,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAA8B;IAC1E,OAAO,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["/**\n * Typed failures of `generateImages()`.\n *\n * One family, {@link ImageGenerationError}, covers every failure the image providers can\n * classify: a rejected request configuration ({@link ImageGenerationConfigError}), an API\n * failure ({@link ImageGenerationApiError} and its subclasses) and a client-side timeout\n * ({@link ImageGenerationTimeoutError}). Branch on the class, its guard or `code`, never on\n * `message`. Cancellation is not a failure: an aborted request resolves with\n * `stopReason: \"aborted\"` and no error.\n */\n\nexport type ImageGenerationErrorFieldValue = string | number | boolean | readonly string[] | undefined;\n\n/** A foreign cause with its name, a safe errno code, and a redacted message. */\nexport interface ImageGenerationForeignCauseData {\n\tname: string;\n\tmessage: string;\n\tcode?: string;\n\tcause?: ImageGenerationErrorData | ImageGenerationForeignCauseData;\n}\n\n/** JSON-safe form of an {@link ImageGenerationError}, for results, IPC and worker boundaries. */\nexport interface ImageGenerationErrorData {\n\tname: string;\n\tcode: string;\n\tmessage: string;\n\thint?: string;\n\tretryable: boolean;\n\tfields: Record<string, ImageGenerationErrorFieldValue>;\n\t/**\n\t * The next link of the `cause` chain. Family errors keep their data; foreign errors keep their\n\t * name and known errno code, with their message redacted. At most eight links are kept.\n\t */\n\tcause?: ImageGenerationErrorData | ImageGenerationForeignCauseData;\n}\n\ninterface ImageGenerationErrorInit {\n\tname: string;\n\tcode: string;\n\tmessage: string;\n\thint?: string;\n\tretryable?: boolean;\n\tcause?: unknown;\n}\n\nconst MAX_CAUSE_DEPTH = 8;\nconst FOREIGN_MESSAGE = \"[foreign error message omitted]\";\nconst SAFE_ERRNO_CODES = new Set([\n\t\"EACCES\",\n\t\"EADDRINUSE\",\n\t\"EADDRNOTAVAIL\",\n\t\"EAFNOSUPPORT\",\n\t\"EAGAIN\",\n\t\"EALREADY\",\n\t\"EBADF\",\n\t\"EBUSY\",\n\t\"ECANCELED\",\n\t\"ECONNABORTED\",\n\t\"ECONNREFUSED\",\n\t\"ECONNRESET\",\n\t\"EDESTADDRREQ\",\n\t\"EEXIST\",\n\t\"EFAULT\",\n\t\"EHOSTUNREACH\",\n\t\"EINTR\",\n\t\"EINVAL\",\n\t\"EIO\",\n\t\"EISDIR\",\n\t\"EMFILE\",\n\t\"EMSGSIZE\",\n\t\"ENETDOWN\",\n\t\"ENETRESET\",\n\t\"ENETUNREACH\",\n\t\"ENFILE\",\n\t\"ENOENT\",\n\t\"ENOMEM\",\n\t\"ENOSPC\",\n\t\"ENOTCONN\",\n\t\"ENOTDIR\",\n\t\"ENOTFOUND\",\n\t\"ENOTSOCK\",\n\t\"ENOTSUP\",\n\t\"EPIPE\",\n\t\"EPERM\",\n\t\"EPROTO\",\n\t\"EPROTONOSUPPORT\",\n\t\"ETIMEDOUT\",\n\t\"EAI_AGAIN\",\n\t\"EAI_FAIL\",\n\t\"EAI_NONAME\",\n]);\n\nfunction safeForeignName(name: unknown): string {\n\treturn typeof name === \"string\" && /^[A-Za-z][A-Za-z0-9_]{0,79}$/.test(name) ? name : \"Error\";\n}\n\nfunction safeErrno(code: unknown): string | undefined {\n\treturn typeof code === \"string\" && SAFE_ERRNO_CODES.has(code) ? code : undefined;\n}\n\nfunction sanitizeCause(cause: unknown, depth: number): Error | undefined {\n\tif (depth > MAX_CAUSE_DEPTH || !(cause instanceof Error)) return undefined;\n\tif (cause instanceof ImageGenerationError) return cause;\n\tconst nested = sanitizeCause(cause.cause, depth + 1);\n\tconst safe = new Error(FOREIGN_MESSAGE, nested ? { cause: nested } : undefined);\n\tsafe.name = safeForeignName(cause.name);\n\tconst code = safeErrno((cause as Error & { code?: unknown }).code);\n\tif (code) Object.assign(safe, { code });\n\treturn safe;\n}\n\n/** Base of every typed image-generation failure. */\nexport class ImageGenerationError extends Error {\n\toverride readonly name: string;\n\treadonly code: string;\n\t/** True when the same request may succeed if sent again unchanged. */\n\treadonly retryable: boolean;\n\treadonly hint?: string;\n\n\tconstructor(init: ImageGenerationErrorInit) {\n\t\tsuper(init.message, { cause: sanitizeCause(init.cause, 2) });\n\t\tthis.name = init.name;\n\t\tthis.code = init.code;\n\t\tthis.retryable = init.retryable ?? false;\n\t\tthis.hint = init.hint;\n\t}\n\n\t/** Safe, JSON-serializable context for this failure. Overridden by classes that carry fields. */\n\tprotected dataFields(): Record<string, ImageGenerationErrorFieldValue> {\n\t\treturn {};\n\t}\n\n\ttoData(): ImageGenerationErrorData {\n\t\treturn this.dataWithCauses(1);\n\t}\n\n\tprivate static causeData(\n\t\tcause: unknown,\n\t\tdepth: number,\n\t): ImageGenerationErrorData | ImageGenerationForeignCauseData | undefined {\n\t\tif (depth > MAX_CAUSE_DEPTH || !(cause instanceof Error)) return undefined;\n\t\tif (cause instanceof ImageGenerationError) return cause.dataWithCauses(depth);\n\t\tconst code = safeErrno((cause as Error & { code?: unknown }).code);\n\t\tconst nested = ImageGenerationError.causeData(cause.cause, depth + 1);\n\t\treturn {\n\t\t\tname: safeForeignName(cause.name),\n\t\t\tmessage: FOREIGN_MESSAGE,\n\t\t\t...(code ? { code } : {}),\n\t\t\t...(nested ? { cause: nested } : {}),\n\t\t};\n\t}\n\n\tprivate dataWithCauses(depth: number): ImageGenerationErrorData {\n\t\tconst causeData = ImageGenerationError.causeData(this.cause, depth + 1);\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tcode: this.code,\n\t\t\tmessage: this.message,\n\t\t\t...(this.hint !== undefined ? { hint: this.hint } : {}),\n\t\t\tretryable: this.retryable,\n\t\t\tfields: this.dataFields(),\n\t\t\t...(causeData ? { cause: causeData } : {}),\n\t\t};\n\t}\n\n\ttoJSON(): ImageGenerationErrorData {\n\t\treturn this.toData();\n\t}\n}\n\nexport type ImageGenerationConfigReason =\n\t| \"out-of-range\"\n\t| \"requires-option\"\n\t| \"conflicts-with-option\"\n\t| \"generation-only\"\n\t| \"unsupported-by-model\"\n\t| \"requires-base-image\"\n\t| \"duplicate-role\";\n\nexport interface ImageGenerationConfigErrorInit {\n\tmodel: string;\n\tfield: string;\n\treason: ImageGenerationConfigReason;\n\t/** The other option or request part that `field` conflicts with or depends on. */\n\trelated?: string;\n\t/** What is wrong, in words. Names options only and never echoes prompt or image content. */\n\tdetail: string;\n\thint: string;\n\tcause?: unknown;\n}\n\n/**\n * The request options or input are invalid. Thrown before any request is sent, so nothing was\n * billed and retrying the same request fails the same way.\n */\nexport class ImageGenerationConfigError extends ImageGenerationError {\n\tdeclare readonly name: \"ImageGenerationConfigError\";\n\tdeclare readonly code: \"invalid-option\";\n\treadonly source = \"sdk\" as const;\n\treadonly model: string;\n\treadonly field: string;\n\treadonly reason: ImageGenerationConfigReason;\n\treadonly related?: string;\n\treadonly detail: string;\n\n\tconstructor(init: ImageGenerationConfigErrorInit) {\n\t\tsuper({\n\t\t\tname: \"ImageGenerationConfigError\",\n\t\t\tcode: \"invalid-option\",\n\t\t\tmessage: `Invalid image generation option: ${init.field} for ${init.model} (invalid-option). ${init.detail}. ${init.hint}`,\n\t\t\thint: init.hint,\n\t\t\tcause: init.cause,\n\t\t});\n\t\tthis.model = init.model;\n\t\tthis.field = init.field;\n\t\tthis.reason = init.reason;\n\t\tthis.related = init.related;\n\t\tthis.detail = init.detail;\n\t}\n\n\tprotected override dataFields(): Record<string, ImageGenerationErrorFieldValue> {\n\t\treturn {\n\t\t\tsource: this.source,\n\t\t\tmodel: this.model,\n\t\t\tfield: this.field,\n\t\t\treason: this.reason,\n\t\t\trelated: this.related,\n\t\t\tdetail: this.detail,\n\t\t};\n\t}\n}\n\nexport type ImageGenerationApiErrorCode =\n\t| \"api-error\"\n\t| \"quota-exceeded\"\n\t| \"rate-limited\"\n\t| \"server-error\"\n\t| \"user-error\"\n\t| \"moderation-blocked\";\n\nexport interface ImageGenerationApiErrorInit {\n\t/**\n\t * A summary built from the HTTP status and the provider's type, code and request ID. Never the\n\t * provider's message, which can quote the prompt.\n\t */\n\tdetail: string;\n\tstatus?: number;\n\t/** The provider's `error.code`, for example `insufficient_quota` or `moderation_blocked`. */\n\tapiCode?: string;\n\t/** The provider's `error.type`, for example `image_generation_user_error`. */\n\tapiType?: string;\n\trequestId?: string;\n\tretryable?: boolean;\n\tcause?: unknown;\n}\n\nconst API_ERROR_HINTS = {\n\t\"api-error\": \"Check the status and provider code, then correct the request or credentials.\",\n\t\"quota-exceeded\": \"Add credit or raise the usage limit on the OpenAI account. Retrying will not help.\",\n\t\"rate-limited\": \"Wait and retry, or set maxRetries to retry automatically.\",\n\t\"server-error\": \"The provider failed. Retry later, or set maxRetries to retry automatically.\",\n\t\"user-error\": \"Change the prompt or the input images before sending the request again.\",\n\t\"moderation-blocked\": \"Revise the prompt or input images. Retrying the same request is blocked again.\",\n} as const satisfies Record<ImageGenerationApiErrorCode, string>;\n\n/** The image API answered with a failure. Subclasses name the cases a caller handles differently. */\nexport class ImageGenerationApiError extends ImageGenerationError {\n\tdeclare readonly name: \"ImageGenerationApiError\" | (typeof API_SUBCLASS_NAMES)[number];\n\tdeclare readonly code: ImageGenerationApiErrorCode;\n\treadonly status?: number;\n\treadonly apiCode?: string;\n\treadonly apiType?: string;\n\treadonly requestId?: string;\n\treadonly detail: string;\n\n\tconstructor(init: ImageGenerationApiErrorInit, identity: ApiErrorIdentity = DEFAULT_API_IDENTITY) {\n\t\tsuper({\n\t\t\tname: identity.name,\n\t\t\tcode: identity.code,\n\t\t\tmessage: `Image generation request failed (${identity.code}): ${init.detail}`,\n\t\t\thint: API_ERROR_HINTS[identity.code],\n\t\t\tretryable: init.retryable ?? identity.retryable,\n\t\t\tcause: init.cause,\n\t\t});\n\t\tthis.detail = init.detail;\n\t\tthis.status = init.status;\n\t\tthis.apiCode = init.apiCode;\n\t\tthis.apiType = init.apiType;\n\t\tthis.requestId = init.requestId;\n\t}\n\n\tprotected override dataFields(): Record<string, ImageGenerationErrorFieldValue> {\n\t\treturn {\n\t\t\tdetail: this.detail,\n\t\t\tstatus: this.status,\n\t\t\tapiCode: this.apiCode,\n\t\t\tapiType: this.apiType,\n\t\t\trequestId: this.requestId,\n\t\t};\n\t}\n}\n\nconst API_SUBCLASS_NAMES = [\n\t\"ImageGenerationQuotaError\",\n\t\"ImageGenerationRateLimitError\",\n\t\"ImageGenerationServerError\",\n\t\"ImageGenerationUserError\",\n\t\"ImageModerationBlockedError\",\n] as const;\n\ninterface ApiErrorIdentity {\n\tname: ImageGenerationApiError[\"name\"];\n\tcode: ImageGenerationApiErrorCode;\n\tretryable: boolean;\n}\n\nconst DEFAULT_API_IDENTITY: ApiErrorIdentity = { name: \"ImageGenerationApiError\", code: \"api-error\", retryable: false };\n\n/** The account is out of quota or credit. Not retryable, even though it arrives as HTTP 429. */\nexport class ImageGenerationQuotaError extends ImageGenerationApiError {\n\tdeclare readonly name: \"ImageGenerationQuotaError\";\n\tdeclare readonly code: \"quota-exceeded\";\n\tconstructor(init: ImageGenerationApiErrorInit) {\n\t\tsuper(init, { name: \"ImageGenerationQuotaError\", code: \"quota-exceeded\", retryable: false });\n\t}\n}\n\n/** The request rate limit was hit. Retryable after a delay. */\nexport class ImageGenerationRateLimitError extends ImageGenerationApiError {\n\tdeclare readonly name: \"ImageGenerationRateLimitError\";\n\tdeclare readonly code: \"rate-limited\";\n\tconstructor(init: ImageGenerationApiErrorInit) {\n\t\tsuper(init, { name: \"ImageGenerationRateLimitError\", code: \"rate-limited\", retryable: true });\n\t}\n}\n\n/** The provider failed with a 5xx status. Retryable. */\nexport class ImageGenerationServerError extends ImageGenerationApiError {\n\tdeclare readonly name: \"ImageGenerationServerError\";\n\tdeclare readonly code: \"server-error\";\n\tconstructor(init: ImageGenerationApiErrorInit) {\n\t\tsuper(init, { name: \"ImageGenerationServerError\", code: \"server-error\", retryable: true });\n\t}\n}\n\n/**\n * The provider rejected the request as user-correctable (`error.type` is\n * `image_generation_user_error`). Not retryable until the prompt or the input images change.\n * `apiCode` is the stable discriminator, for example `moderation_blocked`.\n */\nexport class ImageGenerationUserError extends ImageGenerationApiError {\n\tdeclare readonly name: \"ImageGenerationUserError\" | \"ImageModerationBlockedError\";\n\tdeclare readonly code: \"user-error\" | \"moderation-blocked\";\n\tconstructor(init: ImageGenerationApiErrorInit, identity?: ApiErrorIdentity) {\n\t\tsuper(init, identity ?? { name: \"ImageGenerationUserError\", code: \"user-error\", retryable: false });\n\t}\n}\n\nexport type ImageModerationStage = \"input\" | \"output\" | \"unknown\";\n\nexport interface ImageModerationBlockedErrorInit extends ImageGenerationApiErrorInit {\n\tmoderationStage?: ImageModerationStage;\n\tcategories?: readonly string[];\n}\n\n/** Content moderation blocked the prompt, the input images or the generated image. */\nexport class ImageModerationBlockedError extends ImageGenerationUserError {\n\tdeclare readonly name: \"ImageModerationBlockedError\";\n\tdeclare readonly code: \"moderation-blocked\";\n\t/** Where the block happened, when the provider says. */\n\treadonly moderationStage?: ImageModerationStage;\n\t/** Coarse public category labels such as `harassment` or `violence`. */\n\treadonly categories: readonly string[];\n\n\tconstructor(init: ImageModerationBlockedErrorInit) {\n\t\tsuper(init, { name: \"ImageModerationBlockedError\", code: \"moderation-blocked\", retryable: false });\n\t\tthis.moderationStage = init.moderationStage;\n\t\tthis.categories = init.categories ?? [];\n\t}\n\n\tprotected override dataFields(): Record<string, ImageGenerationErrorFieldValue> {\n\t\treturn { ...super.dataFields(), moderationStage: this.moderationStage, categories: this.categories };\n\t}\n}\n\nexport interface ImageGenerationTimeoutErrorInit {\n\ttimeoutMs: number;\n\telapsedMs: number;\n\tcause?: unknown;\n}\n\n/** The request did not complete within `timeoutMs`. Retryable. */\nexport class ImageGenerationTimeoutError extends ImageGenerationError {\n\tdeclare readonly name: \"ImageGenerationTimeoutError\";\n\tdeclare readonly code: \"timeout\";\n\treadonly timeoutMs: number;\n\treadonly elapsedMs: number;\n\treadonly phase = \"request\" as const;\n\n\tconstructor(init: ImageGenerationTimeoutErrorInit) {\n\t\tsuper({\n\t\t\tname: \"ImageGenerationTimeoutError\",\n\t\t\tcode: \"timeout\",\n\t\t\tmessage: `Image generation timed out: request after ${init.elapsedMs}ms of ${init.timeoutMs}ms (timeout). Raise timeoutMs or lower the image size, count or quality.`,\n\t\t\thint: \"Raise timeoutMs or lower the image size, count or quality.\",\n\t\t\tretryable: true,\n\t\t\tcause: init.cause,\n\t\t});\n\t\tthis.timeoutMs = init.timeoutMs;\n\t\tthis.elapsedMs = init.elapsedMs;\n\t}\n\n\tprotected override dataFields(): Record<string, ImageGenerationErrorFieldValue> {\n\t\treturn { timeoutMs: this.timeoutMs, elapsedMs: this.elapsedMs, phase: this.phase };\n\t}\n}\n\n/** The `code` each concrete family class carries. The family base accepts any code. */\nconst FAMILY_CODES = {\n\tImageGenerationConfigError: \"invalid-option\",\n\tImageGenerationApiError: \"api-error\",\n\tImageGenerationQuotaError: \"quota-exceeded\",\n\tImageGenerationRateLimitError: \"rate-limited\",\n\tImageGenerationServerError: \"server-error\",\n\tImageGenerationUserError: \"user-error\",\n\tImageModerationBlockedError: \"moderation-blocked\",\n\tImageGenerationTimeoutError: \"timeout\",\n} as const;\n\ntype FamilyName = keyof typeof FAMILY_CODES | \"ImageGenerationError\";\n\nfunction hasShape(value: unknown, names: readonly FamilyName[]): boolean {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst { name, code } = value as { name?: unknown; code?: unknown };\n\tif (typeof code !== \"string\" || !(names as readonly unknown[]).includes(name)) return false;\n\treturn name === \"ImageGenerationError\" || FAMILY_CODES[name as keyof typeof FAMILY_CODES] === code;\n}\n\nfunction causeOf(error: unknown): unknown {\n\treturn typeof error === \"object\" && error !== null ? (error as { cause?: unknown }).cause : undefined;\n}\n\n/**\n * Guards check the value itself: an instance of the class, or, across processes and realms, an\n * object whose `name` is the class name and whose `code` is that class's code. Use\n * {@link findImageGenerationError} to search a `cause` chain.\n */\nfunction guard<T extends ImageGenerationError>(\n\ttype: abstract new (...args: never[]) => T,\n\tnames: readonly FamilyName[],\n): (value: unknown) => value is T {\n\treturn (value: unknown): value is T => value instanceof type || hasShape(value, names);\n}\n\nconst API_NAMES = [\"ImageGenerationApiError\", ...API_SUBCLASS_NAMES] as const;\nconst USER_NAMES = [\"ImageGenerationUserError\", \"ImageModerationBlockedError\"] as const;\nconst FAMILY_NAMES = [\n\t\"ImageGenerationError\",\n\t\"ImageGenerationConfigError\",\n\t\"ImageGenerationTimeoutError\",\n\t...API_NAMES,\n] as const;\n\nexport const isImageGenerationError = guard(ImageGenerationError, FAMILY_NAMES);\nexport const isImageGenerationConfigError = guard(ImageGenerationConfigError, [\"ImageGenerationConfigError\"]);\nexport const isImageGenerationApiError = guard(ImageGenerationApiError, API_NAMES);\nexport const isImageGenerationQuotaError = guard(ImageGenerationQuotaError, [\"ImageGenerationQuotaError\"]);\nexport const isImageGenerationRateLimitError = guard(ImageGenerationRateLimitError, [\"ImageGenerationRateLimitError\"]);\nexport const isImageGenerationServerError = guard(ImageGenerationServerError, [\"ImageGenerationServerError\"]);\nexport const isImageGenerationUserError = guard(ImageGenerationUserError, USER_NAMES);\nexport const isImageModerationBlockedError = guard(ImageModerationBlockedError, [\"ImageModerationBlockedError\"]);\nexport const isImageGenerationTimeoutError = guard(ImageGenerationTimeoutError, [\"ImageGenerationTimeoutError\"]);\n\nfunction isImageGenerationErrorInstance(value: unknown): value is ImageGenerationError {\n\treturn value instanceof ImageGenerationError;\n}\n\n/**\n * Search the error and its `cause` chain, at most eight links, for the first value `guard` accepts.\n * Without a guard, returns the nearest {@link ImageGenerationError} instance, for example\n * `findImageGenerationError(error, isImageGenerationQuotaError)`.\n */\nexport function findImageGenerationError(error: unknown): ImageGenerationError | undefined;\nexport function findImageGenerationError<T>(error: unknown, guard: (value: unknown) => value is T): T | undefined;\nexport function findImageGenerationError(\n\terror: unknown,\n\taccept: (value: unknown) => boolean = isImageGenerationErrorInstance,\n): unknown {\n\tlet current: unknown = error;\n\tfor (let depth = 0; depth < MAX_CAUSE_DEPTH; depth++) {\n\t\tif (accept(current)) return current;\n\t\tcurrent = causeOf(current);\n\t}\n\treturn undefined;\n}\n\n/** True when the nearest image-generation error in the `cause` chain says the same request may be retried. */\nexport function isRetryableImageGenerationError(error: unknown): boolean {\n\treturn findImageGenerationError(error, isImageGenerationError)?.retryable === true;\n}\n\nfunction stringField(fields: ImageGenerationErrorData[\"fields\"], key: string): string | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction numberField(fields: ImageGenerationErrorData[\"fields\"], key: string): number | undefined {\n\tconst value = fields[key];\n\treturn typeof value === \"number\" ? value : undefined;\n}\n\nfunction listField(fields: ImageGenerationErrorData[\"fields\"], key: string): readonly string[] {\n\tconst value = fields[key];\n\treturn Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === \"string\") : [];\n}\n\nfunction apiInit(data: ImageGenerationErrorData, cause: Error | undefined): ImageGenerationApiErrorInit {\n\tconst { fields } = data;\n\treturn {\n\t\tdetail: stringField(fields, \"detail\") ?? data.message,\n\t\tstatus: numberField(fields, \"status\"),\n\t\tapiCode: stringField(fields, \"apiCode\"),\n\t\tapiType: stringField(fields, \"apiType\"),\n\t\trequestId: stringField(fields, \"requestId\"),\n\t\tretryable: data.retryable,\n\t\tcause,\n\t};\n}\n\nfunction createFromData(data: ImageGenerationErrorData, cause: Error | undefined): ImageGenerationError {\n\tconst { fields } = data;\n\tswitch (data.name) {\n\t\tcase \"ImageGenerationConfigError\":\n\t\t\treturn new ImageGenerationConfigError({\n\t\t\t\tmodel: stringField(fields, \"model\") ?? \"\",\n\t\t\t\tfield: stringField(fields, \"field\") ?? \"\",\n\t\t\t\treason: (stringField(fields, \"reason\") ?? \"out-of-range\") as ImageGenerationConfigReason,\n\t\t\t\trelated: stringField(fields, \"related\"),\n\t\t\t\tdetail: stringField(fields, \"detail\") ?? data.message,\n\t\t\t\thint: data.hint ?? \"\",\n\t\t\t\tcause,\n\t\t\t});\n\t\tcase \"ImageGenerationTimeoutError\":\n\t\t\treturn new ImageGenerationTimeoutError({\n\t\t\t\ttimeoutMs: numberField(fields, \"timeoutMs\") ?? 0,\n\t\t\t\telapsedMs: numberField(fields, \"elapsedMs\") ?? 0,\n\t\t\t\tcause,\n\t\t\t});\n\t\tcase \"ImageGenerationApiError\":\n\t\t\treturn new ImageGenerationApiError(apiInit(data, cause));\n\t\tcase \"ImageGenerationQuotaError\":\n\t\t\treturn new ImageGenerationQuotaError(apiInit(data, cause));\n\t\tcase \"ImageGenerationRateLimitError\":\n\t\t\treturn new ImageGenerationRateLimitError(apiInit(data, cause));\n\t\tcase \"ImageGenerationServerError\":\n\t\t\treturn new ImageGenerationServerError(apiInit(data, cause));\n\t\tcase \"ImageGenerationUserError\":\n\t\t\treturn new ImageGenerationUserError(apiInit(data, cause));\n\t\tcase \"ImageModerationBlockedError\": {\n\t\t\tconst stage = stringField(fields, \"moderationStage\");\n\t\t\treturn new ImageModerationBlockedError({\n\t\t\t\t...apiInit(data, cause),\n\t\t\t\tmoderationStage: stage === \"input\" || stage === \"output\" || stage === \"unknown\" ? stage : undefined,\n\t\t\t\tcategories: listField(fields, \"categories\"),\n\t\t\t});\n\t\t}\n\t\tdefault:\n\t\t\treturn new ImageGenerationError({\n\t\t\t\tname: data.name,\n\t\t\t\tcode: data.code,\n\t\t\t\tmessage: data.message,\n\t\t\t\thint: data.hint,\n\t\t\t\tretryable: data.retryable,\n\t\t\t\tcause,\n\t\t\t});\n\t}\n}\n\nfunction isErrorData(value: ImageGenerationErrorData[\"cause\"]): value is ImageGenerationErrorData {\n\tconst { code, retryable, fields } = value as Partial<ImageGenerationErrorData>;\n\treturn typeof code === \"string\" && typeof retryable === \"boolean\" && typeof fields === \"object\" && fields !== null;\n}\n\nfunction causeFromData(cause: ImageGenerationErrorData[\"cause\"], depth: number): Error | undefined {\n\tif (cause === undefined || depth > MAX_CAUSE_DEPTH) return undefined;\n\tif (isErrorData(cause)) return errorFromData(cause, depth);\n\tconst nested = causeFromData(cause.cause, depth + 1);\n\tconst error = new Error(FOREIGN_MESSAGE, nested ? { cause: nested } : undefined);\n\terror.name = safeForeignName(cause.name);\n\tconst code = safeErrno(cause.code);\n\tif (code) Object.assign(error, { code });\n\treturn error;\n}\n\nfunction errorFromData(data: ImageGenerationErrorData, depth: number): ImageGenerationError {\n\tconst error = createFromData(data, causeFromData(data.cause, depth + 1));\n\terror.message = data.message;\n\treturn error;\n}\n\n/**\n * Rebuild a typed error from {@link ImageGenerationErrorData}, for example after a result crossed a\n * worker or process boundary. Family causes come back as their own classes, other causes as plain\n * errors, at most eight links deep. Unknown names become an {@link ImageGenerationError} that keeps\n * the original `name` and `code`.\n */\nexport function imageGenerationErrorFromData(data: ImageGenerationErrorData): ImageGenerationError {\n\treturn errorFromData(data, 1);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export * from "./api/lazy.ts";
10
10
  export type { MistralOptions } from "./api/mistral-conversations.ts";
11
11
  export type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from "./api/openai-codex-responses.ts";
12
12
  export type { OpenAICompletionsOptions } from "./api/openai-completions.ts";
13
- export type { OpenAIImagesOptions } from "./api/openai-images.ts";
13
+ export { OPENAI_IMAGES_LIMITS, type OpenAIImagesOptions, type OpenAIImagesOutputFormat, type OpenAIImagesSvgOptions, } from "./api/openai-images-options.ts";
14
14
  export type { OpenAIResponsesOptions } from "./api/openai-responses.ts";
15
15
  export type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from "./api/pi-messages.ts";
16
16
  export * from "./auth/context.ts";
@@ -21,10 +21,13 @@ export * from "./auth/types.ts";
21
21
  export type { OAuthAuthInfo, OAuthDeviceCodeInfo, OAuthLoginCallbacks, OAuthPrompt, OAuthSelectOption, OAuthSelectPrompt, } from "./compat/extension-oauth-types.ts";
22
22
  export * from "./decision-models.ts";
23
23
  export { containsKnownEnvCredential } from "./env-api-keys.ts";
24
+ export * from "./image-generation-error.ts";
24
25
  export * from "./models.ts";
25
26
  export * from "./models-store.ts";
26
27
  export { normalizeProviderId } from "./provider-id.ts";
27
28
  export * from "./providers/faux.ts";
29
+ export * from "./providers/github-copilot-capabilities.ts";
30
+ export * from "./providers/github-copilot-errors.ts";
28
31
  export * from "./session-resources.ts";
29
32
  export * from "./types.ts";
30
33
  export * from "./utils/diagnostics.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,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yBAAyB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Type } from "typebox";
2
2
  export * from "./api/lazy.js";
3
+ export { OPENAI_IMAGES_LIMITS, } from "./api/openai-images-options.js";
3
4
  export * from "./auth/context.js";
4
5
  export * from "./auth/credential-store.js";
5
6
  export * from "./auth/helpers.js";
@@ -7,10 +8,13 @@ export { isOAuthRefreshRejectedError, isPermanentRefreshRejection, OAuthRefreshR
7
8
  export * from "./auth/types.js";
8
9
  export * from "./decision-models.js";
9
10
  export { containsKnownEnvCredential } from "./env-api-keys.js";
11
+ export * from "./image-generation-error.js";
10
12
  export * from "./models.js";
11
13
  export * from "./models-store.js";
12
14
  export { normalizeProviderId } from "./provider-id.js";
13
15
  export * from "./providers/faux.js";
16
+ export * from "./providers/github-copilot-capabilities.js";
17
+ export * from "./providers/github-copilot-errors.js";
14
18
  export * from "./session-resources.js";
15
19
  export * from "./types.js";
16
20
  export * from "./utils/diagnostics.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAO9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACN,2BAA2B,EAC3B,2BAA2B,EAE3B,yBAAyB,EAEzB,mBAAmB,GACnB,MAAM,gCAAgC,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAShC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type { Static, TSchema } from \"typebox\";\nexport { Type } from \"typebox\";\n\n// Core only, side-effect free: no generated catalogs, no provider factories,\n// no api-registry, no OAuth implementations, no compat. Provider factories\n// live under \"@bastani/pi-ai/providers/*\", API implementations under\n// \"@bastani/pi-ai/api/*\", the old global API under\n// \"@bastani/pi-ai/compat\".\nexport type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay } from \"./api/anthropic-messages.ts\";\nexport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nexport type { BedrockOptions, BedrockThinkingDisplay } from \"./api/bedrock-converse-stream.ts\";\nexport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nexport type { GoogleApiThinkingLevel, ResolvedGoogleThinkingLevel } from \"./api/google-shared.ts\";\nexport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nexport * from \"./api/lazy.ts\";\nexport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nexport type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from \"./api/openai-codex-responses.ts\";\nexport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nexport type { OpenAIImagesOptions } from \"./api/openai-images.ts\";\nexport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nexport type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from \"./api/pi-messages.ts\";\nexport * from \"./auth/context.ts\";\nexport * from \"./auth/credential-store.ts\";\nexport * from \"./auth/helpers.ts\";\nexport {\n\tisOAuthRefreshRejectedError,\n\tisPermanentRefreshRejection,\n\ttype OAuthErrorDetail,\n\tOAuthRefreshRejectedError,\n\ttype OAuthRefreshRejection,\n\tparseOAuthErrorBody,\n} from \"./auth/oauth-refresh-errors.ts\";\nexport * from \"./auth/types.ts\";\nexport type {\n\tOAuthAuthInfo,\n\tOAuthDeviceCodeInfo,\n\tOAuthLoginCallbacks,\n\tOAuthPrompt,\n\tOAuthSelectOption,\n\tOAuthSelectPrompt,\n} from \"./compat/extension-oauth-types.ts\";\nexport * from \"./decision-models.ts\";\nexport { containsKnownEnvCredential } from \"./env-api-keys.ts\";\nexport * from \"./models.ts\";\nexport * from \"./models-store.ts\";\nexport { normalizeProviderId } from \"./provider-id.ts\";\nexport * from \"./providers/faux.ts\";\nexport * from \"./session-resources.ts\";\nexport * from \"./types.ts\";\nexport * from \"./utils/diagnostics.ts\";\nexport * from \"./utils/event-stream.ts\";\nexport { AssistantMessageEventStream } from \"./utils/event-stream.ts\";\nexport * from \"./utils/identity.ts\";\nexport * from \"./utils/json-parse.ts\";\nexport * from \"./utils/overflow.ts\";\nexport * from \"./utils/retry.ts\";\nexport * from \"./utils/stream-deadline.ts\";\nexport * from \"./utils/streaming-json.ts\";\nexport { contentText, getSystemMessageText, renderSystemMessageUpdate } from \"./utils/text.ts\";\nexport * from \"./utils/transcript.ts\";\nexport * from \"./utils/typebox-helpers.ts\";\nexport { uuidv7 } from \"./utils/uuid.ts\";\nexport * from \"./utils/validation.ts\";\nexport { PI_AI_VERSION } from \"./utils/version.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAa/B,cAAc,eAAe,CAAC;AAI9B,OAAO,EACN,oBAAoB,GAIpB,MAAM,gCAAgC,CAAC;AAGxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACN,2BAA2B,EAC3B,2BAA2B,EAE3B,yBAAyB,EAEzB,mBAAmB,GACnB,MAAM,gCAAgC,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAShC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export type { Static, TSchema } from \"typebox\";\nexport { Type } from \"typebox\";\n\n// Core only, side-effect free: no generated catalogs, no provider factories,\n// no api-registry, no OAuth implementations, no compat. Provider factories\n// live under \"@bastani/pi-ai/providers/*\", API implementations under\n// \"@bastani/pi-ai/api/*\", the old global API under\n// \"@bastani/pi-ai/compat\".\nexport type { AnthropicEffort, AnthropicOptions, AnthropicThinkingDisplay } from \"./api/anthropic-messages.ts\";\nexport type { AzureOpenAIResponsesOptions } from \"./api/azure-openai-responses.ts\";\nexport type { BedrockOptions, BedrockThinkingDisplay } from \"./api/bedrock-converse-stream.ts\";\nexport type { GoogleOptions } from \"./api/google-generative-ai.ts\";\nexport type { GoogleApiThinkingLevel, ResolvedGoogleThinkingLevel } from \"./api/google-shared.ts\";\nexport type { GoogleVertexOptions } from \"./api/google-vertex.ts\";\nexport * from \"./api/lazy.ts\";\nexport type { MistralOptions } from \"./api/mistral-conversations.ts\";\nexport type { OpenAICodexResponsesOptions, OpenAICodexWebSocketDebugStats } from \"./api/openai-codex-responses.ts\";\nexport type { OpenAICompletionsOptions } from \"./api/openai-completions.ts\";\nexport {\n\tOPENAI_IMAGES_LIMITS,\n\ttype OpenAIImagesOptions,\n\ttype OpenAIImagesOutputFormat,\n\ttype OpenAIImagesSvgOptions,\n} from \"./api/openai-images-options.ts\";\nexport type { OpenAIResponsesOptions } from \"./api/openai-responses.ts\";\nexport type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from \"./api/pi-messages.ts\";\nexport * from \"./auth/context.ts\";\nexport * from \"./auth/credential-store.ts\";\nexport * from \"./auth/helpers.ts\";\nexport {\n\tisOAuthRefreshRejectedError,\n\tisPermanentRefreshRejection,\n\ttype OAuthErrorDetail,\n\tOAuthRefreshRejectedError,\n\ttype OAuthRefreshRejection,\n\tparseOAuthErrorBody,\n} from \"./auth/oauth-refresh-errors.ts\";\nexport * from \"./auth/types.ts\";\nexport type {\n\tOAuthAuthInfo,\n\tOAuthDeviceCodeInfo,\n\tOAuthLoginCallbacks,\n\tOAuthPrompt,\n\tOAuthSelectOption,\n\tOAuthSelectPrompt,\n} from \"./compat/extension-oauth-types.ts\";\nexport * from \"./decision-models.ts\";\nexport { containsKnownEnvCredential } from \"./env-api-keys.ts\";\nexport * from \"./image-generation-error.ts\";\nexport * from \"./models.ts\";\nexport * from \"./models-store.ts\";\nexport { normalizeProviderId } from \"./provider-id.ts\";\nexport * from \"./providers/faux.ts\";\nexport * from \"./providers/github-copilot-capabilities.ts\";\nexport * from \"./providers/github-copilot-errors.ts\";\nexport * from \"./session-resources.ts\";\nexport * from \"./types.ts\";\nexport * from \"./utils/diagnostics.ts\";\nexport * from \"./utils/event-stream.ts\";\nexport { AssistantMessageEventStream } from \"./utils/event-stream.ts\";\nexport * from \"./utils/identity.ts\";\nexport * from \"./utils/json-parse.ts\";\nexport * from \"./utils/overflow.ts\";\nexport * from \"./utils/retry.ts\";\nexport * from \"./utils/stream-deadline.ts\";\nexport * from \"./utils/streaming-json.ts\";\nexport { contentText, getSystemMessageText, renderSystemMessageUpdate } from \"./utils/text.ts\";\nexport * from \"./utils/transcript.ts\";\nexport * from \"./utils/typebox-helpers.ts\";\nexport { uuidv7 } from \"./utils/uuid.ts\";\nexport * from \"./utils/validation.ts\";\nexport { PI_AI_VERSION } from \"./utils/version.ts\";\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Registers a bedrock loader with a literal dynamic import, for Node bundles
3
+ * that split at dynamic imports (esbuild `splitting`, Chord's worker base):
4
+ * the implementation and the AWS SDK land in a chunk loaded on the first
5
+ * bedrock request, inside the bundle. Without it, pi-ai imports bedrock
6
+ * through a variable specifier that bundlers cannot follow, so a bundle loads
7
+ * it from pi-ai's own files. Browser bundles must not import this module.
8
+ */
9
+ export declare function registerLazyBedrockProvider(): void;
10
+ //# sourceMappingURL=lazy-bedrock-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-bedrock-provider.d.ts","sourceRoot":"","sources":["../src/lazy-bedrock-provider.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,IAAI,IAAI,CAElD"}
@@ -0,0 +1,13 @@
1
+ import { setBedrockProviderLoader } from "./api/bedrock-converse-stream.lazy.js";
2
+ /**
3
+ * Registers a bedrock loader with a literal dynamic import, for Node bundles
4
+ * that split at dynamic imports (esbuild `splitting`, Chord's worker base):
5
+ * the implementation and the AWS SDK land in a chunk loaded on the first
6
+ * bedrock request, inside the bundle. Without it, pi-ai imports bedrock
7
+ * through a variable specifier that bundlers cannot follow, so a bundle loads
8
+ * it from pi-ai's own files. Browser bundles must not import this module.
9
+ */
10
+ export function registerLazyBedrockProvider() {
11
+ setBedrockProviderLoader(() => import("./api/bedrock-converse-stream.js"));
12
+ }
13
+ //# sourceMappingURL=lazy-bedrock-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-bedrock-provider.js","sourceRoot":"","sources":["../src/lazy-bedrock-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAEjF;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B;IAC1C,wBAAwB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,kCAAkC,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import { setBedrockProviderLoader } from \"./api/bedrock-converse-stream.lazy.ts\";\n\n/**\n * Registers a bedrock loader with a literal dynamic import, for Node bundles\n * that split at dynamic imports (esbuild `splitting`, Chord's worker base):\n * the implementation and the AWS SDK land in a chunk loaded on the first\n * bedrock request, inside the bundle. Without it, pi-ai imports bedrock\n * through a variable specifier that bundlers cannot follow, so a bundle loads\n * it from pi-ai's own files. Browser bundles must not import this module.\n */\nexport function registerLazyBedrockProvider(): void {\n\tsetBedrockProviderLoader(() => import(\"./api/bedrock-converse-stream.ts\"));\n}\n"]}