Vendored
+24
-3
@@ -10,6 +10,7 @@ const device = require('./device.js');
|
||||
const events = require('./events.js');
|
||||
const paths = require('./paths.js');
|
||||
const completeWatch = require('./complete-watch.js');
|
||||
const toolParse = require('./tool-parse.js');
|
||||
|
||||
let sdk = null;
|
||||
let initError = null;
|
||||
@@ -154,11 +155,22 @@ function toTools(tools) {
|
||||
return {
|
||||
type: 'function',
|
||||
name: t.function.name,
|
||||
description: t.function.description,
|
||||
parameters: t.function.parameters,
|
||||
description: t.function.description || t.function.name,
|
||||
parameters: t.function.parameters && t.function.parameters.type === 'object'
|
||||
? t.function.parameters
|
||||
: { type: 'object', properties: {} },
|
||||
};
|
||||
}
|
||||
return t;
|
||||
if (!t || !t.name) return t;
|
||||
const parameters = t.parameters && t.parameters.type === 'object'
|
||||
? t.parameters
|
||||
: { type: 'object', properties: (t.parameters && t.parameters.properties) || {} };
|
||||
return {
|
||||
type: 'function',
|
||||
name: t.name,
|
||||
description: t.description || t.name,
|
||||
parameters,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -455,6 +467,15 @@ async function complete(opts, onEvent) {
|
||||
if (run.stats) stats = await run.stats;
|
||||
} catch (_) {}
|
||||
}
|
||||
if (tools && tools.length) {
|
||||
const recovered = toolParse.recover({ text, thinking, tools, existing: toolCalls });
|
||||
if (!toolCalls.length && recovered.calls.length) {
|
||||
for (const call of recovered.calls) toolCalls.push(call);
|
||||
}
|
||||
text = recovered.text;
|
||||
} else {
|
||||
text = toolParse.stripToolMarkup(text);
|
||||
}
|
||||
return {
|
||||
text,
|
||||
thinking,
|
||||
|
||||
Reference in New Issue
Block a user