MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / bindAllFunctions

Function bindAllFunctions

packages/agent-core/src/rpc/client.ts:72–92  ·  view source on GitHub ↗
(obj: T)

Source from the content-addressed store, hash-verified

70 }
71
72 function bindAllFunctions<T extends Record<string, any>>(obj: T): T {
73 const bound: Record<string, unknown> = {};
74 let current: object | null = obj;
75
76 while (current !== null && current !== Object.prototype) {
77 for (const key of Object.getOwnPropertyNames(current)) {
78 if (key === 'constructor' || Object.hasOwn(bound, key)) {
79 continue;
80 }
81
82 const descriptor = Object.getOwnPropertyDescriptor(current, key);
83 if (typeof descriptor?.value === 'function') {
84 bound[key] = descriptor.value.bind(obj);
85 }
86 }
87
88 current = Object.getPrototypeOf(current);
89 }
90
91 return bound as T;
92 }
93
94 async function leftClient(self: PromisableMethods<Left>): Promise<RPCMethods<Right>> {
95 left.resolve(bindAllFunctions(self));

Callers 2

leftClientFunction · 0.85
rightClientFunction · 0.85

Calls 1

getPrototypeOfMethod · 0.80

Tested by

no test coverage detected