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

Function invokeWithLayer

packages/plugins/openapi/src/sdk/invoke.ts:922–956  ·  view source on GitHub ↗
(
  operation: OperationBinding,
  args: Record<string, unknown>,
  baseUrl: string,
  resolvedHeaders: Record<string, string>,
  sourceQueryParams: Record<string, string>,
  httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
)

Source from the content-addressed store, hash-verified

920// ---------------------------------------------------------------------------
921
922export const invokeWithLayer = (
923 operation: OperationBinding,
924 args: Record<string, unknown>,
925 baseUrl: string,
926 resolvedHeaders: Record<string, string>,
927 sourceQueryParams: Record<string, string>,
928 httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
929) => {
930 const effectiveBaseUrl = resolveRequestHost(operation.servers ?? [], args.server, baseUrl);
931 const clientWithBaseUrl = effectiveBaseUrl
932 ? Layer.effect(
933 HttpClient.HttpClient,
934 Effect.map(
935 Effect.service(HttpClient.HttpClient),
936 HttpClient.mapRequest(HttpClientRequest.prependUrl(effectiveBaseUrl)),
937 ),
938 ).pipe(Layer.provide(httpClientLayer))
939 : httpClientLayer;
940
941 return invoke(operation, args, resolvedHeaders, sourceQueryParams).pipe(
942 Effect.provide(clientWithBaseUrl),
943 // `invoke` annotates http.status_code on ITS span (`OpenApi.invoke`,
944 // via Effect.fn) — annotateCurrentSpan inside it never reaches this
945 // wrapper span. Stamp the status here too so queries against
946 // `plugin.openapi.invoke` see the upstream outcome directly.
947 Effect.tap((result) => Effect.annotateCurrentSpan({ "http.status_code": result.status })),
948 Effect.withSpan("plugin.openapi.invoke", {
949 attributes: {
950 "plugin.openapi.method": operation.method.toUpperCase(),
951 "plugin.openapi.path_template": operation.pathTemplate,
952 "plugin.openapi.base_url": effectiveBaseUrl,
953 },
954 }),
955 );
956};
957
958// ---------------------------------------------------------------------------
959// Derive annotations from HTTP method

Callers 4

invokeOpenApiBackedToolFunction · 0.90
checkHealthOpenApiFunction · 0.90

Calls 1

resolveRequestHostFunction · 0.85

Tested by

no test coverage detected