@polka-codes/cli 0.9.2 → 0.9.3
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 +1032 -583
- 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.3";
|
|
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,11 +76668,11 @@ ${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
|
+
respMessages = [];
|
|
76742
76676
|
let timeout;
|
|
76743
76677
|
const resetTimeout = () => {
|
|
76744
76678
|
if (timeout) {
|
|
@@ -76752,40 +76686,22 @@ ${instance.prompt}`;
|
|
|
76752
76686
|
}
|
|
76753
76687
|
};
|
|
76754
76688
|
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
76689
|
try {
|
|
76775
|
-
const
|
|
76690
|
+
const streamTextOptions = {
|
|
76776
76691
|
model: this.ai,
|
|
76777
76692
|
messages,
|
|
76778
|
-
providerOptions,
|
|
76693
|
+
providerOptions: this.config.parameters?.providerOptions,
|
|
76779
76694
|
onChunk: async ({ chunk }) => {
|
|
76780
76695
|
resetTimeout();
|
|
76781
76696
|
switch (chunk.type) {
|
|
76782
76697
|
case "text":
|
|
76783
|
-
currentAssistantMessage += chunk.text;
|
|
76784
76698
|
await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
|
|
76785
76699
|
break;
|
|
76786
76700
|
case "reasoning":
|
|
76787
76701
|
await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
|
|
76788
76702
|
break;
|
|
76703
|
+
case "tool-call":
|
|
76704
|
+
break;
|
|
76789
76705
|
}
|
|
76790
76706
|
},
|
|
76791
76707
|
onFinish: this.config.usageMeter.onFinishHandler(this.ai),
|
|
@@ -76793,8 +76709,18 @@ ${instance.prompt}`;
|
|
|
76793
76709
|
console.error("Error in stream:", error81);
|
|
76794
76710
|
},
|
|
76795
76711
|
abortSignal: this.#abortController.signal
|
|
76712
|
+
};
|
|
76713
|
+
if (this.config.toolFormat === "native") {
|
|
76714
|
+
streamTextOptions.tools = this.#toolSet;
|
|
76715
|
+
}
|
|
76716
|
+
const stream = streamText(streamTextOptions);
|
|
76717
|
+
await stream.consumeStream({
|
|
76718
|
+
onError: (error81) => {
|
|
76719
|
+
console.error("Error in stream:", error81);
|
|
76720
|
+
}
|
|
76796
76721
|
});
|
|
76797
|
-
await stream.
|
|
76722
|
+
const resp = await stream.response;
|
|
76723
|
+
respMessages = resp.messages;
|
|
76798
76724
|
} catch (error81) {
|
|
76799
76725
|
if (error81 instanceof Error && error81.name === "AbortError") {
|
|
76800
76726
|
break;
|
|
@@ -76805,7 +76731,7 @@ ${instance.prompt}`;
|
|
|
76805
76731
|
clearTimeout(timeout);
|
|
76806
76732
|
}
|
|
76807
76733
|
}
|
|
76808
|
-
if (
|
|
76734
|
+
if (respMessages.length > 0) {
|
|
76809
76735
|
break;
|
|
76810
76736
|
}
|
|
76811
76737
|
if (this.#aborted) {
|
|
@@ -76813,17 +76739,45 @@ ${instance.prompt}`;
|
|
|
76813
76739
|
}
|
|
76814
76740
|
console.debug(`Retrying request ${i + 1} of ${retryCount}`);
|
|
76815
76741
|
}
|
|
76816
|
-
if (
|
|
76742
|
+
if (respMessages.length === 0) {
|
|
76817
76743
|
if (this.#aborted) {
|
|
76818
76744
|
return [];
|
|
76819
76745
|
}
|
|
76820
76746
|
throw new Error("No assistant message received");
|
|
76821
76747
|
}
|
|
76822
|
-
|
|
76823
|
-
this
|
|
76824
|
-
|
|
76825
|
-
|
|
76826
|
-
|
|
76748
|
+
this.#messages.push(...respMessages);
|
|
76749
|
+
if (this.config.toolFormat === "native") {
|
|
76750
|
+
return respMessages.flatMap((msg) => {
|
|
76751
|
+
if (msg.role === "assistant") {
|
|
76752
|
+
const content = msg.content;
|
|
76753
|
+
if (typeof content === "string") {
|
|
76754
|
+
return [{ type: "text", content }];
|
|
76755
|
+
}
|
|
76756
|
+
return content.flatMap((part) => {
|
|
76757
|
+
if (part.type === "text") {
|
|
76758
|
+
return [{ type: "text", content: part.text }];
|
|
76759
|
+
}
|
|
76760
|
+
if (part.type === "tool-call") {
|
|
76761
|
+
return [{ type: "tool_use", id: part.toolCallId, name: part.toolName, params: part.input }];
|
|
76762
|
+
}
|
|
76763
|
+
return [];
|
|
76764
|
+
});
|
|
76765
|
+
}
|
|
76766
|
+
return [];
|
|
76767
|
+
});
|
|
76768
|
+
}
|
|
76769
|
+
const currentAssistantMessage = respMessages.map((msg) => {
|
|
76770
|
+
if (typeof msg.content === "string") {
|
|
76771
|
+
return msg.content;
|
|
76772
|
+
}
|
|
76773
|
+
return msg.content.map((part) => {
|
|
76774
|
+
if (part.type === "text") {
|
|
76775
|
+
return part.text;
|
|
76776
|
+
}
|
|
76777
|
+
return "";
|
|
76778
|
+
});
|
|
76779
|
+
}).join(`
|
|
76780
|
+
`);
|
|
76827
76781
|
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools.map(toToolInfoV1), this.config.toolNamePrefix);
|
|
76828
76782
|
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: currentAssistantMessage });
|
|
76829
76783
|
return ret;
|
|
@@ -76837,12 +76791,12 @@ ${instance.prompt}`;
|
|
|
76837
76791
|
case "text":
|
|
76838
76792
|
break;
|
|
76839
76793
|
case "tool_use": {
|
|
76840
|
-
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
76794
|
+
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name, content: content.params });
|
|
76841
76795
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
76842
76796
|
switch (toolResp.type) {
|
|
76843
76797
|
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 });
|
|
76798
|
+
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name, content: toolResp.message });
|
|
76799
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
76846
76800
|
break;
|
|
76847
76801
|
}
|
|
76848
76802
|
case "Exit" /* Exit */:
|
|
@@ -76851,17 +76805,17 @@ ${instance.prompt}`;
|
|
|
76851
76805
|
}
|
|
76852
76806
|
return { type: "exit", reason: toolResp };
|
|
76853
76807
|
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 });
|
|
76808
|
+
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name, content: toolResp.message });
|
|
76809
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
76856
76810
|
break outer;
|
|
76857
76811
|
}
|
|
76858
76812
|
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 });
|
|
76813
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name, content: toolResp.message });
|
|
76814
|
+
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message, id: content.id });
|
|
76861
76815
|
break outer;
|
|
76862
76816
|
}
|
|
76863
76817
|
case "Interrupted" /* Interrupted */:
|
|
76864
|
-
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
76818
|
+
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name, content: toolResp.message });
|
|
76865
76819
|
return { type: "exit", reason: toolResp };
|
|
76866
76820
|
case "HandOver" /* HandOver */: {
|
|
76867
76821
|
if (toolResponses.length > 0) {
|
|
@@ -76895,7 +76849,7 @@ ${instance.prompt}`;
|
|
|
76895
76849
|
}
|
|
76896
76850
|
case "Pause" /* Pause */: {
|
|
76897
76851
|
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 });
|
|
76852
|
+
toolResponses.push({ type: "pause", tool: content.name, object: toolResp.object, id: content.id });
|
|
76899
76853
|
hasPause = true;
|
|
76900
76854
|
}
|
|
76901
76855
|
}
|
|
@@ -76907,10 +76861,49 @@ ${instance.prompt}`;
|
|
|
76907
76861
|
return { type: "exit", reason: { type: "Pause", responses: toolResponses } };
|
|
76908
76862
|
}
|
|
76909
76863
|
if (toolResponses.length === 0) {
|
|
76910
|
-
return {
|
|
76864
|
+
return {
|
|
76865
|
+
type: "reply",
|
|
76866
|
+
message: {
|
|
76867
|
+
role: "user",
|
|
76868
|
+
content: responsePrompts.requireUseToolNative
|
|
76869
|
+
}
|
|
76870
|
+
};
|
|
76871
|
+
}
|
|
76872
|
+
if (this.config.toolFormat === "native") {
|
|
76873
|
+
const toolResults = toolResponses.filter((resp) => resp.type === "response").map((resp) => ({
|
|
76874
|
+
type: "tool-result",
|
|
76875
|
+
toolCallId: resp.id,
|
|
76876
|
+
toolName: resp.tool,
|
|
76877
|
+
output: {
|
|
76878
|
+
type: "text",
|
|
76879
|
+
value: resp.response
|
|
76880
|
+
}
|
|
76881
|
+
}));
|
|
76882
|
+
return {
|
|
76883
|
+
type: "reply",
|
|
76884
|
+
message: {
|
|
76885
|
+
role: "tool",
|
|
76886
|
+
content: toolResults
|
|
76887
|
+
}
|
|
76888
|
+
};
|
|
76889
|
+
}
|
|
76890
|
+
if (toolResponses.length === 0) {
|
|
76891
|
+
return {
|
|
76892
|
+
type: "reply",
|
|
76893
|
+
message: {
|
|
76894
|
+
role: "user",
|
|
76895
|
+
content: responsePrompts.requireUseTool
|
|
76896
|
+
}
|
|
76897
|
+
};
|
|
76911
76898
|
}
|
|
76912
76899
|
const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool: tool2, response: response2 }) => responsePrompts.toolResults(tool2, response2));
|
|
76913
|
-
return {
|
|
76900
|
+
return {
|
|
76901
|
+
type: "reply",
|
|
76902
|
+
message: {
|
|
76903
|
+
role: "user",
|
|
76904
|
+
content: finalResp
|
|
76905
|
+
}
|
|
76906
|
+
};
|
|
76914
76907
|
}
|
|
76915
76908
|
async#invokeTool(name17, args) {
|
|
76916
76909
|
try {
|
|
@@ -76991,10 +76984,10 @@ class AnalyzerAgent extends AgentBase {
|
|
|
76991
76984
|
permissionLevel: 1 /* Read */,
|
|
76992
76985
|
interactive: true
|
|
76993
76986
|
});
|
|
76994
|
-
const toolNamePrefix = "tool_";
|
|
76987
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
76995
76988
|
const systemPrompt = fullSystemPrompt({
|
|
76996
76989
|
os: options.os
|
|
76997
|
-
}, tools
|
|
76990
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
76998
76991
|
super(analyzerAgentInfo.name, options.ai, {
|
|
76999
76992
|
systemPrompt,
|
|
77000
76993
|
tools,
|
|
@@ -77080,10 +77073,10 @@ class ArchitectAgent extends AgentBase {
|
|
|
77080
77073
|
permissionLevel: 1 /* Read */,
|
|
77081
77074
|
interactive: true
|
|
77082
77075
|
});
|
|
77083
|
-
const toolNamePrefix = "tool_";
|
|
77076
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
77084
77077
|
const systemPrompt = fullSystemPrompt2({
|
|
77085
77078
|
os: options.os
|
|
77086
|
-
}, tools
|
|
77079
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
77087
77080
|
super(architectAgentInfo.name, options.ai, {
|
|
77088
77081
|
systemPrompt,
|
|
77089
77082
|
tools,
|
|
@@ -77202,10 +77195,10 @@ class CodeFixerAgent extends AgentBase {
|
|
|
77202
77195
|
permissionLevel: 3 /* Arbitrary */,
|
|
77203
77196
|
interactive: true
|
|
77204
77197
|
});
|
|
77205
|
-
const toolNamePrefix = "tool_";
|
|
77198
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
77206
77199
|
const systemPrompt = fullSystemPrompt3({
|
|
77207
77200
|
os: options.os
|
|
77208
|
-
}, tools
|
|
77201
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive, options.toolFormat === "native");
|
|
77209
77202
|
super(codeFixerAgentInfo.name, options.ai, {
|
|
77210
77203
|
systemPrompt,
|
|
77211
77204
|
tools,
|
|
@@ -77400,10 +77393,10 @@ class CoderAgent extends AgentBase {
|
|
|
77400
77393
|
permissionLevel: 3 /* Arbitrary */,
|
|
77401
77394
|
interactive: true
|
|
77402
77395
|
});
|
|
77403
|
-
const toolNamePrefix = "tool_";
|
|
77396
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
77404
77397
|
const systemPrompt = fullSystemPrompt4({
|
|
77405
77398
|
os: options.os
|
|
77406
|
-
}, tools
|
|
77399
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
77407
77400
|
super(coderAgentInfo.name, options.ai, {
|
|
77408
77401
|
systemPrompt,
|
|
77409
77402
|
tools,
|
|
@@ -77804,23 +77797,23 @@ var prompt = `You are an AiTool designed to assist users in creating new project
|
|
|
77804
77797
|
- Create a .gitattributes file with appropriate configurations:
|
|
77805
77798
|
- Mark lock files as generated and exclude them from diffs
|
|
77806
77799
|
- Example for different package managers:
|
|
77807
|
-
|
|
77800
|
+
|
|
77808
77801
|
# For Bun
|
|
77809
77802
|
bun.lock linguist-generated=true
|
|
77810
77803
|
bun.lock -diff
|
|
77811
|
-
|
|
77804
|
+
|
|
77812
77805
|
# For npm
|
|
77813
77806
|
package-lock.json linguist-generated=true
|
|
77814
77807
|
package-lock.json -diff
|
|
77815
|
-
|
|
77808
|
+
|
|
77816
77809
|
# For Yarn
|
|
77817
77810
|
yarn.lock linguist-generated=true
|
|
77818
77811
|
yarn.lock -diff
|
|
77819
|
-
|
|
77812
|
+
|
|
77820
77813
|
# For pnpm
|
|
77821
77814
|
pnpm-lock.yaml linguist-generated=true
|
|
77822
77815
|
pnpm-lock.yaml -diff
|
|
77823
|
-
|
|
77816
|
+
|
|
77824
77817
|
- Include other common configurations as needed based on project type
|
|
77825
77818
|
|
|
77826
77819
|
6. **Handover to Coder Agent:**
|
|
@@ -78076,6 +78069,184 @@ var generateProjectConfig_default = {
|
|
|
78076
78069
|
agent: "analyzer"
|
|
78077
78070
|
};
|
|
78078
78071
|
|
|
78072
|
+
// ../core/src/AiTool/tools/gitDiff.ts
|
|
78073
|
+
var toolInfo14 = {
|
|
78074
|
+
name: "git_diff",
|
|
78075
|
+
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.",
|
|
78076
|
+
parameters: exports_external.object({
|
|
78077
|
+
staged: exports_external.preprocess((val) => {
|
|
78078
|
+
if (typeof val === "string") {
|
|
78079
|
+
const lower = val.toLowerCase();
|
|
78080
|
+
if (lower === "false")
|
|
78081
|
+
return false;
|
|
78082
|
+
if (lower === "true")
|
|
78083
|
+
return true;
|
|
78084
|
+
}
|
|
78085
|
+
return val;
|
|
78086
|
+
}, exports_external.boolean().optional().default(false)).describe("Get staged changes instead of unstaged changes."),
|
|
78087
|
+
commitRange: exports_external.string().optional().describe('The commit range to get the diff for (e.g., "main...HEAD").'),
|
|
78088
|
+
file: exports_external.string().optional().describe("Get the diff for a specific file.")
|
|
78089
|
+
}),
|
|
78090
|
+
permissionLevel: 1 /* Read */
|
|
78091
|
+
};
|
|
78092
|
+
var handler14 = async (provider2, args) => {
|
|
78093
|
+
if (!provider2.executeCommand) {
|
|
78094
|
+
return {
|
|
78095
|
+
type: "Error" /* Error */,
|
|
78096
|
+
message: "Not possible to execute command. Abort."
|
|
78097
|
+
};
|
|
78098
|
+
}
|
|
78099
|
+
const { staged, file: file3, commitRange } = toolInfo14.parameters.parse(args);
|
|
78100
|
+
const commandParts = ["git", "diff", "--no-color"];
|
|
78101
|
+
if (staged) {
|
|
78102
|
+
commandParts.push("--staged");
|
|
78103
|
+
}
|
|
78104
|
+
if (commitRange) {
|
|
78105
|
+
commandParts.push(commitRange);
|
|
78106
|
+
}
|
|
78107
|
+
if (file3) {
|
|
78108
|
+
commandParts.push("--", file3);
|
|
78109
|
+
}
|
|
78110
|
+
const command = commandParts.join(" ");
|
|
78111
|
+
try {
|
|
78112
|
+
const result = await provider2.executeCommand(command, false);
|
|
78113
|
+
if (result.exitCode === 0) {
|
|
78114
|
+
if (!result.stdout.trim()) {
|
|
78115
|
+
return {
|
|
78116
|
+
type: "Reply" /* Reply */,
|
|
78117
|
+
message: "No diff found."
|
|
78118
|
+
};
|
|
78119
|
+
}
|
|
78120
|
+
return {
|
|
78121
|
+
type: "Reply" /* Reply */,
|
|
78122
|
+
message: `<diff file="${file3 ?? "all"}">
|
|
78123
|
+
${result.stdout}
|
|
78124
|
+
</diff>`
|
|
78125
|
+
};
|
|
78126
|
+
}
|
|
78127
|
+
return {
|
|
78128
|
+
type: "Error" /* Error */,
|
|
78129
|
+
message: `\`${command}\` exited with code ${result.exitCode}:
|
|
78130
|
+
${result.stderr}`
|
|
78131
|
+
};
|
|
78132
|
+
} catch (error81) {
|
|
78133
|
+
return {
|
|
78134
|
+
type: "Error" /* Error */,
|
|
78135
|
+
message: error81 instanceof Error ? error81.message : String(error81)
|
|
78136
|
+
};
|
|
78137
|
+
}
|
|
78138
|
+
};
|
|
78139
|
+
var isAvailable14 = (provider2) => {
|
|
78140
|
+
return !!provider2.executeCommand;
|
|
78141
|
+
};
|
|
78142
|
+
var gitDiff_default = {
|
|
78143
|
+
...toolInfo14,
|
|
78144
|
+
handler: handler14,
|
|
78145
|
+
isAvailable: isAvailable14
|
|
78146
|
+
};
|
|
78147
|
+
|
|
78148
|
+
// ../core/src/AiTool/reviewDiff.ts
|
|
78149
|
+
var prompt5 = `
|
|
78150
|
+
# Code Review Prompt
|
|
78151
|
+
|
|
78152
|
+
You are a senior software engineer reviewing code changes.
|
|
78153
|
+
|
|
78154
|
+
## Viewing Changes
|
|
78155
|
+
- Use **git_diff** to inspect code.
|
|
78156
|
+
- **Pull request**: use the provided commit range.
|
|
78157
|
+
- **Local changes**: diff staged or unstaged files.
|
|
78158
|
+
- If a pull request is present you may receive:
|
|
78159
|
+
- <pr_title>
|
|
78160
|
+
- <pr_description>
|
|
78161
|
+
- <commit_messages>
|
|
78162
|
+
- A <review_instructions> tag tells you the focus of the review.
|
|
78163
|
+
|
|
78164
|
+
## Focus Areas
|
|
78165
|
+
- Readability and maintainability
|
|
78166
|
+
- Correctness, edge cases, potential bugs
|
|
78167
|
+
- Performance implications
|
|
78168
|
+
- Clarity of intent
|
|
78169
|
+
- Best-practice adherence
|
|
78170
|
+
|
|
78171
|
+
## Output Format
|
|
78172
|
+
Do **not** include praise or positive feedback. Ignore generated files such as lock files.
|
|
78173
|
+
|
|
78174
|
+
Return your review as a JSON object inside a \`\`\`json block, wrapped like:
|
|
78175
|
+
<tool_attempt_completion>
|
|
78176
|
+
<tool_parameter_result>
|
|
78177
|
+
\`\`\`json
|
|
78178
|
+
{
|
|
78179
|
+
"overview": "Summary of overall concerns.",
|
|
78180
|
+
"specificReviews": [
|
|
78181
|
+
{
|
|
78182
|
+
"file": "path/filename.ext",
|
|
78183
|
+
"lines": "N or N-M",
|
|
78184
|
+
"review": "Describe the issue and actionable fix or improvement."
|
|
78185
|
+
}
|
|
78186
|
+
]
|
|
78187
|
+
}
|
|
78188
|
+
\`\`\`
|
|
78189
|
+
</tool_parameter_result>
|
|
78190
|
+
</tool_attempt_completion>
|
|
78191
|
+
`;
|
|
78192
|
+
var reviewDiff_default = {
|
|
78193
|
+
name: "reviewDiff",
|
|
78194
|
+
description: "Reviews a git diff",
|
|
78195
|
+
prompt: prompt5,
|
|
78196
|
+
formatInput: (params) => {
|
|
78197
|
+
const parts = [];
|
|
78198
|
+
if (params.pullRequestTitle) {
|
|
78199
|
+
parts.push(`<pr_title>
|
|
78200
|
+
${params.pullRequestTitle}
|
|
78201
|
+
</pr_title>`);
|
|
78202
|
+
}
|
|
78203
|
+
if (params.pullRequestDescription) {
|
|
78204
|
+
parts.push(`<pr_description>
|
|
78205
|
+
${params.pullRequestDescription}
|
|
78206
|
+
</pr_description>`);
|
|
78207
|
+
}
|
|
78208
|
+
if (params.commitMessages) {
|
|
78209
|
+
parts.push(`<commit_messages>
|
|
78210
|
+
${params.commitMessages}
|
|
78211
|
+
</commit_messages>`);
|
|
78212
|
+
}
|
|
78213
|
+
let instructions = "";
|
|
78214
|
+
if (params.commitRange) {
|
|
78215
|
+
instructions = `Review the pull request. Get the diff using the git_diff tool with the commit range '${params.commitRange}'.`;
|
|
78216
|
+
} else if (params.staged) {
|
|
78217
|
+
instructions = "Review the staged changes. Get the diff using the git_diff tool with staged: true.";
|
|
78218
|
+
} else {
|
|
78219
|
+
instructions = "Review the unstaged changes. Get the diff using the git_diff tool.";
|
|
78220
|
+
}
|
|
78221
|
+
parts.push(`<review_instructions>
|
|
78222
|
+
${instructions}
|
|
78223
|
+
</review_instructions>`);
|
|
78224
|
+
return parts.join(`
|
|
78225
|
+
`);
|
|
78226
|
+
},
|
|
78227
|
+
parseOutput: (output) => {
|
|
78228
|
+
const jsonBlockRegex = /```json\n([\s\S]*?)\n```/;
|
|
78229
|
+
const match = output.match(jsonBlockRegex);
|
|
78230
|
+
const content = match ? match[1] : output;
|
|
78231
|
+
try {
|
|
78232
|
+
return JSON.parse(content);
|
|
78233
|
+
} catch (error81) {
|
|
78234
|
+
console.error("Error parsing JSON output:", error81);
|
|
78235
|
+
return {
|
|
78236
|
+
overview: `Could not parse review output. Raw output:
|
|
78237
|
+
${output}`,
|
|
78238
|
+
specificReviews: []
|
|
78239
|
+
};
|
|
78240
|
+
}
|
|
78241
|
+
},
|
|
78242
|
+
agent: (options) => {
|
|
78243
|
+
return new AnalyzerAgent({
|
|
78244
|
+
...options,
|
|
78245
|
+
additionalTools: [gitDiff_default]
|
|
78246
|
+
});
|
|
78247
|
+
}
|
|
78248
|
+
};
|
|
78249
|
+
|
|
78079
78250
|
// ../core/src/AiTool/index.ts
|
|
78080
78251
|
var executeTool = async (definition, ai, params, usageMeter) => {
|
|
78081
78252
|
const resp = await generateText({
|
|
@@ -78091,10 +78262,7 @@ var executeTool = async (definition, ai, params, usageMeter) => {
|
|
|
78091
78262
|
usageMeter.addUsage(ai, resp);
|
|
78092
78263
|
return definition.parseOutput(resp.text);
|
|
78093
78264
|
};
|
|
78094
|
-
var
|
|
78095
|
-
if (!definition.agent) {
|
|
78096
|
-
throw new Error("Agent not specified");
|
|
78097
|
-
}
|
|
78265
|
+
var executeMultiAgentTool = async (definition, agent, params) => {
|
|
78098
78266
|
const exitReason = await agent.startTask({
|
|
78099
78267
|
agentName: definition.agent,
|
|
78100
78268
|
task: definition.prompt,
|
|
@@ -78105,22 +78273,41 @@ var executeAgentTool = async (definition, agent, params) => {
|
|
|
78105
78273
|
}
|
|
78106
78274
|
throw new Error(`Tool execution failed: ${exitReason.type}`);
|
|
78107
78275
|
};
|
|
78276
|
+
var executeAgentTool = async (definition, options, params) => {
|
|
78277
|
+
const agent = definition.agent(options);
|
|
78278
|
+
const exitReason = await agent.start(`${definition.prompt}
|
|
78279
|
+
|
|
78280
|
+
${definition.formatInput(params)}`);
|
|
78281
|
+
if (exitReason.type === "Exit" /* Exit */) {
|
|
78282
|
+
return definition.parseOutput(exitReason.message);
|
|
78283
|
+
}
|
|
78284
|
+
throw new Error(`Tool execution failed: ${exitReason.type}`);
|
|
78285
|
+
};
|
|
78108
78286
|
var makeTool = (definition) => {
|
|
78109
78287
|
return async (ai, params, usageMeter) => {
|
|
78110
78288
|
return executeTool(definition, ai, params, usageMeter);
|
|
78111
78289
|
};
|
|
78112
78290
|
};
|
|
78113
|
-
var
|
|
78291
|
+
var makeMultiAgentTool = (definition) => {
|
|
78114
78292
|
return async (agent, params) => {
|
|
78115
|
-
return
|
|
78293
|
+
return executeMultiAgentTool(definition, agent, params);
|
|
78294
|
+
};
|
|
78295
|
+
};
|
|
78296
|
+
var makeAgentTool = (definition) => {
|
|
78297
|
+
return async (options, params) => {
|
|
78298
|
+
return executeAgentTool(definition, options, params);
|
|
78116
78299
|
};
|
|
78117
78300
|
};
|
|
78118
78301
|
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
78119
78302
|
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
78120
|
-
var
|
|
78121
|
-
var
|
|
78303
|
+
var reviewDiff = makeAgentTool(reviewDiff_default);
|
|
78304
|
+
var generateProjectConfig = makeMultiAgentTool(generateProjectConfig_default);
|
|
78305
|
+
var createNewProject = makeMultiAgentTool(createNewProject_default);
|
|
78122
78306
|
// src/commands/chat.ts
|
|
78123
|
-
var
|
|
78307
|
+
var import_lodash5 = __toESM(require_lodash(), 1);
|
|
78308
|
+
|
|
78309
|
+
// src/getModel.ts
|
|
78310
|
+
import { appendFileSync } from "node:fs";
|
|
78124
78311
|
|
|
78125
78312
|
// ../../node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
78126
78313
|
var anthropicErrorDataSchema = exports_external2.object({
|
|
@@ -78342,13 +78529,13 @@ function convertToString(data) {
|
|
|
78342
78529
|
});
|
|
78343
78530
|
}
|
|
78344
78531
|
async function convertToAnthropicMessagesPrompt({
|
|
78345
|
-
prompt:
|
|
78532
|
+
prompt: prompt6,
|
|
78346
78533
|
sendReasoning,
|
|
78347
78534
|
warnings
|
|
78348
78535
|
}) {
|
|
78349
78536
|
var _a16, _b8, _c, _d, _e;
|
|
78350
78537
|
const betas = /* @__PURE__ */ new Set;
|
|
78351
|
-
const blocks = groupIntoBlocks(
|
|
78538
|
+
const blocks = groupIntoBlocks(prompt6);
|
|
78352
78539
|
let system = undefined;
|
|
78353
78540
|
const messages = [];
|
|
78354
78541
|
function getCacheControl(providerMetadata) {
|
|
@@ -78680,10 +78867,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
78680
78867
|
betas
|
|
78681
78868
|
};
|
|
78682
78869
|
}
|
|
78683
|
-
function groupIntoBlocks(
|
|
78870
|
+
function groupIntoBlocks(prompt6) {
|
|
78684
78871
|
const blocks = [];
|
|
78685
78872
|
let currentBlock = undefined;
|
|
78686
|
-
for (const message of
|
|
78873
|
+
for (const message of prompt6) {
|
|
78687
78874
|
const { role } = message;
|
|
78688
78875
|
switch (role) {
|
|
78689
78876
|
case "system": {
|
|
@@ -78830,7 +79017,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78830
79017
|
return (_c = (_b8 = (_a16 = this.config).supportedUrls) == null ? undefined : _b8.call(_a16)) != null ? _c : {};
|
|
78831
79018
|
}
|
|
78832
79019
|
async getArgs({
|
|
78833
|
-
prompt:
|
|
79020
|
+
prompt: prompt6,
|
|
78834
79021
|
maxOutputTokens = 4096,
|
|
78835
79022
|
temperature,
|
|
78836
79023
|
topP,
|
|
@@ -78891,7 +79078,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78891
79078
|
schema: anthropicProviderOptions
|
|
78892
79079
|
});
|
|
78893
79080
|
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
78894
|
-
prompt:
|
|
79081
|
+
prompt: prompt6,
|
|
78895
79082
|
sendReasoning: (_a16 = anthropicOptions == null ? undefined : anthropicOptions.sendReasoning) != null ? _a16 : true,
|
|
78896
79083
|
warnings
|
|
78897
79084
|
});
|
|
@@ -78976,7 +79163,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78976
79163
|
var _a16, _b8, _c;
|
|
78977
79164
|
return (_c = (_b8 = (_a16 = this.config).transformRequestBody) == null ? undefined : _b8.call(_a16, args)) != null ? _c : args;
|
|
78978
79165
|
}
|
|
78979
|
-
extractCitationDocuments(
|
|
79166
|
+
extractCitationDocuments(prompt6) {
|
|
78980
79167
|
const isCitationPart = (part) => {
|
|
78981
79168
|
var _a16, _b8;
|
|
78982
79169
|
if (part.type !== "file") {
|
|
@@ -78989,7 +79176,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
78989
79176
|
const citationsConfig = anthropic2 == null ? undefined : anthropic2.citations;
|
|
78990
79177
|
return (_b8 = citationsConfig == null ? undefined : citationsConfig.enabled) != null ? _b8 : false;
|
|
78991
79178
|
};
|
|
78992
|
-
return
|
|
79179
|
+
return prompt6.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
78993
79180
|
var _a16;
|
|
78994
79181
|
const filePart = part;
|
|
78995
79182
|
return {
|
|
@@ -79808,9 +79995,9 @@ function getOpenAIMetadata(message) {
|
|
|
79808
79995
|
var _a16, _b8;
|
|
79809
79996
|
return (_b8 = (_a16 = message == null ? undefined : message.providerOptions) == null ? undefined : _a16.openaiCompatible) != null ? _b8 : {};
|
|
79810
79997
|
}
|
|
79811
|
-
function convertToOpenAICompatibleChatMessages(
|
|
79998
|
+
function convertToOpenAICompatibleChatMessages(prompt6) {
|
|
79812
79999
|
const messages = [];
|
|
79813
|
-
for (const { role, content, ...message } of
|
|
80000
|
+
for (const { role, content, ...message } of prompt6) {
|
|
79814
80001
|
const metadata = getOpenAIMetadata({ ...message });
|
|
79815
80002
|
switch (role) {
|
|
79816
80003
|
case "system": {
|
|
@@ -80035,7 +80222,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
80035
80222
|
return (_c = (_b8 = (_a16 = this.config).supportedUrls) == null ? undefined : _b8.call(_a16)) != null ? _c : {};
|
|
80036
80223
|
}
|
|
80037
80224
|
async getArgs({
|
|
80038
|
-
prompt:
|
|
80225
|
+
prompt: prompt6,
|
|
80039
80226
|
maxOutputTokens,
|
|
80040
80227
|
temperature,
|
|
80041
80228
|
topP,
|
|
@@ -80099,7 +80286,7 @@ var OpenAICompatibleChatLanguageModel = class {
|
|
|
80099
80286
|
seed,
|
|
80100
80287
|
...providerOptions == null ? undefined : providerOptions[this.providerOptionsName],
|
|
80101
80288
|
reasoning_effort: compatibleOptions.reasoningEffort,
|
|
80102
|
-
messages: convertToOpenAICompatibleChatMessages(
|
|
80289
|
+
messages: convertToOpenAICompatibleChatMessages(prompt6),
|
|
80103
80290
|
tools: openaiTools,
|
|
80104
80291
|
tool_choice: openaiToolChoice
|
|
80105
80292
|
},
|
|
@@ -80705,13 +80892,13 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema2) {
|
|
|
80705
80892
|
function isEmptyObjectSchema(jsonSchema2) {
|
|
80706
80893
|
return jsonSchema2 != null && typeof jsonSchema2 === "object" && jsonSchema2.type === "object" && (jsonSchema2.properties == null || Object.keys(jsonSchema2.properties).length === 0) && !jsonSchema2.additionalProperties;
|
|
80707
80894
|
}
|
|
80708
|
-
function convertToGoogleGenerativeAIMessages(
|
|
80895
|
+
function convertToGoogleGenerativeAIMessages(prompt6, options) {
|
|
80709
80896
|
var _a16;
|
|
80710
80897
|
const systemInstructionParts = [];
|
|
80711
80898
|
const contents = [];
|
|
80712
80899
|
let systemMessagesAllowed = true;
|
|
80713
80900
|
const isGemmaModel = (_a16 = options == null ? undefined : options.isGemmaModel) != null ? _a16 : false;
|
|
80714
|
-
for (const { role, content } of
|
|
80901
|
+
for (const { role, content } of prompt6) {
|
|
80715
80902
|
switch (role) {
|
|
80716
80903
|
case "system": {
|
|
80717
80904
|
if (!systemMessagesAllowed) {
|
|
@@ -81085,7 +81272,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
81085
81272
|
return (_c = (_b8 = (_a16 = this.config).supportedUrls) == null ? undefined : _b8.call(_a16)) != null ? _c : {};
|
|
81086
81273
|
}
|
|
81087
81274
|
async getArgs({
|
|
81088
|
-
prompt:
|
|
81275
|
+
prompt: prompt6,
|
|
81089
81276
|
maxOutputTokens,
|
|
81090
81277
|
temperature,
|
|
81091
81278
|
topP,
|
|
@@ -81113,7 +81300,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
81113
81300
|
});
|
|
81114
81301
|
}
|
|
81115
81302
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
81116
|
-
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
|
81303
|
+
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt6, { isGemmaModel });
|
|
81117
81304
|
const {
|
|
81118
81305
|
tools: googleTools2,
|
|
81119
81306
|
toolConfig: googleToolConfig,
|
|
@@ -81626,7 +81813,7 @@ var GoogleVertexImageModel = class {
|
|
|
81626
81813
|
return this.config.provider;
|
|
81627
81814
|
}
|
|
81628
81815
|
async doGenerate({
|
|
81629
|
-
prompt:
|
|
81816
|
+
prompt: prompt6,
|
|
81630
81817
|
n,
|
|
81631
81818
|
size,
|
|
81632
81819
|
aspectRatio,
|
|
@@ -81650,7 +81837,7 @@ var GoogleVertexImageModel = class {
|
|
|
81650
81837
|
schema: vertexImageProviderOptionsSchema
|
|
81651
81838
|
});
|
|
81652
81839
|
const body = {
|
|
81653
|
-
instances: [{ prompt:
|
|
81840
|
+
instances: [{ prompt: prompt6 }],
|
|
81654
81841
|
parameters: {
|
|
81655
81842
|
sampleCount: n,
|
|
81656
81843
|
...aspectRatio != null ? { aspectRatio } : {},
|
|
@@ -81779,12 +81966,12 @@ var vertex = createVertex2();
|
|
|
81779
81966
|
|
|
81780
81967
|
// ../../node_modules/@ai-sdk/openai/dist/index.mjs
|
|
81781
81968
|
function convertToOpenAIChatMessages({
|
|
81782
|
-
prompt:
|
|
81969
|
+
prompt: prompt6,
|
|
81783
81970
|
systemMessageMode = "system"
|
|
81784
81971
|
}) {
|
|
81785
81972
|
const messages = [];
|
|
81786
81973
|
const warnings = [];
|
|
81787
|
-
for (const { role, content } of
|
|
81974
|
+
for (const { role, content } of prompt6) {
|
|
81788
81975
|
switch (role) {
|
|
81789
81976
|
case "system": {
|
|
81790
81977
|
switch (systemMessageMode) {
|
|
@@ -82125,7 +82312,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
82125
82312
|
return this.config.provider;
|
|
82126
82313
|
}
|
|
82127
82314
|
async getArgs({
|
|
82128
|
-
prompt:
|
|
82315
|
+
prompt: prompt6,
|
|
82129
82316
|
maxOutputTokens,
|
|
82130
82317
|
temperature,
|
|
82131
82318
|
topP,
|
|
@@ -82161,7 +82348,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
82161
82348
|
});
|
|
82162
82349
|
}
|
|
82163
82350
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages({
|
|
82164
|
-
prompt:
|
|
82351
|
+
prompt: prompt6,
|
|
82165
82352
|
systemMessageMode: getSystemMessageMode(this.modelId)
|
|
82166
82353
|
});
|
|
82167
82354
|
warnings.push(...messageWarnings);
|
|
@@ -82686,23 +82873,23 @@ var reasoningModels = {
|
|
|
82686
82873
|
}
|
|
82687
82874
|
};
|
|
82688
82875
|
function convertToOpenAICompletionPrompt({
|
|
82689
|
-
prompt:
|
|
82876
|
+
prompt: prompt6,
|
|
82690
82877
|
user = "user",
|
|
82691
82878
|
assistant = "assistant"
|
|
82692
82879
|
}) {
|
|
82693
82880
|
let text2 = "";
|
|
82694
|
-
if (
|
|
82695
|
-
text2 += `${
|
|
82881
|
+
if (prompt6[0].role === "system") {
|
|
82882
|
+
text2 += `${prompt6[0].content}
|
|
82696
82883
|
|
|
82697
82884
|
`;
|
|
82698
|
-
|
|
82885
|
+
prompt6 = prompt6.slice(1);
|
|
82699
82886
|
}
|
|
82700
|
-
for (const { role, content } of
|
|
82887
|
+
for (const { role, content } of prompt6) {
|
|
82701
82888
|
switch (role) {
|
|
82702
82889
|
case "system": {
|
|
82703
82890
|
throw new InvalidPromptError({
|
|
82704
82891
|
message: "Unexpected system message in prompt: ${content}",
|
|
82705
|
-
prompt:
|
|
82892
|
+
prompt: prompt6
|
|
82706
82893
|
});
|
|
82707
82894
|
}
|
|
82708
82895
|
case "user": {
|
|
@@ -82778,7 +82965,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
82778
82965
|
return this.config.provider;
|
|
82779
82966
|
}
|
|
82780
82967
|
async getArgs({
|
|
82781
|
-
prompt:
|
|
82968
|
+
prompt: prompt6,
|
|
82782
82969
|
maxOutputTokens,
|
|
82783
82970
|
temperature,
|
|
82784
82971
|
topP,
|
|
@@ -82821,7 +83008,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
82821
83008
|
details: "JSON response format is not supported."
|
|
82822
83009
|
});
|
|
82823
83010
|
}
|
|
82824
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt:
|
|
83011
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt: prompt6 });
|
|
82825
83012
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
82826
83013
|
return {
|
|
82827
83014
|
args: {
|
|
@@ -83106,7 +83293,7 @@ var OpenAIImageModel = class {
|
|
|
83106
83293
|
return this.config.provider;
|
|
83107
83294
|
}
|
|
83108
83295
|
async doGenerate({
|
|
83109
|
-
prompt:
|
|
83296
|
+
prompt: prompt6,
|
|
83110
83297
|
n,
|
|
83111
83298
|
size,
|
|
83112
83299
|
aspectRatio,
|
|
@@ -83136,7 +83323,7 @@ var OpenAIImageModel = class {
|
|
|
83136
83323
|
headers: combineHeaders(this.config.headers(), headers),
|
|
83137
83324
|
body: {
|
|
83138
83325
|
model: this.modelId,
|
|
83139
|
-
prompt:
|
|
83326
|
+
prompt: prompt6,
|
|
83140
83327
|
n,
|
|
83141
83328
|
size,
|
|
83142
83329
|
...(_d = providerOptions.openai) != null ? _d : {},
|
|
@@ -83332,13 +83519,13 @@ var openaiTranscriptionResponseSchema = exports_external2.object({
|
|
|
83332
83519
|
})).nullish()
|
|
83333
83520
|
});
|
|
83334
83521
|
async function convertToOpenAIResponsesMessages({
|
|
83335
|
-
prompt:
|
|
83522
|
+
prompt: prompt6,
|
|
83336
83523
|
systemMessageMode
|
|
83337
83524
|
}) {
|
|
83338
83525
|
var _a16, _b8, _c, _d, _e, _f;
|
|
83339
83526
|
const messages = [];
|
|
83340
83527
|
const warnings = [];
|
|
83341
|
-
for (const { role, content } of
|
|
83528
|
+
for (const { role, content } of prompt6) {
|
|
83342
83529
|
switch (role) {
|
|
83343
83530
|
case "system": {
|
|
83344
83531
|
switch (systemMessageMode) {
|
|
@@ -83622,7 +83809,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
83622
83809
|
presencePenalty,
|
|
83623
83810
|
frequencyPenalty,
|
|
83624
83811
|
seed,
|
|
83625
|
-
prompt:
|
|
83812
|
+
prompt: prompt6,
|
|
83626
83813
|
providerOptions,
|
|
83627
83814
|
tools: tools2,
|
|
83628
83815
|
toolChoice,
|
|
@@ -83653,7 +83840,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
83653
83840
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
83654
83841
|
}
|
|
83655
83842
|
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
83656
|
-
prompt:
|
|
83843
|
+
prompt: prompt6,
|
|
83657
83844
|
systemMessageMode: modelConfig.systemMessageMode
|
|
83658
83845
|
});
|
|
83659
83846
|
warnings.push(...messageWarnings);
|
|
@@ -84771,13 +84958,13 @@ var symbol54 = Symbol.for(marker54);
|
|
|
84771
84958
|
var _a54;
|
|
84772
84959
|
var InvalidPromptError2 = class extends AISDKError2 {
|
|
84773
84960
|
constructor({
|
|
84774
|
-
prompt:
|
|
84961
|
+
prompt: prompt6,
|
|
84775
84962
|
message,
|
|
84776
84963
|
cause
|
|
84777
84964
|
}) {
|
|
84778
84965
|
super({ name: name44, message: `Invalid prompt: ${message}`, cause });
|
|
84779
84966
|
this[_a54] = true;
|
|
84780
|
-
this.prompt =
|
|
84967
|
+
this.prompt = prompt6;
|
|
84781
84968
|
}
|
|
84782
84969
|
static isInstance(error81) {
|
|
84783
84970
|
return AISDKError2.hasMarker(error81, marker54);
|
|
@@ -85540,10 +85727,10 @@ function getCacheControl(providerMetadata) {
|
|
|
85540
85727
|
const openrouter2 = providerMetadata == null ? undefined : providerMetadata.openrouter;
|
|
85541
85728
|
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
85729
|
}
|
|
85543
|
-
function convertToOpenRouterChatMessages(
|
|
85730
|
+
function convertToOpenRouterChatMessages(prompt6) {
|
|
85544
85731
|
var _a153, _b8, _c;
|
|
85545
85732
|
const messages = [];
|
|
85546
|
-
for (const { role, content, providerOptions } of
|
|
85733
|
+
for (const { role, content, providerOptions } of prompt6) {
|
|
85547
85734
|
switch (role) {
|
|
85548
85735
|
case "system": {
|
|
85549
85736
|
messages.push({
|
|
@@ -85832,7 +86019,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
85832
86019
|
this.config = config4;
|
|
85833
86020
|
}
|
|
85834
86021
|
getArgs({
|
|
85835
|
-
prompt:
|
|
86022
|
+
prompt: prompt6,
|
|
85836
86023
|
maxOutputTokens,
|
|
85837
86024
|
temperature,
|
|
85838
86025
|
topP,
|
|
@@ -85862,7 +86049,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
85862
86049
|
stop: stopSequences,
|
|
85863
86050
|
response_format: responseFormat,
|
|
85864
86051
|
top_k: topK,
|
|
85865
|
-
messages: convertToOpenRouterChatMessages(
|
|
86052
|
+
messages: convertToOpenRouterChatMessages(prompt6),
|
|
85866
86053
|
include_reasoning: this.settings.includeReasoning,
|
|
85867
86054
|
reasoning: this.settings.reasoning,
|
|
85868
86055
|
usage: this.settings.usage
|
|
@@ -86307,27 +86494,27 @@ var OpenRouterChatLanguageModel = class {
|
|
|
86307
86494
|
}
|
|
86308
86495
|
};
|
|
86309
86496
|
function convertToOpenRouterCompletionPrompt({
|
|
86310
|
-
prompt:
|
|
86497
|
+
prompt: prompt6,
|
|
86311
86498
|
inputFormat,
|
|
86312
86499
|
user = "user",
|
|
86313
86500
|
assistant = "assistant"
|
|
86314
86501
|
}) {
|
|
86315
|
-
if (inputFormat === "prompt" &&
|
|
86316
|
-
return { prompt:
|
|
86502
|
+
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") {
|
|
86503
|
+
return { prompt: prompt6[0].content[0].text };
|
|
86317
86504
|
}
|
|
86318
86505
|
let text2 = "";
|
|
86319
|
-
if (
|
|
86320
|
-
text2 += `${
|
|
86506
|
+
if (prompt6[0] && prompt6[0].role === "system") {
|
|
86507
|
+
text2 += `${prompt6[0].content}
|
|
86321
86508
|
|
|
86322
86509
|
`;
|
|
86323
|
-
|
|
86510
|
+
prompt6 = prompt6.slice(1);
|
|
86324
86511
|
}
|
|
86325
|
-
for (const { role, content } of
|
|
86512
|
+
for (const { role, content } of prompt6) {
|
|
86326
86513
|
switch (role) {
|
|
86327
86514
|
case "system": {
|
|
86328
86515
|
throw new InvalidPromptError2({
|
|
86329
86516
|
message: `Unexpected system message in prompt: ${content}`,
|
|
86330
|
-
prompt:
|
|
86517
|
+
prompt: prompt6
|
|
86331
86518
|
});
|
|
86332
86519
|
}
|
|
86333
86520
|
case "user": {
|
|
@@ -86454,7 +86641,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
86454
86641
|
this.config = config4;
|
|
86455
86642
|
}
|
|
86456
86643
|
getArgs({
|
|
86457
|
-
prompt:
|
|
86644
|
+
prompt: prompt6,
|
|
86458
86645
|
maxOutputTokens,
|
|
86459
86646
|
temperature,
|
|
86460
86647
|
topP,
|
|
@@ -86468,7 +86655,7 @@ var OpenRouterCompletionLanguageModel = class {
|
|
|
86468
86655
|
toolChoice
|
|
86469
86656
|
}) {
|
|
86470
86657
|
const { prompt: completionPrompt } = convertToOpenRouterCompletionPrompt({
|
|
86471
|
-
prompt:
|
|
86658
|
+
prompt: prompt6,
|
|
86472
86659
|
inputFormat: "prompt"
|
|
86473
86660
|
});
|
|
86474
86661
|
if (tools2 == null ? undefined : tools2.length) {
|
|
@@ -101707,11 +101894,11 @@ var coerce = {
|
|
|
101707
101894
|
var NEVER4 = INVALID2;
|
|
101708
101895
|
// ../../node_modules/ollama-ai-provider-v2/dist/index.mjs
|
|
101709
101896
|
function convertToOllamaChatMessages({
|
|
101710
|
-
prompt:
|
|
101897
|
+
prompt: prompt6,
|
|
101711
101898
|
systemMessageMode = "system"
|
|
101712
101899
|
}) {
|
|
101713
101900
|
const messages = [];
|
|
101714
|
-
for (const { role, content } of
|
|
101901
|
+
for (const { role, content } of prompt6) {
|
|
101715
101902
|
switch (role) {
|
|
101716
101903
|
case "system": {
|
|
101717
101904
|
switch (systemMessageMode) {
|
|
@@ -101928,7 +102115,7 @@ var OllamaChatLanguageModel = class {
|
|
|
101928
102115
|
return this.config.provider;
|
|
101929
102116
|
}
|
|
101930
102117
|
async getArgs({
|
|
101931
|
-
prompt:
|
|
102118
|
+
prompt: prompt6,
|
|
101932
102119
|
maxOutputTokens,
|
|
101933
102120
|
temperature,
|
|
101934
102121
|
topP,
|
|
@@ -101964,7 +102151,7 @@ var OllamaChatLanguageModel = class {
|
|
|
101964
102151
|
});
|
|
101965
102152
|
}
|
|
101966
102153
|
const messages = convertToOllamaChatMessages({
|
|
101967
|
-
prompt:
|
|
102154
|
+
prompt: prompt6,
|
|
101968
102155
|
systemMessageMode: getSystemMessageMode2(this.modelId)
|
|
101969
102156
|
});
|
|
101970
102157
|
const strictJsonSchema = (_c = ollamaOptions.strictJsonSchema) != null ? _c : false;
|
|
@@ -101993,7 +102180,7 @@ var OllamaChatLanguageModel = class {
|
|
|
101993
102180
|
seed,
|
|
101994
102181
|
think: (_e = ollamaOptions.think) != null ? _e : false,
|
|
101995
102182
|
messages: convertToOllamaChatMessages({
|
|
101996
|
-
prompt:
|
|
102183
|
+
prompt: prompt6,
|
|
101997
102184
|
systemMessageMode: getSystemMessageMode2(this.modelId)
|
|
101998
102185
|
})
|
|
101999
102186
|
};
|
|
@@ -102327,23 +102514,23 @@ var reasoningModels2 = {
|
|
|
102327
102514
|
}
|
|
102328
102515
|
};
|
|
102329
102516
|
function convertToOllamaCompletionPrompt({
|
|
102330
|
-
prompt:
|
|
102517
|
+
prompt: prompt6,
|
|
102331
102518
|
user = "user",
|
|
102332
102519
|
assistant = "assistant"
|
|
102333
102520
|
}) {
|
|
102334
102521
|
let text2 = "";
|
|
102335
|
-
if (
|
|
102336
|
-
text2 += `${
|
|
102522
|
+
if (prompt6[0].role === "system") {
|
|
102523
|
+
text2 += `${prompt6[0].content}
|
|
102337
102524
|
|
|
102338
102525
|
`;
|
|
102339
|
-
|
|
102526
|
+
prompt6 = prompt6.slice(1);
|
|
102340
102527
|
}
|
|
102341
|
-
for (const { role, content } of
|
|
102528
|
+
for (const { role, content } of prompt6) {
|
|
102342
102529
|
switch (role) {
|
|
102343
102530
|
case "system": {
|
|
102344
102531
|
throw new InvalidPromptError({
|
|
102345
102532
|
message: "Unexpected system message in prompt: ${content}",
|
|
102346
|
-
prompt:
|
|
102533
|
+
prompt: prompt6
|
|
102347
102534
|
});
|
|
102348
102535
|
}
|
|
102349
102536
|
case "user": {
|
|
@@ -102413,7 +102600,7 @@ var OllamaCompletionLanguageModel = class {
|
|
|
102413
102600
|
return this.config.provider;
|
|
102414
102601
|
}
|
|
102415
102602
|
async getArgs({
|
|
102416
|
-
prompt:
|
|
102603
|
+
prompt: prompt6,
|
|
102417
102604
|
maxOutputTokens,
|
|
102418
102605
|
temperature,
|
|
102419
102606
|
topP,
|
|
@@ -102453,7 +102640,7 @@ var OllamaCompletionLanguageModel = class {
|
|
|
102453
102640
|
details: "JSON response format is not supported."
|
|
102454
102641
|
});
|
|
102455
102642
|
}
|
|
102456
|
-
const { prompt: completionPrompt, stopSequences } = convertToOllamaCompletionPrompt({ prompt:
|
|
102643
|
+
const { prompt: completionPrompt, stopSequences } = convertToOllamaCompletionPrompt({ prompt: prompt6 });
|
|
102457
102644
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
102458
102645
|
return {
|
|
102459
102646
|
args: {
|
|
@@ -102687,7 +102874,7 @@ var OllamaImageModel = class {
|
|
|
102687
102874
|
return this.config.provider;
|
|
102688
102875
|
}
|
|
102689
102876
|
async doGenerate({
|
|
102690
|
-
prompt:
|
|
102877
|
+
prompt: prompt6,
|
|
102691
102878
|
n,
|
|
102692
102879
|
size,
|
|
102693
102880
|
aspectRatio,
|
|
@@ -102717,7 +102904,7 @@ var OllamaImageModel = class {
|
|
|
102717
102904
|
headers: combineHeaders(this.config.headers(), headers),
|
|
102718
102905
|
body: {
|
|
102719
102906
|
model: this.modelId,
|
|
102720
|
-
prompt:
|
|
102907
|
+
prompt: prompt6,
|
|
102721
102908
|
n,
|
|
102722
102909
|
size,
|
|
102723
102910
|
...(_d = providerOptions.ollama) != null ? _d : {},
|
|
@@ -102743,12 +102930,12 @@ var ollamaImageResponseSchema = exports_external4.object({
|
|
|
102743
102930
|
data: exports_external4.array(exports_external4.object({ b64_json: exports_external4.string() }))
|
|
102744
102931
|
});
|
|
102745
102932
|
function convertToOllamaResponsesMessages({
|
|
102746
|
-
prompt:
|
|
102933
|
+
prompt: prompt6,
|
|
102747
102934
|
systemMessageMode
|
|
102748
102935
|
}) {
|
|
102749
102936
|
const messages = [];
|
|
102750
102937
|
const warnings = [];
|
|
102751
|
-
for (const { role, content } of
|
|
102938
|
+
for (const { role, content } of prompt6) {
|
|
102752
102939
|
switch (role) {
|
|
102753
102940
|
case "system": {
|
|
102754
102941
|
switch (systemMessageMode) {
|
|
@@ -102962,7 +103149,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
102962
103149
|
presencePenalty,
|
|
102963
103150
|
frequencyPenalty,
|
|
102964
103151
|
seed,
|
|
102965
|
-
prompt:
|
|
103152
|
+
prompt: prompt6,
|
|
102966
103153
|
providerOptions,
|
|
102967
103154
|
tools: tools2,
|
|
102968
103155
|
toolChoice,
|
|
@@ -102993,7 +103180,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
102993
103180
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
102994
103181
|
}
|
|
102995
103182
|
const { messages, warnings: messageWarnings } = convertToOllamaResponsesMessages({
|
|
102996
|
-
prompt:
|
|
103183
|
+
prompt: prompt6,
|
|
102997
103184
|
systemMessageMode: modelConfig.systemMessageMode
|
|
102998
103185
|
});
|
|
102999
103186
|
warnings.push(...messageWarnings);
|
|
@@ -103006,7 +103193,7 @@ var OllamaResponsesLanguageModel = class {
|
|
|
103006
103193
|
const baseArgs = {
|
|
103007
103194
|
model: this.modelId,
|
|
103008
103195
|
messages: convertToOllamaChatMessages({
|
|
103009
|
-
prompt:
|
|
103196
|
+
prompt: prompt6,
|
|
103010
103197
|
systemMessageMode: "system"
|
|
103011
103198
|
}),
|
|
103012
103199
|
temperature,
|
|
@@ -103543,6 +103730,22 @@ var ollama = createOllama({
|
|
|
103543
103730
|
compatibility: "strict"
|
|
103544
103731
|
});
|
|
103545
103732
|
|
|
103733
|
+
// src/env.ts
|
|
103734
|
+
function getEnv(override) {
|
|
103735
|
+
return {
|
|
103736
|
+
POLKA_API_PROVIDER: process.env.POLKA_API_PROVIDER,
|
|
103737
|
+
POLKA_MODEL: process.env.POLKA_MODEL,
|
|
103738
|
+
POLKA_API_KEY: process.env.POLKA_API_KEY,
|
|
103739
|
+
POLKA_BUDGET: process.env.POLKA_BUDGET,
|
|
103740
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
|
|
103741
|
+
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY,
|
|
103742
|
+
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY,
|
|
103743
|
+
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
|
|
103744
|
+
TRACING_FILE: process.env.TRACING_FILE,
|
|
103745
|
+
...override
|
|
103746
|
+
};
|
|
103747
|
+
}
|
|
103748
|
+
|
|
103546
103749
|
// src/getModel.ts
|
|
103547
103750
|
var AiProvider;
|
|
103548
103751
|
((AiProvider2) => {
|
|
@@ -103554,12 +103757,28 @@ var AiProvider;
|
|
|
103554
103757
|
AiProvider2["GoogleVertex"] = "google-vertex";
|
|
103555
103758
|
})(AiProvider ||= {});
|
|
103556
103759
|
var getModel = (config5, debugLogging = false) => {
|
|
103557
|
-
const
|
|
103558
|
-
|
|
103559
|
-
|
|
103560
|
-
|
|
103760
|
+
const { TRACING_FILE } = getEnv();
|
|
103761
|
+
const fetchOverride = debugLogging || TRACING_FILE ? async (url4, options) => {
|
|
103762
|
+
const requestBody = options?.body ? JSON.parse(options.body) : undefined;
|
|
103763
|
+
if (debugLogging) {
|
|
103764
|
+
console.log("-> Request URL:", url4);
|
|
103765
|
+
console.log("-> Request Headers:", options?.headers);
|
|
103766
|
+
console.log("-> Request Body:");
|
|
103767
|
+
console.dir(requestBody, { depth: null });
|
|
103768
|
+
}
|
|
103769
|
+
if (TRACING_FILE) {
|
|
103770
|
+
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103771
|
+
type: "request",
|
|
103772
|
+
timestamp: new Date().toISOString(),
|
|
103773
|
+
url: url4,
|
|
103774
|
+
headers: options?.headers,
|
|
103775
|
+
body: requestBody
|
|
103776
|
+
}, null, 2));
|
|
103777
|
+
}
|
|
103561
103778
|
const res = await fetch(url4, options);
|
|
103562
|
-
|
|
103779
|
+
if (debugLogging) {
|
|
103780
|
+
console.log("<- Response Status:", res.status);
|
|
103781
|
+
}
|
|
103563
103782
|
const contentType = res.headers.get("content-type") || "";
|
|
103564
103783
|
if (contentType.includes("text/event-stream") && res.body) {
|
|
103565
103784
|
const [branch, clientStream] = res.body.tee();
|
|
@@ -103572,7 +103791,16 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103572
103791
|
done = d;
|
|
103573
103792
|
if (value) {
|
|
103574
103793
|
const text2 = decoder.decode(value);
|
|
103575
|
-
|
|
103794
|
+
if (debugLogging) {
|
|
103795
|
+
console.log("<- Stream chunk:", text2.replace(/\n/g, "\\n"));
|
|
103796
|
+
}
|
|
103797
|
+
if (TRACING_FILE) {
|
|
103798
|
+
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103799
|
+
type: "response-chunk",
|
|
103800
|
+
timestamp: new Date().toISOString(),
|
|
103801
|
+
chunk: text2
|
|
103802
|
+
}, null, 2));
|
|
103803
|
+
}
|
|
103576
103804
|
}
|
|
103577
103805
|
}
|
|
103578
103806
|
})();
|
|
@@ -103582,8 +103810,20 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103582
103810
|
});
|
|
103583
103811
|
}
|
|
103584
103812
|
const full = await res.text();
|
|
103585
|
-
|
|
103586
|
-
|
|
103813
|
+
const responseBody = JSON.parse(full);
|
|
103814
|
+
if (debugLogging) {
|
|
103815
|
+
console.log("<- Response Body:");
|
|
103816
|
+
console.dir(responseBody, { depth: null });
|
|
103817
|
+
}
|
|
103818
|
+
if (TRACING_FILE) {
|
|
103819
|
+
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103820
|
+
type: "response",
|
|
103821
|
+
timestamp: new Date().toISOString(),
|
|
103822
|
+
status: res.status,
|
|
103823
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
103824
|
+
body: responseBody
|
|
103825
|
+
}, null, 2));
|
|
103826
|
+
}
|
|
103587
103827
|
return new Response(full, {
|
|
103588
103828
|
headers: res.headers,
|
|
103589
103829
|
status: res.status
|
|
@@ -103646,12 +103886,12 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103646
103886
|
};
|
|
103647
103887
|
|
|
103648
103888
|
// src/ApiProviderConfig.ts
|
|
103649
|
-
var
|
|
103889
|
+
var isClaude = (model) => model.includes("claude");
|
|
103650
103890
|
var getToolFormat = (model, toolFormat) => {
|
|
103651
103891
|
if (toolFormat) {
|
|
103652
103892
|
return toolFormat;
|
|
103653
103893
|
}
|
|
103654
|
-
if (
|
|
103894
|
+
if (isClaude(model)) {
|
|
103655
103895
|
return "native";
|
|
103656
103896
|
}
|
|
103657
103897
|
return "polka-codes";
|
|
@@ -103872,11 +104112,11 @@ Aborting request...`);
|
|
|
103872
104112
|
// src/prices.ts
|
|
103873
104113
|
var prices_default = {
|
|
103874
104114
|
["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 }
|
|
104115
|
+
"claude-opus-4-20250514": { inputPrice: 15, outputPrice: 75, cacheWritesPrice: 18.75, cacheReadsPrice: 1.5, supportsThinking: true },
|
|
104116
|
+
"claude-sonnet-4-20250514": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: true },
|
|
104117
|
+
"claude-3-7-sonnet-20250219": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: true },
|
|
104118
|
+
"claude-3-5-sonnet-20241022": { inputPrice: 3, outputPrice: 15, cacheWritesPrice: 3.75, cacheReadsPrice: 0.3, supportsThinking: false },
|
|
104119
|
+
"claude-3-5-haiku-20241022": { inputPrice: 0.8, outputPrice: 4, cacheWritesPrice: 1, cacheReadsPrice: 0.08, supportsThinking: false }
|
|
103880
104120
|
},
|
|
103881
104121
|
["ollama" /* Ollama */]: {},
|
|
103882
104122
|
["deepseek" /* DeepSeek */]: {
|
|
@@ -103891,9 +104131,9 @@ var prices_default = {
|
|
|
103891
104131
|
"o4-mini": { inputPrice: 1.1, outputPrice: 4.4, cacheWritesPrice: 0.275, cacheReadsPrice: 0.275 }
|
|
103892
104132
|
},
|
|
103893
104133
|
["google-vertex" /* GoogleVertex */]: {
|
|
103894
|
-
"gemini-
|
|
103895
|
-
"gemini-
|
|
103896
|
-
"gemini-
|
|
104134
|
+
"gemini-2.5-pro": { inputPrice: 2.5, outputPrice: 10, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: true },
|
|
104135
|
+
"gemini-2.5-flash": { inputPrice: 0.3, outputPrice: 2.5, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: false },
|
|
104136
|
+
"gemini-2.5-flash-lite": { inputPrice: 0.1, outputPrice: 0.4, cacheWritesPrice: 0, cacheReadsPrice: 0, supportsThinking: false }
|
|
103897
104137
|
}
|
|
103898
104138
|
};
|
|
103899
104139
|
|
|
@@ -103969,7 +104209,7 @@ import os2 from "node:os";
|
|
|
103969
104209
|
import { existsSync, readFileSync } from "node:fs";
|
|
103970
104210
|
import { homedir } from "node:os";
|
|
103971
104211
|
import { join } from "node:path";
|
|
103972
|
-
var
|
|
104212
|
+
var import_lodash2 = __toESM(require_lodash(), 1);
|
|
103973
104213
|
|
|
103974
104214
|
// ../cli-shared/node_modules/yaml/dist/index.js
|
|
103975
104215
|
var composer = require_composer();
|
|
@@ -107880,7 +108120,7 @@ function mergeConfigs(configs) {
|
|
|
107880
108120
|
return {};
|
|
107881
108121
|
}
|
|
107882
108122
|
const mergedConfig = configs.reduce((acc, config5) => {
|
|
107883
|
-
const merged =
|
|
108123
|
+
const merged = import_lodash2.merge({}, acc, config5);
|
|
107884
108124
|
let accRules = acc.rules ?? [];
|
|
107885
108125
|
if (typeof accRules === "string") {
|
|
107886
108126
|
accRules = [accRules];
|
|
@@ -108727,7 +108967,7 @@ ${event.systemPrompt}`);
|
|
|
108727
108967
|
======== New Request ========
|
|
108728
108968
|
`);
|
|
108729
108969
|
if (verbose) {
|
|
108730
|
-
const
|
|
108970
|
+
const userMessage = event.userMessage.content;
|
|
108731
108971
|
if (typeof userMessage === "string") {
|
|
108732
108972
|
console.log(userMessage);
|
|
108733
108973
|
} else {
|
|
@@ -108746,9 +108986,17 @@ ${event.systemPrompt}`);
|
|
|
108746
108986
|
case "file":
|
|
108747
108987
|
console.log(source_default.yellow(`[File name: ${content.filename}, type: ${content.mediaType}]`));
|
|
108748
108988
|
break;
|
|
108749
|
-
|
|
108750
|
-
console.log(source_default.
|
|
108751
|
-
|
|
108989
|
+
case "tool-call":
|
|
108990
|
+
console.log(source_default.yellow(`[Tool call: ${content.toolName}]`));
|
|
108991
|
+
break;
|
|
108992
|
+
case "tool-result":
|
|
108993
|
+
console.log(source_default.yellow(`[Tool result: ${content.toolName}]`));
|
|
108994
|
+
if (verbose > 0) {
|
|
108995
|
+
console.log(content.output);
|
|
108996
|
+
}
|
|
108997
|
+
break;
|
|
108998
|
+
case "reasoning":
|
|
108999
|
+
break;
|
|
108752
109000
|
}
|
|
108753
109001
|
}
|
|
108754
109002
|
}
|
|
@@ -108782,29 +109030,33 @@ ${event.systemPrompt}`);
|
|
|
108782
109030
|
process.stdout.write(source_default.dim(event.newText));
|
|
108783
109031
|
hadReasoning = true;
|
|
108784
109032
|
break;
|
|
108785
|
-
case "ToolUse" /* ToolUse */:
|
|
108786
|
-
|
|
108787
|
-
|
|
108788
|
-
|
|
108789
|
-
|
|
108790
|
-
|
|
109033
|
+
case "ToolUse" /* ToolUse */: {
|
|
109034
|
+
console.log(source_default.yellow(`
|
|
109035
|
+
|
|
109036
|
+
Tool use:`, event.tool), event.content);
|
|
109037
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
109038
|
+
stats.calls++;
|
|
109039
|
+
toolCallStats.set(event.tool, stats);
|
|
108791
109040
|
break;
|
|
108792
|
-
|
|
108793
|
-
|
|
108794
|
-
|
|
108795
|
-
|
|
108796
|
-
|
|
108797
|
-
}
|
|
109041
|
+
}
|
|
109042
|
+
case "ToolReply" /* ToolReply */: {
|
|
109043
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
109044
|
+
stats.success++;
|
|
109045
|
+
toolCallStats.set(event.tool, stats);
|
|
108798
109046
|
break;
|
|
109047
|
+
}
|
|
108799
109048
|
case "ToolInvalid" /* ToolInvalid */:
|
|
108800
109049
|
break;
|
|
108801
|
-
case "ToolError" /* ToolError */:
|
|
108802
|
-
|
|
108803
|
-
|
|
108804
|
-
|
|
108805
|
-
|
|
108806
|
-
}
|
|
109050
|
+
case "ToolError" /* ToolError */: {
|
|
109051
|
+
console.error(source_default.red(`
|
|
109052
|
+
|
|
109053
|
+
Tool error:`, event.tool));
|
|
109054
|
+
console.error(source_default.red(event.content));
|
|
109055
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
109056
|
+
stats.errors++;
|
|
109057
|
+
toolCallStats.set(event.tool, stats);
|
|
108807
109058
|
break;
|
|
109059
|
+
}
|
|
108808
109060
|
case "ToolInterrupted" /* ToolInterrupted */:
|
|
108809
109061
|
break;
|
|
108810
109062
|
case "ToolHandOver" /* ToolHandOver */:
|
|
@@ -108872,23 +109124,7 @@ ${event.systemPrompt}`);
|
|
|
108872
109124
|
};
|
|
108873
109125
|
};
|
|
108874
109126
|
// 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
|
|
109127
|
+
var import_lodash3 = __toESM(require_lodash(), 1);
|
|
108892
109128
|
function addSharedOptions(command) {
|
|
108893
109129
|
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
109130
|
}
|
|
@@ -108898,8 +109134,6 @@ function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
|
|
|
108898
109134
|
process.chdir(options.baseDir);
|
|
108899
109135
|
cwd = options.baseDir;
|
|
108900
109136
|
console.log("Changed working directory to", cwd);
|
|
108901
|
-
} else {
|
|
108902
|
-
cwd = process.cwd();
|
|
108903
109137
|
}
|
|
108904
109138
|
const config6 = loadConfig(options.config, cwd, home) ?? {};
|
|
108905
109139
|
if (options.retryCount !== undefined) {
|
|
@@ -108911,26 +109145,26 @@ function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
|
|
|
108911
109145
|
const defaultProvider = options.apiProvider || env2.POLKA_API_PROVIDER || config6.defaultProvider;
|
|
108912
109146
|
const defaultModel = options.model || env2.POLKA_MODEL || config6.defaultModel;
|
|
108913
109147
|
if (defaultProvider && defaultModel) {
|
|
108914
|
-
|
|
109148
|
+
import_lodash3.set(config6, ["providers", defaultProvider, "defaultModel"], defaultModel);
|
|
108915
109149
|
}
|
|
108916
109150
|
const apiKey = options.apiKey || env2.POLKA_API_KEY;
|
|
108917
109151
|
if (apiKey) {
|
|
108918
109152
|
if (!defaultProvider) {
|
|
108919
109153
|
throw new Error("Must specify a provider if providing an API key");
|
|
108920
109154
|
}
|
|
108921
|
-
|
|
109155
|
+
import_lodash3.set(config6, ["providers", defaultProvider, "apiKey"], apiKey);
|
|
108922
109156
|
}
|
|
108923
109157
|
if (env2.ANTHROPIC_API_KEY) {
|
|
108924
|
-
|
|
109158
|
+
import_lodash3.set(config6, ["providers", "anthropic" /* Anthropic */, "apiKey"], env2.ANTHROPIC_API_KEY);
|
|
108925
109159
|
}
|
|
108926
109160
|
if (env2.DEEPSEEK_API_KEY) {
|
|
108927
|
-
|
|
109161
|
+
import_lodash3.set(config6, ["providers", "deepseek" /* DeepSeek */, "apiKey"], env2.DEEPSEEK_API_KEY);
|
|
108928
109162
|
}
|
|
108929
109163
|
if (env2.OPENROUTER_API_KEY) {
|
|
108930
|
-
|
|
109164
|
+
import_lodash3.set(config6, ["providers", "openrouter" /* OpenRouter */, "apiKey"], env2.OPENROUTER_API_KEY);
|
|
108931
109165
|
}
|
|
108932
109166
|
if (env2.OPENAI_API_KEY) {
|
|
108933
|
-
|
|
109167
|
+
import_lodash3.set(config6, ["providers", "ollama" /* Ollama */, "apiKey"], env2.OPENAI_API_KEY);
|
|
108934
109168
|
}
|
|
108935
109169
|
const providerConfig = new ApiProviderConfig({
|
|
108936
109170
|
defaultProvider,
|
|
@@ -108949,14 +109183,59 @@ function parseOptions(options, cwdArg, home = os2.homedir(), env2 = getEnv()) {
|
|
|
108949
109183
|
// src/Runner.ts
|
|
108950
109184
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
108951
109185
|
import os3 from "node:os";
|
|
108952
|
-
var
|
|
109186
|
+
var import_lodash4 = __toESM(require_lodash(), 1);
|
|
109187
|
+
|
|
109188
|
+
// src/getProviderOptions.ts
|
|
109189
|
+
function getProviderOptions(provider3, modelId, thinkingBudgetTokens, supportThinking) {
|
|
109190
|
+
if (thinkingBudgetTokens <= 0 || !provider3 || !modelId) {
|
|
109191
|
+
return {};
|
|
109192
|
+
}
|
|
109193
|
+
const modelInfo = prices_default[provider3]?.[modelId];
|
|
109194
|
+
const providerSupportsThinking = provider3 === "openrouter" /* OpenRouter */ || !!modelInfo?.supportsThinking;
|
|
109195
|
+
const shouldSupportThinking = supportThinking ?? providerSupportsThinking;
|
|
109196
|
+
if (!shouldSupportThinking) {
|
|
109197
|
+
return {};
|
|
109198
|
+
}
|
|
109199
|
+
const providerOptions = {};
|
|
109200
|
+
switch (provider3) {
|
|
109201
|
+
case "anthropic" /* Anthropic */:
|
|
109202
|
+
providerOptions.anthropic = {
|
|
109203
|
+
thinking: { type: "enabled", budgetTokens: thinkingBudgetTokens }
|
|
109204
|
+
};
|
|
109205
|
+
break;
|
|
109206
|
+
case "openrouter" /* OpenRouter */:
|
|
109207
|
+
providerOptions.openrouter = {
|
|
109208
|
+
reasoning: {
|
|
109209
|
+
max_tokens: thinkingBudgetTokens
|
|
109210
|
+
}
|
|
109211
|
+
};
|
|
109212
|
+
break;
|
|
109213
|
+
case "google-vertex" /* GoogleVertex */:
|
|
109214
|
+
providerOptions.google = {
|
|
109215
|
+
thinkingConfig: {
|
|
109216
|
+
includeThoughts: true,
|
|
109217
|
+
thinkingBudget: thinkingBudgetTokens
|
|
109218
|
+
}
|
|
109219
|
+
};
|
|
109220
|
+
break;
|
|
109221
|
+
case "ollama" /* Ollama */:
|
|
109222
|
+
break;
|
|
109223
|
+
case "deepseek" /* DeepSeek */:
|
|
109224
|
+
break;
|
|
109225
|
+
case "openai" /* OpenAI */:
|
|
109226
|
+
break;
|
|
109227
|
+
}
|
|
109228
|
+
return providerOptions;
|
|
109229
|
+
}
|
|
109230
|
+
|
|
109231
|
+
// src/Runner.ts
|
|
108953
109232
|
class Runner {
|
|
108954
109233
|
#options;
|
|
108955
109234
|
usageMeter;
|
|
108956
109235
|
multiAgent;
|
|
108957
109236
|
constructor(options) {
|
|
108958
109237
|
this.#options = options;
|
|
108959
|
-
this.usageMeter = new UsageMeter(
|
|
109238
|
+
this.usageMeter = new UsageMeter(import_lodash4.merge(prices_default, options.config.prices ?? {}), {
|
|
108960
109239
|
maxMessages: options.config.maxMessageCount ?? 0,
|
|
108961
109240
|
maxCost: options.config.budget ?? 0
|
|
108962
109241
|
});
|
|
@@ -108964,7 +109243,7 @@ class Runner {
|
|
|
108964
109243
|
if (typeof rules2 === "string") {
|
|
108965
109244
|
rules2 = [rules2];
|
|
108966
109245
|
}
|
|
108967
|
-
const
|
|
109246
|
+
const toolProviderOptions = {
|
|
108968
109247
|
command: {
|
|
108969
109248
|
onStarted(command) {
|
|
108970
109249
|
console.log(`$ >>>> $ ${command}`);
|
|
@@ -109027,6 +109306,7 @@ class Runner {
|
|
|
109027
109306
|
const requestTimeoutSeconds = agentConfig.requestTimeoutSeconds ?? this.#options.config.requestTimeoutSeconds;
|
|
109028
109307
|
const ai = getOrCreateLlm(agentName);
|
|
109029
109308
|
const config6 = this.#options.providerConfig.getConfigForAgent(agentName);
|
|
109309
|
+
const providerOptions = config6 ? getProviderOptions(config6.provider, ai.modelId, config6.parameters?.thinkingBudgetTokens ?? 0) : {};
|
|
109030
109310
|
const args = {
|
|
109031
109311
|
ai,
|
|
109032
109312
|
os: platform,
|
|
@@ -109038,8 +109318,11 @@ class Runner {
|
|
|
109038
109318
|
policies: policies2,
|
|
109039
109319
|
retryCount,
|
|
109040
109320
|
requestTimeoutSeconds,
|
|
109041
|
-
toolFormat: this.#options.config.toolFormat ?? "polka-codes",
|
|
109042
|
-
parameters:
|
|
109321
|
+
toolFormat: this.#options.config.toolFormat ?? config6?.toolFormat ?? "polka-codes",
|
|
109322
|
+
parameters: {
|
|
109323
|
+
...config6?.parameters,
|
|
109324
|
+
providerOptions
|
|
109325
|
+
},
|
|
109043
109326
|
usageMeter: this.usageMeter
|
|
109044
109327
|
};
|
|
109045
109328
|
switch (agentName) {
|
|
@@ -109047,23 +109330,23 @@ class Runner {
|
|
|
109047
109330
|
return new CoderAgent({
|
|
109048
109331
|
...args,
|
|
109049
109332
|
interactive: false,
|
|
109050
|
-
provider: getProvider(agentName, options.config,
|
|
109333
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109051
109334
|
});
|
|
109052
109335
|
case architectAgentInfo.name:
|
|
109053
109336
|
return new ArchitectAgent({
|
|
109054
109337
|
...args,
|
|
109055
|
-
provider: getProvider(agentName, options.config,
|
|
109338
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109056
109339
|
});
|
|
109057
109340
|
case analyzerAgentInfo.name:
|
|
109058
109341
|
return new AnalyzerAgent({
|
|
109059
109342
|
...args,
|
|
109060
109343
|
interactive: false,
|
|
109061
|
-
provider: getProvider(agentName, options.config,
|
|
109344
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109062
109345
|
});
|
|
109063
109346
|
case codeFixerAgentInfo.name:
|
|
109064
109347
|
return new CodeFixerAgent({
|
|
109065
109348
|
...args,
|
|
109066
|
-
provider: getProvider(agentName, options.config,
|
|
109349
|
+
provider: getProvider(agentName, options.config, toolProviderOptions)
|
|
109067
109350
|
});
|
|
109068
109351
|
default:
|
|
109069
109352
|
throw new Error(`Unknown agent: ${name18}`);
|
|
@@ -109160,10 +109443,10 @@ var runChat = async (opts, command) => {
|
|
|
109160
109443
|
if (!providerDetails?.provider) {
|
|
109161
109444
|
const newConfig = await configPrompt({});
|
|
109162
109445
|
const updatedConfig = JSON.parse(JSON.stringify(config6 ?? {}));
|
|
109163
|
-
|
|
109164
|
-
|
|
109446
|
+
import_lodash5.set(updatedConfig, `providers.${newConfig.provider}.model`, newConfig.model);
|
|
109447
|
+
import_lodash5.set(updatedConfig, `providers.${newConfig.provider}.apiKey`, newConfig.apiKey);
|
|
109165
109448
|
if (newConfig.baseURL) {
|
|
109166
|
-
|
|
109449
|
+
import_lodash5.set(updatedConfig, `providers.${newConfig.provider}.baseURL`, newConfig.baseURL);
|
|
109167
109450
|
}
|
|
109168
109451
|
providerConfig = new ApiProviderConfig(updatedConfig);
|
|
109169
109452
|
providerDetails = providerConfig.getConfigForAgent(agent);
|
|
@@ -109233,6 +109516,7 @@ var runChat = async (opts, command) => {
|
|
|
109233
109516
|
|
|
109234
109517
|
// src/commands/commit.ts
|
|
109235
109518
|
import { execSync, spawnSync as spawnSync2 } from "node:child_process";
|
|
109519
|
+
var import_lodash6 = __toESM(require_lodash(), 1);
|
|
109236
109520
|
|
|
109237
109521
|
// ../../node_modules/ora/index.js
|
|
109238
109522
|
import process10 from "node:process";
|
|
@@ -109841,15 +110125,15 @@ function ora(options) {
|
|
|
109841
110125
|
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
110126
|
const spinner = ora("Gathering information...").start();
|
|
109843
110127
|
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.');
|
|
110128
|
+
const { providerConfig, config: config6 } = parseOptions(options);
|
|
110129
|
+
const commandConfig = providerConfig.getConfigForCommand("commit");
|
|
110130
|
+
if (!commandConfig || !commandConfig.provider || !commandConfig.model) {
|
|
110131
|
+
console.error('Error: No provider specified. Please run "polka config" to configure your AI provider.');
|
|
109850
110132
|
process.exit(1);
|
|
109851
110133
|
}
|
|
109852
|
-
|
|
110134
|
+
console.log("Provider:", commandConfig.provider);
|
|
110135
|
+
console.log("Model:", commandConfig.model);
|
|
110136
|
+
const usage = new UsageMeter(import_lodash6.merge(prices_default, config6.prices ?? {}));
|
|
109853
110137
|
try {
|
|
109854
110138
|
const status = execSync("git status --porcelain").toString();
|
|
109855
110139
|
const stagedFiles = status.split(`
|
|
@@ -109874,11 +110158,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
109874
110158
|
}
|
|
109875
110159
|
const diff = execSync("git diff --cached -U50").toString();
|
|
109876
110160
|
spinner.text = "Generating commit message...";
|
|
109877
|
-
const llm = getModel(
|
|
109878
|
-
provider: provider3,
|
|
109879
|
-
model,
|
|
109880
|
-
apiKey
|
|
109881
|
-
});
|
|
110161
|
+
const llm = getModel(commandConfig);
|
|
109882
110162
|
const _schema = exports_external2.object({
|
|
109883
110163
|
reasoning: exports_external2.string().describe("Reasoning if any"),
|
|
109884
110164
|
message: exports_external2.string().describe("The generated commit message")
|
|
@@ -109973,7 +110253,7 @@ var createCommand2 = new Command("create").description("Create a new project").a
|
|
|
109973
110253
|
// src/commands/init.ts
|
|
109974
110254
|
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
109975
110255
|
import { dirname as dirname2 } from "node:path";
|
|
109976
|
-
var
|
|
110256
|
+
var import_lodash7 = __toESM(require_lodash(), 1);
|
|
109977
110257
|
|
|
109978
110258
|
// ../../node_modules/yaml/dist/index.js
|
|
109979
110259
|
var composer2 = require_composer2();
|
|
@@ -110104,7 +110384,7 @@ initCommand.action(async (options, command) => {
|
|
|
110104
110384
|
break;
|
|
110105
110385
|
case 2: {
|
|
110106
110386
|
const globalConfig4 = loadConfigAtPath(globalConfigPath) ?? {};
|
|
110107
|
-
|
|
110387
|
+
import_lodash7.set(globalConfig4, ["providers", newConfig.provider, "apiKey"], newConfig.apiKey);
|
|
110108
110388
|
mkdirSync(dirname2(globalConfigPath), { recursive: true });
|
|
110109
110389
|
writeFileSync(globalConfigPath, $stringify2(globalConfig4));
|
|
110110
110390
|
console.log(`API key saved to global config file: ${globalConfigPath}`);
|
|
@@ -110159,7 +110439,7 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
110159
110439
|
finalConfig.defaultProvider = newConfig.provider;
|
|
110160
110440
|
finalConfig.defaultModel = newConfig.model;
|
|
110161
110441
|
if (newConfig.apiKey) {
|
|
110162
|
-
|
|
110442
|
+
import_lodash7.set(finalConfig, ["providers", newConfig.provider, "apiKey"], newConfig.apiKey);
|
|
110163
110443
|
}
|
|
110164
110444
|
}
|
|
110165
110445
|
mkdirSync(dirname2(configPath), { recursive: true });
|
|
@@ -110173,17 +110453,18 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
110173
110453
|
|
|
110174
110454
|
// src/commands/pr.ts
|
|
110175
110455
|
import { execSync as execSync2, spawnSync as spawnSync3 } from "node:child_process";
|
|
110456
|
+
var import_lodash8 = __toESM(require_lodash(), 1);
|
|
110176
110457
|
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
110458
|
const options = command.parent?.opts() ?? {};
|
|
110178
110459
|
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.');
|
|
110460
|
+
const commandConfig = providerConfig.getConfigForCommand("pr");
|
|
110461
|
+
if (!commandConfig || !commandConfig.provider || !commandConfig.model) {
|
|
110462
|
+
console.error('Error: No provider specified. Please run "polka config" to configure your AI provider.');
|
|
110183
110463
|
process.exit(1);
|
|
110184
110464
|
}
|
|
110185
|
-
|
|
110186
|
-
console.log("
|
|
110465
|
+
const spinner = ora("Gathering information...").start();
|
|
110466
|
+
console.log("Provider:", commandConfig.provider);
|
|
110467
|
+
console.log("Model:", commandConfig.model);
|
|
110187
110468
|
try {
|
|
110188
110469
|
execSync2("gh --version", { stdio: "ignore" });
|
|
110189
110470
|
} catch {
|
|
@@ -110212,12 +110493,8 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
110212
110493
|
encoding: "utf-8"
|
|
110213
110494
|
});
|
|
110214
110495
|
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
|
-
});
|
|
110496
|
+
const usage = new UsageMeter(import_lodash8.merge(prices_default, config6.prices ?? {}));
|
|
110497
|
+
const ai = getModel(commandConfig);
|
|
110221
110498
|
spinner.text = "Generating pull request details...";
|
|
110222
110499
|
const resp = await generateGithubPullRequestDetails(ai, {
|
|
110223
110500
|
commitDiff: diff,
|
|
@@ -110242,6 +110519,177 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
110242
110519
|
}
|
|
110243
110520
|
});
|
|
110244
110521
|
|
|
110522
|
+
// src/commands/review.ts
|
|
110523
|
+
import { execSync as execSync3 } from "node:child_process";
|
|
110524
|
+
var import_lodash9 = __toESM(require_lodash(), 1);
|
|
110525
|
+
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) => {
|
|
110526
|
+
const parentOptions = command.parent?.opts() ?? {};
|
|
110527
|
+
const { providerConfig, config: config6 } = parseOptions(parentOptions);
|
|
110528
|
+
const commandConfig = providerConfig.getConfigForCommand("review");
|
|
110529
|
+
if (!commandConfig || !commandConfig.provider || !commandConfig.model) {
|
|
110530
|
+
console.error('Error: No provider specified. Please run "polka config" to configure your AI provider.');
|
|
110531
|
+
process.exit(1);
|
|
110532
|
+
}
|
|
110533
|
+
if (!options.json) {
|
|
110534
|
+
console.log("Provider:", commandConfig.provider);
|
|
110535
|
+
console.log("Model:", commandConfig.model);
|
|
110536
|
+
}
|
|
110537
|
+
const spinner = ora({
|
|
110538
|
+
text: "Gathering information...",
|
|
110539
|
+
stream: options.json ? process.stderr : process.stdout
|
|
110540
|
+
}).start();
|
|
110541
|
+
const usage = new UsageMeter(import_lodash9.merge(prices_default, config6.prices ?? {}));
|
|
110542
|
+
const ai = getModel(commandConfig);
|
|
110543
|
+
const toolProviderOptions = {
|
|
110544
|
+
excludeFiles: parentOptions.config.excludeFiles,
|
|
110545
|
+
interactive: parentOptions.interactive
|
|
110546
|
+
};
|
|
110547
|
+
const toolProvider = getProvider("analyzer", config6, toolProviderOptions);
|
|
110548
|
+
const sharedAiOptions = {
|
|
110549
|
+
ai,
|
|
110550
|
+
usageMeter: usage,
|
|
110551
|
+
os: process.platform,
|
|
110552
|
+
provider: toolProvider,
|
|
110553
|
+
interactive: false,
|
|
110554
|
+
policies: [],
|
|
110555
|
+
toolFormat: commandConfig.toolFormat
|
|
110556
|
+
};
|
|
110557
|
+
try {
|
|
110558
|
+
if (options.pr) {
|
|
110559
|
+
await reviewPR(options.pr, spinner, sharedAiOptions, options.json);
|
|
110560
|
+
} else {
|
|
110561
|
+
await reviewLocal(spinner, sharedAiOptions, options.json);
|
|
110562
|
+
}
|
|
110563
|
+
} catch (error120) {
|
|
110564
|
+
spinner.fail(`Error reviewing: ${error120 instanceof Error ? error120.message : String(error120)}`);
|
|
110565
|
+
console.error(error120);
|
|
110566
|
+
process.exit(1);
|
|
110567
|
+
}
|
|
110568
|
+
if (!options.json) {
|
|
110569
|
+
usage.printUsage();
|
|
110570
|
+
}
|
|
110571
|
+
});
|
|
110572
|
+
async function reviewPR(prIdentifier, spinner, sharedAiOptions, isJsonOutput) {
|
|
110573
|
+
const prNumberMatch = prIdentifier.match(/\d+$/);
|
|
110574
|
+
if (!prNumberMatch) {
|
|
110575
|
+
spinner.fail("Invalid PR number or URL.");
|
|
110576
|
+
process.exit(1);
|
|
110577
|
+
}
|
|
110578
|
+
const prNumber = prNumberMatch[0];
|
|
110579
|
+
try {
|
|
110580
|
+
execSync3("gh --version", { stdio: "ignore" });
|
|
110581
|
+
} catch {
|
|
110582
|
+
spinner.fail("Error: GitHub CLI (gh) is not installed. Please install it from https://cli.github.com/");
|
|
110583
|
+
process.exit(1);
|
|
110584
|
+
}
|
|
110585
|
+
try {
|
|
110586
|
+
spinner.text = `Checking out PR #${prNumber}...`;
|
|
110587
|
+
execSync3(`gh pr checkout ${prNumber}`, { stdio: "pipe" });
|
|
110588
|
+
} catch (_error) {
|
|
110589
|
+
spinner.fail(`Error checking out PR #${prNumber}. Make sure the PR number is correct and you have access to the repository.`);
|
|
110590
|
+
process.exit(1);
|
|
110591
|
+
}
|
|
110592
|
+
const gitRoot = execSync3("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
|
|
110593
|
+
const remoteUrl = execSync3("git remote get-url origin", { cwd: gitRoot, encoding: "utf-8" }).trim();
|
|
110594
|
+
const remoteMatch = remoteUrl.match(/github\.com[/:](?<owner>[^/]+)\/(?<repo>[^/]+)\.git$/);
|
|
110595
|
+
if (!remoteMatch?.groups) {
|
|
110596
|
+
spinner.fail("Could not determine GitHub repository owner and repo from remote URL.");
|
|
110597
|
+
process.exit(1);
|
|
110598
|
+
}
|
|
110599
|
+
spinner.text = "Fetching pull request details...";
|
|
110600
|
+
const prDetails = JSON.parse(execSync3(`gh pr view ${prNumber} --json title,body,commits`, { encoding: "utf-8" }));
|
|
110601
|
+
const defaultBranch = execSync3("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name", {
|
|
110602
|
+
encoding: "utf-8"
|
|
110603
|
+
}).trim();
|
|
110604
|
+
const commitMessages = prDetails.commits.map((c) => c.messageBody).join(`
|
|
110605
|
+
---
|
|
110606
|
+
`);
|
|
110607
|
+
spinner.text = "Generating review...";
|
|
110608
|
+
const result = await reviewDiff(sharedAiOptions, {
|
|
110609
|
+
commitRange: `${defaultBranch}...HEAD`,
|
|
110610
|
+
pullRequestTitle: prDetails.title,
|
|
110611
|
+
pullRequestDescription: prDetails.body,
|
|
110612
|
+
commitMessages
|
|
110613
|
+
});
|
|
110614
|
+
spinner.succeed("Review generated successfully");
|
|
110615
|
+
if (isJsonOutput) {
|
|
110616
|
+
console.log(JSON.stringify(result, null, 2));
|
|
110617
|
+
} else {
|
|
110618
|
+
console.log(formatReviewForConsole(result));
|
|
110619
|
+
}
|
|
110620
|
+
}
|
|
110621
|
+
async function reviewLocal(spinner, sharedAiOptions, isJsonOutput) {
|
|
110622
|
+
const hasStagedChanges = execSync3('git diff --staged --quiet || echo "staged"', { encoding: "utf-8" }).trim() === "staged";
|
|
110623
|
+
if (hasStagedChanges) {
|
|
110624
|
+
spinner.text = "Generating review for staged changes...";
|
|
110625
|
+
const result2 = await reviewDiff(sharedAiOptions, { staged: true });
|
|
110626
|
+
spinner.succeed("Review generated successfully");
|
|
110627
|
+
if (isJsonOutput) {
|
|
110628
|
+
console.log(JSON.stringify(result2, null, 2));
|
|
110629
|
+
} else {
|
|
110630
|
+
console.log(formatReviewForConsole(result2));
|
|
110631
|
+
}
|
|
110632
|
+
return;
|
|
110633
|
+
}
|
|
110634
|
+
const hasUnstagedChanges = execSync3('git diff --quiet || echo "unstaged"', { encoding: "utf-8" }).trim() === "unstaged";
|
|
110635
|
+
if (hasUnstagedChanges) {
|
|
110636
|
+
spinner.text = "Generating review for unstaged changes...";
|
|
110637
|
+
const result2 = await reviewDiff(sharedAiOptions, { staged: false });
|
|
110638
|
+
spinner.succeed("Review generated successfully");
|
|
110639
|
+
if (isJsonOutput) {
|
|
110640
|
+
console.log(JSON.stringify(result2, null, 2));
|
|
110641
|
+
} else {
|
|
110642
|
+
console.log(formatReviewForConsole(result2));
|
|
110643
|
+
}
|
|
110644
|
+
return;
|
|
110645
|
+
}
|
|
110646
|
+
spinner.text = "No local changes detected. Falling back to branch diff...";
|
|
110647
|
+
spinner.render();
|
|
110648
|
+
try {
|
|
110649
|
+
execSync3("gh --version", { stdio: "ignore" });
|
|
110650
|
+
} catch {
|
|
110651
|
+
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.");
|
|
110652
|
+
process.exit(1);
|
|
110653
|
+
}
|
|
110654
|
+
const defaultBranch = execSync3("gh repo view --json defaultBranchRef --jq .defaultBranchRef.name", {
|
|
110655
|
+
encoding: "utf-8"
|
|
110656
|
+
}).trim();
|
|
110657
|
+
const currentBranch = execSync3("git rev-parse --abbrev-ref HEAD", { encoding: "utf-8" }).trim();
|
|
110658
|
+
if (currentBranch === defaultBranch) {
|
|
110659
|
+
spinner.succeed(`No changes to review. You are on the default branch ('${defaultBranch}').`);
|
|
110660
|
+
process.exit(0);
|
|
110661
|
+
}
|
|
110662
|
+
spinner.text = `Generating review for changes between '${defaultBranch}' and '${currentBranch}'...`;
|
|
110663
|
+
const result = await reviewDiff(sharedAiOptions, {
|
|
110664
|
+
commitRange: `${defaultBranch}...${currentBranch}`
|
|
110665
|
+
});
|
|
110666
|
+
spinner.succeed("Review generated successfully");
|
|
110667
|
+
if (isJsonOutput) {
|
|
110668
|
+
console.log(JSON.stringify(result, null, 2));
|
|
110669
|
+
} else {
|
|
110670
|
+
console.log(formatReviewForConsole(result));
|
|
110671
|
+
}
|
|
110672
|
+
}
|
|
110673
|
+
function formatReviewForConsole(output) {
|
|
110674
|
+
let formatted = `### Overview
|
|
110675
|
+
|
|
110676
|
+
${output.overview}`;
|
|
110677
|
+
if (output.specificReviews.length > 0) {
|
|
110678
|
+
formatted += `
|
|
110679
|
+
|
|
110680
|
+
### File-specific feedback
|
|
110681
|
+
`;
|
|
110682
|
+
for (const item of output.specificReviews) {
|
|
110683
|
+
formatted += `
|
|
110684
|
+
**${item.file}:${item.lines}**
|
|
110685
|
+
|
|
110686
|
+
${item.review}
|
|
110687
|
+
`;
|
|
110688
|
+
}
|
|
110689
|
+
}
|
|
110690
|
+
return formatted;
|
|
110691
|
+
}
|
|
110692
|
+
|
|
110245
110693
|
// src/commands/task.ts
|
|
110246
110694
|
var readStdin = async (timeoutMs = 30000) => {
|
|
110247
110695
|
if (process.stdin.isTTY) {
|
|
@@ -110331,6 +110779,7 @@ program2.command("chat").description("Start an interactive chat session").action
|
|
|
110331
110779
|
program2.addCommand(initCommand);
|
|
110332
110780
|
program2.addCommand(commitCommand);
|
|
110333
110781
|
program2.addCommand(prCommand);
|
|
110782
|
+
program2.addCommand(reviewCommand);
|
|
110334
110783
|
program2.addCommand(createCommand2);
|
|
110335
110784
|
addSharedOptions(program2);
|
|
110336
110785
|
program2.parse();
|