@polka-codes/core 0.8.6 → 0.8.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/_tsup-dts-rollup.d.ts +3 -0
- package/dist/index.js +59 -9
- package/package.json +1 -1
|
@@ -780,6 +780,7 @@ declare const _default: {
|
|
|
780
780
|
readonly description: "One or more follow-up questions you need answered before you can continue.";
|
|
781
781
|
readonly required: true;
|
|
782
782
|
readonly allowMultiple: true;
|
|
783
|
+
readonly usageValue: "questions here";
|
|
783
784
|
readonly children: [{
|
|
784
785
|
readonly name: "prompt";
|
|
785
786
|
readonly description: "The text of the question.";
|
|
@@ -841,6 +842,7 @@ declare const _default: {
|
|
|
841
842
|
readonly description: "One or more follow-up questions you need answered before you can continue.";
|
|
842
843
|
readonly required: true;
|
|
843
844
|
readonly allowMultiple: true;
|
|
845
|
+
readonly usageValue: "questions here";
|
|
844
846
|
readonly children: [{
|
|
845
847
|
readonly name: "prompt";
|
|
846
848
|
readonly description: "The text of the question.";
|
|
@@ -2586,6 +2588,7 @@ export declare const toolInfo: {
|
|
|
2586
2588
|
readonly description: "One or more follow-up questions you need answered before you can continue.";
|
|
2587
2589
|
readonly required: true;
|
|
2588
2590
|
readonly allowMultiple: true;
|
|
2591
|
+
readonly usageValue: "questions here";
|
|
2589
2592
|
readonly children: [{
|
|
2590
2593
|
readonly name: "prompt";
|
|
2591
2594
|
readonly description: "The text of the question.";
|
package/dist/index.js
CHANGED
|
@@ -1087,6 +1087,7 @@ var toolInfo = {
|
|
|
1087
1087
|
description: "One or more follow-up questions you need answered before you can continue.",
|
|
1088
1088
|
required: true,
|
|
1089
1089
|
allowMultiple: true,
|
|
1090
|
+
usageValue: "questions here",
|
|
1090
1091
|
children: [
|
|
1091
1092
|
{
|
|
1092
1093
|
name: "prompt",
|
|
@@ -2310,16 +2311,46 @@ var getAvailableTools = ({
|
|
|
2310
2311
|
};
|
|
2311
2312
|
|
|
2312
2313
|
// src/Agent/parseAssistantMessage.ts
|
|
2313
|
-
function parseNestedParameters(content, parameterPrefix) {
|
|
2314
|
+
function parseNestedParameters(content, parameterPrefix, childrenParams) {
|
|
2314
2315
|
const result = {};
|
|
2315
2316
|
const nestedParamRegex = new RegExp(`<${parameterPrefix}([^>]+)>([\\s\\S]*?)<\\/${parameterPrefix}\\1>`, "gs");
|
|
2317
|
+
const arrayParams = /* @__PURE__ */ new Set();
|
|
2318
|
+
if (childrenParams) {
|
|
2319
|
+
for (const param of childrenParams) {
|
|
2320
|
+
if (param.allowMultiple) {
|
|
2321
|
+
arrayParams.add(param.name);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2316
2325
|
while (true) {
|
|
2317
2326
|
const match = nestedParamRegex.exec(content);
|
|
2318
2327
|
if (match === null) break;
|
|
2319
2328
|
const paramName = match[1];
|
|
2320
2329
|
const paramContent = match[2].trim();
|
|
2321
|
-
|
|
2322
|
-
|
|
2330
|
+
const childParam = childrenParams?.find((p) => p.name === paramName);
|
|
2331
|
+
if (paramContent.includes(`<${parameterPrefix}`) && childParam?.children) {
|
|
2332
|
+
const nestedResult = parseNestedParameters(paramContent, parameterPrefix, childParam.children);
|
|
2333
|
+
if (arrayParams.has(paramName)) {
|
|
2334
|
+
if (!result[paramName]) {
|
|
2335
|
+
result[paramName] = [];
|
|
2336
|
+
}
|
|
2337
|
+
if (Array.isArray(result[paramName])) {
|
|
2338
|
+
result[paramName].push(nestedResult);
|
|
2339
|
+
} else {
|
|
2340
|
+
result[paramName] = [nestedResult];
|
|
2341
|
+
}
|
|
2342
|
+
} else {
|
|
2343
|
+
result[paramName] = nestedResult;
|
|
2344
|
+
}
|
|
2345
|
+
} else if (arrayParams.has(paramName)) {
|
|
2346
|
+
if (!result[paramName]) {
|
|
2347
|
+
result[paramName] = [];
|
|
2348
|
+
}
|
|
2349
|
+
if (Array.isArray(result[paramName])) {
|
|
2350
|
+
result[paramName].push(paramContent);
|
|
2351
|
+
} else {
|
|
2352
|
+
result[paramName] = [paramContent];
|
|
2353
|
+
}
|
|
2323
2354
|
} else {
|
|
2324
2355
|
result[paramName] = paramContent;
|
|
2325
2356
|
}
|
|
@@ -2361,15 +2392,29 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
2361
2392
|
paramMatches.push(paramMatch[1].trim());
|
|
2362
2393
|
}
|
|
2363
2394
|
if (paramMatches.length > 0) {
|
|
2364
|
-
if (paramMatches.length === 1) {
|
|
2395
|
+
if (paramMatches.length === 1 && !param.allowMultiple) {
|
|
2365
2396
|
const paramContent = paramMatches[0];
|
|
2366
|
-
if (paramContent.includes(`<${parameterPrefix}`)) {
|
|
2367
|
-
params[param.name] = parseNestedParameters(paramContent, parameterPrefix);
|
|
2397
|
+
if (paramContent.includes(`<${parameterPrefix}`) && param.children) {
|
|
2398
|
+
params[param.name] = parseNestedParameters(paramContent, parameterPrefix, param.children);
|
|
2368
2399
|
} else {
|
|
2369
2400
|
params[param.name] = paramContent;
|
|
2370
2401
|
}
|
|
2371
2402
|
} else {
|
|
2372
|
-
|
|
2403
|
+
if (param.allowMultiple) {
|
|
2404
|
+
params[param.name] = paramMatches.map((paramContent) => {
|
|
2405
|
+
if (paramContent.includes(`<${parameterPrefix}`) && param.children) {
|
|
2406
|
+
return parseNestedParameters(paramContent, parameterPrefix, param.children);
|
|
2407
|
+
}
|
|
2408
|
+
return paramContent;
|
|
2409
|
+
});
|
|
2410
|
+
} else {
|
|
2411
|
+
const paramContent = paramMatches[0];
|
|
2412
|
+
if (paramContent.includes(`<${parameterPrefix}`) && param.children) {
|
|
2413
|
+
params[param.name] = parseNestedParameters(paramContent, parameterPrefix, param.children);
|
|
2414
|
+
} else {
|
|
2415
|
+
params[param.name] = paramContent;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2373
2418
|
}
|
|
2374
2419
|
}
|
|
2375
2420
|
}
|
|
@@ -2420,11 +2465,16 @@ var toolInfoPrompt = (tool, toolNamePrefix, parameterPrefix) => `
|
|
|
2420
2465
|
Description: ${tool.description}
|
|
2421
2466
|
|
|
2422
2467
|
Parameters:
|
|
2423
|
-
${tool.parameters.map(
|
|
2468
|
+
${tool.parameters.map(
|
|
2469
|
+
(param) => `- ${parameterPrefix}${param.name}: (${param.required ? "required" : "optional"})${param.allowMultiple ? " (multiple allowed)" : ""} ${param.description}`
|
|
2470
|
+
).join("\n")}
|
|
2424
2471
|
|
|
2425
2472
|
Usage:
|
|
2426
2473
|
<${toolNamePrefix}${tool.name}>
|
|
2427
|
-
${tool.parameters.map(
|
|
2474
|
+
${tool.parameters.map(
|
|
2475
|
+
(param) => param.allowMultiple ? `<${parameterPrefix}${param.name}>${param.usageValue}</${parameterPrefix}${param.name}>
|
|
2476
|
+
<${parameterPrefix}${param.name}>${param.usageValue}</${parameterPrefix}${param.name}>` : `<${parameterPrefix}${param.name}>${param.usageValue}</${parameterPrefix}${param.name}>`
|
|
2477
|
+
).join("\n")}
|
|
2428
2478
|
</${toolNamePrefix}${tool.name}>`;
|
|
2429
2479
|
var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) => `
|
|
2430
2480
|
## Example: ${example.description}
|