@kenkaiiii/gg-ai 4.3.205 → 4.3.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +69 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1981,6 +1981,8 @@ var DEFAULT_CODE_ASSIST_BASE_URL = "https://cloudcode-pa.googleapis.com";
|
|
|
1981
1981
|
var CODE_ASSIST_API_VERSION = "v1internal";
|
|
1982
1982
|
var GEMINI_CLI_USER_AGENT = "google-gemini-cli";
|
|
1983
1983
|
var GEMINI_CLI_API_CLIENT = "gemini-cli/0.0.0";
|
|
1984
|
+
var CODE_ASSIST_NON_STREAMING_RETRIES = 3;
|
|
1985
|
+
var CODE_ASSIST_NON_STREAMING_RETRY_DELAY_MS = 1e3;
|
|
1984
1986
|
var SYNTHETIC_THOUGHT_SIGNATURE = "skip_thought_signature_validator";
|
|
1985
1987
|
var CODE_ASSIST_SUPPORTED_MODELS = /* @__PURE__ */ new Set([
|
|
1986
1988
|
"gemini-3-pro-preview",
|
|
@@ -2005,7 +2007,10 @@ function getGoogleProject(options) {
|
|
|
2005
2007
|
return options.projectId ?? env?.GOOGLE_CLOUD_PROJECT ?? env?.GOOGLE_CLOUD_PROJECT_ID;
|
|
2006
2008
|
}
|
|
2007
2009
|
function getCodeAssistEndpoint(method) {
|
|
2008
|
-
|
|
2010
|
+
const env = getEnvironment();
|
|
2011
|
+
const endpoint = env?.CODE_ASSIST_ENDPOINT ?? DEFAULT_CODE_ASSIST_BASE_URL;
|
|
2012
|
+
const version = env?.CODE_ASSIST_API_VERSION || CODE_ASSIST_API_VERSION;
|
|
2013
|
+
return new URL(`${endpoint}/${version}:${method}`);
|
|
2009
2014
|
}
|
|
2010
2015
|
function formatUnsupportedModelMessage(model) {
|
|
2011
2016
|
return `Gemini OAuth is configured to use the Gemini Code Assist subscription endpoint only. That endpoint does not currently expose model "${model}".`;
|
|
@@ -2184,7 +2189,8 @@ function buildGenerateRequest(options) {
|
|
|
2184
2189
|
...systemInstruction ? { systemInstruction } : {},
|
|
2185
2190
|
...tools ? { tools } : {},
|
|
2186
2191
|
...toolConfig ? { toolConfig } : {},
|
|
2187
|
-
...Object.keys(generationConfig).length > 0 ? { generationConfig } : {}
|
|
2192
|
+
...Object.keys(generationConfig).length > 0 ? { generationConfig } : {},
|
|
2193
|
+
...options.promptCacheKey ? { session_id: options.promptCacheKey } : {}
|
|
2188
2194
|
};
|
|
2189
2195
|
}
|
|
2190
2196
|
function buildCodeAssistRequest(options, request, projectId) {
|
|
@@ -2304,31 +2310,78 @@ function readFunctionCallPart(part) {
|
|
|
2304
2310
|
function makeToolCallId(index, providerId) {
|
|
2305
2311
|
return providerId ?? `gemini_call_${index}_${crypto.randomUUID().replace(/-/g, "")}`;
|
|
2306
2312
|
}
|
|
2307
|
-
function
|
|
2308
|
-
return
|
|
2313
|
+
function shouldRetryCodeAssistStatus(status) {
|
|
2314
|
+
return status === 429 || status === 499 || status >= 500 && status <= 599;
|
|
2315
|
+
}
|
|
2316
|
+
function isAbortError(err) {
|
|
2317
|
+
return err instanceof Error && err.name === "AbortError";
|
|
2318
|
+
}
|
|
2319
|
+
async function sleep(ms, signal) {
|
|
2320
|
+
if (ms <= 0) return;
|
|
2321
|
+
await new Promise((resolve, reject) => {
|
|
2322
|
+
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
2323
|
+
const timer = setTimeout(() => {
|
|
2324
|
+
cleanup();
|
|
2325
|
+
resolve();
|
|
2326
|
+
}, ms);
|
|
2327
|
+
const onAbort = () => {
|
|
2328
|
+
clearTimeout(timer);
|
|
2329
|
+
cleanup();
|
|
2330
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
2331
|
+
};
|
|
2332
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2333
|
+
if (signal?.aborted) onAbort();
|
|
2334
|
+
});
|
|
2309
2335
|
}
|
|
2310
|
-
async function
|
|
2311
|
-
const useStreaming = options.streaming !== false;
|
|
2312
|
-
const method = useStreaming ? "streamGenerateContent" : "generateContent";
|
|
2313
|
-
const plan = buildRequestPlan(options, method);
|
|
2314
|
-
if (useStreaming) plan.url.searchParams.set("alt", "sse");
|
|
2315
|
-
let response;
|
|
2336
|
+
async function fetchCodeAssist(plan, options) {
|
|
2316
2337
|
try {
|
|
2317
|
-
response = await fetch(plan.url, {
|
|
2338
|
+
const response = await fetch(plan.url, {
|
|
2318
2339
|
method: "POST",
|
|
2319
2340
|
headers: plan.headers,
|
|
2320
2341
|
body: JSON.stringify(plan.body),
|
|
2321
2342
|
signal: options.signal
|
|
2322
2343
|
});
|
|
2344
|
+
if (!response.ok) {
|
|
2345
|
+
const text = await response.text().catch(() => "");
|
|
2346
|
+
throw new ProviderError("gemini", formatErrorMessage(response.status, text, options.model), {
|
|
2347
|
+
statusCode: response.status
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
return response;
|
|
2323
2351
|
} catch (err) {
|
|
2324
2352
|
throw toError3(err);
|
|
2325
2353
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2354
|
+
}
|
|
2355
|
+
async function fetchCodeAssistWithRetry(plan, options) {
|
|
2356
|
+
let lastError;
|
|
2357
|
+
for (let attempt = 0; attempt <= CODE_ASSIST_NON_STREAMING_RETRIES; attempt++) {
|
|
2358
|
+
try {
|
|
2359
|
+
return await fetchCodeAssist(plan, options);
|
|
2360
|
+
} catch (err) {
|
|
2361
|
+
const error = toError3(err);
|
|
2362
|
+
const statusCode = error instanceof ProviderError ? error.statusCode : void 0;
|
|
2363
|
+
if (options.signal?.aborted || isAbortError(error) || attempt === CODE_ASSIST_NON_STREAMING_RETRIES || statusCode != null && !shouldRetryCodeAssistStatus(statusCode)) {
|
|
2364
|
+
throw error;
|
|
2365
|
+
}
|
|
2366
|
+
lastError = error;
|
|
2367
|
+
}
|
|
2368
|
+
try {
|
|
2369
|
+
await sleep(CODE_ASSIST_NON_STREAMING_RETRY_DELAY_MS, options.signal);
|
|
2370
|
+
} catch (err) {
|
|
2371
|
+
throw toError3(err);
|
|
2372
|
+
}
|
|
2331
2373
|
}
|
|
2374
|
+
throw lastError ?? new ProviderError("gemini", "Gemini Code Assist request failed.");
|
|
2375
|
+
}
|
|
2376
|
+
function streamGemini(options) {
|
|
2377
|
+
return new StreamResult(runStream4(options));
|
|
2378
|
+
}
|
|
2379
|
+
async function* runStream4(options) {
|
|
2380
|
+
const useStreaming = options.streaming !== false;
|
|
2381
|
+
const method = useStreaming ? "streamGenerateContent" : "generateContent";
|
|
2382
|
+
const plan = buildRequestPlan(options, method);
|
|
2383
|
+
if (useStreaming) plan.url.searchParams.set("alt", "sse");
|
|
2384
|
+
const response = useStreaming ? await fetchCodeAssist(plan, options) : await fetchCodeAssistWithRetry(plan, options);
|
|
2332
2385
|
const contentParts = [];
|
|
2333
2386
|
const pendingToolCalls = [];
|
|
2334
2387
|
let textAccum = "";
|