thebird 1.2.100 → 1.2.102
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/.gm/lastskill +1 -0
- package/CLAUDE.md +25 -8
- package/README.md +21 -233
- package/index.js +1 -104
- package/package.json +2 -3
- package/server.js +1 -1
- package/examples/basic-chat.js +0 -34
- package/examples/multi-turn.js +0 -45
- package/examples/sdk-validate.js +0 -31
- package/examples/streaming.js +0 -81
- package/examples/tool-use.js +0 -77
- package/examples/vision.js +0 -84
- package/index.d.ts +0 -126
- package/lib/capabilities.js +0 -50
- package/lib/circuit-breaker.js +0 -36
- package/lib/client.js +0 -10
- package/lib/cloud-generate.js +0 -119
- package/lib/config.js +0 -24
- package/lib/convert.js +0 -87
- package/lib/errors.js +0 -140
- package/lib/oauth.js +0 -133
- package/lib/providers/acp.js +0 -88
- package/lib/providers/openai.js +0 -134
- package/lib/router-stream.js +0 -95
- package/lib/router.js +0 -51
- package/lib/stream-guard.js +0 -35
- package/lib/transformers.js +0 -93
- package/thebird-browser-entry-esm.js +0 -4
- package/thebird-browser-entry.js +0 -196
package/lib/router.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const { loadConfig } = require('./config');
|
|
2
|
-
|
|
3
|
-
const SUBAGENT_RE = /<CCR-SUBAGENT-MODEL>([^<]+)<\/CCR-SUBAGENT-MODEL>/;
|
|
4
|
-
|
|
5
|
-
function estimateTokens(messages, system) {
|
|
6
|
-
let chars = typeof system === 'string' ? system.length : (system ? JSON.stringify(system).length : 0);
|
|
7
|
-
for (const m of (messages || [])) {
|
|
8
|
-
chars += typeof m.content === 'string' ? m.content.length : JSON.stringify(m.content || '').length;
|
|
9
|
-
}
|
|
10
|
-
return Math.ceil(chars / 4);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function extractSubagentModel(messages) {
|
|
14
|
-
const first = messages?.[0];
|
|
15
|
-
if (!first) return null;
|
|
16
|
-
const text = typeof first.content === 'string' ? first.content :
|
|
17
|
-
(Array.isArray(first.content) ? first.content.map(b => b.text || '').join('') : '');
|
|
18
|
-
const m = SUBAGENT_RE.exec(text);
|
|
19
|
-
return m ? m[1].trim() : null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function parseProviderModel(str) {
|
|
23
|
-
const idx = str.indexOf(',');
|
|
24
|
-
if (idx === -1) return { providerName: null, modelName: str };
|
|
25
|
-
return { providerName: str.slice(0, idx), modelName: str.slice(idx + 1) };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function route(params, routerCfg, customRouterFn) {
|
|
29
|
-
const { messages, system, taskType } = params;
|
|
30
|
-
|
|
31
|
-
if (customRouterFn) {
|
|
32
|
-
const custom = await customRouterFn(params, routerCfg);
|
|
33
|
-
if (custom) return parseProviderModel(custom);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const subagent = extractSubagentModel(messages);
|
|
37
|
-
if (subagent) return parseProviderModel(subagent);
|
|
38
|
-
|
|
39
|
-
if (taskType === 'background' && routerCfg.background) return parseProviderModel(routerCfg.background);
|
|
40
|
-
if (taskType === 'think' && routerCfg.think) return parseProviderModel(routerCfg.think);
|
|
41
|
-
if (taskType === 'webSearch' && routerCfg.webSearch) return parseProviderModel(routerCfg.webSearch);
|
|
42
|
-
if (taskType === 'image' && routerCfg.image) return parseProviderModel(routerCfg.image);
|
|
43
|
-
|
|
44
|
-
const threshold = routerCfg.longContextThreshold || 60000;
|
|
45
|
-
if (routerCfg.longContext && estimateTokens(messages, system) > threshold) return parseProviderModel(routerCfg.longContext);
|
|
46
|
-
|
|
47
|
-
if (routerCfg.default) return parseProviderModel(routerCfg.default);
|
|
48
|
-
return { providerName: null, modelName: null };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = { route, estimateTokens, parseProviderModel };
|
package/lib/stream-guard.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const { TimeoutError, BridgeError } = require('./errors');
|
|
2
|
-
|
|
3
|
-
async function* guardStream(iterable, opts = {}) {
|
|
4
|
-
const timeoutMs = opts?.chunkTimeoutMs ?? 30000;
|
|
5
|
-
const maxRepeats = opts?.maxRepeats ?? 100;
|
|
6
|
-
let lastChunk = null;
|
|
7
|
-
let repeatCount = 0;
|
|
8
|
-
for await (const chunk of raceTimeout(iterable, timeoutMs)) {
|
|
9
|
-
const key = JSON.stringify(chunk);
|
|
10
|
-
if (key === lastChunk && key !== '{}' && key !== 'null') {
|
|
11
|
-
repeatCount++;
|
|
12
|
-
if (repeatCount >= maxRepeats) {
|
|
13
|
-
throw new BridgeError(`Same chunk repeated ${maxRepeats} times`, { retryable: false });
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
lastChunk = key;
|
|
17
|
-
repeatCount = 1;
|
|
18
|
-
}
|
|
19
|
-
yield chunk;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function* raceTimeout(iterable, ms) {
|
|
24
|
-
const iter = iterable[Symbol.asyncIterator]();
|
|
25
|
-
while (true) {
|
|
26
|
-
const result = await Promise.race([
|
|
27
|
-
iter.next(),
|
|
28
|
-
new Promise((_, reject) => setTimeout(() => reject(new TimeoutError(`Stream chunk timeout after ${ms}ms`)), ms))
|
|
29
|
-
]);
|
|
30
|
-
if (result.done) return;
|
|
31
|
-
yield result.value;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = { guardStream };
|
package/lib/transformers.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
function removeCacheControl(obj) {
|
|
2
|
-
if (!obj || typeof obj !== 'object') return obj;
|
|
3
|
-
if (Array.isArray(obj)) return obj.map(removeCacheControl);
|
|
4
|
-
const out = {};
|
|
5
|
-
for (const [k, v] of Object.entries(obj)) {
|
|
6
|
-
if (k === 'cache_control') continue;
|
|
7
|
-
out[k] = removeCacheControl(v);
|
|
8
|
-
}
|
|
9
|
-
return out;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const BUILT_IN = {
|
|
13
|
-
cleancache: {
|
|
14
|
-
request(req) { return { ...req, messages: removeCacheControl(req.messages), system: removeCacheControl(req.system) }; }
|
|
15
|
-
},
|
|
16
|
-
deepseek: {
|
|
17
|
-
request(req) {
|
|
18
|
-
const r = removeCacheControl(req);
|
|
19
|
-
if (r.system && typeof r.system !== 'string') {
|
|
20
|
-
r.system = (Array.isArray(r.system) ? r.system : [r.system]).map(b => b.text || '').join('\n');
|
|
21
|
-
}
|
|
22
|
-
return r;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
openrouter: {
|
|
26
|
-
options: {},
|
|
27
|
-
request(req, opts) {
|
|
28
|
-
const headers = { 'HTTP-Referer': 'https://github.com/AnEntrypoint/thebird', 'X-Title': 'thebird', ...(opts || {}).headers };
|
|
29
|
-
if ((opts || {}).provider) req = { ...req, provider: (opts || {}).provider };
|
|
30
|
-
return { ...req, _extraHeaders: { ...(req._extraHeaders || {}), ...headers } };
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
maxtoken: {
|
|
34
|
-
request(req, opts) { return { ...req, max_tokens: (opts || {}).max_tokens || req.max_tokens }; }
|
|
35
|
-
},
|
|
36
|
-
tooluse: {
|
|
37
|
-
request(req) {
|
|
38
|
-
if (req.tools && req.tools.length > 0) return { ...req, tool_choice: { type: 'required' } };
|
|
39
|
-
return req;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
reasoning: {
|
|
43
|
-
request(req) { return req; },
|
|
44
|
-
response(res) {
|
|
45
|
-
if (!res.choices) return res;
|
|
46
|
-
return {
|
|
47
|
-
...res,
|
|
48
|
-
choices: res.choices.map(c => {
|
|
49
|
-
if (!c.message) return c;
|
|
50
|
-
const msg = { ...c.message };
|
|
51
|
-
if (msg.reasoning_content) { msg._reasoning = msg.reasoning_content; delete msg.reasoning_content; }
|
|
52
|
-
return { ...c, message: msg };
|
|
53
|
-
})
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
sampling: {
|
|
58
|
-
request(req) {
|
|
59
|
-
const r = { ...req };
|
|
60
|
-
delete r.top_k;
|
|
61
|
-
delete r.repetition_penalty;
|
|
62
|
-
return r;
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
groq: {
|
|
66
|
-
request(req) {
|
|
67
|
-
const r = { ...req };
|
|
68
|
-
delete r.top_k;
|
|
69
|
-
return r;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
function resolveTransformers(useList, customMap) {
|
|
75
|
-
if (!useList) return [];
|
|
76
|
-
return useList.map(entry => {
|
|
77
|
-
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
78
|
-
const opts = Array.isArray(entry) ? entry[1] : undefined;
|
|
79
|
-
const t = (customMap && customMap[name]) || BUILT_IN[name];
|
|
80
|
-
if (!t) { console.warn('[thebird] unknown transformer:', name); return null; }
|
|
81
|
-
return { transformer: t, opts };
|
|
82
|
-
}).filter(Boolean);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function applyRequestTransformers(req, transformers) {
|
|
86
|
-
return transformers.reduce((r, { transformer, opts }) => transformer.request ? transformer.request(r, opts) : r, req);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function applyResponseTransformers(res, transformers) {
|
|
90
|
-
return transformers.reduce((r, { transformer, opts }) => transformer.response ? transformer.response(r, opts) : r, res);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
module.exports = { resolveTransformers, applyRequestTransformers, applyResponseTransformers, BUILT_IN };
|
package/thebird-browser-entry.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
const { getClient } = require('./lib/client.js');
|
|
2
|
-
const { GeminiError, withRetry } = require('./lib/errors.js');
|
|
3
|
-
const { convertMessages, convertTools, cleanSchema, extractModelId, buildConfig } = require('./lib/convert.js');
|
|
4
|
-
|
|
5
|
-
function streamGemini({ model, system, messages, tools, onStepFinish, apiKey, temperature, maxOutputTokens, topP, topK, safetySettings, responseModalities }) {
|
|
6
|
-
return { fullStream: createFullStream({ model, system, messages, tools, onStepFinish, apiKey, temperature, maxOutputTokens, topP, topK, safetySettings, responseModalities }), warnings: Promise.resolve([]) };
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async function* createFullStream({ model, system, messages, tools, onStepFinish, apiKey, temperature, maxOutputTokens, topP, topK, safetySettings, responseModalities }) {
|
|
10
|
-
const client = getClient(apiKey);
|
|
11
|
-
const modelId = extractModelId(model);
|
|
12
|
-
let contents = convertMessages(messages);
|
|
13
|
-
const { config } = buildConfig({ system, tools, temperature, maxOutputTokens, topP, topK, safetySettings, responseModalities });
|
|
14
|
-
while (true) {
|
|
15
|
-
yield { type: 'start-step' };
|
|
16
|
-
try {
|
|
17
|
-
const stream = await withRetry(() => client.models.generateContentStream({ model: modelId, contents, config }));
|
|
18
|
-
const allParts = [];
|
|
19
|
-
for await (const chunk of stream) {
|
|
20
|
-
for (const candidate of (chunk.candidates || [])) {
|
|
21
|
-
for (const part of (candidate.content?.parts || [])) {
|
|
22
|
-
allParts.push(part);
|
|
23
|
-
if (part.text && !part.thought) yield { type: 'text-delta', textDelta: part.text };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const fcParts = allParts.filter(p => p.functionCall);
|
|
28
|
-
if (fcParts.length === 0) {
|
|
29
|
-
yield { type: 'finish-step', finishReason: 'stop' };
|
|
30
|
-
if (onStepFinish) await onStepFinish();
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const toolResultParts = [];
|
|
34
|
-
for (const part of fcParts) {
|
|
35
|
-
const name = part.functionCall.name;
|
|
36
|
-
const args = part.functionCall.args || {};
|
|
37
|
-
const toolId = 'toolu_' + Math.random().toString(36).slice(2, 10);
|
|
38
|
-
yield { type: 'tool-call', toolCallId: toolId, toolName: name, args };
|
|
39
|
-
const toolDef = tools?.[name];
|
|
40
|
-
let result = toolDef ? null : { error: true, message: 'Tool not found: ' + name };
|
|
41
|
-
if (toolDef?.execute) {
|
|
42
|
-
try { result = await toolDef.execute(args, { toolCallId: toolId }); }
|
|
43
|
-
catch (e) { result = { error: true, message: e.message }; }
|
|
44
|
-
}
|
|
45
|
-
yield { type: 'tool-result', toolCallId: toolId, toolName: name, args, result };
|
|
46
|
-
toolResultParts.push({ functionResponse: { name, response: typeof result === 'string' ? { output: result } : (result || {}) } });
|
|
47
|
-
}
|
|
48
|
-
yield { type: 'finish-step', finishReason: 'tool-calls' };
|
|
49
|
-
if (onStepFinish) await onStepFinish();
|
|
50
|
-
contents.push({ role: 'model', parts: allParts });
|
|
51
|
-
contents.push({ role: 'user', parts: toolResultParts });
|
|
52
|
-
} catch (err) {
|
|
53
|
-
yield { type: 'error', error: err };
|
|
54
|
-
yield { type: 'finish-step', finishReason: 'error' };
|
|
55
|
-
if (onStepFinish) await onStepFinish();
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function generateGemini({ model, system, messages, tools, apiKey, temperature, maxOutputTokens, topP, topK, safetySettings, responseModalities }) {
|
|
62
|
-
const client = getClient(apiKey);
|
|
63
|
-
const modelId = extractModelId(model);
|
|
64
|
-
let contents = convertMessages(messages);
|
|
65
|
-
const { config } = buildConfig({ system, tools, temperature, maxOutputTokens, topP, topK, safetySettings, responseModalities });
|
|
66
|
-
while (true) {
|
|
67
|
-
const response = await withRetry(() => client.models.generateContent({ model: modelId, contents, config }));
|
|
68
|
-
const candidate = response.candidates?.[0];
|
|
69
|
-
if (!candidate) throw new GeminiError('No candidates returned', { retryable: false });
|
|
70
|
-
const allParts = candidate.content?.parts || [];
|
|
71
|
-
const fcParts = allParts.filter(p => p.functionCall);
|
|
72
|
-
if (fcParts.length === 0) {
|
|
73
|
-
const text = allParts.filter(p => p.text && !p.thought).map(p => p.text).join('');
|
|
74
|
-
return { text, parts: allParts, response };
|
|
75
|
-
}
|
|
76
|
-
const toolResultParts = [];
|
|
77
|
-
for (const part of fcParts) {
|
|
78
|
-
const name = part.functionCall.name;
|
|
79
|
-
const args = part.functionCall.args || {};
|
|
80
|
-
const toolDef = tools?.[name];
|
|
81
|
-
let result = toolDef ? null : { error: true, message: 'Tool not found: ' + name };
|
|
82
|
-
if (toolDef?.execute) {
|
|
83
|
-
try { result = await toolDef.execute(args); }
|
|
84
|
-
catch (e) { result = { error: true, message: e.message }; }
|
|
85
|
-
}
|
|
86
|
-
toolResultParts.push({ functionResponse: { name, response: typeof result === 'string' ? { output: result } : (result || {}) } });
|
|
87
|
-
}
|
|
88
|
-
contents.push({ role: 'model', parts: allParts });
|
|
89
|
-
contents.push({ role: 'user', parts: toolResultParts });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function convertMessagesOAI(messages, system) {
|
|
94
|
-
const result = [];
|
|
95
|
-
if (system) result.push({ role: 'system', content: typeof system === 'string' ? system : JSON.stringify(system) });
|
|
96
|
-
for (const m of messages) {
|
|
97
|
-
if (typeof m.content === 'string') { result.push({ role: m.role, content: m.content }); continue; }
|
|
98
|
-
if (!Array.isArray(m.content)) continue;
|
|
99
|
-
const toolCalls = m.content.filter(b => b.type === 'tool_use');
|
|
100
|
-
const toolResults = m.content.filter(b => b.type === 'tool_result');
|
|
101
|
-
if (toolResults.length) {
|
|
102
|
-
for (const b of toolResults) {
|
|
103
|
-
const c = typeof b.content === 'string' ? b.content : JSON.stringify(b.content || '');
|
|
104
|
-
result.push({ role: 'tool', tool_call_id: b.tool_use_id || b.id || b.name, content: c });
|
|
105
|
-
}
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const textParts = m.content.filter(b => b.type === 'text').map(b => b.text).join('');
|
|
109
|
-
if (toolCalls.length) {
|
|
110
|
-
result.push({ role: 'assistant', content: textParts || null,
|
|
111
|
-
tool_calls: toolCalls.map(b => ({ id: b.id || ('call_' + Math.random().toString(36).slice(2,8)), type: 'function',
|
|
112
|
-
function: { name: b.name, arguments: JSON.stringify(b.input || {}) } })) });
|
|
113
|
-
} else {
|
|
114
|
-
result.push({ role: m.role, content: textParts });
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function convertToolsOAI(tools) {
|
|
121
|
-
if (!tools || typeof tools !== 'object') return undefined;
|
|
122
|
-
const list = Object.entries(tools).map(([name, t]) => ({
|
|
123
|
-
type: 'function', function: { name, description: t.description || '',
|
|
124
|
-
parameters: t.parameters?.jsonSchema || t.parameters || { type: 'object' } }
|
|
125
|
-
}));
|
|
126
|
-
return list.length ? list : undefined;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function* streamOpenAI({ url, apiKey, messages, system, model, tools, maxOutputTokens, temperature, onStepFinish }) {
|
|
130
|
-
const oaiMsgs = convertMessagesOAI(messages, system);
|
|
131
|
-
const oaiTools = convertToolsOAI(tools);
|
|
132
|
-
let body = { messages: oaiMsgs, model, max_tokens: maxOutputTokens || 8192, temperature: temperature ?? 0.5 };
|
|
133
|
-
if (oaiTools) body.tools = oaiTools;
|
|
134
|
-
while (true) {
|
|
135
|
-
yield { type: 'start-step' };
|
|
136
|
-
const res = await fetch(url, { method: 'POST',
|
|
137
|
-
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiKey}` },
|
|
138
|
-
body: JSON.stringify({ ...body, stream: true }) });
|
|
139
|
-
if (!res.ok) { const t = await res.text(); throw new Error(t); }
|
|
140
|
-
const reader = res.body.getReader();
|
|
141
|
-
const dec = new TextDecoder();
|
|
142
|
-
let buf = '', toolCallsMap = {};
|
|
143
|
-
try {
|
|
144
|
-
while (true) {
|
|
145
|
-
const { done, value } = await reader.read();
|
|
146
|
-
if (done) break;
|
|
147
|
-
buf += dec.decode(value, { stream: true });
|
|
148
|
-
const lines = buf.split('\n');
|
|
149
|
-
buf = lines.pop();
|
|
150
|
-
for (const line of lines) {
|
|
151
|
-
if (!line.startsWith('data: ')) continue;
|
|
152
|
-
const d = line.slice(6).trim();
|
|
153
|
-
if (d === '[DONE]') break;
|
|
154
|
-
let chunk; try { chunk = JSON.parse(d); } catch { continue; }
|
|
155
|
-
const delta = chunk.choices?.[0]?.delta;
|
|
156
|
-
if (!delta) continue;
|
|
157
|
-
if (delta.content) yield { type: 'text-delta', textDelta: delta.content };
|
|
158
|
-
if (delta.tool_calls) {
|
|
159
|
-
for (const tc of delta.tool_calls) {
|
|
160
|
-
const idx = tc.index ?? 0;
|
|
161
|
-
if (!toolCallsMap[idx]) toolCallsMap[idx] = { id: tc.id || '', name: '', args: '' };
|
|
162
|
-
if (tc.id) toolCallsMap[idx].id = tc.id;
|
|
163
|
-
if (tc.function?.name) toolCallsMap[idx].name += tc.function.name;
|
|
164
|
-
if (tc.function?.arguments) toolCallsMap[idx].args += tc.function.arguments;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
} finally { reader.releaseLock(); }
|
|
170
|
-
const pending = Object.values(toolCallsMap);
|
|
171
|
-
if (!pending.length) {
|
|
172
|
-
yield { type: 'finish-step', finishReason: 'stop' };
|
|
173
|
-
if (onStepFinish) await onStepFinish();
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
const toolResultMsgs = [];
|
|
177
|
-
for (const tc of pending) {
|
|
178
|
-
let args; try { args = JSON.parse(tc.args || '{}'); } catch { args = {}; }
|
|
179
|
-
const toolDef = tools?.[tc.name];
|
|
180
|
-
let result = toolDef ? null : { error: true, message: 'Tool not found: ' + tc.name };
|
|
181
|
-
if (toolDef?.execute) try { result = await toolDef.execute(args, { toolCallId: tc.id }); } catch(e) { result = { error: true, message: e.message }; }
|
|
182
|
-
yield { type: 'tool-call', toolCallId: tc.id, toolName: tc.name, args };
|
|
183
|
-
yield { type: 'tool-result', toolCallId: tc.id, toolName: tc.name, args, result };
|
|
184
|
-
toolResultMsgs.push({ role: 'tool', tool_call_id: tc.id, content: JSON.stringify(result ?? '') });
|
|
185
|
-
}
|
|
186
|
-
yield { type: 'finish-step', finishReason: 'tool-calls' };
|
|
187
|
-
if (onStepFinish) await onStepFinish();
|
|
188
|
-
body = { ...body, messages: [...body.messages,
|
|
189
|
-
{ role: 'assistant', content: null, tool_calls: pending.map(tc => ({ id: tc.id, type: 'function', function: { name: tc.name, arguments: tc.args } })) },
|
|
190
|
-
...toolResultMsgs
|
|
191
|
-
]};
|
|
192
|
-
toolCallsMap = {};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports = { streamGemini, generateGemini, streamOpenAI };
|