@dual-os/sdk 0.10.0 → 0.12.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.
- package/dist/AgentChannel.d.ts +818 -59
- package/dist/AgentChannel.d.ts.map +1 -1
- package/dist/AgentChannel.js +118 -13
- package/dist/AgentChannel.js.map +1 -1
- package/dist/AgentChannelConformance.d.ts +602 -6
- package/dist/AgentChannelConformance.d.ts.map +1 -1
- package/dist/AgentChannelRuntime.js +4 -3
- package/dist/AgentChannelRuntime.js.map +1 -1
- package/dist/AiProvider.d.ts +11 -1
- package/dist/AiProvider.d.ts.map +1 -1
- package/dist/AiProvider.js +7 -2
- package/dist/AiProvider.js.map +1 -1
- package/dist/DualRuntime.d.ts +9 -3
- package/dist/DualRuntime.d.ts.map +1 -1
- package/dist/DualRuntime.js +12 -1
- package/dist/DualRuntime.js.map +1 -1
- package/package.json +1 -1
- package/src/AgentChannel.ts +122 -16
- package/src/AgentChannelRuntime.ts +11 -3
- package/src/AiProvider.ts +16 -0
- package/src/DualRuntime.ts +21 -1
|
@@ -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;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,QACJ,QACA,SAEA,OAAO,KACL,OAAO,YAAW,UAChB,MAAM,cAAc,KAAK,IA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rB,OAAO,oBACLG,aAA0B,WAAW,OAAO,WAAW,QAAQ,CACjE,CAAC,CACC,OAAO,SAAS,YACZ;GACE,GAAG;GACH,QAAQ;GACR,GAAI,gBAAgB,WAAW,IAAI,CAAC,IAAI,EAAE,gBAAgB;EAC5D,IACA,QACJ,MACF,GACA,gBACF;EACA,OAAO,OAAO,WACZC,eACA,SACA,kBACA,SAAS,YACX;CACF,CAAC;CAGD,MAAM,OACJ,WAGA,OAAO,KAAK,OAAO,eAAe,OAAO,CAAC;CAC5C,MAAM,kBAAkB,UACtB,OAAO,GAAG,oCAAoC,CAAC,CAAC,WAAW,OAAgB;EACzE,MAAM,UAAU,OAAO,OACrB,OAAO,OAAO;GAAE,GAAG,IAAI;GAAQ,OAAO,OAAO;EAAK,CAAC,GACnD,OACA,eACF;EAEA,MAAM,UAAS,OADW,IAAI,EAAE,WAAW,QAAQ,UAAU,CAAC,EAAA,CACpC;EAC1B,MAAM,QAAQ,OAAO,WAAW,QAAQ,QAAQ,OAAO,eAAe;EACtE,OAAO,OAAO,KACZ,OAAO,KAAK,OAAO,oBAAoB,MAAM,CAAC,CAAC,OAAO,MAAM,GAAG,eAAe,GAC9E,eACF;CACF,CAAC;CACH,OAAO,QAAQ,GAAG;EAChB,cAAa,UAAS,IAAI,YAAY,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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5D,IACA,QACJ,MACF,GACA,gBACF;EACA,OAAO,OAAO,WACZC,eACA,SACA,kBACA,SAAS,YACX;CACF,CAAC;CAGD,MAAM,OACJ,WAGA,OAAO,KAAK,OAAO,eAAe,OAAO,CAAC;CAC5C,MAAM,kBAAkB,UACtB,OAAO,GAAG,oCAAoC,CAAC,CAAC,WAAW,OAAgB;EACzE,MAAM,UAAU,OAAO,OACrB,OAAO,OAAO;GAAE,GAAG,IAAI;GAAQ,OAAO,OAAO;EAAK,CAAC,GACnD,OACA,eACF;EAEA,MAAM,UAAS,OADW,IAAI,EAAE,WAAW,QAAQ,UAAU,CAAC,EAAA,CACpC;EAC1B,MAAM,QAAQ,OAAO,WAAW,QAAQ,QAAQ,OAAO,eAAe;EACtE,OAAO,OAAO,KACZ,OAAO,KAAK,OAAO,oBAAoB,MAAM,CAAC,CAAC,OAAO,MAAM,GAAG,eAAe,GAC9E,eACF;CACF,CAAC;CACH,OAAO,QAAQ,GAAG;EAChB,cAAa,UAAS,IAAI,YAAY,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"}
|
package/dist/AiProvider.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Any as Any$1 } from "./AuthMethod.js";
|
|
|
3
3
|
import { Category } from "./Plugin.js";
|
|
4
4
|
import { Pipeable, Schema } from "effect";
|
|
5
5
|
declare namespace AiProvider_d_exports {
|
|
6
|
-
export { AddAuthMethods, AiProvider, AiProviderOptions, Any, RuntimeConfig, RuntimeConfigResolver, RuntimeConfigResolverInput, RuntimeModel, TypeId, isAiProvider, make, registryId, withAuthMethod, withAuthMethods, withCategories, withDescription, withDocsUrl, withHomepageUrl, withIconUrl, withIconUrlDark, withName, withRuntimeConfig };
|
|
6
|
+
export { AddAuthMethods, AiProvider, AiProviderOptions, AllowedModelIds, Any, RuntimeConfig, RuntimeConfigResolver, RuntimeConfigResolverInput, RuntimeModel, TypeId, isAiProvider, make, registryId, withAllowedModelIds, withAuthMethod, withAuthMethods, withCategories, withDescription, withDocsUrl, withHomepageUrl, withIconUrl, withIconUrlDark, withName, withRuntimeConfig };
|
|
7
7
|
}
|
|
8
8
|
/** @since 0.0.0 @category type ids */
|
|
9
9
|
export declare const TypeId: "@dual-os/sdk/AiProvider";
|
|
@@ -21,8 +21,11 @@ export interface Any extends Pipeable.Pipeable {
|
|
|
21
21
|
readonly homepageUrl: string | undefined;
|
|
22
22
|
readonly docsUrl: string | undefined;
|
|
23
23
|
readonly authMethods: readonly Any$1[];
|
|
24
|
+
readonly allowedModelIds?: AllowedModelIds | undefined;
|
|
24
25
|
readonly resolveRuntimeConfig: unknown;
|
|
25
26
|
}
|
|
27
|
+
/** Projects allowed model IDs from stored credential material. Undefined permits every catalog model. */
|
|
28
|
+
export type AllowedModelIds = (material: unknown) => readonly string[] | undefined;
|
|
26
29
|
/** @since 0.0.0 @category models */
|
|
27
30
|
export declare const RuntimeConfig: Schema.Struct<{
|
|
28
31
|
readonly apiKey: Schema.optional<Schema.String>;
|
|
@@ -54,6 +57,7 @@ export interface AiProviderOptions<Identifier extends string = string> {
|
|
|
54
57
|
readonly categories?: readonly Category[];
|
|
55
58
|
readonly homepageUrl?: string;
|
|
56
59
|
readonly docsUrl?: string;
|
|
60
|
+
readonly allowedModelIds?: AllowedModelIds;
|
|
57
61
|
}
|
|
58
62
|
/** @since 0.0.0 @category models */
|
|
59
63
|
export interface AiProvider<out Identifier extends string = string, out AuthMethods extends readonly Any$1[] = readonly []> extends Pipeable.Pipeable {
|
|
@@ -67,6 +71,7 @@ export interface AiProvider<out Identifier extends string = string, out AuthMeth
|
|
|
67
71
|
readonly homepageUrl: string | undefined;
|
|
68
72
|
readonly docsUrl: string | undefined;
|
|
69
73
|
readonly authMethods: AuthMethods;
|
|
74
|
+
readonly allowedModelIds?: AllowedModelIds | undefined;
|
|
70
75
|
readonly resolveRuntimeConfig: RuntimeConfigResolver<AuthMethods> | undefined;
|
|
71
76
|
}
|
|
72
77
|
/** @since 0.0.0 @category type-level */
|
|
@@ -78,6 +83,11 @@ export declare const registryId: (identifier: string) => string;
|
|
|
78
83
|
/** @since 0.0.0 @category guards */
|
|
79
84
|
export declare const isAiProvider: (value: unknown) => value is Any;
|
|
80
85
|
/** @since 0.0.0 @category combinators */
|
|
86
|
+
export declare const withAllowedModelIds: {
|
|
87
|
+
(resolve: AllowedModelIds): <Self extends Any>(provider: Self) => Self;
|
|
88
|
+
<Self extends Any>(provider: Self, resolve: AllowedModelIds): Self;
|
|
89
|
+
};
|
|
90
|
+
/** @since 0.0.0 @category combinators */
|
|
81
91
|
export declare const withName: {
|
|
82
92
|
(name: string): <P extends AiProvider<any, any>>(provider: P) => P;
|
|
83
93
|
<P extends AiProvider<any, any>>(provider: P, name: string): P;
|
package/dist/AiProvider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiProvider.d.ts","names":["AuthMethod.Any","AuthMethodBinding.BindingFor"],"sources":["../src/AiProvider.ts"],"mappings":";;;;;;;;qBAqBa;;YAED,gBAAgB;;iBAGX,YAAY,SAAS;YAC1B,SAAS;WACV;WACA;WACA;WACA;WACA;WACA,qBAAqB;WACrB;WACA;WACA,sBAAsBA;WACtB;;;
|
|
1
|
+
{"version":3,"file":"AiProvider.d.ts","names":["AuthMethod.Any","AuthMethodBinding.BindingFor"],"sources":["../src/AiProvider.ts"],"mappings":";;;;;;;;qBAqBa;;YAED,gBAAgB;;iBAGX,YAAY,SAAS;YAC1B,SAAS;WACV;WACA;WACA;WACA;WACA;WACA,qBAAqB;WACrB;WACA;WACA,sBAAsBA;WACtB,kBAAkB;WAClB;;;YAIC,mBAAmB;;qBAGlB,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sB,UAAU,GAAG,sBAAsB;;;qBAMzD;GACV,mBAAmB,UAAU,sBAAsB,UAAU,MAAM;GACnE,UAAU,sBAAsB,UAAU,GAAG,kBAAkB;;;qBAMrD;SACJ,8BAA8BA,SACnC,SAAS,gBACP,aAAa,KAAK,UAAU,SAAS,eAAe,MAAM;GAC7D,aAAa,WAAW,8BAA8BA,SACrD,UAAU,MACV,SAAS,eACR,eAAe,MAAM;;;qBAWb;SACJ,oBAAoBA,OACzB,QAAQ,eACN,aAAa,KAAK,UAAU,SAAS,eAAe,gBAAgB;GACvE,aAAa,WAAW,oBAAoBA,OAC3C,UAAU,MACV,QAAQ,cACP,eAAe,gBAAgB;;;qBAMvB;GACV,aAAa,KAAK,SAAS,sBAAsB,wBAAwB,UAAU,SAAS;GAC5F,aAAa,KAAK,UAAU,MAAM,SAAS,sBAAsB,uBAAuB"}
|
package/dist/AiProvider.js
CHANGED
|
@@ -11,6 +11,7 @@ var AiProvider_exports = /* @__PURE__ */ __exportAll({
|
|
|
11
11
|
isAiProvider: () => isAiProvider,
|
|
12
12
|
make: () => make,
|
|
13
13
|
registryId: () => registryId,
|
|
14
|
+
withAllowedModelIds: () => withAllowedModelIds,
|
|
14
15
|
withAuthMethod: () => withAuthMethod,
|
|
15
16
|
withAuthMethods: () => withAuthMethods,
|
|
16
17
|
withCategories: () => withCategories,
|
|
@@ -39,7 +40,8 @@ const optionsFromProvider = (provider) => ({
|
|
|
39
40
|
...provider.iconUrlDark === void 0 ? {} : { iconUrlDark: provider.iconUrlDark },
|
|
40
41
|
...provider.categories.length === 0 ? {} : { categories: provider.categories },
|
|
41
42
|
...provider.homepageUrl === void 0 ? {} : { homepageUrl: provider.homepageUrl },
|
|
42
|
-
...provider.docsUrl === void 0 ? {} : { docsUrl: provider.docsUrl }
|
|
43
|
+
...provider.docsUrl === void 0 ? {} : { docsUrl: provider.docsUrl },
|
|
44
|
+
...provider.allowedModelIds === void 0 ? {} : { allowedModelIds: provider.allowedModelIds }
|
|
43
45
|
});
|
|
44
46
|
const Proto = {
|
|
45
47
|
...PipeableProto,
|
|
@@ -49,6 +51,7 @@ const makeProvider = (options, authMethods, resolveRuntimeConfig) => {
|
|
|
49
51
|
validateIdentifier("provider", options.identifier);
|
|
50
52
|
assertNoDuplicateAuthMethodIdentifiers(options.identifier, authMethods);
|
|
51
53
|
return Object.assign(Object.create(Proto), {
|
|
54
|
+
allowedModelIds: options.allowedModelIds,
|
|
52
55
|
authMethods,
|
|
53
56
|
categories: options.categories ?? [],
|
|
54
57
|
description: options.description,
|
|
@@ -72,6 +75,8 @@ const withOption = (provider, options) => makeProvider({
|
|
|
72
75
|
...options
|
|
73
76
|
}, provider.authMethods, provider.resolveRuntimeConfig);
|
|
74
77
|
/** @since 0.0.0 @category combinators */
|
|
78
|
+
const withAllowedModelIds = Function.dual(2, (provider, allowedModelIds) => withOption(provider, { allowedModelIds }));
|
|
79
|
+
/** @since 0.0.0 @category combinators */
|
|
75
80
|
const withName = Function.dual(2, (provider, name) => withOption(provider, { name }));
|
|
76
81
|
/** @since 0.0.0 @category combinators */
|
|
77
82
|
const withDescription = Function.dual(2, (provider, description) => withOption(provider, { description }));
|
|
@@ -94,6 +99,6 @@ const withAuthMethods = Function.dual(2, (provider, methods) => {
|
|
|
94
99
|
const withAuthMethod = Function.dual(2, (provider, method) => withAuthMethods(provider, [method]));
|
|
95
100
|
/** @since 0.0.0 @category combinators */
|
|
96
101
|
const withRuntimeConfig = Function.dual(2, (provider, resolve) => makeProvider(optionsFromProvider(provider), provider.authMethods, resolve));
|
|
97
|
-
export { AiProvider_exports, RuntimeConfig, TypeId, isAiProvider, make, registryId, withAuthMethod, withAuthMethods, withCategories, withDescription, withDocsUrl, withHomepageUrl, withIconUrl, withIconUrlDark, withName, withRuntimeConfig };
|
|
102
|
+
export { AiProvider_exports, RuntimeConfig, TypeId, isAiProvider, make, registryId, withAllowedModelIds, withAuthMethod, withAuthMethods, withCategories, withDescription, withDocsUrl, withHomepageUrl, withIconUrl, withIconUrlDark, withName, withRuntimeConfig };
|
|
98
103
|
|
|
99
104
|
//# sourceMappingURL=AiProvider.js.map
|
package/dist/AiProvider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AiProvider.js","names":["Func"],"sources":["../src/AiProvider.ts"],"sourcesContent":["/**\n * AI provider definitions for model authentication.\n *\n * AI providers share provider metadata and auth methods with Tools providers,\n * but cannot contribute actions, triggers, or groups. Their identifier is a\n * stable key matched exactly against Pi's `Model.provider` value.\n *\n * @since 0.0.0\n */\nimport type { Pipeable } from \"effect\";\nimport { Function as Func, Predicate, Schema } from \"effect\";\n\nimport type * as AuthMethod from \"./AuthMethod.ts\";\nimport type * as AuthMethodBinding from \"./AuthMethodBinding.ts\";\nimport { assertNoDuplicateAuthMethodIdentifiers } from \"./internal/auth-runtime.ts\";\nimport { appendElements } from \"./internal/collection-utils.ts\";\nimport { validateIdentifier } from \"./internal/identifier.ts\";\nimport { PipeableProto } from \"./internal/proto.ts\";\nimport type { Category } from \"./Plugin.ts\";\n\n/** @since 0.0.0 @category type ids */\nexport const TypeId = \"@dual-os/sdk/AiProvider\" as const;\n/** @since 0.0.0 @category type ids */\nexport type TypeId = typeof TypeId;\n\n/** @since 0.0.0 @category type-level */\nexport interface Any extends Pipeable.Pipeable {\n readonly [TypeId]: TypeId;\n readonly identifier: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly iconUrl: string | undefined;\n readonly iconUrlDark: string | undefined;\n readonly categories: readonly Category[];\n readonly homepageUrl: string | undefined;\n readonly docsUrl: string | undefined;\n readonly authMethods: readonly AuthMethod.Any[];\n readonly resolveRuntimeConfig: unknown;\n}\n\n/** @since 0.0.0 @category models */\nexport const RuntimeConfig = Schema.Struct({\n apiKey: Schema.optional(Schema.String),\n baseUrl: Schema.optional(Schema.String),\n env: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n headers: Schema.optional(Schema.Record(Schema.String, Schema.NullOr(Schema.String))),\n});\n\n/** @since 0.0.0 @category models */\nexport type RuntimeConfig = typeof RuntimeConfig.Type;\n\n/** @since 0.0.0 @category models */\nexport interface RuntimeModel {\n readonly id: string;\n readonly baseUrl: string;\n}\n\n/** @since 0.0.0 @category models */\nexport interface RuntimeConfigResolverInput<Methods extends readonly AuthMethod.Any[]> {\n readonly model: RuntimeModel;\n readonly binding: AuthMethodBinding.BindingFor<Methods>;\n}\n\n/** @since 0.0.0 @category models */\nexport type RuntimeConfigResolver<Methods extends readonly AuthMethod.Any[]> = (\n input: RuntimeConfigResolverInput<Methods>,\n) => RuntimeConfig;\n\n/** @since 0.0.0 @category models */\nexport interface AiProviderOptions<Identifier extends string = string> {\n readonly identifier: Identifier;\n readonly name?: string;\n readonly description?: string;\n readonly iconUrl?: string;\n readonly iconUrlDark?: string;\n readonly categories?: readonly Category[];\n readonly homepageUrl?: string;\n readonly docsUrl?: string;\n}\n\n/** @since 0.0.0 @category models */\nexport interface AiProvider<\n out Identifier extends string = string,\n out AuthMethods extends readonly AuthMethod.Any[] = readonly [],\n>\n extends Pipeable.Pipeable {\n readonly [TypeId]: TypeId;\n readonly identifier: Identifier;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly iconUrl: string | undefined;\n readonly iconUrlDark: string | undefined;\n readonly categories: readonly Category[];\n readonly homepageUrl: string | undefined;\n readonly docsUrl: string | undefined;\n readonly authMethods: AuthMethods;\n readonly resolveRuntimeConfig: RuntimeConfigResolver<AuthMethods> | undefined;\n}\n\n/** @since 0.0.0 @category type-level */\nexport type AddAuthMethods<Self extends Any, AddedMethods extends readonly AuthMethod.Any[]> =\n Self extends AiProvider<infer Identifier, infer AuthMethods>\n ? AiProvider<Identifier, readonly [...AuthMethods, ...AddedMethods]>\n : never;\n\nconst optionsFromProvider = (provider: Any): AiProviderOptions => ({\n identifier: provider.identifier,\n ...(provider.name === undefined ? {} : { name: provider.name }),\n ...(provider.description === undefined ? {} : { description: provider.description }),\n ...(provider.iconUrl === undefined ? {} : { iconUrl: provider.iconUrl }),\n ...(provider.iconUrlDark === undefined ? {} : { iconUrlDark: provider.iconUrlDark }),\n ...(provider.categories.length === 0 ? {} : { categories: provider.categories }),\n ...(provider.homepageUrl === undefined ? {} : { homepageUrl: provider.homepageUrl }),\n ...(provider.docsUrl === undefined ? {} : { docsUrl: provider.docsUrl }),\n});\n\nconst Proto = { ...PipeableProto, [TypeId]: TypeId };\n\nconst makeProvider = <Identifier extends string, AuthMethods extends readonly AuthMethod.Any[]>(\n options: AiProviderOptions<Identifier>,\n authMethods: AuthMethods,\n resolveRuntimeConfig?: RuntimeConfigResolver<AuthMethods>,\n): AiProvider<Identifier, AuthMethods> => {\n validateIdentifier(\"provider\", options.identifier);\n assertNoDuplicateAuthMethodIdentifiers(options.identifier, authMethods);\n\n return Object.assign(Object.create(Proto), {\n authMethods,\n categories: options.categories ?? [],\n description: options.description,\n docsUrl: options.docsUrl,\n homepageUrl: options.homepageUrl,\n iconUrl: options.iconUrl,\n iconUrlDark: options.iconUrlDark,\n identifier: options.identifier,\n name: options.name,\n resolveRuntimeConfig,\n });\n};\n\n/** @since 0.0.0 @category constructors */\nexport const make = <const Identifier extends string>(\n identifier: Identifier,\n): AiProvider<Identifier> => makeProvider({ identifier }, [] as const);\n\n/** @since 0.0.0 @category registry */\nexport const registryId = (identifier: string): string => `ai/${identifier}`;\n\n/** @since 0.0.0 @category guards */\nexport const isAiProvider = (value: unknown): value is Any => Predicate.hasProperty(value, TypeId);\n\nconst withOption = <P extends AiProvider<any, any>>(\n provider: P,\n options: Partial<AiProviderOptions>,\n): P =>\n makeProvider(\n { ...optionsFromProvider(provider), ...options },\n provider.authMethods,\n provider.resolveRuntimeConfig,\n ) as P;\n\n/** @since 0.0.0 @category combinators */\nexport const withName: {\n (name: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, name: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, name: string) => withOption(provider, { name }));\n\n/** @since 0.0.0 @category combinators */\nexport const withDescription: {\n (description: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, description: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, description: string) =>\n withOption(provider, { description }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withIconUrl: {\n (iconUrl: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, iconUrl: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, iconUrl: string) =>\n withOption(provider, { iconUrl }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withIconUrlDark: {\n (iconUrlDark: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, iconUrlDark: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, iconUrlDark: string) =>\n withOption(provider, { iconUrlDark }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withCategories: {\n (categories: readonly Category[]): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, categories: readonly Category[]): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, categories: readonly Category[]) =>\n withOption(provider, { categories: [...categories] }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withHomepageUrl: {\n (homepageUrl: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, homepageUrl: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, homepageUrl: string) =>\n withOption(provider, { homepageUrl }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withDocsUrl: {\n (docsUrl: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, docsUrl: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, docsUrl: string) =>\n withOption(provider, { docsUrl }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withAuthMethods: {\n <const AddedMethods extends readonly AuthMethod.Any[]>(\n methods: AddedMethods,\n ): <Self extends Any>(provider: Self) => AddAuthMethods<Self, AddedMethods>;\n <Self extends Any, const AddedMethods extends readonly AuthMethod.Any[]>(\n provider: Self,\n methods: AddedMethods,\n ): AddAuthMethods<Self, AddedMethods>;\n} = Func.dual(2, (provider: Any, methods: readonly AuthMethod.Any[]) => {\n if (provider.resolveRuntimeConfig !== undefined) {\n throw new Error(\n `AI provider \"${provider.identifier}\" must declare auth methods before its runtime config`,\n );\n }\n return makeProvider(optionsFromProvider(provider), appendElements(provider.authMethods, methods));\n});\n\n/** @since 0.0.0 @category combinators */\nexport const withAuthMethod: {\n <const AddedMethod extends AuthMethod.Any>(\n method: AddedMethod,\n ): <Self extends Any>(provider: Self) => AddAuthMethods<Self, readonly [AddedMethod]>;\n <Self extends Any, const AddedMethod extends AuthMethod.Any>(\n provider: Self,\n method: AddedMethod,\n ): AddAuthMethods<Self, readonly [AddedMethod]>;\n} = Func.dual(2, (provider: Any, method: AuthMethod.Any) =>\n withAuthMethods(provider, [method] as const),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withRuntimeConfig: {\n <Self extends Any>(resolve: RuntimeConfigResolver<Self[\"authMethods\"]>): (provider: Self) => Self;\n <Self extends Any>(provider: Self, resolve: RuntimeConfigResolver<Self[\"authMethods\"]>): Self;\n} = Func.dual(\n 2,\n (provider: AiProvider<any, any>, resolve: RuntimeConfigResolver<readonly AuthMethod.Any[]>) =>\n makeProvider(optionsFromProvider(provider), provider.authMethods, resolve),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAS;;AAoBtB,MAAa,gBAAgB,OAAO,OAAO;CACzC,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,SAAS,OAAO,SAAS,OAAO,MAAM;CACtC,KAAK,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,MAAM,CAAC;CAChE,SAAS,OAAO,SAAS,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,MAAM,CAAC,CAAC;AACrF,CAAC;AA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MAAa,WAGTA,SAAK,KAAK,IAAI,UAAgC,SAAiB,WAAW,UAAU,EAAE,KAAK,CAAC,CAAC;;AAGjG,MAAa,kBAGTA,SAAK,KAAK,IAAI,UAAgC,gBAChD,WAAW,UAAU,EAAE,YAAY,CAAC,CACtC;;AAGA,MAAa,cAGTA,SAAK,KAAK,IAAI,UAAgC,YAChD,WAAW,UAAU,EAAE,QAAQ,CAAC,CAClC;;AAGA,MAAa,kBAGTA,SAAK,KAAK,IAAI,UAAgC,gBAChD,WAAW,UAAU,EAAE,YAAY,CAAC,CACtC;;AAGA,MAAa,iBAGTA,SAAK,KAAK,IAAI,UAAgC,eAChD,WAAW,UAAU,EAAE,YAAY,CAAC,GAAG,UAAU,EAAE,CAAC,CACtD;;AAGA,MAAa,kBAGTA,SAAK,KAAK,IAAI,UAAgC,gBAChD,WAAW,UAAU,EAAE,YAAY,CAAC,CACtC;;AAGA,MAAa,cAGTA,SAAK,KAAK,IAAI,UAAgC,YAChD,WAAW,UAAU,EAAE,QAAQ,CAAC,CAClC;;AAGA,MAAa,kBAQTA,SAAK,KAAK,IAAI,UAAe,YAAuC;CACtE,IAAI,SAAS,yBAAyB,KAAA,GACpC,MAAM,IAAI,MACR,gBAAgB,SAAS,WAAW,sDACtC;CAEF,OAAO,aAAa,oBAAoB,QAAQ,GAAG,eAAe,SAAS,aAAa,OAAO,CAAC;AAClG,CAAC;;AAGD,MAAa,iBAQTA,SAAK,KAAK,IAAI,UAAe,WAC/B,gBAAgB,UAAU,CAAC,MAAM,CAAU,CAC7C;;AAGA,MAAa,oBAGTA,SAAK,KACP,IACC,UAAgC,YAC/B,aAAa,oBAAoB,QAAQ,GAAG,SAAS,aAAa,OAAO,CAC7E"}
|
|
1
|
+
{"version":3,"file":"AiProvider.js","names":["Func"],"sources":["../src/AiProvider.ts"],"sourcesContent":["/**\n * AI provider definitions for model authentication.\n *\n * AI providers share provider metadata and auth methods with Tools providers,\n * but cannot contribute actions, triggers, or groups. Their identifier is a\n * stable key matched exactly against Pi's `Model.provider` value.\n *\n * @since 0.0.0\n */\nimport type { Pipeable } from \"effect\";\nimport { Function as Func, Predicate, Schema } from \"effect\";\n\nimport type * as AuthMethod from \"./AuthMethod.ts\";\nimport type * as AuthMethodBinding from \"./AuthMethodBinding.ts\";\nimport { assertNoDuplicateAuthMethodIdentifiers } from \"./internal/auth-runtime.ts\";\nimport { appendElements } from \"./internal/collection-utils.ts\";\nimport { validateIdentifier } from \"./internal/identifier.ts\";\nimport { PipeableProto } from \"./internal/proto.ts\";\nimport type { Category } from \"./Plugin.ts\";\n\n/** @since 0.0.0 @category type ids */\nexport const TypeId = \"@dual-os/sdk/AiProvider\" as const;\n/** @since 0.0.0 @category type ids */\nexport type TypeId = typeof TypeId;\n\n/** @since 0.0.0 @category type-level */\nexport interface Any extends Pipeable.Pipeable {\n readonly [TypeId]: TypeId;\n readonly identifier: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly iconUrl: string | undefined;\n readonly iconUrlDark: string | undefined;\n readonly categories: readonly Category[];\n readonly homepageUrl: string | undefined;\n readonly docsUrl: string | undefined;\n readonly authMethods: readonly AuthMethod.Any[];\n readonly allowedModelIds?: AllowedModelIds | undefined;\n readonly resolveRuntimeConfig: unknown;\n}\n\n/** Projects allowed model IDs from stored credential material. Undefined permits every catalog model. */\nexport type AllowedModelIds = (material: unknown) => readonly string[] | undefined;\n\n/** @since 0.0.0 @category models */\nexport const RuntimeConfig = Schema.Struct({\n apiKey: Schema.optional(Schema.String),\n baseUrl: Schema.optional(Schema.String),\n env: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n headers: Schema.optional(Schema.Record(Schema.String, Schema.NullOr(Schema.String))),\n});\n\n/** @since 0.0.0 @category models */\nexport type RuntimeConfig = typeof RuntimeConfig.Type;\n\n/** @since 0.0.0 @category models */\nexport interface RuntimeModel {\n readonly id: string;\n readonly baseUrl: string;\n}\n\n/** @since 0.0.0 @category models */\nexport interface RuntimeConfigResolverInput<Methods extends readonly AuthMethod.Any[]> {\n readonly model: RuntimeModel;\n readonly binding: AuthMethodBinding.BindingFor<Methods>;\n}\n\n/** @since 0.0.0 @category models */\nexport type RuntimeConfigResolver<Methods extends readonly AuthMethod.Any[]> = (\n input: RuntimeConfigResolverInput<Methods>,\n) => RuntimeConfig;\n\n/** @since 0.0.0 @category models */\nexport interface AiProviderOptions<Identifier extends string = string> {\n readonly identifier: Identifier;\n readonly name?: string;\n readonly description?: string;\n readonly iconUrl?: string;\n readonly iconUrlDark?: string;\n readonly categories?: readonly Category[];\n readonly homepageUrl?: string;\n readonly docsUrl?: string;\n readonly allowedModelIds?: AllowedModelIds;\n}\n\n/** @since 0.0.0 @category models */\nexport interface AiProvider<\n out Identifier extends string = string,\n out AuthMethods extends readonly AuthMethod.Any[] = readonly [],\n>\n extends Pipeable.Pipeable {\n readonly [TypeId]: TypeId;\n readonly identifier: Identifier;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly iconUrl: string | undefined;\n readonly iconUrlDark: string | undefined;\n readonly categories: readonly Category[];\n readonly homepageUrl: string | undefined;\n readonly docsUrl: string | undefined;\n readonly authMethods: AuthMethods;\n readonly allowedModelIds?: AllowedModelIds | undefined;\n readonly resolveRuntimeConfig: RuntimeConfigResolver<AuthMethods> | undefined;\n}\n\n/** @since 0.0.0 @category type-level */\nexport type AddAuthMethods<Self extends Any, AddedMethods extends readonly AuthMethod.Any[]> =\n Self extends AiProvider<infer Identifier, infer AuthMethods>\n ? AiProvider<Identifier, readonly [...AuthMethods, ...AddedMethods]>\n : never;\n\nconst optionsFromProvider = (provider: Any): AiProviderOptions => ({\n identifier: provider.identifier,\n ...(provider.name === undefined ? {} : { name: provider.name }),\n ...(provider.description === undefined ? {} : { description: provider.description }),\n ...(provider.iconUrl === undefined ? {} : { iconUrl: provider.iconUrl }),\n ...(provider.iconUrlDark === undefined ? {} : { iconUrlDark: provider.iconUrlDark }),\n ...(provider.categories.length === 0 ? {} : { categories: provider.categories }),\n ...(provider.homepageUrl === undefined ? {} : { homepageUrl: provider.homepageUrl }),\n ...(provider.docsUrl === undefined ? {} : { docsUrl: provider.docsUrl }),\n ...(provider.allowedModelIds === undefined ? {} : { allowedModelIds: provider.allowedModelIds }),\n});\n\nconst Proto = { ...PipeableProto, [TypeId]: TypeId };\n\nconst makeProvider = <Identifier extends string, AuthMethods extends readonly AuthMethod.Any[]>(\n options: AiProviderOptions<Identifier>,\n authMethods: AuthMethods,\n resolveRuntimeConfig?: RuntimeConfigResolver<AuthMethods>,\n): AiProvider<Identifier, AuthMethods> => {\n validateIdentifier(\"provider\", options.identifier);\n assertNoDuplicateAuthMethodIdentifiers(options.identifier, authMethods);\n\n return Object.assign(Object.create(Proto), {\n allowedModelIds: options.allowedModelIds,\n authMethods,\n categories: options.categories ?? [],\n description: options.description,\n docsUrl: options.docsUrl,\n homepageUrl: options.homepageUrl,\n iconUrl: options.iconUrl,\n iconUrlDark: options.iconUrlDark,\n identifier: options.identifier,\n name: options.name,\n resolveRuntimeConfig,\n });\n};\n\n/** @since 0.0.0 @category constructors */\nexport const make = <const Identifier extends string>(\n identifier: Identifier,\n): AiProvider<Identifier> => makeProvider({ identifier }, [] as const);\n\n/** @since 0.0.0 @category registry */\nexport const registryId = (identifier: string): string => `ai/${identifier}`;\n\n/** @since 0.0.0 @category guards */\nexport const isAiProvider = (value: unknown): value is Any => Predicate.hasProperty(value, TypeId);\n\nconst withOption = <P extends AiProvider<any, any>>(\n provider: P,\n options: Partial<AiProviderOptions>,\n): P =>\n makeProvider(\n { ...optionsFromProvider(provider), ...options },\n provider.authMethods,\n provider.resolveRuntimeConfig,\n ) as P;\n\n/** @since 0.0.0 @category combinators */\nexport const withAllowedModelIds: {\n (resolve: AllowedModelIds): <Self extends Any>(provider: Self) => Self;\n <Self extends Any>(provider: Self, resolve: AllowedModelIds): Self;\n} = Func.dual(2, (provider: AiProvider<any, any>, allowedModelIds: AllowedModelIds) =>\n withOption(provider, { allowedModelIds }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withName: {\n (name: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, name: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, name: string) => withOption(provider, { name }));\n\n/** @since 0.0.0 @category combinators */\nexport const withDescription: {\n (description: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, description: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, description: string) =>\n withOption(provider, { description }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withIconUrl: {\n (iconUrl: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, iconUrl: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, iconUrl: string) =>\n withOption(provider, { iconUrl }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withIconUrlDark: {\n (iconUrlDark: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, iconUrlDark: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, iconUrlDark: string) =>\n withOption(provider, { iconUrlDark }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withCategories: {\n (categories: readonly Category[]): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, categories: readonly Category[]): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, categories: readonly Category[]) =>\n withOption(provider, { categories: [...categories] }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withHomepageUrl: {\n (homepageUrl: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, homepageUrl: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, homepageUrl: string) =>\n withOption(provider, { homepageUrl }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withDocsUrl: {\n (docsUrl: string): <P extends AiProvider<any, any>>(provider: P) => P;\n <P extends AiProvider<any, any>>(provider: P, docsUrl: string): P;\n} = Func.dual(2, (provider: AiProvider<any, any>, docsUrl: string) =>\n withOption(provider, { docsUrl }),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withAuthMethods: {\n <const AddedMethods extends readonly AuthMethod.Any[]>(\n methods: AddedMethods,\n ): <Self extends Any>(provider: Self) => AddAuthMethods<Self, AddedMethods>;\n <Self extends Any, const AddedMethods extends readonly AuthMethod.Any[]>(\n provider: Self,\n methods: AddedMethods,\n ): AddAuthMethods<Self, AddedMethods>;\n} = Func.dual(2, (provider: Any, methods: readonly AuthMethod.Any[]) => {\n if (provider.resolveRuntimeConfig !== undefined) {\n throw new Error(\n `AI provider \"${provider.identifier}\" must declare auth methods before its runtime config`,\n );\n }\n return makeProvider(optionsFromProvider(provider), appendElements(provider.authMethods, methods));\n});\n\n/** @since 0.0.0 @category combinators */\nexport const withAuthMethod: {\n <const AddedMethod extends AuthMethod.Any>(\n method: AddedMethod,\n ): <Self extends Any>(provider: Self) => AddAuthMethods<Self, readonly [AddedMethod]>;\n <Self extends Any, const AddedMethod extends AuthMethod.Any>(\n provider: Self,\n method: AddedMethod,\n ): AddAuthMethods<Self, readonly [AddedMethod]>;\n} = Func.dual(2, (provider: Any, method: AuthMethod.Any) =>\n withAuthMethods(provider, [method] as const),\n);\n\n/** @since 0.0.0 @category combinators */\nexport const withRuntimeConfig: {\n <Self extends Any>(resolve: RuntimeConfigResolver<Self[\"authMethods\"]>): (provider: Self) => Self;\n <Self extends Any>(provider: Self, resolve: RuntimeConfigResolver<Self[\"authMethods\"]>): Self;\n} = Func.dual(\n 2,\n (provider: AiProvider<any, any>, resolve: RuntimeConfigResolver<readonly AuthMethod.Any[]>) =>\n makeProvider(optionsFromProvider(provider), provider.authMethods, resolve),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,SAAS;;AAwBtB,MAAa,gBAAgB,OAAO,OAAO;CACzC,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,SAAS,OAAO,SAAS,OAAO,M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AGD,MAAa,iBAQTA,SAAK,KAAK,IAAI,UAAe,WAC/B,gBAAgB,UAAU,CAAC,MAAM,CAAU,CAC7C;;AAGA,MAAa,oBAGTA,SAAK,KACP,IACC,UAAgC,YAC/B,aAAa,oBAAoB,QAAQ,GAAG,SAAS,aAAa,OAAO,CAC7E"}
|
package/dist/DualRuntime.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ import { ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, Co
|
|
|
6
6
|
import { ActivateSuccess, DeactivateSuccess, EmittedEventsSuccess, VerifySuccess, WebhookRequest } from "./Trigger.js";
|
|
7
7
|
import { Any as Any$1, LayerError, LayerOutput as LayerOutput$1, LayerRequirements as LayerRequirements$1 } from "./Plugin.js";
|
|
8
8
|
import { Interface, Requirements as Requirements$1 } from "./AgentChannelRuntime.js";
|
|
9
|
-
import { Any as Any$2, RuntimeConfig, RuntimeModel } from "./AiProvider.js";
|
|
9
|
+
import { AllowedModelIds, Any as Any$2, RuntimeConfig, RuntimeModel } from "./AiProvider.js";
|
|
10
10
|
import { PluginActions } from "./internal/dual/actions.js";
|
|
11
11
|
import { ActionHandlerNotFoundError, ActionNotFoundError, FieldIssue, InvalidActionInputError, InvalidActionOutputError, InvokeError, InvokeMeta, InvokeRequest, InvokeRequirementsFor, InvokeSuccess, PluginRequirements } from "./internal/dual/invoke.js";
|
|
12
12
|
import "./DualRuntime.js";
|
|
13
13
|
import { Context, Effect, Layer, Schema } from "effect";
|
|
14
14
|
import { HttpClientRequest } from "effect/http";
|
|
15
15
|
declare namespace DualRuntime_d_exports {
|
|
16
|
-
export { ActionHandlerError, ActionHandlerFailure, ActionHandlerNotFoundError, ActionNotFoundError, AiModelConfigError, AiProviderRuntimeNotConfiguredError, AnyApp, App, AuthMethodExecutionError, AuthMethodNotFoundError, AuthMethodRequest, ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, ConnectionRequiredError, ConnectionResolverStoreError, ConnectionSelectionRequiredError, DecodeAuthMethodSetupRequest, DualRuntime_d_exports as DualRuntime, FieldIssue, InvalidActionInputError, InvalidActionOutputError, InvalidConnectionIdError, InvalidResolvedConnectionError, InvokeError, InvokeMeta, InvokeRequest, InvokeRequirementsFor, InvokeSuccess, PluginInstallation, PrepareAuthMethodRequest, PrepareOAuth2TokensRequest, RefreshAuthMethodRequest, ResolveAiModelConfigRequest, ResolveAuthMethodRequest, ResolvedSandboxAccess, RetryableActionHandlerError, RuntimeInvokeRequest, RuntimeRequirementsFor, RuntimeService, RuntimeTriggerLifecycleRequest, RuntimeWebhookActivationRequest, RuntimeWebhookTriggerLifecycleRequest, SandboxAccessError, SandboxAccessNotDeclaredError, SandboxRequestNotAllowedError, Service, ToLayerError, ToLayerRequirements, WithPlugin, WithPlugins, fromPlugin, install, invoke, make, toLayer, withPlugin, withPlugins };
|
|
16
|
+
export { ActionHandlerError, ActionHandlerFailure, ActionHandlerNotFoundError, ActionNotFoundError, AiModelConfigError, AiModelNotAllowedError, AiProviderRuntimeNotConfiguredError, AnyApp, App, AuthMethodExecutionError, AuthMethodNotFoundError, AuthMethodRequest, ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, ConnectionRequiredError, ConnectionResolverStoreError, ConnectionSelectionRequiredError, DecodeAuthMethodSetupRequest, DualRuntime_d_exports as DualRuntime, FieldIssue, InvalidActionInputError, InvalidActionOutputError, InvalidConnectionIdError, InvalidResolvedConnectionError, InvokeError, InvokeMeta, InvokeRequest, InvokeRequirementsFor, InvokeSuccess, PluginInstallation, PrepareAuthMethodRequest, PrepareOAuth2TokensRequest, RefreshAuthMethodRequest, ResolveAiModelConfigRequest, ResolveAuthMethodRequest, ResolvedSandboxAccess, RetryableActionHandlerError, RuntimeInvokeRequest, RuntimeRequirementsFor, RuntimeService, RuntimeTriggerLifecycleRequest, RuntimeWebhookActivationRequest, RuntimeWebhookTriggerLifecycleRequest, SandboxAccessError, SandboxAccessNotDeclaredError, SandboxRequestNotAllowedError, Service, ToLayerError, ToLayerRequirements, WithPlugin, WithPlugins, fromPlugin, install, invoke, make, toLayer, withPlugin, withPlugins };
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* One installed plugin release.
|
|
@@ -182,7 +182,12 @@ declare const AiProviderRuntimeNotConfiguredError_base: Schema.Class<AiProviderR
|
|
|
182
182
|
readonly providerId: Schema.String;
|
|
183
183
|
}>, import("effect/Cause").YieldableError>;
|
|
184
184
|
export declare class AiProviderRuntimeNotConfiguredError extends AiProviderRuntimeNotConfiguredError_base {}
|
|
185
|
-
|
|
185
|
+
declare const AiModelNotAllowedError_base: Schema.Class<AiModelNotAllowedError, Schema.TaggedStruct<"AiModelNotAllowedError", {
|
|
186
|
+
readonly modelId: Schema.String;
|
|
187
|
+
readonly providerId: Schema.String;
|
|
188
|
+
}>, import("effect/Cause").YieldableError>;
|
|
189
|
+
export declare class AiModelNotAllowedError extends AiModelNotAllowedError_base {}
|
|
190
|
+
export type AiModelConfigError = AuthMethodExecutionError | AiProviderRuntimeNotConfiguredError | AiModelNotAllowedError;
|
|
186
191
|
declare const SandboxAccessNotDeclaredError_base: Schema.Class<SandboxAccessNotDeclaredError, Schema.TaggedStruct<"SandboxAccessNotDeclaredError", {
|
|
187
192
|
readonly providerId: Schema.String;
|
|
188
193
|
}>, import("effect/Cause").YieldableError>;
|
|
@@ -227,6 +232,7 @@ export interface RuntimeService {
|
|
|
227
232
|
readonly prepareOAuth2Tokens: (request: PrepareOAuth2TokensRequest) => Effect.Effect<unknown, AuthMethodExecutionError>;
|
|
228
233
|
readonly refreshAuthMethod: (request: RefreshAuthMethodRequest) => Effect.Effect<unknown | undefined, AuthMethodExecutionError>;
|
|
229
234
|
readonly resolveAuthMethod: (request: ResolveAuthMethodRequest) => Effect.Effect<Binding, AuthMethodExecutionError>;
|
|
235
|
+
readonly allowedModelIdsFor: (providerId: string) => AllowedModelIds | undefined;
|
|
230
236
|
readonly resolveAiModelConfig: (request: ResolveAiModelConfigRequest) => Effect.Effect<RuntimeConfig, AiModelConfigError>;
|
|
231
237
|
readonly resolveSandboxAccess: (request: ResolveAuthMethodRequest) => Effect.Effect<ResolvedSandboxAccess, SandboxAccessError>;
|
|
232
238
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DualRuntime.d.ts","names":["Plugin.Any","AiProvider.Any","Plugin.LayerOutput","Plugin.LayerError","Plugin.LayerRequirements","Trigger.WebhookRequest","AuthMethod.OAuth2TokenResponse","AuthMethod.RefreshReason","AiProvider.RuntimeModel","AuthMethod.ExpectedOAuth2MethodError","AuthMethod.OAuth2RefreshTokenUnavailableError","AuthMethod.AuthMethodHookError","AuthMethodExecution.JsonRequest","AgentChannelRuntime.Interface","Trigger.ActivateSuccess","Trigger.DeactivateSuccess","Trigger.VerifySuccess","Trigger.EmittedEventsSuccess","AuthMethod.Any","AuthMethodBinding.Binding","AiProvider.RuntimeConfig","AgentChannelRuntime.Requirements","AuthMethod.SetupSchema","AuthMethod.InputSchema","AuthMethod.Requirements","AuthMethod.MaterialSchema","AuthMethod.ValueSchema"],"sources":["../src/DualRuntime.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;iBAqEiB,mBAAmB,UAAUA,QAAaA;WAChD,QAAQ;;WAER;;;;;;;;iBASM,QACX,UAAUA,QAAaA,OAC3B,yBACI,wBACA,+BACA,6BAA6BC,mBAA4BA;WAEpD;WACA,aAAa;WACb,kBAAkB,mBAAmB;WACrC,OAAO,MAAM,MAAM,aAAa,YAAY;;;;;;;;iBAStC,eAAe,IAAID,iCAAsCC;;;;;;;qBAQ7D,UAAW,UAAUD,OAAU,QAClC,GAAC,oBAER,mBAAmB;;;;;;;;qBAST,mBAAoB,UAAUA,OAAU,QAC3C,GAAC,qBAER,IACD,GACAE,wBAA6B,KAC7BC,qBAA4B,KAC5BC,8BAAmC;;;;;;;qBAgBxB,OAAI,uBAAyB;KAOrC,UAAU,UAAU,UAAU,UAAU,UAAU,yBAAyB;KAC3E,eAAe,UAAU,UAC5B,UAAU,eAAe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uBAAuB;;;;;;;iBAQlB;WACN;WACA;;WAEA;WACA;WACA;WACA;WACA,UAAU;;iBAGJ,wCAAwC;WAC9C;;iBAGM,8CAA8C;WACpD,SAASI;;iBAGH;WACN;WACA;;iBAGM,qCAAqC;WAC3C;WACA;;iBAGM,iCAAiC;WACvC;WACA;;iBAGM,mCAAmC;WACzC,QAAQC;WACR;;iBAGM,iCAAiC;WACvC;WACA;WACA;WACA;WACA,QAAQC;;iBAGF,iCAAiC;;WAEvC;WACA;WACA;;iBAGM,oCAAoC;WAC1C,OAAOC;;;;;;qBAGL,gCAAgC;YAKjC,2BACR,0BACA,OAAO,cACPC,4BACAC,qCACAC;;;;qBAES,4CAA4C;
|
|
1
|
+
{"version":3,"file":"DualRuntime.d.ts","names":["Plugin.Any","AiProvider.Any","Plugin.LayerOutput","Plugin.LayerError","Plugin.LayerRequirements","Trigger.WebhookRequest","AuthMethod.OAuth2TokenResponse","AuthMethod.RefreshReason","AiProvider.RuntimeModel","AuthMethod.ExpectedOAuth2MethodError","AuthMethod.OAuth2RefreshTokenUnavailableError","AuthMethod.AuthMethodHookError","AuthMethodExecution.JsonRequest","AgentChannelRuntime.Interface","Trigger.ActivateSuccess","Trigger.DeactivateSuccess","Trigger.VerifySuccess","Trigger.EmittedEventsSuccess","AuthMethod.Any","AuthMethodBinding.Binding","AiProvider.AllowedModelIds","AiProvider.RuntimeConfig","AgentChannelRuntime.Requirements","AuthMethod.SetupSchema","AuthMethod.InputSchema","AuthMethod.Requirements","AuthMethod.MaterialSchema","AuthMethod.ValueSchema"],"sources":["../src/DualRuntime.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;iBAqEiB,mBAAmB,UAAUA,QAAaA;WAChD,QAAQ;;WAER;;;;;;;;iBASM,QACX,UAAUA,QAAaA,OAC3B,yBACI,wBACA,+BACA,6BAA6BC,mBAA4BA;WAEpD;WACA,aAAa;WACb,kBAAkB,mBAAmB;WACrC,OAAO,MAAM,MAAM,aAAa,YAAY;;;;;;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ACA,QAAQ,uBAAuB,IAAI,eACnC,QAAQ,mCAAmC,IAAI,sBAAsB;;;;;;;YASnE,aAAa,UAAU,UACjC,UAAU,oBAAoB,wBAAwB;;;;;;;qBAQ3C,gBACL,UAAUD,OAChB,aACA,YACA,yBACM,6BAA6BC,SAAgB,KAE9C,IAAI,GAAG,aAAa,YAAY,mBAAmB,iBACvD,MAAM,MACP,SACA,YACE,oBACA,QAAQ,uBAAuB,IAAI,eACnC,QAAQ,mCAAmC,IAAI,sBAAsB"}
|
package/dist/DualRuntime.js
CHANGED
|
@@ -26,6 +26,7 @@ var DualRuntime_exports = /* @__PURE__ */ __exportAll({
|
|
|
26
26
|
ActionHandlerError: () => ActionHandlerError,
|
|
27
27
|
ActionHandlerNotFoundError: () => ActionHandlerNotFoundError,
|
|
28
28
|
ActionNotFoundError: () => ActionNotFoundError,
|
|
29
|
+
AiModelNotAllowedError: () => AiModelNotAllowedError,
|
|
29
30
|
AiProviderRuntimeNotConfiguredError: () => AiProviderRuntimeNotConfiguredError,
|
|
30
31
|
AuthMethodNotFoundError: () => AuthMethodNotFoundError,
|
|
31
32
|
ConnectionIdNotAllowedError: () => ConnectionIdNotAllowedError,
|
|
@@ -142,6 +143,10 @@ var AuthMethodNotFoundError = class extends Schema.TaggedError()("AuthMethodNotF
|
|
|
142
143
|
providerId: Schema.String
|
|
143
144
|
}) {};
|
|
144
145
|
var AiProviderRuntimeNotConfiguredError = class extends Schema.TaggedError()("AiProviderRuntimeNotConfiguredError", { providerId: Schema.String }) {};
|
|
146
|
+
var AiModelNotAllowedError = class extends Schema.TaggedError()("AiModelNotAllowedError", {
|
|
147
|
+
modelId: Schema.String,
|
|
148
|
+
providerId: Schema.String
|
|
149
|
+
}) {};
|
|
145
150
|
/** Raised when a provider declares no sandbox access. */
|
|
146
151
|
var SandboxAccessNotDeclaredError = class extends Schema.TaggedError()("SandboxAccessNotDeclaredError", { providerId: Schema.String }) {};
|
|
147
152
|
/** Raised when the Connection may not be sent with a sandbox request: another origin, or a request the provider refuses. */
|
|
@@ -248,6 +253,11 @@ const toLayer = (app) => {
|
|
|
248
253
|
const provider = app.aiProviders.find((candidate) => registryId(candidate.identifier) === request.providerId);
|
|
249
254
|
if (provider?.resolveRuntimeConfig === void 0) return yield* new AiProviderRuntimeNotConfiguredError({ providerId: request.providerId });
|
|
250
255
|
const binding = yield* resolveAuthMethod(request);
|
|
256
|
+
const allowed = provider.allowedModelIds?.(request.material);
|
|
257
|
+
if (allowed !== void 0 && !allowed.includes(request.model.id)) return yield* new AiModelNotAllowedError({
|
|
258
|
+
modelId: request.model.id,
|
|
259
|
+
providerId: request.providerId
|
|
260
|
+
});
|
|
251
261
|
const resolveRuntimeConfig = provider.resolveRuntimeConfig;
|
|
252
262
|
return yield* Schema.decodeUnknownEffect(RuntimeConfig)(resolveRuntimeConfig({
|
|
253
263
|
binding,
|
|
@@ -298,6 +308,7 @@ const toLayer = (app) => {
|
|
|
298
308
|
prepareAuthMethod,
|
|
299
309
|
prepareOAuth2Tokens: prepareOAuth2Tokens$1,
|
|
300
310
|
refreshAuthMethod,
|
|
311
|
+
allowedModelIdsFor: (providerId) => app.aiProviders.find((provider) => registryId(provider.identifier) === providerId)?.allowedModelIds,
|
|
301
312
|
resolveAiModelConfig,
|
|
302
313
|
resolveAuthMethod,
|
|
303
314
|
resolveSandboxAccess,
|
|
@@ -305,6 +316,6 @@ const toLayer = (app) => {
|
|
|
305
316
|
});
|
|
306
317
|
})).pipe(Layer.provide(layer(app.plugins.map((installation) => installation.plugin))), Layer.provide(app.layer));
|
|
307
318
|
};
|
|
308
|
-
export { ActionHandlerError, ActionHandlerNotFoundError, ActionNotFoundError, AiProviderRuntimeNotConfiguredError, AuthMethodNotFoundError, ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, ConnectionRequiredError, ConnectionResolverStoreError, ConnectionSelectionRequiredError, DualRuntime_exports as DualRuntime, DualRuntime_exports, FieldIssue, InvalidActionInputError, InvalidActionOutputError, InvalidConnectionIdError, InvalidResolvedConnectionError, RetryableActionHandlerError, SandboxAccessNotDeclaredError, SandboxRequestNotAllowedError, Service, fromPlugin, install, invoke, make, toLayer, withPlugin, withPlugins };
|
|
319
|
+
export { ActionHandlerError, ActionHandlerNotFoundError, ActionNotFoundError, AiModelNotAllowedError, AiProviderRuntimeNotConfiguredError, AuthMethodNotFoundError, ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, ConnectionRequiredError, ConnectionResolverStoreError, ConnectionSelectionRequiredError, DualRuntime_exports as DualRuntime, DualRuntime_exports, FieldIssue, InvalidActionInputError, InvalidActionOutputError, InvalidConnectionIdError, InvalidResolvedConnectionError, RetryableActionHandlerError, SandboxAccessNotDeclaredError, SandboxRequestNotAllowedError, Service, fromPlugin, install, invoke, make, toLayer, withPlugin, withPlugins };
|
|
309
320
|
|
|
310
321
|
//# sourceMappingURL=DualRuntime.js.map
|