@polka-codes/core 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/_tsup-dts-rollup.d.ts +22 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.js +30 -12
- package/package.json +1 -1
|
@@ -6,13 +6,11 @@ declare abstract class AgentBase {
|
|
|
6
6
|
protected readonly ai: AiServiceBase;
|
|
7
7
|
protected readonly config: Readonly<AgentBaseConfig>;
|
|
8
8
|
protected readonly handlers: Record<string, FullToolInfo>;
|
|
9
|
-
protected readonly messages: MessageParam[];
|
|
10
9
|
constructor(name: string, ai: AiServiceBase, config: AgentBaseConfig, messages?: MessageParam[]);
|
|
10
|
+
get messages(): Readonly<MessageParam[]>;
|
|
11
11
|
start(prompt: string): Promise<ExitReason>;
|
|
12
|
-
step(promp: string): Promise<AssistantMessageContent[]
|
|
13
|
-
|
|
14
|
-
}>;
|
|
15
|
-
handleStepResponse(response: AssistantMessageContent[]): Promise<{
|
|
12
|
+
step(promp: string, messages?: MessageParam[]): Promise<AssistantMessageContent[]>;
|
|
13
|
+
handleStepResponse(response: AssistantMessageContent[], messages?: MessageParam[]): Promise<{
|
|
16
14
|
replay: string;
|
|
17
15
|
} | {
|
|
18
16
|
exit: ExitReason;
|
|
@@ -305,7 +303,10 @@ export { ArchitectAgentOptions }
|
|
|
305
303
|
export { ArchitectAgentOptions as ArchitectAgentOptions_alias_1 }
|
|
306
304
|
export { ArchitectAgentOptions as ArchitectAgentOptions_alias_2 }
|
|
307
305
|
|
|
308
|
-
|
|
306
|
+
declare type AssistantMessageContent = TextContent | ToolUse;
|
|
307
|
+
export { AssistantMessageContent }
|
|
308
|
+
export { AssistantMessageContent as AssistantMessageContent_alias_1 }
|
|
309
|
+
export { AssistantMessageContent as AssistantMessageContent_alias_2 }
|
|
309
310
|
|
|
310
311
|
export declare const basePrompt = "You are a highly skilled software engineer specializing in debugging and fixing code issues. You have extensive experience with:\n- Type systems and type checking\n- Test frameworks and debugging test failures\n- Code quality tools and best practices\n- Systematic debugging approaches";
|
|
311
312
|
|
|
@@ -1753,7 +1754,10 @@ declare type Output = {
|
|
|
1753
1754
|
* // {type: "text", content: "Here are the results"}
|
|
1754
1755
|
* // ]
|
|
1755
1756
|
*/
|
|
1756
|
-
|
|
1757
|
+
declare function parseAssistantMessage(assistantMessage: string, tools: ToolInfo[], toolNamePrefix: string): AssistantMessageContent[];
|
|
1758
|
+
export { parseAssistantMessage }
|
|
1759
|
+
export { parseAssistantMessage as parseAssistantMessage_alias_1 }
|
|
1760
|
+
export { parseAssistantMessage as parseAssistantMessage_alias_2 }
|
|
1757
1761
|
|
|
1758
1762
|
declare enum PermissionLevel {
|
|
1759
1763
|
None = 0,
|
|
@@ -1956,10 +1960,13 @@ export { TaskEventUsageExceeded }
|
|
|
1956
1960
|
export { TaskEventUsageExceeded as TaskEventUsageExceeded_alias_1 }
|
|
1957
1961
|
export { TaskEventUsageExceeded as TaskEventUsageExceeded_alias_2 }
|
|
1958
1962
|
|
|
1959
|
-
|
|
1963
|
+
declare interface TextContent {
|
|
1960
1964
|
type: 'text';
|
|
1961
1965
|
content: string;
|
|
1962
1966
|
}
|
|
1967
|
+
export { TextContent }
|
|
1968
|
+
export { TextContent as TextContent_alias_1 }
|
|
1969
|
+
export { TextContent as TextContent_alias_2 }
|
|
1963
1970
|
|
|
1964
1971
|
declare type ToolExample = {
|
|
1965
1972
|
description: string;
|
|
@@ -2448,11 +2455,14 @@ declare enum ToolResponseType {
|
|
|
2448
2455
|
export { ToolResponseType }
|
|
2449
2456
|
export { ToolResponseType as ToolResponseType_alias_1 }
|
|
2450
2457
|
|
|
2451
|
-
|
|
2458
|
+
declare interface ToolUse {
|
|
2452
2459
|
type: 'tool_use';
|
|
2453
2460
|
name: string;
|
|
2454
2461
|
params: Record<string, string>;
|
|
2455
2462
|
}
|
|
2463
|
+
export { ToolUse }
|
|
2464
|
+
export { ToolUse as ToolUse_alias_1 }
|
|
2465
|
+
export { ToolUse as ToolUse_alias_2 }
|
|
2456
2466
|
|
|
2457
2467
|
declare const toolUsePrompt: (tools: ToolInfo[], toolNamePrefix: string) => string;
|
|
2458
2468
|
export { toolUsePrompt }
|
|
@@ -2478,9 +2488,12 @@ declare class UsageMeter {
|
|
|
2478
2488
|
incrementMessageCount(count?: number): void;
|
|
2479
2489
|
isLimitExceeded(): {
|
|
2480
2490
|
messageCount: boolean;
|
|
2491
|
+
maxMessageCount: number;
|
|
2481
2492
|
cost: boolean;
|
|
2493
|
+
maxCost: number;
|
|
2482
2494
|
result: boolean;
|
|
2483
2495
|
};
|
|
2496
|
+
checkLimit(): void;
|
|
2484
2497
|
/**
|
|
2485
2498
|
* Get current usage totals
|
|
2486
2499
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export { systemInformation } from './_tsup-dts-rollup.js';
|
|
|
51
51
|
export { customInstructions } from './_tsup-dts-rollup.js';
|
|
52
52
|
export { customScripts } from './_tsup-dts-rollup.js';
|
|
53
53
|
export { responsePrompts } from './_tsup-dts-rollup.js';
|
|
54
|
+
export { parseAssistantMessage } from './_tsup-dts-rollup.js';
|
|
55
|
+
export { TextContent } from './_tsup-dts-rollup.js';
|
|
56
|
+
export { ToolUse } from './_tsup-dts-rollup.js';
|
|
57
|
+
export { AssistantMessageContent } from './_tsup-dts-rollup.js';
|
|
54
58
|
export { allTools } from './_tsup-dts-rollup.js';
|
|
55
59
|
export { FilesystemProvider } from './_tsup-dts-rollup.js';
|
|
56
60
|
export { CommandProvider } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var AiServiceBase = class {
|
|
|
11
11
|
this.usageMeter = usageMeter;
|
|
12
12
|
}
|
|
13
13
|
async *send(systemPrompt, messages) {
|
|
14
|
+
this.usageMeter.checkLimit();
|
|
14
15
|
this.usageMeter.incrementMessageCount();
|
|
15
16
|
const stream = this.sendImpl(systemPrompt, messages);
|
|
16
17
|
for await (const chunk of stream) {
|
|
@@ -23,6 +24,7 @@ var AiServiceBase = class {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
async request(systemPrompt, messages) {
|
|
27
|
+
this.usageMeter.checkLimit();
|
|
26
28
|
this.usageMeter.incrementMessageCount();
|
|
27
29
|
const stream = this.sendImpl(systemPrompt, messages);
|
|
28
30
|
const usage = {
|
|
@@ -783,10 +785,20 @@ var UsageMeter = class {
|
|
|
783
785
|
const cost = this.#usage.totalCost >= this.maxCost;
|
|
784
786
|
return {
|
|
785
787
|
messageCount,
|
|
788
|
+
maxMessageCount: this.maxMessageCount,
|
|
786
789
|
cost,
|
|
790
|
+
maxCost: this.maxCost,
|
|
787
791
|
result: messageCount || cost
|
|
788
792
|
};
|
|
789
793
|
}
|
|
794
|
+
checkLimit() {
|
|
795
|
+
const result = this.isLimitExceeded();
|
|
796
|
+
if (result.result) {
|
|
797
|
+
throw new Error(
|
|
798
|
+
`Usage limit exceeded. Message count: ${result.messageCount}/${result.maxMessageCount}, cost: ${result.cost}/${result.maxCost}`
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
790
802
|
/**
|
|
791
803
|
* Get current usage totals
|
|
792
804
|
*/
|
|
@@ -2185,10 +2197,10 @@ var AgentBase = class {
|
|
|
2185
2197
|
ai;
|
|
2186
2198
|
config;
|
|
2187
2199
|
handlers;
|
|
2188
|
-
messages;
|
|
2200
|
+
#messages;
|
|
2189
2201
|
constructor(name, ai, config, messages = []) {
|
|
2190
2202
|
this.ai = ai;
|
|
2191
|
-
this
|
|
2203
|
+
this.#messages = messages;
|
|
2192
2204
|
if (config.agents && config.agents.length > 0) {
|
|
2193
2205
|
const agents = agentsPrompt(config.agents, name);
|
|
2194
2206
|
config.systemPrompt += `
|
|
@@ -2201,6 +2213,9 @@ ${agents}`;
|
|
|
2201
2213
|
}
|
|
2202
2214
|
this.handlers = handlers;
|
|
2203
2215
|
}
|
|
2216
|
+
get messages() {
|
|
2217
|
+
return this.#messages;
|
|
2218
|
+
}
|
|
2204
2219
|
async #callback(event) {
|
|
2205
2220
|
await this.config.callback?.(event);
|
|
2206
2221
|
}
|
|
@@ -2208,17 +2223,19 @@ ${agents}`;
|
|
|
2208
2223
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
2209
2224
|
return await this.#processLoop(prompt5);
|
|
2210
2225
|
}
|
|
2211
|
-
async step(promp) {
|
|
2212
|
-
if (
|
|
2213
|
-
this.#
|
|
2226
|
+
async step(promp, messages) {
|
|
2227
|
+
if (messages) {
|
|
2228
|
+
this.#messages = messages;
|
|
2214
2229
|
}
|
|
2215
|
-
if (this.
|
|
2216
|
-
this.#callback({ kind: "
|
|
2217
|
-
return { type: "UsageExceeded" };
|
|
2230
|
+
if (this.#messages.length === 0) {
|
|
2231
|
+
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
2218
2232
|
}
|
|
2219
2233
|
return await this.#request(promp);
|
|
2220
2234
|
}
|
|
2221
|
-
async handleStepResponse(response) {
|
|
2235
|
+
async handleStepResponse(response, messages) {
|
|
2236
|
+
if (messages) {
|
|
2237
|
+
this.#messages = messages;
|
|
2238
|
+
}
|
|
2222
2239
|
return this.#handleResponse(response);
|
|
2223
2240
|
}
|
|
2224
2241
|
async #processLoop(userMessage) {
|
|
@@ -2245,7 +2262,7 @@ ${agents}`;
|
|
|
2245
2262
|
throw new Error("userMessage is missing");
|
|
2246
2263
|
}
|
|
2247
2264
|
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
2248
|
-
this
|
|
2265
|
+
this.#messages.push({
|
|
2249
2266
|
role: "user",
|
|
2250
2267
|
content: userMessage
|
|
2251
2268
|
});
|
|
@@ -2253,7 +2270,7 @@ ${agents}`;
|
|
|
2253
2270
|
const retryCount = 5;
|
|
2254
2271
|
for (let i = 0; i < retryCount; i++) {
|
|
2255
2272
|
currentAssistantMessage = "";
|
|
2256
|
-
const stream = this.ai.send(this.config.systemPrompt, this
|
|
2273
|
+
const stream = this.ai.send(this.config.systemPrompt, this.#messages);
|
|
2257
2274
|
try {
|
|
2258
2275
|
for await (const chunk of stream) {
|
|
2259
2276
|
switch (chunk.type) {
|
|
@@ -2280,7 +2297,7 @@ ${agents}`;
|
|
|
2280
2297
|
if (!currentAssistantMessage) {
|
|
2281
2298
|
throw new Error("No assistant message received");
|
|
2282
2299
|
}
|
|
2283
|
-
this
|
|
2300
|
+
this.#messages.push({
|
|
2284
2301
|
role: "assistant",
|
|
2285
2302
|
content: currentAssistantMessage
|
|
2286
2303
|
});
|
|
@@ -3432,6 +3449,7 @@ export {
|
|
|
3432
3449
|
makeTool,
|
|
3433
3450
|
modelInfos,
|
|
3434
3451
|
openAiModelInfoSaneDefaults,
|
|
3452
|
+
parseAssistantMessage,
|
|
3435
3453
|
readFile_default as readFile,
|
|
3436
3454
|
removeFile_default as removeFile,
|
|
3437
3455
|
renameFile_default as renameFile,
|