@executor-js/plugin-openapi 1.4.31 → 1.4.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AddOpenApiSource-KSOMPQ2R.js → AddOpenApiSource-NSCULGTM.js} +4 -4
- package/dist/{EditOpenApiSource-AOA7APR2.js → EditOpenApiSource-MV7NYTRP.js} +4 -4
- package/dist/{OpenApiSourceSummary-Y3S6ZBOZ.js → OpenApiSourceSummary-7JBS7PUV.js} +3 -3
- package/dist/{chunk-YJMXYKYX.js → chunk-2ZKKZYZH.js} +3 -3
- package/dist/{chunk-EOXXE5DG.js → chunk-AN4HJFNP.js} +4 -1
- package/dist/chunk-AN4HJFNP.js.map +1 -0
- package/dist/{chunk-NIKLYJ3X.js → chunk-PRVJDE43.js} +161 -18
- package/dist/chunk-PRVJDE43.js.map +1 -0
- package/dist/{chunk-ZZBTLFTA.js → chunk-X5JX3KTA.js} +2 -2
- package/dist/client.js +3 -3
- package/dist/core.js +2 -2
- package/dist/index.js +2 -2
- package/dist/sdk/errors.d.ts +19 -0
- package/package.json +3 -3
- package/dist/chunk-EOXXE5DG.js.map +0 -1
- package/dist/chunk-NIKLYJ3X.js.map +0 -1
- /package/dist/{AddOpenApiSource-KSOMPQ2R.js.map → AddOpenApiSource-NSCULGTM.js.map} +0 -0
- /package/dist/{EditOpenApiSource-AOA7APR2.js.map → EditOpenApiSource-MV7NYTRP.js.map} +0 -0
- /package/dist/{OpenApiSourceSummary-Y3S6ZBOZ.js.map → OpenApiSourceSummary-7JBS7PUV.js.map} +0 -0
- /package/dist/{chunk-YJMXYKYX.js.map → chunk-2ZKKZYZH.js.map} +0 -0
- /package/dist/{chunk-ZZBTLFTA.js.map → chunk-X5JX3KTA.js.map} +0 -0
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
inferOAuthIssuerUrl,
|
|
6
6
|
openApiOAuthConnectionId,
|
|
7
7
|
resolveOAuthUrl
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-2ZKKZYZH.js";
|
|
9
|
+
import "./chunk-X5JX3KTA.js";
|
|
10
|
+
import "./chunk-AN4HJFNP.js";
|
|
11
11
|
export {
|
|
12
12
|
OPENAPI_OAUTH_CALLBACK_PATH,
|
|
13
13
|
OPENAPI_OAUTH_POPUP_NAME,
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
openApiOAuthConnectionId,
|
|
17
17
|
resolveOAuthUrl
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=AddOpenApiSource-
|
|
19
|
+
//# sourceMappingURL=AddOpenApiSource-NSCULGTM.js.map
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
OpenApiSourceDetailsFields,
|
|
5
5
|
inferOAuthIssuerUrl,
|
|
6
6
|
resolveOAuthUrl
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-2ZKKZYZH.js";
|
|
8
8
|
import {
|
|
9
9
|
openApiSourceAtom,
|
|
10
10
|
openApiSourceBindingsAtom
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-X5JX3KTA.js";
|
|
12
12
|
import {
|
|
13
13
|
OAuth2SourceConfig,
|
|
14
14
|
oauth2ClientSecretSlot
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-AN4HJFNP.js";
|
|
16
16
|
|
|
17
17
|
// src/react/EditOpenApiSource.tsx
|
|
18
18
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -771,4 +771,4 @@ function EditOpenApiSource(props) {
|
|
|
771
771
|
export {
|
|
772
772
|
EditOpenApiSource as default
|
|
773
773
|
};
|
|
774
|
-
//# sourceMappingURL=EditOpenApiSource-
|
|
774
|
+
//# sourceMappingURL=EditOpenApiSource-MV7NYTRP.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
openApiSourceAtom,
|
|
3
3
|
openApiSourceBindingsAtom
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-X5JX3KTA.js";
|
|
5
5
|
import {
|
|
6
6
|
oauth2ClientSecretSlot
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AN4HJFNP.js";
|
|
8
8
|
|
|
9
9
|
// src/react/OpenApiSourceSummary.tsx
|
|
10
10
|
import { useAtomValue } from "@effect/atom-react";
|
|
@@ -119,4 +119,4 @@ function OpenApiSourceSummary(props) {
|
|
|
119
119
|
export {
|
|
120
120
|
OpenApiSourceSummary as default
|
|
121
121
|
};
|
|
122
|
-
//# sourceMappingURL=OpenApiSourceSummary-
|
|
122
|
+
//# sourceMappingURL=OpenApiSourceSummary-7JBS7PUV.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
addOpenApiSpecOptimistic,
|
|
3
3
|
previewOpenApiSpec
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-X5JX3KTA.js";
|
|
5
5
|
import {
|
|
6
6
|
OAuth2SourceConfig,
|
|
7
7
|
expandServerUrlOptions,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
queryParamBindingSlot,
|
|
13
13
|
specFetchHeaderBindingSlot,
|
|
14
14
|
specFetchQueryParamBindingSlot
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-AN4HJFNP.js";
|
|
16
16
|
|
|
17
17
|
// src/react/AddOpenApiSource.tsx
|
|
18
18
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -1178,4 +1178,4 @@ export {
|
|
|
1178
1178
|
inferOAuthIssuerUrl,
|
|
1179
1179
|
AddOpenApiSource
|
|
1180
1180
|
};
|
|
1181
|
-
//# sourceMappingURL=chunk-
|
|
1181
|
+
//# sourceMappingURL=chunk-2ZKKZYZH.js.map
|
|
@@ -26,6 +26,8 @@ var OpenApiOAuthError = class extends Schema.TaggedErrorClass()(
|
|
|
26
26
|
{ httpApiStatus: 400 }
|
|
27
27
|
) {
|
|
28
28
|
};
|
|
29
|
+
var OpenApiAuthRequiredError = class extends Data.TaggedError("OpenApiAuthRequiredError") {
|
|
30
|
+
};
|
|
29
31
|
|
|
30
32
|
// src/sdk/parse.ts
|
|
31
33
|
import { Duration, Effect, Schema as Schema2 } from "effect";
|
|
@@ -818,6 +820,7 @@ export {
|
|
|
818
820
|
OpenApiExtractionError,
|
|
819
821
|
OpenApiInvocationError,
|
|
820
822
|
OpenApiOAuthError,
|
|
823
|
+
OpenApiAuthRequiredError,
|
|
821
824
|
fetchSpecText,
|
|
822
825
|
resolveSpecText,
|
|
823
826
|
parse,
|
|
@@ -862,4 +865,4 @@ export {
|
|
|
862
865
|
oauth2ClientSecretSlot,
|
|
863
866
|
oauth2ConnectionSlot
|
|
864
867
|
};
|
|
865
|
-
//# sourceMappingURL=chunk-
|
|
868
|
+
//# sourceMappingURL=chunk-AN4HJFNP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/errors.ts","../src/sdk/parse.ts","../src/sdk/openapi-utils.ts","../src/sdk/types.ts","../src/sdk/extract.ts","../src/sdk/preview.ts","../src/sdk/source-contracts.ts"],"sourcesContent":["import { Data, Schema } from \"effect\";\nimport type { Option } from \"effect\";\nimport type { AuthToolFailureCode } from \"@executor-js/sdk/core\";\n\n// HTTP status lives on the class declaration so HttpApiBuilder's error\n// encoder (which reads `ast.annotations` off the schema it stored on\n// `group.addError(...)`) finds it. Applying the annotation post-hoc\n// via `.annotate(...)` in group.ts produced a transform-wrapper AST\n// whose status was not picked up — the error then slipped the typed\n// channel and was captured as a 500 by the observability middleware,\n// spamming Sentry on user misconfig.\nexport class OpenApiParseError extends Schema.TaggedErrorClass<OpenApiParseError>()(\n \"OpenApiParseError\",\n {\n message: Schema.String,\n },\n { httpApiStatus: 400 },\n) {}\n\nexport class OpenApiExtractionError extends Schema.TaggedErrorClass<OpenApiExtractionError>()(\n \"OpenApiExtractionError\",\n {\n message: Schema.String,\n },\n { httpApiStatus: 400 },\n) {}\n\nexport class OpenApiInvocationError extends Data.TaggedError(\"OpenApiInvocationError\")<{\n readonly message: string;\n readonly statusCode: Option.Option<number>;\n readonly cause?: unknown;\n}> {}\n\nexport class OpenApiOAuthError extends Schema.TaggedErrorClass<OpenApiOAuthError>()(\n \"OpenApiOAuthError\",\n {\n message: Schema.String,\n },\n { httpApiStatus: 400 },\n) {}\n\nexport class OpenApiAuthRequiredError extends Data.TaggedError(\"OpenApiAuthRequiredError\")<{\n readonly code: AuthToolFailureCode;\n readonly message: string;\n readonly sourceId: string;\n readonly sourceScope: string;\n readonly credentialKind: \"secret\" | \"connection\" | \"oauth\" | \"upstream\";\n readonly credentialLabel?: string;\n readonly slotKey?: string;\n readonly secretId?: string;\n readonly connectionId?: string;\n readonly status?: number;\n readonly details?: unknown;\n readonly cause?: unknown;\n}> {}\n","import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from \"openapi-types\";\nimport { Duration, Effect, Schema } from \"effect\";\nimport { HttpClient, HttpClientRequest } from \"effect/unstable/http\";\nimport YAML from \"yaml\";\n\nimport { OpenApiExtractionError, OpenApiParseError } from \"./errors\";\n\nexport type ParsedDocument = OpenAPIV3.Document | OpenAPIV3_1.Document;\n\nexport interface SpecFetchCredentials {\n readonly headers?: Record<string, string>;\n readonly queryParams?: Record<string, string>;\n}\n\n// ExtractionError subclass raised from parse() for non-3.x specs\nclass OpenApiExtractionErrorFromParse extends OpenApiExtractionError {}\n\n/**\n * Fetch an OpenAPI spec URL and return its body text. Uses the Effect\n * HttpClient so the caller chooses the transport via layer — in Cloudflare\n * Workers, `FetchHttpClient.layer` binds to the Workers-native `fetch`.\n * Bounded by a 60s timeout.\n */\nexport const fetchSpecText = Effect.fn(\"OpenApi.fetchSpecText\")(function* (\n url: string,\n credentials?: SpecFetchCredentials,\n) {\n const client = yield* HttpClient.HttpClient;\n const requestUrl = new URL(url);\n for (const [name, value] of Object.entries(credentials?.queryParams ?? {})) {\n requestUrl.searchParams.set(name, value);\n }\n let request = HttpClientRequest.get(requestUrl.toString()).pipe(\n HttpClientRequest.setHeader(\"Accept\", \"application/json, application/yaml, text/yaml, */*\"),\n );\n for (const [name, value] of Object.entries(credentials?.headers ?? {})) {\n request = HttpClientRequest.setHeader(request, name, value);\n }\n const response = yield* client.execute(request).pipe(\n Effect.timeout(Duration.seconds(60)),\n Effect.mapError(\n (_cause) =>\n new OpenApiParseError({\n message: \"Failed to fetch OpenAPI document\",\n }),\n ),\n );\n if (response.status < 200 || response.status >= 300) {\n return yield* new OpenApiParseError({\n message: `Failed to fetch OpenAPI document: HTTP ${response.status}`,\n });\n }\n return yield* response.text.pipe(\n Effect.mapError(\n (_cause) =>\n new OpenApiParseError({\n message: \"Failed to read OpenAPI document body\",\n }),\n ),\n );\n});\n\n/**\n * Resolve an input string to spec text — if it's a URL, fetch it via\n * HttpClient; otherwise return it as-is.\n */\nexport const resolveSpecText = (input: string, credentials?: SpecFetchCredentials) =>\n input.startsWith(\"http://\") || input.startsWith(\"https://\")\n ? fetchSpecText(input, credentials)\n : Effect.succeed(input);\n\n/**\n * Parse an OpenAPI document from spec text and validate it's OpenAPI 3.x.\n *\n * NOTE: does NOT resolve `$ref`s. `DocResolver` + `normalizeOpenApiRefs`\n * downstream work on refs lazily, so inlining them here would just waste\n * memory — and for big specs (e.g. Cloudflare's API) that blows through\n * the 128MB Cloudflare Workers memory cap.\n */\nexport const parse = Effect.fn(\"OpenApi.parse\")(function* (text: string) {\n const api = yield* parseTextToObject(text);\n\n if (!isOpenApi3(api)) {\n return yield* new OpenApiExtractionErrorFromParse({\n message:\n \"Only OpenAPI 3.x documents are supported. Swagger 2.x documents should be converted first.\",\n });\n }\n\n return api as ParsedDocument;\n});\n\n// ---------------------------------------------------------------------------\n// Internals\n// ---------------------------------------------------------------------------\n\nconst isOpenApi3 = (doc: OpenAPI.Document): doc is OpenAPIV3.Document | OpenAPIV3_1.Document =>\n \"openapi\" in doc && typeof doc.openapi === \"string\" && doc.openapi.startsWith(\"3.\");\n\nconst parseTextToObject = (text: string): Effect.Effect<OpenAPI.Document, OpenApiParseError> =>\n Effect.gen(function* () {\n const trimmed = text.trim();\n if (trimmed.length === 0) {\n return yield* new OpenApiParseError({\n message: \"OpenAPI document is empty\",\n });\n }\n\n const parsed = yield* parseJsonLike(trimmed).pipe(\n Effect.mapError(\n () =>\n new OpenApiParseError({\n message: \"Failed to parse OpenAPI document\",\n }),\n ),\n );\n\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n return yield* new OpenApiParseError({\n message: \"OpenAPI document must parse to an object\",\n });\n }\n\n return parsed as OpenAPI.Document;\n });\n\nconst parseJsonText = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));\n\nconst parseJsonLike = (text: string): Effect.Effect<unknown, unknown> => {\n const parseYaml = Effect.try({\n try: () => YAML.parse(text) as unknown,\n catch: () => \"YamlParseFailed\" as const,\n });\n if (!text.startsWith(\"{\") && !text.startsWith(\"[\")) return parseYaml;\n return parseJsonText(text).pipe(Effect.catch(() => parseYaml));\n};\n","// ---------------------------------------------------------------------------\n// OpenAPI type aliases and $ref resolution\n//\n// Wraps the openapi-types V3/V3_1 union mess and provides clean ref resolution.\n// ---------------------------------------------------------------------------\n\nimport { Option } from \"effect\";\nimport type { OpenAPIV3, OpenAPIV3_1 } from \"openapi-types\";\nimport type { ParsedDocument } from \"./parse\";\nimport type { ServerVariable } from \"./types\";\n\n// ---------------------------------------------------------------------------\n// Type aliases — collapse V3 / V3_1 unions into single names\n// ---------------------------------------------------------------------------\n\nexport type ParameterObject = OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject;\nexport type OperationObject = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject;\nexport type PathItemObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject;\nexport type RequestBodyObject = OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject;\nexport type ResponseObject = OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject;\nexport type MediaTypeObject = OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject;\n\n// ---------------------------------------------------------------------------\n// DocResolver — wraps a parsed document for clean $ref resolution\n// ---------------------------------------------------------------------------\n\nexport class DocResolver {\n constructor(readonly doc: ParsedDocument) {}\n\n /** Resolve a value that might be a $ref, returning the resolved object */\n resolve<T>(value: T | OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject): T | null {\n if (isRef(value)) {\n const resolved = this.resolvePointer(value.$ref);\n return resolved as T | null;\n }\n return value as T;\n }\n\n private resolvePointer(ref: string): unknown {\n if (!ref.startsWith(\"#/\")) return null;\n const segments = ref.slice(2).split(\"/\");\n let current: unknown = this.doc;\n for (const segment of segments) {\n if (typeof current !== \"object\" || current === null) return null;\n current = (current as Record<string, unknown>)[segment];\n }\n return current;\n }\n}\n\nconst isRef = (value: unknown): value is { $ref: string } =>\n typeof value === \"object\" && value !== null && \"$ref\" in value;\n\n// ---------------------------------------------------------------------------\n// Server URL resolution\n// ---------------------------------------------------------------------------\n\n/** Substitute `{var}` placeholders in a templated URL using a plain map. */\nexport const substituteUrlVariables = (url: string, values: Record<string, string>): string => {\n let out = url;\n for (const [name, value] of Object.entries(values)) {\n out = out.replaceAll(`{${name}}`, value);\n }\n return out;\n};\n\nexport const OPENAPI_MAX_SERVER_VARIABLE_OPTIONS = 64;\n\ntype ServerLike = {\n url: string;\n variables: import(\"effect/Option\").Option<Record<string, ServerVariable | string>>;\n};\n\nexport const expandServerUrlOptions = (\n server: ServerLike,\n limit = OPENAPI_MAX_SERVER_VARIABLE_OPTIONS,\n): readonly string[] => {\n if (!Option.isSome(server.variables)) return [server.url];\n let urls: readonly string[] = [server.url];\n for (const [name, variable] of Object.entries(server.variables.value)) {\n const enumValues =\n typeof variable === \"string\" ? [] : Option.getOrElse(variable.enum, () => []);\n const values =\n enumValues.length > 0\n ? enumValues\n : [typeof variable === \"string\" ? variable : variable.default];\n const next: string[] = [];\n for (const url of urls) {\n for (const value of values) {\n next.push(url.replaceAll(`{${name}}`, value));\n if (next.length >= limit) return next;\n }\n }\n urls = next;\n }\n return urls;\n};\n\nexport const resolveBaseUrl = (servers: readonly ServerLike[]): string => {\n const server = servers[0];\n if (!server) return \"\";\n\n if (!Option.isSome(server.variables)) return server.url;\n\n const values: Record<string, string> = {};\n for (const [name, v] of Object.entries(server.variables.value)) {\n values[name] = typeof v === \"string\" ? v : v.default;\n }\n return substituteUrlVariables(server.url, values);\n};\n\n// ---------------------------------------------------------------------------\n// Content negotiation\n// ---------------------------------------------------------------------------\n\n/**\n * Return all declared media entries in spec order. `Object.entries` on a\n * plain object preserves insertion order in modern engines, which matches\n * spec declaration order as the parser produced it.\n */\nexport const declaredContents = (\n content: Record<string, MediaTypeObject> | undefined,\n): ReadonlyArray<{ mediaType: string; media: MediaTypeObject }> => {\n if (!content) return [];\n return Object.entries(content).map(([mediaType, media]) => ({ mediaType, media }));\n};\n\n/**\n * Pick the default media type for a requestBody or response. Matches\n * swagger-client behaviour: **first declared wins** (not JSON-first). Spec\n * authors order content entries to signal intent (upload-heavy endpoints\n * declare multipart first, JSON second); respecting that order avoids\n * silently downgrading a multipart endpoint to JSON.\n *\n * For response bodies we still want a JSON preference because the server\n * picks the response content type, not the client — the old `application/\n * json` preference is preserved via `preferredResponseContent` below.\n */\nexport const preferredContent = (\n content: Record<string, MediaTypeObject> | undefined,\n): { mediaType: string; media: MediaTypeObject } | undefined => {\n const first = declaredContents(content)[0];\n return first ? first : undefined;\n};\n\n/** Response-side content picker — still JSON-first because the server\n * picks the response media type, so we want to advertise a preference. */\nexport const preferredResponseContent = (\n content: Record<string, MediaTypeObject> | undefined,\n): { mediaType: string; media: MediaTypeObject } | undefined => {\n if (!content) return undefined;\n const entries = Object.entries(content);\n const pick =\n entries.find(([mt]) => mt === \"application/json\") ??\n entries.find(([mt]) => mt.toLowerCase().includes(\"+json\")) ??\n entries.find(([mt]) => mt.toLowerCase().includes(\"json\")) ??\n entries[0];\n return pick ? { mediaType: pick[0], media: pick[1] } : undefined;\n};\n","import { Schema } from \"effect\";\nimport { ScopedSecretCredentialInput, SecretBackedValue } from \"@executor-js/sdk/shared\";\nimport {\n OAuth2Flow as HttpOAuth2Flow,\n OAuth2SourceConfig as SharedOAuth2SourceConfig,\n type OAuth2FlowType,\n type OAuth2SourceConfigType,\n} from \"@executor-js/sdk/http-source\";\n\nexport const OAuth2Flow = HttpOAuth2Flow;\nexport type OAuth2Flow = OAuth2FlowType;\nexport const OAuth2SourceConfig = SharedOAuth2SourceConfig;\nexport type OAuth2SourceConfig = OAuth2SourceConfigType;\n\n// ---------------------------------------------------------------------------\n// Branded IDs\n// ---------------------------------------------------------------------------\n\nexport const OperationId = Schema.String.pipe(Schema.brand(\"OperationId\"));\nexport type OperationId = typeof OperationId.Type;\n\n// ---------------------------------------------------------------------------\n// HTTP\n// ---------------------------------------------------------------------------\n\nexport const HttpMethod = Schema.Literals([\n \"get\",\n \"put\",\n \"post\",\n \"delete\",\n \"patch\",\n \"head\",\n \"options\",\n \"trace\",\n]);\nexport type HttpMethod = typeof HttpMethod.Type;\n\nexport const ParameterLocation = Schema.Literals([\"path\", \"query\", \"header\", \"cookie\"]);\nexport type ParameterLocation = typeof ParameterLocation.Type;\n\n// ---------------------------------------------------------------------------\n// Extracted operation\n// ---------------------------------------------------------------------------\n\nexport const OperationParameter = Schema.Struct({\n name: Schema.String,\n location: ParameterLocation,\n required: Schema.Boolean,\n schema: Schema.OptionFromOptional(Schema.Unknown),\n style: Schema.OptionFromOptional(Schema.String),\n explode: Schema.OptionFromOptional(Schema.Boolean),\n allowReserved: Schema.OptionFromOptional(Schema.Boolean),\n description: Schema.OptionFromOptional(Schema.String),\n});\nexport type OperationParameter = typeof OperationParameter.Type;\n\n/**\n * OpenAPI 3.x `Encoding Object` (§4.8.15). Declared per-property inside a\n * multipart/form-data or application/x-www-form-urlencoded request body.\n *\n * - `contentType` — for multipart, overrides the per-part `Content-Type`\n * header (e.g. `application/json` for a JSON-encoded metadata part).\n * - `style` / `explode` / `allowReserved` — for form-urlencoded, control\n * array / object serialization the same way parameter-level style does.\n */\nexport const EncodingObject = Schema.Struct({\n contentType: Schema.OptionFromOptional(Schema.String),\n style: Schema.OptionFromOptional(Schema.String),\n explode: Schema.OptionFromOptional(Schema.Boolean),\n allowReserved: Schema.OptionFromOptional(Schema.Boolean),\n});\nexport type EncodingObject = typeof EncodingObject.Type;\n\nexport const MediaBinding = Schema.Struct({\n contentType: Schema.String,\n schema: Schema.OptionFromOptional(Schema.Unknown),\n encoding: Schema.OptionFromOptional(Schema.Record(Schema.String, EncodingObject)),\n});\nexport type MediaBinding = typeof MediaBinding.Type;\n\nexport const OperationRequestBody = Schema.Struct({\n required: Schema.Boolean,\n /** Default media type — first declared in spec order (not JSON-first).\n * Used when the caller does not override via the tool's `contentType` arg. */\n contentType: Schema.String,\n /** Schema of the default media type. Kept for backward compat with stored\n * bindings from before `contents` was added. */\n schema: Schema.OptionFromOptional(Schema.Unknown),\n /** All declared media types in spec order. Populated by `extract.ts`\n * going forward; older persisted bindings may have this unset and will\n * fall back to `{contentType, schema}`. */\n contents: Schema.OptionFromOptional(Schema.Array(MediaBinding)),\n});\nexport type OperationRequestBody = typeof OperationRequestBody.Type;\n\nexport const ExtractedOperation = Schema.Struct({\n operationId: OperationId,\n method: HttpMethod,\n pathTemplate: Schema.String,\n summary: Schema.OptionFromOptional(Schema.String),\n description: Schema.OptionFromOptional(Schema.String),\n tags: Schema.Array(Schema.String),\n parameters: Schema.Array(OperationParameter),\n requestBody: Schema.OptionFromOptional(OperationRequestBody),\n inputSchema: Schema.OptionFromOptional(Schema.Unknown),\n outputSchema: Schema.OptionFromOptional(Schema.Unknown),\n deprecated: Schema.Boolean,\n});\nexport type ExtractedOperation = typeof ExtractedOperation.Type;\n\nexport const ServerVariable = Schema.Struct({\n default: Schema.String,\n enum: Schema.OptionFromOptional(Schema.Array(Schema.String)),\n description: Schema.OptionFromOptional(Schema.String),\n});\nexport type ServerVariable = typeof ServerVariable.Type;\n\nexport const ServerInfo = Schema.Struct({\n url: Schema.String,\n description: Schema.OptionFromOptional(Schema.String),\n variables: Schema.OptionFromOptional(Schema.Record(Schema.String, ServerVariable)),\n});\nexport type ServerInfo = typeof ServerInfo.Type;\n\nexport const ExtractionResult = Schema.Struct({\n title: Schema.OptionFromOptional(Schema.String),\n version: Schema.OptionFromOptional(Schema.String),\n servers: Schema.Array(ServerInfo),\n operations: Schema.Array(ExtractedOperation),\n});\nexport type ExtractionResult = typeof ExtractionResult.Type;\n\n// ---------------------------------------------------------------------------\n// Operation binding — minimal invocation data (no schemas/metadata)\n// ---------------------------------------------------------------------------\n\nexport const OperationBinding = Schema.Struct({\n method: HttpMethod,\n pathTemplate: Schema.String,\n parameters: Schema.Array(OperationParameter),\n requestBody: Schema.OptionFromOptional(OperationRequestBody),\n});\nexport type OperationBinding = typeof OperationBinding.Type;\n\n// ---------------------------------------------------------------------------\n// Invocation\n// ---------------------------------------------------------------------------\n\n/**\n * A header value — either a static string or a reference to a secret.\n * Stored as JSON-serializable data.\n */\nexport const HeaderValue = SecretBackedValue;\nexport type HeaderValue = typeof HeaderValue.Type;\n\nexport const ConfiguredHeaderBinding = Schema.Struct({\n kind: Schema.Literal(\"binding\"),\n slot: Schema.String,\n prefix: Schema.optional(Schema.String),\n}).annotate({ identifier: \"OpenApiConfiguredHeaderBinding\" });\nexport type ConfiguredHeaderBinding = typeof ConfiguredHeaderBinding.Type;\n\nexport const ConfiguredHeaderValue = Schema.Union([Schema.String, ConfiguredHeaderBinding]);\nexport type ConfiguredHeaderValue = typeof ConfiguredHeaderValue.Type;\n\nexport const OpenApiCredentialInput = Schema.Union([\n ScopedSecretCredentialInput,\n HeaderValue,\n ConfiguredHeaderValue,\n]);\nexport type OpenApiCredentialInput = typeof OpenApiCredentialInput.Type;\n\n// ---------------------------------------------------------------------------\n// OAuth2 source config — carries source-owned slots and API-level config to\n// kick off a fresh sign-in from the source detail UI without needing any\n// one user's live connection to still exist.\n//\n// Split of responsibilities:\n// - The Source owns: the OAuth config (tokenUrl, authorizationUrl,\n// client credential slots, connection slot, scopes, flow,\n// securitySchemeName).\n// Values are a property of the target API, identical for every user\n// signing into this source. Source-owned = reconnect works even if\n// the connection row has been removed.\n// - The Connection owns: live access/refresh tokens, token expiry,\n// provider state the refresh path reads from. The connection's\n// `providerState` caches the refresh-relevant bits of the config\n// so the refresh loop never reaches back into source storage.\n//\n// This is a deliberate small duplication (scopes + tokenUrl and the static\n// client credential ids referenced by slots appear in source bindings and\n// connection providerState). The values are static per source so the two\n// copies can't drift under normal reconnect flows.\n// ---------------------------------------------------------------------------\n\nexport const InvocationResult = Schema.Struct({\n status: Schema.Number,\n headers: Schema.Record(Schema.String, Schema.String),\n data: Schema.NullOr(Schema.Unknown),\n error: Schema.NullOr(Schema.Unknown),\n});\nexport type InvocationResult = typeof InvocationResult.Type;\n","import { Effect, Option } from \"effect\";\n\nimport { OpenApiExtractionError } from \"./errors\";\nimport type { ParsedDocument } from \"./parse\";\nimport {\n declaredContents,\n DocResolver,\n preferredResponseContent,\n type OperationObject,\n type ParameterObject,\n type PathItemObject,\n type RequestBodyObject,\n type ResponseObject,\n} from \"./openapi-utils\";\nimport {\n EncodingObject,\n ExtractedOperation,\n ExtractionResult,\n type HttpMethod,\n MediaBinding,\n OperationId,\n OperationParameter,\n OperationRequestBody,\n type ParameterLocation,\n ServerInfo,\n ServerVariable,\n} from \"./types\";\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst HTTP_METHODS: readonly HttpMethod[] = [\n \"get\",\n \"put\",\n \"post\",\n \"delete\",\n \"patch\",\n \"head\",\n \"options\",\n \"trace\",\n];\n\nconst VALID_PARAM_LOCATIONS = new Set<string>([\"path\", \"query\", \"header\", \"cookie\"]);\n\n// ---------------------------------------------------------------------------\n// Parameter extraction\n// ---------------------------------------------------------------------------\n\nconst extractParameters = (\n pathItem: PathItemObject,\n operation: OperationObject,\n r: DocResolver,\n): OperationParameter[] => {\n const merged = new Map<string, ParameterObject>();\n\n for (const raw of pathItem.parameters ?? []) {\n const p = r.resolve<ParameterObject>(raw);\n if (!p) continue;\n merged.set(`${p.in}:${p.name}`, p);\n }\n for (const raw of operation.parameters ?? []) {\n const p = r.resolve<ParameterObject>(raw);\n if (!p) continue;\n merged.set(`${p.in}:${p.name}`, p);\n }\n\n return [...merged.values()]\n .filter((p) => VALID_PARAM_LOCATIONS.has(p.in))\n .map((p) =>\n OperationParameter.make({\n name: p.name,\n location: p.in as ParameterLocation,\n required: p.in === \"path\" ? true : p.required === true,\n schema: Option.fromNullishOr(p.schema),\n style: Option.fromNullishOr(p.style),\n explode: Option.fromNullishOr(p.explode),\n allowReserved: Option.fromNullishOr(\"allowReserved\" in p ? p.allowReserved : undefined),\n description: Option.fromNullishOr(p.description),\n }),\n );\n};\n\n// ---------------------------------------------------------------------------\n// Request body extraction\n// ---------------------------------------------------------------------------\n\nconst buildEncodingRecord = (\n encoding: Record<string, unknown> | undefined,\n): Record<string, EncodingObject> | undefined => {\n if (!encoding) return undefined;\n const out: Record<string, EncodingObject> = {};\n for (const [prop, raw] of Object.entries(encoding)) {\n if (typeof raw !== \"object\" || raw === null) continue;\n const e = raw as {\n contentType?: string;\n style?: string;\n explode?: boolean;\n allowReserved?: boolean;\n };\n out[prop] = EncodingObject.make({\n contentType: Option.fromNullishOr(e.contentType),\n style: Option.fromNullishOr(e.style),\n explode: Option.fromNullishOr(e.explode),\n allowReserved: Option.fromNullishOr(e.allowReserved),\n });\n }\n return Object.keys(out).length > 0 ? out : undefined;\n};\n\nconst extractRequestBody = (\n operation: OperationObject,\n r: DocResolver,\n): OperationRequestBody | undefined => {\n if (!operation.requestBody) return undefined;\n\n const body = r.resolve<RequestBodyObject>(operation.requestBody);\n if (!body) return undefined;\n\n const contents = declaredContents(body.content).map(({ mediaType, media }) =>\n MediaBinding.make({\n contentType: mediaType,\n schema: Option.fromNullishOr(media.schema),\n encoding: Option.fromNullishOr(\n buildEncodingRecord((media as { encoding?: Record<string, unknown> }).encoding),\n ),\n }),\n );\n if (contents.length === 0) return undefined;\n\n // Default = first declared (spec author's preferred order). Callers can\n // override at invoke time with a `contentType` arg.\n const defaultContent = contents[0]!;\n\n return OperationRequestBody.make({\n required: body.required === true,\n contentType: defaultContent.contentType,\n schema: defaultContent.schema,\n contents: Option.some(contents),\n });\n};\n\n// ---------------------------------------------------------------------------\n// Response schema extraction\n// ---------------------------------------------------------------------------\n\nconst extractOutputSchema = (operation: OperationObject, r: DocResolver): unknown | undefined => {\n if (!operation.responses) return undefined;\n\n const entries = Object.entries(operation.responses);\n const preferred = [\n ...entries.filter(([s]) => /^2\\d\\d$/.test(s)).sort(([a], [b]) => a.localeCompare(b)),\n ...entries.filter(([s]) => s === \"default\"),\n ];\n\n for (const [, ref] of preferred) {\n const resp = r.resolve<ResponseObject>(ref);\n if (!resp) continue;\n const content = preferredResponseContent(resp.content);\n if (content?.media.schema) return content.media.schema;\n }\n\n return undefined;\n};\n\n// ---------------------------------------------------------------------------\n// Input schema builder\n// ---------------------------------------------------------------------------\n\nconst buildInputSchema = (\n parameters: readonly OperationParameter[],\n requestBody: OperationRequestBody | undefined,\n): Record<string, unknown> | undefined => {\n const properties: Record<string, unknown> = {};\n const required: string[] = [];\n\n for (const param of parameters) {\n properties[param.name] = Option.getOrElse(param.schema, () => ({ type: \"string\" }));\n if (param.required) required.push(param.name);\n }\n\n if (requestBody) {\n properties.body = Option.getOrElse(requestBody.schema, () => ({ type: \"object\" }));\n if (requestBody.required) required.push(\"body\");\n\n // When the spec declares multiple media types for this requestBody,\n // expose `contentType` so the model can pick. Default = first declared.\n // `body` schema tracks the default; the model is responsible for\n // supplying a body shape that matches whichever contentType it picks.\n const contents = Option.getOrUndefined(requestBody.contents);\n if (contents && contents.length > 1) {\n properties.contentType = {\n type: \"string\",\n enum: contents.map((c) => c.contentType),\n default: requestBody.contentType,\n description:\n \"Content-Type for the request body. Declared media types for this operation, in spec order.\",\n };\n }\n }\n\n if (Object.keys(properties).length === 0) return undefined;\n\n return {\n type: \"object\",\n properties,\n ...(required.length > 0 ? { required } : {}),\n additionalProperties: false,\n };\n};\n\n// ---------------------------------------------------------------------------\n// Operation ID derivation\n// ---------------------------------------------------------------------------\n\nconst deriveOperationId = (\n method: HttpMethod,\n pathTemplate: string,\n operation: OperationObject,\n): string =>\n operation.operationId ??\n (`${method}_${pathTemplate.replace(/[^a-zA-Z0-9]+/g, \"_\")}`.replace(/^_+|_+$/g, \"\") ||\n `${method}_operation`);\n\n// ---------------------------------------------------------------------------\n// Server extraction\n// ---------------------------------------------------------------------------\n\nconst extractServers = (doc: ParsedDocument): ServerInfo[] =>\n (doc.servers ?? []).flatMap((server) => {\n if (!server.url) return [];\n const vars = server.variables\n ? Object.fromEntries(\n Object.entries(server.variables).flatMap(([name, v]) => {\n if (v.default === undefined || v.default === null) return [];\n const enumValues = Array.isArray(v.enum)\n ? v.enum.filter((x): x is string => typeof x === \"string\")\n : undefined;\n return [\n [\n name,\n ServerVariable.make({\n default: String(v.default),\n enum:\n enumValues && enumValues.length > 0 ? Option.some(enumValues) : Option.none(),\n description: Option.fromNullishOr(v.description),\n }),\n ],\n ];\n }),\n )\n : undefined;\n return [\n ServerInfo.make({\n url: server.url,\n description: Option.fromNullishOr(server.description),\n variables: vars && Object.keys(vars).length > 0 ? Option.some(vars) : Option.none(),\n }),\n ];\n });\n\n// ---------------------------------------------------------------------------\n// Main extraction\n// ---------------------------------------------------------------------------\n\n/** Extract all operations from a bundled OpenAPI 3.x document */\nexport const extract = Effect.fn(\"OpenApi.extract\")(function* (doc: ParsedDocument) {\n const paths = doc.paths;\n if (!paths) {\n return yield* new OpenApiExtractionError({\n message: \"OpenAPI document has no paths defined\",\n });\n }\n\n const r = new DocResolver(doc);\n const operations: ExtractedOperation[] = [];\n\n for (const [pathTemplate, pathItem] of Object.entries(paths).sort(([a], [b]) =>\n a.localeCompare(b),\n )) {\n if (!pathItem) continue;\n\n for (const method of HTTP_METHODS) {\n const operation = pathItem[method];\n if (!operation) continue;\n\n const parameters = extractParameters(pathItem, operation, r);\n const requestBody = extractRequestBody(operation, r);\n const inputSchema = buildInputSchema(parameters, requestBody);\n const outputSchema = extractOutputSchema(operation, r);\n const tags = (operation.tags ?? []).filter((t) => t.trim().length > 0);\n\n operations.push(\n ExtractedOperation.make({\n operationId: OperationId.make(deriveOperationId(method, pathTemplate, operation)),\n method,\n pathTemplate,\n summary: Option.fromNullishOr(operation.summary),\n description: Option.fromNullishOr(operation.description),\n tags,\n parameters,\n requestBody: Option.fromNullishOr(requestBody),\n inputSchema: Option.fromNullishOr(inputSchema),\n outputSchema: Option.fromNullishOr(outputSchema),\n deprecated: operation.deprecated === true,\n }),\n );\n }\n }\n\n return ExtractionResult.make({\n title: Option.fromNullishOr(doc.info?.title),\n version: Option.fromNullishOr(doc.info?.version),\n servers: extractServers(doc),\n operations,\n });\n});\n","import { Effect, Option, Predicate } from \"effect\";\nimport { Schema } from \"effect\";\n\nimport { parse, resolveSpecText, type ParsedDocument } from \"./parse\";\nimport { extract } from \"./extract\";\nimport { DocResolver } from \"./openapi-utils\";\nimport { HttpMethod, ServerInfo, type ExtractionResult } from \"./types\";\n\n// ---------------------------------------------------------------------------\n// OAuth 2.0 flows — one entry per supported grant type\n// ---------------------------------------------------------------------------\n\n/** Scopes declared by a flow: `{ scopeName: description }` */\nconst OAuth2Scopes = Schema.Record(Schema.String, Schema.String);\nconst SecuritySchemeType = Schema.Literals([\"http\", \"apiKey\", \"oauth2\", \"openIdConnect\"]);\ntype SecuritySchemeType = typeof SecuritySchemeType.Type;\n\nconst decodeSecuritySchemeType = Schema.decodeUnknownOption(SecuritySchemeType);\n\nexport const OAuth2AuthorizationCodeFlow = Schema.Struct({\n authorizationUrl: Schema.String,\n tokenUrl: Schema.String,\n refreshUrl: Schema.OptionFromOptional(Schema.String),\n scopes: OAuth2Scopes,\n});\nexport type OAuth2AuthorizationCodeFlow = typeof OAuth2AuthorizationCodeFlow.Type;\n\nexport const OAuth2ClientCredentialsFlow = Schema.Struct({\n tokenUrl: Schema.String,\n refreshUrl: Schema.OptionFromOptional(Schema.String),\n scopes: OAuth2Scopes,\n});\nexport type OAuth2ClientCredentialsFlow = typeof OAuth2ClientCredentialsFlow.Type;\n\nexport const OAuth2Flows = Schema.Struct({\n authorizationCode: Schema.OptionFromOptional(OAuth2AuthorizationCodeFlow),\n clientCredentials: Schema.OptionFromOptional(OAuth2ClientCredentialsFlow),\n});\nexport type OAuth2Flows = typeof OAuth2Flows.Type;\n\n// ---------------------------------------------------------------------------\n// Security scheme — what the spec declares it needs\n// ---------------------------------------------------------------------------\n\nexport const SecurityScheme = Schema.Struct({\n /** Key name in components.securitySchemes (e.g. \"api_token\") */\n name: Schema.String,\n /** OpenAPI security scheme type */\n type: SecuritySchemeType,\n /** For type: \"http\" — e.g. \"bearer\", \"basic\" */\n scheme: Schema.OptionFromOptional(Schema.String),\n /** For type: \"http\" with scheme \"bearer\" — e.g. \"JWT\" */\n bearerFormat: Schema.OptionFromOptional(Schema.String),\n /** For type: \"apiKey\" — where the key goes */\n in: Schema.OptionFromOptional(Schema.Literals([\"header\", \"query\", \"cookie\"])),\n /** For type: \"apiKey\" — the header/query/cookie name */\n headerName: Schema.OptionFromOptional(Schema.String),\n description: Schema.OptionFromOptional(Schema.String),\n /** For type: \"oauth2\" — declared flows (authorizationCode / clientCredentials only; implicit and password are deprecated). */\n flows: Schema.OptionFromOptional(OAuth2Flows),\n /** For type: \"openIdConnect\" — the discovery URL. */\n openIdConnectUrl: Schema.OptionFromOptional(Schema.String),\n});\nexport type SecurityScheme = typeof SecurityScheme.Type;\n\n// ---------------------------------------------------------------------------\n// Auth strategy — a valid combination of security schemes\n// ---------------------------------------------------------------------------\n\nexport const AuthStrategy = Schema.Struct({\n /** The security schemes required together for this strategy */\n schemes: Schema.Array(Schema.String),\n});\nexport type AuthStrategy = typeof AuthStrategy.Type;\n\n// ---------------------------------------------------------------------------\n// Header preset — derived from an auth strategy\n// ---------------------------------------------------------------------------\n\nexport const HeaderPreset = Schema.Struct({\n /** Human-readable label for the UI (e.g. \"Bearer Token\", \"API Key + Email\") */\n label: Schema.String,\n /** Headers this strategy needs. Value is null when the user must provide it. */\n headers: Schema.Record(Schema.String, Schema.NullOr(Schema.String)),\n /** Which headers should be stored as secrets */\n secretHeaders: Schema.Array(Schema.String),\n});\nexport type HeaderPreset = typeof HeaderPreset.Type;\n\n// ---------------------------------------------------------------------------\n// OAuth2 preset — derived from an oauth2 security scheme + a flow choice\n// ---------------------------------------------------------------------------\n\nexport const OAuth2Preset = Schema.Struct({\n /** Human-readable label for the UI (e.g. \"OAuth2 (Authorization Code) — oauth_app\") */\n label: Schema.String,\n /** The source security scheme this preset came from (components.securitySchemes key). */\n securitySchemeName: Schema.String,\n /** Which OAuth2 flow this preset uses. */\n flow: Schema.Literals([\"authorizationCode\", \"clientCredentials\"]),\n /** For authorizationCode: user-agent redirect URL (from the spec). */\n authorizationUrl: Schema.OptionFromOptional(Schema.String),\n /** Token endpoint to exchange the code / refresh. */\n tokenUrl: Schema.String,\n /** Optional refresh endpoint if the spec declares one separately. */\n refreshUrl: Schema.OptionFromOptional(Schema.String),\n /** Declared scopes for this flow: `{ scope: description }`. */\n scopes: Schema.Record(Schema.String, Schema.String),\n});\nexport type OAuth2Preset = typeof OAuth2Preset.Type;\n\n// ---------------------------------------------------------------------------\n// Preview operation — lightweight shape for the add-source UI list\n// ---------------------------------------------------------------------------\n\nexport const PreviewOperation = Schema.Struct({\n operationId: Schema.String,\n method: HttpMethod,\n path: Schema.String,\n summary: Schema.OptionFromOptional(Schema.String),\n tags: Schema.Array(Schema.String),\n deprecated: Schema.Boolean,\n});\nexport type PreviewOperation = typeof PreviewOperation.Type;\n\n// ---------------------------------------------------------------------------\n// Spec preview — everything the frontend needs\n// ---------------------------------------------------------------------------\n\nexport const SpecPreview = Schema.Struct({\n title: Schema.OptionFromOptional(Schema.String),\n version: Schema.OptionFromOptional(Schema.String),\n /** Reuses ServerInfo from extraction */\n servers: Schema.Array(ServerInfo),\n operationCount: Schema.Number,\n /** Lightweight operation list for the add-source UI */\n operations: Schema.Array(PreviewOperation),\n tags: Schema.Array(Schema.String),\n securitySchemes: Schema.Array(SecurityScheme),\n /** Valid auth strategies (each is a set of schemes used together) */\n authStrategies: Schema.Array(AuthStrategy),\n /** Pre-built header presets derived from auth strategies */\n headerPresets: Schema.Array(HeaderPreset),\n /** OAuth2 presets — one per (oauth2 scheme × supported flow) combination */\n oauth2Presets: Schema.Array(OAuth2Preset),\n});\nexport type SpecPreview = typeof SpecPreview.Type;\n\n// ---------------------------------------------------------------------------\n// Security scheme extraction\n// ---------------------------------------------------------------------------\n\nconst stringRecord = (value: unknown): Record<string, string> => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return {};\n const out: Record<string, string> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (typeof v === \"string\") out[k] = v;\n }\n return out;\n};\n\nconst extractFlows = (rawFlows: unknown): Option.Option<OAuth2Flows> => {\n if (!rawFlows || typeof rawFlows !== \"object\") return Option.none();\n const flows = rawFlows as Record<string, unknown>;\n\n const parseFlow = <K extends \"authorizationCode\" | \"clientCredentials\">(key: K): unknown =>\n flows[key];\n\n let authorizationCode: Option.Option<OAuth2AuthorizationCodeFlow> = Option.none();\n const authCodeRaw = parseFlow(\"authorizationCode\");\n if (authCodeRaw && typeof authCodeRaw === \"object\") {\n const f = authCodeRaw as Record<string, unknown>;\n const authUrl = typeof f.authorizationUrl === \"string\" ? f.authorizationUrl : null;\n const tokenUrl = typeof f.tokenUrl === \"string\" ? f.tokenUrl : null;\n if (authUrl && tokenUrl) {\n authorizationCode = Option.some(\n OAuth2AuthorizationCodeFlow.make({\n authorizationUrl: authUrl,\n tokenUrl,\n refreshUrl: Option.fromNullishOr(\n typeof f.refreshUrl === \"string\" ? f.refreshUrl : undefined,\n ),\n scopes: stringRecord(f.scopes),\n }),\n );\n }\n }\n\n let clientCredentials: Option.Option<OAuth2ClientCredentialsFlow> = Option.none();\n const ccRaw = parseFlow(\"clientCredentials\");\n if (ccRaw && typeof ccRaw === \"object\") {\n const f = ccRaw as Record<string, unknown>;\n const tokenUrl = typeof f.tokenUrl === \"string\" ? f.tokenUrl : null;\n if (tokenUrl) {\n clientCredentials = Option.some(\n OAuth2ClientCredentialsFlow.make({\n tokenUrl,\n refreshUrl: Option.fromNullishOr(\n typeof f.refreshUrl === \"string\" ? f.refreshUrl : undefined,\n ),\n scopes: stringRecord(f.scopes),\n }),\n );\n }\n }\n\n if (Option.isNone(authorizationCode) && Option.isNone(clientCredentials)) {\n return Option.none();\n }\n return Option.some(OAuth2Flows.make({ authorizationCode, clientCredentials }));\n};\n\nconst extractSecuritySchemes = (\n rawSchemes: Record<string, unknown>,\n resolver: DocResolver,\n): SecurityScheme[] =>\n Object.entries(rawSchemes).flatMap(([name, schemeOrRef]) => {\n if (!schemeOrRef || typeof schemeOrRef !== \"object\") return [];\n // Resolve $ref so schemes defined via `$ref` aren't silently dropped.\n const resolved = resolver.resolve<Record<string, unknown>>(\n schemeOrRef as Record<string, unknown>,\n );\n if (!resolved || typeof resolved !== \"object\") return [];\n const scheme = resolved;\n\n const type = decodeSecuritySchemeType(scheme.type);\n if (Option.isNone(type)) return [];\n const schemeType = type.value;\n\n return [\n SecurityScheme.make({\n name,\n type: schemeType,\n scheme: Option.fromNullishOr(scheme.scheme as string | undefined),\n bearerFormat: Option.fromNullishOr(scheme.bearerFormat as string | undefined),\n in: Option.fromNullishOr(scheme.in as \"header\" | \"query\" | \"cookie\" | undefined),\n headerName: Option.fromNullishOr(scheme.name as string | undefined),\n description: Option.fromNullishOr(scheme.description as string | undefined),\n flows: schemeType === \"oauth2\" ? extractFlows(scheme.flows) : Option.none(),\n openIdConnectUrl: Option.fromNullishOr(scheme.openIdConnectUrl as string | undefined),\n }),\n ];\n });\n\n// ---------------------------------------------------------------------------\n// Header preset builder\n// ---------------------------------------------------------------------------\n\nconst buildHeaderPresets = (\n schemes: readonly SecurityScheme[],\n strategies: readonly AuthStrategy[],\n): HeaderPreset[] => {\n const schemeMap = new Map(schemes.map((s) => [s.name, s]));\n\n return strategies.flatMap((strategy) => {\n const resolved = strategy.schemes\n .map((name) => schemeMap.get(name))\n .filter(Predicate.isNotUndefined);\n\n if (resolved.length === 0) return [];\n\n const headers: Record<string, string | null> = {};\n const secretHeaders: string[] = [];\n const labelParts: string[] = [];\n\n for (const scheme of resolved) {\n if (scheme.type === \"http\" && Option.getOrElse(scheme.scheme, () => \"\") === \"bearer\") {\n headers[\"Authorization\"] = null;\n secretHeaders.push(\"Authorization\");\n labelParts.push(\"Bearer Token\");\n } else if (scheme.type === \"http\" && Option.getOrElse(scheme.scheme, () => \"\") === \"basic\") {\n headers[\"Authorization\"] = null;\n secretHeaders.push(\"Authorization\");\n labelParts.push(\"Basic Auth\");\n } else if (scheme.type === \"apiKey\" && Option.getOrElse(scheme.in, () => \"\") === \"header\") {\n const headerName = Option.getOrElse(scheme.headerName, () => scheme.name);\n headers[headerName] = null;\n secretHeaders.push(headerName);\n labelParts.push(scheme.name);\n } else if (scheme.type === \"apiKey\") {\n labelParts.push(`${scheme.name} (${Option.getOrElse(scheme.in, () => \"unknown\")})`);\n } else if (scheme.type === \"oauth2\" || scheme.type === \"openIdConnect\") {\n return [];\n } else {\n labelParts.push(scheme.name);\n }\n }\n\n if (Object.keys(headers).length === 0 && resolved.length > 0) {\n return [\n HeaderPreset.make({\n label: labelParts.join(\" + \"),\n headers: {},\n secretHeaders: [],\n }),\n ];\n }\n\n return [\n HeaderPreset.make({\n label: labelParts.join(\" + \"),\n headers,\n secretHeaders,\n }),\n ];\n });\n};\n\n// ---------------------------------------------------------------------------\n// OAuth2 preset builder\n// ---------------------------------------------------------------------------\n\nconst buildOAuth2Presets = (schemes: readonly SecurityScheme[]): OAuth2Preset[] => {\n const presets: OAuth2Preset[] = [];\n for (const scheme of schemes) {\n if (scheme.type !== \"oauth2\") continue;\n if (Option.isNone(scheme.flows)) continue;\n const flows = scheme.flows.value;\n\n if (Option.isSome(flows.authorizationCode)) {\n const flow = flows.authorizationCode.value;\n presets.push(\n OAuth2Preset.make({\n label: `OAuth2 Authorization Code · ${scheme.name}`,\n securitySchemeName: scheme.name,\n flow: \"authorizationCode\",\n authorizationUrl: Option.some(flow.authorizationUrl),\n tokenUrl: flow.tokenUrl,\n refreshUrl: flow.refreshUrl,\n scopes: flow.scopes,\n }),\n );\n }\n\n if (Option.isSome(flows.clientCredentials)) {\n const flow = flows.clientCredentials.value;\n presets.push(\n OAuth2Preset.make({\n label: `OAuth2 Client Credentials · ${scheme.name}`,\n securitySchemeName: scheme.name,\n flow: \"clientCredentials\",\n authorizationUrl: Option.none(),\n tokenUrl: flow.tokenUrl,\n refreshUrl: flow.refreshUrl,\n scopes: flow.scopes,\n }),\n );\n }\n }\n return presets;\n};\n\n// ---------------------------------------------------------------------------\n// Collect unique tags from extraction result\n// ---------------------------------------------------------------------------\n\nconst collectTags = (result: ExtractionResult): string[] => {\n const tagSet = new Set<string>();\n for (const op of result.operations) {\n for (const tag of op.tags) tagSet.add(tag);\n }\n return [...tagSet].sort();\n};\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/** Preview an OpenAPI spec — extract metadata without registering anything.\n * Accepts either a URL or raw JSON/YAML text. */\nexport const previewSpec = Effect.fn(\"OpenApi.previewSpec\")(function* (input: string) {\n const specText = yield* resolveSpecText(input);\n const doc: ParsedDocument = yield* parse(specText);\n const result = yield* extract(doc);\n\n const resolver = new DocResolver(doc);\n const securitySchemes = extractSecuritySchemes(doc.components?.securitySchemes ?? {}, resolver);\n\n const rawSecurity = (doc.security ?? []) as Array<Record<string, unknown>>;\n const declaredStrategies = rawSecurity.map((entry) =>\n AuthStrategy.make({ schemes: Object.keys(entry) }),\n );\n // Fall back to one strategy per scheme when the spec only declares schemes\n // under components (e.g. Sentry) so the user still sees auth options.\n const authStrategies =\n declaredStrategies.length > 0\n ? declaredStrategies\n : securitySchemes.map((scheme) => AuthStrategy.make({ schemes: [scheme.name] }));\n\n return SpecPreview.make({\n title: result.title,\n version: result.version,\n servers: result.servers,\n operationCount: result.operations.length,\n operations: result.operations.map((op) =>\n PreviewOperation.make({\n operationId: op.operationId,\n method: op.method,\n path: op.pathTemplate,\n summary: op.summary,\n tags: op.tags,\n deprecated: op.deprecated,\n }),\n ),\n tags: collectTags(result),\n securitySchemes,\n authStrategies,\n headerPresets: buildHeaderPresets(securitySchemes, authStrategies),\n oauth2Presets: buildOAuth2Presets(securitySchemes),\n });\n});\n","import { Schema } from \"effect\";\n\nimport { ConfiguredHeaderValue, OAuth2SourceConfig } from \"./types\";\n\nexport const StoredSourceSchema = Schema.Struct({\n namespace: Schema.String,\n scope: Schema.String,\n name: Schema.String,\n config: Schema.Struct({\n spec: Schema.optional(Schema.String),\n sourceUrl: Schema.optional(Schema.String),\n baseUrl: Schema.optional(Schema.String),\n namespace: Schema.optional(Schema.String),\n headers: Schema.optional(Schema.Record(Schema.String, ConfiguredHeaderValue)),\n queryParams: Schema.optional(Schema.Record(Schema.String, ConfiguredHeaderValue)),\n specFetchCredentials: Schema.optional(\n Schema.Struct({\n headers: Schema.optional(Schema.Record(Schema.String, ConfiguredHeaderValue)),\n queryParams: Schema.optional(Schema.Record(Schema.String, ConfiguredHeaderValue)),\n }),\n ),\n // Canonical source-owned OAuth config. Concrete client credentials\n // and connection ids live in OpenAPI-owned scoped binding rows.\n oauth2: Schema.optional(OAuth2SourceConfig),\n }),\n}).annotate({ identifier: \"OpenApiStoredSource\" });\nexport type StoredSourceSchema = typeof StoredSourceSchema.Type;\n\nexport type StoredSourceSchemaType = typeof StoredSourceSchema.Type;\n\nconst slugifySlotPart = (value: string): string =>\n value\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\") || \"default\";\n\nexport const headerBindingSlot = (headerName: string): string =>\n `header:${slugifySlotPart(headerName)}`;\n\nexport const queryParamBindingSlot = (name: string): string =>\n `query_param:${slugifySlotPart(name)}`;\n\nexport const specFetchHeaderBindingSlot = (headerName: string): string =>\n `spec_fetch_header:${slugifySlotPart(headerName)}`;\n\nexport const specFetchQueryParamBindingSlot = (name: string): string =>\n `spec_fetch_query_param:${slugifySlotPart(name)}`;\n\nexport const oauth2ClientIdSlot = (securitySchemeName: string): string =>\n `oauth2:${slugifySlotPart(securitySchemeName)}:client-id`;\n\nexport const oauth2ClientSecretSlot = (securitySchemeName: string): string =>\n `oauth2:${slugifySlotPart(securitySchemeName)}:client-secret`;\n\nexport const oauth2ConnectionSlot = (securitySchemeName: string): string =>\n `oauth2:${slugifySlotPart(securitySchemeName)}:connection`;\n"],"mappings":";AAAA,SAAS,MAAM,cAAc;AAWtB,IAAM,oBAAN,cAAgC,OAAO,iBAAoC;AAAA,EAChF;AAAA,EACA;AAAA,IACE,SAAS,OAAO;AAAA,EAClB;AAAA,EACA,EAAE,eAAe,IAAI;AACvB,EAAE;AAAC;AAEI,IAAM,yBAAN,cAAqC,OAAO,iBAAyC;AAAA,EAC1F;AAAA,EACA;AAAA,IACE,SAAS,OAAO;AAAA,EAClB;AAAA,EACA,EAAE,eAAe,IAAI;AACvB,EAAE;AAAC;AAEI,IAAM,yBAAN,cAAqC,KAAK,YAAY,wBAAwB,EAIlF;AAAC;AAEG,IAAM,oBAAN,cAAgC,OAAO,iBAAoC;AAAA,EAChF;AAAA,EACA;AAAA,IACE,SAAS,OAAO;AAAA,EAClB;AAAA,EACA,EAAE,eAAe,IAAI;AACvB,EAAE;AAAC;AAEI,IAAM,2BAAN,cAAuC,KAAK,YAAY,0BAA0B,EAatF;AAAC;;;ACrDJ,SAAS,UAAU,QAAQ,UAAAA,eAAc;AACzC,SAAS,YAAY,yBAAyB;AAC9C,OAAO,UAAU;AAYjB,IAAM,kCAAN,cAA8C,uBAAuB;AAAC;AAQ/D,IAAM,gBAAgB,OAAO,GA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A,QAAO,MAAM;AAAA,IACxC,SAASA,QAAO,SAASA,QAAO,MAAM;AAAA,IACtC,WAAWA,QAAO,SAASA,QAAO,MAAM;AAAA,IACxC,SAASA,QAAO,SAASA,QAAO,OAAOA,QAAO,QAAQ,qBAAqB,CAAC;AAAA,IAC5E,aAAaA,QAAO,SAASA,QAAO,OAAOA,QAAO,QAAQ,qBAAqB,CAAC;AAAA,IAChF,sBAAsBA,QAAO;AAAA,MAC3BA,QAAO,OAAO;AAAA,QACZ,SAASA,QAAO,SAASA,QAAO,OAAOA,QAAO,QAAQ,qBAAqB,CAAC;AAAA,QAC5E,aAAaA,QAAO,SAASA,QAAO,OAAOA,QAAO,QAAQ,qBAAqB,CAAC;AAAA,MAClF,CAAC;AAAA,IACH;AAAA;AAAA;AAAA,IAGA,QAAQA,QAAO,SAAS,kBAAkB;AAAA,EAC5C,CAAC;AACH,CAAC,EAAE,SAAS,EAAE,YAAY,sBAAsB,CAAC;AAKjD,IAAM,kBAAkB,CAAC,UACvB,MACG,KAAK,EACL,YAAY,EACZ,QAAQ,eAAe,GAAG,EAC1B,QAAQ,YAAY,EAAE,KAAK;AAEzB,IAAM,oBAAoB,CAAC,eAChC,UAAU,gBAAgB,UAAU,CAAC;AAEhC,IAAM,wBAAwB,CAAC,SACpC,eAAe,gBAAgB,IAAI,CAAC;AAE/B,IAAM,6BAA6B,CAAC,eACzC,qBAAqB,gBAAgB,UAAU,CAAC;AAE3C,IAAM,iCAAiC,CAAC,SAC7C,0BAA0B,gBAAgB,IAAI,CAAC;AAE1C,IAAM,qBAAqB,CAAC,uBACjC,UAAU,gBAAgB,kBAAkB,CAAC;AAExC,IAAM,yBAAyB,CAAC,uBACrC,UAAU,gBAAgB,kBAAkB,CAAC;AAExC,IAAM,uBAAuB,CAAC,uBACnC,UAAU,gBAAgB,kBAAkB,CAAC;","names":["Schema","Schema","Schema","Schema","Effect","Option","Option","Effect","Effect","Option","Schema","Schema","Option","Effect","Schema","Schema"]}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
HeaderValue,
|
|
7
7
|
InvocationResult,
|
|
8
8
|
OAuth2SourceConfig,
|
|
9
|
+
OpenApiAuthRequiredError,
|
|
9
10
|
OpenApiExtractionError,
|
|
10
11
|
OpenApiInvocationError,
|
|
11
12
|
OpenApiOAuthError,
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
parse,
|
|
15
16
|
previewSpec,
|
|
16
17
|
resolveSpecText
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-AN4HJFNP.js";
|
|
18
19
|
|
|
19
20
|
// src/sdk/invoke.ts
|
|
20
21
|
import { Effect, Layer, Option } from "effect";
|
|
@@ -643,6 +644,7 @@ import {
|
|
|
643
644
|
SourceDetectionResult,
|
|
644
645
|
StorageError,
|
|
645
646
|
ToolResult,
|
|
647
|
+
authToolFailure,
|
|
646
648
|
defaultSourceInstallScopeId,
|
|
647
649
|
definePlugin,
|
|
648
650
|
tool,
|
|
@@ -1027,6 +1029,26 @@ var openApiToolFailure = (code, message, details) => ToolResult.fail({
|
|
|
1027
1029
|
message,
|
|
1028
1030
|
...details === void 0 ? {} : { details }
|
|
1029
1031
|
});
|
|
1032
|
+
var openApiAuthToolFailure = (failure) => authToolFailure({
|
|
1033
|
+
code: failure.code,
|
|
1034
|
+
message: failure.message,
|
|
1035
|
+
source: { id: failure.sourceId, scope: failure.sourceScope },
|
|
1036
|
+
credential: {
|
|
1037
|
+
kind: failure.credentialKind,
|
|
1038
|
+
...failure.credentialLabel ? { label: failure.credentialLabel } : {},
|
|
1039
|
+
...failure.slotKey ? { slotKey: failure.slotKey } : {},
|
|
1040
|
+
...failure.secretId ? { secretId: failure.secretId } : {},
|
|
1041
|
+
...failure.connectionId ? { connectionId: failure.connectionId } : {}
|
|
1042
|
+
},
|
|
1043
|
+
...failure.status !== void 0 ? { status: failure.status } : {},
|
|
1044
|
+
...failure.details !== void 0 ? {
|
|
1045
|
+
upstream: {
|
|
1046
|
+
...failure.status !== void 0 ? { status: failure.status } : {},
|
|
1047
|
+
details: failure.details
|
|
1048
|
+
}
|
|
1049
|
+
} : {},
|
|
1050
|
+
recovery: { configureSourceTool: "executor.openapi.configureSource" }
|
|
1051
|
+
});
|
|
1030
1052
|
var staticPreviewOutput = (preview) => ({
|
|
1031
1053
|
title: Option3.getOrNull(preview.title),
|
|
1032
1054
|
version: Option3.getOrNull(preview.version),
|
|
@@ -1390,19 +1412,34 @@ var resolveConfiguredValueMap = (ctx, params) => Effect3.gen(function* () {
|
|
|
1390
1412
|
value.slot
|
|
1391
1413
|
);
|
|
1392
1414
|
if (binding?.value.kind === "secret") {
|
|
1393
|
-
const
|
|
1415
|
+
const secretBinding = binding.value;
|
|
1416
|
+
const secret = yield* ctx.secrets.getAtScope(secretBinding.secretId, secretBinding.secretScopeId ?? binding.scopeId).pipe(
|
|
1394
1417
|
Effect3.catchTag(
|
|
1395
1418
|
"SecretOwnedByConnectionError",
|
|
1396
1419
|
() => Effect3.fail(
|
|
1397
|
-
new
|
|
1398
|
-
|
|
1420
|
+
new OpenApiAuthRequiredError({
|
|
1421
|
+
code: "credential_secret_missing",
|
|
1422
|
+
sourceId: params.sourceId,
|
|
1423
|
+
sourceScope: params.sourceScope,
|
|
1424
|
+
credentialKind: "secret",
|
|
1425
|
+
credentialLabel: name,
|
|
1426
|
+
slotKey: value.slot,
|
|
1427
|
+
secretId: String(secretBinding.secretId),
|
|
1428
|
+
message: `Secret not found for ${params.missingLabel} "${name}"`
|
|
1399
1429
|
})
|
|
1400
1430
|
)
|
|
1401
1431
|
)
|
|
1402
1432
|
);
|
|
1403
1433
|
if (secret === null) {
|
|
1404
|
-
return yield* new
|
|
1405
|
-
|
|
1434
|
+
return yield* new OpenApiAuthRequiredError({
|
|
1435
|
+
code: "credential_secret_missing",
|
|
1436
|
+
sourceId: params.sourceId,
|
|
1437
|
+
sourceScope: params.sourceScope,
|
|
1438
|
+
credentialKind: "secret",
|
|
1439
|
+
credentialLabel: name,
|
|
1440
|
+
slotKey: value.slot,
|
|
1441
|
+
secretId: String(secretBinding.secretId),
|
|
1442
|
+
message: `Missing secret "${secretBinding.secretId}" for ${params.missingLabel} "${name}"`
|
|
1406
1443
|
});
|
|
1407
1444
|
}
|
|
1408
1445
|
resolved[name] = value.prefix ? `${value.prefix}${secret}` : secret;
|
|
@@ -1412,7 +1449,13 @@ var resolveConfiguredValueMap = (ctx, params) => Effect3.gen(function* () {
|
|
|
1412
1449
|
resolved[name] = value.prefix ? `${value.prefix}${binding.value.text}` : binding.value.text;
|
|
1413
1450
|
continue;
|
|
1414
1451
|
}
|
|
1415
|
-
return yield* new
|
|
1452
|
+
return yield* new OpenApiAuthRequiredError({
|
|
1453
|
+
code: "credential_binding_missing",
|
|
1454
|
+
sourceId: params.sourceId,
|
|
1455
|
+
sourceScope: params.sourceScope,
|
|
1456
|
+
credentialKind: "secret",
|
|
1457
|
+
credentialLabel: name,
|
|
1458
|
+
slotKey: value.slot,
|
|
1416
1459
|
message: `Missing binding for ${params.missingLabel} "${name}"`
|
|
1417
1460
|
});
|
|
1418
1461
|
}
|
|
@@ -1476,7 +1519,12 @@ var resolveStoredSpecFetchCredentials = (ctx, params) => Effect3.gen(function* (
|
|
|
1476
1519
|
missingLabel: "spec fetch query parameter"
|
|
1477
1520
|
})
|
|
1478
1521
|
};
|
|
1479
|
-
})
|
|
1522
|
+
}).pipe(
|
|
1523
|
+
Effect3.catchTag(
|
|
1524
|
+
"OpenApiAuthRequiredError",
|
|
1525
|
+
({ message }) => Effect3.fail(new OpenApiOAuthError({ message }))
|
|
1526
|
+
)
|
|
1527
|
+
);
|
|
1480
1528
|
var toOpenApiSourceConfig = (namespace, config) => {
|
|
1481
1529
|
const configHeaders = {};
|
|
1482
1530
|
for (const [name, value] of Object.entries(config.headers ?? {})) {
|
|
@@ -1496,6 +1544,19 @@ var toOpenApiSourceConfig = (namespace, config) => {
|
|
|
1496
1544
|
};
|
|
1497
1545
|
var specInputToConfigString = (spec) => spec.kind === "url" ? spec.url : spec.value;
|
|
1498
1546
|
var openApiPlugin = definePlugin((options) => {
|
|
1547
|
+
const openApiTransportOutputSchema = (dataSchema) => ({
|
|
1548
|
+
type: "object",
|
|
1549
|
+
additionalProperties: false,
|
|
1550
|
+
required: ["status", "headers", "data"],
|
|
1551
|
+
properties: {
|
|
1552
|
+
status: { type: "integer" },
|
|
1553
|
+
headers: {
|
|
1554
|
+
type: "object",
|
|
1555
|
+
additionalProperties: { type: "string" }
|
|
1556
|
+
},
|
|
1557
|
+
data: dataSchema ?? {}
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1499
1560
|
const rebuildSource = (ctx, input) => Effect3.gen(function* () {
|
|
1500
1561
|
const doc = yield* parse(input.specText);
|
|
1501
1562
|
const result = yield* extract(doc);
|
|
@@ -1564,7 +1625,9 @@ var openApiPlugin = definePlugin((options) => {
|
|
|
1564
1625
|
name: def.toolPath,
|
|
1565
1626
|
description: descriptionFor(def),
|
|
1566
1627
|
inputSchema: normalizeOpenApiRefs(Option3.getOrUndefined(def.operation.inputSchema)),
|
|
1567
|
-
outputSchema:
|
|
1628
|
+
outputSchema: openApiTransportOutputSchema(
|
|
1629
|
+
normalizeOpenApiRefs(Option3.getOrUndefined(def.operation.outputSchema))
|
|
1630
|
+
)
|
|
1568
1631
|
}))
|
|
1569
1632
|
});
|
|
1570
1633
|
if (Object.keys(hoistedDefs).length > 0) {
|
|
@@ -1822,22 +1885,86 @@ var openApiPlugin = definePlugin((options) => {
|
|
|
1822
1885
|
missingLabel: "query parameter"
|
|
1823
1886
|
});
|
|
1824
1887
|
if (config.oauth2) {
|
|
1888
|
+
const oauth2 = config.oauth2;
|
|
1825
1889
|
const connection = yield* resolveOAuthConnectionId(ctx, {
|
|
1826
1890
|
sourceId: op.sourceId,
|
|
1827
1891
|
sourceScope: effective.oauth2Source.scope,
|
|
1828
|
-
oauth2
|
|
1892
|
+
oauth2
|
|
1829
1893
|
});
|
|
1830
1894
|
if (!connection) {
|
|
1831
|
-
return yield* new
|
|
1895
|
+
return yield* new OpenApiAuthRequiredError({
|
|
1896
|
+
code: "oauth_connection_missing",
|
|
1897
|
+
sourceId: op.sourceId,
|
|
1898
|
+
sourceScope: effective.oauth2Source.scope,
|
|
1899
|
+
credentialKind: "connection",
|
|
1900
|
+
credentialLabel: oauth2.flow === "clientCredentials" ? "OAuth client connection" : "OAuth sign-in",
|
|
1901
|
+
slotKey: oauth2.connectionSlot,
|
|
1832
1902
|
message: `OAuth configuration for "${op.sourceId}" is missing a connection binding`
|
|
1833
1903
|
});
|
|
1834
1904
|
}
|
|
1835
1905
|
const accessToken = yield* ctx.connections.accessTokenAtScope(connection.connectionId, connection.scopeId).pipe(
|
|
1836
|
-
Effect3.
|
|
1837
|
-
() =>
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1906
|
+
Effect3.catchTags({
|
|
1907
|
+
ConnectionReauthRequiredError: ({ message, connectionId }) => Effect3.fail(
|
|
1908
|
+
new OpenApiAuthRequiredError({
|
|
1909
|
+
code: "oauth_reauth_required",
|
|
1910
|
+
sourceId: op.sourceId,
|
|
1911
|
+
sourceScope: effective.oauth2Source.scope,
|
|
1912
|
+
credentialKind: "oauth",
|
|
1913
|
+
credentialLabel: oauth2.flow === "clientCredentials" ? "OAuth client connection" : "OAuth sign-in",
|
|
1914
|
+
slotKey: oauth2.connectionSlot,
|
|
1915
|
+
connectionId: String(connectionId),
|
|
1916
|
+
message: `OAuth connection "${connectionId}" needs re-authentication: ${message}`
|
|
1917
|
+
})
|
|
1918
|
+
),
|
|
1919
|
+
ConnectionNotFoundError: ({ connectionId }) => Effect3.fail(
|
|
1920
|
+
new OpenApiAuthRequiredError({
|
|
1921
|
+
code: "oauth_connection_missing",
|
|
1922
|
+
sourceId: op.sourceId,
|
|
1923
|
+
sourceScope: effective.oauth2Source.scope,
|
|
1924
|
+
credentialKind: "connection",
|
|
1925
|
+
credentialLabel: oauth2.flow === "clientCredentials" ? "OAuth client connection" : "OAuth sign-in",
|
|
1926
|
+
slotKey: oauth2.connectionSlot,
|
|
1927
|
+
connectionId: String(connectionId),
|
|
1928
|
+
message: `OAuth connection "${connectionId}" was not found for "${op.sourceId}"`
|
|
1929
|
+
})
|
|
1930
|
+
),
|
|
1931
|
+
ConnectionProviderNotRegisteredError: ({ provider }) => Effect3.fail(
|
|
1932
|
+
new OpenApiAuthRequiredError({
|
|
1933
|
+
code: "oauth_connection_failed",
|
|
1934
|
+
sourceId: op.sourceId,
|
|
1935
|
+
sourceScope: effective.oauth2Source.scope,
|
|
1936
|
+
credentialKind: "oauth",
|
|
1937
|
+
credentialLabel: oauth2.flow === "clientCredentials" ? "OAuth client connection" : "OAuth sign-in",
|
|
1938
|
+
slotKey: oauth2.connectionSlot,
|
|
1939
|
+
connectionId: connection.connectionId,
|
|
1940
|
+
message: `OAuth provider "${provider}" is not registered`
|
|
1941
|
+
})
|
|
1942
|
+
),
|
|
1943
|
+
ConnectionRefreshNotSupportedError: ({ provider, connectionId }) => Effect3.fail(
|
|
1944
|
+
new OpenApiAuthRequiredError({
|
|
1945
|
+
code: "oauth_connection_failed",
|
|
1946
|
+
sourceId: op.sourceId,
|
|
1947
|
+
sourceScope: effective.oauth2Source.scope,
|
|
1948
|
+
credentialKind: "oauth",
|
|
1949
|
+
credentialLabel: oauth2.flow === "clientCredentials" ? "OAuth client connection" : "OAuth sign-in",
|
|
1950
|
+
slotKey: oauth2.connectionSlot,
|
|
1951
|
+
connectionId: String(connectionId),
|
|
1952
|
+
message: `OAuth provider "${provider}" cannot refresh connection "${connectionId}"`
|
|
1953
|
+
})
|
|
1954
|
+
),
|
|
1955
|
+
ConnectionRefreshError: ({ message, connectionId }) => Effect3.fail(
|
|
1956
|
+
new OpenApiAuthRequiredError({
|
|
1957
|
+
code: "oauth_connection_failed",
|
|
1958
|
+
sourceId: op.sourceId,
|
|
1959
|
+
sourceScope: effective.oauth2Source.scope,
|
|
1960
|
+
credentialKind: "oauth",
|
|
1961
|
+
credentialLabel: oauth2.flow === "clientCredentials" ? "OAuth client connection" : "OAuth sign-in",
|
|
1962
|
+
slotKey: oauth2.connectionSlot,
|
|
1963
|
+
connectionId: String(connectionId),
|
|
1964
|
+
message: `OAuth connection "${connectionId}" refresh failed: ${message}`
|
|
1965
|
+
})
|
|
1966
|
+
)
|
|
1967
|
+
})
|
|
1841
1968
|
);
|
|
1842
1969
|
resolvedHeaders.authorization = `Bearer ${accessToken}`;
|
|
1843
1970
|
}
|
|
@@ -1851,6 +1978,17 @@ var openApiPlugin = definePlugin((options) => {
|
|
|
1851
1978
|
);
|
|
1852
1979
|
const ok = result.status >= 200 && result.status < 300;
|
|
1853
1980
|
if (!ok) {
|
|
1981
|
+
if (result.status === 401 || result.status === 403) {
|
|
1982
|
+
return authToolFailure({
|
|
1983
|
+
code: "credential_rejected",
|
|
1984
|
+
status: result.status,
|
|
1985
|
+
message: `Upstream rejected credentials for "${op.sourceId}" with HTTP ${result.status}. Re-authenticate or update the source credentials before retrying this tool.`,
|
|
1986
|
+
source: { id: op.sourceId, scope: toolScope },
|
|
1987
|
+
credential: { kind: "upstream", label: "Upstream authorization" },
|
|
1988
|
+
upstream: { status: result.status, details: result.error },
|
|
1989
|
+
recovery: { configureSourceTool: "executor.openapi.configureSource" }
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1854
1992
|
return ToolResult.fail({
|
|
1855
1993
|
code: "upstream_http_error",
|
|
1856
1994
|
status: result.status,
|
|
@@ -1863,7 +2001,12 @@ var openApiPlugin = definePlugin((options) => {
|
|
|
1863
2001
|
headers: result.headers,
|
|
1864
2002
|
data: result.data
|
|
1865
2003
|
});
|
|
1866
|
-
})
|
|
2004
|
+
}).pipe(
|
|
2005
|
+
Effect3.catchTag(
|
|
2006
|
+
"OpenApiAuthRequiredError",
|
|
2007
|
+
(error) => Effect3.succeed(openApiAuthToolFailure(error))
|
|
2008
|
+
)
|
|
2009
|
+
),
|
|
1867
2010
|
resolveAnnotations: ({ ctx, sourceId, toolRows }) => Effect3.gen(function* () {
|
|
1868
2011
|
const scopes = /* @__PURE__ */ new Set();
|
|
1869
2012
|
for (const row of toolRows) {
|
|
@@ -1955,4 +2098,4 @@ export {
|
|
|
1955
2098
|
makeDefaultOpenapiStore,
|
|
1956
2099
|
openApiPlugin
|
|
1957
2100
|
};
|
|
1958
|
-
//# sourceMappingURL=chunk-
|
|
2101
|
+
//# sourceMappingURL=chunk-PRVJDE43.js.map
|