@aeye/google 0.0.0-stage → 0.11.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/README.md +118 -2
- package/aeye-google.md +123 -0
- package/dist/convert.d.ts +191 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +539 -0
- package/dist/convert.js.map +1 -0
- package/dist/decisions.d.ts +97 -0
- package/dist/decisions.d.ts.map +1 -0
- package/dist/decisions.js +62 -0
- package/dist/decisions.js.map +1 -0
- package/dist/google.d.ts +494 -0
- package/dist/google.d.ts.map +1 -0
- package/dist/google.js +1366 -0
- package/dist/google.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +56 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +143 -0
- package/dist/media.js.map +1 -0
- package/dist/models.d.ts +133 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +126 -0
- package/dist/models.js.map +1 -0
- package/dist/retry.d.ts +112 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +234 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +76 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -4
package/dist/models.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the provider reads about a Gemini API model, as data on its
|
|
3
|
+
* `ModelInfo`: `providerOptions.google` ({@link GoogleModelOptions}),
|
|
4
|
+
* `supportedParameters`, `capabilities` and `reasoningEfforts`.
|
|
5
|
+
*
|
|
6
|
+
* The provider keeps no per-model rules or tables. `@aeye/models`
|
|
7
|
+
* (`googleModels`) carries the data for every model Google lists: what
|
|
8
|
+
* models.list and the docs pages say (`packages/models/scraped/google.json`),
|
|
9
|
+
* with the family defaults, corrections and live-measured results of
|
|
10
|
+
* `packages/models/overrides/google.ts` merged in. Pass it as
|
|
11
|
+
* `GoogleConfig.modelInfo` (or register it with the AI). A model the
|
|
12
|
+
* provider has no data for is treated as {@link defaultGoogleModel} says.
|
|
13
|
+
*/
|
|
14
|
+
import { providerOptionsOf } from '@aeye/ai';
|
|
15
|
+
/**
|
|
16
|
+
* A model id without the `models/` (or `publishers/google/models/`) prefix.
|
|
17
|
+
* (This parses a resource name; it says nothing about the model.)
|
|
18
|
+
*/
|
|
19
|
+
export function bareModelId(id) {
|
|
20
|
+
return id.replace(/^(projects\/[^/]+\/locations\/[^/]+\/)?(publishers\/google\/)?models\//, '');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A model's Google options (empty when it has none).
|
|
24
|
+
*/
|
|
25
|
+
export function googleOptions(model) {
|
|
26
|
+
return providerOptionsOf(model, 'google') ?? {};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The chat parameters the default model takes: no sampling, penalties,
|
|
30
|
+
* log probabilities or service tier, since current Gemini models ignore or
|
|
31
|
+
* refuse them.
|
|
32
|
+
*/
|
|
33
|
+
const DEFAULT_PARAMETERS = ['maxTokens', 'stop', 'seed', 'responseFormat', 'structuredOutput', 'tools', 'toolChoice', 'toolsStrict', 'reason'];
|
|
34
|
+
/**
|
|
35
|
+
* The model info of a model the provider has no data for: a current Gemini
|
|
36
|
+
* chat model (text, images, tools, structured output, thinking by level at
|
|
37
|
+
* low, medium and high). It is conservative: no sampling, penalties, log
|
|
38
|
+
* probabilities, service tier, explicit caching, per-part media resolution,
|
|
39
|
+
* media in function responses, server-side tool invocations or tools
|
|
40
|
+
* combined with a response schema, which it doesn't know the model takes.
|
|
41
|
+
* Function calls replayed from elsewhere get the skip signature current
|
|
42
|
+
* models require. Give the provider the model's data (`@aeye/models`
|
|
43
|
+
* `googleModels` as `GoogleConfig.modelInfo`) for anything else.
|
|
44
|
+
*/
|
|
45
|
+
export function defaultGoogleModel(id, provider = 'google') {
|
|
46
|
+
return {
|
|
47
|
+
provider,
|
|
48
|
+
id: bareModelId(id),
|
|
49
|
+
name: bareModelId(id),
|
|
50
|
+
capabilities: new Set(['chat', 'streaming', 'vision', 'json', 'tools', 'toolsStrict', 'structured', 'reasoning']),
|
|
51
|
+
supportedParameters: new Set(DEFAULT_PARAMETERS),
|
|
52
|
+
tier: 'efficient',
|
|
53
|
+
pricing: {},
|
|
54
|
+
contextWindow: 0,
|
|
55
|
+
tokenizer: 'Gemini',
|
|
56
|
+
reasoningEfforts: ['low', 'medium', 'high'],
|
|
57
|
+
schema: { base: 'google' },
|
|
58
|
+
providerOptions: { google: { kind: 'chat', thinking: { style: 'level' }, thoughtSignatures: true } },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The kind a models.list entry's methods say it is: `embedContent`,
|
|
63
|
+
* `createDecision` and `predict` name their kinds; anything else that
|
|
64
|
+
* generates content is taken for chat (only data says it's an image, speech
|
|
65
|
+
* or transcription model).
|
|
66
|
+
*/
|
|
67
|
+
function kindByMethods(methods) {
|
|
68
|
+
if (methods.includes('embedContent'))
|
|
69
|
+
return 'embedding';
|
|
70
|
+
if (methods.includes('createDecision'))
|
|
71
|
+
return 'decision';
|
|
72
|
+
if (methods.includes('predict'))
|
|
73
|
+
return 'imagen';
|
|
74
|
+
return methods.includes('generateContent') ? 'chat' : 'other';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A models.list entry as ModelInfo, from the API's own data (limits,
|
|
78
|
+
* methods, the thinking flag) over {@link defaultGoogleModel}. Prices and
|
|
79
|
+
* everything the API doesn't say come from `@aeye/models`.
|
|
80
|
+
*
|
|
81
|
+
* @param model - The API's model
|
|
82
|
+
* @param provider - The provider name to record
|
|
83
|
+
*/
|
|
84
|
+
export function toModelInfo(model, provider = 'google') {
|
|
85
|
+
const base = defaultGoogleModel(model.name ?? '', provider);
|
|
86
|
+
const methods = model.supportedActions ?? model.supportedGenerationMethods ?? [];
|
|
87
|
+
const kind = kindByMethods(methods);
|
|
88
|
+
const thinks = model.thinking === true;
|
|
89
|
+
const options = {
|
|
90
|
+
...googleOptions(base),
|
|
91
|
+
kind,
|
|
92
|
+
thinking: thinks && kind === 'chat' ? { style: 'level' } : { style: 'none' },
|
|
93
|
+
explicitCaching: methods.includes('createCachedContent'),
|
|
94
|
+
};
|
|
95
|
+
const chat = kind === 'chat';
|
|
96
|
+
const capabilities = new Set(chat ? [...base.capabilities].filter(c => thinks || c !== 'reasoning')
|
|
97
|
+
: kind === 'embedding' ? ['embedding']
|
|
98
|
+
: kind === 'decision' ? ['decision']
|
|
99
|
+
: kind === 'imagen' ? ['image']
|
|
100
|
+
: []);
|
|
101
|
+
const parameters = new Set(chat ? [...base.supportedParameters].filter(p => thinks || p !== 'reason')
|
|
102
|
+
: kind === 'embedding' ? ['embeddingDimensions']
|
|
103
|
+
: kind === 'imagen' ? ['imageMultiple', 'imageFormat']
|
|
104
|
+
: []);
|
|
105
|
+
return {
|
|
106
|
+
...base,
|
|
107
|
+
name: model.displayName || base.id,
|
|
108
|
+
capabilities,
|
|
109
|
+
supportedParameters: parameters,
|
|
110
|
+
contextWindow: model.inputTokenLimit ?? 0,
|
|
111
|
+
maxOutputTokens: model.outputTokenLimit,
|
|
112
|
+
reasoningEfforts: thinks && chat ? base.reasoningEfforts : undefined,
|
|
113
|
+
...(kind === 'decision' ? { maxQuestions: 1000 } : {}),
|
|
114
|
+
providerOptions: { google: options },
|
|
115
|
+
metadata: { version: model.version, description: model.description, methods },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Whether a models.list entry is one @aeye can call: it generates content,
|
|
120
|
+
* embeds, predicts or decides (live-only and music-streaming models aren't).
|
|
121
|
+
*/
|
|
122
|
+
export function isUsableModel(model) {
|
|
123
|
+
const methods = model.supportedActions ?? model.supportedGenerationMethods ?? [];
|
|
124
|
+
return methods.some(m => ['generateContent', 'embedContent', 'createDecision', 'predict'].includes(m));
|
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,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,eAAe,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QACpC,QAAQ,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE;KAC9E,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAA8D;IAC1F,MAAM,OAAO,GAAG,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC;IACjF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACzG,CAAC"}
|
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retries with exponential backoff and jitter, and the mapping from Gemini
|
|
3
|
+
* API failures to the provider's error classes.
|
|
4
|
+
*
|
|
5
|
+
* The SDK retries only when `httpOptions.retryOptions` is set, which the
|
|
6
|
+
* provider never does: it retries here, so the hooks, events and abort signal
|
|
7
|
+
* see every attempt.
|
|
8
|
+
*/
|
|
9
|
+
import { type GoogleErrorBody } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for retry behavior.
|
|
12
|
+
*/
|
|
13
|
+
export interface RetryConfig {
|
|
14
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
15
|
+
maxRetries?: number;
|
|
16
|
+
/** Initial delay in milliseconds before first retry (default: 1000) */
|
|
17
|
+
initialDelay?: number;
|
|
18
|
+
/** Maximum delay in milliseconds between retries (default: 60000) */
|
|
19
|
+
maxDelay?: number;
|
|
20
|
+
/** Multiplier for exponential backoff (default: 2) */
|
|
21
|
+
backoffMultiplier?: number;
|
|
22
|
+
/** Whether to add random jitter to delays (default: true) */
|
|
23
|
+
jitter?: boolean;
|
|
24
|
+
/** HTTP status codes that trigger a retry (default: [0, 429, 500, 502, 503, 504]); 0 is a network failure */
|
|
25
|
+
retryableStatuses?: number[];
|
|
26
|
+
/** Regex patterns for error messages that trigger a retry */
|
|
27
|
+
retryableMessages?: RegExp[];
|
|
28
|
+
/** Timeout in milliseconds for each attempt (optional) */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Context information passed to retry event handlers.
|
|
33
|
+
*/
|
|
34
|
+
export interface RetryContext {
|
|
35
|
+
/** The operation being performed (e.g., 'chat', 'image', 'embed') */
|
|
36
|
+
operation: string;
|
|
37
|
+
/** The model being used (if applicable) */
|
|
38
|
+
model?: string;
|
|
39
|
+
/** The provider name */
|
|
40
|
+
provider: string;
|
|
41
|
+
/** Timestamp when the operation started */
|
|
42
|
+
startTime: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Event handlers for retry lifecycle events.
|
|
46
|
+
*/
|
|
47
|
+
export interface RetryEvents {
|
|
48
|
+
/** Called before each retry attempt */
|
|
49
|
+
onRetry?: (attempt: number, error: Error, delay: number, context: RetryContext) => void;
|
|
50
|
+
/** Called when an attempt times out */
|
|
51
|
+
onTimeout?: (duration: number, context: RetryContext) => void;
|
|
52
|
+
/** Called when max retries are exceeded */
|
|
53
|
+
onMaxRetriesExceeded?: (attempts: number, lastError: Error, context: RetryContext) => void;
|
|
54
|
+
/** Called when the operation succeeds (retry count and total duration) */
|
|
55
|
+
onSuccess?: (attempts: number, duration: number, context: RetryContext) => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The status and error body of a failed call: the SDK's `ApiError` keeps the
|
|
59
|
+
* HTTP status on `status` and the JSON error body as its message.
|
|
60
|
+
*/
|
|
61
|
+
export declare function errorDetails(error: unknown): {
|
|
62
|
+
status: number;
|
|
63
|
+
body?: GoogleErrorBody;
|
|
64
|
+
message: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Seconds the API asks to wait before retrying (`RetryInfo.retryDelay`, such
|
|
68
|
+
* as `"31s"`, or "Please retry in 31.2s" in the message).
|
|
69
|
+
*/
|
|
70
|
+
export declare function retryDelaySeconds(body: GoogleErrorBody | undefined, message: string): number | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Whether an error is an abort, which is never retried.
|
|
73
|
+
*/
|
|
74
|
+
export declare function isAbortError(error: unknown): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether an error says the prompt was longer than the context window.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isContextWindowError(error: unknown): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The maximum token count a context window error names, if it does.
|
|
81
|
+
*/
|
|
82
|
+
export declare function contextWindowSize(message: string): number | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* A failed call as one of the provider's errors. Errors that already are
|
|
85
|
+
* one (and aborts) pass through.
|
|
86
|
+
*/
|
|
87
|
+
export declare function toGoogleError(error: unknown): Error;
|
|
88
|
+
/**
|
|
89
|
+
* Whether an error should be retried, by status and message.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isRetryableError(error: unknown, config: RetryConfig): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* The delay before a retry: exponential backoff with jitter, at least what
|
|
94
|
+
* the API asked for, capped at `maxDelay`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function calculateBackoff(attempt: number, config: RetryConfig, error?: unknown): number;
|
|
97
|
+
/**
|
|
98
|
+
* The error an aborted operation throws.
|
|
99
|
+
*/
|
|
100
|
+
export declare function abortError(): Error;
|
|
101
|
+
/**
|
|
102
|
+
* Run an operation with retries. Each attempt gets a signal that fires on the
|
|
103
|
+
* caller's abort or the per-attempt timeout.
|
|
104
|
+
*
|
|
105
|
+
* @param operation - The call, given the attempt's signal
|
|
106
|
+
* @param context - For the events
|
|
107
|
+
* @param config - Retry configuration
|
|
108
|
+
* @param events - Retry lifecycle events
|
|
109
|
+
* @param signal - The caller's abort signal
|
|
110
|
+
*/
|
|
111
|
+
export declare function withRetry<T>(operation: (signal?: AbortSignal) => Promise<T>, context: RetryContext, config?: RetryConfig, events?: RetryEvents, signal?: AbortSignal): Promise<T>;
|
|
112
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAIL,KAAK,eAAe,EAGrB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,6GAA6G;IAC7G,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,6DAA6D;IAC7D,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uCAAuC;IACvC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAA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,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAa9F;AAuBD;;GAEG;AACH,wBAAgB,UAAU,IAAI,KAAK,CAIlC;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EAC/C,OAAO,EAAE,YAAY,EACrB,MAAM,GAAE,WAAgB,EACxB,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CA2CZ"}
|
package/dist/retry.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retries with exponential backoff and jitter, and the mapping from Gemini
|
|
3
|
+
* API failures to the provider's error classes.
|
|
4
|
+
*
|
|
5
|
+
* The SDK retries only when `httpOptions.retryOptions` is set, which the
|
|
6
|
+
* provider never does: it retries here, so the hooks, events and abort signal
|
|
7
|
+
* see every attempt.
|
|
8
|
+
*/
|
|
9
|
+
import { GoogleAuthError, GoogleContextWindowError, GoogleError, GoogleQuotaError, GoogleRateLimitError, } from './types.js';
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
maxRetries: 3,
|
|
12
|
+
initialDelay: 1000,
|
|
13
|
+
maxDelay: 60000,
|
|
14
|
+
backoffMultiplier: 2,
|
|
15
|
+
jitter: true,
|
|
16
|
+
retryableStatuses: [0, 429, 500, 502, 503, 504],
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* How the Gemini API says a prompt didn't fit, e.g. "The input token count
|
|
20
|
+
* (1200000) exceeds the maximum number of tokens allowed (1048576)."
|
|
21
|
+
*/
|
|
22
|
+
const CONTEXT_WINDOW = /input token count.*exceeds|exceeds the maximum number of tokens|context (length|window)|prompt is too long|too many (input )?tokens/i;
|
|
23
|
+
/**
|
|
24
|
+
* The status and error body of a failed call: the SDK's `ApiError` keeps the
|
|
25
|
+
* HTTP status on `status` and the JSON error body as its message.
|
|
26
|
+
*/
|
|
27
|
+
export function errorDetails(error) {
|
|
28
|
+
const e = error;
|
|
29
|
+
const raw = typeof e?.message === 'string' ? e.message : String(error);
|
|
30
|
+
let body;
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(raw);
|
|
33
|
+
body = parsed?.error ?? parsed;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
body = undefined;
|
|
37
|
+
}
|
|
38
|
+
const status = typeof e?.status === 'number' ? e.status : typeof body?.code === 'number' ? body.code : 0;
|
|
39
|
+
// An answer with an empty body (a 404 for a model the API doesn't serve) still says what happened
|
|
40
|
+
const own = body?.message ?? (body && typeof body === 'object' && !Object.keys(body).length ? '' : raw);
|
|
41
|
+
const message = String(own).trim() || `${status ? `HTTP ${status}` : 'The request failed'}${body?.status ? ` ${body.status}` : ''} with no error message`;
|
|
42
|
+
return { status, body, message };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Seconds the API asks to wait before retrying (`RetryInfo.retryDelay`, such
|
|
46
|
+
* as `"31s"`, or "Please retry in 31.2s" in the message).
|
|
47
|
+
*/
|
|
48
|
+
export function retryDelaySeconds(body, message) {
|
|
49
|
+
const info = body?.details?.find(d => typeof d?.['@type'] === 'string' && d['@type'].endsWith('RetryInfo'));
|
|
50
|
+
const delay = typeof info?.retryDelay === 'string' ? info.retryDelay : /retry in ([\d.]+)s/i.exec(message)?.[1];
|
|
51
|
+
const seconds = delay === undefined ? NaN : parseFloat(delay);
|
|
52
|
+
return Number.isFinite(seconds) ? seconds : undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether a 429 is a quota that won't clear with a retry soon: a per-day
|
|
56
|
+
* limit, or a model the plan doesn't include (limit 0).
|
|
57
|
+
*/
|
|
58
|
+
function isHardQuota(body, message) {
|
|
59
|
+
const failures = body?.details?.filter(d => typeof d?.['@type'] === 'string' && d['@type'].endsWith('QuotaFailure')) ?? [];
|
|
60
|
+
const ids = failures.flatMap(f => (f.violations ?? []).map((v) => `${v.quotaId ?? ''} ${v.quotaValue ?? ''}`));
|
|
61
|
+
return ids.some(id => /PerDay/i.test(id) || /\s0$/.test(id)) || /limit: 0\b/.test(message);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether an error is an abort, which is never retried.
|
|
65
|
+
*/
|
|
66
|
+
export function isAbortError(error) {
|
|
67
|
+
const e = error;
|
|
68
|
+
return e?.name === 'AbortError' || /aborted/i.test(String(error?.message ?? ''));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Whether an error says the prompt was longer than the context window.
|
|
72
|
+
*/
|
|
73
|
+
export function isContextWindowError(error) {
|
|
74
|
+
if (error instanceof GoogleContextWindowError) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
const { status, message } = errorDetails(error);
|
|
78
|
+
return (status === 400 || status === 413 || status === 500) && CONTEXT_WINDOW.test(message);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The maximum token count a context window error names, if it does.
|
|
82
|
+
*/
|
|
83
|
+
export function contextWindowSize(message) {
|
|
84
|
+
const match = /maximum number of tokens allowed \((\d+)\)|limit of (\d+)/i.exec(message);
|
|
85
|
+
const value = match?.[1] ?? match?.[2];
|
|
86
|
+
return value ? parseInt(value, 10) : undefined;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A failed call as one of the provider's errors. Errors that already are
|
|
90
|
+
* one (and aborts) pass through.
|
|
91
|
+
*/
|
|
92
|
+
export function toGoogleError(error) {
|
|
93
|
+
if (error instanceof GoogleError || isAbortError(error)) {
|
|
94
|
+
return error;
|
|
95
|
+
}
|
|
96
|
+
const cause = error instanceof Error ? error : undefined;
|
|
97
|
+
const { status, body, message } = errorDetails(error);
|
|
98
|
+
const reason = body?.details?.find(d => typeof d?.reason === 'string')?.reason;
|
|
99
|
+
if (status === 401 || status === 403 || reason === 'API_KEY_INVALID' || /api key not valid/i.test(message)) {
|
|
100
|
+
return new GoogleAuthError(message, cause, status, body);
|
|
101
|
+
}
|
|
102
|
+
if (status === 402) {
|
|
103
|
+
return new GoogleQuotaError(message, cause, status, body);
|
|
104
|
+
}
|
|
105
|
+
if (status === 429) {
|
|
106
|
+
return isHardQuota(body, message)
|
|
107
|
+
? new GoogleQuotaError(message, cause, status, body)
|
|
108
|
+
: new GoogleRateLimitError(message, retryDelaySeconds(body, message), cause, status, body);
|
|
109
|
+
}
|
|
110
|
+
if (isContextWindowError(error)) {
|
|
111
|
+
return new GoogleContextWindowError(message, contextWindowSize(message), cause, status, body);
|
|
112
|
+
}
|
|
113
|
+
return new GoogleError(message, cause, status || undefined, body);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Whether an error should be retried, by status and message.
|
|
117
|
+
*/
|
|
118
|
+
export function isRetryableError(error, config) {
|
|
119
|
+
if (!error || isAbortError(error) || isContextWindowError(error) || error instanceof GoogleQuotaError || error instanceof GoogleAuthError) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const { status, body, message } = errorDetails(error);
|
|
123
|
+
if (status === 429 && isHardQuota(body, message)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
const statuses = config.retryableStatuses ?? DEFAULTS.retryableStatuses;
|
|
127
|
+
if (statuses.includes(status) && (status !== 0 || error instanceof TypeError || /fetch failed|network|ECONNRESET|ETIMEDOUT|socket/i.test(message))) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return !!config.retryableMessages?.some(pattern => pattern.test(message));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The delay before a retry: exponential backoff with jitter, at least what
|
|
134
|
+
* the API asked for, capped at `maxDelay`.
|
|
135
|
+
*/
|
|
136
|
+
export function calculateBackoff(attempt, config, error) {
|
|
137
|
+
const initialDelay = config.initialDelay ?? DEFAULTS.initialDelay;
|
|
138
|
+
const maxDelay = config.maxDelay ?? DEFAULTS.maxDelay;
|
|
139
|
+
const multiplier = config.backoffMultiplier ?? DEFAULTS.backoffMultiplier;
|
|
140
|
+
let delay = Math.min(initialDelay * Math.pow(multiplier, attempt), maxDelay);
|
|
141
|
+
if (config.jitter ?? DEFAULTS.jitter) {
|
|
142
|
+
delay = delay / 2 + Math.random() * delay / 2;
|
|
143
|
+
}
|
|
144
|
+
const asked = error instanceof GoogleRateLimitError ? error.retryAfter : error ? retryDelaySeconds(errorDetails(error).body, errorDetails(error).message) : undefined;
|
|
145
|
+
if (asked !== undefined) {
|
|
146
|
+
delay = Math.max(delay, asked * 1000);
|
|
147
|
+
}
|
|
148
|
+
return Math.floor(Math.min(delay, maxDelay));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Sleep, ending early (with an abort error) when the signal fires.
|
|
152
|
+
*/
|
|
153
|
+
function sleep(ms, signal) {
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
if (signal?.aborted) {
|
|
156
|
+
reject(abortError());
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const timer = setTimeout(() => {
|
|
160
|
+
signal?.removeEventListener('abort', onAbort);
|
|
161
|
+
resolve();
|
|
162
|
+
}, ms);
|
|
163
|
+
const onAbort = () => {
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
reject(abortError());
|
|
166
|
+
};
|
|
167
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The error an aborted operation throws.
|
|
172
|
+
*/
|
|
173
|
+
export function abortError() {
|
|
174
|
+
const error = new Error('Operation aborted');
|
|
175
|
+
error.name = 'AbortError';
|
|
176
|
+
return error;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Run an operation with retries. Each attempt gets a signal that fires on the
|
|
180
|
+
* caller's abort or the per-attempt timeout.
|
|
181
|
+
*
|
|
182
|
+
* @param operation - The call, given the attempt's signal
|
|
183
|
+
* @param context - For the events
|
|
184
|
+
* @param config - Retry configuration
|
|
185
|
+
* @param events - Retry lifecycle events
|
|
186
|
+
* @param signal - The caller's abort signal
|
|
187
|
+
*/
|
|
188
|
+
export async function withRetry(operation, context, config = {}, events, signal) {
|
|
189
|
+
const maxRetries = config.maxRetries ?? DEFAULTS.maxRetries;
|
|
190
|
+
let attempt = 0;
|
|
191
|
+
for (;;) {
|
|
192
|
+
if (signal?.aborted) {
|
|
193
|
+
throw abortError();
|
|
194
|
+
}
|
|
195
|
+
const controller = config.timeout ? new AbortController() : undefined;
|
|
196
|
+
const onAbort = () => controller?.abort();
|
|
197
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
198
|
+
let timedOut = false;
|
|
199
|
+
const timer = controller && setTimeout(() => {
|
|
200
|
+
timedOut = true;
|
|
201
|
+
events?.onTimeout?.(config.timeout, context);
|
|
202
|
+
controller.abort();
|
|
203
|
+
}, config.timeout);
|
|
204
|
+
try {
|
|
205
|
+
const result = await operation(controller?.signal ?? signal);
|
|
206
|
+
events?.onSuccess?.(attempt, Date.now() - context.startTime, context);
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
const error = timedOut ? Object.assign(new Error(`Operation timed out after ${config.timeout}ms`), { status: 0, name: 'TimeoutError' }) : e;
|
|
211
|
+
if (signal?.aborted) {
|
|
212
|
+
throw abortError();
|
|
213
|
+
}
|
|
214
|
+
const retryable = timedOut || isRetryableError(error, config);
|
|
215
|
+
if (!retryable || attempt >= maxRetries) {
|
|
216
|
+
if (retryable) {
|
|
217
|
+
events?.onMaxRetriesExceeded?.(attempt, error, context);
|
|
218
|
+
}
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const delay = calculateBackoff(attempt, config, error);
|
|
222
|
+
events?.onRetry?.(attempt, error, delay, context);
|
|
223
|
+
await sleep(delay, signal);
|
|
224
|
+
attempt++;
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
if (timer) {
|
|
228
|
+
clearTimeout(timer);
|
|
229
|
+
}
|
|
230
|
+
signal?.removeEventListener('abort', onAbort);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,WAAW,EAEX,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAoDpB,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,CAAC;IACb,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,KAAK;IACf,iBAAiB,EAAE,CAAC;IACpB,MAAM,EAAE,IAAI;IACZ,iBAAiB,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CAChD,CAAC;AAEF;;;GAGG;AACH,MAAM,cAAc,GAAG,sIAAsI,CAAC;AAE9J;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,CAAC,GAAG,KAA4E,CAAC;IACvF,MAAM,GAAG,GAAG,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,IAAI,IAAiC,CAAC;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,GAAG,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,MAAM,KAAK,QAAQ,C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C,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,6BAA6B,MAAM,CAAC,OAAO,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5I,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;gBACpB,MAAM,UAAU,EAAE,CAAC;YACrB,CAAC;YACD,MAAM,SAAS,GAAG,QAAQ,IAAI,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC9D,IAAI,CAAC,SAAS,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;gBACxC,IAAI,SAAS,EAAE,CAAC;oBACd,MAAM,EAAE,oBAAoB,EAAE,CAAC,OAAO,EAAE,KAAc,EAAE,OAAO,CAAC,CAAC;gBACnE,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YACvD,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,KAAc,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAC3D,MAAM,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC3B,OAAO,EAAE,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors the Google provider throws, so callers can tell failures apart
|
|
3
|
+
* without reading the Gemini API's error bodies.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A Gemini API error body, as the SDK puts it in `ApiError.message`.
|
|
7
|
+
*/
|
|
8
|
+
export interface GoogleErrorBody {
|
|
9
|
+
/** HTTP status code */
|
|
10
|
+
code?: number;
|
|
11
|
+
/** What went wrong */
|
|
12
|
+
message?: string;
|
|
13
|
+
/** gRPC status, such as `RESOURCE_EXHAUSTED` */
|
|
14
|
+
status?: string;
|
|
15
|
+
/** `ErrorInfo`, `RetryInfo`, `QuotaFailure` and the like */
|
|
16
|
+
details?: Array<Record<string, any>>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Base class for errors from the Google provider. `status` is the HTTP
|
|
20
|
+
* status when the API answered with one.
|
|
21
|
+
*/
|
|
22
|
+
export declare class GoogleError extends Error {
|
|
23
|
+
cause?: Error | undefined;
|
|
24
|
+
status?: number | undefined;
|
|
25
|
+
body?: GoogleErrorBody | undefined;
|
|
26
|
+
constructor(message: string, cause?: Error | undefined, status?: number | undefined, body?: GoogleErrorBody | undefined);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The API key or credentials were refused (401/403), or the key is invalid.
|
|
30
|
+
*/
|
|
31
|
+
export declare class GoogleAuthError extends GoogleError {
|
|
32
|
+
constructor(message: string, cause?: Error, status?: number, body?: GoogleErrorBody);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A rate limit was hit (429). `retryAfter` is in seconds, when the API said.
|
|
36
|
+
*/
|
|
37
|
+
export declare class GoogleRateLimitError extends GoogleError {
|
|
38
|
+
retryAfter?: number | undefined;
|
|
39
|
+
constructor(message: string, retryAfter?: number | undefined, cause?: Error, status?: number, body?: GoogleErrorBody);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The account's quota or prepaid credit ran out (429 with a daily or
|
|
43
|
+
* monthly quota, or 402).
|
|
44
|
+
*/
|
|
45
|
+
export declare class GoogleQuotaError extends GoogleError {
|
|
46
|
+
constructor(message: string, cause?: Error, status?: number, body?: GoogleErrorBody);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The request was longer than the model's context window.
|
|
50
|
+
*/
|
|
51
|
+
export declare class GoogleContextWindowError extends GoogleError {
|
|
52
|
+
contextWindow?: number | undefined;
|
|
53
|
+
constructor(message: string, contextWindow?: number | undefined, cause?: Error, status?: number, body?: GoogleErrorBody);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The prompt or the answer was blocked by safety filters, where the API
|
|
57
|
+
* fails the call instead of returning a blocked response (the Decisions API).
|
|
58
|
+
*/
|
|
59
|
+
export declare class GoogleSafetyError extends GoogleError {
|
|
60
|
+
reason?: string | undefined;
|
|
61
|
+
constructor(message: string, reason?: string | undefined, cause?: Error, status?: number, body?: GoogleErrorBody);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAG3B,KAAK,CAAC,EAAE,KAAK;IACb,MAAM,CAAC,EAAE,MAAM;IACf,IAAI,CAAC,EAAE,eAAe;gBAH7B,OAAO,EAAE,MAAM,EACR,KAAK,CAAC,EAAE,KAAK,YAAA,EACb,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,IAAI,CAAC,EAAE,eAAe,YAAA;CAOhC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAIpF;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,WAAW;IACf,UAAU,CAAC,EAAE,MAAM;gBAA3C,OAAO,EAAE,MAAM,EAAS,UAAU,CAAC,EAAE,MAAM,YAAA,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAIhH;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAIpF;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,WAAW;IACnB,aAAa,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAS,aAAa,CAAC,EAAE,MAAM,YAAA,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAInH;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,WAAW;IACZ,MAAM,CAAC,EAAE,MAAM;gBAAvC,OAAO,EAAE,MAAM,EAAS,MAAM,CAAC,EAAE,MAAM,YAAA,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,eAAe;CAI5G"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors the Google provider throws, so callers can tell failures apart
|
|
3
|
+
* without reading the Gemini API's error bodies.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Base class for errors from the Google provider. `status` is the HTTP
|
|
7
|
+
* status when the API answered with one.
|
|
8
|
+
*/
|
|
9
|
+
export class GoogleError extends Error {
|
|
10
|
+
cause;
|
|
11
|
+
status;
|
|
12
|
+
body;
|
|
13
|
+
constructor(message, cause, status, body) {
|
|
14
|
+
// Never just "[google] ": an empty message says so, and an HTTP status is always named
|
|
15
|
+
const text = message.trim() || 'The request failed with no error message';
|
|
16
|
+
super(`[google] ${text}${status && !text.includes(String(status)) ? ` (HTTP ${status})` : ''}`);
|
|
17
|
+
this.cause = cause;
|
|
18
|
+
this.status = status;
|
|
19
|
+
this.body = body;
|
|
20
|
+
this.name = 'GoogleError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The API key or credentials were refused (401/403), or the key is invalid.
|
|
25
|
+
*/
|
|
26
|
+
export class GoogleAuthError extends GoogleError {
|
|
27
|
+
constructor(message, cause, status, body) {
|
|
28
|
+
super(`Authentication failed: ${message}`, cause, status, body);
|
|
29
|
+
this.name = 'GoogleAuthError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A rate limit was hit (429). `retryAfter` is in seconds, when the API said.
|
|
34
|
+
*/
|
|
35
|
+
export class GoogleRateLimitError extends GoogleError {
|
|
36
|
+
retryAfter;
|
|
37
|
+
constructor(message, retryAfter, cause, status, body) {
|
|
38
|
+
super(`Rate limit exceeded: ${message}`, cause, status, body);
|
|
39
|
+
this.retryAfter = retryAfter;
|
|
40
|
+
this.name = 'GoogleRateLimitError';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The account's quota or prepaid credit ran out (429 with a daily or
|
|
45
|
+
* monthly quota, or 402).
|
|
46
|
+
*/
|
|
47
|
+
export class GoogleQuotaError extends GoogleError {
|
|
48
|
+
constructor(message, cause, status, body) {
|
|
49
|
+
super(`Quota exceeded: ${message}`, cause, status, body);
|
|
50
|
+
this.name = 'GoogleQuotaError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The request was longer than the model's context window.
|
|
55
|
+
*/
|
|
56
|
+
export class GoogleContextWindowError extends GoogleError {
|
|
57
|
+
contextWindow;
|
|
58
|
+
constructor(message, contextWindow, cause, status, body) {
|
|
59
|
+
super(message, cause, status, body);
|
|
60
|
+
this.contextWindow = contextWindow;
|
|
61
|
+
this.name = 'GoogleContextWindowError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The prompt or the answer was blocked by safety filters, where the API
|
|
66
|
+
* fails the call instead of returning a blocked response (the Decisions API).
|
|
67
|
+
*/
|
|
68
|
+
export class GoogleSafetyError extends GoogleError {
|
|
69
|
+
reason;
|
|
70
|
+
constructor(message, reason, cause, status, body) {
|
|
71
|
+
super(message, cause, status, body);
|
|
72
|
+
this.reason = reason;
|
|
73
|
+
this.name = 'GoogleSafetyError';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAgBH;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IACA;IACA;IAJT,YACE,OAAe,EACR,KAAa,EACb,MAAe,EACf,IAAsB;QAE7B,uFAAuF;QACvF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,0CAA0C,CAAC;QAC1E,KAAK,CAAC,YAAY,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QANzF,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAS;QACf,SAAI,GAAJ,IAAI,CAAkB;QAK7B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED;;GAE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