@polka-codes/cli 0.9.2 → 0.9.4
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 +1189 -592
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18613,7 +18613,7 @@ var require_src5 = __commonJS((exports) => {
|
|
|
18613
18613
|
exports.project = project;
|
|
18614
18614
|
exports.universe = universe;
|
|
18615
18615
|
exports.bulk = bulk;
|
|
18616
|
-
exports.isAvailable =
|
|
18616
|
+
exports.isAvailable = isAvailable15;
|
|
18617
18617
|
exports.resetIsAvailableCache = resetIsAvailableCache;
|
|
18618
18618
|
exports.getGCPResidency = getGCPResidency;
|
|
18619
18619
|
exports.setGCPResidency = setGCPResidency;
|
|
@@ -18759,7 +18759,7 @@ var require_src5 = __commonJS((exports) => {
|
|
|
18759
18759
|
return process.env.DETECT_GCP_RETRIES ? Number(process.env.DETECT_GCP_RETRIES) : 0;
|
|
18760
18760
|
}
|
|
18761
18761
|
var cachedIsAvailableResponse;
|
|
18762
|
-
async function
|
|
18762
|
+
async function isAvailable15() {
|
|
18763
18763
|
if (process.env.METADATA_SERVER_DETECTION) {
|
|
18764
18764
|
const value = process.env.METADATA_SERVER_DETECTION.trim().toLocaleLowerCase();
|
|
18765
18765
|
if (!(value in exports.METADATA_SERVER_DETECTION)) {
|
|
@@ -34399,7 +34399,7 @@ var require_merge2 = __commonJS((exports) => {
|
|
|
34399
34399
|
var identity2 = require_identity2();
|
|
34400
34400
|
var Scalar2 = require_Scalar2();
|
|
34401
34401
|
var MERGE_KEY = "<<";
|
|
34402
|
-
var
|
|
34402
|
+
var merge7 = {
|
|
34403
34403
|
identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
|
|
34404
34404
|
default: "key",
|
|
34405
34405
|
tag: "tag:yaml.org,2002:merge",
|
|
@@ -34409,7 +34409,7 @@ var require_merge2 = __commonJS((exports) => {
|
|
|
34409
34409
|
}),
|
|
34410
34410
|
stringify: () => MERGE_KEY
|
|
34411
34411
|
};
|
|
34412
|
-
var isMergeKey = (ctx, key2) => (
|
|
34412
|
+
var isMergeKey = (ctx, key2) => (merge7.identify(key2) || identity2.isScalar(key2) && (!key2.type || key2.type === Scalar2.Scalar.PLAIN) && merge7.identify(key2.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge7.tag && tag.default);
|
|
34413
34413
|
function addMergeToJSMap(ctx, map5, value) {
|
|
34414
34414
|
value = ctx && identity2.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
34415
34415
|
if (identity2.isSeq(value))
|
|
@@ -34445,21 +34445,21 @@ var require_merge2 = __commonJS((exports) => {
|
|
|
34445
34445
|
}
|
|
34446
34446
|
exports.addMergeToJSMap = addMergeToJSMap;
|
|
34447
34447
|
exports.isMergeKey = isMergeKey;
|
|
34448
|
-
exports.merge =
|
|
34448
|
+
exports.merge = merge7;
|
|
34449
34449
|
});
|
|
34450
34450
|
|
|
34451
34451
|
// ../../node_modules/yaml/dist/nodes/addPairToJSMap.js
|
|
34452
34452
|
var require_addPairToJSMap2 = __commonJS((exports) => {
|
|
34453
34453
|
var log = require_log2();
|
|
34454
|
-
var
|
|
34454
|
+
var merge7 = require_merge2();
|
|
34455
34455
|
var stringify = require_stringify4();
|
|
34456
34456
|
var identity2 = require_identity2();
|
|
34457
34457
|
var toJS = require_toJS2();
|
|
34458
34458
|
function addPairToJSMap(ctx, map5, { key: key2, value }) {
|
|
34459
34459
|
if (identity2.isNode(key2) && key2.addToJSMap)
|
|
34460
34460
|
key2.addToJSMap(ctx, map5, value);
|
|
34461
|
-
else if (
|
|
34462
|
-
|
|
34461
|
+
else if (merge7.isMergeKey(ctx, key2))
|
|
34462
|
+
merge7.addMergeToJSMap(ctx, map5, value);
|
|
34463
34463
|
else {
|
|
34464
34464
|
const jsKey = toJS.toJS(key2, "", ctx);
|
|
34465
34465
|
if (map5 instanceof Map) {
|
|
@@ -35728,7 +35728,7 @@ var require_schema6 = __commonJS((exports) => {
|
|
|
35728
35728
|
var bool = require_bool4();
|
|
35729
35729
|
var float = require_float4();
|
|
35730
35730
|
var int4 = require_int4();
|
|
35731
|
-
var
|
|
35731
|
+
var merge7 = require_merge2();
|
|
35732
35732
|
var omap = require_omap2();
|
|
35733
35733
|
var pairs = require_pairs2();
|
|
35734
35734
|
var set7 = require_set2();
|
|
@@ -35748,7 +35748,7 @@ var require_schema6 = __commonJS((exports) => {
|
|
|
35748
35748
|
float.floatExp,
|
|
35749
35749
|
float.float,
|
|
35750
35750
|
binary.binary,
|
|
35751
|
-
|
|
35751
|
+
merge7.merge,
|
|
35752
35752
|
omap.omap,
|
|
35753
35753
|
pairs.pairs,
|
|
35754
35754
|
set7.set,
|
|
@@ -35771,7 +35771,7 @@ var require_tags2 = __commonJS((exports) => {
|
|
|
35771
35771
|
var schema = require_schema4();
|
|
35772
35772
|
var schema$1 = require_schema5();
|
|
35773
35773
|
var binary = require_binary2();
|
|
35774
|
-
var
|
|
35774
|
+
var merge7 = require_merge2();
|
|
35775
35775
|
var omap = require_omap2();
|
|
35776
35776
|
var pairs = require_pairs2();
|
|
35777
35777
|
var schema$2 = require_schema6();
|
|
@@ -35796,7 +35796,7 @@ var require_tags2 = __commonJS((exports) => {
|
|
|
35796
35796
|
intOct: int4.intOct,
|
|
35797
35797
|
intTime: timestamp.intTime,
|
|
35798
35798
|
map: map5.map,
|
|
35799
|
-
merge:
|
|
35799
|
+
merge: merge7.merge,
|
|
35800
35800
|
null: _null10.nullTag,
|
|
35801
35801
|
omap: omap.omap,
|
|
35802
35802
|
pairs: pairs.pairs,
|
|
@@ -35806,7 +35806,7 @@ var require_tags2 = __commonJS((exports) => {
|
|
|
35806
35806
|
};
|
|
35807
35807
|
var coreKnownTags = {
|
|
35808
35808
|
"tag:yaml.org,2002:binary": binary.binary,
|
|
35809
|
-
"tag:yaml.org,2002:merge":
|
|
35809
|
+
"tag:yaml.org,2002:merge": merge7.merge,
|
|
35810
35810
|
"tag:yaml.org,2002:omap": omap.omap,
|
|
35811
35811
|
"tag:yaml.org,2002:pairs": pairs.pairs,
|
|
35812
35812
|
"tag:yaml.org,2002:set": set7.set,
|
|
@@ -35815,7 +35815,7 @@ var require_tags2 = __commonJS((exports) => {
|
|
|
35815
35815
|
function getTags(customTags, schemaName, addMergeTag) {
|
|
35816
35816
|
const schemaTags = schemas7.get(schemaName);
|
|
35817
35817
|
if (schemaTags && !customTags) {
|
|
35818
|
-
return addMergeTag && !schemaTags.includes(
|
|
35818
|
+
return addMergeTag && !schemaTags.includes(merge7.merge) ? schemaTags.concat(merge7.merge) : schemaTags.slice();
|
|
35819
35819
|
}
|
|
35820
35820
|
let tags = schemaTags;
|
|
35821
35821
|
if (!tags) {
|
|
@@ -35833,7 +35833,7 @@ var require_tags2 = __commonJS((exports) => {
|
|
|
35833
35833
|
tags = customTags(tags.slice());
|
|
35834
35834
|
}
|
|
35835
35835
|
if (addMergeTag)
|
|
35836
|
-
tags = tags.concat(
|
|
35836
|
+
tags = tags.concat(merge7.merge);
|
|
35837
35837
|
return tags.reduce((tags2, tag) => {
|
|
35838
35838
|
const tagObj = typeof tag === "string" ? tagsByName[tag] : tag;
|
|
35839
35839
|
if (!tagObj) {
|
|
@@ -35860,11 +35860,11 @@ var require_Schema2 = __commonJS((exports) => {
|
|
|
35860
35860
|
var sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
35861
35861
|
|
|
35862
35862
|
class Schema2 {
|
|
35863
|
-
constructor({ compat: compat4, customTags, merge:
|
|
35863
|
+
constructor({ compat: compat4, customTags, merge: merge7, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
|
|
35864
35864
|
this.compat = Array.isArray(compat4) ? tags.getTags(compat4, "compat") : compat4 ? tags.getTags(null, compat4) : null;
|
|
35865
35865
|
this.name = typeof schema === "string" && schema || "core";
|
|
35866
35866
|
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
|
|
35867
|
-
this.tags = tags.getTags(customTags, this.name,
|
|
35867
|
+
this.tags = tags.getTags(customTags, this.name, merge7);
|
|
35868
35868
|
this.toStringOptions = toStringDefaults ?? null;
|
|
35869
35869
|
Object.defineProperty(this, identity2.MAP, { value: map5.map });
|
|
35870
35870
|
Object.defineProperty(this, identity2.SCALAR, { value: string11.string });
|
|
@@ -39731,7 +39731,7 @@ var {
|
|
|
39731
39731
|
Help
|
|
39732
39732
|
} = import__.default;
|
|
39733
39733
|
// package.json
|
|
39734
|
-
var version = "0.9.
|
|
39734
|
+
var version = "0.9.4";
|
|
39735
39735
|
|
|
39736
39736
|
// ../../node_modules/@inquirer/core/dist/esm/lib/key.js
|
|
39737
39737
|
var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
|
|
@@ -52171,35 +52171,27 @@ var toolInfo = {
|
|
|
52171
52171
|
description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
|
|
52172
52172
|
parameters: exports_external.object({
|
|
52173
52173
|
questions: exports_external.array(questionObject).describe("One or more follow-up questions you need answered before you can continue.").meta({ usageValue: "questions here" })
|
|
52174
|
-
})
|
|
52175
|
-
|
|
52176
|
-
|
|
52177
|
-
|
|
52178
|
-
|
|
52179
|
-
|
|
52180
|
-
name: "questions",
|
|
52181
|
-
value: { prompt: "What is the target deployment environment?" }
|
|
52174
|
+
}).meta({
|
|
52175
|
+
examples: [
|
|
52176
|
+
{
|
|
52177
|
+
description: "Single clarifying question (no options)",
|
|
52178
|
+
input: {
|
|
52179
|
+
questions: { prompt: "What is the target deployment environment?" }
|
|
52182
52180
|
}
|
|
52183
|
-
|
|
52184
|
-
|
|
52185
|
-
|
|
52186
|
-
|
|
52187
|
-
|
|
52188
|
-
{
|
|
52189
|
-
name: "questions",
|
|
52190
|
-
value: {
|
|
52181
|
+
},
|
|
52182
|
+
{
|
|
52183
|
+
description: "Single question with multiple-choice options",
|
|
52184
|
+
input: {
|
|
52185
|
+
questions: {
|
|
52191
52186
|
prompt: "Which frontend framework are you using?",
|
|
52192
52187
|
options: ["React", "Angular", "Vue", "Svelte"]
|
|
52193
52188
|
}
|
|
52194
52189
|
}
|
|
52195
|
-
|
|
52196
|
-
|
|
52197
|
-
|
|
52198
|
-
|
|
52199
|
-
|
|
52200
|
-
{
|
|
52201
|
-
name: "questions",
|
|
52202
|
-
value: [
|
|
52190
|
+
},
|
|
52191
|
+
{
|
|
52192
|
+
description: "Two related questions in one call",
|
|
52193
|
+
input: {
|
|
52194
|
+
questions: [
|
|
52203
52195
|
{ prompt: "What type of application are you building?" },
|
|
52204
52196
|
{
|
|
52205
52197
|
prompt: "Preferred programming language?",
|
|
@@ -52207,21 +52199,18 @@ var toolInfo = {
|
|
|
52207
52199
|
}
|
|
52208
52200
|
]
|
|
52209
52201
|
}
|
|
52210
|
-
|
|
52211
|
-
|
|
52212
|
-
|
|
52213
|
-
|
|
52214
|
-
|
|
52215
|
-
{
|
|
52216
|
-
name: "questions",
|
|
52217
|
-
value: {
|
|
52202
|
+
},
|
|
52203
|
+
{
|
|
52204
|
+
description: "Binary (yes/no) confirmation",
|
|
52205
|
+
input: {
|
|
52206
|
+
questions: {
|
|
52218
52207
|
prompt: "Is it acceptable to refactor existing tests to improve performance?",
|
|
52219
52208
|
options: ["Yes", "No"]
|
|
52220
52209
|
}
|
|
52221
52210
|
}
|
|
52222
|
-
|
|
52223
|
-
|
|
52224
|
-
|
|
52211
|
+
}
|
|
52212
|
+
]
|
|
52213
|
+
}),
|
|
52225
52214
|
permissionLevel: 0 /* None */
|
|
52226
52215
|
};
|
|
52227
52216
|
var handler = async (provider, args) => {
|
|
@@ -52266,18 +52255,16 @@ var toolInfo2 = {
|
|
|
52266
52255
|
description: "Use this tool when you believe the user’s requested task is complete. Indicate that your work is finished, but acknowledge the user may still provide additional instructions or questions if they want to continue. This tool MUST NOT to be used with any other tool.",
|
|
52267
52256
|
parameters: exports_external.object({
|
|
52268
52257
|
result: exports_external.string().describe("The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.").meta({ usageValue: "Your final result description here" })
|
|
52269
|
-
})
|
|
52270
|
-
|
|
52271
|
-
|
|
52272
|
-
|
|
52273
|
-
|
|
52274
|
-
|
|
52275
|
-
name: "result",
|
|
52276
|
-
value: "Your final result description here"
|
|
52258
|
+
}).meta({
|
|
52259
|
+
examples: [
|
|
52260
|
+
{
|
|
52261
|
+
description: "Request to present the result of the task",
|
|
52262
|
+
input: {
|
|
52263
|
+
result: "Your final result description here"
|
|
52277
52264
|
}
|
|
52278
|
-
|
|
52279
|
-
|
|
52280
|
-
|
|
52265
|
+
}
|
|
52266
|
+
]
|
|
52267
|
+
}),
|
|
52281
52268
|
permissionLevel: 0 /* None */
|
|
52282
52269
|
};
|
|
52283
52270
|
var handler2 = async (provider, args) => {
|
|
@@ -52323,30 +52310,19 @@ var toolInfo3 = {
|
|
|
52323
52310
|
const values = Array.isArray(val) ? val : [val];
|
|
52324
52311
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
52325
52312
|
}, exports_external.array(exports_external.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
|
|
52326
|
-
})
|
|
52327
|
-
|
|
52328
|
-
|
|
52329
|
-
|
|
52330
|
-
|
|
52331
|
-
|
|
52332
|
-
|
|
52333
|
-
|
|
52334
|
-
|
|
52335
|
-
{
|
|
52336
|
-
name: "task",
|
|
52337
|
-
value: "Analyze the authentication implementation"
|
|
52338
|
-
},
|
|
52339
|
-
{
|
|
52340
|
-
name: "context",
|
|
52341
|
-
value: "Need to understand the security implications of the current auth system"
|
|
52342
|
-
},
|
|
52343
|
-
{
|
|
52344
|
-
name: "files",
|
|
52345
|
-
value: "src/auth/login.ts,src/auth/types.ts"
|
|
52313
|
+
}).meta({
|
|
52314
|
+
examples: [
|
|
52315
|
+
{
|
|
52316
|
+
description: "Delegate a code analysis task to the analyzer agent",
|
|
52317
|
+
input: {
|
|
52318
|
+
agentName: "analyzer",
|
|
52319
|
+
task: "Analyze the authentication implementation",
|
|
52320
|
+
context: "Need to understand the security implications of the current auth system",
|
|
52321
|
+
files: "src/auth/login.ts,src/auth/types.ts"
|
|
52346
52322
|
}
|
|
52347
|
-
|
|
52348
|
-
|
|
52349
|
-
|
|
52323
|
+
}
|
|
52324
|
+
]
|
|
52325
|
+
}),
|
|
52350
52326
|
permissionLevel: 0 /* None */
|
|
52351
52327
|
};
|
|
52352
52328
|
var handler3 = async (_provider, args) => {
|
|
@@ -52390,16 +52366,17 @@ var toolInfo4 = {
|
|
|
52390
52366
|
}
|
|
52391
52367
|
return val;
|
|
52392
52368
|
}, exports_external.boolean().optional().default(false)).describe("Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).").meta({ usageValue: "true | false" })
|
|
52369
|
+
}).meta({
|
|
52370
|
+
examples: [
|
|
52371
|
+
{
|
|
52372
|
+
description: "Make a build",
|
|
52373
|
+
input: {
|
|
52374
|
+
command: "npm run build",
|
|
52375
|
+
requiresApproval: "false"
|
|
52376
|
+
}
|
|
52377
|
+
}
|
|
52378
|
+
]
|
|
52393
52379
|
}),
|
|
52394
|
-
examples: [
|
|
52395
|
-
{
|
|
52396
|
-
description: "Make a build",
|
|
52397
|
-
parameters: [
|
|
52398
|
-
{ name: "command", value: "npm run build" },
|
|
52399
|
-
{ name: "requiresApproval", value: "false" }
|
|
52400
|
-
]
|
|
52401
|
-
}
|
|
52402
|
-
],
|
|
52403
52380
|
permissionLevel: 3 /* Arbitrary */
|
|
52404
52381
|
};
|
|
52405
52382
|
var handler4 = async (provider, args) => {
|
|
@@ -52457,36 +52434,28 @@ var toolInfo5 = {
|
|
|
52457
52434
|
const values = Array.isArray(val) ? val : [val];
|
|
52458
52435
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
52459
52436
|
}, exports_external.array(exports_external.string())).describe("One or more URLs to fetch, separated by commas if multiple.").meta({ usageValue: "url" })
|
|
52460
|
-
})
|
|
52461
|
-
|
|
52462
|
-
|
|
52463
|
-
|
|
52464
|
-
|
|
52465
|
-
|
|
52466
|
-
name: "url",
|
|
52467
|
-
value: "https://example.com"
|
|
52437
|
+
}).meta({
|
|
52438
|
+
examples: [
|
|
52439
|
+
{
|
|
52440
|
+
description: "Fetch a single webpage",
|
|
52441
|
+
input: {
|
|
52442
|
+
url: "https://example.com"
|
|
52468
52443
|
}
|
|
52469
|
-
|
|
52470
|
-
|
|
52471
|
-
|
|
52472
|
-
|
|
52473
|
-
|
|
52474
|
-
{
|
|
52475
|
-
name: "url",
|
|
52476
|
-
value: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
|
|
52444
|
+
},
|
|
52445
|
+
{
|
|
52446
|
+
description: "Fetch multiple webpages",
|
|
52447
|
+
input: {
|
|
52448
|
+
url: "https://example.com,https://developer.mozilla.org/en-US/docs/Web/HTTP"
|
|
52477
52449
|
}
|
|
52478
|
-
|
|
52479
|
-
|
|
52480
|
-
|
|
52481
|
-
|
|
52482
|
-
|
|
52483
|
-
{
|
|
52484
|
-
name: "url",
|
|
52485
|
-
value: "https://raw.githubusercontent.com/user/repo/main/README.md"
|
|
52450
|
+
},
|
|
52451
|
+
{
|
|
52452
|
+
description: "Fetch a raw file from GitHub",
|
|
52453
|
+
input: {
|
|
52454
|
+
url: "https://raw.githubusercontent.com/user/repo/main/README.md"
|
|
52486
52455
|
}
|
|
52487
|
-
|
|
52488
|
-
|
|
52489
|
-
|
|
52456
|
+
}
|
|
52457
|
+
]
|
|
52458
|
+
}),
|
|
52490
52459
|
permissionLevel: 1 /* Read */
|
|
52491
52460
|
};
|
|
52492
52461
|
var handler5 = async (provider, args) => {
|
|
@@ -52542,30 +52511,19 @@ var toolInfo6 = {
|
|
|
52542
52511
|
const values = Array.isArray(val) ? val : [val];
|
|
52543
52512
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
52544
52513
|
}, exports_external.array(exports_external.string())).optional().describe("The files relevant to the task. Comma separated paths").meta({ usageValue: "Relevant files" })
|
|
52545
|
-
})
|
|
52546
|
-
|
|
52547
|
-
|
|
52548
|
-
|
|
52549
|
-
|
|
52550
|
-
|
|
52551
|
-
|
|
52552
|
-
|
|
52553
|
-
|
|
52554
|
-
{
|
|
52555
|
-
name: "task",
|
|
52556
|
-
value: "Implement the login feature"
|
|
52557
|
-
},
|
|
52558
|
-
{
|
|
52559
|
-
name: "context",
|
|
52560
|
-
value: "We need a secure login system with email and password"
|
|
52561
|
-
},
|
|
52562
|
-
{
|
|
52563
|
-
name: "files",
|
|
52564
|
-
value: "src/auth/login.ts,src/auth/types.ts"
|
|
52514
|
+
}).meta({
|
|
52515
|
+
examples: [
|
|
52516
|
+
{
|
|
52517
|
+
description: "Hand over a coding task to the coder agent",
|
|
52518
|
+
input: {
|
|
52519
|
+
agentName: "coder",
|
|
52520
|
+
task: "Implement the login feature",
|
|
52521
|
+
context: "We need a secure login system with email and password",
|
|
52522
|
+
files: "src/auth/login.ts,src/auth/types.ts"
|
|
52565
52523
|
}
|
|
52566
|
-
|
|
52567
|
-
|
|
52568
|
-
|
|
52524
|
+
}
|
|
52525
|
+
]
|
|
52526
|
+
}),
|
|
52569
52527
|
permissionLevel: 0 /* None */
|
|
52570
52528
|
};
|
|
52571
52529
|
var handler6 = async (_provider, args) => {
|
|
@@ -52610,22 +52568,17 @@ var toolInfo7 = {
|
|
|
52610
52568
|
}
|
|
52611
52569
|
return val;
|
|
52612
52570
|
}, exports_external.boolean().optional().default(true)).describe("Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.").meta({ usageValue: "true or false (optional)" })
|
|
52613
|
-
})
|
|
52614
|
-
|
|
52615
|
-
|
|
52616
|
-
|
|
52617
|
-
|
|
52618
|
-
|
|
52619
|
-
|
|
52620
|
-
value: "src"
|
|
52621
|
-
},
|
|
52622
|
-
{
|
|
52623
|
-
name: "maxCount",
|
|
52624
|
-
value: "100"
|
|
52571
|
+
}).meta({
|
|
52572
|
+
examples: [
|
|
52573
|
+
{
|
|
52574
|
+
description: "Request to list files",
|
|
52575
|
+
input: {
|
|
52576
|
+
path: "src",
|
|
52577
|
+
maxCount: "100"
|
|
52625
52578
|
}
|
|
52626
|
-
|
|
52627
|
-
|
|
52628
|
-
|
|
52579
|
+
}
|
|
52580
|
+
]
|
|
52581
|
+
}),
|
|
52629
52582
|
permissionLevel: 1 /* Read */
|
|
52630
52583
|
};
|
|
52631
52584
|
var handler7 = async (provider, args) => {
|
|
@@ -52666,27 +52619,22 @@ var toolInfo8 = {
|
|
|
52666
52619
|
const values = Array.isArray(val) ? val : [val];
|
|
52667
52620
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
52668
52621
|
}, exports_external.array(exports_external.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" })
|
|
52669
|
-
})
|
|
52670
|
-
|
|
52671
|
-
|
|
52672
|
-
|
|
52673
|
-
|
|
52674
|
-
|
|
52675
|
-
name: "path",
|
|
52676
|
-
value: "src/main.js"
|
|
52622
|
+
}).meta({
|
|
52623
|
+
examples: [
|
|
52624
|
+
{
|
|
52625
|
+
description: "Request to read the contents of a file",
|
|
52626
|
+
input: {
|
|
52627
|
+
path: "src/main.js"
|
|
52677
52628
|
}
|
|
52678
|
-
|
|
52679
|
-
|
|
52680
|
-
|
|
52681
|
-
|
|
52682
|
-
|
|
52683
|
-
{
|
|
52684
|
-
name: "path",
|
|
52685
|
-
value: "src/main.js,src/index.js"
|
|
52629
|
+
},
|
|
52630
|
+
{
|
|
52631
|
+
description: "Request to read multiple files",
|
|
52632
|
+
input: {
|
|
52633
|
+
path: "src/main.js,src/index.js"
|
|
52686
52634
|
}
|
|
52687
|
-
|
|
52688
|
-
|
|
52689
|
-
|
|
52635
|
+
}
|
|
52636
|
+
]
|
|
52637
|
+
}),
|
|
52690
52638
|
permissionLevel: 1 /* Read */
|
|
52691
52639
|
};
|
|
52692
52640
|
var handler8 = async (provider, args) => {
|
|
@@ -52731,18 +52679,16 @@ var toolInfo9 = {
|
|
|
52731
52679
|
description: "Request to remove a file at the specified path.",
|
|
52732
52680
|
parameters: exports_external.object({
|
|
52733
52681
|
path: exports_external.string().describe("The path of the file to remove").meta({ usageValue: "File path here" })
|
|
52734
|
-
})
|
|
52735
|
-
|
|
52736
|
-
|
|
52737
|
-
|
|
52738
|
-
|
|
52739
|
-
|
|
52740
|
-
name: "path",
|
|
52741
|
-
value: "src/main.js"
|
|
52682
|
+
}).meta({
|
|
52683
|
+
examples: [
|
|
52684
|
+
{
|
|
52685
|
+
description: "Request to remove a file",
|
|
52686
|
+
input: {
|
|
52687
|
+
path: "src/main.js"
|
|
52742
52688
|
}
|
|
52743
|
-
|
|
52744
|
-
|
|
52745
|
-
|
|
52689
|
+
}
|
|
52690
|
+
]
|
|
52691
|
+
}),
|
|
52746
52692
|
permissionLevel: 2 /* Write */
|
|
52747
52693
|
};
|
|
52748
52694
|
var handler9 = async (provider, args) => {
|
|
@@ -52781,22 +52727,17 @@ var toolInfo10 = {
|
|
|
52781
52727
|
parameters: exports_external.object({
|
|
52782
52728
|
source_path: exports_external.string().describe("The current path of the file").meta({ usageValue: "Source file path here" }),
|
|
52783
52729
|
target_path: exports_external.string().describe("The new path for the file").meta({ usageValue: "Target file path here" })
|
|
52784
|
-
})
|
|
52785
|
-
|
|
52786
|
-
|
|
52787
|
-
|
|
52788
|
-
|
|
52789
|
-
|
|
52790
|
-
|
|
52791
|
-
value: "src/old-name.js"
|
|
52792
|
-
},
|
|
52793
|
-
{
|
|
52794
|
-
name: "target_path",
|
|
52795
|
-
value: "src/new-name.js"
|
|
52730
|
+
}).meta({
|
|
52731
|
+
examples: [
|
|
52732
|
+
{
|
|
52733
|
+
description: "Request to rename a file",
|
|
52734
|
+
input: {
|
|
52735
|
+
source_path: "src/old-name.js",
|
|
52736
|
+
target_path: "src/new-name.js"
|
|
52796
52737
|
}
|
|
52797
|
-
|
|
52798
|
-
|
|
52799
|
-
|
|
52738
|
+
}
|
|
52739
|
+
]
|
|
52740
|
+
}),
|
|
52800
52741
|
permissionLevel: 2 /* Write */
|
|
52801
52742
|
};
|
|
52802
52743
|
var handler10 = async (provider, args) => {
|
|
@@ -52925,18 +52866,13 @@ Critical rules:
|
|
|
52925
52866
|
4. Special operations:
|
|
52926
52867
|
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
52927
52868
|
* To delete code: Use empty REPLACE section`).meta({ usageValue: "Search and replace blocks here" })
|
|
52928
|
-
})
|
|
52929
|
-
|
|
52930
|
-
|
|
52931
|
-
|
|
52932
|
-
|
|
52933
|
-
|
|
52934
|
-
|
|
52935
|
-
value: "src/main.js"
|
|
52936
|
-
},
|
|
52937
|
-
{
|
|
52938
|
-
name: "diff",
|
|
52939
|
-
value: `<<<<<<< SEARCH
|
|
52869
|
+
}).meta({
|
|
52870
|
+
examples: [
|
|
52871
|
+
{
|
|
52872
|
+
description: "Request to replace sections of content in a file",
|
|
52873
|
+
input: {
|
|
52874
|
+
path: "src/main.js",
|
|
52875
|
+
diff: `<<<<<<< SEARCH
|
|
52940
52876
|
import React from 'react';
|
|
52941
52877
|
=======
|
|
52942
52878
|
import React, { useState } from 'react';
|
|
@@ -52964,35 +52900,23 @@ return (
|
|
|
52964
52900
|
<div>
|
|
52965
52901
|
>>>>>>> REPLACE`
|
|
52966
52902
|
}
|
|
52967
|
-
|
|
52968
|
-
|
|
52969
|
-
|
|
52970
|
-
|
|
52971
|
-
|
|
52972
|
-
|
|
52973
|
-
name: "path",
|
|
52974
|
-
value: "src/config.js"
|
|
52975
|
-
},
|
|
52976
|
-
{
|
|
52977
|
-
name: "diff",
|
|
52978
|
-
value: `<<<<<<< SEARCH
|
|
52903
|
+
},
|
|
52904
|
+
{
|
|
52905
|
+
description: "Request to perform a simple, single-line replacement",
|
|
52906
|
+
input: {
|
|
52907
|
+
path: "src/config.js",
|
|
52908
|
+
diff: `<<<<<<< SEARCH
|
|
52979
52909
|
const API_URL = 'https://api.example.com';
|
|
52980
52910
|
=======
|
|
52981
52911
|
const API_URL = 'https://api.staging.example.com';
|
|
52982
52912
|
>>>>>>> REPLACE`
|
|
52983
52913
|
}
|
|
52984
|
-
|
|
52985
|
-
|
|
52986
|
-
|
|
52987
|
-
|
|
52988
|
-
|
|
52989
|
-
|
|
52990
|
-
name: "path",
|
|
52991
|
-
value: "src/utils.js"
|
|
52992
|
-
},
|
|
52993
|
-
{
|
|
52994
|
-
name: "diff",
|
|
52995
|
-
value: `<<<<<<< SEARCH
|
|
52914
|
+
},
|
|
52915
|
+
{
|
|
52916
|
+
description: "Request to add a new function to a file",
|
|
52917
|
+
input: {
|
|
52918
|
+
path: "src/utils.js",
|
|
52919
|
+
diff: `<<<<<<< SEARCH
|
|
52996
52920
|
function helperA() {
|
|
52997
52921
|
// ...
|
|
52998
52922
|
}
|
|
@@ -53006,18 +52930,12 @@ function newHelper() {
|
|
|
53006
52930
|
}
|
|
53007
52931
|
>>>>>>> REPLACE`
|
|
53008
52932
|
}
|
|
53009
|
-
|
|
53010
|
-
|
|
53011
|
-
|
|
53012
|
-
|
|
53013
|
-
|
|
53014
|
-
|
|
53015
|
-
name: "path",
|
|
53016
|
-
value: "src/app.js"
|
|
53017
|
-
},
|
|
53018
|
-
{
|
|
53019
|
-
name: "diff",
|
|
53020
|
-
value: `<<<<<<< SEARCH
|
|
52933
|
+
},
|
|
52934
|
+
{
|
|
52935
|
+
description: "Request to delete a block of code from a file",
|
|
52936
|
+
input: {
|
|
52937
|
+
path: "src/app.js",
|
|
52938
|
+
diff: `<<<<<<< SEARCH
|
|
53021
52939
|
function oldFeature() {
|
|
53022
52940
|
// This is no longer needed
|
|
53023
52941
|
}
|
|
@@ -53025,9 +52943,9 @@ function oldFeature() {
|
|
|
53025
52943
|
=======
|
|
53026
52944
|
>>>>>>> REPLACE`
|
|
53027
52945
|
}
|
|
53028
|
-
|
|
53029
|
-
|
|
53030
|
-
|
|
52946
|
+
}
|
|
52947
|
+
]
|
|
52948
|
+
}),
|
|
53031
52949
|
permissionLevel: 2 /* Write */
|
|
53032
52950
|
};
|
|
53033
52951
|
var handler11 = async (provider, args) => {
|
|
@@ -53095,26 +53013,18 @@ var toolInfo12 = {
|
|
|
53095
53013
|
filePattern: exports_external.string().optional().describe('Comma-separated glob pattern to filter files (e.g., "*.ts" for TypeScript files or "*.ts,*.js" for both TypeScript and JavaScript files). If not provided, it will search all files (*).').meta({
|
|
53096
53014
|
usageValue: "file pattern here (optional)"
|
|
53097
53015
|
})
|
|
53098
|
-
})
|
|
53099
|
-
|
|
53100
|
-
|
|
53101
|
-
|
|
53102
|
-
|
|
53103
|
-
|
|
53104
|
-
|
|
53105
|
-
|
|
53106
|
-
},
|
|
53107
|
-
{
|
|
53108
|
-
name: "regex",
|
|
53109
|
-
value: "^components/"
|
|
53110
|
-
},
|
|
53111
|
-
{
|
|
53112
|
-
name: "filePattern",
|
|
53113
|
-
value: "*.ts,*.tsx"
|
|
53016
|
+
}).meta({
|
|
53017
|
+
examples: [
|
|
53018
|
+
{
|
|
53019
|
+
description: "Request to perform a regex search across files",
|
|
53020
|
+
input: {
|
|
53021
|
+
path: "src",
|
|
53022
|
+
regex: "^components/",
|
|
53023
|
+
filePattern: "*.ts,*.tsx"
|
|
53114
53024
|
}
|
|
53115
|
-
|
|
53116
|
-
|
|
53117
|
-
|
|
53025
|
+
}
|
|
53026
|
+
]
|
|
53027
|
+
}),
|
|
53118
53028
|
permissionLevel: 1 /* Read */
|
|
53119
53029
|
};
|
|
53120
53030
|
var handler12 = async (provider, args) => {
|
|
@@ -53160,18 +53070,13 @@ var toolInfo13 = {
|
|
|
53160
53070
|
parameters: exports_external.object({
|
|
53161
53071
|
path: exports_external.string().describe("The path of the file to write to").meta({ usageValue: "File path here" }),
|
|
53162
53072
|
content: exports_external.string().describe("The content to write to the file. ALWAYS provide the COMPLETE intended content of the file, without any truncation or omissions. You MUST include ALL parts of the file, even if they haven't been modified.").meta({ usageValue: "Your file content here" })
|
|
53163
|
-
})
|
|
53164
|
-
|
|
53165
|
-
|
|
53166
|
-
|
|
53167
|
-
|
|
53168
|
-
|
|
53169
|
-
|
|
53170
|
-
value: "src/main.js"
|
|
53171
|
-
},
|
|
53172
|
-
{
|
|
53173
|
-
name: "content",
|
|
53174
|
-
value: `import React from 'react';
|
|
53073
|
+
}).meta({
|
|
53074
|
+
examples: [
|
|
53075
|
+
{
|
|
53076
|
+
description: "Request to write content to a file",
|
|
53077
|
+
input: {
|
|
53078
|
+
path: "src/main.js",
|
|
53079
|
+
content: `import React from 'react';
|
|
53175
53080
|
|
|
53176
53081
|
function App() {
|
|
53177
53082
|
return (
|
|
@@ -53184,9 +53089,9 @@ function App() {
|
|
|
53184
53089
|
export default App;
|
|
53185
53090
|
`
|
|
53186
53091
|
}
|
|
53187
|
-
|
|
53188
|
-
|
|
53189
|
-
|
|
53092
|
+
}
|
|
53093
|
+
]
|
|
53094
|
+
}),
|
|
53190
53095
|
permissionLevel: 2 /* Write */
|
|
53191
53096
|
};
|
|
53192
53097
|
var handler13 = async (provider, args) => {
|
|
@@ -53246,45 +53151,6 @@ var getAvailableTools = ({
|
|
|
53246
53151
|
return tools;
|
|
53247
53152
|
};
|
|
53248
53153
|
|
|
53249
|
-
// ../core/src/tool-v1-compat.ts
|
|
53250
|
-
function zodSchemaToParameters(schema) {
|
|
53251
|
-
const parameters = [];
|
|
53252
|
-
const { shape } = schema;
|
|
53253
|
-
for (const name in shape) {
|
|
53254
|
-
const def = shape[name];
|
|
53255
|
-
const isOptional = def.safeParse(undefined).success;
|
|
53256
|
-
const description = def.description || "";
|
|
53257
|
-
const param = {
|
|
53258
|
-
name,
|
|
53259
|
-
description,
|
|
53260
|
-
required: !isOptional
|
|
53261
|
-
};
|
|
53262
|
-
const usageValue = def.meta()?.usageValue;
|
|
53263
|
-
if (usageValue) {
|
|
53264
|
-
param.usageValue = usageValue;
|
|
53265
|
-
}
|
|
53266
|
-
if (def instanceof exports_external.ZodObject) {
|
|
53267
|
-
param.children = zodSchemaToParameters(def);
|
|
53268
|
-
} else if (def instanceof exports_external.ZodArray) {
|
|
53269
|
-
param.allowMultiple = true;
|
|
53270
|
-
const element = def.element;
|
|
53271
|
-
if (element instanceof exports_external.ZodObject) {
|
|
53272
|
-
param.children = zodSchemaToParameters(element);
|
|
53273
|
-
}
|
|
53274
|
-
}
|
|
53275
|
-
parameters.push(param);
|
|
53276
|
-
}
|
|
53277
|
-
return parameters;
|
|
53278
|
-
}
|
|
53279
|
-
function toToolInfoV1(tool) {
|
|
53280
|
-
const { parameters: zodSchema, ...rest } = tool;
|
|
53281
|
-
const v1Parameters = zodSchemaToParameters(zodSchema);
|
|
53282
|
-
return {
|
|
53283
|
-
...rest,
|
|
53284
|
-
parameters: v1Parameters
|
|
53285
|
-
};
|
|
53286
|
-
}
|
|
53287
|
-
|
|
53288
53154
|
// ../core/src/UsageMeter.ts
|
|
53289
53155
|
class UsageMeter {
|
|
53290
53156
|
#totals = { input: 0, output: 0, cachedRead: 0, cost: 0 };
|
|
@@ -76245,6 +76111,53 @@ var JSONRPCMessageSchema = exports_external2.union([
|
|
|
76245
76111
|
JSONRPCErrorSchema
|
|
76246
76112
|
]);
|
|
76247
76113
|
|
|
76114
|
+
// ../core/src/Agent/AgentBase.ts
|
|
76115
|
+
var import_lodash = __toESM(require_lodash(), 1);
|
|
76116
|
+
|
|
76117
|
+
// ../core/src/tool-v1-compat.ts
|
|
76118
|
+
function zodSchemaToParameters(schema) {
|
|
76119
|
+
const parameters = [];
|
|
76120
|
+
const { shape } = schema;
|
|
76121
|
+
for (const name17 in shape) {
|
|
76122
|
+
const def = shape[name17];
|
|
76123
|
+
const isOptional = def.safeParse(undefined).success;
|
|
76124
|
+
const description = def.description || "";
|
|
76125
|
+
const param = {
|
|
76126
|
+
name: name17,
|
|
76127
|
+
description,
|
|
76128
|
+
required: !isOptional
|
|
76129
|
+
};
|
|
76130
|
+
const usageValue = def.meta()?.usageValue;
|
|
76131
|
+
if (usageValue) {
|
|
76132
|
+
param.usageValue = usageValue;
|
|
76133
|
+
}
|
|
76134
|
+
if (def instanceof exports_external.ZodObject) {
|
|
76135
|
+
param.children = zodSchemaToParameters(def);
|
|
76136
|
+
} else if (def instanceof exports_external.ZodArray) {
|
|
76137
|
+
param.allowMultiple = true;
|
|
76138
|
+
const element = def.element;
|
|
76139
|
+
if (element instanceof exports_external.ZodObject) {
|
|
76140
|
+
param.children = zodSchemaToParameters(element);
|
|
76141
|
+
}
|
|
76142
|
+
}
|
|
76143
|
+
parameters.push(param);
|
|
76144
|
+
}
|
|
76145
|
+
return parameters;
|
|
76146
|
+
}
|
|
76147
|
+
function toToolInfoV1(tool2) {
|
|
76148
|
+
const { parameters: zodSchema2, ...rest } = tool2;
|
|
76149
|
+
const v1Parameters = zodSchemaToParameters(zodSchema2);
|
|
76150
|
+
const examples = zodSchema2.meta()?.examples;
|
|
76151
|
+
const v1Tool = {
|
|
76152
|
+
...rest,
|
|
76153
|
+
parameters: v1Parameters
|
|
76154
|
+
};
|
|
76155
|
+
if (examples) {
|
|
76156
|
+
v1Tool.examples = examples;
|
|
76157
|
+
}
|
|
76158
|
+
return v1Tool;
|
|
76159
|
+
}
|
|
76160
|
+
|
|
76248
76161
|
// ../core/src/Agent/parseAssistantMessage.ts
|
|
76249
76162
|
function parseNestedParameters(content, parameterPrefix, childrenParams) {
|
|
76250
76163
|
const result = {};
|
|
@@ -76418,7 +76331,7 @@ var toolInfoExamplesPrompt = (tool2, example, toolNamePrefix, parameterPrefix) =
|
|
|
76418
76331
|
## Example: ${example.description}
|
|
76419
76332
|
|
|
76420
76333
|
<${toolNamePrefix}${tool2.name}>
|
|
76421
|
-
${example.
|
|
76334
|
+
${Object.entries(example.input).map(([name17, value]) => renderParameterValue(name17, value, parameterPrefix)).join(`
|
|
76422
76335
|
`)}
|
|
76423
76336
|
</${toolNamePrefix}${tool2.name}>
|
|
76424
76337
|
`;
|
|
@@ -76427,6 +76340,7 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
|
|
|
76427
76340
|
return "";
|
|
76428
76341
|
}
|
|
76429
76342
|
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
76343
|
+
const v1Tools = tools.map(toToolInfoV1);
|
|
76430
76344
|
return `
|
|
76431
76345
|
====
|
|
76432
76346
|
|
|
@@ -76485,11 +76399,11 @@ Always adhere to this format, ensuring every opening tag has a matching closing
|
|
|
76485
76399
|
NEVER surround tool use with triple backticks (\`\`\`).
|
|
76486
76400
|
|
|
76487
76401
|
# Tools
|
|
76488
|
-
${
|
|
76402
|
+
${v1Tools.map((tool2) => toolInfoPrompt(tool2, toolNamePrefix, parameterPrefix)).join(`
|
|
76489
76403
|
`)}
|
|
76490
76404
|
|
|
76491
76405
|
# Tool Use Examples
|
|
76492
|
-
${
|
|
76406
|
+
${v1Tools.map((tool2) => {
|
|
76493
76407
|
let promp = "";
|
|
76494
76408
|
for (const example of tool2.examples ?? []) {
|
|
76495
76409
|
promp += toolInfoExamplesPrompt(tool2, example, toolNamePrefix, parameterPrefix);
|
|
@@ -76582,6 +76496,8 @@ e.g. <tool_tool_name>tool_name</tool_tool_name>
|
|
|
76582
76496
|
Ensure the opening and closing tags are correctly nested and closed, and that you are using the correct tool name.
|
|
76583
76497
|
Avoid unnecessary text or symbols before or after the tool use.
|
|
76584
76498
|
Avoid unnecessary escape characters or special characters.
|
|
76499
|
+
`,
|
|
76500
|
+
requireUseToolNative: `Error: No tool use detected. You MUST use a tool before proceeding.
|
|
76585
76501
|
`,
|
|
76586
76502
|
toolResults: (tool2, result) => {
|
|
76587
76503
|
if (typeof result === "string") {
|
|
@@ -76620,6 +76536,7 @@ class AgentBase {
|
|
|
76620
76536
|
config;
|
|
76621
76537
|
handlers;
|
|
76622
76538
|
#policies;
|
|
76539
|
+
#toolSet;
|
|
76623
76540
|
#messages = [];
|
|
76624
76541
|
#aborted = false;
|
|
76625
76542
|
#abortController;
|
|
@@ -76657,6 +76574,20 @@ ${instance.prompt}`;
|
|
|
76657
76574
|
role: "system",
|
|
76658
76575
|
content: this.config.systemPrompt
|
|
76659
76576
|
});
|
|
76577
|
+
if (this.config.toolFormat === "native") {
|
|
76578
|
+
const tools = {};
|
|
76579
|
+
for (const tool2 of Object.values(this.handlers)) {
|
|
76580
|
+
const toolName = import_lodash.camelCase(tool2.name);
|
|
76581
|
+
tools[toolName] = {
|
|
76582
|
+
description: tool2.description,
|
|
76583
|
+
inputSchema: jsonSchema(toJSONSchema(tool2.parameters))
|
|
76584
|
+
};
|
|
76585
|
+
this.handlers[toolName] = tool2;
|
|
76586
|
+
}
|
|
76587
|
+
this.#toolSet = tools;
|
|
76588
|
+
} else {
|
|
76589
|
+
this.#toolSet = {};
|
|
76590
|
+
}
|
|
76660
76591
|
}
|
|
76661
76592
|
abort() {
|
|
76662
76593
|
this.#aborted = true;
|
|
@@ -76684,13 +76615,19 @@ ${instance.prompt}`;
|
|
|
76684
76615
|
if (this.#messages.length === 0) {
|
|
76685
76616
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
76686
76617
|
}
|
|
76687
|
-
return await this.#request(
|
|
76618
|
+
return await this.#request({
|
|
76619
|
+
role: "user",
|
|
76620
|
+
content: prompt
|
|
76621
|
+
});
|
|
76688
76622
|
}
|
|
76689
76623
|
async handleStepResponse(response) {
|
|
76690
76624
|
return this.#handleResponse(response);
|
|
76691
76625
|
}
|
|
76692
76626
|
async#processLoop(userMessage) {
|
|
76693
|
-
let nextRequest =
|
|
76627
|
+
let nextRequest = {
|
|
76628
|
+
role: "user",
|
|
76629
|
+
content: userMessage
|
|
76630
|
+
};
|
|
76694
76631
|
while (true) {
|
|
76695
76632
|
if (this.#aborted) {
|
|
76696
76633
|
return { type: "Aborted" };
|
|
@@ -76719,10 +76656,7 @@ ${instance.prompt}`;
|
|
|
76719
76656
|
throw new Error("userMessage is missing");
|
|
76720
76657
|
}
|
|
76721
76658
|
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
76722
|
-
this.#messages.push(
|
|
76723
|
-
role: "user",
|
|
76724
|
-
content: userMessage
|
|
76725
|
-
});
|
|
76659
|
+
this.#messages.push(userMessage);
|
|
76726
76660
|
for (const instance of this.#policies) {
|
|
76727
76661
|
if (instance.onBeforeRequest) {
|
|
76728
76662
|
await instance.onBeforeRequest(this);
|
|
@@ -76734,96 +76668,132 @@ ${instance.prompt}`;
|
|
|
76734
76668
|
messages = await instance.prepareMessages(this, messages);
|
|
76735
76669
|
}
|
|
76736
76670
|
}
|
|
76737
|
-
let currentAssistantMessage = "";
|
|
76738
76671
|
const retryCount = this.config.retryCount ?? 5;
|
|
76739
|
-
const requestTimeoutSeconds = this.config.requestTimeoutSeconds ??
|
|
76672
|
+
const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 90;
|
|
76673
|
+
let respMessages = [];
|
|
76740
76674
|
for (let i = 0;i < retryCount; i++) {
|
|
76741
|
-
|
|
76675
|
+
if (this.#aborted) {
|
|
76676
|
+
break;
|
|
76677
|
+
}
|
|
76678
|
+
respMessages = [];
|
|
76742
76679
|
let timeout;
|
|
76680
|
+
let requestAbortController;
|
|
76681
|
+
requestAbortController = new AbortController;
|
|
76682
|
+
this.#abortController = requestAbortController;
|
|
76743
76683
|
const resetTimeout = () => {
|
|
76744
76684
|
if (timeout) {
|
|
76745
76685
|
clearTimeout(timeout);
|
|
76746
76686
|
}
|
|
76747
|
-
if (requestTimeoutSeconds > 0) {
|
|
76687
|
+
if (requestTimeoutSeconds > 0 && requestAbortController) {
|
|
76748
76688
|
timeout = setTimeout(() => {
|
|
76749
|
-
console.debug(`
|
|
76750
|
-
|
|
76689
|
+
console.debug(`Request timeout after ${requestTimeoutSeconds} seconds. Canceling current request attempt ${i + 1}/${retryCount}.`);
|
|
76690
|
+
requestAbortController?.abort();
|
|
76751
76691
|
}, requestTimeoutSeconds * 1000);
|
|
76752
76692
|
}
|
|
76753
76693
|
};
|
|
76754
|
-
this.#abortController = new AbortController;
|
|
76755
|
-
const providerOptions = {};
|
|
76756
|
-
const thinkingBudgetTokens = this.config.parameters?.thinkingBudgetTokens;
|
|
76757
|
-
const enableThinking = thinkingBudgetTokens > 0;
|
|
76758
|
-
if (enableThinking) {
|
|
76759
|
-
providerOptions.anthropic = {
|
|
76760
|
-
thinking: { type: "enabled", budgetTokens: thinkingBudgetTokens }
|
|
76761
|
-
};
|
|
76762
|
-
providerOptions.openrouter = {
|
|
76763
|
-
reasoning: {
|
|
76764
|
-
max_tokens: thinkingBudgetTokens
|
|
76765
|
-
}
|
|
76766
|
-
};
|
|
76767
|
-
providerOptions.google = {
|
|
76768
|
-
thinkingConfig: {
|
|
76769
|
-
includeThoughts: true,
|
|
76770
|
-
thinkingBudget: thinkingBudgetTokens
|
|
76771
|
-
}
|
|
76772
|
-
};
|
|
76773
|
-
}
|
|
76774
76694
|
try {
|
|
76775
|
-
|
|
76695
|
+
resetTimeout();
|
|
76696
|
+
const streamTextOptions = {
|
|
76776
76697
|
model: this.ai,
|
|
76777
76698
|
messages,
|
|
76778
|
-
providerOptions,
|
|
76699
|
+
providerOptions: this.config.parameters?.providerOptions,
|
|
76779
76700
|
onChunk: async ({ chunk }) => {
|
|
76780
76701
|
resetTimeout();
|
|
76781
76702
|
switch (chunk.type) {
|
|
76782
76703
|
case "text":
|
|
76783
|
-
currentAssistantMessage += chunk.text;
|
|
76784
76704
|
await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
|
|
76785
76705
|
break;
|
|
76786
76706
|
case "reasoning":
|
|
76787
76707
|
await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
|
|
76788
76708
|
break;
|
|
76709
|
+
case "tool-call":
|
|
76710
|
+
break;
|
|
76789
76711
|
}
|
|
76790
76712
|
},
|
|
76791
76713
|
onFinish: this.config.usageMeter.onFinishHandler(this.ai),
|
|
76792
76714
|
onError: async (error81) => {
|
|
76793
76715
|
console.error("Error in stream:", error81);
|
|
76794
76716
|
},
|
|
76795
|
-
abortSignal:
|
|
76717
|
+
abortSignal: requestAbortController.signal
|
|
76718
|
+
};
|
|
76719
|
+
if (this.config.toolFormat === "native") {
|
|
76720
|
+
streamTextOptions.tools = this.#toolSet;
|
|
76721
|
+
}
|
|
76722
|
+
const stream = streamText(streamTextOptions);
|
|
76723
|
+
await stream.consumeStream({
|
|
76724
|
+
onError: (error81) => {
|
|
76725
|
+
console.error("Error in stream:", error81);
|
|
76726
|
+
}
|
|
76796
76727
|
});
|
|
76797
|
-
await stream.
|
|
76728
|
+
const resp = await stream.response;
|
|
76729
|
+
respMessages = resp.messages;
|
|
76730
|
+
if (timeout) {
|
|
76731
|
+
clearTimeout(timeout);
|
|
76732
|
+
timeout = undefined;
|
|
76733
|
+
}
|
|
76798
76734
|
} catch (error81) {
|
|
76799
76735
|
if (error81 instanceof Error && error81.name === "AbortError") {
|
|
76800
|
-
|
|
76736
|
+
if (this.#aborted) {
|
|
76737
|
+
break;
|
|
76738
|
+
}
|
|
76739
|
+
console.debug(`Request attempt ${i + 1} timed out, will retry`);
|
|
76740
|
+
} else {
|
|
76741
|
+
console.error("Error in stream:", error81);
|
|
76801
76742
|
}
|
|
76802
|
-
console.error("Error in stream:", error81);
|
|
76803
76743
|
} finally {
|
|
76804
76744
|
if (timeout) {
|
|
76805
76745
|
clearTimeout(timeout);
|
|
76806
76746
|
}
|
|
76807
76747
|
}
|
|
76808
|
-
if (
|
|
76748
|
+
if (respMessages.length > 0) {
|
|
76809
76749
|
break;
|
|
76810
76750
|
}
|
|
76811
76751
|
if (this.#aborted) {
|
|
76812
76752
|
break;
|
|
76813
76753
|
}
|
|
76814
|
-
|
|
76754
|
+
if (i < retryCount - 1) {
|
|
76755
|
+
console.debug(`Retrying request ${i + 2} of ${retryCount}`);
|
|
76756
|
+
}
|
|
76815
76757
|
}
|
|
76816
|
-
if (
|
|
76758
|
+
if (respMessages.length === 0) {
|
|
76817
76759
|
if (this.#aborted) {
|
|
76818
76760
|
return [];
|
|
76819
76761
|
}
|
|
76820
|
-
throw new Error("No assistant message received");
|
|
76762
|
+
throw new Error("No assistant message received after all retry attempts");
|
|
76821
76763
|
}
|
|
76822
|
-
|
|
76823
|
-
this
|
|
76824
|
-
|
|
76825
|
-
|
|
76826
|
-
|
|
76764
|
+
this.#messages.push(...respMessages);
|
|
76765
|
+
if (this.config.toolFormat === "native") {
|
|
76766
|
+
return respMessages.flatMap((msg) => {
|
|
76767
|
+
if (msg.role === "assistant") {
|
|
76768
|
+
const content = msg.content;
|
|
76769
|
+
if (typeof content === "string") {
|
|
76770
|
+
return [{ type: "text", content }];
|
|
76771
|
+
}
|
|
76772
|
+
return content.flatMap((part) => {
|
|
76773
|
+
if (part.type === "text" || part.type === "reasoning") {
|
|
76774
|
+
return [{ type: "text", content: part.text }];
|
|
76775
|
+
}
|
|
76776
|
+
if (part.type === "tool-call") {
|
|
76777
|
+
return [{ type: "tool_use", id: part.toolCallId, name: part.toolName, params: part.input }];
|
|
76778
|
+
}
|
|
76779
|
+
return [];
|
|
76780
|
+
});
|
|
76781
|
+
}
|
|
76782
|
+
return [];
|
|
76783
|
+
});
|
|
76784
|
+
}
|
|
76785
|
+
const currentAssistantMessage = respMessages.map((msg) => {
|
|
76786
|
+
if (typeof msg.content === "string") {
|
|
76787
|
+
return msg.content;
|
|
76788
|
+
}
|
|
76789
|
+
return msg.content.map((part) => {
|
|
76790
|
+
if (part.type === "text") {
|
|
76791
|
+
return part.text;
|
|
76792
|
+
}
|
|
76793
|
+
return "";
|
|
76794
|
+
});
|
|
76795
|
+
}).join(`
|
|
76796
|
+
`);
|
|
76827
76797
|
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools.map(toToolInfoV1), this.config.toolNamePrefix);
|
|
76828
76798
|
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: currentAssistantMessage });
|
|
76829
76799
|
return ret;
|
|
@@ -76837,12 +76807,12 @@ ${instance.prompt}`;
|
|
|
76837
76807
|
case "text":
|
|
76838
76808
|
break;
|
|
76839
76809
|
case "tool_use": {
|
|
76840
|
-
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
76810
|
+
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, content: content.params });
|
|
76841
76811
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
76842
76812
|
switch (toolResp.type) {
|
|
76843
76813
|
case "Reply" /* Reply */: {
|
|
76844
|
-
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
|
|
76845
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
76814
|
+
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name, content: toolResp.message });
|
|
76815
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
76846
76816
|
break;
|
|
76847
76817
|
}
|
|
76848
76818
|
case "Exit" /* Exit */:
|
|
@@ -76851,17 +76821,17 @@ ${instance.prompt}`;
|
|
|
76851
76821
|
}
|
|
76852
76822
|
return { type: "exit", reason: toolResp };
|
|
76853
76823
|
case "Invalid" /* Invalid */: {
|
|
76854
|
-
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
|
|
76855
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
76824
|
+
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
|
|
76825
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
76856
76826
|
break outer;
|
|
76857
76827
|
}
|
|
76858
76828
|
case "Error" /* Error */: {
|
|
76859
|
-
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
|
|
76860
|
-
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
76829
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
|
|
76830
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
76861
76831
|
break outer;
|
|
76862
76832
|
}
|
|
76863
76833
|
case "Interrupted" /* Interrupted */:
|
|
76864
|
-
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
76834
|
+
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name, content: toolResp.message });
|
|
76865
76835
|
return { type: "exit", reason: toolResp };
|
|
76866
76836
|
case "HandOver" /* HandOver */: {
|
|
76867
76837
|
if (toolResponses.length > 0) {
|
|
@@ -76895,7 +76865,7 @@ ${instance.prompt}`;
|
|
|
76895
76865
|
}
|
|
76896
76866
|
case "Pause" /* Pause */: {
|
|
76897
76867
|
await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
|
|
76898
|
-
toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object });
|
|
76868
|
+
toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object, id: content.id });
|
|
76899
76869
|
hasPause = true;
|
|
76900
76870
|
}
|
|
76901
76871
|
}
|
|
@@ -76907,10 +76877,49 @@ ${instance.prompt}`;
|
|
|
76907
76877
|
return { type: "exit", reason: { type: "Pause", responses: toolResponses } };
|
|
76908
76878
|
}
|
|
76909
76879
|
if (toolResponses.length === 0) {
|
|
76910
|
-
return {
|
|
76880
|
+
return {
|
|
76881
|
+
type: "reply",
|
|
76882
|
+
message: {
|
|
76883
|
+
role: "user",
|
|
76884
|
+
content: responsePrompts.requireUseToolNative
|
|
76885
|
+
}
|
|
76886
|
+
};
|
|
76887
|
+
}
|
|
76888
|
+
if (this.config.toolFormat === "native") {
|
|
76889
|
+
const toolResults = toolResponses.filter((resp) => resp.type === "response").map((resp) => ({
|
|
76890
|
+
type: "tool-result",
|
|
76891
|
+
toolCallId: resp.id,
|
|
76892
|
+
toolName: resp.tool,
|
|
76893
|
+
output: {
|
|
76894
|
+
type: "text",
|
|
76895
|
+
value: resp.response
|
|
76896
|
+
}
|
|
76897
|
+
}));
|
|
76898
|
+
return {
|
|
76899
|
+
type: "reply",
|
|
76900
|
+
message: {
|
|
76901
|
+
role: "tool",
|
|
76902
|
+
content: toolResults
|
|
76903
|
+
}
|
|
76904
|
+
};
|
|
76905
|
+
}
|
|
76906
|
+
if (toolResponses.length === 0) {
|
|
76907
|
+
return {
|
|
76908
|
+
type: "reply",
|
|
76909
|
+
message: {
|
|
76910
|
+
role: "user",
|
|
76911
|
+
content: responsePrompts.requireUseTool
|
|
76912
|
+
}
|
|
76913
|
+
};
|
|
76911
76914
|
}
|
|
76912
76915
|
const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool: tool2, response: response2 }) => responsePrompts.toolResults(tool2, response2));
|
|
76913
|
-
return {
|
|
76916
|
+
return {
|
|
76917
|
+
type: "reply",
|
|
76918
|
+
message: {
|
|
76919
|
+
role: "user",
|
|
76920
|
+
content: finalResp
|
|
76921
|
+
}
|
|
76922
|
+
};
|
|
76914
76923
|
}
|
|
76915
76924
|
async#invokeTool(name17, args) {
|
|
76916
76925
|
try {
|
|
@@ -76991,10 +77000,10 @@ class AnalyzerAgent extends AgentBase {
|
|
|
76991
77000
|
permissionLevel: 1 /* Read */,
|
|
76992
77001
|
interactive: true
|
|
76993
77002
|
});
|
|
76994
|
-
const toolNamePrefix = "tool_";
|
|
77003
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
76995
77004
|
const systemPrompt = fullSystemPrompt({
|
|
76996
77005
|
os: options.os
|
|
76997
|
-
}, tools
|
|
77006
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
76998
77007
|
super(analyzerAgentInfo.name, options.ai, {
|
|
76999
77008
|
systemPrompt,
|
|
77000
77009
|
tools,
|
|
@@ -77080,10 +77089,10 @@ class ArchitectAgent extends AgentBase {
|
|
|
77080
77089
|
permissionLevel: 1 /* Read */,
|
|
77081
77090
|
interactive: true
|
|
77082
77091
|
});
|
|
77083
|
-
const toolNamePrefix = "tool_";
|
|
77092
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
77084
77093
|
const systemPrompt = fullSystemPrompt2({
|
|
77085
77094
|
os: options.os
|
|
77086
|
-
}, tools
|
|
77095
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
77087
77096
|
super(architectAgentInfo.name, options.ai, {
|
|
77088
77097
|
systemPrompt,
|
|
77089
77098
|
tools,
|
|
@@ -77202,10 +77211,10 @@ class CodeFixerAgent extends AgentBase {
|
|
|
77202
77211
|
permissionLevel: 3 /* Arbitrary */,
|
|
77203
77212
|
interactive: true
|
|
77204
77213
|
});
|
|
77205
|
-
const toolNamePrefix = "tool_";
|
|
77214
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
77206
77215
|
const systemPrompt = fullSystemPrompt3({
|
|
77207
77216
|
os: options.os
|
|
77208
|
-
}, tools
|
|
77217
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive, options.toolFormat === "native");
|
|
77209
77218
|
super(codeFixerAgentInfo.name, options.ai, {
|
|
77210
77219
|
systemPrompt,
|
|
77211
77220
|
tools,
|
|
@@ -77400,10 +77409,10 @@ class CoderAgent extends AgentBase {
|
|
|
77400
77409
|
permissionLevel: 3 /* Arbitrary */,
|
|
77401
77410
|
interactive: true
|
|
77402
77411
|
});
|
|
77403
|
-
const toolNamePrefix = "tool_";
|
|
77412
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
77404
77413
|
const systemPrompt = fullSystemPrompt4({
|
|
77405
77414
|
os: options.os
|
|
77406
|
-
}, tools
|
|
77415
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
77407
77416
|
super(coderAgentInfo.name, options.ai, {
|
|
77408
77417
|
systemPrompt,
|
|
77409
77418
|
tools,
|
|
@@ -77804,23 +77813,23 @@ var prompt = `You are an AiTool designed to assist users in creating new project
|
|
|
77804
77813
|
- Create a .gitattributes file with appropriate configurations:
|
|
77805
77814
|
- Mark lock files as generated and exclude them from diffs
|
|
77806
77815
|
- Example for different package managers:
|
|
77807
|
-
|
|
77816
|
+
|
|
77808
77817
|
# For Bun
|
|
77809
77818
|
bun.lock linguist-generated=true
|
|
77810
77819
|
bun.lock -diff
|
|
77811
|
-
|
|
77820
|
+
|
|
77812
77821
|
# For npm
|
|
77813
77822
|
package-lock.json linguist-generated=true
|
|
77814
77823
|
package-lock.json -diff
|
|
77815
|
-
|
|
77824
|
+
|
|
77816
77825
|
# For Yarn
|
|
77817
77826
|
yarn.lock linguist-generated=true
|
|
77818
77827
|
yarn.lock -diff
|
|
77819
|
-
|
|
77828
|
+
|
|
77820
77829
|
# For pnpm
|
|
77821
77830
|
pnpm-lock.yaml linguist-generated=true
|
|
77822
77831
|
pnpm-lock.yaml -diff
|
|
77823
|
-
|
|
77832
|
+
|
|
77824
77833
|
- Include other common configurations as needed based on project type
|
|
77825
77834
|
|
|
77826
77835
|
6. **Handover to Coder Agent:**
|
|
@@ -78076,6 +78085,202 @@ var generateProjectConfig_default = {
|
|
|
78076
78085
|
agent: "analyzer"
|
|
78077
78086
|
};
|
|
78078
78087
|
|
|
78088
|
+
// ../core/src/AiTool/tools/gitDiff.ts
|
|
78089
|
+
var toolInfo14 = {
|
|
78090
|
+
name: "git_diff",
|
|
78091
|
+
description: "Get the git diff for the current repository. Can be used to get staged changes, unstaged changes, or changes between commits. By default, it returns unstaged changes.",
|
|
78092
|
+
parameters: exports_external.object({
|
|
78093
|
+
staged: exports_external.preprocess((val) => {
|
|
78094
|
+
if (typeof val === "string") {
|
|
78095
|
+
const lower = val.toLowerCase();
|
|
78096
|
+
if (lower === "false")
|
|
78097
|
+
return false;
|
|
78098
|
+
if (lower === "true")
|
|
78099
|
+
return true;
|
|
78100
|
+
}
|
|
78101
|
+
return val;
|
|
78102
|
+
}, exports_external.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
|
|
78103
|
+
commitRange: exports_external.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
|
|
78104
|
+
file: exports_external.string().optional().describe("Get the diff for a specific file.")
|
|
78105
|
+
}),
|
|
78106
|
+
permissionLevel: 1 /* Read */
|
|
78107
|
+
};
|
|
78108
|
+
var handler14 = async (provider2, args) => {
|
|
78109
|
+
if (!provider2.executeCommand) {
|
|
78110
|
+
return {
|
|
78111
|
+
type: "Error" /* Error */,
|
|
78112
|
+
message: "Not possible to execute command. Abort."
|
|
78113
|
+
};
|
|
78114
|
+
}
|
|
78115
|
+
const { staged, file: file3, commitRange } = toolInfo14.parameters.parse(args);
|
|
78116
|
+
const commandParts = ["git", "diff", "--no-color"];
|
|
78117
|
+
if (staged) {
|
|
78118
|
+
commandParts.push("--staged");
|
|
78119
|
+
}
|
|
78120
|
+
if (commitRange) {
|
|
78121
|
+
commandParts.push(commitRange);
|
|
78122
|
+
}
|
|
78123
|
+
if (file3) {
|
|
78124
|
+
commandParts.push("--", file3);
|
|
78125
|
+
}
|
|
78126
|
+
const command = commandParts.join(" ");
|
|
78127
|
+
try {
|
|
78128
|
+
const result = await provider2.executeCommand(command, false);
|
|
78129
|
+
if (result.exitCode === 0) {
|
|
78130
|
+
if (!result.stdout.trim()) {
|
|
78131
|
+
return {
|
|
78132
|
+
type: "Reply" /* Reply */,
|
|
78133
|
+
message: "No diff found."
|
|
78134
|
+
};
|
|
78135
|
+
}
|
|
78136
|
+
return {
|
|
78137
|
+
type: "Reply" /* Reply */,
|
|
78138
|
+
message: `<diff file="${file3 ?? "all"}">
|
|
78139
|
+
${result.stdout}
|
|
78140
|
+
</diff>`
|
|
78141
|
+
};
|
|
78142
|
+
}
|
|
78143
|
+
return {
|
|
78144
|
+
type: "Error" /* Error */,
|
|
78145
|
+
message: `\`${command}\` exited with code ${result.exitCode}:
|
|
78146
|
+
${result.stderr}`
|
|
78147
|
+
};
|
|
78148
|
+
} catch (error81) {
|
|
78149
|
+
return {
|
|
78150
|
+
type: "Error" /* Error */,
|
|
78151
|
+
message: error81 instanceof Error ? error81.message : String(error81)
|
|
78152
|
+
};
|
|
78153
|
+
}
|
|
78154
|
+
};
|
|
78155
|
+
var isAvailable14 = (provider2) => {
|
|
78156
|
+
return !!provider2.executeCommand;
|
|
78157
|
+
};
|
|
78158
|
+
var gitDiff_default = {
|
|
78159
|
+
...toolInfo14,
|
|
78160
|
+
handler: handler14,
|
|
78161
|
+
isAvailable: isAvailable14
|
|
78162
|
+
};
|
|
78163
|
+
|
|
78164
|
+
// ../core/src/AiTool/reviewDiff.ts
|
|
78165
|
+
var prompt5 = `
|
|
78166
|
+
# Code Review Prompt
|
|
78167
|
+
|
|
78168
|
+
You are a senior software engineer reviewing code changes.
|
|
78169
|
+
|
|
78170
|
+
## Critical Instructions
|
|
78171
|
+
**ONLY review the actual changes shown in the diff.** Do not comment on existing code that wasn't modified.
|
|
78172
|
+
|
|
78173
|
+
## Viewing Changes
|
|
78174
|
+
- **Use git_diff** to inspect the actual code changes for each relevant file.
|
|
78175
|
+
- **Pull request**: use the provided commit range for the git_diff tool.
|
|
78176
|
+
- **Local changes**: diff staged or unstaged files using the git_diff tool.
|
|
78177
|
+
- If a pull request is present you may receive:
|
|
78178
|
+
- <pr_title>
|
|
78179
|
+
- <pr_description>
|
|
78180
|
+
- <commit_messages>
|
|
78181
|
+
- A <review_instructions> tag tells you the focus of the review.
|
|
78182
|
+
- File status information is provided in <file_status> - use this to understand which files were modified, added, deleted, or renamed.
|
|
78183
|
+
|
|
78184
|
+
## Review Guidelines
|
|
78185
|
+
Focus exclusively on the changed lines (+ additions, - deletions, modified lines):
|
|
78186
|
+
- **Specific issues**: Point to exact problems in the changed code with line references
|
|
78187
|
+
- **Actionable fixes**: Provide concrete solutions, not vague suggestions
|
|
78188
|
+
- **Clear reasoning**: Explain why each issue matters and how to fix it
|
|
78189
|
+
- **Avoid generic advice**: No generic suggestions like "add more tests", "improve documentation", or "follow best practices" unless directly related to a specific problem in the diff
|
|
78190
|
+
|
|
78191
|
+
## What NOT to review
|
|
78192
|
+
- Existing unchanged code
|
|
78193
|
+
- Overall project structure or architecture (unless directly impacted by changes)
|
|
78194
|
+
- Generic best practices unrelated to the specific changes
|
|
78195
|
+
- Missing features or functionality not part of this diff
|
|
78196
|
+
|
|
78197
|
+
## Output Format
|
|
78198
|
+
Do **not** include praise or positive feedback. Ignore generated files such as lock files.
|
|
78199
|
+
Only include reviews for actual issues found in the changed code.
|
|
78200
|
+
|
|
78201
|
+
Return your review as a JSON object inside a \`\`\`json block, wrapped like:
|
|
78202
|
+
<tool_attempt_completion>
|
|
78203
|
+
<tool_parameter_result>
|
|
78204
|
+
\`\`\`json
|
|
78205
|
+
{
|
|
78206
|
+
"overview": "Summary of specific issues found in the diff changes, or 'No issues found' if the changes look good.",
|
|
78207
|
+
"specificReviews": [
|
|
78208
|
+
{
|
|
78209
|
+
"file": "path/filename.ext",
|
|
78210
|
+
"lines": "N or N-M",
|
|
78211
|
+
"review": "Specific issue with the changed code and exact actionable fix."
|
|
78212
|
+
}
|
|
78213
|
+
]
|
|
78214
|
+
}
|
|
78215
|
+
\`\`\`
|
|
78216
|
+
</tool_parameter_result>
|
|
78217
|
+
</tool_attempt_completion>
|
|
78218
|
+
`;
|
|
78219
|
+
var reviewDiff_default = {
|
|
78220
|
+
name: "reviewDiff",
|
|
78221
|
+
description: "Reviews a git diff",
|
|
78222
|
+
prompt: prompt5,
|
|
78223
|
+
formatInput: (params) => {
|
|
78224
|
+
const parts = [];
|
|
78225
|
+
if (params.pullRequestTitle) {
|
|
78226
|
+
parts.push(`<pr_title>
|
|
78227
|
+
${params.pullRequestTitle}
|
|
78228
|
+
</pr_title>`);
|
|
78229
|
+
}
|
|
78230
|
+
if (params.pullRequestDescription) {
|
|
78231
|
+
parts.push(`<pr_description>
|
|
78232
|
+
${params.pullRequestDescription}
|
|
78233
|
+
</pr_description>`);
|
|
78234
|
+
}
|
|
78235
|
+
if (params.commitMessages) {
|
|
78236
|
+
parts.push(`<commit_messages>
|
|
78237
|
+
${params.commitMessages}
|
|
78238
|
+
</commit_messages>`);
|
|
78239
|
+
}
|
|
78240
|
+
if (params.changedFiles && params.changedFiles.length > 0) {
|
|
78241
|
+
const fileList = params.changedFiles.map((file3) => `${file3.status}: ${file3.path}`).join(`
|
|
78242
|
+
`);
|
|
78243
|
+
parts.push(`<file_status>
|
|
78244
|
+
${fileList}
|
|
78245
|
+
</file_status>`);
|
|
78246
|
+
}
|
|
78247
|
+
let instructions = "";
|
|
78248
|
+
if (params.commitRange) {
|
|
78249
|
+
instructions = `Review the pull request. Use the git_diff tool with commit range '${params.commitRange}' to inspect the actual code changes. File status information is already provided above.`;
|
|
78250
|
+
} else if (params.staged) {
|
|
78251
|
+
instructions = "Review the staged changes. Use the git_diff tool with staged: true to inspect the actual code changes. File status information is already provided above.";
|
|
78252
|
+
} else {
|
|
78253
|
+
instructions = "Review the unstaged changes. Use the git_diff tool to inspect the actual code changes. File status information is already provided above.";
|
|
78254
|
+
}
|
|
78255
|
+
parts.push(`<review_instructions>
|
|
78256
|
+
${instructions}
|
|
78257
|
+
</review_instructions>`);
|
|
78258
|
+
return parts.join(`
|
|
78259
|
+
`);
|
|
78260
|
+
},
|
|
78261
|
+
parseOutput: (output) => {
|
|
78262
|
+
const jsonBlockRegex = /```json\n([\s\S]*?)\n```/;
|
|
78263
|
+
const match = output.match(jsonBlockRegex);
|
|
78264
|
+
const content = match ? match[1] : output;
|
|
78265
|
+
try {
|
|
78266
|
+
return JSON.parse(content);
|
|
78267
|
+
} catch (error81) {
|
|
78268
|
+
console.error("Error parsing JSON output:", error81);
|
|
78269
|
+
return {
|
|
78270
|
+
overview: `Could not parse review output. Raw output:
|
|
78271
|
+
${output}`,
|
|
78272
|
+
specificReviews: []
|
|
78273
|
+
};
|
|
78274
|
+
}
|
|
78275
|
+
},
|
|
78276
|
+
agent: (options) => {
|
|
78277
|
+
return new AnalyzerAgent({
|
|
78278
|
+
...options,
|
|
78279
|
+
additionalTools: [gitDiff_default]
|
|
78280
|
+
});
|
|
78281
|
+
}
|
|
78282
|
+
};
|
|
78283
|
+
|
|
78079
78284
|
// ../core/src/AiTool/index.ts
|
|
78080
78285
|
var executeTool = async (definition, ai, params, usageMeter) => {
|
|
78081
78286
|
const resp = await generateText({
|
|
@@ -78091,10 +78296,7 @@ var executeTool = async (definition, ai, params, usageMeter) => {
|
|
|
78091
78296
|
usageMeter.addUsage(ai, resp);
|
|
78092
78297
|
return definition.parseOutput(resp.text);
|
|
78093
78298
|
};
|
|
78094
|
-
var
|
|
78095
|
-
if (!definition.agent) {
|
|
78096
|
-
throw new Error("Agent not specified");
|
|
78097
|
-
}
|
|
78299
|
+
var executeMultiAgentTool = async (definition, agent, params) => {
|
|
78098
78300
|
const exitReason = await agent.startTask({
|
|
78099
78301
|
agentName: definition.agent,
|
|
78100
78302
|
task: definition.prompt,
|
|
@@ -78105,22 +78307,41 @@ var executeAgentTool = async (definition, agent, params) => {
|
|
|
78105
78307
|
}
|
|
78106
78308
|
throw new Error(`Tool execution failed: ${exitReason.type}`);
|
|
78107
78309
|
};
|
|
78310
|
+
var executeAgentTool = async (definition, options, params) => {
|
|
78311
|
+
const agent = definition.agent(options);
|
|
78312
|
+
const exitReason = await agent.start(`${definition.prompt}
|
|
78313
|
+
|
|
78314
|
+
${definition.formatInput(params)}`);
|
|
78315
|
+
if (exitReason.type === "Exit" /* Exit */) {
|
|
78316
|
+
return definition.parseOutput(exitReason.message);
|
|
78317
|
+
}
|
|
78318
|
+
throw new Error(`Tool execution failed: ${exitReason.type}`);
|
|
78319
|
+
};
|
|
78108
78320
|
var makeTool = (definition) => {
|
|
78109
78321
|
return async (ai, params, usageMeter) => {
|
|
78110
78322
|
return executeTool(definition, ai, params, usageMeter);
|
|
78111
78323
|
};
|
|
78112
78324
|
};
|
|
78113
|
-
var
|
|
78325
|
+
var makeMultiAgentTool = (definition) => {
|
|
78114
78326
|
return async (agent, params) => {
|
|
78115
|
-
return
|
|
78327
|
+
return executeMultiAgentTool(definition, agent, params);
|
|
78328
|
+
};
|
|
78329
|
+
};
|
|
78330
|
+
var makeAgentTool = (definition) => {
|
|
78331
|
+
return async (options, params) => {
|
|
78332
|
+
return executeAgentTool(definition, options, params);
|
|
78116
78333
|
};
|
|
78117
78334
|
};
|
|
78118
78335
|
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
78119
78336
|
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
78120
|
-
var
|
|
78121
|
-
var
|
|
78337
|
+
var reviewDiff = makeAgentTool(reviewDiff_default);
|
|
78338
|
+
var generateProjectConfig = makeMultiAgentTool(generateProjectConfig_default);
|
|
78339
|
+
var createNewProject = makeMultiAgentTool(createNewProject_default);
|
|
78122
78340
|
// src/commands/chat.ts
|
|
78123
|
-
var
|
|
78341
|
+
var import_lodash5 = __toESM(require_lodash(), 1);
|
|
78342
|
+
|
|
78343
|
+
// src/getModel.ts
|
|
78344
|
+
import { appendFileSync } from "node:fs";
|
|
78124
78345
|
|
|
78125
78346
|
// ../../node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
78126
78347
|
var anthropicErrorDataSchema = exports_external2.object({
|
|
@@ -78342,13 +78563,13 @@ function convertToString(data) {
|
|
|
78342
78563
|
});
|
|
78343
78564
|
}
|
|
78344
78565
|
async function convertToAnthropicMessagesPrompt({
|
|
78345
|
-
prompt:
|
|
78566
|
+
prompt: prompt6,
|
|
78346
78567
|
sendReasoning,
|
|
78347
78568
|
warnings
|
|
78348
78569
|
}) {
|
|
78349
78570
|
var _a16, _b8, _c, _d, _e;
|
|
78350
78571
|
const betas = /* @__PURE__ */ new Set;
|
|
78351
|
-
const blocks = groupIntoBlocks(
|
|
78572
|
+
const blocks = groupIntoBlocks(prompt6);
|
|
78352
78573
|
let system = undefined;
|
|
78353
78574
|
const messages = [];
|
|
78354
78575
|
function getCacheControl(providerMetadata) {
|
|
@@ -78680,10 +78901,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
78680
78901
|
betas
|
|
78681
78902
|
};
|
|
78682
78903
|
}
|
|
78683
|
-
function groupIntoBlocks(
|
|
78904
|
+
function groupIntoBlocks(prompt6) {
|
|
78684
78905
|
const blocks = [];
|
|
78685
78906
|
let currentBlock = undefined;
|
|
78686
|
-
for (const message of
|
|
78907
|
+
for (const message of prompt6) {
|
|
78687
78908
|
const { role } = message;
|
|
78688
78909
|
switch (role) {
|
|
78689
78910
|
case "system": {
|
|
@@ -78830,7 +79051,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78830
79051
|
return (_c = (_b8 = (_a16 = this.config).supportedUrls) == null ? undefined : _b8.call(_a16)) != null ? _c : {};
|
|
78831
79052
|
}
|
|
78832
79053
|
async getArgs({
|
|
78833
|
-
prompt:
|
|
79054
|
+
prompt: prompt6,
|
|
78834
79055
|
maxOutputTokens = 4096,
|
|
78835
79056
|
temperature,
|
|
78836
79057
|
topP,
|
|
@@ -78891,7 +79112,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78891
79112
|
schema: anthropicProviderOptions
|
|
78892
79113
|
});
|
|
78893
79114
|
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
78894
|
-
prompt:
|
|
79115
|
+
prompt: prompt6,
|
|
78895
79116
|
sendReasoning: (_a16 = anthropicOptions == null ? undefined : anthropicOptions.sendReasoning) != null ? _a16 : true,
|
|
78896
79117
|
warnings
|
|
78897
79118
|
});
|
|
@@ -78976,7 +79197,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78976
79197
|
var _a16, _b8, _c;
|
|
78977
79198
|
return (_c = (_b8 = (_a16 = this.config).transformRequestBody) == null ? undefined : _b8.call(_a16, args)) != null ? _c : args;
|
|
78978
79199
|
}
|
|
78979
|
-
extractCitationDocuments(
|
|
79200
|
+
extractCitationDocuments(prompt6) {
|
|
78980
79201
|
const isCitationPart = (part) => {
|
|
78981
79202
|
var _a16, _b8;
|
|
78982
79203
|
if (part.type !== "file") {
|
|
@@ -78989,7 +79210,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78989
79210
|
const citationsConfig = anthropic2 == null ? undefined : anthropic2.citations;
|
|
78990
79211
|
return (_b8 = citationsConfig == null ? undefined : citationsConfig.enabled) != null ? _b8 : false;
|
|
78991
79212
|
};
|
|
78992
|
-
return
|
|
79213
|
+
return prompt6.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
78993
79214
|
var _a16;
|
|
78994
79215
|
const filePart = part;
|
|
78995
79216
|
return {
|
|
@@ -79808,9 +80029,9 @@ function getOpenAIMetadata(message) {
|
|
|
79808
80029
|
var _a16, _b8;
|
|
79809
80030
|
return (_b8 = (_a16 = message == null ? undefined : message.providerOptions) == null ? undefined : _a16.openaiCompatible) != null ? _b8 : {};
|
|
79810
80031
|
}
|
|
79811
|
-
function convertToOpenAICompatibleChatMessages(
|
|
80032
|
+
function convertToOpenAICompatibleChatMessages(prompt6) {
|
|
79812
80033
|
const messages = [];
|
|
79813
|
-
for (const { role, content, ...message } of
|
|
80034
|
+
for (const { role, content, ...message } of prompt6) {
|
|
79814
80035
|
const metadata = getOpenAIMetadata({ ...message });
|
|
79815
80036
|
switch (role) {
|
|
79816
80037
|
case "system": {
|
|
@@ -80035,7 +80256,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
80035
80256
|
return (_c = (_b8 = (_a16 = this.config).supportedUrls) == null ? undefined : _b8.call(_a16)) != null ? _c : {};
|
|
80036
80257
|
}
|
|
80037
80258
|
async getArgs({
|
|
80038
|
-
prompt:
|
|
80259
|
+
prompt: prompt6,
|
|
80039
80260
|
maxOutputTokens,
|
|
80040
80261
|
temperature,
|
|
80041
80262
|
topP,
|
|
@@ -80099,7 +80320,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
80099
80320
|
seed,
|
|
80100
80321
|
...providerOptions == null ? undefined : providerOptions[this.providerOptionsName],
|
|
80101
80322
|
reasoning_effort: compatibleOptions.reasoningEffort,
|
|
80102
|
-
messages: convertToOpenAICompatibleChatMessages(
|
|
80323
|
+
messages: convertToOpenAICompatibleChatMessages(prompt6),
|
|
80103
80324
|
tools: openaiTools,
|
|
80104
80325
|
tool_choice: openaiToolChoice
|
|
80105
80326
|
},
|
|
@@ -80705,13 +80926,13 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema2) {
|
|
|
80705
80926
|
function isEmptyObjectSchema(jsonSchema2) {
|
|
80706
80927
|
return jsonSchema2 != null && typeof jsonSchema2 === "object" && jsonSchema2.type === "object" && (jsonSchema2.properties == null || Object.keys(jsonSchema2.properties).length === 0) && !jsonSchema2.additionalProperties;
|
|
80707
80928
|
}
|
|
80708
|
-
function convertToGoogleGenerativeAIMessages(
|
|
80929
|
+
function convertToGoogleGenerativeAIMessages(prompt6, options) {
|
|
80709
80930
|
var _a16;
|
|
80710
80931
|
const systemInstructionParts = [];
|
|
80711
80932
|
const contents = [];
|
|
80712
80933
|
let systemMessagesAllowed = true;
|
|
80713
80934
|
const isGemmaModel = (_a16 = options == null ? undefined : options.isGemmaModel) != null ? _a16 : false;
|
|
80714
|
-
for (const { role, content } of
|
|
80935
|
+
for (const { role, content } of prompt6) {
|
|
80715
80936
|
switch (role) {
|
|
80716
80937
|
case "system": {
|
|
80717
80938
|
if (!systemMessagesAllowed) {
|
|
@@ -81085,7 +81306,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
81085
81306
|
return (_c = (_b8 = (_a16 = this.config).supportedUrls) == null ? undefined : _b8.call(_a16)) != null ? _c : {};
|
|
81086
81307
|
}
|
|
81087
81308
|
async getArgs({
|
|
81088
|
-
prompt:
|
|
81309
|
+
prompt: prompt6,
|
|
81089
81310
|
maxOutputTokens,
|
|
81090
81311
|
temperature,
|
|
81091
81312
|
topP,
|
|
@@ -81113,7 +81334,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
81113
81334
|
});
|
|
81114
81335
|
}
|
|
81115
81336
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
81116
|
-
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
81337
|
+
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt6, { isGemmaModel });
|
|
81117
81338
|
const {
|
|
81118
81339
|
tools: googleTools2,
|
|
81119
81340
|
toolConfig: googleToolConfig,
|
|
@@ -81626,7 +81847,7 @@ var GoogleVertexImageModel = class {
|
|
|
81626
81847
|
return this.config.provider;
|
|
81627
81848
|
}
|
|
81628
81849
|
async doGenerate({
|
|
81629
|
-
prompt:
|
|
81850
|
+
prompt: prompt6,
|
|
81630
81851
|
n,
|
|
81631
81852
|
size,
|
|
81632
81853
|
aspectRatio,
|
|
@@ -81650,7 +81871,7 @@ var GoogleVertexImageModel = class {
|
|
|
81650
81871
|
schema: vertexImageProviderOptionsSchema
|
|
81651
81872
|
});
|
|
81652
81873
|
const body = {
|
|
81653
|
-
instances: [{ prompt:
|
|
81874
|
+
instances: [{ prompt: prompt6 }],
|
|
81654
81875
|
parameters: {
|
|
81655
81876
|
sampleCount: n,
|
|
81656
81877
|
...aspectRatio != null ? { aspectRatio } : {},
|
|
@@ -81779,12 +82000,12 @@ var vertex = createVertex2();
|
|
|
81779
82000
|
|
|
81780
82001
|
// ../../node_modules/@ai-sdk/openai/dist/index.mjs
|
|
81781
82002
|
function convertToOpenAIChatMessages({
|
|
81782
|
-
prompt:
|
|
82003
|
+
prompt: prompt6,
|
|
81783
82004
|
systemMessageMode = "system"
|
|
81784
82005
|
}) {
|
|
81785
82006
|
const messages = [];
|
|
81786
82007
|
const warnings = [];
|
|
81787
|
-
for (const { role, content } of
|
|
82008
|
+
for (const { role, content } of prompt6) {
|
|
81788
82009
|
switch (role) {
|
|
81789
82010
|
case "system": {
|
|
81790
82011
|
switch (systemMessageMode) {
|
|
@@ -82125,7 +82346,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
82125
82346
|
return this.config.provider;
|
|
82126
82347
|
}
|
|
82127
82348
|
async getArgs({
|
|
82128
|
-
prompt:
|
|
82349
|
+
prompt: prompt6,
|
|
82129
82350
|
maxOutputTokens,
|
|
82130
82351
|
temperature,
|
|
82131
82352
|
topP,
|
|
@@ -82161,7 +82382,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
82161
82382
|
});
|
|
82162
82383
|
}
|
|
82163
82384
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages({
|
|
82164
|
-
prompt:
|
|
82385
|
+
prompt: prompt6,
|
|
82165
82386
|
systemMessageMode: getSystemMessageMode(this.modelId)
|
|
82166
82387
|
});
|
|
82167
82388
|
warnings.push(...messageWarnings);
|
|
@@ -82686,23 +82907,23 @@ var reasoningModels = {
|
|
|
82686
82907
|
}
|
|
82687
82908
|
};
|
|
82688
82909
|
function convertToOpenAICompletionPrompt({
|
|
82689
|
-
prompt:
|
|
82910
|
+
prompt: prompt6,
|
|
82690
82911
|
user = "user",
|
|
82691
82912
|
assistant = "assistant"
|
|
82692
82913
|
}) {
|
|
82693
82914
|
let text2 = "";
|
|
82694
|
-
if (
|
|
82695
|
-
text2 += `${
|
|
82915
|
+
if (prompt6[0].role === "system") {
|
|
82916
|
+
text2 += `${prompt6[0].content}
|
|
82696
82917
|
|
|
82697
82918
|
`;
|
|
82698
|
-
|
|
82919
|
+
prompt6 = prompt6.slice(1);
|
|
82699
82920
|
}
|
|
82700
|
-
for (const { role, content } of
|
|
82921
|
+
for (const { role, content } of prompt6) {
|
|
82701
82922
|
switch (role) {
|
|
82702
82923
|
case "system": {
|
|
82703
82924
|
throw new InvalidPromptError({
|
|
82704
82925
|
message: "Unexpected system message in prompt: ${content}",
|
|
82705
|
-
prompt:
|
|
82926
|
+
prompt: prompt6
|
|
82706
82927
|
});
|
|
82707
82928
|
}
|
|
82708
82929
|
case "user": {
|
|
@@ -82778,7 +82999,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
82778
82999
|
return this.config.provider;
|
|
82779
83000
|
}
|
|
82780
83001
|
async getArgs({
|
|
82781
|
-
prompt:
|
|
83002
|
+
prompt: prompt6,
|
|
82782
83003
|
maxOutputTokens,
|
|
82783
83004
|
temperature,
|
|
82784
83005
|
topP,
|
|
@@ -82821,7 +83042,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
82821
83042
|
details: "JSON response format is not supported."
|
|
82822
83043
|
});
|
|
82823
83044
|
}
|
|
82824
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt:
|
|
83045
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt: prompt6 });
|
|
82825
83046
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
82826
83047
|
return {
|
|
82827
83048
|
args: {
|
|
@@ -83106,7 +83327,7 @@ var OpenAIImageModel = class {
|
|
|
83106
83327
|
return this.config.provider;
|
|
83107
83328
|
}
|
|
83108
83329
|
async doGenerate({
|
|
83109
|
-
prompt:
|
|
83330
|
+
prompt: prompt6,
|
|
83110
83331
|
n,
|
|
83111
83332
|
size,
|
|
83112
83333
|
aspectRatio,
|
|
@@ -83136,7 +83357,7 @@ var OpenAIImageModel = class {
|
|
|
83136
83357
|
headers: combineHeaders(this.config.headers(), headers),
|
|
83137
83358
|
body: {
|
|
83138
83359
|
model: this.modelId,
|
|
83139
|
-
prompt:
|
|
83360
|
+
prompt: prompt6,
|
|
83140
83361
|
n,
|
|
83141
83362
|
size,
|
|
83142
83363
|
...(_d = providerOptions.openai) != null ? _d : {},
|
|
@@ -83332,13 +83553,13 @@ var openaiTranscriptionResponseSchema = exports_external2.object({
|
|
|
83332
83553
|
})).nullish()
|
|
83333
83554
|
});
|
|
83334
83555
|
async function convertToOpenAIResponsesMessages({
|
|
83335
|
-
prompt:
|
|
83556
|
+
prompt: prompt6,
|
|
83336
83557
|
systemMessageMode
|
|
83337
83558
|
}) {
|
|
83338
83559
|
var _a16, _b8, _c, _d, _e, _f;
|
|
83339
83560
|
const messages = [];
|
|
83340
83561
|
const warnings = [];
|
|
83341
|
-
for (const { role, content } of
|
|
83562
|
+
for (const { role, content } of prompt6) {
|
|
83342
83563
|
switch (role) {
|
|
83343
83564
|
case "system": {
|
|
83344
83565
|
switch (systemMessageMode) {
|
|
@@ -83622,7 +83843,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
83622
83843
|
presencePenalty,
|
|
83623
83844
|
frequencyPenalty,
|
|
83624
83845
|
seed,
|
|
83625
|
-
prompt:
|
|
83846
|
+
prompt: prompt6,
|
|
83626
83847
|
providerOptions,
|
|
83627
83848
|
tools: tools2,
|
|
83628
83849
|
toolChoice,
|
|
@@ -83653,7 +83874,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
83653
83874
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
83654
83875
|
}
|
|
83655
83876
|
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
83656
|
-
prompt:
|
|
83877
|
+
prompt: prompt6,
|
|
83657
83878
|
systemMessageMode: modelConfig.systemMessageMode
|
|
83658
83879
|
});
|
|
83659
83880
|
warnings.push(...messageWarnings);
|
|
@@ -84771,13 +84992,13 @@ var symbol54 = Symbol.for(marker54);
|
|
|
84771
84992
|
var _a54;
|
|
84772
84993
|
var InvalidPromptError2 = class extends AISDKError2 {
|
|
84773
84994
|
constructor({
|
|
84774
|
-
prompt:
|
|
84995
|
+
prompt: prompt6,
|
|
84775
84996
|
message,
|
|
84776
84997
|
cause
|
|
84777
84998
|
}) {
|
|
84778
84999
|
super({ name: name44, message: `Invalid prompt: ${message}`, cause });
|
|
84779
85000
|
this[_a54] = true;
|
|
84780
|
-
this.prompt =
|
|
85001
|
+
this.prompt = prompt6;
|
|
84781
85002
|
}
|
|
84782
85003
|
static isInstance(error81) {
|
|
84783
85004
|
return AISDKError2.hasMarker(error81, marker54);
|
|
@@ -85540,10 +85761,10 @@ function getCacheControl(providerMetadata) {
|
|
|
85540
85761
|
const openrouter2 = providerMetadata == null ? undefined : providerMetadata.openrouter;
|
|
85541
85762
|
return (_c = (_b8 = (_a153 = openrouter2 == null ? undefined : openrouter2.cacheControl) != null ? _a153 : openrouter2 == null ? undefined : openrouter2.cache_control) != null ? _b8 : anthropic2 == null ? undefined : anthropic2.cacheControl) != null ? _c : anthropic2 == null ? undefined : anthropic2.cache_control;
|
|
85542
85763
|
}
|
|
85543
|
-
function convertToOpenRouterChatMessages(
|
|
85764
|
+
function convertToOpenRouterChatMessages(prompt6) {
|
|
85544
85765
|
var _a153, _b8, _c;
|
|
85545
85766
|
const messages = [];
|
|
85546
|
-
for (const { role, content, providerOptions } of
|
|
85767
|
+
for (const { role, content, providerOptions } of prompt6) {
|
|
85547
85768
|
switch (role) {
|
|
85548
85769
|
case "system": {
|
|
85549
85770
|
messages.push({
|
|
@@ -85832,7 +86053,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
85832
86053
|
this.config = config4;
|
|
85833
86054
|
}
|
|
85834
86055
|
getArgs({
|
|
85835
|
-
prompt:
|
|
86056
|
+
prompt: prompt6,
|
|
85836
86057
|
maxOutputTokens,
|
|
85837
86058
|
temperature,
|
|
85838
86059
|
topP,
|
|
@@ -85862,7 +86083,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
85862
86083
|
stop: stopSequences,
|
|
85863
86084
|
response_format: responseFormat,
|
|
85864
86085
|
top_k: topK,
|
|
85865
|
-
messages: convertToOpenRouterChatMessages(
|
|
86086
|
+
messages: convertToOpenRouterChatMessages(prompt6),
|
|
85866
86087
|
include_reasoning: this.settings.includeReasoning,
|
|
85867
86088
|
reasoning: this.settings.reasoning,
|
|
85868
86089
|
usage: this.settings.usage
|
|
@@ -86307,27 +86528,27 @@ var OpenRouterChatLanguageModel = class {
|
|
|
86307
86528
|
}
|
|
86308
86529
|
};
|
|
86309
86530
|
function convertToOpenRouterCompletionPrompt({
|
|
86310
|
-
prompt:
|
|
86531
|
+
prompt: prompt6,
|
|
86311
86532
|
inputFormat,
|
|
86312
86533
|
user = "user",
|
|
86313
86534
|
assistant = "assistant"
|
|
86314
86535
|
}) {
|
|
86315
|
-
if (inputFormat === "prompt" &&
|
|
86316
|
-
return { prompt:
|
|
86536
|
+
if (inputFormat === "prompt" && prompt6.length === 1 && prompt6[0] && prompt6[0].role === "user" && prompt6[0].content.length === 1 && prompt6[0].content[0] && prompt6[0].content[0].type === "text") {
|
|
86537
|
+
return { prompt: prompt6[0].content[0].text };
|
|
86317
86538
|
}
|
|
86318
86539
|
let text2 = "";
|
|
86319
|
-
if (
|
|
86320
|
-
text2 += `${
|
|
86540
|
+
if (prompt6[0] && prompt6[0].role === "system") {
|
|
86541
|
+
text2 += `${prompt6[0].content}
|
|
86321
86542
|
|
|
86322
86543
|
`;
|
|
86323
|
-
|
|
86544
|
+
prompt6 = prompt6.slice(1);
|
|
86324
86545
|
}
|
|
86325
|
-
for (const { role, content } of
|
|
86546
|
+
for (const { role, content } of prompt6) {
|
|
86326
86547
|
switch (role) {
|
|
86327
86548
|
case "system": {
|
|
86328
86549
|
throw new InvalidPromptError2({
|
|
86329
86550
|
message: `Unexpected system message in prompt: ${content}`,
|
|
86330
|
-
prompt:
|
|
86551
|
+
prompt: prompt6
|
|
86331
86552
|
});
|
|
86332
86553
|
}
|
|
86333
86554
|
case "user": {
|
|
@@ -86454,7 +86675,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
86454
86675
|
this.config = config4;
|
|
86455
86676
|
}
|
|
86456
86677
|
getArgs({
|
|
86457
|
-
prompt:
|
|
86678
|
+
prompt: prompt6,
|
|
86458
86679
|
maxOutputTokens,
|
|
86459
86680
|
temperature,
|
|
86460
86681
|
topP,
|
|
@@ -86468,7 +86689,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
86468
86689
|
toolChoice
|
|
86469
86690
|
}) {
|
|
86470
86691
|
const { prompt: completionPrompt } = convertToOpenRouterCompletionPrompt({
|
|
86471
|
-
prompt:
|
|
86692
|
+
prompt: prompt6,
|
|
86472
86693
|
inputFormat: "prompt"
|
|
86473
86694
|
});
|
|
86474
86695
|
if (tools2 == null ? undefined : tools2.length) {
|
|
@@ -101707,11 +101928,11 @@ var coerce = {
|
|
|
101707
101928
|
var NEVER4 = INVALID2;
|
|
101708
101929
|
// ../../node_modules/ollama-ai-provider-v2/dist/index.mjs
|
|
101709
101930
|
function convertToOllamaChatMessages({
|
|
101710
|
-
prompt:
|
|
101931
|
+
prompt: prompt6,
|
|
101711
101932
|
systemMessageMode = "system"
|
|
101712
101933
|
}) {
|
|
101713
101934
|
const messages = [];
|
|
101714
|
-
for (const { role, content } of
|
|
101935
|
+
for (const { role, content } of prompt6) {
|
|
101715
101936
|
switch (role) {
|
|
101716
101937
|
case "system": {
|
|
101717
101938
|
switch (systemMessageMode) {
|
|
@@ -101928,7 +102149,7 @@ var OllamaChatLanguageModel = class {
|
|
|
101928
102149
|
return this.config.provider;
|
|
101929
102150
|
}
|
|
101930
102151
|
async getArgs({
|
|
101931
|
-
prompt:
|
|
102152
|
+
prompt: prompt6,
|
|
101932
102153
|
maxOutputTokens,
|
|
101933
102154
|
temperature,
|
|
101934
102155
|
topP,
|
|
@@ -101964,7 +102185,7 @@ var OllamaChatLanguageModel = class {
|
|
|
101964
102185
|
});
|
|
101965
102186
|
}
|
|
101966
102187
|
const messages = convertToOllamaChatMessages({
|
|
101967
|
-
prompt:
|
|
102188
|
+
prompt: prompt6,
|
|
101968
102189
|
systemMessageMode: getSystemMessageMode2(this.modelId)
|
|
101969
102190
|
});
|
|
101970
102191
|
const strictJsonSchema = (_c = ollamaOptions.strictJsonSchema) != null ? _c : false;
|
|
@@ -101993,7 +102214,7 @@ var OllamaChatLanguageModel = class {
|
|
|
101993
102214
|
seed,
|
|
101994
102215
|
think: (_e = ollamaOptions.think) != null ? _e : false,
|
|
101995
102216
|
messages: convertToOllamaChatMessages({
|
|
101996
|
-
prompt:
|
|
102217
|
+
prompt: prompt6,
|
|
101997
102218
|
systemMessageMode: getSystemMessageMode2(this.modelId)
|
|
101998
102219
|
})
|
|
101999
102220
|
};
|
|
@@ -102327,23 +102548,23 @@ var reasoningModels2 = {
|
|
|
102327
102548
|
}
|
|
102328
102549
|
};
|
|
102329
102550
|
function convertToOllamaCompletionPrompt({
|
|
102330
|
-
prompt:
|
|
102551
|
+
prompt: prompt6,
|
|
102331
102552
|
user = "user",
|
|
102332
102553
|
assistant = "assistant"
|
|
102333
102554
|
}) {
|
|
102334
102555
|
let text2 = "";
|
|
102335
|
-
if (
|
|
102336
|
-
text2 += `${
|
|
102556
|
+
if (prompt6[0].role === "system") {
|
|
102557
|
+
text2 += `${prompt6[0].content}
|
|
102337
102558
|
|
|
102338
102559
|
`;
|
|
102339
|
-
|
|
102560
|
+
prompt6 = prompt6.slice(1);
|
|
102340
102561
|
}
|
|
102341
|
-
for (const { role, content } of
|
|
102562
|
+
for (const { role, content } of prompt6) {
|
|
102342
102563
|
switch (role) {
|
|
102343
102564
|
case "system": {
|
|
102344
102565
|
throw new InvalidPromptError({
|
|
102345
102566
|
message: "Unexpected system message in prompt: ${content}",
|
|
102346
|
-
prompt:
|
|
102567
|
+
prompt: prompt6
|
|
102347
102568
|
});
|
|
102348
102569
|
}
|
|
102349
102570
|
case "user": {
|
|
@@ -102413,7 +102634,7 @@ var OllamaCompletionLanguageModel = class {
|
|
|
102413
102634
|
return this.config.provider;
|
|
102414
102635
|
}
|
|
102415
102636
|
async getArgs({
|
|
102416
|
-
prompt:
|
|
102637
|
+
prompt: prompt6,
|
|
102417
102638
|
maxOutputTokens,
|
|
102418
102639
|
temperature,
|
|
102419
102640
|
topP,
|
|
@@ -102453,7 +102674,7 @@ var OllamaCompletionLanguageModel = class {
|
|
|
102453
102674
|
details: "JSON response format is not supported."
|
|
102454
102675
|
});
|
|
102455
102676
|
}
|
|
102456
|
-
const { prompt: completionPrompt, stopSequences } = convertToOllamaCompletionPrompt({ prompt:
|
|
102677
|
+
const { prompt: completionPrompt, stopSequences } = convertToOllamaCompletionPrompt({ prompt: prompt6 });
|
|
102457
102678
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
102458
102679
|
return {
|
|
102459
102680
|
args: {
|
|
@@ -102687,7 +102908,7 @@ var OllamaImageModel = class {
|
|
|
102687
102908
|
return this.config.provider;
|
|
102688
102909
|
}
|
|
102689
102910
|
async doGenerate({
|
|
102690
|
-
prompt:
|
|
102911
|
+
prompt: prompt6,
|
|
102691
102912
|
n,
|
|
102692
102913
|
size,
|
|
102693
102914
|
aspectRatio,
|
|
@@ -102717,7 +102938,7 @@ var OllamaImageModel = class {
|
|
|
102717
102938
|
headers: combineHeaders(this.config.headers(), headers),
|
|
102718
102939
|
body: {
|
|
102719
102940
|
model: this.modelId,
|
|
102720
|
-
prompt:
|
|
102941
|
+
prompt: prompt6,
|
|
102721
102942
|
n,
|
|
102722
102943
|
size,
|
|
102723
102944
|
...(_d = providerOptions.ollama) != null ? _d : {},
|
|
@@ -102743,12 +102964,12 @@ var ollamaImageResponseSchema = exports_external4.object({
|
|
|
102743
102964
|
data: exports_external4.array(exports_external4.object({ b64_json: exports_external4.string() }))
|
|
102744
102965
|
});
|
|
102745
102966
|
function convertToOllamaResponsesMessages({
|
|
102746
|
-
prompt:
|
|
102967
|
+
prompt: prompt6,
|
|
102747
102968
|
systemMessageMode
|
|
102748
102969
|
}) {
|
|
102749
102970
|
const messages = [];
|
|
102750
102971
|
const warnings = [];
|
|
102751
|
-
for (const { role, content } of
|
|
102972
|
+
for (const { role, content } of prompt6) {
|
|
102752
102973
|
switch (role) {
|
|
102753
102974
|
case "system": {
|
|
102754
102975
|
switch (systemMessageMode) {
|
|
@@ -102962,7 +103183,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
102962
103183
|
presencePenalty,
|
|
102963
103184
|
frequencyPenalty,
|
|
102964
103185
|
seed,
|
|
102965
|
-
prompt:
|
|
103186
|
+
prompt: prompt6,
|
|
102966
103187
|
providerOptions,
|
|
102967
103188
|
tools: tools2,
|
|
102968
103189
|
toolChoice,
|
|
@@ -102993,7 +103214,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
102993
103214
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
102994
103215
|
}
|
|
102995
103216
|
const { messages, warnings: messageWarnings } = convertToOllamaResponsesMessages({
|
|
102996
|
-
prompt:
|
|
103217
|
+
prompt: prompt6,
|
|
102997
103218
|
systemMessageMode: modelConfig.systemMessageMode
|
|
102998
103219
|
});
|
|
102999
103220
|
warnings.push(...messageWarnings);
|
|
@@ -103006,7 +103227,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
103006
103227
|
const baseArgs = {
|
|
103007
103228
|
model: this.modelId,
|
|
103008
103229
|
messages: convertToOllamaChatMessages({
|
|
103009
|
-
prompt:
|
|
103230
|
+
prompt: prompt6,
|
|
103010
103231
|
systemMessageMode: "system"
|
|
103011
103232
|
}),
|
|
103012
103233
|
temperature,
|
|
@@ -103543,6 +103764,22 @@ var ollama = createOllama({
|
|
|
103543
103764
|
compatibility: "strict"
|
|
103544
103765
|
});
|
|
103545
103766
|
|
|
103767
|
+
// src/env.ts
|
|
103768
|
+
function getEnv(override) {
|
|
103769
|
+
return {
|
|
103770
|
+
POLKA_API_PROVIDER: process.env.POLKA_API_PROVIDER,
|
|
103771
|
+
POLKA_MODEL: process.env.POLKA_MODEL,
|
|
103772
|
+
POLKA_API_KEY: process.env.POLKA_API_KEY,
|
|
103773
|
+
POLKA_BUDGET: process.env.POLKA_BUDGET,
|
|
103774
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
|
|
103775
|
+
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY,
|
|
103776
|
+
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY,
|
|
103777
|
+
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
|
|
103778
|
+
TRACING_FILE: process.env.TRACING_FILE,
|
|
103779
|
+
...override
|
|
103780
|
+
};
|
|
103781
|
+
}
|
|
103782
|
+
|
|
103546
103783
|
// src/getModel.ts
|
|
103547
103784
|
var AiProvider;
|
|
103548
103785
|
((AiProvider2) => {
|
|
@@ -103554,12 +103791,29 @@ var AiProvider;
|
|
|
103554
103791
|
AiProvider2["GoogleVertex"] = "google-vertex";
|
|
103555
103792
|
})(AiProvider ||= {});
|
|
103556
103793
|
var getModel = (config5, debugLogging = false) => {
|
|
103557
|
-
const
|
|
103558
|
-
|
|
103559
|
-
|
|
103560
|
-
|
|
103794
|
+
const { TRACING_FILE } = getEnv();
|
|
103795
|
+
const fetchOverride = debugLogging || TRACING_FILE ? async (url4, options) => {
|
|
103796
|
+
const requestBody = options?.body ? JSON.parse(options.body) : undefined;
|
|
103797
|
+
if (debugLogging) {
|
|
103798
|
+
console.log("-> Request URL:", url4);
|
|
103799
|
+
console.log("-> Request Headers:", options?.headers);
|
|
103800
|
+
console.log("-> Request Body:");
|
|
103801
|
+
console.dir(requestBody, { depth: null });
|
|
103802
|
+
}
|
|
103803
|
+
if (TRACING_FILE) {
|
|
103804
|
+
appendFileSync(TRACING_FILE, `${JSON.stringify({
|
|
103805
|
+
type: "request",
|
|
103806
|
+
timestamp: new Date().toISOString(),
|
|
103807
|
+
url: url4,
|
|
103808
|
+
headers: options?.headers,
|
|
103809
|
+
body: requestBody
|
|
103810
|
+
}, null, 2)}
|
|
103811
|
+
`);
|
|
103812
|
+
}
|
|
103561
103813
|
const res = await fetch(url4, options);
|
|
103562
|
-
|
|
103814
|
+
if (debugLogging) {
|
|
103815
|
+
console.log("<- Response Status:", res.status);
|
|
103816
|
+
}
|
|
103563
103817
|
const contentType = res.headers.get("content-type") || "";
|
|
103564
103818
|
if (contentType.includes("text/event-stream") && res.body) {
|
|
103565
103819
|
const [branch, clientStream] = res.body.tee();
|
|
@@ -103572,7 +103826,16 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103572
103826
|
done = d;
|
|
103573
103827
|
if (value) {
|
|
103574
103828
|
const text2 = decoder.decode(value);
|
|
103575
|
-
|
|
103829
|
+
if (debugLogging) {
|
|
103830
|
+
console.log("<- Stream chunk:", text2.replace(/\n/g, "\\n"));
|
|
103831
|
+
}
|
|
103832
|
+
if (TRACING_FILE) {
|
|
103833
|
+
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103834
|
+
type: "response-chunk",
|
|
103835
|
+
timestamp: new Date().toISOString(),
|
|
103836
|
+
chunk: text2
|
|
103837
|
+
}, null, 2));
|
|
103838
|
+
}
|
|
103576
103839
|
}
|
|
103577
103840
|
}
|
|
103578
103841
|
})();
|
|
@@ -103582,8 +103845,20 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103582
103845
|
});
|
|
103583
103846
|
}
|
|
103584
103847
|
const full = await res.text();
|
|
103585
|
-
|
|
103586
|
-
|
|
103848
|
+
const responseBody = JSON.parse(full);
|
|
103849
|
+
if (debugLogging) {
|
|
103850
|
+
console.log("<- Response Body:");
|
|
103851
|
+
console.dir(responseBody, { depth: null });
|
|
103852
|
+
}
|
|
103853
|
+
if (TRACING_FILE) {
|
|
103854
|
+
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103855
|
+
type: "response",
|
|
103856
|
+
timestamp: new Date().toISOString(),
|
|
103857
|
+
status: res.status,
|
|
103858
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
103859
|
+
body: responseBody
|
|
103860
|
+
}, null, 2));
|
|
103861
|
+
}
|
|
103587
103862
|
return new Response(full, {
|
|
103588
103863
|
headers: res.headers,
|
|
103589
103864
|
status: res.status
|
|
@@ -103646,12 +103921,12 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103646
103921
|
};
|
|
103647
103922
|
|
|
103648
103923
|
// src/ApiProviderConfig.ts
|
|
103649
|
-
var
|
|
103924
|
+
var isClaude = (model) => model.includes("claude");
|
|
103650
103925
|
var getToolFormat = (model, toolFormat) => {
|
|
103651
103926
|
if (toolFormat) {
|
|
103652
103927
|
return toolFormat;
|
|
103653
103928
|
}
|
|
103654
|
-
if (
|
|
103929
|
+
if (isClaude(model)) {
|
|
103655
103930
|
return "native";
|
|
103656
103931
|
}
|
|
103657
103932
|
return "polka-codes";
|
|
@@ -103872,11 +104147,11 @@ Aborting request...`);
|
|
|
103872
104147
|
// src/prices.ts
|
|
103873
104148
|
var prices_default = {
|
|
103874
104149
|
["anthropic" /* Anthropic */]: {
|
|
103875
|
-
"claude-opus-4-20250514": { inputPrice: 15, outputPrice: 75, cacheWritesPrice: 18.75, cacheReadsPrice: 1.5 },
|
|
103876
|
-
"claude-sonnet-4-20250514": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3 },
|
|
103877
|
-
"claude-3-7-sonnet-20250219": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3 },
|
|
103878
|
-
"claude-3-5-sonnet-20241022": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3 },
|
|
103879
|
-
"claude-3-5-haiku-20241022": { inputPrice: 0.8, outputPrice: 4, cacheWritesPrice: 1, cacheReadsPrice: 0.08 }
|
|
104150
|
+
"claude-opus-4-20250514": { inputPrice: 15, outputPrice: 75, cacheWritesPrice: 18.75, cacheReadsPrice: 1.5, supportsThinking: true },
|
|
104151
|
+
"claude-sonnet-4-20250514": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: true },
|
|
104152
|
+
"claude-3-7-sonnet-20250219": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: true },
|
|
104153
|
+
"claude-3-5-sonnet-20241022": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: false },
|
|
104154
|
+
"claude-3-5-haiku-20241022": { inputPrice: 0.8, outputPrice: 4, cacheWritesPrice: 1, cacheReadsPrice: 0.08, supportsThinking: false }
|
|
103880
104155
|
},
|
|
103881
104156
|
["ollama" /* Ollama */]: {},
|
|
103882
104157
|
["deepseek" /* DeepSeek */]: {
|
|
@@ -103891,9 +104166,9 @@ var prices_default = {
|
|
|
103891
104166
|
"o4-mini": { inputPrice: 1.1, outputPrice: 4.4, cacheWritesPrice: 0.275, cacheReadsPrice: 0.275 }
|
|
103892
104167
|
},
|
|
103893
104168
|
["google-vertex" /* GoogleVertex */]: {
|
|
103894
|
-
"gemini-
|
|
103895
|
-
"gemini-
|
|
103896
|
-
"gemini-
|
|
104169
|
+
"gemini-2.5-pro": { inputPrice: 2.5, outputPrice: 10, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: true },
|
|
104170
|
+
"gemini-2.5-flash": { inputPrice: 0.3, outputPrice: 2.5, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: false },
|
|
104171
|
+
"gemini-2.5-flash-lite": { inputPrice: 0.1, outputPrice: 0.4, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: false }
|
|
103897
104172
|
}
|
|
103898
104173
|
};
|
|
103899
104174
|
|
|
@@ -103969,7 +104244,7 @@ import os2 from "node:os";
|
|
|
103969
104244
|
import { existsSync, readFileSync } from "node:fs";
|
|
103970
104245
|
import { homedir } from "node:os";
|
|
103971
104246
|
import { join } from "node:path";
|
|
103972
|
-
var
|
|
104247
|
+
var import_lodash2 = __toESM(require_lodash(), 1);
|
|
103973
104248
|
|
|
103974
104249
|
// ../cli-shared/node_modules/yaml/dist/index.js
|
|
103975
104250
|
var composer = require_composer();
|
|
@@ -107880,7 +108155,7 @@ function mergeConfigs(configs) {
|
|
|
107880
108155
|
return {};
|
|
107881
108156
|
}
|
|
107882
108157
|
const mergedConfig = configs.reduce((acc, config5) => {
|
|
107883
|
-
const merged =
|
|
108158
|
+
const merged = import_lodash2.merge({}, acc, config5);
|
|
107884
108159
|
let accRules = acc.rules ?? [];
|
|
107885
108160
|
if (typeof accRules === "string") {
|
|
107886
108161
|
accRules = [accRules];
|
|
@@ -108727,7 +109002,7 @@ ${event.systemPrompt}`);
|
|
|
108727
109002
|
======== New Request ========
|
|
108728
109003
|
`);
|
|
108729
109004
|
if (verbose) {
|
|
108730
|
-
const
|
|
109005
|
+
const userMessage = event.userMessage.content;
|
|
108731
109006
|
if (typeof userMessage === "string") {
|
|
108732
109007
|
console.log(userMessage);
|
|
108733
109008
|
} else {
|
|
@@ -108746,9 +109021,17 @@ ${event.systemPrompt}`);
|
|
|
108746
109021
|
case "file":
|
|
108747
109022
|
console.log(source_default.yellow(`[File name: ${content.filename}, type: ${content.mediaType}]`));
|
|
108748
109023
|
break;
|
|
108749
|
-
|
|
108750
|
-
console.log(source_default.
|
|
108751
|
-
|
|
109024
|
+
case "tool-call":
|
|
109025
|
+
console.log(source_default.yellow(`[Tool call: ${content.toolName}]`));
|
|
109026
|
+
break;
|
|
109027
|
+
case "tool-result":
|
|
109028
|
+
console.log(source_default.yellow(`[Tool result: ${content.toolName}]`));
|
|
109029
|
+
if (verbose > 0) {
|
|
109030
|
+
console.log(content.output);
|
|
109031
|
+
}
|
|
109032
|
+
break;
|
|
109033
|
+
case "reasoning":
|
|
109034
|
+
break;
|
|
108752
109035
|
}
|
|
108753
109036
|
}
|
|
108754
109037
|
}
|
|
@@ -108782,29 +109065,33 @@ ${event.systemPrompt}`);
|
|
|
108782
109065
|
process.stdout.write(source_default.dim(event.newText));
|
|
108783
109066
|
hadReasoning = true;
|
|
108784
109067
|
break;
|
|
108785
|
-
case "ToolUse" /* ToolUse */:
|
|
108786
|
-
|
|
108787
|
-
|
|
108788
|
-
|
|
108789
|
-
|
|
108790
|
-
|
|
109068
|
+
case "ToolUse" /* ToolUse */: {
|
|
109069
|
+
console.log(source_default.yellow(`
|
|
109070
|
+
|
|
109071
|
+
Tool use:`, event.tool), event.content);
|
|
109072
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
109073
|
+
stats.calls++;
|
|
109074
|
+
toolCallStats.set(event.tool, stats);
|
|
108791
109075
|
break;
|
|
108792
|
-
|
|
108793
|
-
|
|
108794
|
-
|
|
108795
|
-
|
|
108796
|
-
|
|
108797
|
-
}
|
|
109076
|
+
}
|
|
109077
|
+
case "ToolReply" /* ToolReply */: {
|
|
109078
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
109079
|
+
stats.success++;
|
|
109080
|
+
toolCallStats.set(event.tool, stats);
|
|
108798
109081
|
break;
|
|
109082
|
+
}
|
|
108799
109083
|
case "ToolInvalid" /* ToolInvalid */:
|
|
108800
109084
|
break;
|
|
108801
|
-
case "ToolError" /* ToolError */:
|
|
108802
|
-
|
|
108803
|
-
|
|
108804
|
-
|
|
108805
|
-
|
|
108806
|
-
}
|
|
109085
|
+
case "ToolError" /* ToolError */: {
|
|
109086
|
+
console.error(source_default.red(`
|
|
109087
|
+
|
|
109088
|
+
Tool error:`, event.tool));
|
|
109089
|
+
console.error(source_default.red(event.content));
|
|
109090
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
109091
|
+
stats.errors++;
|
|
109092
|
+
toolCallStats.set(event.tool, stats);
|
|
108807
109093
|
break;
|
|
109094
|
+
}
|
|
108808
109095
|
case "ToolInterrupted" /* ToolInterrupted */:
|
|
108809
109096
|
break;
|
|
108810
109097
|
case "ToolHandOver" /* ToolHandOver */:
|
|
@@ -108872,23 +109159,7 @@ ${event.systemPrompt}`);
|
|
|
108872
109159
|
};
|
|
108873
109160
|
};
|
|
108874
109161
|
// src/options.ts
|
|
108875
|
-
var
|
|
108876
|
-
|
|
108877
|
-
// src/env.ts
|
|
108878
|
-
function getEnv(override) {
|
|
108879
|
-
return {
|
|
108880
|
-
POLKA_API_PROVIDER: process.env.POLKA_API_PROVIDER,
|
|
108881
|
-
POLKA_MODEL: process.env.POLKA_MODEL,
|
|
108882
|
-
POLKA_API_KEY: process.env.POLKA_API_KEY,
|
|
108883
|
-
POLKA_BUDGET: process.env.POLKA_BUDGET,
|
|
108884
|
-
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
|
|
108885
|
-
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY,
|
|
108886
|
-
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY,
|
|
108887
|
-
...override
|
|
108888
|
-
};
|
|
108889
|
-
}
|
|
108890
|
-
|
|
108891
|
-
// src/options.ts
|
|
109162
|
+
var import_lodash3 = __toESM(require_lodash(), 1);
|
|
108892
109163
|
function addSharedOptions(command) {
|
|
108893
109164
|
return command.option("-c --config <paths>", "Path to config file(s)", (value, prev) => prev.concat(value), []).option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-messages <iterations>", "Maximum number of messages to send. Default to 50", Number.parseInt, 50).option("--budget <budget>", "Budget for the AI service. Default to $10", Number.parseFloat).option("--retry-count <count>", "Number of retries for failed requests. Default to 5", Number.parseInt, 5).option("--request-timeout-seconds <seconds>", "Request timeout in seconds. Default to 10", Number.parseInt, 10).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (_value, prev) => prev + 1, 0).option("-d --base-dir <path>", "Base directory to run commands in").option("--agent <agent>", "Initial agent to use (default: architect)");
|
|
108894
109165
|
}
|
|
@@ -108898,8 +109169,6 @@ function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
|
|
|
108898
109169
|
process.chdir(options.baseDir);
|
|
108899
109170
|
cwd = options.baseDir;
|
|
108900
109171
|
console.log("Changed working directory to", cwd);
|
|
108901
|
-
} else {
|
|
108902
|
-
cwd = process.cwd();
|
|
108903
109172
|
}
|
|
108904
109173
|
const config6 = loadConfig(options.config, cwd, home) ?? {};
|
|
108905
109174
|
if (options.retryCount !== undefined) {
|
|
@@ -108911,26 +109180,26 @@ function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
|
|
|
108911
109180
|
const defaultProvider = options.apiProvider || env2.POLKA_API_PROVIDER || config6.defaultProvider;
|
|
108912
109181
|
const defaultModel = options.model || env2.POLKA_MODEL || config6.defaultModel;
|
|
108913
109182
|
if (defaultProvider && defaultModel) {
|
|
108914
|
-
|
|
109183
|
+
import_lodash3.set(config6, ["providers", defaultProvider, "defaultModel"], defaultModel);
|
|
108915
109184
|
}
|
|
108916
109185
|
const apiKey = options.apiKey || env2.POLKA_API_KEY;
|
|
108917
109186
|
if (apiKey) {
|
|
108918
109187
|
if (!defaultProvider) {
|
|
108919
109188
|
throw new Error("Must specify a provider if providing an API key");
|
|
108920
109189
|
}
|
|
108921
|
-
|
|
109190
|
+
import_lodash3.set(config6, ["providers", defaultProvider, "apiKey"], apiKey);
|
|
108922
109191
|
}
|
|
108923
109192
|
if (env2.ANTHROPIC_API_KEY) {
|
|
108924
|
-
|
|
109193
|
+
import_lodash3.set(config6, ["providers", "anthropic" /* Anthropic */, "apiKey"], env2.ANTHROPIC_API_KEY);
|
|
108925
109194
|
}
|
|
108926
109195
|
if (env2.DEEPSEEK_API_KEY) {
|
|
108927
|
-
|
|
109196
|
+
import_lodash3.set(config6, ["providers", "deepseek" /* DeepSeek */, "apiKey"], env2.DEEPSEEK_API_KEY);
|
|
108928
109197
|
}
|
|
108929
109198
|
if (env2.OPENROUTER_API_KEY) {
|
|
108930
|
-
|
|
109199
|
+
import_lodash3.set(config6, ["providers", "openrouter" /* OpenRouter */, "apiKey"], env2.OPENROUTER_API_KEY);
|
|
108931
109200
|
}
|
|
108932
109201
|
if (env2.OPENAI_API_KEY) {
|
|
108933
|
-
|
|
109202
|
+
import_lodash3.set(config6, ["providers", "ollama" /* Ollama */, "apiKey"], env2.OPENAI_API_KEY);
|
|
108934
109203
|
}
|
|
108935
109204
|
const providerConfig = new ApiProviderConfig({
|
|
108936
109205
|
defaultProvider,
|
|
@@ -108949,14 +109218,59 @@ function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
|
|
|
108949
109218
|
// src/Runner.ts
|
|
108950
109219
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
108951
109220
|
import os3 from "node:os";
|
|
108952
|
-
var
|
|
109221
|
+
var import_lodash4 = __toESM(require_lodash(), 1);
|
|
109222
|
+
|
|
109223
|
+
// src/getProviderOptions.ts
|
|
109224
|
+
function getProviderOptions(provider3, modelId, thinkingBudgetTokens, supportThinking) {
|
|
109225
|
+
if (thinkingBudgetTokens <= 0 || !provider3 || !modelId) {
|
|
109226
|
+
return {};
|
|
109227
|
+
}
|
|
109228
|
+
const modelInfo = prices_default[provider3]?.[modelId];
|
|
109229
|
+
const providerSupportsThinking = provider3 === "openrouter" /* OpenRouter */ || !!modelInfo?.supportsThinking;
|
|
109230
|
+
const shouldSupportThinking = supportThinking ?? providerSupportsThinking;
|
|
109231
|
+
if (!shouldSupportThinking) {
|
|
109232
|
+
return {};
|
|
109233
|
+
}
|
|
109234
|
+
const providerOptions = {};
|
|
109235
|
+
switch (provider3) {
|
|
109236
|
+
case "anthropic" /* Anthropic */:
|
|
109237
|
+
providerOptions.anthropic = {
|
|
109238
|
+
thinking: { type: "enabled", budgetTokens: thinkingBudgetTokens }
|
|
109239
|
+
};
|
|
109240
|
+
break;
|
|
109241
|
+
case "openrouter" /* OpenRouter */:
|
|
109242
|
+
providerOptions.openrouter = {
|
|
109243
|
+
reasoning: {
|
|
109244
|
+
max_tokens: thinkingBudgetTokens
|
|
109245
|
+
}
|
|
109246
|
+
};
|
|
109247
|
+
break;
|
|
109248
|
+
case "google-vertex" /* GoogleVertex */:
|
|
109249
|
+
providerOptions.google = {
|
|
109250
|
+
thinkingConfig: {
|
|
109251
|
+
includeThoughts: true,
|
|
109252
|
+
thinkingBudget: thinkingBudgetTokens
|
|
109253
|
+
}
|
|
109254
|
+
};
|
|
109255
|
+
break;
|
|
109256
|
+
case "ollama" /* Ollama */:
|
|
109257
|
+
break;
|
|
109258
|
+
case "deepseek" /* DeepSeek */:
|
|
109259
|
+
break;
|
|
109260
|
+
case "openai" /* OpenAI */:
|
|
109261
|
+
break;
|
|
109262
|
+
}
|
|
109263
|
+
return providerOptions;
|
|
109264
|
+
}
|
|
109265
|
+
|
|
109266
|
+
// src/Runner.ts
|
|
108953
109267
|
class Runner {
|
|
108954
109268
|
#options;
|
|
108955
109269
|
usageMeter;
|
|
108956
109270
|
multiAgent;
|
|
108957
109271
|
constructor(options) {
|
|
108958
109272
|
this.#options = options;
|
|
108959
|
-
this.usageMeter = new UsageMeter(
|
|
109273
|
+
this.usageMeter = new UsageMeter(import_lodash4.merge(prices_default, options.config.prices ?? {}), {
|
|
108960
109274
|
maxMessages: options.config.maxMessageCount ?? 0,
|
|
108961
109275
|
maxCost: options.config.budget ?? 0
|
|
108962
109276
|
});
|
|
@@ -108964,7 +109278,7 @@ class Runner {
|
|
|
108964
109278
|
if (typeof rules2 === "string") {
|
|
108965
109279
|
rules2 = [rules2];
|
|
108966
109280
|
}
|
|
108967
|
-
const
|
|
109281
|
+
const toolProviderOptions = {
|
|
108968
109282
|
command: {
|
|
108969
109283
|
onStarted(command) {
|
|
108970
109284
|
console.log(`$ >>>> $ ${command}`);
|
|
@@ -109027,6 +109341,7 @@ class Runner {
|
|
|
109027
109341
|
const requestTimeoutSeconds = agentConfig.requestTimeoutSeconds ?? this.#options.config.requestTimeoutSeconds;
|
|
109028
109342
|
const ai = getOrCreateLlm(agentName);
|
|
109029
109343
|
const config6 = this.#options.providerConfig.getConfigForAgent(agentName);
|
|
109344
|
+
const providerOptions = config6 ? getProviderOptions(config6.provider, ai.modelId, config6.parameters?.thinkingBudgetTokens ?? 0) : {};
|
|
109030
109345
|
const args = {
|
|
109031
109346
|
ai,
|
|
109032
109347
|
os: platform,
|
|
@@ -109038,8 +109353,11 @@ class Runner {
|
|
|
109038
109353
|
policies: policies2,
|
|
109039
109354
|
retryCount,
|
|
109040
109355
|
requestTimeoutSeconds,
|
|
109041
|
-
toolFormat: this.#options.config.toolFormat ?? "polka-codes",
|
|
109042
|
-
parameters:
|
|
109356
|
+
toolFormat: this.#options.config.toolFormat ?? config6?.toolFormat ?? "polka-codes",
|
|
109357
|
+
parameters: {
|
|
109358
|
+
...config6?.parameters,
|
|
109359
|
+
providerOptions
|
|
109360
|
+
},
|
|
109043
109361
|
usageMeter: this.usageMeter
|
|
109044
109362
|
};
|
|
109045
109363
|
switch (agentName) {
|
|
@@ -109047,23 +109365,23 @@ class Runner {
|
|
|
109047
109365
|
return new CoderAgent({
|
|
109048
109366
|
...args,
|
|
109049
109367
|
interactive: false,
|
|
109050
|
-
provider: getProvider(agentName, options.config,
|
|
109368
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109051
109369
|
});
|
|
109052
109370
|
case architectAgentInfo.name:
|
|
109053
109371
|
return new ArchitectAgent({
|
|
109054
109372
|
...args,
|
|
109055
|
-
provider: getProvider(agentName, options.config,
|
|
109373
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109056
109374
|
});
|
|
109057
109375
|
case analyzerAgentInfo.name:
|
|
109058
109376
|
return new AnalyzerAgent({
|
|
109059
109377
|
...args,
|
|
109060
109378
|
interactive: false,
|
|
109061
|
-
provider: getProvider(agentName, options.config,
|
|
109379
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109062
109380
|
});
|
|
109063
109381
|
case codeFixerAgentInfo.name:
|
|
109064
109382
|
return new CodeFixerAgent({
|
|
109065
109383
|
...args,
|
|
109066
|
-
provider: getProvider(agentName, options.config,
|
|
109384
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109067
109385
|
});
|
|
109068
109386
|
default:
|
|
109069
109387
|
throw new Error(`Unknown agent: ${name18}`);
|
|
@@ -109160,10 +109478,10 @@ var runChat = async (opts, command) => {
|
|
|
109160
109478
|
if (!providerDetails?.provider) {
|
|
109161
109479
|
const newConfig = await configPrompt({});
|
|
109162
109480
|
const updatedConfig = JSON.parse(JSON.stringify(config6 ?? {}));
|
|
109163
|
-
|
|
109164
|
-
|
|
109481
|
+
import_lodash5.set(updatedConfig, `providers.${newConfig.provider}.model`, newConfig.model);
|
|
109482
|
+
import_lodash5.set(updatedConfig, `providers.${newConfig.provider}.apiKey`, newConfig.apiKey);
|
|
109165
109483
|
if (newConfig.baseURL) {
|
|
109166
|
-
|
|
109484
|
+
import_lodash5.set(updatedConfig, `providers.${newConfig.provider}.baseURL`, newConfig.baseURL);
|
|
109167
109485
|
}
|
|
109168
109486
|
providerConfig = new ApiProviderConfig(updatedConfig);
|
|
109169
109487
|
providerDetails = providerConfig.getConfigForAgent(agent);
|
|
@@ -109233,6 +109551,7 @@ var runChat = async (opts, command) => {
|
|
|
109233
109551
|
|
|
109234
109552
|
// src/commands/commit.ts
|
|
109235
109553
|
import { execSync, spawnSync as spawnSync2 } from "node:child_process";
|
|
109554
|
+
var import_lodash6 = __toESM(require_lodash(), 1);
|
|
109236
109555
|
|
|
109237
109556
|
// ../../node_modules/ora/index.js
|
|
109238
109557
|
import process10 from "node:process";
|
|
@@ -109841,15 +110160,15 @@ function ora(options) {
|
|
|
109841
110160
|
var commitCommand = new Command("commit").description("Create a commit with AI-generated message").option("-a, --all", "Stage all files before committing").argument("[message]", "Optional context for the commit message generation").action(async (message, localOptions, command) => {
|
|
109842
110161
|
const spinner = ora("Gathering information...").start();
|
|
109843
110162
|
const options = command.parent?.opts() ?? {};
|
|
109844
|
-
const { providerConfig } = parseOptions(options);
|
|
109845
|
-
const
|
|
109846
|
-
|
|
109847
|
-
|
|
109848
|
-
if (!provider3 || !model) {
|
|
109849
|
-
console.error('Error: No provider specified. Please run "pokla config" to configure your AI provider.');
|
|
110163
|
+
const { providerConfig, config: config6 } = parseOptions(options);
|
|
110164
|
+
const commandConfig = providerConfig.getConfigForCommand("commit");
|
|
110165
|
+
if (!commandConfig || !commandConfig.provider || !commandConfig.model) {
|
|
110166
|
+
console.error('Error: No provider specified. Please run "polka config" to configure your AI provider.');
|
|
109850
110167
|
process.exit(1);
|
|
109851
110168
|
}
|
|
109852
|
-
|
|
110169
|
+
console.log("Provider:", commandConfig.provider);
|
|
110170
|
+
console.log("Model:", commandConfig.model);
|
|
110171
|
+
const usage = new UsageMeter(import_lodash6.merge(prices_default, config6.prices ?? {}));
|
|
109853
110172
|
try {
|
|
109854
110173
|
const status = execSync("git status --porcelain").toString();
|
|
109855
110174
|
const stagedFiles = status.split(`
|
|
@@ -109874,11 +110193,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
109874
110193
|
}
|
|
109875
110194
|
const diff = execSync("git diff --cached -U50").toString();
|
|
109876
110195
|
spinner.text = "Generating commit message...";
|
|
109877
|
-
const llm = getModel(
|
|
109878
|
-
provider: provider3,
|
|
109879
|
-
model,
|
|
109880
|
-
apiKey
|
|
109881
|
-
});
|
|
110196
|
+
const llm = getModel(commandConfig);
|
|
109882
110197
|
const _schema = exports_external2.object({
|
|
109883
110198
|
reasoning: exports_external2.string().describe("Reasoning if any"),
|
|
109884
110199
|
message: exports_external2.string().describe("The generated commit message")
|
|
@@ -109973,7 +110288,7 @@ var createCommand2 = new Command("create").description("Create a new project").a
|
|
|
109973
110288
|
// src/commands/init.ts
|
|
109974
110289
|
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
109975
110290
|
import { dirname as dirname2 } from "node:path";
|
|
109976
|
-
var
|
|
110291
|
+
var import_lodash7 = __toESM(require_lodash(), 1);
|
|
109977
110292
|
|
|
109978
110293
|
// ../../node_modules/yaml/dist/index.js
|
|
109979
110294
|
var composer2 = require_composer2();
|
|
@@ -110104,7 +110419,7 @@ initCommand.action(async (options, command) => {
|
|
|
110104
110419
|
break;
|
|
110105
110420
|
case 2: {
|
|
110106
110421
|
const globalConfig4 = loadConfigAtPath(globalConfigPath) ?? {};
|
|
110107
|
-
|
|
110422
|
+
import_lodash7.set(globalConfig4, ["providers", newConfig.provider, "apiKey"], newConfig.apiKey);
|
|
110108
110423
|
mkdirSync(dirname2(globalConfigPath), { recursive: true });
|
|
110109
110424
|
writeFileSync(globalConfigPath, $stringify2(globalConfig4));
|
|
110110
110425
|
console.log(`API key saved to global config file: ${globalConfigPath}`);
|
|
@@ -110159,7 +110474,7 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
110159
110474
|
finalConfig.defaultProvider = newConfig.provider;
|
|
110160
110475
|
finalConfig.defaultModel = newConfig.model;
|
|
110161
110476
|
if (newConfig.apiKey) {
|
|
110162
|
-
|
|
110477
|
+
import_lodash7.set(finalConfig, ["providers", newConfig.provider, "apiKey"], newConfig.apiKey);
|
|
110163
110478
|
}
|
|
110164
110479
|
}
|
|
110165
110480
|
mkdirSync(dirname2(configPath), { recursive: true });
|
|
@@ -110173,17 +110488,18 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
110173
110488
|
|
|
110174
110489
|
// src/commands/pr.ts
|
|
110175
110490
|
import { execSync as execSync2, spawnSync as spawnSync3 } from "node:child_process";
|
|
110491
|
+
var import_lodash8 = __toESM(require_lodash(), 1);
|
|
110176
110492
|
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) => {
|
|
110177
110493
|
const options = command.parent?.opts() ?? {};
|
|
110178
110494
|
const { providerConfig, config: config6 } = parseOptions(options);
|
|
110179
|
-
const
|
|
110180
|
-
|
|
110181
|
-
|
|
110182
|
-
console.error('Error: No provider specified. Please run "pokla config" to configure your AI provider.');
|
|
110495
|
+
const commandConfig = providerConfig.getConfigForCommand("pr");
|
|
110496
|
+
if (!commandConfig || !commandConfig.provider || !commandConfig.model) {
|
|
110497
|
+
console.error('Error: No provider specified. Please run "polka config" to configure your AI provider.');
|
|
110183
110498
|
process.exit(1);
|
|
110184
110499
|
}
|
|
110185
|
-
|
|
110186
|
-
console.log("
|
|
110500
|
+
const spinner = ora("Gathering information...").start();
|
|
110501
|
+
console.log("Provider:", commandConfig.provider);
|
|
110502
|
+
console.log("Model:", commandConfig.model);
|
|
110187
110503
|
try {
|
|
110188
110504
|
execSync2("gh --version", { stdio: "ignore" });
|
|
110189
110505
|
} catch {
|
|
@@ -110212,12 +110528,8 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
110212
110528
|
encoding: "utf-8"
|
|
110213
110529
|
});
|
|
110214
110530
|
const diff = execSync2(`git diff --cached -U50 ${defaultBranch}`, { encoding: "utf-8" });
|
|
110215
|
-
const usage = new UsageMeter(config6.prices);
|
|
110216
|
-
const ai = getModel(
|
|
110217
|
-
provider: provider3,
|
|
110218
|
-
apiKey,
|
|
110219
|
-
model
|
|
110220
|
-
});
|
|
110531
|
+
const usage = new UsageMeter(import_lodash8.merge(prices_default, config6.prices ?? {}));
|
|
110532
|
+
const ai = getModel(commandConfig);
|
|
110221
110533
|
spinner.text = "Generating pull request details...";
|
|
110222
110534
|
const resp = await generateGithubPullRequestDetails(ai, {
|
|
110223
110535
|
commitDiff: diff,
|
|
@@ -110242,6 +110554,290 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
110242
110554
|
}
|
|
110243
110555
|
});
|
|
110244
110556
|
|
|
110557
|
+
// src/commands/review.ts
|
|
110558
|
+
import { execSync as execSync3 } from "node:child_process";
|
|
110559
|
+
var import_lodash9 = __toESM(require_lodash(), 1);
|
|
110560
|
+
function parseGitStatus(statusOutput) {
|
|
110561
|
+
const statusLines = statusOutput.split(`
|
|
110562
|
+
`).filter((line) => line);
|
|
110563
|
+
const files = [];
|
|
110564
|
+
for (const line of statusLines) {
|
|
110565
|
+
const indexStatus = line[0];
|
|
110566
|
+
const workingTreeStatus = line[1];
|
|
110567
|
+
const filepath = line.slice(3);
|
|
110568
|
+
const statuses = [];
|
|
110569
|
+
if (indexStatus !== " " && indexStatus !== "?") {
|
|
110570
|
+
switch (indexStatus) {
|
|
110571
|
+
case "A":
|
|
110572
|
+
statuses.push("Added (staged)");
|
|
110573
|
+
break;
|
|
110574
|
+
case "M":
|
|
110575
|
+
statuses.push("Modified (staged)");
|
|
110576
|
+
break;
|
|
110577
|
+
case "D":
|
|
110578
|
+
statuses.push("Deleted (staged)");
|
|
110579
|
+
break;
|
|
110580
|
+
case "R":
|
|
110581
|
+
statuses.push("Renamed (staged)");
|
|
110582
|
+
break;
|
|
110583
|
+
case "C":
|
|
110584
|
+
statuses.push("Copied (staged)");
|
|
110585
|
+
break;
|
|
110586
|
+
default:
|
|
110587
|
+
statuses.push("Changed (staged)");
|
|
110588
|
+
}
|
|
110589
|
+
}
|
|
110590
|
+
if (workingTreeStatus !== " ") {
|
|
110591
|
+
switch (workingTreeStatus) {
|
|
110592
|
+
case "M":
|
|
110593
|
+
statuses.push("Modified (unstaged)");
|
|
110594
|
+
break;
|
|
110595
|
+
case "D":
|
|
110596
|
+
statuses.push("Deleted (unstaged)");
|
|
110597
|
+
break;
|
|
110598
|
+
case "?":
|
|
110599
|
+
statuses.push("Untracked");
|
|
110600
|
+
break;
|
|
110601
|
+
default:
|
|
110602
|
+
statuses.push("Changed (unstaged)");
|
|
110603
|
+
}
|
|
110604
|
+
}
|
|
110605
|
+
if (statuses.length > 0) {
|
|
110606
|
+
files.push({ path: filepath, status: statuses.join(", ") });
|
|
110607
|
+
}
|
|
110608
|
+
}
|
|
110609
|
+
return files;
|
|
110610
|
+
}
|
|
110611
|
+
function parseGitDiffNameStatus(diffOutput) {
|
|
110612
|
+
const lines = diffOutput.split(`
|
|
110613
|
+
`).filter((line) => line.trim());
|
|
110614
|
+
return lines.map((line) => {
|
|
110615
|
+
const [status, ...pathParts] = line.split("\t");
|
|
110616
|
+
const path = pathParts.join("\t");
|
|
110617
|
+
let statusDescription;
|
|
110618
|
+
switch (status[0]) {
|
|
110619
|
+
case "A":
|
|
110620
|
+
statusDescription = "Added";
|
|
110621
|
+
break;
|
|
110622
|
+
case "M":
|
|
110623
|
+
statusDescription = "Modified";
|
|
110624
|
+
break;
|
|
110625
|
+
case "D":
|
|
110626
|
+
statusDescription = "Deleted";
|
|
110627
|
+
break;
|
|
110628
|
+
case "R":
|
|
110629
|
+
statusDescription = "Renamed";
|
|
110630
|
+
break;
|
|
110631
|
+
case "C":
|
|
110632
|
+
statusDescription = "Copied";
|
|
110633
|
+
break;
|
|
110634
|
+
case "T":
|
|
110635
|
+
statusDescription = "Type changed";
|
|
110636
|
+
break;
|
|
110637
|
+
default:
|
|
110638
|
+
statusDescription = "Unknown";
|
|
110639
|
+
}
|
|
110640
|
+
return { path, status: statusDescription };
|
|
110641
|
+
});
|
|
110642
|
+
}
|
|
110643
|
+
var reviewCommand = new Command("review").description("Review a GitHub pull request or local changes").option("--pr <pr>", "The pull request number or URL to review").option("--json", "Output the review in JSON format", false).action(async (options, command) => {
|
|
110644
|
+
const parentOptions = command.parent?.opts() ?? {};
|
|
110645
|
+
const { providerConfig, config: config6 } = parseOptions(parentOptions);
|
|
110646
|
+
const commandConfig = providerConfig.getConfigForCommand("review");
|
|
110647
|
+
if (!commandConfig || !commandConfig.provider || !commandConfig.model) {
|
|
110648
|
+
console.error('Error: No provider specified. Please run "polka config" to configure your AI provider.');
|
|
110649
|
+
process.exit(1);
|
|
110650
|
+
}
|
|
110651
|
+
if (!options.json) {
|
|
110652
|
+
console.log("Provider:", commandConfig.provider);
|
|
110653
|
+
console.log("Model:", commandConfig.model);
|
|
110654
|
+
}
|
|
110655
|
+
const spinner = ora({
|
|
110656
|
+
text: "Gathering information...",
|
|
110657
|
+
stream: options.json ? process.stderr : process.stdout
|
|
110658
|
+
}).start();
|
|
110659
|
+
const usage = new UsageMeter(import_lodash9.merge(prices_default, config6.prices ?? {}));
|
|
110660
|
+
const ai = getModel(commandConfig);
|
|
110661
|
+
const toolProviderOptions = {
|
|
110662
|
+
excludeFiles: parentOptions.config.excludeFiles,
|
|
110663
|
+
interactive: parentOptions.interactive
|
|
110664
|
+
};
|
|
110665
|
+
const toolProvider = getProvider("analyzer", config6, toolProviderOptions);
|
|
110666
|
+
const sharedAiOptions = {
|
|
110667
|
+
ai,
|
|
110668
|
+
usageMeter: usage,
|
|
110669
|
+
os: process.platform,
|
|
110670
|
+
provider: toolProvider,
|
|
110671
|
+
interactive: false,
|
|
110672
|
+
policies: [],
|
|
110673
|
+
toolFormat: commandConfig.toolFormat
|
|
110674
|
+
};
|
|
110675
|
+
try {
|
|
110676
|
+
if (options.pr) {
|
|
110677
|
+
await reviewPR(options.pr, spinner, sharedAiOptions, options.json);
|
|
110678
|
+
} else {
|
|
110679
|
+
await reviewLocal(spinner, sharedAiOptions, options.json);
|
|
110680
|
+
}
|
|
110681
|
+
} catch (error120) {
|
|
110682
|
+
spinner.fail(`Error reviewing: ${error120 instanceof Error ? error120.message : String(error120)}`);
|
|
110683
|
+
console.error(error120);
|
|
110684
|
+
process.exit(1);
|
|
110685
|
+
}
|
|
110686
|
+
if (!options.json) {
|
|
110687
|
+
usage.printUsage();
|
|
110688
|
+
}
|
|
110689
|
+
});
|
|
110690
|
+
async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput) {
|
|
110691
|
+
const prNumberMatch = prIdentifier.match(/\d+$/);
|
|
110692
|
+
if (!prNumberMatch) {
|
|
110693
|
+
spinner.fail("Invalid PR number or URL.");
|
|
110694
|
+
process.exit(1);
|
|
110695
|
+
}
|
|
110696
|
+
const prNumber = prNumberMatch[0];
|
|
110697
|
+
try {
|
|
110698
|
+
execSync3("gh --version", { stdio: "ignore" });
|
|
110699
|
+
} catch {
|
|
110700
|
+
spinner.fail("Error: GitHub CLI (gh) is not installed. Please install it from https://cli.github.com/");
|
|
110701
|
+
process.exit(1);
|
|
110702
|
+
}
|
|
110703
|
+
try {
|
|
110704
|
+
spinner.text = `Checking out PR #${prNumber}...`;
|
|
110705
|
+
execSync3(`gh pr checkout ${prNumber}`, { stdio: "pipe" });
|
|
110706
|
+
} catch (_error) {
|
|
110707
|
+
spinner.fail(`Error checking out PR #${prNumber}. Make sure the PR number is correct and you have access to the repository.`);
|
|
110708
|
+
process.exit(1);
|
|
110709
|
+
}
|
|
110710
|
+
const gitRoot = execSync3("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
|
|
110711
|
+
const remoteUrl = execSync3("git remote get-url origin", { cwd: gitRoot, encoding: "utf-8" }).trim();
|
|
110712
|
+
const remoteMatch = remoteUrl.match(/github\.com[/:](?<owner>[^/]+)\/(?<repo>[^/]+)\.git$/);
|
|
110713
|
+
if (!remoteMatch?.groups) {
|
|
110714
|
+
spinner.fail("Could not determine GitHub repository owner and repo from remote URL.");
|
|
110715
|
+
process.exit(1);
|
|
110716
|
+
}
|
|
110717
|
+
spinner.text = "Fetching pull request details...";
|
|
110718
|
+
const prDetails = JSON.parse(execSync3(`gh pr view ${prNumber} --json title,body,commits`, { encoding: "utf-8" }));
|
|
110719
|
+
const defaultBranch = execSync3("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name", {
|
|
110720
|
+
encoding: "utf-8"
|
|
110721
|
+
}).trim();
|
|
110722
|
+
const commitMessages = prDetails.commits.map((c) => c.messageBody).join(`
|
|
110723
|
+
---
|
|
110724
|
+
`);
|
|
110725
|
+
spinner.text = "Getting file changes...";
|
|
110726
|
+
let changedFiles = [];
|
|
110727
|
+
try {
|
|
110728
|
+
const diffNameStatus = execSync3(`git diff --name-status --no-color ${defaultBranch}...HEAD`, { encoding: "utf-8" });
|
|
110729
|
+
changedFiles = parseGitDiffNameStatus(diffNameStatus);
|
|
110730
|
+
} catch (_error) {
|
|
110731
|
+
console.warn("Warning: Could not retrieve file changes list");
|
|
110732
|
+
}
|
|
110733
|
+
spinner.text = "Generating review...";
|
|
110734
|
+
const result = await reviewDiff(sharedAiOptions, {
|
|
110735
|
+
commitRange: `${defaultBranch}...HEAD`,
|
|
110736
|
+
pullRequestTitle: prDetails.title,
|
|
110737
|
+
pullRequestDescription: prDetails.body,
|
|
110738
|
+
commitMessages,
|
|
110739
|
+
changedFiles
|
|
110740
|
+
});
|
|
110741
|
+
spinner.succeed("Review generated successfully");
|
|
110742
|
+
if (isJsonOutput) {
|
|
110743
|
+
console.log(JSON.stringify(result, null, 2));
|
|
110744
|
+
} else {
|
|
110745
|
+
console.log(formatReviewForConsole(result));
|
|
110746
|
+
}
|
|
110747
|
+
}
|
|
110748
|
+
async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
|
|
110749
|
+
const gitStatus = execSync3("git status --porcelain=v1", { encoding: "utf-8" }).trim();
|
|
110750
|
+
const statusLines = gitStatus.split(`
|
|
110751
|
+
`).filter((line) => line);
|
|
110752
|
+
const hasStagedChanges = statusLines.some((line) => "MARC".includes(line[0]));
|
|
110753
|
+
const hasUnstagedChanges = statusLines.some((line) => "MARCDU".includes(line[1]));
|
|
110754
|
+
const changedFiles = parseGitStatus(gitStatus);
|
|
110755
|
+
if (hasStagedChanges) {
|
|
110756
|
+
spinner.text = "Generating review for staged changes...";
|
|
110757
|
+
const stagedFiles = changedFiles.filter((file4) => file4.status.includes("staged"));
|
|
110758
|
+
const result2 = await reviewDiff(sharedAiOptions, {
|
|
110759
|
+
staged: true,
|
|
110760
|
+
changedFiles: stagedFiles
|
|
110761
|
+
});
|
|
110762
|
+
spinner.succeed("Review generated successfully");
|
|
110763
|
+
if (isJsonOutput) {
|
|
110764
|
+
console.log(JSON.stringify(result2, null, 2));
|
|
110765
|
+
} else {
|
|
110766
|
+
console.log(formatReviewForConsole(result2));
|
|
110767
|
+
}
|
|
110768
|
+
return;
|
|
110769
|
+
}
|
|
110770
|
+
if (hasUnstagedChanges) {
|
|
110771
|
+
spinner.text = "Generating review for unstaged changes...";
|
|
110772
|
+
const unstagedFiles = changedFiles.filter((file4) => file4.status.includes("unstaged") || file4.status.includes("Untracked"));
|
|
110773
|
+
const result2 = await reviewDiff(sharedAiOptions, {
|
|
110774
|
+
staged: false,
|
|
110775
|
+
changedFiles: unstagedFiles
|
|
110776
|
+
});
|
|
110777
|
+
spinner.succeed("Review generated successfully");
|
|
110778
|
+
if (isJsonOutput) {
|
|
110779
|
+
console.log(JSON.stringify(result2, null, 2));
|
|
110780
|
+
} else {
|
|
110781
|
+
console.log(formatReviewForConsole(result2));
|
|
110782
|
+
}
|
|
110783
|
+
return;
|
|
110784
|
+
}
|
|
110785
|
+
spinner.text = "No local changes detected. Falling back to branch diff...";
|
|
110786
|
+
spinner.render();
|
|
110787
|
+
try {
|
|
110788
|
+
execSync3("gh --version", { stdio: "ignore" });
|
|
110789
|
+
} catch {
|
|
110790
|
+
spinner.fail("Error: GitHub CLI (gh) is not installed, and there are no local changes to review. Please install it from https://cli.github.com/ to review branch changes.");
|
|
110791
|
+
process.exit(1);
|
|
110792
|
+
}
|
|
110793
|
+
const defaultBranch = execSync3("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name", {
|
|
110794
|
+
encoding: "utf-8"
|
|
110795
|
+
}).trim();
|
|
110796
|
+
const currentBranch = execSync3("git rev-parse --abbrev-ref HEAD", { encoding: "utf-8" }).trim();
|
|
110797
|
+
if (currentBranch === defaultBranch) {
|
|
110798
|
+
spinner.succeed(`No changes to review. You are on the default branch ('${defaultBranch}').`);
|
|
110799
|
+
process.exit(0);
|
|
110800
|
+
}
|
|
110801
|
+
spinner.text = "Getting file changes...";
|
|
110802
|
+
let branchChangedFiles = [];
|
|
110803
|
+
try {
|
|
110804
|
+
const diffNameStatus = execSync3(`git diff --name-status --no-color ${defaultBranch}...${currentBranch}`, { encoding: "utf-8" });
|
|
110805
|
+
branchChangedFiles = parseGitDiffNameStatus(diffNameStatus);
|
|
110806
|
+
} catch (_error) {
|
|
110807
|
+
console.warn("Warning: Could not retrieve file changes list");
|
|
110808
|
+
}
|
|
110809
|
+
spinner.text = `Generating review for changes between '${defaultBranch}' and '${currentBranch}'...`;
|
|
110810
|
+
const result = await reviewDiff(sharedAiOptions, {
|
|
110811
|
+
commitRange: `${defaultBranch}...${currentBranch}`,
|
|
110812
|
+
changedFiles: branchChangedFiles
|
|
110813
|
+
});
|
|
110814
|
+
spinner.succeed("Review generated successfully");
|
|
110815
|
+
if (isJsonOutput) {
|
|
110816
|
+
console.log(JSON.stringify(result, null, 2));
|
|
110817
|
+
} else {
|
|
110818
|
+
console.log(formatReviewForConsole(result));
|
|
110819
|
+
}
|
|
110820
|
+
}
|
|
110821
|
+
function formatReviewForConsole(output) {
|
|
110822
|
+
let formatted = `### Overview
|
|
110823
|
+
|
|
110824
|
+
${output.overview}`;
|
|
110825
|
+
if (output.specificReviews.length > 0) {
|
|
110826
|
+
formatted += `
|
|
110827
|
+
|
|
110828
|
+
### File-specific feedback
|
|
110829
|
+
`;
|
|
110830
|
+
for (const item of output.specificReviews) {
|
|
110831
|
+
formatted += `
|
|
110832
|
+
**${item.file}:${item.lines}**
|
|
110833
|
+
|
|
110834
|
+
${item.review}
|
|
110835
|
+
`;
|
|
110836
|
+
}
|
|
110837
|
+
}
|
|
110838
|
+
return formatted;
|
|
110839
|
+
}
|
|
110840
|
+
|
|
110245
110841
|
// src/commands/task.ts
|
|
110246
110842
|
var readStdin = async (timeoutMs = 30000) => {
|
|
110247
110843
|
if (process.stdin.isTTY) {
|
|
@@ -110331,6 +110927,7 @@ program2.command("chat").description("Start an interactive chat session").action
|
|
|
110331
110927
|
program2.addCommand(initCommand);
|
|
110332
110928
|
program2.addCommand(commitCommand);
|
|
110333
110929
|
program2.addCommand(prCommand);
|
|
110930
|
+
program2.addCommand(reviewCommand);
|
|
110334
110931
|
program2.addCommand(createCommand2);
|
|
110335
110932
|
addSharedOptions(program2);
|
|
110336
110933
|
program2.parse();
|