@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,311 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { BuilderCollisionError } from "./DefinitionError.js";
|
|
3
|
+
import { ActionHandlerError, RetryableActionHandlerError } from "./Action.js";
|
|
4
|
+
import { makeBinding } from "./AuthMethodBinding.js";
|
|
5
|
+
import { decodeSetup, executeJson, prepare, prepareOAuth2Tokens, refreshUnknown, resolve, resolveDecoded } from "./AuthMethodExecution.js";
|
|
6
|
+
import { ConnectionIdNotAllowedError, ConnectionReauthorizationRequiredError, ConnectionRequiredError, ConnectionResolverStoreError, ConnectionSelectionRequiredError, InvalidConnectionIdError, InvalidResolvedConnectionError } from "./ConnectionResolver.js";
|
|
7
|
+
import { indexGroups } from "./internal/handler-context.js";
|
|
8
|
+
import { Service as Service$1, layer } from "./AgentChannelRuntime.js";
|
|
9
|
+
import { RuntimeConfig, registryId } from "./AiProvider.js";
|
|
10
|
+
import { resolveAction } from "./internal/dual/actions.js";
|
|
11
|
+
import { resolveRuntimeTrigger } from "./internal/dual/triggers.js";
|
|
12
|
+
import { TriggerNotFoundError } from "./DualRegistry.js";
|
|
13
|
+
import { authRuntimeContext } from "./internal/auth-execution.js";
|
|
14
|
+
import { ActionHandlerNotFoundError, ActionNotFoundError, FieldIssue, InvalidActionInputError, InvalidActionOutputError, invokeResolvedAction, invokeResolvedActionJson } from "./internal/dual/invoke.js";
|
|
15
|
+
import { activate, deactivate, parse, poll, verify } from "./Trigger.js";
|
|
16
|
+
import "./DualRuntime.js";
|
|
17
|
+
import { Array, Context, Effect, Function, Layer, Predicate, Result, Schema, pipe } from "effect";
|
|
18
|
+
import { Url } from "effect/http";
|
|
19
|
+
//#region src/DualRuntime.ts
|
|
20
|
+
/**
|
|
21
|
+
* Dual action invocation, trigger lifecycle, and auth runtime.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.0
|
|
24
|
+
*/
|
|
25
|
+
var DualRuntime_exports = /* @__PURE__ */ __exportAll({
|
|
26
|
+
ActionHandlerError: () => ActionHandlerError,
|
|
27
|
+
ActionHandlerNotFoundError: () => ActionHandlerNotFoundError,
|
|
28
|
+
ActionNotFoundError: () => ActionNotFoundError,
|
|
29
|
+
AiProviderRuntimeNotConfiguredError: () => AiProviderRuntimeNotConfiguredError,
|
|
30
|
+
AuthMethodNotFoundError: () => AuthMethodNotFoundError,
|
|
31
|
+
ConnectionIdNotAllowedError: () => ConnectionIdNotAllowedError,
|
|
32
|
+
ConnectionReauthorizationRequiredError: () => ConnectionReauthorizationRequiredError,
|
|
33
|
+
ConnectionRequiredError: () => ConnectionRequiredError,
|
|
34
|
+
ConnectionResolverStoreError: () => ConnectionResolverStoreError,
|
|
35
|
+
ConnectionSelectionRequiredError: () => ConnectionSelectionRequiredError,
|
|
36
|
+
DualRuntime: () => DualRuntime_exports,
|
|
37
|
+
FieldIssue: () => FieldIssue,
|
|
38
|
+
InvalidActionInputError: () => InvalidActionInputError,
|
|
39
|
+
InvalidActionOutputError: () => InvalidActionOutputError,
|
|
40
|
+
InvalidConnectionIdError: () => InvalidConnectionIdError,
|
|
41
|
+
InvalidResolvedConnectionError: () => InvalidResolvedConnectionError,
|
|
42
|
+
RetryableActionHandlerError: () => RetryableActionHandlerError,
|
|
43
|
+
SandboxAccessNotDeclaredError: () => SandboxAccessNotDeclaredError,
|
|
44
|
+
SandboxRequestNotAllowedError: () => SandboxRequestNotAllowedError,
|
|
45
|
+
Service: () => Service,
|
|
46
|
+
fromPlugin: () => fromPlugin,
|
|
47
|
+
install: () => install,
|
|
48
|
+
invoke: () => invoke,
|
|
49
|
+
make: () => make,
|
|
50
|
+
toLayer: () => toLayer,
|
|
51
|
+
withPlugin: () => withPlugin,
|
|
52
|
+
withPlugins: () => withPlugins
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Install one plugin release.
|
|
56
|
+
*
|
|
57
|
+
* @since 0.7.0
|
|
58
|
+
* @category constructors
|
|
59
|
+
*/
|
|
60
|
+
const install = (plugin, version) => ({
|
|
61
|
+
plugin,
|
|
62
|
+
version
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* The runtime of one plugin release, as the plugin's own process runs it. `version` defaults to
|
|
66
|
+
* `0.0.0` for tests that do not need the package version.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.7.0
|
|
69
|
+
* @category constructors
|
|
70
|
+
*/
|
|
71
|
+
const fromPlugin = (plugin, version = "0.0.0") => ({
|
|
72
|
+
aiProviders: [],
|
|
73
|
+
identifier: plugin.identifier,
|
|
74
|
+
layer: plugin.layer,
|
|
75
|
+
plugins: [install(plugin, version)]
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* An app runtime without plugins, for {@link withPlugin} and {@link withPlugins} to fill.
|
|
79
|
+
*
|
|
80
|
+
* @since 0.7.0
|
|
81
|
+
* @category constructors
|
|
82
|
+
*/
|
|
83
|
+
const make = (identifier) => ({
|
|
84
|
+
aiProviders: [],
|
|
85
|
+
identifier,
|
|
86
|
+
layer: Layer.empty,
|
|
87
|
+
plugins: []
|
|
88
|
+
});
|
|
89
|
+
function addPlugins(app, entries) {
|
|
90
|
+
const seen = new Set(Array.map(app.plugins, (installation) => installation.plugin.identifier));
|
|
91
|
+
for (const [plugin] of entries) {
|
|
92
|
+
if (seen.has(plugin.identifier)) throw new BuilderCollisionError({
|
|
93
|
+
childKind: "plugin",
|
|
94
|
+
existingChildKind: "plugin",
|
|
95
|
+
identifier: plugin.identifier,
|
|
96
|
+
ownerIdentifier: app.identifier,
|
|
97
|
+
ownerKind: "dual"
|
|
98
|
+
});
|
|
99
|
+
seen.add(plugin.identifier);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...app,
|
|
103
|
+
layer: Array.reduce(entries, app.layer, (layer, [plugin]) => Layer.provideMerge(layer, plugin.layer)),
|
|
104
|
+
plugins: [...app.plugins, ...Array.map(entries, ([plugin, version]) => install(plugin, version))]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Add one plugin release: the plugin and its package version.
|
|
109
|
+
*
|
|
110
|
+
* @since 0.7.0
|
|
111
|
+
* @category combinators
|
|
112
|
+
*/
|
|
113
|
+
const withPlugin = Function.dual(3, (app, plugin, version) => addPlugins(app, [[plugin, version]]));
|
|
114
|
+
/**
|
|
115
|
+
* Add several plugin releases in one step, which keeps a large app's inferred type compact.
|
|
116
|
+
*
|
|
117
|
+
* @since 0.7.0
|
|
118
|
+
* @category combinators
|
|
119
|
+
*/
|
|
120
|
+
const withPlugins = Function.dual(2, addPlugins);
|
|
121
|
+
const pluginOf = (app, identifier) => app.plugins.find((installation) => installation.plugin.identifier === identifier)?.plugin;
|
|
122
|
+
/**
|
|
123
|
+
* Invoke an action directly in-process.
|
|
124
|
+
*
|
|
125
|
+
* The invocation boundary resolves an action by canonical machine id, validates
|
|
126
|
+
* unknown input against the resolved runtime schema, runs the handler, and
|
|
127
|
+
* returns a standard success envelope. This mirrors the server trusted invoke
|
|
128
|
+
* boundary: runtime schema validation is authoritative.
|
|
129
|
+
*
|
|
130
|
+
* @since 0.0.0
|
|
131
|
+
* @category execution
|
|
132
|
+
*/
|
|
133
|
+
const failInvokeActionNotFound = (actionId) => Effect.fail(new ActionNotFoundError({ actionId }));
|
|
134
|
+
const invokeRaw = (app, request, json = false) => {
|
|
135
|
+
const resolved = resolveAction(app.plugins, request.actionId, request.actionVersion);
|
|
136
|
+
if (resolved === void 0 || request.pluginKey !== void 0 && resolved.providerId !== request.pluginKey) return failInvokeActionNotFound(request.actionId);
|
|
137
|
+
return (json ? invokeResolvedActionJson : invokeResolvedAction)(resolved.providerId, resolved.actionId, resolved.pluginVersion, resolved.action, resolved.authMethods, request);
|
|
138
|
+
};
|
|
139
|
+
const invoke = (app, request) => invokeRaw(app, request).pipe(Effect.provide(app.layer));
|
|
140
|
+
var AuthMethodNotFoundError = class extends Schema.TaggedError()("AuthMethodNotFoundError", {
|
|
141
|
+
authMethodId: Schema.String,
|
|
142
|
+
providerId: Schema.String
|
|
143
|
+
}) {};
|
|
144
|
+
var AiProviderRuntimeNotConfiguredError = class extends Schema.TaggedError()("AiProviderRuntimeNotConfiguredError", { providerId: Schema.String }) {};
|
|
145
|
+
/** Raised when a provider declares no sandbox access. */
|
|
146
|
+
var SandboxAccessNotDeclaredError = class extends Schema.TaggedError()("SandboxAccessNotDeclaredError", { providerId: Schema.String }) {};
|
|
147
|
+
/** Raised when the Connection may not be sent with a sandbox request: another origin, or a request the provider refuses. */
|
|
148
|
+
var SandboxRequestNotAllowedError = class extends Schema.TaggedError()("SandboxRequestNotAllowedError", {
|
|
149
|
+
origin: Schema.String,
|
|
150
|
+
path: Schema.String,
|
|
151
|
+
providerId: Schema.String
|
|
152
|
+
}) {};
|
|
153
|
+
/**
|
|
154
|
+
* Effect service provided by {@link toLayer}.
|
|
155
|
+
*
|
|
156
|
+
* @since 0.0.0
|
|
157
|
+
* @category services
|
|
158
|
+
*/
|
|
159
|
+
var Service = class extends Context.Service()("@dual-os/sdk/Dual/Service") {};
|
|
160
|
+
/**
|
|
161
|
+
* Turn an {@link App} into a runtime Effect service layer.
|
|
162
|
+
*
|
|
163
|
+
* @since 0.0.0
|
|
164
|
+
* @category layers
|
|
165
|
+
*/
|
|
166
|
+
const toLayer = (app) => {
|
|
167
|
+
const fullAuthMethodId = (providerId, method) => `${providerId}/${method.identifier}`;
|
|
168
|
+
const findAuthMethod = (providerId, authMethodId) => {
|
|
169
|
+
const method = (pluginOf(app, providerId) ?? app.aiProviders.find((candidate) => registryId(candidate.identifier) === providerId))?.authMethods.find((candidate) => candidate.identifier === authMethodId || fullAuthMethodId(providerId, candidate) === authMethodId);
|
|
170
|
+
return method === void 0 ? Effect.fail(new AuthMethodNotFoundError({
|
|
171
|
+
authMethodId,
|
|
172
|
+
providerId
|
|
173
|
+
})) : Effect.succeed(method);
|
|
174
|
+
};
|
|
175
|
+
return Layer.effect(Service, Effect.gen(function* () {
|
|
176
|
+
const channels = yield* Service$1;
|
|
177
|
+
const context = yield* Effect.context();
|
|
178
|
+
const appContext = indexGroups(context);
|
|
179
|
+
const provideRuntimeContext = (effect) => effect.pipe(Effect.updateContext((input) => Context.merge(appContext, input)));
|
|
180
|
+
const runWithCapturedAppContext = (effect) => provideRuntimeContext(effect);
|
|
181
|
+
const getAuthMethod = (request) => findAuthMethod(request.providerId, request.authMethodId);
|
|
182
|
+
const getTrigger = (request) => {
|
|
183
|
+
const resolved = resolveRuntimeTrigger(app.plugins, request.triggerId, request.triggerVersion);
|
|
184
|
+
return resolved === void 0 || request.pluginKey !== void 0 && resolved.providerId !== request.pluginKey ? Effect.fail(new TriggerNotFoundError({ triggerId: request.triggerId })) : Effect.succeed(resolved);
|
|
185
|
+
};
|
|
186
|
+
const triggerLifecycleRequest = (request) => ({
|
|
187
|
+
config: request.config,
|
|
188
|
+
...request.state === void 0 ? {} : { state: request.state },
|
|
189
|
+
...request.connectionId === void 0 ? {} : { connectionId: request.connectionId },
|
|
190
|
+
...request.context === void 0 ? {} : { context: request.context }
|
|
191
|
+
});
|
|
192
|
+
const webhookActivationRequest = (request) => ({
|
|
193
|
+
...triggerLifecycleRequest(request),
|
|
194
|
+
webhookUrl: request.webhookUrl
|
|
195
|
+
});
|
|
196
|
+
const webhookTriggerLifecycleRequest = (request) => ({
|
|
197
|
+
...webhookActivationRequest(request),
|
|
198
|
+
request: Predicate.isString(request.request.rawBody) ? {
|
|
199
|
+
...request.request,
|
|
200
|
+
rawBody: new TextEncoder().encode(request.request.rawBody)
|
|
201
|
+
} : request.request
|
|
202
|
+
});
|
|
203
|
+
const activateTrigger = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
204
|
+
const entry = yield* getTrigger(request);
|
|
205
|
+
return yield* activate(entry, webhookActivationRequest(request));
|
|
206
|
+
}));
|
|
207
|
+
const deactivateTrigger = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
208
|
+
const entry = yield* getTrigger(request);
|
|
209
|
+
return yield* deactivate(entry, webhookActivationRequest(request));
|
|
210
|
+
}));
|
|
211
|
+
const verifyTrigger = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
212
|
+
const entry = yield* getTrigger(request);
|
|
213
|
+
return yield* verify(entry, webhookTriggerLifecycleRequest(request));
|
|
214
|
+
}));
|
|
215
|
+
const parseTrigger = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
216
|
+
const entry = yield* getTrigger(request);
|
|
217
|
+
return yield* parse(entry, webhookTriggerLifecycleRequest(request));
|
|
218
|
+
}));
|
|
219
|
+
const pollTrigger = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
220
|
+
const entry = yield* getTrigger(request);
|
|
221
|
+
return yield* poll(entry, triggerLifecycleRequest(request));
|
|
222
|
+
}));
|
|
223
|
+
const decodeAuthMethodSetup = (request) => runWithCapturedAppContext(getAuthMethod(request).pipe(Effect.flatMap((method) => {
|
|
224
|
+
if (request.encoding === "json" && method.setup !== void 0) return Schema.decodeUnknownEffect(Schema.toCodecJson(method.setup))(request.setup);
|
|
225
|
+
return decodeSetup(method, request.setup);
|
|
226
|
+
})));
|
|
227
|
+
const withAuthMethodSetup = (request, execute) => runWithCapturedAppContext(getAuthMethod(request).pipe(Effect.flatMap((method) => decodeSetup(method, request.setup).pipe(Effect.flatMap((setup) => execute(method, setup))))));
|
|
228
|
+
const prepareAuthMethod = (request) => withAuthMethodSetup(request, (method, setup) => prepare(method, request.input, { setup }));
|
|
229
|
+
const prepareOAuth2Tokens$1 = (request) => withAuthMethodSetup(request, (method, setup) => prepareOAuth2Tokens(method, request.tokens, { setup }));
|
|
230
|
+
const refreshAuthMethod = (request) => runWithCapturedAppContext(getAuthMethod(request).pipe(Effect.flatMap((method) => decodeSetup(method, request.setup).pipe(Effect.flatMap((setup) => refreshUnknown(method, request.material, {
|
|
231
|
+
minValidityMs: request.minValidityMs,
|
|
232
|
+
now: request.now,
|
|
233
|
+
reason: request.reason,
|
|
234
|
+
setup
|
|
235
|
+
}))))));
|
|
236
|
+
const resolveAuthMethod = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
237
|
+
const method = yield* getAuthMethod(request);
|
|
238
|
+
const setup = yield* decodeAuthMethodSetup(request);
|
|
239
|
+
const value = request.encoding === "json" ? yield* resolveDecoded(method, yield* Schema.decodeUnknownEffect(Schema.toCodecJson(method.material))(request.material), { setup }) : yield* resolve(method, request.material, { setup });
|
|
240
|
+
return makeBinding({
|
|
241
|
+
connectionId: void 0,
|
|
242
|
+
method,
|
|
243
|
+
providerId: request.providerId,
|
|
244
|
+
value
|
|
245
|
+
});
|
|
246
|
+
}));
|
|
247
|
+
const resolveAiModelConfig = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
248
|
+
const provider = app.aiProviders.find((candidate) => registryId(candidate.identifier) === request.providerId);
|
|
249
|
+
if (provider?.resolveRuntimeConfig === void 0) return yield* new AiProviderRuntimeNotConfiguredError({ providerId: request.providerId });
|
|
250
|
+
const binding = yield* resolveAuthMethod(request);
|
|
251
|
+
const resolveRuntimeConfig = provider.resolveRuntimeConfig;
|
|
252
|
+
return yield* Schema.decodeUnknownEffect(RuntimeConfig)(resolveRuntimeConfig({
|
|
253
|
+
binding,
|
|
254
|
+
model: request.model
|
|
255
|
+
}));
|
|
256
|
+
}));
|
|
257
|
+
const resolveSandboxAccess = (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
258
|
+
const access = pluginOf(app, request.providerId)?.sandboxAccess;
|
|
259
|
+
if (access === void 0) return yield* new SandboxAccessNotDeclaredError({ providerId: request.providerId });
|
|
260
|
+
const context = authRuntimeContext(yield* resolveAuthMethod(request));
|
|
261
|
+
const origins = Array.map(access.origins(context), (origin) => Result.getOrUndefined(Url.fromString(origin))?.origin ?? origin);
|
|
262
|
+
const authorize = (outgoing) => {
|
|
263
|
+
const url = Result.getOrUndefined(Url.fromString(outgoing.url));
|
|
264
|
+
const refused = new SandboxRequestNotAllowedError({
|
|
265
|
+
origin: url?.origin ?? outgoing.url,
|
|
266
|
+
path: url?.pathname ?? "",
|
|
267
|
+
providerId: request.providerId
|
|
268
|
+
});
|
|
269
|
+
if (url === void 0 || !origins.includes(url.origin)) return Effect.fail(refused);
|
|
270
|
+
return Effect.fromOption(access.authorize(outgoing, context), () => refused);
|
|
271
|
+
};
|
|
272
|
+
return {
|
|
273
|
+
authorize,
|
|
274
|
+
origins
|
|
275
|
+
};
|
|
276
|
+
}));
|
|
277
|
+
return Service.of({
|
|
278
|
+
activateTrigger,
|
|
279
|
+
checkAccessAgentChannel: channels.checkAccess,
|
|
280
|
+
deactivateTrigger,
|
|
281
|
+
decodeAgentChannelDefinitionSettings: channels.decodeDefinitionSettings,
|
|
282
|
+
decodeAgentChannelDeploymentSettings: channels.decodeDeploymentSettings,
|
|
283
|
+
decodeAuthMethodSetup,
|
|
284
|
+
executeAgentChannel: channels.execute,
|
|
285
|
+
executeAuthJson: (request) => runWithCapturedAppContext(pipe(getAuthMethod(request), Effect.flatMap((method) => executeJson(method, request)))),
|
|
286
|
+
getAgentChannel: channels.get,
|
|
287
|
+
getAuthMethod,
|
|
288
|
+
invoke: (request) => runWithCapturedAppContext(invokeRaw(app, request)),
|
|
289
|
+
invokeJson: (request) => runWithCapturedAppContext(Effect.gen(function* () {
|
|
290
|
+
const result = yield* invokeRaw(app, request, true);
|
|
291
|
+
return {
|
|
292
|
+
...result,
|
|
293
|
+
data: yield* Schema.decodeUnknownEffect(Schema.Json)(result.data)
|
|
294
|
+
};
|
|
295
|
+
})),
|
|
296
|
+
parseTrigger,
|
|
297
|
+
pollTrigger,
|
|
298
|
+
prepareAuthMethod,
|
|
299
|
+
prepareOAuth2Tokens: prepareOAuth2Tokens$1,
|
|
300
|
+
refreshAuthMethod,
|
|
301
|
+
resolveAiModelConfig,
|
|
302
|
+
resolveAuthMethod,
|
|
303
|
+
resolveSandboxAccess,
|
|
304
|
+
verifyTrigger
|
|
305
|
+
});
|
|
306
|
+
})).pipe(Layer.provide(layer(app.plugins.map((installation) => installation.plugin))), Layer.provide(app.layer));
|
|
307
|
+
};
|
|
308
|
+
//#endregion
|
|
309
|
+
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 };
|
|
310
|
+
|
|
311
|
+
//# sourceMappingURL=DualRuntime.js.map
|
|
@@ -0,0 +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,Q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AQ,OAAO,CAAC,CAC3E,CACF;GACF,iBAAiB,SAAS;GAC1B;GACA,SAAQ,YAAW,0BAA0B,UAAU,KAAK,OAAO,CAAC;GACpE,aAAY,YACV,0BACE,OAAO,IAAI,aAAa;IACtB,MAAM,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"}
|
package/dist/Files.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import "./Files.js";
|
|
2
|
+
import { Context, Effect, Schema } from "effect";
|
|
3
|
+
declare namespace Files_d_exports {
|
|
4
|
+
export { File, FileError, Files_d_exports as Files, Service, read, write };
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A file stored by the host. Action inputs and outputs carry this reference, never the bytes.
|
|
8
|
+
*
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
* @category schemas
|
|
11
|
+
*/
|
|
12
|
+
export type File = typeof File.Type;
|
|
13
|
+
export declare const File: Schema.Struct<{
|
|
14
|
+
readonly _tag: Schema.tag<"File">;
|
|
15
|
+
readonly contentType: Schema.String;
|
|
16
|
+
readonly id: Schema.NonEmptyString;
|
|
17
|
+
readonly name: Schema.String;
|
|
18
|
+
readonly sizeBytes: Schema.Natural;
|
|
19
|
+
}>;
|
|
20
|
+
declare const FileError_base: Schema.Class<FileError, Schema.TaggedStruct<"FileError", {
|
|
21
|
+
readonly cause: Schema.optionalKey<Schema.Redacted<Schema.Unknown>>;
|
|
22
|
+
readonly message: Schema.String;
|
|
23
|
+
}>, import("effect/Cause").YieldableError>;
|
|
24
|
+
/**
|
|
25
|
+
* A file the host could not read or keep. The message is safe for callers; an optional cause
|
|
26
|
+
* retains the host failure in memory for trusted diagnostics. Wrap causes with Redacted.make
|
|
27
|
+
* without a provider-derived label. JSON schema encoding of a cause is intentionally refused.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.1.0
|
|
30
|
+
* @category errors
|
|
31
|
+
*/
|
|
32
|
+
export declare class FileError extends FileError_base {}
|
|
33
|
+
declare const Service_base: Context.ServiceClass<Service, "@dual-os/sdk/Files/Service", {
|
|
34
|
+
readonly read: (file: File) => Effect.Effect<Uint8Array, FileError>;
|
|
35
|
+
readonly write: (file: {
|
|
36
|
+
bytes: Uint8Array;
|
|
37
|
+
name: string;
|
|
38
|
+
contentType?: string | null | undefined;
|
|
39
|
+
}) => Effect.Effect<File, FileError>;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads and stores files for the caller of an action: a workflow run, or the person in a chat.
|
|
43
|
+
*
|
|
44
|
+
* @since 0.1.0
|
|
45
|
+
* @category services
|
|
46
|
+
*/
|
|
47
|
+
export declare class Service extends Service_base {}
|
|
48
|
+
/**
|
|
49
|
+
* Reads a file's bytes through the caller's file service.
|
|
50
|
+
*
|
|
51
|
+
* @since 0.1.0
|
|
52
|
+
* @category files
|
|
53
|
+
*/
|
|
54
|
+
export declare const read: (file: {
|
|
55
|
+
readonly _tag: "File";
|
|
56
|
+
readonly contentType: string;
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly sizeBytes: number;
|
|
60
|
+
}) => Effect.Effect<Uint8Array<ArrayBufferLike>, FileError, never>;
|
|
61
|
+
/**
|
|
62
|
+
* Stores bytes as a new file of the caller and returns its reference.
|
|
63
|
+
*
|
|
64
|
+
* @since 0.1.0
|
|
65
|
+
* @category files
|
|
66
|
+
*/
|
|
67
|
+
export declare const write: (file: {
|
|
68
|
+
bytes: Uint8Array;
|
|
69
|
+
name: string;
|
|
70
|
+
contentType?: string | null | undefined;
|
|
71
|
+
}) => Effect.Effect<{
|
|
72
|
+
readonly _tag: "File";
|
|
73
|
+
readonly contentType: string;
|
|
74
|
+
readonly id: string;
|
|
75
|
+
readonly name: string;
|
|
76
|
+
readonly sizeBytes: number;
|
|
77
|
+
}, FileError, never>;
|
|
78
|
+
//#endregion
|
|
79
|
+
export { Files_d_exports as Files, Files_d_exports };
|
|
80
|
+
//# sourceMappingURL=Files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Files.d.ts","names":[],"sources":["../src/Files.ts"],"mappings":";;;;;;;;;;;YAcY,cAAc,KAAK;qBAClB,MAAI,OAAA;;;;;;;;;;;;;;;;;;;qBAiBJ,kBAAkB;;WAcZ,OAAC,MAAM,SAAS,OAAO,OAAO,YAAY;WACzC,QAAC;IACf,OAAO;IACP;IAEA;QACI,OAAO,OAAO,MAAM;;;;;;;;qBATjB,gBAAgB;;;;;;;qBA6BhB,OAAI;;;;;;MAEf,OAAA,OAAA,WAAA,kBAAA;;;;;;;qBAQW,QAAK;EAlCL,OAAA;EACD;EAEQ;;;;;;;GAmClB"}
|
package/dist/Files.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import "./Files.js";
|
|
3
|
+
import { Context, Effect, Schema, pipe } from "effect";
|
|
4
|
+
//#region src/Files.ts
|
|
5
|
+
/**
|
|
6
|
+
* Files that actions take and return: a small reference in action data, with the bytes kept by the
|
|
7
|
+
* host and read or written through the host's file service.
|
|
8
|
+
*
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
var Files_exports = /* @__PURE__ */ __exportAll({
|
|
12
|
+
File: () => File,
|
|
13
|
+
FileError: () => FileError,
|
|
14
|
+
Files: () => Files_exports,
|
|
15
|
+
Service: () => Service,
|
|
16
|
+
read: () => read,
|
|
17
|
+
write: () => write
|
|
18
|
+
});
|
|
19
|
+
const File = Schema.TaggedStruct("File", {
|
|
20
|
+
contentType: Schema.String,
|
|
21
|
+
id: Schema.NonEmptyString,
|
|
22
|
+
name: Schema.String,
|
|
23
|
+
sizeBytes: Schema.Natural
|
|
24
|
+
}).annotate({ description: "A file: pass the reference a file input or an earlier step returned." });
|
|
25
|
+
/**
|
|
26
|
+
* A file the host could not read or keep. The message is safe for callers; an optional cause
|
|
27
|
+
* retains the host failure in memory for trusted diagnostics. Wrap causes with Redacted.make
|
|
28
|
+
* without a provider-derived label. JSON schema encoding of a cause is intentionally refused.
|
|
29
|
+
*
|
|
30
|
+
* @since 0.1.0
|
|
31
|
+
* @category errors
|
|
32
|
+
*/
|
|
33
|
+
var FileError = class extends Schema.TaggedError()("FileError", {
|
|
34
|
+
cause: Schema.optionalKey(Schema.Redacted(Schema.Unknown, { disallowJsonEncode: true })),
|
|
35
|
+
message: Schema.String
|
|
36
|
+
}) {};
|
|
37
|
+
/**
|
|
38
|
+
* Reads and stores files for the caller of an action: a workflow run, or the person in a chat.
|
|
39
|
+
*
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
* @category services
|
|
42
|
+
*/
|
|
43
|
+
var Service = class extends Context.Service()("@dual-os/sdk/Files/Service") {};
|
|
44
|
+
const service = pipe(Effect.serviceOption(Service), Effect.flatMap(Effect.fromOption(() => FileError.make({ message: "Files are only available when Dual calls the action" }))));
|
|
45
|
+
/**
|
|
46
|
+
* Reads a file's bytes through the caller's file service.
|
|
47
|
+
*
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
* @category files
|
|
50
|
+
*/
|
|
51
|
+
const read = Effect.fnUntraced(function* (file) {
|
|
52
|
+
return yield* (yield* service).read(file);
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Stores bytes as a new file of the caller and returns its reference.
|
|
56
|
+
*
|
|
57
|
+
* @since 0.1.0
|
|
58
|
+
* @category files
|
|
59
|
+
*/
|
|
60
|
+
const write = Effect.fnUntraced(function* (file) {
|
|
61
|
+
return yield* (yield* service).write(file);
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
export { File, FileError, Files_exports as Files, Files_exports, Service, read, write };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=Files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Files.js","names":[],"sources":["../src/Files.ts"],"sourcesContent":["/**\n * Files that actions take and return: a small reference in action data, with the bytes kept by the\n * host and read or written through the host's file service.\n *\n * @since 0.1.0\n */\nimport { Context, Effect, Schema, pipe } from \"effect\";\n\n/**\n * A file stored by the host. Action inputs and outputs carry this reference, never the bytes.\n *\n * @since 0.1.0\n * @category schemas\n */\nexport type File = typeof File.Type;\nexport const File = Schema.TaggedStruct(\"File\", {\n contentType: Schema.String,\n id: Schema.NonEmptyString,\n name: Schema.String,\n sizeBytes: Schema.Natural,\n}).annotate({\n description: \"A file: pass the reference a file input or an earlier step returned.\",\n});\n\n/**\n * A file the host could not read or keep. The message is safe for callers; an optional cause\n * retains the host failure in memory for trusted diagnostics. Wrap causes with Redacted.make\n * without a provider-derived label. JSON schema encoding of a cause is intentionally refused.\n *\n * @since 0.1.0\n * @category errors\n */\nexport class FileError extends Schema.TaggedError<FileError>()(\"FileError\", {\n cause: Schema.optionalKey(Schema.Redacted(Schema.Unknown, { disallowJsonEncode: true })),\n message: Schema.String,\n}) {}\n\n/**\n * Reads and stores files for the caller of an action: a workflow run, or the person in a chat.\n *\n * @since 0.1.0\n * @category services\n */\nexport class Service extends Context.Service<\n Service,\n {\n readonly read: (file: File) => Effect.Effect<Uint8Array, FileError>;\n readonly write: (file: {\n bytes: Uint8Array;\n name: string;\n // oxlint-disable-next-line typescript/no-restricted-types -- Hosts and existing callers may explicitly supply an absent content type.\n contentType?: string | null | undefined;\n }) => Effect.Effect<File, FileError>;\n }\n>()(\"@dual-os/sdk/Files/Service\") {}\n\n// Dual provides the service to each action call, so an action declares no requirement for it.\nconst service = pipe(\n Effect.serviceOption(Service),\n Effect.flatMap(\n Effect.fromOption(() =>\n FileError.make({ message: \"Files are only available when Dual calls the action\" }),\n ),\n ),\n);\n\n/**\n * Reads a file's bytes through the caller's file service.\n *\n * @since 0.1.0\n * @category files\n */\nexport const read = Effect.fnUntraced(function* (file: File) {\n return yield* (yield* service).read(file);\n});\n\n/**\n * Stores bytes as a new file of the caller and returns its reference.\n *\n * @since 0.1.0\n * @category files\n */\nexport const write = Effect.fnUntraced(function* (\n file: Parameters<Service[\"Service\"][\"write\"]>[0],\n) {\n return yield* (yield* service).write(file);\n});\n\nexport * as Files from \"./Files.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAeA,MAAa,OAAO,OAAO,aAAa,QAAQ;CAC9C,aAAa,OAAO;CACpB,IAAI,OAAO;CACX,MAAM,OAAO;CACb,WAAW,OAAO;AACpB,CAAC,CAAC,CAAC,SAAS,EACV,aAAa,uEACf,CAAC;;;;;;;;;AAUD,IAAa,YAAb,cAA+B,OAAO,YAAuB,CAAC,CAAC,aAAa;CAC1E,OAAO,OAAO,YAAY,OAAO,SAAS,OAAO,SAAS,EAAE,oBAAoB,KAAK,CAAC,CAAC;CACvF,SAAS,OAAO;AAClB,CAAC,CAAC,CAAC,CAAC;;;;;;;AAQJ,IAAa,UAAb,cAA6B,QAAQ,QAWnC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC;AAGnC,MAAM,UAAU,KACd,OAAO,cAAc,OAAO,GAC5B,OAAO,QACL,OAAO,iBACL,UAAU,KAAK,EAAE,SAAS,sDAAsD,CAAC,CACnF,CACF,CACF;;;;;;;AAQA,MAAa,OAAO,OAAO,WAAW,WAAW,MAAY;CAC3D,OAAO,QAAQ,OAAO,QAAA,CAAS,KAAK,IAAI;AAC1C,CAAC;;;;;;;AAQD,MAAa,QAAQ,OAAO,WAAW,WACrC,MACA;CACA,OAAO,QAAQ,OAAO,QAAA,CAAS,MAAM,IAAI;AAC3C,CAAC"}
|