@dual-os/sdk 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +3 -3
- package/src/AiProvider.ts +16 -0
- package/src/DualRuntime.ts +21 -1
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,eAAa,OAAA;;;;;;;YAQd,uBAAuB,cAAc;;iBAGhC;WACN;WACA;;;iBAIM,2BAA2B,yBAAyBA;WAC1D,OAAO;WACP,SAASC,WAA6B;;;YAIrC,sBAAsB,yBAAyBD,YACzD,OAAO,2BAA2B,aAC/B;;iBAGY,kBAAkB;WACxB,YAAY;WACZ;WACA;WACA;WACA;WACA,sBAAsB;WACtB;WACA;WACA,kBAAkB;;;iBAIZ,eACX,wCACA,6BAA6BA,+BAEzB,SAAS;YACP,SAAS;WACV,YAAY;WACZ;WACA;WACA;WACA;WACA,qBAAqB;WACrB;WACA;WACA,aAAa;WACb,kBAAkB;WAClB,sBAAsB,sBAAsB;;;YAI3C,eAAe,aAAa,KAAK,8BAA8BA,WACzE,aAAa,iBAAiB,kBAAkB,eAC5C,WAAW,yBAAyB,gB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AM,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;AA2DD,MAAM,uBAAuB,cAAsC;CACjE,YAAY,SAAS;CACrB,GAAI,SAAS,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,SAAS,KAAK;CAC7D,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,SAAS,YAAY;CAClF,GAAI,SAAS,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,SAAS,QAAQ;CACtE,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,SAAS,YAAY;CAClF,GAAI,SAAS,WAAW,WAAW,IAAI,CAAC,IAAI,EAAE,YAAY,SAAS,WAAW;CAC9E,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,SAAS,YAAY;CAClF,GAAI,SAAS,YA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gC,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,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;AA6DD,MAAM,uBAAuB,cAAsC;CACjE,YAAY,SAAS;CACrB,GAAI,SAAS,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,SAAS,KAAK;CAC7D,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,SAAS,YAAY;CAClF,GAAI,SAAS,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,SAAS,QAAQ;CACtE,GAAI,SAAS,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa,SAAS,YA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,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"}
|
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,yBAAyB;KAC/C,cAAc,UAAU,UAC3B,UAAU,oBAAoB,mBAAmB;KAC9C,qBAAqB,UAAU,UAClC,UAAU,yBAAyB,qBAAqB;;;;;;;;iBASzC,WAAW,aAAa,QAAQ,cAAcJ,eAAoB,IACjF,UAAU,QAAQ,OAClB,eAAe,QAAQE,wBAA6B,SACpD,cAAc,QAAQC,qBAA4B,SAChDC,8BAAmC,UACnC,QAAQ,qBAAqB,OAAOF,wBAA6B,UACnE;KAMG,sBACH,uBAAuBF,SACvB,+BACiB,kBACf,eAAe,MAAM,SAAS,0BAC9B,8BACU,aAAaA,gBACV,sBAAsBA,WAEjC,sBACE,MACA,MAAM,SAAS,iBAAiB,QAAQ,cAAc,MAAM,QAAQ,mBAEtE;;;;;;;iBAQW,YAAY,aAAa,QAAQ,uBAAuBA,iB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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;;;;;;;;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,yBAAyB;KAC/C,cAAc,UAAU,UAC3B,UAAU,oBAAoB,mBAAmB;KAC9C,qBAAqB,UAAU,UAClC,UAAU,yBAAyB,qBAAqB;;;;;;;;iBASzC,WAAW,aAAa,QAAQ,cAAcJ,eAAoB,IACjF,UAAU,QAAQ,OAClB,eAAe,Q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gB;YAIjB,uBAAuB,UAAUrB,SACzCsB,eAAiC,MAChC,UAAUtB,QAAa,mBAAmB,GAAG,cAAc;KAE3D,eAAeA,QAAaC;KAE5B,cAAc,kBAAkB,gBAAgB;KAEhD,kCAAkC,eAAeiB,OACpDK,YAAuB,gBAAgB,OAAO,MAC1C,OAAO,MAAM,iBAAiBA,YAAuB;KAGtD,kCAAkC,eAAeL,OACpDM,YAAuB,gBAAgB,OAAO,MAC1C,OAAO,MAAM,iBAAiBA,YAAuB;KAGtD,mCAAmC,kBAAkB,gBACxD,cAAc,0BAAyB,UACnC,eAAeN,MAETO,aAAwB,UACxB,kCAAkC,UAClC,kCAAkC,UAClC,OAAO,MAAM,iBAAiBC,eAA0B,WACxD,OAAO,MAAM,iBAAiBC,YAAuB,WACrD,OAAO,MAAM,iBAAiBD,eAA0B,WACxD,OAAO,MAAM,iBAAiBC,YAAuB,YACpDJ,YAAuB,gBAAgB,OAAO,MAC3C,OAAO,MAAM,iBAAiBA,YAAuB;;;;;;;;;;;;;;;;YAoBzD,oBAAoB,UAAU,UACxC,UAAU,UACF,UAAUvB,aACV,wBAEA,yBACA,6BAA6BC,WAG7B,oBACA,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
|
package/dist/DualRuntime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DualRuntime.js","names":["Func","AiProvider.registryId","AgentChannelRuntime.Service","Trigger.activate","Trigger.deactivate","Trigger.verify","Trigger.parse","Trigger.poll","AuthMethodExecution.decodeSetup","AuthMethodExecution.prepare","prepareOAuth2Tokens","AuthMethodExecution.prepareOAuth2Tokens","AuthMethodExecution.refreshUnknown","AuthMethodExecution.resolveDecoded","AuthMethodExecution.resolve","AuthMethodBinding.makeBinding","AiProvider.RuntimeConfig","AuthMethodExecution.executeJson","AgentChannelRuntime.layer"],"sources":["../src/DualRuntime.ts"],"sourcesContent":["/**\n * Dual action invocation, trigger lifecycle, and auth runtime.\n *\n * @since 0.0.0\n */\nimport {\n Array,\n Context,\n Effect,\n Function as Func,\n Layer,\n Predicate,\n Result,\n Schema,\n pipe,\n} from \"effect\";\n\nimport { type HttpClientRequest, Url } from \"effect/http\";\n\nimport {\n ActionHandlerError,\n RetryableActionHandlerError,\n type ActionHandlerFailure,\n} from \"./Action.ts\";\nimport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\nimport * as AiProvider from \"./AiProvider.ts\";\nimport type * as AuthMethod from \"./AuthMethod.ts\";\nimport * as AuthMethodBinding from \"./AuthMethodBinding.ts\";\nimport * as AuthMethodExecution from \"./AuthMethodExecution.ts\";\nimport {\n ConnectionIdNotAllowedError,\n ConnectionReauthorizationRequiredError,\n ConnectionRequiredError,\n ConnectionSelectionRequiredError,\n ConnectionResolverStoreError,\n InvalidConnectionIdError,\n InvalidResolvedConnectionError,\n type ConnectionResolutionContext,\n} from \"./ConnectionResolver.ts\";\nimport { BuilderCollisionError } from \"./DefinitionError.ts\";\nimport { TriggerNotFoundError } from \"./DualRegistry.ts\";\nimport { authRuntimeContext } from \"./internal/auth-execution.ts\";\nimport { resolveAction, type PluginActions } from \"./internal/dual/actions.ts\";\nimport {\n ActionNotFoundError,\n FieldIssue,\n InvalidActionInputError,\n InvalidActionOutputError,\n ActionHandlerNotFoundError,\n type InvokeError,\n type InvokeMeta,\n type InvokeRequest,\n type InvokeRequirementsFor,\n type InvokeSuccess,\n type PluginRequirements,\n invokeResolvedAction,\n invokeResolvedActionJson,\n} from \"./internal/dual/invoke.ts\";\nimport { resolveRuntimeTrigger } from \"./internal/dual/triggers.ts\";\nimport { indexGroups } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\nimport * as Trigger from \"./Trigger.ts\";\n\n/**\n * One installed plugin release.\n *\n * @since 0.7.0\n * @category models\n */\nexport interface PluginInstallation<P extends Plugin.Any = Plugin.Any> {\n readonly plugin: P;\n /** The plugin's package version. */\n readonly version: string;\n}\n\n/**\n * The plugin releases and AI providers one runtime executes, with the services their handlers need.\n *\n * @since 0.7.0\n * @category models\n */\nexport interface App<\n out P extends Plugin.Any = Plugin.Any,\n LayerOutput = never,\n out LayerError = never,\n out LayerRequirements = never,\n out AiProviders extends readonly AiProvider.Any[] = readonly AiProvider.Any[],\n> {\n readonly identifier: string;\n readonly aiProviders: AiProviders;\n readonly plugins: readonly PluginInstallation<P>[];\n readonly layer: Layer.Layer<LayerOutput, LayerError, LayerRequirements>;\n}\n\n/**\n * Constraint type for working with any {@link App}.\n *\n * @since 0.7.0\n * @category type-level\n */\nexport interface AnyApp extends App<Plugin.Any, never, any, any, readonly AiProvider.Any[]> {}\n\n/**\n * Install one plugin release.\n *\n * @since 0.7.0\n * @category constructors\n */\nexport const install = <P extends Plugin.Any>(\n plugin: P,\n version: string,\n): PluginInstallation<P> => ({ plugin, version });\n\n/**\n * The runtime of one plugin release, as the plugin's own process runs it. `version` defaults to\n * `0.0.0` for tests that do not need the package version.\n *\n * @since 0.7.0\n * @category constructors\n */\nexport const fromPlugin = <const P extends Plugin.Any>(\n plugin: P,\n version = \"0.0.0\",\n): App<\n P,\n Plugin.LayerOutput<readonly [P]>,\n Plugin.LayerError<readonly [P]>,\n Plugin.LayerRequirements<readonly [P]>,\n readonly []\n> =>\n ({\n aiProviders: [],\n identifier: plugin.identifier,\n layer: plugin.layer,\n plugins: [install(plugin, version)],\n }) as never;\n\n/**\n * An app runtime without plugins, for {@link withPlugin} and {@link withPlugins} to fill.\n *\n * @since 0.7.0\n * @category constructors\n */\nexport const make = (identifier: string): App<never, never, never, never, readonly []> => ({\n aiProviders: [],\n identifier,\n layer: Layer.empty,\n plugins: [],\n});\n\ntype AppPlugin<A extends AnyApp> = A extends App<infer P, any, any, any, any> ? P : never;\ntype AppLayerOutput<A extends AnyApp> =\n A extends App<any, infer Output, any, any, any> ? Output : never;\ntype AppLayerError<A extends AnyApp> =\n A extends App<any, any, infer Error, any, any> ? Error : never;\ntype AppLayerRequirements<A extends AnyApp> =\n A extends App<any, any, any, infer Requirements, any> ? Requirements : never;\n\n/**\n * Result of adding a plugin release to an app runtime. A named interface keeps declaration emit\n * from expanding every plugin and layer member at large call sites.\n *\n * @since 0.7.0\n * @category type-level\n */\nexport interface WithPlugin<Self extends AnyApp, Added extends Plugin.Any> extends App<\n AppPlugin<Self> | Added,\n AppLayerOutput<Self> | Plugin.LayerOutput<readonly [Added]>,\n AppLayerError<Self> | Plugin.LayerError<readonly [Added]>,\n | Plugin.LayerRequirements<readonly [Added]>\n | Exclude<AppLayerRequirements<Self>, Plugin.LayerOutput<readonly [Added]>>,\n Self[\"aiProviders\"]\n // oxlint-disable-next-line typescript/no-empty-object-type -- TypeScript declaration emit expands a type alias at every app call site (TS7056).\n> {}\n\n// Match the runtime's left-to-right provideMerge fold: later plugins can\n// satisfy earlier requirements, but earlier outputs cannot satisfy later ones.\ntype BulkLayerRequirements<\n Added extends readonly Plugin.Any[],\n Requirements,\n> = number extends Added[\"length\"]\n ? Requirements | Layer.Services<Added[number][\"layer\"]>\n : Added extends readonly [\n infer Head extends Plugin.Any,\n ...infer Tail extends readonly Plugin.Any[],\n ]\n ? BulkLayerRequirements<\n Tail,\n Layer.Services<Head[\"layer\"]> | Exclude<Requirements, Layer.Success<Head[\"layer\"]>>\n >\n : Requirements;\n\n/**\n * Result of adding several plugin releases to an app runtime in one step.\n *\n * @since 0.7.0\n * @category type-level\n */\nexport interface WithPlugins<Self extends AnyApp, Added extends readonly Plugin.Any[]> extends App<\n AppPlugin<Self> | Added[number],\n AppLayerOutput<Self> | Layer.Success<Added[number][\"layer\"]>,\n AppLayerError<Self> | Layer.Error<Added[number][\"layer\"]>,\n BulkLayerRequirements<Added, AppLayerRequirements<Self>>,\n Self[\"aiProviders\"]\n // oxlint-disable-next-line typescript/no-empty-object-type -- TypeScript declaration emit expands a type alias at every app call site (TS7056).\n> {}\n\n/** A plugin and the package version of its release. */\ntype PluginEntry = readonly [plugin: Plugin.Any, version: string];\n\ntype PluginsOf<Entries extends readonly PluginEntry[]> = {\n readonly [K in keyof Entries]: Entries[K][0];\n};\n\nfunction addPlugins(app: AnyApp, entries: readonly PluginEntry[]): AnyApp {\n const seen = new Set(Array.map(app.plugins, installation => installation.plugin.identifier));\n for (const [plugin] of entries) {\n if (seen.has(plugin.identifier)) {\n throw new BuilderCollisionError({\n childKind: \"plugin\",\n existingChildKind: \"plugin\",\n identifier: plugin.identifier,\n ownerIdentifier: app.identifier,\n ownerKind: \"dual\",\n });\n }\n seen.add(plugin.identifier);\n }\n return {\n ...app,\n layer: Array.reduce(entries, app.layer, (layer, [plugin]) =>\n Layer.provideMerge(layer, plugin.layer),\n ),\n plugins: [\n ...app.plugins,\n ...Array.map(entries, ([plugin, version]) => install(plugin, version)),\n ],\n };\n}\n\n/**\n * Add one plugin release: the plugin and its package version.\n *\n * @since 0.7.0\n * @category combinators\n */\nexport const withPlugin: {\n <const P extends Plugin.Any>(\n plugin: P,\n version: string,\n ): <Self extends AnyApp>(app: Self) => WithPlugin<Self, P>;\n <Self extends AnyApp, const P extends Plugin.Any>(\n app: Self,\n plugin: P,\n version: string,\n ): WithPlugin<Self, P>;\n} = Func.dual(3, (app: AnyApp, plugin: Plugin.Any, version: string) =>\n addPlugins(app, [[plugin, version]]),\n);\n\n/**\n * Add several plugin releases in one step, which keeps a large app's inferred type compact.\n *\n * @since 0.7.0\n * @category combinators\n */\nexport const withPlugins: {\n <const E extends readonly PluginEntry[]>(\n entries: E,\n ): <Self extends AnyApp>(app: Self) => WithPlugins<Self, PluginsOf<E>>;\n <Self extends AnyApp, const E extends readonly PluginEntry[]>(\n app: Self,\n entries: E,\n ): WithPlugins<Self, PluginsOf<E>>;\n} = Func.dual(2, addPlugins);\n\nconst pluginOf = (app: AnyApp, identifier: string): Plugin.Any | undefined =>\n app.plugins.find(installation => installation.plugin.identifier === identifier)?.plugin;\n\n/**\n * Request payload accepted by {@link invoke}.\n *\n * @since 0.0.0\n * @category models\n */\nexport type { InvokeRequest };\n\n/**\n * Metadata returned alongside successful invocation data.\n *\n * @since 0.0.0\n * @category models\n */\nexport type { InvokeMeta };\n\n/**\n * Successful invocation envelope returned by {@link invoke}.\n *\n * @since 0.0.0\n * @category models\n */\nexport type { InvokeSuccess };\n\n/**\n * Structured field-level validation issue surfaced by {@link InvalidActionInputError}.\n *\n * @since 0.0.0\n * @category models\n */\nexport { FieldIssue };\n\n/**\n * Raised when an invocation references an unknown action id.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ActionNotFoundError };\n\n/**\n * @since 0.0.0\n * @category errors\n */\n\n/**\n * Raised when invocation input fails schema validation.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidActionInputError };\n\n/**\n * Raised when action handler output fails schema validation.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidActionOutputError };\n\n/**\n * Raised when the runtime action handler service is missing.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ActionHandlerNotFoundError };\n\n/**\n * Non-retryable failure reported by a trusted action handler.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ActionHandlerError };\n\n/**\n * Retryable failure reported by a trusted action handler.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { RetryableActionHandlerError };\n\n/**\n * Stable trusted action handler failure contract.\n *\n * @since 0.0.0\n * @category errors\n */\nexport type { ActionHandlerFailure };\n\n/**\n * Raised when an action does not accept a connection but a connectionId was still provided.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionIdNotAllowedError };\n\n/**\n * Raised when invocation requires a connection and no compatible binding is available.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionRequiredError };\n\n/**\n * Raised when several compatible connection bindings exist and the caller must choose one.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionSelectionRequiredError };\n\n/**\n * Raised when the provider refuses a connection's stored grant and the user must sign in again.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionReauthorizationRequiredError };\n\n/**\n * Raised when the host connection store is unavailable.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionResolverStoreError };\n\n/**\n * Raised when a connectionId does not resolve to a compatible binding.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidConnectionIdError };\n\n/**\n * Raised when a resolved connection binding does not satisfy its auth method schema.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidResolvedConnectionError };\n\n/**\n * Structured SDK-owned invocation failures.\n *\n * @since 0.0.0\n * @category errors\n */\nexport type { InvokeError };\nexport type { InvokeRequirementsFor };\n\n/**\n * Invoke an action directly in-process.\n *\n * The invocation boundary resolves an action by canonical machine id, validates\n * unknown input against the resolved runtime schema, runs the handler, and\n * returns a standard success envelope. This mirrors the server trusted invoke\n * boundary: runtime schema validation is authoritative.\n *\n * @since 0.0.0\n * @category execution\n */\nconst failInvokeActionNotFound = (\n actionId: string,\n): Effect.Effect<InvokeSuccess, ActionNotFoundError> =>\n Effect.fail(new ActionNotFoundError({ actionId }));\n\nconst invokeRaw = <\n const P extends Plugin.Any,\n LayerOutput,\n LayerError,\n LayerRequirements,\n const AiProviders extends readonly AiProvider.Any[],\n>(\n app: App<P, LayerOutput, LayerError, LayerRequirements, AiProviders>,\n request: InvokeRequest,\n json = false,\n): Effect.Effect<InvokeSuccess, InvokeError, RuntimeRequirementsFor<P>> => {\n const resolved = resolveAction(app.plugins, request.actionId, request.actionVersion);\n\n if (\n resolved === undefined ||\n (request.pluginKey !== undefined && resolved.providerId !== request.pluginKey)\n ) {\n return failInvokeActionNotFound(request.actionId);\n }\n\n // The runtime entry is resolved from erased plugin trees, so the precise\n // per-action requirement union in the return annotation cannot be recovered\n // here; the annotation is the contract, the cast is the boundary.\n return (json ? invokeResolvedActionJson : invokeResolvedAction)(\n resolved.providerId,\n resolved.actionId,\n resolved.pluginVersion,\n resolved.action,\n resolved.authMethods,\n request,\n ) as never;\n};\n\nexport const invoke = <\n const P extends Plugin.Any,\n LayerOutput,\n LayerError,\n LayerRequirements,\n const AiProviders extends readonly AiProvider.Any[],\n>(\n app: App<P, LayerOutput, LayerError, LayerRequirements, AiProviders>,\n request: InvokeRequest,\n): Effect.Effect<\n InvokeSuccess,\n InvokeError | LayerError,\n LayerRequirements | Exclude<RuntimeRequirementsFor<P>, LayerOutput>\n> => invokeRaw(app, request).pipe(Effect.provide(app.layer));\n\n/**\n * Runtime-first invocation request accepted by {@link Service}.\n *\n * @since 0.0.0\n * @category models\n */\nexport type RuntimeInvokeRequest = InvokeRequest;\n\n/**\n * Runtime-first trigger lifecycle request accepted by {@link Service}.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface RuntimeTriggerLifecycleRequest {\n readonly triggerId: string;\n readonly pluginKey?: string;\n /** The exact plugin release the caller pinned; another installed release does not run. */\n readonly triggerVersion?: string | undefined;\n readonly config: unknown;\n readonly state?: unknown | undefined;\n readonly connectionId?: string | undefined;\n readonly context?: ConnectionResolutionContext | undefined;\n}\n\nexport interface RuntimeWebhookActivationRequest extends RuntimeTriggerLifecycleRequest {\n readonly webhookUrl: string;\n}\n\nexport interface RuntimeWebhookTriggerLifecycleRequest extends RuntimeWebhookActivationRequest {\n readonly request: Trigger.WebhookRequest;\n}\n\nexport interface AuthMethodRequest {\n readonly providerId: string;\n readonly authMethodId: string;\n}\n\nexport interface DecodeAuthMethodSetupRequest extends AuthMethodRequest {\n readonly encoding?: \"json\";\n readonly setup: unknown;\n}\n\nexport interface PrepareAuthMethodRequest extends AuthMethodRequest {\n readonly input: unknown;\n readonly setup: unknown;\n}\n\nexport interface PrepareOAuth2TokensRequest extends AuthMethodRequest {\n readonly tokens: AuthMethod.OAuth2TokenResponse;\n readonly setup: unknown;\n}\n\nexport interface RefreshAuthMethodRequest extends AuthMethodRequest {\n readonly material: unknown;\n readonly setup: unknown;\n readonly now: number;\n readonly minValidityMs: number;\n readonly reason: AuthMethod.RefreshReason;\n}\n\nexport interface ResolveAuthMethodRequest extends AuthMethodRequest {\n /** `json` when the material and setup arrive in their canonical JSON encoding, as in the sandbox. */\n readonly encoding?: \"json\";\n readonly material: unknown;\n readonly setup: unknown;\n}\n\nexport interface ResolveAiModelConfigRequest extends ResolveAuthMethodRequest {\n readonly model: AiProvider.RuntimeModel;\n}\n\nexport class AuthMethodNotFoundError extends Schema.TaggedError<AuthMethodNotFoundError>()(\n \"AuthMethodNotFoundError\",\n { authMethodId: Schema.String, providerId: Schema.String },\n) {}\n\nexport type AuthMethodExecutionError =\n | AuthMethodNotFoundError\n | Schema.SchemaError\n | AuthMethod.ExpectedOAuth2MethodError\n | AuthMethod.OAuth2RefreshTokenUnavailableError\n | AuthMethod.AuthMethodHookError;\n\nexport class AiProviderRuntimeNotConfiguredError extends Schema.TaggedError<AiProviderRuntimeNotConfiguredError>()(\n \"AiProviderRuntimeNotConfiguredError\",\n { providerId: Schema.String },\n) {}\n\nexport type AiModelConfigError = AuthMethodExecutionError | AiProviderRuntimeNotConfiguredError;\n\n/** Raised when a provider declares no sandbox access. */\nexport class SandboxAccessNotDeclaredError extends Schema.TaggedError<SandboxAccessNotDeclaredError>()(\n \"SandboxAccessNotDeclaredError\",\n { providerId: Schema.String },\n) {}\n\n/** Raised when the Connection may not be sent with a sandbox request: another origin, or a request the provider refuses. */\nexport class SandboxRequestNotAllowedError extends Schema.TaggedError<SandboxRequestNotAllowedError>()(\n \"SandboxRequestNotAllowedError\",\n { origin: Schema.String, path: Schema.String, providerId: Schema.String },\n) {}\n\nexport type SandboxAccessError = AuthMethodExecutionError | SandboxAccessNotDeclaredError;\n\n/** One Connection's sandbox access: where its credential may go, and how a request gets it. */\nexport interface ResolvedSandboxAccess {\n readonly origins: readonly string[];\n readonly authorize: (\n request: HttpClientRequest.HttpClientRequest,\n ) => Effect.Effect<HttpClientRequest.HttpClientRequest, SandboxRequestNotAllowedError>;\n}\n\n/**\n * Runtime service materialized from an {@link App}.\n *\n * @since 0.0.0\n * @category services\n */\nexport interface RuntimeService {\n readonly executeAuthJson: (\n request: AuthMethodExecution.JsonRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly invokeJson: (\n request: RuntimeInvokeRequest,\n ) => Effect.Effect<InvokeSuccess<string, Schema.Json>, InvokeError | Schema.SchemaError>;\n readonly decodeAgentChannelDefinitionSettings: AgentChannelRuntime.Interface[\"decodeDefinitionSettings\"];\n readonly decodeAgentChannelDeploymentSettings: AgentChannelRuntime.Interface[\"decodeDeploymentSettings\"];\n readonly getAgentChannel: AgentChannelRuntime.Interface[\"get\"];\n readonly checkAccessAgentChannel: AgentChannelRuntime.Interface[\"checkAccess\"];\n readonly executeAgentChannel: AgentChannelRuntime.Interface[\"execute\"];\n readonly invoke: (request: RuntimeInvokeRequest) => Effect.Effect<InvokeSuccess, InvokeError>;\n readonly activateTrigger: (\n request: RuntimeWebhookActivationRequest,\n ) => Effect.Effect<Trigger.ActivateSuccess, unknown>;\n readonly deactivateTrigger: (\n request: RuntimeWebhookActivationRequest,\n ) => Effect.Effect<Trigger.DeactivateSuccess, unknown>;\n readonly verifyTrigger: (\n request: RuntimeWebhookTriggerLifecycleRequest,\n ) => Effect.Effect<Trigger.VerifySuccess, unknown>;\n readonly parseTrigger: (\n request: RuntimeWebhookTriggerLifecycleRequest,\n ) => Effect.Effect<Trigger.EmittedEventsSuccess<string, \"parse\">, unknown>;\n readonly pollTrigger: (\n request: RuntimeTriggerLifecycleRequest,\n ) => Effect.Effect<Trigger.EmittedEventsSuccess<string, \"poll\">, unknown>;\n readonly getAuthMethod: (\n request: AuthMethodRequest,\n ) => Effect.Effect<AuthMethod.Any, AuthMethodNotFoundError>;\n // TODO(live-schema-validation): expose live action/trigger schema decoders by capability version.\n // Server authoring/runtime must validate against SDK declarations, not JSON Schema projections.\n readonly decodeAuthMethodSetup: (\n request: DecodeAuthMethodSetupRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly prepareAuthMethod: (\n request: PrepareAuthMethodRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly prepareOAuth2Tokens: (\n request: PrepareOAuth2TokensRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly refreshAuthMethod: (\n request: RefreshAuthMethodRequest,\n ) => Effect.Effect<unknown | undefined, AuthMethodExecutionError>;\n readonly resolveAuthMethod: (\n request: ResolveAuthMethodRequest,\n ) => Effect.Effect<AuthMethodBinding.Binding, AuthMethodExecutionError>;\n readonly resolveAiModelConfig: (\n request: ResolveAiModelConfigRequest,\n ) => Effect.Effect<AiProvider.RuntimeConfig, AiModelConfigError>;\n readonly resolveSandboxAccess: (\n request: ResolveAuthMethodRequest,\n ) => Effect.Effect<ResolvedSandboxAccess, SandboxAccessError>;\n}\n\n/**\n * Effect service provided by {@link toLayer}.\n *\n * @since 0.0.0\n * @category services\n */\nexport class Service extends Context.Service<Service, RuntimeService>()(\n \"@dual-os/sdk/Dual/Service\",\n) {}\n\nexport type RuntimeRequirementsFor<P extends Plugin.Any> =\n | AgentChannelRuntime.Requirements<P>\n | (P extends Plugin.Any ? PluginRequirements<P, PluginActions<P>> : never);\n\ntype AuthProvider = Plugin.Any | AiProvider.Any;\n\ntype AuthMethodFor<Providers extends AuthProvider> = Providers[\"authMethods\"][number];\n\ntype AuthMethodSetupDecodeRequirements<Method extends AuthMethod.Any> =\n AuthMethod.SetupSchema<Method> extends Schema.Top\n ? Schema.Codec.DecodingServices<AuthMethod.SetupSchema<Method>>\n : never;\n\ntype AuthMethodInputDecodeRequirements<Method extends AuthMethod.Any> =\n AuthMethod.InputSchema<Method> extends Schema.Top\n ? Schema.Codec.DecodingServices<AuthMethod.InputSchema<Method>>\n : never;\n\ntype AuthMethodExecutionRequirementsFor<Providers extends AuthProvider> =\n AuthMethodFor<Providers> extends infer Method\n ? Method extends AuthMethod.Any\n ?\n | AuthMethod.Requirements<Method>\n | AuthMethodSetupDecodeRequirements<Method>\n | AuthMethodInputDecodeRequirements<Method>\n | Schema.Codec.DecodingServices<AuthMethod.MaterialSchema<Method>>\n | Schema.Codec.DecodingServices<AuthMethod.ValueSchema<Method>>\n | Schema.Codec.EncodingServices<AuthMethod.MaterialSchema<Method>>\n | Schema.Codec.EncodingServices<AuthMethod.ValueSchema<Method>>\n | (AuthMethod.SetupSchema<Method> extends Schema.Top\n ? Schema.Codec.EncodingServices<AuthMethod.SetupSchema<Method>>\n : never)\n : never\n : never;\n\n/**\n * Requirements still needed by {@link toLayer} for an app.\n *\n * Hosts (the server, a worker, a test harness) never know an app's concrete\n * implementations: they talk to it exclusively through the generic\n * {@link Service} layer. App-specific dependencies — a plugin's API client, an\n * auth hook's token service — are discharged where they are known, at the\n * plugin or app definition (the `Exclude<..., LayerOutput>` below cancels\n * them). Only what the definition did not discharge surfaces here,\n * generically, and the host entrypoint forces it to `never` before anything\n * runs.\n *\n * @since 0.0.0\n * @category type-level\n */\nexport type ToLayerRequirements<A extends AnyApp> =\n A extends App<\n infer P extends Plugin.Any,\n infer LayerOutput,\n any,\n infer LayerRequirements,\n infer AiProviders extends readonly AiProvider.Any[]\n >\n ?\n | LayerRequirements\n | Exclude<RuntimeRequirementsFor<P>, LayerOutput>\n | Exclude<AuthMethodExecutionRequirementsFor<P | AiProviders[number]>, LayerOutput>\n : never;\n\n/**\n * Layer-construction errors surfaced by {@link toLayer} for an app.\n *\n * @since 0.0.0\n * @category type-level\n */\nexport type ToLayerError<A extends AnyApp> =\n A extends App<any, any, infer LayerError, any, any> ? LayerError : never;\n\n/**\n * Turn an {@link App} into a runtime Effect service layer.\n *\n * @since 0.0.0\n * @category layers\n */\nexport const toLayer = <\n const P extends Plugin.Any,\n LayerOutput,\n LayerError,\n LayerRequirements,\n const AiProviders extends readonly AiProvider.Any[],\n>(\n app: App<P, LayerOutput, LayerError, LayerRequirements, AiProviders>,\n): Layer.Layer<\n Service,\n LayerError,\n | LayerRequirements\n | Exclude<RuntimeRequirementsFor<P>, LayerOutput>\n | Exclude<AuthMethodExecutionRequirementsFor<P | AiProviders[number]>, LayerOutput>\n> => {\n const fullAuthMethodId = (providerId: string, method: AuthMethod.Any): string =>\n `${providerId}/${method.identifier}`;\n\n const findAuthMethod = (\n providerId: string,\n authMethodId: string,\n ): Effect.Effect<AuthMethod.Any, AuthMethodNotFoundError> => {\n const provider =\n pluginOf(app, providerId) ??\n app.aiProviders.find(candidate => AiProvider.registryId(candidate.identifier) === providerId);\n const method = provider?.authMethods.find(\n candidate =>\n candidate.identifier === authMethodId ||\n fullAuthMethodId(providerId, candidate) === authMethodId,\n );\n\n return method === undefined\n ? Effect.fail(new AuthMethodNotFoundError({ authMethodId, providerId }))\n : Effect.succeed(method);\n };\n\n const serviceLayer = Layer.effect(\n Service,\n Effect.gen(function* () {\n const channels = yield* AgentChannelRuntime.Service;\n const context = yield* Effect.context<\n RuntimeRequirementsFor<P> | AuthMethodExecutionRequirementsFor<P | AiProviders[number]>\n >();\n\n const appContext = indexGroups(context);\n\n const provideRuntimeContext = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(Effect.updateContext(input => Context.merge(appContext, input)));\n\n // Requirements are satisfied by the context captured at layer build time;\n // the cast erases them so service methods expose closed effects.\n const runWithCapturedAppContext = <A, E>(\n effect: Effect.Effect<A, E, unknown>,\n ): Effect.Effect<A, E> => provideRuntimeContext(effect) as never;\n\n const getAuthMethod = (request: AuthMethodRequest) =>\n findAuthMethod(request.providerId, request.authMethodId);\n\n const getTrigger = (request: RuntimeTriggerLifecycleRequest) => {\n const resolved = resolveRuntimeTrigger(\n app.plugins,\n request.triggerId,\n request.triggerVersion,\n );\n return resolved === undefined ||\n (request.pluginKey !== undefined && resolved.providerId !== request.pluginKey)\n ? Effect.fail(new TriggerNotFoundError({ triggerId: request.triggerId }))\n : Effect.succeed(resolved);\n };\n\n const triggerLifecycleRequest = (\n request: RuntimeTriggerLifecycleRequest,\n ): Trigger.LifecycleRequest => ({\n config: request.config,\n ...(request.state === undefined ? {} : { state: request.state }),\n ...(request.connectionId === undefined ? {} : { connectionId: request.connectionId }),\n ...(request.context === undefined ? {} : { context: request.context }),\n });\n\n const webhookActivationRequest = (\n request: RuntimeWebhookActivationRequest,\n ): Trigger.WebhookActivationRequest => ({\n ...triggerLifecycleRequest(request),\n webhookUrl: request.webhookUrl,\n });\n\n // A host can pass the raw body as text; handlers verify signatures over its bytes.\n const webhookTriggerLifecycleRequest = (\n request: RuntimeWebhookTriggerLifecycleRequest,\n ): Trigger.WebhookExecutionRequest => ({\n ...webhookActivationRequest(request),\n request: Predicate.isString(request.request.rawBody)\n ? { ...request.request, rawBody: new TextEncoder().encode(request.request.rawBody) }\n : request.request,\n });\n\n const activateTrigger = (request: RuntimeWebhookActivationRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.activate(entry, webhookActivationRequest(request));\n }),\n );\n\n const deactivateTrigger = (request: RuntimeWebhookActivationRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.deactivate(entry, webhookActivationRequest(request));\n }),\n );\n\n const verifyTrigger = (request: RuntimeWebhookTriggerLifecycleRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.verify(entry, webhookTriggerLifecycleRequest(request));\n }),\n );\n\n const parseTrigger = (request: RuntimeWebhookTriggerLifecycleRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.parse(entry, webhookTriggerLifecycleRequest(request));\n }),\n );\n\n const pollTrigger = (request: RuntimeTriggerLifecycleRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.poll(entry, triggerLifecycleRequest(request));\n }),\n );\n\n const decodeAuthMethodSetup = (request: DecodeAuthMethodSetupRequest) =>\n runWithCapturedAppContext(\n getAuthMethod(request).pipe(\n Effect.flatMap(method => {\n if (request.encoding === \"json\" && method.setup !== undefined) {\n return Schema.decodeUnknownEffect(Schema.toCodecJson(method.setup))(request.setup);\n }\n return AuthMethodExecution.decodeSetup(method, request.setup);\n }),\n ),\n );\n\n const withAuthMethodSetup = <A, E, R>(\n request: DecodeAuthMethodSetupRequest,\n execute: (\n method: AuthMethod.Any,\n setup: AuthMethod.Setup<AuthMethod.Any>,\n ) => Effect.Effect<A, E, R>,\n ) =>\n runWithCapturedAppContext(\n getAuthMethod(request).pipe(\n Effect.flatMap(method =>\n AuthMethodExecution.decodeSetup(method, request.setup).pipe(\n Effect.flatMap(setup => execute(method, setup)),\n ),\n ),\n ),\n );\n\n const prepareAuthMethod = (request: PrepareAuthMethodRequest) =>\n withAuthMethodSetup(request, (method, setup) =>\n AuthMethodExecution.prepare(method, request.input, { setup }),\n );\n\n const prepareOAuth2Tokens = (request: PrepareOAuth2TokensRequest) =>\n withAuthMethodSetup(request, (method, setup) =>\n AuthMethodExecution.prepareOAuth2Tokens(method, request.tokens, { setup }),\n );\n\n const refreshAuthMethod = (request: RefreshAuthMethodRequest) =>\n runWithCapturedAppContext(\n getAuthMethod(request).pipe(\n Effect.flatMap(method =>\n AuthMethodExecution.decodeSetup(method, request.setup).pipe(\n Effect.flatMap(setup =>\n AuthMethodExecution.refreshUnknown(method, request.material, {\n minValidityMs: request.minValidityMs,\n now: request.now,\n reason: request.reason,\n setup,\n }),\n ),\n ),\n ),\n ),\n );\n\n const resolveAuthMethod = (request: ResolveAuthMethodRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const method = yield* getAuthMethod(request);\n const setup = yield* decodeAuthMethodSetup(request);\n const value =\n request.encoding === \"json\"\n ? yield* AuthMethodExecution.resolveDecoded(\n method,\n yield* Schema.decodeUnknownEffect(Schema.toCodecJson(method.material))(\n request.material,\n ),\n { setup },\n )\n : yield* AuthMethodExecution.resolve(method, request.material, { setup });\n return AuthMethodBinding.makeBinding({\n connectionId: undefined,\n method,\n providerId: request.providerId,\n value,\n });\n }),\n );\n\n const resolveAiModelConfig = (request: ResolveAiModelConfigRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const provider = app.aiProviders.find(\n candidate => AiProvider.registryId(candidate.identifier) === request.providerId,\n );\n if (provider?.resolveRuntimeConfig === undefined) {\n return yield* new AiProviderRuntimeNotConfiguredError({\n providerId: request.providerId,\n });\n }\n const binding = yield* resolveAuthMethod(request);\n // SAFETY: the resolver belongs to this provider and the binding was\n // resolved from the same provider's declared auth-method list.\n const resolveRuntimeConfig =\n provider.resolveRuntimeConfig as AiProvider.RuntimeConfigResolver<\n readonly AuthMethod.Any[]\n >;\n return yield* Schema.decodeUnknownEffect(AiProvider.RuntimeConfig)(\n resolveRuntimeConfig({ binding, model: request.model }),\n );\n }),\n );\n\n const resolveSandboxAccess = (request: ResolveAuthMethodRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const access = pluginOf(app, request.providerId)?.sandboxAccess;\n if (access === undefined) {\n return yield* new SandboxAccessNotDeclaredError({ providerId: request.providerId });\n }\n const context = authRuntimeContext(yield* resolveAuthMethod(request));\n // Declared origins compare as URL origins, so `https://GHES.example:443` matches requests.\n const origins = Array.map(\n access.origins(context),\n origin => Result.getOrUndefined(Url.fromString(origin))?.origin ?? origin,\n );\n const authorize = (outgoing: HttpClientRequest.HttpClientRequest) => {\n const url = Result.getOrUndefined(Url.fromString(outgoing.url));\n const refused = new SandboxRequestNotAllowedError({\n origin: url?.origin ?? outgoing.url,\n path: url?.pathname ?? \"\",\n providerId: request.providerId,\n });\n if (url === undefined || !origins.includes(url.origin)) return Effect.fail(refused);\n return Effect.fromOption(access.authorize(outgoing, context), () => refused);\n };\n return { authorize, origins } satisfies ResolvedSandboxAccess;\n }),\n );\n\n return Service.of({\n activateTrigger,\n checkAccessAgentChannel: channels.checkAccess,\n deactivateTrigger,\n decodeAgentChannelDefinitionSettings: channels.decodeDefinitionSettings,\n decodeAgentChannelDeploymentSettings: channels.decodeDeploymentSettings,\n decodeAuthMethodSetup,\n executeAgentChannel: channels.execute,\n executeAuthJson: request =>\n runWithCapturedAppContext(\n pipe(\n getAuthMethod(request),\n Effect.flatMap(method => AuthMethodExecution.executeJson(method, request)),\n ),\n ),\n getAgentChannel: channels.get,\n getAuthMethod,\n invoke: request => runWithCapturedAppContext(invokeRaw(app, request)),\n invokeJson: request =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const result = yield* invokeRaw(app, request, true);\n return {\n ...result,\n data: yield* Schema.decodeUnknownEffect(Schema.Json)(result.data),\n };\n }),\n ),\n parseTrigger,\n pollTrigger,\n prepareAuthMethod,\n prepareOAuth2Tokens,\n refreshAuthMethod,\n resolveAiModelConfig,\n resolveAuthMethod,\n resolveSandboxAccess,\n verifyTrigger,\n });\n }),\n );\n\n return serviceLayer.pipe(\n Layer.provide(AgentChannelRuntime.layer(app.plugins.map(installation => installation.plugin))),\n Layer.provide(app.layer),\n );\n};\n\nexport * as DualRuntime from \"./DualRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,MAAa,WACX,QACA,aAC2B;CAAE;CAAQ;AAAQ;;;;;;;;AAS/C,MAAa,cACX,QACA,UAAU,aAQT;CACC,aAAa,CAAC;CACd,YAAY,OAAO;CACnB,OAAO,OAAO;CACd,SAAS,CAAC,QAAQ,QAA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AAM,SAAS,OAAO,UAAU,KAAK,SAAS,IAAI;IAClD,OAAO;KACL,GAAG;KACH,MAAM,OAAO,OAAO,oBAAoB,OAAO,IAAI,CAAC,CAAC,OAAO,IAAI;IAClE;GACF,CAAC,CACH;GACF;GACA;GACA;GACA,qBAAA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC;CACH,CAAC,CAGe,CAAC,CAAC,KAClB,MAAM,QAAQC,MAA0B,IAAI,QAAQ,KAAI,iBAAgB,aAAa,MAAM,CAAC,CAAC,GAC7F,MAAM,QAAQ,IAAI,KAAK,CACzB;AACF"}
|
|
1
|
+
{"version":3,"file":"DualRuntime.js","names":["Func","AiProvider.registryId","AgentChannelRuntime.Service","Trigger.activate","Trigger.deactivate","Trigger.verify","Trigger.parse","Trigger.poll","AuthMethodExecution.decodeSetup","AuthMethodExecution.prepare","prepareOAuth2Tokens","AuthMethodExecution.prepareOAuth2Tokens","AuthMethodExecution.refreshUnknown","AuthMethodExecution.resolveDecoded","AuthMethodExecution.resolve","AuthMethodBinding.makeBinding","AiProvider.RuntimeConfig","AuthMethodExecution.executeJson","AgentChannelRuntime.layer"],"sources":["../src/DualRuntime.ts"],"sourcesContent":["/**\n * Dual action invocation, trigger lifecycle, and auth runtime.\n *\n * @since 0.0.0\n */\nimport {\n Array,\n Context,\n Effect,\n Function as Func,\n Layer,\n Predicate,\n Result,\n Schema,\n pipe,\n} from \"effect\";\n\nimport { type HttpClientRequest, Url } from \"effect/http\";\n\nimport {\n ActionHandlerError,\n RetryableActionHandlerError,\n type ActionHandlerFailure,\n} from \"./Action.ts\";\nimport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\nimport * as AiProvider from \"./AiProvider.ts\";\nimport type * as AuthMethod from \"./AuthMethod.ts\";\nimport * as AuthMethodBinding from \"./AuthMethodBinding.ts\";\nimport * as AuthMethodExecution from \"./AuthMethodExecution.ts\";\nimport {\n ConnectionIdNotAllowedError,\n ConnectionReauthorizationRequiredError,\n ConnectionRequiredError,\n ConnectionSelectionRequiredError,\n ConnectionResolverStoreError,\n InvalidConnectionIdError,\n InvalidResolvedConnectionError,\n type ConnectionResolutionContext,\n} from \"./ConnectionResolver.ts\";\nimport { BuilderCollisionError } from \"./DefinitionError.ts\";\nimport { TriggerNotFoundError } from \"./DualRegistry.ts\";\nimport { authRuntimeContext } from \"./internal/auth-execution.ts\";\nimport { resolveAction, type PluginActions } from \"./internal/dual/actions.ts\";\nimport {\n ActionNotFoundError,\n FieldIssue,\n InvalidActionInputError,\n InvalidActionOutputError,\n ActionHandlerNotFoundError,\n type InvokeError,\n type InvokeMeta,\n type InvokeRequest,\n type InvokeRequirementsFor,\n type InvokeSuccess,\n type PluginRequirements,\n invokeResolvedAction,\n invokeResolvedActionJson,\n} from \"./internal/dual/invoke.ts\";\nimport { resolveRuntimeTrigger } from \"./internal/dual/triggers.ts\";\nimport { indexGroups } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\nimport * as Trigger from \"./Trigger.ts\";\n\n/**\n * One installed plugin release.\n *\n * @since 0.7.0\n * @category models\n */\nexport interface PluginInstallation<P extends Plugin.Any = Plugin.Any> {\n readonly plugin: P;\n /** The plugin's package version. */\n readonly version: string;\n}\n\n/**\n * The plugin releases and AI providers one runtime executes, with the services their handlers need.\n *\n * @since 0.7.0\n * @category models\n */\nexport interface App<\n out P extends Plugin.Any = Plugin.Any,\n LayerOutput = never,\n out LayerError = never,\n out LayerRequirements = never,\n out AiProviders extends readonly AiProvider.Any[] = readonly AiProvider.Any[],\n> {\n readonly identifier: string;\n readonly aiProviders: AiProviders;\n readonly plugins: readonly PluginInstallation<P>[];\n readonly layer: Layer.Layer<LayerOutput, LayerError, LayerRequirements>;\n}\n\n/**\n * Constraint type for working with any {@link App}.\n *\n * @since 0.7.0\n * @category type-level\n */\nexport interface AnyApp extends App<Plugin.Any, never, any, any, readonly AiProvider.Any[]> {}\n\n/**\n * Install one plugin release.\n *\n * @since 0.7.0\n * @category constructors\n */\nexport const install = <P extends Plugin.Any>(\n plugin: P,\n version: string,\n): PluginInstallation<P> => ({ plugin, version });\n\n/**\n * The runtime of one plugin release, as the plugin's own process runs it. `version` defaults to\n * `0.0.0` for tests that do not need the package version.\n *\n * @since 0.7.0\n * @category constructors\n */\nexport const fromPlugin = <const P extends Plugin.Any>(\n plugin: P,\n version = \"0.0.0\",\n): App<\n P,\n Plugin.LayerOutput<readonly [P]>,\n Plugin.LayerError<readonly [P]>,\n Plugin.LayerRequirements<readonly [P]>,\n readonly []\n> =>\n ({\n aiProviders: [],\n identifier: plugin.identifier,\n layer: plugin.layer,\n plugins: [install(plugin, version)],\n }) as never;\n\n/**\n * An app runtime without plugins, for {@link withPlugin} and {@link withPlugins} to fill.\n *\n * @since 0.7.0\n * @category constructors\n */\nexport const make = (identifier: string): App<never, never, never, never, readonly []> => ({\n aiProviders: [],\n identifier,\n layer: Layer.empty,\n plugins: [],\n});\n\ntype AppPlugin<A extends AnyApp> = A extends App<infer P, any, any, any, any> ? P : never;\ntype AppLayerOutput<A extends AnyApp> =\n A extends App<any, infer Output, any, any, any> ? Output : never;\ntype AppLayerError<A extends AnyApp> =\n A extends App<any, any, infer Error, any, any> ? Error : never;\ntype AppLayerRequirements<A extends AnyApp> =\n A extends App<any, any, any, infer Requirements, any> ? Requirements : never;\n\n/**\n * Result of adding a plugin release to an app runtime. A named interface keeps declaration emit\n * from expanding every plugin and layer member at large call sites.\n *\n * @since 0.7.0\n * @category type-level\n */\nexport interface WithPlugin<Self extends AnyApp, Added extends Plugin.Any> extends App<\n AppPlugin<Self> | Added,\n AppLayerOutput<Self> | Plugin.LayerOutput<readonly [Added]>,\n AppLayerError<Self> | Plugin.LayerError<readonly [Added]>,\n | Plugin.LayerRequirements<readonly [Added]>\n | Exclude<AppLayerRequirements<Self>, Plugin.LayerOutput<readonly [Added]>>,\n Self[\"aiProviders\"]\n // oxlint-disable-next-line typescript/no-empty-object-type -- TypeScript declaration emit expands a type alias at every app call site (TS7056).\n> {}\n\n// Match the runtime's left-to-right provideMerge fold: later plugins can\n// satisfy earlier requirements, but earlier outputs cannot satisfy later ones.\ntype BulkLayerRequirements<\n Added extends readonly Plugin.Any[],\n Requirements,\n> = number extends Added[\"length\"]\n ? Requirements | Layer.Services<Added[number][\"layer\"]>\n : Added extends readonly [\n infer Head extends Plugin.Any,\n ...infer Tail extends readonly Plugin.Any[],\n ]\n ? BulkLayerRequirements<\n Tail,\n Layer.Services<Head[\"layer\"]> | Exclude<Requirements, Layer.Success<Head[\"layer\"]>>\n >\n : Requirements;\n\n/**\n * Result of adding several plugin releases to an app runtime in one step.\n *\n * @since 0.7.0\n * @category type-level\n */\nexport interface WithPlugins<Self extends AnyApp, Added extends readonly Plugin.Any[]> extends App<\n AppPlugin<Self> | Added[number],\n AppLayerOutput<Self> | Layer.Success<Added[number][\"layer\"]>,\n AppLayerError<Self> | Layer.Error<Added[number][\"layer\"]>,\n BulkLayerRequirements<Added, AppLayerRequirements<Self>>,\n Self[\"aiProviders\"]\n // oxlint-disable-next-line typescript/no-empty-object-type -- TypeScript declaration emit expands a type alias at every app call site (TS7056).\n> {}\n\n/** A plugin and the package version of its release. */\ntype PluginEntry = readonly [plugin: Plugin.Any, version: string];\n\ntype PluginsOf<Entries extends readonly PluginEntry[]> = {\n readonly [K in keyof Entries]: Entries[K][0];\n};\n\nfunction addPlugins(app: AnyApp, entries: readonly PluginEntry[]): AnyApp {\n const seen = new Set(Array.map(app.plugins, installation => installation.plugin.identifier));\n for (const [plugin] of entries) {\n if (seen.has(plugin.identifier)) {\n throw new BuilderCollisionError({\n childKind: \"plugin\",\n existingChildKind: \"plugin\",\n identifier: plugin.identifier,\n ownerIdentifier: app.identifier,\n ownerKind: \"dual\",\n });\n }\n seen.add(plugin.identifier);\n }\n return {\n ...app,\n layer: Array.reduce(entries, app.layer, (layer, [plugin]) =>\n Layer.provideMerge(layer, plugin.layer),\n ),\n plugins: [\n ...app.plugins,\n ...Array.map(entries, ([plugin, version]) => install(plugin, version)),\n ],\n };\n}\n\n/**\n * Add one plugin release: the plugin and its package version.\n *\n * @since 0.7.0\n * @category combinators\n */\nexport const withPlugin: {\n <const P extends Plugin.Any>(\n plugin: P,\n version: string,\n ): <Self extends AnyApp>(app: Self) => WithPlugin<Self, P>;\n <Self extends AnyApp, const P extends Plugin.Any>(\n app: Self,\n plugin: P,\n version: string,\n ): WithPlugin<Self, P>;\n} = Func.dual(3, (app: AnyApp, plugin: Plugin.Any, version: string) =>\n addPlugins(app, [[plugin, version]]),\n);\n\n/**\n * Add several plugin releases in one step, which keeps a large app's inferred type compact.\n *\n * @since 0.7.0\n * @category combinators\n */\nexport const withPlugins: {\n <const E extends readonly PluginEntry[]>(\n entries: E,\n ): <Self extends AnyApp>(app: Self) => WithPlugins<Self, PluginsOf<E>>;\n <Self extends AnyApp, const E extends readonly PluginEntry[]>(\n app: Self,\n entries: E,\n ): WithPlugins<Self, PluginsOf<E>>;\n} = Func.dual(2, addPlugins);\n\nconst pluginOf = (app: AnyApp, identifier: string): Plugin.Any | undefined =>\n app.plugins.find(installation => installation.plugin.identifier === identifier)?.plugin;\n\n/**\n * Request payload accepted by {@link invoke}.\n *\n * @since 0.0.0\n * @category models\n */\nexport type { InvokeRequest };\n\n/**\n * Metadata returned alongside successful invocation data.\n *\n * @since 0.0.0\n * @category models\n */\nexport type { InvokeMeta };\n\n/**\n * Successful invocation envelope returned by {@link invoke}.\n *\n * @since 0.0.0\n * @category models\n */\nexport type { InvokeSuccess };\n\n/**\n * Structured field-level validation issue surfaced by {@link InvalidActionInputError}.\n *\n * @since 0.0.0\n * @category models\n */\nexport { FieldIssue };\n\n/**\n * Raised when an invocation references an unknown action id.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ActionNotFoundError };\n\n/**\n * @since 0.0.0\n * @category errors\n */\n\n/**\n * Raised when invocation input fails schema validation.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidActionInputError };\n\n/**\n * Raised when action handler output fails schema validation.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidActionOutputError };\n\n/**\n * Raised when the runtime action handler service is missing.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ActionHandlerNotFoundError };\n\n/**\n * Non-retryable failure reported by a trusted action handler.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ActionHandlerError };\n\n/**\n * Retryable failure reported by a trusted action handler.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { RetryableActionHandlerError };\n\n/**\n * Stable trusted action handler failure contract.\n *\n * @since 0.0.0\n * @category errors\n */\nexport type { ActionHandlerFailure };\n\n/**\n * Raised when an action does not accept a connection but a connectionId was still provided.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionIdNotAllowedError };\n\n/**\n * Raised when invocation requires a connection and no compatible binding is available.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionRequiredError };\n\n/**\n * Raised when several compatible connection bindings exist and the caller must choose one.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionSelectionRequiredError };\n\n/**\n * Raised when the provider refuses a connection's stored grant and the user must sign in again.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionReauthorizationRequiredError };\n\n/**\n * Raised when the host connection store is unavailable.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { ConnectionResolverStoreError };\n\n/**\n * Raised when a connectionId does not resolve to a compatible binding.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidConnectionIdError };\n\n/**\n * Raised when a resolved connection binding does not satisfy its auth method schema.\n *\n * @since 0.0.0\n * @category errors\n */\nexport { InvalidResolvedConnectionError };\n\n/**\n * Structured SDK-owned invocation failures.\n *\n * @since 0.0.0\n * @category errors\n */\nexport type { InvokeError };\nexport type { InvokeRequirementsFor };\n\n/**\n * Invoke an action directly in-process.\n *\n * The invocation boundary resolves an action by canonical machine id, validates\n * unknown input against the resolved runtime schema, runs the handler, and\n * returns a standard success envelope. This mirrors the server trusted invoke\n * boundary: runtime schema validation is authoritative.\n *\n * @since 0.0.0\n * @category execution\n */\nconst failInvokeActionNotFound = (\n actionId: string,\n): Effect.Effect<InvokeSuccess, ActionNotFoundError> =>\n Effect.fail(new ActionNotFoundError({ actionId }));\n\nconst invokeRaw = <\n const P extends Plugin.Any,\n LayerOutput,\n LayerError,\n LayerRequirements,\n const AiProviders extends readonly AiProvider.Any[],\n>(\n app: App<P, LayerOutput, LayerError, LayerRequirements, AiProviders>,\n request: InvokeRequest,\n json = false,\n): Effect.Effect<InvokeSuccess, InvokeError, RuntimeRequirementsFor<P>> => {\n const resolved = resolveAction(app.plugins, request.actionId, request.actionVersion);\n\n if (\n resolved === undefined ||\n (request.pluginKey !== undefined && resolved.providerId !== request.pluginKey)\n ) {\n return failInvokeActionNotFound(request.actionId);\n }\n\n // The runtime entry is resolved from erased plugin trees, so the precise\n // per-action requirement union in the return annotation cannot be recovered\n // here; the annotation is the contract, the cast is the boundary.\n return (json ? invokeResolvedActionJson : invokeResolvedAction)(\n resolved.providerId,\n resolved.actionId,\n resolved.pluginVersion,\n resolved.action,\n resolved.authMethods,\n request,\n ) as never;\n};\n\nexport const invoke = <\n const P extends Plugin.Any,\n LayerOutput,\n LayerError,\n LayerRequirements,\n const AiProviders extends readonly AiProvider.Any[],\n>(\n app: App<P, LayerOutput, LayerError, LayerRequirements, AiProviders>,\n request: InvokeRequest,\n): Effect.Effect<\n InvokeSuccess,\n InvokeError | LayerError,\n LayerRequirements | Exclude<RuntimeRequirementsFor<P>, LayerOutput>\n> => invokeRaw(app, request).pipe(Effect.provide(app.layer));\n\n/**\n * Runtime-first invocation request accepted by {@link Service}.\n *\n * @since 0.0.0\n * @category models\n */\nexport type RuntimeInvokeRequest = InvokeRequest;\n\n/**\n * Runtime-first trigger lifecycle request accepted by {@link Service}.\n *\n * @since 0.0.0\n * @category models\n */\nexport interface RuntimeTriggerLifecycleRequest {\n readonly triggerId: string;\n readonly pluginKey?: string;\n /** The exact plugin release the caller pinned; another installed release does not run. */\n readonly triggerVersion?: string | undefined;\n readonly config: unknown;\n readonly state?: unknown | undefined;\n readonly connectionId?: string | undefined;\n readonly context?: ConnectionResolutionContext | undefined;\n}\n\nexport interface RuntimeWebhookActivationRequest extends RuntimeTriggerLifecycleRequest {\n readonly webhookUrl: string;\n}\n\nexport interface RuntimeWebhookTriggerLifecycleRequest extends RuntimeWebhookActivationRequest {\n readonly request: Trigger.WebhookRequest;\n}\n\nexport interface AuthMethodRequest {\n readonly providerId: string;\n readonly authMethodId: string;\n}\n\nexport interface DecodeAuthMethodSetupRequest extends AuthMethodRequest {\n readonly encoding?: \"json\";\n readonly setup: unknown;\n}\n\nexport interface PrepareAuthMethodRequest extends AuthMethodRequest {\n readonly input: unknown;\n readonly setup: unknown;\n}\n\nexport interface PrepareOAuth2TokensRequest extends AuthMethodRequest {\n readonly tokens: AuthMethod.OAuth2TokenResponse;\n readonly setup: unknown;\n}\n\nexport interface RefreshAuthMethodRequest extends AuthMethodRequest {\n readonly material: unknown;\n readonly setup: unknown;\n readonly now: number;\n readonly minValidityMs: number;\n readonly reason: AuthMethod.RefreshReason;\n}\n\nexport interface ResolveAuthMethodRequest extends AuthMethodRequest {\n /** `json` when the material and setup arrive in their canonical JSON encoding, as in the sandbox. */\n readonly encoding?: \"json\";\n readonly material: unknown;\n readonly setup: unknown;\n}\n\nexport interface ResolveAiModelConfigRequest extends ResolveAuthMethodRequest {\n readonly model: AiProvider.RuntimeModel;\n}\n\nexport class AuthMethodNotFoundError extends Schema.TaggedError<AuthMethodNotFoundError>()(\n \"AuthMethodNotFoundError\",\n { authMethodId: Schema.String, providerId: Schema.String },\n) {}\n\nexport type AuthMethodExecutionError =\n | AuthMethodNotFoundError\n | Schema.SchemaError\n | AuthMethod.ExpectedOAuth2MethodError\n | AuthMethod.OAuth2RefreshTokenUnavailableError\n | AuthMethod.AuthMethodHookError;\n\nexport class AiProviderRuntimeNotConfiguredError extends Schema.TaggedError<AiProviderRuntimeNotConfiguredError>()(\n \"AiProviderRuntimeNotConfiguredError\",\n { providerId: Schema.String },\n) {}\n\nexport class AiModelNotAllowedError extends Schema.TaggedError<AiModelNotAllowedError>()(\n \"AiModelNotAllowedError\",\n { modelId: Schema.String, providerId: Schema.String },\n) {}\n\nexport type AiModelConfigError =\n | AuthMethodExecutionError\n | AiProviderRuntimeNotConfiguredError\n | AiModelNotAllowedError;\n\n/** Raised when a provider declares no sandbox access. */\nexport class SandboxAccessNotDeclaredError extends Schema.TaggedError<SandboxAccessNotDeclaredError>()(\n \"SandboxAccessNotDeclaredError\",\n { providerId: Schema.String },\n) {}\n\n/** Raised when the Connection may not be sent with a sandbox request: another origin, or a request the provider refuses. */\nexport class SandboxRequestNotAllowedError extends Schema.TaggedError<SandboxRequestNotAllowedError>()(\n \"SandboxRequestNotAllowedError\",\n { origin: Schema.String, path: Schema.String, providerId: Schema.String },\n) {}\n\nexport type SandboxAccessError = AuthMethodExecutionError | SandboxAccessNotDeclaredError;\n\n/** One Connection's sandbox access: where its credential may go, and how a request gets it. */\nexport interface ResolvedSandboxAccess {\n readonly origins: readonly string[];\n readonly authorize: (\n request: HttpClientRequest.HttpClientRequest,\n ) => Effect.Effect<HttpClientRequest.HttpClientRequest, SandboxRequestNotAllowedError>;\n}\n\n/**\n * Runtime service materialized from an {@link App}.\n *\n * @since 0.0.0\n * @category services\n */\nexport interface RuntimeService {\n readonly executeAuthJson: (\n request: AuthMethodExecution.JsonRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly invokeJson: (\n request: RuntimeInvokeRequest,\n ) => Effect.Effect<InvokeSuccess<string, Schema.Json>, InvokeError | Schema.SchemaError>;\n readonly decodeAgentChannelDefinitionSettings: AgentChannelRuntime.Interface[\"decodeDefinitionSettings\"];\n readonly decodeAgentChannelDeploymentSettings: AgentChannelRuntime.Interface[\"decodeDeploymentSettings\"];\n readonly getAgentChannel: AgentChannelRuntime.Interface[\"get\"];\n readonly checkAccessAgentChannel: AgentChannelRuntime.Interface[\"checkAccess\"];\n readonly executeAgentChannel: AgentChannelRuntime.Interface[\"execute\"];\n readonly invoke: (request: RuntimeInvokeRequest) => Effect.Effect<InvokeSuccess, InvokeError>;\n readonly activateTrigger: (\n request: RuntimeWebhookActivationRequest,\n ) => Effect.Effect<Trigger.ActivateSuccess, unknown>;\n readonly deactivateTrigger: (\n request: RuntimeWebhookActivationRequest,\n ) => Effect.Effect<Trigger.DeactivateSuccess, unknown>;\n readonly verifyTrigger: (\n request: RuntimeWebhookTriggerLifecycleRequest,\n ) => Effect.Effect<Trigger.VerifySuccess, unknown>;\n readonly parseTrigger: (\n request: RuntimeWebhookTriggerLifecycleRequest,\n ) => Effect.Effect<Trigger.EmittedEventsSuccess<string, \"parse\">, unknown>;\n readonly pollTrigger: (\n request: RuntimeTriggerLifecycleRequest,\n ) => Effect.Effect<Trigger.EmittedEventsSuccess<string, \"poll\">, unknown>;\n readonly getAuthMethod: (\n request: AuthMethodRequest,\n ) => Effect.Effect<AuthMethod.Any, AuthMethodNotFoundError>;\n // TODO(live-schema-validation): expose live action/trigger schema decoders by capability version.\n // Server authoring/runtime must validate against SDK declarations, not JSON Schema projections.\n readonly decodeAuthMethodSetup: (\n request: DecodeAuthMethodSetupRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly prepareAuthMethod: (\n request: PrepareAuthMethodRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly prepareOAuth2Tokens: (\n request: PrepareOAuth2TokensRequest,\n ) => Effect.Effect<unknown, AuthMethodExecutionError>;\n readonly refreshAuthMethod: (\n request: RefreshAuthMethodRequest,\n ) => Effect.Effect<unknown | undefined, AuthMethodExecutionError>;\n readonly resolveAuthMethod: (\n request: ResolveAuthMethodRequest,\n ) => Effect.Effect<AuthMethodBinding.Binding, AuthMethodExecutionError>;\n readonly allowedModelIdsFor: (providerId: string) => AiProvider.AllowedModelIds | undefined;\n readonly resolveAiModelConfig: (\n request: ResolveAiModelConfigRequest,\n ) => Effect.Effect<AiProvider.RuntimeConfig, AiModelConfigError>;\n readonly resolveSandboxAccess: (\n request: ResolveAuthMethodRequest,\n ) => Effect.Effect<ResolvedSandboxAccess, SandboxAccessError>;\n}\n\n/**\n * Effect service provided by {@link toLayer}.\n *\n * @since 0.0.0\n * @category services\n */\nexport class Service extends Context.Service<Service, RuntimeService>()(\n \"@dual-os/sdk/Dual/Service\",\n) {}\n\nexport type RuntimeRequirementsFor<P extends Plugin.Any> =\n | AgentChannelRuntime.Requirements<P>\n | (P extends Plugin.Any ? PluginRequirements<P, PluginActions<P>> : never);\n\ntype AuthProvider = Plugin.Any | AiProvider.Any;\n\ntype AuthMethodFor<Providers extends AuthProvider> = Providers[\"authMethods\"][number];\n\ntype AuthMethodSetupDecodeRequirements<Method extends AuthMethod.Any> =\n AuthMethod.SetupSchema<Method> extends Schema.Top\n ? Schema.Codec.DecodingServices<AuthMethod.SetupSchema<Method>>\n : never;\n\ntype AuthMethodInputDecodeRequirements<Method extends AuthMethod.Any> =\n AuthMethod.InputSchema<Method> extends Schema.Top\n ? Schema.Codec.DecodingServices<AuthMethod.InputSchema<Method>>\n : never;\n\ntype AuthMethodExecutionRequirementsFor<Providers extends AuthProvider> =\n AuthMethodFor<Providers> extends infer Method\n ? Method extends AuthMethod.Any\n ?\n | AuthMethod.Requirements<Method>\n | AuthMethodSetupDecodeRequirements<Method>\n | AuthMethodInputDecodeRequirements<Method>\n | Schema.Codec.DecodingServices<AuthMethod.MaterialSchema<Method>>\n | Schema.Codec.DecodingServices<AuthMethod.ValueSchema<Method>>\n | Schema.Codec.EncodingServices<AuthMethod.MaterialSchema<Method>>\n | Schema.Codec.EncodingServices<AuthMethod.ValueSchema<Method>>\n | (AuthMethod.SetupSchema<Method> extends Schema.Top\n ? Schema.Codec.EncodingServices<AuthMethod.SetupSchema<Method>>\n : never)\n : never\n : never;\n\n/**\n * Requirements still needed by {@link toLayer} for an app.\n *\n * Hosts (the server, a worker, a test harness) never know an app's concrete\n * implementations: they talk to it exclusively through the generic\n * {@link Service} layer. App-specific dependencies — a plugin's API client, an\n * auth hook's token service — are discharged where they are known, at the\n * plugin or app definition (the `Exclude<..., LayerOutput>` below cancels\n * them). Only what the definition did not discharge surfaces here,\n * generically, and the host entrypoint forces it to `never` before anything\n * runs.\n *\n * @since 0.0.0\n * @category type-level\n */\nexport type ToLayerRequirements<A extends AnyApp> =\n A extends App<\n infer P extends Plugin.Any,\n infer LayerOutput,\n any,\n infer LayerRequirements,\n infer AiProviders extends readonly AiProvider.Any[]\n >\n ?\n | LayerRequirements\n | Exclude<RuntimeRequirementsFor<P>, LayerOutput>\n | Exclude<AuthMethodExecutionRequirementsFor<P | AiProviders[number]>, LayerOutput>\n : never;\n\n/**\n * Layer-construction errors surfaced by {@link toLayer} for an app.\n *\n * @since 0.0.0\n * @category type-level\n */\nexport type ToLayerError<A extends AnyApp> =\n A extends App<any, any, infer LayerError, any, any> ? LayerError : never;\n\n/**\n * Turn an {@link App} into a runtime Effect service layer.\n *\n * @since 0.0.0\n * @category layers\n */\nexport const toLayer = <\n const P extends Plugin.Any,\n LayerOutput,\n LayerError,\n LayerRequirements,\n const AiProviders extends readonly AiProvider.Any[],\n>(\n app: App<P, LayerOutput, LayerError, LayerRequirements, AiProviders>,\n): Layer.Layer<\n Service,\n LayerError,\n | LayerRequirements\n | Exclude<RuntimeRequirementsFor<P>, LayerOutput>\n | Exclude<AuthMethodExecutionRequirementsFor<P | AiProviders[number]>, LayerOutput>\n> => {\n const fullAuthMethodId = (providerId: string, method: AuthMethod.Any): string =>\n `${providerId}/${method.identifier}`;\n\n const findAuthMethod = (\n providerId: string,\n authMethodId: string,\n ): Effect.Effect<AuthMethod.Any, AuthMethodNotFoundError> => {\n const provider =\n pluginOf(app, providerId) ??\n app.aiProviders.find(candidate => AiProvider.registryId(candidate.identifier) === providerId);\n const method = provider?.authMethods.find(\n candidate =>\n candidate.identifier === authMethodId ||\n fullAuthMethodId(providerId, candidate) === authMethodId,\n );\n\n return method === undefined\n ? Effect.fail(new AuthMethodNotFoundError({ authMethodId, providerId }))\n : Effect.succeed(method);\n };\n\n const serviceLayer = Layer.effect(\n Service,\n Effect.gen(function* () {\n const channels = yield* AgentChannelRuntime.Service;\n const context = yield* Effect.context<\n RuntimeRequirementsFor<P> | AuthMethodExecutionRequirementsFor<P | AiProviders[number]>\n >();\n\n const appContext = indexGroups(context);\n\n const provideRuntimeContext = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(Effect.updateContext(input => Context.merge(appContext, input)));\n\n // Requirements are satisfied by the context captured at layer build time;\n // the cast erases them so service methods expose closed effects.\n const runWithCapturedAppContext = <A, E>(\n effect: Effect.Effect<A, E, unknown>,\n ): Effect.Effect<A, E> => provideRuntimeContext(effect) as never;\n\n const getAuthMethod = (request: AuthMethodRequest) =>\n findAuthMethod(request.providerId, request.authMethodId);\n\n const getTrigger = (request: RuntimeTriggerLifecycleRequest) => {\n const resolved = resolveRuntimeTrigger(\n app.plugins,\n request.triggerId,\n request.triggerVersion,\n );\n return resolved === undefined ||\n (request.pluginKey !== undefined && resolved.providerId !== request.pluginKey)\n ? Effect.fail(new TriggerNotFoundError({ triggerId: request.triggerId }))\n : Effect.succeed(resolved);\n };\n\n const triggerLifecycleRequest = (\n request: RuntimeTriggerLifecycleRequest,\n ): Trigger.LifecycleRequest => ({\n config: request.config,\n ...(request.state === undefined ? {} : { state: request.state }),\n ...(request.connectionId === undefined ? {} : { connectionId: request.connectionId }),\n ...(request.context === undefined ? {} : { context: request.context }),\n });\n\n const webhookActivationRequest = (\n request: RuntimeWebhookActivationRequest,\n ): Trigger.WebhookActivationRequest => ({\n ...triggerLifecycleRequest(request),\n webhookUrl: request.webhookUrl,\n });\n\n // A host can pass the raw body as text; handlers verify signatures over its bytes.\n const webhookTriggerLifecycleRequest = (\n request: RuntimeWebhookTriggerLifecycleRequest,\n ): Trigger.WebhookExecutionRequest => ({\n ...webhookActivationRequest(request),\n request: Predicate.isString(request.request.rawBody)\n ? { ...request.request, rawBody: new TextEncoder().encode(request.request.rawBody) }\n : request.request,\n });\n\n const activateTrigger = (request: RuntimeWebhookActivationRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.activate(entry, webhookActivationRequest(request));\n }),\n );\n\n const deactivateTrigger = (request: RuntimeWebhookActivationRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.deactivate(entry, webhookActivationRequest(request));\n }),\n );\n\n const verifyTrigger = (request: RuntimeWebhookTriggerLifecycleRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.verify(entry, webhookTriggerLifecycleRequest(request));\n }),\n );\n\n const parseTrigger = (request: RuntimeWebhookTriggerLifecycleRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.parse(entry, webhookTriggerLifecycleRequest(request));\n }),\n );\n\n const pollTrigger = (request: RuntimeTriggerLifecycleRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const entry = yield* getTrigger(request);\n return yield* Trigger.poll(entry, triggerLifecycleRequest(request));\n }),\n );\n\n const decodeAuthMethodSetup = (request: DecodeAuthMethodSetupRequest) =>\n runWithCapturedAppContext(\n getAuthMethod(request).pipe(\n Effect.flatMap(method => {\n if (request.encoding === \"json\" && method.setup !== undefined) {\n return Schema.decodeUnknownEffect(Schema.toCodecJson(method.setup))(request.setup);\n }\n return AuthMethodExecution.decodeSetup(method, request.setup);\n }),\n ),\n );\n\n const withAuthMethodSetup = <A, E, R>(\n request: DecodeAuthMethodSetupRequest,\n execute: (\n method: AuthMethod.Any,\n setup: AuthMethod.Setup<AuthMethod.Any>,\n ) => Effect.Effect<A, E, R>,\n ) =>\n runWithCapturedAppContext(\n getAuthMethod(request).pipe(\n Effect.flatMap(method =>\n AuthMethodExecution.decodeSetup(method, request.setup).pipe(\n Effect.flatMap(setup => execute(method, setup)),\n ),\n ),\n ),\n );\n\n const prepareAuthMethod = (request: PrepareAuthMethodRequest) =>\n withAuthMethodSetup(request, (method, setup) =>\n AuthMethodExecution.prepare(method, request.input, { setup }),\n );\n\n const prepareOAuth2Tokens = (request: PrepareOAuth2TokensRequest) =>\n withAuthMethodSetup(request, (method, setup) =>\n AuthMethodExecution.prepareOAuth2Tokens(method, request.tokens, { setup }),\n );\n\n const refreshAuthMethod = (request: RefreshAuthMethodRequest) =>\n runWithCapturedAppContext(\n getAuthMethod(request).pipe(\n Effect.flatMap(method =>\n AuthMethodExecution.decodeSetup(method, request.setup).pipe(\n Effect.flatMap(setup =>\n AuthMethodExecution.refreshUnknown(method, request.material, {\n minValidityMs: request.minValidityMs,\n now: request.now,\n reason: request.reason,\n setup,\n }),\n ),\n ),\n ),\n ),\n );\n\n const resolveAuthMethod = (request: ResolveAuthMethodRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const method = yield* getAuthMethod(request);\n const setup = yield* decodeAuthMethodSetup(request);\n const value =\n request.encoding === \"json\"\n ? yield* AuthMethodExecution.resolveDecoded(\n method,\n yield* Schema.decodeUnknownEffect(Schema.toCodecJson(method.material))(\n request.material,\n ),\n { setup },\n )\n : yield* AuthMethodExecution.resolve(method, request.material, { setup });\n return AuthMethodBinding.makeBinding({\n connectionId: undefined,\n method,\n providerId: request.providerId,\n value,\n });\n }),\n );\n\n const resolveAiModelConfig = (request: ResolveAiModelConfigRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const provider = app.aiProviders.find(\n candidate => AiProvider.registryId(candidate.identifier) === request.providerId,\n );\n if (provider?.resolveRuntimeConfig === undefined) {\n return yield* new AiProviderRuntimeNotConfiguredError({\n providerId: request.providerId,\n });\n }\n const binding = yield* resolveAuthMethod(request);\n const allowed = provider.allowedModelIds?.(request.material);\n if (allowed !== undefined && !allowed.includes(request.model.id)) {\n return yield* new AiModelNotAllowedError({\n modelId: request.model.id,\n providerId: request.providerId,\n });\n }\n // SAFETY: the resolver belongs to this provider and the binding was\n // resolved from the same provider's declared auth-method list.\n const resolveRuntimeConfig =\n provider.resolveRuntimeConfig as AiProvider.RuntimeConfigResolver<\n readonly AuthMethod.Any[]\n >;\n return yield* Schema.decodeUnknownEffect(AiProvider.RuntimeConfig)(\n resolveRuntimeConfig({ binding, model: request.model }),\n );\n }),\n );\n\n const resolveSandboxAccess = (request: ResolveAuthMethodRequest) =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const access = pluginOf(app, request.providerId)?.sandboxAccess;\n if (access === undefined) {\n return yield* new SandboxAccessNotDeclaredError({ providerId: request.providerId });\n }\n const context = authRuntimeContext(yield* resolveAuthMethod(request));\n // Declared origins compare as URL origins, so `https://GHES.example:443` matches requests.\n const origins = Array.map(\n access.origins(context),\n origin => Result.getOrUndefined(Url.fromString(origin))?.origin ?? origin,\n );\n const authorize = (outgoing: HttpClientRequest.HttpClientRequest) => {\n const url = Result.getOrUndefined(Url.fromString(outgoing.url));\n const refused = new SandboxRequestNotAllowedError({\n origin: url?.origin ?? outgoing.url,\n path: url?.pathname ?? \"\",\n providerId: request.providerId,\n });\n if (url === undefined || !origins.includes(url.origin)) return Effect.fail(refused);\n return Effect.fromOption(access.authorize(outgoing, context), () => refused);\n };\n return { authorize, origins } satisfies ResolvedSandboxAccess;\n }),\n );\n\n return Service.of({\n activateTrigger,\n checkAccessAgentChannel: channels.checkAccess,\n deactivateTrigger,\n decodeAgentChannelDefinitionSettings: channels.decodeDefinitionSettings,\n decodeAgentChannelDeploymentSettings: channels.decodeDeploymentSettings,\n decodeAuthMethodSetup,\n executeAgentChannel: channels.execute,\n executeAuthJson: request =>\n runWithCapturedAppContext(\n pipe(\n getAuthMethod(request),\n Effect.flatMap(method => AuthMethodExecution.executeJson(method, request)),\n ),\n ),\n getAgentChannel: channels.get,\n getAuthMethod,\n invoke: request => runWithCapturedAppContext(invokeRaw(app, request)),\n invokeJson: request =>\n runWithCapturedAppContext(\n Effect.gen(function* () {\n const result = yield* invokeRaw(app, request, true);\n return {\n ...result,\n data: yield* Schema.decodeUnknownEffect(Schema.Json)(result.data),\n };\n }),\n ),\n parseTrigger,\n pollTrigger,\n prepareAuthMethod,\n prepareOAuth2Tokens,\n refreshAuthMethod,\n allowedModelIdsFor: providerId =>\n app.aiProviders.find(\n provider => AiProvider.registryId(provider.identifier) === providerId,\n )?.allowedModelIds,\n resolveAiModelConfig,\n resolveAuthMethod,\n resolveSandboxAccess,\n verifyTrigger,\n });\n }),\n );\n\n return serviceLayer.pipe(\n Layer.provide(AgentChannelRuntime.layer(app.plugins.map(installation => installation.plugin))),\n Layer.provide(app.layer),\n );\n};\n\nexport * as DualRuntime from \"./DualRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,MAAa,WACX,QACA,aAC2B;CAAE;CAAQ;AAAQ;;;;;;;;AAS/C,MAAa,cACX,QACA,UAAU,aAQT;CACC,aAAa,CAAC;CACd,YAAY,OAAO;CACnB,OAAO,OAAO;CACd,SAAS,CAAC,QAAQ,QAAQ,OAAO,CAAC;AACpC;;;;;;;AAQF,MAAa,QAAQ,gBAAsE;CACzF,aAAa,CAAC;CACd;CACA,OAAO,MAAM;CACb,SAAS,CAAC;AACZ;AAkEA,SAAS,WAAW,KAAa,SAAyC;CACxE,MAAM,OAAO,IAAI,IAAI,MAAM,IAAI,IAAI,UAAS,iBAAgB,aAAa,OAAO,UAAU,CAAC;CAC3F,KAAK,MAAM,CAAC,WAAW,SAAS;EAC9B,IAAI,KAAK,IAAI,OAAO,UAAU,GAC5B,MAAM,IAAI,sBAAsB;GAC9B,WAAW;GACX,mBAAmB;GACnB,YAAY,OAAO;GACnB,iBAAiB,IAAI;GACrB,WAAW;EACb,CAAC;EAEH,KAAK,IAAI,OAAO,UAAU;CAC5B;CACA,OAAO;EACL,GAAG;EACH,OAAO,MAAM,OAAO,SAAS,IAAI,QAAQ,OAAO,CAAC,YAC/C,MAAM,aAAa,O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AsB,SAAS,UAAU,MAAM,UAC7D,CAAC,EAAE;GACL;GACA;GACA;GACA;EACF,CAAC;CACH,CAAC,CAGe,CAAC,CAAC,KAClB,MAAM,QAAQiB,MAA0B,IAAI,QAAQ,KAAI,iBAAgB,aAAa,MAAM,CAAC,CAAC,GAC7F,MAAM,QAAQ,IAAI,KAAK,CACzB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dual-os/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*.js",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"typecheck": "tsrs --build tsconfig.json --force --pretty false"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@effect/platform-node": "4.1.
|
|
50
|
-
"effect": "4.1.
|
|
49
|
+
"@effect/platform-node": "4.1.5",
|
|
50
|
+
"effect": "4.1.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "^22.15.3",
|
package/src/AiProvider.ts
CHANGED
|
@@ -35,9 +35,13 @@ export interface Any extends Pipeable.Pipeable {
|
|
|
35
35
|
readonly homepageUrl: string | undefined;
|
|
36
36
|
readonly docsUrl: string | undefined;
|
|
37
37
|
readonly authMethods: readonly AuthMethod.Any[];
|
|
38
|
+
readonly allowedModelIds?: AllowedModelIds | undefined;
|
|
38
39
|
readonly resolveRuntimeConfig: unknown;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
/** Projects allowed model IDs from stored credential material. Undefined permits every catalog model. */
|
|
43
|
+
export type AllowedModelIds = (material: unknown) => readonly string[] | undefined;
|
|
44
|
+
|
|
41
45
|
/** @since 0.0.0 @category models */
|
|
42
46
|
export const RuntimeConfig = Schema.Struct({
|
|
43
47
|
apiKey: Schema.optional(Schema.String),
|
|
@@ -76,6 +80,7 @@ export interface AiProviderOptions<Identifier extends string = string> {
|
|
|
76
80
|
readonly categories?: readonly Category[];
|
|
77
81
|
readonly homepageUrl?: string;
|
|
78
82
|
readonly docsUrl?: string;
|
|
83
|
+
readonly allowedModelIds?: AllowedModelIds;
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
/** @since 0.0.0 @category models */
|
|
@@ -94,6 +99,7 @@ export interface AiProvider<
|
|
|
94
99
|
readonly homepageUrl: string | undefined;
|
|
95
100
|
readonly docsUrl: string | undefined;
|
|
96
101
|
readonly authMethods: AuthMethods;
|
|
102
|
+
readonly allowedModelIds?: AllowedModelIds | undefined;
|
|
97
103
|
readonly resolveRuntimeConfig: RuntimeConfigResolver<AuthMethods> | undefined;
|
|
98
104
|
}
|
|
99
105
|
|
|
@@ -112,6 +118,7 @@ const optionsFromProvider = (provider: Any): AiProviderOptions => ({
|
|
|
112
118
|
...(provider.categories.length === 0 ? {} : { categories: provider.categories }),
|
|
113
119
|
...(provider.homepageUrl === undefined ? {} : { homepageUrl: provider.homepageUrl }),
|
|
114
120
|
...(provider.docsUrl === undefined ? {} : { docsUrl: provider.docsUrl }),
|
|
121
|
+
...(provider.allowedModelIds === undefined ? {} : { allowedModelIds: provider.allowedModelIds }),
|
|
115
122
|
});
|
|
116
123
|
|
|
117
124
|
const Proto = { ...PipeableProto, [TypeId]: TypeId };
|
|
@@ -125,6 +132,7 @@ const makeProvider = <Identifier extends string, AuthMethods extends readonly Au
|
|
|
125
132
|
assertNoDuplicateAuthMethodIdentifiers(options.identifier, authMethods);
|
|
126
133
|
|
|
127
134
|
return Object.assign(Object.create(Proto), {
|
|
135
|
+
allowedModelIds: options.allowedModelIds,
|
|
128
136
|
authMethods,
|
|
129
137
|
categories: options.categories ?? [],
|
|
130
138
|
description: options.description,
|
|
@@ -159,6 +167,14 @@ const withOption = <P extends AiProvider<any, any>>(
|
|
|
159
167
|
provider.resolveRuntimeConfig,
|
|
160
168
|
) as P;
|
|
161
169
|
|
|
170
|
+
/** @since 0.0.0 @category combinators */
|
|
171
|
+
export const withAllowedModelIds: {
|
|
172
|
+
(resolve: AllowedModelIds): <Self extends Any>(provider: Self) => Self;
|
|
173
|
+
<Self extends Any>(provider: Self, resolve: AllowedModelIds): Self;
|
|
174
|
+
} = Func.dual(2, (provider: AiProvider<any, any>, allowedModelIds: AllowedModelIds) =>
|
|
175
|
+
withOption(provider, { allowedModelIds }),
|
|
176
|
+
);
|
|
177
|
+
|
|
162
178
|
/** @since 0.0.0 @category combinators */
|
|
163
179
|
export const withName: {
|
|
164
180
|
(name: string): <P extends AiProvider<any, any>>(provider: P) => P;
|
package/src/DualRuntime.ts
CHANGED
|
@@ -588,7 +588,15 @@ export class AiProviderRuntimeNotConfiguredError extends Schema.TaggedError<AiPr
|
|
|
588
588
|
{ providerId: Schema.String },
|
|
589
589
|
) {}
|
|
590
590
|
|
|
591
|
-
export
|
|
591
|
+
export class AiModelNotAllowedError extends Schema.TaggedError<AiModelNotAllowedError>()(
|
|
592
|
+
"AiModelNotAllowedError",
|
|
593
|
+
{ modelId: Schema.String, providerId: Schema.String },
|
|
594
|
+
) {}
|
|
595
|
+
|
|
596
|
+
export type AiModelConfigError =
|
|
597
|
+
| AuthMethodExecutionError
|
|
598
|
+
| AiProviderRuntimeNotConfiguredError
|
|
599
|
+
| AiModelNotAllowedError;
|
|
592
600
|
|
|
593
601
|
/** Raised when a provider declares no sandbox access. */
|
|
594
602
|
export class SandboxAccessNotDeclaredError extends Schema.TaggedError<SandboxAccessNotDeclaredError>()(
|
|
@@ -666,6 +674,7 @@ export interface RuntimeService {
|
|
|
666
674
|
readonly resolveAuthMethod: (
|
|
667
675
|
request: ResolveAuthMethodRequest,
|
|
668
676
|
) => Effect.Effect<AuthMethodBinding.Binding, AuthMethodExecutionError>;
|
|
677
|
+
readonly allowedModelIdsFor: (providerId: string) => AiProvider.AllowedModelIds | undefined;
|
|
669
678
|
readonly resolveAiModelConfig: (
|
|
670
679
|
request: ResolveAiModelConfigRequest,
|
|
671
680
|
) => Effect.Effect<AiProvider.RuntimeConfig, AiModelConfigError>;
|
|
@@ -992,6 +1001,13 @@ export const toLayer = <
|
|
|
992
1001
|
});
|
|
993
1002
|
}
|
|
994
1003
|
const binding = yield* resolveAuthMethod(request);
|
|
1004
|
+
const allowed = provider.allowedModelIds?.(request.material);
|
|
1005
|
+
if (allowed !== undefined && !allowed.includes(request.model.id)) {
|
|
1006
|
+
return yield* new AiModelNotAllowedError({
|
|
1007
|
+
modelId: request.model.id,
|
|
1008
|
+
providerId: request.providerId,
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
995
1011
|
// SAFETY: the resolver belongs to this provider and the binding was
|
|
996
1012
|
// resolved from the same provider's declared auth-method list.
|
|
997
1013
|
const resolveRuntimeConfig =
|
|
@@ -1064,6 +1080,10 @@ export const toLayer = <
|
|
|
1064
1080
|
prepareAuthMethod,
|
|
1065
1081
|
prepareOAuth2Tokens,
|
|
1066
1082
|
refreshAuthMethod,
|
|
1083
|
+
allowedModelIdsFor: providerId =>
|
|
1084
|
+
app.aiProviders.find(
|
|
1085
|
+
provider => AiProvider.registryId(provider.identifier) === providerId,
|
|
1086
|
+
)?.allowedModelIds,
|
|
1067
1087
|
resolveAiModelConfig,
|
|
1068
1088
|
resolveAuthMethod,
|
|
1069
1089
|
resolveSandboxAccess,
|