slopcode 0.2.138 → 0.2.141
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/bin/slopcode +44 -7
- package/bundle/index.js +2126 -1726
- package/bundle/parser.worker.js +34 -1
- package/bundle/worker.js +1974 -1615
- package/package.json +12 -12
- package/postinstall.mjs +70 -5
package/bundle/worker.js
CHANGED
|
@@ -46,6 +46,39 @@ var __export = (target, all) => {
|
|
|
46
46
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
47
47
|
var __promiseAll = (args2) => Promise.all(args2);
|
|
48
48
|
var __require = import.meta.require;
|
|
49
|
+
var __using = (stack, value, async) => {
|
|
50
|
+
if (value != null) {
|
|
51
|
+
if (typeof value !== "object" && typeof value !== "function")
|
|
52
|
+
throw TypeError('Object expected to be assigned to "using" declaration');
|
|
53
|
+
let dispose;
|
|
54
|
+
if (async)
|
|
55
|
+
dispose = value[Symbol.asyncDispose];
|
|
56
|
+
if (dispose === undefined)
|
|
57
|
+
dispose = value[Symbol.dispose];
|
|
58
|
+
if (typeof dispose !== "function")
|
|
59
|
+
throw TypeError("Object not disposable");
|
|
60
|
+
stack.push([async, dispose, value]);
|
|
61
|
+
} else if (async) {
|
|
62
|
+
stack.push([async]);
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
var __callDispose = (stack, error, hasError) => {
|
|
67
|
+
let fail = (e) => error = hasError ? new SuppressedError(e, error, "An error was suppressed during disposal") : (hasError = true, e), next = (it) => {
|
|
68
|
+
while (it = stack.pop()) {
|
|
69
|
+
try {
|
|
70
|
+
var result = it[1] && it[1].call(it[2]);
|
|
71
|
+
if (it[0])
|
|
72
|
+
return Promise.resolve(result).then(next, (e) => (fail(e), next()));
|
|
73
|
+
} catch (e) {
|
|
74
|
+
fail(e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (hasError)
|
|
78
|
+
throw error;
|
|
79
|
+
};
|
|
80
|
+
return next();
|
|
81
|
+
};
|
|
49
82
|
|
|
50
83
|
// ../../node_modules/.bun/zod@4.1.8/node_modules/zod/v4/core/core.js
|
|
51
84
|
function $constructor(name2, initializer, params) {
|
|
@@ -10538,7 +10571,7 @@ class JSONSchemaGenerator {
|
|
|
10538
10571
|
if (val === undefined) {
|
|
10539
10572
|
if (this.unrepresentable === "throw") {
|
|
10540
10573
|
throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
10541
|
-
}
|
|
10574
|
+
} else {}
|
|
10542
10575
|
} else if (typeof val === "bigint") {
|
|
10543
10576
|
if (this.unrepresentable === "throw") {
|
|
10544
10577
|
throw new Error("BigInt literals cannot be represented in JSON Schema");
|
|
@@ -27961,7 +27994,7 @@ var init_installation = __esm(async () => {
|
|
|
27961
27994
|
await $`${process.execPath} --version`.nothrow().quiet().text();
|
|
27962
27995
|
}
|
|
27963
27996
|
Installation.upgrade = upgrade;
|
|
27964
|
-
Installation.VERSION = "0.2.
|
|
27997
|
+
Installation.VERSION = "0.2.141";
|
|
27965
27998
|
Installation.CHANNEL = "latest";
|
|
27966
27999
|
Installation.USER_AGENT = `${product.id}/${Installation.CHANNEL}/${Installation.VERSION}/${Flag.SLOPCODE_CLIENT}`;
|
|
27967
28000
|
async function latest(installMethod) {
|
|
@@ -81720,7 +81753,7 @@ function toIntArray(seed) {
|
|
|
81720
81753
|
buffer4.push(unicode >>> 6 & 63 | 128);
|
|
81721
81754
|
buffer4.push(unicode >>> 0 & 63 | 128);
|
|
81722
81755
|
index3++;
|
|
81723
|
-
}
|
|
81756
|
+
} else {}
|
|
81724
81757
|
if (buffer4.length > 3) {
|
|
81725
81758
|
result6.push(buffer4.shift() << 0 | buffer4.shift() << 8 | buffer4.shift() << 16 | buffer4.shift() << 24);
|
|
81726
81759
|
}
|
|
@@ -94653,57 +94686,64 @@ var init_bun = __esm(async () => {
|
|
|
94653
94686
|
version: zod_default.string()
|
|
94654
94687
|
}));
|
|
94655
94688
|
async function install(pkg, version4 = "latest") {
|
|
94656
|
-
|
|
94657
|
-
|
|
94658
|
-
|
|
94659
|
-
|
|
94660
|
-
const
|
|
94661
|
-
await Filesystem.
|
|
94662
|
-
|
|
94663
|
-
|
|
94664
|
-
|
|
94665
|
-
|
|
94666
|
-
|
|
94667
|
-
|
|
94668
|
-
|
|
94669
|
-
|
|
94670
|
-
|
|
94671
|
-
|
|
94672
|
-
const isOutdated = await PackageRegistry.isOutdated(pkg, cachedVersion, Global.Path.cache);
|
|
94673
|
-
if (!isOutdated)
|
|
94689
|
+
let __stack = [];
|
|
94690
|
+
try {
|
|
94691
|
+
const _3 = __using(__stack, await Lock.write("bun-install"), 0);
|
|
94692
|
+
const mod = path11.join(Global.Path.cache, "node_modules", pkg);
|
|
94693
|
+
const pkgjsonPath = path11.join(Global.Path.cache, "package.json");
|
|
94694
|
+
const parsed = await Filesystem.readJson(pkgjsonPath).catch(async () => {
|
|
94695
|
+
const result6 = { dependencies: {} };
|
|
94696
|
+
await Filesystem.writeJson(pkgjsonPath, result6);
|
|
94697
|
+
return result6;
|
|
94698
|
+
});
|
|
94699
|
+
if (!parsed.dependencies)
|
|
94700
|
+
parsed.dependencies = {};
|
|
94701
|
+
const dependencies = parsed.dependencies;
|
|
94702
|
+
const modExists = await Filesystem.exists(mod);
|
|
94703
|
+
const cachedVersion = dependencies[pkg];
|
|
94704
|
+
if (!modExists || !cachedVersion) {} else if (version4 !== "latest" && cachedVersion === version4) {
|
|
94674
94705
|
return mod;
|
|
94675
|
-
|
|
94676
|
-
|
|
94677
|
-
|
|
94678
|
-
|
|
94679
|
-
|
|
94680
|
-
|
|
94681
|
-
|
|
94682
|
-
|
|
94683
|
-
|
|
94684
|
-
|
|
94685
|
-
|
|
94686
|
-
|
|
94687
|
-
|
|
94688
|
-
|
|
94689
|
-
|
|
94690
|
-
|
|
94691
|
-
|
|
94692
|
-
|
|
94693
|
-
throw new BunProc.InstallFailedError({ pkg, version: version4 }, {
|
|
94694
|
-
cause: e3
|
|
94706
|
+
} else if (version4 === "latest") {
|
|
94707
|
+
const isOutdated = await PackageRegistry.isOutdated(pkg, cachedVersion, Global.Path.cache);
|
|
94708
|
+
if (!isOutdated)
|
|
94709
|
+
return mod;
|
|
94710
|
+
log4.info("Cached version is outdated, proceeding with install", { pkg, cachedVersion });
|
|
94711
|
+
}
|
|
94712
|
+
const args3 = [
|
|
94713
|
+
"add",
|
|
94714
|
+
"--force",
|
|
94715
|
+
"--exact",
|
|
94716
|
+
...proxied() || process.env.CI ? ["--no-cache"] : [],
|
|
94717
|
+
"--cwd",
|
|
94718
|
+
Global.Path.cache,
|
|
94719
|
+
pkg + "@" + version4
|
|
94720
|
+
];
|
|
94721
|
+
log4.info("installing package using Bun's default registry resolution", {
|
|
94722
|
+
pkg,
|
|
94723
|
+
version: version4
|
|
94695
94724
|
});
|
|
94696
|
-
|
|
94697
|
-
|
|
94698
|
-
|
|
94699
|
-
|
|
94700
|
-
|
|
94701
|
-
|
|
94725
|
+
await BunProc.run(args3, {
|
|
94726
|
+
cwd: Global.Path.cache
|
|
94727
|
+
}).catch((e3) => {
|
|
94728
|
+
throw new BunProc.InstallFailedError({ pkg, version: version4 }, {
|
|
94729
|
+
cause: e3
|
|
94730
|
+
});
|
|
94731
|
+
});
|
|
94732
|
+
let resolvedVersion = version4;
|
|
94733
|
+
if (version4 === "latest") {
|
|
94734
|
+
const installedPkg = await Filesystem.readJson(path11.join(mod, "package.json")).catch(() => null);
|
|
94735
|
+
if (installedPkg?.version) {
|
|
94736
|
+
resolvedVersion = installedPkg.version;
|
|
94737
|
+
}
|
|
94702
94738
|
}
|
|
94739
|
+
parsed.dependencies[pkg] = resolvedVersion;
|
|
94740
|
+
await Filesystem.writeJson(pkgjsonPath, parsed);
|
|
94741
|
+
return mod;
|
|
94742
|
+
} catch (_catch3) {
|
|
94743
|
+
var _err = _catch3, _hasErr = 1;
|
|
94744
|
+
} finally {
|
|
94745
|
+
__callDispose(__stack, _err, _hasErr);
|
|
94703
94746
|
}
|
|
94704
|
-
parsed.dependencies[pkg] = resolvedVersion;
|
|
94705
|
-
await Filesystem.writeJson(pkgjsonPath, parsed);
|
|
94706
|
-
return mod;
|
|
94707
94747
|
}
|
|
94708
94748
|
BunProc.install = install;
|
|
94709
94749
|
})(BunProc ||= {});
|
|
@@ -103573,9 +103613,16 @@ var init_storage = __esm(async () => {
|
|
|
103573
103613
|
const dir2 = await state2().then((x3) => x3.dir);
|
|
103574
103614
|
const target = path17.join(dir2, ...key) + ".json";
|
|
103575
103615
|
return withErrorHandling(async () => {
|
|
103576
|
-
|
|
103577
|
-
|
|
103578
|
-
|
|
103616
|
+
let __stack = [];
|
|
103617
|
+
try {
|
|
103618
|
+
const _3 = __using(__stack, await Lock.read(target), 0);
|
|
103619
|
+
const result6 = await Filesystem.readJson(target);
|
|
103620
|
+
return result6;
|
|
103621
|
+
} catch (_catch3) {
|
|
103622
|
+
var _err = _catch3, _hasErr = 1;
|
|
103623
|
+
} finally {
|
|
103624
|
+
__callDispose(__stack, _err, _hasErr);
|
|
103625
|
+
}
|
|
103579
103626
|
});
|
|
103580
103627
|
}
|
|
103581
103628
|
Storage.read = read2;
|
|
@@ -103583,11 +103630,18 @@ var init_storage = __esm(async () => {
|
|
|
103583
103630
|
const dir2 = await state2().then((x3) => x3.dir);
|
|
103584
103631
|
const target = path17.join(dir2, ...key) + ".json";
|
|
103585
103632
|
return withErrorHandling(async () => {
|
|
103586
|
-
|
|
103587
|
-
|
|
103588
|
-
|
|
103589
|
-
|
|
103590
|
-
|
|
103633
|
+
let __stack = [];
|
|
103634
|
+
try {
|
|
103635
|
+
const _3 = __using(__stack, await Lock.write(target), 0);
|
|
103636
|
+
const content = await Filesystem.readJson(target);
|
|
103637
|
+
fn4(content);
|
|
103638
|
+
await Filesystem.writeJson(target, content);
|
|
103639
|
+
return content;
|
|
103640
|
+
} catch (_catch3) {
|
|
103641
|
+
var _err = _catch3, _hasErr = 1;
|
|
103642
|
+
} finally {
|
|
103643
|
+
__callDispose(__stack, _err, _hasErr);
|
|
103644
|
+
}
|
|
103591
103645
|
});
|
|
103592
103646
|
}
|
|
103593
103647
|
Storage.update = update9;
|
|
@@ -103595,8 +103649,15 @@ var init_storage = __esm(async () => {
|
|
|
103595
103649
|
const dir2 = await state2().then((x3) => x3.dir);
|
|
103596
103650
|
const target = path17.join(dir2, ...key) + ".json";
|
|
103597
103651
|
return withErrorHandling(async () => {
|
|
103598
|
-
|
|
103599
|
-
|
|
103652
|
+
let __stack = [];
|
|
103653
|
+
try {
|
|
103654
|
+
const _3 = __using(__stack, await Lock.write(target), 0);
|
|
103655
|
+
await Filesystem.writeJson(target, content);
|
|
103656
|
+
} catch (_catch3) {
|
|
103657
|
+
var _err = _catch3, _hasErr = 1;
|
|
103658
|
+
} finally {
|
|
103659
|
+
__callDispose(__stack, _err, _hasErr);
|
|
103660
|
+
}
|
|
103600
103661
|
});
|
|
103601
103662
|
}
|
|
103602
103663
|
Storage.write = write;
|
|
@@ -111747,7 +111808,7 @@ var require_tracestate_impl = __commonJS((exports) => {
|
|
|
111747
111808
|
const value8 = listMember.slice(i8 + 1, part.length);
|
|
111748
111809
|
if ((0, tracestate_validators_1.validateKey)(key) && (0, tracestate_validators_1.validateValue)(value8)) {
|
|
111749
111810
|
agg.set(key, value8);
|
|
111750
|
-
}
|
|
111811
|
+
} else {}
|
|
111751
111812
|
}
|
|
111752
111813
|
return agg;
|
|
111753
111814
|
}, new Map);
|
|
@@ -140521,54 +140582,61 @@ var init_file = __esm(async () => {
|
|
|
140521
140582
|
}
|
|
140522
140583
|
File.status = status;
|
|
140523
140584
|
async function read2(file2) {
|
|
140524
|
-
|
|
140525
|
-
|
|
140526
|
-
|
|
140527
|
-
|
|
140528
|
-
|
|
140529
|
-
|
|
140530
|
-
|
|
140531
|
-
|
|
140585
|
+
let __stack = [];
|
|
140586
|
+
try {
|
|
140587
|
+
const _3 = __using(__stack, log8.time("read", { file: file2 }), 0);
|
|
140588
|
+
const project = Instance.project;
|
|
140589
|
+
const full = path24.join(Instance.directory, file2);
|
|
140590
|
+
if (!Instance.containsPath(full)) {
|
|
140591
|
+
throw new Error(`Access denied: path escapes project directory`);
|
|
140592
|
+
}
|
|
140593
|
+
if (isImageByExtension(file2)) {
|
|
140594
|
+
if (await Filesystem.exists(full)) {
|
|
140595
|
+
const buffer4 = await Filesystem.readBytes(full).catch(() => Buffer.from([]));
|
|
140596
|
+
const content2 = buffer4.toString("base64");
|
|
140597
|
+
const mimeType2 = getImageMimeType(file2);
|
|
140598
|
+
return { type: "text", content: content2, mimeType: mimeType2, encoding: "base64" };
|
|
140599
|
+
}
|
|
140600
|
+
return { type: "text", content: "" };
|
|
140601
|
+
}
|
|
140602
|
+
const text9 = isTextByExtension(file2) || isTextByName(file2);
|
|
140603
|
+
if (isBinaryByExtension(file2) && !text9) {
|
|
140604
|
+
return { type: "binary", content: "" };
|
|
140605
|
+
}
|
|
140606
|
+
if (!await Filesystem.exists(full)) {
|
|
140607
|
+
return { type: "text", content: "" };
|
|
140608
|
+
}
|
|
140609
|
+
const mimeType = Filesystem.mimeType(full);
|
|
140610
|
+
const encode5 = text9 ? false : await shouldEncode(mimeType);
|
|
140611
|
+
if (encode5 && !isImage(mimeType)) {
|
|
140612
|
+
return { type: "binary", content: "", mimeType };
|
|
140613
|
+
}
|
|
140614
|
+
if (encode5) {
|
|
140532
140615
|
const buffer4 = await Filesystem.readBytes(full).catch(() => Buffer.from([]));
|
|
140533
140616
|
const content2 = buffer4.toString("base64");
|
|
140534
|
-
|
|
140535
|
-
|
|
140536
|
-
|
|
140537
|
-
|
|
140538
|
-
|
|
140539
|
-
|
|
140540
|
-
|
|
140541
|
-
|
|
140542
|
-
|
|
140543
|
-
|
|
140544
|
-
|
|
140545
|
-
|
|
140546
|
-
|
|
140547
|
-
|
|
140548
|
-
|
|
140549
|
-
|
|
140550
|
-
}
|
|
140551
|
-
if (encode5) {
|
|
140552
|
-
const buffer4 = await Filesystem.readBytes(full).catch(() => Buffer.from([]));
|
|
140553
|
-
const content2 = buffer4.toString("base64");
|
|
140554
|
-
return { type: "text", content: content2, mimeType, encoding: "base64" };
|
|
140555
|
-
}
|
|
140556
|
-
const content = (await Filesystem.readText(full).catch(() => "")).trim();
|
|
140557
|
-
if (project.vcs === "git") {
|
|
140558
|
-
let diff = await $8`git diff ${file2}`.cwd(Instance.directory).quiet().nothrow().text();
|
|
140559
|
-
if (!diff.trim())
|
|
140560
|
-
diff = await $8`git diff --staged ${file2}`.cwd(Instance.directory).quiet().nothrow().text();
|
|
140561
|
-
if (diff.trim()) {
|
|
140562
|
-
const original = await $8`git show HEAD:${file2}`.cwd(Instance.directory).quiet().nothrow().text();
|
|
140563
|
-
const patch = structuredPatch(file2, file2, original, content, "old", "new", {
|
|
140564
|
-
context: Infinity,
|
|
140565
|
-
ignoreWhitespace: true
|
|
140566
|
-
});
|
|
140567
|
-
const diff2 = formatPatch(patch);
|
|
140568
|
-
return { type: "text", content, patch, diff: diff2 };
|
|
140617
|
+
return { type: "text", content: content2, mimeType, encoding: "base64" };
|
|
140618
|
+
}
|
|
140619
|
+
const content = (await Filesystem.readText(full).catch(() => "")).trim();
|
|
140620
|
+
if (project.vcs === "git") {
|
|
140621
|
+
let diff = await $8`git diff ${file2}`.cwd(Instance.directory).quiet().nothrow().text();
|
|
140622
|
+
if (!diff.trim())
|
|
140623
|
+
diff = await $8`git diff --staged ${file2}`.cwd(Instance.directory).quiet().nothrow().text();
|
|
140624
|
+
if (diff.trim()) {
|
|
140625
|
+
const original = await $8`git show HEAD:${file2}`.cwd(Instance.directory).quiet().nothrow().text();
|
|
140626
|
+
const patch = structuredPatch(file2, file2, original, content, "old", "new", {
|
|
140627
|
+
context: Infinity,
|
|
140628
|
+
ignoreWhitespace: true
|
|
140629
|
+
});
|
|
140630
|
+
const diff2 = formatPatch(patch);
|
|
140631
|
+
return { type: "text", content, patch, diff: diff2 };
|
|
140632
|
+
}
|
|
140569
140633
|
}
|
|
140634
|
+
return { type: "text", content };
|
|
140635
|
+
} catch (_catch3) {
|
|
140636
|
+
var _err = _catch3, _hasErr = 1;
|
|
140637
|
+
} finally {
|
|
140638
|
+
__callDispose(__stack, _err, _hasErr);
|
|
140570
140639
|
}
|
|
140571
|
-
return { type: "text", content };
|
|
140572
140640
|
}
|
|
140573
140641
|
File.read = read2;
|
|
140574
140642
|
async function list(dir2) {
|
|
@@ -163200,7 +163268,7 @@ ${JSON.stringify(symbolNames, null, 2)}`);
|
|
|
163200
163268
|
throw new Error(response.status + " : " + response.url);
|
|
163201
163269
|
}, "readAsync");
|
|
163202
163270
|
}
|
|
163203
|
-
}
|
|
163271
|
+
} else {}
|
|
163204
163272
|
var out = Module["print"] || console.log.bind(console);
|
|
163205
163273
|
var err = Module["printErr"] || console.error.bind(console);
|
|
163206
163274
|
Object.assign(Module, moduleOverrides);
|
|
@@ -167902,134 +167970,141 @@ var init_task2 = __esm(async () => {
|
|
|
167902
167970
|
description,
|
|
167903
167971
|
parameters,
|
|
167904
167972
|
async execute(params, ctx2) {
|
|
167905
|
-
|
|
167906
|
-
|
|
167907
|
-
|
|
167908
|
-
|
|
167909
|
-
|
|
167910
|
-
|
|
167911
|
-
|
|
167912
|
-
|
|
167913
|
-
|
|
167914
|
-
|
|
167915
|
-
|
|
167916
|
-
|
|
167917
|
-
|
|
167918
|
-
|
|
167919
|
-
|
|
167920
|
-
|
|
167921
|
-
|
|
167922
|
-
|
|
167923
|
-
|
|
167924
|
-
|
|
167925
|
-
|
|
167926
|
-
|
|
167927
|
-
|
|
167928
|
-
|
|
167929
|
-
if (
|
|
167930
|
-
|
|
167931
|
-
|
|
167932
|
-
|
|
167933
|
-
|
|
167934
|
-
|
|
167935
|
-
|
|
167936
|
-
|
|
167937
|
-
|
|
167938
|
-
|
|
167939
|
-
|
|
167940
|
-
|
|
167941
|
-
|
|
167942
|
-
|
|
167943
|
-
|
|
167944
|
-
|
|
167945
|
-
|
|
167946
|
-
|
|
167947
|
-
|
|
167948
|
-
|
|
167949
|
-
|
|
167950
|
-
|
|
167951
|
-
|
|
167952
|
-
|
|
167973
|
+
let __stack = [];
|
|
167974
|
+
try {
|
|
167975
|
+
const config5 = await Config.get();
|
|
167976
|
+
if (params.background && !Flag.SLOPCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS) {
|
|
167977
|
+
throw new Error("Background subagents require SLOPCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS=true");
|
|
167978
|
+
}
|
|
167979
|
+
if (!ctx2.extra?.bypassAgentCheck) {
|
|
167980
|
+
await ctx2.ask({
|
|
167981
|
+
permission: "task",
|
|
167982
|
+
patterns: [params.subagent_type],
|
|
167983
|
+
always: ["*"],
|
|
167984
|
+
metadata: {
|
|
167985
|
+
description: params.description,
|
|
167986
|
+
subagent_type: params.subagent_type
|
|
167987
|
+
}
|
|
167988
|
+
});
|
|
167989
|
+
}
|
|
167990
|
+
const agent = await Agent.get(params.subagent_type);
|
|
167991
|
+
if (!agent)
|
|
167992
|
+
throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`);
|
|
167993
|
+
const hasTaskPermission = agent.permission.some((rule) => rule.permission === "task");
|
|
167994
|
+
const hasTodoWritePermission = agent.permission.some((rule) => rule.permission === "todowrite");
|
|
167995
|
+
const hasTodoReadPermission = agent.permission.some((rule) => rule.permission === "todoread");
|
|
167996
|
+
const session = await iife2(async () => {
|
|
167997
|
+
if (params.task_id) {
|
|
167998
|
+
const found = await Session.get(params.task_id).catch(() => {});
|
|
167999
|
+
if (found)
|
|
168000
|
+
return found;
|
|
168001
|
+
}
|
|
168002
|
+
return await Session.create({
|
|
168003
|
+
parentID: ctx2.sessionID,
|
|
168004
|
+
title: params.description + ` (@${agent.name} subagent)`,
|
|
168005
|
+
permission: [
|
|
168006
|
+
...hasTodoWritePermission ? [] : [
|
|
168007
|
+
{
|
|
168008
|
+
permission: "todowrite",
|
|
168009
|
+
pattern: "*",
|
|
168010
|
+
action: "deny"
|
|
168011
|
+
}
|
|
168012
|
+
],
|
|
168013
|
+
...hasTodoReadPermission ? [] : [
|
|
168014
|
+
{
|
|
168015
|
+
permission: "todoread",
|
|
168016
|
+
pattern: "*",
|
|
168017
|
+
action: "deny"
|
|
168018
|
+
}
|
|
168019
|
+
],
|
|
168020
|
+
...hasTaskPermission ? [] : [
|
|
168021
|
+
{
|
|
168022
|
+
permission: "task",
|
|
168023
|
+
pattern: "*",
|
|
168024
|
+
action: "deny"
|
|
168025
|
+
}
|
|
168026
|
+
],
|
|
168027
|
+
...config5.experimental?.primary_tools?.map((t3) => ({
|
|
167953
168028
|
pattern: "*",
|
|
167954
|
-
action: "
|
|
167955
|
-
|
|
167956
|
-
|
|
167957
|
-
|
|
167958
|
-
|
|
167959
|
-
action: "allow",
|
|
167960
|
-
permission: t3
|
|
167961
|
-
})) ?? []
|
|
167962
|
-
]
|
|
167963
|
-
});
|
|
167964
|
-
});
|
|
167965
|
-
const msg = await MessageV2.get({ sessionID: ctx2.sessionID, messageID: ctx2.messageID });
|
|
167966
|
-
if (msg.info.role !== "assistant")
|
|
167967
|
-
throw new Error("Not an assistant message");
|
|
167968
|
-
const model2 = agent.model ?? {
|
|
167969
|
-
modelID: msg.info.modelID,
|
|
167970
|
-
providerID: msg.info.providerID
|
|
167971
|
-
};
|
|
167972
|
-
const metadata2 = {
|
|
167973
|
-
sessionId: session.id,
|
|
167974
|
-
model: model2,
|
|
167975
|
-
...params.background ? { background: true } : {}
|
|
167976
|
-
};
|
|
167977
|
-
ctx2.metadata({
|
|
167978
|
-
title: params.description,
|
|
167979
|
-
metadata: metadata2
|
|
167980
|
-
});
|
|
167981
|
-
async function runTask() {
|
|
167982
|
-
const promptParts = await SessionPrompt.resolvePromptParts(params.prompt);
|
|
167983
|
-
const result6 = await SessionPrompt.prompt({
|
|
167984
|
-
messageID: Identifier.ascending("message"),
|
|
167985
|
-
sessionID: session.id,
|
|
167986
|
-
model: {
|
|
167987
|
-
modelID: model2.modelID,
|
|
167988
|
-
providerID: model2.providerID
|
|
167989
|
-
},
|
|
167990
|
-
agent: agent.name,
|
|
167991
|
-
tools: {
|
|
167992
|
-
...hasTodoWritePermission ? {} : { todowrite: false },
|
|
167993
|
-
...hasTodoReadPermission ? {} : { todoread: false },
|
|
167994
|
-
...hasTaskPermission ? {} : { task: false },
|
|
167995
|
-
...Object.fromEntries((config5.experimental?.primary_tools ?? []).map((t3) => [t3, false]))
|
|
167996
|
-
},
|
|
167997
|
-
parts: promptParts
|
|
168029
|
+
action: "allow",
|
|
168030
|
+
permission: t3
|
|
168031
|
+
})) ?? []
|
|
168032
|
+
]
|
|
168033
|
+
});
|
|
167998
168034
|
});
|
|
167999
|
-
|
|
168000
|
-
|
|
168001
|
-
|
|
168002
|
-
const
|
|
168003
|
-
|
|
168004
|
-
|
|
168005
|
-
}
|
|
168006
|
-
const
|
|
168007
|
-
|
|
168008
|
-
|
|
168035
|
+
const msg = await MessageV2.get({ sessionID: ctx2.sessionID, messageID: ctx2.messageID });
|
|
168036
|
+
if (msg.info.role !== "assistant")
|
|
168037
|
+
throw new Error("Not an assistant message");
|
|
168038
|
+
const model2 = agent.model ?? {
|
|
168039
|
+
modelID: msg.info.modelID,
|
|
168040
|
+
providerID: msg.info.providerID
|
|
168041
|
+
};
|
|
168042
|
+
const metadata2 = {
|
|
168043
|
+
sessionId: session.id,
|
|
168044
|
+
model: model2,
|
|
168045
|
+
...params.background ? { background: true } : {}
|
|
168046
|
+
};
|
|
168047
|
+
ctx2.metadata({
|
|
168009
168048
|
title: params.description,
|
|
168010
|
-
metadata: metadata2
|
|
168011
|
-
run: runTask
|
|
168049
|
+
metadata: metadata2
|
|
168012
168050
|
});
|
|
168051
|
+
async function runTask() {
|
|
168052
|
+
const promptParts = await SessionPrompt.resolvePromptParts(params.prompt);
|
|
168053
|
+
const result6 = await SessionPrompt.prompt({
|
|
168054
|
+
messageID: Identifier.ascending("message"),
|
|
168055
|
+
sessionID: session.id,
|
|
168056
|
+
model: {
|
|
168057
|
+
modelID: model2.modelID,
|
|
168058
|
+
providerID: model2.providerID
|
|
168059
|
+
},
|
|
168060
|
+
agent: agent.name,
|
|
168061
|
+
tools: {
|
|
168062
|
+
...hasTodoWritePermission ? {} : { todowrite: false },
|
|
168063
|
+
...hasTodoReadPermission ? {} : { todoread: false },
|
|
168064
|
+
...hasTaskPermission ? {} : { task: false },
|
|
168065
|
+
...Object.fromEntries((config5.experimental?.primary_tools ?? []).map((t3) => [t3, false]))
|
|
168066
|
+
},
|
|
168067
|
+
parts: promptParts
|
|
168068
|
+
});
|
|
168069
|
+
return result6.parts.findLast((x3) => x3.type === "text")?.text ?? "";
|
|
168070
|
+
}
|
|
168071
|
+
if (params.background) {
|
|
168072
|
+
const existing = BackgroundJob.get(session.id);
|
|
168073
|
+
if (existing?.status === "running") {
|
|
168074
|
+
throw new Error(`Task ${session.id} is already running. Use task_status to check progress.`);
|
|
168075
|
+
}
|
|
168076
|
+
const info4 = await BackgroundJob.start({
|
|
168077
|
+
id: session.id,
|
|
168078
|
+
type: "task",
|
|
168079
|
+
title: params.description,
|
|
168080
|
+
metadata: metadata2,
|
|
168081
|
+
run: runTask
|
|
168082
|
+
});
|
|
168083
|
+
return {
|
|
168084
|
+
title: params.description,
|
|
168085
|
+
metadata: {
|
|
168086
|
+
...metadata2,
|
|
168087
|
+
jobId: info4.id
|
|
168088
|
+
},
|
|
168089
|
+
output: backgroundOutput(session.id)
|
|
168090
|
+
};
|
|
168091
|
+
}
|
|
168092
|
+
function cancel() {
|
|
168093
|
+
SessionPrompt.cancel(session.id);
|
|
168094
|
+
}
|
|
168095
|
+
ctx2.abort.addEventListener("abort", cancel);
|
|
168096
|
+
const _3 = __using(__stack, defer(() => ctx2.abort.removeEventListener("abort", cancel)), 0);
|
|
168097
|
+
const text11 = await runTask();
|
|
168013
168098
|
return {
|
|
168014
168099
|
title: params.description,
|
|
168015
|
-
metadata:
|
|
168016
|
-
|
|
168017
|
-
jobId: info4.id
|
|
168018
|
-
},
|
|
168019
|
-
output: backgroundOutput(session.id)
|
|
168100
|
+
metadata: metadata2,
|
|
168101
|
+
output: formatOutput(session.id, text11)
|
|
168020
168102
|
};
|
|
168103
|
+
} catch (_catch3) {
|
|
168104
|
+
var _err = _catch3, _hasErr = 1;
|
|
168105
|
+
} finally {
|
|
168106
|
+
__callDispose(__stack, _err, _hasErr);
|
|
168021
168107
|
}
|
|
168022
|
-
function cancel() {
|
|
168023
|
-
SessionPrompt.cancel(session.id);
|
|
168024
|
-
}
|
|
168025
|
-
ctx2.abort.addEventListener("abort", cancel);
|
|
168026
|
-
using _3 = defer(() => ctx2.abort.removeEventListener("abort", cancel));
|
|
168027
|
-
const text11 = await runTask();
|
|
168028
|
-
return {
|
|
168029
|
-
title: params.description,
|
|
168030
|
-
metadata: metadata2,
|
|
168031
|
-
output: formatOutput(session.id, text11)
|
|
168032
|
-
};
|
|
168033
168108
|
}
|
|
168034
168109
|
};
|
|
168035
168110
|
});
|
|
@@ -187339,19 +187414,26 @@ var init_registry2 = __esm(async () => {
|
|
|
187339
187414
|
return !usePatch;
|
|
187340
187415
|
return true;
|
|
187341
187416
|
}).map(async (t3) => {
|
|
187342
|
-
|
|
187343
|
-
|
|
187344
|
-
|
|
187345
|
-
|
|
187346
|
-
|
|
187347
|
-
|
|
187348
|
-
|
|
187349
|
-
|
|
187350
|
-
|
|
187351
|
-
|
|
187352
|
-
|
|
187353
|
-
|
|
187354
|
-
|
|
187417
|
+
let __stack = [];
|
|
187418
|
+
try {
|
|
187419
|
+
const _3 = __using(__stack, log12.time(t3.id), 0);
|
|
187420
|
+
const tool2 = await t3.init({ agent });
|
|
187421
|
+
const output2 = {
|
|
187422
|
+
description: tool2.description,
|
|
187423
|
+
parameters: tool2.parameters
|
|
187424
|
+
};
|
|
187425
|
+
await Plugin.trigger("tool.definition", { toolID: t3.id }, output2);
|
|
187426
|
+
return {
|
|
187427
|
+
id: t3.id,
|
|
187428
|
+
...tool2,
|
|
187429
|
+
description: output2.description,
|
|
187430
|
+
parameters: output2.parameters
|
|
187431
|
+
};
|
|
187432
|
+
} catch (_catch3) {
|
|
187433
|
+
var _err = _catch3, _hasErr = 1;
|
|
187434
|
+
} finally {
|
|
187435
|
+
__callDispose(__stack, _err, _hasErr);
|
|
187436
|
+
}
|
|
187355
187437
|
}));
|
|
187356
187438
|
return result6;
|
|
187357
187439
|
}
|
|
@@ -188105,404 +188187,411 @@ var init_prompt = __esm(async () => {
|
|
|
188105
188187
|
let step = 0;
|
|
188106
188188
|
const session = await Session.get(sessionID);
|
|
188107
188189
|
while (true) {
|
|
188108
|
-
|
|
188109
|
-
|
|
188110
|
-
|
|
188111
|
-
|
|
188112
|
-
|
|
188113
|
-
|
|
188114
|
-
|
|
188115
|
-
|
|
188116
|
-
|
|
188117
|
-
let msgs = filterQueuedMessages(await MessageV2.filterCompacted(MessageV2.stream(sessionID)), state4()[sessionID], mode2);
|
|
188118
|
-
const current2 = mode2 === "serial" ? state4()[sessionID]?.current : undefined;
|
|
188119
|
-
const currentVisible = current2 ? msgs.some((msg) => msg.info.role === "user" && msg.info.id === current2) : false;
|
|
188120
|
-
let currentMsg;
|
|
188121
|
-
let lastUser;
|
|
188122
|
-
let lastAssistant;
|
|
188123
|
-
let lastFinished;
|
|
188124
|
-
let lastComplete;
|
|
188125
|
-
let tasks = [];
|
|
188126
|
-
for (let i8 = msgs.length - 1;i8 >= 0; i8--) {
|
|
188127
|
-
const msg = msgs[i8];
|
|
188128
|
-
if (!lastUser && msg.info.role === "user" && (!current2 || msg.info.id === current2 || !currentVisible)) {
|
|
188129
|
-
lastUser = msg.info;
|
|
188130
|
-
currentMsg = msg;
|
|
188131
|
-
}
|
|
188132
|
-
if (!lastAssistant && msg.info.role === "assistant")
|
|
188133
|
-
lastAssistant = msg.info;
|
|
188134
|
-
if (!lastFinished && msg.info.role === "assistant" && msg.info.finish) {
|
|
188135
|
-
lastFinished = msg.info;
|
|
188136
|
-
}
|
|
188137
|
-
if (!lastComplete && msg.info.role === "assistant" && msg.info.finish && !["tool-calls", "unknown"].includes(msg.info.finish)) {
|
|
188138
|
-
lastComplete = msg.info;
|
|
188139
|
-
}
|
|
188140
|
-
if (lastUser && lastComplete)
|
|
188190
|
+
let __stack = [];
|
|
188191
|
+
try {
|
|
188192
|
+
SessionStatus.busy(sessionID, "starting");
|
|
188193
|
+
log12.info("loop", { step, sessionID });
|
|
188194
|
+
if (abort2.aborted) {
|
|
188195
|
+
if (held(state4()[sessionID], state4()[sessionID]?.current)) {
|
|
188196
|
+
next4 = "hold";
|
|
188197
|
+
return;
|
|
188198
|
+
}
|
|
188141
188199
|
break;
|
|
188142
|
-
const task2 = msg.parts.filter((part) => part.type === "compaction" || part.type === "subtask");
|
|
188143
|
-
if (task2 && !lastComplete && (!current2 || msg.info.id !== current2)) {
|
|
188144
|
-
tasks.push(...task2);
|
|
188145
188200
|
}
|
|
188146
|
-
|
|
188147
|
-
|
|
188148
|
-
const
|
|
188149
|
-
|
|
188150
|
-
|
|
188151
|
-
|
|
188152
|
-
|
|
188153
|
-
|
|
188154
|
-
|
|
188155
|
-
|
|
188156
|
-
|
|
188157
|
-
|
|
188158
|
-
|
|
188159
|
-
|
|
188160
|
-
|
|
188161
|
-
|
|
188162
|
-
|
|
188163
|
-
|
|
188164
|
-
|
|
188165
|
-
|
|
188166
|
-
|
|
188167
|
-
|
|
188168
|
-
}
|
|
188201
|
+
let msgs = filterQueuedMessages(await MessageV2.filterCompacted(MessageV2.stream(sessionID)), state4()[sessionID], mode2);
|
|
188202
|
+
const current2 = mode2 === "serial" ? state4()[sessionID]?.current : undefined;
|
|
188203
|
+
const currentVisible = current2 ? msgs.some((msg) => msg.info.role === "user" && msg.info.id === current2) : false;
|
|
188204
|
+
let currentMsg;
|
|
188205
|
+
let lastUser;
|
|
188206
|
+
let lastAssistant;
|
|
188207
|
+
let lastFinished;
|
|
188208
|
+
let lastComplete;
|
|
188209
|
+
let tasks = [];
|
|
188210
|
+
for (let i8 = msgs.length - 1;i8 >= 0; i8--) {
|
|
188211
|
+
const msg = msgs[i8];
|
|
188212
|
+
if (!lastUser && msg.info.role === "user" && (!current2 || msg.info.id === current2 || !currentVisible)) {
|
|
188213
|
+
lastUser = msg.info;
|
|
188214
|
+
currentMsg = msg;
|
|
188215
|
+
}
|
|
188216
|
+
if (!lastAssistant && msg.info.role === "assistant")
|
|
188217
|
+
lastAssistant = msg.info;
|
|
188218
|
+
if (!lastFinished && msg.info.role === "assistant" && msg.info.finish) {
|
|
188219
|
+
lastFinished = msg.info;
|
|
188220
|
+
}
|
|
188221
|
+
if (!lastComplete && msg.info.role === "assistant" && msg.info.finish && !["tool-calls", "unknown"].includes(msg.info.finish)) {
|
|
188222
|
+
lastComplete = msg.info;
|
|
188223
|
+
}
|
|
188224
|
+
if (lastUser && lastComplete)
|
|
188225
|
+
break;
|
|
188226
|
+
const task2 = msg.parts.filter((part) => part.type === "compaction" || part.type === "subtask");
|
|
188227
|
+
if (task2 && !lastComplete && (!current2 || msg.info.id !== current2)) {
|
|
188228
|
+
tasks.push(...task2);
|
|
188229
|
+
}
|
|
188169
188230
|
}
|
|
188170
|
-
|
|
188171
|
-
|
|
188172
|
-
|
|
188173
|
-
|
|
188174
|
-
|
|
188175
|
-
|
|
188176
|
-
|
|
188177
|
-
|
|
188178
|
-
|
|
188179
|
-
|
|
188180
|
-
|
|
188181
|
-
|
|
188182
|
-
|
|
188183
|
-
|
|
188184
|
-
|
|
188185
|
-
|
|
188186
|
-
|
|
188187
|
-
|
|
188188
|
-
|
|
188189
|
-
|
|
188190
|
-
|
|
188191
|
-
|
|
188192
|
-
input: 0,
|
|
188193
|
-
output: 0,
|
|
188194
|
-
reasoning: 0,
|
|
188195
|
-
cache: { read: 0, write: 0 }
|
|
188196
|
-
},
|
|
188197
|
-
modelID: taskModel.id,
|
|
188198
|
-
providerID: taskModel.providerID,
|
|
188199
|
-
time: {
|
|
188200
|
-
created: Date.now()
|
|
188231
|
+
if (currentMsg && !lastComplete) {
|
|
188232
|
+
const processed = msgs.filter((msg) => msg.info.role === "assistant" && msg.info.parentID === currentMsg.info.id && msg.parts.some((part) => part.type === "tool" && part.tool === TaskTool.id)).length;
|
|
188233
|
+
const remaining2 = currentMsg.parts.filter((part) => part.type === "subtask").slice(processed);
|
|
188234
|
+
tasks.push(...remaining2);
|
|
188235
|
+
}
|
|
188236
|
+
if (!lastUser)
|
|
188237
|
+
throw new Error("No user message found in stream. This should never happen.");
|
|
188238
|
+
if (shouldExitLoop(lastUser, lastAssistant)) {
|
|
188239
|
+
log12.info("exiting loop", { sessionID });
|
|
188240
|
+
break;
|
|
188241
|
+
}
|
|
188242
|
+
step++;
|
|
188243
|
+
const model2 = await Provider2.getModel(lastUser.model.providerID, lastUser.model.modelID).catch((e4) => {
|
|
188244
|
+
if (Provider2.ModelNotFoundError.isInstance(e4)) {
|
|
188245
|
+
const hint = e4.data.suggestions?.length ? ` Did you mean: ${e4.data.suggestions.join(", ")}?` : "";
|
|
188246
|
+
Bus.publish(Session.Event.Error, {
|
|
188247
|
+
sessionID,
|
|
188248
|
+
error: new NamedError.Unknown({
|
|
188249
|
+
message: `Model not found: ${e4.data.providerID}/${e4.data.modelID}.${hint}`
|
|
188250
|
+
}).toObject(),
|
|
188251
|
+
viewID: Instance.viewID
|
|
188252
|
+
});
|
|
188201
188253
|
}
|
|
188254
|
+
throw e4;
|
|
188202
188255
|
});
|
|
188203
|
-
|
|
188204
|
-
|
|
188205
|
-
|
|
188206
|
-
|
|
188207
|
-
|
|
188208
|
-
|
|
188209
|
-
|
|
188210
|
-
|
|
188211
|
-
|
|
188212
|
-
|
|
188213
|
-
|
|
188214
|
-
|
|
188215
|
-
|
|
188216
|
-
|
|
188256
|
+
const task = tasks.pop();
|
|
188257
|
+
const taskMsg = task && msgs.find((msg) => msg.info.role === "user" && msg.parts.some((part) => part.id === task.id));
|
|
188258
|
+
const taskUser = taskMsg?.info.role === "user" ? taskMsg.info : lastUser;
|
|
188259
|
+
if (task?.type === "subtask") {
|
|
188260
|
+
const taskTool = await TaskTool.init();
|
|
188261
|
+
const taskModel = task.model ? await Provider2.getModel(task.model.providerID, task.model.modelID) : model2;
|
|
188262
|
+
const assistantMessage = await Session.updateMessage({
|
|
188263
|
+
id: Identifier.ascending("message"),
|
|
188264
|
+
role: "assistant",
|
|
188265
|
+
parentID: taskUser.id,
|
|
188266
|
+
sessionID,
|
|
188267
|
+
mode: task.agent,
|
|
188268
|
+
agent: task.agent,
|
|
188269
|
+
variant: taskUser.variant,
|
|
188270
|
+
path: {
|
|
188271
|
+
cwd: Instance.directory,
|
|
188272
|
+
root: Instance.worktree
|
|
188217
188273
|
},
|
|
188274
|
+
cost: 0,
|
|
188275
|
+
tokens: {
|
|
188276
|
+
input: 0,
|
|
188277
|
+
output: 0,
|
|
188278
|
+
reasoning: 0,
|
|
188279
|
+
cache: { read: 0, write: 0 }
|
|
188280
|
+
},
|
|
188281
|
+
modelID: taskModel.id,
|
|
188282
|
+
providerID: taskModel.providerID,
|
|
188218
188283
|
time: {
|
|
188219
|
-
|
|
188284
|
+
created: Date.now()
|
|
188220
188285
|
}
|
|
188286
|
+
});
|
|
188287
|
+
let part = await Session.updatePart({
|
|
188288
|
+
id: Identifier.ascending("part"),
|
|
188289
|
+
messageID: assistantMessage.id,
|
|
188290
|
+
sessionID: assistantMessage.sessionID,
|
|
188291
|
+
type: "tool",
|
|
188292
|
+
callID: ulid4(),
|
|
188293
|
+
tool: TaskTool.id,
|
|
188294
|
+
state: {
|
|
188295
|
+
status: "running",
|
|
188296
|
+
input: {
|
|
188297
|
+
prompt: task.prompt,
|
|
188298
|
+
description: task.description,
|
|
188299
|
+
subagent_type: task.agent,
|
|
188300
|
+
command: task.command
|
|
188301
|
+
},
|
|
188302
|
+
time: {
|
|
188303
|
+
start: Date.now()
|
|
188304
|
+
}
|
|
188305
|
+
}
|
|
188306
|
+
});
|
|
188307
|
+
const taskArgs = {
|
|
188308
|
+
prompt: task.prompt,
|
|
188309
|
+
description: task.description,
|
|
188310
|
+
subagent_type: task.agent,
|
|
188311
|
+
command: task.command
|
|
188312
|
+
};
|
|
188313
|
+
await abortable(Plugin.trigger("tool.execute.before", {
|
|
188314
|
+
tool: "task",
|
|
188315
|
+
sessionID,
|
|
188316
|
+
callID: part.id
|
|
188317
|
+
}, { args: taskArgs }), abort2);
|
|
188318
|
+
let executionError;
|
|
188319
|
+
const taskAgent = await Agent.get(task.agent);
|
|
188320
|
+
const taskCtx = {
|
|
188321
|
+
agent: task.agent,
|
|
188322
|
+
messageID: assistantMessage.id,
|
|
188323
|
+
sessionID,
|
|
188324
|
+
abort: abort2,
|
|
188325
|
+
callID: part.callID,
|
|
188326
|
+
extra: { bypassAgentCheck: true },
|
|
188327
|
+
messages: msgs,
|
|
188328
|
+
async metadata(input2) {
|
|
188329
|
+
await Session.updatePart({
|
|
188330
|
+
...part,
|
|
188331
|
+
type: "tool",
|
|
188332
|
+
state: {
|
|
188333
|
+
...part.state,
|
|
188334
|
+
...input2
|
|
188335
|
+
}
|
|
188336
|
+
});
|
|
188337
|
+
},
|
|
188338
|
+
async ask(req) {
|
|
188339
|
+
await PermissionNext.ask({
|
|
188340
|
+
...req,
|
|
188341
|
+
sessionID,
|
|
188342
|
+
ruleset: PermissionNext.merge(taskAgent.permission, session.permission ?? [])
|
|
188343
|
+
});
|
|
188344
|
+
}
|
|
188345
|
+
};
|
|
188346
|
+
const result7 = await abortable(taskTool.execute(taskArgs, taskCtx), abort2).catch((error46) => {
|
|
188347
|
+
executionError = error46;
|
|
188348
|
+
log12.error("subtask execution failed", { error: error46, agent: task.agent, description: task.description });
|
|
188349
|
+
return;
|
|
188350
|
+
});
|
|
188351
|
+
const attachments = result7?.attachments?.map((attachment) => ({
|
|
188352
|
+
...attachment,
|
|
188353
|
+
id: Identifier.ascending("part"),
|
|
188354
|
+
sessionID,
|
|
188355
|
+
messageID: assistantMessage.id
|
|
188356
|
+
}));
|
|
188357
|
+
await abortable(Plugin.trigger("tool.execute.after", {
|
|
188358
|
+
tool: "task",
|
|
188359
|
+
sessionID,
|
|
188360
|
+
callID: part.id,
|
|
188361
|
+
args: taskArgs
|
|
188362
|
+
}, result7), abort2);
|
|
188363
|
+
assistantMessage.finish = "tool-calls";
|
|
188364
|
+
assistantMessage.time.completed = Date.now();
|
|
188365
|
+
await Session.updateMessage(assistantMessage);
|
|
188366
|
+
if (result7 && part.state.status === "running") {
|
|
188367
|
+
await Session.updatePart({
|
|
188368
|
+
...part,
|
|
188369
|
+
state: {
|
|
188370
|
+
status: "completed",
|
|
188371
|
+
input: part.state.input,
|
|
188372
|
+
title: result7.title,
|
|
188373
|
+
metadata: result7.metadata,
|
|
188374
|
+
output: result7.output,
|
|
188375
|
+
attachments,
|
|
188376
|
+
time: {
|
|
188377
|
+
...part.state.time,
|
|
188378
|
+
end: Date.now()
|
|
188379
|
+
}
|
|
188380
|
+
}
|
|
188381
|
+
});
|
|
188221
188382
|
}
|
|
188222
|
-
|
|
188223
|
-
const taskArgs = {
|
|
188224
|
-
prompt: task.prompt,
|
|
188225
|
-
description: task.description,
|
|
188226
|
-
subagent_type: task.agent,
|
|
188227
|
-
command: task.command
|
|
188228
|
-
};
|
|
188229
|
-
await abortable(Plugin.trigger("tool.execute.before", {
|
|
188230
|
-
tool: "task",
|
|
188231
|
-
sessionID,
|
|
188232
|
-
callID: part.id
|
|
188233
|
-
}, { args: taskArgs }), abort2);
|
|
188234
|
-
let executionError;
|
|
188235
|
-
const taskAgent = await Agent.get(task.agent);
|
|
188236
|
-
const taskCtx = {
|
|
188237
|
-
agent: task.agent,
|
|
188238
|
-
messageID: assistantMessage.id,
|
|
188239
|
-
sessionID,
|
|
188240
|
-
abort: abort2,
|
|
188241
|
-
callID: part.callID,
|
|
188242
|
-
extra: { bypassAgentCheck: true },
|
|
188243
|
-
messages: msgs,
|
|
188244
|
-
async metadata(input2) {
|
|
188383
|
+
if (!result7) {
|
|
188245
188384
|
await Session.updatePart({
|
|
188246
188385
|
...part,
|
|
188247
|
-
type: "tool",
|
|
188248
188386
|
state: {
|
|
188249
|
-
|
|
188250
|
-
|
|
188387
|
+
status: "error",
|
|
188388
|
+
error: executionError ? `Tool execution failed: ${executionError.message}` : "Tool execution failed",
|
|
188389
|
+
time: {
|
|
188390
|
+
start: part.state.status === "running" ? part.state.time.start : Date.now(),
|
|
188391
|
+
end: Date.now()
|
|
188392
|
+
},
|
|
188393
|
+
metadata: part.metadata,
|
|
188394
|
+
input: part.state.input
|
|
188251
188395
|
}
|
|
188252
188396
|
});
|
|
188253
|
-
}
|
|
188254
|
-
|
|
188255
|
-
|
|
188256
|
-
|
|
188397
|
+
}
|
|
188398
|
+
if (task.command) {
|
|
188399
|
+
const summaryUserMsg = {
|
|
188400
|
+
id: Identifier.ascending("message"),
|
|
188257
188401
|
sessionID,
|
|
188258
|
-
|
|
188402
|
+
role: "user",
|
|
188403
|
+
time: {
|
|
188404
|
+
created: Date.now()
|
|
188405
|
+
},
|
|
188406
|
+
agent: taskUser.agent,
|
|
188407
|
+
model: taskUser.model
|
|
188408
|
+
};
|
|
188409
|
+
await Session.updateMessage(summaryUserMsg);
|
|
188410
|
+
await Session.updatePart({
|
|
188411
|
+
id: Identifier.ascending("part"),
|
|
188412
|
+
messageID: summaryUserMsg.id,
|
|
188413
|
+
sessionID,
|
|
188414
|
+
type: "text",
|
|
188415
|
+
text: "Summarize the task tool output above and continue with your task.",
|
|
188416
|
+
synthetic: true
|
|
188259
188417
|
});
|
|
188260
188418
|
}
|
|
188261
|
-
|
|
188262
|
-
const result7 = await abortable(taskTool.execute(taskArgs, taskCtx), abort2).catch((error46) => {
|
|
188263
|
-
executionError = error46;
|
|
188264
|
-
log12.error("subtask execution failed", { error: error46, agent: task.agent, description: task.description });
|
|
188265
|
-
return;
|
|
188266
|
-
});
|
|
188267
|
-
const attachments = result7?.attachments?.map((attachment) => ({
|
|
188268
|
-
...attachment,
|
|
188269
|
-
id: Identifier.ascending("part"),
|
|
188270
|
-
sessionID,
|
|
188271
|
-
messageID: assistantMessage.id
|
|
188272
|
-
}));
|
|
188273
|
-
await abortable(Plugin.trigger("tool.execute.after", {
|
|
188274
|
-
tool: "task",
|
|
188275
|
-
sessionID,
|
|
188276
|
-
callID: part.id,
|
|
188277
|
-
args: taskArgs
|
|
188278
|
-
}, result7), abort2);
|
|
188279
|
-
assistantMessage.finish = "tool-calls";
|
|
188280
|
-
assistantMessage.time.completed = Date.now();
|
|
188281
|
-
await Session.updateMessage(assistantMessage);
|
|
188282
|
-
if (result7 && part.state.status === "running") {
|
|
188283
|
-
await Session.updatePart({
|
|
188284
|
-
...part,
|
|
188285
|
-
state: {
|
|
188286
|
-
status: "completed",
|
|
188287
|
-
input: part.state.input,
|
|
188288
|
-
title: result7.title,
|
|
188289
|
-
metadata: result7.metadata,
|
|
188290
|
-
output: result7.output,
|
|
188291
|
-
attachments,
|
|
188292
|
-
time: {
|
|
188293
|
-
...part.state.time,
|
|
188294
|
-
end: Date.now()
|
|
188295
|
-
}
|
|
188296
|
-
}
|
|
188297
|
-
});
|
|
188419
|
+
continue;
|
|
188298
188420
|
}
|
|
188299
|
-
if (
|
|
188300
|
-
|
|
188301
|
-
|
|
188302
|
-
|
|
188303
|
-
|
|
188304
|
-
|
|
188305
|
-
|
|
188306
|
-
|
|
188307
|
-
|
|
188308
|
-
},
|
|
188309
|
-
metadata: part.metadata,
|
|
188310
|
-
input: part.state.input
|
|
188311
|
-
}
|
|
188421
|
+
if (task?.type === "compaction") {
|
|
188422
|
+
SessionStatus.busy(sessionID, "compacting");
|
|
188423
|
+
const result7 = await SessionCompaction.process({
|
|
188424
|
+
messages: msgs,
|
|
188425
|
+
parentID: taskUser.id,
|
|
188426
|
+
abort: abort2,
|
|
188427
|
+
sessionID,
|
|
188428
|
+
auto: task.auto,
|
|
188429
|
+
overflow: task.overflow
|
|
188312
188430
|
});
|
|
188431
|
+
if (result7 === "stop")
|
|
188432
|
+
break;
|
|
188433
|
+
continue;
|
|
188313
188434
|
}
|
|
188314
|
-
if (
|
|
188315
|
-
|
|
188316
|
-
|
|
188317
|
-
sessionID,
|
|
188318
|
-
role: "user",
|
|
188319
|
-
time: {
|
|
188320
|
-
created: Date.now()
|
|
188321
|
-
},
|
|
188322
|
-
agent: taskUser.agent,
|
|
188323
|
-
model: taskUser.model
|
|
188324
|
-
};
|
|
188325
|
-
await Session.updateMessage(summaryUserMsg);
|
|
188326
|
-
await Session.updatePart({
|
|
188327
|
-
id: Identifier.ascending("part"),
|
|
188328
|
-
messageID: summaryUserMsg.id,
|
|
188435
|
+
if (lastFinished && lastFinished.summary !== true && await SessionCompaction.isOverflow({ tokens: lastFinished.tokens, model: model2 })) {
|
|
188436
|
+
SessionStatus.busy(sessionID, "compacting");
|
|
188437
|
+
await SessionCompaction.create({
|
|
188329
188438
|
sessionID,
|
|
188330
|
-
|
|
188331
|
-
|
|
188332
|
-
|
|
188439
|
+
agent: lastUser.agent,
|
|
188440
|
+
model: lastUser.model,
|
|
188441
|
+
auto: true
|
|
188333
188442
|
});
|
|
188443
|
+
continue;
|
|
188334
188444
|
}
|
|
188335
|
-
|
|
188336
|
-
|
|
188337
|
-
|
|
188338
|
-
|
|
188339
|
-
const result7 = await SessionCompaction.process({
|
|
188445
|
+
const agent = await Agent.get(lastUser.agent);
|
|
188446
|
+
const maxSteps = agent.steps ?? Infinity;
|
|
188447
|
+
const isLastStep = step >= maxSteps;
|
|
188448
|
+
msgs = await insertReminders({
|
|
188340
188449
|
messages: msgs,
|
|
188341
|
-
|
|
188342
|
-
|
|
188343
|
-
sessionID,
|
|
188344
|
-
auto: task.auto,
|
|
188345
|
-
overflow: task.overflow
|
|
188450
|
+
agent,
|
|
188451
|
+
session
|
|
188346
188452
|
});
|
|
188347
|
-
|
|
188348
|
-
|
|
188349
|
-
|
|
188350
|
-
|
|
188351
|
-
|
|
188352
|
-
|
|
188353
|
-
|
|
188453
|
+
const processor = SessionProcessor.create({
|
|
188454
|
+
assistantMessage: await Session.updateMessage({
|
|
188455
|
+
id: Identifier.ascending("message"),
|
|
188456
|
+
parentID: lastUser.id,
|
|
188457
|
+
role: "assistant",
|
|
188458
|
+
mode: agent.name,
|
|
188459
|
+
agent: agent.name,
|
|
188460
|
+
variant: lastUser.variant,
|
|
188461
|
+
path: {
|
|
188462
|
+
cwd: Instance.directory,
|
|
188463
|
+
root: Instance.worktree
|
|
188464
|
+
},
|
|
188465
|
+
cost: 0,
|
|
188466
|
+
tokens: {
|
|
188467
|
+
input: 0,
|
|
188468
|
+
output: 0,
|
|
188469
|
+
reasoning: 0,
|
|
188470
|
+
cache: { read: 0, write: 0 }
|
|
188471
|
+
},
|
|
188472
|
+
modelID: model2.id,
|
|
188473
|
+
providerID: model2.providerID,
|
|
188474
|
+
time: {
|
|
188475
|
+
created: Date.now()
|
|
188476
|
+
},
|
|
188477
|
+
sessionID
|
|
188478
|
+
}),
|
|
188354
188479
|
sessionID,
|
|
188355
|
-
|
|
188356
|
-
|
|
188357
|
-
auto: true
|
|
188358
|
-
});
|
|
188359
|
-
continue;
|
|
188360
|
-
}
|
|
188361
|
-
const agent = await Agent.get(lastUser.agent);
|
|
188362
|
-
const maxSteps = agent.steps ?? Infinity;
|
|
188363
|
-
const isLastStep = step >= maxSteps;
|
|
188364
|
-
msgs = await insertReminders({
|
|
188365
|
-
messages: msgs,
|
|
188366
|
-
agent,
|
|
188367
|
-
session
|
|
188368
|
-
});
|
|
188369
|
-
const processor = SessionProcessor.create({
|
|
188370
|
-
assistantMessage: await Session.updateMessage({
|
|
188371
|
-
id: Identifier.ascending("message"),
|
|
188372
|
-
parentID: lastUser.id,
|
|
188373
|
-
role: "assistant",
|
|
188374
|
-
mode: agent.name,
|
|
188375
|
-
agent: agent.name,
|
|
188376
|
-
variant: lastUser.variant,
|
|
188377
|
-
path: {
|
|
188378
|
-
cwd: Instance.directory,
|
|
188379
|
-
root: Instance.worktree
|
|
188380
|
-
},
|
|
188381
|
-
cost: 0,
|
|
188382
|
-
tokens: {
|
|
188383
|
-
input: 0,
|
|
188384
|
-
output: 0,
|
|
188385
|
-
reasoning: 0,
|
|
188386
|
-
cache: { read: 0, write: 0 }
|
|
188387
|
-
},
|
|
188388
|
-
modelID: model2.id,
|
|
188389
|
-
providerID: model2.providerID,
|
|
188390
|
-
time: {
|
|
188391
|
-
created: Date.now()
|
|
188392
|
-
},
|
|
188393
|
-
sessionID
|
|
188394
|
-
}),
|
|
188395
|
-
sessionID,
|
|
188396
|
-
model: model2,
|
|
188397
|
-
abort: abort2
|
|
188398
|
-
});
|
|
188399
|
-
using _3 = defer(() => InstructionPrompt.clear(processor.message.id));
|
|
188400
|
-
const lastUserMsg = current2 ? msgs.find((m5) => m5.info.role === "user" && m5.info.id === current2) : msgs.findLast((m5) => m5.info.role === "user");
|
|
188401
|
-
const bypassAgentCheck = lastUserMsg?.parts.some((p4) => p4.type === "agent") ?? false;
|
|
188402
|
-
const tools = await resolveTools({
|
|
188403
|
-
agent,
|
|
188404
|
-
session,
|
|
188405
|
-
model: model2,
|
|
188406
|
-
tools: lastUser.tools,
|
|
188407
|
-
processor,
|
|
188408
|
-
bypassAgentCheck,
|
|
188409
|
-
messages: msgs
|
|
188410
|
-
});
|
|
188411
|
-
if (lastUser.format?.type === "json_schema") {
|
|
188412
|
-
tools["StructuredOutput"] = createStructuredOutputTool({
|
|
188413
|
-
schema: lastUser.format.schema,
|
|
188414
|
-
onSuccess(output2) {
|
|
188415
|
-
structuredOutput = output2;
|
|
188416
|
-
}
|
|
188480
|
+
model: model2,
|
|
188481
|
+
abort: abort2
|
|
188417
188482
|
});
|
|
188418
|
-
|
|
188419
|
-
|
|
188420
|
-
|
|
188421
|
-
|
|
188422
|
-
|
|
188423
|
-
|
|
188424
|
-
|
|
188483
|
+
const _3 = __using(__stack, defer(() => InstructionPrompt.clear(processor.message.id)), 0);
|
|
188484
|
+
const lastUserMsg = current2 ? msgs.find((m5) => m5.info.role === "user" && m5.info.id === current2) : msgs.findLast((m5) => m5.info.role === "user");
|
|
188485
|
+
const bypassAgentCheck = lastUserMsg?.parts.some((p4) => p4.type === "agent") ?? false;
|
|
188486
|
+
const tools = await resolveTools({
|
|
188487
|
+
agent,
|
|
188488
|
+
session,
|
|
188489
|
+
model: model2,
|
|
188490
|
+
tools: lastUser.tools,
|
|
188491
|
+
processor,
|
|
188492
|
+
bypassAgentCheck,
|
|
188493
|
+
messages: msgs
|
|
188425
188494
|
});
|
|
188426
|
-
|
|
188427
|
-
|
|
188428
|
-
|
|
188429
|
-
|
|
188430
|
-
|
|
188431
|
-
|
|
188432
|
-
|
|
188433
|
-
|
|
188434
|
-
|
|
188495
|
+
if (lastUser.format?.type === "json_schema") {
|
|
188496
|
+
tools["StructuredOutput"] = createStructuredOutputTool({
|
|
188497
|
+
schema: lastUser.format.schema,
|
|
188498
|
+
onSuccess(output2) {
|
|
188499
|
+
structuredOutput = output2;
|
|
188500
|
+
}
|
|
188501
|
+
});
|
|
188502
|
+
}
|
|
188503
|
+
if (step === 1) {
|
|
188504
|
+
SessionSummary.summarize({
|
|
188505
|
+
sessionID,
|
|
188506
|
+
messageID: lastUser.id
|
|
188507
|
+
}).catch((error46) => {
|
|
188508
|
+
log12.error("failed to summarize session", { sessionID, error: error46 });
|
|
188509
|
+
});
|
|
188510
|
+
}
|
|
188511
|
+
if (mode2 === "injection" && step > 1 && lastFinished) {
|
|
188512
|
+
for (const msg of msgs) {
|
|
188513
|
+
if (msg.info.role !== "user" || msg.info.id <= lastFinished.id)
|
|
188435
188514
|
continue;
|
|
188436
|
-
part.
|
|
188437
|
-
"
|
|
188438
|
-
|
|
188439
|
-
part.text
|
|
188440
|
-
|
|
188441
|
-
|
|
188442
|
-
|
|
188443
|
-
|
|
188515
|
+
for (const part of msg.parts) {
|
|
188516
|
+
if (part.type !== "text" || part.ignored || part.synthetic)
|
|
188517
|
+
continue;
|
|
188518
|
+
if (!part.text.trim())
|
|
188519
|
+
continue;
|
|
188520
|
+
part.text = [
|
|
188521
|
+
"<system-reminder>",
|
|
188522
|
+
"The user sent the following message:",
|
|
188523
|
+
part.text,
|
|
188524
|
+
"",
|
|
188525
|
+
"Please address this message and continue with your tasks.",
|
|
188526
|
+
"</system-reminder>"
|
|
188527
|
+
].join(`
|
|
188444
188528
|
`);
|
|
188529
|
+
}
|
|
188445
188530
|
}
|
|
188446
188531
|
}
|
|
188447
|
-
|
|
188448
|
-
|
|
188449
|
-
|
|
188450
|
-
const format10 = lastUser.format ?? { type: "text" };
|
|
188451
|
-
if (format10.type === "json_schema") {
|
|
188452
|
-
system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT);
|
|
188453
|
-
}
|
|
188454
|
-
const result6 = await processor.process({
|
|
188455
|
-
user: lastUser,
|
|
188456
|
-
agent,
|
|
188457
|
-
abort: abort2,
|
|
188458
|
-
sessionID,
|
|
188459
|
-
system,
|
|
188460
|
-
messages: [
|
|
188461
|
-
...MessageV2.toModelMessages(msgs, model2),
|
|
188462
|
-
...isLastStep ? [
|
|
188463
|
-
{
|
|
188464
|
-
role: "assistant",
|
|
188465
|
-
content: max_steps_default
|
|
188466
|
-
}
|
|
188467
|
-
] : []
|
|
188468
|
-
],
|
|
188469
|
-
tools,
|
|
188470
|
-
model: model2,
|
|
188471
|
-
toolChoice: format10.type === "json_schema" ? "required" : undefined
|
|
188472
|
-
});
|
|
188473
|
-
if (structuredOutput !== undefined) {
|
|
188474
|
-
processor.message.structured = structuredOutput;
|
|
188475
|
-
processor.message.finish = processor.message.finish ?? "stop";
|
|
188476
|
-
await Session.updateMessage(processor.message);
|
|
188477
|
-
break;
|
|
188478
|
-
}
|
|
188479
|
-
const modelFinished = processor.message.finish && !["tool-calls", "unknown"].includes(processor.message.finish);
|
|
188480
|
-
if (modelFinished && !processor.message.error) {
|
|
188532
|
+
await Plugin.trigger("experimental.chat.messages.transform", {}, { messages: msgs });
|
|
188533
|
+
const system = [...await SystemPrompt.environment(model2), ...await InstructionPrompt.system()];
|
|
188534
|
+
const format10 = lastUser.format ?? { type: "text" };
|
|
188481
188535
|
if (format10.type === "json_schema") {
|
|
188482
|
-
|
|
188483
|
-
message: "Model did not produce structured output",
|
|
188484
|
-
retries: 0
|
|
188485
|
-
}).toObject();
|
|
188486
|
-
await Session.updateMessage(processor.message);
|
|
188487
|
-
break;
|
|
188536
|
+
system.push(STRUCTURED_OUTPUT_SYSTEM_PROMPT);
|
|
188488
188537
|
}
|
|
188489
|
-
|
|
188490
|
-
|
|
188491
|
-
|
|
188492
|
-
|
|
188493
|
-
}
|
|
188494
|
-
if (result6 === "stop")
|
|
188495
|
-
break;
|
|
188496
|
-
if (result6 === "compact") {
|
|
188497
|
-
await SessionCompaction.create({
|
|
188538
|
+
const result6 = await processor.process({
|
|
188539
|
+
user: lastUser,
|
|
188540
|
+
agent,
|
|
188541
|
+
abort: abort2,
|
|
188498
188542
|
sessionID,
|
|
188499
|
-
|
|
188500
|
-
|
|
188501
|
-
|
|
188502
|
-
|
|
188543
|
+
system,
|
|
188544
|
+
messages: [
|
|
188545
|
+
...MessageV2.toModelMessages(msgs, model2),
|
|
188546
|
+
...isLastStep ? [
|
|
188547
|
+
{
|
|
188548
|
+
role: "assistant",
|
|
188549
|
+
content: max_steps_default
|
|
188550
|
+
}
|
|
188551
|
+
] : []
|
|
188552
|
+
],
|
|
188553
|
+
tools,
|
|
188554
|
+
model: model2,
|
|
188555
|
+
toolChoice: format10.type === "json_schema" ? "required" : undefined
|
|
188503
188556
|
});
|
|
188557
|
+
if (structuredOutput !== undefined) {
|
|
188558
|
+
processor.message.structured = structuredOutput;
|
|
188559
|
+
processor.message.finish = processor.message.finish ?? "stop";
|
|
188560
|
+
await Session.updateMessage(processor.message);
|
|
188561
|
+
break;
|
|
188562
|
+
}
|
|
188563
|
+
const modelFinished = processor.message.finish && !["tool-calls", "unknown"].includes(processor.message.finish);
|
|
188564
|
+
if (modelFinished && !processor.message.error) {
|
|
188565
|
+
if (format10.type === "json_schema") {
|
|
188566
|
+
processor.message.error = new MessageV2.StructuredOutputError({
|
|
188567
|
+
message: "Model did not produce structured output",
|
|
188568
|
+
retries: 0
|
|
188569
|
+
}).toObject();
|
|
188570
|
+
await Session.updateMessage(processor.message);
|
|
188571
|
+
break;
|
|
188572
|
+
}
|
|
188573
|
+
}
|
|
188574
|
+
if (held(state4()[sessionID], lastUser?.id)) {
|
|
188575
|
+
next4 = "hold";
|
|
188576
|
+
return;
|
|
188577
|
+
}
|
|
188578
|
+
if (result6 === "stop")
|
|
188579
|
+
break;
|
|
188580
|
+
if (result6 === "compact") {
|
|
188581
|
+
await SessionCompaction.create({
|
|
188582
|
+
sessionID,
|
|
188583
|
+
agent: lastUser.agent,
|
|
188584
|
+
model: lastUser.model,
|
|
188585
|
+
auto: true,
|
|
188586
|
+
overflow: !processor.message.finish
|
|
188587
|
+
});
|
|
188588
|
+
}
|
|
188589
|
+
continue;
|
|
188590
|
+
} catch (_catch3) {
|
|
188591
|
+
var _err = _catch3, _hasErr = 1;
|
|
188592
|
+
} finally {
|
|
188593
|
+
__callDispose(__stack, _err, _hasErr);
|
|
188504
188594
|
}
|
|
188505
|
-
continue;
|
|
188506
188595
|
}
|
|
188507
188596
|
SessionCompaction.prune({ sessionID });
|
|
188508
188597
|
const item = await latestAssistant(sessionID);
|
|
@@ -188577,155 +188666,162 @@ var init_prompt = __esm(async () => {
|
|
|
188577
188666
|
});
|
|
188578
188667
|
}
|
|
188579
188668
|
async function resolveTools(input) {
|
|
188580
|
-
|
|
188581
|
-
|
|
188582
|
-
|
|
188583
|
-
|
|
188584
|
-
|
|
188585
|
-
|
|
188586
|
-
|
|
188587
|
-
|
|
188588
|
-
|
|
188589
|
-
|
|
188590
|
-
|
|
188591
|
-
|
|
188592
|
-
|
|
188593
|
-
|
|
188594
|
-
|
|
188595
|
-
|
|
188596
|
-
|
|
188597
|
-
|
|
188598
|
-
|
|
188599
|
-
|
|
188600
|
-
|
|
188601
|
-
|
|
188669
|
+
let __stack = [];
|
|
188670
|
+
try {
|
|
188671
|
+
const _3 = __using(__stack, log12.time("resolveTools"), 0);
|
|
188672
|
+
const tools = {};
|
|
188673
|
+
const context5 = (args3, options2) => ({
|
|
188674
|
+
sessionID: input.session.id,
|
|
188675
|
+
abort: options2.abortSignal,
|
|
188676
|
+
messageID: input.processor.message.id,
|
|
188677
|
+
callID: options2.toolCallId,
|
|
188678
|
+
extra: { model: input.model, bypassAgentCheck: input.bypassAgentCheck },
|
|
188679
|
+
agent: input.agent.name,
|
|
188680
|
+
messages: input.messages,
|
|
188681
|
+
metadata: async (val) => {
|
|
188682
|
+
const match17 = input.processor.partFromToolCall(options2.toolCallId);
|
|
188683
|
+
if (match17 && match17.state.status === "running") {
|
|
188684
|
+
await Session.updatePart({
|
|
188685
|
+
...match17,
|
|
188686
|
+
state: {
|
|
188687
|
+
title: val.title,
|
|
188688
|
+
metadata: val.metadata,
|
|
188689
|
+
status: "running",
|
|
188690
|
+
input: args3,
|
|
188691
|
+
time: {
|
|
188692
|
+
start: Date.now()
|
|
188693
|
+
}
|
|
188602
188694
|
}
|
|
188603
|
-
}
|
|
188695
|
+
});
|
|
188696
|
+
}
|
|
188697
|
+
},
|
|
188698
|
+
async ask(req) {
|
|
188699
|
+
await PermissionNext.ask({
|
|
188700
|
+
...req,
|
|
188701
|
+
sessionID: input.session.id,
|
|
188702
|
+
tool: { messageID: input.processor.message.id, callID: options2.toolCallId },
|
|
188703
|
+
ruleset: PermissionNext.merge(input.agent.permission, input.session.permission ?? [])
|
|
188604
188704
|
});
|
|
188605
188705
|
}
|
|
188606
|
-
}
|
|
188607
|
-
|
|
188608
|
-
|
|
188609
|
-
|
|
188610
|
-
|
|
188611
|
-
|
|
188612
|
-
|
|
188706
|
+
});
|
|
188707
|
+
for (const item of await ToolRegistry.tools({ modelID: input.model.api.id, providerID: input.model.providerID }, input.agent)) {
|
|
188708
|
+
const schema4 = ProviderTransform.schema(input.model, zod_default.toJSONSchema(item.parameters));
|
|
188709
|
+
tools[item.id] = tool({
|
|
188710
|
+
id: item.id,
|
|
188711
|
+
description: item.description,
|
|
188712
|
+
inputSchema: jsonSchema(schema4),
|
|
188713
|
+
async execute(args3, options2) {
|
|
188714
|
+
const ctx = context5(args3, options2);
|
|
188715
|
+
await abortable(Plugin.trigger("tool.execute.before", {
|
|
188716
|
+
tool: item.id,
|
|
188717
|
+
sessionID: ctx.sessionID,
|
|
188718
|
+
callID: ctx.callID
|
|
188719
|
+
}, {
|
|
188720
|
+
args: args3
|
|
188721
|
+
}), ctx.abort);
|
|
188722
|
+
const result6 = await abortable(item.execute(args3, ctx), ctx.abort);
|
|
188723
|
+
const output2 = {
|
|
188724
|
+
...result6,
|
|
188725
|
+
attachments: result6.attachments?.map((attachment) => ({
|
|
188726
|
+
...attachment,
|
|
188727
|
+
id: Identifier.ascending("part"),
|
|
188728
|
+
sessionID: ctx.sessionID,
|
|
188729
|
+
messageID: input.processor.message.id
|
|
188730
|
+
}))
|
|
188731
|
+
};
|
|
188732
|
+
await abortable(Plugin.trigger("tool.execute.after", {
|
|
188733
|
+
tool: item.id,
|
|
188734
|
+
sessionID: ctx.sessionID,
|
|
188735
|
+
callID: ctx.callID,
|
|
188736
|
+
args: args3
|
|
188737
|
+
}, output2), ctx.abort);
|
|
188738
|
+
return output2;
|
|
188739
|
+
}
|
|
188613
188740
|
});
|
|
188614
188741
|
}
|
|
188615
|
-
|
|
188616
|
-
|
|
188617
|
-
|
|
188618
|
-
|
|
188619
|
-
|
|
188620
|
-
|
|
188621
|
-
|
|
188622
|
-
|
|
188623
|
-
const ctx = context5(args3, options2);
|
|
188742
|
+
for (const [key, item] of Object.entries(await MCP.tools())) {
|
|
188743
|
+
const execute = item.execute;
|
|
188744
|
+
if (!execute)
|
|
188745
|
+
continue;
|
|
188746
|
+
const transformed = ProviderTransform.schema(input.model, asSchema(item.inputSchema).jsonSchema);
|
|
188747
|
+
item.inputSchema = jsonSchema(transformed);
|
|
188748
|
+
item.execute = async (args3, opts) => {
|
|
188749
|
+
const ctx = context5(args3, opts);
|
|
188624
188750
|
await abortable(Plugin.trigger("tool.execute.before", {
|
|
188625
|
-
tool:
|
|
188751
|
+
tool: key,
|
|
188626
188752
|
sessionID: ctx.sessionID,
|
|
188627
|
-
callID:
|
|
188753
|
+
callID: opts.toolCallId
|
|
188628
188754
|
}, {
|
|
188629
188755
|
args: args3
|
|
188630
188756
|
}), ctx.abort);
|
|
188631
|
-
|
|
188632
|
-
|
|
188633
|
-
|
|
188634
|
-
|
|
188635
|
-
|
|
188636
|
-
|
|
188637
|
-
|
|
188638
|
-
messageID: input.processor.message.id
|
|
188639
|
-
}))
|
|
188640
|
-
};
|
|
188757
|
+
await ctx.ask({
|
|
188758
|
+
permission: key,
|
|
188759
|
+
metadata: {},
|
|
188760
|
+
patterns: ["*"],
|
|
188761
|
+
always: ["*"]
|
|
188762
|
+
});
|
|
188763
|
+
const result6 = await abortable(execute(args3, opts), ctx.abort);
|
|
188641
188764
|
await abortable(Plugin.trigger("tool.execute.after", {
|
|
188642
|
-
tool:
|
|
188765
|
+
tool: key,
|
|
188643
188766
|
sessionID: ctx.sessionID,
|
|
188644
|
-
callID:
|
|
188767
|
+
callID: opts.toolCallId,
|
|
188645
188768
|
args: args3
|
|
188646
|
-
},
|
|
188647
|
-
|
|
188648
|
-
|
|
188649
|
-
|
|
188650
|
-
|
|
188651
|
-
|
|
188652
|
-
|
|
188653
|
-
if (!execute)
|
|
188654
|
-
continue;
|
|
188655
|
-
const transformed = ProviderTransform.schema(input.model, asSchema(item.inputSchema).jsonSchema);
|
|
188656
|
-
item.inputSchema = jsonSchema(transformed);
|
|
188657
|
-
item.execute = async (args3, opts) => {
|
|
188658
|
-
const ctx = context5(args3, opts);
|
|
188659
|
-
await abortable(Plugin.trigger("tool.execute.before", {
|
|
188660
|
-
tool: key,
|
|
188661
|
-
sessionID: ctx.sessionID,
|
|
188662
|
-
callID: opts.toolCallId
|
|
188663
|
-
}, {
|
|
188664
|
-
args: args3
|
|
188665
|
-
}), ctx.abort);
|
|
188666
|
-
await ctx.ask({
|
|
188667
|
-
permission: key,
|
|
188668
|
-
metadata: {},
|
|
188669
|
-
patterns: ["*"],
|
|
188670
|
-
always: ["*"]
|
|
188671
|
-
});
|
|
188672
|
-
const result6 = await abortable(execute(args3, opts), ctx.abort);
|
|
188673
|
-
await abortable(Plugin.trigger("tool.execute.after", {
|
|
188674
|
-
tool: key,
|
|
188675
|
-
sessionID: ctx.sessionID,
|
|
188676
|
-
callID: opts.toolCallId,
|
|
188677
|
-
args: args3
|
|
188678
|
-
}, result6), ctx.abort);
|
|
188679
|
-
const textParts = [];
|
|
188680
|
-
const attachments = [];
|
|
188681
|
-
for (const contentItem of result6.content) {
|
|
188682
|
-
if (contentItem.type === "text") {
|
|
188683
|
-
textParts.push(contentItem.text);
|
|
188684
|
-
} else if (contentItem.type === "image") {
|
|
188685
|
-
attachments.push({
|
|
188686
|
-
type: "file",
|
|
188687
|
-
mime: contentItem.mimeType,
|
|
188688
|
-
url: `data:${contentItem.mimeType};base64,${contentItem.data}`
|
|
188689
|
-
});
|
|
188690
|
-
} else if (contentItem.type === "resource") {
|
|
188691
|
-
const { resource } = contentItem;
|
|
188692
|
-
if (resource.text) {
|
|
188693
|
-
textParts.push(resource.text);
|
|
188694
|
-
}
|
|
188695
|
-
if (resource.blob) {
|
|
188769
|
+
}, result6), ctx.abort);
|
|
188770
|
+
const textParts = [];
|
|
188771
|
+
const attachments = [];
|
|
188772
|
+
for (const contentItem of result6.content) {
|
|
188773
|
+
if (contentItem.type === "text") {
|
|
188774
|
+
textParts.push(contentItem.text);
|
|
188775
|
+
} else if (contentItem.type === "image") {
|
|
188696
188776
|
attachments.push({
|
|
188697
188777
|
type: "file",
|
|
188698
|
-
mime:
|
|
188699
|
-
url: `data:${
|
|
188700
|
-
filename: resource.uri
|
|
188778
|
+
mime: contentItem.mimeType,
|
|
188779
|
+
url: `data:${contentItem.mimeType};base64,${contentItem.data}`
|
|
188701
188780
|
});
|
|
188781
|
+
} else if (contentItem.type === "resource") {
|
|
188782
|
+
const { resource } = contentItem;
|
|
188783
|
+
if (resource.text) {
|
|
188784
|
+
textParts.push(resource.text);
|
|
188785
|
+
}
|
|
188786
|
+
if (resource.blob) {
|
|
188787
|
+
attachments.push({
|
|
188788
|
+
type: "file",
|
|
188789
|
+
mime: resource.mimeType ?? "application/octet-stream",
|
|
188790
|
+
url: `data:${resource.mimeType ?? "application/octet-stream"};base64,${resource.blob}`,
|
|
188791
|
+
filename: resource.uri
|
|
188792
|
+
});
|
|
188793
|
+
}
|
|
188702
188794
|
}
|
|
188703
188795
|
}
|
|
188704
|
-
|
|
188705
|
-
const truncated = await Truncate.output(textParts.join(`
|
|
188796
|
+
const truncated = await Truncate.output(textParts.join(`
|
|
188706
188797
|
|
|
188707
188798
|
`), {}, input.agent);
|
|
188708
|
-
|
|
188709
|
-
|
|
188710
|
-
|
|
188711
|
-
|
|
188712
|
-
|
|
188713
|
-
|
|
188714
|
-
|
|
188715
|
-
|
|
188716
|
-
|
|
188717
|
-
|
|
188718
|
-
|
|
188719
|
-
|
|
188720
|
-
|
|
188721
|
-
|
|
188722
|
-
|
|
188723
|
-
|
|
188799
|
+
const metadata2 = {
|
|
188800
|
+
...result6.metadata ?? {},
|
|
188801
|
+
truncated: truncated.truncated,
|
|
188802
|
+
...truncated.truncated && { outputPath: truncated.outputPath }
|
|
188803
|
+
};
|
|
188804
|
+
return {
|
|
188805
|
+
title: "",
|
|
188806
|
+
metadata: metadata2,
|
|
188807
|
+
output: truncated.content,
|
|
188808
|
+
attachments: attachments.map((attachment) => ({
|
|
188809
|
+
...attachment,
|
|
188810
|
+
id: Identifier.ascending("part"),
|
|
188811
|
+
sessionID: ctx.sessionID,
|
|
188812
|
+
messageID: input.processor.message.id
|
|
188813
|
+
})),
|
|
188814
|
+
content: result6.content
|
|
188815
|
+
};
|
|
188724
188816
|
};
|
|
188725
|
-
|
|
188726
|
-
|
|
188817
|
+
tools[key] = item;
|
|
188818
|
+
}
|
|
188819
|
+
return tools;
|
|
188820
|
+
} catch (_catch3) {
|
|
188821
|
+
var _err = _catch3, _hasErr = 1;
|
|
188822
|
+
} finally {
|
|
188823
|
+
__callDispose(__stack, _err, _hasErr);
|
|
188727
188824
|
}
|
|
188728
|
-
return tools;
|
|
188729
188825
|
}
|
|
188730
188826
|
SessionPrompt.resolveTools = resolveTools;
|
|
188731
188827
|
function createStructuredOutputTool(input) {
|
|
@@ -188752,321 +188848,328 @@ var init_prompt = __esm(async () => {
|
|
|
188752
188848
|
}
|
|
188753
188849
|
SessionPrompt.createStructuredOutputTool = createStructuredOutputTool;
|
|
188754
188850
|
async function createUserMessage(input) {
|
|
188755
|
-
|
|
188756
|
-
|
|
188757
|
-
|
|
188758
|
-
|
|
188759
|
-
|
|
188760
|
-
|
|
188761
|
-
|
|
188762
|
-
|
|
188763
|
-
|
|
188764
|
-
|
|
188765
|
-
|
|
188766
|
-
|
|
188767
|
-
|
|
188768
|
-
|
|
188769
|
-
|
|
188770
|
-
|
|
188771
|
-
|
|
188772
|
-
|
|
188773
|
-
|
|
188774
|
-
|
|
188775
|
-
|
|
188776
|
-
|
|
188777
|
-
|
|
188778
|
-
|
|
188779
|
-
|
|
188780
|
-
|
|
188781
|
-
|
|
188782
|
-
|
|
188783
|
-
|
|
188784
|
-
|
|
188785
|
-
|
|
188786
|
-
{
|
|
188787
|
-
|
|
188788
|
-
|
|
188789
|
-
|
|
188790
|
-
|
|
188791
|
-
|
|
188792
|
-
|
|
188793
|
-
|
|
188794
|
-
try {
|
|
188795
|
-
const resourceContent = await MCP.readResource(clientName, uri);
|
|
188796
|
-
if (!resourceContent) {
|
|
188797
|
-
throw new Error(`Resource not found: ${clientName}/${uri}`);
|
|
188798
|
-
}
|
|
188799
|
-
const contents = Array.isArray(resourceContent.contents) ? resourceContent.contents : [resourceContent.contents];
|
|
188800
|
-
for (const content of contents) {
|
|
188801
|
-
if ("text" in content && content.text) {
|
|
188802
|
-
pieces.push({
|
|
188803
|
-
messageID: info4.id,
|
|
188804
|
-
sessionID: input.sessionID,
|
|
188805
|
-
type: "text",
|
|
188806
|
-
synthetic: true,
|
|
188807
|
-
text: content.text
|
|
188808
|
-
});
|
|
188809
|
-
} else if ("blob" in content && content.blob) {
|
|
188810
|
-
const mimeType = "mimeType" in content ? content.mimeType : part.mime;
|
|
188811
|
-
pieces.push({
|
|
188812
|
-
messageID: info4.id,
|
|
188813
|
-
sessionID: input.sessionID,
|
|
188814
|
-
type: "text",
|
|
188815
|
-
synthetic: true,
|
|
188816
|
-
text: `[Binary content: ${mimeType}]`
|
|
188817
|
-
});
|
|
188851
|
+
let __stack = [];
|
|
188852
|
+
try {
|
|
188853
|
+
const agent = await Agent.get(input.agent ?? await Agent.defaultAgent());
|
|
188854
|
+
const model2 = input.model ?? agent.model ?? await lastModel(input.sessionID);
|
|
188855
|
+
const full = !input.variant && agent.variant ? await Provider2.getModel(model2.providerID, model2.modelID).catch(() => {
|
|
188856
|
+
return;
|
|
188857
|
+
}) : undefined;
|
|
188858
|
+
const variant = input.variant ?? (agent.variant && full?.variants?.[agent.variant] ? agent.variant : undefined);
|
|
188859
|
+
const info4 = {
|
|
188860
|
+
id: input.messageID ?? Identifier.ascending("message"),
|
|
188861
|
+
role: "user",
|
|
188862
|
+
sessionID: input.sessionID,
|
|
188863
|
+
time: {
|
|
188864
|
+
created: Date.now()
|
|
188865
|
+
},
|
|
188866
|
+
tools: input.tools,
|
|
188867
|
+
agent: agent.name,
|
|
188868
|
+
model: model2,
|
|
188869
|
+
system: input.system,
|
|
188870
|
+
format: input.format,
|
|
188871
|
+
variant
|
|
188872
|
+
};
|
|
188873
|
+
const _3 = __using(__stack, defer(() => InstructionPrompt.clear(info4.id)), 0);
|
|
188874
|
+
const assign2 = (part) => ({
|
|
188875
|
+
...part,
|
|
188876
|
+
id: part.id ?? Identifier.ascending("part")
|
|
188877
|
+
});
|
|
188878
|
+
const parts3 = await Promise.all(input.parts.map(async (part) => {
|
|
188879
|
+
if (part.type === "file") {
|
|
188880
|
+
if (part.source?.type === "resource") {
|
|
188881
|
+
const { clientName, uri } = part.source;
|
|
188882
|
+
log12.info("mcp resource", { clientName, uri, mime: part.mime });
|
|
188883
|
+
const pieces = [
|
|
188884
|
+
{
|
|
188885
|
+
messageID: info4.id,
|
|
188886
|
+
sessionID: input.sessionID,
|
|
188887
|
+
type: "text",
|
|
188888
|
+
synthetic: true,
|
|
188889
|
+
text: `Reading MCP resource: ${part.filename} (${uri})`
|
|
188818
188890
|
}
|
|
188819
|
-
|
|
188820
|
-
|
|
188821
|
-
|
|
188822
|
-
|
|
188823
|
-
|
|
188824
|
-
|
|
188825
|
-
|
|
188826
|
-
|
|
188827
|
-
|
|
188828
|
-
|
|
188829
|
-
|
|
188830
|
-
|
|
188831
|
-
|
|
188832
|
-
|
|
188833
|
-
|
|
188834
|
-
|
|
188835
|
-
|
|
188836
|
-
|
|
188837
|
-
|
|
188838
|
-
|
|
188839
|
-
|
|
188840
|
-
|
|
188841
|
-
|
|
188842
|
-
|
|
188843
|
-
|
|
188844
|
-
messageID: info4.id,
|
|
188845
|
-
sessionID: input.sessionID,
|
|
188846
|
-
type: "text",
|
|
188847
|
-
synthetic: true,
|
|
188848
|
-
text: `Called the Read tool with the following input: ${JSON.stringify({ filePath: part.filename })}`
|
|
188849
|
-
},
|
|
188850
|
-
{
|
|
188851
|
-
messageID: info4.id,
|
|
188852
|
-
sessionID: input.sessionID,
|
|
188853
|
-
type: "text",
|
|
188854
|
-
synthetic: true,
|
|
188855
|
-
text: Buffer.from(part.url, "base64url").toString()
|
|
188856
|
-
},
|
|
188857
|
-
{
|
|
188858
|
-
...part,
|
|
188859
|
-
messageID: info4.id,
|
|
188860
|
-
sessionID: input.sessionID
|
|
188891
|
+
];
|
|
188892
|
+
try {
|
|
188893
|
+
const resourceContent = await MCP.readResource(clientName, uri);
|
|
188894
|
+
if (!resourceContent) {
|
|
188895
|
+
throw new Error(`Resource not found: ${clientName}/${uri}`);
|
|
188896
|
+
}
|
|
188897
|
+
const contents = Array.isArray(resourceContent.contents) ? resourceContent.contents : [resourceContent.contents];
|
|
188898
|
+
for (const content of contents) {
|
|
188899
|
+
if ("text" in content && content.text) {
|
|
188900
|
+
pieces.push({
|
|
188901
|
+
messageID: info4.id,
|
|
188902
|
+
sessionID: input.sessionID,
|
|
188903
|
+
type: "text",
|
|
188904
|
+
synthetic: true,
|
|
188905
|
+
text: content.text
|
|
188906
|
+
});
|
|
188907
|
+
} else if ("blob" in content && content.blob) {
|
|
188908
|
+
const mimeType = "mimeType" in content ? content.mimeType : part.mime;
|
|
188909
|
+
pieces.push({
|
|
188910
|
+
messageID: info4.id,
|
|
188911
|
+
sessionID: input.sessionID,
|
|
188912
|
+
type: "text",
|
|
188913
|
+
synthetic: true,
|
|
188914
|
+
text: `[Binary content: ${mimeType}]`
|
|
188915
|
+
});
|
|
188861
188916
|
}
|
|
188862
|
-
|
|
188863
|
-
|
|
188864
|
-
|
|
188865
|
-
|
|
188866
|
-
|
|
188867
|
-
|
|
188868
|
-
|
|
188869
|
-
|
|
188870
|
-
|
|
188917
|
+
}
|
|
188918
|
+
pieces.push({
|
|
188919
|
+
...part,
|
|
188920
|
+
messageID: info4.id,
|
|
188921
|
+
sessionID: input.sessionID
|
|
188922
|
+
});
|
|
188923
|
+
} catch (error46) {
|
|
188924
|
+
log12.error("failed to read MCP resource", { error: error46, clientName, uri });
|
|
188925
|
+
const message = error46 instanceof Error ? error46.message : String(error46);
|
|
188926
|
+
pieces.push({
|
|
188927
|
+
messageID: info4.id,
|
|
188928
|
+
sessionID: input.sessionID,
|
|
188929
|
+
type: "text",
|
|
188930
|
+
synthetic: true,
|
|
188931
|
+
text: `Failed to read MCP resource ${part.filename}: ${message}`
|
|
188932
|
+
});
|
|
188871
188933
|
}
|
|
188872
|
-
|
|
188873
|
-
|
|
188874
|
-
|
|
188875
|
-
|
|
188876
|
-
|
|
188877
|
-
|
|
188878
|
-
|
|
188879
|
-
|
|
188880
|
-
|
|
188881
|
-
|
|
188882
|
-
|
|
188883
|
-
|
|
188884
|
-
|
|
188885
|
-
|
|
188886
|
-
|
|
188887
|
-
|
|
188888
|
-
|
|
188889
|
-
|
|
188890
|
-
|
|
188891
|
-
|
|
188892
|
-
|
|
188893
|
-
|
|
188894
|
-
|
|
188895
|
-
|
|
188934
|
+
return pieces;
|
|
188935
|
+
}
|
|
188936
|
+
const url4 = new URL(part.url);
|
|
188937
|
+
switch (url4.protocol) {
|
|
188938
|
+
case "data:":
|
|
188939
|
+
if (part.mime === "text/plain") {
|
|
188940
|
+
return [
|
|
188941
|
+
{
|
|
188942
|
+
messageID: info4.id,
|
|
188943
|
+
sessionID: input.sessionID,
|
|
188944
|
+
type: "text",
|
|
188945
|
+
synthetic: true,
|
|
188946
|
+
text: `Called the Read tool with the following input: ${JSON.stringify({ filePath: part.filename })}`
|
|
188947
|
+
},
|
|
188948
|
+
{
|
|
188949
|
+
messageID: info4.id,
|
|
188950
|
+
sessionID: input.sessionID,
|
|
188951
|
+
type: "text",
|
|
188952
|
+
synthetic: true,
|
|
188953
|
+
text: Buffer.from(part.url, "base64url").toString()
|
|
188954
|
+
},
|
|
188955
|
+
{
|
|
188956
|
+
...part,
|
|
188957
|
+
messageID: info4.id,
|
|
188958
|
+
sessionID: input.sessionID
|
|
188959
|
+
}
|
|
188960
|
+
];
|
|
188961
|
+
}
|
|
188962
|
+
break;
|
|
188963
|
+
case "file:":
|
|
188964
|
+
log12.info("file", { mime: part.mime });
|
|
188965
|
+
const filepath = fileURLToPath7(part.url);
|
|
188966
|
+
const s6 = Filesystem.stat(filepath);
|
|
188967
|
+
if (s6?.isDirectory()) {
|
|
188968
|
+
part.mime = "application/x-directory";
|
|
188969
|
+
}
|
|
188970
|
+
if (part.mime === "text/plain") {
|
|
188971
|
+
let offset = undefined;
|
|
188972
|
+
let limit = undefined;
|
|
188973
|
+
const range6 = {
|
|
188974
|
+
start: url4.searchParams.get("start"),
|
|
188975
|
+
end: url4.searchParams.get("end")
|
|
188976
|
+
};
|
|
188977
|
+
if (range6.start != null) {
|
|
188978
|
+
const filePathURI = part.url.split("?")[0];
|
|
188979
|
+
let start4 = parseInt(range6.start);
|
|
188980
|
+
let end4 = range6.end ? parseInt(range6.end) : undefined;
|
|
188981
|
+
if (start4 === end4) {
|
|
188982
|
+
const symbols = await LSP.documentSymbol(filePathURI).catch(() => []);
|
|
188983
|
+
for (const symbol16 of symbols) {
|
|
188984
|
+
let range7;
|
|
188985
|
+
if ("range" in symbol16) {
|
|
188986
|
+
range7 = symbol16.range;
|
|
188987
|
+
} else if ("location" in symbol16) {
|
|
188988
|
+
range7 = symbol16.location.range;
|
|
188989
|
+
}
|
|
188990
|
+
if (range7?.start?.line && range7?.start?.line === start4) {
|
|
188991
|
+
start4 = range7.start.line;
|
|
188992
|
+
end4 = range7?.end?.line ?? start4;
|
|
188993
|
+
break;
|
|
188994
|
+
}
|
|
188896
188995
|
}
|
|
188897
188996
|
}
|
|
188997
|
+
offset = Math.max(start4, 1);
|
|
188998
|
+
if (end4) {
|
|
188999
|
+
limit = end4 - (offset - 1);
|
|
189000
|
+
}
|
|
188898
189001
|
}
|
|
188899
|
-
|
|
188900
|
-
|
|
188901
|
-
|
|
188902
|
-
|
|
189002
|
+
const args3 = { filePath: filepath, offset, limit };
|
|
189003
|
+
const pieces = [
|
|
189004
|
+
{
|
|
189005
|
+
messageID: info4.id,
|
|
189006
|
+
sessionID: input.sessionID,
|
|
189007
|
+
type: "text",
|
|
189008
|
+
synthetic: true,
|
|
189009
|
+
text: `Called the Read tool with the following input: ${JSON.stringify(args3)}`
|
|
189010
|
+
}
|
|
189011
|
+
];
|
|
189012
|
+
await ReadTool.init().then(async (t3) => {
|
|
189013
|
+
const model3 = await Provider2.getModel(info4.model.providerID, info4.model.modelID);
|
|
189014
|
+
const readCtx = {
|
|
189015
|
+
sessionID: input.sessionID,
|
|
189016
|
+
abort: new AbortController().signal,
|
|
189017
|
+
agent: input.agent,
|
|
189018
|
+
messageID: info4.id,
|
|
189019
|
+
extra: { bypassCwdCheck: true, model: model3 },
|
|
189020
|
+
messages: [],
|
|
189021
|
+
metadata: async () => {},
|
|
189022
|
+
ask: async () => {}
|
|
189023
|
+
};
|
|
189024
|
+
const result6 = await t3.execute(args3, readCtx);
|
|
189025
|
+
pieces.push({
|
|
189026
|
+
messageID: info4.id,
|
|
189027
|
+
sessionID: input.sessionID,
|
|
189028
|
+
type: "text",
|
|
189029
|
+
synthetic: true,
|
|
189030
|
+
text: result6.output
|
|
189031
|
+
});
|
|
189032
|
+
if (result6.attachments?.length) {
|
|
189033
|
+
pieces.push(...result6.attachments.map((attachment) => ({
|
|
189034
|
+
...attachment,
|
|
189035
|
+
synthetic: true,
|
|
189036
|
+
filename: attachment.filename ?? part.filename,
|
|
189037
|
+
messageID: info4.id,
|
|
189038
|
+
sessionID: input.sessionID
|
|
189039
|
+
})));
|
|
189040
|
+
} else {
|
|
189041
|
+
pieces.push({
|
|
189042
|
+
...part,
|
|
189043
|
+
messageID: info4.id,
|
|
189044
|
+
sessionID: input.sessionID
|
|
189045
|
+
});
|
|
189046
|
+
}
|
|
189047
|
+
}).catch((error46) => {
|
|
189048
|
+
log12.error("failed to read file", { error: error46 });
|
|
189049
|
+
const message = error46 instanceof Error ? error46.message : error46.toString();
|
|
189050
|
+
Bus.publish(Session.Event.Error, {
|
|
189051
|
+
sessionID: input.sessionID,
|
|
189052
|
+
error: new NamedError.Unknown({
|
|
189053
|
+
message
|
|
189054
|
+
}).toObject(),
|
|
189055
|
+
viewID: Instance.viewID
|
|
189056
|
+
});
|
|
189057
|
+
pieces.push({
|
|
189058
|
+
messageID: info4.id,
|
|
189059
|
+
sessionID: input.sessionID,
|
|
189060
|
+
type: "text",
|
|
189061
|
+
synthetic: true,
|
|
189062
|
+
text: `Read tool failed to read ${filepath} with the following error: ${message}`
|
|
189063
|
+
});
|
|
189064
|
+
});
|
|
189065
|
+
return pieces;
|
|
188903
189066
|
}
|
|
188904
|
-
|
|
188905
|
-
|
|
188906
|
-
{
|
|
188907
|
-
messageID: info4.id,
|
|
188908
|
-
sessionID: input.sessionID,
|
|
188909
|
-
type: "text",
|
|
188910
|
-
synthetic: true,
|
|
188911
|
-
text: `Called the Read tool with the following input: ${JSON.stringify(args3)}`
|
|
188912
|
-
}
|
|
188913
|
-
];
|
|
188914
|
-
await ReadTool.init().then(async (t3) => {
|
|
188915
|
-
const model3 = await Provider2.getModel(info4.model.providerID, info4.model.modelID);
|
|
188916
|
-
const readCtx = {
|
|
189067
|
+
if (part.mime === "application/x-directory") {
|
|
189068
|
+
const args3 = { filePath: filepath };
|
|
189069
|
+
const listCtx = {
|
|
188917
189070
|
sessionID: input.sessionID,
|
|
188918
189071
|
abort: new AbortController().signal,
|
|
188919
189072
|
agent: input.agent,
|
|
188920
189073
|
messageID: info4.id,
|
|
188921
|
-
extra: { bypassCwdCheck: true
|
|
189074
|
+
extra: { bypassCwdCheck: true },
|
|
188922
189075
|
messages: [],
|
|
188923
189076
|
metadata: async () => {},
|
|
188924
189077
|
ask: async () => {}
|
|
188925
189078
|
};
|
|
188926
|
-
const result6 = await t3.execute(args3,
|
|
188927
|
-
|
|
188928
|
-
|
|
188929
|
-
|
|
188930
|
-
|
|
188931
|
-
|
|
188932
|
-
text: result6.output
|
|
188933
|
-
});
|
|
188934
|
-
if (result6.attachments?.length) {
|
|
188935
|
-
pieces.push(...result6.attachments.map((attachment) => ({
|
|
188936
|
-
...attachment,
|
|
189079
|
+
const result6 = await ReadTool.init().then((t3) => t3.execute(args3, listCtx));
|
|
189080
|
+
return [
|
|
189081
|
+
{
|
|
189082
|
+
messageID: info4.id,
|
|
189083
|
+
sessionID: input.sessionID,
|
|
189084
|
+
type: "text",
|
|
188937
189085
|
synthetic: true,
|
|
188938
|
-
|
|
189086
|
+
text: `Called the Read tool with the following input: ${JSON.stringify(args3)}`
|
|
189087
|
+
},
|
|
189088
|
+
{
|
|
188939
189089
|
messageID: info4.id,
|
|
188940
|
-
sessionID: input.sessionID
|
|
188941
|
-
|
|
188942
|
-
|
|
188943
|
-
|
|
189090
|
+
sessionID: input.sessionID,
|
|
189091
|
+
type: "text",
|
|
189092
|
+
synthetic: true,
|
|
189093
|
+
text: result6.output
|
|
189094
|
+
},
|
|
189095
|
+
{
|
|
188944
189096
|
...part,
|
|
188945
189097
|
messageID: info4.id,
|
|
188946
189098
|
sessionID: input.sessionID
|
|
188947
|
-
}
|
|
188948
|
-
|
|
188949
|
-
}
|
|
188950
|
-
|
|
188951
|
-
const message = error46 instanceof Error ? error46.message : error46.toString();
|
|
188952
|
-
Bus.publish(Session.Event.Error, {
|
|
188953
|
-
sessionID: input.sessionID,
|
|
188954
|
-
error: new NamedError.Unknown({
|
|
188955
|
-
message
|
|
188956
|
-
}).toObject(),
|
|
188957
|
-
viewID: Instance.viewID
|
|
188958
|
-
});
|
|
188959
|
-
pieces.push({
|
|
188960
|
-
messageID: info4.id,
|
|
188961
|
-
sessionID: input.sessionID,
|
|
188962
|
-
type: "text",
|
|
188963
|
-
synthetic: true,
|
|
188964
|
-
text: `Read tool failed to read ${filepath} with the following error: ${message}`
|
|
188965
|
-
});
|
|
188966
|
-
});
|
|
188967
|
-
return pieces;
|
|
188968
|
-
}
|
|
188969
|
-
if (part.mime === "application/x-directory") {
|
|
188970
|
-
const args3 = { filePath: filepath };
|
|
188971
|
-
const listCtx = {
|
|
188972
|
-
sessionID: input.sessionID,
|
|
188973
|
-
abort: new AbortController().signal,
|
|
188974
|
-
agent: input.agent,
|
|
188975
|
-
messageID: info4.id,
|
|
188976
|
-
extra: { bypassCwdCheck: true },
|
|
188977
|
-
messages: [],
|
|
188978
|
-
metadata: async () => {},
|
|
188979
|
-
ask: async () => {}
|
|
188980
|
-
};
|
|
188981
|
-
const result6 = await ReadTool.init().then((t3) => t3.execute(args3, listCtx));
|
|
189099
|
+
}
|
|
189100
|
+
];
|
|
189101
|
+
}
|
|
189102
|
+
FileTime.read(input.sessionID, filepath);
|
|
188982
189103
|
return [
|
|
188983
189104
|
{
|
|
188984
189105
|
messageID: info4.id,
|
|
188985
189106
|
sessionID: input.sessionID,
|
|
188986
189107
|
type: "text",
|
|
188987
|
-
|
|
188988
|
-
|
|
189108
|
+
text: `Called the Read tool with the following input: {"filePath":"${filepath}"}`,
|
|
189109
|
+
synthetic: true
|
|
188989
189110
|
},
|
|
188990
189111
|
{
|
|
189112
|
+
id: part.id,
|
|
188991
189113
|
messageID: info4.id,
|
|
188992
189114
|
sessionID: input.sessionID,
|
|
188993
|
-
type: "
|
|
188994
|
-
|
|
188995
|
-
|
|
188996
|
-
|
|
188997
|
-
|
|
188998
|
-
...part,
|
|
188999
|
-
messageID: info4.id,
|
|
189000
|
-
sessionID: input.sessionID
|
|
189115
|
+
type: "file",
|
|
189116
|
+
url: `data:${part.mime};base64,` + (await Filesystem.readBytes(filepath)).toString("base64"),
|
|
189117
|
+
mime: part.mime,
|
|
189118
|
+
filename: part.filename,
|
|
189119
|
+
source: part.source
|
|
189001
189120
|
}
|
|
189002
189121
|
];
|
|
189122
|
+
}
|
|
189123
|
+
}
|
|
189124
|
+
if (part.type === "agent") {
|
|
189125
|
+
const perm = PermissionNext.evaluate("task", part.name, agent.permission);
|
|
189126
|
+
const hint = perm.action === "deny" ? " . Invoked by user; guaranteed to exist." : "";
|
|
189127
|
+
return [
|
|
189128
|
+
{
|
|
189129
|
+
...part,
|
|
189130
|
+
messageID: info4.id,
|
|
189131
|
+
sessionID: input.sessionID
|
|
189132
|
+
},
|
|
189133
|
+
{
|
|
189134
|
+
messageID: info4.id,
|
|
189135
|
+
sessionID: input.sessionID,
|
|
189136
|
+
type: "text",
|
|
189137
|
+
synthetic: true,
|
|
189138
|
+
text: " Use the above message and context to generate a prompt and call the task tool with subagent: " + part.name + hint
|
|
189003
189139
|
}
|
|
189004
|
-
|
|
189005
|
-
return [
|
|
189006
|
-
{
|
|
189007
|
-
messageID: info4.id,
|
|
189008
|
-
sessionID: input.sessionID,
|
|
189009
|
-
type: "text",
|
|
189010
|
-
text: `Called the Read tool with the following input: {"filePath":"${filepath}"}`,
|
|
189011
|
-
synthetic: true
|
|
189012
|
-
},
|
|
189013
|
-
{
|
|
189014
|
-
id: part.id,
|
|
189015
|
-
messageID: info4.id,
|
|
189016
|
-
sessionID: input.sessionID,
|
|
189017
|
-
type: "file",
|
|
189018
|
-
url: `data:${part.mime};base64,` + (await Filesystem.readBytes(filepath)).toString("base64"),
|
|
189019
|
-
mime: part.mime,
|
|
189020
|
-
filename: part.filename,
|
|
189021
|
-
source: part.source
|
|
189022
|
-
}
|
|
189023
|
-
];
|
|
189140
|
+
];
|
|
189024
189141
|
}
|
|
189025
|
-
}
|
|
189026
|
-
if (part.type === "agent") {
|
|
189027
|
-
const perm = PermissionNext.evaluate("task", part.name, agent.permission);
|
|
189028
|
-
const hint = perm.action === "deny" ? " . Invoked by user; guaranteed to exist." : "";
|
|
189029
189142
|
return [
|
|
189030
189143
|
{
|
|
189031
189144
|
...part,
|
|
189032
189145
|
messageID: info4.id,
|
|
189033
189146
|
sessionID: input.sessionID
|
|
189034
|
-
},
|
|
189035
|
-
{
|
|
189036
|
-
messageID: info4.id,
|
|
189037
|
-
sessionID: input.sessionID,
|
|
189038
|
-
type: "text",
|
|
189039
|
-
synthetic: true,
|
|
189040
|
-
text: " Use the above message and context to generate a prompt and call the task tool with subagent: " + part.name + hint
|
|
189041
189147
|
}
|
|
189042
189148
|
];
|
|
189149
|
+
})).then((x3) => x3.flat().map(assign2));
|
|
189150
|
+
await Plugin.trigger("chat.message", {
|
|
189151
|
+
sessionID: input.sessionID,
|
|
189152
|
+
agent: input.agent,
|
|
189153
|
+
model: input.model,
|
|
189154
|
+
messageID: input.messageID,
|
|
189155
|
+
variant: input.variant
|
|
189156
|
+
}, {
|
|
189157
|
+
message: info4,
|
|
189158
|
+
parts: parts3
|
|
189159
|
+
});
|
|
189160
|
+
await Session.updateMessage(info4);
|
|
189161
|
+
for (const part of parts3) {
|
|
189162
|
+
await Session.updatePart(part);
|
|
189043
189163
|
}
|
|
189044
|
-
return
|
|
189045
|
-
|
|
189046
|
-
|
|
189047
|
-
|
|
189048
|
-
|
|
189049
|
-
|
|
189050
|
-
|
|
189051
|
-
|
|
189052
|
-
await Plugin.trigger("chat.message", {
|
|
189053
|
-
sessionID: input.sessionID,
|
|
189054
|
-
agent: input.agent,
|
|
189055
|
-
model: input.model,
|
|
189056
|
-
messageID: input.messageID,
|
|
189057
|
-
variant: input.variant
|
|
189058
|
-
}, {
|
|
189059
|
-
message: info4,
|
|
189060
|
-
parts: parts3
|
|
189061
|
-
});
|
|
189062
|
-
await Session.updateMessage(info4);
|
|
189063
|
-
for (const part of parts3) {
|
|
189064
|
-
await Session.updatePart(part);
|
|
189164
|
+
return {
|
|
189165
|
+
info: info4,
|
|
189166
|
+
parts: parts3
|
|
189167
|
+
};
|
|
189168
|
+
} catch (_catch3) {
|
|
189169
|
+
var _err = _catch3, _hasErr = 1;
|
|
189170
|
+
} finally {
|
|
189171
|
+
__callDispose(__stack, _err, _hasErr);
|
|
189065
189172
|
}
|
|
189066
|
-
return {
|
|
189067
|
-
info: info4,
|
|
189068
|
-
parts: parts3
|
|
189069
|
-
};
|
|
189070
189173
|
}
|
|
189071
189174
|
async function insertReminders(input) {
|
|
189072
189175
|
const userMessage = input.messages.findLast((msg) => msg.info.role === "user");
|
|
@@ -189223,279 +189326,286 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
|
|
189223
189326
|
command: zod_default.string()
|
|
189224
189327
|
});
|
|
189225
189328
|
async function shell(input) {
|
|
189226
|
-
|
|
189227
|
-
|
|
189228
|
-
|
|
189229
|
-
|
|
189230
|
-
|
|
189231
|
-
|
|
189232
|
-
const
|
|
189233
|
-
|
|
189234
|
-
|
|
189235
|
-
|
|
189236
|
-
|
|
189237
|
-
|
|
189238
|
-
|
|
189239
|
-
|
|
189329
|
+
let __stack = [];
|
|
189330
|
+
try {
|
|
189331
|
+
const abort2 = start3(input.sessionID);
|
|
189332
|
+
if (!abort2) {
|
|
189333
|
+
throw new Session.BusyError(input.sessionID);
|
|
189334
|
+
}
|
|
189335
|
+
const _3 = __using(__stack, defer(() => {
|
|
189336
|
+
const entry = state4()[input.sessionID];
|
|
189337
|
+
const hasQueuedWork = !!entry && (entry.callbacks.length > 0 || entry.queued.length > 0);
|
|
189338
|
+
if (!hasQueuedWork) {
|
|
189339
|
+
cancel(input.sessionID);
|
|
189340
|
+
} else {
|
|
189341
|
+
SessionPrompt.loop({ sessionID: input.sessionID, resume_existing: true }).catch((error47) => {
|
|
189342
|
+
log12.error("session loop failed to resume after shell command", { sessionID: input.sessionID, error: error47 });
|
|
189343
|
+
cancel(input.sessionID, error47);
|
|
189344
|
+
});
|
|
189345
|
+
}
|
|
189346
|
+
}), 0);
|
|
189347
|
+
const session = await Session.get(input.sessionID);
|
|
189348
|
+
if (session.revert) {
|
|
189349
|
+
await SessionRevert.cleanup(session);
|
|
189240
189350
|
}
|
|
189241
|
-
|
|
189242
|
-
|
|
189243
|
-
|
|
189244
|
-
|
|
189245
|
-
|
|
189246
|
-
|
|
189247
|
-
|
|
189248
|
-
|
|
189249
|
-
|
|
189250
|
-
|
|
189251
|
-
|
|
189252
|
-
|
|
189253
|
-
|
|
189254
|
-
|
|
189255
|
-
|
|
189256
|
-
|
|
189351
|
+
const agent = await Agent.get(input.agent);
|
|
189352
|
+
const model2 = input.model ?? agent.model ?? await lastModel(input.sessionID);
|
|
189353
|
+
const userMsg = {
|
|
189354
|
+
id: Identifier.ascending("message"),
|
|
189355
|
+
sessionID: input.sessionID,
|
|
189356
|
+
time: {
|
|
189357
|
+
created: Date.now()
|
|
189358
|
+
},
|
|
189359
|
+
role: "user",
|
|
189360
|
+
agent: input.agent,
|
|
189361
|
+
model: {
|
|
189362
|
+
providerID: model2.providerID,
|
|
189363
|
+
modelID: model2.modelID
|
|
189364
|
+
}
|
|
189365
|
+
};
|
|
189366
|
+
await Session.updateMessage(userMsg);
|
|
189367
|
+
const userPart = {
|
|
189368
|
+
type: "text",
|
|
189369
|
+
id: Identifier.ascending("part"),
|
|
189370
|
+
messageID: userMsg.id,
|
|
189371
|
+
sessionID: input.sessionID,
|
|
189372
|
+
text: "The following tool was executed by the user",
|
|
189373
|
+
synthetic: true
|
|
189374
|
+
};
|
|
189375
|
+
await Session.updatePart(userPart);
|
|
189376
|
+
queueTitle({
|
|
189377
|
+
sessionID: input.sessionID,
|
|
189257
189378
|
providerID: model2.providerID,
|
|
189258
|
-
modelID: model2.modelID
|
|
189259
|
-
|
|
189260
|
-
|
|
189261
|
-
|
|
189262
|
-
|
|
189263
|
-
|
|
189264
|
-
|
|
189265
|
-
|
|
189266
|
-
|
|
189267
|
-
|
|
189268
|
-
|
|
189269
|
-
|
|
189270
|
-
|
|
189271
|
-
|
|
189272
|
-
sessionID: input.sessionID,
|
|
189273
|
-
providerID: model2.providerID,
|
|
189274
|
-
modelID: model2.modelID,
|
|
189275
|
-
text: input.command
|
|
189276
|
-
});
|
|
189277
|
-
const msg = {
|
|
189278
|
-
id: Identifier.ascending("message"),
|
|
189279
|
-
sessionID: input.sessionID,
|
|
189280
|
-
parentID: userMsg.id,
|
|
189281
|
-
mode: input.agent,
|
|
189282
|
-
agent: input.agent,
|
|
189283
|
-
cost: 0,
|
|
189284
|
-
path: {
|
|
189285
|
-
cwd: Instance.directory,
|
|
189286
|
-
root: Instance.worktree
|
|
189287
|
-
},
|
|
189288
|
-
time: {
|
|
189289
|
-
created: Date.now()
|
|
189290
|
-
},
|
|
189291
|
-
role: "assistant",
|
|
189292
|
-
tokens: {
|
|
189293
|
-
input: 0,
|
|
189294
|
-
output: 0,
|
|
189295
|
-
reasoning: 0,
|
|
189296
|
-
cache: { read: 0, write: 0 }
|
|
189297
|
-
},
|
|
189298
|
-
modelID: model2.modelID,
|
|
189299
|
-
providerID: model2.providerID
|
|
189300
|
-
};
|
|
189301
|
-
await Session.updateMessage(msg);
|
|
189302
|
-
const part = {
|
|
189303
|
-
type: "tool",
|
|
189304
|
-
id: Identifier.ascending("part"),
|
|
189305
|
-
messageID: msg.id,
|
|
189306
|
-
sessionID: input.sessionID,
|
|
189307
|
-
tool: "bash",
|
|
189308
|
-
callID: ulid4(),
|
|
189309
|
-
state: {
|
|
189310
|
-
status: "running",
|
|
189379
|
+
modelID: model2.modelID,
|
|
189380
|
+
text: input.command
|
|
189381
|
+
});
|
|
189382
|
+
const msg = {
|
|
189383
|
+
id: Identifier.ascending("message"),
|
|
189384
|
+
sessionID: input.sessionID,
|
|
189385
|
+
parentID: userMsg.id,
|
|
189386
|
+
mode: input.agent,
|
|
189387
|
+
agent: input.agent,
|
|
189388
|
+
cost: 0,
|
|
189389
|
+
path: {
|
|
189390
|
+
cwd: Instance.directory,
|
|
189391
|
+
root: Instance.worktree
|
|
189392
|
+
},
|
|
189311
189393
|
time: {
|
|
189312
|
-
|
|
189394
|
+
created: Date.now()
|
|
189313
189395
|
},
|
|
189314
|
-
|
|
189315
|
-
|
|
189396
|
+
role: "assistant",
|
|
189397
|
+
tokens: {
|
|
189398
|
+
input: 0,
|
|
189399
|
+
output: 0,
|
|
189400
|
+
reasoning: 0,
|
|
189401
|
+
cache: { read: 0, write: 0 }
|
|
189402
|
+
},
|
|
189403
|
+
modelID: model2.modelID,
|
|
189404
|
+
providerID: model2.providerID
|
|
189405
|
+
};
|
|
189406
|
+
await Session.updateMessage(msg);
|
|
189407
|
+
const part = {
|
|
189408
|
+
type: "tool",
|
|
189409
|
+
id: Identifier.ascending("part"),
|
|
189410
|
+
messageID: msg.id,
|
|
189411
|
+
sessionID: input.sessionID,
|
|
189412
|
+
tool: "bash",
|
|
189413
|
+
callID: ulid4(),
|
|
189414
|
+
state: {
|
|
189415
|
+
status: "running",
|
|
189416
|
+
time: {
|
|
189417
|
+
start: Date.now()
|
|
189418
|
+
},
|
|
189419
|
+
input: {
|
|
189420
|
+
command: input.command
|
|
189421
|
+
}
|
|
189316
189422
|
}
|
|
189317
|
-
}
|
|
189318
|
-
|
|
189319
|
-
|
|
189320
|
-
|
|
189321
|
-
|
|
189322
|
-
|
|
189323
|
-
|
|
189324
|
-
|
|
189325
|
-
|
|
189326
|
-
|
|
189327
|
-
|
|
189328
|
-
|
|
189329
|
-
|
|
189330
|
-
|
|
189331
|
-
|
|
189332
|
-
|
|
189333
|
-
|
|
189334
|
-
`
|
|
189423
|
+
};
|
|
189424
|
+
await Session.updatePart(part);
|
|
189425
|
+
const cfg = await Config.get();
|
|
189426
|
+
const shell2 = Shell.preferred(cfg.shell?.program);
|
|
189427
|
+
const shellName = Shell.name(shell2);
|
|
189428
|
+
const invocations = {
|
|
189429
|
+
nu: {
|
|
189430
|
+
args: ["-c", input.command]
|
|
189431
|
+
},
|
|
189432
|
+
fish: {
|
|
189433
|
+
args: ["-c", input.command]
|
|
189434
|
+
},
|
|
189435
|
+
zsh: {
|
|
189436
|
+
args: [
|
|
189437
|
+
"-c",
|
|
189438
|
+
"-l",
|
|
189439
|
+
`
|
|
189335
189440
|
[[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
|
|
189336
189441
|
[[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
|
|
189337
189442
|
eval ${JSON.stringify(input.command)}
|
|
189338
189443
|
`
|
|
189339
|
-
|
|
189340
|
-
|
|
189341
|
-
|
|
189342
|
-
|
|
189343
|
-
|
|
189344
|
-
|
|
189345
|
-
|
|
189444
|
+
]
|
|
189445
|
+
},
|
|
189446
|
+
bash: {
|
|
189447
|
+
args: [
|
|
189448
|
+
"-c",
|
|
189449
|
+
"-l",
|
|
189450
|
+
`
|
|
189346
189451
|
shopt -s expand_aliases
|
|
189347
189452
|
[[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
|
|
189348
189453
|
eval ${JSON.stringify(input.command)}
|
|
189349
189454
|
`
|
|
189350
|
-
|
|
189351
|
-
|
|
189352
|
-
|
|
189353
|
-
|
|
189354
|
-
|
|
189355
|
-
|
|
189356
|
-
|
|
189357
|
-
|
|
189358
|
-
|
|
189359
|
-
|
|
189360
|
-
|
|
189361
|
-
|
|
189362
|
-
|
|
189363
|
-
|
|
189364
|
-
|
|
189365
|
-
|
|
189366
|
-
|
|
189367
|
-
|
|
189368
|
-
|
|
189369
|
-
|
|
189370
|
-
|
|
189371
|
-
|
|
189372
|
-
|
|
189373
|
-
|
|
189374
|
-
|
|
189375
|
-
|
|
189376
|
-
|
|
189377
|
-
|
|
189378
|
-
|
|
189379
|
-
|
|
189380
|
-
|
|
189381
|
-
|
|
189382
|
-
|
|
189383
|
-
|
|
189384
|
-
|
|
189385
|
-
|
|
189386
|
-
|
|
189387
|
-
|
|
189388
|
-
|
|
189455
|
+
]
|
|
189456
|
+
},
|
|
189457
|
+
cmd: {
|
|
189458
|
+
args: ["/c", input.command]
|
|
189459
|
+
},
|
|
189460
|
+
powershell: {
|
|
189461
|
+
args: ["-NoProfile", "-Command", input.command]
|
|
189462
|
+
},
|
|
189463
|
+
pwsh: {
|
|
189464
|
+
args: ["-NoProfile", "-Command", input.command]
|
|
189465
|
+
},
|
|
189466
|
+
"": {
|
|
189467
|
+
args: ["-c", `${input.command}`]
|
|
189468
|
+
}
|
|
189469
|
+
};
|
|
189470
|
+
const matchingInvocation = invocations[shellName] ?? invocations[""];
|
|
189471
|
+
const args3 = matchingInvocation?.args;
|
|
189472
|
+
const cwd = Instance.directory;
|
|
189473
|
+
const shellEnv = await Plugin.trigger("shell.env", { cwd, sessionID: input.sessionID, callID: part.callID }, { env: {} });
|
|
189474
|
+
const proc = spawn6(shell2, args3, {
|
|
189475
|
+
cwd,
|
|
189476
|
+
detached: process.platform !== "win32",
|
|
189477
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
189478
|
+
env: {
|
|
189479
|
+
...Env.all({ sessionID: input.sessionID }),
|
|
189480
|
+
...shellEnv.env,
|
|
189481
|
+
TERM: "dumb"
|
|
189482
|
+
}
|
|
189483
|
+
});
|
|
189484
|
+
const timeout4 = cfg.shell?.timeout_ms ?? SHELL_TIMEOUT;
|
|
189485
|
+
const decoder2 = new TextDecoder;
|
|
189486
|
+
let output2 = "";
|
|
189487
|
+
let clipped = 0;
|
|
189488
|
+
const format10 = (notes2 = []) => {
|
|
189489
|
+
const meta = [
|
|
189490
|
+
...clipped > 0 ? [`Output truncated after ${SHELL_OUTPUT_LIMIT} characters; ${clipped} additional characters omitted.`] : [],
|
|
189491
|
+
...notes2
|
|
189492
|
+
];
|
|
189493
|
+
const suffix = meta.length ? `
|
|
189389
189494
|
|
|
189390
189495
|
<shell_metadata>
|
|
189391
189496
|
${meta.join(`
|
|
189392
189497
|
`)}
|
|
189393
189498
|
</shell_metadata>` : "";
|
|
189394
|
-
|
|
189395
|
-
|
|
189396
|
-
|
|
189397
|
-
|
|
189499
|
+
const text12 = output2 + suffix;
|
|
189500
|
+
if (text12.length <= SHELL_METADATA_LIMIT)
|
|
189501
|
+
return text12;
|
|
189502
|
+
return text12.slice(0, SHELL_METADATA_LIMIT) + `
|
|
189398
189503
|
|
|
189399
189504
|
...`;
|
|
189400
|
-
|
|
189401
|
-
|
|
189402
|
-
|
|
189403
|
-
|
|
189404
|
-
|
|
189405
|
-
} else {
|
|
189406
|
-
const remaining2 = SHELL_OUTPUT_LIMIT - output2.length;
|
|
189407
|
-
if (text12.length <= remaining2) {
|
|
189408
|
-
output2 += text12;
|
|
189505
|
+
};
|
|
189506
|
+
const append7 = (chunk) => {
|
|
189507
|
+
const text12 = typeof chunk === "string" ? chunk : decoder2.decode(chunk);
|
|
189508
|
+
if (clipped > 0) {
|
|
189509
|
+
clipped += text12.length;
|
|
189409
189510
|
} else {
|
|
189410
|
-
|
|
189411
|
-
|
|
189511
|
+
const remaining2 = SHELL_OUTPUT_LIMIT - output2.length;
|
|
189512
|
+
if (text12.length <= remaining2) {
|
|
189513
|
+
output2 += text12;
|
|
189514
|
+
} else {
|
|
189515
|
+
output2 += text12.slice(0, remaining2);
|
|
189516
|
+
clipped += text12.length - remaining2;
|
|
189517
|
+
}
|
|
189412
189518
|
}
|
|
189413
|
-
|
|
189414
|
-
|
|
189415
|
-
|
|
189416
|
-
|
|
189417
|
-
|
|
189418
|
-
|
|
189519
|
+
if (part.state.status !== "running")
|
|
189520
|
+
return;
|
|
189521
|
+
part.state.metadata = {
|
|
189522
|
+
output: format10(),
|
|
189523
|
+
description: ""
|
|
189524
|
+
};
|
|
189525
|
+
Session.updatePart(part);
|
|
189419
189526
|
};
|
|
189420
|
-
|
|
189421
|
-
|
|
189422
|
-
|
|
189423
|
-
|
|
189424
|
-
|
|
189425
|
-
|
|
189426
|
-
|
|
189427
|
-
|
|
189428
|
-
|
|
189429
|
-
|
|
189430
|
-
|
|
189431
|
-
|
|
189432
|
-
|
|
189433
|
-
aborted3 = true;
|
|
189434
|
-
kill();
|
|
189435
|
-
};
|
|
189436
|
-
const timeoutTimer = setTimeout(() => {
|
|
189437
|
-
timedOut = true;
|
|
189438
|
-
kill();
|
|
189439
|
-
}, timeout4 + 100);
|
|
189440
|
-
abort2.addEventListener("abort", abortHandler, { once: true });
|
|
189441
|
-
const error46 = await new Promise((resolve10) => {
|
|
189442
|
-
const cleanup = () => {
|
|
189443
|
-
clearTimeout(timeoutTimer);
|
|
189444
|
-
abort2.removeEventListener("abort", abortHandler);
|
|
189445
|
-
proc.stdout?.off("data", append7);
|
|
189446
|
-
proc.stderr?.off("data", append7);
|
|
189527
|
+
proc.stdout?.on("data", append7);
|
|
189528
|
+
proc.stderr?.on("data", append7);
|
|
189529
|
+
let timedOut = false;
|
|
189530
|
+
let aborted3 = false;
|
|
189531
|
+
let exited = false;
|
|
189532
|
+
const kill = () => Shell.killTree(proc, { exited: () => exited });
|
|
189533
|
+
if (abort2.aborted) {
|
|
189534
|
+
aborted3 = true;
|
|
189535
|
+
await kill();
|
|
189536
|
+
}
|
|
189537
|
+
const abortHandler = () => {
|
|
189538
|
+
aborted3 = true;
|
|
189539
|
+
kill();
|
|
189447
189540
|
};
|
|
189448
|
-
|
|
189449
|
-
|
|
189450
|
-
|
|
189451
|
-
|
|
189452
|
-
});
|
|
189453
|
-
|
|
189454
|
-
|
|
189455
|
-
|
|
189456
|
-
|
|
189541
|
+
const timeoutTimer = setTimeout(() => {
|
|
189542
|
+
timedOut = true;
|
|
189543
|
+
kill();
|
|
189544
|
+
}, timeout4 + 100);
|
|
189545
|
+
abort2.addEventListener("abort", abortHandler, { once: true });
|
|
189546
|
+
const error46 = await new Promise((resolve10) => {
|
|
189547
|
+
const cleanup = () => {
|
|
189548
|
+
clearTimeout(timeoutTimer);
|
|
189549
|
+
abort2.removeEventListener("abort", abortHandler);
|
|
189550
|
+
proc.stdout?.off("data", append7);
|
|
189551
|
+
proc.stderr?.off("data", append7);
|
|
189552
|
+
};
|
|
189553
|
+
proc.once("close", () => {
|
|
189554
|
+
exited = true;
|
|
189555
|
+
cleanup();
|
|
189556
|
+
resolve10(undefined);
|
|
189557
|
+
});
|
|
189558
|
+
proc.once("error", (error47) => {
|
|
189559
|
+
exited = true;
|
|
189560
|
+
cleanup();
|
|
189561
|
+
resolve10(error47);
|
|
189562
|
+
});
|
|
189457
189563
|
});
|
|
189458
|
-
|
|
189459
|
-
|
|
189460
|
-
|
|
189461
|
-
|
|
189564
|
+
msg.time.completed = Date.now();
|
|
189565
|
+
await Session.updateMessage(msg);
|
|
189566
|
+
if (error46) {
|
|
189567
|
+
if (part.state.status === "running") {
|
|
189568
|
+
part.state = {
|
|
189569
|
+
status: "error",
|
|
189570
|
+
input: part.state.input,
|
|
189571
|
+
error: error46.toString(),
|
|
189572
|
+
time: {
|
|
189573
|
+
...part.state.time,
|
|
189574
|
+
end: Date.now()
|
|
189575
|
+
}
|
|
189576
|
+
};
|
|
189577
|
+
await Session.updatePart(part);
|
|
189578
|
+
}
|
|
189579
|
+
throw error46;
|
|
189580
|
+
}
|
|
189581
|
+
const notes = [
|
|
189582
|
+
...timedOut ? [`shell command terminated after exceeding timeout ${timeout4} ms`] : [],
|
|
189583
|
+
...aborted3 ? ["User aborted the command"] : []
|
|
189584
|
+
];
|
|
189585
|
+
const text11 = format10(notes);
|
|
189462
189586
|
if (part.state.status === "running") {
|
|
189463
189587
|
part.state = {
|
|
189464
|
-
status: "
|
|
189465
|
-
input: part.state.input,
|
|
189466
|
-
error: error46.toString(),
|
|
189588
|
+
status: "completed",
|
|
189467
189589
|
time: {
|
|
189468
189590
|
...part.state.time,
|
|
189469
189591
|
end: Date.now()
|
|
189470
|
-
}
|
|
189592
|
+
},
|
|
189593
|
+
input: part.state.input,
|
|
189594
|
+
title: "",
|
|
189595
|
+
metadata: {
|
|
189596
|
+
output: text11,
|
|
189597
|
+
description: ""
|
|
189598
|
+
},
|
|
189599
|
+
output: text11
|
|
189471
189600
|
};
|
|
189472
189601
|
await Session.updatePart(part);
|
|
189473
189602
|
}
|
|
189474
|
-
|
|
189475
|
-
}
|
|
189476
|
-
|
|
189477
|
-
|
|
189478
|
-
|
|
189479
|
-
];
|
|
189480
|
-
const text11 = format10(notes);
|
|
189481
|
-
if (part.state.status === "running") {
|
|
189482
|
-
part.state = {
|
|
189483
|
-
status: "completed",
|
|
189484
|
-
time: {
|
|
189485
|
-
...part.state.time,
|
|
189486
|
-
end: Date.now()
|
|
189487
|
-
},
|
|
189488
|
-
input: part.state.input,
|
|
189489
|
-
title: "",
|
|
189490
|
-
metadata: {
|
|
189491
|
-
output: text11,
|
|
189492
|
-
description: ""
|
|
189493
|
-
},
|
|
189494
|
-
output: text11
|
|
189495
|
-
};
|
|
189496
|
-
await Session.updatePart(part);
|
|
189603
|
+
return { info: msg, parts: [part] };
|
|
189604
|
+
} catch (_catch3) {
|
|
189605
|
+
var _err = _catch3, _hasErr = 1;
|
|
189606
|
+
} finally {
|
|
189607
|
+
__callDispose(__stack, _err, _hasErr);
|
|
189497
189608
|
}
|
|
189498
|
-
return { info: msg, parts: [part] };
|
|
189499
189609
|
}
|
|
189500
189610
|
SessionPrompt.shell = shell;
|
|
189501
189611
|
SessionPrompt.CommandInput = zod_default.object({
|
|
@@ -256877,11 +256987,11 @@ var init_types4 = () => {};
|
|
|
256877
256987
|
var exports_dist_es = {};
|
|
256878
256988
|
__export(exports_dist_es, {
|
|
256879
256989
|
providerConfigFromInit: () => providerConfigFromInit,
|
|
256880
|
-
httpRequest: () =>
|
|
256881
|
-
getInstanceMetadataEndpoint: () =>
|
|
256990
|
+
httpRequest: () => httpRequest2,
|
|
256991
|
+
getInstanceMetadataEndpoint: () => getInstanceMetadataEndpoint2,
|
|
256882
256992
|
fromInstanceMetadata: () => fromInstanceMetadata,
|
|
256883
256993
|
fromContainerMetadata: () => fromContainerMetadata,
|
|
256884
|
-
Endpoint: () =>
|
|
256994
|
+
Endpoint: () => Endpoint2,
|
|
256885
256995
|
ENV_CMDS_RELATIVE_URI: () => ENV_CMDS_RELATIVE_URI,
|
|
256886
256996
|
ENV_CMDS_FULL_URI: () => ENV_CMDS_FULL_URI,
|
|
256887
256997
|
ENV_CMDS_AUTH_TOKEN: () => ENV_CMDS_AUTH_TOKEN,
|
|
@@ -256889,9 +256999,6 @@ __export(exports_dist_es, {
|
|
|
256889
256999
|
DEFAULT_MAX_RETRIES: () => DEFAULT_MAX_RETRIES
|
|
256890
257000
|
});
|
|
256891
257001
|
var init_dist_es4 = __esm(() => {
|
|
256892
|
-
init_httpRequest();
|
|
256893
|
-
init_getInstanceMetadataEndpoint();
|
|
256894
|
-
init_Endpoint();
|
|
256895
257002
|
init_fromContainerMetadata();
|
|
256896
257003
|
init_fromInstanceMetadata();
|
|
256897
257004
|
init_types4();
|
|
@@ -257302,7 +257409,7 @@ var require_dist_cjs14 = __commonJS((exports) => {
|
|
|
257302
257409
|
return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
|
|
257303
257410
|
};
|
|
257304
257411
|
var MIN_WAIT_TIME = 6000;
|
|
257305
|
-
async function writeRequestBody(
|
|
257412
|
+
async function writeRequestBody(httpRequest3, request5, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) {
|
|
257306
257413
|
const headers = request5.headers ?? {};
|
|
257307
257414
|
const expect = headers.Expect || headers.expect;
|
|
257308
257415
|
let timeoutId = -1;
|
|
@@ -257313,15 +257420,15 @@ var require_dist_cjs14 = __commonJS((exports) => {
|
|
|
257313
257420
|
timeoutId = Number(timing.setTimeout(() => resolve12(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
|
|
257314
257421
|
}),
|
|
257315
257422
|
new Promise((resolve12) => {
|
|
257316
|
-
|
|
257423
|
+
httpRequest3.on("continue", () => {
|
|
257317
257424
|
timing.clearTimeout(timeoutId);
|
|
257318
257425
|
resolve12(true);
|
|
257319
257426
|
});
|
|
257320
|
-
|
|
257427
|
+
httpRequest3.on("response", () => {
|
|
257321
257428
|
timing.clearTimeout(timeoutId);
|
|
257322
257429
|
resolve12(false);
|
|
257323
257430
|
});
|
|
257324
|
-
|
|
257431
|
+
httpRequest3.on("error", () => {
|
|
257325
257432
|
timing.clearTimeout(timeoutId);
|
|
257326
257433
|
resolve12(false);
|
|
257327
257434
|
});
|
|
@@ -257329,12 +257436,12 @@ var require_dist_cjs14 = __commonJS((exports) => {
|
|
|
257329
257436
|
]);
|
|
257330
257437
|
}
|
|
257331
257438
|
if (sendBody) {
|
|
257332
|
-
writeBody(
|
|
257439
|
+
writeBody(httpRequest3, request5.body);
|
|
257333
257440
|
}
|
|
257334
257441
|
}
|
|
257335
|
-
function writeBody(
|
|
257442
|
+
function writeBody(httpRequest3, body2) {
|
|
257336
257443
|
if (body2 instanceof stream3.Readable) {
|
|
257337
|
-
body2.pipe(
|
|
257444
|
+
body2.pipe(httpRequest3);
|
|
257338
257445
|
return;
|
|
257339
257446
|
}
|
|
257340
257447
|
if (body2) {
|
|
@@ -257342,21 +257449,21 @@ var require_dist_cjs14 = __commonJS((exports) => {
|
|
|
257342
257449
|
const isString4 = typeof body2 === "string";
|
|
257343
257450
|
if (isBuffer || isString4) {
|
|
257344
257451
|
if (isBuffer && body2.byteLength === 0) {
|
|
257345
|
-
|
|
257452
|
+
httpRequest3.end();
|
|
257346
257453
|
} else {
|
|
257347
|
-
|
|
257454
|
+
httpRequest3.end(body2);
|
|
257348
257455
|
}
|
|
257349
257456
|
return;
|
|
257350
257457
|
}
|
|
257351
257458
|
const uint8 = body2;
|
|
257352
257459
|
if (typeof uint8 === "object" && uint8.buffer && typeof uint8.byteOffset === "number" && typeof uint8.byteLength === "number") {
|
|
257353
|
-
|
|
257460
|
+
httpRequest3.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength));
|
|
257354
257461
|
return;
|
|
257355
257462
|
}
|
|
257356
|
-
|
|
257463
|
+
httpRequest3.end(Buffer.from(body2));
|
|
257357
257464
|
return;
|
|
257358
257465
|
}
|
|
257359
|
-
|
|
257466
|
+
httpRequest3.end();
|
|
257360
257467
|
}
|
|
257361
257468
|
var DEFAULT_REQUEST_TIMEOUT = 0;
|
|
257362
257469
|
|
|
@@ -262956,7 +263063,7 @@ var require_dist_cjs26 = __commonJS((exports) => {
|
|
|
262956
263063
|
}
|
|
262957
263064
|
|
|
262958
263065
|
class HttpApiKeyAuthSigner {
|
|
262959
|
-
async sign(
|
|
263066
|
+
async sign(httpRequest3, identity3, signingProperties) {
|
|
262960
263067
|
if (!signingProperties) {
|
|
262961
263068
|
throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
|
|
262962
263069
|
}
|
|
@@ -262969,7 +263076,7 @@ var require_dist_cjs26 = __commonJS((exports) => {
|
|
|
262969
263076
|
if (!identity3.apiKey) {
|
|
262970
263077
|
throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
|
|
262971
263078
|
}
|
|
262972
|
-
const clonedRequest = protocolHttp.HttpRequest.clone(
|
|
263079
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest3);
|
|
262973
263080
|
if (signingProperties.in === types6.HttpApiKeyAuthLocation.QUERY) {
|
|
262974
263081
|
clonedRequest.query[signingProperties.name] = identity3.apiKey;
|
|
262975
263082
|
} else if (signingProperties.in === types6.HttpApiKeyAuthLocation.HEADER) {
|
|
@@ -262982,8 +263089,8 @@ var require_dist_cjs26 = __commonJS((exports) => {
|
|
|
262982
263089
|
}
|
|
262983
263090
|
|
|
262984
263091
|
class HttpBearerAuthSigner {
|
|
262985
|
-
async sign(
|
|
262986
|
-
const clonedRequest = protocolHttp.HttpRequest.clone(
|
|
263092
|
+
async sign(httpRequest3, identity3, signingProperties) {
|
|
263093
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest3);
|
|
262987
263094
|
if (!identity3.token) {
|
|
262988
263095
|
throw new Error("request could not be signed with `token` since the `token` is not defined");
|
|
262989
263096
|
}
|
|
@@ -262993,8 +263100,8 @@ var require_dist_cjs26 = __commonJS((exports) => {
|
|
|
262993
263100
|
}
|
|
262994
263101
|
|
|
262995
263102
|
class NoAuthSigner {
|
|
262996
|
-
async sign(
|
|
262997
|
-
return
|
|
263103
|
+
async sign(httpRequest3, identity3, signingProperties) {
|
|
263104
|
+
return httpRequest3;
|
|
262998
263105
|
}
|
|
262999
263106
|
}
|
|
263000
263107
|
var createIsIdentityExpiredFunction = (expirationMs) => function isIdentityExpired2(identity3) {
|
|
@@ -266755,8 +266862,8 @@ More information can be found at: https://a.co/c895JFp`);
|
|
|
266755
266862
|
};
|
|
266756
266863
|
|
|
266757
266864
|
class AwsSdkSigV4Signer {
|
|
266758
|
-
async sign(
|
|
266759
|
-
if (!protocolHttp.HttpRequest.isInstance(
|
|
266865
|
+
async sign(httpRequest3, identity3, signingProperties) {
|
|
266866
|
+
if (!protocolHttp.HttpRequest.isInstance(httpRequest3)) {
|
|
266760
266867
|
throw new Error("The request is not an instance of `HttpRequest` and cannot be signed");
|
|
266761
266868
|
}
|
|
266762
266869
|
const validatedProps = await validateSigningProperties(signingProperties);
|
|
@@ -266770,7 +266877,7 @@ More information can be found at: https://a.co/c895JFp`);
|
|
|
266770
266877
|
signingName = second?.signingName ?? signingName;
|
|
266771
266878
|
}
|
|
266772
266879
|
}
|
|
266773
|
-
const signedRequest = await signer.sign(
|
|
266880
|
+
const signedRequest = await signer.sign(httpRequest3, {
|
|
266774
266881
|
signingDate: getSkewCorrectedDate(config5.systemClockOffset),
|
|
266775
266882
|
signingRegion,
|
|
266776
266883
|
signingService: signingName
|
|
@@ -266803,14 +266910,14 @@ More information can be found at: https://a.co/c895JFp`);
|
|
|
266803
266910
|
var AWSSDKSigV4Signer = AwsSdkSigV4Signer;
|
|
266804
266911
|
|
|
266805
266912
|
class AwsSdkSigV4ASigner extends AwsSdkSigV4Signer {
|
|
266806
|
-
async sign(
|
|
266807
|
-
if (!protocolHttp.HttpRequest.isInstance(
|
|
266913
|
+
async sign(httpRequest3, identity3, signingProperties) {
|
|
266914
|
+
if (!protocolHttp.HttpRequest.isInstance(httpRequest3)) {
|
|
266808
266915
|
throw new Error("The request is not an instance of `HttpRequest` and cannot be signed");
|
|
266809
266916
|
}
|
|
266810
266917
|
const { config: config5, signer, signingRegion, signingRegionSet, signingName } = await validateSigningProperties(signingProperties);
|
|
266811
266918
|
const configResolvedSigningRegionSet = await config5.sigv4aSigningRegionSet?.();
|
|
266812
266919
|
const multiRegionOverride = (configResolvedSigningRegionSet ?? signingRegionSet ?? [signingRegion]).join(",");
|
|
266813
|
-
const signedRequest = await signer.sign(
|
|
266920
|
+
const signedRequest = await signer.sign(httpRequest3, {
|
|
266814
266921
|
signingDate: getSkewCorrectedDate(config5.systemClockOffset),
|
|
266815
266922
|
signingRegion: multiRegionOverride,
|
|
266816
266923
|
signingService: signingName
|
|
@@ -270566,9 +270673,9 @@ var require_dist_cjs44 = __commonJS((exports) => {
|
|
|
270566
270673
|
}
|
|
270567
270674
|
if (!process.env[ENV_IMDS_DISABLED]) {
|
|
270568
270675
|
try {
|
|
270569
|
-
const { getInstanceMetadataEndpoint:
|
|
270570
|
-
const endpoint = await
|
|
270571
|
-
return (await
|
|
270676
|
+
const { getInstanceMetadataEndpoint: getInstanceMetadataEndpoint3, httpRequest: httpRequest3 } = await Promise.resolve().then(() => (init_dist_es4(), exports_dist_es));
|
|
270677
|
+
const endpoint = await getInstanceMetadataEndpoint3();
|
|
270678
|
+
return (await httpRequest3({ ...endpoint, path: IMDS_REGION_PATH })).toString();
|
|
270572
270679
|
} catch (e4) {}
|
|
270573
270680
|
}
|
|
270574
270681
|
};
|
|
@@ -277644,256 +277751,263 @@ var init_provider = __esm(async () => {
|
|
|
277644
277751
|
}
|
|
277645
277752
|
Provider.fromModelsDevProvider = fromModelsDevProvider;
|
|
277646
277753
|
const state4 = Instance.state(async () => {
|
|
277647
|
-
|
|
277648
|
-
|
|
277649
|
-
|
|
277650
|
-
|
|
277651
|
-
|
|
277652
|
-
|
|
277653
|
-
|
|
277654
|
-
|
|
277655
|
-
|
|
277656
|
-
|
|
277657
|
-
|
|
277658
|
-
|
|
277659
|
-
|
|
277660
|
-
|
|
277661
|
-
const languages = new Map;
|
|
277662
|
-
const modelLoaders = {};
|
|
277663
|
-
const sdk = new Map;
|
|
277664
|
-
log12.info("init");
|
|
277665
|
-
const configProviders = Object.entries(config5.provider ?? {});
|
|
277666
|
-
if (database["github-copilot"]) {
|
|
277667
|
-
const githubCopilot = database["github-copilot"];
|
|
277668
|
-
database["github-copilot-enterprise"] = {
|
|
277669
|
-
...githubCopilot,
|
|
277670
|
-
id: "github-copilot-enterprise",
|
|
277671
|
-
name: "GitHub Copilot Enterprise",
|
|
277672
|
-
models: i4(githubCopilot.models, (model2) => ({
|
|
277673
|
-
...model2,
|
|
277674
|
-
providerID: "github-copilot-enterprise"
|
|
277675
|
-
}))
|
|
277676
|
-
};
|
|
277677
|
-
}
|
|
277678
|
-
function mergeProvider(providerID, provider) {
|
|
277679
|
-
const existing = providers2[providerID];
|
|
277680
|
-
if (existing) {
|
|
277681
|
-
providers2[providerID] = D2(existing, provider);
|
|
277682
|
-
return;
|
|
277754
|
+
let __stack = [];
|
|
277755
|
+
try {
|
|
277756
|
+
const _3 = __using(__stack, log12.time("state"), 0);
|
|
277757
|
+
const config5 = await Config.get();
|
|
277758
|
+
const modelsDev = await ModelsDev.get();
|
|
277759
|
+
const database = i4(modelsDev, fromModelsDevProvider);
|
|
277760
|
+
const disabled = new Set(config5.disabled_providers ?? []);
|
|
277761
|
+
const enabled = config5.enabled_providers ? new Set(config5.enabled_providers) : null;
|
|
277762
|
+
function isProviderAllowed(providerID) {
|
|
277763
|
+
if (enabled && !enabled.has(providerID))
|
|
277764
|
+
return false;
|
|
277765
|
+
if (disabled.has(providerID))
|
|
277766
|
+
return false;
|
|
277767
|
+
return true;
|
|
277683
277768
|
}
|
|
277684
|
-
const
|
|
277685
|
-
|
|
277686
|
-
|
|
277687
|
-
|
|
277688
|
-
|
|
277689
|
-
|
|
277690
|
-
|
|
277691
|
-
|
|
277692
|
-
|
|
277693
|
-
|
|
277694
|
-
|
|
277695
|
-
|
|
277696
|
-
|
|
277697
|
-
|
|
277698
|
-
|
|
277699
|
-
|
|
277700
|
-
|
|
277701
|
-
|
|
277702
|
-
|
|
277703
|
-
|
|
277704
|
-
|
|
277705
|
-
|
|
277706
|
-
return
|
|
277707
|
-
}
|
|
277708
|
-
const
|
|
277709
|
-
|
|
277710
|
-
|
|
277711
|
-
|
|
277712
|
-
|
|
277713
|
-
|
|
277714
|
-
|
|
277715
|
-
|
|
277716
|
-
|
|
277717
|
-
providerID,
|
|
277718
|
-
|
|
277719
|
-
|
|
277720
|
-
|
|
277721
|
-
|
|
277722
|
-
|
|
277723
|
-
|
|
277724
|
-
|
|
277725
|
-
|
|
277726
|
-
|
|
277727
|
-
|
|
277728
|
-
|
|
277769
|
+
const providers2 = {};
|
|
277770
|
+
const languages = new Map;
|
|
277771
|
+
const modelLoaders = {};
|
|
277772
|
+
const sdk = new Map;
|
|
277773
|
+
log12.info("init");
|
|
277774
|
+
const configProviders = Object.entries(config5.provider ?? {});
|
|
277775
|
+
if (database["github-copilot"]) {
|
|
277776
|
+
const githubCopilot = database["github-copilot"];
|
|
277777
|
+
database["github-copilot-enterprise"] = {
|
|
277778
|
+
...githubCopilot,
|
|
277779
|
+
id: "github-copilot-enterprise",
|
|
277780
|
+
name: "GitHub Copilot Enterprise",
|
|
277781
|
+
models: i4(githubCopilot.models, (model2) => ({
|
|
277782
|
+
...model2,
|
|
277783
|
+
providerID: "github-copilot-enterprise"
|
|
277784
|
+
}))
|
|
277785
|
+
};
|
|
277786
|
+
}
|
|
277787
|
+
function mergeProvider(providerID, provider) {
|
|
277788
|
+
const existing = providers2[providerID];
|
|
277789
|
+
if (existing) {
|
|
277790
|
+
providers2[providerID] = D2(existing, provider);
|
|
277791
|
+
return;
|
|
277792
|
+
}
|
|
277793
|
+
const match17 = database[providerID];
|
|
277794
|
+
if (!match17)
|
|
277795
|
+
return;
|
|
277796
|
+
providers2[providerID] = D2(match17, provider);
|
|
277797
|
+
}
|
|
277798
|
+
for (const [providerID, provider] of configProviders) {
|
|
277799
|
+
const existing = database[providerID];
|
|
277800
|
+
const parsed = {
|
|
277801
|
+
id: providerID,
|
|
277802
|
+
name: provider.name ?? existing?.name ?? providerID,
|
|
277803
|
+
env: provider.env ?? existing?.env ?? [],
|
|
277804
|
+
options: D2(existing?.options ?? {}, provider.options ?? {}),
|
|
277805
|
+
source: "config",
|
|
277806
|
+
models: existing?.models ?? {}
|
|
277807
|
+
};
|
|
277808
|
+
for (const [modelID, model2] of Object.entries(provider.models ?? {})) {
|
|
277809
|
+
const existingModel = parsed.models[model2.id ?? modelID];
|
|
277810
|
+
const name19 = iife2(() => {
|
|
277811
|
+
if (model2.name)
|
|
277812
|
+
return model2.name;
|
|
277813
|
+
if (model2.id && model2.id !== modelID)
|
|
277814
|
+
return modelID;
|
|
277815
|
+
return existingModel?.name ?? modelID;
|
|
277816
|
+
});
|
|
277817
|
+
const parsedModel = {
|
|
277818
|
+
id: modelID,
|
|
277819
|
+
api: {
|
|
277820
|
+
id: model2.id ?? existingModel?.api.id ?? modelID,
|
|
277821
|
+
npm: model2.provider?.npm ?? provider.npm ?? existingModel?.api.npm ?? modelsDev[providerID]?.npm ?? "@ai-sdk/openai-compatible",
|
|
277822
|
+
url: model2.provider?.api ?? provider?.api ?? existingModel?.api.url ?? modelsDev[providerID]?.api
|
|
277823
|
+
},
|
|
277824
|
+
status: model2.status ?? existingModel?.status ?? "active",
|
|
277825
|
+
name: name19,
|
|
277826
|
+
providerID,
|
|
277827
|
+
capabilities: {
|
|
277828
|
+
temperature: model2.temperature ?? existingModel?.capabilities.temperature ?? false,
|
|
277829
|
+
reasoning: model2.reasoning ?? existingModel?.capabilities.reasoning ?? false,
|
|
277830
|
+
attachment: model2.attachment ?? existingModel?.capabilities.attachment ?? false,
|
|
277831
|
+
toolcall: model2.tool_call ?? existingModel?.capabilities.toolcall ?? true,
|
|
277832
|
+
input: {
|
|
277833
|
+
text: model2.modalities?.input?.includes("text") ?? existingModel?.capabilities.input.text ?? true,
|
|
277834
|
+
audio: model2.modalities?.input?.includes("audio") ?? existingModel?.capabilities.input.audio ?? false,
|
|
277835
|
+
image: model2.modalities?.input?.includes("image") ?? existingModel?.capabilities.input.image ?? false,
|
|
277836
|
+
video: model2.modalities?.input?.includes("video") ?? existingModel?.capabilities.input.video ?? false,
|
|
277837
|
+
pdf: model2.modalities?.input?.includes("pdf") ?? existingModel?.capabilities.input.pdf ?? false
|
|
277838
|
+
},
|
|
277839
|
+
output: {
|
|
277840
|
+
text: model2.modalities?.output?.includes("text") ?? existingModel?.capabilities.output.text ?? true,
|
|
277841
|
+
audio: model2.modalities?.output?.includes("audio") ?? existingModel?.capabilities.output.audio ?? false,
|
|
277842
|
+
image: model2.modalities?.output?.includes("image") ?? existingModel?.capabilities.output.image ?? false,
|
|
277843
|
+
video: model2.modalities?.output?.includes("video") ?? existingModel?.capabilities.output.video ?? false,
|
|
277844
|
+
pdf: model2.modalities?.output?.includes("pdf") ?? existingModel?.capabilities.output.pdf ?? false
|
|
277845
|
+
},
|
|
277846
|
+
interleaved: model2.interleaved ?? false
|
|
277729
277847
|
},
|
|
277730
|
-
|
|
277731
|
-
|
|
277732
|
-
|
|
277733
|
-
|
|
277734
|
-
|
|
277735
|
-
|
|
277848
|
+
cost: {
|
|
277849
|
+
input: model2?.cost?.input ?? existingModel?.cost?.input ?? 0,
|
|
277850
|
+
output: model2?.cost?.output ?? existingModel?.cost?.output ?? 0,
|
|
277851
|
+
cache: {
|
|
277852
|
+
read: model2?.cost?.cache_read ?? existingModel?.cost?.cache.read ?? 0,
|
|
277853
|
+
write: model2?.cost?.cache_write ?? existingModel?.cost?.cache.write ?? 0
|
|
277854
|
+
}
|
|
277736
277855
|
},
|
|
277737
|
-
|
|
277738
|
-
|
|
277739
|
-
|
|
277740
|
-
|
|
277741
|
-
|
|
277742
|
-
|
|
277743
|
-
|
|
277744
|
-
|
|
277745
|
-
}
|
|
277746
|
-
}
|
|
277747
|
-
|
|
277748
|
-
|
|
277749
|
-
|
|
277750
|
-
|
|
277751
|
-
|
|
277752
|
-
headers: D2(existingModel?.headers ?? {}, model2.headers ?? {}),
|
|
277753
|
-
family: model2.family ?? existingModel?.family ?? "",
|
|
277754
|
-
release_date: model2.release_date ?? existingModel?.release_date ?? "",
|
|
277755
|
-
variants: {}
|
|
277756
|
-
};
|
|
277757
|
-
const merged = D2(ProviderTransform.variants(parsedModel), model2.variants ?? {});
|
|
277758
|
-
parsedModel.variants = i4(d3(merged, (v4) => !v4.disabled), (v4) => y4(v4, ["disabled"]));
|
|
277759
|
-
parsed.models[modelID] = parsedModel;
|
|
277856
|
+
options: D2(existingModel?.options ?? {}, model2.options ?? {}),
|
|
277857
|
+
limit: {
|
|
277858
|
+
context: model2.limit?.context ?? existingModel?.limit?.context ?? 0,
|
|
277859
|
+
output: model2.limit?.output ?? existingModel?.limit?.output ?? 0
|
|
277860
|
+
},
|
|
277861
|
+
headers: D2(existingModel?.headers ?? {}, model2.headers ?? {}),
|
|
277862
|
+
family: model2.family ?? existingModel?.family ?? "",
|
|
277863
|
+
release_date: model2.release_date ?? existingModel?.release_date ?? "",
|
|
277864
|
+
variants: {}
|
|
277865
|
+
};
|
|
277866
|
+
const merged = D2(ProviderTransform.variants(parsedModel), model2.variants ?? {});
|
|
277867
|
+
parsedModel.variants = i4(d3(merged, (v4) => !v4.disabled), (v4) => y4(v4, ["disabled"]));
|
|
277868
|
+
parsed.models[modelID] = parsedModel;
|
|
277869
|
+
}
|
|
277870
|
+
database[providerID] = parsed;
|
|
277760
277871
|
}
|
|
277761
|
-
|
|
277762
|
-
|
|
277763
|
-
|
|
277764
|
-
|
|
277765
|
-
|
|
277766
|
-
|
|
277767
|
-
|
|
277768
|
-
if (!apiKey)
|
|
277769
|
-
continue;
|
|
277770
|
-
mergeProvider(providerID, {
|
|
277771
|
-
source: "env",
|
|
277772
|
-
key: provider.env.length === 1 ? apiKey : undefined
|
|
277773
|
-
});
|
|
277774
|
-
}
|
|
277775
|
-
for (const [providerID, provider] of Object.entries(await Auth.all())) {
|
|
277776
|
-
if (disabled.has(providerID))
|
|
277777
|
-
continue;
|
|
277778
|
-
if (provider.type === "api") {
|
|
277872
|
+
const env3 = Env.all();
|
|
277873
|
+
for (const [providerID, provider] of Object.entries(database)) {
|
|
277874
|
+
if (disabled.has(providerID))
|
|
277875
|
+
continue;
|
|
277876
|
+
const apiKey = provider.env.map((item) => env3[item]).find(Boolean);
|
|
277877
|
+
if (!apiKey)
|
|
277878
|
+
continue;
|
|
277779
277879
|
mergeProvider(providerID, {
|
|
277780
|
-
source: "
|
|
277781
|
-
key: provider.
|
|
277880
|
+
source: "env",
|
|
277881
|
+
key: provider.env.length === 1 ? apiKey : undefined
|
|
277782
277882
|
});
|
|
277783
277883
|
}
|
|
277784
|
-
|
|
277785
|
-
|
|
277786
|
-
|
|
277787
|
-
|
|
277788
|
-
|
|
277789
|
-
|
|
277790
|
-
|
|
277791
|
-
|
|
277792
|
-
|
|
277793
|
-
if (auth3)
|
|
277794
|
-
hasAuth = true;
|
|
277795
|
-
if (providerID === "github-copilot" && !hasAuth) {
|
|
277796
|
-
const enterpriseAuth = await Auth.get("github-copilot-enterprise");
|
|
277797
|
-
if (enterpriseAuth)
|
|
277798
|
-
hasAuth = true;
|
|
277799
|
-
}
|
|
277800
|
-
if (!hasAuth)
|
|
277801
|
-
continue;
|
|
277802
|
-
if (!plugin.auth.loader)
|
|
277803
|
-
continue;
|
|
277804
|
-
if (auth3) {
|
|
277805
|
-
const options2 = await plugin.auth.loader(() => Auth.get(providerID), database[plugin.auth.provider]);
|
|
277806
|
-
const opts = options2 ?? {};
|
|
277807
|
-
const patch = providers2[providerID] ? { options: opts } : { source: "custom", options: opts };
|
|
277808
|
-
mergeProvider(providerID, patch);
|
|
277884
|
+
for (const [providerID, provider] of Object.entries(await Auth.all())) {
|
|
277885
|
+
if (disabled.has(providerID))
|
|
277886
|
+
continue;
|
|
277887
|
+
if (provider.type === "api") {
|
|
277888
|
+
mergeProvider(providerID, {
|
|
277889
|
+
source: "api",
|
|
277890
|
+
key: provider.key
|
|
277891
|
+
});
|
|
277892
|
+
}
|
|
277809
277893
|
}
|
|
277810
|
-
|
|
277811
|
-
|
|
277812
|
-
|
|
277813
|
-
|
|
277814
|
-
|
|
277815
|
-
|
|
277816
|
-
|
|
277817
|
-
|
|
277818
|
-
|
|
277894
|
+
for (const plugin of await Plugin.list()) {
|
|
277895
|
+
if (!plugin.auth)
|
|
277896
|
+
continue;
|
|
277897
|
+
const providerID = plugin.auth.provider;
|
|
277898
|
+
if (disabled.has(providerID))
|
|
277899
|
+
continue;
|
|
277900
|
+
let hasAuth = false;
|
|
277901
|
+
const auth3 = await Auth.get(providerID);
|
|
277902
|
+
if (auth3)
|
|
277903
|
+
hasAuth = true;
|
|
277904
|
+
if (providerID === "github-copilot" && !hasAuth) {
|
|
277905
|
+
const enterpriseAuth = await Auth.get("github-copilot-enterprise");
|
|
277906
|
+
if (enterpriseAuth)
|
|
277907
|
+
hasAuth = true;
|
|
277908
|
+
}
|
|
277909
|
+
if (!hasAuth)
|
|
277910
|
+
continue;
|
|
277911
|
+
if (!plugin.auth.loader)
|
|
277912
|
+
continue;
|
|
277913
|
+
if (auth3) {
|
|
277914
|
+
const options2 = await plugin.auth.loader(() => Auth.get(providerID), database[plugin.auth.provider]);
|
|
277915
|
+
const opts = options2 ?? {};
|
|
277916
|
+
const patch = providers2[providerID] ? { options: opts } : { source: "custom", options: opts };
|
|
277917
|
+
mergeProvider(providerID, patch);
|
|
277918
|
+
}
|
|
277919
|
+
if (providerID === "github-copilot") {
|
|
277920
|
+
const enterpriseProviderID = "github-copilot-enterprise";
|
|
277921
|
+
if (!disabled.has(enterpriseProviderID)) {
|
|
277922
|
+
const enterpriseAuth = await Auth.get(enterpriseProviderID);
|
|
277923
|
+
if (enterpriseAuth) {
|
|
277924
|
+
const enterpriseOptions = await plugin.auth.loader(() => Auth.get(enterpriseProviderID), database[enterpriseProviderID]);
|
|
277925
|
+
const opts = enterpriseOptions ?? {};
|
|
277926
|
+
const patch = providers2[enterpriseProviderID] ? { options: opts } : { source: "custom", options: opts };
|
|
277927
|
+
mergeProvider(enterpriseProviderID, patch);
|
|
277928
|
+
}
|
|
277819
277929
|
}
|
|
277820
277930
|
}
|
|
277821
277931
|
}
|
|
277822
|
-
|
|
277823
|
-
|
|
277824
|
-
|
|
277825
|
-
|
|
277826
|
-
|
|
277827
|
-
|
|
277828
|
-
|
|
277829
|
-
|
|
277830
|
-
|
|
277831
|
-
|
|
277832
|
-
|
|
277833
|
-
|
|
277834
|
-
|
|
277835
|
-
|
|
277836
|
-
|
|
277837
|
-
|
|
277838
|
-
}
|
|
277839
|
-
|
|
277840
|
-
|
|
277841
|
-
|
|
277842
|
-
|
|
277843
|
-
|
|
277844
|
-
|
|
277845
|
-
|
|
277846
|
-
|
|
277847
|
-
partial2
|
|
277848
|
-
|
|
277849
|
-
|
|
277850
|
-
|
|
277851
|
-
|
|
277852
|
-
|
|
277853
|
-
|
|
277854
|
-
|
|
277855
|
-
|
|
277856
|
-
|
|
277857
|
-
|
|
277858
|
-
|
|
277859
|
-
|
|
277860
|
-
}
|
|
277861
|
-
}
|
|
277862
|
-
for (const [providerID, provider] of Object.entries(providers2)) {
|
|
277863
|
-
if (!isProviderAllowed(providerID)) {
|
|
277864
|
-
delete providers2[providerID];
|
|
277865
|
-
continue;
|
|
277932
|
+
for (const [providerID, fn5] of Object.entries(CUSTOM_LOADERS)) {
|
|
277933
|
+
if (disabled.has(providerID))
|
|
277934
|
+
continue;
|
|
277935
|
+
const data2 = database[providerID];
|
|
277936
|
+
if (!data2) {
|
|
277937
|
+
log12.debug("skipping custom loader for missing provider", { providerID });
|
|
277938
|
+
continue;
|
|
277939
|
+
}
|
|
277940
|
+
const result6 = await fn5(data2);
|
|
277941
|
+
if (result6 && (result6.autoload || providers2[providerID])) {
|
|
277942
|
+
if (result6.getModel)
|
|
277943
|
+
modelLoaders[providerID] = result6.getModel;
|
|
277944
|
+
const opts = result6.options ?? {};
|
|
277945
|
+
const patch = providers2[providerID] ? { options: opts } : { source: "custom", options: opts };
|
|
277946
|
+
mergeProvider(providerID, patch);
|
|
277947
|
+
}
|
|
277948
|
+
}
|
|
277949
|
+
for (const [providerID, provider] of configProviders) {
|
|
277950
|
+
const partial2 = { source: "config" };
|
|
277951
|
+
if (provider.env)
|
|
277952
|
+
partial2.env = provider.env;
|
|
277953
|
+
if (provider.name)
|
|
277954
|
+
partial2.name = provider.name;
|
|
277955
|
+
if (provider.options)
|
|
277956
|
+
partial2.options = provider.options;
|
|
277957
|
+
mergeProvider(providerID, partial2);
|
|
277958
|
+
}
|
|
277959
|
+
for (const plugin of await Plugin.list()) {
|
|
277960
|
+
if (!plugin.provider?.models)
|
|
277961
|
+
continue;
|
|
277962
|
+
const providerID = plugin.provider.id;
|
|
277963
|
+
const provider = providers2[providerID];
|
|
277964
|
+
if (!provider || !isProviderAllowed(providerID))
|
|
277965
|
+
continue;
|
|
277966
|
+
const models = await plugin.provider.models(provider, { auth: await Auth.get(providerID) });
|
|
277967
|
+
if (models) {
|
|
277968
|
+
provider.models = D2(provider.models, models);
|
|
277969
|
+
}
|
|
277866
277970
|
}
|
|
277867
|
-
const
|
|
277868
|
-
|
|
277869
|
-
|
|
277870
|
-
|
|
277871
|
-
|
|
277872
|
-
|
|
277873
|
-
|
|
277874
|
-
|
|
277875
|
-
|
|
277876
|
-
|
|
277877
|
-
|
|
277878
|
-
|
|
277879
|
-
|
|
277880
|
-
|
|
277881
|
-
|
|
277882
|
-
|
|
277883
|
-
|
|
277884
|
-
|
|
277885
|
-
|
|
277886
|
-
|
|
277887
|
-
|
|
277971
|
+
for (const [providerID, provider] of Object.entries(providers2)) {
|
|
277972
|
+
if (!isProviderAllowed(providerID)) {
|
|
277973
|
+
delete providers2[providerID];
|
|
277974
|
+
continue;
|
|
277975
|
+
}
|
|
277976
|
+
const configProvider = config5.provider?.[providerID];
|
|
277977
|
+
for (const [modelID, model2] of Object.entries(provider.models)) {
|
|
277978
|
+
model2.api.id = model2.api.id ?? model2.id ?? modelID;
|
|
277979
|
+
if (modelID === "gpt-5-chat-latest" || providerID === "openrouter" && modelID === "openai/gpt-5-chat")
|
|
277980
|
+
delete provider.models[modelID];
|
|
277981
|
+
if (model2.status === "alpha" && !Flag.SLOPCODE_ENABLE_EXPERIMENTAL_MODELS)
|
|
277982
|
+
delete provider.models[modelID];
|
|
277983
|
+
if (model2.status === "deprecated")
|
|
277984
|
+
delete provider.models[modelID];
|
|
277985
|
+
if (configProvider?.blacklist && configProvider.blacklist.includes(modelID) || configProvider?.whitelist && !configProvider.whitelist.includes(modelID))
|
|
277986
|
+
delete provider.models[modelID];
|
|
277987
|
+
model2.variants = i4(ProviderTransform.variants(model2), (v4) => v4);
|
|
277988
|
+
const configVariants = configProvider?.models?.[modelID]?.variants;
|
|
277989
|
+
if (configVariants && model2.variants) {
|
|
277990
|
+
const merged = D2(model2.variants, configVariants);
|
|
277991
|
+
model2.variants = i4(d3(merged, (v4) => !v4.disabled), (v4) => y4(v4, ["disabled"]));
|
|
277992
|
+
}
|
|
277993
|
+
}
|
|
277994
|
+
if (Object.keys(provider.models).length === 0) {
|
|
277995
|
+
delete providers2[providerID];
|
|
277996
|
+
continue;
|
|
277997
|
+
}
|
|
277998
|
+
log12.info("found", { providerID });
|
|
277888
277999
|
}
|
|
277889
|
-
|
|
278000
|
+
return {
|
|
278001
|
+
models: languages,
|
|
278002
|
+
providers: providers2,
|
|
278003
|
+
sdk,
|
|
278004
|
+
modelLoaders
|
|
278005
|
+
};
|
|
278006
|
+
} catch (_catch3) {
|
|
278007
|
+
var _err = _catch3, _hasErr = 1;
|
|
278008
|
+
} finally {
|
|
278009
|
+
__callDispose(__stack, _err, _hasErr);
|
|
277890
278010
|
}
|
|
277891
|
-
return {
|
|
277892
|
-
models: languages,
|
|
277893
|
-
providers: providers2,
|
|
277894
|
-
sdk,
|
|
277895
|
-
modelLoaders
|
|
277896
|
-
};
|
|
277897
278011
|
});
|
|
277898
278012
|
async function list() {
|
|
277899
278013
|
return state4().then((state5) => state5.providers);
|
|
@@ -277901,113 +278015,120 @@ var init_provider = __esm(async () => {
|
|
|
277901
278015
|
Provider.list = list;
|
|
277902
278016
|
async function getSDK(model2) {
|
|
277903
278017
|
try {
|
|
277904
|
-
|
|
277905
|
-
|
|
277906
|
-
|
|
277907
|
-
|
|
277908
|
-
|
|
277909
|
-
|
|
277910
|
-
|
|
277911
|
-
|
|
277912
|
-
|
|
277913
|
-
|
|
277914
|
-
|
|
277915
|
-
|
|
277916
|
-
|
|
277917
|
-
|
|
277918
|
-
|
|
277919
|
-
|
|
277920
|
-
|
|
277921
|
-
|
|
277922
|
-
|
|
277923
|
-
|
|
277924
|
-
|
|
277925
|
-
|
|
277926
|
-
|
|
277927
|
-
|
|
277928
|
-
|
|
277929
|
-
|
|
277930
|
-
|
|
277931
|
-
|
|
277932
|
-
const
|
|
277933
|
-
|
|
277934
|
-
|
|
277935
|
-
const
|
|
277936
|
-
if (
|
|
277937
|
-
signals
|
|
277938
|
-
|
|
277939
|
-
|
|
277940
|
-
|
|
277941
|
-
|
|
277942
|
-
|
|
277943
|
-
|
|
277944
|
-
|
|
277945
|
-
if (
|
|
277946
|
-
const
|
|
277947
|
-
|
|
277948
|
-
|
|
277949
|
-
|
|
277950
|
-
|
|
277951
|
-
|
|
277952
|
-
|
|
278018
|
+
let __stack = [];
|
|
278019
|
+
try {
|
|
278020
|
+
const _3 = __using(__stack, log12.time("getSDK", {
|
|
278021
|
+
providerID: model2.providerID
|
|
278022
|
+
}), 0);
|
|
278023
|
+
const s7 = await state4();
|
|
278024
|
+
const provider = s7.providers[model2.providerID];
|
|
278025
|
+
const options2 = { ...provider.options };
|
|
278026
|
+
if (model2.providerID === "google-vertex" && !model2.api.npm.includes("@ai-sdk/openai-compatible")) {
|
|
278027
|
+
delete options2.fetch;
|
|
278028
|
+
}
|
|
278029
|
+
if (model2.api.npm.includes("@ai-sdk/openai-compatible") && options2["includeUsage"] !== false) {
|
|
278030
|
+
options2["includeUsage"] = true;
|
|
278031
|
+
}
|
|
278032
|
+
const baseURL2 = loadBaseURL(model2, options2);
|
|
278033
|
+
if (baseURL2 !== undefined)
|
|
278034
|
+
options2["baseURL"] = baseURL2;
|
|
278035
|
+
if (options2["apiKey"] === undefined && provider.key)
|
|
278036
|
+
options2["apiKey"] = provider.key;
|
|
278037
|
+
if (model2.headers)
|
|
278038
|
+
options2["headers"] = {
|
|
278039
|
+
...options2["headers"],
|
|
278040
|
+
...model2.headers
|
|
278041
|
+
};
|
|
278042
|
+
const key = Bun.hash.xxHash32(JSON.stringify({ providerID: model2.providerID, npm: model2.api.npm, options: options2 }));
|
|
278043
|
+
const existing = s7.sdk.get(key);
|
|
278044
|
+
if (existing)
|
|
278045
|
+
return existing;
|
|
278046
|
+
const customFetch = options2["fetch"];
|
|
278047
|
+
options2["fetch"] = async (input, init3) => {
|
|
278048
|
+
const fetchFn = customFetch ?? fetch;
|
|
278049
|
+
const opts = init3 ?? {};
|
|
278050
|
+
if (options2["timeout"] !== undefined && options2["timeout"] !== null) {
|
|
278051
|
+
const signals = [];
|
|
278052
|
+
if (opts.signal)
|
|
278053
|
+
signals.push(opts.signal);
|
|
278054
|
+
if (options2["timeout"] !== false)
|
|
278055
|
+
signals.push(AbortSignal.timeout(options2["timeout"]));
|
|
278056
|
+
const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
278057
|
+
opts.signal = combined;
|
|
278058
|
+
}
|
|
278059
|
+
if (opts.method === "POST" && typeof opts.body === "string") {
|
|
278060
|
+
const url4 = new URL(input instanceof Request ? input.url : input.toString());
|
|
278061
|
+
if (model2.api.npm === "@ai-sdk/openai") {
|
|
278062
|
+
const body2 = JSON.parse(opts.body);
|
|
278063
|
+
const isAzure = model2.providerID.includes("azure");
|
|
278064
|
+
const keepIds = isAzure && body2.store === true;
|
|
278065
|
+
if (!keepIds && Array.isArray(body2.input)) {
|
|
278066
|
+
for (const item of body2.input) {
|
|
278067
|
+
if ("id" in item) {
|
|
278068
|
+
delete item.id;
|
|
278069
|
+
}
|
|
277953
278070
|
}
|
|
278071
|
+
opts.body = JSON.stringify(body2);
|
|
277954
278072
|
}
|
|
277955
|
-
opts.body = JSON.stringify(body2);
|
|
277956
278073
|
}
|
|
277957
|
-
|
|
277958
|
-
|
|
277959
|
-
|
|
277960
|
-
|
|
277961
|
-
|
|
277962
|
-
|
|
277963
|
-
|
|
277964
|
-
|
|
277965
|
-
|
|
277966
|
-
|
|
277967
|
-
|
|
277968
|
-
|
|
277969
|
-
|
|
277970
|
-
|
|
277971
|
-
|
|
277972
|
-
|
|
278074
|
+
if (LlamaCppSessionCache.isEnabled(provider.options) && (url4.pathname.endsWith("/chat/completions") || url4.pathname.endsWith("/completions"))) {
|
|
278075
|
+
const sessionID = new Headers(opts.headers).get("x-slopcode-session");
|
|
278076
|
+
if (sessionID) {
|
|
278077
|
+
const body2 = JSON.parse(opts.body);
|
|
278078
|
+
const injected = await LlamaCppSessionCache.prepareRequest({
|
|
278079
|
+
sessionID,
|
|
278080
|
+
providerID: model2.providerID,
|
|
278081
|
+
modelID: model2.id,
|
|
278082
|
+
providerOptions: provider.options,
|
|
278083
|
+
baseURL: String(baseURL2 ?? model2.api.url),
|
|
278084
|
+
fetch: fetchFn,
|
|
278085
|
+
signal: opts.signal ?? undefined
|
|
278086
|
+
});
|
|
278087
|
+
if (injected) {
|
|
278088
|
+
opts.body = JSON.stringify({ ...body2, ...injected });
|
|
278089
|
+
}
|
|
277973
278090
|
}
|
|
277974
278091
|
}
|
|
277975
278092
|
}
|
|
278093
|
+
const response = await fetchFn(input, {
|
|
278094
|
+
...opts,
|
|
278095
|
+
timeout: false
|
|
278096
|
+
});
|
|
278097
|
+
if (response.ok) {
|
|
278098
|
+
ProviderLimit.capture(response.headers);
|
|
278099
|
+
}
|
|
278100
|
+
return response;
|
|
278101
|
+
};
|
|
278102
|
+
const bundledFn = BUNDLED_PROVIDERS[model2.api.npm];
|
|
278103
|
+
if (bundledFn) {
|
|
278104
|
+
log12.info("using bundled provider", { providerID: model2.providerID, pkg: model2.api.npm });
|
|
278105
|
+
const loaded2 = bundledFn({
|
|
278106
|
+
name: model2.providerID,
|
|
278107
|
+
...options2
|
|
278108
|
+
});
|
|
278109
|
+
s7.sdk.set(key, loaded2);
|
|
278110
|
+
return loaded2;
|
|
277976
278111
|
}
|
|
277977
|
-
|
|
277978
|
-
|
|
277979
|
-
|
|
277980
|
-
}
|
|
277981
|
-
|
|
277982
|
-
|
|
278112
|
+
let installedPath;
|
|
278113
|
+
if (!model2.api.npm.startsWith("file://")) {
|
|
278114
|
+
installedPath = await BunProc.install(model2.api.npm, "latest");
|
|
278115
|
+
} else {
|
|
278116
|
+
log12.info("loading local provider", { pkg: model2.api.npm });
|
|
278117
|
+
installedPath = model2.api.npm;
|
|
277983
278118
|
}
|
|
277984
|
-
|
|
277985
|
-
|
|
277986
|
-
|
|
277987
|
-
if (bundledFn) {
|
|
277988
|
-
log12.info("using bundled provider", { providerID: model2.providerID, pkg: model2.api.npm });
|
|
277989
|
-
const loaded2 = bundledFn({
|
|
278119
|
+
const mod2 = await import(installedPath);
|
|
278120
|
+
const fn5 = mod2[Object.keys(mod2).find((key2) => key2.startsWith("create"))];
|
|
278121
|
+
const loaded = fn5({
|
|
277990
278122
|
name: model2.providerID,
|
|
277991
278123
|
...options2
|
|
277992
278124
|
});
|
|
277993
|
-
s7.sdk.set(key,
|
|
277994
|
-
return
|
|
277995
|
-
}
|
|
277996
|
-
|
|
277997
|
-
|
|
277998
|
-
|
|
277999
|
-
} else {
|
|
278000
|
-
log12.info("loading local provider", { pkg: model2.api.npm });
|
|
278001
|
-
installedPath = model2.api.npm;
|
|
278125
|
+
s7.sdk.set(key, loaded);
|
|
278126
|
+
return loaded;
|
|
278127
|
+
} catch (_catch3) {
|
|
278128
|
+
var _err = _catch3, _hasErr = 1;
|
|
278129
|
+
} finally {
|
|
278130
|
+
__callDispose(__stack, _err, _hasErr);
|
|
278002
278131
|
}
|
|
278003
|
-
const mod2 = await import(installedPath);
|
|
278004
|
-
const fn5 = mod2[Object.keys(mod2).find((key2) => key2.startsWith("create"))];
|
|
278005
|
-
const loaded = fn5({
|
|
278006
|
-
name: model2.providerID,
|
|
278007
|
-
...options2
|
|
278008
|
-
});
|
|
278009
|
-
s7.sdk.set(key, loaded);
|
|
278010
|
-
return loaded;
|
|
278011
278132
|
} catch (e5) {
|
|
278012
278133
|
throw new Provider.InitError({ providerID: model2.providerID }, { cause: e5 });
|
|
278013
278134
|
}
|
|
@@ -278292,7 +278413,8 @@ function createSurfaceManifest(input = {}) {
|
|
|
278292
278413
|
version: TUI_SURFACE_VERSION,
|
|
278293
278414
|
renderer: {
|
|
278294
278415
|
linux: "opentui/solid",
|
|
278295
|
-
android: "ratatui/crossterm"
|
|
278416
|
+
android: "ratatui/crossterm",
|
|
278417
|
+
frame: "shared/terminal-frame"
|
|
278296
278418
|
},
|
|
278297
278419
|
capabilities: {
|
|
278298
278420
|
"android.runtime": input.android ?? false,
|
|
@@ -278429,7 +278551,166 @@ function createSurfaceSnapshot(input) {
|
|
|
278429
278551
|
}
|
|
278430
278552
|
};
|
|
278431
278553
|
}
|
|
278432
|
-
|
|
278554
|
+
function cellWidth(char2) {
|
|
278555
|
+
const code = char2.codePointAt(0) ?? 0;
|
|
278556
|
+
if (code === 0)
|
|
278557
|
+
return 0;
|
|
278558
|
+
if (code < 32 || code >= 127 && code < 160)
|
|
278559
|
+
return 0;
|
|
278560
|
+
return code >= 4352 ? 2 : 1;
|
|
278561
|
+
}
|
|
278562
|
+
function visibleWidth(text11) {
|
|
278563
|
+
let width = 0;
|
|
278564
|
+
for (const char2 of text11)
|
|
278565
|
+
width += cellWidth(char2);
|
|
278566
|
+
return width;
|
|
278567
|
+
}
|
|
278568
|
+
function fit(text11, width) {
|
|
278569
|
+
if (width <= 0)
|
|
278570
|
+
return "";
|
|
278571
|
+
let out2 = "";
|
|
278572
|
+
let size24 = 0;
|
|
278573
|
+
for (const char2 of text11.replace(/\s+/g, " ")) {
|
|
278574
|
+
const next4 = cellWidth(char2);
|
|
278575
|
+
if (size24 + next4 > width)
|
|
278576
|
+
break;
|
|
278577
|
+
out2 += char2;
|
|
278578
|
+
size24 += next4;
|
|
278579
|
+
}
|
|
278580
|
+
return out2 + " ".repeat(Math.max(0, width - size24));
|
|
278581
|
+
}
|
|
278582
|
+
function wrap2(text11, width) {
|
|
278583
|
+
if (width <= 0)
|
|
278584
|
+
return [""];
|
|
278585
|
+
const words = text11.split(/\s+/).filter(Boolean);
|
|
278586
|
+
if (words.length === 0)
|
|
278587
|
+
return [""];
|
|
278588
|
+
const lines = [];
|
|
278589
|
+
let line2 = "";
|
|
278590
|
+
for (const word of words) {
|
|
278591
|
+
const candidate = line2 ? `${line2} ${word}` : word;
|
|
278592
|
+
if (visibleWidth(candidate) <= width) {
|
|
278593
|
+
line2 = candidate;
|
|
278594
|
+
continue;
|
|
278595
|
+
}
|
|
278596
|
+
if (line2)
|
|
278597
|
+
lines.push(line2);
|
|
278598
|
+
if (visibleWidth(word) <= width) {
|
|
278599
|
+
line2 = word;
|
|
278600
|
+
continue;
|
|
278601
|
+
}
|
|
278602
|
+
let chunk = "";
|
|
278603
|
+
let size24 = 0;
|
|
278604
|
+
for (const char2 of word) {
|
|
278605
|
+
const next4 = cellWidth(char2);
|
|
278606
|
+
if (size24 + next4 > width) {
|
|
278607
|
+
lines.push(chunk);
|
|
278608
|
+
chunk = "";
|
|
278609
|
+
size24 = 0;
|
|
278610
|
+
}
|
|
278611
|
+
chunk += char2;
|
|
278612
|
+
size24 += next4;
|
|
278613
|
+
}
|
|
278614
|
+
line2 = chunk;
|
|
278615
|
+
}
|
|
278616
|
+
if (line2)
|
|
278617
|
+
lines.push(line2);
|
|
278618
|
+
return lines;
|
|
278619
|
+
}
|
|
278620
|
+
function clampDimension(value8, fallback, min13, max13) {
|
|
278621
|
+
if (!Number.isFinite(value8))
|
|
278622
|
+
return fallback;
|
|
278623
|
+
return Math.max(min13, Math.min(max13, Math.floor(value8)));
|
|
278624
|
+
}
|
|
278625
|
+
function tabLine(snapshot4) {
|
|
278626
|
+
const tabs = snapshot4.tabs.length ? snapshot4.tabs.map((item) => `${item.active ? "[*]" : "[ ]"} ${item.title} ${item.status}`).join(" ") : "[ ] new session idle";
|
|
278627
|
+
return tabs;
|
|
278628
|
+
}
|
|
278629
|
+
function transcriptLines(snapshot4, width) {
|
|
278630
|
+
const lines = [];
|
|
278631
|
+
if (snapshot4.transcript.length === 0) {
|
|
278632
|
+
lines.push("Start a conversation or type /help for commands.");
|
|
278633
|
+
return lines;
|
|
278634
|
+
}
|
|
278635
|
+
for (const message of snapshot4.transcript) {
|
|
278636
|
+
const label = message.role === "user" ? "You" : "Assistant";
|
|
278637
|
+
if (message.text)
|
|
278638
|
+
lines.push(...wrap2(`${label}: ${message.text}`, width));
|
|
278639
|
+
for (const tool3 of message.tools) {
|
|
278640
|
+
lines.push(...wrap2(`tool ${tool3.tool} ${tool3.status}`, width));
|
|
278641
|
+
for (const row of tool3.preview)
|
|
278642
|
+
lines.push(...wrap2(`output ${row}`, width));
|
|
278643
|
+
for (const row of tool3.diff)
|
|
278644
|
+
lines.push(...wrap2(`diff ${row}`, width));
|
|
278645
|
+
if (tool3.expandable)
|
|
278646
|
+
lines.push("more output available");
|
|
278647
|
+
}
|
|
278648
|
+
if (message.text || message.tools.length > 0)
|
|
278649
|
+
lines.push("");
|
|
278650
|
+
}
|
|
278651
|
+
while (lines.at(-1) === "")
|
|
278652
|
+
lines.pop();
|
|
278653
|
+
return lines.length ? lines : ["No transcript yet."];
|
|
278654
|
+
}
|
|
278655
|
+
function sidebarLines(snapshot4, width) {
|
|
278656
|
+
const title = snapshot4.sidebar.mode === "files" ? "Files" : "Modified Files";
|
|
278657
|
+
const rows = snapshot4.sidebar.rows.length ? snapshot4.sidebar.rows : ["No changed files"];
|
|
278658
|
+
return [title, ...rows.flatMap((row) => wrap2(row, width))];
|
|
278659
|
+
}
|
|
278660
|
+
function createSurfaceFrame(input) {
|
|
278661
|
+
const width = clampDimension(input.width, 80, 20, 240);
|
|
278662
|
+
const height = clampDimension(input.height, 24, 8, 100);
|
|
278663
|
+
const snapshot4 = input.snapshot;
|
|
278664
|
+
const header = `SlopCode | ${snapshot4.header.title} | ${snapshot4.status}`;
|
|
278665
|
+
const footer = [
|
|
278666
|
+
snapshot4.footer.directory,
|
|
278667
|
+
snapshot4.footer.workspaceID ? `workspace ${snapshot4.footer.workspaceID}` : undefined,
|
|
278668
|
+
`lsp ${snapshot4.footer.lsp}`,
|
|
278669
|
+
`mcp ${snapshot4.footer.mcp}${snapshot4.footer.mcpFailed ? "!" : ""}`,
|
|
278670
|
+
snapshot4.footer.permissions ? `perm ${snapshot4.footer.permissions}` : undefined
|
|
278671
|
+
].filter(Boolean).join(" | ");
|
|
278672
|
+
const prompt = "> ";
|
|
278673
|
+
const bodyHeight = Math.max(1, height - 4);
|
|
278674
|
+
const useSidebar = width >= 90;
|
|
278675
|
+
const body2 = [];
|
|
278676
|
+
if (useSidebar) {
|
|
278677
|
+
const sidebarWidth = Math.min(32, Math.max(24, Math.floor(width * 0.3)));
|
|
278678
|
+
const mainWidth = width - sidebarWidth - 3;
|
|
278679
|
+
const main = transcriptLines(snapshot4, mainWidth);
|
|
278680
|
+
const side = sidebarLines(snapshot4, sidebarWidth);
|
|
278681
|
+
for (let index3 = 0;index3 < bodyHeight; index3++) {
|
|
278682
|
+
body2.push(`${fit(main[index3] ?? "", mainWidth)} | ${fit(side[index3] ?? "", sidebarWidth)}`);
|
|
278683
|
+
}
|
|
278684
|
+
} else {
|
|
278685
|
+
const main = [...transcriptLines(snapshot4, width), "", ...sidebarLines(snapshot4, width)];
|
|
278686
|
+
for (let index3 = 0;index3 < bodyHeight; index3++)
|
|
278687
|
+
body2.push(fit(main[index3] ?? "", width));
|
|
278688
|
+
}
|
|
278689
|
+
const lines = [
|
|
278690
|
+
fit(header, width),
|
|
278691
|
+
fit(tabLine(snapshot4), width),
|
|
278692
|
+
...body2,
|
|
278693
|
+
fit(prompt, width),
|
|
278694
|
+
fit(footer, width)
|
|
278695
|
+
].slice(0, height);
|
|
278696
|
+
while (lines.length < height)
|
|
278697
|
+
lines.push(" ".repeat(width));
|
|
278698
|
+
return {
|
|
278699
|
+
version: TUI_SURFACE_VERSION,
|
|
278700
|
+
renderer: "shared/terminal-frame",
|
|
278701
|
+
width,
|
|
278702
|
+
height,
|
|
278703
|
+
sessionID: snapshot4.sessionID,
|
|
278704
|
+
title: snapshot4.title,
|
|
278705
|
+
status: snapshot4.status,
|
|
278706
|
+
lines,
|
|
278707
|
+
rows: lines.map((line2, y6) => ({
|
|
278708
|
+
y: y6,
|
|
278709
|
+
spans: [{ x: 0, text: line2 }]
|
|
278710
|
+
}))
|
|
278711
|
+
};
|
|
278712
|
+
}
|
|
278713
|
+
var TUI_SURFACE_VERSION = 2, TuiSurfaceCommand, TuiSurfaceManifest, TuiSurfaceAction, TuiSurfaceSnapshot, TuiSurfaceFrameStyle, TuiSurfaceFrameSpan, TuiSurfaceFrame, command = (input) => input, surfaceCommands;
|
|
278433
278714
|
var init_surface = __esm(async () => {
|
|
278434
278715
|
init_zod();
|
|
278435
278716
|
init_keybind();
|
|
@@ -278451,7 +278732,8 @@ var init_surface = __esm(async () => {
|
|
|
278451
278732
|
version: zod_default.literal(TUI_SURFACE_VERSION),
|
|
278452
278733
|
renderer: zod_default.object({
|
|
278453
278734
|
linux: zod_default.literal("opentui/solid"),
|
|
278454
|
-
android: zod_default.literal("ratatui/crossterm")
|
|
278735
|
+
android: zod_default.literal("ratatui/crossterm"),
|
|
278736
|
+
frame: zod_default.literal("shared/terminal-frame")
|
|
278455
278737
|
}),
|
|
278456
278738
|
capabilities: zod_default.record(zod_default.string(), zod_default.boolean()),
|
|
278457
278739
|
commands: TuiSurfaceCommand.array(),
|
|
@@ -278559,6 +278841,33 @@ var init_surface = __esm(async () => {
|
|
|
278559
278841
|
rows: zod_default.string().array()
|
|
278560
278842
|
})
|
|
278561
278843
|
});
|
|
278844
|
+
TuiSurfaceFrameStyle = zod_default.object({
|
|
278845
|
+
fg: zod_default.string().optional(),
|
|
278846
|
+
bg: zod_default.string().optional(),
|
|
278847
|
+
bold: zod_default.boolean().optional(),
|
|
278848
|
+
dim: zod_default.boolean().optional(),
|
|
278849
|
+
underline: zod_default.boolean().optional(),
|
|
278850
|
+
reverse: zod_default.boolean().optional()
|
|
278851
|
+
});
|
|
278852
|
+
TuiSurfaceFrameSpan = zod_default.object({
|
|
278853
|
+
x: zod_default.number(),
|
|
278854
|
+
text: zod_default.string(),
|
|
278855
|
+
style: TuiSurfaceFrameStyle.optional()
|
|
278856
|
+
});
|
|
278857
|
+
TuiSurfaceFrame = zod_default.object({
|
|
278858
|
+
version: zod_default.literal(TUI_SURFACE_VERSION),
|
|
278859
|
+
renderer: zod_default.literal("shared/terminal-frame"),
|
|
278860
|
+
width: zod_default.number(),
|
|
278861
|
+
height: zod_default.number(),
|
|
278862
|
+
sessionID: zod_default.string().optional(),
|
|
278863
|
+
title: zod_default.string(),
|
|
278864
|
+
status: zod_default.string(),
|
|
278865
|
+
lines: zod_default.string().array(),
|
|
278866
|
+
rows: zod_default.object({
|
|
278867
|
+
y: zod_default.number(),
|
|
278868
|
+
spans: TuiSurfaceFrameSpan.array()
|
|
278869
|
+
}).array()
|
|
278870
|
+
});
|
|
278562
278871
|
surfaceCommands = [
|
|
278563
278872
|
command({
|
|
278564
278873
|
id: "help.show",
|
|
@@ -279336,6 +279645,32 @@ var init_tui2 = __esm(async () => {
|
|
|
279336
279645
|
sessionID: zod_default.string().optional()
|
|
279337
279646
|
})), async (c4) => {
|
|
279338
279647
|
return c4.json(await snapshot4(c4.req.valid("query").sessionID));
|
|
279648
|
+
}).get("/frame", describeRoute({
|
|
279649
|
+
summary: "Get shared TUI terminal frame",
|
|
279650
|
+
description: "Return a deterministic terminal-cell frame that native renderers can paint exactly across Linux and Android.",
|
|
279651
|
+
operationId: "tui.frame",
|
|
279652
|
+
responses: {
|
|
279653
|
+
200: {
|
|
279654
|
+
description: "Shared TUI terminal frame",
|
|
279655
|
+
content: {
|
|
279656
|
+
"application/json": {
|
|
279657
|
+
schema: resolver(TuiSurfaceFrame)
|
|
279658
|
+
}
|
|
279659
|
+
}
|
|
279660
|
+
},
|
|
279661
|
+
...errors6(400, 404)
|
|
279662
|
+
}
|
|
279663
|
+
}), validator2("query", zod_default.object({
|
|
279664
|
+
sessionID: zod_default.string().optional(),
|
|
279665
|
+
width: zod_default.coerce.number().optional(),
|
|
279666
|
+
height: zod_default.coerce.number().optional()
|
|
279667
|
+
})), async (c4) => {
|
|
279668
|
+
const query2 = c4.req.valid("query");
|
|
279669
|
+
return c4.json(createSurfaceFrame({
|
|
279670
|
+
snapshot: await snapshot4(query2.sessionID),
|
|
279671
|
+
width: query2.width ?? 80,
|
|
279672
|
+
height: query2.height ?? 24
|
|
279673
|
+
}));
|
|
279339
279674
|
}).post("/action", describeRoute({
|
|
279340
279675
|
summary: "Dispatch shared TUI action",
|
|
279341
279676
|
description: "Dispatch a typed action from a native TUI renderer through the shared TUI surface contract.",
|
|
@@ -281229,7 +281564,7 @@ var CAPTURING_REGEX_SOURCE, RegexSource = class {
|
|
|
281229
281564
|
let localIncludedRule = repository[reference.ruleName];
|
|
281230
281565
|
if (localIncludedRule) {
|
|
281231
281566
|
ruleId = _RuleFactory.getCompiledRuleId(localIncludedRule, helper, repository);
|
|
281232
|
-
}
|
|
281567
|
+
} else {}
|
|
281233
281568
|
break;
|
|
281234
281569
|
case 3:
|
|
281235
281570
|
case 4:
|
|
@@ -281241,11 +281576,11 @@ var CAPTURING_REGEX_SOURCE, RegexSource = class {
|
|
|
281241
281576
|
let externalIncludedRule = externalGrammar.repository[externalGrammarInclude];
|
|
281242
281577
|
if (externalIncludedRule) {
|
|
281243
281578
|
ruleId = _RuleFactory.getCompiledRuleId(externalIncludedRule, helper, externalGrammar.repository);
|
|
281244
|
-
}
|
|
281579
|
+
} else {}
|
|
281245
281580
|
} else {
|
|
281246
281581
|
ruleId = _RuleFactory.getCompiledRuleId(externalGrammar.repository.$self, helper, externalGrammar.repository);
|
|
281247
281582
|
}
|
|
281248
|
-
}
|
|
281583
|
+
} else {}
|
|
281249
281584
|
break;
|
|
281250
281585
|
}
|
|
281251
281586
|
} else {
|
|
@@ -300492,12 +300827,19 @@ var init_config3 = __esm(async () => {
|
|
|
300492
300827
|
}
|
|
300493
300828
|
}
|
|
300494
300829
|
}), async (c4) => {
|
|
300495
|
-
|
|
300496
|
-
|
|
300497
|
-
|
|
300498
|
-
|
|
300499
|
-
|
|
300500
|
-
|
|
300830
|
+
let __stack = [];
|
|
300831
|
+
try {
|
|
300832
|
+
const _3 = __using(__stack, log18.time("providers"), 0);
|
|
300833
|
+
const providers2 = await Provider2.list().then((x4) => i4(x4, (item) => item));
|
|
300834
|
+
return c4.json({
|
|
300835
|
+
providers: Object.values(providers2),
|
|
300836
|
+
default: i4(providers2, (item) => Provider2.sort(Object.values(item.models))[0].id)
|
|
300837
|
+
});
|
|
300838
|
+
} catch (_catch3) {
|
|
300839
|
+
var _err = _catch3, _hasErr = 1;
|
|
300840
|
+
} finally {
|
|
300841
|
+
__callDispose(__stack, _err, _hasErr);
|
|
300842
|
+
}
|
|
300501
300843
|
}));
|
|
300502
300844
|
});
|
|
300503
300845
|
|
|
@@ -308501,6 +308843,23 @@ var init_sdk_gen2 = __esm(() => {
|
|
|
308501
308843
|
...params
|
|
308502
308844
|
});
|
|
308503
308845
|
}
|
|
308846
|
+
frame(parameters5, options2) {
|
|
308847
|
+
const params = buildClientParams2([parameters5], [
|
|
308848
|
+
{
|
|
308849
|
+
args: [
|
|
308850
|
+
{ in: "query", key: "directory" },
|
|
308851
|
+
{ in: "query", key: "sessionID" },
|
|
308852
|
+
{ in: "query", key: "width" },
|
|
308853
|
+
{ in: "query", key: "height" }
|
|
308854
|
+
]
|
|
308855
|
+
}
|
|
308856
|
+
]);
|
|
308857
|
+
return (options2?.client ?? this.client).get({
|
|
308858
|
+
url: "/tui/frame",
|
|
308859
|
+
...options2,
|
|
308860
|
+
...params
|
|
308861
|
+
});
|
|
308862
|
+
}
|
|
308504
308863
|
action(parameters5, options2) {
|
|
308505
308864
|
const params = buildClientParams2([parameters5], [
|
|
308506
308865
|
{
|