bazilion 0.58.2 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +16 -1
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +391 -114
- package/dist/daemon.js.map +1 -1
- package/dist/web/client/assets/AddProviderDialog-PK8ZRkVP.js +1 -0
- package/dist/web/client/assets/{AgentTemplateParts-BaeuW_3n.js → AgentTemplateParts-DXqswWc_.js} +1 -1
- package/dist/web/client/assets/{ConfirmDialog-D8f2wI5x.js → ConfirmDialog-C7Id43en.js} +1 -1
- package/dist/web/client/assets/{ConnectionsView-BUZcfBHw.js → ConnectionsView-sCcb1DqZ.js} +1 -1
- package/dist/web/client/assets/{SkillsParts-jMYdOiWh.js → SkillsParts-ClIFyTi8.js} +1 -1
- package/dist/web/client/assets/{SpawnTeamModal-Dq7D3Zlc.js → SpawnTeamModal-BxRg6e3v.js} +1 -1
- package/dist/web/client/assets/{TeamForm-Crz3mvXu.js → TeamForm-e_yDks2o.js} +1 -1
- package/dist/web/client/assets/{TeamThread-qTkvxv27.js → TeamThread-BFz7jkrt.js} +1 -1
- package/dist/web/client/assets/{UnsavedChangesGuard-DGzP-x1t.js → UnsavedChangesGuard-Cgc9WraN.js} +1 -1
- package/dist/web/client/assets/{_id-DsZBpW5G.js → _id-C24VHwwo.js} +1 -1
- package/dist/web/client/assets/{_id-CiqTBi2Q.js → _id-DeCenuG4.js} +1 -1
- package/dist/web/client/assets/{access-ssWsYTEU.js → access-Dh3w6dHo.js} +1 -1
- package/dist/web/client/assets/{agents-BmkaQvWh.js → agents-CUQ-DKWA.js} +1 -1
- package/dist/web/client/assets/{agents-D3tZ58Dh.js → agents-DHTN7twQ.js} +1 -1
- package/dist/web/client/assets/{attention-ChHdu7E8.js → attention-pzVO90iq.js} +1 -1
- package/dist/web/client/assets/{config-DPsq6Zy9.js → config-B29EfkVV.js} +1 -1
- package/dist/web/client/assets/{index-CVVVmIFC.js → index-B8Bft71n.js} +3 -3
- package/dist/web/client/assets/{login-B-Kpyw9o.js → login-CUACsY1J.js} +1 -1
- package/dist/web/client/assets/{manage-Dwe9yQl9.js → manage-DrwsI5ur.js} +1 -1
- package/dist/web/client/assets/{mcp-73AMOCv3.js → mcp-DFBkafUW.js} +1 -1
- package/dist/web/client/assets/routes-DPz6Wrxz.js +85 -0
- package/dist/web/client/assets/{skills-DmYDuDbl.js → skills-B0khtQXg.js} +1 -1
- package/dist/web/client/assets/{style-B9Vy-99n.js → style-BEcLEdJR.js} +1 -1
- package/dist/web/client/assets/styles-B-X0olFi.css +2 -0
- package/dist/web/client/assets/{system-t9hcqYBg.js → system-DexaXrV1.js} +1 -1
- package/dist/web/client/assets/{teams-5B2cyDin.js → teams-CUgnrqA5.js} +1 -1
- package/dist/web/client/assets/{teams-Nk_bHpr0.js → teams-DC-abyJ_.js} +1 -1
- package/dist/web/client/assets/telegram-DlnKiJP1.js +1 -0
- package/dist/web/client/assets/{tools-mdAuMsYJ.js → tools-BefW81ig.js} +1 -1
- package/dist/web/client/assets/{usage-CWu7R8ZD.js → usage-oJ-ACG85.js} +1 -1
- package/dist/web/client/assets/{welcome-BuRNFxpc.js → welcome-BzesXAyM.js} +1 -1
- package/dist/web/server/assets/{AddProviderDialog-Bqsz5NaL.js → AddProviderDialog-CxwjFPVY.js} +3 -3
- package/dist/web/server/assets/{AgentTemplateParts-D97gKNdN.js → AgentTemplateParts-CDDoX_bG.js} +5 -5
- package/dist/web/server/assets/{ConfigPage-CrxctbtN.js → ConfigPage-DwbP35aS.js} +2 -2
- package/dist/web/server/assets/{ConfirmDialog-CuD5HXTw.js → ConfirmDialog-CR_DTRpW.js} +1 -1
- package/dist/web/server/assets/{ConnectionsView-CSf83J-v.js → ConnectionsView-HoyHjzrZ.js} +6 -6
- package/dist/web/server/assets/{Dialog-CwAfaXpM.js → Dialog-B2ZAk0JC.js} +1 -1
- package/dist/web/server/assets/{ManagePage-DGYNJ6XG.js → ManagePage-DSzEP6tP.js} +2 -2
- package/dist/web/server/assets/{ModelMenu-DEJoYASj.js → ModelMenu-BgIvpkO0.js} +1 -1
- package/dist/web/server/assets/{SectionTabs--vMBvaUz.js → SectionTabs-B56iIxRj.js} +1 -1
- package/dist/web/server/assets/{SkillsParts-hjS9a_Ht.js → SkillsParts-Bf5aGuER.js} +5 -5
- package/dist/web/server/assets/{SpawnDialog-BjVZl7xK.js → SpawnDialog-Fsdom-ur.js} +4 -4
- package/dist/web/server/assets/{SpawnTeamModal-BmBXqfFi.js → SpawnTeamModal-Zz03rkBZ.js} +4 -4
- package/dist/web/server/assets/{TeamForm-B4702hBg.js → TeamForm-DwXwjZWb.js} +4 -4
- package/dist/web/server/assets/{TeamThread-BGl5z8_I.js → TeamThread-Be_seq83.js} +1 -1
- package/dist/web/server/assets/{UnsavedChangesGuard-Be8EqfV_.js → UnsavedChangesGuard-BEtAdwza.js} +1 -1
- package/dist/web/server/assets/{_id-VqiN2zRR.js → _id-D1USZSkO.js} +9 -9
- package/dist/web/server/assets/{_id-BWtcQovD.js → _id-Dkx7QsM_.js} +1 -1
- package/dist/web/server/assets/{_id-DBhvSxVl.js → _id-R5F7ISnu.js} +1 -1
- package/dist/web/server/assets/{_id-TT_ZsaSc.js → _id-gh-ba9YO.js} +10 -10
- package/dist/web/server/assets/{_id-CKBQM7LH.js → _id-sS3ozDuV.js} +1 -1
- package/dist/web/server/assets/{_tanstack-start-manifest_v-gHDkHqeS.js → _tanstack-start-manifest_v-CEGe-Ovy.js} +57 -57
- package/dist/web/server/assets/{access-Bog7dbtP.js → access-BcKK4G_w.js} +1 -1
- package/dist/web/server/assets/{access-C5lXP5JS.js → access-CftAsKX6.js} +5 -5
- package/dist/web/server/assets/{activity-Czfq-5_F.js → activity-Dy1HUqjo.js} +13 -0
- package/dist/web/server/assets/{agents-DDUHE3eY.js → agents-BAlP1gc_.js} +8 -8
- package/dist/web/server/assets/{agents-8XZAjHh0.js → agents-BBQyhQz7.js} +7 -7
- package/dist/web/server/assets/{agents-Co6S2Ml9.js → agents-Bgo3LnIL.js} +1 -1
- package/dist/web/server/assets/{agents-BepbikC0.js → agents-CSMQtQCr.js} +1 -1
- package/dist/web/server/assets/{agents-DnUK-7qJ.js → agents-CvU8ljqt.js} +1 -1
- package/dist/web/server/assets/{agents-CKkMouJX.js → agents-DlxkPC-q.js} +1 -1
- package/dist/web/server/assets/{attention-n8edCJBL.js → attention-CHqUjESP.js} +5 -5
- package/dist/web/server/assets/{attention--1dBWt0c.js → attention-rfqLfyDE.js} +1 -1
- package/dist/web/server/assets/{config-BpwsF11b.js → config-CraGjaZB.js} +1 -1
- package/dist/web/server/assets/{config-UHRqSrh4.js → config-DSBJKiDX.js} +7 -7
- package/dist/web/server/assets/{form-Bwsyt9OY.js → form-BGif16IN.js} +2 -2
- package/dist/web/server/assets/{manage-C7ss0xG5.js → manage-CfDQUV7j.js} +1 -1
- package/dist/web/server/assets/{mcp-CUoF4jIO.js → mcp-RKq9Cj-h.js} +6 -6
- package/dist/web/server/assets/{mcp-COn047tO.js → mcp-VCW2SGMk.js} +1 -1
- package/dist/web/server/assets/{parts-B0wbj_yK.js → parts-BpwHijPN.js} +1 -1
- package/dist/web/server/assets/{router-yEsciAts.js → router-CE6lnn8Z.js} +22 -22
- package/dist/web/server/assets/{routes-CjtC0rDs.js → routes-B0oBIDOC.js} +1 -1
- package/dist/web/server/assets/{routes-BgjikzXy.js → routes-BYmi9O0B.js} +2 -0
- package/dist/web/server/assets/{routes-Bfkccvfb.js → routes-Ci6C5w_N.js} +240 -93
- package/dist/web/server/assets/{skills-D5oN5ehC.js → skills-DM_Qcvqk.js} +7 -7
- package/dist/web/server/assets/{skills-DouMCq_2.js → skills-DZI56DdW.js} +1 -1
- package/dist/web/server/assets/{style-BgFXDhAR.js → style-DuiMhwn4.js} +1 -1
- package/dist/web/server/assets/{system-4WV2pOS4.js → system-Bx-_Vfss.js} +1 -1
- package/dist/web/server/assets/{system-DtGHi7X7.js → system-C_kmuned.js} +3 -3
- package/dist/web/server/assets/{teams-BnsbH4YW.js → teams-BL_lLFPd.js} +8 -8
- package/dist/web/server/assets/{teams-Blfyu8ej.js → teams-Bd6J6rHj.js} +1 -1
- package/dist/web/server/assets/{teams-QVxXJfo7.js → teams-CRGLRUp9.js} +1 -1
- package/dist/web/server/assets/{teams-gzY3tOtu.js → teams-fQEKru2G.js} +7 -7
- package/dist/web/server/assets/{telegram-CIbuQ5-U.js → telegram-CpHjomwG.js} +1 -1
- package/dist/web/server/assets/{telegram-Ctj5dqvs.js → telegram-Do0oUOXQ.js} +6 -6
- package/dist/web/server/assets/{tools-x_DQTQtE.js → tools-CMXn8htp.js} +5 -5
- package/dist/web/server/assets/{tools-Dn6RnOFu.js → tools-Ctckgev8.js} +1 -1
- package/dist/web/server/assets/{usage-CeiyPffw.js → usage-DaV-iwEz.js} +1 -1
- package/dist/web/server/assets/{usage-Dsi2V9Wh.js → usage-sZ4SFz36.js} +3 -3
- package/dist/web/server/assets/{welcome-C71pZOQ9.js → welcome-BhfLQBOr.js} +1 -1
- package/dist/web/server/assets/{welcome-A2Koo4HI.js → welcome-Dz5zfvV2.js} +3 -3
- package/dist/web/server/server.js +6 -6
- package/dist/worker.js +224 -26
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/web/client/assets/AddProviderDialog-BsUXLr-m.js +0 -1
- package/dist/web/client/assets/routes-Lj8n-RF7.js +0 -85
- package/dist/web/client/assets/styles-DyFDuWBI.css +0 -2
- package/dist/web/client/assets/telegram-BWfL_OIt.js +0 -1
package/dist/daemon.js
CHANGED
|
@@ -728,6 +728,7 @@ var init_ssrf = __esm({
|
|
|
728
728
|
|
|
729
729
|
// ../daemon/src/lib/browser/attach.ts
|
|
730
730
|
import { readFileSync as readFileSync7 } from "node:fs";
|
|
731
|
+
import { rm } from "node:fs/promises";
|
|
731
732
|
import { connect as connect2 } from "node:net";
|
|
732
733
|
import { homedir as homedir2 } from "node:os";
|
|
733
734
|
import { join as join11 } from "node:path";
|
|
@@ -793,6 +794,7 @@ async function openConnection(url) {
|
|
|
793
794
|
try {
|
|
794
795
|
browser = await chromium.connectOverCDP(target.endpoint, {
|
|
795
796
|
timeout: CONNECT_MS,
|
|
797
|
+
noDefaults: true,
|
|
796
798
|
...url ? {} : { isLocal: true }
|
|
797
799
|
});
|
|
798
800
|
} catch (error) {
|
|
@@ -807,7 +809,32 @@ async function openConnection(url) {
|
|
|
807
809
|
});
|
|
808
810
|
throw new Error(`${target.name} has no browser window to work in`);
|
|
809
811
|
}
|
|
810
|
-
|
|
812
|
+
const agentFrames = /* @__PURE__ */ new Map();
|
|
813
|
+
try {
|
|
814
|
+
await refuseAgentDownloads(browser, agentFrames);
|
|
815
|
+
} catch (error) {
|
|
816
|
+
await browser.close().catch(() => {
|
|
817
|
+
});
|
|
818
|
+
throw error;
|
|
819
|
+
}
|
|
820
|
+
return { browser, context, agentFrames };
|
|
821
|
+
}
|
|
822
|
+
async function refuseAgentDownloads(browser, agentFrames) {
|
|
823
|
+
const cdp = await browser.newBrowserCDPSession();
|
|
824
|
+
const refused = /* @__PURE__ */ new Set();
|
|
825
|
+
cdp.on("Browser.downloadWillBegin", ({ guid, frameId }) => {
|
|
826
|
+
if (![...agentFrames.values()].some((frames) => frames.has(frameId))) return;
|
|
827
|
+
refused.add(guid);
|
|
828
|
+
cdp.send("Browser.cancelDownload", { guid }).catch(() => {
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
cdp.on("Browser.downloadProgress", ({ guid, state: state2, filePath }) => {
|
|
832
|
+
if (!refused.has(guid) || state2 === "inProgress") return;
|
|
833
|
+
refused.delete(guid);
|
|
834
|
+
if (state2 === "completed" && filePath) rm(filePath, { force: true }).catch(() => {
|
|
835
|
+
});
|
|
836
|
+
});
|
|
837
|
+
await cdp.send("Browser.setDownloadBehavior", { behavior: "default", eventsEnabled: true });
|
|
811
838
|
}
|
|
812
839
|
function acquire(url) {
|
|
813
840
|
const key2 = url ?? "";
|
|
@@ -839,9 +866,19 @@ async function refusePrivateRequests(page) {
|
|
|
839
866
|
}
|
|
840
867
|
});
|
|
841
868
|
}
|
|
842
|
-
async function
|
|
869
|
+
async function setUpAgentTab(context, page, agentFrames) {
|
|
870
|
+
const frames = /* @__PURE__ */ new Set();
|
|
871
|
+
agentFrames.set(page, frames);
|
|
872
|
+
page.once("close", () => agentFrames.delete(page));
|
|
843
873
|
const cdp = await context.newCDPSession(page);
|
|
844
|
-
|
|
874
|
+
cdp.on("Page.frameAttached", ({ frameId }) => frames.add(frameId));
|
|
875
|
+
await cdp.send("Page.enable");
|
|
876
|
+
const add3 = (tree) => {
|
|
877
|
+
frames.add(tree.frame.id);
|
|
878
|
+
for (const child of tree.childFrames ?? []) add3(child);
|
|
879
|
+
};
|
|
880
|
+
add3((await cdp.send("Page.getFrameTree")).frameTree);
|
|
881
|
+
await cdp.send("Emulation.setFocusEmulationEnabled", { enabled: true });
|
|
845
882
|
}
|
|
846
883
|
async function attachBrowser(opts) {
|
|
847
884
|
const shared = acquire(opts.url);
|
|
@@ -852,7 +889,7 @@ async function attachBrowser(opts) {
|
|
|
852
889
|
await release(opts.url, shared);
|
|
853
890
|
throw error;
|
|
854
891
|
}
|
|
855
|
-
const { browser, context } = connection2;
|
|
892
|
+
const { browser, context, agentFrames } = connection2;
|
|
856
893
|
const owned = /* @__PURE__ */ new Set();
|
|
857
894
|
const own = (page) => {
|
|
858
895
|
owned.add(page);
|
|
@@ -862,7 +899,7 @@ async function attachBrowser(opts) {
|
|
|
862
899
|
page.setDefaultTimeout(1e4);
|
|
863
900
|
return Promise.all([
|
|
864
901
|
opts.allowPrivate ? void 0 : refusePrivateRequests(page),
|
|
865
|
-
|
|
902
|
+
setUpAgentTab(context, page, agentFrames)
|
|
866
903
|
]).catch(() => {
|
|
867
904
|
});
|
|
868
905
|
};
|
|
@@ -3628,8 +3665,8 @@ var IncompatibleDatabaseError = class extends Error {
|
|
|
3628
3665
|
}
|
|
3629
3666
|
};
|
|
3630
3667
|
var SCHEMA_OBJECTS = "SELECT type, name, sql FROM sqlite_schema WHERE sql IS NOT NULL AND substr(name, 1, 7) <> 'sqlite_' ORDER BY type, name";
|
|
3631
|
-
function fingerprint(
|
|
3632
|
-
return
|
|
3668
|
+
function fingerprint(read3) {
|
|
3669
|
+
return read3(SCHEMA_OBJECTS).map((object) => {
|
|
3633
3670
|
const sql = object.sql.replace(/--[^\n]*/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ").replace(/\s+/g, " ").trim();
|
|
3634
3671
|
return `${object.type} ${object.name} ${sql}`;
|
|
3635
3672
|
}).join("\n");
|
|
@@ -3640,7 +3677,7 @@ function readSchemaSql() {
|
|
|
3640
3677
|
return schemaSql;
|
|
3641
3678
|
}
|
|
3642
3679
|
var canonical;
|
|
3643
|
-
function schemaMatches(
|
|
3680
|
+
function schemaMatches(read3) {
|
|
3644
3681
|
if (canonical === void 0) {
|
|
3645
3682
|
const scratch = openInMemoryDb("");
|
|
3646
3683
|
try {
|
|
@@ -3650,12 +3687,12 @@ function schemaMatches(read2) {
|
|
|
3650
3687
|
scratch.close();
|
|
3651
3688
|
}
|
|
3652
3689
|
}
|
|
3653
|
-
return fingerprint(
|
|
3690
|
+
return fingerprint(read3) === canonical;
|
|
3654
3691
|
}
|
|
3655
3692
|
function initSchema(db) {
|
|
3656
|
-
const
|
|
3657
|
-
if (
|
|
3658
|
-
else if (!schemaMatches(
|
|
3693
|
+
const read3 = (query) => db.raw.query(query).all();
|
|
3694
|
+
if (read3(SCHEMA_OBJECTS).length === 0) inTx(db, () => db.raw.exec(readSchemaSql()));
|
|
3695
|
+
else if (!schemaMatches(read3)) throw new IncompatibleDatabaseError();
|
|
3659
3696
|
}
|
|
3660
3697
|
|
|
3661
3698
|
// ../daemon/src/core/paths.ts
|
|
@@ -7985,7 +8022,8 @@ function piMessagesToProviderView(messages, secrets = []) {
|
|
|
7985
8022
|
toolCallId: tr.toolCallId,
|
|
7986
8023
|
toolName: tr.toolName,
|
|
7987
8024
|
results: extractResultReferences(m),
|
|
7988
|
-
...images.length > 0 ? { images } : {}
|
|
8025
|
+
...images.length > 0 ? { images } : {},
|
|
8026
|
+
...tr.isError ? { isError: true } : {}
|
|
7989
8027
|
});
|
|
7990
8028
|
break;
|
|
7991
8029
|
}
|
|
@@ -8027,6 +8065,79 @@ import {
|
|
|
8027
8065
|
// ../daemon/src/runtime/providers/pi-runtime.ts
|
|
8028
8066
|
import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
|
|
8029
8067
|
import { ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
8068
|
+
|
|
8069
|
+
// ../daemon/src/runtime/providers/catalog.ts
|
|
8070
|
+
import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
|
|
8071
|
+
import { fetch as undiciFetch2 } from "undici";
|
|
8072
|
+
function listCatalogEntries(providerName) {
|
|
8073
|
+
const models = getBuiltinModels(
|
|
8074
|
+
piProviderName(providerName)
|
|
8075
|
+
);
|
|
8076
|
+
return (models ?? []).map((model) => {
|
|
8077
|
+
const input = model.cost?.input ?? 0;
|
|
8078
|
+
const output = model.cost?.output ?? 0;
|
|
8079
|
+
return {
|
|
8080
|
+
id: model.id,
|
|
8081
|
+
// Pi marks the undated alias "(latest)"; the dated copy is told apart by its id.
|
|
8082
|
+
name: (model.name ?? model.id).replace(/ \(latest\)$/, ""),
|
|
8083
|
+
contextWindow: model.contextWindow ?? 0,
|
|
8084
|
+
images: model.input?.includes("image") ?? false,
|
|
8085
|
+
reasoning: model.reasoning ?? false,
|
|
8086
|
+
// Subscription and free endpoints are priced at zero, which says nothing about cost.
|
|
8087
|
+
...input > 0 || output > 0 ? { price: { input, output } } : {}
|
|
8088
|
+
};
|
|
8089
|
+
});
|
|
8090
|
+
}
|
|
8091
|
+
function catalogContextWindow(model) {
|
|
8092
|
+
try {
|
|
8093
|
+
const { providerName, modelId } = parseModelString(model);
|
|
8094
|
+
const entry = listCatalogEntries(providerName).find((candidate) => candidate.id === modelId);
|
|
8095
|
+
return entry && entry.contextWindow > 0 ? entry.contextWindow : null;
|
|
8096
|
+
} catch {
|
|
8097
|
+
return null;
|
|
8098
|
+
}
|
|
8099
|
+
}
|
|
8100
|
+
var DATED = /^(.+)-(\d{8}|\d{4}-\d{2}-\d{2})$/;
|
|
8101
|
+
function datedCopies(ids) {
|
|
8102
|
+
const all = new Set(ids);
|
|
8103
|
+
return new Set(
|
|
8104
|
+
ids.filter((id) => {
|
|
8105
|
+
const base = DATED.exec(id)?.[1];
|
|
8106
|
+
return base !== void 0 && all.has(base);
|
|
8107
|
+
})
|
|
8108
|
+
);
|
|
8109
|
+
}
|
|
8110
|
+
async function fetchLiveModels(baseUrl, apiKey2, signal) {
|
|
8111
|
+
try {
|
|
8112
|
+
const headers = { accept: "application/json" };
|
|
8113
|
+
if (apiKey2) headers.authorization = `Bearer ${apiKey2}`;
|
|
8114
|
+
const res = await undiciFetch2(`${baseUrl.replace(/\/$/, "")}/models`, { headers, signal });
|
|
8115
|
+
if (!res.ok) return { models: [], error: `${res.status} ${res.statusText}` };
|
|
8116
|
+
const body = await res.json();
|
|
8117
|
+
return { models: (body?.data ?? []).flatMap((model) => model.id ? [model.id] : []) };
|
|
8118
|
+
} catch (err) {
|
|
8119
|
+
const cause = err.cause;
|
|
8120
|
+
return { models: [], error: cause?.code ?? cause?.message ?? err.message };
|
|
8121
|
+
}
|
|
8122
|
+
}
|
|
8123
|
+
async function listLiveModels(providerName, env = process.env, signal) {
|
|
8124
|
+
const url = providerModelsUrl(providerName, env);
|
|
8125
|
+
if (!url) return void 0;
|
|
8126
|
+
return fetchLiveModels(url, providerApiKey(providerName, env), signal);
|
|
8127
|
+
}
|
|
8128
|
+
|
|
8129
|
+
// ../daemon/src/runtime/providers/pi-runtime.ts
|
|
8130
|
+
var ENDPOINT_CONTEXT_WINDOW = 32768;
|
|
8131
|
+
function turnContextWindow(model) {
|
|
8132
|
+
let providerName;
|
|
8133
|
+
try {
|
|
8134
|
+
providerName = parseModelString(model).providerName;
|
|
8135
|
+
} catch {
|
|
8136
|
+
return null;
|
|
8137
|
+
}
|
|
8138
|
+
if (findProvider(providerName)?.local) return ENDPOINT_CONTEXT_WINDOW;
|
|
8139
|
+
return catalogContextWindow(model) ?? ENDPOINT_CONTEXT_WINDOW;
|
|
8140
|
+
}
|
|
8030
8141
|
function endpointModel(providerName, modelId, baseUrl) {
|
|
8031
8142
|
return {
|
|
8032
8143
|
id: modelId,
|
|
@@ -8037,7 +8148,7 @@ function endpointModel(providerName, modelId, baseUrl) {
|
|
|
8037
8148
|
reasoning: false,
|
|
8038
8149
|
input: ["text"],
|
|
8039
8150
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
8040
|
-
contextWindow:
|
|
8151
|
+
contextWindow: ENDPOINT_CONTEXT_WINDOW,
|
|
8041
8152
|
maxTokens: 4096
|
|
8042
8153
|
};
|
|
8043
8154
|
}
|
|
@@ -8278,7 +8389,7 @@ function loadPromptSkills(skillsDir, attachedNames) {
|
|
|
8278
8389
|
var CONTEXT_FILE_ORDER = ["AGENTS.md", "SOUL.md", "TOOLS.md", "IDENTITY.md"];
|
|
8279
8390
|
function loadHomeDocuments(agentDir2) {
|
|
8280
8391
|
const root = resolveRealDirectory(agentDir2);
|
|
8281
|
-
const
|
|
8392
|
+
const read3 = (file) => {
|
|
8282
8393
|
try {
|
|
8283
8394
|
return readRegularFileNoFollow(join17(root, file));
|
|
8284
8395
|
} catch (error) {
|
|
@@ -8287,11 +8398,11 @@ function loadHomeDocuments(agentDir2) {
|
|
|
8287
8398
|
}
|
|
8288
8399
|
};
|
|
8289
8400
|
return {
|
|
8290
|
-
"AGENTS.md":
|
|
8291
|
-
"SOUL.md":
|
|
8292
|
-
"TOOLS.md":
|
|
8293
|
-
"IDENTITY.md":
|
|
8294
|
-
"BOOTSTRAP.md":
|
|
8401
|
+
"AGENTS.md": read3("AGENTS.md"),
|
|
8402
|
+
"SOUL.md": read3("SOUL.md"),
|
|
8403
|
+
"TOOLS.md": read3("TOOLS.md"),
|
|
8404
|
+
"IDENTITY.md": read3("IDENTITY.md"),
|
|
8405
|
+
"BOOTSTRAP.md": read3("BOOTSTRAP.md")
|
|
8295
8406
|
};
|
|
8296
8407
|
}
|
|
8297
8408
|
function buildSystemPrompt(agent, options = {}) {
|
|
@@ -8443,7 +8554,7 @@ ${reviewedLessons.map((lesson) => `- ${lesson}`).join("\n")}`
|
|
|
8443
8554
|
}
|
|
8444
8555
|
parts.push({
|
|
8445
8556
|
id: "memory",
|
|
8446
|
-
text: "# Memory\n\nYou share a persistent memory backend with every other agent in this team. Use `memory_write` to remember things across sessions, and `memory_search` / `memory_read` / `memory_list` to recall them. This memory is for project knowledge \u2014 codebase notes, decisions, things the user told you about the work. For personal notes about yourself (preferences, persona quirks), use `home_write` on IDENTITY.md instead. Always check memory at the start of a session: another agent in the team may have already learned something useful. **Do NOT send peer messages announcing memory writes \u2014 every agent has access to the same store via `memory_search` and will find your note when they need it
|
|
8557
|
+
text: "# Memory\n\nYou share a persistent memory backend with every other agent in this team. Use `memory_write` to remember things across sessions, and `memory_search` / `memory_read` / `memory_list` to recall them. This memory is for project knowledge \u2014 codebase notes, decisions, things the user told you about the work. For personal notes about yourself (preferences, persona quirks), use `home_write` on IDENTITY.md instead. Always check memory at the start of a session: another agent in the team may have already learned something useful. **Do NOT send peer messages announcing memory writes \u2014 every agent has access to the same store via `memory_search` and will find your note when they need it.**\n\nWhen a conversation grows long, its older messages are replaced by a summary. They stay saved: when the summary leaves out a detail you need, find it with `recall` instead of guessing or asking again."
|
|
8447
8558
|
});
|
|
8448
8559
|
return parts;
|
|
8449
8560
|
}
|
|
@@ -9030,6 +9141,57 @@ function readOnlyMount(source, target, root) {
|
|
|
9030
9141
|
return { source: real, target };
|
|
9031
9142
|
}
|
|
9032
9143
|
|
|
9144
|
+
// ../daemon/src/runtime/pi/history.ts
|
|
9145
|
+
import {
|
|
9146
|
+
calculateContextTokens
|
|
9147
|
+
} from "@earendil-works/pi-coding-agent";
|
|
9148
|
+
function branchOf(entries) {
|
|
9149
|
+
const all = entries.filter((entry) => entry.type !== "session");
|
|
9150
|
+
const byId = new Map(all.map((entry) => [entry.id, entry]));
|
|
9151
|
+
const path = [];
|
|
9152
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9153
|
+
for (let entry = all.at(-1); entry && !seen.has(entry.id); ) {
|
|
9154
|
+
seen.add(entry.id);
|
|
9155
|
+
path.push(entry);
|
|
9156
|
+
entry = entry.parentId ? byId.get(entry.parentId) : void 0;
|
|
9157
|
+
}
|
|
9158
|
+
return path.reverse();
|
|
9159
|
+
}
|
|
9160
|
+
function conversationHistory(branch) {
|
|
9161
|
+
const messages = [];
|
|
9162
|
+
const position = /* @__PURE__ */ new Map();
|
|
9163
|
+
const compactions = [];
|
|
9164
|
+
for (const entry of branch) {
|
|
9165
|
+
position.set(entry.id, messages.length);
|
|
9166
|
+
if (entry.type === "message" && entry.message.role !== "system") {
|
|
9167
|
+
const message = entry.message;
|
|
9168
|
+
messages.push(
|
|
9169
|
+
"content" in message && message.content == null ? { ...message, content: [] } : message
|
|
9170
|
+
);
|
|
9171
|
+
} else if (entry.type === "compaction") {
|
|
9172
|
+
compactions.push({
|
|
9173
|
+
// The part kept verbatim starts at firstKeptEntryId; the summary stands for what precedes.
|
|
9174
|
+
index: position.get(entry.firstKeptEntryId) ?? messages.length,
|
|
9175
|
+
summary: entry.summary,
|
|
9176
|
+
tokensBefore: entry.tokensBefore,
|
|
9177
|
+
at: Date.parse(entry.timestamp) || 0
|
|
9178
|
+
});
|
|
9179
|
+
}
|
|
9180
|
+
}
|
|
9181
|
+
return { messages, compactions };
|
|
9182
|
+
}
|
|
9183
|
+
function contextUse(branch, window) {
|
|
9184
|
+
const latestCompaction = branch.findLastIndex((entry) => entry.type === "compaction");
|
|
9185
|
+
for (let i = branch.length - 1; i > latestCompaction; i--) {
|
|
9186
|
+
const entry = branch[i];
|
|
9187
|
+
if (entry?.type !== "message" || entry.message.role !== "assistant") continue;
|
|
9188
|
+
if (entry.message.stopReason === "aborted" || entry.message.stopReason === "error") continue;
|
|
9189
|
+
const tokens = calculateContextTokens(entry.message.usage);
|
|
9190
|
+
if (tokens > 0) return { tokens, window };
|
|
9191
|
+
}
|
|
9192
|
+
return { tokens: null, window };
|
|
9193
|
+
}
|
|
9194
|
+
|
|
9033
9195
|
// ../daemon/src/runtime/pi/session-file.ts
|
|
9034
9196
|
import { closeSync as closeSync3, constants as constants4, fstatSync as fstatSync3, openSync as openSync3, readSync as readSync2 } from "node:fs";
|
|
9035
9197
|
import { join as join19 } from "node:path";
|
|
@@ -9734,6 +9896,143 @@ function messagingTools(host3, fromAgentId) {
|
|
|
9734
9896
|
];
|
|
9735
9897
|
}
|
|
9736
9898
|
|
|
9899
|
+
// ../daemon/src/runtime/tools/recall.ts
|
|
9900
|
+
var MAX_WORDS = 8;
|
|
9901
|
+
var MAX_HITS = 12;
|
|
9902
|
+
var READ_COUNT = 5;
|
|
9903
|
+
var MAX_READ = 20;
|
|
9904
|
+
var BUDGET = 2e4;
|
|
9905
|
+
var MIN_SHARE = 2e3;
|
|
9906
|
+
var BEFORE = 60;
|
|
9907
|
+
var AFTER = 200;
|
|
9908
|
+
var NOTHING_SUMMARIZED = "Nothing in this conversation has been summarized: every message is still in your context.";
|
|
9909
|
+
function recallTool(source) {
|
|
9910
|
+
return {
|
|
9911
|
+
def: {
|
|
9912
|
+
name: "recall",
|
|
9913
|
+
description: "Search or read this conversation's older messages that were summarized to make room. When a conversation fills your context, its older messages are replaced by a summary, but they stay saved. When the summary leaves out something you need (an exact value, a link, a file name, the user's own words, what a tool returned), find it here rather than guessing or asking again. Give `query` to list the summarized messages that hold every word, with their numbers; give `from` (a number from a search, or 1 for the start) to read messages in full.",
|
|
9914
|
+
parameters: {
|
|
9915
|
+
type: "object",
|
|
9916
|
+
properties: {
|
|
9917
|
+
query: {
|
|
9918
|
+
type: "string",
|
|
9919
|
+
description: "words that must all appear in a message (case is ignored)"
|
|
9920
|
+
},
|
|
9921
|
+
from: {
|
|
9922
|
+
type: "integer",
|
|
9923
|
+
minimum: 1,
|
|
9924
|
+
description: "the number of the first message to read"
|
|
9925
|
+
},
|
|
9926
|
+
count: {
|
|
9927
|
+
type: "integer",
|
|
9928
|
+
minimum: 1,
|
|
9929
|
+
maximum: MAX_READ,
|
|
9930
|
+
description: `how many messages to read from \`from\` (default ${READ_COUNT}); long messages are cut, less so when you read fewer`
|
|
9931
|
+
}
|
|
9932
|
+
}
|
|
9933
|
+
}
|
|
9934
|
+
},
|
|
9935
|
+
async invoke(args) {
|
|
9936
|
+
const summarized = summarizedMessages(source);
|
|
9937
|
+
if (summarized.length === 0) return NOTHING_SUMMARIZED;
|
|
9938
|
+
if (args.from !== void 0) return read2(summarized, Number(args.from), args.count);
|
|
9939
|
+
if (typeof args.query === "string") return search(summarized, args.query);
|
|
9940
|
+
throw new Error("recall: give `query` to search or `from` to read");
|
|
9941
|
+
}
|
|
9942
|
+
};
|
|
9943
|
+
}
|
|
9944
|
+
function summarizedMessages(source) {
|
|
9945
|
+
const { messages, compactions } = conversationHistory(source.branch());
|
|
9946
|
+
const end = compactions.at(-1)?.index ?? 0;
|
|
9947
|
+
return messages.slice(0, end).flatMap((message, index) => {
|
|
9948
|
+
const [shown2] = piMessagesToProviderView([message], source.secrets);
|
|
9949
|
+
if (!shown2) return [];
|
|
9950
|
+
const at = message.timestamp;
|
|
9951
|
+
const when = typeof at === "number" && Number.isFinite(at) ? ` \xB7 ${new Date(at).toISOString().slice(0, 16).replace("T", " ")} UTC` : "";
|
|
9952
|
+
return [
|
|
9953
|
+
{
|
|
9954
|
+
number: index + 1,
|
|
9955
|
+
heading: `#${index + 1} \xB7 ${speaker(shown2)}${when}`,
|
|
9956
|
+
text: redactExactValues(textOf(shown2), source.secrets)
|
|
9957
|
+
}
|
|
9958
|
+
];
|
|
9959
|
+
});
|
|
9960
|
+
}
|
|
9961
|
+
function speaker(message) {
|
|
9962
|
+
if (message.role === "tool") {
|
|
9963
|
+
return `result of ${message.toolName ?? "a tool"}${message.isError ? ", failed" : ""}`;
|
|
9964
|
+
}
|
|
9965
|
+
return message.role;
|
|
9966
|
+
}
|
|
9967
|
+
function textOf(message) {
|
|
9968
|
+
const parts = message.content ? [message.content] : [];
|
|
9969
|
+
for (const call of message.toolCalls ?? []) parts.push(`[called ${call.name} ${call.arguments}]`);
|
|
9970
|
+
const images = message.images?.length ?? 0;
|
|
9971
|
+
if (images > 0) parts.push(`[${images === 1 ? "an image" : `${images} images`}]`);
|
|
9972
|
+
if (message.stopped) parts.push(`[${message.stopped}]`);
|
|
9973
|
+
return parts.join("\n");
|
|
9974
|
+
}
|
|
9975
|
+
function search(summarized, query) {
|
|
9976
|
+
const words = [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))];
|
|
9977
|
+
if (words.join("").length < 2) throw new Error("recall: search for at least two characters");
|
|
9978
|
+
if (words.length > MAX_WORDS) throw new Error(`recall: search for at most ${MAX_WORDS} words`);
|
|
9979
|
+
const hits = summarized.filter((message) => {
|
|
9980
|
+
const lower = message.text.toLowerCase();
|
|
9981
|
+
return words.every((word) => lower.includes(word));
|
|
9982
|
+
});
|
|
9983
|
+
const of = `of the ${summarized.length} summarized messages`;
|
|
9984
|
+
if (hits.length === 0) {
|
|
9985
|
+
return `None ${of} holds every word of "${query}". Search for fewer or other words, or read from 1.`;
|
|
9986
|
+
}
|
|
9987
|
+
const shown2 = hits.slice(-MAX_HITS);
|
|
9988
|
+
const lines = shown2.map((hit) => `${hit.heading}: ${snippetOf(hit.text, words)}`);
|
|
9989
|
+
const earlier = hits.length - shown2.length;
|
|
9990
|
+
return [
|
|
9991
|
+
`${hits.length} ${of} ${hits.length === 1 ? "holds" : "hold"} every word of "${query}"${earlier > 0 ? `; the latest ${shown2.length}` : ""}:`,
|
|
9992
|
+
...lines,
|
|
9993
|
+
...earlier > 0 ? [`${earlier} earlier ones are not listed: add a word to narrow the search.`] : [],
|
|
9994
|
+
"Read one in full with `from` and its number."
|
|
9995
|
+
].join("\n");
|
|
9996
|
+
}
|
|
9997
|
+
function snippetOf(text4, words) {
|
|
9998
|
+
const flat = text4.replace(/\s+/g, " ").trim();
|
|
9999
|
+
const lower = flat.toLowerCase();
|
|
10000
|
+
const at = Math.min(...words.map((word) => lower.indexOf(word)).filter((index) => index >= 0));
|
|
10001
|
+
const start2 = Math.max(0, at - BEFORE);
|
|
10002
|
+
const end = Math.min(flat.length, at + AFTER);
|
|
10003
|
+
return `${start2 > 0 ? "\u2026" : ""}${flat.slice(start2, end).trim()}${end < flat.length ? "\u2026" : ""}`;
|
|
10004
|
+
}
|
|
10005
|
+
function read2(summarized, from, rawCount) {
|
|
10006
|
+
const total = summarized.at(-1)?.number ?? 0;
|
|
10007
|
+
if (!Number.isInteger(from) || from < 1) throw new Error("recall: `from` is a message number");
|
|
10008
|
+
if (from > total) {
|
|
10009
|
+
return `Only messages 1 to ${total} were summarized; the later ones are in your context.`;
|
|
10010
|
+
}
|
|
10011
|
+
const count2 = rawCount === void 0 ? READ_COUNT : Number(rawCount);
|
|
10012
|
+
if (!Number.isInteger(count2) || count2 < 1 || count2 > MAX_READ) {
|
|
10013
|
+
throw new Error(`recall: \`count\` is from 1 to ${MAX_READ}`);
|
|
10014
|
+
}
|
|
10015
|
+
const share = Math.max(MIN_SHARE, Math.floor(BUDGET / count2));
|
|
10016
|
+
const blocks = [];
|
|
10017
|
+
let used = 0;
|
|
10018
|
+
let next = null;
|
|
10019
|
+
for (const message of summarized) {
|
|
10020
|
+
if (message.number < from) continue;
|
|
10021
|
+
if (blocks.length === count2 || blocks.length > 0 && used >= BUDGET) {
|
|
10022
|
+
next = message.number;
|
|
10023
|
+
break;
|
|
10024
|
+
}
|
|
10025
|
+
const cut = message.text.length > share;
|
|
10026
|
+
const body = cut ? `${message.text.slice(0, share)}\u2026 [${(message.text.length - share).toLocaleString("en-US")} more characters cut${count2 > 1 ? "; read this message alone to see more" : ""}]` : message.text;
|
|
10027
|
+
blocks.push(`${message.heading}
|
|
10028
|
+
${body}`);
|
|
10029
|
+
used += body.length;
|
|
10030
|
+
}
|
|
10031
|
+
const last = next === null ? total : next - 1;
|
|
10032
|
+
const head = `Messages ${from} to ${last} of the ${total} summarized${next === null ? "" : `; read on from ${next}`}:`;
|
|
10033
|
+
return [head, ...blocks].join("\n\n");
|
|
10034
|
+
}
|
|
10035
|
+
|
|
9737
10036
|
// ../daemon/src/runtime/tools/team.ts
|
|
9738
10037
|
function agentCreateTool(host3) {
|
|
9739
10038
|
return {
|
|
@@ -9835,7 +10134,7 @@ etag: ${etag}`;
|
|
|
9835
10134
|
}
|
|
9836
10135
|
|
|
9837
10136
|
// ../daemon/src/runtime/tools/web.ts
|
|
9838
|
-
import { fetch as
|
|
10137
|
+
import { fetch as undiciFetch3 } from "undici";
|
|
9839
10138
|
|
|
9840
10139
|
// ../daemon/src/runtime/tools/web-extract.ts
|
|
9841
10140
|
import { Readability } from "@mozilla/readability";
|
|
@@ -10072,7 +10371,7 @@ function webSearchTool(host3) {
|
|
|
10072
10371
|
};
|
|
10073
10372
|
}
|
|
10074
10373
|
function webFetchTool(opts) {
|
|
10075
|
-
const fetchFn = opts?.fetchImpl ??
|
|
10374
|
+
const fetchFn = opts?.fetchImpl ?? undiciFetch3;
|
|
10076
10375
|
const env = opts?.env ?? process.env;
|
|
10077
10376
|
const allowPrivate = opts?.allowPrivate ?? false;
|
|
10078
10377
|
const cacheTtlMs = opts?.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
|
|
@@ -10208,6 +10507,7 @@ function toPiPart(part) {
|
|
|
10208
10507
|
function createBazilionCustomTools(opts) {
|
|
10209
10508
|
const handlers = [
|
|
10210
10509
|
...memoryTools(opts.memory),
|
|
10510
|
+
recallTool(opts.recall),
|
|
10211
10511
|
...homeTools(opts.agent.agent.dir),
|
|
10212
10512
|
bootstrapTool(opts.agent.agent.dir),
|
|
10213
10513
|
webFetchTool({ env: opts.env }),
|
|
@@ -10236,10 +10536,11 @@ function createBazilionCustomTools(opts) {
|
|
|
10236
10536
|
async function openPiSession(spec) {
|
|
10237
10537
|
const { runtime: modelRuntime, model } = await createPiModel(spec.model);
|
|
10238
10538
|
const settingsManager = SettingsManager.inMemory({
|
|
10239
|
-
// Provider requests happen only for turns: no cache warming
|
|
10240
|
-
//
|
|
10539
|
+
// Provider requests happen only for turns: no cache warming. A turn compacts the
|
|
10540
|
+
// conversation when it nears the model's window (Pi's defaults: within 16,384 tokens of it,
|
|
10541
|
+
// keeping the last 20,000 verbatim), and redoes a reply the full window cut short.
|
|
10241
10542
|
cacheWarming: "off",
|
|
10242
|
-
compaction: { enabled:
|
|
10543
|
+
compaction: { enabled: true },
|
|
10243
10544
|
retry: {
|
|
10244
10545
|
enabled: true,
|
|
10245
10546
|
maxRetries: 2,
|
|
@@ -10289,7 +10590,7 @@ async function openPiSession(spec) {
|
|
|
10289
10590
|
}
|
|
10290
10591
|
return { session, redactionSecrets, dispose: () => session.dispose() };
|
|
10291
10592
|
}
|
|
10292
|
-
function turnSurface(opts) {
|
|
10593
|
+
function turnSurface(opts, recall) {
|
|
10293
10594
|
const { agent, paths, env } = opts;
|
|
10294
10595
|
const cwd = agent.team.path;
|
|
10295
10596
|
const promptSkills = loadPromptSkills(paths.skillsDir, agent.skills);
|
|
@@ -10304,6 +10605,7 @@ function turnSurface(opts) {
|
|
|
10304
10605
|
const customTools = createBazilionCustomTools({
|
|
10305
10606
|
agent,
|
|
10306
10607
|
memory: opts.memory,
|
|
10608
|
+
recall,
|
|
10307
10609
|
messagingHost: opts.messagingHost,
|
|
10308
10610
|
userMdHost: opts.userMdHost,
|
|
10309
10611
|
browserHost: opts.browserHost,
|
|
@@ -10343,7 +10645,11 @@ async function createBazilionSession(opts) {
|
|
|
10343
10645
|
if (!existsSync15(agent.team.path)) mkdirSync10(agent.team.path, { recursive: true });
|
|
10344
10646
|
mkdirSync10(join22(paths.agentDir(agent.agent.id), "sessions"), { recursive: true });
|
|
10345
10647
|
const sessionManager = openConversation(agent, paths, opts.conversation);
|
|
10346
|
-
const
|
|
10648
|
+
const redactionSecrets = [...new Set(envSecretValues(opts.env).filter(Boolean))];
|
|
10649
|
+
const turn = turnSurface(opts, {
|
|
10650
|
+
branch: () => sessionManager.getBranch(),
|
|
10651
|
+
secrets: redactionSecrets
|
|
10652
|
+
});
|
|
10347
10653
|
return openPiSession({
|
|
10348
10654
|
model: {
|
|
10349
10655
|
providerName,
|
|
@@ -10362,7 +10668,7 @@ async function createBazilionSession(opts) {
|
|
|
10362
10668
|
})),
|
|
10363
10669
|
tools: turn.tools,
|
|
10364
10670
|
hostToolNames: turn.hostToolNames,
|
|
10365
|
-
redactionSecrets
|
|
10671
|
+
redactionSecrets,
|
|
10366
10672
|
refreshApiKey: opts.refreshApiKey
|
|
10367
10673
|
});
|
|
10368
10674
|
}
|
|
@@ -10376,7 +10682,7 @@ var HOST_TOOL_DEFINITIONS = {
|
|
|
10376
10682
|
ls: createLsToolDefinition
|
|
10377
10683
|
};
|
|
10378
10684
|
function describeTurn(opts) {
|
|
10379
|
-
const turn = turnSurface(opts);
|
|
10685
|
+
const turn = turnSurface(opts, { branch: () => [], secrets: [] });
|
|
10380
10686
|
const hostTools = turn.hostToolNames.flatMap((name) => {
|
|
10381
10687
|
const define = HOST_TOOL_DEFINITIONS[name];
|
|
10382
10688
|
return define ? [define(turn.modelCwd)] : [];
|
|
@@ -10387,6 +10693,9 @@ function describeTurn(opts) {
|
|
|
10387
10693
|
tools: [...hostTools, ...turn.tools]
|
|
10388
10694
|
};
|
|
10389
10695
|
}
|
|
10696
|
+
function conversationWindow(conversation, model) {
|
|
10697
|
+
return contextUse(conversation.getBranch(), turnContextWindow(model));
|
|
10698
|
+
}
|
|
10390
10699
|
function conversationUsage(conversation) {
|
|
10391
10700
|
const branch = conversation.getBranch();
|
|
10392
10701
|
return {
|
|
@@ -10418,6 +10727,14 @@ function openConversation(agent, paths, target) {
|
|
|
10418
10727
|
agent.team.path
|
|
10419
10728
|
);
|
|
10420
10729
|
}
|
|
10730
|
+
function loadConversation(agent, paths, target) {
|
|
10731
|
+
const window = turnContextWindow(agent.model);
|
|
10732
|
+
if (!target) return { messages: [], compactions: [], context: { tokens: null, window } };
|
|
10733
|
+
const branch = branchOf(
|
|
10734
|
+
readSessionFile(join22(paths.agentDir(agent.agent.id), "sessions"), target.id)
|
|
10735
|
+
);
|
|
10736
|
+
return { ...conversationHistory(branch), context: contextUse(branch, window) };
|
|
10737
|
+
}
|
|
10421
10738
|
function loadInitialMessages(agent, paths, target) {
|
|
10422
10739
|
if (!target) return [];
|
|
10423
10740
|
const entries = readSessionFile(join22(paths.agentDir(agent.agent.id), "sessions"), target.id);
|
|
@@ -10452,57 +10769,6 @@ function explicitConversationFile(directory, target) {
|
|
|
10452
10769
|
return join22(directory, `${target.id}.jsonl`);
|
|
10453
10770
|
}
|
|
10454
10771
|
|
|
10455
|
-
// ../daemon/src/runtime/providers/catalog.ts
|
|
10456
|
-
import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
|
|
10457
|
-
import { fetch as undiciFetch3 } from "undici";
|
|
10458
|
-
function listCatalogEntries(providerName) {
|
|
10459
|
-
const models = getBuiltinModels(
|
|
10460
|
-
piProviderName(providerName)
|
|
10461
|
-
);
|
|
10462
|
-
return (models ?? []).map((model) => {
|
|
10463
|
-
const input = model.cost?.input ?? 0;
|
|
10464
|
-
const output = model.cost?.output ?? 0;
|
|
10465
|
-
return {
|
|
10466
|
-
id: model.id,
|
|
10467
|
-
// Pi marks the undated alias "(latest)"; the dated copy is told apart by its id.
|
|
10468
|
-
name: (model.name ?? model.id).replace(/ \(latest\)$/, ""),
|
|
10469
|
-
contextWindow: model.contextWindow ?? 0,
|
|
10470
|
-
images: model.input?.includes("image") ?? false,
|
|
10471
|
-
reasoning: model.reasoning ?? false,
|
|
10472
|
-
// Subscription and free endpoints are priced at zero, which says nothing about cost.
|
|
10473
|
-
...input > 0 || output > 0 ? { price: { input, output } } : {}
|
|
10474
|
-
};
|
|
10475
|
-
});
|
|
10476
|
-
}
|
|
10477
|
-
var DATED = /^(.+)-(\d{8}|\d{4}-\d{2}-\d{2})$/;
|
|
10478
|
-
function datedCopies(ids) {
|
|
10479
|
-
const all = new Set(ids);
|
|
10480
|
-
return new Set(
|
|
10481
|
-
ids.filter((id) => {
|
|
10482
|
-
const base = DATED.exec(id)?.[1];
|
|
10483
|
-
return base !== void 0 && all.has(base);
|
|
10484
|
-
})
|
|
10485
|
-
);
|
|
10486
|
-
}
|
|
10487
|
-
async function fetchLiveModels(baseUrl, apiKey2, signal) {
|
|
10488
|
-
try {
|
|
10489
|
-
const headers = { accept: "application/json" };
|
|
10490
|
-
if (apiKey2) headers.authorization = `Bearer ${apiKey2}`;
|
|
10491
|
-
const res = await undiciFetch3(`${baseUrl.replace(/\/$/, "")}/models`, { headers, signal });
|
|
10492
|
-
if (!res.ok) return { models: [], error: `${res.status} ${res.statusText}` };
|
|
10493
|
-
const body = await res.json();
|
|
10494
|
-
return { models: (body?.data ?? []).flatMap((model) => model.id ? [model.id] : []) };
|
|
10495
|
-
} catch (err) {
|
|
10496
|
-
const cause = err.cause;
|
|
10497
|
-
return { models: [], error: cause?.code ?? cause?.message ?? err.message };
|
|
10498
|
-
}
|
|
10499
|
-
}
|
|
10500
|
-
async function listLiveModels(providerName, env = process.env, signal) {
|
|
10501
|
-
const url = providerModelsUrl(providerName, env);
|
|
10502
|
-
if (!url) return void 0;
|
|
10503
|
-
return fetchLiveModels(url, providerApiKey(providerName, env), signal);
|
|
10504
|
-
}
|
|
10505
|
-
|
|
10506
10772
|
// ../daemon/src/runtime/worker/spawn.ts
|
|
10507
10773
|
import { spawn as spawn4 } from "node:child_process";
|
|
10508
10774
|
import { existsSync as existsSync16 } from "node:fs";
|
|
@@ -12487,6 +12753,10 @@ function renderFrame(frame, mode2) {
|
|
|
12487
12753
|
return mode2 === "verbose" ? `\u2713 ${ev.name} \u2192 ${clip2(ev.result, 200)}` : null;
|
|
12488
12754
|
case "tool_error":
|
|
12489
12755
|
return mode2 === "verbose" ? `\u2715 ${ev.name}: ${ev.error}` : null;
|
|
12756
|
+
case "compaction":
|
|
12757
|
+
if (ev.state === "failed") return `\u26A0\uFE0F Could not summarize older messages: ${ev.error ?? ""}`;
|
|
12758
|
+
if (mode2 !== "verbose") return null;
|
|
12759
|
+
return ev.state === "running" ? "Summarizing older messages to make room\u2026" : "Older messages summarized to make room.";
|
|
12490
12760
|
case "command_approval":
|
|
12491
12761
|
return null;
|
|
12492
12762
|
case "file":
|
|
@@ -13083,7 +13353,7 @@ function turnHosts(turn, env) {
|
|
|
13083
13353
|
const { signal } = turn.controller;
|
|
13084
13354
|
const secretsEnv = () => mergeSecretsIntoEnv(db, authToken);
|
|
13085
13355
|
const codexConnected = hasCredentials(db, authToken);
|
|
13086
|
-
const
|
|
13356
|
+
const search2 = searchRoute(env, agent.model, codexConnected);
|
|
13087
13357
|
return {
|
|
13088
13358
|
messagingHost: createDbMessagingHost(db, {
|
|
13089
13359
|
causalParentMessageId: turn.request.causalParentMessageId
|
|
@@ -13111,8 +13381,8 @@ function turnHosts(turn, env) {
|
|
|
13111
13381
|
accessToken: () => loadAccessToken(db, authToken)
|
|
13112
13382
|
}
|
|
13113
13383
|
}) : void 0,
|
|
13114
|
-
webSearchHost:
|
|
13115
|
-
backend:
|
|
13384
|
+
webSearchHost: search2.backend ? createWebSearchHost({
|
|
13385
|
+
backend: search2.backend,
|
|
13116
13386
|
env: secretsEnv,
|
|
13117
13387
|
model: agent.model,
|
|
13118
13388
|
codexToken: () => loadAccessToken(db, authToken),
|
|
@@ -13323,17 +13593,21 @@ agentChatRouter.get("/:id/sessions/messages", (c) => {
|
|
|
13323
13593
|
const target = selectedConversationTarget(db, resolved.agent.id);
|
|
13324
13594
|
const conversationId = target?.id ?? null;
|
|
13325
13595
|
try {
|
|
13326
|
-
const messages =
|
|
13327
|
-
loadInitialMessages(resolved, paths, target),
|
|
13328
|
-
envSecretValues(mergeSecretsIntoEnv(db, authToken))
|
|
13329
|
-
);
|
|
13596
|
+
const { messages, compactions, context } = loadConversation(resolved, paths, target);
|
|
13330
13597
|
return c.json({
|
|
13331
|
-
messages
|
|
13598
|
+
messages: piMessagesToProviderView(
|
|
13599
|
+
messages,
|
|
13600
|
+
envSecretValues(mergeSecretsIntoEnv(db, authToken))
|
|
13601
|
+
),
|
|
13602
|
+
compactions,
|
|
13603
|
+
context,
|
|
13332
13604
|
head: { ...loadSessionHead(resolved, paths, target), conversationId }
|
|
13333
13605
|
});
|
|
13334
13606
|
} catch {
|
|
13335
13607
|
return c.json({
|
|
13336
13608
|
messages: [],
|
|
13609
|
+
compactions: [],
|
|
13610
|
+
context: { tokens: null, window: null },
|
|
13337
13611
|
head: unavailableHead(target, conversationId)
|
|
13338
13612
|
});
|
|
13339
13613
|
}
|
|
@@ -13541,7 +13815,8 @@ agentChatRouter.get(
|
|
|
13541
13815
|
path: resolved.team.path,
|
|
13542
13816
|
userMdChars: resolved.team.userMd.length
|
|
13543
13817
|
};
|
|
13544
|
-
const
|
|
13818
|
+
const conversation = openConversation(resolved, paths, target);
|
|
13819
|
+
const history = conversationUsage(conversation);
|
|
13545
13820
|
const historyChars = history.tokens * 4;
|
|
13546
13821
|
const cap = c.req.query("detail") === "1" ? Number.POSITIVE_INFINITY : 30;
|
|
13547
13822
|
const totalsChars = systemPromptChars + toolsSchemaChars + historyChars;
|
|
@@ -13572,7 +13847,8 @@ agentChatRouter.get(
|
|
|
13572
13847
|
bytes: loadSessionHead(resolved, paths, target).size,
|
|
13573
13848
|
tokensEstimate: history.tokens
|
|
13574
13849
|
},
|
|
13575
|
-
totals: { chars: totalsChars, tokens: estimateTokens2(totalsChars) }
|
|
13850
|
+
totals: { chars: totalsChars, tokens: estimateTokens2(totalsChars) },
|
|
13851
|
+
window: conversationWindow(conversation, resolved.model)
|
|
13576
13852
|
});
|
|
13577
13853
|
})
|
|
13578
13854
|
);
|
|
@@ -13589,11 +13865,13 @@ agentChatRouter.post("/:id/chat/truncate", async (c) => {
|
|
|
13589
13865
|
}
|
|
13590
13866
|
const { db, paths } = getCtx();
|
|
13591
13867
|
const conversation = openConversation(resolveAgent(db, paths, id), paths, target);
|
|
13592
|
-
const
|
|
13868
|
+
const branch = conversation.getBranch();
|
|
13869
|
+
const messageEntries = branch.filter((e) => e.type === "message" && e.message.role !== "system");
|
|
13593
13870
|
const before = messageEntries.length;
|
|
13594
13871
|
const after = Math.max(0, Math.min(keep2, before));
|
|
13595
13872
|
if (after === before) return c.json({ before, after });
|
|
13596
|
-
const
|
|
13873
|
+
const firstDropped = messageEntries[after];
|
|
13874
|
+
const lastKept = firstDropped ? branch[branch.indexOf(firstDropped) - 1] : void 0;
|
|
13597
13875
|
if (lastKept) conversation.branch(lastKept.id);
|
|
13598
13876
|
else conversation.resetLeaf();
|
|
13599
13877
|
conversation.appendCustomEntry("bazilion.truncate", { keep: after });
|
|
@@ -14340,9 +14618,9 @@ function describeProviderFailure(message, context) {
|
|
|
14340
14618
|
|
|
14341
14619
|
// ../daemon/src/lib/setting-fields.ts
|
|
14342
14620
|
import { isAbsolute as isAbsolute7 } from "node:path";
|
|
14343
|
-
function readAll(
|
|
14621
|
+
function readAll(read3) {
|
|
14344
14622
|
try {
|
|
14345
|
-
return
|
|
14623
|
+
return read3();
|
|
14346
14624
|
} catch {
|
|
14347
14625
|
return {};
|
|
14348
14626
|
}
|
|
@@ -15365,30 +15643,29 @@ configRouter.delete("/fields/:envVar", (c) => {
|
|
|
15365
15643
|
|
|
15366
15644
|
// ../daemon/src/lib/conversation-search.ts
|
|
15367
15645
|
import { join as join32 } from "node:path";
|
|
15368
|
-
import { buildSessionContext as buildSessionContext2 } from "@earendil-works/pi-coding-agent";
|
|
15369
15646
|
var INBOX_WAKE_PREFIX = "[[bazilion:inbox-wake]]\n";
|
|
15370
|
-
var
|
|
15647
|
+
var MAX_WORDS2 = 8;
|
|
15371
15648
|
var MAX_SEARCH_HITS = 50;
|
|
15372
|
-
var
|
|
15373
|
-
var
|
|
15649
|
+
var BEFORE2 = 24;
|
|
15650
|
+
var AFTER2 = 140;
|
|
15374
15651
|
function searchWords(query) {
|
|
15375
15652
|
const words = [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))];
|
|
15376
15653
|
if (words.join("").length < 2) throw new DomainError(400, "Search for at least two characters");
|
|
15377
|
-
if (words.length >
|
|
15654
|
+
if (words.length > MAX_WORDS2) throw new DomainError(400, `Search for at most ${MAX_WORDS2} words`);
|
|
15378
15655
|
return words;
|
|
15379
15656
|
}
|
|
15380
15657
|
function plainText(markdown) {
|
|
15381
15658
|
return markdown.replace(/^\s*```.*$/gm, " ").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/^\s{0,3}#{1,6}\s+/gm, "").replace(/^\s*>\s?/gm, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+/gm, "").replace(/^\s*\|?(?:\s*:?-{3,}:?\s*\|)+\s*:?-*:?\s*$/gm, " ").replace(/\|/g, " ").replace(/(\*\*|__|`)/g, "").replace(/(^|[\s(])[*_]([^*_\s][^*_]*?)[*_](?=[\s).,;:!?]|$)/g, "$1$2");
|
|
15382
15659
|
}
|
|
15383
|
-
function
|
|
15660
|
+
function snippetOf2(text4, words) {
|
|
15384
15661
|
const flat = plainText(text4).replace(/\s+/g, " ").trim();
|
|
15385
15662
|
const lower = flat.toLowerCase();
|
|
15386
15663
|
const at = Math.min(
|
|
15387
15664
|
...words.map((word) => lower.indexOf(word)).filter((index) => index >= 0),
|
|
15388
15665
|
flat.length
|
|
15389
15666
|
);
|
|
15390
|
-
const start2 = Math.max(0, at -
|
|
15391
|
-
const end = Math.min(flat.length, at +
|
|
15667
|
+
const start2 = Math.max(0, at - BEFORE2);
|
|
15668
|
+
const end = Math.min(flat.length, at + AFTER2);
|
|
15392
15669
|
return `${start2 > 0 ? "\u2026" : ""}${flat.slice(start2, end).trim()}${end < flat.length ? "\u2026" : ""}`;
|
|
15393
15670
|
}
|
|
15394
15671
|
async function searchConversations(db, paths, options) {
|
|
@@ -15420,8 +15697,7 @@ async function searchConversations(db, paths, options) {
|
|
|
15420
15697
|
if (!raw.every((word) => lower.includes(word))) continue;
|
|
15421
15698
|
let messages;
|
|
15422
15699
|
try {
|
|
15423
|
-
|
|
15424
|
-
messages = buildSessionContext2(entries.filter((entry) => entry.type !== "session")).messages;
|
|
15700
|
+
messages = conversationHistory(branchOf(parseSessionText(text4, row.id))).messages;
|
|
15425
15701
|
} catch {
|
|
15426
15702
|
unreadable++;
|
|
15427
15703
|
continue;
|
|
@@ -15449,7 +15725,7 @@ async function searchConversations(db, paths, options) {
|
|
|
15449
15725
|
active: row.selected === row.id,
|
|
15450
15726
|
role: message.role,
|
|
15451
15727
|
at: typeof at === "number" && Number.isFinite(at) ? at : null,
|
|
15452
|
-
snippet:
|
|
15728
|
+
snippet: snippetOf2(content, words),
|
|
15453
15729
|
nth: nth++
|
|
15454
15730
|
});
|
|
15455
15731
|
}
|
|
@@ -15851,14 +16127,15 @@ conversationsRouter.get("/:agentId/conversations/:id", (c) => {
|
|
|
15851
16127
|
const conversation = get16(db, agentId, id);
|
|
15852
16128
|
if (!conversation) return c.json({ error: "Conversation not found" }, 404);
|
|
15853
16129
|
try {
|
|
16130
|
+
const history = loadConversation(resolveAgent(db, paths, agentId), paths, { id });
|
|
15854
16131
|
const messages = piMessagesToProviderView(
|
|
15855
|
-
|
|
16132
|
+
history.messages,
|
|
15856
16133
|
envSecretValues(mergeSecretsIntoEnv(db, authToken))
|
|
15857
16134
|
);
|
|
15858
16135
|
const usage = conversationUsage2(paths, agentId, planProviders(mergeSecretsIntoEnv(db, authToken))).get(
|
|
15859
16136
|
id
|
|
15860
16137
|
) ?? null;
|
|
15861
|
-
return c.json({ conversation, messages, usage });
|
|
16138
|
+
return c.json({ conversation, messages, compactions: history.compactions, usage });
|
|
15862
16139
|
} catch {
|
|
15863
16140
|
return c.json(
|
|
15864
16141
|
{
|
|
@@ -17836,18 +18113,18 @@ async function attachPatches(captured, report, limits = REVIEW_LIMITS, onlyPath)
|
|
|
17836
18113
|
changes.push({ ...change, contentOmitted: "total_limit" });
|
|
17837
18114
|
continue;
|
|
17838
18115
|
}
|
|
17839
|
-
const
|
|
17840
|
-
const bytes =
|
|
17841
|
-
if (bytes > limits.fileBytes && !
|
|
18116
|
+
const read3 = await readChangePatch(captured, report.base, change, limits.patchBytes);
|
|
18117
|
+
const bytes = read3.patch ? Buffer.byteLength(read3.patch) : 0;
|
|
18118
|
+
if (bytes > limits.fileBytes && !read3.truncated) {
|
|
17842
18119
|
changes.push({ ...change, patch: null, contentOmitted: "too_large" });
|
|
17843
18120
|
continue;
|
|
17844
18121
|
}
|
|
17845
18122
|
total += bytes;
|
|
17846
18123
|
changes.push({
|
|
17847
18124
|
...change,
|
|
17848
|
-
patch:
|
|
17849
|
-
patchTruncated:
|
|
17850
|
-
contentOmitted:
|
|
18125
|
+
patch: read3.patch,
|
|
18126
|
+
patchTruncated: read3.truncated,
|
|
18127
|
+
contentOmitted: read3.omitted
|
|
17851
18128
|
});
|
|
17852
18129
|
}
|
|
17853
18130
|
return { ...report, changes };
|