@dual-os/sdk 0.8.0-next.0 → 0.8.0-next.1
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/README.md +5 -17
- package/dist/Action.d.ts +0 -1
- package/dist/Action.js +1 -2
- package/dist/AgentChannel.d.ts +11 -3
- package/dist/AgentChannel.d.ts.map +1 -1
- package/dist/AgentChannel.js +31 -5
- package/dist/AgentChannel.js.map +1 -1
- package/dist/AgentChannelConformance.d.ts +0 -1
- package/dist/AgentChannelConformance.js +1 -2
- package/dist/AgentChannelRuntime.d.ts +0 -1
- package/dist/AgentChannelRuntime.d.ts.map +1 -1
- package/dist/AgentChannelRuntime.js +3 -4
- package/dist/AgentChannelRuntime.js.map +1 -1
- package/dist/AiProvider.d.ts +0 -1
- package/dist/AiProvider.js +1 -2
- package/dist/AuthMethod.d.ts +0 -1
- package/dist/AuthMethod.js +1 -2
- package/dist/AuthMethodBinding.d.ts +0 -1
- package/dist/AuthMethodBinding.js +1 -2
- package/dist/AuthMethodExecution.d.ts +0 -1
- package/dist/AuthMethodExecution.js +1 -2
- package/dist/ConnectionResolver.d.ts +0 -1
- package/dist/ConnectionResolver.js +1 -2
- package/dist/DefinitionError.d.ts +0 -1
- package/dist/DefinitionError.js +1 -2
- package/dist/DualRegistry.d.ts +0 -1
- package/dist/DualRegistry.js +1 -2
- package/dist/DualRuntime.d.ts +0 -1
- package/dist/DualRuntime.js +1 -2
- package/dist/Files.d.ts +0 -1
- package/dist/Files.js +1 -2
- package/dist/Group.d.ts +0 -1
- package/dist/Group.js +1 -2
- package/dist/Http.d.ts +0 -1
- package/dist/Http.d.ts.map +1 -1
- package/dist/Http.js +4 -5
- package/dist/Http.js.map +1 -1
- package/dist/Mcp.d.ts +0 -1
- package/dist/Mcp.js +1 -2
- package/dist/OAuth2TokenRefresher.d.ts +0 -1
- package/dist/OAuth2TokenRefresher.js +1 -2
- package/dist/OAuthFlow.d.ts +0 -1
- package/dist/OAuthFlow.js +1 -2
- package/dist/Plugin.d.ts +0 -1
- package/dist/Plugin.js +1 -2
- package/dist/PluginRuntime.d.ts +0 -1
- package/dist/PluginRuntime.js +1 -2
- package/dist/Runner.js +3 -4
- package/dist/Runner.js.map +1 -1
- package/dist/ToolFile.d.ts +0 -1
- package/dist/ToolFile.js +1 -2
- package/dist/Trigger.d.ts +0 -1
- package/dist/Trigger.js +1 -2
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/internal/auth-context.d.ts +0 -2
- package/dist/internal/auth-context.d.ts.map +1 -1
- package/dist/internal/auth-execution.d.ts +0 -2
- package/dist/internal/auth-execution.d.ts.map +1 -1
- package/dist/internal/auth-execution.js +1 -2
- package/dist/internal/auth-runtime.d.ts +0 -2
- package/dist/internal/auth-runtime.d.ts.map +1 -1
- package/dist/internal/auth-runtime.js +1 -2
- package/dist/internal/capabilities.d.ts +0 -2
- package/dist/internal/capabilities.d.ts.map +1 -1
- package/dist/internal/capabilities.js +1 -2
- package/dist/internal/children.d.ts +0 -2
- package/dist/internal/children.d.ts.map +1 -1
- package/dist/internal/children.js +1 -2
- package/dist/internal/collection-utils.d.ts +0 -2
- package/dist/internal/collection-utils.d.ts.map +1 -1
- package/dist/internal/collection-utils.js +1 -2
- package/dist/internal/dual/actions.d.ts +0 -2
- package/dist/internal/dual/actions.d.ts.map +1 -1
- package/dist/internal/dual/actions.js +1 -2
- package/dist/internal/dual/invoke.d.ts +0 -2
- package/dist/internal/dual/invoke.d.ts.map +1 -1
- package/dist/internal/dual/invoke.js +1 -2
- package/dist/internal/dual/registry.d.ts +0 -2
- package/dist/internal/dual/registry.d.ts.map +1 -1
- package/dist/internal/dual/registry.js +1 -2
- package/dist/internal/dual/triggers.d.ts +0 -2
- package/dist/internal/dual/triggers.d.ts.map +1 -1
- package/dist/internal/dual/triggers.js +1 -2
- package/dist/internal/handler-context.d.ts +0 -2
- package/dist/internal/handler-context.d.ts.map +1 -1
- package/dist/internal/handler-context.js +1 -2
- package/dist/internal/identifier.d.ts +0 -2
- package/dist/internal/identifier.d.ts.map +1 -1
- package/dist/internal/identifier.js +1 -2
- package/dist/internal/plugin-handlers.d.ts +0 -2
- package/dist/internal/plugin-handlers.d.ts.map +1 -1
- package/dist/internal/plugin-handlers.js +1 -2
- package/dist/internal/proto.d.ts +0 -2
- package/dist/internal/proto.d.ts.map +1 -1
- package/dist/internal/proto.js +1 -2
- package/dist/internal/schema-runtime.d.ts +0 -2
- package/dist/internal/schema-runtime.d.ts.map +1 -1
- package/dist/internal/schema-runtime.js +1 -2
- package/dist/internal/trigger-runtime-shared.d.ts +0 -2
- package/dist/internal/trigger-runtime-shared.d.ts.map +1 -1
- package/dist/internal/trigger-runtime-shared.js +1 -2
- package/dist/internal/trigger-runtime.d.ts +0 -2
- package/dist/internal/trigger-runtime.d.ts.map +1 -1
- package/dist/internal/trigger-runtime.js +1 -2
- package/dist/internal/types.d.ts +0 -2
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/remote-runtime.d.ts +0 -1
- package/dist/remote-runtime.js +1 -2
- package/package.json +6 -7
- package/src/AgentChannel.ts +30 -2
- package/src/AgentChannelRuntime.ts +2 -1
- package/src/Http.ts +21 -4
- package/src/Runner.ts +5 -4
package/dist/Http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.js","names":["ToolFile.Schema","Files.read","Files.File","Action.ActionHandlerError","Action.fromHttpClientFailure","Files.write","Mcp.connect","Mcp.CallToolResult","Mcp.McpError"],"sources":["../src/Http.ts"],"sourcesContent":["/**\n * The HTTP runtime of generated API plugins: each operation's contract and call, request encoding,\n * response decoding, continuation links, redirects and uploads.\n *\n * @since 0.0.0\n */\nimport {\n Array,\n Boolean,\n DateTime,\n Effect,\n Equal,\n Option,\n Order,\n Predicate,\n Random,\n Record,\n Result,\n Schema,\n SchemaGetter,\n SchemaIssue,\n String,\n flow,\n pipe,\n} from \"effect\";\nimport type { SchemaAST } from \"effect\";\n\nimport { Base64, Base64Url } from \"effect/encoding\";\nimport {\n FetchHttpClient,\n HttpBody,\n HttpClient,\n HttpClientError,\n HttpClientRequest,\n} from \"effect/http\";\nimport type { HttpClientResponse } from \"effect/http\";\n\nimport * as Action from \"./Action.ts\";\nimport type * as AuthMethod from \"./AuthMethod.ts\";\nimport { Files } from \"./Files.ts\";\nimport { Mcp } from \"./Mcp.ts\";\nimport * as ToolFile from \"./ToolFile.ts\";\n\nfunction preserveJsonProperties<A, Input>(value: A, input: Input): A {\n if (Equal.equals(value, input)) return value;\n if (Array.isArray(value) && Array.isArray(input)) {\n for (const entry of Array.zip(value, input)) preserveJsonProperties(entry[0], entry[1]);\n } else if (Predicate.isObject(value) && Predicate.isObject(input)) {\n for (const entry of Record.toEntries(input)) {\n if (Record.has(value, entry[0])) {\n preserveJsonProperties(value[entry[0]], entry[1]);\n } else {\n Object.defineProperty(value, entry[0], {\n configurable: true,\n enumerable: true,\n value: entry[1],\n writable: true,\n });\n }\n }\n }\n return value;\n}\n\nfunction decodeResponse<Output extends Schema.Top>(output: Output) {\n return flow(\n Effect.succeed,\n Effect.flatMap(input =>\n pipe(\n Schema.decodeUnknownEffect(output)(input),\n Effect.map(value => preserveJsonProperties(value, input)),\n ),\n ),\n );\n}\n\n/**\n * An action's input and output schemas.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface Contract {\n readonly input: Schema.Top;\n readonly output: Schema.Top;\n}\n\n/**\n * Runs an action: its input in, its output or a failure out.\n *\n * @since 0.0.0\n * @category models\n */\nexport type Handler<Methods extends readonly AuthMethod.Any[], Input, Output> = (\n input: Input,\n context: Action.HandlerContext<Methods>,\n) => Effect.Effect<Output, Action.ActionHandlerFailure, HttpClient.HttpClient>;\n\n/**\n * A file input: a ToolFile as a download returns it, or just its bytes with a type and name.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport type File = typeof File.Type;\nexport const File = Schema.Struct({\n _tag: Schema.optionalKey(Schema.Literal(\"ToolFile\")),\n contentBase64: Schema.Uint8ArrayFromBase64,\n contentType: Schema.optionalKey(Schema.NullOr(Schema.String)),\n filename: Schema.optionalKey(Schema.NullOr(Schema.String)),\n sizeBytes: Schema.optionalKey(Schema.Natural),\n}).annotate({\n description:\n \"A ToolFile, such as the result of a download, passed unchanged; or its contentBase64 with an optional contentType and filename.\",\n});\n\nconst signatures: [string, [number, number[]][]][] = [\n [\"image/jpeg\", [[0, [0xff, 0xd8, 0xff]]]],\n [\"image/png\", [[0, [0x89, 0x50, 0x4e, 0x47]]]],\n [\"image/gif\", [[0, [0x47, 0x49, 0x46, 0x38]]]],\n [\n \"image/webp\",\n [\n [0, [0x52, 0x49, 0x46, 0x46]],\n [8, [0x57, 0x45, 0x42, 0x50]],\n ],\n ],\n [\"application/pdf\", [[0, [0x25, 0x50, 0x44, 0x46]]]],\n [\"application/zip\", [[0, [0x50, 0x4b, 0x03, 0x04]]]],\n];\n\nconst utf8 = new TextDecoder(\"utf-8\", { fatal: true });\n\nfunction sniff(bytes: Uint8Array) {\n return pipe(\n Array.findFirst(signatures, signature =>\n Array.every(signature[1], part =>\n Array.every(part[1], (byte, index) => bytes[part[0] + index] === byte),\n ),\n ),\n Option.map(signature => signature[0]),\n Option.orElse(() =>\n Option.liftPredicate(\"text/plain\", () =>\n Result.isSuccess(Result.try(() => utf8.decode(bytes))),\n ),\n ),\n Option.getOrNull,\n );\n}\n\nfunction toolFile(bytes: Uint8Array, declared: string | null, filename: string | null) {\n return {\n _tag: \"ToolFile\",\n contentBase64: Base64.encode(bytes),\n contentType:\n declared === null || pipe(declared, String.startsWith(\"application/octet-stream\"))\n ? (sniff(bytes) ?? declared)\n : declared,\n filename,\n sizeBytes: bytes.byteLength,\n } satisfies ToolFile.File;\n}\n\nfunction invalid(expected: string, value: unknown, options: SchemaAST.ParseOptions) {\n return Effect.fail(new SchemaIssue.InvalidValue({ expected }, value, options));\n}\n\nfunction decodeBytes(text: string, options: SchemaAST.ParseOptions) {\n return Result.match(\n Base64Url.decode(pipe(text, String.replaceAll(\"+\", \"-\"), String.replaceAll(\"/\", \"_\"))),\n {\n onFailure: () => invalid(\"a Base64 or Base64Url string\", text, options),\n onSuccess: bytes => Effect.succeed(bytes),\n },\n );\n}\n\ntype Carrier = \"base64\" | \"base64url\" | \"data-uri\";\n\ninterface Content {\n bytes: Uint8Array;\n contentType: string | null;\n}\n\nfunction contentOf(carrier: Carrier) {\n return SchemaGetter.transformEffect<Content, string>((text, options) => {\n if (carrier !== \"data-uri\") {\n return Effect.map(decodeBytes(text, options), bytes => ({ bytes, contentType: null }));\n }\n return Option.match(pipe(text, String.match(/^data:([^;,]*)(?:;[^;,]*)*;base64,(.*)$/su)), {\n onNone: () => invalid(\"a Base64 data URI\", text, options),\n onSome: parts =>\n Effect.map(decodeBytes(Array.getUnsafe(parts, 2), options), bytes => ({\n bytes,\n contentType: pipe(\n Array.getUnsafe(parts, 1),\n Option.liftPredicate(String.isNonEmpty),\n Option.getOrNull,\n ),\n })),\n });\n });\n}\n\nfunction textOf(carrier: Carrier, content: Content) {\n if (carrier === \"base64\") return Base64.encode(content.bytes);\n if (carrier === \"base64url\") return Base64Url.encode(content.bytes);\n const contentType = content.contentType ?? sniff(content.bytes) ?? \"application/octet-stream\";\n return `data:${contentType};base64,${Base64.encode(content.bytes)}`;\n}\n\nfunction fileFrom(carrier: Carrier) {\n return Schema.String.pipe(\n Schema.decodeTo(ToolFile.Schema, {\n decode: SchemaGetter.compose(\n contentOf(carrier),\n SchemaGetter.transform(content => toolFile(content.bytes, content.contentType, null)),\n ),\n encode: SchemaGetter.transformEffect((file: ToolFile.File, options) =>\n Effect.map(decodeBytes(file.contentBase64, options), bytes =>\n textOf(carrier, { bytes, contentType: file.contentType }),\n ),\n ),\n }),\n );\n}\n\nfunction encodedFrom(carrier: Carrier) {\n return File.pipe(\n Schema.decodeTo(Schema.String, {\n decode: SchemaGetter.transform(file =>\n textOf(carrier, { bytes: file.contentBase64, contentType: file.contentType ?? null }),\n ),\n encode: SchemaGetter.compose(\n contentOf(carrier),\n SchemaGetter.transform(content => ({\n contentBase64: content.bytes,\n contentType: content.contentType,\n })),\n ),\n }),\n );\n}\n\n/**\n * A file the API returns as a Base64 string inside JSON, decoded into a ToolFile with its content\n * type recognized from the bytes.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const FileFromBase64 = fileFrom(\"base64\");\n\n/**\n * {@link FileFromBase64} for an API that writes the file in Base64Url.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const FileFromBase64Url = fileFrom(\"base64url\");\n\n/**\n * A {@link File} input the API reads as a Base64 string inside JSON.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const Base64FromFile = encodedFrom(\"base64\");\n\n/**\n * {@link Base64FromFile} for an API that reads the file in Base64Url.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const Base64UrlFromFile = encodedFrom(\"base64url\");\n\n/**\n * {@link FileFromBase64} for an API that writes the file as a data URI, which also carries its\n * content type.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const FileFromDataUri = fileFrom(\"data-uri\");\n\n/**\n * {@link Base64FromFile} for an API that reads the file as a data URI, built from the file's\n * content type.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const DataUriFromFile = encodedFrom(\"data-uri\");\n\ntype DateTimeText = typeof DateTimeText.Type;\nconst DateTimeText = Schema.String.annotate({ format: \"date-time\" });\n\nconst rfc3339 = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})(?:\\.\\d+)?(?:Z|([+-]\\d{2}:\\d{2}))$/u;\n\n/** The instant of an RFC 3339 date-time with its offset; an impossible date such as February 30 has none. */\nfunction rfc3339Instant(text: string) {\n return pipe(\n Option.fromNullishOr(rfc3339.exec(text)),\n Option.flatMap(match =>\n Option.filter(DateTime.makeZoned(text, { timeZone: match[2] ?? \"+00:00\" }), zoned =>\n String.startsWith(match[1] ?? \"\")(DateTime.formatIsoOffset(zoned)),\n ),\n ),\n Option.map(DateTime.toUtc),\n );\n}\n\nfunction instants<Wire>(\n wire: Schema.Codec<Wire>,\n expected: string,\n read: (value: Wire) => Option.Option<DateTime.Utc>,\n write: (instant: DateTime.Utc) => Wire,\n) {\n const fromWire = SchemaGetter.transformEffect<string, Wire>((value, options) =>\n Option.match(read(value), {\n onNone: () => invalid(expected, value, options),\n onSome: instant => Effect.succeed(DateTime.formatIso(instant)),\n }),\n );\n const toWire = SchemaGetter.transformEffect<Wire, string>((text, options) =>\n Option.match(rfc3339Instant(text), {\n onNone: () => invalid(\"an ISO 8601 date-time\", text, options),\n onSome: instant => Effect.succeed(write(instant)),\n }),\n );\n return {\n input: pipe(DateTimeText, Schema.decodeTo(wire, { decode: toWire, encode: fromWire })),\n output: pipe(wire, Schema.decodeTo(DateTimeText, { decode: fromWire, encode: toWire })),\n };\n}\n\nconst unixSeconds = instants(\n Schema.Int,\n \"Unix seconds\",\n seconds => Option.map(DateTime.make(seconds * 1000), DateTime.toUtc),\n instant => Math.floor(DateTime.toEpochMillis(instant) / 1000),\n);\n\nconst rfc2822 = instants(\n Schema.String,\n \"an RFC 2822 date-time\",\n text => Option.map(DateTime.make(text), DateTime.toUtc),\n instant => DateTime.toDateUtc(instant).toUTCString(),\n);\n\n/**\n * A date-time the API writes as Unix seconds, decoded into an ISO 8601 UTC string.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const DateTimeFromUnixSeconds = unixSeconds.output;\n\n/**\n * An ISO 8601 date-time input the API reads as Unix seconds.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const UnixSecondsFromDateTime = unixSeconds.input;\n\n/**\n * A date-time the API writes in RFC 2822 form, decoded into an ISO 8601 UTC string.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const DateTimeFromRfc2822 = rfc2822.output;\n\n/**\n * An ISO 8601 date-time input the API reads in RFC 2822 form.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const Rfc2822FromDateTime = rfc2822.input;\n\n/**\n * An action output whose response decodes into a different shape, such as a file the API sends as\n * Base64: the action declares the decoded shape and the call decodes the response with `wire`.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface Decoded<Wire extends Schema.Top> {\n readonly _tag: \"Decoded\";\n readonly wire: Wire;\n}\n\n/**\n * Declares an output by the response schema it decodes from; see {@link Decoded}.\n *\n * @since 0.0.0\n * @category constructors\n */\nexport function decoded<const Wire extends Schema.Top>(wire: Wire): Decoded<Wire> {\n return { _tag: \"Decoded\", wire };\n}\n\ntype Request =\n | HttpClientRequest.HttpClientRequest\n | Effect.Effect<HttpClientRequest.HttpClientRequest, Action.ActionHandlerError>;\n\n/** `binary` returns a released version's base64 `ToolFile`; `file` stores the body as a file. */\ntype Body = \"json\" | \"text\" | \"binary\" | \"file\" | \"void\" | \"unknown\";\n\ntype GraphqlResponse = typeof GraphqlResponse.Type;\nconst GraphqlResponse = Schema.Struct({\n data: Schema.optionalKey(Schema.NullOr(Schema.Record(Schema.String, Schema.Unknown))),\n errors: Schema.optionalKey(\n Schema.Array(\n Schema.StructWithRest(Schema.Struct({ message: Schema.String }), [\n Schema.Record(Schema.String, Schema.Unknown),\n ]),\n ),\n ),\n});\n\n/**\n * A response status, media type and decoding mode advertised by an HTTP action.\n *\n * @since 0.4.1\n * @category models\n */\nexport interface Variant {\n readonly status?: number;\n readonly contentType: string;\n readonly body: Body;\n readonly headers?: readonly string[];\n}\n\ntype Media =\n | { readonly contentBase64: Uint8Array; readonly contentType?: string | null }\n | Files.File;\n\ntype Upload =\n | { readonly mode: \"media\"; readonly media: Media }\n | { readonly mode: \"multipart\"; readonly media: Media; readonly metadata: unknown }\n | {\n readonly mode: \"start\";\n readonly contentType: string;\n readonly metadata?: unknown;\n readonly totalBytes: number;\n }\n | {\n readonly mode: \"chunk\";\n readonly sessionUrl: string;\n readonly totalBytes: number;\n readonly offset: number;\n readonly media: Media;\n }\n | { readonly mode: \"status\"; readonly sessionUrl: string; readonly totalBytes: number };\n\nfunction coerce(value: unknown) {\n return Predicate.isObject(value) ? JSON.stringify(value) : `${value}`;\n}\n\n/**\n * Encodes a path parameter as one segment.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function path(value: unknown) {\n return encodeURIComponent(coerce(value));\n}\n\n/**\n * Encodes a path parameter written inside single quotes, an OData string literal, doubling its\n * quotes: `O'Brien` in `People('{name}')` is sent as `People('O''Brien')`.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function literal(value: unknown) {\n return path(pipe(coerce(value), String.replaceAll(\"'\", \"''\")));\n}\n\n/**\n * Encodes a path parameter whose slashes stay path separators.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function segments(value: unknown) {\n return Array.join(Array.map(String.split(coerce(value), \"/\"), encodeURIComponent), \"/\");\n}\n\nfunction deepObject(name: string, value: unknown): [string, string][] {\n if (Array.isArray(value)) {\n return Array.flatMap(value, (item, index) => deepObject(`${name}[${index}]`, item));\n }\n if (Predicate.isObject(value)) {\n return Array.flatMap(Record.toEntries(value), entry =>\n deepObject(`${name}[${entry[0]}]`, entry[1]),\n );\n }\n return value === undefined ? [] : [[name, coerce(value)]];\n}\n\n/**\n * Query, header or form entries, repeating array values unless their name is joined, and encoding\n * `deep` names as bracketed keys such as `metadata[plan]` and `expand[0]`. A joined name is\n * comma-separated, or separated by the delimiter it is paired with, such as `[\"ids\", \"|\"]`.\n * `exploded` object parameters use their property names as query keys (`role=vet&active=true`).\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function params(\n fields: Record.ReadonlyRecord<string, unknown>,\n joined: readonly (string | readonly [string, string])[] = [],\n deep: readonly string[] = [],\n exploded: readonly string[] = [],\n) {\n return Array.flatMap(Record.toEntries(fields), field => {\n if (field[1] === undefined) return [];\n if (Array.contains(deep, field[0])) return deepObject(field[0], field[1]);\n const values = field[1];\n if (\n Array.contains(exploded, field[0]) &&\n Predicate.isObject(values) &&\n !Array.isArray(values)\n ) {\n return Array.filterMap(Record.toEntries(values), entry =>\n entry[1] === undefined\n ? Result.failVoid\n : Result.succeed([entry[0], coerce(entry[1])] as const),\n );\n }\n if (!Array.isArray(values)) return [[field[0], coerce(values)] as const];\n const separator = Array.findFirst(joined, entry => {\n const pair = Predicate.isString(entry) ? ([entry, \",\"] as const) : entry;\n return pair[0] === field[0] ? Option.some(pair[1]) : Option.none();\n });\n return Option.match(separator, {\n onNone: () => Array.map(values, item => [field[0], coerce(item)] as const),\n onSome: value => [[field[0], Array.join(Array.map(values, coerce), value)] as const],\n });\n });\n}\n\nfunction filePart(bytes: Uint8Array, name: string, contentType: string) {\n return new globalThis.File([new Uint8Array(bytes)], name, { type: contentType });\n}\n\n/**\n * Multipart form fields, sending each {@link File} as a file part.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function form(payload: Record.ReadonlyRecord<string, unknown>) {\n return Record.map(payload, (value, name) =>\n Array.map(Array.ensure(value), item => {\n if (item === undefined) return undefined;\n if (!Schema.is(File)(item)) return coerce(item);\n return filePart(\n item.contentBase64,\n item.filename ?? name,\n item.contentType ?? \"application/octet-stream\",\n );\n }),\n );\n}\n\nfunction fileFailed(error: Files.FileError) {\n return Action.ActionHandlerError.make({ cause: error, message: error.message });\n}\n\nfunction readFile(file: Files.File) {\n return pipe(Files.read(file), Effect.mapError(fileFailed));\n}\n\n/**\n * Sends a file as the raw request body.\n *\n * @since 0.1.0\n * @category encoding\n */\nexport const withFile = Effect.fnUntraced(function* (\n request: HttpClientRequest.HttpClientRequest,\n file: Files.File,\n) {\n return HttpClientRequest.bodyUint8Array(request, yield* readFile(file), file.contentType);\n});\n\n/**\n * Sends multipart form fields, each {@link Files.File} as a file part.\n *\n * @since 0.1.0\n * @category encoding\n */\nexport const withForm = Effect.fnUntraced(function* (\n request: HttpClientRequest.HttpClientRequest,\n payload: Record.ReadonlyRecord<string, unknown>,\n) {\n return HttpClientRequest.bodyFormDataRecord(\n request,\n Record.fromEntries(\n yield* Effect.forEach(Record.toEntries(payload), field =>\n Effect.map(\n Effect.forEach(\n Array.filter(Array.ensure(field[1]), item => item !== undefined),\n item =>\n Effect.gen(function* () {\n if (!Schema.is(Files.File)(item)) return coerce(item);\n return filePart(yield* readFile(item), item.name, item.contentType);\n }),\n ),\n parts => [field[0], parts] satisfies [string, (string | globalThis.File)[]],\n ),\n ),\n ),\n );\n});\n\nfunction mediaBytes(media: Media) {\n if (Schema.is(Files.File)(media)) {\n return Effect.map(readFile(media), bytes => ({ bytes, contentType: media.contentType }));\n }\n return Effect.succeed({\n bytes: media.contentBase64,\n contentType: Option.getOrNull(Option.fromNullishOr(media.contentType)),\n });\n}\n\nfunction isSafeUrl(value: string, origin?: string) {\n if (!URL.canParse(value)) return false;\n const url = new URL(value);\n return (\n url.protocol === \"https:\" &&\n url.username === \"\" &&\n url.password === \"\" &&\n (origin === undefined || url.origin === origin)\n );\n}\n\nfunction refused(message: string) {\n return Effect.fail(Action.ActionHandlerError.make({ message }));\n}\n\n/**\n * Follows a returned next-page link on the operation's own origin: only its path and query are\n * taken, so the connection's host routing applies and credentials never reach another host.\n *\n * @since 0.0.0\n * @category requests\n */\nexport function continuation(request: HttpClientRequest.HttpClientRequest, nextLink?: string) {\n if (nextLink === undefined) return Effect.succeed(request);\n const declared = new URL(request.url);\n const next = URL.canParse(nextLink) ? new URL(nextLink) : undefined;\n if (next === undefined || !isSafeUrl(nextLink) || next.pathname !== declared.pathname) {\n return refused(\"A continuation URL must be an HTTPS link to the same operation path\");\n }\n return Effect.succeed(\n HttpClientRequest.make(request.method)(`${declared.origin}${next.pathname}${next.search}`, {\n headers: request.headers,\n }),\n );\n}\n\n/**\n * A request to a preauthenticated upload URL, which is sent without the connection's credentials.\n *\n * @since 0.0.0\n * @category requests\n */\nexport function preauthenticated(\n method: (url: string) => HttpClientRequest.HttpClientRequest,\n url: string,\n ...steps: readonly ((\n request: HttpClientRequest.HttpClientRequest,\n ) => HttpClientRequest.HttpClientRequest)[]\n) {\n if (!isSafeUrl(url)) return refused(\"An upload session requires a preauthenticated HTTPS URL\");\n return Effect.succeed(Array.reduce(steps, method(url), (request, step) => step(request)));\n}\n\nfunction failure(\n error:\n | Action.ActionHandlerError\n | Action.HttpClientFailure\n | { readonly cause: unknown; readonly response: HttpClientResponse.HttpClientResponse },\n) {\n return Schema.is(Action.ActionHandlerError)(error) ? error : Action.fromHttpClientFailure(error);\n}\n\n// Like HttpClient.followRedirects, except that a redirect to another origin sends no\n// request header at all: auth methods may set any header, such as GitLab's PRIVATE-TOKEN.\nfunction redirect(response: HttpClientResponse.HttpClientResponse) {\n const location = response.headers[\"location\"];\n if (response.status < 300 || response.status >= 400 || location === undefined) return undefined;\n const sent = response.request;\n const url = new URL(location, sent.url);\n const request =\n (response.status === 303 && sent.method !== \"GET\" && sent.method !== \"HEAD\") ||\n ((response.status === 301 || response.status === 302) && sent.method === \"POST\")\n ? HttpClientRequest.setBody(HttpClientRequest.setMethod(sent, \"GET\"), HttpBody.empty)\n : sent;\n return url.origin === new URL(sent.url).origin\n ? HttpClientRequest.setUrl(request, url)\n : HttpClientRequest.make(request.method)(url, { body: request.body });\n}\n\nfunction follow(\n client: HttpClient.HttpClient,\n response: HttpClientResponse.HttpClientResponse,\n redirects: number,\n): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> {\n const next = redirect(response);\n return next === undefined || redirects === 10\n ? Effect.succeed(response)\n : Effect.flatMap(client.execute(next), result => follow(client, result, redirects + 1));\n}\n\n/** The file name a `Content-Disposition` header suggests, preferring its encoded form. */\nfunction dispositionName(header?: string) {\n if (header === undefined) return undefined;\n const encoded = pipe(\n String.match(/(?:^|;)\\s*filename\\*\\s*=\\s*UTF-8'[^']*'([^;]+)/iu)(header),\n Option.flatMap(match => Option.fromUndefinedOr(match[1])),\n );\n const decoded = pipe(\n encoded,\n Option.flatMap(value => Option.liftThrowable(() => decodeURIComponent(String.trim(value)))()),\n );\n return Option.getOrElse(decoded, () =>\n pipe(\n String.match(/(?:^|;)\\s*filename\\s*=\\s*(?:\"((?:\\\\.|[^\"\\\\])*)\"|([^;]*))/iu)(header),\n Option.flatMap(match =>\n Option.orElse(\n Option.map(Option.fromUndefinedOr(match[1]), name =>\n String.replace(/\\\\(.)/gu, \"$1\")(name),\n ),\n () => Option.map(Option.fromUndefinedOr(match[2]), String.trim),\n ),\n ),\n Option.getOrUndefined,\n ),\n );\n}\n\nconst read = Effect.fnUntraced(function* (\n response: HttpClientResponse.HttpClientResponse,\n body: Body,\n) {\n if (body === \"json\") return yield* response.json;\n if (body === \"text\") return yield* response.text;\n if (body === \"void\") return {};\n if (body === \"unknown\") {\n const text = yield* response.text;\n if (String.isEmpty(String.trim(text))) return null;\n return Option.getOrElse(\n Schema.decodeOption(Schema.fromJsonString(Schema.Json))(text),\n () => text,\n );\n }\n const bytes = new Uint8Array(yield* response.arrayBuffer);\n const name = dispositionName(response.headers[\"content-disposition\"]);\n if (body === \"file\") {\n return yield* pipe(\n Files.write({\n bytes,\n contentType: Option.getOrNull(Option.fromUndefinedOr(response.headers[\"content-type\"])),\n name: name ?? \"file\",\n }),\n Effect.mapError(fileFailed),\n );\n }\n return toolFile(bytes, response.headers[\"content-type\"] ?? null, name ?? null);\n});\n\n/**\n * One API operation as {@link make} returns it: its contract and the call that performs it. The\n * `Context` parameter lets a package name its handler context once, so declaration files print\n * `Endpoint<Context, …>` instead of repeating its auth methods in every action.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface Endpoint<Context, Input extends Schema.Top, Output extends Schema.Top> {\n readonly input: Input;\n readonly output: Output;\n readonly run: (\n input: Input[\"Type\"],\n context: Context,\n ) => Effect.Effect<Output[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>;\n}\n\n/**\n * An {@link Endpoint} whose output is the decoded type of the response schema it keeps as `wire`.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface DecodedEndpoint<Context, Input extends Schema.Top, Wire extends Schema.Top> {\n readonly input: Input;\n readonly output: Schema.toType<Wire>;\n readonly wire: Wire;\n readonly run: (\n input: Input[\"Type\"],\n context: Context,\n ) => Effect.Effect<Wire[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>;\n}\n\n/**\n * Binds the runtime to a package's auth module: the calls a generated version file makes. Its\n * `authorize` applies a connection's credentials to the client. Its optional `checkResponse` fails\n * a successful response that reports a failed call, such as Slack's `{ ok: false, error }`.\n * `preauthenticatedUploadUrl` restricts credential-free upload requests and every redirect to\n * provider-approved HTTPS URLs, without changing authenticated calls or other providers.\n *\n * @since 0.0.0\n * @category constructors\n */\nexport function make<\n const Methods extends readonly AuthMethod.Any[],\n Context extends Action.HandlerContext<Methods> = Action.HandlerContext<Methods>,\n>(auth: {\n readonly authorize: (\n client: HttpClient.HttpClient,\n context: Action.HandlerContext<Methods>,\n ) => HttpClient.HttpClient;\n readonly checkResponse?: (\n response: HttpClientResponse.HttpClientResponse,\n ) => Effect.Effect<void, Action.ActionHandlerError | HttpClientError.HttpClientError>;\n readonly preauthenticatedUploadUrl?: Schema.Schema<string>;\n}) {\n const { authorize, checkResponse = () => Effect.void } = auth;\n const send = Effect.fnUntraced(function* (context: Context | undefined, request: Request) {\n const base = yield* HttpClient.HttpClient;\n const uploadPolicy = context === undefined ? auth.preauthenticatedUploadUrl : undefined;\n const client =\n uploadPolicy === undefined\n ? base\n : HttpClient.mapRequestEffect(base, outgoing =>\n isSafeUrl(outgoing.url) && Schema.is(uploadPolicy)(outgoing.url)\n ? Effect.succeed(outgoing)\n : Effect.fail(\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.InvalidUrlError({\n description: \"The upload URL is not an approved provider HTTPS destination\",\n request: outgoing,\n }),\n }),\n ),\n );\n const transport = HttpClient.transformResponse(\n client,\n Effect.flatMap(response => follow(client, response, 0)),\n );\n const authorized = context === undefined ? transport : authorize(transport, context);\n const execution = authorized.execute(Effect.isEffect(request) ? yield* request : request);\n const options = yield* Effect.serviceOption(FetchHttpClient.RequestInit);\n const response = yield* Boolean.match(uploadPolicy !== undefined, {\n onFalse: () => execution,\n onTrue: () =>\n Effect.provideService(execution, FetchHttpClient.RequestInit, {\n ...Option.getOrElse(options, () => ({})),\n redirect: \"manual\",\n }),\n });\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n yield* checkResponse(response);\n return response;\n });\n\n /**\n * One API operation: its action contract and the call that performs it. A {@link Decoded} output\n * declares the decoded shape and hands the call its response schema.\n */\n function endpoint<const Input extends Schema.Top, const Output extends Schema.Top>(\n contract: { readonly input: Input; readonly output: Output },\n run: (\n input: Input[\"Type\"],\n context: Context,\n output: Output,\n ) => Effect.Effect<Output[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>,\n ): Endpoint<Context, Input, Output>;\n function endpoint<const Input extends Schema.Top, const Wire extends Schema.Top>(\n contract: { readonly input: Input; readonly output: Decoded<Wire> },\n run: (\n input: Input[\"Type\"],\n context: Context,\n output: Wire,\n ) => Effect.Effect<Wire[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>,\n ): DecodedEndpoint<Context, Input, Wire>;\n function endpoint<const Input extends Schema.Top, const Output extends Schema.Top>(\n contract: { readonly input: Input; readonly output: Output | Decoded<Output> },\n run: (\n input: Input[\"Type\"],\n context: Context,\n output: Output,\n ) => Effect.Effect<Output[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>,\n ) {\n if (!Schema.isSchema(contract.output)) {\n const wire = contract.output.wire;\n return {\n input: contract.input,\n output: Schema.toType(wire),\n run: (input: Input[\"Type\"], context: Context) => run(input, context, wire),\n wire,\n };\n }\n const output = contract.output;\n return {\n input: contract.input,\n output,\n run: (input: Input[\"Type\"], context: Context) => run(input, context, output),\n };\n }\n\n /** Sends a request and decodes its body as the operation's single response. */\n function execute<Output extends Schema.Top>(\n context: Context | undefined,\n output: Output,\n request: Request,\n body: Body,\n ) {\n return pipe(\n send(context, request),\n Effect.flatMap(response => read(response, body)),\n Effect.flatMap(decodeResponse(output)),\n Effect.mapError(failure),\n );\n }\n\n /** Sends a request and decodes the declared response variant its status and media type select. */\n const variants = Effect.fnUntraced(function* <Output extends Schema.Top>(\n context: Context | undefined,\n output: Output,\n request: Request,\n declared: readonly Variant[],\n media?: boolean,\n ) {\n const response = yield* send(context, request);\n const exact = Array.flatMap(declared, variant =>\n variant.status === undefined ? [] : [variant.status],\n );\n const contentType = pipe(\n response.headers[\"content-type\"] ?? \"\",\n String.split(\";\"),\n Array.headNonEmpty,\n String.trim,\n String.toLowerCase,\n );\n const ordered = Array.sort(\n declared,\n Order.mapInput(Order.Number, (variant: Variant) => {\n if (variant.body === \"void\" || variant.body === \"unknown\") return 3;\n if (variant.contentType === \"*/*\") return 2;\n return pipe(variant.contentType, String.endsWith(\"/*\")) ? 1 : 0;\n }),\n );\n const variant = Array.findFirst(ordered, candidate => {\n const status =\n candidate.status === undefined\n ? !Array.contains(exact, response.status)\n : candidate.status === response.status;\n if (!status) return false;\n if (media !== undefined) {\n return (candidate.body === \"binary\" || candidate.body === \"file\") === media;\n }\n if (\n candidate.body === \"void\" ||\n candidate.body === \"unknown\" ||\n candidate.contentType === \"*/*\"\n ) {\n return true;\n }\n if (pipe(candidate.contentType, String.endsWith(\"/*\"))) {\n return pipe(\n contentType,\n String.startsWith(pipe(candidate.contentType, String.slice(0, -1))),\n );\n }\n return contentType === candidate.contentType;\n });\n if (Option.isNone(variant)) {\n return yield* Effect.fail({\n cause: \"The API returned an undeclared successful response\",\n response,\n });\n }\n const headers = Array.flatMap(variant.value.headers ?? [], name => {\n const value = response.headers[String.toLowerCase(name)];\n return value === undefined ? [] : [[name, value] as const];\n });\n return yield* decodeResponse(output)({\n body: yield* read(response, variant.value.body),\n contentType: variant.value.contentType,\n status: response.status,\n ...(variant.value.headers === undefined ? {} : { headers: Record.fromEntries(headers) }),\n });\n }, Effect.mapError(failure));\n\n /** Google's media, multipart and resumable upload protocols. */\n const googleUpload = Effect.fnUntraced(function* <Output extends Schema.Top>(\n context: Context,\n output: Output,\n request: HttpClientRequest.HttpClientRequest,\n payload: Upload,\n options: { readonly maxSize?: number; readonly resumable?: string },\n ) {\n const client = authorize(yield* HttpClient.HttpClient, context);\n const media = \"media\" in payload ? yield* mediaBytes(payload.media) : undefined;\n const size = \"totalBytes\" in payload ? payload.totalBytes : (media?.bytes.byteLength ?? 0);\n if (size < 0 || (options.maxSize !== undefined && size > options.maxSize)) {\n return yield* refused(\"The upload size is outside the API's declared limit\");\n }\n const origin = new URL(request.url).origin;\n if (payload.mode === \"start\") {\n if (options.resumable === undefined) {\n return yield* refused(\"This API has no resumable upload protocol\");\n }\n const response = yield* client.execute(\n pipe(\n HttpClientRequest.setUrl(request, options.resumable),\n HttpClientRequest.setUrlParam(\"uploadType\", \"resumable\"),\n HttpClientRequest.setHeaders({\n \"x-upload-content-length\": `${size}`,\n \"x-upload-content-type\": payload.contentType,\n }),\n HttpClientRequest.bodyJsonUnsafe(payload.metadata ?? {}),\n ),\n );\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n const sessionUrl = response.headers[\"location\"];\n if (sessionUrl === undefined || !isSafeUrl(sessionUrl, origin)) {\n return yield* Effect.fail({\n cause: \"The API returned an invalid upload session URL\",\n response,\n });\n }\n return yield* decodeResponse(output)({ nextOffset: 0, sessionUrl, state: \"pending\" });\n }\n if (payload.mode === \"chunk\" || payload.mode === \"status\") {\n if (!isSafeUrl(payload.sessionUrl, origin)) {\n return yield* refused(\"The upload session URL must use the API's HTTPS origin\");\n }\n const bytes = media?.bytes ?? new Uint8Array();\n const end = payload.mode === \"chunk\" ? payload.offset + bytes.byteLength : 0;\n if (\n payload.mode === \"chunk\" &&\n (payload.offset < 0 ||\n bytes.byteLength === 0 ||\n end > size ||\n (end < size && bytes.byteLength % 262_144 !== 0))\n ) {\n return yield* refused(\n \"Upload chunks must fit the total size and use 256 KiB multiples except for the final chunk\",\n );\n }\n const response = yield* client.execute(\n pipe(\n HttpClientRequest.put(payload.sessionUrl),\n HttpClientRequest.bodyUint8Array(bytes, media?.contentType ?? \"application/octet-stream\"),\n HttpClientRequest.setHeader(\n \"content-range\",\n payload.mode === \"status\"\n ? `bytes */${size}`\n : `bytes ${payload.offset}-${end - 1}/${size}`,\n ),\n ),\n );\n if (response.status === 308) {\n const range = response.headers[\"range\"];\n if (range !== undefined && !/^bytes=0-\\d+$/u.test(range)) {\n return yield* Effect.fail({\n cause: \"The API returned an invalid upload range\",\n response,\n });\n }\n const nextOffset = range === undefined ? 0 : Number(pipe(range, String.slice(8))) + 1;\n if (nextOffset > size) {\n return yield* Effect.fail({\n cause: \"The API returned an upload offset beyond the total size\",\n response,\n });\n }\n return yield* decodeResponse(output)({\n nextOffset,\n sessionUrl: payload.sessionUrl,\n state: \"pending\",\n });\n }\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n return yield* decodeResponse(output)({ resource: yield* response.json, state: \"complete\" });\n }\n const selected = HttpClientRequest.setUrlParam(request, \"uploadType\", payload.mode);\n const bytes = media?.bytes ?? new Uint8Array();\n const contentType = media?.contentType ?? \"application/octet-stream\";\n const boundary = `dual-${yield* Random.nextInt}-${yield* Random.nextInt}`;\n const metadata =\n payload.mode === \"multipart\"\n ? yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown))(payload.metadata)\n : \"\";\n const body =\n payload.mode === \"media\"\n ? HttpClientRequest.bodyUint8Array(selected, bytes, contentType)\n : HttpClientRequest.bodyUint8Array(\n selected,\n new Uint8Array(\n yield* Effect.promise(() =>\n new Blob([\n `--${boundary}\\r\\nContent-Type: application/json; charset=UTF-8\\r\\n\\r\\n${metadata}\\r\\n--${boundary}\\r\\nContent-Type: ${contentType}\\r\\n\\r\\n`,\n new Uint8Array(bytes),\n `\\r\\n--${boundary}--\\r\\n`,\n ]).arrayBuffer(),\n ),\n ),\n `multipart/related; boundary=${boundary}`,\n );\n const response = yield* client.execute(body);\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n return yield* decodeResponse(output)({ resource: yield* response.json, state: \"complete\" });\n }, Effect.mapError(failure));\n\n /** Sends a GraphQL operation and decodes its root field, failing with the errors it returns. */\n const graphql = Effect.fnUntraced(function* <Output extends Schema.Top>(\n context: Context,\n output: Output,\n request: Request,\n field: string,\n ) {\n const response = yield* send(context, request);\n const body = yield* Schema.decodeUnknownEffect(GraphqlResponse)(yield* response.json);\n if (body.errors !== undefined && Array.isReadonlyArrayNonEmpty(body.errors)) {\n return yield* Action.ActionHandlerError.make({\n details: body.errors,\n message: Array.join(\n Array.map(body.errors, error => error.message),\n \"; \",\n ),\n });\n }\n return yield* decodeResponse(output)(body.data?.[field]);\n }, Effect.mapError(failure));\n\n /**\n * Calls a Model Context Protocol tool in a session with the server. A tool that reports an error\n * fails the action with its text; otherwise the output is its structured content, or its content\n * blocks when it declares no output schema.\n */\n const mcp = Effect.fnUntraced(\n function* <Output extends Schema.Top>(\n context: Context,\n output: Output,\n server: string,\n tool: string,\n args: unknown,\n structured: boolean,\n ) {\n const connection = yield* Mcp.connect(\n authorize(yield* HttpClient.HttpClient, context),\n server,\n {},\n );\n const result = yield* Schema.decodeUnknownEffect(Mcp.CallToolResult)(\n yield* connection.request(\"tools/call\", { arguments: args, name: tool }),\n );\n if (result.isError === true) {\n return yield* Action.ActionHandlerError.make({\n details: result.content,\n message: Array.join(\n Array.flatMap(result.content, block => Array.fromNullishOr(block.text)),\n \"\\n\",\n ),\n });\n }\n return yield* decodeResponse(output)(\n Boolean.match(structured, {\n onFalse: () => ({ content: result.content }),\n onTrue: () => result.structuredContent,\n }),\n );\n },\n Effect.scoped,\n Effect.mapError(error =>\n Schema.is(Mcp.McpError)(error)\n ? Action.ActionHandlerError.make({ message: error.message })\n : failure(error),\n ),\n );\n\n return { endpoint, execute, googleUpload, graphql, mcp, variants };\n}\n\nexport * as Http from \"./Http.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAS,uBAAiC,OAAU,OAAiB;CACnE,IAAI,MAAM,OAAO,OAAO,KAAK,GAAG,OAAO;CACvC,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,KAA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AAG,KAzCvC,OAAO,WACjB,WACE,SACA,QACA,QACA,MACA,MACA,YACA;GACA,MAAM,aAAa,OAAOC,QACxB,UAAU,OAAO,WAAW,YAAY,OAAO,GAC/C,QACA,CAAC,CACH;GACA,MAAM,SAAS,OAAO,OAAO,oBAAoBC,cAAkB,CAAC,CAClE,OAAO,WAAW,QAAQ,cAAc;IAAE,WAAW;IAAM,MAAM;GAAK,CAAC,CACzE;GACA,IAAI,OAAO,YAAY,MACrB,OAAO,OAAA,mBAAiC,KAAK;IAC3C,SAAS,OAAO;IAChB,SAAS,MAAM,KACb,MAAM,QAAQ,OAAO,UAAS,UAAS,MAAM,cAAc,MAAM,IAAI,CAAC,GACtE,IACF;GACF,CAAC;GAEH,OAAO,OAAO,eAAe,MAAM,CAAC,CAClC,QAAQ,MAAM,YAAY;IACxB,gBAAgB,EAAE,SAAS,OAAO,QAAQ;IAC1C,cAAc,OAAO;GACvB,CAAC,CACH;EACF,GACA,OAAO,QACP,OAAO,UAAS,UACd,OAAO,GAAGC,QAAY,CAAC,CAAC,KAAK,IAAA,mBACC,KAAK,EAAE,SAAS,MAAM,QAAQ,CAAC,IACzD,QAAQ,KAAK,CACnB,CAGmD;EAAG;CAAS;AACnE"}
|
|
1
|
+
{"version":3,"file":"Http.js","names":["ToolFile.Schema","Files.read","Files.File","Action.ActionHandlerError","Action.fromHttpClientFailure","Files.write","Mcp.connect","Mcp.CallToolResult","Mcp.McpError"],"sources":["../src/Http.ts"],"sourcesContent":["/**\n * The HTTP runtime of generated API plugins: each operation's contract and call, request encoding,\n * response decoding, continuation links, redirects and uploads.\n *\n * @since 0.0.0\n */\nimport {\n Array,\n Boolean,\n DateTime,\n Effect,\n Equal,\n Option,\n Order,\n Predicate,\n Random,\n Record,\n Result,\n Schema,\n SchemaGetter,\n SchemaIssue,\n String,\n flow,\n pipe,\n} from \"effect\";\nimport type { SchemaAST } from \"effect\";\n\nimport { Base64, Base64Url } from \"effect/encoding\";\nimport {\n FetchHttpClient,\n HttpBody,\n HttpClient,\n HttpClientError,\n HttpClientRequest,\n Headers,\n UrlParams,\n} from \"effect/http\";\nimport type { HttpClientResponse } from \"effect/http\";\n\nimport * as Action from \"./Action.ts\";\nimport type * as AuthMethod from \"./AuthMethod.ts\";\nimport { Files } from \"./Files.ts\";\nimport { Mcp } from \"./Mcp.ts\";\nimport * as ToolFile from \"./ToolFile.ts\";\n\nfunction preserveJsonProperties<A, Input>(value: A, input: Input): A {\n if (Equal.equals(value, input)) return value;\n if (Array.isArray(value) && Array.isArray(input)) {\n for (const entry of Array.zip(value, input)) preserveJsonProperties(entry[0], entry[1]);\n } else if (Predicate.isObject(value) && Predicate.isObject(input)) {\n for (const entry of Record.toEntries(input)) {\n if (Record.has(value, entry[0])) {\n preserveJsonProperties(value[entry[0]], entry[1]);\n } else {\n Object.defineProperty(value, entry[0], {\n configurable: true,\n enumerable: true,\n value: entry[1],\n writable: true,\n });\n }\n }\n }\n return value;\n}\n\nfunction decodeResponse<Output extends Schema.Top>(output: Output) {\n return flow(\n Effect.succeed,\n Effect.flatMap(input =>\n pipe(\n Schema.decodeUnknownEffect(output)(input),\n Effect.map(value => preserveJsonProperties(value, input)),\n ),\n ),\n );\n}\n\n/**\n * An action's input and output schemas.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface Contract {\n readonly input: Schema.Top;\n readonly output: Schema.Top;\n}\n\n/**\n * Runs an action: its input in, its output or a failure out.\n *\n * @since 0.0.0\n * @category models\n */\nexport type Handler<Methods extends readonly AuthMethod.Any[], Input, Output> = (\n input: Input,\n context: Action.HandlerContext<Methods>,\n) => Effect.Effect<Output, Action.ActionHandlerFailure, HttpClient.HttpClient>;\n\n/**\n * A file input: a ToolFile as a download returns it, or just its bytes with a type and name.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport type File = typeof File.Type;\nexport const File = Schema.Struct({\n _tag: Schema.optionalKey(Schema.Literal(\"ToolFile\")),\n contentBase64: Schema.Uint8ArrayFromBase64,\n contentType: Schema.optionalKey(Schema.NullOr(Schema.String)),\n filename: Schema.optionalKey(Schema.NullOr(Schema.String)),\n sizeBytes: Schema.optionalKey(Schema.Natural),\n}).annotate({\n description:\n \"A ToolFile, such as the result of a download, passed unchanged; or its contentBase64 with an optional contentType and filename.\",\n});\n\nconst signatures: [string, [number, number[]][]][] = [\n [\"image/jpeg\", [[0, [0xff, 0xd8, 0xff]]]],\n [\"image/png\", [[0, [0x89, 0x50, 0x4e, 0x47]]]],\n [\"image/gif\", [[0, [0x47, 0x49, 0x46, 0x38]]]],\n [\n \"image/webp\",\n [\n [0, [0x52, 0x49, 0x46, 0x46]],\n [8, [0x57, 0x45, 0x42, 0x50]],\n ],\n ],\n [\"application/pdf\", [[0, [0x25, 0x50, 0x44, 0x46]]]],\n [\"application/zip\", [[0, [0x50, 0x4b, 0x03, 0x04]]]],\n];\n\nconst utf8 = new TextDecoder(\"utf-8\", { fatal: true });\n\nfunction sniff(bytes: Uint8Array) {\n return pipe(\n Array.findFirst(signatures, signature =>\n Array.every(signature[1], part =>\n Array.every(part[1], (byte, index) => bytes[part[0] + index] === byte),\n ),\n ),\n Option.map(signature => signature[0]),\n Option.orElse(() =>\n Option.liftPredicate(\"text/plain\", () =>\n Result.isSuccess(Result.try(() => utf8.decode(bytes))),\n ),\n ),\n Option.getOrNull,\n );\n}\n\nfunction toolFile(bytes: Uint8Array, declared: string | null, filename: string | null) {\n return {\n _tag: \"ToolFile\",\n contentBase64: Base64.encode(bytes),\n contentType:\n declared === null || pipe(declared, String.startsWith(\"application/octet-stream\"))\n ? (sniff(bytes) ?? declared)\n : declared,\n filename,\n sizeBytes: bytes.byteLength,\n } satisfies ToolFile.File;\n}\n\nfunction invalid(expected: string, value: unknown, options: SchemaAST.ParseOptions) {\n return Effect.fail(new SchemaIssue.InvalidValue({ expected }, value, options));\n}\n\nfunction decodeBytes(text: string, options: SchemaAST.ParseOptions) {\n return Result.match(\n Base64Url.decode(pipe(text, String.replaceAll(\"+\", \"-\"), String.replaceAll(\"/\", \"_\"))),\n {\n onFailure: () => invalid(\"a Base64 or Base64Url string\", text, options),\n onSuccess: bytes => Effect.succeed(bytes),\n },\n );\n}\n\ntype Carrier = \"base64\" | \"base64url\" | \"data-uri\";\n\ninterface Content {\n bytes: Uint8Array;\n contentType: string | null;\n}\n\nfunction contentOf(carrier: Carrier) {\n return SchemaGetter.transformEffect<Content, string>((text, options) => {\n if (carrier !== \"data-uri\") {\n return Effect.map(decodeBytes(text, options), bytes => ({ bytes, contentType: null }));\n }\n return Option.match(pipe(text, String.match(/^data:([^;,]*)(?:;[^;,]*)*;base64,(.*)$/su)), {\n onNone: () => invalid(\"a Base64 data URI\", text, options),\n onSome: parts =>\n Effect.map(decodeBytes(Array.getUnsafe(parts, 2), options), bytes => ({\n bytes,\n contentType: pipe(\n Array.getUnsafe(parts, 1),\n Option.liftPredicate(String.isNonEmpty),\n Option.getOrNull,\n ),\n })),\n });\n });\n}\n\nfunction textOf(carrier: Carrier, content: Content) {\n if (carrier === \"base64\") return Base64.encode(content.bytes);\n if (carrier === \"base64url\") return Base64Url.encode(content.bytes);\n const contentType = content.contentType ?? sniff(content.bytes) ?? \"application/octet-stream\";\n return `data:${contentType};base64,${Base64.encode(content.bytes)}`;\n}\n\nfunction fileFrom(carrier: Carrier) {\n return Schema.String.pipe(\n Schema.decodeTo(ToolFile.Schema, {\n decode: SchemaGetter.compose(\n contentOf(carrier),\n SchemaGetter.transform(content => toolFile(content.bytes, content.contentType, null)),\n ),\n encode: SchemaGetter.transformEffect((file: ToolFile.File, options) =>\n Effect.map(decodeBytes(file.contentBase64, options), bytes =>\n textOf(carrier, { bytes, contentType: file.contentType }),\n ),\n ),\n }),\n );\n}\n\nfunction encodedFrom(carrier: Carrier) {\n return File.pipe(\n Schema.decodeTo(Schema.String, {\n decode: SchemaGetter.transform(file =>\n textOf(carrier, { bytes: file.contentBase64, contentType: file.contentType ?? null }),\n ),\n encode: SchemaGetter.compose(\n contentOf(carrier),\n SchemaGetter.transform(content => ({\n contentBase64: content.bytes,\n contentType: content.contentType,\n })),\n ),\n }),\n );\n}\n\n/**\n * A file the API returns as a Base64 string inside JSON, decoded into a ToolFile with its content\n * type recognized from the bytes.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const FileFromBase64 = fileFrom(\"base64\");\n\n/**\n * {@link FileFromBase64} for an API that writes the file in Base64Url.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const FileFromBase64Url = fileFrom(\"base64url\");\n\n/**\n * A {@link File} input the API reads as a Base64 string inside JSON.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const Base64FromFile = encodedFrom(\"base64\");\n\n/**\n * {@link Base64FromFile} for an API that reads the file in Base64Url.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const Base64UrlFromFile = encodedFrom(\"base64url\");\n\n/**\n * {@link FileFromBase64} for an API that writes the file as a data URI, which also carries its\n * content type.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const FileFromDataUri = fileFrom(\"data-uri\");\n\n/**\n * {@link Base64FromFile} for an API that reads the file as a data URI, built from the file's\n * content type.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const DataUriFromFile = encodedFrom(\"data-uri\");\n\ntype DateTimeText = typeof DateTimeText.Type;\nconst DateTimeText = Schema.String.annotate({ format: \"date-time\" });\n\nconst rfc3339 = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})(?:\\.\\d+)?(?:Z|([+-]\\d{2}:\\d{2}))$/u;\n\n/** The instant of an RFC 3339 date-time with its offset; an impossible date such as February 30 has none. */\nfunction rfc3339Instant(text: string) {\n return pipe(\n Option.fromNullishOr(rfc3339.exec(text)),\n Option.flatMap(match =>\n Option.filter(DateTime.makeZoned(text, { timeZone: match[2] ?? \"+00:00\" }), zoned =>\n String.startsWith(match[1] ?? \"\")(DateTime.formatIsoOffset(zoned)),\n ),\n ),\n Option.map(DateTime.toUtc),\n );\n}\n\nfunction instants<Wire>(\n wire: Schema.Codec<Wire>,\n expected: string,\n read: (value: Wire) => Option.Option<DateTime.Utc>,\n write: (instant: DateTime.Utc) => Wire,\n) {\n const fromWire = SchemaGetter.transformEffect<string, Wire>((value, options) =>\n Option.match(read(value), {\n onNone: () => invalid(expected, value, options),\n onSome: instant => Effect.succeed(DateTime.formatIso(instant)),\n }),\n );\n const toWire = SchemaGetter.transformEffect<Wire, string>((text, options) =>\n Option.match(rfc3339Instant(text), {\n onNone: () => invalid(\"an ISO 8601 date-time\", text, options),\n onSome: instant => Effect.succeed(write(instant)),\n }),\n );\n return {\n input: pipe(DateTimeText, Schema.decodeTo(wire, { decode: toWire, encode: fromWire })),\n output: pipe(wire, Schema.decodeTo(DateTimeText, { decode: fromWire, encode: toWire })),\n };\n}\n\nconst unixSeconds = instants(\n Schema.Int,\n \"Unix seconds\",\n seconds => Option.map(DateTime.make(seconds * 1000), DateTime.toUtc),\n instant => Math.floor(DateTime.toEpochMillis(instant) / 1000),\n);\n\nconst rfc2822 = instants(\n Schema.String,\n \"an RFC 2822 date-time\",\n text => Option.map(DateTime.make(text), DateTime.toUtc),\n instant => DateTime.toDateUtc(instant).toUTCString(),\n);\n\n/**\n * A date-time the API writes as Unix seconds, decoded into an ISO 8601 UTC string.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const DateTimeFromUnixSeconds = unixSeconds.output;\n\n/**\n * An ISO 8601 date-time input the API reads as Unix seconds.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const UnixSecondsFromDateTime = unixSeconds.input;\n\n/**\n * A date-time the API writes in RFC 2822 form, decoded into an ISO 8601 UTC string.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const DateTimeFromRfc2822 = rfc2822.output;\n\n/**\n * An ISO 8601 date-time input the API reads in RFC 2822 form.\n *\n * @since 0.0.0\n * @category schemas\n */\nexport const Rfc2822FromDateTime = rfc2822.input;\n\n/**\n * An action output whose response decodes into a different shape, such as a file the API sends as\n * Base64: the action declares the decoded shape and the call decodes the response with `wire`.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface Decoded<Wire extends Schema.Top> {\n readonly _tag: \"Decoded\";\n readonly wire: Wire;\n}\n\n/**\n * Declares an output by the response schema it decodes from; see {@link Decoded}.\n *\n * @since 0.0.0\n * @category constructors\n */\nexport function decoded<const Wire extends Schema.Top>(wire: Wire): Decoded<Wire> {\n return { _tag: \"Decoded\", wire };\n}\n\ntype Request =\n | HttpClientRequest.HttpClientRequest\n | Effect.Effect<HttpClientRequest.HttpClientRequest, Action.ActionHandlerError>;\n\n/** `binary` returns a released version's base64 `ToolFile`; `file` stores the body as a file. */\ntype Body = \"json\" | \"text\" | \"binary\" | \"file\" | \"void\" | \"unknown\";\n\ntype GraphqlResponse = typeof GraphqlResponse.Type;\nconst GraphqlResponse = Schema.Struct({\n data: Schema.optionalKey(Schema.NullOr(Schema.Record(Schema.String, Schema.Unknown))),\n errors: Schema.optionalKey(\n Schema.Array(\n Schema.StructWithRest(Schema.Struct({ message: Schema.String }), [\n Schema.Record(Schema.String, Schema.Unknown),\n ]),\n ),\n ),\n});\n\n/**\n * A response status, media type and decoding mode advertised by an HTTP action.\n *\n * @since 0.4.1\n * @category models\n */\nexport interface Variant {\n readonly status?: number;\n readonly contentType: string;\n readonly body: Body;\n readonly headers?: readonly string[];\n}\n\ntype Media =\n | { readonly contentBase64: Uint8Array; readonly contentType?: string | null }\n | Files.File;\n\ntype Upload =\n | { readonly mode: \"media\"; readonly media: Media }\n | { readonly mode: \"multipart\"; readonly media: Media; readonly metadata: unknown }\n | {\n readonly mode: \"start\";\n readonly contentType: string;\n readonly metadata?: unknown;\n readonly totalBytes: number;\n }\n | {\n readonly mode: \"chunk\";\n readonly sessionUrl: string;\n readonly totalBytes: number;\n readonly offset: number;\n readonly media: Media;\n }\n | { readonly mode: \"status\"; readonly sessionUrl: string; readonly totalBytes: number };\n\nfunction coerce(value: unknown) {\n return Predicate.isObject(value) ? JSON.stringify(value) : `${value}`;\n}\n\n/**\n * Encodes a path parameter as one segment.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function path(value: unknown) {\n return encodeURIComponent(coerce(value));\n}\n\n/**\n * Encodes a path parameter written inside single quotes, an OData string literal, doubling its\n * quotes: `O'Brien` in `People('{name}')` is sent as `People('O''Brien')`.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function literal(value: unknown) {\n return path(pipe(coerce(value), String.replaceAll(\"'\", \"''\")));\n}\n\n/**\n * Encodes a path parameter whose slashes stay path separators.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function segments(value: unknown) {\n return Array.join(Array.map(String.split(coerce(value), \"/\"), encodeURIComponent), \"/\");\n}\n\nfunction deepObject(name: string, value: unknown): [string, string][] {\n if (Array.isArray(value)) {\n return Array.flatMap(value, (item, index) => deepObject(`${name}[${index}]`, item));\n }\n if (Predicate.isObject(value)) {\n return Array.flatMap(Record.toEntries(value), entry =>\n deepObject(`${name}[${entry[0]}]`, entry[1]),\n );\n }\n return value === undefined ? [] : [[name, coerce(value)]];\n}\n\n/**\n * Query, header or form entries, repeating array values unless their name is joined, and encoding\n * `deep` names as bracketed keys such as `metadata[plan]` and `expand[0]`. A joined name is\n * comma-separated, or separated by the delimiter it is paired with, such as `[\"ids\", \"|\"]`.\n * `exploded` object parameters use their property names as query keys (`role=vet&active=true`).\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function params(\n fields: Record.ReadonlyRecord<string, unknown>,\n joined: readonly (string | readonly [string, string])[] = [],\n deep: readonly string[] = [],\n exploded: readonly string[] = [],\n) {\n return Array.flatMap(Record.toEntries(fields), field => {\n if (field[1] === undefined) return [];\n if (Array.contains(deep, field[0])) return deepObject(field[0], field[1]);\n const values = field[1];\n if (\n Array.contains(exploded, field[0]) &&\n Predicate.isObject(values) &&\n !Array.isArray(values)\n ) {\n return Array.filterMap(Record.toEntries(values), entry =>\n entry[1] === undefined\n ? Result.failVoid\n : Result.succeed([entry[0], coerce(entry[1])] as const),\n );\n }\n if (!Array.isArray(values)) return [[field[0], coerce(values)] as const];\n const separator = Array.findFirst(joined, entry => {\n const pair = Predicate.isString(entry) ? ([entry, \",\"] as const) : entry;\n return pair[0] === field[0] ? Option.some(pair[1]) : Option.none();\n });\n return Option.match(separator, {\n onNone: () => Array.map(values, item => [field[0], coerce(item)] as const),\n onSome: value => [[field[0], Array.join(Array.map(values, coerce), value)] as const],\n });\n });\n}\n\nfunction filePart(bytes: Uint8Array, name: string, contentType: string) {\n return new globalThis.File([new Uint8Array(bytes)], name, { type: contentType });\n}\n\n/**\n * Multipart form fields, sending each {@link File} as a file part.\n *\n * @since 0.0.0\n * @category encoding\n */\nexport function form(payload: Record.ReadonlyRecord<string, unknown>) {\n return Record.map(payload, (value, name) =>\n Array.map(Array.ensure(value), item => {\n if (item === undefined) return undefined;\n if (!Schema.is(File)(item)) return coerce(item);\n return filePart(\n item.contentBase64,\n item.filename ?? name,\n item.contentType ?? \"application/octet-stream\",\n );\n }),\n );\n}\n\nfunction fileFailed(error: Files.FileError) {\n return Action.ActionHandlerError.make({ cause: error, message: error.message });\n}\n\nfunction readFile(file: Files.File) {\n return pipe(Files.read(file), Effect.mapError(fileFailed));\n}\n\n/**\n * Sends a file as the raw request body.\n *\n * @since 0.1.0\n * @category encoding\n */\nexport const withFile = Effect.fnUntraced(function* (\n request: HttpClientRequest.HttpClientRequest,\n file: Files.File,\n) {\n return HttpClientRequest.bodyUint8Array(request, yield* readFile(file), file.contentType);\n});\n\n/**\n * Sends multipart form fields, each {@link Files.File} as a file part.\n *\n * @since 0.1.0\n * @category encoding\n */\nexport const withForm = Effect.fnUntraced(function* (\n request: HttpClientRequest.HttpClientRequest,\n payload: Record.ReadonlyRecord<string, unknown>,\n) {\n return HttpClientRequest.bodyFormDataRecord(\n request,\n Record.fromEntries(\n yield* Effect.forEach(Record.toEntries(payload), field =>\n Effect.map(\n Effect.forEach(\n Array.filter(Array.ensure(field[1]), item => item !== undefined),\n item =>\n Effect.gen(function* () {\n if (!Schema.is(Files.File)(item)) return coerce(item);\n return filePart(yield* readFile(item), item.name, item.contentType);\n }),\n ),\n parts => [field[0], parts] satisfies [string, (string | globalThis.File)[]],\n ),\n ),\n ),\n );\n});\n\nfunction mediaBytes(media: Media) {\n if (Schema.is(Files.File)(media)) {\n return Effect.map(readFile(media), bytes => ({ bytes, contentType: media.contentType }));\n }\n return Effect.succeed({\n bytes: media.contentBase64,\n contentType: Option.getOrNull(Option.fromNullishOr(media.contentType)),\n });\n}\n\nfunction isSafeUrl(value: string, origin?: string) {\n if (!URL.canParse(value)) return false;\n const url = new URL(value);\n return (\n url.protocol === \"https:\" &&\n url.username === \"\" &&\n url.password === \"\" &&\n (origin === undefined || url.origin === origin)\n );\n}\n\nfunction refused(message: string) {\n return Effect.fail(Action.ActionHandlerError.make({ message }));\n}\n\n/**\n * Follows a returned next-page link on the operation's own origin: only its path and query are\n * taken, so the connection's host routing applies and credentials never reach another host.\n *\n * @since 0.0.0\n * @category requests\n */\nexport function continuation(request: HttpClientRequest.HttpClientRequest, nextLink?: string) {\n if (nextLink === undefined) return Effect.succeed(request);\n const declared = new URL(request.url);\n const next = URL.canParse(nextLink) ? new URL(nextLink) : undefined;\n if (next === undefined || !isSafeUrl(nextLink) || next.pathname !== declared.pathname) {\n return refused(\"A continuation URL must be an HTTPS link to the same operation path\");\n }\n return Effect.succeed(\n HttpClientRequest.makeWith(\n request.method,\n `${declared.origin}${next.pathname}${next.search}`,\n UrlParams.empty,\n Option.none(),\n request.headers,\n HttpBody.empty,\n ),\n );\n}\n\n/**\n * A request to a preauthenticated upload URL, which is sent without the connection's credentials.\n *\n * @since 0.0.0\n * @category requests\n */\nexport function preauthenticated(\n method: (url: string) => HttpClientRequest.HttpClientRequest,\n url: string,\n ...steps: readonly ((\n request: HttpClientRequest.HttpClientRequest,\n ) => HttpClientRequest.HttpClientRequest)[]\n) {\n if (!isSafeUrl(url)) return refused(\"An upload session requires a preauthenticated HTTPS URL\");\n return Effect.succeed(Array.reduce(steps, method(url), (request, step) => step(request)));\n}\n\nfunction failure(\n error:\n | Action.ActionHandlerError\n | Action.HttpClientFailure\n | { readonly cause: unknown; readonly response: HttpClientResponse.HttpClientResponse },\n) {\n return Schema.is(Action.ActionHandlerError)(error) ? error : Action.fromHttpClientFailure(error);\n}\n\n// Like HttpClient.followRedirects, except that a redirect to another origin sends no\n// request header at all: auth methods may set any header, such as GitLab's PRIVATE-TOKEN.\nfunction redirect(response: HttpClientResponse.HttpClientResponse) {\n const location = response.headers[\"location\"];\n if (response.status < 300 || response.status >= 400 || location === undefined) return undefined;\n const sent = response.request;\n const url = new URL(location, sent.url);\n const request =\n (response.status === 303 && sent.method !== \"GET\" && sent.method !== \"HEAD\") ||\n ((response.status === 301 || response.status === 302) && sent.method === \"POST\")\n ? HttpClientRequest.setBody(HttpClientRequest.setMethod(sent, \"GET\"), HttpBody.empty)\n : sent;\n return url.origin === new URL(sent.url).origin\n ? HttpClientRequest.setUrl(request, url)\n : HttpClientRequest.setUrl(\n HttpClientRequest.makeWith(\n request.method,\n \"\",\n UrlParams.empty,\n Option.none(),\n Headers.empty,\n request.body,\n ),\n url,\n );\n}\n\nfunction follow(\n client: HttpClient.HttpClient,\n response: HttpClientResponse.HttpClientResponse,\n redirects: number,\n): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> {\n const next = redirect(response);\n return next === undefined || redirects === 10\n ? Effect.succeed(response)\n : Effect.flatMap(client.execute(next), result => follow(client, result, redirects + 1));\n}\n\n/** The file name a `Content-Disposition` header suggests, preferring its encoded form. */\nfunction dispositionName(header?: string) {\n if (header === undefined) return undefined;\n const encoded = pipe(\n String.match(/(?:^|;)\\s*filename\\*\\s*=\\s*UTF-8'[^']*'([^;]+)/iu)(header),\n Option.flatMap(match => Option.fromUndefinedOr(match[1])),\n );\n const decoded = pipe(\n encoded,\n Option.flatMap(value => Option.liftThrowable(() => decodeURIComponent(String.trim(value)))()),\n );\n return Option.getOrElse(decoded, () =>\n pipe(\n String.match(/(?:^|;)\\s*filename\\s*=\\s*(?:\"((?:\\\\.|[^\"\\\\])*)\"|([^;]*))/iu)(header),\n Option.flatMap(match =>\n Option.orElse(\n Option.map(Option.fromUndefinedOr(match[1]), name =>\n String.replace(/\\\\(.)/gu, \"$1\")(name),\n ),\n () => Option.map(Option.fromUndefinedOr(match[2]), String.trim),\n ),\n ),\n Option.getOrUndefined,\n ),\n );\n}\n\nconst read = Effect.fnUntraced(function* (\n response: HttpClientResponse.HttpClientResponse,\n body: Body,\n) {\n if (body === \"json\") return yield* response.json;\n if (body === \"text\") return yield* response.text;\n if (body === \"void\") return {};\n if (body === \"unknown\") {\n const text = yield* response.text;\n if (String.isEmpty(String.trim(text))) return null;\n return Option.getOrElse(\n Schema.decodeOption(Schema.fromJsonString(Schema.Json))(text),\n () => text,\n );\n }\n const bytes = new Uint8Array(yield* response.arrayBuffer);\n const name = dispositionName(response.headers[\"content-disposition\"]);\n if (body === \"file\") {\n return yield* pipe(\n Files.write({\n bytes,\n contentType: Option.getOrNull(Option.fromUndefinedOr(response.headers[\"content-type\"])),\n name: name ?? \"file\",\n }),\n Effect.mapError(fileFailed),\n );\n }\n return toolFile(bytes, response.headers[\"content-type\"] ?? null, name ?? null);\n});\n\n/**\n * One API operation as {@link make} returns it: its contract and the call that performs it. The\n * `Context` parameter lets a package name its handler context once, so declaration files print\n * `Endpoint<Context, …>` instead of repeating its auth methods in every action.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface Endpoint<Context, Input extends Schema.Top, Output extends Schema.Top> {\n readonly input: Input;\n readonly output: Output;\n readonly run: (\n input: Input[\"Type\"],\n context: Context,\n ) => Effect.Effect<Output[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>;\n}\n\n/**\n * An {@link Endpoint} whose output is the decoded type of the response schema it keeps as `wire`.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface DecodedEndpoint<Context, Input extends Schema.Top, Wire extends Schema.Top> {\n readonly input: Input;\n readonly output: Schema.toType<Wire>;\n readonly wire: Wire;\n readonly run: (\n input: Input[\"Type\"],\n context: Context,\n ) => Effect.Effect<Wire[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>;\n}\n\n/**\n * Binds the runtime to a package's auth module: the calls a generated version file makes. Its\n * `authorize` applies a connection's credentials to the client. Its optional `checkResponse` fails\n * a successful response that reports a failed call, such as Slack's `{ ok: false, error }`.\n * `preauthenticatedUploadUrl` restricts credential-free upload requests and every redirect to\n * provider-approved HTTPS URLs, without changing authenticated calls or other providers.\n *\n * @since 0.0.0\n * @category constructors\n */\nexport function make<\n const Methods extends readonly AuthMethod.Any[],\n Context extends Action.HandlerContext<Methods> = Action.HandlerContext<Methods>,\n>(auth: {\n readonly authorize: (\n client: HttpClient.HttpClient,\n context: Action.HandlerContext<Methods>,\n ) => HttpClient.HttpClient;\n readonly checkResponse?: (\n response: HttpClientResponse.HttpClientResponse,\n ) => Effect.Effect<void, Action.ActionHandlerError | HttpClientError.HttpClientError>;\n readonly preauthenticatedUploadUrl?: Schema.Schema<string>;\n}) {\n const { authorize, checkResponse = () => Effect.void } = auth;\n const send = Effect.fnUntraced(function* (context: Context | undefined, request: Request) {\n const base = yield* HttpClient.HttpClient;\n const uploadPolicy = context === undefined ? auth.preauthenticatedUploadUrl : undefined;\n const client =\n uploadPolicy === undefined\n ? base\n : HttpClient.mapRequestEffect(base, outgoing =>\n isSafeUrl(outgoing.url) && Schema.is(uploadPolicy)(outgoing.url)\n ? Effect.succeed(outgoing)\n : Effect.fail(\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.InvalidUrlError({\n description: \"The upload URL is not an approved provider HTTPS destination\",\n request: outgoing,\n }),\n }),\n ),\n );\n const transport = HttpClient.transformResponse(\n client,\n Effect.flatMap(response => follow(client, response, 0)),\n );\n const authorized = context === undefined ? transport : authorize(transport, context);\n const execution = authorized.execute(Effect.isEffect(request) ? yield* request : request);\n const options = yield* Effect.serviceOption(FetchHttpClient.RequestInit);\n const response = yield* Boolean.match(uploadPolicy !== undefined, {\n onFalse: () => execution,\n onTrue: () =>\n Effect.provideService(execution, FetchHttpClient.RequestInit, {\n ...Option.getOrElse(options, () => ({})),\n redirect: \"manual\",\n }),\n });\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n yield* checkResponse(response);\n return response;\n });\n\n /**\n * One API operation: its action contract and the call that performs it. A {@link Decoded} output\n * declares the decoded shape and hands the call its response schema.\n */\n function endpoint<const Input extends Schema.Top, const Output extends Schema.Top>(\n contract: { readonly input: Input; readonly output: Output },\n run: (\n input: Input[\"Type\"],\n context: Context,\n output: Output,\n ) => Effect.Effect<Output[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>,\n ): Endpoint<Context, Input, Output>;\n function endpoint<const Input extends Schema.Top, const Wire extends Schema.Top>(\n contract: { readonly input: Input; readonly output: Decoded<Wire> },\n run: (\n input: Input[\"Type\"],\n context: Context,\n output: Wire,\n ) => Effect.Effect<Wire[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>,\n ): DecodedEndpoint<Context, Input, Wire>;\n function endpoint<const Input extends Schema.Top, const Output extends Schema.Top>(\n contract: { readonly input: Input; readonly output: Output | Decoded<Output> },\n run: (\n input: Input[\"Type\"],\n context: Context,\n output: Output,\n ) => Effect.Effect<Output[\"Type\"], Action.ActionHandlerFailure, HttpClient.HttpClient>,\n ) {\n if (!Schema.isSchema(contract.output)) {\n const wire = contract.output.wire;\n return {\n input: contract.input,\n output: Schema.toType(wire),\n run: (input: Input[\"Type\"], context: Context) => run(input, context, wire),\n wire,\n };\n }\n const output = contract.output;\n return {\n input: contract.input,\n output,\n run: (input: Input[\"Type\"], context: Context) => run(input, context, output),\n };\n }\n\n /** Sends a request and decodes its body as the operation's single response. */\n function execute<Output extends Schema.Top>(\n context: Context | undefined,\n output: Output,\n request: Request,\n body: Body,\n ) {\n return pipe(\n send(context, request),\n Effect.flatMap(response => read(response, body)),\n Effect.flatMap(decodeResponse(output)),\n Effect.mapError(failure),\n );\n }\n\n /** Sends a request and decodes the declared response variant its status and media type select. */\n const variants = Effect.fnUntraced(function* <Output extends Schema.Top>(\n context: Context | undefined,\n output: Output,\n request: Request,\n declared: readonly Variant[],\n media?: boolean,\n ) {\n const response = yield* send(context, request);\n const exact = Array.flatMap(declared, variant =>\n variant.status === undefined ? [] : [variant.status],\n );\n const contentType = pipe(\n response.headers[\"content-type\"] ?? \"\",\n String.split(\";\"),\n Array.headNonEmpty,\n String.trim,\n String.toLowerCase,\n );\n const ordered = Array.sort(\n declared,\n Order.mapInput(Order.Number, (variant: Variant) => {\n if (variant.body === \"void\" || variant.body === \"unknown\") return 3;\n if (variant.contentType === \"*/*\") return 2;\n return pipe(variant.contentType, String.endsWith(\"/*\")) ? 1 : 0;\n }),\n );\n const variant = Array.findFirst(ordered, candidate => {\n const status =\n candidate.status === undefined\n ? !Array.contains(exact, response.status)\n : candidate.status === response.status;\n if (!status) return false;\n if (media !== undefined) {\n return (candidate.body === \"binary\" || candidate.body === \"file\") === media;\n }\n if (\n candidate.body === \"void\" ||\n candidate.body === \"unknown\" ||\n candidate.contentType === \"*/*\"\n ) {\n return true;\n }\n if (pipe(candidate.contentType, String.endsWith(\"/*\"))) {\n return pipe(\n contentType,\n String.startsWith(pipe(candidate.contentType, String.slice(0, -1))),\n );\n }\n return contentType === candidate.contentType;\n });\n if (Option.isNone(variant)) {\n return yield* Effect.fail({\n cause: \"The API returned an undeclared successful response\",\n response,\n });\n }\n const headers = Array.flatMap(variant.value.headers ?? [], name => {\n const value = response.headers[String.toLowerCase(name)];\n return value === undefined ? [] : [[name, value] as const];\n });\n return yield* decodeResponse(output)({\n body: yield* read(response, variant.value.body),\n contentType: variant.value.contentType,\n status: response.status,\n ...(variant.value.headers === undefined ? {} : { headers: Record.fromEntries(headers) }),\n });\n }, Effect.mapError(failure));\n\n /** Google's media, multipart and resumable upload protocols. */\n const googleUpload = Effect.fnUntraced(function* <Output extends Schema.Top>(\n context: Context,\n output: Output,\n request: HttpClientRequest.HttpClientRequest,\n payload: Upload,\n options: { readonly maxSize?: number; readonly resumable?: string },\n ) {\n const client = authorize(yield* HttpClient.HttpClient, context);\n const media = \"media\" in payload ? yield* mediaBytes(payload.media) : undefined;\n const size = \"totalBytes\" in payload ? payload.totalBytes : (media?.bytes.byteLength ?? 0);\n if (size < 0 || (options.maxSize !== undefined && size > options.maxSize)) {\n return yield* refused(\"The upload size is outside the API's declared limit\");\n }\n const origin = new URL(request.url).origin;\n if (payload.mode === \"start\") {\n if (options.resumable === undefined) {\n return yield* refused(\"This API has no resumable upload protocol\");\n }\n const response = yield* client.execute(\n pipe(\n HttpClientRequest.setUrl(request, options.resumable),\n HttpClientRequest.setUrlParam(\"uploadType\", \"resumable\"),\n HttpClientRequest.setHeaders({\n \"x-upload-content-length\": `${size}`,\n \"x-upload-content-type\": payload.contentType,\n }),\n HttpClientRequest.bodyJsonUnsafe(payload.metadata ?? {}),\n ),\n );\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n const sessionUrl = response.headers[\"location\"];\n if (sessionUrl === undefined || !isSafeUrl(sessionUrl, origin)) {\n return yield* Effect.fail({\n cause: \"The API returned an invalid upload session URL\",\n response,\n });\n }\n return yield* decodeResponse(output)({ nextOffset: 0, sessionUrl, state: \"pending\" });\n }\n if (payload.mode === \"chunk\" || payload.mode === \"status\") {\n if (!isSafeUrl(payload.sessionUrl, origin)) {\n return yield* refused(\"The upload session URL must use the API's HTTPS origin\");\n }\n const bytes = media?.bytes ?? new Uint8Array();\n const end = payload.mode === \"chunk\" ? payload.offset + bytes.byteLength : 0;\n if (\n payload.mode === \"chunk\" &&\n (payload.offset < 0 ||\n bytes.byteLength === 0 ||\n end > size ||\n (end < size && bytes.byteLength % 262_144 !== 0))\n ) {\n return yield* refused(\n \"Upload chunks must fit the total size and use 256 KiB multiples except for the final chunk\",\n );\n }\n const response = yield* client.execute(\n pipe(\n HttpClientRequest.put(payload.sessionUrl),\n HttpClientRequest.bodyUint8Array(bytes, media?.contentType ?? \"application/octet-stream\"),\n HttpClientRequest.setHeader(\n \"content-range\",\n payload.mode === \"status\"\n ? `bytes */${size}`\n : `bytes ${payload.offset}-${end - 1}/${size}`,\n ),\n ),\n );\n if (response.status === 308) {\n const range = response.headers[\"range\"];\n if (range !== undefined && !/^bytes=0-\\d+$/u.test(range)) {\n return yield* Effect.fail({\n cause: \"The API returned an invalid upload range\",\n response,\n });\n }\n const nextOffset = range === undefined ? 0 : Number(pipe(range, String.slice(8))) + 1;\n if (nextOffset > size) {\n return yield* Effect.fail({\n cause: \"The API returned an upload offset beyond the total size\",\n response,\n });\n }\n return yield* decodeResponse(output)({\n nextOffset,\n sessionUrl: payload.sessionUrl,\n state: \"pending\",\n });\n }\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n return yield* decodeResponse(output)({ resource: yield* response.json, state: \"complete\" });\n }\n const selected = HttpClientRequest.setUrlParam(request, \"uploadType\", payload.mode);\n const bytes = media?.bytes ?? new Uint8Array();\n const contentType = media?.contentType ?? \"application/octet-stream\";\n const boundary = `dual-${yield* Random.nextInt}-${yield* Random.nextInt}`;\n const metadata =\n payload.mode === \"multipart\"\n ? yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown))(payload.metadata)\n : \"\";\n const body =\n payload.mode === \"media\"\n ? HttpClientRequest.bodyUint8Array(selected, bytes, contentType)\n : HttpClientRequest.bodyUint8Array(\n selected,\n new Uint8Array(\n yield* Effect.promise(() =>\n new Blob([\n `--${boundary}\\r\\nContent-Type: application/json; charset=UTF-8\\r\\n\\r\\n${metadata}\\r\\n--${boundary}\\r\\nContent-Type: ${contentType}\\r\\n\\r\\n`,\n new Uint8Array(bytes),\n `\\r\\n--${boundary}--\\r\\n`,\n ]).arrayBuffer(),\n ),\n ),\n `multipart/related; boundary=${boundary}`,\n );\n const response = yield* client.execute(body);\n if (response.status < 200 || response.status >= 300) {\n return yield* Effect.fail({ cause: yield* response.text, response });\n }\n return yield* decodeResponse(output)({ resource: yield* response.json, state: \"complete\" });\n }, Effect.mapError(failure));\n\n /** Sends a GraphQL operation and decodes its root field, failing with the errors it returns. */\n const graphql = Effect.fnUntraced(function* <Output extends Schema.Top>(\n context: Context,\n output: Output,\n request: Request,\n field: string,\n ) {\n const response = yield* send(context, request);\n const body = yield* Schema.decodeUnknownEffect(GraphqlResponse)(yield* response.json);\n if (body.errors !== undefined && Array.isReadonlyArrayNonEmpty(body.errors)) {\n return yield* Action.ActionHandlerError.make({\n details: body.errors,\n message: Array.join(\n Array.map(body.errors, error => error.message),\n \"; \",\n ),\n });\n }\n return yield* decodeResponse(output)(body.data?.[field]);\n }, Effect.mapError(failure));\n\n /**\n * Calls a Model Context Protocol tool in a session with the server. A tool that reports an error\n * fails the action with its text; otherwise the output is its structured content, or its content\n * blocks when it declares no output schema.\n */\n const mcp = Effect.fnUntraced(\n function* <Output extends Schema.Top>(\n context: Context,\n output: Output,\n server: string,\n tool: string,\n args: unknown,\n structured: boolean,\n ) {\n const connection = yield* Mcp.connect(\n authorize(yield* HttpClient.HttpClient, context),\n server,\n {},\n );\n const result = yield* Schema.decodeUnknownEffect(Mcp.CallToolResult)(\n yield* connection.request(\"tools/call\", { arguments: args, name: tool }),\n );\n if (result.isError === true) {\n return yield* Action.ActionHandlerError.make({\n details: result.content,\n message: Array.join(\n Array.flatMap(result.content, block => Array.fromNullishOr(block.text)),\n \"\\n\",\n ),\n });\n }\n return yield* decodeResponse(output)(\n Boolean.match(structured, {\n onFalse: () => ({ content: result.content }),\n onTrue: () => result.structuredContent,\n }),\n );\n },\n Effect.scoped,\n Effect.mapError(error =>\n Schema.is(Mcp.McpError)(error)\n ? Action.ActionHandlerError.make({ message: error.message })\n : failure(error),\n ),\n );\n\n return { endpoint, execute, googleUpload, graphql, mcp, variants };\n}\n\nexport * as Http from \"./Http.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAS,uBAAiC,OAAU,OAAiB;CACnE,IAA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M,OAAO,GAC7C,IACF;GACF,CAAC;GAEH,OAAO,OAAO,eAAe,MAAM,CAAC,CAAC,KAAK,OAAO,MAAM;EACzD,GAAG,OAAO,SAAS,OAAO,CAgDsB;EAAG,KAzCvC,OAAO,WACjB,WACE,SACA,QACA,QACA,MACA,MACA,YACA;GACA,MAAM,aAAa,OAAOC,QACxB,UAAU,OAAO,WAAW,YAAY,OAAO,GAC/C,QACA,CAAC,CACH;GACA,MAAM,SAAS,OAAO,OAAO,oBAAoBC,cAAkB,CAAC,CAClE,OAAO,WAAW,QAAQ,cAAc;IAAE,WAAW;IAAM,MAAM;GAAK,CAAC,CACzE;GACA,IAAI,OAAO,YAAY,MACrB,OAAO,OAAA,mBAAiC,KAAK;IAC3C,SAAS,OAAO;IAChB,SAAS,MAAM,KACb,MAAM,QAAQ,OAAO,UAAS,UAAS,MAAM,cAAc,MAAM,IAAI,CAAC,GACtE,IACF;GACF,CAAC;GAEH,OAAO,OAAO,eAAe,MAAM,CAAC,CAClC,QAAQ,MAAM,YAAY;IACxB,gBAAgB,EAAE,SAAS,OAAO,QAAQ;IAC1C,cAAc,OAAO;GACvB,CAAC,CACH;EACF,GACA,OAAO,QACP,OAAO,UAAS,UACd,OAAO,GAAGC,QAAY,CAAC,CAAC,KAAK,IAAA,mBACC,KAAK,EAAE,SAAS,MAAM,QAAQ,CAAC,IACzD,QAAQ,KAAK,CACnB,CAGmD;EAAG;CAAS;AACnE"}
|
package/dist/Mcp.d.ts
CHANGED
|
@@ -104,6 +104,5 @@ export declare const listTools: (client: HttpClient.HttpClient, endpoint: string
|
|
|
104
104
|
readonly title?: string;
|
|
105
105
|
}[];
|
|
106
106
|
}, import("effect/http/HttpClientError").HttpClientError | McpError | Schema.SchemaError, never>;
|
|
107
|
-
//#endregion
|
|
108
107
|
export { Mcp_d_exports as Mcp, Mcp_d_exports };
|
|
109
108
|
//# sourceMappingURL=Mcp.d.ts.map
|
package/dist/Mcp.js
CHANGED
|
@@ -3,7 +3,7 @@ import "./Mcp.js";
|
|
|
3
3
|
import { Array, Boolean, Effect, MutableRef, Number, Option, Ref, Result, Schema, Stream, String, pipe } from "effect";
|
|
4
4
|
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
5
5
|
import * as Sse from "effect/encoding/Sse";
|
|
6
|
-
|
|
6
|
+
// src/Mcp.ts
|
|
7
7
|
/**
|
|
8
8
|
* A Model Context Protocol client over Streamable HTTP: the session generated plugins call tools
|
|
9
9
|
* through and the CLI lists them with.
|
|
@@ -170,7 +170,6 @@ const listTools = Effect.fn("Mcp.listTools")(function* (client, endpoint, header
|
|
|
170
170
|
tools
|
|
171
171
|
};
|
|
172
172
|
}, Effect.scoped);
|
|
173
|
-
//#endregion
|
|
174
173
|
export { CallToolResult, Implementation, Mcp_exports as Mcp, McpError, Mcp_exports, Tool, connect, listTools };
|
|
175
174
|
|
|
176
175
|
//# sourceMappingURL=Mcp.js.map
|
|
@@ -13,6 +13,5 @@ declare const Service_base: Context.ServiceClass<Service, "@dual-os/sdk/AuthMeth
|
|
|
13
13
|
}>;
|
|
14
14
|
/** @since 0.0.0 @category services */
|
|
15
15
|
export declare class Service extends Service_base {}
|
|
16
|
-
//#endregion
|
|
17
16
|
export { OAuth2TokenRefresher_d_exports as OAuth2TokenRefresher, OAuth2TokenRefresher_d_exports };
|
|
18
17
|
//# sourceMappingURL=OAuth2TokenRefresher.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import "./OAuth2TokenRefresher.js";
|
|
3
3
|
import { Context } from "effect";
|
|
4
|
-
|
|
4
|
+
// src/OAuth2TokenRefresher.ts
|
|
5
5
|
/**
|
|
6
6
|
* Host service that refreshes OAuth2 tokens for SDK auth execution.
|
|
7
7
|
*
|
|
@@ -13,7 +13,6 @@ var OAuth2TokenRefresher_exports = /* @__PURE__ */ __exportAll({
|
|
|
13
13
|
});
|
|
14
14
|
/** @since 0.0.0 @category services */
|
|
15
15
|
var Service = class extends Context.Service()("@dual-os/sdk/AuthMethod/OAuth2TokenRefresher") {};
|
|
16
|
-
//#endregion
|
|
17
16
|
export { OAuth2TokenRefresher_exports as OAuth2TokenRefresher, OAuth2TokenRefresher_exports, Service };
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=OAuth2TokenRefresher.js.map
|
package/dist/OAuthFlow.d.ts
CHANGED
|
@@ -66,6 +66,5 @@ export declare const testing: (options?: {
|
|
|
66
66
|
/** Live protocol layer that reads OAuth client config from Effect ConfigProvider. */
|
|
67
67
|
export declare const layer: Layer.Layer<Service, never, never>;
|
|
68
68
|
export declare const oauth2TokenRefresherLayer: Layer.Layer<Service$1, never, Service>;
|
|
69
|
-
//#endregion
|
|
70
69
|
export { OAuthFlow_d_exports as OAuthFlow, OAuthFlow_d_exports };
|
|
71
70
|
//# sourceMappingURL=OAuthFlow.d.ts.map
|
package/dist/OAuthFlow.js
CHANGED
|
@@ -5,7 +5,7 @@ import "./OAuthFlow.js";
|
|
|
5
5
|
import { Array, Clock, ConfigProvider, Context, Effect, HashSet, Layer, Predicate, Random, Record, Redacted, Schema, String, pipe } from "effect";
|
|
6
6
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
|
|
7
7
|
import { Base64, Base64Url } from "effect/encoding";
|
|
8
|
-
|
|
8
|
+
// src/OAuthFlow.ts
|
|
9
9
|
/**
|
|
10
10
|
* OAuth protocol runner used by ConnectionStore.
|
|
11
11
|
*
|
|
@@ -482,7 +482,6 @@ const oauth2TokenRefresherLayer = Layer.effect(Service$1, Effect.gen(function* (
|
|
|
482
482
|
setup: input.setup
|
|
483
483
|
}).pipe(Effect.map((refreshed) => refreshed.tokens)) });
|
|
484
484
|
}));
|
|
485
|
-
//#endregion
|
|
486
485
|
export { OAuthConnectionValidationFailed, OAuthFlow_exports as OAuthFlow, OAuthFlow_exports, OAuthGrantRejected, OAuthProviderRejected, Service, layer, oauth2TokenRefresherLayer, testing };
|
|
487
486
|
|
|
488
487
|
//# sourceMappingURL=OAuthFlow.js.map
|
package/dist/Plugin.d.ts
CHANGED
|
@@ -378,6 +378,5 @@ export type Handlers<P extends Any> = HandlerCollection<P, P["authMethods"]>;
|
|
|
378
378
|
* @category handlers
|
|
379
379
|
*/
|
|
380
380
|
export declare const toLayer: <P extends Any, Return>(plugin: P, build: (handlers: Handlers<P>) => ValidateReturn<Return, P>) => Layer.Layer<HandlerServices<P>, BuildError<Return>, Exclude<Requirements<Return>, Scope.Scope>>;
|
|
381
|
-
//#endregion
|
|
382
381
|
export { type ActionHandlerService, type ActionHandlerServiceOf, Plugin_d_exports };
|
|
383
382
|
//# sourceMappingURL=Plugin.d.ts.map
|
package/dist/Plugin.js
CHANGED
|
@@ -8,7 +8,7 @@ import { assertUniqueMixedChildIdentifiers, assertUniqueStructuralChildIdentifie
|
|
|
8
8
|
import { toHandlers } from "./internal/plugin-handlers.js";
|
|
9
9
|
import { Array, Effect, Function, Layer, Option, Predicate, Result, String } from "effect";
|
|
10
10
|
import { Url, UrlParams } from "effect/http";
|
|
11
|
-
|
|
11
|
+
// src/Plugin.ts
|
|
12
12
|
var Plugin_exports = /* @__PURE__ */ __exportAll({
|
|
13
13
|
TypeId: () => TypeId,
|
|
14
14
|
add: () => add,
|
|
@@ -243,7 +243,6 @@ const toLayer = (plugin, build) => Layer.effectContext(Effect.gen(function* () {
|
|
|
243
243
|
const handlers = Effect.isEffect(result) ? yield* result : result;
|
|
244
244
|
return yield* toHandlers(plugin, handlers);
|
|
245
245
|
}));
|
|
246
|
-
//#endregion
|
|
247
246
|
export { Plugin_exports, TypeId, add, categories, isGitRequest, isPlugin, make, provide, toLayer, withAction, withAgentChannel, withAuthMethod, withAuthMethods, withCategories, withDescription, withDocsUrl, withGroup, withGroups, withHomepageUrl, withIconUrl, withIconUrlDark, withName, withSandboxAccess, withTrigger, withTriggers };
|
|
248
247
|
|
|
249
248
|
//# sourceMappingURL=Plugin.js.map
|
package/dist/PluginRuntime.d.ts
CHANGED
|
@@ -3181,6 +3181,5 @@ export declare const execute: (request: {
|
|
|
3181
3181
|
};
|
|
3182
3182
|
readonly value: Schema.Json;
|
|
3183
3183
|
}, never, Service | Service$1>;
|
|
3184
|
-
//#endregion
|
|
3185
3184
|
export { PluginRuntime_d_exports as PluginRuntime, PluginRuntime_d_exports };
|
|
3186
3185
|
//# sourceMappingURL=PluginRuntime.d.ts.map
|
package/dist/PluginRuntime.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Identity, Request as Request$1, Response, execute as execute$1, failure
|
|
|
6
6
|
import "./PluginRuntime.js";
|
|
7
7
|
import { Cause, Effect, Queue, Redacted, Schema, Stream, pipe } from "effect";
|
|
8
8
|
import { HttpClientRequest } from "effect/http";
|
|
9
|
-
|
|
9
|
+
// src/PluginRuntime.ts
|
|
10
10
|
var PluginRuntime_exports = /* @__PURE__ */ __exportAll({
|
|
11
11
|
AuthRequest: () => AuthRequest,
|
|
12
12
|
ChannelSettingsRequest: () => ChannelSettingsRequest,
|
|
@@ -325,7 +325,6 @@ const execute = Effect.fnUntraced(function* (request) {
|
|
|
325
325
|
if (request._tag === "auth") return yield* executeAuth(request);
|
|
326
326
|
return yield* executeChannelSettings(request);
|
|
327
327
|
});
|
|
328
|
-
//#endregion
|
|
329
328
|
export { AuthRequest, ChannelSettingsRequest, ExecutionRequest, Input, Invocation, OAuthContinuation, OAuthStarted, Output, PluginExecutionError, PluginRuntime_exports as PluginRuntime, PluginRuntime_exports, Request, SandboxAccessResult, cancellationTimeout, checkMessageSize, decodeInput, decodeOutput, encodeInput, encodeOutput, encodeRequest, execute, ipcMessages, maxChannelResultBytes, maxMetadataBytes, maxPayloadBytes, readBounded, responseLimit, sendIpc, verifyResponse };
|
|
330
329
|
|
|
331
330
|
//# sourceMappingURL=PluginRuntime.js.map
|
package/dist/Runner.js
CHANGED
|
@@ -6,8 +6,8 @@ import { Identity, filesUnavailable } from "./remote-runtime.js";
|
|
|
6
6
|
import { PluginExecutionError, decodeInput, encodeOutput, execute, ipcMessages, responseLimit, sendIpc } from "./PluginRuntime.js";
|
|
7
7
|
import { Array, Cause, ConfigProvider, Context, Deferred, Effect, Exit, Fiber, FiberMap, Formatter, Inspectable, Layer, Match, Option, Predicate, Redacted, Schema, Scope, Stdio, Stream, String, pipe } from "effect";
|
|
8
8
|
import { FetchHttpClient } from "effect/http";
|
|
9
|
-
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
10
|
-
|
|
9
|
+
import { NodeCrypto, NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
10
|
+
// src/Runner.ts
|
|
11
11
|
const guestOAuth = pipe(oauth2TokenRefresherLayer, Layer.provideMerge(layer), Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))));
|
|
12
12
|
function initializationError(cause) {
|
|
13
13
|
if (Schema.is(PluginExecutionError)(cause)) return cause;
|
|
@@ -117,8 +117,7 @@ pipe(Effect.gen(function* () {
|
|
|
117
117
|
return yield* initializationError(Cause.squash(exit.cause));
|
|
118
118
|
}), Effect.catchCause((cause) => Deferred.fail(failed, initializationError(Cause.squash(cause)))), Effect.forkIn(scope));
|
|
119
119
|
})), Effect.mapError(initializationError)), Deferred.await(failed));
|
|
120
|
-
}), Effect.scoped, Effect.provide(NodeServices.layer), NodeRuntime.runMain({ disableErrorReporting: process.argv[4] !== "inspect" }));
|
|
121
|
-
//#endregion
|
|
120
|
+
}), Effect.scoped, Effect.provide([NodeServices.layer, NodeCrypto.layer]), NodeRuntime.runMain({ disableErrorReporting: process.argv[4] !== "inspect" }));
|
|
122
121
|
export {};
|
|
123
122
|
|
|
124
123
|
//# sourceMappingURL=Runner.js.map
|
package/dist/Runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Runner.js","names":["OAuthFlow.layer","PluginRuntime.PluginExecutionError","Plugin.isPlugin","Plugin.make","DualRuntime.toLayer","DualRuntime.fromPlugin","RemoteRuntime.filesUnavailable","execute","DualRegistry.materializePlugin","PluginRuntime.execute","PluginRuntime.ipcMessages","PluginRuntime.decodeInput","RemoteRuntime.Identity","PluginRuntime.encodeOutput","PluginRuntime.responseLimit","PluginRuntime.sendIpc"],"sources":["../src/Runner.ts"],"sourcesContent":["import { NodeRuntime, NodeServices } from \"@effect/platform-node\";\n\nimport {\n Array,\n Cause,\n ConfigProvider,\n Context,\n Deferred,\n Effect,\n Exit,\n Fiber,\n FiberMap,\n Formatter,\n Inspectable,\n Layer,\n Match,\n Option,\n Predicate,\n Redacted,\n Schema,\n Scope,\n Stdio,\n Stream,\n String,\n pipe,\n} from \"effect\";\n\nimport { FetchHttpClient } from \"effect/http\";\n\nimport * as DualRegistry from \"./DualRegistry.ts\";\nimport * as DualRuntime from \"./DualRuntime.ts\";\nimport { OAuthFlow, oauth2TokenRefresherLayer } from \"./OAuthFlow.ts\";\nimport * as Plugin from \"./Plugin.ts\";\nimport { PluginRuntime } from \"./PluginRuntime.ts\";\nimport { RemoteRuntime } from \"./remote-runtime.ts\";\n\nconst guestOAuth = pipe(\n oauth2TokenRefresherLayer,\n Layer.provideMerge(OAuthFlow.layer),\n Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))),\n);\n\nfunction initializationError(cause: unknown) {\n // Each hop of the runner maps its failure here; the first error keeps its message.\n if (Schema.is(PluginRuntime.PluginExecutionError)(cause)) return cause;\n return PluginRuntime.PluginExecutionError.make({\n category: \"runner\",\n cause: Redacted.make(cause),\n message:\n pipe(\n Match.value(cause),\n Match.when(Predicate.isString, String.trim),\n Match.orElse(value =>\n Formatter.format(Inspectable.toJson(value), { ignoreToString: true, space: 2 }),\n ),\n ) || \"No error details returned by the plugin.\",\n });\n}\n\n// This executable runs only in the plugin's process, using its own SDK and Effect.\npipe(\n Effect.gen(function* () {\n const guestServices = yield* Effect.context<NodeServices.NodeServices>();\n const scope = yield* Scope.Scope;\n const runtimeScope = yield* Scope.fork(scope, \"sequential\");\n const failed = yield* Deferred.make<never, PluginRuntime.PluginExecutionError>();\n const invocations = yield* FiberMap.make<\n string,\n RemoteRuntime.Response,\n PluginRuntime.PluginExecutionError\n >();\n const stdio = yield* Stdio.Stdio;\n const args = yield* Schema.decodeUnknownEffect(\n Schema.Tuple([\n Schema.NonEmptyString,\n Schema.NonEmptyString,\n Schema.Literals([\"inspect\", \"execute\"]),\n Schema.NonEmptyString,\n ]),\n )(yield* stdio.args);\n const load = yield* Effect.cached(\n Effect.forkIn(\n Effect.gen(function* () {\n const exports = yield* Schema.decodeUnknownEffect(\n Schema.Record(Schema.String, Schema.Unknown),\n )(yield* Effect.tryPromise({ try: () => import(args[0]), catch: initializationError }));\n const plugin = exports[args[1]];\n if (!Plugin.isPlugin(plugin)) {\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"The configured export is not an integration plugin\",\n });\n }\n yield* Effect.try({\n try: () => Plugin.make(plugin.identifier),\n catch: initializationError,\n });\n const runtime = yield* Effect.cached(\n Effect.forkIn(\n pipe(\n Layer.buildWithScope(\n pipe(\n // @effect-diagnostics-next-line anyUnknownInErrorContext:off -- Imported plugin requirements are erased; the guest supplies only its own services.\n DualRuntime.toLayer(DualRuntime.fromPlugin(plugin, args[3])),\n Layer.provideMerge(\n Layer.mergeAll(\n RemoteRuntime.filesUnavailable,\n FetchHttpClient.layer,\n guestOAuth,\n ),\n ),\n ),\n runtimeScope,\n ),\n Effect.provideContext(Context.makeUnsafe<unknown>(guestServices.mapUnsafe)),\n ),\n runtimeScope,\n ),\n );\n return { plugin, runtime };\n }),\n runtimeScope,\n ),\n );\n const execute = Effect.fnUntraced(function* (request: PluginRuntime.Request) {\n return yield* pipe(\n Effect.gen(function* () {\n const { plugin, runtime } = yield* Fiber.join(yield* load);\n if (\n request.identity.pluginKey !== plugin.identifier &&\n !(args[2] === \"inspect\" && \"_tag\" in request && request._tag === \"extract\")\n ) {\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin identity does not match the request\",\n });\n }\n if (request.identity.pluginVersion !== args[3])\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin release does not match the request\",\n });\n if (\"_tag\" in request && request._tag === \"extract\") {\n return {\n _tag: \"success\",\n identity: request.identity,\n value: yield* Schema.decodeEffect(Schema.fromJsonString(Schema.Json))(\n yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown))(\n DualRegistry.materializePlugin(plugin, {\n version: request.identity.pluginVersion,\n }),\n ),\n ),\n } satisfies RemoteRuntime.Response;\n }\n return yield* pipe(\n PluginRuntime.execute(request),\n Effect.provideContext(yield* Fiber.join(yield* runtime)),\n );\n }),\n Effect.catchCauseIf(\n cause => !Cause.hasInterrupts(cause),\n cause =>\n args[2] === \"inspect\"\n ? Effect.fail(initializationError(Cause.squash(cause)))\n : Effect.succeed({\n _tag: \"failure\",\n identity: request.identity,\n error: {\n category: \"initialization\",\n code: \"PluginInitializationFailed\",\n message: \"Cannot initialize the installed plugin\",\n retryable: false,\n },\n } satisfies RemoteRuntime.Response),\n ),\n Effect.mapError(initializationError),\n );\n });\n yield* Effect.raceFirst(\n pipe(\n PluginRuntime.ipcMessages(process),\n Stream.runForEach(\n Effect.fnUntraced(function* (message) {\n const input = yield* PluginRuntime.decodeInput(message);\n const key = yield* Schema.encodeEffect(Schema.fromJsonString(RemoteRuntime.Identity))(\n input.identity,\n );\n if (\"_tag\" in input && input._tag === \"cancel\") {\n const fiber = Option.getOrUndefined(yield* FiberMap.get(invocations, key));\n if (fiber !== undefined) yield* pipe(Fiber.interrupt(fiber), Effect.forkIn(scope));\n return;\n }\n if (\n (yield* FiberMap.has(invocations, key)) ||\n (yield* FiberMap.size(invocations)) >= 16\n ) {\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin invocation is duplicate or exceeds concurrency\",\n });\n }\n const fiber = yield* FiberMap.run(invocations, key, Effect.scoped(execute(input)));\n yield* pipe(\n Effect.gen(function* () {\n const exit = yield* Fiber.await(fiber);\n const send = Effect.fnUntraced(function* (output: PluginRuntime.Output) {\n const encoded = yield* PluginRuntime.encodeOutput(\n output,\n PluginRuntime.responseLimit(input),\n );\n if (args[2] !== \"inspect\") return yield* PluginRuntime.sendIpc(process, encoded);\n // Bun can discard queued data on disconnect; wait for its native send callback.\n yield* Effect.callback<void, PluginRuntime.PluginExecutionError>(resume => {\n if (process.send === undefined) {\n resume(Effect.fail(initializationError(\"Plugin IPC channel is closed\")));\n return;\n }\n process.send(encoded, error => {\n if (error !== null) resume(Effect.fail(initializationError(error)));\n else resume(Effect.void);\n });\n });\n if (process.connected) process.disconnect();\n });\n if (Exit.isSuccess(exit)) return yield* send(exit.value);\n if (Array.every(exit.cause.reasons, Cause.isInterruptReason)) {\n return yield* send({ _tag: \"interrupted\", identity: input.identity });\n }\n return yield* initializationError(Cause.squash(exit.cause));\n }),\n Effect.catchCause(cause =>\n Deferred.fail(failed, initializationError(Cause.squash(cause))),\n ),\n Effect.forkIn(scope),\n );\n }),\n ),\n Effect.mapError(initializationError),\n ),\n Deferred.await(failed),\n );\n }),\n Effect.scoped,\n // @effect-diagnostics-next-line strictEffectProvide:off -- This executable owns the guest process services.\n Effect.provide(NodeServices.layer),\n NodeRuntime.runMain({ disableErrorReporting: process.argv[4] !== \"inspect\" }),\n);\n"],"mappings":";;;;;;;;;;AAoCA,MAAM,aAAa,KACjB,2BACA,MAAM,aAAaA,KAAe,GAClC,MAAM,QAAQ,eAAe,MAAM,eAAe,YAAY,CAAC,CAAC,CAAC,CAAC,CACpE;AAEA,SAAS,oBAAoB,OAAgB;CAE3C,IAAI,OAAO,GAAGC,oBAAkC,CAAC,CAAC,KAAK,GAAG,OAAO;CACjE,OAAA,qBAA0C,KAAK;EAC7C,UAAU;EACV,OAAO,SAAS,KAAK,KAAK;EAC1B,SACE,KACE,MAAM,MAAM,KAAK,GACjB,MAAM,KAAK,UAAU,UAAU,OAAO,IAAI,GAC1C,MAAM,QAAO,UACX,UAAU,OAAO,YAAY,OAAO,KAAK,GAAG;GAAE,gB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AE,MAAM;IAAe,UAAU,MAAM;GAAS,CAAC;GAEtE,OAAO,OAAO,oBAAoB,MAAM,OAAO,KAAK,KAAK,CAAC;EAC5D,CAAC,GACD,OAAO,YAAW,UAChB,SAAS,KAAK,QAAQ,oBAAoB,MAAM,OAAO,KAAK,CAAC,CAAC,CAChE,GACA,OAAO,OAAO,KAAK,CACrB;CACF,CAAC,CACH,GACA,OAAO,SAAS,mBAAmB,CACrC,GACA,SAAS,MAAM,MAAM,CACvB;AACF,CAAC,GACD,OAAO,QAEP,OAAO,QAAQ,aAAa,KAAK,GACjC,YAAY,QAAQ,EAAE,uBAAuB,QAAQ,KAAK,OAAO,UAAU,CAAC,CAC9E"}
|
|
1
|
+
{"version":3,"file":"Runner.js","names":["OAuthFlow.layer","PluginRuntime.PluginExecutionError","Plugin.isPlugin","Plugin.make","DualRuntime.toLayer","DualRuntime.fromPlugin","RemoteRuntime.filesUnavailable","execute","DualRegistry.materializePlugin","PluginRuntime.execute","PluginRuntime.ipcMessages","PluginRuntime.decodeInput","RemoteRuntime.Identity","PluginRuntime.encodeOutput","PluginRuntime.responseLimit","PluginRuntime.sendIpc"],"sources":["../src/Runner.ts"],"sourcesContent":["import { NodeCrypto, NodeRuntime, NodeServices } from \"@effect/platform-node\";\n\nimport {\n Array,\n Cause,\n ConfigProvider,\n Context,\n Deferred,\n Effect,\n Exit,\n Fiber,\n FiberMap,\n Formatter,\n Inspectable,\n Layer,\n Match,\n Option,\n Predicate,\n Redacted,\n Schema,\n Scope,\n Stdio,\n Stream,\n String,\n pipe,\n} from \"effect\";\n\nimport { FetchHttpClient } from \"effect/http\";\n\nimport * as DualRegistry from \"./DualRegistry.ts\";\nimport * as DualRuntime from \"./DualRuntime.ts\";\nimport { OAuthFlow, oauth2TokenRefresherLayer } from \"./OAuthFlow.ts\";\nimport * as Plugin from \"./Plugin.ts\";\nimport { PluginRuntime } from \"./PluginRuntime.ts\";\nimport { RemoteRuntime } from \"./remote-runtime.ts\";\n\nconst guestOAuth = pipe(\n oauth2TokenRefresherLayer,\n Layer.provideMerge(OAuthFlow.layer),\n Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))),\n);\n\nfunction initializationError(cause: unknown) {\n // Each hop of the runner maps its failure here; the first error keeps its message.\n if (Schema.is(PluginRuntime.PluginExecutionError)(cause)) return cause;\n return PluginRuntime.PluginExecutionError.make({\n category: \"runner\",\n cause: Redacted.make(cause),\n message:\n pipe(\n Match.value(cause),\n Match.when(Predicate.isString, String.trim),\n Match.orElse(value =>\n Formatter.format(Inspectable.toJson(value), { ignoreToString: true, space: 2 }),\n ),\n ) || \"No error details returned by the plugin.\",\n });\n}\n\n// This executable runs only in the plugin's process, using its own SDK and Effect.\npipe(\n Effect.gen(function* () {\n const guestServices = yield* Effect.context<\n NodeServices.NodeServices | Layer.Success<typeof NodeCrypto.layer>\n >();\n const scope = yield* Scope.Scope;\n const runtimeScope = yield* Scope.fork(scope, \"sequential\");\n const failed = yield* Deferred.make<never, PluginRuntime.PluginExecutionError>();\n const invocations = yield* FiberMap.make<\n string,\n RemoteRuntime.Response,\n PluginRuntime.PluginExecutionError\n >();\n const stdio = yield* Stdio.Stdio;\n const args = yield* Schema.decodeUnknownEffect(\n Schema.Tuple([\n Schema.NonEmptyString,\n Schema.NonEmptyString,\n Schema.Literals([\"inspect\", \"execute\"]),\n Schema.NonEmptyString,\n ]),\n )(yield* stdio.args);\n const load = yield* Effect.cached(\n Effect.forkIn(\n Effect.gen(function* () {\n const exports = yield* Schema.decodeUnknownEffect(\n Schema.Record(Schema.String, Schema.Unknown),\n )(yield* Effect.tryPromise({ try: () => import(args[0]), catch: initializationError }));\n const plugin = exports[args[1]];\n if (!Plugin.isPlugin(plugin)) {\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"The configured export is not an integration plugin\",\n });\n }\n yield* Effect.try({\n try: () => Plugin.make(plugin.identifier),\n catch: initializationError,\n });\n const runtime = yield* Effect.cached(\n Effect.forkIn(\n pipe(\n Layer.buildWithScope(\n pipe(\n // @effect-diagnostics-next-line anyUnknownInErrorContext:off -- Imported plugin requirements are erased; the guest supplies only its own services.\n DualRuntime.toLayer(DualRuntime.fromPlugin(plugin, args[3])),\n Layer.provideMerge(\n Layer.mergeAll(\n RemoteRuntime.filesUnavailable,\n FetchHttpClient.layer,\n guestOAuth,\n ),\n ),\n ),\n runtimeScope,\n ),\n Effect.provideContext(Context.makeUnsafe<unknown>(guestServices.mapUnsafe)),\n ),\n runtimeScope,\n ),\n );\n return { plugin, runtime };\n }),\n runtimeScope,\n ),\n );\n const execute = Effect.fnUntraced(function* (request: PluginRuntime.Request) {\n return yield* pipe(\n Effect.gen(function* () {\n const { plugin, runtime } = yield* Fiber.join(yield* load);\n if (\n request.identity.pluginKey !== plugin.identifier &&\n !(args[2] === \"inspect\" && \"_tag\" in request && request._tag === \"extract\")\n ) {\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin identity does not match the request\",\n });\n }\n if (request.identity.pluginVersion !== args[3])\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin release does not match the request\",\n });\n if (\"_tag\" in request && request._tag === \"extract\") {\n return {\n _tag: \"success\",\n identity: request.identity,\n value: yield* Schema.decodeEffect(Schema.fromJsonString(Schema.Json))(\n yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown))(\n DualRegistry.materializePlugin(plugin, {\n version: request.identity.pluginVersion,\n }),\n ),\n ),\n } satisfies RemoteRuntime.Response;\n }\n return yield* pipe(\n PluginRuntime.execute(request),\n Effect.provideContext(yield* Fiber.join(yield* runtime)),\n );\n }),\n Effect.catchCauseIf(\n cause => !Cause.hasInterrupts(cause),\n cause =>\n args[2] === \"inspect\"\n ? Effect.fail(initializationError(Cause.squash(cause)))\n : Effect.succeed({\n _tag: \"failure\",\n identity: request.identity,\n error: {\n category: \"initialization\",\n code: \"PluginInitializationFailed\",\n message: \"Cannot initialize the installed plugin\",\n retryable: false,\n },\n } satisfies RemoteRuntime.Response),\n ),\n Effect.mapError(initializationError),\n );\n });\n yield* Effect.raceFirst(\n pipe(\n PluginRuntime.ipcMessages(process),\n Stream.runForEach(\n Effect.fnUntraced(function* (message) {\n const input = yield* PluginRuntime.decodeInput(message);\n const key = yield* Schema.encodeEffect(Schema.fromJsonString(RemoteRuntime.Identity))(\n input.identity,\n );\n if (\"_tag\" in input && input._tag === \"cancel\") {\n const fiber = Option.getOrUndefined(yield* FiberMap.get(invocations, key));\n if (fiber !== undefined) yield* pipe(Fiber.interrupt(fiber), Effect.forkIn(scope));\n return;\n }\n if (\n (yield* FiberMap.has(invocations, key)) ||\n (yield* FiberMap.size(invocations)) >= 16\n ) {\n return yield* PluginRuntime.PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin invocation is duplicate or exceeds concurrency\",\n });\n }\n const fiber = yield* FiberMap.run(invocations, key, Effect.scoped(execute(input)));\n yield* pipe(\n Effect.gen(function* () {\n const exit = yield* Fiber.await(fiber);\n const send = Effect.fnUntraced(function* (output: PluginRuntime.Output) {\n const encoded = yield* PluginRuntime.encodeOutput(\n output,\n PluginRuntime.responseLimit(input),\n );\n if (args[2] !== \"inspect\") return yield* PluginRuntime.sendIpc(process, encoded);\n // Bun can discard queued data on disconnect; wait for its native send callback.\n yield* Effect.callback<void, PluginRuntime.PluginExecutionError>(resume => {\n if (process.send === undefined) {\n resume(Effect.fail(initializationError(\"Plugin IPC channel is closed\")));\n return;\n }\n process.send(encoded, error => {\n if (error !== null) resume(Effect.fail(initializationError(error)));\n else resume(Effect.void);\n });\n });\n if (process.connected) process.disconnect();\n });\n if (Exit.isSuccess(exit)) return yield* send(exit.value);\n if (Array.every(exit.cause.reasons, Cause.isInterruptReason)) {\n return yield* send({ _tag: \"interrupted\", identity: input.identity });\n }\n return yield* initializationError(Cause.squash(exit.cause));\n }),\n Effect.catchCause(cause =>\n Deferred.fail(failed, initializationError(Cause.squash(cause))),\n ),\n Effect.forkIn(scope),\n );\n }),\n ),\n Effect.mapError(initializationError),\n ),\n Deferred.await(failed),\n );\n }),\n Effect.scoped,\n Effect.provide([NodeServices.layer, NodeCrypto.layer]),\n NodeRuntime.runMain({ disableErrorReporting: process.argv[4] !== \"inspect\" }),\n);\n"],"mappings":";;;;;;;;;;AAoCA,MAAM,aAAa,KACjB,2BACA,MAAM,aAAaA,KAAe,GAClC,MAAM,QAAQ,eAAe,MAAM,eAAe,YAAY,CAAC,CAAC,CAAC,CAAC,CACpE;AAEA,SAAS,oBAAoB,OAAgB;CAE3C,IAAI,OAAO,GAAGC,oBAAkC,CAAC,CAAC,KAAK,GAAG,OAAO;CACjE,OAAA,qBAA0C,KAAK;EAC7C,UAAU;EACV,OAAO,SAAS,KAAK,KAAK;EAC1B,SACE,KACE,MAAM,MAAM,KAAK,GACjB,MAAM,KAAK,UAAU,UAAU,OAAO,IAAI,GAC1C,MAAM,QAAO,UACX,UAAU,OAAO,YAAY,OAAO,KAAK,GAAG;GAAE,gBAAgB;GAAM,OAAO;EAAE,CAAC,CAChF,CACF,KAAK;CACT,CAAC;AACH;AAGA,KACE,OAAO,IAAI,aAAa;CACtB,MAAM,gBAAgB,OAAO,OAAO,QAElC;CACF,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,eAAe,OAAO,MAAM,KAAK,OAAO,YAAY;CAC1D,MAAM,SAAS,OAAO,SAAS,KAAgD;CAC/E,MAAM,cAAc,OAAO,SAAS,KAIlC;CACF,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,OAAO,OAAO,OAAO,oBACzB,OAAO,MAAM;EACX,OAAO;EACP,OAAO;EACP,OAAO,SAAS,CAAC,WAAW,SAAS,CAAC;EACtC,OAAO;CACT,CAAC,CACH,CAAC,CAAC,OAAO,MAAM,IAAI;CACnB,MAAM,OAAO,OAAO,OAAO,OACzB,OAAO,OACL,OAAO,IAAI,aAAa;EAItB,MAAM,UAAS,OAHQ,OAAO,oBAC5B,OAAO,OAAO,OAAO,QAAQ,OAAO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,QAA8B;IACtE,MAAM,UAAU,OAAOM,aACrB,QACAC,cAA4B,KAAK,CACnC;IACA,IAAI,KAAK,OAAO,WAAW,OAAO,OAAOC,QAAsB,SAAS,OAAO;IAE/E,OAAO,OAAO,UAAmD,WAAU;KACzE,IAAI,QAAQ,SAAS,KAAA,GAAW;MAC9B,OAAO,OAAO,KAAK,oBAAoB,8BAA8B,CAAC,CAAC;MACvE;KACF;KACA,QAAQ,KAAK,UAAS,UAAS;MAC7B,IAAI,UAAU,MAAM,OAAO,OAAO,KAAK,oBAAoB,KAAK,CAAC,CAAC;WAC7D,OAAO,OAAO,IAAI;KACzB,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,WAAW,QAAQ,WAAW;GAC5C,CAAC;GACD,IAAI,KAAK,UAAU,IAAI,GAAG,OAAO,OAAO,KAAK,KAAK,KAAK;GACvD,IAAI,MAAM,MAAM,KAAK,MAAM,SAAS,MAAM,iBAAiB,GACzD,OAAO,OAAO,KAAK;IAAE,MAAM;IAAe,UAAU,MAAM;GAAS,CAAC;GAEtE,OAAO,OAAO,oBAAoB,MAAM,OAAO,KAAK,KAAK,CAAC;EAC5D,CAAC,GACD,OAAO,YAAW,UAChB,SAAS,KAAK,QAAQ,oBAAoB,MAAM,OAAO,KAAK,CAAC,CAAC,CAChE,GACA,OAAO,OAAO,KAAK,CACrB;CACF,CAAC,CACH,GACA,OAAO,SAAS,mBAAmB,CACrC,GACA,SAAS,MAAM,MAAM,CACvB;AACF,CAAC,GACD,OAAO,QACP,OAAO,QAAQ,CAAC,aAAa,OAAO,WAAW,KAAK,CAAC,GACrD,YAAY,QAAQ,EAAE,uBAAuB,QAAQ,KAAK,OAAO,UAAU,CAAC,CAC9E"}
|
package/dist/ToolFile.d.ts
CHANGED
|
@@ -18,6 +18,5 @@ export declare const Schema: Schema$1.TaggedStruct<"ToolFile", {
|
|
|
18
18
|
}>;
|
|
19
19
|
/** @since 0.0.0 @category models */
|
|
20
20
|
export type File = typeof Schema.Type;
|
|
21
|
-
//#endregion
|
|
22
21
|
export { ToolFile_d_exports as ToolFile, ToolFile_d_exports };
|
|
23
22
|
//# sourceMappingURL=ToolFile.d.ts.map
|
package/dist/ToolFile.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
2
|
import "./ToolFile.js";
|
|
3
3
|
import { Schema as Schema$1 } from "effect";
|
|
4
|
-
|
|
4
|
+
// src/ToolFile.ts
|
|
5
5
|
/**
|
|
6
6
|
* JSON-safe file results that hosts can persist without reconstructing displayed text.
|
|
7
7
|
*
|
|
@@ -27,7 +27,6 @@ const Schema = Schema$1.TaggedStruct("ToolFile", {
|
|
|
27
27
|
filename: Schema$1.NullOr(Schema$1.String),
|
|
28
28
|
sizeBytes: Schema$1.Natural
|
|
29
29
|
});
|
|
30
|
-
//#endregion
|
|
31
30
|
export { Schema, ToolFile_exports as ToolFile, ToolFile_exports };
|
|
32
31
|
|
|
33
32
|
//# sourceMappingURL=ToolFile.js.map
|
package/dist/Trigger.d.ts
CHANGED
|
@@ -353,6 +353,5 @@ export declare const verify: <Entry extends RuntimeTriggerEntry<any, any, any, a
|
|
|
353
353
|
export declare const parse: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: WebhookExecutionRequest) => Effect.Effect<EmittedEventsSuccess<TriggerIdOf<Entry>, "parse", TriggerEncodedOutput<EntryTrigger<Entry>>, TriggerEncodedState<EntryTrigger<Entry>>>, InvalidTriggerConfigError | InvalidTriggerStateError | InvalidTriggerOutputError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "parse">>;
|
|
354
354
|
/** @since 0.0.0 @category execution */
|
|
355
355
|
export declare const poll: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: PollExecutionRequest) => Effect.Effect<EmittedEventsSuccess<TriggerIdOf<Entry>, "poll", TriggerEncodedOutput<EntryTrigger<Entry>>, TriggerEncodedState<EntryTrigger<Entry>>>, InvalidTriggerConfigError | InvalidTriggerStateError | InvalidTriggerOutputError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "poll">>;
|
|
356
|
-
//#endregion
|
|
357
356
|
export { Trigger_d_exports };
|
|
358
357
|
//# sourceMappingURL=Trigger.d.ts.map
|
package/dist/Trigger.js
CHANGED
|
@@ -4,7 +4,7 @@ import { PipeableProto } from "./internal/proto.js";
|
|
|
4
4
|
import { activate as activate$1, deactivate as deactivate$1, parse as parse$1, poll as poll$1, verify as verify$1 } from "./internal/trigger-runtime.js";
|
|
5
5
|
import { Array, Clock, Duration, Effect, Match, Number, Option, Predicate, Record, Result, Schema, String, pipe } from "effect";
|
|
6
6
|
import { Base64, Hex } from "effect/encoding";
|
|
7
|
-
|
|
7
|
+
// src/Trigger.ts
|
|
8
8
|
var Trigger_exports = /* @__PURE__ */ __exportAll({
|
|
9
9
|
InvalidTriggerConfigError: () => InvalidTriggerConfigError,
|
|
10
10
|
InvalidTriggerOutputError: () => InvalidTriggerOutputError,
|
|
@@ -281,7 +281,6 @@ const verify = verify$1;
|
|
|
281
281
|
const parse = parse$1;
|
|
282
282
|
/** @since 0.0.0 @category execution */
|
|
283
283
|
const poll = poll$1;
|
|
284
|
-
//#endregion
|
|
285
284
|
export { InvalidTriggerConfigError, InvalidTriggerOutputError, InvalidTriggerStateError, Trigger_exports, TypeId, UnsupportedTriggerRuntimeError, activate, bodyDigest, deactivate, handlerKey, isTrigger, parse, poll, polling, verify, verifyEcdsaP256, verifyHmac, verifyHmacSha256, verifyStandardWebhook, verifyToken, webhook };
|
|
286
285
|
|
|
287
286
|
//# sourceMappingURL=Trigger.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
@@ -9,5 +9,4 @@ var __exportAll = (all, no_symbols) => {
|
|
|
9
9
|
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
10
|
return target;
|
|
11
11
|
};
|
|
12
|
-
//#endregion
|
|
13
12
|
export { __exportAll };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Context } from "../AuthMethodBinding.js";
|
|
2
2
|
import { Any } from "../AuthMethod.js";
|
|
3
|
-
//#region src/internal/auth-context.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Runtime handler context for a known effective provider auth-method set.
|
|
6
5
|
*
|
|
@@ -19,5 +18,4 @@ export type ContextForMethods<Methods extends readonly Any[]> = Methods extends
|
|
|
19
18
|
export type ContextForContract<Methods extends readonly Any[], RequireAuth> = [RequireAuth] extends [true] ? ContextForMethods<Methods> : Methods extends readonly [] ? {} : {
|
|
20
19
|
readonly auth?: Context<Methods>;
|
|
21
20
|
};
|
|
22
|
-
//#endregion
|
|
23
21
|
//# sourceMappingURL=auth-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-context.d.ts","names":["AuthMethod.Any","AuthMethodBinding.Context"],"sources":["../../src/internal/auth-context.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-context.d.ts","names":["AuthMethod.Any","AuthMethodBinding.Context"],"sources":["../../src/internal/auth-context.ts"],"mappings":";;;;;;;;YASY,kBAAkB,yBAAyBA,SACrD,kDAEmB;WACF,OAAOC,QAA0B;;WACjC,MAAMA,QAA0B;;;;;;YAMvC,mBAAmB,yBAAyBD,OAAkB,gBACxE,8BAEE,kBAAkB,WAClB;WAEa,OAAOC,QAA0B"}
|