@polka-codes/cli 0.7.13 → 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.
- package/dist/index.js +28 -13
- 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.
|
|
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,10 +34684,10 @@ class AgentBase {
|
|
|
34674
34684
|
ai;
|
|
34675
34685
|
config;
|
|
34676
34686
|
handlers;
|
|
34677
|
-
messages;
|
|
34687
|
+
#messages;
|
|
34678
34688
|
constructor(name2, ai, config, messages = []) {
|
|
34679
34689
|
this.ai = ai;
|
|
34680
|
-
this
|
|
34690
|
+
this.#messages = messages;
|
|
34681
34691
|
if (config.agents && config.agents.length > 0) {
|
|
34682
34692
|
const agents = agentsPrompt(config.agents, name2);
|
|
34683
34693
|
config.systemPrompt += `
|
|
@@ -34690,6 +34700,9 @@ ${agents}`;
|
|
|
34690
34700
|
}
|
|
34691
34701
|
this.handlers = handlers;
|
|
34692
34702
|
}
|
|
34703
|
+
get messages() {
|
|
34704
|
+
return this.#messages;
|
|
34705
|
+
}
|
|
34693
34706
|
async#callback(event) {
|
|
34694
34707
|
await this.config.callback?.(event);
|
|
34695
34708
|
}
|
|
@@ -34697,17 +34710,19 @@ ${agents}`;
|
|
|
34697
34710
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
34698
34711
|
return await this.#processLoop(prompt);
|
|
34699
34712
|
}
|
|
34700
|
-
async step(promp) {
|
|
34701
|
-
if (
|
|
34702
|
-
this.#
|
|
34713
|
+
async step(promp, messages) {
|
|
34714
|
+
if (messages) {
|
|
34715
|
+
this.#messages = messages;
|
|
34703
34716
|
}
|
|
34704
|
-
if (this.
|
|
34705
|
-
this.#callback({ kind: "
|
|
34706
|
-
return { type: "UsageExceeded" };
|
|
34717
|
+
if (this.#messages.length === 0) {
|
|
34718
|
+
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
34707
34719
|
}
|
|
34708
34720
|
return await this.#request(promp);
|
|
34709
34721
|
}
|
|
34710
|
-
async handleStepResponse(response) {
|
|
34722
|
+
async handleStepResponse(response, messages) {
|
|
34723
|
+
if (messages) {
|
|
34724
|
+
this.#messages = messages;
|
|
34725
|
+
}
|
|
34711
34726
|
return this.#handleResponse(response);
|
|
34712
34727
|
}
|
|
34713
34728
|
async#processLoop(userMessage) {
|
|
@@ -34734,7 +34749,7 @@ ${agents}`;
|
|
|
34734
34749
|
throw new Error("userMessage is missing");
|
|
34735
34750
|
}
|
|
34736
34751
|
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
34737
|
-
this
|
|
34752
|
+
this.#messages.push({
|
|
34738
34753
|
role: "user",
|
|
34739
34754
|
content: userMessage
|
|
34740
34755
|
});
|
|
@@ -34742,7 +34757,7 @@ ${agents}`;
|
|
|
34742
34757
|
const retryCount = 5;
|
|
34743
34758
|
for (let i3 = 0;i3 < retryCount; i3++) {
|
|
34744
34759
|
currentAssistantMessage = "";
|
|
34745
|
-
const stream = this.ai.send(this.config.systemPrompt, this
|
|
34760
|
+
const stream = this.ai.send(this.config.systemPrompt, this.#messages);
|
|
34746
34761
|
try {
|
|
34747
34762
|
for await (const chunk of stream) {
|
|
34748
34763
|
switch (chunk.type) {
|
|
@@ -34769,7 +34784,7 @@ ${agents}`;
|
|
|
34769
34784
|
if (!currentAssistantMessage) {
|
|
34770
34785
|
throw new Error("No assistant message received");
|
|
34771
34786
|
}
|
|
34772
|
-
this
|
|
34787
|
+
this.#messages.push({
|
|
34773
34788
|
role: "assistant",
|
|
34774
34789
|
content: currentAssistantMessage
|
|
34775
34790
|
});
|