@dual-os/sdk 0.0.0-stage → 0.8.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +19 -2
- package/dist/Action.d.ts +201 -0
- package/dist/Action.d.ts.map +1 -0
- package/dist/Action.js +172 -0
- package/dist/Action.js.map +1 -0
- package/dist/AgentChannel.d.ts +1717 -0
- package/dist/AgentChannel.d.ts.map +1 -0
- package/dist/AgentChannel.js +708 -0
- package/dist/AgentChannel.js.map +1 -0
- package/dist/AgentChannelConformance.d.ts +1543 -0
- package/dist/AgentChannelConformance.d.ts.map +1 -0
- package/dist/AgentChannelConformance.js +163 -0
- package/dist/AgentChannelConformance.js.map +1 -0
- package/dist/AgentChannelRuntime.d.ts +78 -0
- package/dist/AgentChannelRuntime.d.ts.map +1 -0
- package/dist/AgentChannelRuntime.js +270 -0
- package/dist/AgentChannelRuntime.js.map +1 -0
- package/dist/AiProvider.d.ts +132 -0
- package/dist/AiProvider.d.ts.map +1 -0
- package/dist/AiProvider.js +100 -0
- package/dist/AiProvider.js.map +1 -0
- package/dist/AuthMethod.d.ts +381 -0
- package/dist/AuthMethod.d.ts.map +1 -0
- package/dist/AuthMethod.js +225 -0
- package/dist/AuthMethod.js.map +1 -0
- package/dist/AuthMethodBinding.d.ts +77 -0
- package/dist/AuthMethodBinding.d.ts.map +1 -0
- package/dist/AuthMethodBinding.js +31 -0
- package/dist/AuthMethodBinding.js.map +1 -0
- package/dist/AuthMethodExecution.d.ts +223 -0
- package/dist/AuthMethodExecution.d.ts.map +1 -0
- package/dist/AuthMethodExecution.js +277 -0
- package/dist/AuthMethodExecution.js.map +1 -0
- package/dist/ConnectionResolver.d.ts +219 -0
- package/dist/ConnectionResolver.d.ts.map +1 -0
- package/dist/ConnectionResolver.js +153 -0
- package/dist/ConnectionResolver.js.map +1 -0
- package/dist/DefinitionError.d.ts +67 -0
- package/dist/DefinitionError.d.ts.map +1 -0
- package/dist/DefinitionError.js +82 -0
- package/dist/DefinitionError.js.map +1 -0
- package/dist/DualRegistry.d.ts +71 -0
- package/dist/DualRegistry.d.ts.map +1 -0
- package/dist/DualRegistry.js +96 -0
- package/dist/DualRegistry.js.map +1 -0
- package/dist/DualRuntime.d.ts +279 -0
- package/dist/DualRuntime.d.ts.map +1 -0
- package/dist/DualRuntime.js +311 -0
- package/dist/DualRuntime.js.map +1 -0
- package/dist/Files.d.ts +80 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +66 -0
- package/dist/Files.js.map +1 -0
- package/dist/Group.d.ts +106 -0
- package/dist/Group.d.ts.map +1 -0
- package/dist/Group.js +86 -0
- package/dist/Group.js.map +1 -0
- package/dist/Http.d.ts +342 -0
- package/dist/Http.d.ts.map +1 -0
- package/dist/Http.js +677 -0
- package/dist/Http.js.map +1 -0
- package/dist/Mcp.d.ts +109 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +176 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/OAuth2TokenRefresher.d.ts +18 -0
- package/dist/OAuth2TokenRefresher.d.ts.map +1 -0
- package/dist/OAuth2TokenRefresher.js +19 -0
- package/dist/OAuth2TokenRefresher.js.map +1 -0
- package/dist/OAuthFlow.d.ts +71 -0
- package/dist/OAuthFlow.d.ts.map +1 -0
- package/dist/OAuthFlow.js +488 -0
- package/dist/OAuthFlow.js.map +1 -0
- package/dist/Plugin.d.ts +383 -0
- package/dist/Plugin.d.ts.map +1 -0
- package/dist/Plugin.js +249 -0
- package/dist/Plugin.js.map +1 -0
- package/dist/PluginRuntime.d.ts +3186 -0
- package/dist/PluginRuntime.d.ts.map +1 -0
- package/dist/PluginRuntime.js +331 -0
- package/dist/PluginRuntime.js.map +1 -0
- package/dist/Runner.d.ts +1 -0
- package/dist/Runner.js +124 -0
- package/dist/Runner.js.map +1 -0
- package/dist/ToolFile.d.ts +23 -0
- package/dist/ToolFile.d.ts.map +1 -0
- package/dist/ToolFile.js +33 -0
- package/dist/ToolFile.js.map +1 -0
- package/dist/Trigger.d.ts +358 -0
- package/dist/Trigger.d.ts.map +1 -0
- package/dist/Trigger.js +287 -0
- package/dist/Trigger.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/internal/auth-context.d.ts +23 -0
- package/dist/internal/auth-context.d.ts.map +1 -0
- package/dist/internal/auth-context.js +1 -0
- package/dist/internal/auth-execution.d.ts +27 -0
- package/dist/internal/auth-execution.d.ts.map +1 -0
- package/dist/internal/auth-execution.js +66 -0
- package/dist/internal/auth-execution.js.map +1 -0
- package/dist/internal/auth-runtime.d.ts +5 -0
- package/dist/internal/auth-runtime.d.ts.map +1 -0
- package/dist/internal/auth-runtime.js +16 -0
- package/dist/internal/auth-runtime.js.map +1 -0
- package/dist/internal/capabilities.d.ts +24 -0
- package/dist/internal/capabilities.d.ts.map +1 -0
- package/dist/internal/capabilities.js +22 -0
- package/dist/internal/capabilities.js.map +1 -0
- package/dist/internal/children.d.ts +34 -0
- package/dist/internal/children.d.ts.map +1 -0
- package/dist/internal/children.js +53 -0
- package/dist/internal/children.js.map +1 -0
- package/dist/internal/collection-utils.d.ts +4 -0
- package/dist/internal/collection-utils.d.ts.map +1 -0
- package/dist/internal/collection-utils.js +6 -0
- package/dist/internal/collection-utils.js.map +1 -0
- package/dist/internal/dual/actions.d.ts +33 -0
- package/dist/internal/dual/actions.d.ts.map +1 -0
- package/dist/internal/dual/actions.js +26 -0
- package/dist/internal/dual/actions.js.map +1 -0
- package/dist/internal/dual/invoke.d.ts +63 -0
- package/dist/internal/dual/invoke.d.ts.map +1 -0
- package/dist/internal/dual/invoke.js +75 -0
- package/dist/internal/dual/invoke.js.map +1 -0
- package/dist/internal/dual/registry.d.ts +125 -0
- package/dist/internal/dual/registry.d.ts.map +1 -0
- package/dist/internal/dual/registry.js +172 -0
- package/dist/internal/dual/registry.js.map +1 -0
- package/dist/internal/dual/triggers.d.ts +29 -0
- package/dist/internal/dual/triggers.d.ts.map +1 -0
- package/dist/internal/dual/triggers.js +26 -0
- package/dist/internal/dual/triggers.js.map +1 -0
- package/dist/internal/handler-context.d.ts +9 -0
- package/dist/internal/handler-context.d.ts.map +1 -0
- package/dist/internal/handler-context.js +31 -0
- package/dist/internal/handler-context.js.map +1 -0
- package/dist/internal/identifier.d.ts +6 -0
- package/dist/internal/identifier.d.ts.map +1 -0
- package/dist/internal/identifier.js +28 -0
- package/dist/internal/identifier.js.map +1 -0
- package/dist/internal/plugin-handlers.d.ts +38 -0
- package/dist/internal/plugin-handlers.d.ts.map +1 -0
- package/dist/internal/plugin-handlers.js +52 -0
- package/dist/internal/plugin-handlers.js.map +1 -0
- package/dist/internal/proto.d.ts +7 -0
- package/dist/internal/proto.d.ts.map +1 -0
- package/dist/internal/proto.js +10 -0
- package/dist/internal/proto.js.map +1 -0
- package/dist/internal/schema-runtime.d.ts +6 -0
- package/dist/internal/schema-runtime.d.ts.map +1 -0
- package/dist/internal/schema-runtime.js +10 -0
- package/dist/internal/schema-runtime.js.map +1 -0
- package/dist/internal/trigger-runtime-shared.d.ts +41 -0
- package/dist/internal/trigger-runtime-shared.d.ts.map +1 -0
- package/dist/internal/trigger-runtime-shared.js +132 -0
- package/dist/internal/trigger-runtime-shared.js.map +1 -0
- package/dist/internal/trigger-runtime.d.ts +12 -0
- package/dist/internal/trigger-runtime.d.ts.map +1 -0
- package/dist/internal/trigger-runtime.js +95 -0
- package/dist/internal/trigger-runtime.js.map +1 -0
- package/dist/internal/types.d.ts +7 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +1 -0
- package/dist/remote-runtime.d.ts +585 -0
- package/dist/remote-runtime.d.ts.map +1 -0
- package/dist/remote-runtime.js +367 -0
- package/dist/remote-runtime.js.map +1 -0
- package/package.json +55 -4
- package/src/Action.ts +370 -0
- package/src/AgentChannel.ts +860 -0
- package/src/AgentChannelConformance.ts +124 -0
- package/src/AgentChannelRuntime.ts +616 -0
- package/src/AiProvider.ts +255 -0
- package/src/AuthMethod.ts +954 -0
- package/src/AuthMethodBinding.ts +112 -0
- package/src/AuthMethodExecution.ts +542 -0
- package/src/ConnectionResolver.ts +265 -0
- package/src/DefinitionError.ts +115 -0
- package/src/DualRegistry.ts +152 -0
- package/src/DualRuntime.ts +1081 -0
- package/src/Files.ts +89 -0
- package/src/Group.ts +292 -0
- package/src/Http.ts +1205 -0
- package/src/Mcp.ts +299 -0
- package/src/OAuth2TokenRefresher.ts +22 -0
- package/src/OAuthFlow.ts +874 -0
- package/src/Plugin.ts +912 -0
- package/src/PluginRuntime.ts +414 -0
- package/src/Runner.ts +248 -0
- package/src/ToolFile.ts +28 -0
- package/src/Trigger.ts +722 -0
- package/src/index.ts +158 -0
- package/src/internal/auth-context.ts +27 -0
- package/src/internal/auth-execution.ts +241 -0
- package/src/internal/auth-runtime.ts +20 -0
- package/src/internal/capabilities.ts +55 -0
- package/src/internal/children.ts +126 -0
- package/src/internal/collection-utils.ts +8 -0
- package/src/internal/dual/actions.ts +116 -0
- package/src/internal/dual/invoke.ts +307 -0
- package/src/internal/dual/registry.ts +340 -0
- package/src/internal/dual/triggers.ts +128 -0
- package/src/internal/handler-context.ts +57 -0
- package/src/internal/identifier.ts +27 -0
- package/src/internal/plugin-handlers.ts +146 -0
- package/src/internal/proto.ts +8 -0
- package/src/internal/schema-runtime.ts +15 -0
- package/src/internal/trigger-runtime-shared.ts +449 -0
- package/src/internal/trigger-runtime.ts +223 -0
- package/src/internal/types.ts +12 -0
- package/src/remote-runtime.ts +469 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type * as Action from "../../Action.ts";
|
|
2
|
+
import type * as AuthMethod from "../../AuthMethod.ts";
|
|
3
|
+
import type { PluginInstallation } from "../../DualRuntime.ts";
|
|
4
|
+
import type * as Group from "../../Group.ts";
|
|
5
|
+
import type * as Plugin from "../../Plugin.ts";
|
|
6
|
+
import { walkCapabilities } from "../capabilities.ts";
|
|
7
|
+
import type { MachineIdSeparator } from "../identifier.ts";
|
|
8
|
+
import type { IsAny, IsGenericArray } from "../types.ts";
|
|
9
|
+
|
|
10
|
+
interface ActionEntry<Id extends string = string, ActionDef extends Action.Any = Action.Any> {
|
|
11
|
+
readonly actionId: Id;
|
|
12
|
+
readonly action: ActionDef;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ActionEntriesFromActions<Actions extends readonly Action.Any[], Prefix extends string> =
|
|
16
|
+
IsGenericArray<Actions> extends true
|
|
17
|
+
? ActionEntry
|
|
18
|
+
: Actions[number] extends infer ActionDef
|
|
19
|
+
? ActionDef extends Action.Any
|
|
20
|
+
? ActionEntry<`${Prefix}${typeof MachineIdSeparator}${ActionDef["identifier"]}`, ActionDef>
|
|
21
|
+
: never
|
|
22
|
+
: never;
|
|
23
|
+
|
|
24
|
+
type ActionEntriesFromGroups<Groups extends readonly Group.Any[], Prefix extends string> =
|
|
25
|
+
IsGenericArray<Groups> extends true
|
|
26
|
+
? ActionEntry
|
|
27
|
+
: Groups[number] extends infer GroupDef
|
|
28
|
+
? GroupDef extends Group.Any
|
|
29
|
+
? GroupActionEntries<
|
|
30
|
+
GroupDef,
|
|
31
|
+
`${Prefix}${typeof MachineIdSeparator}${GroupDef["identifier"]}`
|
|
32
|
+
>
|
|
33
|
+
: never
|
|
34
|
+
: never;
|
|
35
|
+
|
|
36
|
+
type GroupActionEntries<GroupDef extends Group.Any, Prefix extends string> =
|
|
37
|
+
| ActionEntriesFromActions<GroupDef["actions"], Prefix>
|
|
38
|
+
| ActionEntriesFromGroups<GroupDef["groups"], Prefix>;
|
|
39
|
+
|
|
40
|
+
export type PluginActionEntries<P extends Plugin.Any> =
|
|
41
|
+
| ActionEntriesFromActions<P["actions"], P["identifier"]>
|
|
42
|
+
| ActionEntriesFromGroups<P["groups"], P["identifier"]>;
|
|
43
|
+
|
|
44
|
+
export type AllActionEntries<Plugins extends readonly Plugin.Any[]> =
|
|
45
|
+
IsAny<Plugins> extends true
|
|
46
|
+
? ActionEntry
|
|
47
|
+
: IsGenericArray<Plugins> extends true
|
|
48
|
+
? ActionEntry
|
|
49
|
+
: Plugins[number] extends infer P
|
|
50
|
+
? P extends Plugin.Any
|
|
51
|
+
? PluginActionEntries<P>
|
|
52
|
+
: never
|
|
53
|
+
: never;
|
|
54
|
+
|
|
55
|
+
type GroupActions<Groups extends readonly Group.Any[]> =
|
|
56
|
+
IsGenericArray<Groups> extends true
|
|
57
|
+
? Action.Any
|
|
58
|
+
: Groups[number] extends infer GroupDef
|
|
59
|
+
? GroupDef extends Group.Any
|
|
60
|
+
? GroupDef["actions"][number] | GroupActions<GroupDef["groups"]>
|
|
61
|
+
: never
|
|
62
|
+
: never;
|
|
63
|
+
|
|
64
|
+
export type PluginActions<P extends Plugin.Any> = P["actions"][number] | GroupActions<P["groups"]>;
|
|
65
|
+
|
|
66
|
+
export interface RuntimeActionEntry<
|
|
67
|
+
out ActionId extends string = string,
|
|
68
|
+
out ProviderId extends string = string,
|
|
69
|
+
out ActionDef extends Action.Any = Action.Any,
|
|
70
|
+
out AllowedMethods extends readonly AuthMethod.Any[] = readonly AuthMethod.Any[],
|
|
71
|
+
> {
|
|
72
|
+
readonly actionId: ActionId;
|
|
73
|
+
readonly providerId: ProviderId;
|
|
74
|
+
readonly localId: string;
|
|
75
|
+
readonly pluginVersion: string;
|
|
76
|
+
readonly action: ActionDef;
|
|
77
|
+
readonly authMethods: AllowedMethods;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const entriesOf = (installation: PluginInstallation): readonly RuntimeActionEntry[] =>
|
|
81
|
+
walkCapabilities(installation.plugin, owner => owner.actions).map(
|
|
82
|
+
({ localId, canonicalId, node }) => ({
|
|
83
|
+
action: node,
|
|
84
|
+
actionId: canonicalId,
|
|
85
|
+
authMethods: installation.plugin.authMethods,
|
|
86
|
+
localId,
|
|
87
|
+
pluginVersion: installation.version,
|
|
88
|
+
providerId: installation.plugin.identifier,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export const collectActionEntries = (
|
|
93
|
+
installations: readonly PluginInstallation[],
|
|
94
|
+
): readonly RuntimeActionEntry[] => installations.flatMap(entriesOf);
|
|
95
|
+
|
|
96
|
+
const actionIndex = new WeakMap<
|
|
97
|
+
readonly PluginInstallation[],
|
|
98
|
+
ReadonlyMap<string, RuntimeActionEntry>
|
|
99
|
+
>();
|
|
100
|
+
|
|
101
|
+
/** An action of the installed releases, or of the exact `version` when the caller pins one. */
|
|
102
|
+
export const resolveAction = (
|
|
103
|
+
installations: readonly PluginInstallation[],
|
|
104
|
+
actionId: string,
|
|
105
|
+
version?: string,
|
|
106
|
+
): RuntimeActionEntry | undefined => {
|
|
107
|
+
let index = actionIndex.get(installations);
|
|
108
|
+
if (index === undefined) {
|
|
109
|
+
index = new Map(collectActionEntries(installations).map(entry => [entry.actionId, entry]));
|
|
110
|
+
actionIndex.set(installations, index);
|
|
111
|
+
}
|
|
112
|
+
const entry = index.get(actionId);
|
|
113
|
+
return entry === undefined || (version !== undefined && entry.pluginVersion !== version)
|
|
114
|
+
? undefined
|
|
115
|
+
: entry;
|
|
116
|
+
};
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { Effect, Schema, SchemaIssue } from "effect";
|
|
2
|
+
|
|
3
|
+
import * as Action from "../../Action.ts";
|
|
4
|
+
import type * as AuthMethod from "../../AuthMethod.ts";
|
|
5
|
+
import type {
|
|
6
|
+
ConnectionError,
|
|
7
|
+
ConnectionResolutionContext,
|
|
8
|
+
Service as ConnectionResolverService,
|
|
9
|
+
} from "../../ConnectionResolver.ts";
|
|
10
|
+
import type * as Plugin from "../../Plugin.ts";
|
|
11
|
+
import {
|
|
12
|
+
authRuntimeContext,
|
|
13
|
+
failConnectionIdNotAllowed,
|
|
14
|
+
noAuthRuntimeContext,
|
|
15
|
+
resolveRuntimeConnection,
|
|
16
|
+
type AuthResolutionRequirements,
|
|
17
|
+
type AuthSchemaRequirements,
|
|
18
|
+
toNonEmptyArray,
|
|
19
|
+
} from "../auth-execution.ts";
|
|
20
|
+
import { findHandler, mergeUnder } from "../handler-context.ts";
|
|
21
|
+
import type { ActionHandlerServiceOf } from "../plugin-handlers.ts";
|
|
22
|
+
import { decodeJsonMapError } from "../schema-runtime.ts";
|
|
23
|
+
|
|
24
|
+
import type { PluginActionEntries } from "./actions.ts";
|
|
25
|
+
|
|
26
|
+
export interface InvokeRequest {
|
|
27
|
+
readonly actionId: string;
|
|
28
|
+
/** The exact plugin release the caller pinned; another installed release does not run. */
|
|
29
|
+
readonly actionVersion?: string;
|
|
30
|
+
readonly pluginKey?: string;
|
|
31
|
+
readonly input: unknown;
|
|
32
|
+
readonly connectionId?: string;
|
|
33
|
+
readonly context?: ConnectionResolutionContext;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface InvokeMeta<ActionId extends string = string> {
|
|
37
|
+
readonly actionId: ActionId;
|
|
38
|
+
readonly providerId: string;
|
|
39
|
+
readonly pluginVersion: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface InvokeSuccess<ActionId extends string = string, Data = unknown> {
|
|
43
|
+
readonly data: Data;
|
|
44
|
+
readonly meta: InvokeMeta<ActionId>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class FieldIssue extends Schema.Class<FieldIssue>("FieldIssue")({
|
|
48
|
+
message: Schema.String,
|
|
49
|
+
path: Schema.String,
|
|
50
|
+
}) {}
|
|
51
|
+
|
|
52
|
+
export class ActionNotFoundError extends Schema.TaggedError<ActionNotFoundError>()(
|
|
53
|
+
"ActionNotFoundError",
|
|
54
|
+
{ actionId: Schema.String },
|
|
55
|
+
) {}
|
|
56
|
+
|
|
57
|
+
export class InvalidActionInputError extends Schema.TaggedError<InvalidActionInputError>()(
|
|
58
|
+
"InvalidActionInputError",
|
|
59
|
+
{ actionId: Schema.String, description: Schema.String, fields: Schema.Array(FieldIssue) },
|
|
60
|
+
) {}
|
|
61
|
+
|
|
62
|
+
export class ActionHandlerNotFoundError extends Schema.TaggedError<ActionHandlerNotFoundError>()(
|
|
63
|
+
"ActionHandlerNotFoundError",
|
|
64
|
+
{ actionId: Schema.String },
|
|
65
|
+
) {}
|
|
66
|
+
|
|
67
|
+
export class InvalidActionOutputError extends Schema.TaggedError<InvalidActionOutputError>()(
|
|
68
|
+
"InvalidActionOutputError",
|
|
69
|
+
{ actionId: Schema.String, description: Schema.String, fields: Schema.Array(FieldIssue) },
|
|
70
|
+
) {}
|
|
71
|
+
|
|
72
|
+
type InvokeResolvedActionError =
|
|
73
|
+
| InvalidActionInputError
|
|
74
|
+
| InvalidActionOutputError
|
|
75
|
+
| ActionHandlerNotFoundError
|
|
76
|
+
| Action.ActionHandlerFailure
|
|
77
|
+
| ConnectionError;
|
|
78
|
+
|
|
79
|
+
export type InvokeError = ActionNotFoundError | InvokeResolvedActionError;
|
|
80
|
+
|
|
81
|
+
export type InvokeRequirementsFor<
|
|
82
|
+
Plugins extends readonly Plugin.Any[],
|
|
83
|
+
ActionId extends string,
|
|
84
|
+
> = Plugins[number] extends infer P
|
|
85
|
+
? P extends Plugin.Any
|
|
86
|
+
? PluginRequirements<
|
|
87
|
+
P,
|
|
88
|
+
Extract<PluginActionEntries<P>, { readonly actionId: ActionId }>["action"]
|
|
89
|
+
>
|
|
90
|
+
: never
|
|
91
|
+
: never;
|
|
92
|
+
|
|
93
|
+
export type PluginRequirements<P extends Plugin.Any, ActionDef extends Action.Any> = [
|
|
94
|
+
ActionDef,
|
|
95
|
+
] extends [never]
|
|
96
|
+
? never
|
|
97
|
+
:
|
|
98
|
+
| ActionHandlerServiceOf<P>
|
|
99
|
+
| Action.InputSchema<ActionDef>["DecodingServices"]
|
|
100
|
+
| Action.OutputSchema<ActionDef>["EncodingServices"]
|
|
101
|
+
| ([P["authMethods"][number]] extends [never]
|
|
102
|
+
? never
|
|
103
|
+
:
|
|
104
|
+
| ConnectionResolverService
|
|
105
|
+
| AuthSchemaRequirements<P["authMethods"]>
|
|
106
|
+
| AuthResolutionRequirements<P["authMethods"]>);
|
|
107
|
+
|
|
108
|
+
const schemaIssueFormatter = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
109
|
+
|
|
110
|
+
const formatFieldPath = (path: readonly unknown[]): string => {
|
|
111
|
+
let current = "$";
|
|
112
|
+
|
|
113
|
+
for (const segment of path) {
|
|
114
|
+
if (typeof segment === "number") {
|
|
115
|
+
current += `[${segment}]`;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const key = String(segment);
|
|
120
|
+
current += /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return current;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const schemaErrorFields = (error: Schema.SchemaError): readonly FieldIssue[] =>
|
|
127
|
+
schemaIssueFormatter(error.issue).issues.map(
|
|
128
|
+
issue => new FieldIssue({ message: issue.message, path: formatFieldPath(issue.path ?? []) }),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const decodeActionInput = <Input extends Schema.Top>(
|
|
132
|
+
actionId: string,
|
|
133
|
+
schema: Input,
|
|
134
|
+
input: unknown,
|
|
135
|
+
): Effect.Effect<Input["Type"], InvalidActionInputError, Input["DecodingServices"]> =>
|
|
136
|
+
decodeJsonMapError(
|
|
137
|
+
schema,
|
|
138
|
+
input,
|
|
139
|
+
error =>
|
|
140
|
+
new InvalidActionInputError({
|
|
141
|
+
actionId,
|
|
142
|
+
description: error.message,
|
|
143
|
+
fields: schemaErrorFields(error),
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const validateActionOutput = <Output extends Schema.Top>(
|
|
148
|
+
actionId: string,
|
|
149
|
+
schema: Output,
|
|
150
|
+
output: Output["Type"],
|
|
151
|
+
): Effect.Effect<Output["Type"], InvalidActionOutputError, Output["EncodingServices"]> =>
|
|
152
|
+
Schema.encodeEffect(schema)(output).pipe(
|
|
153
|
+
Effect.as(output),
|
|
154
|
+
Effect.mapError(
|
|
155
|
+
error =>
|
|
156
|
+
new InvalidActionOutputError({
|
|
157
|
+
actionId,
|
|
158
|
+
description: error.message,
|
|
159
|
+
fields: schemaErrorFields(error),
|
|
160
|
+
}),
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const getActionHandler = <ActionId extends string>(
|
|
165
|
+
providerId: string,
|
|
166
|
+
actionId: ActionId,
|
|
167
|
+
): Effect.Effect<Action.Handler<ActionId>, ActionHandlerNotFoundError, Action.Handler<ActionId>> =>
|
|
168
|
+
Effect.context<Action.Handler<ActionId>>().pipe(
|
|
169
|
+
Effect.flatMap(context => {
|
|
170
|
+
const handler = findHandler(context, providerId, Action.handlerKey(actionId)) as
|
|
171
|
+
| Action.Handler<ActionId>
|
|
172
|
+
| undefined;
|
|
173
|
+
|
|
174
|
+
return handler === undefined
|
|
175
|
+
? Effect.fail(new ActionHandlerNotFoundError({ actionId }))
|
|
176
|
+
: Effect.succeed(handler);
|
|
177
|
+
}),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const invokeResolvedActionWithOutput = <
|
|
181
|
+
ActionId extends string,
|
|
182
|
+
Input extends Schema.Top,
|
|
183
|
+
Output extends Schema.Top,
|
|
184
|
+
ActionAuthMethods extends readonly AuthMethod.Any[],
|
|
185
|
+
OutputValue,
|
|
186
|
+
>(
|
|
187
|
+
providerId: string,
|
|
188
|
+
actionId: ActionId,
|
|
189
|
+
pluginVersion: string,
|
|
190
|
+
action: Action.Action<string, Input, Output>,
|
|
191
|
+
authMethods: ActionAuthMethods,
|
|
192
|
+
request: InvokeRequest,
|
|
193
|
+
finish: (
|
|
194
|
+
output: unknown,
|
|
195
|
+
) => Effect.Effect<OutputValue, InvalidActionOutputError, Output["EncodingServices"]>,
|
|
196
|
+
): Effect.Effect<
|
|
197
|
+
InvokeSuccess<ActionId, OutputValue>,
|
|
198
|
+
InvokeResolvedActionError,
|
|
199
|
+
| Action.Handler<ActionId>
|
|
200
|
+
| Input["DecodingServices"]
|
|
201
|
+
| Output["EncodingServices"]
|
|
202
|
+
| ([ActionAuthMethods[number]] extends [never]
|
|
203
|
+
? never
|
|
204
|
+
:
|
|
205
|
+
| ConnectionResolverService
|
|
206
|
+
| AuthSchemaRequirements<ActionAuthMethods>
|
|
207
|
+
| AuthResolutionRequirements<ActionAuthMethods>)
|
|
208
|
+
> => {
|
|
209
|
+
const requiredAuthMethods = toNonEmptyArray(authMethods);
|
|
210
|
+
|
|
211
|
+
if (requiredAuthMethods === undefined && request.connectionId !== undefined) {
|
|
212
|
+
return failConnectionIdNotAllowed(
|
|
213
|
+
"action",
|
|
214
|
+
actionId,
|
|
215
|
+
undefined,
|
|
216
|
+
providerId,
|
|
217
|
+
request.connectionId,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return getActionHandler(providerId, actionId).pipe(
|
|
222
|
+
Effect.flatMap(handler =>
|
|
223
|
+
decodeActionInput(actionId, action.input, request.input).pipe(
|
|
224
|
+
Effect.flatMap(decodedInput =>
|
|
225
|
+
requiredAuthMethods === undefined ||
|
|
226
|
+
// Only an explicit false skips auth for definitions built outside the SDK.
|
|
227
|
+
(action.requireAuth === false && request.connectionId === undefined)
|
|
228
|
+
? Effect.suspend(() => handler.handler(decodedInput, noAuthRuntimeContext()))
|
|
229
|
+
: resolveRuntimeConnection(
|
|
230
|
+
"action",
|
|
231
|
+
actionId,
|
|
232
|
+
undefined,
|
|
233
|
+
providerId,
|
|
234
|
+
requiredAuthMethods,
|
|
235
|
+
request.connectionId,
|
|
236
|
+
request.context,
|
|
237
|
+
).pipe(
|
|
238
|
+
Effect.flatMap(binding =>
|
|
239
|
+
Effect.suspend(() => handler.handler(decodedInput, authRuntimeContext(binding))),
|
|
240
|
+
),
|
|
241
|
+
),
|
|
242
|
+
),
|
|
243
|
+
Effect.updateContext(input => mergeUnder(handler.context, input)),
|
|
244
|
+
),
|
|
245
|
+
),
|
|
246
|
+
Effect.flatMap(finish),
|
|
247
|
+
Effect.map((data): InvokeSuccess<ActionId, OutputValue> => ({
|
|
248
|
+
data,
|
|
249
|
+
meta: { actionId, pluginVersion, providerId },
|
|
250
|
+
})),
|
|
251
|
+
);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const invokeResolvedAction = <
|
|
255
|
+
ActionId extends string,
|
|
256
|
+
Input extends Schema.Top,
|
|
257
|
+
Output extends Schema.Top,
|
|
258
|
+
ActionAuthMethods extends readonly AuthMethod.Any[],
|
|
259
|
+
>(
|
|
260
|
+
providerId: string,
|
|
261
|
+
actionId: ActionId,
|
|
262
|
+
pluginVersion: string,
|
|
263
|
+
action: Action.Action<string, Input, Output>,
|
|
264
|
+
authMethods: ActionAuthMethods,
|
|
265
|
+
request: InvokeRequest,
|
|
266
|
+
) =>
|
|
267
|
+
invokeResolvedActionWithOutput(
|
|
268
|
+
providerId,
|
|
269
|
+
actionId,
|
|
270
|
+
pluginVersion,
|
|
271
|
+
action,
|
|
272
|
+
authMethods,
|
|
273
|
+
request,
|
|
274
|
+
data => validateActionOutput(actionId, action.output, data as Output["Type"]),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
export const invokeResolvedActionJson = <
|
|
278
|
+
ActionId extends string,
|
|
279
|
+
Input extends Schema.Top,
|
|
280
|
+
Output extends Schema.Top,
|
|
281
|
+
ActionAuthMethods extends readonly AuthMethod.Any[],
|
|
282
|
+
>(
|
|
283
|
+
providerId: string,
|
|
284
|
+
actionId: ActionId,
|
|
285
|
+
pluginVersion: string,
|
|
286
|
+
action: Action.Action<string, Input, Output>,
|
|
287
|
+
authMethods: ActionAuthMethods,
|
|
288
|
+
request: InvokeRequest,
|
|
289
|
+
) =>
|
|
290
|
+
invokeResolvedActionWithOutput(
|
|
291
|
+
providerId,
|
|
292
|
+
actionId,
|
|
293
|
+
pluginVersion,
|
|
294
|
+
action,
|
|
295
|
+
authMethods,
|
|
296
|
+
request,
|
|
297
|
+
data =>
|
|
298
|
+
Schema.encodeUnknownEffect(Schema.toCodecJson(action.output))(data).pipe(
|
|
299
|
+
Effect.mapError(error =>
|
|
300
|
+
InvalidActionOutputError.make({
|
|
301
|
+
actionId,
|
|
302
|
+
description: error.message,
|
|
303
|
+
fields: schemaErrorFields(error),
|
|
304
|
+
}),
|
|
305
|
+
),
|
|
306
|
+
),
|
|
307
|
+
);
|