@openclaw/ai 2026.10.10 → 2026.11.5-beta.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 +11 -1
- package/dist/.source-module-urls/fe058cc430242ce2ab0dfbcbe153e240a52cf9c3072c3dc0a73e5f956b6ba49b.json +1 -0
- package/dist/anthropic-CTND83W3.mjs +182 -0
- package/dist/{anthropic-payload-policy-rqCq9sT_.d.mts → anthropic-payload-policy-CXCJ5Pmj.d.mts} +21 -4
- package/dist/{anthropic-stream-reducer-C__ByTq1.mjs → anthropic-stream-lifecycle-rJe4OH5H.mjs} +845 -649
- package/dist/{anthropic-tool-projection-JTvMo4KG.d.mts → anthropic-tool-projection-D5DyrL6C.d.mts} +6 -7
- package/dist/{anthropic-tool-projection-DA_KeluM.mjs → anthropic-tool-projection-dGRfr4iT.mjs} +22 -32
- package/dist/{api-registry-gDt0faai.d.mts → api-registry-DY2MLUyg.d.mts} +2 -2
- package/dist/assistant-output-CD4kY9gu.mjs +16 -0
- package/dist/{azure-openai-responses-DHzTwi-y.mjs → azure-openai-responses-BhoLtP4Z.mjs} +46 -52
- package/dist/{cloudflare-Dttf8jKq.mjs → cloudflare-BJ2_Xabx.mjs} +1 -1
- package/dist/{credential-redaction-XvsPf7Yi.d.mts → credential-redaction-DrgndwTJ.d.mts} +5 -3
- package/dist/{deferred-event-buffer-DAvyP7qA.mjs → deferred-event-buffer-tIGkTkTm.mjs} +1 -2
- package/dist/{diagnostics-Cv7cW3pS.mjs → diagnostics-CloVGQiK.mjs} +42 -19
- package/dist/{diagnostics-DzrF1h4J.mjs → diagnostics-o1PrVNQb.mjs} +11 -4
- package/dist/diagnostics.d.mts +6 -7
- package/dist/diagnostics.mjs +4 -4
- package/dist/{env-api-keys-Xd8dm_aV.mjs → env-api-keys-BuHc86ya.mjs} +1 -26
- package/dist/event-stream-B4ZcSvsu.d.mts +1 -0
- package/dist/{event-stream-CzpE1g_o.d.mts → event-stream-BYmtRe8-.d.mts} +1 -1
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -2
- package/dist/expect-lbe3Hgrh.mjs +8 -0
- package/dist/{github-copilot-request-facts-F-EmvkpW.mjs → github-copilot-request-facts-BZ_EMo7X.mjs} +1 -1
- package/dist/{google-CZ6uGVkV.mjs → google-1uObh-eI.mjs} +7 -8
- package/dist/{google-interactions-qd4flmND.mjs → google-interactions-CY8Xb87S.mjs} +208 -233
- package/dist/{google-messages-B-svbJuN.mjs → google-messages-CwBqSoa4.mjs} +16 -13
- package/dist/{google-provider-stream-DlhaCvCf.mjs → google-provider-stream-D30s9EZp.mjs} +17 -10
- package/dist/{google-shared-Cif7nve-.mjs → google-shared-li0lmEZK.mjs} +70 -42
- package/dist/{google-vertex-BZTcYnWU.mjs → google-vertex-B5CHglca.mjs} +3 -3
- package/dist/{host-rCxf5Tjd.mjs → host-DX7ORpeH.mjs} +57 -46
- package/dist/{host-jJOffdlW.d.mts → host-ccbwPC3A.d.mts} +17 -9
- package/dist/{host-policy-Ci1cKluf.mjs → host-policy-jCZebuXx.mjs} +2 -2
- package/dist/index-Bczt0MnO.d.mts +17 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +9 -7
- package/dist/internal/anthropic.d.mts +21 -26
- package/dist/internal/anthropic.mjs +6 -6
- package/dist/internal/google-model-family.mjs +1 -1
- package/dist/internal/google.d.mts +15 -0
- package/dist/internal/google.mjs +1 -0
- package/dist/internal/model-request-body.d.mts +37 -0
- package/dist/internal/model-request-body.mjs +106 -0
- package/dist/internal/openai-completions-compat.d.mts +5 -1
- package/dist/internal/openai-completions-compat.mjs +3 -2
- package/dist/internal/openai-responses-payload-policy.d.mts +2 -2
- package/dist/internal/openai-responses-payload-policy.mjs +2 -2
- package/dist/internal/openai.d.mts +14 -12
- package/dist/internal/openai.mjs +11 -10
- package/dist/internal/reasoning-tag-text-partitioner.d.mts +26 -0
- package/dist/{reasoning-tag-text-partitioner-DzlRubwU.mjs → internal/reasoning-tag-text-partitioner.mjs} +313 -122
- package/dist/internal/retry-after.d.mts +2 -2
- package/dist/internal/retry-after.mjs +165 -27
- package/dist/internal/runtime.d.mts +15 -41
- package/dist/internal/runtime.mjs +9 -10
- package/dist/internal/shared.d.mts +21 -25
- package/dist/internal/shared.mjs +9 -98
- package/dist/internal/tool-schema.d.mts +10 -10
- package/dist/internal/tool-schema.mjs +4 -4
- package/dist/{llm-request-activity-CfMuh5cC.mjs → llm-request-activity-DzaHoRAU.mjs} +2 -2
- package/dist/mistral-F5_asrmU.mjs +3741 -0
- package/dist/mistral.LICENSE +201 -0
- package/dist/{model-transport-url-BrsjjdjR.d.mts → model-transport-url-BdksnBqu.d.mts} +6 -8
- package/dist/{number-coercion-37gmNkuA.mjs → number-coercion-C7HsBgUL.mjs} +7 -2
- package/dist/observe-async-iterator-AlARO5wS.d.mts +178 -0
- package/dist/observe-async-iterator-DgmegcZR.mjs +181 -0
- package/dist/{openai-chatgpt-responses-iGYDPbmc.mjs → openai-chatgpt-responses-BIK7HROH.mjs} +61 -80
- package/dist/{openai-completions-CDy5u1mv.mjs → openai-completions-ClJ7QHEB.mjs} +5 -5
- package/dist/{openai-completions-compat-CBvb2eld.d.mts → openai-completions-compat-CJ-NsDzg.d.mts} +12 -6
- package/dist/{openai-completions-compat-CJ0OXZgi.mjs → openai-completions-compat-CstlTQuF.mjs} +74 -50
- package/dist/openai-completions-reasoning-replay-BwT1xwRI.mjs +45 -0
- package/dist/{openai-completions-transport-DLrm5EWi.mjs → openai-completions-transport-C6J4_oGf.mjs} +501 -563
- package/dist/{openai-prompt-cache-DgjD-UL5.d.mts → openai-prompt-cache-BZGaIWYh.d.mts} +4 -4
- package/dist/{openai-prompt-cache-h8vXRiaH.mjs → openai-prompt-cache-CgDoFhO0.mjs} +5 -4
- package/dist/openai-responses-Beifmf1s.mjs +89 -0
- package/dist/{openai-responses-compaction-replay-DUBbsfku.d.mts → openai-responses-compaction-replay-CNHk6k53.d.mts} +4 -4
- package/dist/{openai-responses-contracts-gnl6ZRs1.d.mts → openai-responses-contracts-BXMcvO7F.d.mts} +4 -10
- package/dist/{openai-responses-contracts-DCG51Us0.mjs → openai-responses-contracts-xU-n9AJJ.mjs} +36 -37
- package/dist/{openai-responses-endpoint-JbBT8IDv.mjs → openai-responses-endpoint-DCkURKS0.mjs} +55 -8
- package/dist/{openai-responses-payload-policy-BzM52TTH.d.mts → openai-responses-payload-policy-DyE30gdD.d.mts} +7 -7
- package/dist/{openai-responses-request-lifecycle-DuMpdA6y.mjs → openai-responses-request-lifecycle-o-ODC_rF.mjs} +12 -26
- package/dist/{openai-responses-shared-CNfHudFg.mjs → openai-responses-shared-CrFDkZ0N.mjs} +637 -389
- package/dist/{openai-responses-terminal-usage-CpVjkqn-.d.mts → openai-responses-terminal-usage-D7IhRA6i.d.mts} +9 -3
- package/dist/{openai-tool-schema-CGhEl7ao.mjs → openai-tool-schema-CsoYgnWy.mjs} +97 -122
- package/dist/otel-D-BkX8bB.mjs +766 -0
- package/dist/{overflow-OF3PgPbw.mjs → overflow-CpApyjG2.mjs} +1 -1
- package/dist/{positive-integer-Bb4Evc7L.mjs → positive-integer-DiqE5vNi.mjs} +2 -3
- package/dist/{prompt-cache-stability-D_MeCQFI.mjs → prompt-cache-stability-w-ICeyOI.mjs} +1 -1
- package/dist/{provider-error-qtZD2inE.mjs → provider-error-DD-fo4Rz.mjs} +71 -234
- package/dist/{provider-options-Bo8GzTGX.d.mts → provider-options-Mo8NM5d1.d.mts} +15 -4
- package/dist/{provider-replay-context-BC23HyZo.mjs → provider-replay-context-xyU7-CiT.mjs} +2 -2
- package/dist/provider-transcript-transform-BHq3Q4nc.mjs +32 -0
- package/dist/{provider-transport-turn-state-B11rmZpv.mjs → provider-transport-turn-state-DQd9K4Pd.mjs} +3 -3
- package/dist/{provider-types-ODq57rG_.d.mts → provider-types-B1e98js5.d.mts} +6 -4
- package/dist/provider-types.d.mts +7 -6
- package/dist/provider-types.mjs +2 -1
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +26 -29
- package/dist/{record-coerce-CNDovvft.mjs → record-coerce-BQaoiN3r.mjs} +4 -1
- package/dist/request-headers-DO4Mqhw1.mjs +10 -0
- package/dist/{required-api-key-D088S4Cd.mjs → required-api-key-2zZTkmsi.mjs} +1 -1
- package/dist/retry-after-DnHBlFS2.d.mts +45 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/{sanitize-unicode-ZqVLLEKC.d.mts → sanitize-unicode-BISmUlUv.d.mts} +2 -2
- package/dist/{simple-options-BdJJbzZk.mjs → simple-options-tLSeECry.mjs} +108 -82
- package/dist/src-BUsVkrNt.mjs +105 -0
- package/dist/{src-CyA0zJnt.mjs → src-CQ7nH2mL.mjs} +4 -7
- package/dist/stable-stringify-CchQEmeA.mjs +84 -0
- package/dist/{stream-DQqGjhbq.mjs → stream-DrtAWu7c.mjs} +2 -6
- package/dist/{stream-first-event-timeout-D_TfJHRJ.mjs → stream-first-event-timeout-B7RcufAV.mjs} +16 -13
- package/dist/{string-coerce-Cj8sqWHx.mjs → string-coerce-BCuWMIrk.mjs} +1 -1
- package/dist/string-normalization-B8TDDBX_.mjs +32 -0
- package/dist/telemetry-B9f7K_Xe.mjs +582 -0
- package/dist/{tool-schema-json-projection-Cvq69Ajp.mjs → tool-schema-json-projection-BQpiJlXJ.mjs} +53 -69
- package/dist/{transport-stream-shared-DdnJGEj0.mjs → transport-stream-shared-D2uFMhMc.mjs} +177 -93
- package/dist/{transport-stream-shared-8ru8eX4s.d.mts → transport-stream-shared-D3IAU4jn.d.mts} +29 -15
- package/dist/{transport-utils-CcCAuFVS.mjs → transport-utils-Da_39MYi.mjs} +23 -38
- package/dist/transports.d.mts +39 -38
- package/dist/transports.mjs +214 -295
- package/dist/{types-CVYzKrMl.d.mts → types-BVdTf0YV.d.mts} +38 -3
- package/dist/types-Cb3-5WM9.d.mts +1 -0
- package/dist/{types-BXd0kI8-.mjs → types-OVEWUaDh.mjs} +3 -1
- package/dist/types.d.mts +7 -6
- package/dist/types.mjs +7 -5
- package/dist/{validation-9FSkE8T-.mjs → validation-DGXqfvkj.mjs} +45 -27
- package/dist/{validation-BQ5u20Ru.d.mts → validation-QmyD0E5A.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -2
- package/package.json +40 -6
- package/dist/anthropic-B54Ts1tV.mjs +0 -221
- package/dist/assistant-output-DbgdWAhJ.mjs +0 -47
- package/dist/event-stream-CDpFza-M.d.mts +0 -1
- package/dist/index-DSprYWaz.d.mts +0 -185
- package/dist/mistral-C_ImzxlK.mjs +0 -512
- package/dist/model-request-body-BD5vy4rP.d.mts +0 -17
- package/dist/openai-responses-Cp2QPq7K.mjs +0 -87
- package/dist/retry-after-sw-XX8aC.d.mts +0 -15
- package/dist/types-CBJthzJX.d.mts +0 -1
|
@@ -1,35 +1,33 @@
|
|
|
1
|
+
import "./src-CQ7nH2mL.mjs";
|
|
2
|
+
import { t as omitNullRequestHeaders } from "./request-headers-DO4Mqhw1.mjs";
|
|
1
3
|
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { a as asRecord,
|
|
3
|
-
import { O as calculateCost, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-
|
|
4
|
-
import {
|
|
5
|
-
import { t as buildGuardedModelFetch } from "./host-policy-
|
|
4
|
+
import { a as asRecord, c as readStringField, i as asOptionalRecord } from "./record-coerce-BQaoiN3r.mjs";
|
|
5
|
+
import { O as calculateCost, a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-DX7ORpeH.mjs";
|
|
6
|
+
import { a as streamFragmentError } from "./transport-utils-Da_39MYi.mjs";
|
|
7
|
+
import { t as buildGuardedModelFetch } from "./host-policy-jCZebuXx.mjs";
|
|
6
8
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-CRGuMONI.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { n as getEnvApiKey } from "./env-api-keys-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { C as stripSystemPromptCacheBoundary, n as buildBaseOptions } from "./simple-options-tLSeECry.mjs";
|
|
10
|
+
import { T as parseJsonPreservingUnsafeIntegers, _ as parseTerminalToolCallArguments, c as failTransportStream, f as iterateSseFrames, g as notifyProviderStreamOpened, h as notifyProviderHttpResponse, x as transportAbortError } from "./transport-stream-shared-D2uFMhMc.mjs";
|
|
11
|
+
import { n as getEnvApiKey } from "./env-api-keys-BuHc86ya.mjs";
|
|
12
|
+
import { t as transformProviderMessages } from "./provider-transcript-transform-BHq3Q4nc.mjs";
|
|
13
|
+
import { t as createAssistantOutput } from "./assistant-output-CD4kY9gu.mjs";
|
|
14
|
+
import { r as buildGoogleInteractionsSimpleThinking } from "./google-shared-li0lmEZK.mjs";
|
|
12
15
|
//#region packages/ai/package.json
|
|
13
|
-
var version = "2026.
|
|
16
|
+
var version = "2026.11.5-beta.1";
|
|
14
17
|
//#endregion
|
|
15
18
|
//#region packages/ai/src/providers/google-interactions-request.ts
|
|
16
|
-
const DEFAULT_GOOGLE_API_BASE_URL = "https://generativelanguage.googleapis.com";
|
|
17
19
|
let packageVersionMemo;
|
|
18
|
-
function resolvePackageVersion() {
|
|
19
|
-
if (!packageVersionMemo) packageVersionMemo = typeof process !== "undefined" && process.env?.OPENCLAW_VERSION || version;
|
|
20
|
-
return packageVersionMemo;
|
|
21
|
-
}
|
|
22
20
|
function resolveGoogleApiClientHeaders(params) {
|
|
23
21
|
const hostHeaders = getAiTransportHost().resolveProviderRequestHeaders({
|
|
24
22
|
provider: "google",
|
|
25
|
-
api:
|
|
26
|
-
baseUrl: params
|
|
27
|
-
model: params
|
|
23
|
+
api: "google-generative-ai",
|
|
24
|
+
baseUrl: params.baseUrl,
|
|
25
|
+
model: params.model
|
|
28
26
|
});
|
|
29
27
|
if (hostHeaders?.["x-goog-api-client"]) return hostHeaders;
|
|
30
28
|
return {
|
|
31
29
|
...hostHeaders,
|
|
32
|
-
"x-goog-api-client": `openclaw/${
|
|
30
|
+
"x-goog-api-client": `openclaw/${packageVersionMemo ||= typeof process !== "undefined" && process.env?.OPENCLAW_VERSION || version}`
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
33
|
function convertMessages(model, context) {
|
|
@@ -153,11 +151,12 @@ function buildGoogleInteractionsParams(model, context, options = {}) {
|
|
|
153
151
|
};
|
|
154
152
|
}
|
|
155
153
|
//#endregion
|
|
156
|
-
//#region packages/ai/src/providers/google-interactions
|
|
154
|
+
//#region packages/ai/src/providers/google-interactions.ts
|
|
157
155
|
/**
|
|
158
156
|
* Gemini Interactions API adapter and lifecycle for OpenClaw.
|
|
159
157
|
* POST /v1beta/interactions
|
|
160
158
|
*/
|
|
159
|
+
let toolCallCounter = 0;
|
|
161
160
|
function resolveGoogleInteractionsApiKey(model, options) {
|
|
162
161
|
return options?.apiKey || getEnvApiKey(model.provider) || process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY || "";
|
|
163
162
|
}
|
|
@@ -175,185 +174,172 @@ function isGoogleInteractionsRequestBody(value) {
|
|
|
175
174
|
if (!record) return false;
|
|
176
175
|
return typeof record.model === "string" && Array.isArray(record.input) && typeof record.store === "boolean" && typeof record.stream === "boolean";
|
|
177
176
|
}
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
baseUrl
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
177
|
+
const streamGoogleInteractions = (model, context, options) => {
|
|
178
|
+
const stream = new AssistantMessageEventStream();
|
|
179
|
+
const output = createAssistantOutput(model, "google-interactions");
|
|
180
|
+
(async () => {
|
|
181
|
+
let reader;
|
|
182
|
+
try {
|
|
183
|
+
const host = getAiTransportHost();
|
|
184
|
+
const unresolvedApiKey = resolveGoogleInteractionsApiKey(model, options);
|
|
185
|
+
const apiKey = host.resolveSecretSentinel(unresolvedApiKey);
|
|
186
|
+
if (!apiKey.trim()) throw new Error(`No API key for provider: ${model.provider}`);
|
|
187
|
+
let body = buildGoogleInteractionsParams(model, context, options);
|
|
188
|
+
const nextBody = await options?.onPayload?.(body, model);
|
|
189
|
+
if (nextBody !== void 0) {
|
|
190
|
+
if (!isGoogleInteractionsRequestBody(nextBody)) throw new Error("Google Interactions onPayload returned an invalid request body");
|
|
191
|
+
body = nextBody;
|
|
192
|
+
}
|
|
193
|
+
let baseUrl = (model.baseUrl || "https://generativelanguage.googleapis.com/v1beta").trim().replace(/\/+$/, "");
|
|
194
|
+
if (/^https:\/\/generativelanguage\.googleapis\.com$/i.test(baseUrl)) baseUrl = "https://generativelanguage.googleapis.com/v1beta";
|
|
195
|
+
const url = `${baseUrl}/interactions?alt=sse`;
|
|
196
|
+
const googleClientHeaders = resolveGoogleApiClientHeaders({
|
|
197
|
+
baseUrl,
|
|
198
|
+
model
|
|
199
|
+
});
|
|
200
|
+
const headers = resolveAiTransportHeaderSentinels({
|
|
201
|
+
"Content-Type": "application/json",
|
|
202
|
+
"x-goog-api-key": apiKey,
|
|
203
|
+
"Api-Revision": "2026-05-20",
|
|
204
|
+
...googleClientHeaders,
|
|
205
|
+
...model.headers,
|
|
206
|
+
...options?.headers
|
|
207
|
+
}) ?? {
|
|
208
|
+
"Content-Type": "application/json",
|
|
209
|
+
"x-goog-api-key": apiKey
|
|
210
|
+
};
|
|
211
|
+
logGoogleInteractionsDebug("request", {
|
|
212
|
+
method: "POST",
|
|
213
|
+
url,
|
|
214
|
+
model: model.id,
|
|
215
|
+
inputSteps: body.input.length,
|
|
216
|
+
tools: body.tools?.length ?? 0
|
|
217
|
+
});
|
|
218
|
+
const response = await buildGuardedModelFetch({
|
|
219
|
+
...model,
|
|
220
|
+
baseUrl
|
|
221
|
+
}, options?.timeoutMs, { sanitizeSse: true })(url, {
|
|
222
|
+
method: "POST",
|
|
223
|
+
headers: omitNullRequestHeaders(headers),
|
|
224
|
+
body: JSON.stringify(body),
|
|
225
|
+
signal: options?.signal
|
|
226
|
+
});
|
|
227
|
+
await notifyProviderHttpResponse({
|
|
228
|
+
options,
|
|
229
|
+
response,
|
|
230
|
+
model
|
|
231
|
+
});
|
|
232
|
+
logGoogleInteractionsDebug("response", {
|
|
233
|
+
status: response.status,
|
|
234
|
+
statusText: response.statusText
|
|
235
|
+
});
|
|
236
|
+
if (!response.ok) {
|
|
237
|
+
const errorText = await response.text();
|
|
238
|
+
logGoogleInteractionsDebug("request failed", { status: response.status });
|
|
239
|
+
throw new Error(`Google Interactions API error HTTP ${response.status}: ${errorText}`);
|
|
240
|
+
}
|
|
241
|
+
if (!response.body) throw new Error("Google Interactions API returned empty response body");
|
|
242
|
+
reader = response.body.getReader();
|
|
243
|
+
await notifyProviderStreamOpened({
|
|
244
|
+
options,
|
|
245
|
+
cancelStream: () => reader?.cancel()
|
|
246
|
+
});
|
|
247
|
+
stream.push({
|
|
248
|
+
type: "start",
|
|
249
|
+
partial: output
|
|
250
|
+
});
|
|
251
|
+
let currentBlock = null;
|
|
252
|
+
let currentBlockIndex = -1;
|
|
253
|
+
let latestThoughtSignature;
|
|
254
|
+
let latestUsage;
|
|
255
|
+
const endCurrentBlock = () => {
|
|
256
|
+
if (!currentBlock) return;
|
|
257
|
+
if (currentBlock.type === "toolCall") {
|
|
258
|
+
if (currentBlock.partialJson?.trim()) currentBlock.arguments = parseTerminalToolCallArguments(currentBlock.partialJson);
|
|
259
|
+
delete currentBlock.partialJson;
|
|
260
|
+
stream.push({
|
|
261
|
+
type: "toolcall_end",
|
|
262
|
+
contentIndex: currentBlockIndex,
|
|
263
|
+
toolCall: currentBlock,
|
|
264
|
+
partial: output
|
|
265
|
+
});
|
|
266
|
+
} else {
|
|
267
|
+
if (currentBlock.type === "thinking") {
|
|
268
|
+
if (!currentBlock.thinkingSignature && latestThoughtSignature) currentBlock.thinkingSignature = latestThoughtSignature;
|
|
269
|
+
latestThoughtSignature = void 0;
|
|
270
|
+
}
|
|
271
|
+
stream.push({
|
|
272
|
+
type: currentBlock.type === "text" ? "text_end" : "thinking_end",
|
|
273
|
+
contentIndex: currentBlockIndex,
|
|
274
|
+
content: currentBlock.type === "text" ? currentBlock.text : currentBlock.thinking,
|
|
275
|
+
partial: output
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
currentBlock = null;
|
|
279
|
+
};
|
|
280
|
+
const startTextBlock = (type, text = "") => {
|
|
281
|
+
endCurrentBlock();
|
|
282
|
+
currentBlockIndex = output.content.length;
|
|
283
|
+
const block = type === "text" ? {
|
|
284
|
+
type,
|
|
285
|
+
text
|
|
286
|
+
} : {
|
|
287
|
+
type,
|
|
288
|
+
thinking: text,
|
|
289
|
+
...latestThoughtSignature ? { thinkingSignature: latestThoughtSignature } : {}
|
|
290
|
+
};
|
|
291
|
+
output.content.push(block);
|
|
262
292
|
stream.push({
|
|
263
|
-
type: "
|
|
293
|
+
type: type === "text" ? "text_start" : "thinking_start",
|
|
264
294
|
contentIndex: currentBlockIndex,
|
|
265
|
-
toolCall: currentBlock,
|
|
266
295
|
partial: output
|
|
267
296
|
});
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
297
|
+
if (text) stream.push({
|
|
298
|
+
type: type === "text" ? "text_delta" : "thinking_delta",
|
|
299
|
+
contentIndex: currentBlockIndex,
|
|
300
|
+
delta: text,
|
|
301
|
+
partial: output
|
|
302
|
+
});
|
|
303
|
+
return block;
|
|
304
|
+
};
|
|
305
|
+
const appendTextDelta = (type, text) => {
|
|
306
|
+
if (!text) return;
|
|
307
|
+
const block = currentBlock?.type === type ? currentBlock : startTextBlock(type);
|
|
308
|
+
currentBlock = block;
|
|
309
|
+
if (block.type === "text") block.text += text;
|
|
310
|
+
else block.thinking += text;
|
|
273
311
|
stream.push({
|
|
274
|
-
type:
|
|
312
|
+
type: type === "text" ? "text_delta" : "thinking_delta",
|
|
275
313
|
contentIndex: currentBlockIndex,
|
|
276
|
-
|
|
314
|
+
delta: text,
|
|
277
315
|
partial: output
|
|
278
316
|
});
|
|
279
|
-
}
|
|
280
|
-
currentBlock = null;
|
|
281
|
-
};
|
|
282
|
-
const startTextBlock = (type, text = "") => {
|
|
283
|
-
endCurrentBlock();
|
|
284
|
-
currentBlockIndex = output.content.length;
|
|
285
|
-
const block = type === "text" ? {
|
|
286
|
-
type,
|
|
287
|
-
text
|
|
288
|
-
} : {
|
|
289
|
-
type,
|
|
290
|
-
thinking: text,
|
|
291
|
-
...latestThoughtSignature ? { thinkingSignature: latestThoughtSignature } : {}
|
|
292
317
|
};
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (block.type === "text") block.text += text;
|
|
312
|
-
else block.thinking += text;
|
|
313
|
-
stream.push({
|
|
314
|
-
type: type === "text" ? "text_delta" : "thinking_delta",
|
|
315
|
-
contentIndex: currentBlockIndex,
|
|
316
|
-
delta: text,
|
|
317
|
-
partial: output
|
|
318
|
-
});
|
|
319
|
-
};
|
|
320
|
-
const startToolCallBlock = (source, args = {}) => {
|
|
321
|
-
endCurrentBlock();
|
|
322
|
-
currentBlockIndex = output.content.length;
|
|
323
|
-
const name = readStringField(source, "name") ?? "tool";
|
|
324
|
-
const toolCall = {
|
|
325
|
-
type: "toolCall",
|
|
326
|
-
id: readStringField(source, "id") ?? nextToolCallId(name),
|
|
327
|
-
name,
|
|
328
|
-
arguments: args,
|
|
329
|
-
partialJson: Object.keys(args).length > 0 ? JSON.stringify(args) : ""
|
|
318
|
+
const startToolCallBlock = (source, args = {}) => {
|
|
319
|
+
endCurrentBlock();
|
|
320
|
+
currentBlockIndex = output.content.length;
|
|
321
|
+
const name = readStringField(source, "name") ?? "tool";
|
|
322
|
+
const toolCall = {
|
|
323
|
+
type: "toolCall",
|
|
324
|
+
id: readStringField(source, "id") ?? `${name}_${Date.now()}_${++toolCallCounter}`,
|
|
325
|
+
name,
|
|
326
|
+
arguments: args,
|
|
327
|
+
partialJson: Object.keys(args).length > 0 ? JSON.stringify(args) : ""
|
|
328
|
+
};
|
|
329
|
+
output.content.push(toolCall);
|
|
330
|
+
stream.push({
|
|
331
|
+
type: "toolcall_start",
|
|
332
|
+
contentIndex: currentBlockIndex,
|
|
333
|
+
partial: output
|
|
334
|
+
});
|
|
335
|
+
return toolCall;
|
|
330
336
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
contentIndex: currentBlockIndex,
|
|
335
|
-
partial: output
|
|
336
|
-
});
|
|
337
|
-
return toolCall;
|
|
338
|
-
};
|
|
339
|
-
let streamDone = false;
|
|
340
|
-
let sawCompletion = false;
|
|
341
|
-
while (!streamDone) {
|
|
342
|
-
const { done, value } = await reader.read();
|
|
343
|
-
buffer += decoder.decode(value, { stream: !done });
|
|
344
|
-
const frames = buffer.split(/(?:\r\n|\r(?!\n)|\n)(?:\r\n|\r(?!\n)|\n)/);
|
|
345
|
-
buffer = frames.pop() ?? "";
|
|
346
|
-
if (done) {
|
|
347
|
-
if (/[\r\n]$/.test(buffer)) frames.push(buffer);
|
|
348
|
-
streamDone = true;
|
|
349
|
-
}
|
|
350
|
-
for (const frame of frames) {
|
|
337
|
+
let sawCompletion = false;
|
|
338
|
+
for await (const { frame, terminated } of iterateSseFrames(reader.read.bind(reader))) {
|
|
339
|
+
if (!terminated && !/[\r\n]$/.test(frame)) continue;
|
|
351
340
|
const dataStr = frame.split(/\r\n|\r|\n/).filter((line) => line.startsWith("data:")).map((line) => line.slice(5)).join("\n").trim();
|
|
352
341
|
if (!dataStr) continue;
|
|
353
|
-
if (dataStr === "[DONE]")
|
|
354
|
-
streamDone = true;
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
342
|
+
if (dataStr === "[DONE]") break;
|
|
357
343
|
let event;
|
|
358
344
|
try {
|
|
359
345
|
event = asRecord(parseJsonPreservingUnsafeIntegers(dataStr));
|
|
@@ -453,55 +439,44 @@ async function runGoogleInteractionsLifecycle(params) {
|
|
|
453
439
|
const status = typeof interaction.status === "string" ? interaction.status : "completed";
|
|
454
440
|
if (status === "failed" || status === "cancelled" || status === "budget_exceeded") throw new Error(`Google Interactions API completed with status: ${status}`);
|
|
455
441
|
if (status === "incomplete") output.stopReason = "length";
|
|
456
|
-
else
|
|
442
|
+
else {
|
|
443
|
+
const hasToolCalls = output.content.some((b) => b.type === "toolCall");
|
|
444
|
+
output.stopReason = hasToolCalls ? "toolUse" : "stop";
|
|
445
|
+
}
|
|
457
446
|
}
|
|
458
447
|
}
|
|
448
|
+
endCurrentBlock();
|
|
449
|
+
if (!sawCompletion) throw Object.assign(/* @__PURE__ */ new Error("Google Interactions stream ended before a terminal event"), {
|
|
450
|
+
code: "STREAM_INCOMPLETE",
|
|
451
|
+
type: "google_incomplete_stream"
|
|
452
|
+
});
|
|
453
|
+
if (latestThoughtSignature) {
|
|
454
|
+
for (const block of output.content) if (block.type === "thinking" && !block.thinkingSignature) block.thinkingSignature = latestThoughtSignature;
|
|
455
|
+
}
|
|
456
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
457
|
+
stream.push({
|
|
458
|
+
type: "done",
|
|
459
|
+
reason: output.stopReason,
|
|
460
|
+
message: output
|
|
461
|
+
});
|
|
462
|
+
stream.end();
|
|
463
|
+
} catch (error) {
|
|
464
|
+
const failure = options?.signal?.aborted ? transportAbortError(options.signal) : error;
|
|
465
|
+
for (const block of output.content) if (block.type === "toolCall") delete block.partialJson;
|
|
466
|
+
failTransportStream({
|
|
467
|
+
stream,
|
|
468
|
+
output,
|
|
469
|
+
signal: options?.signal,
|
|
470
|
+
error: failure
|
|
471
|
+
});
|
|
472
|
+
} finally {
|
|
473
|
+
if (reader) {
|
|
474
|
+
const cancellation = reader.cancel().catch(() => void 0);
|
|
475
|
+
reader.releaseLock();
|
|
476
|
+
getAiTransportHost().observePendingProviderWork?.(cancellation);
|
|
477
|
+
}
|
|
459
478
|
}
|
|
460
|
-
|
|
461
|
-
if (!sawCompletion) throw Object.assign(/* @__PURE__ */ new Error("Google Interactions stream ended before a terminal event"), {
|
|
462
|
-
code: "STREAM_INCOMPLETE",
|
|
463
|
-
type: "google_incomplete_stream"
|
|
464
|
-
});
|
|
465
|
-
if (latestThoughtSignature) {
|
|
466
|
-
for (const block of output.content) if (block.type === "thinking" && !block.thinkingSignature) block.thinkingSignature = latestThoughtSignature;
|
|
467
|
-
}
|
|
468
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
469
|
-
stream.push({
|
|
470
|
-
type: "done",
|
|
471
|
-
reason: output.stopReason,
|
|
472
|
-
message: output
|
|
473
|
-
});
|
|
474
|
-
stream.end();
|
|
475
|
-
} catch (error) {
|
|
476
|
-
const failure = options?.signal?.aborted ? transportAbortError(options.signal) : error;
|
|
477
|
-
for (const block of output.content) if (block.type === "toolCall") delete block.partialJson;
|
|
478
|
-
failTransportStream({
|
|
479
|
-
stream,
|
|
480
|
-
output,
|
|
481
|
-
signal: options?.signal,
|
|
482
|
-
error: failure
|
|
483
|
-
});
|
|
484
|
-
} finally {
|
|
485
|
-
if (reader) {
|
|
486
|
-
const cancellation = reader.cancel().catch(() => void 0);
|
|
487
|
-
reader.releaseLock();
|
|
488
|
-
getAiTransportHost().observePendingProviderWork?.(cancellation);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
//#endregion
|
|
493
|
-
//#region packages/ai/src/providers/google-interactions.ts
|
|
494
|
-
let toolCallCounter = 0;
|
|
495
|
-
const streamGoogleInteractions = (model, context, options) => {
|
|
496
|
-
const stream = new AssistantMessageEventStream();
|
|
497
|
-
runGoogleInteractionsLifecycle({
|
|
498
|
-
stream,
|
|
499
|
-
model,
|
|
500
|
-
output: createAssistantOutput(model, "google-interactions"),
|
|
501
|
-
options,
|
|
502
|
-
context,
|
|
503
|
-
nextToolCallId: (name) => `${name}_${Date.now()}_${++toolCallCounter}`
|
|
504
|
-
});
|
|
479
|
+
})();
|
|
505
480
|
return stream;
|
|
506
481
|
};
|
|
507
482
|
const streamSimpleGoogleInteractions = (model, context, options) => {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { p as hasRuntimeContextMarker } from "./types-OVEWUaDh.mjs";
|
|
1
2
|
import { r as appendAssistantThinking } from "./event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { N as isImageWithMediaPayload, O as calculateCost } from "./host-
|
|
3
|
+
import { N as isImageWithMediaPayload, O as calculateCost } from "./host-DX7ORpeH.mjs";
|
|
3
4
|
import { t as sanitizeSurrogates } from "./sanitize-unicode-CRGuMONI.mjs";
|
|
4
|
-
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-
|
|
5
|
-
import {
|
|
6
|
-
import { a as createEmptyTransportUsage,
|
|
7
|
-
import { t as notifyLlmRequestActivity } from "./llm-request-activity-
|
|
5
|
+
import { r as sortPromptCacheToolsByName } from "./prompt-cache-stability-w-ICeyOI.mjs";
|
|
6
|
+
import { a as describeToolResultMediaPlaceholder, c as extractToolResultText } from "./simple-options-tLSeECry.mjs";
|
|
7
|
+
import { a as createEmptyTransportUsage, r as coerceTransportToolCallArguments, x as transportAbortError, y as sanitizeTransportPayloadText } from "./transport-stream-shared-D2uFMhMc.mjs";
|
|
8
|
+
import { t as notifyLlmRequestActivity } from "./llm-request-activity-DzaHoRAU.mjs";
|
|
8
9
|
import { isGoogleGemini4Model } from "./internal/google-model-family.mjs";
|
|
10
|
+
import "./types.mjs";
|
|
9
11
|
//#region packages/ai/src/transports/google-thinking-level.ts
|
|
10
12
|
/** Reports MINIMAL support for Gemini Flash and Gemini 4 models. */
|
|
11
13
|
function googleFlashSupportsMinimalThinking(modelId) {
|
|
@@ -265,13 +267,6 @@ function sanitizeGeminiThoughtSignature(value) {
|
|
|
265
267
|
const trimmed = value.trim();
|
|
266
268
|
return trimmed && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(trimmed) ? trimmed : void 0;
|
|
267
269
|
}
|
|
268
|
-
function toolCallThoughtSignatureReplayKey(id, name, args) {
|
|
269
|
-
return [
|
|
270
|
-
id,
|
|
271
|
-
name,
|
|
272
|
-
stableStringifyGoogleToolCallValue(args)
|
|
273
|
-
].join("\0");
|
|
274
|
-
}
|
|
275
270
|
function requiresGoogleToolCallId(modelId) {
|
|
276
271
|
return modelId.startsWith("claude-") || modelId.startsWith("gpt-oss-");
|
|
277
272
|
}
|
|
@@ -311,6 +306,10 @@ function projectGoogleMessages(params) {
|
|
|
311
306
|
});
|
|
312
307
|
const visibleParts = managed && !model.input.includes("image") ? parts.filter((part) => !part.inlineData) : parts;
|
|
313
308
|
if (visibleParts.length === 0) visibleParts.push({ text: " " });
|
|
309
|
+
if (hasRuntimeContextMarker(msg)) {
|
|
310
|
+
visibleParts.unshift({ text: "The following is runtime context, not a user request. Do not respond to or acknowledge this context." });
|
|
311
|
+
visibleParts.push({ text: "Use this context to continue responding to the user's request." });
|
|
312
|
+
}
|
|
314
313
|
contents.push({
|
|
315
314
|
role: "user",
|
|
316
315
|
parts: visibleParts
|
|
@@ -333,7 +332,11 @@ function projectGoogleMessages(params) {
|
|
|
333
332
|
if (isSameProviderAndModel && (managed || model.provider !== "google-gemini-cli")) sameRouteToolCallIds.add(block.id);
|
|
334
333
|
const args = coerceTransportToolCallArguments(block.arguments);
|
|
335
334
|
const ownSignature = isSameProviderAndModel ? signature(block.thoughtSignature) : void 0;
|
|
336
|
-
const replayKey = managed && (ownSignature || params.requiresToolCallSignature && isSameProviderAndModel && replaySignatures.size > 0) ?
|
|
335
|
+
const replayKey = managed && (ownSignature || params.requiresToolCallSignature && isSameProviderAndModel && replaySignatures.size > 0) ? [
|
|
336
|
+
block.id,
|
|
337
|
+
block.name,
|
|
338
|
+
stableStringifyGoogleToolCallValue(args)
|
|
339
|
+
].join("\0") : "";
|
|
337
340
|
if (managed && ownSignature) nextReplaySignatures.set(replayKey, ownSignature);
|
|
338
341
|
const thoughtSignature = ownSignature ?? (managed && params.requiresToolCallSignature && isSameProviderAndModel ? replaySignatures.get(replayKey) : void 0) ?? (params.requiresToolCallSignature && (managed || !sawFunctionCall) ? GEMINI_THOUGHT_SIGNATURE_VALIDATOR_SKIP : void 0);
|
|
339
342
|
sawFunctionCall = true;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import "./src-CQ7nH2mL.mjs";
|
|
2
|
+
import { t as omitNullRequestHeaders } from "./request-headers-DO4Mqhw1.mjs";
|
|
1
3
|
import { t as AssistantMessageEventStream } from "./event-stream-X2gmsUWv.mjs";
|
|
2
|
-
import { a as resolveAiTransportHeaderSentinels } from "./host-
|
|
3
|
-
import { n as buildManagedModelFetch } from "./host-policy-
|
|
4
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
5
|
-
import {
|
|
6
|
-
import { t as createAssistantOutput } from "./assistant-output-
|
|
7
|
-
import {
|
|
4
|
+
import { a as resolveAiTransportHeaderSentinels, r as getAiTransportHost } from "./host-DX7ORpeH.mjs";
|
|
5
|
+
import { n as buildManagedModelFetch } from "./host-policy-jCZebuXx.mjs";
|
|
6
|
+
import { n as buildBaseOptions } from "./simple-options-tLSeECry.mjs";
|
|
7
|
+
import { p as mergeTransportHeaders } from "./transport-stream-shared-D2uFMhMc.mjs";
|
|
8
|
+
import { t as createAssistantOutput } from "./assistant-output-CD4kY9gu.mjs";
|
|
9
|
+
import { a as runGoogleGenerateContentLifecycle, i as buildGoogleSimpleThinking, t as buildGoogleGenerateContentParams } from "./google-shared-li0lmEZK.mjs";
|
|
8
10
|
import { ResourceScope } from "@google/genai";
|
|
9
11
|
//#region packages/ai/src/providers/google-http-options.ts
|
|
10
12
|
function buildGoogleHttpOptions(model, optionsHeaders, profile) {
|
|
@@ -23,10 +25,15 @@ function buildGoogleHttpOptions(model, optionsHeaders, profile) {
|
|
|
23
25
|
httpOptions.baseUrl = model.baseUrl;
|
|
24
26
|
httpOptions.apiVersion = "";
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const headers = profile === "vertex" ? mergeTransportHeaders(model.headers, optionsHeaders) : getAiTransportHost().resolveProviderRequestHeaders({
|
|
29
|
+
provider: model.provider,
|
|
30
|
+
api: model.api,
|
|
31
|
+
baseUrl: model.baseUrl,
|
|
32
|
+
callerHeaders: mergeTransportHeaders(model.headers, optionsHeaders),
|
|
33
|
+
precedence: "caller-wins",
|
|
34
|
+
model
|
|
35
|
+
});
|
|
36
|
+
if (headers) httpOptions.headers = omitNullRequestHeaders(resolveAiTransportHeaderSentinels(headers));
|
|
30
37
|
return Object.keys(httpOptions).length > 0 ? httpOptions : void 0;
|
|
31
38
|
}
|
|
32
39
|
//#endregion
|