@dual-os/sdk 0.0.0-stage → 0.8.0-next.1

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