MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / nest

Function nest

packages/hosts/mcp-apps-shell/src/shell/tools-proxy.ts:157–258  ·  view source on GitHub ↗
(path: string[], role: string | undefined)

Source from the content-addressed store, hash-verified

155 */
156export const createToolsProxy = (request: ToolCallTransport): Record<string, unknown> => {
157 const nest = (path: string[], role: string | undefined): unknown =>
158 new Proxy(function () {}, {
159 get(_target, key: string | symbol) {
160 if (key === "then" || key === "toJSON" || key === Symbol.toPrimitive) return undefined;
161 if (typeof key !== "string") return undefined;
162 if (key === "queryOptions") {
163 return (input?: unknown, options?: Omit<UseQueryOptions, "queryKey" | "queryFn">) =>
164 queryOptions({
165 ...options,
166 queryKey: toolQueryKey(path, role, input === skipToken ? undefined : input),
167 queryFn:
168 input === skipToken
169 ? skipToken
170 : () =>
171 request({
172 path,
173 args: [input ?? {}],
174 ...(role === undefined ? {} : { role }),
175 }),
176 });
177 }
178 if (key === "infiniteQueryOptions") {
179 return (input?: unknown, options?: ToolInfiniteQueryOptions) => {
180 const {
181 cursorKey = DEFAULT_CURSOR_KEY,
182 initialPageParam = null,
183 ...rest
184 } = options ?? {};
185 return infiniteQueryOptions({
186 ...rest,
187 initialPageParam,
188 queryKey: toolInfiniteQueryKey(path, role, input === skipToken ? undefined : input),
189 queryFn:
190 input === skipToken
191 ? skipToken
192 : ({ pageParam }: { pageParam: unknown }) =>
193 request({
194 path,
195 args: [withCursor(input, cursorKey, pageParam)],
196 ...(role === undefined ? {} : { role }),
197 }),
198 // oxlint-disable-next-line executor/no-double-cast -- boundary: TanStack's option types are generic over the page-param type the model supplies at runtime
199 } as unknown as UseInfiniteQueryOptions);
200 };
201 }
202 if (key === "infiniteQueryKey") {
203 return (input?: unknown) => toolInfiniteQueryKey(path, role, input);
204 }
205 if (key === "infiniteQueryFilter") {
206 return (input?: unknown, filters?: Omit<QueryFilters, "queryKey">) => ({
207 ...filters,
208 queryKey: toolInfiniteQueryKey(path, role, input),
209 });
210 }
211 if (key === "queryKey") {
212 return (input?: unknown) => toolQueryKey(path, role, input);
213 }
214 if (key === "queryFilter") {

Callers 3

getFunction · 0.85
applyFunction · 0.85
createToolsProxyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected