@polka-codes/core 0.8.5 → 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 +67 -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
|
@@ -1010,6 +1010,14 @@ var getStringArray = (args, name, defaultValue) => {
|
|
|
1010
1010
|
if (ret === "") {
|
|
1011
1011
|
return [];
|
|
1012
1012
|
}
|
|
1013
|
+
if (Array.isArray(ret)) {
|
|
1014
|
+
for (const item of ret) {
|
|
1015
|
+
if (typeof item !== "string") {
|
|
1016
|
+
throw new Error(`Invalid argument type: ${name} ${item}`);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return ret;
|
|
1020
|
+
}
|
|
1013
1021
|
if (typeof ret !== "string") {
|
|
1014
1022
|
throw new Error(`Invalid argument type: ${name} ${ret}`);
|
|
1015
1023
|
}
|
|
@@ -1079,6 +1087,7 @@ var toolInfo = {
|
|
|
1079
1087
|
description: "One or more follow-up questions you need answered before you can continue.",
|
|
1080
1088
|
required: true,
|
|
1081
1089
|
allowMultiple: true,
|
|
1090
|
+
usageValue: "questions here",
|
|
1082
1091
|
children: [
|
|
1083
1092
|
{
|
|
1084
1093
|
name: "prompt",
|
|
@@ -2302,16 +2311,46 @@ var getAvailableTools = ({
|
|
|
2302
2311
|
};
|
|
2303
2312
|
|
|
2304
2313
|
// src/Agent/parseAssistantMessage.ts
|
|
2305
|
-
function parseNestedParameters(content, parameterPrefix) {
|
|
2314
|
+
function parseNestedParameters(content, parameterPrefix, childrenParams) {
|
|
2306
2315
|
const result = {};
|
|
2307
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
|
+
}
|
|
2308
2325
|
while (true) {
|
|
2309
2326
|
const match = nestedParamRegex.exec(content);
|
|
2310
2327
|
if (match === null) break;
|
|
2311
2328
|
const paramName = match[1];
|
|
2312
2329
|
const paramContent = match[2].trim();
|
|
2313
|
-
|
|
2314
|
-
|
|
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
|
+
}
|
|
2315
2354
|
} else {
|
|
2316
2355
|
result[paramName] = paramContent;
|
|
2317
2356
|
}
|
|
@@ -2353,15 +2392,29 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
2353
2392
|
paramMatches.push(paramMatch[1].trim());
|
|
2354
2393
|
}
|
|
2355
2394
|
if (paramMatches.length > 0) {
|
|
2356
|
-
if (paramMatches.length === 1) {
|
|
2395
|
+
if (paramMatches.length === 1 && !param.allowMultiple) {
|
|
2357
2396
|
const paramContent = paramMatches[0];
|
|
2358
|
-
if (paramContent.includes(`<${parameterPrefix}`)) {
|
|
2359
|
-
params[param.name] = parseNestedParameters(paramContent, parameterPrefix);
|
|
2397
|
+
if (paramContent.includes(`<${parameterPrefix}`) && param.children) {
|
|
2398
|
+
params[param.name] = parseNestedParameters(paramContent, parameterPrefix, param.children);
|
|
2360
2399
|
} else {
|
|
2361
2400
|
params[param.name] = paramContent;
|
|
2362
2401
|
}
|
|
2363
2402
|
} else {
|
|
2364
|
-
|
|
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
|
+
}
|
|
2365
2418
|
}
|
|
2366
2419
|
}
|
|
2367
2420
|
}
|
|
@@ -2412,11 +2465,16 @@ var toolInfoPrompt = (tool, toolNamePrefix, parameterPrefix) => `
|
|
|
2412
2465
|
Description: ${tool.description}
|
|
2413
2466
|
|
|
2414
2467
|
Parameters:
|
|
2415
|
-
${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")}
|
|
2416
2471
|
|
|
2417
2472
|
Usage:
|
|
2418
2473
|
<${toolNamePrefix}${tool.name}>
|
|
2419
|
-
${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")}
|
|
2420
2478
|
</${toolNamePrefix}${tool.name}>`;
|
|
2421
2479
|
var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) => `
|
|
2422
2480
|
## Example: ${example.description}
|