p-api-agent 0.0.6 → 0.0.7
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.cjs +19 -3
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -293,7 +293,20 @@ ${tool_schemas}`;
|
|
|
293
293
|
find_first_json_block(content) {
|
|
294
294
|
const fenced = content.match(/```json\s*([\s\S]*?)\s*```/i);
|
|
295
295
|
if (fenced?.[1]) return fenced[1];
|
|
296
|
-
const
|
|
296
|
+
const objectStart = content.indexOf("{");
|
|
297
|
+
const arrayStart = content.indexOf("[");
|
|
298
|
+
let start = -1;
|
|
299
|
+
let openChar = "{";
|
|
300
|
+
let closeChar = "}";
|
|
301
|
+
if (objectStart >= 0 && (arrayStart < 0 || objectStart < arrayStart)) {
|
|
302
|
+
start = objectStart;
|
|
303
|
+
openChar = "{";
|
|
304
|
+
closeChar = "}";
|
|
305
|
+
} else if (arrayStart >= 0) {
|
|
306
|
+
start = arrayStart;
|
|
307
|
+
openChar = "[";
|
|
308
|
+
closeChar = "]";
|
|
309
|
+
}
|
|
297
310
|
if (start < 0) return null;
|
|
298
311
|
let depth = 0;
|
|
299
312
|
let inString = false;
|
|
@@ -318,8 +331,8 @@ ${tool_schemas}`;
|
|
|
318
331
|
inString = true;
|
|
319
332
|
continue;
|
|
320
333
|
}
|
|
321
|
-
if (ch ===
|
|
322
|
-
if (ch ===
|
|
334
|
+
if (ch === openChar) depth++;
|
|
335
|
+
if (ch === closeChar) {
|
|
323
336
|
depth--;
|
|
324
337
|
if (depth === 0) {
|
|
325
338
|
return content.slice(start, i + 1);
|
|
@@ -330,6 +343,9 @@ ${tool_schemas}`;
|
|
|
330
343
|
}
|
|
331
344
|
/** 兼容常见 Function Calling 输出结构并转换为内部指令 */
|
|
332
345
|
adapt_common_tool_call(json) {
|
|
346
|
+
if (Array.isArray(json) && json.length > 0) {
|
|
347
|
+
return this.adapt_common_tool_call(json[0]);
|
|
348
|
+
}
|
|
333
349
|
if (typeof json?.name === "string") {
|
|
334
350
|
const params = this.normalize_params(json.params ?? json.arguments ?? {});
|
|
335
351
|
return {
|
package/dist/index.js
CHANGED
|
@@ -264,7 +264,20 @@ ${tool_schemas}`;
|
|
|
264
264
|
find_first_json_block(content) {
|
|
265
265
|
const fenced = content.match(/```json\s*([\s\S]*?)\s*```/i);
|
|
266
266
|
if (fenced?.[1]) return fenced[1];
|
|
267
|
-
const
|
|
267
|
+
const objectStart = content.indexOf("{");
|
|
268
|
+
const arrayStart = content.indexOf("[");
|
|
269
|
+
let start = -1;
|
|
270
|
+
let openChar = "{";
|
|
271
|
+
let closeChar = "}";
|
|
272
|
+
if (objectStart >= 0 && (arrayStart < 0 || objectStart < arrayStart)) {
|
|
273
|
+
start = objectStart;
|
|
274
|
+
openChar = "{";
|
|
275
|
+
closeChar = "}";
|
|
276
|
+
} else if (arrayStart >= 0) {
|
|
277
|
+
start = arrayStart;
|
|
278
|
+
openChar = "[";
|
|
279
|
+
closeChar = "]";
|
|
280
|
+
}
|
|
268
281
|
if (start < 0) return null;
|
|
269
282
|
let depth = 0;
|
|
270
283
|
let inString = false;
|
|
@@ -289,8 +302,8 @@ ${tool_schemas}`;
|
|
|
289
302
|
inString = true;
|
|
290
303
|
continue;
|
|
291
304
|
}
|
|
292
|
-
if (ch ===
|
|
293
|
-
if (ch ===
|
|
305
|
+
if (ch === openChar) depth++;
|
|
306
|
+
if (ch === closeChar) {
|
|
294
307
|
depth--;
|
|
295
308
|
if (depth === 0) {
|
|
296
309
|
return content.slice(start, i + 1);
|
|
@@ -301,6 +314,9 @@ ${tool_schemas}`;
|
|
|
301
314
|
}
|
|
302
315
|
/** 兼容常见 Function Calling 输出结构并转换为内部指令 */
|
|
303
316
|
adapt_common_tool_call(json) {
|
|
317
|
+
if (Array.isArray(json) && json.length > 0) {
|
|
318
|
+
return this.adapt_common_tool_call(json[0]);
|
|
319
|
+
}
|
|
304
320
|
if (typeof json?.name === "string") {
|
|
305
321
|
const params = this.normalize_params(json.params ?? json.arguments ?? {});
|
|
306
322
|
return {
|