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

Function apiCall

e2e/scripts/cli.ts:389–431  ·  view source on GitHub ↗
(targetName: string, endpoint: string | undefined, json?: string)

Source from the content-addressed store, hash-verified

387};
388
389const apiCall = async (targetName: string, endpoint: string | undefined, json?: string) => {
390 if (!endpoint?.includes(".")) {
391 throw new Error("usage: api <target> <group.endpoint> [json] — e.g. api selfhost tools.list");
392 }
393 const { target } = await loadTarget(targetName);
394 const [group, method] = endpoint.split(".", 2) as [string, string];
395 // No-arg endpoints (tools.list) reject a spurious {}; only pass what was given.
396 const args = json === undefined ? undefined : (JSON.parse(json) as Record<string, unknown>);
397
398 const { Effect } = await import("effect");
399 const { FetchHttpClient } = await import("effect/unstable/http");
400 const { composePluginApi } = await import("@executor-js/api/server");
401 const { openApiHttpPlugin } = await import("@executor-js/plugin-openapi/api");
402 const { graphqlHttpPlugin } = await import("@executor-js/plugin-graphql/api");
403 const { mcpHttpPlugin } = await import("@executor-js/plugin-mcp/api");
404 const { makeApiSurface } = await import("../src/surfaces/api");
405
406 const apiDef = composePluginApi([
407 openApiHttpPlugin(),
408 graphqlHttpPlugin(),
409 mcpHttpPlugin(),
410 ] as const);
411 const surface = makeApiSurface(target);
412
413 // The endpoint is picked at runtime, so the client is driven untyped here —
414 // the full static typing lives in scenarios; this is the interactive probe.
415 const program = Effect.gen(function* () {
416 const who = yield* target.newIdentity();
417 // eslint-disable-next-line @typescript-eslint/no-explicit-any
418 const client: any = yield* surface.client(apiDef as any, who);
419 if (typeof client[group]?.[method] !== "function") {
420 const groups = Object.keys(client).filter((k) => typeof client[k] === "object");
421 throw new Error(`no endpoint ${endpoint}; groups: ${groups.join(", ")}`);
422 }
423 return yield* client[group][method](args);
424 }) as import("effect").Effect.Effect<
425 unknown,
426 unknown,
427 import("effect/unstable/http").HttpClient.HttpClient
428 >;
429 const result = await Effect.runPromise(program.pipe(Effect.provide(FetchHttpClient.layer)));
430 console.log(JSON.stringify(result, null, 2));
431};
432
433const mcpCall = async (
434 targetName: string,

Callers 1

mainFunction · 0.85

Calls 4

loadTargetFunction · 0.85
composePluginApiFunction · 0.85
makeApiSurfaceFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected