@polka-codes/core 0.7.5 → 0.7.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.
@@ -8,10 +8,7 @@ declare abstract class AgentBase {
8
8
  protected readonly handlers: Record<string, FullToolInfo>;
9
9
  protected readonly messages: MessageParam[];
10
10
  constructor(name: string, ai: AiServiceBase, config: AgentBaseConfig);
11
- startTask({ task, context }: {
12
- task: string;
13
- context?: string;
14
- }): Promise<ExitReason>;
11
+ start(prompt: string): Promise<ExitReason>;
15
12
  continueTask(userMessage: string): Promise<ExitReason>;
16
13
  protected abstract onBeforeInvokeTool(name: string, args: Record<string, string>): Promise<ToolResponse | undefined>;
17
14
  get model(): {
@@ -241,9 +238,15 @@ export declare class AnthropicService extends AiServiceBase {
241
238
  sendImpl(systemPrompt: string, messages: MessageParam[]): ApiStream;
242
239
  }
243
240
 
244
- export declare type ApiStream = AsyncGenerator<ApiStreamChunk>;
241
+ declare type ApiStream = AsyncGenerator<ApiStreamChunk>;
242
+ export { ApiStream }
243
+ export { ApiStream as ApiStream_alias_1 }
244
+ export { ApiStream as ApiStream_alias_2 }
245
245
 
246
- export declare type ApiStreamChunk = ApiStreamTextChunk | ApiStreamUsageChunk | ApiStreamReasoningTextChunk;
246
+ declare type ApiStreamChunk = ApiStreamTextChunk | ApiStreamUsageChunk | ApiStreamReasoningTextChunk;
247
+ export { ApiStreamChunk }
248
+ export { ApiStreamChunk as ApiStreamChunk_alias_1 }
249
+ export { ApiStreamChunk as ApiStreamChunk_alias_2 }
247
250
 
248
251
  export declare interface ApiStreamReasoningTextChunk {
249
252
  type: 'reasoning';
@@ -1637,7 +1640,6 @@ declare class MultiAgent {
1637
1640
  startTask(options: {
1638
1641
  agentName: string;
1639
1642
  task: string;
1640
- context?: string;
1641
1643
  }): Promise<ExitReason>;
1642
1644
  continueTask(userMessage: string): Promise<ExitReason>;
1643
1645
  get hasActiveAgent(): boolean;
@@ -1648,7 +1650,7 @@ export { MultiAgent as MultiAgent_alias_2 }
1648
1650
 
1649
1651
  declare type MultiAgentConfig = {
1650
1652
  createAgent: (name: string) => Promise<AgentBase>;
1651
- getContext?: (name: string, context?: string, files?: string[]) => Promise<string>;
1653
+ getPrompt?: (name: string, task: string, context?: string, files?: string[]) => Promise<string>;
1652
1654
  };
1653
1655
  export { MultiAgentConfig }
1654
1656
  export { MultiAgentConfig as MultiAgentConfig_alias_1 }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { AiServiceOptions } from './_tsup-dts-rollup.js';
7
7
  export { AiServiceBase } from './_tsup-dts-rollup.js';
8
8
  export { ModelInfo } from './_tsup-dts-rollup.js';
9
9
  export { ApiUsage } from './_tsup-dts-rollup.js';
10
+ export { ApiStream } from './_tsup-dts-rollup.js';
11
+ export { ApiStreamChunk } from './_tsup-dts-rollup.js';
10
12
  export { allAgents } from './_tsup-dts-rollup.js';
11
13
  export { AgentNameType } from './_tsup-dts-rollup.js';
12
14
  export { TaskEventKind } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -2209,14 +2209,9 @@ ${agents}`;
2209
2209
  async #callback(event) {
2210
2210
  await this.config.callback?.(event);
2211
2211
  }
2212
- async startTask({ task, context }) {
2213
- let text = `<task>${task}</task>`;
2214
- if (context) {
2215
- text += `
2216
- <context>${context}</context>`;
2217
- }
2212
+ async start(prompt5) {
2218
2213
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
2219
- return await this.#processLoop(text);
2214
+ return await this.#processLoop(prompt5);
2220
2215
  }
2221
2216
  async #processLoop(userMessage) {
2222
2217
  let nextRequest = userMessage;
@@ -2944,12 +2939,12 @@ var MultiAgent = class {
2944
2939
  switch (exitReason.type) {
2945
2940
  case "HandOver" /* HandOver */: {
2946
2941
  this.#agents.pop();
2947
- const newContext = await this.#config.getContext?.(exitReason.agentName, exitReason.context, exitReason.files);
2948
- return await this.#startTask(exitReason.agentName, exitReason.task, newContext);
2942
+ const prompt5 = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files) ?? exitReason.task;
2943
+ return await this.#startTask(exitReason.agentName, prompt5);
2949
2944
  }
2950
2945
  case "Delegate" /* Delegate */: {
2951
- const newContext = await this.#config.getContext?.(exitReason.agentName, exitReason.context, exitReason.files);
2952
- const delegateResult = await this.#startTask(exitReason.agentName, exitReason.task, newContext);
2946
+ const prompt5 = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files) ?? exitReason.task;
2947
+ const delegateResult = await this.#startTask(exitReason.agentName, prompt5);
2953
2948
  switch (delegateResult.type) {
2954
2949
  case "HandOver" /* HandOver */:
2955
2950
  case "Delegate" /* Delegate */:
@@ -2970,20 +2965,17 @@ var MultiAgent = class {
2970
2965
  return exitReason;
2971
2966
  }
2972
2967
  }
2973
- async #startTask(agentName, task, context) {
2968
+ async #startTask(agentName, task) {
2974
2969
  const newAgent = await this.#config.createAgent(agentName);
2975
2970
  this.#agents.push(newAgent);
2976
- const exitReason = await newAgent.startTask({
2977
- task,
2978
- context
2979
- });
2971
+ const exitReason = await newAgent.start(task);
2980
2972
  return await this.#handleTaskResult(exitReason);
2981
2973
  }
2982
2974
  async startTask(options) {
2983
2975
  if (this.#agents.length > 0) {
2984
2976
  throw new Error("An active agent already exists");
2985
2977
  }
2986
- return this.#startTask(options.agentName, options.task, options.context);
2978
+ return this.#startTask(options.agentName, options.task);
2987
2979
  }
2988
2980
  async continueTask(userMessage) {
2989
2981
  if (!this.#agents.length) {
@@ -3358,8 +3350,8 @@ var executeAgentTool = async (definition, agent, params) => {
3358
3350
  }
3359
3351
  const exitReason = await agent.startTask({
3360
3352
  agentName: definition.agent,
3361
- task: definition.prompt,
3362
- context: definition.formatInput(params)
3353
+ task: `<task>${definition.prompt}</task>
3354
+ <context>${definition.formatInput(params)}</context>`
3363
3355
  });
3364
3356
  if (exitReason.type === "Exit" /* Exit */) {
3365
3357
  return definition.parseOutput(exitReason.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",