@browser-ai/core 2.1.11 → 2.1.12
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/index.js +59 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -131,11 +131,35 @@ ${payloads.join("\n")}
|
|
|
131
131
|
var DEFAULT_OPTIONS = {
|
|
132
132
|
supportXmlTags: true,
|
|
133
133
|
supportPythonStyle: true,
|
|
134
|
-
supportParametersField: true
|
|
134
|
+
supportParametersField: true,
|
|
135
|
+
supportCallColonStyle: true
|
|
135
136
|
};
|
|
136
137
|
function generateToolCallId() {
|
|
137
138
|
return `call_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
|
|
138
139
|
}
|
|
140
|
+
function parseCallColonParams(params) {
|
|
141
|
+
const args = {};
|
|
142
|
+
if (!params || !params.trim()) return args;
|
|
143
|
+
const pairs = params.split(",").map((s) => s.trim());
|
|
144
|
+
for (const pair of pairs) {
|
|
145
|
+
const colonIndex = pair.indexOf(":");
|
|
146
|
+
if (colonIndex > 0) {
|
|
147
|
+
const key = pair.substring(0, colonIndex).trim();
|
|
148
|
+
const rawValue = pair.substring(colonIndex + 1).trim();
|
|
149
|
+
if (rawValue === "true") {
|
|
150
|
+
args[key] = true;
|
|
151
|
+
} else if (rawValue === "false") {
|
|
152
|
+
args[key] = false;
|
|
153
|
+
} else if (rawValue === "null") {
|
|
154
|
+
args[key] = null;
|
|
155
|
+
} else {
|
|
156
|
+
const numValue = Number(rawValue);
|
|
157
|
+
args[key] = !isNaN(numValue) && rawValue !== "" ? numValue : rawValue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return args;
|
|
162
|
+
}
|
|
139
163
|
function buildRegex(options) {
|
|
140
164
|
const patterns = [];
|
|
141
165
|
patterns.push("```tool[_-]?call\\s*([\\s\\S]*?)```");
|
|
@@ -145,6 +169,9 @@ function buildRegex(options) {
|
|
|
145
169
|
if (options.supportPythonStyle) {
|
|
146
170
|
patterns.push("\\[(\\w+)\\(([^)]*)\\)\\]");
|
|
147
171
|
}
|
|
172
|
+
if (options.supportCallColonStyle) {
|
|
173
|
+
patterns.push("<\\|tool_call>\\s*([\\s\\S]*?)\\s*<tool_call\\|>");
|
|
174
|
+
}
|
|
148
175
|
return new RegExp(patterns.join("|"), "gi");
|
|
149
176
|
}
|
|
150
177
|
function parseJsonFunctionCalls(response, options = DEFAULT_OPTIONS) {
|
|
@@ -189,7 +216,20 @@ function parseJsonFunctionCalls(response, options = DEFAULT_OPTIONS) {
|
|
|
189
216
|
continue;
|
|
190
217
|
}
|
|
191
218
|
}
|
|
192
|
-
|
|
219
|
+
if (mergedOptions.supportCallColonStyle) {
|
|
220
|
+
const callMatch = fullMatch.match(/call:(\w+)\{([^}]*)\}/);
|
|
221
|
+
if (callMatch) {
|
|
222
|
+
const [, funcName, params] = callMatch;
|
|
223
|
+
toolCalls.push({
|
|
224
|
+
type: "tool-call",
|
|
225
|
+
toolCallId: generateToolCallId(),
|
|
226
|
+
toolName: funcName,
|
|
227
|
+
args: parseCallColonParams(params)
|
|
228
|
+
});
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const innerContent = match.slice(1).find((g) => g !== void 0) || "";
|
|
193
233
|
const trimmed = innerContent.trim();
|
|
194
234
|
if (!trimmed) continue;
|
|
195
235
|
try {
|
|
@@ -255,6 +295,11 @@ var EXTENDED_FENCE_PATTERNS = [
|
|
|
255
295
|
start: "<tool_call>",
|
|
256
296
|
end: "</tool_call>",
|
|
257
297
|
reconstructStart: "<tool_call>"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
start: "<|tool_call>",
|
|
301
|
+
end: "<tool_call|>",
|
|
302
|
+
reconstructStart: "<|tool_call>"
|
|
258
303
|
}
|
|
259
304
|
];
|
|
260
305
|
var ToolCallFenceDetector = class {
|
|
@@ -490,6 +535,10 @@ function extractToolName(content) {
|
|
|
490
535
|
if (jsonMatch) {
|
|
491
536
|
return jsonMatch[1];
|
|
492
537
|
}
|
|
538
|
+
const callColonMatch = content.match(/call:(\w+)\{/);
|
|
539
|
+
if (callColonMatch) {
|
|
540
|
+
return callColonMatch[1];
|
|
541
|
+
}
|
|
493
542
|
return null;
|
|
494
543
|
}
|
|
495
544
|
var ARGUMENTS_FIELD_REGEX = /"arguments"\s*:\s*/g;
|
|
@@ -1339,17 +1388,19 @@ var BrowserAIChatLanguageModel = class {
|
|
|
1339
1388
|
if (responseFormat?.type === "json") {
|
|
1340
1389
|
promptOptions.responseConstraint = responseFormat.schema;
|
|
1341
1390
|
}
|
|
1391
|
+
const sessionOptions = {};
|
|
1342
1392
|
if (temperature !== void 0) {
|
|
1343
|
-
|
|
1393
|
+
sessionOptions.temperature = temperature;
|
|
1344
1394
|
}
|
|
1345
1395
|
if (topK !== void 0) {
|
|
1346
|
-
|
|
1396
|
+
sessionOptions.topK = topK;
|
|
1347
1397
|
}
|
|
1348
1398
|
return {
|
|
1349
1399
|
systemMessage,
|
|
1350
1400
|
messages,
|
|
1351
1401
|
warnings,
|
|
1352
1402
|
promptOptions,
|
|
1403
|
+
sessionOptions,
|
|
1353
1404
|
hasMultiModalInput,
|
|
1354
1405
|
expectedInputs,
|
|
1355
1406
|
functionTools
|
|
@@ -1369,6 +1420,7 @@ var BrowserAIChatLanguageModel = class {
|
|
|
1369
1420
|
messages,
|
|
1370
1421
|
warnings,
|
|
1371
1422
|
promptOptions,
|
|
1423
|
+
sessionOptions,
|
|
1372
1424
|
expectedInputs,
|
|
1373
1425
|
functionTools
|
|
1374
1426
|
} = converted;
|
|
@@ -1380,7 +1432,7 @@ var BrowserAIChatLanguageModel = class {
|
|
|
1380
1432
|
}
|
|
1381
1433
|
);
|
|
1382
1434
|
const session = await this.getSession(
|
|
1383
|
-
{ signal: options.abortSignal },
|
|
1435
|
+
{ ...sessionOptions, signal: options.abortSignal },
|
|
1384
1436
|
expectedInputs,
|
|
1385
1437
|
systemPrompt || void 0
|
|
1386
1438
|
);
|
|
@@ -1520,6 +1572,7 @@ var BrowserAIChatLanguageModel = class {
|
|
|
1520
1572
|
messages,
|
|
1521
1573
|
warnings,
|
|
1522
1574
|
promptOptions,
|
|
1575
|
+
sessionOptions,
|
|
1523
1576
|
expectedInputs,
|
|
1524
1577
|
functionTools
|
|
1525
1578
|
} = converted;
|
|
@@ -1531,7 +1584,7 @@ var BrowserAIChatLanguageModel = class {
|
|
|
1531
1584
|
}
|
|
1532
1585
|
);
|
|
1533
1586
|
const session = await this.getSession(
|
|
1534
|
-
{ signal: options.abortSignal },
|
|
1587
|
+
{ ...sessionOptions, signal: options.abortSignal },
|
|
1535
1588
|
expectedInputs,
|
|
1536
1589
|
systemPrompt || void 0
|
|
1537
1590
|
);
|