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

Function injectIntoAsyncMethods

tools/lib/patch.js:67–93  ·  view source on GitHub ↗
(src, methodName, buildInjection)

Source from the content-addressed store, hash-verified

65}
66
67function injectIntoAsyncMethods(src, methodName, buildInjection) {
68 const s = String(src || "");
69 const re = new RegExp(`async\\s+${methodName}\\s*\\(([^)]*)\\)`, "g");
70 const matches = Array.from(s.matchAll(re));
71 if (matches.length === 0) throw new Error(`${methodName} needle not found (upstream may have changed)`);
72
73 let out = s;
74 let patched = 0;
75 for (let i = matches.length - 1; i >= 0; i--) {
76 const match = matches[i];
77 const idx = typeof match.index === "number" ? match.index : -1;
78 if (idx < 0) throw new Error(`${methodName} needle match missing index`);
79 const openBrace = out.indexOf("{", idx);
80 if (openBrace < 0) throw new Error(`${methodName} patch: failed to locate method body opening brace`);
81
82 const injection =
83 typeof buildInjection === "function"
84 ? String(buildInjection({ params: parseParamNames(match[1] || ""), match, index: idx }) ?? "")
85 : String(buildInjection ?? "");
86 if (!injection) continue;
87
88 out = out.slice(0, openBrace + 1) + injection + out.slice(openBrace + 1);
89 patched += 1;
90 }
91
92 return { out, count: patched };
93}
94
95function injectIntoArrowPropertyFunctions(src, propertyName, buildInjection) {
96 const s = String(src || "");

Callers 5

patchCallApiShimFunction · 0.85
patchClientAuthGettersFunction · 0.85

Calls 2

buildInjectionFunction · 0.85
parseParamNamesFunction · 0.85

Tested by

no test coverage detected