@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,708 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { validateIdentifier } from "./internal/identifier.js";
|
|
3
|
+
import { PipeableProto } from "./internal/proto.js";
|
|
4
|
+
import { isAuthMethod } from "./AuthMethod.js";
|
|
5
|
+
import { Schema as Schema$1 } from "./ToolFile.js";
|
|
6
|
+
import "./AgentChannel.js";
|
|
7
|
+
import { Match, Predicate, Schema } from "effect";
|
|
8
|
+
//#region src/AgentChannel.ts
|
|
9
|
+
var AgentChannel_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
+
AccessOutcome: () => AccessOutcome,
|
|
11
|
+
AgentChannel: () => AgentChannel_exports,
|
|
12
|
+
Asset: () => Asset,
|
|
13
|
+
AssetFile: () => AssetFile,
|
|
14
|
+
ChannelError: () => ChannelError,
|
|
15
|
+
CheckedResult: () => CheckedResult,
|
|
16
|
+
Content: () => Content,
|
|
17
|
+
ContextMessage: () => ContextMessage,
|
|
18
|
+
Contract: () => Contract,
|
|
19
|
+
DeliveryUpdate: () => DeliveryUpdate,
|
|
20
|
+
Destination: () => Destination,
|
|
21
|
+
Echo: () => Echo,
|
|
22
|
+
ErrorCode: () => ErrorCode,
|
|
23
|
+
Event: () => Event,
|
|
24
|
+
EventV2: () => EventV2,
|
|
25
|
+
Exposure: () => Exposure,
|
|
26
|
+
FailureCode: () => FailureCode,
|
|
27
|
+
Features: () => Features,
|
|
28
|
+
HandlerError: () => HandlerError,
|
|
29
|
+
Key: () => Key,
|
|
30
|
+
Message: () => Message,
|
|
31
|
+
Operation: () => Operation,
|
|
32
|
+
OperationKind: () => OperationKind,
|
|
33
|
+
Plan: () => Plan,
|
|
34
|
+
PlanItem: () => PlanItem,
|
|
35
|
+
Protocol: () => Protocol,
|
|
36
|
+
Reaction: () => Reaction,
|
|
37
|
+
Request: () => Request,
|
|
38
|
+
RequiredChecks: () => RequiredChecks,
|
|
39
|
+
Stop: () => Stop,
|
|
40
|
+
Timestamp: () => Timestamp,
|
|
41
|
+
TypeId: () => TypeId,
|
|
42
|
+
Verification: () => Verification,
|
|
43
|
+
VerifiedIdentity: () => VerifiedIdentity,
|
|
44
|
+
WebhookResponse: () => WebhookResponse,
|
|
45
|
+
commandSchema: () => commandSchema,
|
|
46
|
+
commandSchemaV2: () => commandSchemaV2,
|
|
47
|
+
handlerKey: () => handlerKey,
|
|
48
|
+
isAgentChannel: () => isAgentChannel,
|
|
49
|
+
make: () => make,
|
|
50
|
+
projectContract: () => projectContract,
|
|
51
|
+
resultSchema: () => resultSchema,
|
|
52
|
+
resultSchemaV2: () => resultSchemaV2,
|
|
53
|
+
schemasFor: () => schemasFor,
|
|
54
|
+
validateDefinition: () => validateDefinition
|
|
55
|
+
});
|
|
56
|
+
const TypeId = "@dual-os/sdk/AgentChannel";
|
|
57
|
+
/** Keys are opaque and installation-scoped. Never parse them into product identities. */
|
|
58
|
+
const Key = Schema.NonEmptyString.check(Schema.isMaxLength(512), Schema.isPattern(/^[^\p{Cc}]+$/u));
|
|
59
|
+
/**
|
|
60
|
+
* The command and result schemas a version uses. Absent means the original protocol, whose
|
|
61
|
+
* projection stays byte-identical for contracts already published with it. `v2` adds the stop
|
|
62
|
+
* event, conversation reads and output operations.
|
|
63
|
+
*/
|
|
64
|
+
const Protocol = Schema.Literals(["v2"]);
|
|
65
|
+
/** What a `v2` destination can show. Every channel shows `present_outcome`. */
|
|
66
|
+
const OperationKind = Schema.Literals([
|
|
67
|
+
"present_outcome",
|
|
68
|
+
"create_message",
|
|
69
|
+
"update_message",
|
|
70
|
+
"delete_message",
|
|
71
|
+
"set_reaction",
|
|
72
|
+
"set_activity",
|
|
73
|
+
"render_plan"
|
|
74
|
+
]);
|
|
75
|
+
const Features = Schema.Struct({
|
|
76
|
+
assets: Schema.Boolean,
|
|
77
|
+
/** Whether replaying one durable delivery key is safe at the provider boundary. */
|
|
78
|
+
deliveryMode: Schema.Literals(["idempotent", "at-most-once"]),
|
|
79
|
+
deliveryState: Schema.Boolean,
|
|
80
|
+
directText: Schema.Literal(true),
|
|
81
|
+
groups: Schema.Boolean,
|
|
82
|
+
/** Maximum Unicode code points per physical text message, including server-added prefixes. */
|
|
83
|
+
maxTextLength: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
84
|
+
mentions: Schema.Boolean,
|
|
85
|
+
/** `v2` only: the output operations every destination of this version shows. */
|
|
86
|
+
operations: Schema.optionalKey(Schema.Array(OperationKind)),
|
|
87
|
+
/** `v2` only: whether `read_context` returns the conversation's earlier messages. */
|
|
88
|
+
readContext: Schema.optionalKey(Schema.Boolean),
|
|
89
|
+
replies: Schema.Boolean,
|
|
90
|
+
/** Maximum age of the original responding input before preparation and delivery. */
|
|
91
|
+
responseWindowMs: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
92
|
+
threads: Schema.Boolean
|
|
93
|
+
});
|
|
94
|
+
const HttpUrl = Schema.String.check(Schema.isMaxLength(8192), Schema.makeFilter((value) => {
|
|
95
|
+
const url = URL.parse(value);
|
|
96
|
+
return url !== null && (url.protocol === "https:" || url.protocol === "http:") && url.username === "" && url.password === "";
|
|
97
|
+
}));
|
|
98
|
+
const Text = Schema.String.check(Schema.isMaxLength(65536));
|
|
99
|
+
const ExtensionKey = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*\/[a-z0-9]+(?:-[a-z0-9]+)*$/));
|
|
100
|
+
const Extensions = Schema.Record(Schema.String, Schema.Json).check(Schema.makeFilter((values) => Object.keys(values).every(Schema.is(ExtensionKey))));
|
|
101
|
+
const Destination = Schema.Struct({
|
|
102
|
+
conversationKey: Key,
|
|
103
|
+
kind: Schema.Literals(["direct", "group"]),
|
|
104
|
+
threadKey: Schema.optionalKey(Key)
|
|
105
|
+
});
|
|
106
|
+
const Asset = Schema.Struct({
|
|
107
|
+
assetKey: Key,
|
|
108
|
+
mediaType: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
|
|
109
|
+
url: HttpUrl
|
|
110
|
+
});
|
|
111
|
+
const Content = Schema.Struct({
|
|
112
|
+
assets: Schema.optionalKey(Schema.Array(Asset).check(Schema.isMaxLength(20))),
|
|
113
|
+
mentions: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),
|
|
114
|
+
replyToMessageKey: Schema.optionalKey(Key),
|
|
115
|
+
text: Text
|
|
116
|
+
}).check(Schema.makeFilter((content) => content.text.length > 0 || (content.assets?.length ?? 0) > 0));
|
|
117
|
+
/** The body is the unmodified UTF-8 provider body, before JSON parsing/signature verification. */
|
|
118
|
+
const Request = Schema.Struct({
|
|
119
|
+
body: Schema.String.check(Schema.isMaxLength(1048576), Schema.makeFilter((body) => new TextEncoder().encode(body).byteLength <= 1048576)),
|
|
120
|
+
headers: Schema.Record(Schema.NonEmptyString.check(Schema.isMaxLength(256)), Schema.String.check(Schema.isMaxLength(8192))),
|
|
121
|
+
method: Schema.Literals([
|
|
122
|
+
"GET",
|
|
123
|
+
"POST",
|
|
124
|
+
"PUT",
|
|
125
|
+
"PATCH",
|
|
126
|
+
"DELETE"
|
|
127
|
+
]),
|
|
128
|
+
url: HttpUrl
|
|
129
|
+
});
|
|
130
|
+
const ResponseHeaders = Schema.Record(Schema.NonEmptyString.check(Schema.isMaxLength(256), Schema.isPattern(/^[a-z0-9-]+$/)), Schema.String.check(Schema.isMaxLength(8192))).check(Schema.makeFilter((headers) => Object.keys(headers).every((name) => name === "content-type" || name === "cache-control")));
|
|
131
|
+
/** Bounded provider-required webhook response, returned only after request verification. */
|
|
132
|
+
const WebhookResponse = Schema.Struct({
|
|
133
|
+
body: Schema.String.check(Schema.isMaxLength(65536), Schema.makeFilter((body) => new TextEncoder().encode(body).byteLength <= 65536)),
|
|
134
|
+
headers: Schema.optionalKey(ResponseHeaders),
|
|
135
|
+
status: Schema.Int.check(Schema.isBetween({
|
|
136
|
+
maximum: 299,
|
|
137
|
+
minimum: 200
|
|
138
|
+
}))
|
|
139
|
+
});
|
|
140
|
+
const Timestamp = Schema.String.check(Schema.isMaxLength(64), Schema.isPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/), Schema.makeFilter((value) => {
|
|
141
|
+
const year = Number(value.slice(0, 4));
|
|
142
|
+
const month = Number(value.slice(5, 7));
|
|
143
|
+
const day = Number(value.slice(8, 10));
|
|
144
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
145
|
+
const days = month === 2 ? leap ? 29 : 28 : [
|
|
146
|
+
4,
|
|
147
|
+
6,
|
|
148
|
+
9,
|
|
149
|
+
11
|
|
150
|
+
].includes(month) ? 30 : 31;
|
|
151
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= days && Number(value.slice(11, 13)) < 24 && Number(value.slice(14, 16)) < 60 && Number(value.slice(17, 19)) < 60 && Schema.decodeUnknownExit(Schema.DateTimeUtcFromString)(value)._tag === "Success";
|
|
152
|
+
}));
|
|
153
|
+
const VerifiedIdentity = Schema.Struct({
|
|
154
|
+
conversation: Destination,
|
|
155
|
+
senderKey: Key
|
|
156
|
+
});
|
|
157
|
+
const AccessOutcome = Schema.Struct({ decision: Schema.Literals(["allow", "deny"]) });
|
|
158
|
+
const Verification = Schema.Struct({ verified: Schema.Literal(true) });
|
|
159
|
+
const Exposure = Schema.Literals(["webhook", "host"]);
|
|
160
|
+
const RequiredChecks = Schema.Tuple([Schema.Literal("access")]);
|
|
161
|
+
const Message = Schema.Struct({
|
|
162
|
+
content: Content,
|
|
163
|
+
conversation: Destination,
|
|
164
|
+
eventKey: Key,
|
|
165
|
+
extensions: Schema.optionalKey(Extensions),
|
|
166
|
+
kind: Schema.Literal("message"),
|
|
167
|
+
messageKey: Key,
|
|
168
|
+
respond: Schema.Boolean,
|
|
169
|
+
senderKey: Key,
|
|
170
|
+
timestamp: Timestamp
|
|
171
|
+
});
|
|
172
|
+
const DeliveryUpdate = Schema.Struct({
|
|
173
|
+
deliveryKey: Key,
|
|
174
|
+
deliveryUpdateKey: Key,
|
|
175
|
+
eventKey: Key,
|
|
176
|
+
extensions: Schema.optionalKey(Extensions),
|
|
177
|
+
kind: Schema.Literal("delivery_update"),
|
|
178
|
+
providerDeliveryKey: Key,
|
|
179
|
+
sequence: Schema.Natural,
|
|
180
|
+
status: Schema.Literals(["succeeded", "failed"]),
|
|
181
|
+
timestamp: Timestamp
|
|
182
|
+
});
|
|
183
|
+
/** Provider-confirmed own output. No content is accepted or added to conversation history. */
|
|
184
|
+
const Echo = Schema.Struct({
|
|
185
|
+
...VerifiedIdentity.fields,
|
|
186
|
+
eventKey: Key,
|
|
187
|
+
extensions: Schema.optionalKey(Extensions),
|
|
188
|
+
kind: Schema.Literal("echo"),
|
|
189
|
+
messageKey: Key,
|
|
190
|
+
timestamp: Timestamp
|
|
191
|
+
});
|
|
192
|
+
const Event = Schema.Union([
|
|
193
|
+
Message,
|
|
194
|
+
Echo,
|
|
195
|
+
DeliveryUpdate
|
|
196
|
+
]);
|
|
197
|
+
/** `v2`: the sender asked the agent to stop working in this conversation. Access applies. */
|
|
198
|
+
const Stop = Schema.Struct({
|
|
199
|
+
...VerifiedIdentity.fields,
|
|
200
|
+
eventKey: Key,
|
|
201
|
+
extensions: Schema.optionalKey(Extensions),
|
|
202
|
+
kind: Schema.Literal("stop"),
|
|
203
|
+
timestamp: Timestamp
|
|
204
|
+
});
|
|
205
|
+
const EventV2 = Schema.Union([
|
|
206
|
+
Message,
|
|
207
|
+
Echo,
|
|
208
|
+
DeliveryUpdate,
|
|
209
|
+
Stop
|
|
210
|
+
]);
|
|
211
|
+
/** The reactions every `v2` provider can show. Each provider maps them to its own emoji. */
|
|
212
|
+
const Reaction = Schema.Literals([
|
|
213
|
+
"thumbs_up",
|
|
214
|
+
"thumbs_down",
|
|
215
|
+
"laugh",
|
|
216
|
+
"confused",
|
|
217
|
+
"heart",
|
|
218
|
+
"hooray",
|
|
219
|
+
"rocket",
|
|
220
|
+
"eyes"
|
|
221
|
+
]);
|
|
222
|
+
const ShortText = Schema.NonEmptyString.check(Schema.isMaxLength(200));
|
|
223
|
+
const PlanItem = Schema.Struct({
|
|
224
|
+
itemKey: Key,
|
|
225
|
+
note: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(2e3))),
|
|
226
|
+
state: Schema.Literals([
|
|
227
|
+
"pending",
|
|
228
|
+
"in_progress",
|
|
229
|
+
"completed",
|
|
230
|
+
"failed"
|
|
231
|
+
]),
|
|
232
|
+
title: Schema.NonEmptyString.check(Schema.isMaxLength(256))
|
|
233
|
+
});
|
|
234
|
+
/** A whole task list, always sent complete. Item keys are unique and stable across revisions. */
|
|
235
|
+
const Plan = Schema.Struct({
|
|
236
|
+
items: Schema.Array(PlanItem).check(Schema.isMaxLength(50), Schema.makeFilter((items) => new Set(items.map((item) => item.itemKey)).size === items.length)),
|
|
237
|
+
title: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256)))
|
|
238
|
+
});
|
|
239
|
+
/**
|
|
240
|
+
* One piece of `v2` output. A `reference` is the `providerDeliveryKey` the provider returned for
|
|
241
|
+
* the message or plan it made; only that provider reads it.
|
|
242
|
+
*/
|
|
243
|
+
const Operation = Schema.Union([
|
|
244
|
+
Schema.Struct({
|
|
245
|
+
kind: Schema.Literal("present_outcome"),
|
|
246
|
+
options: Schema.optionalKey(Schema.Array(ShortText).check(Schema.isMaxLength(10))),
|
|
247
|
+
outcome: Schema.Literals([
|
|
248
|
+
"completed",
|
|
249
|
+
"failed",
|
|
250
|
+
"awaiting_input"
|
|
251
|
+
]),
|
|
252
|
+
text: Text
|
|
253
|
+
}).check(Schema.makeFilter((operation) => operation.options === void 0 || operation.outcome === "awaiting_input")),
|
|
254
|
+
Schema.Struct({
|
|
255
|
+
kind: Schema.Literal("create_message"),
|
|
256
|
+
messageKey: Key,
|
|
257
|
+
text: Text.check(Schema.isMinLength(1))
|
|
258
|
+
}),
|
|
259
|
+
Schema.Struct({
|
|
260
|
+
kind: Schema.Literal("update_message"),
|
|
261
|
+
messageKey: Key,
|
|
262
|
+
reference: Key,
|
|
263
|
+
text: Text.check(Schema.isMinLength(1))
|
|
264
|
+
}),
|
|
265
|
+
Schema.Struct({
|
|
266
|
+
kind: Schema.Literal("delete_message"),
|
|
267
|
+
messageKey: Key,
|
|
268
|
+
reference: Key
|
|
269
|
+
}),
|
|
270
|
+
Schema.Struct({
|
|
271
|
+
active: Schema.Boolean,
|
|
272
|
+
kind: Schema.Literal("set_reaction"),
|
|
273
|
+
reaction: Reaction,
|
|
274
|
+
target: Schema.Union([Schema.Struct({ kind: Schema.Literal("activation") }), Schema.Struct({
|
|
275
|
+
kind: Schema.Literal("message"),
|
|
276
|
+
reference: Key
|
|
277
|
+
})])
|
|
278
|
+
}),
|
|
279
|
+
Schema.Struct({
|
|
280
|
+
activity: Schema.Union([Schema.Struct({
|
|
281
|
+
kind: Schema.Literal("working"),
|
|
282
|
+
text: Schema.optionalKey(ShortText)
|
|
283
|
+
}), Schema.Struct({ kind: Schema.Literal("idle") })]),
|
|
284
|
+
kind: Schema.Literal("set_activity")
|
|
285
|
+
}),
|
|
286
|
+
Schema.Struct({
|
|
287
|
+
kind: Schema.Literal("render_plan"),
|
|
288
|
+
plan: Plan,
|
|
289
|
+
reference: Schema.optionalKey(Key),
|
|
290
|
+
revision: Schema.Int.check(Schema.isGreaterThan(0))
|
|
291
|
+
})
|
|
292
|
+
]);
|
|
293
|
+
/** A message read back from the provider's conversation history. */
|
|
294
|
+
const ContextMessage = Schema.Struct({
|
|
295
|
+
messageKey: Key,
|
|
296
|
+
/** The agent's own message. */
|
|
297
|
+
own: Schema.Boolean,
|
|
298
|
+
senderKey: Key,
|
|
299
|
+
senderName: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),
|
|
300
|
+
text: Text,
|
|
301
|
+
timestamp: Timestamp
|
|
302
|
+
});
|
|
303
|
+
/** Decoded originals are limited separately by the host; ordinary command JSON stays bounded. */
|
|
304
|
+
const AssetFile = Schema$1.check(Schema.makeFilter((file) => file.sizeBytes > 0 && file.sizeBytes <= 10485760 && file.contentBase64.length <= 13981016));
|
|
305
|
+
/** Closed error vocabulary: provider messages, payloads, and causes never cross this seam. */
|
|
306
|
+
const FailureCode = Schema.Literals([
|
|
307
|
+
"rejected",
|
|
308
|
+
"unauthorized",
|
|
309
|
+
"rate_limited",
|
|
310
|
+
"unavailable",
|
|
311
|
+
"unknown_completion",
|
|
312
|
+
"window_closed"
|
|
313
|
+
]);
|
|
314
|
+
var HandlerError = class extends Schema.TaggedError()("AgentChannelHandlerError", { code: FailureCode }) {};
|
|
315
|
+
const ErrorCode = Schema.Literals([
|
|
316
|
+
"invalid_definition",
|
|
317
|
+
"not_found",
|
|
318
|
+
"invalid_input",
|
|
319
|
+
"invalid_auth",
|
|
320
|
+
"unsupported_feature",
|
|
321
|
+
"invalid_result",
|
|
322
|
+
"handler_unavailable",
|
|
323
|
+
"provider_failure"
|
|
324
|
+
]);
|
|
325
|
+
var ChannelError = class extends Schema.TaggedError()("AgentChannelError", {
|
|
326
|
+
code: ErrorCode,
|
|
327
|
+
providerCode: Schema.optionalKey(FailureCode)
|
|
328
|
+
}) {
|
|
329
|
+
get message() {
|
|
330
|
+
return `Agent Channel ${this.code}`;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const installedCommandSchema = (state) => {
|
|
334
|
+
const operation = {
|
|
335
|
+
extensions: Schema.optionalKey(Extensions),
|
|
336
|
+
operationKey: Key
|
|
337
|
+
};
|
|
338
|
+
const installed = {
|
|
339
|
+
...operation,
|
|
340
|
+
installationKey: Key,
|
|
341
|
+
state
|
|
342
|
+
};
|
|
343
|
+
return Schema.Union([
|
|
344
|
+
Schema.Struct({
|
|
345
|
+
kind: Schema.Literal("activate"),
|
|
346
|
+
...operation,
|
|
347
|
+
ingressUrl: HttpUrl,
|
|
348
|
+
state: Schema.optionalKey(state)
|
|
349
|
+
}),
|
|
350
|
+
Schema.Struct({
|
|
351
|
+
kind: Schema.Literal("deactivate"),
|
|
352
|
+
...installed
|
|
353
|
+
}),
|
|
354
|
+
Schema.Struct({
|
|
355
|
+
kind: Schema.Literal("receive"),
|
|
356
|
+
...installed,
|
|
357
|
+
request: Request
|
|
358
|
+
}),
|
|
359
|
+
Schema.Struct({
|
|
360
|
+
kind: Schema.Literal("deliver"),
|
|
361
|
+
...installed,
|
|
362
|
+
deliveryKey: Key,
|
|
363
|
+
destination: Destination,
|
|
364
|
+
content: Content,
|
|
365
|
+
/** Original responding input timestamp; retries must preserve this reference. */
|
|
366
|
+
responseToTimestamp: Schema.optionalKey(Timestamp)
|
|
367
|
+
})
|
|
368
|
+
]);
|
|
369
|
+
};
|
|
370
|
+
const installedCommandSchemaV2 = (state) => {
|
|
371
|
+
const operation = {
|
|
372
|
+
extensions: Schema.optionalKey(Extensions),
|
|
373
|
+
operationKey: Key
|
|
374
|
+
};
|
|
375
|
+
const installed = {
|
|
376
|
+
...operation,
|
|
377
|
+
installationKey: Key,
|
|
378
|
+
state
|
|
379
|
+
};
|
|
380
|
+
return Schema.Union([
|
|
381
|
+
Schema.Struct({
|
|
382
|
+
kind: Schema.Literal("activate"),
|
|
383
|
+
...operation,
|
|
384
|
+
ingressUrl: HttpUrl,
|
|
385
|
+
state: Schema.optionalKey(state)
|
|
386
|
+
}),
|
|
387
|
+
Schema.Struct({
|
|
388
|
+
kind: Schema.Literal("deactivate"),
|
|
389
|
+
...installed
|
|
390
|
+
}),
|
|
391
|
+
Schema.Struct({
|
|
392
|
+
kind: Schema.Literal("receive"),
|
|
393
|
+
...installed,
|
|
394
|
+
request: Request
|
|
395
|
+
}),
|
|
396
|
+
Schema.Struct({
|
|
397
|
+
kind: Schema.Literal("deliver"),
|
|
398
|
+
...installed,
|
|
399
|
+
/** The provider message that started the turn, when the host knows it. */
|
|
400
|
+
activationMessageKey: Schema.optionalKey(Key),
|
|
401
|
+
deliveryKey: Key,
|
|
402
|
+
destination: Destination,
|
|
403
|
+
operation: Operation,
|
|
404
|
+
/** Original responding input timestamp; retries must preserve this reference. */
|
|
405
|
+
responseToTimestamp: Schema.optionalKey(Timestamp)
|
|
406
|
+
}),
|
|
407
|
+
Schema.Struct({
|
|
408
|
+
kind: Schema.Literal("read_context"),
|
|
409
|
+
...installed,
|
|
410
|
+
destination: Destination,
|
|
411
|
+
limit: Schema.Int.check(Schema.isBetween({
|
|
412
|
+
maximum: 200,
|
|
413
|
+
minimum: 1
|
|
414
|
+
}))
|
|
415
|
+
})
|
|
416
|
+
]);
|
|
417
|
+
};
|
|
418
|
+
const installedResultSchema = (state) => {
|
|
419
|
+
const operation = {
|
|
420
|
+
extensions: Schema.optionalKey(Extensions),
|
|
421
|
+
operationKey: Key
|
|
422
|
+
};
|
|
423
|
+
return Schema.Union([
|
|
424
|
+
Schema.Struct({
|
|
425
|
+
kind: Schema.Literal("activate"),
|
|
426
|
+
...operation,
|
|
427
|
+
installationKey: Key,
|
|
428
|
+
state,
|
|
429
|
+
/** Durable read-only provider state that the host must persist before retrying activation. */
|
|
430
|
+
checkpoint: Schema.optionalKey(Schema.Literal(true)),
|
|
431
|
+
/** The host must observe a verified webhook handshake before cutover. */
|
|
432
|
+
verification: Schema.optionalKey(Schema.Literal("ingress"))
|
|
433
|
+
}),
|
|
434
|
+
Schema.Struct({
|
|
435
|
+
kind: Schema.Literal("deactivate"),
|
|
436
|
+
...operation
|
|
437
|
+
}),
|
|
438
|
+
Schema.Struct({
|
|
439
|
+
kind: Schema.Literal("receive"),
|
|
440
|
+
...operation,
|
|
441
|
+
verified: Schema.Literal(true),
|
|
442
|
+
deniedEventKeys: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),
|
|
443
|
+
events: Schema.Array(Event).check(Schema.isMaxLength(100)),
|
|
444
|
+
response: Schema.optionalKey(WebhookResponse),
|
|
445
|
+
/** A provider-native setup challenge or ping proved the configured ingress. */
|
|
446
|
+
activationProof: Schema.optionalKey(Schema.Literal("verified"))
|
|
447
|
+
}),
|
|
448
|
+
Schema.Struct({
|
|
449
|
+
kind: Schema.Literal("deliver"),
|
|
450
|
+
...operation,
|
|
451
|
+
deliveryKey: Key,
|
|
452
|
+
status: Schema.Literal("succeeded"),
|
|
453
|
+
providerDeliveryKey: Key
|
|
454
|
+
}),
|
|
455
|
+
Schema.Struct({
|
|
456
|
+
kind: Schema.Literal("deliver"),
|
|
457
|
+
...operation,
|
|
458
|
+
deliveryKey: Key,
|
|
459
|
+
status: Schema.Literal("pending"),
|
|
460
|
+
providerDeliveryKey: Key
|
|
461
|
+
}),
|
|
462
|
+
Schema.Struct({
|
|
463
|
+
kind: Schema.Literal("deliver"),
|
|
464
|
+
...operation,
|
|
465
|
+
deliveryKey: Key,
|
|
466
|
+
status: Schema.Literal("failed"),
|
|
467
|
+
code: Schema.Literals([
|
|
468
|
+
"rejected",
|
|
469
|
+
"unauthorized",
|
|
470
|
+
"rate_limited",
|
|
471
|
+
"unavailable",
|
|
472
|
+
"window_closed"
|
|
473
|
+
])
|
|
474
|
+
})
|
|
475
|
+
]);
|
|
476
|
+
};
|
|
477
|
+
const installedResultSchemaV2 = (state) => {
|
|
478
|
+
const operation = {
|
|
479
|
+
extensions: Schema.optionalKey(Extensions),
|
|
480
|
+
operationKey: Key
|
|
481
|
+
};
|
|
482
|
+
return Schema.Union([
|
|
483
|
+
Schema.Struct({
|
|
484
|
+
kind: Schema.Literal("activate"),
|
|
485
|
+
...operation,
|
|
486
|
+
installationKey: Key,
|
|
487
|
+
state,
|
|
488
|
+
/** Durable read-only provider state that the host must persist before retrying activation. */
|
|
489
|
+
checkpoint: Schema.optionalKey(Schema.Literal(true)),
|
|
490
|
+
/** The host must observe a verified webhook handshake before cutover. */
|
|
491
|
+
verification: Schema.optionalKey(Schema.Literal("ingress"))
|
|
492
|
+
}),
|
|
493
|
+
Schema.Struct({
|
|
494
|
+
kind: Schema.Literal("deactivate"),
|
|
495
|
+
...operation
|
|
496
|
+
}),
|
|
497
|
+
Schema.Struct({
|
|
498
|
+
kind: Schema.Literal("receive"),
|
|
499
|
+
...operation,
|
|
500
|
+
verified: Schema.Literal(true),
|
|
501
|
+
deniedEventKeys: Schema.optionalKey(Schema.Array(Key).check(Schema.isMaxLength(100))),
|
|
502
|
+
events: Schema.Array(EventV2).check(Schema.isMaxLength(100)),
|
|
503
|
+
response: Schema.optionalKey(WebhookResponse),
|
|
504
|
+
/** A provider-native setup challenge or ping proved the configured ingress. */
|
|
505
|
+
activationProof: Schema.optionalKey(Schema.Literal("verified"))
|
|
506
|
+
}),
|
|
507
|
+
Schema.Struct({
|
|
508
|
+
kind: Schema.Literal("deliver"),
|
|
509
|
+
...operation,
|
|
510
|
+
deliveryKey: Key,
|
|
511
|
+
status: Schema.Literal("succeeded"),
|
|
512
|
+
providerDeliveryKey: Key
|
|
513
|
+
}),
|
|
514
|
+
Schema.Struct({
|
|
515
|
+
kind: Schema.Literal("deliver"),
|
|
516
|
+
...operation,
|
|
517
|
+
deliveryKey: Key,
|
|
518
|
+
status: Schema.Literal("pending"),
|
|
519
|
+
providerDeliveryKey: Key
|
|
520
|
+
}),
|
|
521
|
+
Schema.Struct({
|
|
522
|
+
kind: Schema.Literal("deliver"),
|
|
523
|
+
...operation,
|
|
524
|
+
deliveryKey: Key,
|
|
525
|
+
status: Schema.Literal("failed"),
|
|
526
|
+
code: Schema.Literals([
|
|
527
|
+
"rejected",
|
|
528
|
+
"unauthorized",
|
|
529
|
+
"rate_limited",
|
|
530
|
+
"unavailable",
|
|
531
|
+
"window_closed"
|
|
532
|
+
])
|
|
533
|
+
}),
|
|
534
|
+
Schema.Struct({
|
|
535
|
+
kind: Schema.Literal("read_context"),
|
|
536
|
+
...operation,
|
|
537
|
+
messages: Schema.Array(ContextMessage).check(Schema.isMaxLength(200))
|
|
538
|
+
})
|
|
539
|
+
]);
|
|
540
|
+
};
|
|
541
|
+
const readAssetCommand = (state) => Schema.Struct({
|
|
542
|
+
asset: Asset,
|
|
543
|
+
extensions: Schema.optionalKey(Extensions),
|
|
544
|
+
identity: VerifiedIdentity,
|
|
545
|
+
installationKey: Key,
|
|
546
|
+
kind: Schema.Literal("read_asset"),
|
|
547
|
+
operationKey: Key,
|
|
548
|
+
state
|
|
549
|
+
});
|
|
550
|
+
const readAssetResult = Schema.Struct({
|
|
551
|
+
assetKey: Key,
|
|
552
|
+
extensions: Schema.optionalKey(Extensions),
|
|
553
|
+
file: AssetFile,
|
|
554
|
+
kind: Schema.Literal("read_asset"),
|
|
555
|
+
operationKey: Key
|
|
556
|
+
});
|
|
557
|
+
const commandSchema = (state) => Schema.Union([installedCommandSchema(state), readAssetCommand(state)]);
|
|
558
|
+
const resultSchema = (state) => Schema.Union([installedResultSchema(state), readAssetResult]);
|
|
559
|
+
const commandSchemaV2 = (state) => Schema.Union([installedCommandSchemaV2(state), readAssetCommand(state)]);
|
|
560
|
+
const resultSchemaV2 = (state) => Schema.Union([installedResultSchemaV2(state), readAssetResult]);
|
|
561
|
+
/** The command and result schemas of a Channel's protocol. */
|
|
562
|
+
const schemasFor = (definition) => definition.protocol === "v2" ? {
|
|
563
|
+
command: commandSchemaV2(definition.state),
|
|
564
|
+
result: resultSchemaV2(definition.state),
|
|
565
|
+
typeResult: resultSchemaV2(Schema.toType(definition.state))
|
|
566
|
+
} : {
|
|
567
|
+
command: commandSchema(definition.state),
|
|
568
|
+
result: resultSchema(definition.state),
|
|
569
|
+
typeResult: resultSchema(Schema.toType(definition.state))
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* Encoded, JSON-safe runtime result suitable for host persistence. It accepts both protocols;
|
|
573
|
+
* a `v1` result decodes unchanged.
|
|
574
|
+
*/
|
|
575
|
+
const CheckedResult = resultSchemaV2(Schema.Json);
|
|
576
|
+
/** Immutable catalog projection. Live schemas remain the execution validators. */
|
|
577
|
+
const Contract = Schema.Struct({
|
|
578
|
+
definitionSettingsSchemaJson: Schema.Json,
|
|
579
|
+
deploymentSettingsSchemaJson: Schema.Json,
|
|
580
|
+
exposure: Exposure,
|
|
581
|
+
extensionsSchemaJson: Schema.Record(Schema.String, Schema.Json),
|
|
582
|
+
featuresJson: Features,
|
|
583
|
+
operationInputSchemaJson: Schema.Json,
|
|
584
|
+
operationOutputSchemaJson: Schema.Json,
|
|
585
|
+
protocol: Schema.optionalKey(Protocol),
|
|
586
|
+
requiredChecks: RequiredChecks,
|
|
587
|
+
stateSchemaJson: Schema.Json
|
|
588
|
+
});
|
|
589
|
+
/** Project the exact declaration once for SDK discovery and server contract comparison. */
|
|
590
|
+
const projectContract = (definition, project = (schema) => Schema.toJsonSchemaDocument(schema, { onExcessProperty: "error" })) => {
|
|
591
|
+
const schemas = schemasFor(definition);
|
|
592
|
+
return Schema.decodeUnknownSync(Contract)({
|
|
593
|
+
definitionSettingsSchemaJson: project(definition.definitionSettings),
|
|
594
|
+
deploymentSettingsSchemaJson: project(definition.deploymentSettings),
|
|
595
|
+
exposure: definition.exposure,
|
|
596
|
+
extensionsSchemaJson: Object.fromEntries(Object.entries(definition.extensions ?? {}).map(([key, schema]) => [key, project(schema)])),
|
|
597
|
+
featuresJson: definition.features,
|
|
598
|
+
operationInputSchemaJson: project(schemas.command),
|
|
599
|
+
operationOutputSchemaJson: project(schemas.result),
|
|
600
|
+
...definition.protocol === void 0 ? {} : { protocol: definition.protocol },
|
|
601
|
+
requiredChecks: definition.requiredChecks,
|
|
602
|
+
stateSchemaJson: project(definition.state)
|
|
603
|
+
}, { onExcessProperty: "error" });
|
|
604
|
+
};
|
|
605
|
+
const handlerKey = (channelId) => `@dual-os/sdk/AgentChannel/Handler/${channelId}`;
|
|
606
|
+
const SchemaDefinition = Schema.declare(Schema.isSchema);
|
|
607
|
+
const checkSchema = (schema, allowOpaque = false) => {
|
|
608
|
+
const seen = /* @__PURE__ */ new Set();
|
|
609
|
+
const visit = (ast) => {
|
|
610
|
+
if (seen.has(ast)) return;
|
|
611
|
+
seen.add(ast);
|
|
612
|
+
if (ast.annotations?.["parseOptions"] !== void 0 || (ast.checks?.some((check) => check.annotations?.["parseOptions"] !== void 0) ?? false)) throw new ChannelError({ code: "invalid_definition" });
|
|
613
|
+
ast.encoding?.forEach((link) => {
|
|
614
|
+
visit(link.to);
|
|
615
|
+
});
|
|
616
|
+
Match.value(ast).pipe(Match.tag("Unknown", "Any", "ObjectKeyword", () => {
|
|
617
|
+
throw new ChannelError({ code: "invalid_definition" });
|
|
618
|
+
}), Match.tag("Declaration", (declaration) => {
|
|
619
|
+
if (!allowOpaque) throw new ChannelError({ code: "invalid_definition" });
|
|
620
|
+
declaration.typeParameters.forEach(visit);
|
|
621
|
+
}), Match.tag("Objects", (objects) => {
|
|
622
|
+
objects.propertySignatures.forEach((property) => visit(property.type));
|
|
623
|
+
objects.indexSignatures.forEach((index) => {
|
|
624
|
+
if (index.parameter._tag !== "String" || index.parameter.checks !== void 0 || index.parameter.encoding !== void 0) throw new ChannelError({ code: "invalid_definition" });
|
|
625
|
+
visit(index.parameter);
|
|
626
|
+
visit(index.type);
|
|
627
|
+
});
|
|
628
|
+
}), Match.tag("Arrays", (arrays) => {
|
|
629
|
+
arrays.elements.forEach(visit);
|
|
630
|
+
arrays.rest.forEach(visit);
|
|
631
|
+
}), Match.tag("Union", (union) => {
|
|
632
|
+
union.types.forEach(visit);
|
|
633
|
+
}), Match.tag("Suspend", (suspend) => {
|
|
634
|
+
visit(suspend.thunk());
|
|
635
|
+
}), Match.orElse(() => void 0));
|
|
636
|
+
};
|
|
637
|
+
visit(schema.ast);
|
|
638
|
+
};
|
|
639
|
+
const DefinitionSchema = Schema.Struct({
|
|
640
|
+
authMethods: Schema.Array(Schema.declare(isAuthMethod)),
|
|
641
|
+
definitionSettings: SchemaDefinition,
|
|
642
|
+
deploymentSettings: SchemaDefinition,
|
|
643
|
+
exposure: Exposure,
|
|
644
|
+
extensions: Schema.optionalKey(Schema.Record(Schema.String, SchemaDefinition).check(Schema.makeFilter((values) => Object.keys(values).every(Schema.is(ExtensionKey))))),
|
|
645
|
+
features: Features,
|
|
646
|
+
protocol: Schema.optionalKey(Protocol),
|
|
647
|
+
requiredChecks: RequiredChecks,
|
|
648
|
+
state: SchemaDefinition
|
|
649
|
+
}).check(Schema.makeFilter(({ features, protocol }) => {
|
|
650
|
+
if (protocol === void 0) return features.operations === void 0 && features.readContext === void 0;
|
|
651
|
+
const operations = features.operations ?? [];
|
|
652
|
+
return operations.includes("present_outcome") && new Set(operations).size === operations.length && (features.maxTextLength === void 0 || operations.includes("create_message"));
|
|
653
|
+
}));
|
|
654
|
+
/** Validate declarations at registration as well as at builder time. */
|
|
655
|
+
const validateDefinition = (definition, providerId, methods) => {
|
|
656
|
+
try {
|
|
657
|
+
Schema.decodeUnknownSync(DefinitionSchema)(definition, { onExcessProperty: "error" });
|
|
658
|
+
for (const schema of [
|
|
659
|
+
definition.definitionSettings,
|
|
660
|
+
definition.deploymentSettings,
|
|
661
|
+
definition.state,
|
|
662
|
+
...Object.values(definition.extensions ?? {})
|
|
663
|
+
]) {
|
|
664
|
+
checkSchema(schema);
|
|
665
|
+
Schema.toJsonSchemaDocument(schema);
|
|
666
|
+
}
|
|
667
|
+
const seen = /* @__PURE__ */ new Set();
|
|
668
|
+
for (const method of definition.authMethods) {
|
|
669
|
+
if (seen.has(method.identifier) || methods !== void 0 && !methods.includes(method)) throw new ChannelError({ code: "invalid_definition" });
|
|
670
|
+
seen.add(method.identifier);
|
|
671
|
+
Schema.decodeUnknownSync(SchemaDefinition)(method.material);
|
|
672
|
+
Schema.decodeUnknownSync(SchemaDefinition)(method.value);
|
|
673
|
+
for (const schema of [
|
|
674
|
+
method.material,
|
|
675
|
+
method.value,
|
|
676
|
+
...method.setup === void 0 ? [] : [method.setup]
|
|
677
|
+
]) checkSchema(schema, true);
|
|
678
|
+
}
|
|
679
|
+
if (providerId !== void 0 && Object.keys(definition.extensions ?? {}).some((key) => !key.startsWith(`${providerId}/`))) throw new ChannelError({ code: "invalid_definition" });
|
|
680
|
+
} catch {
|
|
681
|
+
throw new ChannelError({ code: "invalid_definition" });
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
/** Create a Channel from its contract. */
|
|
685
|
+
const make = (identifier, options) => {
|
|
686
|
+
validateIdentifier("agent-channel", identifier);
|
|
687
|
+
const { description, name, ...definition } = options;
|
|
688
|
+
validateDefinition(definition);
|
|
689
|
+
return {
|
|
690
|
+
...PipeableProto,
|
|
691
|
+
[TypeId]: TypeId,
|
|
692
|
+
definition: Object.freeze({
|
|
693
|
+
...definition,
|
|
694
|
+
authMethods: Object.freeze([...definition.authMethods]),
|
|
695
|
+
features: Object.freeze({ ...definition.features }),
|
|
696
|
+
requiredChecks: Object.freeze([...definition.requiredChecks]),
|
|
697
|
+
...definition.extensions === void 0 ? {} : { extensions: Object.freeze({ ...definition.extensions }) }
|
|
698
|
+
}),
|
|
699
|
+
description,
|
|
700
|
+
identifier,
|
|
701
|
+
name
|
|
702
|
+
};
|
|
703
|
+
};
|
|
704
|
+
const isAgentChannel = (value) => Predicate.hasProperty(value, TypeId);
|
|
705
|
+
//#endregion
|
|
706
|
+
export { AccessOutcome, AgentChannel_exports as AgentChannel, AgentChannel_exports, Asset, AssetFile, ChannelError, CheckedResult, Content, ContextMessage, Contract, DeliveryUpdate, Destination, Echo, ErrorCode, Event, EventV2, Exposure, FailureCode, Features, HandlerError, Key, Message, Operation, OperationKind, Plan, PlanItem, Protocol, Reaction, Request, RequiredChecks, Stop, Timestamp, TypeId, Verification, VerifiedIdentity, WebhookResponse, commandSchema, commandSchemaV2, handlerKey, isAgentChannel, make, projectContract, resultSchema, resultSchemaV2, schemasFor, validateDefinition };
|
|
707
|
+
|
|
708
|
+
//# sourceMappingURL=AgentChannel.js.map
|