@polka-codes/core 0.8.2 → 0.8.4

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.
@@ -774,64 +774,122 @@ export declare class DeepSeekService extends AiServiceBase {
774
774
  declare const _default: {
775
775
  handler: ToolHandler<{
776
776
  readonly name: "ask_followup_question";
777
- readonly description: "Whenever you need extra details or clarification to complete the task, pose a direct question to the user. Use this tool sparingly to avoid excessive back-and-forth. If helpful, offer multiple-choice options or examples to guide the user’s response.";
777
+ readonly description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.";
778
778
  readonly parameters: [{
779
- readonly name: "question";
780
- readonly description: "The question to ask the user. This should be a clear, specific question that addresses the information you need.";
779
+ readonly name: "questions";
780
+ readonly description: "One or more follow-up questions you need answered before you can continue.";
781
781
  readonly required: true;
782
- readonly usageValue: "Your question here";
783
- }, {
784
- readonly name: "options";
785
- readonly description: "A comma separated list of possible answers to the question. Ordered by preference. If not provided, the user will be prompted to provide an answer.";
786
- readonly required: false;
787
- readonly usageValue: "A comma separated list of possible answers (optional)";
782
+ readonly allowMultiple: true;
783
+ readonly children: [{
784
+ readonly name: "prompt";
785
+ readonly description: "The text of the question.";
786
+ readonly required: true;
787
+ readonly usageValue: "question text here";
788
+ }, {
789
+ readonly name: "options";
790
+ readonly description: "Ordered list of suggested answers (omit if none).";
791
+ readonly required: false;
792
+ readonly allowMultiple: true;
793
+ readonly usageValue: "suggested answer here";
794
+ }];
788
795
  }];
789
796
  readonly examples: [{
790
- readonly description: "Request to ask a question";
797
+ readonly description: "Single clarifying question (no options)";
791
798
  readonly parameters: [{
792
- readonly name: "question";
793
- readonly value: "What is the name of the project?";
799
+ readonly name: "questions";
800
+ readonly value: {
801
+ readonly prompt: "What is the target deployment environment?";
802
+ };
794
803
  }];
795
804
  }, {
796
- readonly description: "Request to ask a question with options";
805
+ readonly description: "Single question with multiple-choice options";
797
806
  readonly parameters: [{
798
- readonly name: "question";
799
- readonly value: "What framework do you use?";
800
- }, {
801
- readonly name: "options";
802
- readonly value: "React,Angular,Vue,Svelte";
807
+ readonly name: "questions";
808
+ readonly value: {
809
+ readonly prompt: "Which frontend framework are you using?";
810
+ readonly options: ["React", "Angular", "Vue", "Svelte"];
811
+ };
812
+ }];
813
+ }, {
814
+ readonly description: "Two related questions in one call";
815
+ readonly parameters: [{
816
+ readonly name: "questions";
817
+ readonly value: [{
818
+ readonly prompt: "What type of application are you building?";
819
+ }, {
820
+ readonly prompt: "Preferred programming language?";
821
+ readonly options: ["JavaScript", "TypeScript", "Python", "Java"];
822
+ }];
823
+ }];
824
+ }, {
825
+ readonly description: "Binary (yes/no) confirmation";
826
+ readonly parameters: [{
827
+ readonly name: "questions";
828
+ readonly value: {
829
+ readonly prompt: "Is it acceptable to refactor existing tests to improve performance?";
830
+ readonly options: ["Yes", "No"];
831
+ };
803
832
  }];
804
833
  }];
805
834
  readonly permissionLevel: PermissionLevel.None;
806
835
  }, InteractionProvider>;
807
836
  isAvailable: (provider: InteractionProvider) => boolean;
808
837
  name: "ask_followup_question";
809
- description: "Whenever you need extra details or clarification to complete the task, pose a direct question to the user. Use this tool sparingly to avoid excessive back-and-forth. If helpful, offer multiple-choice options or examples to guide the user’s response.";
838
+ description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.";
810
839
  parameters: [{
811
- readonly name: "question";
812
- readonly description: "The question to ask the user. This should be a clear, specific question that addresses the information you need.";
840
+ readonly name: "questions";
841
+ readonly description: "One or more follow-up questions you need answered before you can continue.";
813
842
  readonly required: true;
814
- readonly usageValue: "Your question here";
815
- }, {
816
- readonly name: "options";
817
- readonly description: "A comma separated list of possible answers to the question. Ordered by preference. If not provided, the user will be prompted to provide an answer.";
818
- readonly required: false;
819
- readonly usageValue: "A comma separated list of possible answers (optional)";
843
+ readonly allowMultiple: true;
844
+ readonly children: [{
845
+ readonly name: "prompt";
846
+ readonly description: "The text of the question.";
847
+ readonly required: true;
848
+ readonly usageValue: "question text here";
849
+ }, {
850
+ readonly name: "options";
851
+ readonly description: "Ordered list of suggested answers (omit if none).";
852
+ readonly required: false;
853
+ readonly allowMultiple: true;
854
+ readonly usageValue: "suggested answer here";
855
+ }];
820
856
  }];
821
857
  examples: [{
822
- readonly description: "Request to ask a question";
858
+ readonly description: "Single clarifying question (no options)";
823
859
  readonly parameters: [{
824
- readonly name: "question";
825
- readonly value: "What is the name of the project?";
860
+ readonly name: "questions";
861
+ readonly value: {
862
+ readonly prompt: "What is the target deployment environment?";
863
+ };
826
864
  }];
827
865
  }, {
828
- readonly description: "Request to ask a question with options";
866
+ readonly description: "Single question with multiple-choice options";
829
867
  readonly parameters: [{
830
- readonly name: "question";
831
- readonly value: "What framework do you use?";
832
- }, {
833
- readonly name: "options";
834
- readonly value: "React,Angular,Vue,Svelte";
868
+ readonly name: "questions";
869
+ readonly value: {
870
+ readonly prompt: "Which frontend framework are you using?";
871
+ readonly options: ["React", "Angular", "Vue", "Svelte"];
872
+ };
873
+ }];
874
+ }, {
875
+ readonly description: "Two related questions in one call";
876
+ readonly parameters: [{
877
+ readonly name: "questions";
878
+ readonly value: [{
879
+ readonly prompt: "What type of application are you building?";
880
+ }, {
881
+ readonly prompt: "Preferred programming language?";
882
+ readonly options: ["JavaScript", "TypeScript", "Python", "Java"];
883
+ }];
884
+ }];
885
+ }, {
886
+ readonly description: "Binary (yes/no) confirmation";
887
+ readonly parameters: [{
888
+ readonly name: "questions";
889
+ readonly value: {
890
+ readonly prompt: "Is it acceptable to refactor existing tests to improve performance?";
891
+ readonly options: ["Yes", "No"];
892
+ };
835
893
  }];
836
894
  }];
837
895
  permissionLevel: PermissionLevel.None;
@@ -1354,23 +1412,23 @@ export { _default_3 as delegate_alias_2 }
1354
1412
  declare const _default_4: {
1355
1413
  handler: ToolHandler<{
1356
1414
  readonly name: "execute_command";
1357
- readonly description: "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.";
1415
+ readonly description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call, no other tool calls are allowed in the same assistant response.";
1358
1416
  readonly parameters: [{
1359
1417
  readonly name: "command";
1360
- readonly description: "The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.";
1418
+ readonly description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.";
1361
1419
  readonly required: true;
1362
- readonly usageValue: "Your command here";
1420
+ readonly usageValue: "your-command-here";
1363
1421
  }, {
1364
1422
  readonly name: "requires_approval";
1365
- readonly description: "A boolean indicating whether this command requires explicit user approval before execution in case the user has auto-approve mode enabled. Set to 'true' for potentially impactful operations like installing/uninstalling packages, deleting/overwriting files, system configuration changes, network operations, or any commands that could have unintended side effects. Set to 'false' for safe operations like reading files/directories, running development servers, building projects, and other non-destructive operations.";
1423
+ readonly description: "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).";
1366
1424
  readonly required: false;
1367
- readonly usageValue: "true or false";
1425
+ readonly usageValue: "true | false";
1368
1426
  }];
1369
1427
  readonly examples: [{
1370
- readonly description: "Request to execute a command";
1428
+ readonly description: "Make a build";
1371
1429
  readonly parameters: [{
1372
1430
  readonly name: "command";
1373
- readonly value: "npm run dev";
1431
+ readonly value: "npm run build";
1374
1432
  }, {
1375
1433
  readonly name: "requires_approval";
1376
1434
  readonly value: "false";
@@ -1380,23 +1438,23 @@ declare const _default_4: {
1380
1438
  }, CommandProvider>;
1381
1439
  isAvailable: (provider: CommandProvider) => boolean;
1382
1440
  name: "execute_command";
1383
- description: "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.";
1441
+ description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call, no other tool calls are allowed in the same assistant response.";
1384
1442
  parameters: [{
1385
1443
  readonly name: "command";
1386
- readonly description: "The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.";
1444
+ readonly description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.";
1387
1445
  readonly required: true;
1388
- readonly usageValue: "Your command here";
1446
+ readonly usageValue: "your-command-here";
1389
1447
  }, {
1390
1448
  readonly name: "requires_approval";
1391
- readonly description: "A boolean indicating whether this command requires explicit user approval before execution in case the user has auto-approve mode enabled. Set to 'true' for potentially impactful operations like installing/uninstalling packages, deleting/overwriting files, system configuration changes, network operations, or any commands that could have unintended side effects. Set to 'false' for safe operations like reading files/directories, running development servers, building projects, and other non-destructive operations.";
1449
+ readonly description: "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).";
1392
1450
  readonly required: false;
1393
- readonly usageValue: "true or false";
1451
+ readonly usageValue: "true | false";
1394
1452
  }];
1395
1453
  examples: [{
1396
- readonly description: "Request to execute a command";
1454
+ readonly description: "Make a build";
1397
1455
  readonly parameters: [{
1398
1456
  readonly name: "command";
1399
- readonly value: "npm run dev";
1457
+ readonly value: "npm run build";
1400
1458
  }, {
1401
1459
  readonly name: "requires_approval";
1402
1460
  readonly value: "false";
@@ -1861,6 +1919,11 @@ declare const generateProjectConfig: (agent: MultiAgent, params: unknown) => Pro
1861
1919
  export { generateProjectConfig }
1862
1920
  export { generateProjectConfig as generateProjectConfig_alias_1 }
1863
1921
 
1922
+ declare const getArray: <T extends string>(args: Partial<Record<T, ToolParameterValue>> | ToolParameterValue, name: T, defaultValue?: ToolParameterValue[]) => ToolParameterValue[];
1923
+ export { getArray }
1924
+ export { getArray as getArray_alias_1 }
1925
+ export { getArray as getArray_alias_2 }
1926
+
1864
1927
  /**
1865
1928
  * Get the available tools based on the provider and agent availability
1866
1929
  * @param provider The provider to use.
@@ -1880,7 +1943,7 @@ declare const getAvailableTools: ({ provider, allTools, hasAgent, permissionLeve
1880
1943
  export { getAvailableTools }
1881
1944
  export { getAvailableTools as getAvailableTools_alias_1 }
1882
1945
 
1883
- declare const getBoolean: <T extends string>(args: Partial<Record<T, string>>, name: T, defaultValue?: boolean) => boolean;
1946
+ declare const getBoolean: <T extends string>(args: Partial<Record<T, ToolParameterValue>>, name: T, defaultValue?: boolean) => boolean;
1884
1947
  export { getBoolean }
1885
1948
  export { getBoolean as getBoolean_alias_1 }
1886
1949
  export { getBoolean as getBoolean_alias_2 }
@@ -1890,7 +1953,7 @@ export { GetInput }
1890
1953
  export { GetInput as GetInput_alias_1 }
1891
1954
  export { GetInput as GetInput_alias_2 }
1892
1955
 
1893
- declare const getInt: <T extends string>(args: Partial<Record<T, string>>, name: T, defaultValue?: number) => number;
1956
+ declare const getInt: <T extends string>(args: Partial<Record<T, ToolParameterValue>>, name: T, defaultValue?: number) => number;
1894
1957
  export { getInt }
1895
1958
  export { getInt as getInt_alias_1 }
1896
1959
  export { getInt as getInt_alias_2 }
@@ -1900,12 +1963,12 @@ export { GetOutput }
1900
1963
  export { GetOutput as GetOutput_alias_1 }
1901
1964
  export { GetOutput as GetOutput_alias_2 }
1902
1965
 
1903
- declare const getString: <T extends string>(args: Partial<Partial<Record<T, string>>>, name: T, defaultValue?: string) => string;
1966
+ declare const getString: <T extends string>(args: Partial<Record<T, string>> | ToolParameterValue, name: T, defaultValue?: string) => string;
1904
1967
  export { getString }
1905
1968
  export { getString as getString_alias_1 }
1906
1969
  export { getString as getString_alias_2 }
1907
1970
 
1908
- declare const getStringArray: <T extends string>(args: Partial<Record<T, string>>, name: T, defaultValue?: string[]) => string[];
1971
+ declare const getStringArray: <T extends string>(args: Partial<Record<T, ToolParameterValue>>, name: T, defaultValue?: string[]) => string[];
1909
1972
  export { getStringArray }
1910
1973
  export { getStringArray as getStringArray_alias_1 }
1911
1974
  export { getStringArray as getStringArray_alias_2 }
@@ -2229,6 +2292,34 @@ declare type Output = {
2229
2292
  * // {type: "tool_use", name: "search", params: {query: "cats"}},
2230
2293
  * // {type: "text", content: "Here are the results"}
2231
2294
  * // ]
2295
+ *
2296
+ * // Array mode (multiple occurrences of the same parameter)
2297
+ * parseAssistantMessage(
2298
+ * `<tool_read_file>
2299
+ * <tool_parameter_path>test.ts</tool_parameter_path>
2300
+ * <tool_parameter_path>main.ts</tool_parameter_path>
2301
+ * </tool_read_file>`,
2302
+ * tools,
2303
+ * "tool_"
2304
+ * )
2305
+ * // Returns: [
2306
+ * // {type: "tool_use", name: "read_file", params: {path: ["test.ts", "main.ts"]}}
2307
+ * // ]
2308
+ *
2309
+ * // Nested objects
2310
+ * parseAssistantMessage(
2311
+ * `<tool_example>
2312
+ * <tool_parameter_key>
2313
+ * <tool_parameter_key2>value</tool_parameter_key2>
2314
+ * <tool_parameter_key3>value2</tool_parameter_key3>
2315
+ * </tool_parameter_key>
2316
+ * </tool_example>`,
2317
+ * tools,
2318
+ * "tool_"
2319
+ * )
2320
+ * // Returns: [
2321
+ * // {type: "tool_use", name: "example", params: {key: {key2: "value", key3: "value2"}}}
2322
+ * // ]
2232
2323
  */
2233
2324
  declare function parseAssistantMessage(assistantMessage: string, tools: ToolInfo[], toolNamePrefix: string): AssistantMessageContent[];
2234
2325
  export { parseAssistantMessage }
@@ -2467,13 +2558,13 @@ declare type ToolExample = {
2467
2558
  description: string;
2468
2559
  parameters: {
2469
2560
  name: string;
2470
- value: string;
2561
+ value: ToolParameterValue;
2471
2562
  }[];
2472
2563
  };
2473
2564
  export { ToolExample }
2474
2565
  export { ToolExample as ToolExample_alias_1 }
2475
2566
 
2476
- declare type ToolHandler<T extends ToolInfo, P> = (provider: P, args: Partial<Record<T['parameters'][number]['name'], string>>) => Promise<ToolResponse>;
2567
+ declare type ToolHandler<T extends ToolInfo, P> = (provider: P, args: Partial<Record<T['parameters'][number]['name'], ToolParameterValue>>) => Promise<ToolResponse>;
2477
2568
  export { ToolHandler }
2478
2569
  export { ToolHandler as ToolHandler_alias_1 }
2479
2570
 
@@ -2489,32 +2580,61 @@ export { ToolInfo as ToolInfo_alias_1 }
2489
2580
 
2490
2581
  export declare const toolInfo: {
2491
2582
  readonly name: "ask_followup_question";
2492
- readonly description: "Whenever you need extra details or clarification to complete the task, pose a direct question to the user. Use this tool sparingly to avoid excessive back-and-forth. If helpful, offer multiple-choice options or examples to guide the user’s response.";
2583
+ readonly description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.";
2493
2584
  readonly parameters: [{
2494
- readonly name: "question";
2495
- readonly description: "The question to ask the user. This should be a clear, specific question that addresses the information you need.";
2585
+ readonly name: "questions";
2586
+ readonly description: "One or more follow-up questions you need answered before you can continue.";
2496
2587
  readonly required: true;
2497
- readonly usageValue: "Your question here";
2498
- }, {
2499
- readonly name: "options";
2500
- readonly description: "A comma separated list of possible answers to the question. Ordered by preference. If not provided, the user will be prompted to provide an answer.";
2501
- readonly required: false;
2502
- readonly usageValue: "A comma separated list of possible answers (optional)";
2588
+ readonly allowMultiple: true;
2589
+ readonly children: [{
2590
+ readonly name: "prompt";
2591
+ readonly description: "The text of the question.";
2592
+ readonly required: true;
2593
+ readonly usageValue: "question text here";
2594
+ }, {
2595
+ readonly name: "options";
2596
+ readonly description: "Ordered list of suggested answers (omit if none).";
2597
+ readonly required: false;
2598
+ readonly allowMultiple: true;
2599
+ readonly usageValue: "suggested answer here";
2600
+ }];
2503
2601
  }];
2504
2602
  readonly examples: [{
2505
- readonly description: "Request to ask a question";
2603
+ readonly description: "Single clarifying question (no options)";
2506
2604
  readonly parameters: [{
2507
- readonly name: "question";
2508
- readonly value: "What is the name of the project?";
2605
+ readonly name: "questions";
2606
+ readonly value: {
2607
+ readonly prompt: "What is the target deployment environment?";
2608
+ };
2509
2609
  }];
2510
2610
  }, {
2511
- readonly description: "Request to ask a question with options";
2611
+ readonly description: "Single question with multiple-choice options";
2512
2612
  readonly parameters: [{
2513
- readonly name: "question";
2514
- readonly value: "What framework do you use?";
2515
- }, {
2516
- readonly name: "options";
2517
- readonly value: "React,Angular,Vue,Svelte";
2613
+ readonly name: "questions";
2614
+ readonly value: {
2615
+ readonly prompt: "Which frontend framework are you using?";
2616
+ readonly options: ["React", "Angular", "Vue", "Svelte"];
2617
+ };
2618
+ }];
2619
+ }, {
2620
+ readonly description: "Two related questions in one call";
2621
+ readonly parameters: [{
2622
+ readonly name: "questions";
2623
+ readonly value: [{
2624
+ readonly prompt: "What type of application are you building?";
2625
+ }, {
2626
+ readonly prompt: "Preferred programming language?";
2627
+ readonly options: ["JavaScript", "TypeScript", "Python", "Java"];
2628
+ }];
2629
+ }];
2630
+ }, {
2631
+ readonly description: "Binary (yes/no) confirmation";
2632
+ readonly parameters: [{
2633
+ readonly name: "questions";
2634
+ readonly value: {
2635
+ readonly prompt: "Is it acceptable to refactor existing tests to improve performance?";
2636
+ readonly options: ["Yes", "No"];
2637
+ };
2518
2638
  }];
2519
2639
  }];
2520
2640
  readonly permissionLevel: PermissionLevel.None;
@@ -2736,23 +2856,23 @@ export declare const toolInfo_alias_2: {
2736
2856
 
2737
2857
  export declare const toolInfo_alias_3: {
2738
2858
  readonly name: "execute_command";
2739
- readonly description: "Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.";
2859
+ readonly description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call, no other tool calls are allowed in the same assistant response.";
2740
2860
  readonly parameters: [{
2741
2861
  readonly name: "command";
2742
- readonly description: "The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.";
2862
+ readonly description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.";
2743
2863
  readonly required: true;
2744
- readonly usageValue: "Your command here";
2864
+ readonly usageValue: "your-command-here";
2745
2865
  }, {
2746
2866
  readonly name: "requires_approval";
2747
- readonly description: "A boolean indicating whether this command requires explicit user approval before execution in case the user has auto-approve mode enabled. Set to 'true' for potentially impactful operations like installing/uninstalling packages, deleting/overwriting files, system configuration changes, network operations, or any commands that could have unintended side effects. Set to 'false' for safe operations like reading files/directories, running development servers, building projects, and other non-destructive operations.";
2867
+ readonly description: "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).";
2748
2868
  readonly required: false;
2749
- readonly usageValue: "true or false";
2869
+ readonly usageValue: "true | false";
2750
2870
  }];
2751
2871
  readonly examples: [{
2752
- readonly description: "Request to execute a command";
2872
+ readonly description: "Make a build";
2753
2873
  readonly parameters: [{
2754
2874
  readonly name: "command";
2755
- readonly value: "npm run dev";
2875
+ readonly value: "npm run build";
2756
2876
  }, {
2757
2877
  readonly name: "requires_approval";
2758
2878
  readonly value: "false";
@@ -2930,11 +3050,19 @@ declare type ToolParameter = {
2930
3050
  name: string;
2931
3051
  description: string;
2932
3052
  required: boolean;
2933
- usageValue: string;
3053
+ usageValue?: string;
3054
+ allowMultiple?: boolean;
3055
+ children?: ToolParameter[];
2934
3056
  };
2935
3057
  export { ToolParameter }
2936
3058
  export { ToolParameter as ToolParameter_alias_1 }
2937
3059
 
3060
+ declare type ToolParameterValue = string | {
3061
+ [key: string]: ToolParameterValue;
3062
+ } | ToolParameterValue[];
3063
+ export { ToolParameterValue }
3064
+ export { ToolParameterValue as ToolParameterValue_alias_1 }
3065
+
2938
3066
  declare type ToolProvider = FilesystemProvider & CommandProvider & InteractionProvider;
2939
3067
  export { ToolProvider }
2940
3068
  export { ToolProvider as ToolProvider_alias_1 }
@@ -3039,7 +3167,7 @@ export { ToolResponseType as ToolResponseType_alias_1 }
3039
3167
  declare interface ToolUse {
3040
3168
  type: 'tool_use';
3041
3169
  name: string;
3042
- params: Record<string, string>;
3170
+ params: Record<string, any>;
3043
3171
  }
3044
3172
  export { ToolUse }
3045
3173
  export { ToolUse as ToolUse_alias_1 }
package/dist/index.d.ts CHANGED
@@ -100,6 +100,7 @@ export { AiToolDefinition } from './_tsup-dts-rollup.js';
100
100
  export { GetInput } from './_tsup-dts-rollup.js';
101
101
  export { GetOutput } from './_tsup-dts-rollup.js';
102
102
  export { ToolParameter } from './_tsup-dts-rollup.js';
103
+ export { ToolParameterValue } from './_tsup-dts-rollup.js';
103
104
  export { ToolExample } from './_tsup-dts-rollup.js';
104
105
  export { PermissionLevel } from './_tsup-dts-rollup.js';
105
106
  export { ToolInfo } from './_tsup-dts-rollup.js';
@@ -123,3 +124,4 @@ export { getString } from './_tsup-dts-rollup.js';
123
124
  export { getStringArray } from './_tsup-dts-rollup.js';
124
125
  export { getBoolean } from './_tsup-dts-rollup.js';
125
126
  export { getInt } from './_tsup-dts-rollup.js';
127
+ export { getArray } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -987,10 +987,16 @@ ${search}`);
987
987
 
988
988
  // src/tools/utils/getArg.ts
989
989
  var getString = (args, name, defaultValue) => {
990
+ if (typeof args !== "object" || Array.isArray(args)) {
991
+ throw new Error(`Invalid argument type: ${name} ${args}`);
992
+ }
990
993
  const ret = args[name] ?? defaultValue;
991
994
  if (ret === void 0) {
992
995
  throw new Error(`Missing required argument: ${name}`);
993
996
  }
997
+ if (typeof ret !== "string") {
998
+ throw new Error(`Invalid argument type: ${name} ${ret}`);
999
+ }
994
1000
  return ret;
995
1001
  };
996
1002
  var getStringArray = (args, name, defaultValue) => {
@@ -1004,6 +1010,9 @@ var getStringArray = (args, name, defaultValue) => {
1004
1010
  if (ret === "") {
1005
1011
  return [];
1006
1012
  }
1013
+ if (typeof ret !== "string") {
1014
+ throw new Error(`Invalid argument type: ${name} ${ret}`);
1015
+ }
1007
1016
  return ret.split(",").map((s) => s.trim());
1008
1017
  };
1009
1018
  var getBoolean = (args, name, defaultValue) => {
@@ -1014,13 +1023,16 @@ var getBoolean = (args, name, defaultValue) => {
1014
1023
  }
1015
1024
  return defaultValue;
1016
1025
  }
1026
+ if (typeof ret !== "string") {
1027
+ throw new Error(`Invalid argument type: ${name} ${ret}`);
1028
+ }
1017
1029
  switch (ret.toLowerCase()) {
1018
1030
  case "true":
1019
1031
  return true;
1020
1032
  case "false":
1021
1033
  return false;
1022
1034
  default:
1023
- throw new Error(`Invalid argument value: ${name}`);
1035
+ throw new Error(`Invalid argument value: ${name} ${ret}`);
1024
1036
  }
1025
1037
  };
1026
1038
  var getInt = (args, name, defaultValue) => {
@@ -1031,51 +1043,105 @@ var getInt = (args, name, defaultValue) => {
1031
1043
  }
1032
1044
  return defaultValue;
1033
1045
  }
1046
+ if (typeof ret !== "string") {
1047
+ throw new Error(`Invalid argument type: ${name} ${ret}`);
1048
+ }
1034
1049
  const parsed = Number.parseInt(ret);
1035
1050
  if (Number.isNaN(parsed)) {
1036
- throw new Error(`Invalid argument value: ${name}`);
1051
+ throw new Error(`Invalid argument value: ${name} ${ret}`);
1037
1052
  }
1038
1053
  return parsed;
1039
1054
  };
1055
+ var getArray = (args, name, defaultValue) => {
1056
+ if (typeof args !== "object" || Array.isArray(args)) {
1057
+ throw new Error(`Invalid argument type: ${name} ${args}`);
1058
+ }
1059
+ const ret = args[name];
1060
+ if (ret === void 0) {
1061
+ if (defaultValue === void 0) {
1062
+ throw new Error(`Missing required argument: ${name}`);
1063
+ }
1064
+ return defaultValue;
1065
+ }
1066
+ if (Array.isArray(ret)) {
1067
+ return ret;
1068
+ }
1069
+ return [ret];
1070
+ };
1040
1071
 
1041
1072
  // src/tools/askFollowupQuestion.ts
1042
1073
  var toolInfo = {
1043
1074
  name: "ask_followup_question",
1044
- description: "Whenever you need extra details or clarification to complete the task, pose a direct question to the user. Use this tool sparingly to avoid excessive back-and-forth. If helpful, offer multiple-choice options or examples to guide the user\u2019s response.",
1075
+ description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
1045
1076
  parameters: [
1046
1077
  {
1047
- name: "question",
1048
- description: "The question to ask the user. This should be a clear, specific question that addresses the information you need.",
1078
+ name: "questions",
1079
+ description: "One or more follow-up questions you need answered before you can continue.",
1049
1080
  required: true,
1050
- usageValue: "Your question here"
1051
- },
1052
- {
1053
- name: "options",
1054
- description: "A comma separated list of possible answers to the question. Ordered by preference. If not provided, the user will be prompted to provide an answer.",
1055
- required: false,
1056
- usageValue: "A comma separated list of possible answers (optional)"
1081
+ allowMultiple: true,
1082
+ children: [
1083
+ {
1084
+ name: "prompt",
1085
+ description: "The text of the question.",
1086
+ required: true,
1087
+ usageValue: "question text here"
1088
+ },
1089
+ {
1090
+ name: "options",
1091
+ description: "Ordered list of suggested answers (omit if none).",
1092
+ required: false,
1093
+ allowMultiple: true,
1094
+ usageValue: "suggested answer here"
1095
+ }
1096
+ ]
1057
1097
  }
1058
1098
  ],
1059
1099
  examples: [
1060
1100
  {
1061
- description: "Request to ask a question",
1101
+ description: "Single clarifying question (no options)",
1062
1102
  parameters: [
1063
1103
  {
1064
- name: "question",
1065
- value: "What is the name of the project?"
1104
+ name: "questions",
1105
+ value: { prompt: "What is the target deployment environment?" }
1066
1106
  }
1067
1107
  ]
1068
1108
  },
1069
1109
  {
1070
- description: "Request to ask a question with options",
1110
+ description: "Single question with multiple-choice options",
1071
1111
  parameters: [
1072
1112
  {
1073
- name: "question",
1074
- value: "What framework do you use?"
1075
- },
1113
+ name: "questions",
1114
+ value: {
1115
+ prompt: "Which frontend framework are you using?",
1116
+ options: ["React", "Angular", "Vue", "Svelte"]
1117
+ }
1118
+ }
1119
+ ]
1120
+ },
1121
+ {
1122
+ description: "Two related questions in one call",
1123
+ parameters: [
1076
1124
  {
1077
- name: "options",
1078
- value: "React,Angular,Vue,Svelte"
1125
+ name: "questions",
1126
+ value: [
1127
+ { prompt: "What type of application are you building?" },
1128
+ {
1129
+ prompt: "Preferred programming language?",
1130
+ options: ["JavaScript", "TypeScript", "Python", "Java"]
1131
+ }
1132
+ ]
1133
+ }
1134
+ ]
1135
+ },
1136
+ {
1137
+ description: "Binary (yes/no) confirmation",
1138
+ parameters: [
1139
+ {
1140
+ name: "questions",
1141
+ value: {
1142
+ prompt: "Is it acceptable to refactor existing tests to improve performance?",
1143
+ options: ["Yes", "No"]
1144
+ }
1079
1145
  }
1080
1146
  ]
1081
1147
  }
@@ -1089,13 +1155,25 @@ var handler = async (provider, args) => {
1089
1155
  message: "Not possible to ask followup question. Abort."
1090
1156
  };
1091
1157
  }
1092
- const question = getString(args, "question");
1093
- const options = getStringArray(args, "options", []);
1094
- const answer = await provider.askFollowupQuestion(question, options);
1158
+ const questions = getArray(args, "questions");
1159
+ if (!questions || questions.length === 0) {
1160
+ return {
1161
+ type: "Error" /* Error */,
1162
+ message: "No questions provided"
1163
+ };
1164
+ }
1165
+ const answers = [];
1166
+ for (const question of questions) {
1167
+ const prompt6 = getString(question, "prompt");
1168
+ const options = getArray(question, "options", []);
1169
+ const answer = await provider.askFollowupQuestion(prompt6, options);
1170
+ answers.push(`<ask_followup_question_answer question="${prompt6}">
1171
+ ${answer}
1172
+ </ask_followup_question_answer>`);
1173
+ }
1095
1174
  return {
1096
1175
  type: "Reply" /* Reply */,
1097
- message: `<ask_followup_question_question>${question}</ask_followup_question_question>
1098
- <ask_followup_question_answer>${answer}</ask_followup_question_answer>`
1176
+ message: answers.join("\n")
1099
1177
  };
1100
1178
  };
1101
1179
  var isAvailable = (provider) => {
@@ -1236,33 +1314,27 @@ var delegate_default = {
1236
1314
  // src/tools/executeCommand.ts
1237
1315
  var toolInfo4 = {
1238
1316
  name: "execute_command",
1239
- description: `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.`,
1317
+ description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call, no other tool calls are allowed in the same assistant response.",
1240
1318
  parameters: [
1241
1319
  {
1242
1320
  name: "command",
1243
- description: "The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.",
1321
+ description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.",
1244
1322
  required: true,
1245
- usageValue: "Your command here"
1323
+ usageValue: "your-command-here"
1246
1324
  },
1247
1325
  {
1248
1326
  name: "requires_approval",
1249
- description: `A boolean indicating whether this command requires explicit user approval before execution in case the user has auto-approve mode enabled. Set to 'true' for potentially impactful operations like installing/uninstalling packages, deleting/overwriting files, system configuration changes, network operations, or any commands that could have unintended side effects. Set to 'false' for safe operations like reading files/directories, running development servers, building projects, and other non-destructive operations.`,
1327
+ description: "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).",
1250
1328
  required: false,
1251
- usageValue: "true or false"
1329
+ usageValue: "true | false"
1252
1330
  }
1253
1331
  ],
1254
1332
  examples: [
1255
1333
  {
1256
- description: "Request to execute a command",
1334
+ description: "Make a build",
1257
1335
  parameters: [
1258
- {
1259
- name: "command",
1260
- value: "npm run dev"
1261
- },
1262
- {
1263
- name: "requires_approval",
1264
- value: "false"
1265
- }
1336
+ { name: "command", value: "npm run build" },
1337
+ { name: "requires_approval", value: "false" }
1266
1338
  ]
1267
1339
  }
1268
1340
  ],
@@ -2230,6 +2302,22 @@ var getAvailableTools = ({
2230
2302
  };
2231
2303
 
2232
2304
  // src/Agent/parseAssistantMessage.ts
2305
+ function parseNestedParameters(content, parameterPrefix) {
2306
+ const result = {};
2307
+ const nestedParamRegex = new RegExp(`<${parameterPrefix}([^>]+)>([\\s\\S]*?)<\\/${parameterPrefix}\\1>`, "gs");
2308
+ while (true) {
2309
+ const match = nestedParamRegex.exec(content);
2310
+ if (match === null) break;
2311
+ const paramName = match[1];
2312
+ const paramContent = match[2].trim();
2313
+ if (paramContent.includes(`<${parameterPrefix}`)) {
2314
+ result[paramName] = parseNestedParameters(paramContent, parameterPrefix);
2315
+ } else {
2316
+ result[paramName] = paramContent;
2317
+ }
2318
+ }
2319
+ return result;
2320
+ }
2233
2321
  function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
2234
2322
  const parameterPrefix = `${toolNamePrefix}parameter_`;
2235
2323
  const results = [];
@@ -2257,10 +2345,24 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
2257
2345
  for (const param of tool.parameters) {
2258
2346
  const paramName = `${parameterPrefix}${param.name}`;
2259
2347
  const escapedParamName = paramName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2260
- const paramPattern = `<${escapedParamName}>([\\s\\S]*?)<\\/${escapedParamName}>`;
2261
- const paramMatch = fullTagContent.match(new RegExp(paramPattern, "s"));
2262
- if (paramMatch) {
2263
- params[param.name] = paramMatch[1].trim();
2348
+ const paramRegex = new RegExp(`<${escapedParamName}>([\\s\\S]*?)<\\/${escapedParamName}>`, "gs");
2349
+ const paramMatches = [];
2350
+ while (true) {
2351
+ const paramMatch = paramRegex.exec(fullTagContent);
2352
+ if (paramMatch === null) break;
2353
+ paramMatches.push(paramMatch[1].trim());
2354
+ }
2355
+ if (paramMatches.length > 0) {
2356
+ if (paramMatches.length === 1) {
2357
+ const paramContent = paramMatches[0];
2358
+ if (paramContent.includes(`<${parameterPrefix}`)) {
2359
+ params[param.name] = parseNestedParameters(paramContent, parameterPrefix);
2360
+ } else {
2361
+ params[param.name] = paramContent;
2362
+ }
2363
+ } else {
2364
+ params[param.name] = paramMatches;
2365
+ }
2264
2366
  }
2265
2367
  }
2266
2368
  results.push({
@@ -2292,6 +2394,18 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
2292
2394
  }
2293
2395
 
2294
2396
  // src/Agent/prompts.ts
2397
+ var renderParameterValue = (key, value, parameterPrefix) => {
2398
+ if (typeof value === "string") {
2399
+ return `<${parameterPrefix}${key}>${value}</${parameterPrefix}${key}>`;
2400
+ }
2401
+ if (Array.isArray(value)) {
2402
+ return value.map((v) => renderParameterValue(key, v, parameterPrefix)).join("\n");
2403
+ }
2404
+ const inner = Object.entries(value).map(([key2, v]) => renderParameterValue(key2, v, parameterPrefix)).join("\n");
2405
+ return `<${parameterPrefix}${key}>
2406
+ ${inner}
2407
+ </${parameterPrefix}${key}>`;
2408
+ };
2295
2409
  var toolInfoPrompt = (tool, toolNamePrefix, parameterPrefix) => `
2296
2410
  ## ${toolNamePrefix}${tool.name}
2297
2411
 
@@ -2304,11 +2418,11 @@ Usage:
2304
2418
  <${toolNamePrefix}${tool.name}>
2305
2419
  ${tool.parameters.map((param) => `<${parameterPrefix}${param.name}>${param.usageValue}</${parameterPrefix}${param.name}>`).join("\n")}
2306
2420
  </${toolNamePrefix}${tool.name}>`;
2307
- var toolInfoExamplesPrompt = (idx, tool, example, toolNamePrefix, parameterPrefix) => `
2308
- ## Example ${idx + 1}: ${example.description}
2421
+ var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) => `
2422
+ ## Example: ${example.description}
2309
2423
 
2310
2424
  <${toolNamePrefix}${tool.name}>
2311
- ${example.parameters.map((param) => `<${parameterPrefix}${param.name}>${param.value}</${parameterPrefix}${param.name}>`).join("\n")}
2425
+ ${example.parameters.map((param) => `${renderParameterValue(param.name, param.value, parameterPrefix)}`).join("\n")}
2312
2426
  </${toolNamePrefix}${tool.name}>
2313
2427
  `;
2314
2428
  var toolUsePrompt = (tools, toolNamePrefix) => {
@@ -2316,7 +2430,6 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
2316
2430
  return "";
2317
2431
  }
2318
2432
  const parameterPrefix = `${toolNamePrefix}parameter_`;
2319
- let exampleIndex = 0;
2320
2433
  return `
2321
2434
  ====
2322
2435
 
@@ -2334,11 +2447,39 @@ Tool use is formatted using XML-style tags. The tool name is enclosed in opening
2334
2447
  ...
2335
2448
  </${toolNamePrefix}tool_name>
2336
2449
 
2337
- For example:
2450
+ ## Array Parameters
2451
+
2452
+ To create an array of values for a parameter, repeat the parameter tag multiple times:
2453
+
2454
+ <${toolNamePrefix}process_file>
2455
+ <${parameterPrefix}path>test.ts</${parameterPrefix}path>
2456
+ <${parameterPrefix}path>main.ts</${parameterPrefix}path>
2457
+ </${toolNamePrefix}process_file>
2458
+
2459
+ ## Nested Object Parameters
2460
+
2461
+ To create nested objects, nest parameter tags within other parameter tags:
2462
+
2463
+ <${toolNamePrefix}example_tool>
2464
+ <${parameterPrefix}key>
2465
+ <${parameterPrefix}key2>value</${parameterPrefix}key2>
2466
+ <${parameterPrefix}key3>value2</${parameterPrefix}key3>
2467
+ </${parameterPrefix}key>
2468
+ </${toolNamePrefix}example_tool>
2469
+
2470
+ You can also combine array parameters with nested objects:
2338
2471
 
2339
- <${toolNamePrefix}read_file>
2340
- <${parameterPrefix}path>src/main.js</${parameterPrefix}path>
2341
- </${toolNamePrefix}read_file>
2472
+ <${toolNamePrefix}example_tool>
2473
+ <${parameterPrefix}key>
2474
+ <${parameterPrefix}key2>value</${parameterPrefix}key2>
2475
+ <${parameterPrefix}key3>value2</${parameterPrefix}key3>
2476
+ </${parameterPrefix}key>
2477
+ <${parameterPrefix}key>
2478
+ <${parameterPrefix}key2>value3</${parameterPrefix}key2>
2479
+ <${parameterPrefix}key3>value4</${parameterPrefix}key3>
2480
+ <${parameterPrefix}key3>value5</${parameterPrefix}key3>
2481
+ </${parameterPrefix}key>
2482
+ </${toolNamePrefix}example_tool>
2342
2483
 
2343
2484
  Always adhere to this format for the tool use to ensure proper parsing and execution.
2344
2485
 
@@ -2351,7 +2492,7 @@ ${tools.map((tool) => toolInfoPrompt(tool, toolNamePrefix, parameterPrefix)).joi
2351
2492
  ${tools.map((tool) => {
2352
2493
  let promp = "";
2353
2494
  for (const example of tool.examples ?? []) {
2354
- promp += toolInfoExamplesPrompt(exampleIndex++, tool, example, toolNamePrefix, parameterPrefix);
2495
+ promp += toolInfoExamplesPrompt(tool, example, toolNamePrefix, parameterPrefix);
2355
2496
  }
2356
2497
  return promp;
2357
2498
  }).join("")}
@@ -3997,6 +4138,7 @@ export {
3997
4138
  generateGitCommitMessage,
3998
4139
  generateGithubPullRequestDetails,
3999
4140
  generateProjectConfig,
4141
+ getArray,
4000
4142
  getAvailableTools,
4001
4143
  getBoolean,
4002
4144
  getInt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",