@dual-os/sdk 0.8.0-next.2 → 0.8.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.
@@ -1 +1 @@
1
- {"version":3,"file":"PluginRuntime.js","names":["RemoteRuntime.Identity","AuthMethodExecution.JsonRequest","RemoteRuntime.Request","RemoteRuntime.Response","DualRuntime.Service","OAuthFlow.Service","RemoteRuntime.failure","RemoteRuntime.execute"],"sources":["../src/PluginRuntime.ts"],"sourcesContent":["import { Cause, Effect, Queue, Redacted, Schema, Stream, pipe } from \"effect\";\n\nimport { HttpClientRequest } from \"effect/http\";\n\nimport * as AuthMethodExecution from \"./AuthMethodExecution.ts\";\nimport * as DualRuntime from \"./DualRuntime.ts\";\nimport { OAuthFlow, OAuthGrantRejected } from \"./OAuthFlow.ts\";\nimport { RemoteRuntime } from \"./remote-runtime.ts\";\n\nexport class PluginExecutionError extends Schema.TaggedError<PluginExecutionError>()(\n \"PluginExecutionError\",\n {\n category: Schema.Literals([\"transport\", \"runner\", \"protocol\", \"cleanup\", \"artifact-expired\"]),\n cause: Schema.optionalKey(Schema.Redacted(Schema.Defect())),\n message: Schema.String,\n },\n) {}\n\nexport const maxPayloadBytes = 1024 * 1024;\nexport const maxMetadataBytes = 64 * 1024 * 1024;\n/** An Agent Channel result carries a read asset of up to 14 MiB. */\nexport const maxChannelResultBytes = 16 * 1024 * 1024;\nexport const cancellationTimeout = \"5 seconds\";\n\n/** The listener half of a Node or Bun IPC channel: a process or a child process. */\nexport interface IpcEvents {\n readonly on: (event: string, listener: (value: unknown) => void) => unknown;\n readonly removeListener: (event: string, listener: (value: unknown) => void) => unknown;\n}\n\n/** The sending half of a Node or Bun IPC channel: a process or a child process. */\nexport interface IpcSender {\n readonly connected: boolean;\n readonly send?: ((message: object) => unknown) | undefined;\n}\n\n/** Receive native Node and Bun IPC messages without interpreting plugin logs. */\nexport function ipcMessages(channel: IpcEvents) {\n return Stream.callback<unknown, PluginExecutionError>(queue => {\n const message = (value: unknown) => {\n Queue.offerUnsafe(queue, value);\n };\n const disconnected = () => {\n Queue.endUnsafe(queue);\n };\n const failed = (cause: unknown) => {\n Queue.failCauseUnsafe(\n queue,\n Cause.fail(\n PluginExecutionError.make({\n category: \"runner\",\n cause: Redacted.make(cause),\n message: \"Plugin IPC channel failed\",\n }),\n ),\n );\n };\n return Effect.acquireRelease(\n Effect.sync(() => {\n channel.on(\"message\", message);\n channel.on(\"disconnect\", disconnected);\n channel.on(\"error\", failed);\n }),\n () =>\n Effect.sync(() => {\n channel.removeListener(\"message\", message);\n channel.removeListener(\"disconnect\", disconnected);\n channel.removeListener(\"error\", failed);\n }),\n );\n });\n}\n\n/** Queue a JSON message; the runtime reports asynchronous send failures through its error event. */\nexport function sendIpc(channel: IpcSender, value: object) {\n return Effect.try({\n try: () => {\n if (!channel.connected || channel.send === undefined) {\n throw PluginExecutionError.make({\n category: \"runner\",\n message: \"Plugin IPC channel is closed\",\n });\n }\n channel.send(value);\n },\n catch: cause =>\n PluginExecutionError.make({\n category: \"runner\",\n cause: Redacted.make(cause),\n message: \"Cannot send plugin IPC message\",\n }),\n });\n}\n\nexport type OAuthContinuation = typeof OAuthContinuation.Type;\nexport const OAuthContinuation = Schema.Struct({\n expiresAt: Schema.DateFromString,\n pkceVerifier: Schema.NullOr(Schema.String),\n redirectUri: Schema.String,\n state: Schema.String,\n});\n\nexport type OAuthStarted = typeof OAuthStarted.Type;\nexport const OAuthStarted = Schema.Struct({\n authorizationUrl: Schema.String,\n continuation: OAuthContinuation,\n});\n\nconst oauth = {\n authMethodId: Schema.NonEmptyString,\n providerId: Schema.NonEmptyString,\n setup: Schema.optionalKey(Schema.Json),\n};\n\n/** The origins a Connection's credential may reach from a run sandbox, and the headers one request gets. */\nexport type SandboxAccessResult = typeof SandboxAccessResult.Type;\nexport const SandboxAccessResult = Schema.Struct({\n headers: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),\n origins: Schema.Array(Schema.String),\n});\n\nexport type AuthRequest = typeof AuthRequest.Type;\nexport const AuthRequest = Schema.TaggedStruct(\"auth\", {\n identity: RemoteRuntime.Identity,\n operation: Schema.Union([\n AuthMethodExecution.JsonRequest,\n Schema.TaggedStruct(\"oauthStart\", { ...oauth, redirectUri: Schema.String }),\n Schema.TaggedStruct(\"oauthComplete\", {\n ...oauth,\n continuation: OAuthContinuation,\n query: Schema.Record(Schema.String, Schema.String),\n }),\n // Without `request`, only the origins; with it, the headers the plugin adds to that request.\n Schema.TaggedStruct(\"sandboxAccess\", {\n ...oauth,\n material: Schema.Json,\n request: Schema.optionalKey(\n Schema.Struct({\n headers: Schema.Record(Schema.String, Schema.String),\n method: Schema.Literals([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"PATCH\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"QUERY\",\n ]),\n url: Schema.String,\n }),\n ),\n }),\n ]),\n});\n\n/** Decode an Agent Channel's settings outside any tenant, as publication validates them. */\nexport type ChannelSettingsRequest = typeof ChannelSettingsRequest.Type;\nexport const ChannelSettingsRequest = Schema.TaggedStruct(\"channelSettings\", {\n identity: RemoteRuntime.Identity,\n operation: Schema.TaggedStruct(\"decodeChannelSettings\", {\n channelId: Schema.NonEmptyString,\n field: Schema.Literals([\"definitionSettings\", \"deploymentSettings\"]),\n value: Schema.Json,\n }),\n});\n\nexport type ExecutionRequest = typeof ExecutionRequest.Type;\nexport const ExecutionRequest = Schema.Union([\n RemoteRuntime.Request,\n AuthRequest,\n ChannelSettingsRequest,\n]);\n\nexport type Request = typeof Request.Type;\nexport const Request = Schema.Union([\n ExecutionRequest,\n Schema.TaggedStruct(\"extract\", { identity: RemoteRuntime.Identity }),\n]);\n\nexport type Input = typeof Input.Type;\nexport const Input = Schema.Union([\n Request,\n Schema.TaggedStruct(\"cancel\", { identity: RemoteRuntime.Identity }),\n]);\n\nexport type Output = typeof Output.Type;\nexport const Output = Schema.Union([\n RemoteRuntime.Response,\n Schema.TaggedStruct(\"interrupted\", { identity: RemoteRuntime.Identity }),\n]);\n\nexport function checkMessageSize(value: unknown, maximum: number) {\n if (new TextEncoder().encode(JSON.stringify(value)).byteLength <= maximum) return Effect.void;\n return Effect.fail(\n PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin message exceeds its transport limit\",\n }),\n );\n}\n\nexport const encodeInput = Effect.fnUntraced(function* (input: Input) {\n const encoded = yield* Schema.encodeEffect(Input)(input);\n yield* checkMessageSize(encoded, maxPayloadBytes);\n return encoded;\n});\n\nexport const decodeInput = Effect.fnUntraced(function* (input: unknown) {\n const json = yield* Schema.decodeUnknownEffect(Schema.Json)(input);\n yield* checkMessageSize(json, maxPayloadBytes);\n return yield* Schema.decodeUnknownEffect(Input)(json);\n});\n\nexport const encodeOutput = Effect.fnUntraced(function* (output: Output, maximum: number) {\n const encoded = yield* Schema.encodeEffect(Output)(output);\n yield* checkMessageSize(encoded, maximum);\n return encoded;\n});\n\nexport const decodeOutput = Effect.fnUntraced(function* (output: unknown) {\n const json = yield* Schema.decodeUnknownEffect(Schema.Json)(output);\n yield* checkMessageSize(json, maxMetadataBytes);\n return yield* Schema.decodeUnknownEffect(Output)(json);\n});\n\nexport function responseLimit(request: Request) {\n if (\"_tag\" in request && request._tag === \"extract\") return maxMetadataBytes;\n if (\"context\" in request && request.operation._tag === \"channelExecute\") {\n return maxChannelResultBytes;\n }\n return maxPayloadBytes;\n}\n\nexport type Invocation = typeof Invocation.Type;\nexport const Invocation = Schema.Struct({\n entrypoint: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]+(?:[./][A-Za-z0-9_-]+)*$/u)),\n exportName: Schema.String.check(Schema.isPattern(/^[A-Za-z_$][A-Za-z0-9_$]*$/u)),\n request: Request,\n});\n\nexport const encodeRequest = Effect.fnUntraced(function* (request: Request) {\n const encoded = yield* pipe(\n Schema.encodeEffect(Schema.fromJsonString(Request))(request),\n Effect.mapError(cause =>\n PluginExecutionError.make({\n cause: Redacted.make(cause),\n category: \"protocol\",\n message: \"Invalid plugin request\",\n }),\n ),\n );\n if (new TextEncoder().encode(encoded).byteLength > maxPayloadBytes) {\n return yield* PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin request exceeds the 1 MiB transport limit\",\n });\n }\n return encoded;\n});\n\nexport const readBounded = Effect.fnUntraced(function* <E, R>(\n input: Stream.Stream<Uint8Array, E, R>,\n maximum = maxPayloadBytes,\n) {\n const output = { bytes: Buffer.alloc(maximum), size: 0 };\n yield* pipe(\n input,\n Stream.runForEach(chunk =>\n Effect.gen(function* () {\n if (output.size + chunk.byteLength > maximum) {\n return yield* PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin payload exceeds its transport limit\",\n });\n }\n Buffer.from(chunk).copy(output.bytes, output.size);\n output.size += chunk.byteLength;\n }),\n ),\n Effect.mapError(cause =>\n PluginExecutionError.make({\n cause: Redacted.make(cause),\n category: \"protocol\",\n message: \"Cannot read plugin payload\",\n }),\n ),\n );\n return output.bytes.toString(\"utf8\", 0, output.size);\n});\n\nexport const verifyResponse = Effect.fnUntraced(function* <Response extends Output>(\n request: Request,\n response: Response,\n) {\n if (\n response.identity.invocationId !== request.identity.invocationId ||\n response.identity.artifactDigest !== request.identity.artifactDigest ||\n response.identity.organizationId !== request.identity.organizationId ||\n response.identity.pluginKey !== request.identity.pluginKey ||\n response.identity.pluginVersion !== request.identity.pluginVersion\n ) {\n return yield* PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin result does not match its invocation\",\n });\n }\n return response;\n});\n\nconst executeAuth = Effect.fnUntraced(\n function* (request: AuthRequest) {\n const operation = request.operation;\n const runtime = yield* DualRuntime.Service;\n if (operation._tag === \"sandboxAccess\") {\n const access = yield* runtime.resolveSandboxAccess({\n ...operation,\n encoding: \"json\",\n setup: operation.setup,\n });\n if (operation.request === undefined) {\n return yield* Schema.encodeEffect(SandboxAccessResult)({ origins: access.origins });\n }\n const authorized = yield* access.authorize(\n HttpClientRequest.make(operation.request.method)(operation.request.url, {\n headers: operation.request.headers,\n }),\n );\n return yield* Schema.encodeEffect(SandboxAccessResult)({\n headers: authorized.headers,\n origins: access.origins,\n });\n }\n if (operation._tag !== \"oauthStart\" && operation._tag !== \"oauthComplete\") {\n return yield* runtime.executeAuthJson(operation);\n }\n const method = yield* runtime.getAuthMethod(operation);\n const setup = yield* runtime.decodeAuthMethodSetup({\n ...operation,\n encoding: \"json\",\n setup: operation.setup,\n });\n const oauth = yield* OAuthFlow.Service;\n if (operation._tag === \"oauthStart\") {\n return yield* Schema.encodeEffect(OAuthStarted)(\n yield* oauth.start({ method, redirectUri: operation.redirectUri, setup }),\n );\n }\n const completed = yield* oauth.complete({ ...operation, method, setup });\n return yield* runtime.executeAuthJson(\n yield* Schema.decodeUnknownEffect(AuthMethodExecution.JsonRequest)({\n ...operation,\n _tag: \"prepareOAuth2Tokens\",\n tokens: completed.tokens,\n }),\n );\n },\n (effect, request) =>\n pipe(\n effect,\n Effect.flatMap(\n Effect.fnUntraced(function* (value) {\n const result = { _tag: \"success\" as const, identity: request.identity };\n if (value === undefined) return result;\n return { ...result, value: yield* Schema.decodeUnknownEffect(Schema.Json)(value) };\n }),\n ),\n Effect.catch(error => {\n const cause = error._tag === \"AuthMethodHookError\" ? error.cause : error;\n return Effect.succeed({\n _tag: \"failure\" as const,\n error: {\n ...RemoteRuntime.failure(error),\n ...(Schema.is(OAuthGrantRejected)(cause) ? { code: \"OAuthGrantRejected\" } : {}),\n },\n identity: request.identity,\n });\n }),\n ),\n);\n\nconst executeChannelSettings = Effect.fnUntraced(\n function* (request: ChannelSettingsRequest) {\n const runtime = yield* DualRuntime.Service;\n const { channelId, field, value } = request.operation;\n const input = { channelId, value };\n if (field === \"definitionSettings\") {\n return yield* runtime.decodeAgentChannelDefinitionSettings(input);\n }\n return yield* runtime.decodeAgentChannelDeploymentSettings(input);\n },\n (effect, request) =>\n pipe(\n effect,\n Effect.map(value => ({ _tag: \"success\", identity: request.identity, value }) as const),\n Effect.catch(error =>\n Effect.succeed({\n _tag: \"failure\" as const,\n error: RemoteRuntime.failure(error),\n identity: request.identity,\n }),\n ),\n ),\n);\n\n/** Execute one request against the plugin built in this process; only the guest runner calls it in production. */\nexport const execute = Effect.fnUntraced(function* (request: ExecutionRequest) {\n if (!(\"_tag\" in request)) return yield* RemoteRuntime.execute(request);\n if (request._tag === \"auth\") return yield* executeAuth(request);\n return yield* executeChannelSettings(request);\n});\n\nexport * as PluginRuntime from \"./PluginRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,wBACA;CACE,UAAU,OAAO,SAAS;EAAC;EAAa;EAAU;EAAY;EAAW;CAAkB,CAAC;CAC5F,OAAO,OAAO,YAAY,OAAO,SAAS,OAAO,OAAO,CAAC,CAAC;CAC1D,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;AAEH,MAAa,kBAAkB;AAC/B,MAAa,mBAAmB;;AAEhC,MAAa,wBAAwB;AACrC,MAAa,sBAAsB;;AAenC,SAAgB,YAAY,SAAoB;CAC9C,OAAO,OAAO,UAAwC,UAAS;EAC7D,MAAM,WAAW,UAAmB;GAClC,MAAM,YAAY,OAAO,KAAK;EAChC;EACA,MAAM,qBAAqB;GACzB,MAAM,UAAU,KAAK;EACvB;EACA,MAAM,UAAU,UAAmB;GACjC,MAAM,gBACJ,OACA,MAAM,KACJ,qBAAqB,KAAK;IACxB,UAAU;IACV,OAAO,SAAS,KAAK,KAAK;IAC1B,SAAS;GACX,CAAC,CACH,CACF;EACF;EACA,OAAO,OAAO,eACZ,OAAO,WAAW;GAChB,QAAQ,GAAG,WAAW,OAAO;GAC7B,QAAQ,GAAG,cAAc,YAAY;GACrC,QAAQ,GAAG,SAAS,MAAM;EAC5B,CAAC,SAEC,OAAO,WAAW;GAChB,QAAQ,eAAe,WAAW,OAAO;GACzC,QAAQ,eAAe,cAAc,YAAY;GACjD,QAAQ,e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,EAAE,MAAM,qBAAqB,IAAI,CAAC;EAC/E;EACA,UAAU,QAAQ;CACpB,CAAC;AACH,CAAC,CACH,CACJ;AAEA,MAAM,yBAAyB,OAAO,WACpC,WAAW,SAAiC;CAC1C,MAAM,UAAU,OAAOF;CACvB,MAAM,EAAE,WAAW,OAAO,UAAU,QAAQ;CAC5C,MAAM,QAAQ;EAAE;EAAW;CAAM;CACjC,IAAI,UAAU,sBACZ,OAAO,OAAO,QAAQ,qCAAqC,KAAK;CAElE,OAAO,OAAO,QAAQ,qCAAqC,KAAK;AAClE,IACC,QAAQ,YACP,KACE,QACA,OAAO,KAAI,WAAU;CAAE,MAAM;CAAW,UAAU,QAAQ;CAAU;AAAM,EAAW,GACrF,OAAO,OAAM,UACX,OAAO,QAAQ;CACb,MAAM;CACN,OAAOE,QAAsB,KAAK;CAClC,UAAU,QAAQ;AACpB,CAAC,CACH,CACF,CACJ;;AAGA,MAAa,UAAU,OAAO,WAAW,WAAW,SAA2B;CAC7E,IAAI,EAAE,UAAU,UAAU,OAAO,OAAOC,UAAsB,OAAO;CACrE,IAAI,QAAQ,SAAS,QAAQ,OAAO,OAAO,YAAY,OAAO;CAC9D,OAAO,OAAO,uBAAuB,OAAO;AAC9C,CAAC"}
1
+ {"version":3,"file":"PluginRuntime.js","names":["RemoteRuntime.Identity","AuthMethodExecution.JsonRequest","RemoteRuntime.Request","RemoteRuntime.Response","DualRuntime.Service","OAuthFlow.Service","failure","RemoteRuntime.failure","RemoteRuntime.execute"],"sources":["../src/PluginRuntime.ts"],"sourcesContent":["import { Cause, Effect, Queue, Redacted, Schema, Stream, pipe } from \"effect\";\n\nimport { HttpClientRequest } from \"effect/http\";\n\nimport * as AuthMethodExecution from \"./AuthMethodExecution.ts\";\nimport * as DualRuntime from \"./DualRuntime.ts\";\nimport { OAuthFlow, OAuthGrantRejected } from \"./OAuthFlow.ts\";\nimport { RemoteRuntime } from \"./remote-runtime.ts\";\n\nexport class PluginExecutionError extends Schema.TaggedError<PluginExecutionError>()(\n \"PluginExecutionError\",\n {\n category: Schema.Literals([\"transport\", \"runner\", \"protocol\", \"cleanup\", \"artifact-expired\"]),\n cause: Schema.optionalKey(Schema.Redacted(Schema.Defect())),\n message: Schema.String,\n },\n) {}\n\nexport const maxPayloadBytes = 1024 * 1024;\nexport const maxMetadataBytes = 64 * 1024 * 1024;\n/** An Agent Channel result carries a read asset of up to 14 MiB. */\nexport const maxChannelResultBytes = 16 * 1024 * 1024;\nexport const cancellationTimeout = \"5 seconds\";\n\n/** The listener half of a Node or Bun IPC channel: a process or a child process. */\nexport interface IpcEvents {\n readonly on: (event: string, listener: (value: unknown) => void) => unknown;\n readonly removeListener: (event: string, listener: (value: unknown) => void) => unknown;\n}\n\n/** The sending half of a Node or Bun IPC channel: a process or a child process. */\nexport interface IpcSender {\n readonly connected: boolean;\n readonly send?: ((message: object) => unknown) | undefined;\n}\n\n/** Receive native Node and Bun IPC messages without interpreting plugin logs. */\nexport function ipcMessages(channel: IpcEvents) {\n return Stream.callback<unknown, PluginExecutionError>(queue => {\n const message = (value: unknown) => {\n Queue.offerUnsafe(queue, value);\n };\n const disconnected = () => {\n Queue.endUnsafe(queue);\n };\n const failed = (cause: unknown) => {\n Queue.failCauseUnsafe(\n queue,\n Cause.fail(\n PluginExecutionError.make({\n category: \"runner\",\n cause: Redacted.make(cause),\n message: \"Plugin IPC channel failed\",\n }),\n ),\n );\n };\n return Effect.acquireRelease(\n Effect.sync(() => {\n channel.on(\"message\", message);\n channel.on(\"disconnect\", disconnected);\n channel.on(\"error\", failed);\n }),\n () =>\n Effect.sync(() => {\n channel.removeListener(\"message\", message);\n channel.removeListener(\"disconnect\", disconnected);\n channel.removeListener(\"error\", failed);\n }),\n );\n });\n}\n\n/** Queue a JSON message; the runtime reports asynchronous send failures through its error event. */\nexport function sendIpc(channel: IpcSender, value: object) {\n return Effect.try({\n try: () => {\n if (!channel.connected || channel.send === undefined) {\n throw PluginExecutionError.make({\n category: \"runner\",\n message: \"Plugin IPC channel is closed\",\n });\n }\n channel.send(value);\n },\n catch: cause =>\n PluginExecutionError.make({\n category: \"runner\",\n cause: Redacted.make(cause),\n message: \"Cannot send plugin IPC message\",\n }),\n });\n}\n\nexport type OAuthContinuation = typeof OAuthContinuation.Type;\nexport const OAuthContinuation = Schema.Struct({\n expiresAt: Schema.DateFromString,\n pkceVerifier: Schema.NullOr(Schema.String),\n redirectUri: Schema.String,\n state: Schema.String,\n});\n\nexport type OAuthStarted = typeof OAuthStarted.Type;\nexport const OAuthStarted = Schema.Struct({\n authorizationUrl: Schema.String,\n continuation: OAuthContinuation,\n});\n\nconst oauth = {\n authMethodId: Schema.NonEmptyString,\n providerId: Schema.NonEmptyString,\n setup: Schema.optionalKey(Schema.Json),\n};\n\n/** The origins a Connection's credential may reach from a run sandbox, and the headers one request gets. */\nexport type SandboxAccessResult = typeof SandboxAccessResult.Type;\nexport const SandboxAccessResult = Schema.Struct({\n headers: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),\n origins: Schema.Array(Schema.String),\n});\n\nexport type AuthRequest = typeof AuthRequest.Type;\nexport const AuthRequest = Schema.TaggedStruct(\"auth\", {\n identity: RemoteRuntime.Identity,\n operation: Schema.Union([\n AuthMethodExecution.JsonRequest,\n Schema.TaggedStruct(\"oauthStart\", { ...oauth, redirectUri: Schema.String }),\n Schema.TaggedStruct(\"oauthComplete\", {\n ...oauth,\n continuation: OAuthContinuation,\n query: Schema.Record(Schema.String, Schema.String),\n }),\n // Without `request`, only the origins; with it, the headers the plugin adds to that request.\n Schema.TaggedStruct(\"sandboxAccess\", {\n ...oauth,\n material: Schema.Json,\n request: Schema.optionalKey(\n Schema.Struct({\n headers: Schema.Record(Schema.String, Schema.String),\n method: Schema.Literals([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"PATCH\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"QUERY\",\n ]),\n url: Schema.String,\n }),\n ),\n }),\n ]),\n});\n\n/** Decode an Agent Channel's settings outside any tenant, as publication validates them. */\nexport type ChannelSettingsRequest = typeof ChannelSettingsRequest.Type;\nexport const ChannelSettingsRequest = Schema.TaggedStruct(\"channelSettings\", {\n identity: RemoteRuntime.Identity,\n operation: Schema.TaggedStruct(\"decodeChannelSettings\", {\n channelId: Schema.NonEmptyString,\n field: Schema.Literals([\"definitionSettings\", \"deploymentSettings\"]),\n value: Schema.Json,\n }),\n});\n\nexport type ExecutionRequest = typeof ExecutionRequest.Type;\nexport const ExecutionRequest = Schema.Union([\n RemoteRuntime.Request,\n AuthRequest,\n ChannelSettingsRequest,\n]);\n\nexport type Request = typeof Request.Type;\nexport const Request = Schema.Union([\n ExecutionRequest,\n Schema.TaggedStruct(\"extract\", { identity: RemoteRuntime.Identity }),\n]);\n\nexport type Input = typeof Input.Type;\nexport const Input = Schema.Union([\n Request,\n Schema.TaggedStruct(\"cancel\", { identity: RemoteRuntime.Identity }),\n]);\n\nexport type Output = typeof Output.Type;\nexport const Output = Schema.Union([\n RemoteRuntime.Response,\n Schema.TaggedStruct(\"interrupted\", { identity: RemoteRuntime.Identity }),\n]);\n\nexport function checkMessageSize(value: unknown, maximum: number) {\n if (new TextEncoder().encode(JSON.stringify(value)).byteLength <= maximum) return Effect.void;\n return Effect.fail(\n PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin message exceeds its transport limit\",\n }),\n );\n}\n\nexport const encodeInput = Effect.fnUntraced(function* (input: Input) {\n const encoded = yield* Schema.encodeEffect(Input)(input);\n yield* checkMessageSize(encoded, maxPayloadBytes);\n return encoded;\n});\n\nexport const decodeInput = Effect.fnUntraced(function* (input: unknown) {\n const json = yield* Schema.decodeUnknownEffect(Schema.Json)(input);\n yield* checkMessageSize(json, maxPayloadBytes);\n return yield* Schema.decodeUnknownEffect(Input)(json);\n});\n\nexport const encodeOutput = Effect.fnUntraced(function* (output: Output, maximum: number) {\n const encoded = yield* Schema.encodeEffect(Output)(output);\n yield* checkMessageSize(encoded, maximum);\n return encoded;\n});\n\nexport const decodeOutput = Effect.fnUntraced(function* (output: unknown) {\n const json = yield* Schema.decodeUnknownEffect(Schema.Json)(output);\n yield* checkMessageSize(json, maxMetadataBytes);\n return yield* Schema.decodeUnknownEffect(Output)(json);\n});\n\nexport function responseLimit(request: Request) {\n if (\"_tag\" in request && request._tag === \"extract\") return maxMetadataBytes;\n if (\"context\" in request && request.operation._tag === \"channelExecute\") {\n return maxChannelResultBytes;\n }\n return maxPayloadBytes;\n}\n\nexport type Invocation = typeof Invocation.Type;\nexport const Invocation = Schema.Struct({\n entrypoint: Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]+(?:[./][A-Za-z0-9_-]+)*$/u)),\n exportName: Schema.String.check(Schema.isPattern(/^[A-Za-z_$][A-Za-z0-9_$]*$/u)),\n request: Request,\n});\n\nexport const encodeRequest = Effect.fnUntraced(function* (request: Request) {\n const encoded = yield* pipe(\n Schema.encodeEffect(Schema.fromJsonString(Request))(request),\n Effect.mapError(cause =>\n PluginExecutionError.make({\n cause: Redacted.make(cause),\n category: \"protocol\",\n message: \"Invalid plugin request\",\n }),\n ),\n );\n if (new TextEncoder().encode(encoded).byteLength > maxPayloadBytes) {\n return yield* PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin request exceeds the 1 MiB transport limit\",\n });\n }\n return encoded;\n});\n\nexport const readBounded = Effect.fnUntraced(function* <E, R>(\n input: Stream.Stream<Uint8Array, E, R>,\n maximum = maxPayloadBytes,\n) {\n const output = { bytes: Buffer.alloc(maximum), size: 0 };\n yield* pipe(\n input,\n Stream.runForEach(chunk =>\n Effect.gen(function* () {\n if (output.size + chunk.byteLength > maximum) {\n return yield* PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin payload exceeds its transport limit\",\n });\n }\n Buffer.from(chunk).copy(output.bytes, output.size);\n output.size += chunk.byteLength;\n }),\n ),\n Effect.mapError(cause =>\n PluginExecutionError.make({\n cause: Redacted.make(cause),\n category: \"protocol\",\n message: \"Cannot read plugin payload\",\n }),\n ),\n );\n return output.bytes.toString(\"utf8\", 0, output.size);\n});\n\nexport const verifyResponse = Effect.fnUntraced(function* <Response extends Output>(\n request: Request,\n response: Response,\n) {\n if (\n response.identity.invocationId !== request.identity.invocationId ||\n response.identity.artifactDigest !== request.identity.artifactDigest ||\n response.identity.organizationId !== request.identity.organizationId ||\n response.identity.pluginKey !== request.identity.pluginKey ||\n response.identity.pluginVersion !== request.identity.pluginVersion\n ) {\n return yield* PluginExecutionError.make({\n category: \"protocol\",\n message: \"Plugin result does not match its invocation\",\n });\n }\n return response;\n});\n\nconst executeAuth = Effect.fnUntraced(\n function* (request: AuthRequest) {\n const operation = request.operation;\n const runtime = yield* DualRuntime.Service;\n if (operation._tag === \"sandboxAccess\") {\n const access = yield* runtime.resolveSandboxAccess({\n ...operation,\n encoding: \"json\",\n setup: operation.setup,\n });\n if (operation.request === undefined) {\n return yield* Schema.encodeEffect(SandboxAccessResult)({ origins: access.origins });\n }\n const authorized = yield* access.authorize(\n HttpClientRequest.make(operation.request.method)(operation.request.url, {\n headers: operation.request.headers,\n }),\n );\n return yield* Schema.encodeEffect(SandboxAccessResult)({\n headers: authorized.headers,\n origins: access.origins,\n });\n }\n if (operation._tag !== \"oauthStart\" && operation._tag !== \"oauthComplete\") {\n return yield* runtime.executeAuthJson(operation);\n }\n const method = yield* runtime.getAuthMethod(operation);\n const setup = yield* runtime.decodeAuthMethodSetup({\n ...operation,\n encoding: \"json\",\n setup: operation.setup,\n });\n const oauth = yield* OAuthFlow.Service;\n if (operation._tag === \"oauthStart\") {\n return yield* Schema.encodeEffect(OAuthStarted)(\n yield* oauth.start({ method, redirectUri: operation.redirectUri, setup }),\n );\n }\n const completed = yield* oauth.complete({ ...operation, method, setup });\n return yield* runtime.executeAuthJson(\n yield* Schema.decodeUnknownEffect(AuthMethodExecution.JsonRequest)({\n ...operation,\n _tag: \"prepareOAuth2Tokens\",\n tokens: completed.tokens,\n }),\n );\n },\n (effect, request) =>\n pipe(\n effect,\n Effect.flatMap(\n Effect.fnUntraced(function* (value) {\n const result = { _tag: \"success\" as const, identity: request.identity };\n if (value === undefined) return result;\n return { ...result, value: yield* Schema.decodeUnknownEffect(Schema.Json)(value) };\n }),\n ),\n Effect.catch(error => {\n const cause = error._tag === \"AuthMethodHookError\" ? error.cause : error;\n const failure = RemoteRuntime.failure(error);\n if (Schema.is(OAuthGrantRejected)(cause) && !(\"_tag\" in failure)) {\n return Effect.succeed({\n _tag: \"failure\" as const,\n error: { ...failure, code: \"OAuthGrantRejected\" },\n identity: request.identity,\n });\n }\n return Effect.succeed({\n _tag: \"failure\" as const,\n error: failure,\n identity: request.identity,\n });\n }),\n ),\n);\n\nconst executeChannelSettings = Effect.fnUntraced(\n function* (request: ChannelSettingsRequest) {\n const runtime = yield* DualRuntime.Service;\n const { channelId, field, value } = request.operation;\n const input = { channelId, value };\n if (field === \"definitionSettings\") {\n return yield* runtime.decodeAgentChannelDefinitionSettings(input);\n }\n return yield* runtime.decodeAgentChannelDeploymentSettings(input);\n },\n (effect, request) =>\n pipe(\n effect,\n Effect.map(value => ({ _tag: \"success\", identity: request.identity, value }) as const),\n Effect.catch(error =>\n Effect.succeed({\n _tag: \"failure\" as const,\n error: RemoteRuntime.failure(error),\n identity: request.identity,\n }),\n ),\n ),\n);\n\n/** Execute one request against the plugin built in this process; only the guest runner calls it in production. */\nexport const execute = Effect.fnUntraced(function* (request: ExecutionRequest) {\n if (!(\"_tag\" in request)) return yield* RemoteRuntime.execute(request);\n if (request._tag === \"auth\") return yield* executeAuth(request);\n return yield* executeChannelSettings(request);\n});\n\nexport * as PluginRuntime from \"./PluginRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,wBACA;CACE,UAAU,OAAO,SAAS;EAAC;EAAa;EAAU;EAAY;EAAW;CAAkB,CAAC;CAC5F,OAAO,OAAO,YAAY,OAAO,SAAS,OA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U,QAAQ;CAAU;AAAM,EAAW,GACrF,OAAO,OAAM,UACX,OAAO,QAAQ;CACb,MAAM;CACN,OAAOG,QAAsB,KAAK;CAClC,UAAU,QAAQ;AACpB,CAAC,CACH,CACF,CACJ;;AAGA,MAAa,UAAU,OAAO,WAAW,WAAW,SAA2B;CAC7E,IAAI,EAAE,UAAU,UAAU,OAAO,OAAOC,UAAsB,OAAO;CACrE,IAAI,QAAQ,SAAS,QAAQ,OAAO,OAAO,YAAY,OAAO;CAC9D,OAAO,OAAO,uBAAuB,OAAO;AAC9C,CAAC"}
@@ -1,7 +1,9 @@
1
+ import { AuthMethodHookError, ExpectedOAuth2MethodError, OAuth2RefreshTokenUnavailableError } from "./AuthMethod.js";
2
+ import { ActionHandlerError, RetryableActionHandlerError } from "./Action.js";
1
3
  import { ChannelError } from "./AgentChannel.js";
2
- import { Service } from "./ConnectionResolver.js";
3
- import { InvokeError } from "./internal/dual/invoke.js";
4
- import { AuthMethodExecutionError, Service as Service$1 } from "./DualRuntime.js";
4
+ import { ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, ConnectionRequiredError, ConnectionResolverStoreError, ConnectionSelectionRequiredError, InvalidConnectionIdError, InvalidResolvedConnectionError, Service } from "./ConnectionResolver.js";
5
+ import { ActionHandlerNotFoundError, ActionNotFoundError, InvalidActionInputError, InvalidActionOutputError } from "./internal/dual/invoke.js";
6
+ import { AuthMethodNotFoundError, Service as Service$1 } from "./DualRuntime.js";
5
7
  import { Service as Service$2 } from "./Files.js";
6
8
  import "./remote-runtime.js";
7
9
  import { Effect, Layer, Schema } from "effect";
@@ -276,7 +278,7 @@ export declare const Request: Schema.Struct<{
276
278
  }>]>]>;
277
279
  }>;
278
280
  export type Failure = typeof Failure.Type;
279
- export declare const Failure: Schema.Struct<{
281
+ export declare const Failure: Schema.Union<readonly [typeof ActionHandlerError, typeof RetryableActionHandlerError, Schema.Struct<{
280
282
  readonly category: Schema.Literals<readonly ["validation", "connection", "handler", "initialization", "protocol"]>;
281
283
  /** The Agent Channel failure the host rebuilds as its `ChannelError`. */
282
284
  readonly channel: Schema.optionalKey<Schema.Struct<{
@@ -292,7 +294,7 @@ export declare const Failure: Schema.Struct<{
292
294
  readonly retryable: Schema.Boolean;
293
295
  /** The provider's HTTP status, kept so the host can report why a provider rejected the call. */
294
296
  readonly status: Schema.optionalKey<Schema.Int>;
295
- }>;
297
+ }>]>;
296
298
  export type Response = typeof Response.Type;
297
299
  export declare const Response: Schema.Union<readonly [Schema.TaggedStruct<"success", {
298
300
  readonly identity: Schema.Struct<{
@@ -304,7 +306,7 @@ export declare const Response: Schema.Union<readonly [Schema.TaggedStruct<"succe
304
306
  }>;
305
307
  readonly value: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
306
308
  }>, Schema.TaggedStruct<"failure", {
307
- readonly error: Schema.Struct<{
309
+ readonly error: Schema.Union<readonly [typeof ActionHandlerError, typeof RetryableActionHandlerError, Schema.Struct<{
308
310
  readonly category: Schema.Literals<readonly ["validation", "connection", "handler", "initialization", "protocol"]>;
309
311
  /** The Agent Channel failure the host rebuilds as its `ChannelError`. */
310
312
  readonly channel: Schema.optionalKey<Schema.Struct<{
@@ -320,7 +322,7 @@ export declare const Response: Schema.Union<readonly [Schema.TaggedStruct<"succe
320
322
  readonly retryable: Schema.Boolean;
321
323
  /** The provider's HTTP status, kept so the host can report why a provider rejected the call. */
322
324
  readonly status: Schema.optionalKey<Schema.Int>;
323
- }>;
325
+ }>]>;
324
326
  readonly identity: Schema.Struct<{
325
327
  readonly artifactDigest: Schema.String;
326
328
  readonly invocationId: Schema.NonEmptyString;
@@ -528,7 +530,7 @@ export declare const execute: (request: {
528
530
  value: Schema.Json;
529
531
  } | {
530
532
  _tag: "failure";
531
- error: (ChannelError | {
533
+ error: ActionHandlerError | RetryableActionHandlerError | {
532
534
  readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
533
535
  readonly channel?: {
534
536
  readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
@@ -542,7 +544,7 @@ export declare const execute: (request: {
542
544
  readonly retryAfterSeconds?: number;
543
545
  readonly retryable: boolean;
544
546
  readonly status?: number;
545
- } | AuthMethodExecutionError | InvokeError) & {
547
+ } | (ActionHandlerError & {
546
548
  readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
547
549
  readonly channel?: {
548
550
  readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
@@ -556,7 +558,287 @@ export declare const execute: (request: {
556
558
  readonly retryAfterSeconds?: number;
557
559
  readonly retryable: boolean;
558
560
  readonly status?: number;
559
- };
561
+ }) | (ActionHandlerNotFoundError & {
562
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
563
+ readonly channel?: {
564
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
565
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
566
+ };
567
+ readonly code: string;
568
+ readonly fields?: readonly {
569
+ readonly path: string;
570
+ }[];
571
+ readonly message: string;
572
+ readonly retryAfterSeconds?: number;
573
+ readonly retryable: boolean;
574
+ readonly status?: number;
575
+ }) | (ActionNotFoundError & {
576
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
577
+ readonly channel?: {
578
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
579
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
580
+ };
581
+ readonly code: string;
582
+ readonly fields?: readonly {
583
+ readonly path: string;
584
+ }[];
585
+ readonly message: string;
586
+ readonly retryAfterSeconds?: number;
587
+ readonly retryable: boolean;
588
+ readonly status?: number;
589
+ }) | (AuthMethodHookError & {
590
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
591
+ readonly channel?: {
592
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
593
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
594
+ };
595
+ readonly code: string;
596
+ readonly fields?: readonly {
597
+ readonly path: string;
598
+ }[];
599
+ readonly message: string;
600
+ readonly retryAfterSeconds?: number;
601
+ readonly retryable: boolean;
602
+ readonly status?: number;
603
+ }) | (AuthMethodNotFoundError & {
604
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
605
+ readonly channel?: {
606
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
607
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
608
+ };
609
+ readonly code: string;
610
+ readonly fields?: readonly {
611
+ readonly path: string;
612
+ }[];
613
+ readonly message: string;
614
+ readonly retryAfterSeconds?: number;
615
+ readonly retryable: boolean;
616
+ readonly status?: number;
617
+ }) | (ChannelError & {
618
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
619
+ readonly channel?: {
620
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
621
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
622
+ };
623
+ readonly code: string;
624
+ readonly fields?: readonly {
625
+ readonly path: string;
626
+ }[];
627
+ readonly message: string;
628
+ readonly retryAfterSeconds?: number;
629
+ readonly retryable: boolean;
630
+ readonly status?: number;
631
+ }) | (ConnectionIdNotAllowedError & {
632
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
633
+ readonly channel?: {
634
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
635
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
636
+ };
637
+ readonly code: string;
638
+ readonly fields?: readonly {
639
+ readonly path: string;
640
+ }[];
641
+ readonly message: string;
642
+ readonly retryAfterSeconds?: number;
643
+ readonly retryable: boolean;
644
+ readonly status?: number;
645
+ }) | (ConnectionReauthorizationRequiredError & {
646
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
647
+ readonly channel?: {
648
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
649
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
650
+ };
651
+ readonly code: string;
652
+ readonly fields?: readonly {
653
+ readonly path: string;
654
+ }[];
655
+ readonly message: string;
656
+ readonly retryAfterSeconds?: number;
657
+ readonly retryable: boolean;
658
+ readonly status?: number;
659
+ }) | (ConnectionRequiredError & {
660
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
661
+ readonly channel?: {
662
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
663
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
664
+ };
665
+ readonly code: string;
666
+ readonly fields?: readonly {
667
+ readonly path: string;
668
+ }[];
669
+ readonly message: string;
670
+ readonly retryAfterSeconds?: number;
671
+ readonly retryable: boolean;
672
+ readonly status?: number;
673
+ }) | (ConnectionResolverStoreError & {
674
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
675
+ readonly channel?: {
676
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
677
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
678
+ };
679
+ readonly code: string;
680
+ readonly fields?: readonly {
681
+ readonly path: string;
682
+ }[];
683
+ readonly message: string;
684
+ readonly retryAfterSeconds?: number;
685
+ readonly retryable: boolean;
686
+ readonly status?: number;
687
+ }) | (ConnectionSelectionRequiredError & {
688
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
689
+ readonly channel?: {
690
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
691
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
692
+ };
693
+ readonly code: string;
694
+ readonly fields?: readonly {
695
+ readonly path: string;
696
+ }[];
697
+ readonly message: string;
698
+ readonly retryAfterSeconds?: number;
699
+ readonly retryable: boolean;
700
+ readonly status?: number;
701
+ }) | (ExpectedOAuth2MethodError & {
702
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
703
+ readonly channel?: {
704
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
705
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
706
+ };
707
+ readonly code: string;
708
+ readonly fields?: readonly {
709
+ readonly path: string;
710
+ }[];
711
+ readonly message: string;
712
+ readonly retryAfterSeconds?: number;
713
+ readonly retryable: boolean;
714
+ readonly status?: number;
715
+ }) | (InvalidActionInputError & {
716
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
717
+ readonly channel?: {
718
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
719
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
720
+ };
721
+ readonly code: string;
722
+ readonly fields?: readonly {
723
+ readonly path: string;
724
+ }[];
725
+ readonly message: string;
726
+ readonly retryAfterSeconds?: number;
727
+ readonly retryable: boolean;
728
+ readonly status?: number;
729
+ }) | (InvalidActionOutputError & {
730
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
731
+ readonly channel?: {
732
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
733
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
734
+ };
735
+ readonly code: string;
736
+ readonly fields?: readonly {
737
+ readonly path: string;
738
+ }[];
739
+ readonly message: string;
740
+ readonly retryAfterSeconds?: number;
741
+ readonly retryable: boolean;
742
+ readonly status?: number;
743
+ }) | (InvalidConnectionIdError & {
744
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
745
+ readonly channel?: {
746
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
747
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
748
+ };
749
+ readonly code: string;
750
+ readonly fields?: readonly {
751
+ readonly path: string;
752
+ }[];
753
+ readonly message: string;
754
+ readonly retryAfterSeconds?: number;
755
+ readonly retryable: boolean;
756
+ readonly status?: number;
757
+ }) | (InvalidResolvedConnectionError & {
758
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
759
+ readonly channel?: {
760
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
761
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
762
+ };
763
+ readonly code: string;
764
+ readonly fields?: readonly {
765
+ readonly path: string;
766
+ }[];
767
+ readonly message: string;
768
+ readonly retryAfterSeconds?: number;
769
+ readonly retryable: boolean;
770
+ readonly status?: number;
771
+ }) | (OAuth2RefreshTokenUnavailableError & {
772
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
773
+ readonly channel?: {
774
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
775
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
776
+ };
777
+ readonly code: string;
778
+ readonly fields?: readonly {
779
+ readonly path: string;
780
+ }[];
781
+ readonly message: string;
782
+ readonly retryAfterSeconds?: number;
783
+ readonly retryable: boolean;
784
+ readonly status?: number;
785
+ }) | (RetryableActionHandlerError & {
786
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
787
+ readonly channel?: {
788
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
789
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
790
+ };
791
+ readonly code: string;
792
+ readonly fields?: readonly {
793
+ readonly path: string;
794
+ }[];
795
+ readonly message: string;
796
+ readonly retryAfterSeconds?: number;
797
+ readonly retryable: boolean;
798
+ readonly status?: number;
799
+ }) | (Schema.SchemaError & {
800
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
801
+ readonly channel?: {
802
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
803
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
804
+ };
805
+ readonly code: string;
806
+ readonly fields?: readonly {
807
+ readonly path: string;
808
+ }[];
809
+ readonly message: string;
810
+ readonly retryAfterSeconds?: number;
811
+ readonly retryable: boolean;
812
+ readonly status?: number;
813
+ }) | ({
814
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
815
+ readonly channel?: {
816
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
817
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
818
+ };
819
+ readonly code: string;
820
+ readonly fields?: readonly {
821
+ readonly path: string;
822
+ }[];
823
+ readonly message: string;
824
+ readonly retryAfterSeconds?: number;
825
+ readonly retryable: boolean;
826
+ readonly status?: number;
827
+ } & ActionHandlerError) | ({
828
+ readonly category: "connection" | "handler" | "initialization" | "protocol" | "validation";
829
+ readonly channel?: {
830
+ readonly code: "handler_unavailable" | "invalid_auth" | "invalid_definition" | "invalid_input" | "invalid_result" | "not_found" | "provider_failure" | "unsupported_feature";
831
+ readonly providerCode?: "rate_limited" | "rejected" | "unauthorized" | "unavailable" | "unknown_completion" | "window_closed";
832
+ };
833
+ readonly code: string;
834
+ readonly fields?: readonly {
835
+ readonly path: string;
836
+ }[];
837
+ readonly message: string;
838
+ readonly retryAfterSeconds?: number;
839
+ readonly retryable: boolean;
840
+ readonly status?: number;
841
+ } & RetryableActionHandlerError);
560
842
  identity: {
561
843
  readonly artifactDigest: string;
562
844
  readonly invocationId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"remote-runtime.d.ts","names":["Files.Service","ConnectionResolver.Service","AgentChannel.ChannelError","DualRuntime.AuthMethodExecutionError","DualRuntime.InvokeError","DualRuntime.Service"],"sources":["../src/remote-runtime.ts"],"mappings":";;;;;;;;;;YA6BY,kBAAkB,SAAS;qBAC1B,UAAQ,OAAA;;;;;;;YAoDT,mBAAmB,UAAU;qBAC5B,WAAS,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAeV,oBAAoB,WAAW;qBAC9B,YAAU,OAAA;;;;YACX,iBAAiB,QAAQ;qBACxB,SAAO,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAQR,iBAAiB,QAAQ;qBACxB,SAAO,OAAA;;;;;;;;;;;;;;;;;YAiBR,kBAAkB,SAAS;qBAC1B,UAAQ,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAML,QAAQ,iBAAiB;qBAqH5B,kBAAgB,MAAA,MAAAA;wBA2Eb,gBAAgB,SAAS,UAAO,MAAA,MAAAC;;qBAiFnC,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA2DlBI"}
1
+ {"version":3,"file":"remote-runtime.d.ts","names":["Files.Service","ConnectionResolver.Service","DualRuntime.ActionHandlerNotFoundError","DualRuntime.ActionNotFoundError","_$__AuthMethod_ts0.AuthMethodHookError","DualRuntime.AuthMethodNotFoundError","AgentChannel.ChannelError","ConnectionResolver.ConnectionIdNotAllowedError","ConnectionResolver.ConnectionReauthorizationRequiredError","ConnectionResolver.ConnectionRequiredError","ConnectionResolver.ConnectionResolverStoreError","ConnectionResolver.ConnectionSelectionRequiredError","_$__AuthMethod_ts0.ExpectedOAuth2MethodError","DualRuntime.InvalidActionInputError","DualRuntime.InvalidActionOutputError","ConnectionResolver.InvalidConnectionIdError","ConnectionResolver.InvalidResolvedConnectionError","_$__AuthMethod_ts0.OAuth2RefreshTokenUnavailableError","DualRuntime.Service"],"sources":["../src/remote-runtime.ts"],"mappings":";;;;;;;;;;;;YA6BY,kBAAkB,SAAS;qBAC1B,UAAQ,OAAA;;;;;;;YAoDT,mBAAmB,UAAU;qBAC5B,WAAS,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAeV,oBAAoB,WAAW;qBAC9B,YAAU,OAAA;;;;YACX,iBAAiB,QAAQ;qBACxB,SAAO,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAyBR,iBAAiB,QAAQ;qBACxB,SAAO,OAAA,uBAAA,2BAAA,6BAAA,OAAA;;;;;;;;;;;;;;;;;YAKR,kBAAkB,SAAS;qBAC1B,UAAQ,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAML,QAAQ,iBAAiB;qBAqG5B,kBAAgB,MAAA,MAAAA;wBA2Eb,gBAAgB,SAAS,UAAO,MAAA,MAAAC;;qBAiFnC,UAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA2DlBiB"}
@@ -117,7 +117,7 @@ const Request = Schema.Struct({
117
117
  identity: Identity,
118
118
  operation: Operation
119
119
  });
120
- const Failure = Schema.Struct({
120
+ const RuntimeFailure = Schema.Struct({
121
121
  category: Schema.Literals([
122
122
  "validation",
123
123
  "connection",
@@ -138,6 +138,11 @@ const Failure = Schema.Struct({
138
138
  /** The provider's HTTP status, kept so the host can report why a provider rejected the call. */
139
139
  status: Schema.optionalKey(Schema.Int)
140
140
  });
141
+ const Failure = Schema.Union([
142
+ ActionHandlerError,
143
+ RetryableActionHandlerError,
144
+ RuntimeFailure
145
+ ]);
141
146
  const Response = Schema.Union([Schema.TaggedStruct("success", {
142
147
  identity: Identity,
143
148
  value: Schema.optionalKey(Schema.Json)
@@ -146,6 +151,7 @@ const Response = Schema.Union([Schema.TaggedStruct("success", {
146
151
  identity: Identity
147
152
  })]);
148
153
  function failure(error) {
154
+ if (Schema.is(ActionHandlerError)(error) || Schema.is(RetryableActionHandlerError)(error)) return error;
149
155
  if (Schema.is(ChannelError)(error)) return {
150
156
  category: "handler",
151
157
  channel: Option.match(Option.fromUndefinedOr(error.providerCode), {
@@ -159,7 +165,7 @@ function failure(error) {
159
165
  message: "Agent Channel operation failed",
160
166
  retryable: false
161
167
  };
162
- if (Schema.is(FileError)(error) || Schema.is(ActionHandlerError)(error) && Schema.is(FileError)(error.cause)) return {
168
+ if (Schema.is(FileError)(error)) return {
163
169
  category: "handler",
164
170
  code: "FileError",
165
171
  message: "A Dual Files operation failed",
@@ -172,16 +178,6 @@ function failure(error) {
172
178
  message: "Plugin action validation failed",
173
179
  retryable: false
174
180
  };
175
- if (Schema.is(RetryableActionHandlerError)(error)) return {
176
- category: "handler",
177
- code: error._tag,
178
- message: "Plugin handler failed",
179
- retryable: true,
180
- ...Option.match(Option.fromUndefinedOr(error.retryAfterSeconds), {
181
- onNone: () => ({}),
182
- onSome: (seconds) => ({ retryAfterSeconds: seconds })
183
- })
184
- };
185
181
  const tag = Predicate.hasProperty(error, "_tag") && Predicate.isString(error._tag) ? error._tag : "PluginHandlerError";
186
182
  return {
187
183
  category: pipe(Match.value(tag), Match.when("SchemaError", () => "validation"), Match.whenOr("InvalidTriggerConfigError", "InvalidTriggerStateError", "InvalidTriggerOutputError", () => "validation"), Match.whenOr("ConnectionRequiredError", "InvalidConnectionIdError", "InvalidResolvedConnectionError", "ConnectionIdNotAllowedError", "AuthMethodNotFoundError", "AuthMethodHookError", "ExpectedOAuth2MethodError", "OAuth2RefreshTokenUnavailableError", () => "connection"), Match.orElse(() => "handler")),
@@ -200,7 +196,6 @@ function failure(error) {
200
196
  "OAuth2RefreshTokenUnavailableError",
201
197
  "ActionNotFoundError",
202
198
  "ActionHandlerNotFoundError",
203
- "ActionHandlerError",
204
199
  "TriggerNotFoundError",
205
200
  "UnsupportedTriggerRuntimeError",
206
201
  "FileError",
@@ -208,8 +203,7 @@ function failure(error) {
208
203
  "SandboxRequestNotAllowedError"
209
204
  ], tag) ? tag : "PluginHandlerError",
210
205
  message: "Plugin operation failed",
211
- retryable: false,
212
- ...Schema.is(ActionHandlerError)(error) && Schema.is(Schema.Int)(error.status) ? { status: error.status } : {}
206
+ retryable: false
213
207
  };
214
208
  }
215
209
  const unavailableFiles = Service$2.of({