@polka-codes/core 0.7.12 → 0.7.13

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.
@@ -7,8 +7,16 @@ declare abstract class AgentBase {
7
7
  protected readonly config: Readonly<AgentBaseConfig>;
8
8
  protected readonly handlers: Record<string, FullToolInfo>;
9
9
  protected readonly messages: MessageParam[];
10
- constructor(name: string, ai: AiServiceBase, config: AgentBaseConfig);
10
+ constructor(name: string, ai: AiServiceBase, config: AgentBaseConfig, messages?: MessageParam[]);
11
11
  start(prompt: string): Promise<ExitReason>;
12
+ step(promp: string): Promise<AssistantMessageContent[] | {
13
+ type: string;
14
+ }>;
15
+ handleStepResponse(response: AssistantMessageContent[]): Promise<{
16
+ replay: string;
17
+ } | {
18
+ exit: ExitReason;
19
+ }>;
12
20
  continueTask(userMessage: string): Promise<ExitReason>;
13
21
  protected abstract onBeforeInvokeTool(name: string, args: Record<string, string>): Promise<ToolResponse | undefined>;
14
22
  get model(): {
@@ -2392,6 +2400,7 @@ export { ToolResponseError as ToolResponseError_alias_1 }
2392
2400
  declare type ToolResponseExit = {
2393
2401
  type: ToolResponseType.Exit;
2394
2402
  message: string;
2403
+ object?: any;
2395
2404
  };
2396
2405
  export { ToolResponseExit }
2397
2406
  export { ToolResponseExit as ToolResponseExit_alias_1 }
package/dist/index.js CHANGED
@@ -2185,9 +2185,10 @@ var AgentBase = class {
2185
2185
  ai;
2186
2186
  config;
2187
2187
  handlers;
2188
- messages = [];
2189
- constructor(name, ai, config) {
2188
+ messages;
2189
+ constructor(name, ai, config, messages = []) {
2190
2190
  this.ai = ai;
2191
+ this.messages = messages;
2191
2192
  if (config.agents && config.agents.length > 0) {
2192
2193
  const agents = agentsPrompt(config.agents, name);
2193
2194
  config.systemPrompt += `
@@ -2207,6 +2208,19 @@ ${agents}`;
2207
2208
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
2208
2209
  return await this.#processLoop(prompt5);
2209
2210
  }
2211
+ async step(promp) {
2212
+ if (this.messages.length === 0) {
2213
+ this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
2214
+ }
2215
+ if (this.ai.usageMeter.isLimitExceeded().result) {
2216
+ this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
2217
+ return { type: "UsageExceeded" };
2218
+ }
2219
+ return await this.#request(promp);
2220
+ }
2221
+ async handleStepResponse(response) {
2222
+ return this.#handleResponse(response);
2223
+ }
2210
2224
  async #processLoop(userMessage) {
2211
2225
  let nextRequest = userMessage;
2212
2226
  while (true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",