@polka-codes/cli 0.7.12 → 0.7.14

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24629,7 +24629,7 @@ var {
24629
24629
  Help
24630
24630
  } = import__.default;
24631
24631
  // package.json
24632
- var version = "0.7.12";
24632
+ var version = "0.7.14";
24633
24633
 
24634
24634
  // ../core/src/AiService/AiServiceBase.ts
24635
24635
  class AiServiceBase {
@@ -24638,6 +24638,7 @@ class AiServiceBase {
24638
24638
  this.usageMeter = usageMeter;
24639
24639
  }
24640
24640
  async* send(systemPrompt, messages) {
24641
+ this.usageMeter.checkLimit();
24641
24642
  this.usageMeter.incrementMessageCount();
24642
24643
  const stream = this.sendImpl(systemPrompt, messages);
24643
24644
  for await (const chunk of stream) {
@@ -24650,6 +24651,7 @@ class AiServiceBase {
24650
24651
  }
24651
24652
  }
24652
24653
  async request(systemPrompt, messages) {
24654
+ this.usageMeter.checkLimit();
24653
24655
  this.usageMeter.incrementMessageCount();
24654
24656
  const stream = this.sendImpl(systemPrompt, messages);
24655
24657
  const usage = {
@@ -33352,10 +33354,18 @@ class UsageMeter {
33352
33354
  const cost = this.#usage.totalCost >= this.maxCost;
33353
33355
  return {
33354
33356
  messageCount,
33357
+ maxMessageCount: this.maxMessageCount,
33355
33358
  cost,
33359
+ maxCost: this.maxCost,
33356
33360
  result: messageCount || cost
33357
33361
  };
33358
33362
  }
33363
+ checkLimit() {
33364
+ const result = this.isLimitExceeded();
33365
+ if (result.result) {
33366
+ throw new Error(`Usage limit exceeded. Message count: ${result.messageCount}/${result.maxMessageCount}, cost: ${result.cost}/${result.maxCost}`);
33367
+ }
33368
+ }
33359
33369
  get usage() {
33360
33370
  return { ...this.#usage };
33361
33371
  }
@@ -34674,9 +34684,10 @@ class AgentBase {
34674
34684
  ai;
34675
34685
  config;
34676
34686
  handlers;
34677
- messages = [];
34678
- constructor(name2, ai, config) {
34687
+ #messages;
34688
+ constructor(name2, ai, config, messages = []) {
34679
34689
  this.ai = ai;
34690
+ this.#messages = messages;
34680
34691
  if (config.agents && config.agents.length > 0) {
34681
34692
  const agents = agentsPrompt(config.agents, name2);
34682
34693
  config.systemPrompt += `
@@ -34689,6 +34700,9 @@ ${agents}`;
34689
34700
  }
34690
34701
  this.handlers = handlers;
34691
34702
  }
34703
+ get messages() {
34704
+ return this.#messages;
34705
+ }
34692
34706
  async#callback(event) {
34693
34707
  await this.config.callback?.(event);
34694
34708
  }
@@ -34696,6 +34710,21 @@ ${agents}`;
34696
34710
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
34697
34711
  return await this.#processLoop(prompt);
34698
34712
  }
34713
+ async step(promp, messages) {
34714
+ if (messages) {
34715
+ this.#messages = messages;
34716
+ }
34717
+ if (this.#messages.length === 0) {
34718
+ this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
34719
+ }
34720
+ return await this.#request(promp);
34721
+ }
34722
+ async handleStepResponse(response, messages) {
34723
+ if (messages) {
34724
+ this.#messages = messages;
34725
+ }
34726
+ return this.#handleResponse(response);
34727
+ }
34699
34728
  async#processLoop(userMessage) {
34700
34729
  let nextRequest = userMessage;
34701
34730
  while (true) {
@@ -34720,7 +34749,7 @@ ${agents}`;
34720
34749
  throw new Error("userMessage is missing");
34721
34750
  }
34722
34751
  await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
34723
- this.messages.push({
34752
+ this.#messages.push({
34724
34753
  role: "user",
34725
34754
  content: userMessage
34726
34755
  });
@@ -34728,7 +34757,7 @@ ${agents}`;
34728
34757
  const retryCount = 5;
34729
34758
  for (let i3 = 0;i3 < retryCount; i3++) {
34730
34759
  currentAssistantMessage = "";
34731
- const stream = this.ai.send(this.config.systemPrompt, this.messages);
34760
+ const stream = this.ai.send(this.config.systemPrompt, this.#messages);
34732
34761
  try {
34733
34762
  for await (const chunk of stream) {
34734
34763
  switch (chunk.type) {
@@ -34755,7 +34784,7 @@ ${agents}`;
34755
34784
  if (!currentAssistantMessage) {
34756
34785
  throw new Error("No assistant message received");
34757
34786
  }
34758
- this.messages.push({
34787
+ this.#messages.push({
34759
34788
  role: "assistant",
34760
34789
  content: currentAssistantMessage
34761
34790
  });
@@ -47427,12 +47456,12 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
47427
47456
  // src/commands/pr.ts
47428
47457
  import { execSync as execSync2, spawnSync as spawnSync2 } from "node:child_process";
47429
47458
  var prCommand = new Command("pr").description("Create a GitHub pull request").argument("[message]", "Optional context for the commit message generation").action(async (message, _options, command) => {
47430
- const spinner = ora("Gathering information...").start();
47431
47459
  const options = command.parent?.opts() ?? {};
47432
47460
  const { providerConfig, config } = parseOptions(options);
47433
47461
  const { provider: provider2, model, apiKey, parameters } = providerConfig.getConfigForCommand("pr") ?? {};
47434
47462
  console.log("Provider:", provider2);
47435
47463
  console.log("Model:", model);
47464
+ const spinner = ora("Gathering information...").start();
47436
47465
  if (!provider2) {
47437
47466
  console.error('Error: No provider specified. Please run "pokla config" to configure your AI provider.');
47438
47467
  process.exit(1);
@@ -47482,6 +47511,8 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
47482
47511
  commitDiff: diff
47483
47512
  });
47484
47513
  spinner.succeed("Pull request details generated");
47514
+ console.log("Title:", prDetails.response.title);
47515
+ console.log(prDetails.response.description);
47485
47516
  await new Promise((resolve3) => setTimeout(resolve3, 10));
47486
47517
  spawnSync2("gh", ["pr", "create", "--title", prDetails.response.title.trim(), "--body", prDetails.response.description.trim()], {
47487
47518
  stdio: "inherit"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
3
- "version": "0.7.12",
3
+ "version": "0.7.14",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",