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

Function invokeWithLayer

packages/plugins/openapi/src/sdk/invoke.ts:1214–1249  ·  view source on GitHub ↗
(
  operation: OperationBinding,
  args: Record<string, unknown>,
  baseUrl: string,
  resolvedHeaders: Record<string, string>,
  integrationQueryParams: Record<string, string>,
  httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
  options: InvokeOptions = {},
)

Source from the content-addressed store, hash-verified

1212// ---------------------------------------------------------------------------
1213
1214export const invokeWithLayer = (
1215 operation: OperationBinding,
1216 args: Record<string, unknown>,
1217 baseUrl: string,
1218 resolvedHeaders: Record<string, string>,
1219 integrationQueryParams: Record<string, string>,
1220 httpClientLayer: Layer.Layer<HttpClient.HttpClient, never, never>,
1221 options: InvokeOptions = {},
1222) => {
1223 const effectiveBaseUrl = resolveRequestHost(operation.servers ?? [], args.server, baseUrl);
1224 const clientWithBaseUrl = effectiveBaseUrl
1225 ? Layer.effect(
1226 HttpClient.HttpClient,
1227 Effect.map(
1228 Effect.service(HttpClient.HttpClient),
1229 HttpClient.mapRequest(HttpClientRequest.prependUrl(effectiveBaseUrl)),
1230 ),
1231 ).pipe(Layer.provide(httpClientLayer))
1232 : httpClientLayer;
1233
1234 return invoke(operation, args, resolvedHeaders, integrationQueryParams, options).pipe(
1235 Effect.provide(clientWithBaseUrl),
1236 // `invoke` annotates http.status_code on ITS span (`OpenApi.invoke`,
1237 // via Effect.fn) — annotateCurrentSpan inside it never reaches this
1238 // wrapper span. Stamp the status here too so queries against
1239 // `plugin.openapi.invoke` see the upstream outcome directly.
1240 Effect.tap((result) => Effect.annotateCurrentSpan({ "http.status_code": result.status })),
1241 Effect.withSpan("plugin.openapi.invoke", {
1242 attributes: {
1243 "plugin.openapi.method": operation.method.toUpperCase(),
1244 "plugin.openapi.path_template": operation.pathTemplate,
1245 "plugin.openapi.base_url": effectiveBaseUrl,
1246 },
1247 }),
1248 );
1249};
1250
1251// ---------------------------------------------------------------------------
1252// Derive annotations from HTTP method

Calls 2

resolveRequestHostFunction · 0.85
invokeFunction · 0.85

Tested by

no test coverage detected