@openclaw/ai 2026.9.1 → 2026.9.3
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 +3 -2
- package/dist/anthropic-CZy5U0NY.mjs +376 -0
- package/dist/anthropic-payload-policy-wuRCb6MH.d.mts +85 -0
- package/dist/anthropic-stream-reducer-B_yo_7pf.mjs +1669 -0
- package/dist/{api-registry-Cs6HGNqY.d.mts → api-registry-CB1-1oQ2.d.mts} +2 -2
- package/dist/assistant-output-iqnlJCV2.mjs +16 -0
- package/dist/assistant-text-phase-C20rxWwP.mjs +55 -0
- package/dist/{azure-openai-responses-CN4Fy5zV.mjs → azure-openai-responses-Crpa40QR.mjs} +5 -5
- package/dist/{base64-CEFBpSkN.mjs → base64-D-su8YVo.mjs} +1 -27
- package/dist/{diagnostics-KhXK-QJI.mjs → diagnostics-dV98PqIy.mjs} +96 -21
- package/dist/diagnostics.d.mts +3 -1
- package/dist/diagnostics.mjs +3 -3
- package/dist/{event-stream-vK_7r3bj.d.mts → event-stream-C1Z2piyk.d.mts} +11 -3
- package/dist/{event-stream-uSMZJ3FA.mjs → event-stream-D8PARQfL.mjs} +48 -10
- package/dist/event-stream-I_GlBsuZ.d.mts +1 -0
- package/dist/event-stream.d.mts +2 -2
- package/dist/event-stream.mjs +1 -1
- package/dist/{github-copilot-headers-NCJtz9i0.mjs → github-copilot-headers-B37TB3rB.mjs} +3 -10
- package/dist/github-copilot-request-facts-BTEBMeOv.mjs +16 -0
- package/dist/{google-CC-nrwXg.mjs → google-BDPriaVe.mjs} +10 -10
- package/dist/google-messages-CVn9eFpF.mjs +449 -0
- package/dist/google-shared-BedY23XS.mjs +185 -0
- package/dist/{google-vertex-DCr0pyzQ.mjs → google-vertex-DMz8XQCn.mjs} +7 -6
- package/dist/{host-BIaiBURL.mjs → host-CWuF-sS3.mjs} +84 -34
- package/dist/{host-BztR4tQj.d.mts → host-DK3wmS3e.d.mts} +3 -3
- package/dist/host-policy-CAopLRKA.mjs +37 -0
- package/dist/{index-AfaxKT8w.d.mts → index-CQ6LTHw8.d.mts} +11 -5
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +5 -5
- package/dist/internal/anthropic.d.mts +14 -11
- package/dist/internal/anthropic.mjs +5 -5
- package/dist/internal/google-model-family.d.mts +5 -0
- package/dist/internal/google-model-family.mjs +15 -0
- package/dist/internal/openai-responses-payload-policy.d.mts +1 -1
- package/dist/internal/openai-responses-payload-policy.mjs +1 -1
- package/dist/internal/openai.d.mts +8 -103
- package/dist/internal/openai.mjs +10 -10
- package/dist/internal/retry-after.d.mts +2 -4
- package/dist/internal/retry-after.mjs +57 -8
- package/dist/internal/runtime.d.mts +7 -6
- package/dist/internal/runtime.mjs +8 -7
- package/dist/internal/shared.d.mts +14 -3
- package/dist/internal/shared.mjs +6 -4
- package/dist/internal/tool-schema.d.mts +63 -0
- package/dist/internal/tool-schema.mjs +3 -0
- package/dist/{json-parse-BuAJEbdW.mjs → json-parse-Dw_hnxsA.mjs} +1 -1
- package/dist/{mistral-B7etBd_H.mjs → mistral--m-Jm6VZ.mjs} +16 -38
- package/dist/model-transport-url-DKocrEsb.d.mts +28 -0
- package/dist/{openai-chatgpt-responses-BAJ4gq3i.mjs → openai-chatgpt-responses-nDZccFW-.mjs} +62 -54
- package/dist/openai-completions-KuoZyx0d.mjs +187 -0
- package/dist/{openai-completions-compat-4IjSBpr6.d.mts → openai-completions-compat-CXn3T1we.d.mts} +26 -4
- package/dist/{openai-completions-stream-DZjwK8vp.mjs → openai-completions-stream-BQk3SkLD.mjs} +621 -451
- package/dist/openai-prompt-cache-BI0rkM-5.mjs +220 -0
- package/dist/openai-prompt-cache-rrutvqxq.d.mts +16 -0
- package/dist/openai-provider-client-ha_WxTyj.mjs +24 -0
- package/dist/openai-reasoning-effort-BK7FbcLT.mjs +167 -0
- package/dist/{openai-responses-BEUlxfDu.mjs → openai-responses-D99dOzKI.mjs} +14 -32
- package/dist/{openai-responses-compaction-window-DO7yV7az.mjs → openai-responses-compaction-window-D5jbzCi3.mjs} +7 -159
- package/dist/{openai-responses-contracts-bPzSN_Ba.d.mts → openai-responses-contracts-B55afwRo.d.mts} +12 -4
- package/dist/{openai-responses-prompt-observer-internal-C7x4IK7r.mjs → openai-responses-prompt-observer-internal-tApyTLVu.mjs} +3 -3
- package/dist/{openai-responses-shared-DiAdpNAM.mjs → openai-responses-shared-ZyQEzS5i.mjs} +217 -212
- package/dist/openai-tool-projection-793cE3QX.d.mts +37 -0
- package/dist/{openai-tool-schema-BMiHFH36.mjs → openai-tool-schema-CzjyYXun.mjs} +53 -583
- package/dist/openai-tool-schema-ynZBgqW-.d.mts +38 -0
- package/dist/openai-transport-params-DNasp2fU.mjs +674 -0
- package/dist/{provider-error-B6EGq6gg.mjs → provider-error-C6TbKiey.mjs} +29 -13
- package/dist/{provider-options-CxFPtvh7.d.mts → provider-options-BXr9Ec83.d.mts} +19 -42
- package/dist/provider-replay-context-BuSUaAk5.mjs +21 -0
- package/dist/{provider-transcript-transform-WvJmFUAf.mjs → provider-transcript-transform-pPmUIwKt.mjs} +1 -1
- package/dist/provider-types-CAV0Og3m.d.mts +29 -0
- package/dist/provider-types.d.mts +6 -31
- package/dist/providers.d.mts +2 -2
- package/dist/providers.mjs +11 -11
- package/dist/{reasoning-tag-text-partitioner-C-4uedDb.mjs → reasoning-tag-text-partitioner-BQBi4B9d.mjs} +90 -35
- package/dist/record-coerce-DwRYMj3t.mjs +32 -0
- package/dist/retry-after-CdCURCVg.d.mts +15 -0
- package/dist/{sanitize-unicode-S6binQG-.mjs → sanitize-unicode-Bb-v9meu.mjs} +1 -1
- package/dist/session-affinity-CCH7eYdB.mjs +20 -0
- package/dist/{simple-options-0PLDyJ-d.mjs → simple-options-tcKOqnpF.mjs} +3 -3
- package/dist/{src-C8U7lkoa.mjs → src-B2Q_6G8V.mjs} +10 -2
- package/dist/{stream-first-event-timeout-DcNjoFQE.mjs → stream-first-event-timeout-2hfrquuz.mjs} +1 -1
- package/dist/string-coerce-fsri9iCu.mjs +34 -0
- package/dist/{string-normalization--fwJ4S2q.mjs → string-normalization-CmLIasuf.mjs} +1 -1
- package/dist/{tool-schema-json-projection-BtZiml7r.mjs → tool-schema-json-projection-ClptDdAO.mjs} +2 -38
- package/dist/{transport-stream-shared-CytPVLIg.mjs → transport-stream-shared-Cu3ZPhNW.mjs} +5 -5
- package/dist/{transport-stream-shared-BrvFTkoO.d.mts → transport-stream-shared-DOxpGJ-H.d.mts} +4 -4
- package/dist/transport-utils-CCooe-cr.mjs +121 -0
- package/dist/transports.d.mts +114 -41
- package/dist/transports.mjs +796 -1596
- package/dist/types-BADKjDBI.d.mts +1 -0
- package/dist/{types-DbrhszyQ.d.mts → types-Dy1q0CSu.d.mts} +101 -64
- package/dist/types.d.mts +6 -6
- package/dist/types.mjs +4 -4
- package/dist/utf16-slice-CvGodqok.mjs +29 -0
- package/dist/{validation-CJZtym2g.mjs → validation-BDzVDnTs.mjs} +9 -1
- package/dist/{validation-BOwtcl9X.d.mts → validation-CaFUZN9B.d.mts} +1 -1
- package/dist/validation.d.mts +1 -1
- package/dist/validation.mjs +1 -1
- package/package.json +14 -4
- package/dist/anthropic-compaction-replay-OMJZ0uyo.mjs +0 -838
- package/dist/anthropic-hk7F7ptG.mjs +0 -883
- package/dist/anthropic-payload-policy-DBT1itQ-.d.mts +0 -51
- package/dist/event-stream-DeDhbCc5.d.mts +0 -1
- package/dist/google-shared-CjPY0hZM.mjs +0 -634
- package/dist/google-thinking-level-C-V3tecN.mjs +0 -9
- package/dist/openai-completions-D0QZ0AyB.mjs +0 -403
- package/dist/openai-prompt-cache-2uo_1OR1.d.mts +0 -7
- package/dist/openai-prompt-cache-mZTCdRPo.mjs +0 -12
- package/dist/transport-utils-CtuS1Upe.mjs +0 -138
- package/dist/types-B5EFUmXs.d.mts +0 -1
- package/dist/utf16-slice-qz3nsy87.mjs +0 -84
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./index-
|
|
2
|
-
import { D as Model, J as StreamOptions, W as SimpleStreamOptions, d as Context, n as Api, q as StreamFunction, s as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import "./index-CQ6LTHw8.mjs";
|
|
2
|
+
import { D as Model, J as StreamOptions, W as SimpleStreamOptions, d as Context, n as Api, q as StreamFunction, s as AssistantMessageEventStreamContract } from "./types-Dy1q0CSu.mjs";
|
|
3
3
|
//#region packages/ai/src/api-registry.d.ts
|
|
4
4
|
/** Runtime stream adapter signature stored in the API provider registry. */
|
|
5
5
|
type ApiStreamFunction = (model: Model, context: Context, options?: StreamOptions) => AssistantMessageEventStreamContract;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { i as createEmptyTransportUsage } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
2
|
+
//#region packages/ai/src/transports/assistant-output.ts
|
|
3
|
+
function createAssistantOutput(model, api = model.api) {
|
|
4
|
+
return {
|
|
5
|
+
role: "assistant",
|
|
6
|
+
content: [],
|
|
7
|
+
api,
|
|
8
|
+
provider: model.provider,
|
|
9
|
+
model: model.id,
|
|
10
|
+
usage: createEmptyTransportUsage(),
|
|
11
|
+
stopReason: "stop",
|
|
12
|
+
timestamp: Date.now()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { createAssistantOutput as t };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
//#region packages/ai/src/utils/assistant-text-phase.ts
|
|
3
|
+
const EMPTY_ASSISTANT_TEXT_BLOCK_SET = /* @__PURE__ */ new Set();
|
|
4
|
+
function isAssistantTextPhaseBlock(block) {
|
|
5
|
+
if (!block || typeof block !== "object") return false;
|
|
6
|
+
const record = block;
|
|
7
|
+
return record.type === "text" && typeof record.text === "string";
|
|
8
|
+
}
|
|
9
|
+
function encodeAssistantTextSignatureV1(id, phase) {
|
|
10
|
+
return JSON.stringify({
|
|
11
|
+
v: 1,
|
|
12
|
+
id,
|
|
13
|
+
...phase ? { phase } : {}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function tagUnphasedText(content, phase, idPrefix) {
|
|
17
|
+
const textBlocks = content.filter(isAssistantTextPhaseBlock);
|
|
18
|
+
let phaseIndex = textBlocks.filter((block) => block.textSignature !== void 0).length;
|
|
19
|
+
const tagged = /* @__PURE__ */ new Map();
|
|
20
|
+
for (const block of textBlocks) {
|
|
21
|
+
if (block.text.trim().length === 0 || block.textSignature !== void 0) continue;
|
|
22
|
+
const signature = encodeAssistantTextSignatureV1(`${idPrefix}-${phaseIndex}-${randomUUID().replaceAll("-", "").slice(0, 24)}`, phase);
|
|
23
|
+
block.textSignature = signature;
|
|
24
|
+
tagged.set(block, signature);
|
|
25
|
+
phaseIndex += 1;
|
|
26
|
+
}
|
|
27
|
+
return tagged;
|
|
28
|
+
}
|
|
29
|
+
/** Tags unphased narration before a tool-call event becomes consumer-visible. */
|
|
30
|
+
function tagPendingCommentaryText(content) {
|
|
31
|
+
return tagUnphasedText(content, "commentary", "commentary");
|
|
32
|
+
}
|
|
33
|
+
/** Records the confirmed final-answer boundary after reasoning resumes. */
|
|
34
|
+
function tagInterruptedTextPhases(content, interruptedText, preservedVisibleText = EMPTY_ASSISTANT_TEXT_BLOCK_SET) {
|
|
35
|
+
const interruptedTextIndex = content.indexOf(interruptedText);
|
|
36
|
+
if (interruptedTextIndex === -1) return;
|
|
37
|
+
const finalAnswerIndex = content.findIndex((block, index) => index > interruptedTextIndex && isAssistantTextPhaseBlock(block) && block.text.trim().length > 0);
|
|
38
|
+
if (finalAnswerIndex === -1) return;
|
|
39
|
+
tagUnphasedText(content.slice(0, finalAnswerIndex).filter((block) => !preservedVisibleText.has(block)), "commentary", "commentary");
|
|
40
|
+
tagUnphasedText(content.filter((block, index) => index >= finalAnswerIndex || preservedVisibleText.has(block)), "final_answer", "final-answer");
|
|
41
|
+
}
|
|
42
|
+
/** Prevents unresolved completion text from becoming a fallback answer after stream failure. */
|
|
43
|
+
function tagUnresolvedTextAsCommentary(message) {
|
|
44
|
+
if (message.openclawDelivery?.textPhaseRequiresTerminal) tagUnphasedText(message.content, "commentary", "commentary");
|
|
45
|
+
}
|
|
46
|
+
/** Rolls back only the exact provisional signatures created by this transport turn. */
|
|
47
|
+
function clearPendingCommentaryText(tags) {
|
|
48
|
+
for (const [block, signature] of tags) if (block.textSignature === signature) delete block.textSignature;
|
|
49
|
+
tags.clear();
|
|
50
|
+
}
|
|
51
|
+
function rememberPendingCommentaryTags(target, tagged) {
|
|
52
|
+
for (const [block, signature] of tagged) target.set(block, signature);
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { tagUnresolvedTextAsCommentary as a, tagPendingCommentaryText as i, rememberPendingCommentaryTags as n, tagInterruptedTextPhases as r, clearPendingCommentaryText as t };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { n as getAiTransportHost } from "./host-
|
|
3
|
-
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-
|
|
4
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
+
import { n as getAiTransportHost } from "./host-CWuF-sS3.mjs";
|
|
3
|
+
import { n as clampOpenAIPromptCacheKey } from "./openai-prompt-cache-BI0rkM-5.mjs";
|
|
4
|
+
import { n as buildBaseOptions } from "./simple-options-tcKOqnpF.mjs";
|
|
5
5
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
6
|
-
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput,
|
|
6
|
+
import { a as resolveResponsesReasoningEffort, i as createResponsesAssistantOutput, r as convertResponsesMessages, s as runResponsesStreamLifecycle, t as applyCommonResponsesParams } from "./openai-responses-shared-ZyQEzS5i.mjs";
|
|
7
7
|
import { i as resolveAzureDeploymentNameFromMap, t as isOpenAICompatibleAzureResponsesBaseUrl } from "./azure-openai-responses-client-compat-C7K7QfUE.mjs";
|
|
8
8
|
import OpenAI, { AzureOpenAI } from "openai";
|
|
9
9
|
//#region packages/ai/src/providers/azure-openai-responses.ts
|
|
@@ -8,18 +8,6 @@ function asNonNegativeFiniteNumber(value) {
|
|
|
8
8
|
const number = asFiniteNumber(value);
|
|
9
9
|
return number && number < 0 ? void 0 : number;
|
|
10
10
|
}
|
|
11
|
-
/** Returns a finite number only when it satisfies the supplied inclusive/exclusive bounds. */
|
|
12
|
-
function asFiniteNumberInRange(value, range) {
|
|
13
|
-
const number = asFiniteNumber(value);
|
|
14
|
-
if (number === void 0) return;
|
|
15
|
-
if (range.min !== void 0) {
|
|
16
|
-
if (range.minExclusive ? number <= range.min : number < range.min) return;
|
|
17
|
-
}
|
|
18
|
-
if (range.max !== void 0) {
|
|
19
|
-
if (range.maxExclusive ? number >= range.max : number > range.max) return;
|
|
20
|
-
}
|
|
21
|
-
return number;
|
|
22
|
-
}
|
|
23
11
|
function normalizeNumericString(value) {
|
|
24
12
|
const trimmed = value.trim();
|
|
25
13
|
return trimmed ? trimmed : void 0;
|
|
@@ -33,15 +21,6 @@ function parseStrictInteger(value) {
|
|
|
33
21
|
const parsed = Number(normalized);
|
|
34
22
|
return Number.isSafeInteger(parsed) ? parsed : void 0;
|
|
35
23
|
}
|
|
36
|
-
/** Parses only finite decimal/scientific string tokens, rejecting partial numbers. */
|
|
37
|
-
function parseStrictFiniteNumber(value) {
|
|
38
|
-
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
39
|
-
if (typeof value !== "string") return;
|
|
40
|
-
const normalized = normalizeNumericString(value);
|
|
41
|
-
if (!normalized || !/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:e[+-]?\d+)?$/i.test(normalized)) return;
|
|
42
|
-
const parsed = Number(normalized);
|
|
43
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
44
|
-
}
|
|
45
24
|
/** Conservative upper bound for Node timer delays. */
|
|
46
25
|
const MAX_TIMER_TIMEOUT_MS = 2147e6;
|
|
47
26
|
/** Clamps finite millisecond values into the Node-safe timer range. */
|
|
@@ -62,11 +41,6 @@ function parseStrictPositiveInteger(value) {
|
|
|
62
41
|
const parsed = parseStrictInteger(value);
|
|
63
42
|
return parsed !== void 0 && parsed > 0 ? parsed : void 0;
|
|
64
43
|
}
|
|
65
|
-
/** Parses strict non-negative integer values from numbers or strings. */
|
|
66
|
-
function parseStrictNonNegativeInteger(value) {
|
|
67
|
-
const parsed = parseStrictInteger(value);
|
|
68
|
-
return parsed !== void 0 && parsed >= 0 ? parsed : void 0;
|
|
69
|
-
}
|
|
70
44
|
//#endregion
|
|
71
45
|
//#region packages/media-core/src/base64.ts
|
|
72
46
|
/** Estimates decoded bytes without allocating a cleaned copy of the base64 payload. */
|
|
@@ -140,4 +114,4 @@ function canonicalizeBase64(base64) {
|
|
|
140
114
|
return remainder === 0 ? cleaned : cleaned + "=".repeat(4 - remainder);
|
|
141
115
|
}
|
|
142
116
|
//#endregion
|
|
143
|
-
export {
|
|
117
|
+
export { clampTimerTimeoutMs as a, asNonNegativeFiniteNumber as i, estimateBase64DecodedBytes as n, parseStrictPositiveInteger as o, asFiniteNumber as r, resolveTimerTimeoutMs as s, canonicalizeBase64 as t };
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./provider-error-
|
|
1
|
+
import { n as normalizeLowercaseStringOrEmpty } from "./string-coerce-fsri9iCu.mjs";
|
|
2
|
+
import "./provider-error-C6TbKiey.mjs";
|
|
3
3
|
//#region packages/normalization-core/src/error-coercion.ts
|
|
4
|
+
function readProperty(value, key) {
|
|
5
|
+
try {
|
|
6
|
+
return value[key];
|
|
7
|
+
} catch {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Normalizes an unknown thrown value into an Error. Non-Error objects become
|
|
6
13
|
* the `cause` and have their enumerable fields copied so structured details
|
|
@@ -15,7 +22,7 @@ function toErrorObject(value, fallbackMessage) {
|
|
|
15
22
|
}
|
|
16
23
|
function extractErrorCode(err) {
|
|
17
24
|
if (!err || typeof err !== "object") return;
|
|
18
|
-
const code = err
|
|
25
|
+
const code = readProperty(err, "code");
|
|
19
26
|
if (typeof code === "string") return code;
|
|
20
27
|
if (typeof code === "number") return String(code);
|
|
21
28
|
}
|
|
@@ -25,16 +32,15 @@ function readErrorName(err) {
|
|
|
25
32
|
return typeof name === "string" ? name : "";
|
|
26
33
|
}
|
|
27
34
|
function collectErrorGraphCandidates(err, resolveNested) {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const current = queue.shift();
|
|
33
|
-
if (current == null || seen.has(current)) continue;
|
|
34
|
-
seen.add(current);
|
|
35
|
-
candidates.push(current);
|
|
35
|
+
if (err == null) return [];
|
|
36
|
+
const candidates = [err];
|
|
37
|
+
const seen = (/* @__PURE__ */ new Set()).add(err);
|
|
38
|
+
for (const current of candidates) {
|
|
36
39
|
if (!current || typeof current !== "object" || !resolveNested) continue;
|
|
37
|
-
for (const nested of resolveNested(current)) if (nested != null && !seen.has(nested))
|
|
40
|
+
for (const nested of resolveNested(current)) if (nested != null && !seen.has(nested)) {
|
|
41
|
+
seen.add(nested);
|
|
42
|
+
candidates.push(nested);
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
return candidates;
|
|
40
46
|
}
|
|
@@ -49,18 +55,20 @@ function extractErrorCodeOrErrno(err) {
|
|
|
49
55
|
function collectNestedErrorCandidates(err) {
|
|
50
56
|
return collectErrorGraphCandidates(err, (current) => {
|
|
51
57
|
const nested = [
|
|
52
|
-
current
|
|
53
|
-
current
|
|
54
|
-
current
|
|
55
|
-
current
|
|
56
|
-
current
|
|
58
|
+
readProperty(current, "cause"),
|
|
59
|
+
readProperty(current, "reason"),
|
|
60
|
+
readProperty(current, "original"),
|
|
61
|
+
readProperty(current, "error"),
|
|
62
|
+
readProperty(current, "data")
|
|
57
63
|
];
|
|
58
|
-
|
|
64
|
+
const errors = readProperty(current, "errors");
|
|
65
|
+
if (Array.isArray(errors)) nested.push(...errors);
|
|
59
66
|
return nested;
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
//#endregion
|
|
63
70
|
//#region packages/ai/src/utils/retryable-network-errors.ts
|
|
71
|
+
const WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE = "ERR_WEBSOCKET_NON_RETRYABLE_CLOSE";
|
|
64
72
|
const TRANSIENT_NETWORK_CODES = /* @__PURE__ */ new Set([
|
|
65
73
|
"ECONNRESET",
|
|
66
74
|
"ECONNREFUSED",
|
|
@@ -83,7 +91,8 @@ const TRANSIENT_NETWORK_CODES = /* @__PURE__ */ new Set([
|
|
|
83
91
|
"ERR_HTTP2_INVALID_SESSION",
|
|
84
92
|
"EPROTO",
|
|
85
93
|
"ERR_SSL_WRONG_VERSION_NUMBER",
|
|
86
|
-
"ERR_SSL_PROTOCOL_RETURNED_AN_ERROR"
|
|
94
|
+
"ERR_SSL_PROTOCOL_RETURNED_AN_ERROR",
|
|
95
|
+
"ERR_WEBSOCKET_TRANSPORT"
|
|
87
96
|
]);
|
|
88
97
|
const TRANSIENT_NETWORK_ERROR_NAMES = /* @__PURE__ */ new Set([
|
|
89
98
|
"AbortError",
|
|
@@ -118,7 +127,9 @@ function hasRetryableConnectionErrorCode(message) {
|
|
|
118
127
|
/** Returns true when any nested error proves a transient network failure. */
|
|
119
128
|
function isTransientNetworkError(err) {
|
|
120
129
|
if (!err) return false;
|
|
121
|
-
|
|
130
|
+
const candidates = collectNestedErrorCandidates(err);
|
|
131
|
+
if (candidates.some((candidate) => extractErrorCodeOrErrno(candidate) === "ERR_WEBSOCKET_NON_RETRYABLE_CLOSE")) return false;
|
|
132
|
+
for (const candidate of candidates) {
|
|
122
133
|
const code = extractErrorCodeOrErrno(candidate);
|
|
123
134
|
if (code && TRANSIENT_NETWORK_CODES.has(code)) return true;
|
|
124
135
|
const name = readErrorName(candidate);
|
|
@@ -133,4 +144,68 @@ function isTransientNetworkError(err) {
|
|
|
133
144
|
return false;
|
|
134
145
|
}
|
|
135
146
|
//#endregion
|
|
136
|
-
|
|
147
|
+
//#region packages/ai/src/transports/model-transport-debug.ts
|
|
148
|
+
/**
|
|
149
|
+
* Environment-driven debug controls for model transport logging.
|
|
150
|
+
*
|
|
151
|
+
* Model adapters share these helpers so payload, SSE, and transport diagnostics
|
|
152
|
+
* interpret OpenClaw debug environment variables consistently.
|
|
153
|
+
*/
|
|
154
|
+
function isTruthyEnv(value) {
|
|
155
|
+
const normalized = normalizeLowercaseStringOrEmpty(value);
|
|
156
|
+
return normalized.length > 0 && normalized !== "0" && normalized !== "false" && normalized !== "off" && normalized !== "no";
|
|
157
|
+
}
|
|
158
|
+
/** Resolves model payload debug verbosity from `OPENCLAW_DEBUG_MODEL_PAYLOAD`. */
|
|
159
|
+
function resolveModelPayloadDebugMode(env = process.env) {
|
|
160
|
+
const normalized = normalizeLowercaseStringOrEmpty(env.OPENCLAW_DEBUG_MODEL_PAYLOAD);
|
|
161
|
+
if (normalized === "tools" || normalized === "full-redacted") return normalized;
|
|
162
|
+
if (normalized === "summary") return "summary";
|
|
163
|
+
return "off";
|
|
164
|
+
}
|
|
165
|
+
/** Resolves SSE stream debug verbosity from `OPENCLAW_DEBUG_SSE`. */
|
|
166
|
+
function resolveModelSseDebugMode(env = process.env) {
|
|
167
|
+
const normalized = normalizeLowercaseStringOrEmpty(env.OPENCLAW_DEBUG_SSE);
|
|
168
|
+
if (normalized === "peek") return "peek";
|
|
169
|
+
if (normalized === "events" || isTruthyEnv(normalized)) return "events";
|
|
170
|
+
return "off";
|
|
171
|
+
}
|
|
172
|
+
/** Returns whether any model transport debug channel is enabled. */
|
|
173
|
+
function isModelTransportDebugEnabled(env = process.env) {
|
|
174
|
+
return isTruthyEnv(env.OPENCLAW_DEBUG_MODEL_TRANSPORT) || resolveModelPayloadDebugMode(env) !== "off" || resolveModelSseDebugMode(env) !== "off" || isTruthyEnv(env.OPENCLAW_DEBUG_CODE_MODE);
|
|
175
|
+
}
|
|
176
|
+
function isModelFetchMetadataMessage(message) {
|
|
177
|
+
return message.startsWith("[model-fetch]");
|
|
178
|
+
}
|
|
179
|
+
/** Emits model-fetch metadata at info level by default; other diagnostics require debug env. */
|
|
180
|
+
function emitModelTransportDebug(log, message) {
|
|
181
|
+
if (isModelFetchMetadataMessage(message) || isModelTransportDebugEnabled()) {
|
|
182
|
+
log.info(message);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
log.debug(message);
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region packages/ai/src/transports/model-transport-url.ts
|
|
189
|
+
/**
|
|
190
|
+
* Debug formatting helpers for model transport endpoints.
|
|
191
|
+
* Keeps logs useful without exposing credentials, request params, or fragments.
|
|
192
|
+
*/
|
|
193
|
+
/** Return a sanitized URL suitable for logs and diagnostics. */
|
|
194
|
+
function formatModelTransportDebugUrl(rawUrl) {
|
|
195
|
+
try {
|
|
196
|
+
const parsed = new URL(rawUrl);
|
|
197
|
+
parsed.username = "";
|
|
198
|
+
parsed.password = "";
|
|
199
|
+
parsed.search = "";
|
|
200
|
+
parsed.hash = "";
|
|
201
|
+
return parsed.toString();
|
|
202
|
+
} catch {
|
|
203
|
+
return "<invalid-url>";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Format a configured base URL for debug output, or the implicit default. */
|
|
207
|
+
function formatModelTransportDebugBaseUrl(rawUrl) {
|
|
208
|
+
return rawUrl ? formatModelTransportDebugUrl(rawUrl) : "default";
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
export { resolveModelSseDebugMode as a, isTransientNetworkError as c, resolveModelPayloadDebugMode as i, extractErrorCodeOrErrno as l, formatModelTransportDebugUrl as n, WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE as o, emitModelTransportDebug as r, hasRetryableConnectionErrorCode as s, formatModelTransportDebugBaseUrl as t, toErrorObject as u };
|
package/dist/diagnostics.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { a as extractDiagnosticError, i as createAssistantMessageDiagnostic, n as DiagnosticErrorInfo, o as formatThrownValue, r as appendAssistantMessageDiagnostic, s as isProviderRefusalAssistantError, t as AssistantMessageDiagnostic } from "./diagnostics-DnPnOui6.mjs";
|
|
2
2
|
import { n as ProviderErrorRedactor, r as configureProviderErrorRedactor } from "./provider-error-CzNw4BWX.mjs";
|
|
3
|
+
import { n as formatModelTransportDebugUrl, r as emitModelTransportDebug, t as formatModelTransportDebugBaseUrl } from "./model-transport-url-DKocrEsb.mjs";
|
|
3
4
|
//#region packages/ai/src/utils/credential-redaction.d.ts
|
|
4
5
|
type DiagnosticMediaField = {
|
|
5
6
|
kind: "context";
|
|
@@ -22,8 +23,9 @@ export declare function projectDiagnosticValue(value: unknown, policy?: Diagnost
|
|
|
22
23
|
}): unknown;
|
|
23
24
|
//#endregion
|
|
24
25
|
//#region packages/ai/src/utils/retryable-network-errors.d.ts
|
|
26
|
+
export declare const WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE = "ERR_WEBSOCKET_NON_RETRYABLE_CLOSE";
|
|
25
27
|
export declare function hasRetryableConnectionErrorCode(message: string): boolean;
|
|
26
28
|
/** Returns true when any nested error proves a transient network failure. */
|
|
27
29
|
export declare function isTransientNetworkError(err: unknown): boolean;
|
|
28
30
|
//#endregion
|
|
29
|
-
export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, isProviderRefusalAssistantError };
|
|
31
|
+
export { AssistantMessageDiagnostic, DiagnosticErrorInfo, type DiagnosticProjectionPolicy, type ProviderErrorRedactor, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, emitModelTransportDebug, extractDiagnosticError, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, formatThrownValue, isProviderRefusalAssistantError };
|
package/dist/diagnostics.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { a as isProviderRefusalAssistantError, i as formatThrownValue, n as createAssistantMessageDiagnostic, r as extractDiagnosticError, t as appendAssistantMessageDiagnostic } from "./diagnostics-CPeq9F7y.mjs";
|
|
2
|
-
import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-
|
|
3
|
-
import {
|
|
4
|
-
export { appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, extractDiagnosticError, formatThrownValue, hasRetryableConnectionErrorCode, isProviderRefusalAssistantError, isTransientNetworkError, projectDiagnosticValue };
|
|
2
|
+
import { r as projectDiagnosticValue, t as configureProviderErrorRedactor } from "./provider-error-C6TbKiey.mjs";
|
|
3
|
+
import { c as isTransientNetworkError, n as formatModelTransportDebugUrl, o as WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, r as emitModelTransportDebug, s as hasRetryableConnectionErrorCode, t as formatModelTransportDebugBaseUrl } from "./diagnostics-dV98PqIy.mjs";
|
|
4
|
+
export { WEBSOCKET_NON_RETRYABLE_CLOSE_ERROR_CODE, appendAssistantMessageDiagnostic, configureProviderErrorRedactor, createAssistantMessageDiagnostic, emitModelTransportDebug, extractDiagnosticError, formatModelTransportDebugBaseUrl, formatModelTransportDebugUrl, formatThrownValue, hasRetryableConnectionErrorCode, isProviderRefusalAssistantError, isTransientNetworkError, projectDiagnosticValue };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-
|
|
1
|
+
import { Q as ThinkingContent, a as AssistantMessage, o as AssistantMessageEvent, s as AssistantMessageEventStreamContract } from "./types-Dy1q0CSu.mjs";
|
|
2
2
|
//#region packages/llm-core/src/utils/event-stream.d.ts
|
|
3
|
+
/** Returns only an append whose current and previously observed snapshots still match. */
|
|
4
|
+
declare function readAssistantThinkingAppend(block: ThinkingContent, previous: string): string | undefined;
|
|
5
|
+
/** Observe native producer settlement without invoking consumer result decorators. */
|
|
6
|
+
declare function getEventStreamCompletion(stream: object): Promise<unknown> | undefined;
|
|
3
7
|
/** Generic async-iterable event stream with a separately awaited final result. */
|
|
4
8
|
declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
5
9
|
private queue;
|
|
6
10
|
private queueHead;
|
|
7
11
|
private waiting;
|
|
8
|
-
|
|
12
|
+
protected done: boolean;
|
|
9
13
|
private resultSettled;
|
|
10
14
|
private finalResultPromise;
|
|
11
15
|
private resolveFinalResult;
|
|
@@ -20,9 +24,13 @@ declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
|
20
24
|
}
|
|
21
25
|
/** Assistant-message event stream that resolves on done/error terminal events. */
|
|
22
26
|
declare class AssistantMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> implements AssistantMessageEventStreamContract {
|
|
27
|
+
private activeThinkingBlocks?;
|
|
28
|
+
push(event: AssistantMessageEvent): void;
|
|
29
|
+
end(result?: AssistantMessage): void;
|
|
30
|
+
private clearThinkingAppends;
|
|
23
31
|
constructor();
|
|
24
32
|
}
|
|
25
33
|
/** Creates an assistant-message stream for provider and plugin adapters. */
|
|
26
34
|
declare function createAssistantMessageEventStream(): AssistantMessageEventStream;
|
|
27
35
|
//#endregion
|
|
28
|
-
export { EventStream as n, createAssistantMessageEventStream as r, AssistantMessageEventStream as t };
|
|
36
|
+
export { readAssistantThinkingAppend as a, getEventStreamCompletion as i, EventStream as n, createAssistantMessageEventStream as r, AssistantMessageEventStream as t };
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
//#region packages/llm-core/src/utils/event-stream.ts
|
|
2
|
+
const thinkingAppends = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
/** Package-internal mutation fact for native reasoning projection. */
|
|
4
|
+
function appendAssistantThinking(block, delta) {
|
|
5
|
+
const before = block.thinking;
|
|
6
|
+
block.thinking += delta;
|
|
7
|
+
thinkingAppends.set(block, {
|
|
8
|
+
before,
|
|
9
|
+
after: block.thinking,
|
|
10
|
+
delta
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/** Returns only an append whose current and previously observed snapshots still match. */
|
|
14
|
+
function readAssistantThinkingAppend(block, previous) {
|
|
15
|
+
const append = thinkingAppends.get(block);
|
|
16
|
+
return append?.before === previous && append.after === block.thinking ? append.delta : void 0;
|
|
17
|
+
}
|
|
18
|
+
const eventStreamCompletions = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
/** Observe native producer settlement without invoking consumer result decorators. */
|
|
20
|
+
function getEventStreamCompletion(stream) {
|
|
21
|
+
return eventStreamCompletions.get(stream);
|
|
22
|
+
}
|
|
2
23
|
/** Generic async-iterable event stream with a separately awaited final result. */
|
|
3
24
|
var EventStream = class {
|
|
4
25
|
constructor(isComplete, extractResult) {
|
|
@@ -9,17 +30,11 @@ var EventStream = class {
|
|
|
9
30
|
this.resultSettled = false;
|
|
10
31
|
this.isComplete = isComplete;
|
|
11
32
|
this.extractResult = extractResult;
|
|
12
|
-
const resolvers = [];
|
|
13
|
-
const rejecters = [];
|
|
14
33
|
this.finalResultPromise = new Promise((resolve, reject) => {
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
this.resolveFinalResult = resolve;
|
|
35
|
+
this.rejectFinalResult = reject;
|
|
17
36
|
});
|
|
18
|
-
|
|
19
|
-
const rejectFinalResult = rejecters.at(0);
|
|
20
|
-
if (!resolveFinalResult || !rejectFinalResult) throw new Error("event stream result promise did not initialize its resolver");
|
|
21
|
-
this.resolveFinalResult = resolveFinalResult;
|
|
22
|
-
this.rejectFinalResult = rejectFinalResult;
|
|
37
|
+
eventStreamCompletions.set(this, this.finalResultPromise);
|
|
23
38
|
}
|
|
24
39
|
push(event) {
|
|
25
40
|
if (this.done) return;
|
|
@@ -57,6 +72,7 @@ var EventStream = class {
|
|
|
57
72
|
async *[Symbol.asyncIterator]() {
|
|
58
73
|
while (true) if (this.queueHead < this.queue.length) {
|
|
59
74
|
const event = this.queue[this.queueHead];
|
|
75
|
+
this.queue[this.queueHead] = void 0;
|
|
60
76
|
this.queueHead += 1;
|
|
61
77
|
if (this.queueHead >= 1024 && this.queueHead * 2 >= this.queue.length) {
|
|
62
78
|
this.queue = this.queue.slice(this.queueHead);
|
|
@@ -78,6 +94,28 @@ var EventStream = class {
|
|
|
78
94
|
};
|
|
79
95
|
/** Assistant-message event stream that resolves on done/error terminal events. */
|
|
80
96
|
var AssistantMessageEventStream = class extends EventStream {
|
|
97
|
+
push(event) {
|
|
98
|
+
if (event.type === "thinking_delta" || event.type === "thinking_end") {
|
|
99
|
+
const block = event.partial.content[event.contentIndex];
|
|
100
|
+
if (block?.type === "thinking") {
|
|
101
|
+
if (this.done || event.type === "thinking_end") {
|
|
102
|
+
thinkingAppends.delete(block);
|
|
103
|
+
this.activeThinkingBlocks?.delete(block);
|
|
104
|
+
} else if (thinkingAppends.has(block)) (this.activeThinkingBlocks ??= /* @__PURE__ */ new Set()).add(block);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (event.type === "done" || event.type === "error") this.clearThinkingAppends(event.type === "done" ? event.message : event.error);
|
|
108
|
+
super.push(event);
|
|
109
|
+
}
|
|
110
|
+
end(result) {
|
|
111
|
+
this.clearThinkingAppends(result);
|
|
112
|
+
super.end(result);
|
|
113
|
+
}
|
|
114
|
+
clearThinkingAppends(message) {
|
|
115
|
+
for (const block of message?.content ?? []) if (block.type === "thinking") thinkingAppends.delete(block);
|
|
116
|
+
for (const block of this.activeThinkingBlocks ?? []) thinkingAppends.delete(block);
|
|
117
|
+
this.activeThinkingBlocks = void 0;
|
|
118
|
+
}
|
|
81
119
|
constructor() {
|
|
82
120
|
super((event) => event.type === "done" || event.type === "error", (event) => {
|
|
83
121
|
if (event.type === "done") return event.message;
|
|
@@ -91,4 +129,4 @@ function createAssistantMessageEventStream() {
|
|
|
91
129
|
return new AssistantMessageEventStream();
|
|
92
130
|
}
|
|
93
131
|
//#endregion
|
|
94
|
-
export { EventStream as n,
|
|
132
|
+
export { getEventStreamCompletion as a, createAssistantMessageEventStream as i, EventStream as n, readAssistantThinkingAppend as o, appendAssistantThinking as r, AssistantMessageEventStream as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./event-stream-C1Z2piyk.mjs";
|
package/dist/event-stream.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import "./event-stream-
|
|
1
|
+
import { n as EventStream, r as createAssistantMessageEventStream, t as AssistantMessageEventStream } from "./event-stream-C1Z2piyk.mjs";
|
|
2
|
+
import "./event-stream-I_GlBsuZ.mjs";
|
|
3
3
|
export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
|
package/dist/event-stream.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as createAssistantMessageEventStream, n as EventStream, t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
2
|
export { AssistantMessageEventStream, EventStream, createAssistantMessageEventStream };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as projectCopilotRequestFacts } from "./github-copilot-request-facts-BTEBMeOv.mjs";
|
|
1
2
|
//#region packages/ai/src/providers/cloudflare.ts
|
|
2
3
|
function isCloudflareProvider(provider) {
|
|
3
4
|
return provider === "cloudflare-workers-ai" || provider === "cloudflare-ai-gateway";
|
|
@@ -14,20 +15,12 @@ function resolveCloudflareBaseUrl(model) {
|
|
|
14
15
|
}
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region packages/ai/src/providers/github-copilot-headers.ts
|
|
17
|
-
function inferCopilotInitiator(messages) {
|
|
18
|
-
const last = messages[messages.length - 1];
|
|
19
|
-
return last && last.role !== "user" ? "agent" : "user";
|
|
20
|
-
}
|
|
21
18
|
function hasCopilotVisionInput(messages) {
|
|
22
|
-
return messages.
|
|
23
|
-
if (msg.role === "user" && Array.isArray(msg.content)) return msg.content.some((c) => c.type === "image");
|
|
24
|
-
if (msg.role === "toolResult" && Array.isArray(msg.content)) return msg.content.some((c) => c.type === "image");
|
|
25
|
-
return false;
|
|
26
|
-
});
|
|
19
|
+
return projectCopilotRequestFacts(messages, "direct").hasImages;
|
|
27
20
|
}
|
|
28
21
|
function buildCopilotDynamicHeaders(params) {
|
|
29
22
|
const headers = {
|
|
30
|
-
"X-Initiator":
|
|
23
|
+
"X-Initiator": projectCopilotRequestFacts(params.messages, "direct", params.hasImages).initiator,
|
|
31
24
|
"Openai-Intent": "conversation-edits"
|
|
32
25
|
};
|
|
33
26
|
if (params.hasImages) headers["Copilot-Vision-Request"] = "true";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region packages/ai/src/providers/github-copilot-request-facts.ts
|
|
2
|
+
/** Request facts shared by Copilot transports; identity headers remain plugin-owned. */
|
|
3
|
+
function projectCopilotRequestFacts(messages, contentMode, hasImages) {
|
|
4
|
+
const last = messages.at(-1);
|
|
5
|
+
return {
|
|
6
|
+
initiator: last && (last.role !== "user" || contentMode === "nested" && containsContentType(last.content, "tool_result")) ? "agent" : "user",
|
|
7
|
+
hasImages: hasImages ?? messages.some((message) => (message.role === "user" || message.role === "toolResult") && Array.isArray(message.content) && message.content.some((item) => containsContentType(item, "image", contentMode)))
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function containsContentType(value, type, contentMode = "nested") {
|
|
11
|
+
if (contentMode === "nested" && Array.isArray(value)) return value.some((item) => containsContentType(item, type));
|
|
12
|
+
if (!value || typeof value !== "object") return false;
|
|
13
|
+
return "type" in value && value.type === type || contentMode === "nested" && "content" in value && containsContentType(value.content, type);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { projectCopilotRequestFacts as t };
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
2
|
-
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-
|
|
3
|
-
import { n as buildBaseOptions } from "./simple-options-
|
|
1
|
+
import { t as AssistantMessageEventStream } from "./event-stream-D8PARQfL.mjs";
|
|
2
|
+
import { n as getAiTransportHost, r as resolveAiTransportHeaderSentinels } from "./host-CWuF-sS3.mjs";
|
|
3
|
+
import { n as buildBaseOptions } from "./simple-options-tcKOqnpF.mjs";
|
|
4
4
|
import { n as getEnvApiKey } from "./env-api-keys-bktO00EJ.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { l as mergeTransportHeaders } from "./transport-stream-shared-Cu3ZPhNW.mjs";
|
|
6
|
+
import { t as createAssistantOutput } from "./assistant-output-iqnlJCV2.mjs";
|
|
7
|
+
import { t as resolveOpencodeSessionHeaders } from "./session-affinity-CCH7eYdB.mjs";
|
|
8
|
+
import { n as buildGoogleSimpleThinking, r as runGoogleGenerateContentLifecycle, t as buildGoogleGenerateContentParams } from "./google-shared-BedY23XS.mjs";
|
|
6
9
|
import { GoogleGenAI } from "@google/genai";
|
|
7
10
|
//#region packages/ai/src/providers/google.ts
|
|
8
11
|
let toolCallCounter = 0;
|
|
9
12
|
const streamGoogle = (model, context, options) => {
|
|
10
13
|
const stream = new AssistantMessageEventStream();
|
|
11
|
-
const output =
|
|
14
|
+
const output = createAssistantOutput(model, "google-generative-ai");
|
|
12
15
|
runGoogleGenerateContentLifecycle({
|
|
13
16
|
stream,
|
|
14
17
|
model,
|
|
15
18
|
output,
|
|
16
19
|
options,
|
|
17
20
|
createClient: () => {
|
|
18
|
-
return createClient(model, options?.apiKey || getEnvApiKey(model.provider) || "", options
|
|
21
|
+
return createClient(model, options?.apiKey || getEnvApiKey(model.provider) || "", resolveOpencodeSessionHeaders(model, options));
|
|
19
22
|
},
|
|
20
23
|
buildParams: () => buildParams(model, context, options),
|
|
21
24
|
nextToolCallId: (name) => `${name}_${Date.now()}_${++toolCallCounter}`
|
|
@@ -40,10 +43,7 @@ function createClient(model, apiKey, optionsHeaders) {
|
|
|
40
43
|
httpOptions.baseUrl = model.baseUrl;
|
|
41
44
|
httpOptions.apiVersion = "";
|
|
42
45
|
}
|
|
43
|
-
if (model.headers || optionsHeaders) httpOptions.headers = resolveAiTransportHeaderSentinels(
|
|
44
|
-
...model.headers,
|
|
45
|
-
...optionsHeaders
|
|
46
|
-
});
|
|
46
|
+
if (model.headers || optionsHeaders) httpOptions.headers = resolveAiTransportHeaderSentinels(mergeTransportHeaders(model.headers, optionsHeaders));
|
|
47
47
|
const resolvedApiKey = apiKey ? getAiTransportHost().resolveSecretSentinel(apiKey) : void 0;
|
|
48
48
|
return new GoogleGenAI({
|
|
49
49
|
apiKey: resolvedApiKey,
|