@polka-codes/core 0.9.45 → 0.9.46

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.
@@ -105,25 +105,6 @@ export { agentsPrompt }
105
105
  export { agentsPrompt as agentsPrompt_alias_1 }
106
106
  export { agentsPrompt as agentsPrompt_alias_2 }
107
107
 
108
- declare type AiToolDefinition<Input, Output = string> = {
109
- name: string;
110
- description: string;
111
- prompt: string;
112
- formatInput: (params: Input) => string;
113
- parseOutput: (output: string) => Output;
114
- };
115
- export { AiToolDefinition }
116
- export { AiToolDefinition as AiToolDefinition_alias_1 }
117
- export { AiToolDefinition as AiToolDefinition_alias_2 }
118
-
119
- export declare type AiToolDefinitionWithAgent<Input, Output = string> = AiToolDefinition<Input, Output> & {
120
- agent: (options: SharedAgentOptions) => AgentBase;
121
- };
122
-
123
- export declare type AiToolDefinitionWithMultiAgent<Input, Output = string> = AiToolDefinition<Input, Output> & {
124
- agent: AgentNameType;
125
- };
126
-
127
108
  declare const allAgents: readonly [{
128
109
  readonly name: "architect";
129
110
  readonly responsibilities: ["Analyzing the user’s overall task and requirements.", "Creating plans and making higher-level decisions about system structure and design.", "Reviewing and analyzing existing code or components for maintainability and scalability.", "Laying out the roadmap for implementation."];
@@ -270,7 +251,9 @@ export { CommandProvider as CommandProvider_alias_2 }
270
251
  * The backoff starts at baseSeconds and doubles each time, capped at capSeconds.
271
252
  * Example with base=2, cap=60: 2, 4, 8, 16, 32, 60, 60, ...
272
253
  */
273
- export declare function computeRateLimitBackoffSeconds(count: number, baseSeconds?: number, capSeconds?: number): number;
254
+ declare function computeRateLimitBackoffSeconds(count: number, baseSeconds?: number, capSeconds?: number): number;
255
+ export { computeRateLimitBackoffSeconds }
256
+ export { computeRateLimitBackoffSeconds as computeRateLimitBackoffSeconds_alias_1 }
274
257
 
275
258
  declare type Config = z.infer<typeof configSchema>;
276
259
  export { Config }
@@ -349,10 +332,6 @@ declare const configSchema: z.ZodObject<{
349
332
  export { configSchema }
350
333
  export { configSchema as configSchema_alias_1 }
351
334
 
352
- declare const createNewProject: (agent: MultiAgent, params: string) => Promise<string>;
353
- export { createNewProject }
354
- export { createNewProject as createNewProject_alias_1 }
355
-
356
335
  declare const customInstructions: (customInstructions: string[]) => string;
357
336
  export { customInstructions }
358
337
  export { customInstructions as customInstructions_alias_1 }
@@ -389,7 +368,7 @@ declare const _default: {
389
368
  };
390
369
  export { _default as askFollowupQuestion }
391
370
  export { _default as askFollowupQuestion_alias_1 }
392
- export { _default as default_alias_1 }
371
+ export { _default as default_alias }
393
372
 
394
373
  declare const _default_10: {
395
374
  handler: ToolHandler<{
@@ -406,7 +385,7 @@ declare const _default_10: {
406
385
  path: z.ZodString;
407
386
  }, z.core.$strip>;
408
387
  };
409
- export { _default_10 as default_alias_10 }
388
+ export { _default_10 as default_alias_9 }
410
389
  export { _default_10 as removeFile }
411
390
  export { _default_10 as removeFile_alias_1 }
412
391
 
@@ -427,7 +406,7 @@ declare const _default_11: {
427
406
  target_path: z.ZodString;
428
407
  }, z.core.$strip>;
429
408
  };
430
- export { _default_11 as default_alias_11 }
409
+ export { _default_11 as default_alias_10 }
431
410
  export { _default_11 as renameFile }
432
411
  export { _default_11 as renameFile_alias_1 }
433
412
 
@@ -448,7 +427,7 @@ declare const _default_12: {
448
427
  diff: z.ZodString;
449
428
  }, z.core.$strip>;
450
429
  };
451
- export { _default_12 as default_alias_12 }
430
+ export { _default_12 as default_alias_11 }
452
431
  export { _default_12 as replaceInFile }
453
432
  export { _default_12 as replaceInFile_alias_1 }
454
433
 
@@ -471,7 +450,7 @@ declare const _default_13: {
471
450
  filePattern: z.ZodOptional<z.ZodString>;
472
451
  }, z.core.$strip>;
473
452
  };
474
- export { _default_13 as default_alias_13 }
453
+ export { _default_13 as default_alias_12 }
475
454
  export { _default_13 as searchFiles }
476
455
  export { _default_13 as searchFiles_alias_1 }
477
456
 
@@ -492,7 +471,7 @@ declare const _default_14: {
492
471
  content: z.ZodString;
493
472
  }, z.core.$strip>;
494
473
  };
495
- export { _default_14 as default_alias_14 }
474
+ export { _default_14 as default_alias_13 }
496
475
  export { _default_14 as writeToFile }
497
476
  export { _default_14 as writeToFile_alias_1 }
498
477
 
@@ -513,7 +492,7 @@ declare const _default_2: {
513
492
  };
514
493
  export { _default_2 as attemptCompletion }
515
494
  export { _default_2 as attemptCompletion_alias_1 }
516
- export { _default_2 as default_alias_2 }
495
+ export { _default_2 as default_alias_1 }
517
496
 
518
497
  declare const _default_3: {
519
498
  handler: ToolHandler<{
@@ -536,7 +515,7 @@ declare const _default_3: {
536
515
  files: z.ZodOptional<z.ZodPipe<z.ZodTransform<string[], unknown>, z.ZodArray<z.ZodString>>>;
537
516
  }, z.core.$strip>;
538
517
  };
539
- export { _default_3 as default_alias_3 }
518
+ export { _default_3 as default_alias_2 }
540
519
  export { _default_3 as delegate }
541
520
  export { _default_3 as delegate_alias_1 }
542
521
 
@@ -557,7 +536,7 @@ declare const _default_4: {
557
536
  requiresApproval: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
558
537
  }, z.core.$strip>;
559
538
  };
560
- export { _default_4 as default_alias_4 }
539
+ export { _default_4 as default_alias_3 }
561
540
  export { _default_4 as executeCommand }
562
541
  export { _default_4 as executeCommand_alias_1 }
563
542
 
@@ -576,7 +555,7 @@ declare const _default_5: {
576
555
  url: z.ZodPipe<z.ZodTransform<string[], unknown>, z.ZodArray<z.ZodString>>;
577
556
  }, z.core.$strip>;
578
557
  };
579
- export { _default_5 as default_alias_5 }
558
+ export { _default_5 as default_alias_4 }
580
559
  export { _default_5 as fetchUrl }
581
560
  export { _default_5 as fetchUrl_alias_1 }
582
561
 
@@ -601,7 +580,7 @@ declare const _default_6: {
601
580
  files: z.ZodOptional<z.ZodPipe<z.ZodTransform<string[], unknown>, z.ZodArray<z.ZodString>>>;
602
581
  }, z.core.$strip>;
603
582
  };
604
- export { _default_6 as default_alias_6 }
583
+ export { _default_6 as default_alias_5 }
605
584
  export { _default_6 as handOver }
606
585
  export { _default_6 as handOver_alias_1 }
607
586
 
@@ -626,7 +605,7 @@ declare const _default_7: {
626
605
  includeIgnored: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
627
606
  }, z.core.$strip>;
628
607
  };
629
- export { _default_7 as default_alias_7 }
608
+ export { _default_7 as default_alias_6 }
630
609
  export { _default_7 as listFiles }
631
610
  export { _default_7 as listFiles_alias_1 }
632
611
 
@@ -645,7 +624,7 @@ declare const _default_8: {
645
624
  url: z.ZodString;
646
625
  }, z.core.$strip>;
647
626
  };
648
- export { _default_8 as default_alias_8 }
627
+ export { _default_8 as default_alias_7 }
649
628
  export { _default_8 as readBinaryFile }
650
629
  export { _default_8 as readBinaryFile_alias_1 }
651
630
 
@@ -666,23 +645,10 @@ declare const _default_9: {
666
645
  includeIgnored: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
667
646
  }, z.core.$strip>;
668
647
  };
669
- export { _default_9 as default_alias_9 }
648
+ export { _default_9 as default_alias_8 }
670
649
  export { _default_9 as readFile }
671
650
  export { _default_9 as readFile_alias_1 }
672
651
 
673
- /**
674
- * AI tool for creating new projects based on user specifications.
675
- * Generated by polka.codes
676
- */
677
- export declare const default_alias: {
678
- readonly name: "createNewProject";
679
- readonly description: "Creates a new project";
680
- readonly prompt: "You are an AiTool designed to assist users in creating new projects. Follow these guidelines:\n\n1. **Gather Information:**\n - Begin by asking the user for essential project details, including:\n - Project type (e.g., web, mobile, desktop, etc.)\n - Desired programming languages\n - Preferred frameworks or libraries\n - Build tools and package manager preferences\n - Testing frameworks and patterns\n - Code style and linting preferences\n - Any additional specifications or requirements\n\n2. **Clarification & Confirmation:**\n - Do not make any decisions or assumptions on behalf of the user.\n - Ask clarifying questions if any detail is ambiguous.\n - Confirm each piece of information with the user before proceeding to the next step.\n\n3. **Avoid Redundancy:**\n - Do not repeat questions or details that have already been confirmed.\n - Keep interactions concise and focused on gathering complete and accurate details.\n\n4. **Generate Configuration:**\n - Based on the collected information, generate a .polkacodes.yml configuration file that includes:\n - scripts section with common development commands (test, format, check, etc.)\n - rules section reflecting project conventions and tools\n - excludeFiles section for sensitive files only\n - Example structure:\n ```yaml\n scripts:\n test:\n command: \"[test-command]\"\n description: \"Run tests\"\n format:\n command: \"[format-command]\"\n description: \"Format code\"\n check:\n command: \"[check-command]\"\n description: \"Check code\"\n\n rules:\n - \"[package-manager-rule]\"\n - \"[testing-framework-rule]\"\n - \"[code-style-rule]\"\n - \"[other-rule]\"\n\n excludeFiles:\n - \".env\"\n - \".env.*\"\n ```\n\n5. **Generate Essential Project Files:**\n - Create a .gitattributes file with appropriate configurations:\n - Mark lock files as generated and exclude them from diffs\n - Example for different package managers:\n\n # For Bun\n bun.lock linguist-generated=true\n bun.lock -diff\n\n # For npm\n package-lock.json linguist-generated=true\n package-lock.json -diff\n\n # For Yarn\n yarn.lock linguist-generated=true\n yarn.lock -diff\n\n # For pnpm\n pnpm-lock.yaml linguist-generated=true\n pnpm-lock.yaml -diff\n\n - Include other common configurations as needed based on project type\n\n6. **Handover to Coder Agent:**\n - Once all required information is collected and validated by the user, compile:\n 1. The final project specifications\n 2. The .polkacodes.yml configuration content\n - Clearly hand over these details to the coder agent, instructing them to:\n 1. Create the new project based on the confirmed specifications\n 2. Include the .polkacodes.yml file in the project root\n 3. Include the .gitattributes file with appropriate configurations\n 4. Ensure all specified tools and configurations are properly set up";
681
- readonly formatInput: (params: string) => string;
682
- readonly parseOutput: (output: string) => string;
683
- readonly agent: "architect";
684
- };
685
-
686
652
  /**
687
653
  * Returns the directory portion of a path string.
688
654
  * Strips trailing slashes, then takes everything up to the last slash.
@@ -697,18 +663,6 @@ export { EnableCachePolicy as EnableCachePolicy_alias_1 }
697
663
  export { EnableCachePolicy as EnableCachePolicy_alias_2 }
698
664
  export { EnableCachePolicy as EnableCachePolicy_alias_3 }
699
665
 
700
- declare const executeAgentTool: <T extends AiToolDefinitionWithAgent<any, any>>(definition: T, options: SharedAgentOptions, params: GetInput<T>) => Promise<GetOutput<T>>;
701
- export { executeAgentTool }
702
- export { executeAgentTool as executeAgentTool_alias_1 }
703
-
704
- declare const executeMultiAgentTool: <T extends AiToolDefinitionWithMultiAgent<any, any>>(definition: T, agent: MultiAgent, params: GetInput<T>) => Promise<GetOutput<T>>;
705
- export { executeMultiAgentTool }
706
- export { executeMultiAgentTool as executeMultiAgentTool_alias_1 }
707
-
708
- declare const executeTool: <T extends AiToolDefinition<any, any>>(definition: T, ai: LanguageModelV2, params: GetInput<T>, usageMeter: UsageMeter) => Promise<GetOutput<T>>;
709
- export { executeTool }
710
- export { executeTool as executeTool_alias_1 }
711
-
712
666
  declare type ExitReason = {
713
667
  type: 'UsageExceeded';
714
668
  } | {
@@ -800,18 +754,8 @@ export { getAvailableTools as getAvailableTools_alias_1 }
800
754
 
801
755
  export declare const getBoolean: <T extends string>(args: Partial<Record<T, ToolParameterValue>>, name: T, defaultValue?: boolean) => boolean;
802
756
 
803
- declare type GetInput<T> = T extends AiToolDefinition<infer Input, any> ? Input : never;
804
- export { GetInput }
805
- export { GetInput as GetInput_alias_1 }
806
- export { GetInput as GetInput_alias_2 }
807
-
808
757
  export declare const getInt: <T extends string>(args: Partial<Record<T, ToolParameterValue>>, name: T, defaultValue?: number) => number;
809
758
 
810
- declare type GetOutput<T> = T extends AiToolDefinition<any, infer Output> ? Output : never;
811
- export { GetOutput }
812
- export { GetOutput as GetOutput_alias_1 }
813
- export { GetOutput as GetOutput_alias_2 }
814
-
815
759
  export declare const getString: <T extends string>(args: Partial<Record<T, string>> | ToolParameterValue, name: T, defaultValue?: string) => string;
816
760
 
817
761
  export declare const getStringArray: <T extends string>(args: Partial<Record<T, ToolParameterValue>>, name: T, defaultValue?: string[]) => string[];
@@ -885,18 +829,6 @@ export declare const isAvailable_alias_9: (provider: FilesystemProvider) => bool
885
829
  */
886
830
  export declare function join(...parts: string[]): string;
887
831
 
888
- declare const makeAgentTool: <T extends AiToolDefinitionWithAgent<any, any>>(definition: T) => (options: SharedAgentOptions, params: GetInput<T>) => Promise<GetOutput<T>>;
889
- export { makeAgentTool }
890
- export { makeAgentTool as makeAgentTool_alias_1 }
891
-
892
- declare const makeMultiAgentTool: <T extends AiToolDefinitionWithMultiAgent<any, any>>(definition: T) => (agent: MultiAgent, params: GetInput<T>) => Promise<GetOutput<T>>;
893
- export { makeMultiAgentTool }
894
- export { makeMultiAgentTool as makeMultiAgentTool_alias_1 }
895
-
896
- declare const makeTool: <T extends AiToolDefinition<any, any>>(definition: T) => (ai: LanguageModelV2, params: GetInput<T>, usageMeter: UsageMeter) => Promise<GetOutput<T>>;
897
- export { makeTool }
898
- export { makeTool as makeTool_alias_1 }
899
-
900
832
  declare class MockProvider implements ToolProvider {
901
833
  readFile(_path: string, _includeIgnored?: boolean): Promise<string>;
902
834
  writeFile(_path: string, _content: string): Promise<void>;
@@ -1115,7 +1047,6 @@ export { TaskEvent as TaskEvent_alias_2 }
1115
1047
  */
1116
1048
  declare interface TaskEventBase {
1117
1049
  kind: TaskEventKind;
1118
- agent: AgentBase;
1119
1050
  }
1120
1051
  export { TaskEventBase }
1121
1052
  export { TaskEventBase as TaskEventBase_alias_1 }
@@ -1680,8 +1611,7 @@ declare class UsageMeter {
1680
1611
  };
1681
1612
  /** Merge another UsageMeter's totals into this one. */
1682
1613
  merge(other: UsageMeter): void;
1683
- /** Print a concise usage summary to console. */
1684
- printUsage(customConsole?: Console): void;
1614
+ getUsageText(): string;
1685
1615
  onFinishHandler(llm: LanguageModelV2): (evt: {
1686
1616
  totalUsage: LanguageModelV2Usage;
1687
1617
  providerMetadata: any;
package/dist/index.d.ts CHANGED
@@ -55,16 +55,7 @@ export { systemInformation } from './_tsup-dts-rollup.js';
55
55
  export { customInstructions } from './_tsup-dts-rollup.js';
56
56
  export { customScripts } from './_tsup-dts-rollup.js';
57
57
  export { responsePrompts } from './_tsup-dts-rollup.js';
58
- export { executeTool } from './_tsup-dts-rollup.js';
59
- export { executeMultiAgentTool } from './_tsup-dts-rollup.js';
60
- export { executeAgentTool } from './_tsup-dts-rollup.js';
61
- export { makeTool } from './_tsup-dts-rollup.js';
62
- export { makeMultiAgentTool } from './_tsup-dts-rollup.js';
63
- export { makeAgentTool } from './_tsup-dts-rollup.js';
64
- export { createNewProject } from './_tsup-dts-rollup.js';
65
- export { AiToolDefinition } from './_tsup-dts-rollup.js';
66
- export { GetInput } from './_tsup-dts-rollup.js';
67
- export { GetOutput } from './_tsup-dts-rollup.js';
58
+ export { computeRateLimitBackoffSeconds } from './_tsup-dts-rollup.js';
68
59
  export { configSchema_alias_1 as configSchema } from './_tsup-dts-rollup.js';
69
60
  export { Config_alias_1 as Config } from './_tsup-dts-rollup.js';
70
61
  export { Policies_alias_1 as Policies } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -91,9 +91,9 @@ var handler = async (provider, args) => {
91
91
  }
92
92
  const answers = [];
93
93
  for (const question of questions) {
94
- const { prompt: prompt2, options } = question;
95
- const answer = await provider.askFollowupQuestion(prompt2, options);
96
- answers.push(`<ask_followup_question_answer question="${prompt2}">
94
+ const { prompt, options } = question;
95
+ const answer = await provider.askFollowupQuestion(prompt, options);
96
+ answers.push(`<ask_followup_question_answer question="${prompt}">
97
97
  ${answer}
98
98
  </ask_followup_question_answer>`);
99
99
  }
@@ -268,7 +268,6 @@ var handler4 = async (provider, args) => {
268
268
  }
269
269
  const { command, requiresApproval } = toolInfo4.parameters.parse(args);
270
270
  try {
271
- console.log("Executing command:", command, "Requires approval:", requiresApproval);
272
271
  const result = await provider.executeCommand(command, requiresApproval);
273
272
  let message = `<command>${command}</command>
274
273
  <command_exit_code>${result.exitCode}</command_exit_code>
@@ -1391,12 +1390,9 @@ var UsageMeter = class {
1391
1390
  this.#totals.cost += otherUsage.cost;
1392
1391
  this.#totals.messageCount += otherUsage.messageCount;
1393
1392
  }
1394
- /** Print a concise usage summary to console. */
1395
- printUsage(customConsole = console) {
1393
+ getUsageText() {
1396
1394
  const u = this.usage;
1397
- customConsole.log(
1398
- `Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, output: ${u.output}, cost: $${u.cost.toFixed(4)}`
1399
- );
1395
+ return `Usage - messages: ${u.messageCount}, input: ${u.input}, cached: ${u.cachedRead}, output: ${u.output}, cost: $${u.cost.toFixed(4)}`;
1400
1396
  }
1401
1397
  onFinishHandler(llm) {
1402
1398
  return (evt) => {
@@ -1407,7 +1403,7 @@ var UsageMeter = class {
1407
1403
 
1408
1404
  // src/Agent/AgentBase.ts
1409
1405
  import { jsonSchema, streamText } from "ai";
1410
- import { camelCase } from "lodash";
1406
+ import { camelCase } from "lodash-es";
1411
1407
  import { toJSONSchema } from "zod";
1412
1408
 
1413
1409
  // src/tool-v1-compat.ts
@@ -1980,13 +1976,13 @@ ${instance.prompt}`;
1980
1976
  async #callback(event) {
1981
1977
  await this.config.callback?.(event);
1982
1978
  }
1983
- async start(prompt2) {
1984
- this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
1985
- return await this.#processLoop(prompt2);
1979
+ async start(prompt) {
1980
+ this.#callback({ kind: "StartTask" /* StartTask */, systemPrompt: this.config.systemPrompt });
1981
+ return await this.#processLoop(prompt);
1986
1982
  }
1987
1983
  async step(message) {
1988
1984
  if (this.#messages.length === 0) {
1989
- this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
1985
+ this.#callback({ kind: "StartTask" /* StartTask */, systemPrompt: this.config.systemPrompt });
1990
1986
  }
1991
1987
  return await this.#request(message);
1992
1988
  }
@@ -2005,7 +2001,7 @@ ${instance.prompt}`;
2005
2001
  return { type: "Aborted" };
2006
2002
  }
2007
2003
  if (this.config.usageMeter.isLimitExceeded().result) {
2008
- this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
2004
+ this.#callback({ kind: "UsageExceeded" /* UsageExceeded */ });
2009
2005
  return { type: "UsageExceeded" };
2010
2006
  }
2011
2007
  const response = await this.#request(nextRequest);
@@ -2014,7 +2010,7 @@ ${instance.prompt}`;
2014
2010
  }
2015
2011
  const resp = await this.#handleResponse(response);
2016
2012
  if (resp.type === "exit") {
2017
- this.#callback({ kind: "EndTask" /* EndTask */, agent: this, exitReason: resp.reason });
2013
+ this.#callback({ kind: "EndTask" /* EndTask */, exitReason: resp.reason });
2018
2014
  return resp.reason;
2019
2015
  }
2020
2016
  nextRequest = resp.message;
@@ -2027,7 +2023,7 @@ ${instance.prompt}`;
2027
2023
  if (!userMessage) {
2028
2024
  throw new Error("userMessage is missing");
2029
2025
  }
2030
- await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
2026
+ await this.#callback({ kind: "StartRequest" /* StartRequest */, userMessage });
2031
2027
  this.#messages.push(...userMessage);
2032
2028
  for (const instance of this.#policies) {
2033
2029
  if (instance.onBeforeRequest) {
@@ -2079,10 +2075,10 @@ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current reques
2079
2075
  resetTimeout();
2080
2076
  switch (chunk.type) {
2081
2077
  case "text-delta":
2082
- await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
2078
+ await this.#callback({ kind: "Text" /* Text */, newText: chunk.text });
2083
2079
  break;
2084
2080
  case "reasoning-delta":
2085
- await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
2081
+ await this.#callback({ kind: "Reasoning" /* Reasoning */, newText: chunk.text });
2086
2082
  break;
2087
2083
  case "tool-call":
2088
2084
  break;
@@ -2090,7 +2086,7 @@ Request timeout after ${requestTimeoutSeconds} seconds. Canceling current reques
2090
2086
  },
2091
2087
  onFinish: (evt) => {
2092
2088
  usageMeterOnFinishHandler(evt);
2093
- this.#callback({ kind: "Usage" /* Usage */, agent: this, usage: evt.totalUsage });
2089
+ this.#callback({ kind: "Usage" /* Usage */, usage: evt.totalUsage });
2094
2090
  },
2095
2091
  onError: async (error) => {
2096
2092
  console.error("Error in stream:", error);
@@ -2177,7 +2173,7 @@ Retrying request ${i + 2} of ${retryCount}`);
2177
2173
  }
2178
2174
  return msg.content.map((part) => part.type === "text" || part.type === "reasoning" ? part.text : "").join("");
2179
2175
  }).join("\n");
2180
- await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: assistantText });
2176
+ await this.#callback({ kind: "EndRequest" /* EndRequest */, message: assistantText });
2181
2177
  return respMessages.flatMap((msg) => {
2182
2178
  if (msg.role === "assistant") {
2183
2179
  const content = msg.content;
@@ -2209,7 +2205,7 @@ Retrying request ${i + 2} of ${retryCount}`);
2209
2205
  });
2210
2206
  }).join("\n");
2211
2207
  const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools.map(toToolInfoV1), this.config.toolNamePrefix);
2212
- await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: currentAssistantMessage });
2208
+ await this.#callback({ kind: "EndRequest" /* EndRequest */, message: currentAssistantMessage });
2213
2209
  return ret;
2214
2210
  }
2215
2211
  async #handleResponse(response) {
@@ -2240,11 +2236,11 @@ Retrying request ${i + 2} of ${retryCount}`);
2240
2236
  case "text":
2241
2237
  break;
2242
2238
  case "tool_use": {
2243
- await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, params: content.params });
2239
+ await this.#callback({ kind: "ToolUse" /* ToolUse */, tool: content.name, params: content.params });
2244
2240
  const toolResp = await this.#invokeTool(content.name, content.params);
2245
2241
  switch (toolResp.type) {
2246
2242
  case "Reply" /* Reply */: {
2247
- await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name, content: toolResp.message });
2243
+ await this.#callback({ kind: "ToolReply" /* ToolReply */, tool: content.name, content: toolResp.message });
2248
2244
  toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
2249
2245
  break;
2250
2246
  }
@@ -2260,7 +2256,7 @@ Retrying request ${i + 2} of ${retryCount}`);
2260
2256
  },
2261
2257
  canRetry: false
2262
2258
  };
2263
- await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, error: message });
2259
+ await this.#callback({ kind: "ToolError" /* ToolError */, tool: content.name, error: message });
2264
2260
  toolResponses.push({
2265
2261
  type: "response",
2266
2262
  tool: content.name,
@@ -2278,7 +2274,6 @@ Retrying request ${i + 2} of ${retryCount}`);
2278
2274
  if (toolResp.type === "HandOver" /* HandOver */) {
2279
2275
  await this.#callback({
2280
2276
  kind: "ToolHandOver" /* ToolHandOver */,
2281
- agent: this,
2282
2277
  tool: content.name,
2283
2278
  agentName: toolResp.agentName,
2284
2279
  task: toolResp.task,
@@ -2290,7 +2285,6 @@ Retrying request ${i + 2} of ${retryCount}`);
2290
2285
  if (toolResp.type === "Delegate" /* Delegate */) {
2291
2286
  await this.#callback({
2292
2287
  kind: "ToolDelegate" /* ToolDelegate */,
2293
- agent: this,
2294
2288
  tool: content.name,
2295
2289
  agentName: toolResp.agentName,
2296
2290
  task: toolResp.task,
@@ -2302,7 +2296,7 @@ Retrying request ${i + 2} of ${retryCount}`);
2302
2296
  break;
2303
2297
  }
2304
2298
  case "Invalid" /* Invalid */: {
2305
- await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
2299
+ await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, tool: content.name, content: toolResp.message });
2306
2300
  toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
2307
2301
  if (this.config.toolFormat !== "native") {
2308
2302
  break outer;
@@ -2310,7 +2304,7 @@ Retrying request ${i + 2} of ${retryCount}`);
2310
2304
  break;
2311
2305
  }
2312
2306
  case "Error" /* Error */: {
2313
- await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, error: toolResp.message });
2307
+ await this.#callback({ kind: "ToolError" /* ToolError */, tool: content.name, error: toolResp.message });
2314
2308
  toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
2315
2309
  if (this.config.toolFormat !== "native") {
2316
2310
  break outer;
@@ -2318,7 +2312,7 @@ Retrying request ${i + 2} of ${retryCount}`);
2318
2312
  break;
2319
2313
  }
2320
2314
  case "Pause" /* Pause */: {
2321
- await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
2315
+ await this.#callback({ kind: "ToolPause" /* ToolPause */, tool: content.name, object: toolResp.object });
2322
2316
  toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object, id: content.id });
2323
2317
  hasPause = true;
2324
2318
  }
@@ -3059,24 +3053,24 @@ var MultiAgent = class {
3059
3053
  switch (exitReason.type) {
3060
3054
  case "HandOver" /* HandOver */: {
3061
3055
  this.#agents.pop();
3062
- const prompt2 = await this.#config.getPrompt?.(
3056
+ const prompt = await this.#config.getPrompt?.(
3063
3057
  exitReason.agentName,
3064
3058
  exitReason.task,
3065
3059
  exitReason.context,
3066
3060
  exitReason.files,
3067
3061
  this.#originalTask
3068
3062
  ) ?? exitReason.task;
3069
- return await this.#startTask(exitReason.agentName, prompt2);
3063
+ return await this.#startTask(exitReason.agentName, prompt);
3070
3064
  }
3071
3065
  case "Delegate" /* Delegate */: {
3072
- const prompt2 = await this.#config.getPrompt?.(
3066
+ const prompt = await this.#config.getPrompt?.(
3073
3067
  exitReason.agentName,
3074
3068
  exitReason.task,
3075
3069
  exitReason.context,
3076
3070
  exitReason.files,
3077
3071
  this.#originalTask
3078
3072
  ) ?? exitReason.task;
3079
- const delegateResult = await this.#startTask(exitReason.agentName, prompt2);
3073
+ const delegateResult = await this.#startTask(exitReason.agentName, prompt);
3080
3074
  switch (delegateResult.type) {
3081
3075
  case "HandOver" /* HandOver */:
3082
3076
  case "Delegate" /* Delegate */:
@@ -3320,7 +3314,7 @@ function estimateMessageTokens(msg) {
3320
3314
  }
3321
3315
  return 0;
3322
3316
  }
3323
- var TruncateContextPolicy = () => {
3317
+ var TruncateContextPolicy = (() => {
3324
3318
  return {
3325
3319
  name: "truncatecontext" /* TruncateContext */,
3326
3320
  async onBeforeRequest(agent) {
@@ -3388,163 +3382,10 @@ var TruncateContextPolicy = () => {
3388
3382
  agent.setMessages(truncatedMessages);
3389
3383
  }
3390
3384
  };
3391
- };
3385
+ });
3392
3386
 
3393
3387
  // src/Agent/index.ts
3394
3388
  var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo, codeFixerAgentInfo];
3395
-
3396
- // src/AiTool/index.ts
3397
- import { generateText } from "ai";
3398
-
3399
- // src/AiTool/createNewProject.ts
3400
- var prompt = `You are an AiTool designed to assist users in creating new projects. Follow these guidelines:
3401
-
3402
- 1. **Gather Information:**
3403
- - Begin by asking the user for essential project details, including:
3404
- - Project type (e.g., web, mobile, desktop, etc.)
3405
- - Desired programming languages
3406
- - Preferred frameworks or libraries
3407
- - Build tools and package manager preferences
3408
- - Testing frameworks and patterns
3409
- - Code style and linting preferences
3410
- - Any additional specifications or requirements
3411
-
3412
- 2. **Clarification & Confirmation:**
3413
- - Do not make any decisions or assumptions on behalf of the user.
3414
- - Ask clarifying questions if any detail is ambiguous.
3415
- - Confirm each piece of information with the user before proceeding to the next step.
3416
-
3417
- 3. **Avoid Redundancy:**
3418
- - Do not repeat questions or details that have already been confirmed.
3419
- - Keep interactions concise and focused on gathering complete and accurate details.
3420
-
3421
- 4. **Generate Configuration:**
3422
- - Based on the collected information, generate a .polkacodes.yml configuration file that includes:
3423
- - scripts section with common development commands (test, format, check, etc.)
3424
- - rules section reflecting project conventions and tools
3425
- - excludeFiles section for sensitive files only
3426
- - Example structure:
3427
- \`\`\`yaml
3428
- scripts:
3429
- test:
3430
- command: "[test-command]"
3431
- description: "Run tests"
3432
- format:
3433
- command: "[format-command]"
3434
- description: "Format code"
3435
- check:
3436
- command: "[check-command]"
3437
- description: "Check code"
3438
-
3439
- rules:
3440
- - "[package-manager-rule]"
3441
- - "[testing-framework-rule]"
3442
- - "[code-style-rule]"
3443
- - "[other-rule]"
3444
-
3445
- excludeFiles:
3446
- - ".env"
3447
- - ".env.*"
3448
- \`\`\`
3449
-
3450
- 5. **Generate Essential Project Files:**
3451
- - Create a .gitattributes file with appropriate configurations:
3452
- - Mark lock files as generated and exclude them from diffs
3453
- - Example for different package managers:
3454
-
3455
- # For Bun
3456
- bun.lock linguist-generated=true
3457
- bun.lock -diff
3458
-
3459
- # For npm
3460
- package-lock.json linguist-generated=true
3461
- package-lock.json -diff
3462
-
3463
- # For Yarn
3464
- yarn.lock linguist-generated=true
3465
- yarn.lock -diff
3466
-
3467
- # For pnpm
3468
- pnpm-lock.yaml linguist-generated=true
3469
- pnpm-lock.yaml -diff
3470
-
3471
- - Include other common configurations as needed based on project type
3472
-
3473
- 6. **Handover to Coder Agent:**
3474
- - Once all required information is collected and validated by the user, compile:
3475
- 1. The final project specifications
3476
- 2. The .polkacodes.yml configuration content
3477
- - Clearly hand over these details to the coder agent, instructing them to:
3478
- 1. Create the new project based on the confirmed specifications
3479
- 2. Include the .polkacodes.yml file in the project root
3480
- 3. Include the .gitattributes file with appropriate configurations
3481
- 4. Ensure all specified tools and configurations are properly set up`;
3482
- var createNewProject_default = {
3483
- name: "createNewProject",
3484
- description: "Creates a new project",
3485
- prompt,
3486
- formatInput: (params) => {
3487
- return `<project_name>${params}</project_name>`;
3488
- },
3489
- parseOutput: (output) => {
3490
- return output.trim();
3491
- },
3492
- agent: "architect"
3493
- };
3494
-
3495
- // src/AiTool/index.ts
3496
- var executeTool = async (definition, ai, params, usageMeter) => {
3497
- const resp = await generateText({
3498
- model: ai,
3499
- temperature: 0,
3500
- system: definition.prompt,
3501
- messages: [
3502
- {
3503
- role: "user",
3504
- content: definition.formatInput(params)
3505
- }
3506
- ]
3507
- });
3508
- usageMeter.addUsage(ai, resp);
3509
- return definition.parseOutput(resp.text);
3510
- };
3511
- var executeMultiAgentTool = async (definition, agent, params) => {
3512
- const exitReason = await agent.startTask({
3513
- agentName: definition.agent,
3514
- task: definition.prompt,
3515
- context: definition.formatInput(params)
3516
- });
3517
- if (exitReason.type === "Exit" /* Exit */) {
3518
- return definition.parseOutput(exitReason.message);
3519
- }
3520
- throw new Error(`Tool execution failed: ${exitReason.type}`);
3521
- };
3522
- var executeAgentTool = async (definition, options, params) => {
3523
- const agent = definition.agent(options);
3524
- const exitReason = await agent.start(`${definition.prompt}
3525
-
3526
- ${definition.formatInput(params)}`);
3527
- if (exitReason.type === "Exit" /* Exit */) {
3528
- return definition.parseOutput(exitReason.message);
3529
- }
3530
- throw new Error(`Tool execution failed: ${exitReason.type}`);
3531
- };
3532
- var makeTool = (definition) => {
3533
- return async (ai, params, usageMeter) => {
3534
- return executeTool(definition, ai, params, usageMeter);
3535
- };
3536
- };
3537
- var makeMultiAgentTool = (definition) => {
3538
- return async (agent, params) => {
3539
- return executeMultiAgentTool(definition, agent, params);
3540
- };
3541
- };
3542
- var makeAgentTool = (definition) => {
3543
- return async (options, params) => {
3544
- return executeAgentTool(definition, options, params);
3545
- };
3546
- };
3547
- var createNewProject = makeMultiAgentTool(createNewProject_default);
3548
3389
  export {
3549
3390
  AgentBase,
3550
3391
  AnalyzerAgent,
@@ -3568,22 +3409,16 @@ export {
3568
3409
  capabilities,
3569
3410
  codeFixerAgentInfo,
3570
3411
  coderAgentInfo,
3412
+ computeRateLimitBackoffSeconds,
3571
3413
  configSchema,
3572
- createNewProject,
3573
3414
  customInstructions,
3574
3415
  customScripts,
3575
3416
  delegate_default as delegate,
3576
- executeAgentTool,
3577
3417
  executeCommand_default as executeCommand,
3578
- executeMultiAgentTool,
3579
- executeTool,
3580
3418
  fetchUrl_default as fetchUrl,
3581
3419
  getAvailableTools,
3582
3420
  handOver_default as handOver,
3583
3421
  listFiles_default as listFiles,
3584
- makeAgentTool,
3585
- makeMultiAgentTool,
3586
- makeTool,
3587
3422
  parseAssistantMessage,
3588
3423
  parseJsonFromMarkdown,
3589
3424
  readBinaryFile_default as readBinaryFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.9.45",
3
+ "version": "0.9.46",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",
@@ -18,10 +18,13 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@ai-sdk/provider": "^2.0.0",
21
- "@ai-sdk/provider-utils": "^3.0.10",
22
- "ai": "^5.0.60",
23
- "lodash": "^4.17.21",
21
+ "@ai-sdk/provider-utils": "^3.0.12",
22
+ "ai": "^5.0.68",
23
+ "lodash-es": "^4.17.21",
24
24
  "yaml": "^2.8.1",
25
25
  "zod": "^4.1.12"
26
+ },
27
+ "devDependencies": {
28
+ "@types/lodash-es": "^4.17.12"
26
29
  }
27
30
  }