@vibe-lark/larkpal 0.1.86 → 0.1.88
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/account-id-BM1T6029-BzQ_cMoi.mjs +1 -0
- package/dist/activation-context--5yu1dPF-XV0Y0pTy.mjs +1 -0
- package/dist/anthropic-CFZUCb1w.mjs +39 -0
- package/dist/assistant-visible-text-DuFWokAt-BOJV_zwc.mjs +9 -0
- package/dist/azure-openai-responses-BEuiMaF-.mjs +1 -0
- package/dist/boundary-file-read-BSd9MXPy-gnNVhPKT.mjs +1 -0
- package/dist/browser-lifecycle-cleanup-BdNsMhMD-BM97qA_M.mjs +1 -0
- package/dist/build-Bkj0hOS2.mjs +3 -0
- package/dist/bundled-compat-BpaDaAAu-DJtrIX6i.mjs +27 -0
- package/dist/bundled-dir-U738ay4K-BxbzrJOo.mjs +1 -0
- package/dist/call-DimWbpgJ-B4pv55RH.mjs +20 -0
- package/dist/channel-bootstrap.runtime-BVclcGv1-CEZ0-JP9.mjs +1 -0
- package/dist/channel-bootstrap.runtime-Cwcr38m2-Dt6QlQkX.mjs +1 -0
- package/dist/chunk-DHbaKqs-.mjs +1 -0
- package/dist/cli.mjs +7 -92
- package/dist/command-format-LSnUCVVF-Dn4h9IOh.mjs +16 -0
- package/dist/config-Bim2pi8a-03N-28sw.mjs +1 -0
- package/dist/delivery-context.shared-j5hC5qb1-BSLQG47q.mjs +1 -0
- package/dist/diagnostic-ClMwNnUA-BMKvPQJT.mjs +1 -0
- package/dist/dist-J5UB83Ws.mjs +601 -0
- package/dist/dist-coestTs9.mjs +5 -0
- package/dist/env-api-keys-Cuz5irWW.mjs +1 -0
- package/dist/event-stream-B7Ei41Bu.mjs +1 -0
- package/dist/facade-loader-DFzIYYt_-4bzFvy-b.mjs +1 -0
- package/dist/from-Ba69_5cR.mjs +14 -0
- package/dist/gateway-method-policy-C7rf0SeV-CTJcMQCE.mjs +1 -0
- package/dist/github-copilot-headers-BfhryVuU.mjs +1 -0
- package/dist/google-ABo-1guT.mjs +1 -0
- package/dist/google-gemini-cli-CGlN1zUA.mjs +2 -0
- package/dist/google-shared-C60sNhwd.mjs +301 -0
- package/dist/google-vertex-De0nAItu.mjs +1 -0
- package/dist/hash-Dw-N8Y9l.mjs +1 -0
- package/dist/headers-Bpsp70B9.mjs +1 -0
- package/dist/home-dir-C44RaPME-B5iLWwCq.mjs +1 -0
- package/dist/ids-BPsM98Uu-CJBJAeVC.mjs +1 -0
- package/dist/image-2w3cApg7-CrpUMCvm.mjs +3 -0
- package/dist/interactive-init-C5MFL5MW.mjs +8 -0
- package/dist/io-CH2g3vsv-JJtUIa_U.mjs +10 -0
- package/dist/jiti-loader-cache-Bat69wam-DNIteTtO.mjs +9 -0
- package/dist/json-file-BQRNuxmK-hRjIgOXI.mjs +1 -0
- package/dist/json-parse-BESd8UAM.mjs +3 -0
- package/dist/jws-YaZ38F_i.mjs +12 -0
- package/dist/lark-cli-provider-BLMxH6CN.mjs +4 -0
- package/dist/lark-logger-xpMKNNtY.mjs +1 -0
- package/dist/live-smoke-DpURW676.mjs +33 -0
- package/dist/load-context-mb7uvLSn-3xYwSnOZ.mjs +1 -0
- package/dist/loader-708jrx4Y-BbJRXNlQ.mjs +4 -0
- package/dist/main.mjs +153 -74571
- package/dist/manifest-registry-_hxKCS2K-OL8KK_o4.mjs +15 -0
- package/dist/mcp-server.mjs +4 -527
- package/dist/message-channel-Bk_YHfQg-n2Hw2Y0L.mjs +1 -0
- package/dist/message-channel-core-DTA--Gjh-CIh10vfo.mjs +1 -0
- package/dist/message.config.runtime-K-k4XOyq-F_h0Cgkl.mjs +1 -0
- package/dist/message.gateway.runtime-DqHOHRTQ-ge4c5p4s.mjs +1 -0
- package/dist/mistral-DyL3Zo1b.mjs +7 -0
- package/dist/model-auth-env-oyg2Hexc-DJbt9J3o.mjs +1 -0
- package/dist/models-config-BmpSQJQF-BL6S5qAo.mjs +1 -0
- package/dist/models-config.runtime-SOhLEw-f.mjs +1 -0
- package/dist/multipart-parser-B9dwXBqu.mjs +2 -0
- package/dist/oauth-25y2wc7K.mjs +75 -0
- package/dist/openai-C-rgGb7X.mjs +16 -0
- package/dist/openai-codex-responses-BbyAPsP1.mjs +7 -0
- package/dist/openai-completions-Bu5qvQzb.mjs +5 -0
- package/dist/openai-responses-pIdwQBc4.mjs +1 -0
- package/dist/openai-responses-shared-DqW1JSux.mjs +10 -0
- package/dist/paths-D6msg0S1-BO4XgM1u.mjs +1 -0
- package/dist/paths-D92DjaZ--DdtJ-zYp.mjs +1 -0
- package/dist/pi-model-discovery-Bd0TWzo8-DvSM0eWu.mjs +1 -0
- package/dist/pi-model-discovery-runtime-PrjWOmsV.mjs +1 -0
- package/dist/pi-tools.before-tool-call.runtime-Bn7uqKie-WPxU5oNX.mjs +2 -0
- package/dist/plugin-auto-enable-DdH3n9V8-Dr_bUXkG.mjs +1 -0
- package/dist/process-scoped-map-B2cWkYET-Co-i-MXA.mjs +1 -0
- package/dist/provider-discovery.runtime-DY0VWQ81.mjs +1 -0
- package/dist/provider-model-compat-CFqcq0it-BUwZENrz.mjs +1 -0
- package/dist/provider-runtime-C8rljsNs-BDvu6FW3.mjs +1 -0
- package/dist/provider-runtime-CT50mNIX-DImw7ZZu.mjs +79 -0
- package/dist/provider-stream-COLujAAo-Dpq1DSIk.mjs +248 -0
- package/dist/providers.runtime-Ba7tOlq7-B4t6ywCr.mjs +1 -0
- package/dist/public-surface-loader-BVl0NQAE-TfJ3izj1.mjs +1 -0
- package/dist/resolve-C33B7eeu-DZM_z6Wr.mjs +1 -0
- package/dist/runtime-Cym-fqI8-1GOIuRRQ.mjs +1 -0
- package/dist/runtime-channel-state-CohMybAh-BBzhl07Q.mjs +1 -0
- package/dist/runtime-snapshot-C54O1-gI-DxusscPf.mjs +1 -0
- package/dist/runtime-state-IBOIXKOx-Cw1GA1td.mjs +1 -0
- package/dist/runtime-web-tools-fallback.runtime-Ca-qn1mj-BsYE2gOd.mjs +1 -0
- package/dist/runtime-web-tools-manifest.runtime-BgxQTjmq-P6MKP9gQ.mjs +1 -0
- package/dist/runtime-web-tools-public-artifacts.runtime-D9qcoWIX-5VoyjouO.mjs +1 -0
- package/dist/session-archive.runtime-B52_5vs4-cU2tYbBz.mjs +1 -0
- package/dist/session-key-Cn2QoOyX-QZeYmbxd.mjs +1 -0
- package/dist/session-transcript-files.fs-DEeFXruQ-CXIAFSsr.mjs +1 -0
- package/dist/src-CCDx_C-U.mjs +3 -0
- package/dist/src-DACmA9V6.mjs +5 -0
- package/dist/subagent-announce-L5WsQatW--rMn240x.mjs +2 -0
- package/dist/subagent-announce.registry.runtime-DiqZyeTs-DNfNHsls.mjs +1 -0
- package/dist/subagent-registry-steer-runtime-DFgZFC0j-XYS1_qwl.mjs +1 -0
- package/dist/subagent-system-prompt-C1qnN--K-CsU4f97T.mjs +23 -0
- package/dist/target-parsing-loaded-DKkb6jJY-B830OA1a.mjs +12 -0
- package/dist/task-registry-delivery-runtime-Dd1CUkZF-B2Hj2k8C.mjs +16 -0
- package/dist/task-registry-delivery-runtime-ragbeVx5-Bdvo2Q5u.mjs +1 -0
- package/dist/thinking-Bh-7MqXz-uApNUe6g.mjs +1 -0
- package/dist/transcript-E_-ISOkD-VTwb782D.mjs +5 -0
- package/dist/transcript.runtime-BqhvZZdl-B4E0TiX5.mjs +1 -0
- package/dist/transform-messages-BTA3xbAI.mjs +1 -0
- package/dist/web-provider-public-artifacts-BlpRwIUS-DbVhDOrY.mjs +1 -0
- package/dist/web-search-providers.runtime--0aUtC3b-Bjh4Bmrz.mjs +1 -0
- package/package.json +3 -3
- package/dist/account-id-BM1T6029-DYjVxojW.mjs +0 -46
- package/dist/activation-context--5yu1dPF-Bwsn3moT.mjs +0 -172
- package/dist/anthropic-TH8ERTXK.mjs +0 -5962
- package/dist/assistant-visible-text-DuFWokAt-CsbII5KS.mjs +0 -596
- package/dist/azure-openai-responses-Bt_Ag9Er.mjs +0 -166
- package/dist/boundary-file-read-BSd9MXPy--KThL5e6.mjs +0 -594
- package/dist/browser-lifecycle-cleanup-BdNsMhMD-O3tnAM4i.mjs +0 -60
- package/dist/build-DgTrEpge.mjs +0 -3333
- package/dist/bundled-compat-BpaDaAAu-D7oazKjD.mjs +0 -5216
- package/dist/bundled-dir-U738ay4K-DXK0q_TV.mjs +0 -258
- package/dist/call-DimWbpgJ-ColD4W-y.mjs +0 -9993
- package/dist/channel-bootstrap.runtime-BVclcGv1-DJv_Z-Kr.mjs +0 -2
- package/dist/channel-bootstrap.runtime-Cwcr38m2-VRfVCR-i.mjs +0 -33
- package/dist/chunk-D6SyT4dJ.mjs +0 -36
- package/dist/command-format-LSnUCVVF-BQ2SMKka.mjs +0 -685
- package/dist/config-Bim2pi8a-BQUdfiEi.mjs +0 -9
- package/dist/delivery-context.shared-j5hC5qb1-CI83RXXZ.mjs +0 -72
- package/dist/diagnostic-ClMwNnUA-D6nUtLnb.mjs +0 -140
- package/dist/dist-CEGw8-2W.mjs +0 -429
- package/dist/dist-DD2aJ2UL.mjs +0 -125135
- package/dist/env-api-keys-BVvSg7T2.mjs +0 -68
- package/dist/event-stream-xaQWmyas.mjs +0 -15226
- package/dist/facade-loader-DFzIYYt_-CIr4HKtE.mjs +0 -194
- package/dist/from-DF7cl2wz.mjs +0 -3842
- package/dist/gateway-method-policy-C7rf0SeV-CJQMEYIE.mjs +0 -28
- package/dist/github-copilot-headers-DjqWtUoP.mjs +0 -22
- package/dist/google-C2pVrgBZ.mjs +0 -336
- package/dist/google-gemini-cli-BBxgS5Ho.mjs +0 -623
- package/dist/google-shared-BsWgwEk1.mjs +0 -22791
- package/dist/google-vertex-BsVLJrrC.mjs +0 -358
- package/dist/hash-DAFtW_W7.mjs +0 -16
- package/dist/headers-R3HdCbAE.mjs +0 -8
- package/dist/home-dir-C44RaPME-CBRS4HLP.mjs +0 -93
- package/dist/ids-BPsM98Uu-CwuxvUai.mjs +0 -77
- package/dist/image-2w3cApg7-CxpHvoB5.mjs +0 -207
- package/dist/interactive-init-BXQBalNr.mjs +0 -450
- package/dist/io-CH2g3vsv-BOGlLlB8.mjs +0 -26218
- package/dist/jiti-loader-cache-Bat69wam-D6hCxboy.mjs +0 -5049
- package/dist/json-file-BQRNuxmK-DhJM5NsG.mjs +0 -108
- package/dist/json-parse-v_HIJjjI.mjs +0 -381
- package/dist/jws-GFcTvvVT.mjs +0 -2291
- package/dist/lark-cli-provider-BARgbbmo.mjs +0 -554
- package/dist/lark-logger-D7_pEVQc.mjs +0 -143
- package/dist/live-smoke-BhkBOcH9.mjs +0 -7135
- package/dist/load-context-mb7uvLSn-B10MAi3I.mjs +0 -29
- package/dist/loader-708jrx4Y-BOswuvpe.mjs +0 -5053
- package/dist/manifest-registry-_hxKCS2K-CZdeyN0f.mjs +0 -3512
- package/dist/message-channel-Bk_YHfQg-AeNrPPpp.mjs +0 -50
- package/dist/message-channel-core-DTA--Gjh-CY4Tkb7N.mjs +0 -29
- package/dist/message.config.runtime-K-k4XOyq-DZTmXomP.mjs +0 -2
- package/dist/message.gateway.runtime-DqHOHRTQ-DH4ml0YF.mjs +0 -2
- package/dist/mistral-CaR4DiLu.mjs +0 -28657
- package/dist/model-auth-env-oyg2Hexc-DU_rOUU5.mjs +0 -1306
- package/dist/models-config-BmpSQJQF-Gfvh1n3A.mjs +0 -1282
- package/dist/models-config.runtime-BsU_22xk.mjs +0 -2
- package/dist/multipart-parser-DedmaB5g.mjs +0 -294
- package/dist/oauth-DOJeGfcE.mjs +0 -6392
- package/dist/openai-BDtIh3Ja.mjs +0 -6693
- package/dist/openai-codex-responses-C5EORu31.mjs +0 -664
- package/dist/openai-completions-CR_cS6gX.mjs +0 -669
- package/dist/openai-responses-oGxwZyuC.mjs +0 -184
- package/dist/openai-responses-shared-BixMSDZE.mjs +0 -398
- package/dist/paths-D6msg0S1-C2lYuisN.mjs +0 -189
- package/dist/paths-D92DjaZ--CTOESW2b.mjs +0 -192
- package/dist/pi-model-discovery-Bd0TWzo8-BFsJmeMb.mjs +0 -227
- package/dist/pi-model-discovery-runtime-CCCZxkd8.mjs +0 -2
- package/dist/pi-tools.before-tool-call.runtime-Bn7uqKie-C5ewk8kK.mjs +0 -399
- package/dist/plugin-auto-enable-DdH3n9V8-DsA1isaF.mjs +0 -1456
- package/dist/process-scoped-map-B2cWkYET-CXwUZ8CZ.mjs +0 -61
- package/dist/provider-discovery.runtime-BPzz1PFj.mjs +0 -58
- package/dist/provider-model-compat-CFqcq0it-BDDuBI3A.mjs +0 -118
- package/dist/provider-runtime-C8rljsNs-CIT93zoy.mjs +0 -2
- package/dist/provider-runtime-CT50mNIX-BwEV6GyO.mjs +0 -573
- package/dist/provider-stream-COLujAAo-CbJPDngm.mjs +0 -35449
- package/dist/providers.runtime-Ba7tOlq7-CXkhkzU9.mjs +0 -219
- package/dist/public-surface-loader-BVl0NQAE-C0piXtsT.mjs +0 -117
- package/dist/resolve-C33B7eeu-BNvYTl6k.mjs +0 -1041
- package/dist/runtime-Cym-fqI8-DaSDMH-a.mjs +0 -120
- package/dist/runtime-channel-state-CohMybAh-hXR6y5Gx.mjs +0 -19
- package/dist/runtime-snapshot-C54O1-gI-40cbyi7P.mjs +0 -677
- package/dist/runtime-state-IBOIXKOx-Bf9tcLvc.mjs +0 -10
- package/dist/runtime-web-tools-fallback.runtime-Ca-qn1mj-BCVImm7a.mjs +0 -39
- package/dist/runtime-web-tools-manifest.runtime-BgxQTjmq-Cb4nJkRT.mjs +0 -2
- package/dist/runtime-web-tools-public-artifacts.runtime-D9qcoWIX-BrQdXzOQ.mjs +0 -2
- package/dist/session-archive.runtime-B52_5vs4-BG-_IwNJ.mjs +0 -2
- package/dist/session-key-Cn2QoOyX-CuHbJMgR.mjs +0 -82
- package/dist/session-transcript-files.fs-DEeFXruQ-B1PF6nLy.mjs +0 -147
- package/dist/src-BgCX0MLG.mjs +0 -813
- package/dist/src-DYbqlAqf.mjs +0 -1177
- package/dist/subagent-announce-L5WsQatW-CQWI9GMd.mjs +0 -344
- package/dist/subagent-announce.registry.runtime-DiqZyeTs-BKuniyi3.mjs +0 -28
- package/dist/subagent-registry-steer-runtime-DFgZFC0j-BhBz0roy.mjs +0 -211
- package/dist/subagent-system-prompt-C1qnN--K-DpnTFP47.mjs +0 -3061
- package/dist/target-parsing-loaded-DKkb6jJY-BMD4CkpS.mjs +0 -1002
- package/dist/task-registry-delivery-runtime-Dd1CUkZF-C8U40a3O.mjs +0 -2950
- package/dist/task-registry-delivery-runtime-ragbeVx5-CNbFAkjD.mjs +0 -2
- package/dist/thinking-Bh-7MqXz-D3woGbO7.mjs +0 -2
- package/dist/transcript-E_-ISOkD-DWCfZP2p.mjs +0 -2019
- package/dist/transcript.runtime-BqhvZZdl-BPy42vBP.mjs +0 -2
- package/dist/transform-messages-DbhIzTxq.mjs +0 -207
- package/dist/web-provider-public-artifacts-BlpRwIUS-CGPSV4W2.mjs +0 -295
- package/dist/web-search-providers.runtime--0aUtC3b-DyuhC95V.mjs +0 -200
|
@@ -1,623 +0,0 @@
|
|
|
1
|
-
import { r as calculateCost, t as AssistantMessageEventStream } from "./event-stream-xaQWmyas.mjs";
|
|
2
|
-
import { t as headersToRecord } from "./headers-R3HdCbAE.mjs";
|
|
3
|
-
import { a as sanitizeSurrogates, i as clampReasoning, r as buildBaseOptions } from "./transform-messages-DbhIzTxq.mjs";
|
|
4
|
-
import { a as mapStopReasonString, n as convertTools, o as mapToolChoice, r as isThinkingPart, s as retainThoughtSignature, t as convertMessages } from "./google-shared-BsWgwEk1.mjs";
|
|
5
|
-
//#region node_modules/.pnpm/@mariozechner+pi-ai@0.69.0_@modelcontextprotocol+sdk@1.29.0_zod@4.3.6__ws@8.21.0_zod@4.3.6/node_modules/@mariozechner/pi-ai/dist/providers/google-gemini-cli.js
|
|
6
|
-
/**
|
|
7
|
-
* Google Gemini CLI / Antigravity provider.
|
|
8
|
-
* Shared implementation for both google-gemini-cli and google-antigravity providers.
|
|
9
|
-
* Uses the Cloud Code Assist API endpoint to access Gemini and Claude models.
|
|
10
|
-
*/
|
|
11
|
-
const DEFAULT_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
12
|
-
const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
|
|
13
|
-
"https://daily-cloudcode-pa.sandbox.googleapis.com",
|
|
14
|
-
"https://autopush-cloudcode-pa.sandbox.googleapis.com",
|
|
15
|
-
DEFAULT_ENDPOINT
|
|
16
|
-
];
|
|
17
|
-
const GEMINI_CLI_HEADERS = {
|
|
18
|
-
"User-Agent": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
19
|
-
"X-Goog-Api-Client": "gl-node/22.17.0",
|
|
20
|
-
"Client-Metadata": JSON.stringify({
|
|
21
|
-
ideType: "IDE_UNSPECIFIED",
|
|
22
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
23
|
-
pluginType: "GEMINI"
|
|
24
|
-
})
|
|
25
|
-
};
|
|
26
|
-
const DEFAULT_ANTIGRAVITY_VERSION = "1.21.9";
|
|
27
|
-
function getAntigravityHeaders() {
|
|
28
|
-
return { "User-Agent": `antigravity/${process.env.PI_AI_ANTIGRAVITY_VERSION || DEFAULT_ANTIGRAVITY_VERSION} darwin/arm64` };
|
|
29
|
-
}
|
|
30
|
-
const ANTIGRAVITY_SYSTEM_INSTRUCTION = "You are Antigravity, a powerful agentic AI coding assistant designed by the Google Deepmind team working on Advanced Agentic Coding.You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question.**Absolute paths only****Proactiveness**";
|
|
31
|
-
let toolCallCounter = 0;
|
|
32
|
-
const MAX_RETRIES = 3;
|
|
33
|
-
const BASE_DELAY_MS = 1e3;
|
|
34
|
-
const MAX_EMPTY_STREAM_RETRIES = 2;
|
|
35
|
-
const EMPTY_STREAM_BASE_DELAY_MS = 500;
|
|
36
|
-
const CLAUDE_THINKING_BETA_HEADER = "interleaved-thinking-2025-05-14";
|
|
37
|
-
/**
|
|
38
|
-
* Extract retry delay from Gemini error response (in milliseconds).
|
|
39
|
-
* Checks headers first (Retry-After, x-ratelimit-reset, x-ratelimit-reset-after),
|
|
40
|
-
* then parses body patterns like:
|
|
41
|
-
* - "Your quota will reset after 39s"
|
|
42
|
-
* - "Your quota will reset after 18h31m10s"
|
|
43
|
-
* - "Please retry in Xs" or "Please retry in Xms"
|
|
44
|
-
* - "retryDelay": "34.074824224s" (JSON field)
|
|
45
|
-
*/
|
|
46
|
-
function extractRetryDelay(errorText, response) {
|
|
47
|
-
const normalizeDelay = (ms) => ms > 0 ? Math.ceil(ms + 1e3) : void 0;
|
|
48
|
-
const headers = response instanceof Headers ? response : response?.headers;
|
|
49
|
-
if (headers) {
|
|
50
|
-
const retryAfter = headers.get("retry-after");
|
|
51
|
-
if (retryAfter) {
|
|
52
|
-
const retryAfterSeconds = Number(retryAfter);
|
|
53
|
-
if (Number.isFinite(retryAfterSeconds)) {
|
|
54
|
-
const delay = normalizeDelay(retryAfterSeconds * 1e3);
|
|
55
|
-
if (delay !== void 0) return delay;
|
|
56
|
-
}
|
|
57
|
-
const retryAfterMs = new Date(retryAfter).getTime();
|
|
58
|
-
if (!Number.isNaN(retryAfterMs)) {
|
|
59
|
-
const delay = normalizeDelay(retryAfterMs - Date.now());
|
|
60
|
-
if (delay !== void 0) return delay;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const rateLimitReset = headers.get("x-ratelimit-reset");
|
|
64
|
-
if (rateLimitReset) {
|
|
65
|
-
const resetSeconds = Number.parseInt(rateLimitReset, 10);
|
|
66
|
-
if (!Number.isNaN(resetSeconds)) {
|
|
67
|
-
const delay = normalizeDelay(resetSeconds * 1e3 - Date.now());
|
|
68
|
-
if (delay !== void 0) return delay;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const rateLimitResetAfter = headers.get("x-ratelimit-reset-after");
|
|
72
|
-
if (rateLimitResetAfter) {
|
|
73
|
-
const resetAfterSeconds = Number(rateLimitResetAfter);
|
|
74
|
-
if (Number.isFinite(resetAfterSeconds)) {
|
|
75
|
-
const delay = normalizeDelay(resetAfterSeconds * 1e3);
|
|
76
|
-
if (delay !== void 0) return delay;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const durationMatch = errorText.match(/reset after (?:(\d+)h)?(?:(\d+)m)?(\d+(?:\.\d+)?)s/i);
|
|
81
|
-
if (durationMatch) {
|
|
82
|
-
const hours = durationMatch[1] ? parseInt(durationMatch[1], 10) : 0;
|
|
83
|
-
const minutes = durationMatch[2] ? parseInt(durationMatch[2], 10) : 0;
|
|
84
|
-
const seconds = parseFloat(durationMatch[3]);
|
|
85
|
-
if (!Number.isNaN(seconds)) {
|
|
86
|
-
const delay = normalizeDelay(((hours * 60 + minutes) * 60 + seconds) * 1e3);
|
|
87
|
-
if (delay !== void 0) return delay;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const retryInMatch = errorText.match(/Please retry in ([0-9.]+)(ms|s)/i);
|
|
91
|
-
if (retryInMatch?.[1]) {
|
|
92
|
-
const value = parseFloat(retryInMatch[1]);
|
|
93
|
-
if (!Number.isNaN(value) && value > 0) {
|
|
94
|
-
const delay = normalizeDelay(retryInMatch[2].toLowerCase() === "ms" ? value : value * 1e3);
|
|
95
|
-
if (delay !== void 0) return delay;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const retryDelayMatch = errorText.match(/"retryDelay":\s*"([0-9.]+)(ms|s)"/i);
|
|
99
|
-
if (retryDelayMatch?.[1]) {
|
|
100
|
-
const value = parseFloat(retryDelayMatch[1]);
|
|
101
|
-
if (!Number.isNaN(value) && value > 0) {
|
|
102
|
-
const delay = normalizeDelay(retryDelayMatch[2].toLowerCase() === "ms" ? value : value * 1e3);
|
|
103
|
-
if (delay !== void 0) return delay;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function needsClaudeThinkingBetaHeader(model) {
|
|
108
|
-
return model.provider === "google-antigravity" && model.id.startsWith("claude-") && model.reasoning;
|
|
109
|
-
}
|
|
110
|
-
function isGemini3ProModel(modelId) {
|
|
111
|
-
return /gemini-3(?:\.1)?-pro/.test(modelId.toLowerCase());
|
|
112
|
-
}
|
|
113
|
-
function isGemini3FlashModel(modelId) {
|
|
114
|
-
return /gemini-3(?:\.1)?-flash/.test(modelId.toLowerCase());
|
|
115
|
-
}
|
|
116
|
-
function isGemini3Model(modelId) {
|
|
117
|
-
return isGemini3ProModel(modelId) || isGemini3FlashModel(modelId);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Check if an error is retryable (rate limit, server error, network error, etc.)
|
|
121
|
-
*/
|
|
122
|
-
function isRetryableError(status, errorText) {
|
|
123
|
-
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) return true;
|
|
124
|
-
return /resource.?exhausted|rate.?limit|overloaded|service.?unavailable|other.?side.?closed/i.test(errorText);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Extract a clean, user-friendly error message from Google API error response.
|
|
128
|
-
* Parses JSON error responses and returns just the message field.
|
|
129
|
-
*/
|
|
130
|
-
function extractErrorMessage(errorText) {
|
|
131
|
-
try {
|
|
132
|
-
const parsed = JSON.parse(errorText);
|
|
133
|
-
if (parsed.error?.message) return parsed.error.message;
|
|
134
|
-
} catch {}
|
|
135
|
-
return errorText;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Sleep for a given number of milliseconds, respecting abort signal.
|
|
139
|
-
*/
|
|
140
|
-
function sleep(ms, signal) {
|
|
141
|
-
return new Promise((resolve, reject) => {
|
|
142
|
-
if (signal?.aborted) {
|
|
143
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const timeout = setTimeout(resolve, ms);
|
|
147
|
-
signal?.addEventListener("abort", () => {
|
|
148
|
-
clearTimeout(timeout);
|
|
149
|
-
reject(/* @__PURE__ */ new Error("Request was aborted"));
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
const streamGoogleGeminiCli = (model, context, options) => {
|
|
154
|
-
const stream = new AssistantMessageEventStream();
|
|
155
|
-
(async () => {
|
|
156
|
-
const output = {
|
|
157
|
-
role: "assistant",
|
|
158
|
-
content: [],
|
|
159
|
-
api: "google-gemini-cli",
|
|
160
|
-
provider: model.provider,
|
|
161
|
-
model: model.id,
|
|
162
|
-
usage: {
|
|
163
|
-
input: 0,
|
|
164
|
-
output: 0,
|
|
165
|
-
cacheRead: 0,
|
|
166
|
-
cacheWrite: 0,
|
|
167
|
-
totalTokens: 0,
|
|
168
|
-
cost: {
|
|
169
|
-
input: 0,
|
|
170
|
-
output: 0,
|
|
171
|
-
cacheRead: 0,
|
|
172
|
-
cacheWrite: 0,
|
|
173
|
-
total: 0
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
stopReason: "stop",
|
|
177
|
-
timestamp: Date.now()
|
|
178
|
-
};
|
|
179
|
-
try {
|
|
180
|
-
const apiKeyRaw = options?.apiKey;
|
|
181
|
-
if (!apiKeyRaw) throw new Error("Google Cloud Code Assist requires OAuth authentication. Use /login to authenticate.");
|
|
182
|
-
let accessToken;
|
|
183
|
-
let projectId;
|
|
184
|
-
try {
|
|
185
|
-
const parsed = JSON.parse(apiKeyRaw);
|
|
186
|
-
accessToken = parsed.token;
|
|
187
|
-
projectId = parsed.projectId;
|
|
188
|
-
} catch {
|
|
189
|
-
throw new Error("Invalid Google Cloud Code Assist credentials. Use /login to re-authenticate.");
|
|
190
|
-
}
|
|
191
|
-
if (!accessToken || !projectId) throw new Error("Missing token or projectId in Google Cloud credentials. Use /login to re-authenticate.");
|
|
192
|
-
const isAntigravity = model.provider === "google-antigravity";
|
|
193
|
-
const baseUrl = model.baseUrl?.trim();
|
|
194
|
-
const endpoints = baseUrl ? [baseUrl] : isAntigravity ? ANTIGRAVITY_ENDPOINT_FALLBACKS : [DEFAULT_ENDPOINT];
|
|
195
|
-
let requestBody = buildRequest(model, context, projectId, options, isAntigravity);
|
|
196
|
-
const nextRequestBody = await options?.onPayload?.(requestBody, model);
|
|
197
|
-
if (nextRequestBody !== void 0) requestBody = nextRequestBody;
|
|
198
|
-
const headers = isAntigravity ? getAntigravityHeaders() : GEMINI_CLI_HEADERS;
|
|
199
|
-
const requestHeaders = {
|
|
200
|
-
Authorization: `Bearer ${accessToken}`,
|
|
201
|
-
"Content-Type": "application/json",
|
|
202
|
-
Accept: "text/event-stream",
|
|
203
|
-
...headers,
|
|
204
|
-
...needsClaudeThinkingBetaHeader(model) ? { "anthropic-beta": CLAUDE_THINKING_BETA_HEADER } : {},
|
|
205
|
-
...options?.headers
|
|
206
|
-
};
|
|
207
|
-
const requestBodyJson = JSON.stringify(requestBody);
|
|
208
|
-
let response;
|
|
209
|
-
let lastError;
|
|
210
|
-
let requestUrl;
|
|
211
|
-
let endpointIndex = 0;
|
|
212
|
-
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
213
|
-
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
214
|
-
try {
|
|
215
|
-
requestUrl = `${endpoints[endpointIndex]}/v1internal:streamGenerateContent?alt=sse`;
|
|
216
|
-
response = await fetch(requestUrl, {
|
|
217
|
-
method: "POST",
|
|
218
|
-
headers: requestHeaders,
|
|
219
|
-
body: requestBodyJson,
|
|
220
|
-
signal: options?.signal
|
|
221
|
-
});
|
|
222
|
-
await options?.onResponse?.({
|
|
223
|
-
status: response.status,
|
|
224
|
-
headers: headersToRecord(response.headers)
|
|
225
|
-
}, model);
|
|
226
|
-
if (response.ok) break;
|
|
227
|
-
const errorText = await response.text();
|
|
228
|
-
if ((response.status === 403 || response.status === 404) && endpointIndex < endpoints.length - 1) {
|
|
229
|
-
endpointIndex++;
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
if (attempt < MAX_RETRIES && isRetryableError(response.status, errorText)) {
|
|
233
|
-
if (endpointIndex < endpoints.length - 1) endpointIndex++;
|
|
234
|
-
const serverDelay = extractRetryDelay(errorText, response);
|
|
235
|
-
const delayMs = serverDelay ?? BASE_DELAY_MS * 2 ** attempt;
|
|
236
|
-
const maxDelayMs = options?.maxRetryDelayMs ?? 6e4;
|
|
237
|
-
if (maxDelayMs > 0 && serverDelay && serverDelay > maxDelayMs) {
|
|
238
|
-
const delaySeconds = Math.ceil(serverDelay / 1e3);
|
|
239
|
-
throw new Error(`Server requested ${delaySeconds}s retry delay (max: ${Math.ceil(maxDelayMs / 1e3)}s). ${extractErrorMessage(errorText)}`);
|
|
240
|
-
}
|
|
241
|
-
await sleep(delayMs, options?.signal);
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
throw new Error(`Cloud Code Assist API error (${response.status}): ${extractErrorMessage(errorText)}`);
|
|
245
|
-
} catch (error) {
|
|
246
|
-
if (error instanceof Error) {
|
|
247
|
-
if (error.name === "AbortError" || error.message === "Request was aborted") throw new Error("Request was aborted");
|
|
248
|
-
}
|
|
249
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
250
|
-
if (lastError.message === "fetch failed" && lastError.cause instanceof Error) lastError = /* @__PURE__ */ new Error(`Network error: ${lastError.cause.message}`);
|
|
251
|
-
if (attempt < MAX_RETRIES) {
|
|
252
|
-
await sleep(BASE_DELAY_MS * 2 ** attempt, options?.signal);
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
throw lastError;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
if (!response || !response.ok) throw lastError ?? /* @__PURE__ */ new Error("Failed to get response after retries");
|
|
259
|
-
let started = false;
|
|
260
|
-
const ensureStarted = () => {
|
|
261
|
-
if (!started) {
|
|
262
|
-
stream.push({
|
|
263
|
-
type: "start",
|
|
264
|
-
partial: output
|
|
265
|
-
});
|
|
266
|
-
started = true;
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
const resetOutput = () => {
|
|
270
|
-
output.content = [];
|
|
271
|
-
output.usage = {
|
|
272
|
-
input: 0,
|
|
273
|
-
output: 0,
|
|
274
|
-
cacheRead: 0,
|
|
275
|
-
cacheWrite: 0,
|
|
276
|
-
totalTokens: 0,
|
|
277
|
-
cost: {
|
|
278
|
-
input: 0,
|
|
279
|
-
output: 0,
|
|
280
|
-
cacheRead: 0,
|
|
281
|
-
cacheWrite: 0,
|
|
282
|
-
total: 0
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
output.stopReason = "stop";
|
|
286
|
-
output.errorMessage = void 0;
|
|
287
|
-
output.timestamp = Date.now();
|
|
288
|
-
started = false;
|
|
289
|
-
};
|
|
290
|
-
const streamResponse = async (activeResponse) => {
|
|
291
|
-
if (!activeResponse.body) throw new Error("No response body");
|
|
292
|
-
let hasContent = false;
|
|
293
|
-
let currentBlock = null;
|
|
294
|
-
const blocks = output.content;
|
|
295
|
-
const blockIndex = () => blocks.length - 1;
|
|
296
|
-
const reader = activeResponse.body.getReader();
|
|
297
|
-
const decoder = new TextDecoder();
|
|
298
|
-
let buffer = "";
|
|
299
|
-
const abortHandler = () => {
|
|
300
|
-
reader.cancel().catch(() => {});
|
|
301
|
-
};
|
|
302
|
-
options?.signal?.addEventListener("abort", abortHandler);
|
|
303
|
-
try {
|
|
304
|
-
while (true) {
|
|
305
|
-
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
306
|
-
const { done, value } = await reader.read();
|
|
307
|
-
if (done) break;
|
|
308
|
-
buffer += decoder.decode(value, { stream: true });
|
|
309
|
-
const lines = buffer.split("\n");
|
|
310
|
-
buffer = lines.pop() || "";
|
|
311
|
-
for (const line of lines) {
|
|
312
|
-
if (!line.startsWith("data:")) continue;
|
|
313
|
-
const jsonStr = line.slice(5).trim();
|
|
314
|
-
if (!jsonStr) continue;
|
|
315
|
-
let chunk;
|
|
316
|
-
try {
|
|
317
|
-
chunk = JSON.parse(jsonStr);
|
|
318
|
-
} catch {
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
const responseData = chunk.response;
|
|
322
|
-
if (!responseData) continue;
|
|
323
|
-
output.responseId ||= responseData.responseId;
|
|
324
|
-
const candidate = responseData.candidates?.[0];
|
|
325
|
-
if (candidate?.content?.parts) for (const part of candidate.content.parts) {
|
|
326
|
-
if (part.text !== void 0) {
|
|
327
|
-
hasContent = true;
|
|
328
|
-
const isThinking = isThinkingPart(part);
|
|
329
|
-
if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
|
|
330
|
-
if (currentBlock) if (currentBlock.type === "text") stream.push({
|
|
331
|
-
type: "text_end",
|
|
332
|
-
contentIndex: blocks.length - 1,
|
|
333
|
-
content: currentBlock.text,
|
|
334
|
-
partial: output
|
|
335
|
-
});
|
|
336
|
-
else stream.push({
|
|
337
|
-
type: "thinking_end",
|
|
338
|
-
contentIndex: blockIndex(),
|
|
339
|
-
content: currentBlock.thinking,
|
|
340
|
-
partial: output
|
|
341
|
-
});
|
|
342
|
-
if (isThinking) {
|
|
343
|
-
currentBlock = {
|
|
344
|
-
type: "thinking",
|
|
345
|
-
thinking: "",
|
|
346
|
-
thinkingSignature: void 0
|
|
347
|
-
};
|
|
348
|
-
output.content.push(currentBlock);
|
|
349
|
-
ensureStarted();
|
|
350
|
-
stream.push({
|
|
351
|
-
type: "thinking_start",
|
|
352
|
-
contentIndex: blockIndex(),
|
|
353
|
-
partial: output
|
|
354
|
-
});
|
|
355
|
-
} else {
|
|
356
|
-
currentBlock = {
|
|
357
|
-
type: "text",
|
|
358
|
-
text: ""
|
|
359
|
-
};
|
|
360
|
-
output.content.push(currentBlock);
|
|
361
|
-
ensureStarted();
|
|
362
|
-
stream.push({
|
|
363
|
-
type: "text_start",
|
|
364
|
-
contentIndex: blockIndex(),
|
|
365
|
-
partial: output
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (currentBlock.type === "thinking") {
|
|
370
|
-
currentBlock.thinking += part.text;
|
|
371
|
-
currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
|
|
372
|
-
stream.push({
|
|
373
|
-
type: "thinking_delta",
|
|
374
|
-
contentIndex: blockIndex(),
|
|
375
|
-
delta: part.text,
|
|
376
|
-
partial: output
|
|
377
|
-
});
|
|
378
|
-
} else {
|
|
379
|
-
currentBlock.text += part.text;
|
|
380
|
-
currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
|
|
381
|
-
stream.push({
|
|
382
|
-
type: "text_delta",
|
|
383
|
-
contentIndex: blockIndex(),
|
|
384
|
-
delta: part.text,
|
|
385
|
-
partial: output
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
if (part.functionCall) {
|
|
390
|
-
hasContent = true;
|
|
391
|
-
if (currentBlock) {
|
|
392
|
-
if (currentBlock.type === "text") stream.push({
|
|
393
|
-
type: "text_end",
|
|
394
|
-
contentIndex: blockIndex(),
|
|
395
|
-
content: currentBlock.text,
|
|
396
|
-
partial: output
|
|
397
|
-
});
|
|
398
|
-
else stream.push({
|
|
399
|
-
type: "thinking_end",
|
|
400
|
-
contentIndex: blockIndex(),
|
|
401
|
-
content: currentBlock.thinking,
|
|
402
|
-
partial: output
|
|
403
|
-
});
|
|
404
|
-
currentBlock = null;
|
|
405
|
-
}
|
|
406
|
-
const providedId = part.functionCall.id;
|
|
407
|
-
const toolCall = {
|
|
408
|
-
type: "toolCall",
|
|
409
|
-
id: !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId) ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId,
|
|
410
|
-
name: part.functionCall.name || "",
|
|
411
|
-
arguments: part.functionCall.args ?? {},
|
|
412
|
-
...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
|
|
413
|
-
};
|
|
414
|
-
output.content.push(toolCall);
|
|
415
|
-
ensureStarted();
|
|
416
|
-
stream.push({
|
|
417
|
-
type: "toolcall_start",
|
|
418
|
-
contentIndex: blockIndex(),
|
|
419
|
-
partial: output
|
|
420
|
-
});
|
|
421
|
-
stream.push({
|
|
422
|
-
type: "toolcall_delta",
|
|
423
|
-
contentIndex: blockIndex(),
|
|
424
|
-
delta: JSON.stringify(toolCall.arguments),
|
|
425
|
-
partial: output
|
|
426
|
-
});
|
|
427
|
-
stream.push({
|
|
428
|
-
type: "toolcall_end",
|
|
429
|
-
contentIndex: blockIndex(),
|
|
430
|
-
toolCall,
|
|
431
|
-
partial: output
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
if (candidate?.finishReason) {
|
|
436
|
-
output.stopReason = mapStopReasonString(candidate.finishReason);
|
|
437
|
-
if (output.content.some((b) => b.type === "toolCall")) output.stopReason = "toolUse";
|
|
438
|
-
}
|
|
439
|
-
if (responseData.usageMetadata) {
|
|
440
|
-
const promptTokens = responseData.usageMetadata.promptTokenCount || 0;
|
|
441
|
-
const cacheReadTokens = responseData.usageMetadata.cachedContentTokenCount || 0;
|
|
442
|
-
output.usage = {
|
|
443
|
-
input: promptTokens - cacheReadTokens,
|
|
444
|
-
output: (responseData.usageMetadata.candidatesTokenCount || 0) + (responseData.usageMetadata.thoughtsTokenCount || 0),
|
|
445
|
-
cacheRead: cacheReadTokens,
|
|
446
|
-
cacheWrite: 0,
|
|
447
|
-
totalTokens: responseData.usageMetadata.totalTokenCount || 0,
|
|
448
|
-
cost: {
|
|
449
|
-
input: 0,
|
|
450
|
-
output: 0,
|
|
451
|
-
cacheRead: 0,
|
|
452
|
-
cacheWrite: 0,
|
|
453
|
-
total: 0
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
calculateCost(model, output.usage);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
} finally {
|
|
461
|
-
options?.signal?.removeEventListener("abort", abortHandler);
|
|
462
|
-
}
|
|
463
|
-
if (currentBlock) if (currentBlock.type === "text") stream.push({
|
|
464
|
-
type: "text_end",
|
|
465
|
-
contentIndex: blockIndex(),
|
|
466
|
-
content: currentBlock.text,
|
|
467
|
-
partial: output
|
|
468
|
-
});
|
|
469
|
-
else stream.push({
|
|
470
|
-
type: "thinking_end",
|
|
471
|
-
contentIndex: blockIndex(),
|
|
472
|
-
content: currentBlock.thinking,
|
|
473
|
-
partial: output
|
|
474
|
-
});
|
|
475
|
-
return hasContent;
|
|
476
|
-
};
|
|
477
|
-
let receivedContent = false;
|
|
478
|
-
let currentResponse = response;
|
|
479
|
-
for (let emptyAttempt = 0; emptyAttempt <= MAX_EMPTY_STREAM_RETRIES; emptyAttempt++) {
|
|
480
|
-
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
481
|
-
if (emptyAttempt > 0) {
|
|
482
|
-
await sleep(EMPTY_STREAM_BASE_DELAY_MS * 2 ** (emptyAttempt - 1), options?.signal);
|
|
483
|
-
if (!requestUrl) throw new Error("Missing request URL");
|
|
484
|
-
currentResponse = await fetch(requestUrl, {
|
|
485
|
-
method: "POST",
|
|
486
|
-
headers: requestHeaders,
|
|
487
|
-
body: requestBodyJson,
|
|
488
|
-
signal: options?.signal
|
|
489
|
-
});
|
|
490
|
-
await options?.onResponse?.({
|
|
491
|
-
status: currentResponse.status,
|
|
492
|
-
headers: headersToRecord(currentResponse.headers)
|
|
493
|
-
}, model);
|
|
494
|
-
if (!currentResponse.ok) {
|
|
495
|
-
const retryErrorText = await currentResponse.text();
|
|
496
|
-
throw new Error(`Cloud Code Assist API error (${currentResponse.status}): ${retryErrorText}`);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
if (await streamResponse(currentResponse)) {
|
|
500
|
-
receivedContent = true;
|
|
501
|
-
break;
|
|
502
|
-
}
|
|
503
|
-
if (emptyAttempt < MAX_EMPTY_STREAM_RETRIES) resetOutput();
|
|
504
|
-
}
|
|
505
|
-
if (!receivedContent) throw new Error("Cloud Code Assist API returned an empty response");
|
|
506
|
-
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
507
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
508
|
-
stream.push({
|
|
509
|
-
type: "done",
|
|
510
|
-
reason: output.stopReason,
|
|
511
|
-
message: output
|
|
512
|
-
});
|
|
513
|
-
stream.end();
|
|
514
|
-
} catch (error) {
|
|
515
|
-
for (const block of output.content) if ("index" in block) delete block.index;
|
|
516
|
-
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
517
|
-
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
518
|
-
stream.push({
|
|
519
|
-
type: "error",
|
|
520
|
-
reason: output.stopReason,
|
|
521
|
-
error: output
|
|
522
|
-
});
|
|
523
|
-
stream.end();
|
|
524
|
-
}
|
|
525
|
-
})();
|
|
526
|
-
return stream;
|
|
527
|
-
};
|
|
528
|
-
const streamSimpleGoogleGeminiCli = (model, context, options) => {
|
|
529
|
-
const apiKey = options?.apiKey;
|
|
530
|
-
if (!apiKey) throw new Error("Google Cloud Code Assist requires OAuth authentication. Use /login to authenticate.");
|
|
531
|
-
const base = buildBaseOptions(model, options, apiKey);
|
|
532
|
-
if (!options?.reasoning) return streamGoogleGeminiCli(model, context, {
|
|
533
|
-
...base,
|
|
534
|
-
thinking: { enabled: false }
|
|
535
|
-
});
|
|
536
|
-
const effort = clampReasoning(options.reasoning);
|
|
537
|
-
if (isGemini3Model(model.id)) return streamGoogleGeminiCli(model, context, {
|
|
538
|
-
...base,
|
|
539
|
-
thinking: {
|
|
540
|
-
enabled: true,
|
|
541
|
-
level: getGeminiCliThinkingLevel(effort, model.id)
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
const budgets = {
|
|
545
|
-
minimal: 1024,
|
|
546
|
-
low: 2048,
|
|
547
|
-
medium: 8192,
|
|
548
|
-
high: 16384,
|
|
549
|
-
...options.thinkingBudgets
|
|
550
|
-
};
|
|
551
|
-
const minOutputTokens = 1024;
|
|
552
|
-
let thinkingBudget = budgets[effort];
|
|
553
|
-
const maxTokens = Math.min((base.maxTokens || 0) + thinkingBudget, model.maxTokens);
|
|
554
|
-
if (maxTokens <= thinkingBudget) thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
|
|
555
|
-
return streamGoogleGeminiCli(model, context, {
|
|
556
|
-
...base,
|
|
557
|
-
maxTokens,
|
|
558
|
-
thinking: {
|
|
559
|
-
enabled: true,
|
|
560
|
-
budgetTokens: thinkingBudget
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
};
|
|
564
|
-
function buildRequest(model, context, projectId, options = {}, isAntigravity = false) {
|
|
565
|
-
const contents = convertMessages(model, context);
|
|
566
|
-
const generationConfig = {};
|
|
567
|
-
if (options.temperature !== void 0) generationConfig.temperature = options.temperature;
|
|
568
|
-
if (options.maxTokens !== void 0) generationConfig.maxOutputTokens = options.maxTokens;
|
|
569
|
-
if (options.thinking?.enabled && model.reasoning) {
|
|
570
|
-
generationConfig.thinkingConfig = { includeThoughts: true };
|
|
571
|
-
if (options.thinking.level !== void 0) generationConfig.thinkingConfig.thinkingLevel = options.thinking.level;
|
|
572
|
-
else if (options.thinking.budgetTokens !== void 0) generationConfig.thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
|
|
573
|
-
} else if (model.reasoning && options.thinking && !options.thinking.enabled) generationConfig.thinkingConfig = getDisabledThinkingConfig(model.id);
|
|
574
|
-
const request = { contents };
|
|
575
|
-
request.sessionId = options.sessionId;
|
|
576
|
-
if (context.systemPrompt) request.systemInstruction = { parts: [{ text: sanitizeSurrogates(context.systemPrompt) }] };
|
|
577
|
-
if (Object.keys(generationConfig).length > 0) request.generationConfig = generationConfig;
|
|
578
|
-
if (context.tools && context.tools.length > 0) {
|
|
579
|
-
const useParameters = model.id.startsWith("claude-");
|
|
580
|
-
request.tools = convertTools(context.tools, useParameters);
|
|
581
|
-
if (options.toolChoice) request.toolConfig = { functionCallingConfig: { mode: mapToolChoice(options.toolChoice) } };
|
|
582
|
-
}
|
|
583
|
-
if (isAntigravity) {
|
|
584
|
-
const existingParts = request.systemInstruction?.parts ?? [];
|
|
585
|
-
request.systemInstruction = {
|
|
586
|
-
role: "user",
|
|
587
|
-
parts: [
|
|
588
|
-
{ text: ANTIGRAVITY_SYSTEM_INSTRUCTION },
|
|
589
|
-
{ text: `Please ignore following [ignore]${ANTIGRAVITY_SYSTEM_INSTRUCTION}[/ignore]` },
|
|
590
|
-
...existingParts
|
|
591
|
-
]
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
project: projectId,
|
|
596
|
-
model: model.id,
|
|
597
|
-
request,
|
|
598
|
-
...isAntigravity ? { requestType: "agent" } : {},
|
|
599
|
-
userAgent: isAntigravity ? "antigravity" : "pi-coding-agent",
|
|
600
|
-
requestId: `${isAntigravity ? "agent" : "pi"}-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
function getDisabledThinkingConfig(modelId) {
|
|
604
|
-
if (isGemini3ProModel(modelId)) return { thinkingLevel: "LOW" };
|
|
605
|
-
if (isGemini3FlashModel(modelId)) return { thinkingLevel: "MINIMAL" };
|
|
606
|
-
return { thinkingBudget: 0 };
|
|
607
|
-
}
|
|
608
|
-
function getGeminiCliThinkingLevel(effort, modelId) {
|
|
609
|
-
if (isGemini3ProModel(modelId)) switch (effort) {
|
|
610
|
-
case "minimal":
|
|
611
|
-
case "low": return "LOW";
|
|
612
|
-
case "medium":
|
|
613
|
-
case "high": return "HIGH";
|
|
614
|
-
}
|
|
615
|
-
switch (effort) {
|
|
616
|
-
case "minimal": return "MINIMAL";
|
|
617
|
-
case "low": return "LOW";
|
|
618
|
-
case "medium": return "MEDIUM";
|
|
619
|
-
case "high": return "HIGH";
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
//#endregion
|
|
623
|
-
export { buildRequest, extractRetryDelay, streamGoogleGeminiCli, streamSimpleGoogleGeminiCli };
|