@dual-os/sdk 0.9.2 → 0.11.0

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.
@@ -184,6 +184,7 @@ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
184
184
  if (command.kind === "deliver" && !checkDelivery(definition.features, command)) return yield* fail("unsupported_feature");
185
185
  if (command.kind === "deliver" && command.operation.kind === "set_reaction" && command.operation.target.kind === "activation" && command.activationMessageKey === void 0) return yield* fail("invalid_input");
186
186
  if (command.kind === "read_context" && (definition.features.readContext !== true || !checkMessage(definition.features, command.destination, { text: "" }))) return yield* fail("unsupported_feature");
187
+ if (command.kind === "read_asset" && !definition.features.assets || command.kind === "read_sender" && definition.features.readSender !== true) return yield* fail("unsupported_feature");
187
188
  const handler = Option.fromNullishOr(findHandler(context, found.provider.identifier, handlerKey(request.channelId)));
188
189
  if (Option.isNone(handler)) return yield* fail("handler_unavailable");
189
190
  const auth = yield* resolveAuth(found.provider.identifier, request.channelId, definition, request.connectionId, command.kind, request.context);
@@ -191,6 +192,7 @@ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
191
192
  const kind = command.kind;
192
193
  const deliveryKey = command.kind === "deliver" ? command.deliveryKey : void 0;
193
194
  const assetKey = command.kind === "read_asset" ? command.asset.assetKey : void 0;
195
+ const senderKey = command.kind === "read_sender" ? command.identity.senderKey : void 0;
194
196
  const adapterContext = {
195
197
  definitionSettings,
196
198
  deploymentSettings,
@@ -198,8 +200,7 @@ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
198
200
  };
199
201
  if (!Predicate.isFunction(handler.value.runtime.execute) || !Predicate.isFunction(handler.value.runtime.verify) || !Predicate.isFunction(handler.value.runtime.checkAccess)) return yield* fail("handler_unavailable");
200
202
  if (command.kind === "receive") yield* decodeData(Verification, yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext))), "invalid_result");
201
- if (command.kind === "read_asset") {
202
- if (!definition.features.assets) return yield* fail("unsupported_feature");
203
+ if (command.kind === "read_asset" || command.kind === "read_sender") {
203
204
  if ((yield* decodeData(AccessOutcome, yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.checkAccess(command.identity, adapterContext))), "invalid_result")).decision !== "allow") return yield* new ChannelError({
204
205
  code: "provider_failure",
205
206
  providerCode: "unauthorized"
@@ -207,7 +208,7 @@ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
207
208
  }
208
209
  const output = yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)));
209
210
  const result = yield* decodeData(resultSchema(Schema.toType(definition.state), definition.features), output, "invalid_result", kind === "read_asset");
210
- if (result.kind !== kind || result.operationKey !== operationKey || result.kind === "deliver" && result.deliveryKey !== deliveryKey || result.kind === "read_asset" && result.assetKey !== assetKey) return yield* fail("invalid_result");
211
+ if (result.kind !== kind || result.operationKey !== operationKey || result.kind === "deliver" && result.deliveryKey !== deliveryKey || result.kind === "read_asset" && result.assetKey !== assetKey || result.kind === "read_sender" && result.senderKey !== senderKey) return yield* fail("invalid_result");
211
212
  yield* checkExtensions(definition, result.extensions, "invalid_result");
212
213
  if (result.kind === "deliver" && result.status === "pending" && !definition.features.deliveryState) return yield* fail("invalid_result");
213
214
  const allowedEvents = [];
@@ -1 +1 @@
1
- {"version":3,"file":"AgentChannelRuntime.js","names":["AgentChannel.Key","AgentChannel.VerifiedIdentity","AgentChannel.ChannelError","AgentChannel.resultByteLimit","AgentChannel.FailureCode","ConnectionResolver.Service","AgentChannel.handlerKey","AgentChannel.AccessOutcome","AgentChannel.commandSchema","AgentChannel.Verification","AgentChannel.resultSchema","AgentChannel.CheckedResult"],"sources":["../src/AgentChannelRuntime.ts"],"sourcesContent":["/** Checked execution of pinned Agent Channel capabilities. No product lifecycle or persistence. */\nimport { Cause, Context, Effect, Layer, Option, Predicate, Schema } from \"effect\";\n\nimport * as AgentChannel from \"./AgentChannel.ts\";\nimport { ConnectionResolver } from \"./ConnectionResolver.ts\";\nimport type { AuthResolutionRequirements } from \"./internal/auth-execution.ts\";\nimport { findHandler } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\n\n/** Host-only connection authority context. It is never included in handler inputs. */\nexport const ConnectionContext = Schema.Struct({\n actor: Schema.optionalKey(\n Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"user\"), userId: AgentChannel.Key }),\n Schema.Struct({\n kind: Schema.Literal(\"system\"),\n reason: Schema.optionalKey(AgentChannel.Key),\n }),\n ]),\n ),\n source: Schema.optionalKey(\n Schema.Struct({ kind: AgentChannel.Key, subjectId: Schema.optionalKey(AgentChannel.Key) }),\n ),\n tenant: Schema.optionalKey(\n Schema.Struct({ organizationId: AgentChannel.Key, teamId: AgentChannel.Key }),\n ),\n});\nconst Pin = Schema.Struct({ channelId: AgentChannel.Key });\nconst Input = Schema.Struct({\n ...Pin.fields,\n command: Schema.Unknown,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n});\nconst AccessInput = Schema.Struct({\n ...Pin.fields,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n identity: AgentChannel.VerifiedIdentity,\n});\nexport type Pin = typeof Pin.Type;\nexport type Input = typeof Input.Type;\nexport interface Interface {\n /** Reauthorize an already verified identity; does not verify a transport or execute provider operations. */\n readonly checkAccess: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.AccessOutcome, AgentChannel.ChannelError>;\n readonly get: (pin: unknown) => Effect.Effect<AgentChannel.Definition, AgentChannel.ChannelError>;\n readonly decodeDefinitionSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly decodeDeploymentSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly execute: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.CheckedResult, AgentChannel.ChannelError>;\n}\nexport class Service extends Context.Service<Service, Interface>()(\n \"@dual-os/sdk/AgentChannelRuntime\",\n) {}\n\ntype Definitions<P extends Plugin.Any> = P[\"agentChannels\"][number][\"definition\"];\ntype ChannelHandlers<P extends Plugin.Any, C> = C extends AgentChannel.Any\n ? AgentChannel.Handler<`${P[\"identifier\"]}/${C[\"identifier\"]}`>\n : never;\ntype PluginHandlers<P> = P extends Plugin.Any\n ? ChannelHandlers<P, P[\"agentChannels\"][number]>\n : never;\ntype ExtensionRequirements<D> = D extends {\n readonly extensions: infer Extensions extends Readonly<Record<string, Schema.Top>>;\n}\n ?\n | Extensions[keyof Extensions][\"DecodingServices\"]\n | Extensions[keyof Extensions][\"EncodingServices\"]\n : never;\nexport type Requirements<P extends Plugin.Any> =\n | PluginHandlers<P>\n | ExtensionRequirements<Definitions<P>>\n | Definitions<P>[\"definitionSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"deploymentSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"EncodingServices\"]\n | AuthResolutionRequirements<Definitions<P>[\"authMethods\"]>\n | (Definitions<P>[\"authMethods\"][number] extends never ? never : ConnectionResolver.Service);\n\nconst fail = (code: typeof AgentChannel.ErrorCode.Type) => new AgentChannel.ChannelError({ code });\nconst safe = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n code: typeof AgentChannel.ErrorCode.Type,\n): Effect.Effect<A, AgentChannel.ChannelError, R> =>\n effect.pipe(\n Effect.catchCause(cause =>\n Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.fail(fail(code)),\n ),\n );\nconst AssetResultJson = Schema.Json.check(\n Schema.makeFilter(\n value => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 14_680_064,\n ),\n);\nconst Json = Schema.Json.check(\n Schema.makeFilter(\n value =>\n new TextEncoder().encode(JSON.stringify(value)).byteLength <= AgentChannel.resultByteLimit,\n ),\n);\nconst strict = { onExcessProperty: \"error\" } as const;\nconst decode = <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n) =>\n safe(\n Effect.suspend(() => Schema.decodeUnknownEffect(schema)(input, strict)),\n code,\n );\nconst json = (value: unknown, code: typeof AgentChannel.ErrorCode.Type) =>\n decode(Json, value, code);\nconst decodeData = Effect.fn(\"AgentChannelRuntime.decodeData\")(function* <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n largeAssetResult = false,\n) {\n const boundary = largeAssetResult ? AssetResultJson : Json;\n yield* decode(boundary, input, code);\n const value = yield* decode(schema, input, code);\n yield* decode(boundary, value, code);\n return value;\n});\n\nconst invokeHandler = (\n handler: AgentChannel.Handler,\n effect: Effect.Effect<unknown, unknown, unknown>,\n) =>\n effect.pipe(\n Effect.provideContext(handler.context),\n Effect.catch(error =>\n decode(\n Schema.TaggedStruct(\"AgentChannelHandlerError\", { code: AgentChannel.FailureCode }),\n Predicate.isObject(error) ? { ...error } : error,\n \"provider_failure\",\n ).pipe(\n Effect.flatMap(checked =>\n Effect.fail(\n new AgentChannel.ChannelError({ code: \"provider_failure\", providerCode: checked.code }),\n ),\n ),\n ),\n ),\n Effect.catchCause(cause => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n const error = Cause.findErrorOption(cause);\n return Option.isSome(error) && error.value instanceof AgentChannel.ChannelError\n ? Effect.fail(error.value)\n : Effect.fail(fail(\"provider_failure\"));\n }),\n );\n\nconst checkExtensions = Effect.fn(\"AgentChannelRuntime.checkExtensions\")(function* (\n definition: AgentChannel.Definition,\n extensions: Readonly<Record<string, Schema.Json>> | undefined,\n code: typeof AgentChannel.ErrorCode.Type,\n) {\n for (const [key, value] of Object.entries(extensions ?? {})) {\n const schema = definition.extensions?.[key];\n if (schema === undefined) return yield* fail(code);\n // Extensions are checked values, not a provider payload escape hatch. No normalization.\n yield* decodeData(Schema.toType(schema), value, code);\n }\n});\nconst checkMessage = (\n features: AgentChannel.Features,\n destination: AgentChannel.Destination,\n content: AgentChannel.Content,\n): boolean =>\n (destination.kind === \"direct\" || features.groups) &&\n (destination.threadKey === undefined || features.threads) &&\n (content.mentions === undefined || features.mentions) &&\n (content.assets === undefined || features.assets) &&\n (content.replyToMessageKey === undefined || features.replies);\n\nconst checkDelivery = (\n features: AgentChannel.Features,\n command: Extract<AgentChannel.Command, { kind: \"deliver\" }>,\n): boolean =>\n checkMessage(features, command.destination, { text: \"\" }) &&\n (features.operations ?? []).includes(command.operation.kind);\n\nconst Material = Schema.Struct({\n connectionId: AgentChannel.Key,\n // The plugin worker's resolver marks its JSON-carried material.\n encoding: Schema.optionalKey(Schema.Literal(\"json\")),\n material: Schema.Unknown,\n methodId: AgentChannel.Key,\n providerId: AgentChannel.Key,\n setup: Schema.Unknown,\n});\nconst ResolveHook = Schema.declare(\n (value): value is (material: unknown, context: { readonly setup: unknown }) => unknown =>\n Predicate.isFunction(value),\n);\nconst resolveAuth = Effect.fn(\"AgentChannelRuntime.resolveAuth\")(function* (\n providerId: string,\n channelId: string,\n definition: AgentChannel.Definition,\n connectionId: string | undefined,\n phase: string,\n context: typeof ConnectionContext.Type | undefined,\n) {\n if (definition.authMethods.length === 0) {\n if (connectionId !== undefined) return yield* fail(\"invalid_auth\");\n return undefined;\n }\n // The host alone selects/authorizes the pinned connection. Its records never reach the plugin.\n if (connectionId === undefined) return yield* fail(\"invalid_auth\");\n const resolver = yield* Effect.serviceOption(ConnectionResolver.Service);\n if (Option.isNone(resolver)) return yield* fail(\"invalid_auth\");\n const raw = yield* safe(\n Effect.suspend(() =>\n resolver.value.resolve({\n connectionId,\n target: { phase, providerId, targetId: channelId, targetKind: \"agent-channel\" },\n ...(context === undefined ? {} : { context }),\n }),\n ),\n \"invalid_auth\",\n );\n const resolved = yield* decode(Material, raw, \"invalid_auth\");\n if (resolved.providerId !== providerId || resolved.connectionId !== connectionId) {\n return yield* fail(\"invalid_auth\");\n }\n const method = definition.authMethods.find(\n method =>\n resolved.methodId === method.identifier ||\n resolved.methodId === `${providerId}/${method.identifier}`,\n );\n if (method === undefined) return yield* fail(\"invalid_auth\");\n // Material the worker received as JSON decodes through each schema's JSON codec.\n const decodeAuth = <S extends Schema.Top>(schema: S, value: unknown) =>\n decode(\n resolved.encoding === \"json\" ? Schema.toCodecJson(schema) : schema,\n value,\n \"invalid_auth\",\n );\n const setup =\n method.setup === undefined\n ? yield* decode(Schema.Undefined, resolved.setup, \"invalid_auth\")\n : yield* decodeAuth(method.setup, resolved.setup);\n const material = yield* decodeAuth(method.material, resolved.material);\n let value: unknown;\n if (method.resolve === undefined) {\n value =\n method.material === method.value\n ? material\n : yield* decode(method.value, material, \"invalid_auth\");\n } else {\n const hook = yield* decode(ResolveHook, method.resolve, \"invalid_auth\");\n const output = yield* safe(\n Effect.suspend(() => {\n const result = hook(material, { setup });\n return Effect.isEffect(result) ? result : Effect.succeed(result);\n }),\n \"invalid_auth\",\n );\n value = yield* decode(method.value, output, \"invalid_auth\");\n }\n // Schemas may use Redacted for auth. Only this checked value, never material/setup/binding,\n // is exposed to the command handler.\n return { methodId: method.identifier, value };\n});\n\nconst find = (plugins: readonly Plugin.Any[], pin: Pin) => {\n for (const provider of plugins) {\n const channel = provider.agentChannels.find(\n channel => `${provider.identifier}/${channel.identifier}` === pin.channelId,\n );\n if (channel !== undefined) return { definition: channel.definition, provider };\n }\n return undefined;\n};\n\n/** Build from the installed plugins. */\nexport const layer = <P extends Plugin.Any>(\n plugins: readonly P[],\n): Layer.Layer<Service, never, Requirements<P>> =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const context = yield* Effect.context<Requirements<P>>();\n const get = Effect.fn(\"AgentChannelRuntime.get\")(function* (input: unknown) {\n const pin = yield* decode(Pin, input, \"invalid_input\");\n const found = find(plugins, pin);\n if (found === undefined) return yield* fail(\"not_found\");\n yield* safe(\n Effect.sync(() => {\n AgentChannel.validateDefinition(\n found.definition,\n found.provider.identifier,\n found.provider.authMethods,\n );\n }),\n \"invalid_definition\",\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(pin.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (\n Option.isNone(handler) ||\n !Predicate.isObject(handler.value.runtime) ||\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n return found.definition;\n });\n const checkAccess = Effect.fn(\"AgentChannelRuntime.checkAccess\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(AccessInput, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n if (!checkMessage(definition.features, request.identity.conversation, { text: \"\" })) {\n return yield* fail(\"unsupported_feature\");\n }\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n \"check_access\",\n request.context,\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(request.identity, {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n }),\n ),\n );\n return yield* decodeData(AgentChannel.AccessOutcome, output, \"invalid_result\");\n });\n const execute = Effect.fn(\"AgentChannelRuntime.execute\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(Input, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n const command: AgentChannel.Command = yield* decodeData(\n AgentChannel.commandSchema(definition.state),\n request.command,\n \"invalid_input\",\n );\n yield* checkExtensions(definition, command.extensions, \"invalid_input\");\n if (command.kind === \"deliver\" && command.operationKey !== command.deliveryKey) {\n return yield* fail(\"invalid_input\");\n }\n if (command.kind === \"deliver\" && !checkDelivery(definition.features, command)) {\n return yield* fail(\"unsupported_feature\");\n }\n if (\n command.kind === \"deliver\" &&\n command.operation.kind === \"set_reaction\" &&\n command.operation.target.kind === \"activation\" &&\n command.activationMessageKey === undefined\n ) {\n return yield* fail(\"invalid_input\");\n }\n if (\n command.kind === \"read_context\" &&\n (definition.features.readContext !== true ||\n !checkMessage(definition.features, command.destination, { text: \"\" }))\n ) {\n return yield* fail(\"unsupported_feature\");\n }\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n command.kind,\n request.context,\n );\n // Keep correlation facts independent of any mutation by provider code.\n const operationKey = command.operationKey;\n const kind = command.kind;\n const deliveryKey = command.kind === \"deliver\" ? command.deliveryKey : undefined;\n const assetKey = command.kind === \"read_asset\" ? command.asset.assetKey : undefined;\n const adapterContext = {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n };\n if (\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n if (command.kind === \"receive\") {\n yield* decodeData(\n AgentChannel.Verification,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext)),\n ),\n \"invalid_result\",\n );\n }\n if (command.kind === \"read_asset\") {\n if (!definition.features.assets) return yield* fail(\"unsupported_feature\");\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(command.identity, adapterContext),\n ),\n ),\n \"invalid_result\",\n );\n if (decision.decision !== \"allow\") {\n return yield* new AgentChannel.ChannelError({\n code: \"provider_failure\",\n providerCode: \"unauthorized\",\n });\n }\n }\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)),\n );\n const result: AgentChannel.Result = yield* decodeData(\n AgentChannel.resultSchema(Schema.toType(definition.state), definition.features),\n output,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n if (\n result.kind !== kind ||\n result.operationKey !== operationKey ||\n (result.kind === \"deliver\" && result.deliveryKey !== deliveryKey) ||\n (result.kind === \"read_asset\" && result.assetKey !== assetKey)\n ) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, result.extensions, \"invalid_result\");\n if (\n result.kind === \"deliver\" &&\n result.status === \"pending\" &&\n !definition.features.deliveryState\n ) {\n return yield* fail(\"invalid_result\");\n }\n const allowedEvents: AgentChannel.Event[] = [];\n const deniedEventKeys: string[] = [];\n if (result.kind === \"receive\") {\n if (result.deniedEventKeys !== undefined) return yield* fail(\"invalid_result\");\n if (\n result.activationProof === \"verified\" &&\n (result.response === undefined || result.events.length !== 0)\n ) {\n return yield* fail(\"invalid_result\");\n }\n const eventKeys = new Set<string>();\n for (const event of result.events) {\n if (eventKeys.has(event.eventKey)) return yield* fail(\"invalid_result\");\n eventKeys.add(event.eventKey);\n if (\n event.kind === \"message\" &&\n !checkMessage(definition.features, event.conversation, event.content)\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (\n (event.kind === \"echo\" || event.kind === \"stop\") &&\n !checkMessage(definition.features, event.conversation, { text: \"\" })\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (event.kind === \"delivery_update\" && !definition.features.deliveryState) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, event.extensions, \"invalid_result\");\n let denied = false;\n if (event.kind === \"message\" || event.kind === \"echo\" || event.kind === \"stop\") {\n const identity = yield* decodeData(\n AgentChannel.VerifiedIdentity,\n { conversation: event.conversation, senderKey: event.senderKey },\n \"invalid_result\",\n );\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.checkAccess(identity, adapterContext)),\n ),\n \"invalid_result\",\n );\n denied = decision.decision === \"deny\";\n }\n if (denied) {\n deniedEventKeys.push(event.eventKey);\n continue;\n }\n allowedEvents.push(event);\n }\n }\n // Store the encoded state so subsequent pinned commands can decode it exactly once.\n const encoded = yield* safe(\n Schema.encodeUnknownEffect(\n AgentChannel.resultSchema(definition.state, definition.features),\n )(\n result.kind === \"receive\"\n ? {\n ...result,\n events: allowedEvents,\n ...(deniedEventKeys.length === 0 ? {} : { deniedEventKeys }),\n }\n : result,\n strict,\n ),\n \"invalid_result\",\n );\n return yield* decodeData(\n AgentChannel.CheckedResult,\n encoded,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n });\n // SAFETY: Requirements above account for each schema, auth method and Channel handler. The\n // dynamic lookup erases their union; the captured application context discharges it here.\n const run = <A>(\n effect: Effect.Effect<A, AgentChannel.ChannelError, unknown>,\n ): Effect.Effect<A, AgentChannel.ChannelError> =>\n // @effect-diagnostics-next-line unsafeEffectTypeAssertion:off -- Channel handlers are checked and their captured context satisfies the declared Requirements (SAFETY above).\n effect.pipe(Effect.provideContext(context)) as Effect.Effect<A, AgentChannel.ChannelError>;\n const decodeSettings = (field: \"definitionSettings\" | \"deploymentSettings\") =>\n Effect.fn(\"AgentChannelRuntime.decodeSettings\")(function* (input: unknown) {\n const request = yield* decode(\n Schema.Struct({ ...Pin.fields, value: Schema.Json }),\n input,\n \"invalid_input\",\n );\n const definition = yield* get({ channelId: request.channelId });\n const schema = definition[field];\n const value = yield* decodeData(schema, request.value, \"invalid_input\");\n return yield* json(\n yield* safe(Schema.encodeUnknownEffect(schema)(value, strict), \"invalid_input\"),\n \"invalid_input\",\n );\n });\n return Service.of({\n checkAccess: input => run(checkAccess(input)),\n decodeDefinitionSettings: input => run(decodeSettings(\"definitionSettings\")(input)),\n decodeDeploymentSettings: input => run(decodeSettings(\"deploymentSettings\")(input)),\n execute: input => run(execute(input)),\n get: input => run(get(input)),\n });\n }),\n );\n\nexport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,OAAO,OAAO,YACZ,OAAO,MAAM,CACX,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,MAAM;EAAG,QAAQA;CAAiB,CAAC,GACxE,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,QAAQ;EAC7B,QAAQ,OAAO,YAAYA,GAAgB;CAC7C,CAAC,CACH,CAAC,CACH;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,MAAMA;EAAkB,WAAW,OAAO,YAAYA,GAAgB;CAAE,CAAC,CAC3F;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,gBAAgBA;EAAkB,QAAQA;CAAiB,CAAC,CAC9E;AACF,CAAC;AACD,MAAM,MAAM,OAAO,OAAO,EAAE,WAAWA,IAAiB,CAAC;AACzD,MAAM,QAAQ,OAAO,OAAO;CAC1B,GAAG,IAAI;CACP,SAAS,OAAO;CAChB,cAAc,OAAO,YAAYA,GAAgB;CACjD,SAAS,OAAO,YAAY,iBAAiB;CAC7C,oBAAoB,OAAO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KAAK,CAAC;EAC5C,2BAA0B,UAAS,IAAI,eAAe,oBAAoB,CAAC,CAAC,KAAK,CAAC;EAClF,2BAA0B,UAAS,IAAI,eAAe,oBAAoB,CAAC,CAAC,KAAK,CAAC;EAClF,UAAS,UAAS,IAAI,QAAQ,KAAK,CAAC;EACpC,MAAK,UAAS,IAAI,IAAI,KAAK,CAAC;CAC9B,CAAC;AACH,CAAC,CACH"}
1
+ {"version":3,"file":"AgentChannelRuntime.js","names":["AgentChannel.Key","AgentChannel.VerifiedIdentity","AgentChannel.ChannelError","AgentChannel.resultByteLimit","AgentChannel.FailureCode","ConnectionResolver.Service","AgentChannel.handlerKey","AgentChannel.AccessOutcome","AgentChannel.commandSchema","AgentChannel.Verification","AgentChannel.resultSchema","AgentChannel.CheckedResult"],"sources":["../src/AgentChannelRuntime.ts"],"sourcesContent":["/** Checked execution of pinned Agent Channel capabilities. No product lifecycle or persistence. */\nimport { Cause, Context, Effect, Layer, Option, Predicate, Schema } from \"effect\";\n\nimport * as AgentChannel from \"./AgentChannel.ts\";\nimport { ConnectionResolver } from \"./ConnectionResolver.ts\";\nimport type { AuthResolutionRequirements } from \"./internal/auth-execution.ts\";\nimport { findHandler } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\n\n/** Host-only connection authority context. It is never included in handler inputs. */\nexport const ConnectionContext = Schema.Struct({\n actor: Schema.optionalKey(\n Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"user\"), userId: AgentChannel.Key }),\n Schema.Struct({\n kind: Schema.Literal(\"system\"),\n reason: Schema.optionalKey(AgentChannel.Key),\n }),\n ]),\n ),\n source: Schema.optionalKey(\n Schema.Struct({ kind: AgentChannel.Key, subjectId: Schema.optionalKey(AgentChannel.Key) }),\n ),\n tenant: Schema.optionalKey(\n Schema.Struct({ organizationId: AgentChannel.Key, teamId: AgentChannel.Key }),\n ),\n});\nconst Pin = Schema.Struct({ channelId: AgentChannel.Key });\nconst Input = Schema.Struct({\n ...Pin.fields,\n command: Schema.Unknown,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n});\nconst AccessInput = Schema.Struct({\n ...Pin.fields,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n identity: AgentChannel.VerifiedIdentity,\n});\nexport type Pin = typeof Pin.Type;\nexport type Input = typeof Input.Type;\nexport interface Interface {\n /** Reauthorize an already verified identity; does not verify a transport or execute provider operations. */\n readonly checkAccess: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.AccessOutcome, AgentChannel.ChannelError>;\n readonly get: (pin: unknown) => Effect.Effect<AgentChannel.Definition, AgentChannel.ChannelError>;\n readonly decodeDefinitionSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly decodeDeploymentSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly execute: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.CheckedResult, AgentChannel.ChannelError>;\n}\nexport class Service extends Context.Service<Service, Interface>()(\n \"@dual-os/sdk/AgentChannelRuntime\",\n) {}\n\ntype Definitions<P extends Plugin.Any> = P[\"agentChannels\"][number][\"definition\"];\ntype ChannelHandlers<P extends Plugin.Any, C> = C extends AgentChannel.Any\n ? AgentChannel.Handler<`${P[\"identifier\"]}/${C[\"identifier\"]}`>\n : never;\ntype PluginHandlers<P> = P extends Plugin.Any\n ? ChannelHandlers<P, P[\"agentChannels\"][number]>\n : never;\ntype ExtensionRequirements<D> = D extends {\n readonly extensions: infer Extensions extends Readonly<Record<string, Schema.Top>>;\n}\n ?\n | Extensions[keyof Extensions][\"DecodingServices\"]\n | Extensions[keyof Extensions][\"EncodingServices\"]\n : never;\nexport type Requirements<P extends Plugin.Any> =\n | PluginHandlers<P>\n | ExtensionRequirements<Definitions<P>>\n | Definitions<P>[\"definitionSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"deploymentSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"EncodingServices\"]\n | AuthResolutionRequirements<Definitions<P>[\"authMethods\"]>\n | (Definitions<P>[\"authMethods\"][number] extends never ? never : ConnectionResolver.Service);\n\nconst fail = (code: typeof AgentChannel.ErrorCode.Type) => new AgentChannel.ChannelError({ code });\nconst safe = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n code: typeof AgentChannel.ErrorCode.Type,\n): Effect.Effect<A, AgentChannel.ChannelError, R> =>\n effect.pipe(\n Effect.catchCause(cause =>\n Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.fail(fail(code)),\n ),\n );\nconst AssetResultJson = Schema.Json.check(\n Schema.makeFilter(\n value => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 14_680_064,\n ),\n);\nconst Json = Schema.Json.check(\n Schema.makeFilter(\n value =>\n new TextEncoder().encode(JSON.stringify(value)).byteLength <= AgentChannel.resultByteLimit,\n ),\n);\nconst strict = { onExcessProperty: \"error\" } as const;\nconst decode = <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n) =>\n safe(\n Effect.suspend(() => Schema.decodeUnknownEffect(schema)(input, strict)),\n code,\n );\nconst json = (value: unknown, code: typeof AgentChannel.ErrorCode.Type) =>\n decode(Json, value, code);\nconst decodeData = Effect.fn(\"AgentChannelRuntime.decodeData\")(function* <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n largeAssetResult = false,\n) {\n const boundary = largeAssetResult ? AssetResultJson : Json;\n yield* decode(boundary, input, code);\n const value = yield* decode(schema, input, code);\n yield* decode(boundary, value, code);\n return value;\n});\n\nconst invokeHandler = (\n handler: AgentChannel.Handler,\n effect: Effect.Effect<unknown, unknown, unknown>,\n) =>\n effect.pipe(\n Effect.provideContext(handler.context),\n Effect.catch(error =>\n decode(\n Schema.TaggedStruct(\"AgentChannelHandlerError\", { code: AgentChannel.FailureCode }),\n Predicate.isObject(error) ? { ...error } : error,\n \"provider_failure\",\n ).pipe(\n Effect.flatMap(checked =>\n Effect.fail(\n new AgentChannel.ChannelError({ code: \"provider_failure\", providerCode: checked.code }),\n ),\n ),\n ),\n ),\n Effect.catchCause(cause => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n const error = Cause.findErrorOption(cause);\n return Option.isSome(error) && error.value instanceof AgentChannel.ChannelError\n ? Effect.fail(error.value)\n : Effect.fail(fail(\"provider_failure\"));\n }),\n );\n\nconst checkExtensions = Effect.fn(\"AgentChannelRuntime.checkExtensions\")(function* (\n definition: AgentChannel.Definition,\n extensions: Readonly<Record<string, Schema.Json>> | undefined,\n code: typeof AgentChannel.ErrorCode.Type,\n) {\n for (const [key, value] of Object.entries(extensions ?? {})) {\n const schema = definition.extensions?.[key];\n if (schema === undefined) return yield* fail(code);\n // Extensions are checked values, not a provider payload escape hatch. No normalization.\n yield* decodeData(Schema.toType(schema), value, code);\n }\n});\nconst checkMessage = (\n features: AgentChannel.Features,\n destination: AgentChannel.Destination,\n content: AgentChannel.Content,\n): boolean =>\n (destination.kind === \"direct\" || features.groups) &&\n (destination.threadKey === undefined || features.threads) &&\n (content.mentions === undefined || features.mentions) &&\n (content.assets === undefined || features.assets) &&\n (content.replyToMessageKey === undefined || features.replies);\n\nconst checkDelivery = (\n features: AgentChannel.Features,\n command: Extract<AgentChannel.Command, { kind: \"deliver\" }>,\n): boolean =>\n checkMessage(features, command.destination, { text: \"\" }) &&\n (features.operations ?? []).includes(command.operation.kind);\n\nconst Material = Schema.Struct({\n connectionId: AgentChannel.Key,\n // The plugin worker's resolver marks its JSON-carried material.\n encoding: Schema.optionalKey(Schema.Literal(\"json\")),\n material: Schema.Unknown,\n methodId: AgentChannel.Key,\n providerId: AgentChannel.Key,\n setup: Schema.Unknown,\n});\nconst ResolveHook = Schema.declare(\n (value): value is (material: unknown, context: { readonly setup: unknown }) => unknown =>\n Predicate.isFunction(value),\n);\nconst resolveAuth = Effect.fn(\"AgentChannelRuntime.resolveAuth\")(function* (\n providerId: string,\n channelId: string,\n definition: AgentChannel.Definition,\n connectionId: string | undefined,\n phase: string,\n context: typeof ConnectionContext.Type | undefined,\n) {\n if (definition.authMethods.length === 0) {\n if (connectionId !== undefined) return yield* fail(\"invalid_auth\");\n return undefined;\n }\n // The host alone selects/authorizes the pinned connection. Its records never reach the plugin.\n if (connectionId === undefined) return yield* fail(\"invalid_auth\");\n const resolver = yield* Effect.serviceOption(ConnectionResolver.Service);\n if (Option.isNone(resolver)) return yield* fail(\"invalid_auth\");\n const raw = yield* safe(\n Effect.suspend(() =>\n resolver.value.resolve({\n connectionId,\n target: { phase, providerId, targetId: channelId, targetKind: \"agent-channel\" },\n ...(context === undefined ? {} : { context }),\n }),\n ),\n \"invalid_auth\",\n );\n const resolved = yield* decode(Material, raw, \"invalid_auth\");\n if (resolved.providerId !== providerId || resolved.connectionId !== connectionId) {\n return yield* fail(\"invalid_auth\");\n }\n const method = definition.authMethods.find(\n method =>\n resolved.methodId === method.identifier ||\n resolved.methodId === `${providerId}/${method.identifier}`,\n );\n if (method === undefined) return yield* fail(\"invalid_auth\");\n // Material the worker received as JSON decodes through each schema's JSON codec.\n const decodeAuth = <S extends Schema.Top>(schema: S, value: unknown) =>\n decode(\n resolved.encoding === \"json\" ? Schema.toCodecJson(schema) : schema,\n value,\n \"invalid_auth\",\n );\n const setup =\n method.setup === undefined\n ? yield* decode(Schema.Undefined, resolved.setup, \"invalid_auth\")\n : yield* decodeAuth(method.setup, resolved.setup);\n const material = yield* decodeAuth(method.material, resolved.material);\n let value: unknown;\n if (method.resolve === undefined) {\n value =\n method.material === method.value\n ? material\n : yield* decode(method.value, material, \"invalid_auth\");\n } else {\n const hook = yield* decode(ResolveHook, method.resolve, \"invalid_auth\");\n const output = yield* safe(\n Effect.suspend(() => {\n const result = hook(material, { setup });\n return Effect.isEffect(result) ? result : Effect.succeed(result);\n }),\n \"invalid_auth\",\n );\n value = yield* decode(method.value, output, \"invalid_auth\");\n }\n // Schemas may use Redacted for auth. Only this checked value, never material/setup/binding,\n // is exposed to the command handler.\n return { methodId: method.identifier, value };\n});\n\nconst find = (plugins: readonly Plugin.Any[], pin: Pin) => {\n for (const provider of plugins) {\n const channel = provider.agentChannels.find(\n channel => `${provider.identifier}/${channel.identifier}` === pin.channelId,\n );\n if (channel !== undefined) return { definition: channel.definition, provider };\n }\n return undefined;\n};\n\n/** Build from the installed plugins. */\nexport const layer = <P extends Plugin.Any>(\n plugins: readonly P[],\n): Layer.Layer<Service, never, Requirements<P>> =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const context = yield* Effect.context<Requirements<P>>();\n const get = Effect.fn(\"AgentChannelRuntime.get\")(function* (input: unknown) {\n const pin = yield* decode(Pin, input, \"invalid_input\");\n const found = find(plugins, pin);\n if (found === undefined) return yield* fail(\"not_found\");\n yield* safe(\n Effect.sync(() => {\n AgentChannel.validateDefinition(\n found.definition,\n found.provider.identifier,\n found.provider.authMethods,\n );\n }),\n \"invalid_definition\",\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(pin.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (\n Option.isNone(handler) ||\n !Predicate.isObject(handler.value.runtime) ||\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n return found.definition;\n });\n const checkAccess = Effect.fn(\"AgentChannelRuntime.checkAccess\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(AccessInput, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n if (!checkMessage(definition.features, request.identity.conversation, { text: \"\" })) {\n return yield* fail(\"unsupported_feature\");\n }\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n \"check_access\",\n request.context,\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(request.identity, {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n }),\n ),\n );\n return yield* decodeData(AgentChannel.AccessOutcome, output, \"invalid_result\");\n });\n const execute = Effect.fn(\"AgentChannelRuntime.execute\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(Input, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n const command: AgentChannel.Command = yield* decodeData(\n AgentChannel.commandSchema(definition.state),\n request.command,\n \"invalid_input\",\n );\n yield* checkExtensions(definition, command.extensions, \"invalid_input\");\n if (command.kind === \"deliver\" && command.operationKey !== command.deliveryKey) {\n return yield* fail(\"invalid_input\");\n }\n if (command.kind === \"deliver\" && !checkDelivery(definition.features, command)) {\n return yield* fail(\"unsupported_feature\");\n }\n if (\n command.kind === \"deliver\" &&\n command.operation.kind === \"set_reaction\" &&\n command.operation.target.kind === \"activation\" &&\n command.activationMessageKey === undefined\n ) {\n return yield* fail(\"invalid_input\");\n }\n if (\n command.kind === \"read_context\" &&\n (definition.features.readContext !== true ||\n !checkMessage(definition.features, command.destination, { text: \"\" }))\n ) {\n return yield* fail(\"unsupported_feature\");\n }\n if (\n (command.kind === \"read_asset\" && !definition.features.assets) ||\n (command.kind === \"read_sender\" && definition.features.readSender !== true)\n ) {\n return yield* fail(\"unsupported_feature\");\n }\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n command.kind,\n request.context,\n );\n // Keep correlation facts independent of any mutation by provider code.\n const operationKey = command.operationKey;\n const kind = command.kind;\n const deliveryKey = command.kind === \"deliver\" ? command.deliveryKey : undefined;\n const assetKey = command.kind === \"read_asset\" ? command.asset.assetKey : undefined;\n const senderKey = command.kind === \"read_sender\" ? command.identity.senderKey : undefined;\n const adapterContext = {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n };\n if (\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n if (command.kind === \"receive\") {\n yield* decodeData(\n AgentChannel.Verification,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext)),\n ),\n \"invalid_result\",\n );\n }\n // A read on behalf of a sender acts for that sender, so the sender must have access.\n if (command.kind === \"read_asset\" || command.kind === \"read_sender\") {\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(command.identity, adapterContext),\n ),\n ),\n \"invalid_result\",\n );\n if (decision.decision !== \"allow\") {\n return yield* new AgentChannel.ChannelError({\n code: \"provider_failure\",\n providerCode: \"unauthorized\",\n });\n }\n }\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)),\n );\n const result: AgentChannel.Result = yield* decodeData(\n AgentChannel.resultSchema(Schema.toType(definition.state), definition.features),\n output,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n if (\n result.kind !== kind ||\n result.operationKey !== operationKey ||\n (result.kind === \"deliver\" && result.deliveryKey !== deliveryKey) ||\n (result.kind === \"read_asset\" && result.assetKey !== assetKey) ||\n (result.kind === \"read_sender\" && result.senderKey !== senderKey)\n ) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, result.extensions, \"invalid_result\");\n if (\n result.kind === \"deliver\" &&\n result.status === \"pending\" &&\n !definition.features.deliveryState\n ) {\n return yield* fail(\"invalid_result\");\n }\n const allowedEvents: AgentChannel.Event[] = [];\n const deniedEventKeys: string[] = [];\n if (result.kind === \"receive\") {\n if (result.deniedEventKeys !== undefined) return yield* fail(\"invalid_result\");\n if (\n result.activationProof === \"verified\" &&\n (result.response === undefined || result.events.length !== 0)\n ) {\n return yield* fail(\"invalid_result\");\n }\n const eventKeys = new Set<string>();\n for (const event of result.events) {\n if (eventKeys.has(event.eventKey)) return yield* fail(\"invalid_result\");\n eventKeys.add(event.eventKey);\n if (\n event.kind === \"message\" &&\n !checkMessage(definition.features, event.conversation, event.content)\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (\n (event.kind === \"echo\" || event.kind === \"stop\") &&\n !checkMessage(definition.features, event.conversation, { text: \"\" })\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (event.kind === \"delivery_update\" && !definition.features.deliveryState) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, event.extensions, \"invalid_result\");\n let denied = false;\n if (event.kind === \"message\" || event.kind === \"echo\" || event.kind === \"stop\") {\n const identity = yield* decodeData(\n AgentChannel.VerifiedIdentity,\n { conversation: event.conversation, senderKey: event.senderKey },\n \"invalid_result\",\n );\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.checkAccess(identity, adapterContext)),\n ),\n \"invalid_result\",\n );\n denied = decision.decision === \"deny\";\n }\n if (denied) {\n deniedEventKeys.push(event.eventKey);\n continue;\n }\n allowedEvents.push(event);\n }\n }\n // Store the encoded state so subsequent pinned commands can decode it exactly once.\n const encoded = yield* safe(\n Schema.encodeUnknownEffect(\n AgentChannel.resultSchema(definition.state, definition.features),\n )(\n result.kind === \"receive\"\n ? {\n ...result,\n events: allowedEvents,\n ...(deniedEventKeys.length === 0 ? {} : { deniedEventKeys }),\n }\n : result,\n strict,\n ),\n \"invalid_result\",\n );\n return yield* decodeData(\n AgentChannel.CheckedResult,\n encoded,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n });\n // SAFETY: Requirements above account for each schema, auth method and Channel handler. The\n // dynamic lookup erases their union; the captured application context discharges it here.\n const run = <A>(\n effect: Effect.Effect<A, AgentChannel.ChannelError, unknown>,\n ): Effect.Effect<A, AgentChannel.ChannelError> =>\n // @effect-diagnostics-next-line unsafeEffectTypeAssertion:off -- Channel handlers are checked and their captured context satisfies the declared Requirements (SAFETY above).\n effect.pipe(Effect.provideContext(context)) as Effect.Effect<A, AgentChannel.ChannelError>;\n const decodeSettings = (field: \"definitionSettings\" | \"deploymentSettings\") =>\n Effect.fn(\"AgentChannelRuntime.decodeSettings\")(function* (input: unknown) {\n const request = yield* decode(\n Schema.Struct({ ...Pin.fields, value: Schema.Json }),\n input,\n \"invalid_input\",\n );\n const definition = yield* get({ channelId: request.channelId });\n const schema = definition[field];\n const value = yield* decodeData(schema, request.value, \"invalid_input\");\n return yield* json(\n yield* safe(Schema.encodeUnknownEffect(schema)(value, strict), \"invalid_input\"),\n \"invalid_input\",\n );\n });\n return Service.of({\n checkAccess: input => run(checkAccess(input)),\n decodeDefinitionSettings: input => run(decodeSettings(\"definitionSettings\")(input)),\n decodeDeploymentSettings: input => run(decodeSettings(\"deploymentSettings\")(input)),\n execute: input => run(execute(input)),\n get: input => run(get(input)),\n });\n }),\n );\n\nexport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,OAAO,OAAO,YACZ,OAAO,MAAM,CACX,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,MAAM;EAAG,QAAQA;CAAiB,CAAC,GACxE,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,QAAQ;EAC7B,QAAQ,OAAO,YAAYA,GAAgB;CAC7C,CAAC,CACH,CAAC,CACH;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,MAAMA;EAAkB,WAAW,OAAO,YAAYA,GAAgB;CAAE,CAAC,CAC3F;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,gBAAgBA;EAAkB,QAAQA;CAAiB,CAAC,CAC9E;AACF,CAAC;AACD,MAAM,MAAM,OAAO,OAAO,EAAE,WAAWA,IAAiB,CAAC;AACzD,MAAM,QAAQ,OAAO,OAAO;CAC1B,GAAG,IAAI;CACP,SAAS,OAAO;CAChB,cAAc,OAAO,YAAYA,GAAgB;CACjD,SAAS,OAAO,YAAY,iBAAiB;CAC7C,oBAAoB,OAAO;CAC3B,oBAAoB,OAAO;AAC7B,CAAC;AACD,MAAM,cAAc,OAAO,OAAO;CAChC,GAAG,IAAI;CACP,cAAc,OAAO,YAAYA,GAAgB;CACjD,SAAS,OAAO,YAAY,iBAAiB;CAC7C,oBAAoB,OAAO;CAC3B,oBAAoB,OAAO;CAC3B,UAAUC;AACZ,CAAC;AAmBD,IAAa,UAAb,cAA6B,QAAQ,QAA4B,CAAC,CAChE,kCACF,CAAC,CAAC,CAAC;AA0BH,MAAM,QAAQ,SAA6C,IAAIC,aAA0B,EAAE,KAAK,CAAC;AACjG,MAAM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AAK,CAAC;EACpC,MAAK,UAAS,IAAI,IAAI,KAAK,CAAC;CAC9B,CAAC;AACH,CAAC,CACH"}
package/dist/Files.d.ts CHANGED
@@ -39,7 +39,7 @@ declare const Service_base: Context.ServiceClass<Service, "@dual-os/sdk/Files/Se
39
39
  }) => Effect.Effect<File, FileError>;
40
40
  }>;
41
41
  /**
42
- * Reads and stores files for the caller of an action: a workflow run, or the person in a chat.
42
+ * Reads and stores files for the caller of an action, trigger or channel operation.
43
43
  *
44
44
  * @since 0.1.0
45
45
  * @category services
package/dist/Files.js CHANGED
@@ -35,13 +35,13 @@ var FileError = class extends Schema.TaggedError()("FileError", {
35
35
  message: Schema.String
36
36
  }) {};
37
37
  /**
38
- * Reads and stores files for the caller of an action: a workflow run, or the person in a chat.
38
+ * Reads and stores files for the caller of an action, trigger or channel operation.
39
39
  *
40
40
  * @since 0.1.0
41
41
  * @category services
42
42
  */
43
43
  var Service = class extends Context.Service()("@dual-os/sdk/Files/Service") {};
44
- const service = pipe(Effect.serviceOption(Service), Effect.flatMap(Effect.fromOption(() => FileError.make({ message: "Files are only available when Dual calls the action" }))));
44
+ const service = pipe(Effect.serviceOption(Service), Effect.flatMap(Effect.fromOption(() => FileError.make({ message: "Files are only available during a Dual plugin invocation" }))));
45
45
  /**
46
46
  * Reads a file's bytes through the caller's file service.
47
47
  *
package/dist/Files.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Files.js","names":[],"sources":["../src/Files.ts"],"sourcesContent":["/**\n * Files that actions take and return: a small reference in action data, with the bytes kept by the\n * host and read or written through the host's file service.\n *\n * @since 0.1.0\n */\nimport { Context, Effect, Schema, pipe } from \"effect\";\n\n/**\n * A file stored by the host. Action inputs and outputs carry this reference, never the bytes.\n *\n * @since 0.1.0\n * @category schemas\n */\nexport type File = typeof File.Type;\nexport const File = Schema.TaggedStruct(\"File\", {\n contentType: Schema.String,\n id: Schema.NonEmptyString,\n name: Schema.String,\n sizeBytes: Schema.Natural,\n}).annotate({\n description: \"A file: pass the reference a file input or an earlier step returned.\",\n});\n\n/**\n * A file the host could not read or keep. The message is safe for callers; an optional cause\n * retains the host failure in memory for trusted diagnostics. Wrap causes with Redacted.make\n * without a provider-derived label. JSON schema encoding of a cause is intentionally refused.\n *\n * @since 0.1.0\n * @category errors\n */\nexport class FileError extends Schema.TaggedError<FileError>()(\"FileError\", {\n cause: Schema.optionalKey(Schema.Redacted(Schema.Unknown, { disallowJsonEncode: true })),\n message: Schema.String,\n}) {}\n\n/**\n * Reads and stores files for the caller of an action: a workflow run, or the person in a chat.\n *\n * @since 0.1.0\n * @category services\n */\nexport class Service extends Context.Service<\n Service,\n {\n readonly read: (file: File) => Effect.Effect<Uint8Array, FileError>;\n readonly write: (file: {\n bytes: Uint8Array;\n name: string;\n // oxlint-disable-next-line typescript/no-restricted-types -- Hosts and existing callers may explicitly supply an absent content type.\n contentType?: string | null | undefined;\n }) => Effect.Effect<File, FileError>;\n }\n>()(\"@dual-os/sdk/Files/Service\") {}\n\n// Dual provides the service to each action call, so an action declares no requirement for it.\nconst service = pipe(\n Effect.serviceOption(Service),\n Effect.flatMap(\n Effect.fromOption(() =>\n FileError.make({ message: \"Files are only available when Dual calls the action\" }),\n ),\n ),\n);\n\n/**\n * Reads a file's bytes through the caller's file service.\n *\n * @since 0.1.0\n * @category files\n */\nexport const read = Effect.fnUntraced(function* (file: File) {\n return yield* (yield* service).read(file);\n});\n\n/**\n * Stores bytes as a new file of the caller and returns its reference.\n *\n * @since 0.1.0\n * @category files\n */\nexport const write = Effect.fnUntraced(function* (\n file: Parameters<Service[\"Service\"][\"write\"]>[0],\n) {\n return yield* (yield* service).write(file);\n});\n\nexport * as Files from \"./Files.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,OAAO,OAAO,aAAa,QAAQ;CAC9C,aAAa,OAAO;CACpB,IAAI,OAAO;CACX,MAAM,OAAO;CACb,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,SAAS,EACV,aAAa,uEACf,CAAC;;;;;;;;;AAUD,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa;CAC1E,OAAO,OAAO,YAAY,OAAO,SAAS,OAAO,SAAS,EAAE,oBAAoB,KAAK,CAAC,CAAC;CACvF,SAAS,OAAO;AAClB,CAAC,CAAC,CAAC,CAAC;;;;;;;AAQJ,IAAa,UAAb,cAA6B,QAAQ,QAWnC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC;AAGnC,MAAM,UAAU,KACd,OAAO,cAAc,OAAO,GAC5B,OAAO,QACL,OAAO,iBACL,UAAU,KAAK,EAAE,SAAS,sDAAsD,CAAC,CACnF,CACF,CACF;;;;;;;AAQA,MAAa,OAAO,OAAO,WAAW,WAAW,MAAY;CAC3D,OAAO,QAAQ,OAAO,QAAA,CAAS,KAAK,IAAI;AAC1C,CAAC;;;;;;;AAQD,MAAa,QAAQ,OAAO,WAAW,WACrC,MACA;CACA,OAAO,QAAQ,OAAO,QAAA,CAAS,MAAM,IAAI;AAC3C,CAAC"}
1
+ {"version":3,"file":"Files.js","names":[],"sources":["../src/Files.ts"],"sourcesContent":["/**\n * Files that actions take and return: a small reference in action data, with the bytes kept by the\n * host and read or written through the host's file service.\n *\n * @since 0.1.0\n */\nimport { Context, Effect, Schema, pipe } from \"effect\";\n\n/**\n * A file stored by the host. Action inputs and outputs carry this reference, never the bytes.\n *\n * @since 0.1.0\n * @category schemas\n */\nexport type File = typeof File.Type;\nexport const File = Schema.TaggedStruct(\"File\", {\n contentType: Schema.String,\n id: Schema.NonEmptyString,\n name: Schema.String,\n sizeBytes: Schema.Natural,\n}).annotate({\n description: \"A file: pass the reference a file input or an earlier step returned.\",\n});\n\n/**\n * A file the host could not read or keep. The message is safe for callers; an optional cause\n * retains the host failure in memory for trusted diagnostics. Wrap causes with Redacted.make\n * without a provider-derived label. JSON schema encoding of a cause is intentionally refused.\n *\n * @since 0.1.0\n * @category errors\n */\nexport class FileError extends Schema.TaggedError<FileError>()(\"FileError\", {\n cause: Schema.optionalKey(Schema.Redacted(Schema.Unknown, { disallowJsonEncode: true })),\n message: Schema.String,\n}) {}\n\n/**\n * Reads and stores files for the caller of an action, trigger or channel operation.\n *\n * @since 0.1.0\n * @category services\n */\nexport class Service extends Context.Service<\n Service,\n {\n readonly read: (file: File) => Effect.Effect<Uint8Array, FileError>;\n readonly write: (file: {\n bytes: Uint8Array;\n name: string;\n // oxlint-disable-next-line typescript/no-restricted-types -- Hosts and existing callers may explicitly supply an absent content type.\n contentType?: string | null | undefined;\n }) => Effect.Effect<File, FileError>;\n }\n>()(\"@dual-os/sdk/Files/Service\") {}\n\n// Dual provides the service to each action call, so an action declares no requirement for it.\nconst service = pipe(\n Effect.serviceOption(Service),\n Effect.flatMap(\n Effect.fromOption(() =>\n FileError.make({ message: \"Files are only available during a Dual plugin invocation\" }),\n ),\n ),\n);\n\n/**\n * Reads a file's bytes through the caller's file service.\n *\n * @since 0.1.0\n * @category files\n */\nexport const read = Effect.fnUntraced(function* (file: File) {\n return yield* (yield* service).read(file);\n});\n\n/**\n * Stores bytes as a new file of the caller and returns its reference.\n *\n * @since 0.1.0\n * @category files\n */\nexport const write = Effect.fnUntraced(function* (\n file: Parameters<Service[\"Service\"][\"write\"]>[0],\n) {\n return yield* (yield* service).write(file);\n});\n\nexport * as Files from \"./Files.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,OAAO,OAAO,aAAa,QAAQ;CAC9C,aAAa,OAAO;CACpB,IAAI,OAAO;CACX,MAAM,OAAO;CACb,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,SAAS,EACV,aAAa,uEACf,CAAC;;;;;;;;;AAUD,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa;CAC1E,OAAO,OAAO,YAAY,OAAO,SAAS,OAAO,SAAS,EAAE,oBAAoB,KAAK,CAAC,CAAC;CACvF,SAAS,OAAO;AAClB,CAAC,CAAC,CAAC,CAAC;;;;;;;AAQJ,IAAa,UAAb,cAA6B,QAAQ,QAWnC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC;AAGnC,MAAM,UAAU,KACd,OAAO,cAAc,OAAO,GAC5B,OAAO,QACL,OAAO,iBACL,UAAU,KAAK,EAAE,SAAS,2DAA2D,CAAC,CACxF,CACF,CACF;;;;;;;AAQA,MAAa,OAAO,OAAO,WAAW,WAAW,MAAY;CAC3D,OAAO,QAAQ,OAAO,QAAA,CAAS,KAAK,IAAI;AAC1C,CAAC;;;;;;;AAQD,MAAa,QAAQ,OAAO,WAAW,WACrC,MACA;CACA,OAAO,QAAQ,OAAO,QAAA,CAAS,MAAM,IAAI;AAC3C,CAAC"}
package/dist/Http.d.ts CHANGED
@@ -39,16 +39,16 @@ export declare const File: Schema.Struct<{
39
39
  readonly sizeBytes: Schema.optionalKey<Schema.Natural>;
40
40
  }>;
41
41
  /**
42
- * A file the API returns as a Base64 string inside JSON, decoded into a ToolFile with its content
43
- * type recognized from the bytes.
42
+ * A file the API returns as a Base64 string inside JSON, stored by the host and returned by reference.
44
43
  *
45
44
  * @since 0.0.0
46
45
  * @category schemas
47
46
  */
48
- export declare const FileFromBase64: Schema.decodeTo<Schema.TaggedStruct<"ToolFile", {
49
- readonly contentBase64: Schema.String;
50
- readonly contentType: Schema.NullOr<Schema.String>;
51
- readonly filename: Schema.NullOr<Schema.String>;
47
+ export declare const FileFromBase64: Schema.decodeTo<Schema.Struct<{
48
+ readonly _tag: Schema.tag<"File">;
49
+ readonly contentType: Schema.String;
50
+ readonly id: Schema.NonEmptyString;
51
+ readonly name: Schema.String;
52
52
  readonly sizeBytes: Schema.Natural;
53
53
  }>, Schema.String, never, never>;
54
54
  /**
@@ -57,38 +57,39 @@ export declare const FileFromBase64: Schema.decodeTo<Schema.TaggedStruct<"ToolFi
57
57
  * @since 0.0.0
58
58
  * @category schemas
59
59
  */
60
- export declare const FileFromBase64Url: Schema.decodeTo<Schema.TaggedStruct<"ToolFile", {
61
- readonly contentBase64: Schema.String;
62
- readonly contentType: Schema.NullOr<Schema.String>;
63
- readonly filename: Schema.NullOr<Schema.String>;
60
+ export declare const FileFromBase64Url: Schema.decodeTo<Schema.Struct<{
61
+ readonly _tag: Schema.tag<"File">;
62
+ readonly contentType: Schema.String;
63
+ readonly id: Schema.NonEmptyString;
64
+ readonly name: Schema.String;
64
65
  readonly sizeBytes: Schema.Natural;
65
66
  }>, Schema.String, never, never>;
66
67
  /**
67
- * A {@link File} input the API reads as a Base64 string inside JSON.
68
+ * A {@link Files.File} input the API reads as a Base64 string inside JSON.
68
69
  *
69
70
  * @since 0.0.0
70
71
  * @category schemas
71
72
  */
72
- export declare const Base64FromFile: Schema.decodeTo<Schema.String, Schema.Struct<{
73
- readonly _tag: Schema.optionalKey<Schema.Literal<"ToolFile">>;
74
- readonly contentBase64: Schema.Uint8ArrayFromBase64;
75
- readonly contentType: Schema.optionalKey<Schema.NullOr<Schema.String>>;
76
- readonly filename: Schema.optionalKey<Schema.NullOr<Schema.String>>;
77
- readonly sizeBytes: Schema.optionalKey<Schema.Natural>;
78
- }>, never, never>;
73
+ export declare const Base64FromFile: Schema.flip<Schema.decodeTo<Schema.Struct<{
74
+ readonly _tag: Schema.tag<"File">;
75
+ readonly contentType: Schema.String;
76
+ readonly id: Schema.NonEmptyString;
77
+ readonly name: Schema.String;
78
+ readonly sizeBytes: Schema.Natural;
79
+ }>, Schema.String, never, never>>;
79
80
  /**
80
81
  * {@link Base64FromFile} for an API that reads the file in Base64Url.
81
82
  *
82
83
  * @since 0.0.0
83
84
  * @category schemas
84
85
  */
85
- export declare const Base64UrlFromFile: Schema.decodeTo<Schema.String, Schema.Struct<{
86
- readonly _tag: Schema.optionalKey<Schema.Literal<"ToolFile">>;
87
- readonly contentBase64: Schema.Uint8ArrayFromBase64;
88
- readonly contentType: Schema.optionalKey<Schema.NullOr<Schema.String>>;
89
- readonly filename: Schema.optionalKey<Schema.NullOr<Schema.String>>;
90
- readonly sizeBytes: Schema.optionalKey<Schema.Natural>;
91
- }>, never, never>;
86
+ export declare const Base64UrlFromFile: Schema.flip<Schema.decodeTo<Schema.Struct<{
87
+ readonly _tag: Schema.tag<"File">;
88
+ readonly contentType: Schema.String;
89
+ readonly id: Schema.NonEmptyString;
90
+ readonly name: Schema.String;
91
+ readonly sizeBytes: Schema.Natural;
92
+ }>, Schema.String, never, never>>;
92
93
  /**
93
94
  * {@link FileFromBase64} for an API that writes the file as a data URI, which also carries its
94
95
  * content type.
@@ -96,10 +97,11 @@ export declare const Base64UrlFromFile: Schema.decodeTo<Schema.String, Schema.St
96
97
  * @since 0.0.0
97
98
  * @category schemas
98
99
  */
99
- export declare const FileFromDataUri: Schema.decodeTo<Schema.TaggedStruct<"ToolFile", {
100
- readonly contentBase64: Schema.String;
101
- readonly contentType: Schema.NullOr<Schema.String>;
102
- readonly filename: Schema.NullOr<Schema.String>;
100
+ export declare const FileFromDataUri: Schema.decodeTo<Schema.Struct<{
101
+ readonly _tag: Schema.tag<"File">;
102
+ readonly contentType: Schema.String;
103
+ readonly id: Schema.NonEmptyString;
104
+ readonly name: Schema.String;
103
105
  readonly sizeBytes: Schema.Natural;
104
106
  }>, Schema.String, never, never>;
105
107
  /**
@@ -109,13 +111,13 @@ export declare const FileFromDataUri: Schema.decodeTo<Schema.TaggedStruct<"ToolF
109
111
  * @since 0.0.0
110
112
  * @category schemas
111
113
  */
112
- export declare const DataUriFromFile: Schema.decodeTo<Schema.String, Schema.Struct<{
113
- readonly _tag: Schema.optionalKey<Schema.Literal<"ToolFile">>;
114
- readonly contentBase64: Schema.Uint8ArrayFromBase64;
115
- readonly contentType: Schema.optionalKey<Schema.NullOr<Schema.String>>;
116
- readonly filename: Schema.optionalKey<Schema.NullOr<Schema.String>>;
117
- readonly sizeBytes: Schema.optionalKey<Schema.Natural>;
118
- }>, never, never>;
114
+ export declare const DataUriFromFile: Schema.flip<Schema.decodeTo<Schema.Struct<{
115
+ readonly _tag: Schema.tag<"File">;
116
+ readonly contentType: Schema.String;
117
+ readonly id: Schema.NonEmptyString;
118
+ readonly name: Schema.String;
119
+ readonly sizeBytes: Schema.Natural;
120
+ }>, Schema.String, never, never>>;
119
121
  /**
120
122
  * A date-time the API writes as Unix seconds, decoded into an ISO 8601 UTC string.
121
123
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Http.d.ts","names":["AuthMethod.Any","Action.HandlerContext","Action.ActionHandlerFailure","Action.ActionHandlerError","Files.File","Action.RetryableActionHandlerError"],"sources":["../src/Http.ts"],"mappings":";;;;;;;;;;;;;;;iBAoFiB;WACN,OAAO,OAAO;WACd,QAAQ,OAAO;;;;;;;;YASd,QAAQ,yBAAyBA,OAAkB,OAAO,WACpE,OAAO,OACP,SAASC,eAAsB,aAC5B,OAAO,OAAO,QAAQC,sBAA6B,WAAW;;;;;;;YAQvD,cAAc,KAAK;qBAClB,MAAI,OAAA;;;;;;;;;;;;;;qBAkJJ,gBAAc,OAAA,SAAA,OAAA;;;;;IAAqB,OAAA;;;;;;;qBAQnC,mBAAiB,OAAA,SAAA,OAAA;;;;;IAAwB,OAAA;;;;;;;qBAQzC,gBAAc,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;;;;;;;qBAQd,mBAAiB,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;;;;;;;;qBASjB,iBAAe,OAAA,SAAA,OAAA;;;;;IAAuB,OAAA;;;;;;;;qBAStC,iBAAe,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;;;;;;;qBAgEf,yBAAuB,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;qBAQvB,yBAAuB,OAAA,SAAA,OAAA,qCAAA,OAAA;;;;;;;qBAQvB,qBAAmB,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;qBAQnB,qBAAmB,OAAA,SAAA,OAAA,qCAAA,OAAA;;;;;;;;iBASf,QAAQ,aAAa,OAAO;WAClC;WACA,MAAM;;;;;;;;wBASD,cAAc,aAAa,OAAO,KAAK,MAAM,OAAO,QAAQ;KAIvE,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erContext","Action.ActionHandlerFailure","Action.ActionHandlerError","Files.File","Action.RetryableActionHandlerError"],"sources":["../src/Http.ts"],"mappings":";;;;;;;;;;;;;;;iBAoFiB;WACN,OAAO,OAAO;WACd,QAAQ,OAAO;;;;;;;;YASd,QAAQ,yBAAyBA,OAAkB,OAAO,WACpE,OAAO,OACP,SAASC,eAAsB,aAC5B,OAAO,OAAO,QAAQC,sBAA6B,WAAW;;;;;;;YAQvD,cAAc,KAAK;qBAClB,MAAI,OAAA;;;;;;;;;;;;;qBAuJJ,gBAAc,OAAA,SAAA,OAAA;;;;;;IAAqB,OAAA;;;;;;;qBAQnC,mBAAiB,OAAA,SAAA,OAAA;;;;;;IAAwB,OAAA;;;;;;;qBAQzC,gBAAc,OAAA,KAAA,OAAA,SAAA,OAAA;;;;;;IAAwB,OAAA;;;;;;;qBAQtC,mBAAiB,OAAA,KAAA,OAAA,SAAA,OAAA;;;;;;IAA2B,OAAA;;;;;;;;qBAS5C,iBAAe,OAAA,SAAA,OAAA;;;;;;IAAuB,OAAA;;;;;;;;qBAStC,iBAAe,OAAA,KAAA,OAAA,SAAA,OAAA;;;;;;IAA0B,OAAA;;;;;;;qBAgEzC,yBAAuB,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;qBAQvB,yBAAuB,OAAA,SAAA,OAAA,qCAAA,OAAA;;;;;;;qBAQvB,qBAAmB,OAAA,SAAA,OAAA,QAAA,OAAA;;;;;;;qBAQnB,qBAAmB,OAAA,SAAA,OAAA,qCAAA,OAAA;;;;;;;;iBASf,QAAQ,aAAa,OAAO;WAClC;WACA,MAAM;;;;;;;;wBASD,cAAc,aAAa,OAAO,KAAK,MAAM,OAAO,QAAQ;KAIvE,UACD,kBAAkB,oBAClB,OAAO,OAAO,kBAAkB,mBAAmBC;;KAGlD;;;;;;;iBAoBY;WACN;WACA;WACA,MAAM;WACN;;KAGN;WACU,eAAe;WAAqB;IAC/CC;KAEC;WACU;WAAwB,OAAO;;WAC/B;WAA4B,OAAO;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B,cAAc,OAAO,WAAW,eAAe,OAAO,KAAG;eAC1D,OAAO;eAAgB,QAAQ;OAAQ,MAE1D,OAAO,eACP,SAAS,SACT,QAAQ,WACL,OAAO,OAAO,gBAAgBD,sBAA6B,WAAW,cAC1E,SAAS,SAAS,OAAO;WACJ,cAAc,OAAO,WAAW,aAAa,OAAO,KAAG;eACxD,OAAO;eAAgB,QAAQ,QAAQ;OAAO,MAEjE,OAAO,eACP,SAAS,SACT,QAAQ,SACL,OAAO,OAAO,cAAcA,sBAA6B,WAAW,cACxE,gBAAgB,SAAS,OAAO;;EA2BlB,UAAA,eAAe,OAAO,KAAG,SAC/B,qBAAmB,QACpB,QAAM,SACL,SAAO,MACV,SAAI,OAAA,OAAA,gBAAAC,qBAAAE,6BAAA,WAAA,aAAA;EAgFsC,eAAA,eAAe,OAAO,KAAG,SAAA,SAAA,QAAA,QAAA,SAAA,kBAAA,mBAAA,SAAA,QAAA;aAK3C;aAA6B;;EA2HhB,UAAA,eAAe,OAAO,KAAG,SAAA,SAAA,QAAA,QAAA,SAAA,SAAA,kBAAA,OAAA,OAAA,gBAAAF,qBAAAE,6BAAA,WAAA,aAAA;EA0BzD,MAAA,eAAe,OAAO,KAAG,SAAA,SAAA,QAAA,QAAA,gBAAA,cAAA,eAAA,wBAAA,OAAA,OAAA,gBAAAF,qBAAAE,6BAAA,WAAA,aAAA,QAAA,mDAAA;EA/NQ,WAAA,eAAe,OAAO,KAAG,SAAA,qBAAA,QAAA,QAAA,SAAA,SAAA,mBAAA,WAAA,gCAAA,OAAA,OAAA,gBAAAF,qBAAAE,6BAAA,WAAA,aAAA"}
package/dist/Http.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
2
  import { ActionHandlerError, fromHttpClientFailure } from "./Action.js";
3
- import { Schema as Schema$1 } from "./ToolFile.js";
4
3
  import { File as File$1, read as read$1, write } from "./Files.js";
5
4
  import { CallToolResult, McpError, connect } from "./Mcp.js";
5
+ import "./ToolFile.js";
6
6
  import "./Http.js";
7
7
  import { Array, Boolean, DateTime, Effect, Equal, Option, Order, Predicate, Random, Record, Result, Schema, SchemaGetter, SchemaIssue, String, flow, pipe } from "effect";
8
8
  import { FetchHttpClient, Headers, HttpBody, HttpClient, HttpClientError, HttpClientRequest, UrlParams } from "effect/http";
@@ -107,11 +107,14 @@ const utf8 = new TextDecoder("utf-8", { fatal: true });
107
107
  function sniff(bytes) {
108
108
  return pipe(Array.findFirst(signatures, (signature) => Array.every(signature[1], (part) => Array.every(part[1], (byte, index) => bytes[part[0] + index] === byte))), Option.map((signature) => signature[0]), Option.orElse(() => Option.liftPredicate("text/plain", () => Result.isSuccess(Result.try(() => utf8.decode(bytes))))), Option.getOrNull);
109
109
  }
110
+ function fileContentType(bytes, declared) {
111
+ return declared === null || pipe(declared, String.startsWith("application/octet-stream")) ? sniff(bytes) ?? declared : declared;
112
+ }
110
113
  function toolFile(bytes, declared, filename) {
111
114
  return {
112
115
  _tag: "ToolFile",
113
116
  contentBase64: Base64.encode(bytes),
114
- contentType: declared === null || pipe(declared, String.startsWith("application/octet-stream")) ? sniff(bytes) ?? declared : declared,
117
+ contentType: fileContentType(bytes, declared),
115
118
  filename,
116
119
  sizeBytes: bytes.byteLength
117
120
  };
@@ -146,29 +149,26 @@ function textOf(carrier, content) {
146
149
  return `data:${content.contentType ?? sniff(content.bytes) ?? "application/octet-stream"};base64,${Base64.encode(content.bytes)}`;
147
150
  }
148
151
  function fileFrom(carrier) {
149
- return Schema.String.pipe(Schema.decodeTo(Schema$1, {
150
- decode: SchemaGetter.compose(contentOf(carrier), SchemaGetter.transform((content) => toolFile(content.bytes, content.contentType, null))),
151
- encode: SchemaGetter.transformEffect((file, options) => Effect.map(decodeBytes(file.contentBase64, options), (bytes) => textOf(carrier, {
152
- bytes,
153
- contentType: file.contentType
152
+ return Schema.String.pipe(Schema.decodeTo(File$1, {
153
+ decode: SchemaGetter.compose(contentOf(carrier), SchemaGetter.transformEffect((content, options) => pipe(write({
154
+ bytes: content.bytes,
155
+ contentType: fileContentType(content.bytes, content.contentType),
156
+ name: "file"
157
+ }), Effect.mapError((error) => new SchemaIssue.InvalidValue({ expected: error.message }, content, options))))),
158
+ encode: SchemaGetter.transformEffect((file, options) => pipe(read$1(file), Effect.mapBoth({
159
+ onSuccess: (bytes) => textOf(carrier, {
160
+ bytes,
161
+ contentType: file.contentType
162
+ }),
163
+ onFailure: (error) => new SchemaIssue.InvalidValue({ expected: error.message }, file, options)
154
164
  })))
155
165
  }));
156
166
  }
157
167
  function encodedFrom(carrier) {
158
- return File.pipe(Schema.decodeTo(Schema.String, {
159
- decode: SchemaGetter.transform((file) => textOf(carrier, {
160
- bytes: file.contentBase64,
161
- contentType: file.contentType ?? null
162
- })),
163
- encode: SchemaGetter.compose(contentOf(carrier), SchemaGetter.transform((content) => ({
164
- contentBase64: content.bytes,
165
- contentType: content.contentType
166
- })))
167
- }));
168
+ return Schema.flip(fileFrom(carrier));
168
169
  }
169
170
  /**
170
- * A file the API returns as a Base64 string inside JSON, decoded into a ToolFile with its content
171
- * type recognized from the bytes.
171
+ * A file the API returns as a Base64 string inside JSON, stored by the host and returned by reference.
172
172
  *
173
173
  * @since 0.0.0
174
174
  * @category schemas
@@ -182,7 +182,7 @@ const FileFromBase64 = fileFrom("base64");
182
182
  */
183
183
  const FileFromBase64Url = fileFrom("base64url");
184
184
  /**
185
- * A {@link File} input the API reads as a Base64 string inside JSON.
185
+ * A {@link Files.File} input the API reads as a Base64 string inside JSON.
186
186
  *
187
187
  * @since 0.0.0
188
188
  * @category schemas
@@ -466,11 +466,14 @@ const read = Effect.fnUntraced(function* (response, body) {
466
466
  }
467
467
  const bytes = new Uint8Array(yield* response.arrayBuffer);
468
468
  const name = dispositionName(response.headers["content-disposition"]);
469
- if (body === "file") return yield* pipe(write({
470
- bytes,
471
- contentType: Option.getOrNull(Option.fromUndefinedOr(response.headers["content-type"])),
472
- name: name ?? "file"
473
- }), Effect.mapError(fileFailed));
469
+ if (body === "file") {
470
+ const declared = response.headers["content-type"] ?? null;
471
+ return yield* pipe(write({
472
+ bytes,
473
+ contentType: fileContentType(bytes, declared),
474
+ name: name ?? "file"
475
+ }), Effect.mapError(fileFailed));
476
+ }
474
477
  return toolFile(bytes, response.headers["content-type"] ?? null, name ?? null);
475
478
  });
476
479
  /**