@polka-codes/core 0.9.22 → 0.9.24
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 +31 -11
- package/dist/index.d.ts +3 -1
- package/dist/index.js +66 -39
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import type { ModelMessage as ModelMessage_2 } from 'ai';
|
|
|
9
9
|
import type { TextPart } from 'ai';
|
|
10
10
|
import type { ToolModelMessage } from '@ai-sdk/provider-utils';
|
|
11
11
|
import type { UserContent } from '@ai-sdk/provider-utils';
|
|
12
|
+
import type { UserContent as UserContent_2 } from 'ai';
|
|
12
13
|
import type { UserModelMessage } from '@ai-sdk/provider-utils';
|
|
13
14
|
import { z } from 'zod';
|
|
14
15
|
|
|
@@ -1122,8 +1123,9 @@ declare class MultiAgent {
|
|
|
1122
1123
|
agentName: string;
|
|
1123
1124
|
task: string;
|
|
1124
1125
|
context: string;
|
|
1126
|
+
files?: (ImagePart | FilePart)[];
|
|
1125
1127
|
}): Promise<ExitReason>;
|
|
1126
|
-
continueTask(userMessage:
|
|
1128
|
+
continueTask(userMessage: UserContent_2): Promise<ExitReason>;
|
|
1127
1129
|
get hasActiveAgent(): boolean;
|
|
1128
1130
|
abort(): void;
|
|
1129
1131
|
}
|
|
@@ -1329,7 +1331,7 @@ export { systemInformation as systemInformation_alias_2 }
|
|
|
1329
1331
|
/**
|
|
1330
1332
|
* Union type of all possible task events
|
|
1331
1333
|
*/
|
|
1332
|
-
declare type TaskEvent = TaskEventStartTask | TaskEventStartRequest | TaskEventEndRequest | TaskEventUsage | TaskEventText |
|
|
1334
|
+
declare type TaskEvent = TaskEventStartTask | TaskEventStartRequest | TaskEventEndRequest | TaskEventUsage | TaskEventText | TaskEventToolUse | TaskEventToolResult | TaskEventToolError | TaskEventToolPause | TaskEventToolHandOverDelegate | TaskEventUsageExceeded | TaskEventEndTask;
|
|
1333
1335
|
export { TaskEvent }
|
|
1334
1336
|
export { TaskEvent as TaskEvent_alias_1 }
|
|
1335
1337
|
export { TaskEvent as TaskEvent_alias_2 }
|
|
@@ -1430,17 +1432,14 @@ export { TaskEventText }
|
|
|
1430
1432
|
export { TaskEventText as TaskEventText_alias_1 }
|
|
1431
1433
|
export { TaskEventText as TaskEventText_alias_2 }
|
|
1432
1434
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
*/
|
|
1436
|
-
declare interface TaskEventTool extends TaskEventBase {
|
|
1437
|
-
kind: TaskEventKind.ToolUse | TaskEventKind.ToolReply | TaskEventKind.ToolInvalid | TaskEventKind.ToolError | TaskEventKind.ToolInterrupted;
|
|
1435
|
+
declare interface TaskEventToolError extends TaskEventBase {
|
|
1436
|
+
kind: TaskEventKind.ToolError;
|
|
1438
1437
|
tool: string;
|
|
1439
|
-
|
|
1438
|
+
error: ToolResponseError | ToolResponseResult;
|
|
1440
1439
|
}
|
|
1441
|
-
export {
|
|
1442
|
-
export {
|
|
1443
|
-
export {
|
|
1440
|
+
export { TaskEventToolError }
|
|
1441
|
+
export { TaskEventToolError as TaskEventToolError_alias_1 }
|
|
1442
|
+
export { TaskEventToolError as TaskEventToolError_alias_2 }
|
|
1444
1443
|
|
|
1445
1444
|
/**
|
|
1446
1445
|
* Event for tool handover
|
|
@@ -1466,6 +1465,27 @@ export { TaskEventToolPause }
|
|
|
1466
1465
|
export { TaskEventToolPause as TaskEventToolPause_alias_1 }
|
|
1467
1466
|
export { TaskEventToolPause as TaskEventToolPause_alias_2 }
|
|
1468
1467
|
|
|
1468
|
+
declare interface TaskEventToolResult extends TaskEventBase {
|
|
1469
|
+
kind: TaskEventKind.ToolReply | TaskEventKind.ToolInvalid | TaskEventKind.ToolInterrupted;
|
|
1470
|
+
tool: string;
|
|
1471
|
+
content: ToolResponseResult;
|
|
1472
|
+
}
|
|
1473
|
+
export { TaskEventToolResult }
|
|
1474
|
+
export { TaskEventToolResult as TaskEventToolResult_alias_1 }
|
|
1475
|
+
export { TaskEventToolResult as TaskEventToolResult_alias_2 }
|
|
1476
|
+
|
|
1477
|
+
/**
|
|
1478
|
+
* Event for tool-related updates
|
|
1479
|
+
*/
|
|
1480
|
+
declare interface TaskEventToolUse extends TaskEventBase {
|
|
1481
|
+
kind: TaskEventKind.ToolUse;
|
|
1482
|
+
tool: string;
|
|
1483
|
+
params: Record<string, any>;
|
|
1484
|
+
}
|
|
1485
|
+
export { TaskEventToolUse }
|
|
1486
|
+
export { TaskEventToolUse as TaskEventToolUse_alias_1 }
|
|
1487
|
+
export { TaskEventToolUse as TaskEventToolUse_alias_2 }
|
|
1488
|
+
|
|
1469
1489
|
/**
|
|
1470
1490
|
* Event for API usage updates
|
|
1471
1491
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ export { TaskEventStartRequest } from './_tsup-dts-rollup.js';
|
|
|
9
9
|
export { TaskEventEndRequest } from './_tsup-dts-rollup.js';
|
|
10
10
|
export { TaskEventUsage } from './_tsup-dts-rollup.js';
|
|
11
11
|
export { TaskEventText } from './_tsup-dts-rollup.js';
|
|
12
|
-
export {
|
|
12
|
+
export { TaskEventToolUse } from './_tsup-dts-rollup.js';
|
|
13
|
+
export { TaskEventToolResult } from './_tsup-dts-rollup.js';
|
|
14
|
+
export { TaskEventToolError } from './_tsup-dts-rollup.js';
|
|
13
15
|
export { TaskEventToolPause } from './_tsup-dts-rollup.js';
|
|
14
16
|
export { TaskEventToolHandOverDelegate } from './_tsup-dts-rollup.js';
|
|
15
17
|
export { TaskEventUsageExceeded } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -2236,12 +2236,13 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2236
2236
|
return resp;
|
|
2237
2237
|
};
|
|
2238
2238
|
let hasPause = false;
|
|
2239
|
+
const toolUseContents = response.filter((c) => c.type === "tool_use");
|
|
2239
2240
|
outer: for (const content of response) {
|
|
2240
2241
|
switch (content.type) {
|
|
2241
2242
|
case "text":
|
|
2242
2243
|
break;
|
|
2243
2244
|
case "tool_use": {
|
|
2244
|
-
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name,
|
|
2245
|
+
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, params: content.params });
|
|
2245
2246
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
2246
2247
|
switch (toolResp.type) {
|
|
2247
2248
|
case "Reply" /* Reply */: {
|
|
@@ -2250,52 +2251,73 @@ Retrying request ${i + 2} of ${retryCount}`);
|
|
|
2250
2251
|
break;
|
|
2251
2252
|
}
|
|
2252
2253
|
case "Exit" /* Exit */:
|
|
2254
|
+
case "HandOver" /* HandOver */:
|
|
2255
|
+
case "Delegate" /* Delegate */: {
|
|
2256
|
+
if (this.config.toolFormat === "native" && toolUseContents.length > 1) {
|
|
2257
|
+
const message = {
|
|
2258
|
+
type: "Error" /* Error */,
|
|
2259
|
+
message: {
|
|
2260
|
+
type: "error-text",
|
|
2261
|
+
value: `Error: The tool '${content.name}' must be called alone, but it was called with other tools.`
|
|
2262
|
+
},
|
|
2263
|
+
canRetry: false
|
|
2264
|
+
};
|
|
2265
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, error: message });
|
|
2266
|
+
toolResponses.push({
|
|
2267
|
+
type: "response",
|
|
2268
|
+
tool: content.name,
|
|
2269
|
+
response: processResponse(message.message),
|
|
2270
|
+
id: content.id
|
|
2271
|
+
});
|
|
2272
|
+
break;
|
|
2273
|
+
}
|
|
2253
2274
|
if (toolResponses.length > 0) {
|
|
2254
2275
|
break outer;
|
|
2255
2276
|
}
|
|
2256
|
-
|
|
2277
|
+
if (toolResp.type === "Exit" /* Exit */) {
|
|
2278
|
+
return { type: "exit", reason: toolResp };
|
|
2279
|
+
}
|
|
2280
|
+
if (toolResp.type === "HandOver" /* HandOver */) {
|
|
2281
|
+
await this.#callback({
|
|
2282
|
+
kind: "ToolHandOver" /* ToolHandOver */,
|
|
2283
|
+
agent: this,
|
|
2284
|
+
tool: content.name,
|
|
2285
|
+
agentName: toolResp.agentName,
|
|
2286
|
+
task: toolResp.task,
|
|
2287
|
+
context: toolResp.context,
|
|
2288
|
+
files: toolResp.files
|
|
2289
|
+
});
|
|
2290
|
+
return { type: "exit", reason: toolResp };
|
|
2291
|
+
}
|
|
2292
|
+
if (toolResp.type === "Delegate" /* Delegate */) {
|
|
2293
|
+
await this.#callback({
|
|
2294
|
+
kind: "ToolDelegate" /* ToolDelegate */,
|
|
2295
|
+
agent: this,
|
|
2296
|
+
tool: content.name,
|
|
2297
|
+
agentName: toolResp.agentName,
|
|
2298
|
+
task: toolResp.task,
|
|
2299
|
+
context: toolResp.context,
|
|
2300
|
+
files: toolResp.files
|
|
2301
|
+
});
|
|
2302
|
+
return { type: "exit", reason: toolResp };
|
|
2303
|
+
}
|
|
2304
|
+
break;
|
|
2305
|
+
}
|
|
2257
2306
|
case "Invalid" /* Invalid */: {
|
|
2258
2307
|
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
|
|
2259
2308
|
toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
|
|
2260
|
-
|
|
2261
|
-
}
|
|
2262
|
-
case "Error" /* Error */: {
|
|
2263
|
-
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
|
|
2264
|
-
toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
|
|
2265
|
-
break outer;
|
|
2266
|
-
}
|
|
2267
|
-
case "Interrupted" /* Interrupted */:
|
|
2268
|
-
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name, content: toolResp.message });
|
|
2269
|
-
return { type: "exit", reason: toolResp };
|
|
2270
|
-
case "HandOver" /* HandOver */: {
|
|
2271
|
-
if (toolResponses.length > 0) {
|
|
2309
|
+
if (this.config.toolFormat !== "native") {
|
|
2272
2310
|
break outer;
|
|
2273
2311
|
}
|
|
2274
|
-
|
|
2275
|
-
kind: "ToolHandOver" /* ToolHandOver */,
|
|
2276
|
-
agent: this,
|
|
2277
|
-
tool: content.name,
|
|
2278
|
-
agentName: toolResp.agentName,
|
|
2279
|
-
task: toolResp.task,
|
|
2280
|
-
context: toolResp.context,
|
|
2281
|
-
files: toolResp.files
|
|
2282
|
-
});
|
|
2283
|
-
return { type: "exit", reason: toolResp };
|
|
2312
|
+
break;
|
|
2284
2313
|
}
|
|
2285
|
-
case "
|
|
2286
|
-
|
|
2314
|
+
case "Error" /* Error */: {
|
|
2315
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, error: toolResp.message });
|
|
2316
|
+
toolResponses.push({ type: "response", tool: content.name, response: processResponse(toolResp.message), id: content.id });
|
|
2317
|
+
if (this.config.toolFormat !== "native") {
|
|
2287
2318
|
break outer;
|
|
2288
2319
|
}
|
|
2289
|
-
|
|
2290
|
-
kind: "ToolDelegate" /* ToolDelegate */,
|
|
2291
|
-
agent: this,
|
|
2292
|
-
tool: content.name,
|
|
2293
|
-
agentName: toolResp.agentName,
|
|
2294
|
-
task: toolResp.task,
|
|
2295
|
-
context: toolResp.context,
|
|
2296
|
-
files: toolResp.files
|
|
2297
|
-
});
|
|
2298
|
-
return { type: "exit", reason: toolResp };
|
|
2320
|
+
break;
|
|
2299
2321
|
}
|
|
2300
2322
|
case "Pause" /* Pause */: {
|
|
2301
2323
|
await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
|
|
@@ -3049,8 +3071,13 @@ var MultiAgent = class {
|
|
|
3049
3071
|
throw new Error("An active agent already exists");
|
|
3050
3072
|
}
|
|
3051
3073
|
this.#originalTask = options.task;
|
|
3052
|
-
|
|
3053
|
-
|
|
3074
|
+
const userContent = options.files ?? [];
|
|
3075
|
+
userContent.push({
|
|
3076
|
+
type: "text",
|
|
3077
|
+
text: `<task>${options.task}</task>
|
|
3078
|
+
<context>${options.context}</context>`
|
|
3079
|
+
});
|
|
3080
|
+
return this.#startTask(options.agentName, userContent);
|
|
3054
3081
|
}
|
|
3055
3082
|
async continueTask(userMessage) {
|
|
3056
3083
|
if (!this.#agents.length) {
|
|
@@ -3738,7 +3765,7 @@ var handler15 = async (provider, args) => {
|
|
|
3738
3765
|
commandParts.push(commitRange);
|
|
3739
3766
|
}
|
|
3740
3767
|
if (file) {
|
|
3741
|
-
commandParts.push("--", file);
|
|
3768
|
+
commandParts.push("--", `'${file}'`);
|
|
3742
3769
|
}
|
|
3743
3770
|
const command = commandParts.join(" ");
|
|
3744
3771
|
try {
|