MCPcopy Create free account
hub / github.com/AnkRoot/Augment-BYOK / patchExposeUpstream

Function patchExposeUpstream

tools/patch/patch-expose-upstream.js:11–32  ·  view source on GitHub ↗
(filePath)

Source from the content-addressed store, hash-verified

9const MARKER = "__augment_byok_expose_upstream_v1";
10
11function patchExposeUpstream(filePath) {
12 const { original, alreadyPatched } = loadPatchText(filePath, { marker: MARKER });
13 if (alreadyPatched) return { changed: false, reason: "already_patched" };
14
15 const { classIdent, varName, terminatorIdx } = findFirstInstantiationOfExportedClass(original, "AugmentExtension");
16
17 const injection =
18 `;try{` +
19 `globalThis.__augment_byok_upstream=globalThis.__augment_byok_upstream||{};` +
20 `globalThis.__augment_byok_upstream.augmentExtension=${varName};` +
21 `globalThis.__augment_byok_upstream.officialChatDelegation=${varName};` +
22 `globalThis.__augment_byok_upstream.capturedAtMs=Date.now();` +
23 `if(${varName}&&typeof ${varName}.callApi==="function")globalThis.__augment_byok_upstream.callApiOriginal=${varName}.callApi.bind(${varName});` +
24 `if(${varName}&&typeof ${varName}.callApiStream==="function")globalThis.__augment_byok_upstream.callApiStreamOriginal=${varName}.callApiStream.bind(${varName});` +
25 `const __tm=(${varName}&&(${varName}._toolsModel||${varName}.toolsModel||${varName}.tools_model));` +
26 `if(__tm&&typeof __tm.getToolDefinitions==="function"&&typeof __tm.callTool==="function")globalThis.__augment_byok_upstream.toolsModel=__tm;` +
27 `}catch{}`;
28
29 const next = original.slice(0, terminatorIdx + 1) + injection + original.slice(terminatorIdx + 1);
30 savePatchText(filePath, next, { marker: MARKER });
31 return { changed: true, reason: "patched", classIdent, varName };
32}
33
34module.exports = { patchExposeUpstream };
35

Callers 3

applyByokPatchesFunction · 0.85

Calls 3

loadPatchTextFunction · 0.85
savePatchTextFunction · 0.85

Tested by

no test coverage detected