@vibe-lark/larkpal 0.1.85 → 0.1.86
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-DYjVxojW.mjs +46 -0
- package/dist/activation-context--5yu1dPF-Bwsn3moT.mjs +172 -0
- package/dist/anthropic-TH8ERTXK.mjs +5962 -0
- package/dist/assistant-visible-text-DuFWokAt-CsbII5KS.mjs +596 -0
- package/dist/azure-openai-responses-Bt_Ag9Er.mjs +166 -0
- package/dist/boundary-file-read-BSd9MXPy--KThL5e6.mjs +594 -0
- package/dist/browser-lifecycle-cleanup-BdNsMhMD-O3tnAM4i.mjs +60 -0
- package/dist/build-DgTrEpge.mjs +3333 -0
- package/dist/bundled-compat-BpaDaAAu-D7oazKjD.mjs +5216 -0
- package/dist/bundled-dir-U738ay4K-DXK0q_TV.mjs +258 -0
- package/dist/call-DimWbpgJ-ColD4W-y.mjs +9993 -0
- package/dist/channel-bootstrap.runtime-BVclcGv1-DJv_Z-Kr.mjs +2 -0
- package/dist/channel-bootstrap.runtime-Cwcr38m2-VRfVCR-i.mjs +33 -0
- package/dist/chunk-D6SyT4dJ.mjs +36 -0
- package/dist/cli.mjs +6 -6
- package/dist/command-format-LSnUCVVF-BQ2SMKka.mjs +685 -0
- package/dist/config-Bim2pi8a-BQUdfiEi.mjs +9 -0
- package/dist/delivery-context.shared-j5hC5qb1-CI83RXXZ.mjs +72 -0
- package/dist/diagnostic-ClMwNnUA-D6nUtLnb.mjs +140 -0
- package/dist/dist-CEGw8-2W.mjs +429 -0
- package/dist/dist-DD2aJ2UL.mjs +125135 -0
- package/dist/env-api-keys-BVvSg7T2.mjs +68 -0
- package/dist/event-stream-xaQWmyas.mjs +15226 -0
- package/dist/facade-loader-DFzIYYt_-CIr4HKtE.mjs +194 -0
- package/dist/from-DF7cl2wz.mjs +3842 -0
- package/dist/gateway-method-policy-C7rf0SeV-CJQMEYIE.mjs +28 -0
- package/dist/github-copilot-headers-DjqWtUoP.mjs +22 -0
- package/dist/google-C2pVrgBZ.mjs +336 -0
- package/dist/google-gemini-cli-BBxgS5Ho.mjs +623 -0
- package/dist/google-shared-BsWgwEk1.mjs +22791 -0
- package/dist/google-vertex-BsVLJrrC.mjs +358 -0
- package/dist/hash-DAFtW_W7.mjs +16 -0
- package/dist/headers-R3HdCbAE.mjs +8 -0
- package/dist/home-dir-C44RaPME-CBRS4HLP.mjs +93 -0
- package/dist/ids-BPsM98Uu-CwuxvUai.mjs +77 -0
- package/dist/image-2w3cApg7-CxpHvoB5.mjs +207 -0
- package/dist/io-CH2g3vsv-BOGlLlB8.mjs +26218 -0
- package/dist/jiti-loader-cache-Bat69wam-D6hCxboy.mjs +5049 -0
- package/dist/json-file-BQRNuxmK-DhJM5NsG.mjs +108 -0
- package/dist/json-parse-v_HIJjjI.mjs +381 -0
- package/dist/jws-GFcTvvVT.mjs +2291 -0
- package/dist/{lark-cli-provider-7LvtOIF_.mjs → lark-cli-provider-BARgbbmo.mjs} +1 -1
- package/dist/{live-smoke-nvTUPtrv.mjs → live-smoke-BhkBOcH9.mjs} +3 -3
- package/dist/load-context-mb7uvLSn-B10MAi3I.mjs +29 -0
- package/dist/loader-708jrx4Y-BOswuvpe.mjs +5053 -0
- package/dist/main.mjs +56550 -205
- package/dist/manifest-registry-_hxKCS2K-CZdeyN0f.mjs +3512 -0
- package/dist/mcp-server.mjs +1 -1
- package/dist/message-channel-Bk_YHfQg-AeNrPPpp.mjs +50 -0
- package/dist/message-channel-core-DTA--Gjh-CY4Tkb7N.mjs +29 -0
- package/dist/message.config.runtime-K-k4XOyq-DZTmXomP.mjs +2 -0
- package/dist/message.gateway.runtime-DqHOHRTQ-DH4ml0YF.mjs +2 -0
- package/dist/mistral-CaR4DiLu.mjs +28657 -0
- package/dist/model-auth-env-oyg2Hexc-DU_rOUU5.mjs +1306 -0
- package/dist/models-config-BmpSQJQF-Gfvh1n3A.mjs +1282 -0
- package/dist/models-config.runtime-BsU_22xk.mjs +2 -0
- package/dist/multipart-parser-DedmaB5g.mjs +294 -0
- package/dist/oauth-DOJeGfcE.mjs +6392 -0
- package/dist/openai-BDtIh3Ja.mjs +6693 -0
- package/dist/openai-codex-responses-C5EORu31.mjs +664 -0
- package/dist/openai-completions-CR_cS6gX.mjs +669 -0
- package/dist/openai-responses-oGxwZyuC.mjs +184 -0
- package/dist/openai-responses-shared-BixMSDZE.mjs +398 -0
- package/dist/paths-D6msg0S1-C2lYuisN.mjs +189 -0
- package/dist/paths-D92DjaZ--CTOESW2b.mjs +192 -0
- package/dist/pi-model-discovery-Bd0TWzo8-BFsJmeMb.mjs +227 -0
- package/dist/pi-model-discovery-runtime-CCCZxkd8.mjs +2 -0
- package/dist/pi-tools.before-tool-call.runtime-Bn7uqKie-C5ewk8kK.mjs +399 -0
- package/dist/plugin-auto-enable-DdH3n9V8-DsA1isaF.mjs +1456 -0
- package/dist/process-scoped-map-B2cWkYET-CXwUZ8CZ.mjs +61 -0
- package/dist/provider-discovery.runtime-BPzz1PFj.mjs +58 -0
- package/dist/provider-model-compat-CFqcq0it-BDDuBI3A.mjs +118 -0
- package/dist/provider-runtime-C8rljsNs-CIT93zoy.mjs +2 -0
- package/dist/provider-runtime-CT50mNIX-BwEV6GyO.mjs +573 -0
- package/dist/provider-stream-COLujAAo-CbJPDngm.mjs +35449 -0
- package/dist/providers.runtime-Ba7tOlq7-CXkhkzU9.mjs +219 -0
- package/dist/public-surface-loader-BVl0NQAE-C0piXtsT.mjs +117 -0
- package/dist/resolve-C33B7eeu-BNvYTl6k.mjs +1041 -0
- package/dist/runtime-Cym-fqI8-DaSDMH-a.mjs +120 -0
- package/dist/runtime-channel-state-CohMybAh-hXR6y5Gx.mjs +19 -0
- package/dist/runtime-snapshot-C54O1-gI-40cbyi7P.mjs +677 -0
- package/dist/runtime-state-IBOIXKOx-Bf9tcLvc.mjs +10 -0
- package/dist/runtime-web-tools-fallback.runtime-Ca-qn1mj-BCVImm7a.mjs +39 -0
- package/dist/runtime-web-tools-manifest.runtime-BgxQTjmq-Cb4nJkRT.mjs +2 -0
- package/dist/runtime-web-tools-public-artifacts.runtime-D9qcoWIX-BrQdXzOQ.mjs +2 -0
- package/dist/session-archive.runtime-B52_5vs4-BG-_IwNJ.mjs +2 -0
- package/dist/session-key-Cn2QoOyX-CuHbJMgR.mjs +82 -0
- package/dist/session-transcript-files.fs-DEeFXruQ-B1PF6nLy.mjs +147 -0
- package/dist/src-BgCX0MLG.mjs +813 -0
- package/dist/src-DYbqlAqf.mjs +1177 -0
- package/dist/subagent-announce-L5WsQatW-CQWI9GMd.mjs +344 -0
- package/dist/subagent-announce.registry.runtime-DiqZyeTs-BKuniyi3.mjs +28 -0
- package/dist/subagent-registry-steer-runtime-DFgZFC0j-BhBz0roy.mjs +211 -0
- package/dist/subagent-system-prompt-C1qnN--K-DpnTFP47.mjs +3061 -0
- package/dist/target-parsing-loaded-DKkb6jJY-BMD4CkpS.mjs +1002 -0
- package/dist/task-registry-delivery-runtime-Dd1CUkZF-C8U40a3O.mjs +2950 -0
- package/dist/task-registry-delivery-runtime-ragbeVx5-CNbFAkjD.mjs +2 -0
- package/dist/thinking-Bh-7MqXz-D3woGbO7.mjs +2 -0
- package/dist/transcript-E_-ISOkD-DWCfZP2p.mjs +2019 -0
- package/dist/transcript.runtime-BqhvZZdl-BPy42vBP.mjs +2 -0
- package/dist/transform-messages-DbhIzTxq.mjs +207 -0
- package/dist/web-provider-public-artifacts-BlpRwIUS-CGPSV4W2.mjs +295 -0
- package/dist/web-search-providers.runtime--0aUtC3b-DyuhC95V.mjs +200 -0
- package/package.json +3 -3
- package/dist/rolldown-runtime-wcPFST8Q.mjs +0 -13
- /package/dist/{interactive-init-B6j8j_Ap.mjs → interactive-init-BXQBalNr.mjs} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/openclaw@2026.4.22_@napi-rs+canvas@0.1.99/node_modules/openclaw/dist/gateway-method-policy-C7rf0SeV.js
|
|
2
|
+
const RESERVED_ADMIN_GATEWAY_METHOD_PREFIXES = [
|
|
3
|
+
"exec.approvals.",
|
|
4
|
+
"config.",
|
|
5
|
+
"wizard.",
|
|
6
|
+
"update."
|
|
7
|
+
];
|
|
8
|
+
const RESERVED_ADMIN_GATEWAY_METHOD_SCOPE = "operator.admin";
|
|
9
|
+
function isReservedAdminGatewayMethod(method) {
|
|
10
|
+
return RESERVED_ADMIN_GATEWAY_METHOD_PREFIXES.some((prefix) => method.startsWith(prefix));
|
|
11
|
+
}
|
|
12
|
+
function resolveReservedGatewayMethodScope(method) {
|
|
13
|
+
if (!isReservedAdminGatewayMethod(method)) return;
|
|
14
|
+
return RESERVED_ADMIN_GATEWAY_METHOD_SCOPE;
|
|
15
|
+
}
|
|
16
|
+
function normalizePluginGatewayMethodScope(method, scope) {
|
|
17
|
+
const reservedScope = resolveReservedGatewayMethodScope(method);
|
|
18
|
+
if (!reservedScope || !scope || scope === reservedScope) return {
|
|
19
|
+
scope,
|
|
20
|
+
coercedToReservedAdmin: false
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
scope: reservedScope,
|
|
24
|
+
coercedToReservedAdmin: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { resolveReservedGatewayMethodScope as n, normalizePluginGatewayMethodScope as t };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#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/github-copilot-headers.js
|
|
2
|
+
function inferCopilotInitiator(messages) {
|
|
3
|
+
const last = messages[messages.length - 1];
|
|
4
|
+
return last && last.role !== "user" ? "agent" : "user";
|
|
5
|
+
}
|
|
6
|
+
function hasCopilotVisionInput(messages) {
|
|
7
|
+
return messages.some((msg) => {
|
|
8
|
+
if (msg.role === "user" && Array.isArray(msg.content)) return msg.content.some((c) => c.type === "image");
|
|
9
|
+
if (msg.role === "toolResult" && Array.isArray(msg.content)) return msg.content.some((c) => c.type === "image");
|
|
10
|
+
return false;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function buildCopilotDynamicHeaders(params) {
|
|
14
|
+
const headers = {
|
|
15
|
+
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
16
|
+
"Openai-Intent": "conversation-edits"
|
|
17
|
+
};
|
|
18
|
+
if (params.hasImages) headers["Copilot-Vision-Request"] = "true";
|
|
19
|
+
return headers;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { hasCopilotVisionInput as n, buildCopilotDynamicHeaders as t };
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { t as getEnvApiKey } from "./env-api-keys-BVvSg7T2.mjs";
|
|
2
|
+
import { r as calculateCost, t as AssistantMessageEventStream } from "./event-stream-xaQWmyas.mjs";
|
|
3
|
+
import { a as sanitizeSurrogates, i as clampReasoning, r as buildBaseOptions } from "./transform-messages-DbhIzTxq.mjs";
|
|
4
|
+
import { c as GoogleGenAI, i as mapStopReason, 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.js
|
|
6
|
+
let toolCallCounter = 0;
|
|
7
|
+
const streamGoogle = (model, context, options) => {
|
|
8
|
+
const stream = new AssistantMessageEventStream();
|
|
9
|
+
(async () => {
|
|
10
|
+
const output = {
|
|
11
|
+
role: "assistant",
|
|
12
|
+
content: [],
|
|
13
|
+
api: "google-generative-ai",
|
|
14
|
+
provider: model.provider,
|
|
15
|
+
model: model.id,
|
|
16
|
+
usage: {
|
|
17
|
+
input: 0,
|
|
18
|
+
output: 0,
|
|
19
|
+
cacheRead: 0,
|
|
20
|
+
cacheWrite: 0,
|
|
21
|
+
totalTokens: 0,
|
|
22
|
+
cost: {
|
|
23
|
+
input: 0,
|
|
24
|
+
output: 0,
|
|
25
|
+
cacheRead: 0,
|
|
26
|
+
cacheWrite: 0,
|
|
27
|
+
total: 0
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
stopReason: "stop",
|
|
31
|
+
timestamp: Date.now()
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const client = createClient(model, options?.apiKey || getEnvApiKey(model.provider) || "", options?.headers);
|
|
35
|
+
let params = buildParams(model, context, options);
|
|
36
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
37
|
+
if (nextParams !== void 0) params = nextParams;
|
|
38
|
+
const googleStream = await client.models.generateContentStream(params);
|
|
39
|
+
stream.push({
|
|
40
|
+
type: "start",
|
|
41
|
+
partial: output
|
|
42
|
+
});
|
|
43
|
+
let currentBlock = null;
|
|
44
|
+
const blocks = output.content;
|
|
45
|
+
const blockIndex = () => blocks.length - 1;
|
|
46
|
+
for await (const chunk of googleStream) {
|
|
47
|
+
output.responseId ||= chunk.responseId;
|
|
48
|
+
const candidate = chunk.candidates?.[0];
|
|
49
|
+
if (candidate?.content?.parts) for (const part of candidate.content.parts) {
|
|
50
|
+
if (part.text !== void 0) {
|
|
51
|
+
const isThinking = isThinkingPart(part);
|
|
52
|
+
if (!currentBlock || isThinking && currentBlock.type !== "thinking" || !isThinking && currentBlock.type !== "text") {
|
|
53
|
+
if (currentBlock) if (currentBlock.type === "text") stream.push({
|
|
54
|
+
type: "text_end",
|
|
55
|
+
contentIndex: blocks.length - 1,
|
|
56
|
+
content: currentBlock.text,
|
|
57
|
+
partial: output
|
|
58
|
+
});
|
|
59
|
+
else stream.push({
|
|
60
|
+
type: "thinking_end",
|
|
61
|
+
contentIndex: blockIndex(),
|
|
62
|
+
content: currentBlock.thinking,
|
|
63
|
+
partial: output
|
|
64
|
+
});
|
|
65
|
+
if (isThinking) {
|
|
66
|
+
currentBlock = {
|
|
67
|
+
type: "thinking",
|
|
68
|
+
thinking: "",
|
|
69
|
+
thinkingSignature: void 0
|
|
70
|
+
};
|
|
71
|
+
output.content.push(currentBlock);
|
|
72
|
+
stream.push({
|
|
73
|
+
type: "thinking_start",
|
|
74
|
+
contentIndex: blockIndex(),
|
|
75
|
+
partial: output
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
currentBlock = {
|
|
79
|
+
type: "text",
|
|
80
|
+
text: ""
|
|
81
|
+
};
|
|
82
|
+
output.content.push(currentBlock);
|
|
83
|
+
stream.push({
|
|
84
|
+
type: "text_start",
|
|
85
|
+
contentIndex: blockIndex(),
|
|
86
|
+
partial: output
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (currentBlock.type === "thinking") {
|
|
91
|
+
currentBlock.thinking += part.text;
|
|
92
|
+
currentBlock.thinkingSignature = retainThoughtSignature(currentBlock.thinkingSignature, part.thoughtSignature);
|
|
93
|
+
stream.push({
|
|
94
|
+
type: "thinking_delta",
|
|
95
|
+
contentIndex: blockIndex(),
|
|
96
|
+
delta: part.text,
|
|
97
|
+
partial: output
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
currentBlock.text += part.text;
|
|
101
|
+
currentBlock.textSignature = retainThoughtSignature(currentBlock.textSignature, part.thoughtSignature);
|
|
102
|
+
stream.push({
|
|
103
|
+
type: "text_delta",
|
|
104
|
+
contentIndex: blockIndex(),
|
|
105
|
+
delta: part.text,
|
|
106
|
+
partial: output
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (part.functionCall) {
|
|
111
|
+
if (currentBlock) {
|
|
112
|
+
if (currentBlock.type === "text") stream.push({
|
|
113
|
+
type: "text_end",
|
|
114
|
+
contentIndex: blockIndex(),
|
|
115
|
+
content: currentBlock.text,
|
|
116
|
+
partial: output
|
|
117
|
+
});
|
|
118
|
+
else stream.push({
|
|
119
|
+
type: "thinking_end",
|
|
120
|
+
contentIndex: blockIndex(),
|
|
121
|
+
content: currentBlock.thinking,
|
|
122
|
+
partial: output
|
|
123
|
+
});
|
|
124
|
+
currentBlock = null;
|
|
125
|
+
}
|
|
126
|
+
const providedId = part.functionCall.id;
|
|
127
|
+
const toolCall = {
|
|
128
|
+
type: "toolCall",
|
|
129
|
+
id: !providedId || output.content.some((b) => b.type === "toolCall" && b.id === providedId) ? `${part.functionCall.name}_${Date.now()}_${++toolCallCounter}` : providedId,
|
|
130
|
+
name: part.functionCall.name || "",
|
|
131
|
+
arguments: part.functionCall.args ?? {},
|
|
132
|
+
...part.thoughtSignature && { thoughtSignature: part.thoughtSignature }
|
|
133
|
+
};
|
|
134
|
+
output.content.push(toolCall);
|
|
135
|
+
stream.push({
|
|
136
|
+
type: "toolcall_start",
|
|
137
|
+
contentIndex: blockIndex(),
|
|
138
|
+
partial: output
|
|
139
|
+
});
|
|
140
|
+
stream.push({
|
|
141
|
+
type: "toolcall_delta",
|
|
142
|
+
contentIndex: blockIndex(),
|
|
143
|
+
delta: JSON.stringify(toolCall.arguments),
|
|
144
|
+
partial: output
|
|
145
|
+
});
|
|
146
|
+
stream.push({
|
|
147
|
+
type: "toolcall_end",
|
|
148
|
+
contentIndex: blockIndex(),
|
|
149
|
+
toolCall,
|
|
150
|
+
partial: output
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (candidate?.finishReason) {
|
|
155
|
+
output.stopReason = mapStopReason(candidate.finishReason);
|
|
156
|
+
if (output.content.some((b) => b.type === "toolCall")) output.stopReason = "toolUse";
|
|
157
|
+
}
|
|
158
|
+
if (chunk.usageMetadata) {
|
|
159
|
+
output.usage = {
|
|
160
|
+
input: (chunk.usageMetadata.promptTokenCount || 0) - (chunk.usageMetadata.cachedContentTokenCount || 0),
|
|
161
|
+
output: (chunk.usageMetadata.candidatesTokenCount || 0) + (chunk.usageMetadata.thoughtsTokenCount || 0),
|
|
162
|
+
cacheRead: chunk.usageMetadata.cachedContentTokenCount || 0,
|
|
163
|
+
cacheWrite: 0,
|
|
164
|
+
totalTokens: chunk.usageMetadata.totalTokenCount || 0,
|
|
165
|
+
cost: {
|
|
166
|
+
input: 0,
|
|
167
|
+
output: 0,
|
|
168
|
+
cacheRead: 0,
|
|
169
|
+
cacheWrite: 0,
|
|
170
|
+
total: 0
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
calculateCost(model, output.usage);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (currentBlock) if (currentBlock.type === "text") stream.push({
|
|
177
|
+
type: "text_end",
|
|
178
|
+
contentIndex: blockIndex(),
|
|
179
|
+
content: currentBlock.text,
|
|
180
|
+
partial: output
|
|
181
|
+
});
|
|
182
|
+
else stream.push({
|
|
183
|
+
type: "thinking_end",
|
|
184
|
+
contentIndex: blockIndex(),
|
|
185
|
+
content: currentBlock.thinking,
|
|
186
|
+
partial: output
|
|
187
|
+
});
|
|
188
|
+
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
189
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
190
|
+
stream.push({
|
|
191
|
+
type: "done",
|
|
192
|
+
reason: output.stopReason,
|
|
193
|
+
message: output
|
|
194
|
+
});
|
|
195
|
+
stream.end();
|
|
196
|
+
} catch (error) {
|
|
197
|
+
for (const block of output.content) if ("index" in block) delete block.index;
|
|
198
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
199
|
+
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
200
|
+
stream.push({
|
|
201
|
+
type: "error",
|
|
202
|
+
reason: output.stopReason,
|
|
203
|
+
error: output
|
|
204
|
+
});
|
|
205
|
+
stream.end();
|
|
206
|
+
}
|
|
207
|
+
})();
|
|
208
|
+
return stream;
|
|
209
|
+
};
|
|
210
|
+
const streamSimpleGoogle = (model, context, options) => {
|
|
211
|
+
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
212
|
+
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
213
|
+
const base = buildBaseOptions(model, options, apiKey);
|
|
214
|
+
if (!options?.reasoning) return streamGoogle(model, context, {
|
|
215
|
+
...base,
|
|
216
|
+
thinking: { enabled: false }
|
|
217
|
+
});
|
|
218
|
+
const effort = clampReasoning(options.reasoning);
|
|
219
|
+
const googleModel = model;
|
|
220
|
+
if (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) return streamGoogle(model, context, {
|
|
221
|
+
...base,
|
|
222
|
+
thinking: {
|
|
223
|
+
enabled: true,
|
|
224
|
+
level: getThinkingLevel(effort, googleModel)
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return streamGoogle(model, context, {
|
|
228
|
+
...base,
|
|
229
|
+
thinking: {
|
|
230
|
+
enabled: true,
|
|
231
|
+
budgetTokens: getGoogleBudget(googleModel, effort, options.thinkingBudgets)
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
function createClient(model, apiKey, optionsHeaders) {
|
|
236
|
+
const httpOptions = {};
|
|
237
|
+
if (model.baseUrl) {
|
|
238
|
+
httpOptions.baseUrl = model.baseUrl;
|
|
239
|
+
httpOptions.apiVersion = "";
|
|
240
|
+
}
|
|
241
|
+
if (model.headers || optionsHeaders) httpOptions.headers = {
|
|
242
|
+
...model.headers,
|
|
243
|
+
...optionsHeaders
|
|
244
|
+
};
|
|
245
|
+
return new GoogleGenAI({
|
|
246
|
+
apiKey,
|
|
247
|
+
httpOptions: Object.keys(httpOptions).length > 0 ? httpOptions : void 0
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function buildParams(model, context, options = {}) {
|
|
251
|
+
const contents = convertMessages(model, context);
|
|
252
|
+
const generationConfig = {};
|
|
253
|
+
if (options.temperature !== void 0) generationConfig.temperature = options.temperature;
|
|
254
|
+
if (options.maxTokens !== void 0) generationConfig.maxOutputTokens = options.maxTokens;
|
|
255
|
+
const config = {
|
|
256
|
+
...Object.keys(generationConfig).length > 0 && generationConfig,
|
|
257
|
+
...context.systemPrompt && { systemInstruction: sanitizeSurrogates(context.systemPrompt) },
|
|
258
|
+
...context.tools && context.tools.length > 0 && { tools: convertTools(context.tools) }
|
|
259
|
+
};
|
|
260
|
+
if (context.tools && context.tools.length > 0 && options.toolChoice) config.toolConfig = { functionCallingConfig: { mode: mapToolChoice(options.toolChoice) } };
|
|
261
|
+
else config.toolConfig = void 0;
|
|
262
|
+
if (options.thinking?.enabled && model.reasoning) {
|
|
263
|
+
const thinkingConfig = { includeThoughts: true };
|
|
264
|
+
if (options.thinking.level !== void 0) thinkingConfig.thinkingLevel = options.thinking.level;
|
|
265
|
+
else if (options.thinking.budgetTokens !== void 0) thinkingConfig.thinkingBudget = options.thinking.budgetTokens;
|
|
266
|
+
config.thinkingConfig = thinkingConfig;
|
|
267
|
+
} else if (model.reasoning && options.thinking && !options.thinking.enabled) config.thinkingConfig = getDisabledThinkingConfig(model);
|
|
268
|
+
if (options.signal) {
|
|
269
|
+
if (options.signal.aborted) throw new Error("Request aborted");
|
|
270
|
+
config.abortSignal = options.signal;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
model: model.id,
|
|
274
|
+
contents,
|
|
275
|
+
config
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function isGemma4Model(model) {
|
|
279
|
+
return /gemma-?4/.test(model.id.toLowerCase());
|
|
280
|
+
}
|
|
281
|
+
function isGemini3ProModel(model) {
|
|
282
|
+
return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
|
|
283
|
+
}
|
|
284
|
+
function isGemini3FlashModel(model) {
|
|
285
|
+
return /gemini-3(?:\.\d+)?-flash/.test(model.id.toLowerCase());
|
|
286
|
+
}
|
|
287
|
+
function getDisabledThinkingConfig(model) {
|
|
288
|
+
if (isGemini3ProModel(model)) return { thinkingLevel: "LOW" };
|
|
289
|
+
if (isGemini3FlashModel(model)) return { thinkingLevel: "MINIMAL" };
|
|
290
|
+
if (isGemma4Model(model)) return { thinkingLevel: "MINIMAL" };
|
|
291
|
+
return { thinkingBudget: 0 };
|
|
292
|
+
}
|
|
293
|
+
function getThinkingLevel(effort, model) {
|
|
294
|
+
if (isGemini3ProModel(model)) switch (effort) {
|
|
295
|
+
case "minimal":
|
|
296
|
+
case "low": return "LOW";
|
|
297
|
+
case "medium":
|
|
298
|
+
case "high": return "HIGH";
|
|
299
|
+
}
|
|
300
|
+
if (isGemma4Model(model)) switch (effort) {
|
|
301
|
+
case "minimal":
|
|
302
|
+
case "low": return "MINIMAL";
|
|
303
|
+
case "medium":
|
|
304
|
+
case "high": return "HIGH";
|
|
305
|
+
}
|
|
306
|
+
switch (effort) {
|
|
307
|
+
case "minimal": return "MINIMAL";
|
|
308
|
+
case "low": return "LOW";
|
|
309
|
+
case "medium": return "MEDIUM";
|
|
310
|
+
case "high": return "HIGH";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function getGoogleBudget(model, effort, customBudgets) {
|
|
314
|
+
if (customBudgets?.[effort] !== void 0) return customBudgets[effort];
|
|
315
|
+
if (model.id.includes("2.5-pro")) return {
|
|
316
|
+
minimal: 128,
|
|
317
|
+
low: 2048,
|
|
318
|
+
medium: 8192,
|
|
319
|
+
high: 32768
|
|
320
|
+
}[effort];
|
|
321
|
+
if (model.id.includes("2.5-flash-lite")) return {
|
|
322
|
+
minimal: 512,
|
|
323
|
+
low: 2048,
|
|
324
|
+
medium: 8192,
|
|
325
|
+
high: 24576
|
|
326
|
+
}[effort];
|
|
327
|
+
if (model.id.includes("2.5-flash")) return {
|
|
328
|
+
minimal: 128,
|
|
329
|
+
low: 2048,
|
|
330
|
+
medium: 8192,
|
|
331
|
+
high: 24576
|
|
332
|
+
}[effort];
|
|
333
|
+
return -1;
|
|
334
|
+
}
|
|
335
|
+
//#endregion
|
|
336
|
+
export { streamGoogle, streamSimpleGoogle };
|