(filePath)
| 9 | const MARKER = "__augment_byok_expose_upstream_v1"; |
| 10 | |
| 11 | function 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 | |
| 34 | module.exports = { patchExposeUpstream }; |
| 35 |
no test coverage detected