@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.
Files changed (214) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +19 -2
  3. package/dist/Action.d.ts +201 -0
  4. package/dist/Action.d.ts.map +1 -0
  5. package/dist/Action.js +172 -0
  6. package/dist/Action.js.map +1 -0
  7. package/dist/AgentChannel.d.ts +1717 -0
  8. package/dist/AgentChannel.d.ts.map +1 -0
  9. package/dist/AgentChannel.js +708 -0
  10. package/dist/AgentChannel.js.map +1 -0
  11. package/dist/AgentChannelConformance.d.ts +1543 -0
  12. package/dist/AgentChannelConformance.d.ts.map +1 -0
  13. package/dist/AgentChannelConformance.js +163 -0
  14. package/dist/AgentChannelConformance.js.map +1 -0
  15. package/dist/AgentChannelRuntime.d.ts +78 -0
  16. package/dist/AgentChannelRuntime.d.ts.map +1 -0
  17. package/dist/AgentChannelRuntime.js +270 -0
  18. package/dist/AgentChannelRuntime.js.map +1 -0
  19. package/dist/AiProvider.d.ts +132 -0
  20. package/dist/AiProvider.d.ts.map +1 -0
  21. package/dist/AiProvider.js +100 -0
  22. package/dist/AiProvider.js.map +1 -0
  23. package/dist/AuthMethod.d.ts +381 -0
  24. package/dist/AuthMethod.d.ts.map +1 -0
  25. package/dist/AuthMethod.js +225 -0
  26. package/dist/AuthMethod.js.map +1 -0
  27. package/dist/AuthMethodBinding.d.ts +77 -0
  28. package/dist/AuthMethodBinding.d.ts.map +1 -0
  29. package/dist/AuthMethodBinding.js +31 -0
  30. package/dist/AuthMethodBinding.js.map +1 -0
  31. package/dist/AuthMethodExecution.d.ts +223 -0
  32. package/dist/AuthMethodExecution.d.ts.map +1 -0
  33. package/dist/AuthMethodExecution.js +277 -0
  34. package/dist/AuthMethodExecution.js.map +1 -0
  35. package/dist/ConnectionResolver.d.ts +219 -0
  36. package/dist/ConnectionResolver.d.ts.map +1 -0
  37. package/dist/ConnectionResolver.js +153 -0
  38. package/dist/ConnectionResolver.js.map +1 -0
  39. package/dist/DefinitionError.d.ts +67 -0
  40. package/dist/DefinitionError.d.ts.map +1 -0
  41. package/dist/DefinitionError.js +82 -0
  42. package/dist/DefinitionError.js.map +1 -0
  43. package/dist/DualRegistry.d.ts +71 -0
  44. package/dist/DualRegistry.d.ts.map +1 -0
  45. package/dist/DualRegistry.js +96 -0
  46. package/dist/DualRegistry.js.map +1 -0
  47. package/dist/DualRuntime.d.ts +279 -0
  48. package/dist/DualRuntime.d.ts.map +1 -0
  49. package/dist/DualRuntime.js +311 -0
  50. package/dist/DualRuntime.js.map +1 -0
  51. package/dist/Files.d.ts +80 -0
  52. package/dist/Files.d.ts.map +1 -0
  53. package/dist/Files.js +66 -0
  54. package/dist/Files.js.map +1 -0
  55. package/dist/Group.d.ts +106 -0
  56. package/dist/Group.d.ts.map +1 -0
  57. package/dist/Group.js +86 -0
  58. package/dist/Group.js.map +1 -0
  59. package/dist/Http.d.ts +342 -0
  60. package/dist/Http.d.ts.map +1 -0
  61. package/dist/Http.js +677 -0
  62. package/dist/Http.js.map +1 -0
  63. package/dist/Mcp.d.ts +109 -0
  64. package/dist/Mcp.d.ts.map +1 -0
  65. package/dist/Mcp.js +176 -0
  66. package/dist/Mcp.js.map +1 -0
  67. package/dist/OAuth2TokenRefresher.d.ts +18 -0
  68. package/dist/OAuth2TokenRefresher.d.ts.map +1 -0
  69. package/dist/OAuth2TokenRefresher.js +19 -0
  70. package/dist/OAuth2TokenRefresher.js.map +1 -0
  71. package/dist/OAuthFlow.d.ts +71 -0
  72. package/dist/OAuthFlow.d.ts.map +1 -0
  73. package/dist/OAuthFlow.js +488 -0
  74. package/dist/OAuthFlow.js.map +1 -0
  75. package/dist/Plugin.d.ts +383 -0
  76. package/dist/Plugin.d.ts.map +1 -0
  77. package/dist/Plugin.js +249 -0
  78. package/dist/Plugin.js.map +1 -0
  79. package/dist/PluginRuntime.d.ts +3186 -0
  80. package/dist/PluginRuntime.d.ts.map +1 -0
  81. package/dist/PluginRuntime.js +331 -0
  82. package/dist/PluginRuntime.js.map +1 -0
  83. package/dist/Runner.d.ts +1 -0
  84. package/dist/Runner.js +124 -0
  85. package/dist/Runner.js.map +1 -0
  86. package/dist/ToolFile.d.ts +23 -0
  87. package/dist/ToolFile.d.ts.map +1 -0
  88. package/dist/ToolFile.js +33 -0
  89. package/dist/ToolFile.js.map +1 -0
  90. package/dist/Trigger.d.ts +358 -0
  91. package/dist/Trigger.d.ts.map +1 -0
  92. package/dist/Trigger.js +287 -0
  93. package/dist/Trigger.js.map +1 -0
  94. package/dist/_virtual/_rolldown/runtime.js +13 -0
  95. package/dist/index.d.ts +24 -0
  96. package/dist/index.js +24 -0
  97. package/dist/internal/auth-context.d.ts +23 -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 +27 -0
  101. package/dist/internal/auth-execution.d.ts.map +1 -0
  102. package/dist/internal/auth-execution.js +66 -0
  103. package/dist/internal/auth-execution.js.map +1 -0
  104. package/dist/internal/auth-runtime.d.ts +5 -0
  105. package/dist/internal/auth-runtime.d.ts.map +1 -0
  106. package/dist/internal/auth-runtime.js +16 -0
  107. package/dist/internal/auth-runtime.js.map +1 -0
  108. package/dist/internal/capabilities.d.ts +24 -0
  109. package/dist/internal/capabilities.d.ts.map +1 -0
  110. package/dist/internal/capabilities.js +22 -0
  111. package/dist/internal/capabilities.js.map +1 -0
  112. package/dist/internal/children.d.ts +34 -0
  113. package/dist/internal/children.d.ts.map +1 -0
  114. package/dist/internal/children.js +53 -0
  115. package/dist/internal/children.js.map +1 -0
  116. package/dist/internal/collection-utils.d.ts +4 -0
  117. package/dist/internal/collection-utils.d.ts.map +1 -0
  118. package/dist/internal/collection-utils.js +6 -0
  119. package/dist/internal/collection-utils.js.map +1 -0
  120. package/dist/internal/dual/actions.d.ts +33 -0
  121. package/dist/internal/dual/actions.d.ts.map +1 -0
  122. package/dist/internal/dual/actions.js +26 -0
  123. package/dist/internal/dual/actions.js.map +1 -0
  124. package/dist/internal/dual/invoke.d.ts +63 -0
  125. package/dist/internal/dual/invoke.d.ts.map +1 -0
  126. package/dist/internal/dual/invoke.js +75 -0
  127. package/dist/internal/dual/invoke.js.map +1 -0
  128. package/dist/internal/dual/registry.d.ts +125 -0
  129. package/dist/internal/dual/registry.d.ts.map +1 -0
  130. package/dist/internal/dual/registry.js +172 -0
  131. package/dist/internal/dual/registry.js.map +1 -0
  132. package/dist/internal/dual/triggers.d.ts +29 -0
  133. package/dist/internal/dual/triggers.d.ts.map +1 -0
  134. package/dist/internal/dual/triggers.js +26 -0
  135. package/dist/internal/dual/triggers.js.map +1 -0
  136. package/dist/internal/handler-context.d.ts +9 -0
  137. package/dist/internal/handler-context.d.ts.map +1 -0
  138. package/dist/internal/handler-context.js +31 -0
  139. package/dist/internal/handler-context.js.map +1 -0
  140. package/dist/internal/identifier.d.ts +6 -0
  141. package/dist/internal/identifier.d.ts.map +1 -0
  142. package/dist/internal/identifier.js +28 -0
  143. package/dist/internal/identifier.js.map +1 -0
  144. package/dist/internal/plugin-handlers.d.ts +38 -0
  145. package/dist/internal/plugin-handlers.d.ts.map +1 -0
  146. package/dist/internal/plugin-handlers.js +52 -0
  147. package/dist/internal/plugin-handlers.js.map +1 -0
  148. package/dist/internal/proto.d.ts +7 -0
  149. package/dist/internal/proto.d.ts.map +1 -0
  150. package/dist/internal/proto.js +10 -0
  151. package/dist/internal/proto.js.map +1 -0
  152. package/dist/internal/schema-runtime.d.ts +6 -0
  153. package/dist/internal/schema-runtime.d.ts.map +1 -0
  154. package/dist/internal/schema-runtime.js +10 -0
  155. package/dist/internal/schema-runtime.js.map +1 -0
  156. package/dist/internal/trigger-runtime-shared.d.ts +41 -0
  157. package/dist/internal/trigger-runtime-shared.d.ts.map +1 -0
  158. package/dist/internal/trigger-runtime-shared.js +132 -0
  159. package/dist/internal/trigger-runtime-shared.js.map +1 -0
  160. package/dist/internal/trigger-runtime.d.ts +12 -0
  161. package/dist/internal/trigger-runtime.d.ts.map +1 -0
  162. package/dist/internal/trigger-runtime.js +95 -0
  163. package/dist/internal/trigger-runtime.js.map +1 -0
  164. package/dist/internal/types.d.ts +7 -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 +585 -0
  168. package/dist/remote-runtime.d.ts.map +1 -0
  169. package/dist/remote-runtime.js +367 -0
  170. package/dist/remote-runtime.js.map +1 -0
  171. package/package.json +55 -4
  172. package/src/Action.ts +370 -0
  173. package/src/AgentChannel.ts +860 -0
  174. package/src/AgentChannelConformance.ts +124 -0
  175. package/src/AgentChannelRuntime.ts +616 -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 +1205 -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 +248 -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 @@
1
+ {"version":3,"file":"AgentChannelConformance.d.ts","names":["AgentChannel.ChannelError","DualRuntime.Service"],"sources":["../src/AgentChannelConformance.ts"],"mappings":";;;;;;;qBAWa,SAAO,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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from "./AgentChannel.js";
3
+ import { Service } from "./DualRuntime.js";
4
+ import "./AgentChannelConformance.js";
5
+ import { Effect, Schema } from "effect";
6
+ //#region src/AgentChannelConformance.ts
7
+ /** Public replay conformance suite for channel plugins, runnable with @effect/vitest. */
8
+ var AgentChannelConformance_exports = /* @__PURE__ */ __exportAll({
9
+ AgentChannelConformance: () => AgentChannelConformance_exports,
10
+ ConformanceError: () => ConformanceError,
11
+ Fixture: () => Fixture,
12
+ run: () => run
13
+ });
14
+ const Command = Schema.Union([commandSchema(Schema.Json), commandSchemaV2(Schema.Json)]);
15
+ const Fixture = Schema.Struct({
16
+ activate: Command,
17
+ channelId: Key,
18
+ connectionId: Schema.optionalKey(Key),
19
+ deactivate: Command,
20
+ definitionSettings: Schema.Json,
21
+ deliver: Command,
22
+ deploymentSettings: Schema.Json,
23
+ receive: Command
24
+ });
25
+ var ConformanceError = class extends Schema.TaggedError()("AgentChannelConformanceError", {
26
+ command: Schema.Literals([
27
+ "activate",
28
+ "deactivate",
29
+ "receive",
30
+ "deliver"
31
+ ]),
32
+ rule: Schema.Literals([
33
+ "command_kind",
34
+ "stable_result",
35
+ "stable_events",
36
+ "boundary_rejection"
37
+ ])
38
+ }) {};
39
+ /**
40
+ * Replays operations that providers declare safe to replay. At-most-once delivery executes once;
41
+ * the durable host owns its replay prohibition. Use an isolated provider test installation: this
42
+ * suite performs provider effects. The host supplies stable keys; the plugin must recover the same
43
+ * external subscription and emit the same provider event keys, even for a fresh receipt key.
44
+ * Boundary rejection and feature/auth matrices are covered by the SDK's public runtime tests.
45
+ */
46
+ const run = Effect.fn("AgentChannelConformance.run")(function* (input) {
47
+ const fixture = yield* Schema.decodeUnknownEffect(Fixture)(input, { onExcessProperty: "error" });
48
+ const runtime = yield* Service;
49
+ const definition = yield* runtime.getAgentChannel({ channelId: fixture.channelId });
50
+ const { activate, receive, deliver, deactivate, ...config } = fixture;
51
+ const { connectionId: _connectionId, ...withoutConnection } = config;
52
+ const probes = [
53
+ {
54
+ code: "invalid_input",
55
+ input: {
56
+ ...config,
57
+ channelId: "",
58
+ command: activate
59
+ }
60
+ },
61
+ {
62
+ input: {
63
+ ...config,
64
+ channelId: "conformance/missing/channel",
65
+ command: activate
66
+ },
67
+ code: "not_found"
68
+ },
69
+ {
70
+ code: "invalid_input",
71
+ input: {
72
+ ...config,
73
+ command: {
74
+ ...activate,
75
+ operationKey: ""
76
+ }
77
+ }
78
+ },
79
+ {
80
+ code: "invalid_input",
81
+ input: {
82
+ ...config,
83
+ agent: { id: "synthetic-authority" },
84
+ command: activate
85
+ }
86
+ },
87
+ {
88
+ code: "invalid_auth",
89
+ input: definition.authMethods.length === 0 ? {
90
+ ...config,
91
+ command: activate,
92
+ connectionId: "unexpected"
93
+ } : {
94
+ ...withoutConnection,
95
+ command: activate
96
+ }
97
+ }
98
+ ];
99
+ for (const probe of probes) {
100
+ const outcome = yield* Effect.suspend(() => runtime.executeAgentChannel(probe.input)).pipe(Effect.result);
101
+ if (outcome._tag !== "Failure" || outcome.failure.code !== probe.code) return yield* new ConformanceError({
102
+ command: "activate",
103
+ rule: "boundary_rejection"
104
+ });
105
+ }
106
+ const commands = [
107
+ ["activate", activate],
108
+ ["receive", receive],
109
+ ["deliver", deliver],
110
+ ["deactivate", deactivate]
111
+ ];
112
+ for (const [kind, command] of commands) if (command.kind !== kind) return yield* new ConformanceError({
113
+ command: kind,
114
+ rule: "command_kind"
115
+ });
116
+ const activated = yield* Effect.acquireRelease(runtime.executeAgentChannel({
117
+ ...config,
118
+ command: activate
119
+ }), (result) => runtime.executeAgentChannel({
120
+ ...config,
121
+ command: {
122
+ ...deactivate,
123
+ ...result.kind === "activate" ? {
124
+ installationKey: result.installationKey,
125
+ state: result.state
126
+ } : {}
127
+ }
128
+ }).pipe(Effect.orDie));
129
+ for (const [kind, command] of commands) {
130
+ const first = kind === "activate" ? activated : yield* runtime.executeAgentChannel({
131
+ ...config,
132
+ command
133
+ });
134
+ if (kind === "deliver" && definition.features.deliveryMode === "at-most-once") continue;
135
+ const second = yield* runtime.executeAgentChannel({
136
+ ...config,
137
+ command
138
+ });
139
+ const firstJson = yield* Schema.decodeUnknownEffect(Schema.Json)(first);
140
+ const secondJson = yield* Schema.decodeUnknownEffect(Schema.Json)(second);
141
+ if (!Schema.toEquivalence(Schema.Json)(firstJson, secondJson)) return yield* new ConformanceError({
142
+ command: kind,
143
+ rule: "stable_result"
144
+ });
145
+ if (kind === "receive") {
146
+ const nextReceipt = yield* runtime.executeAgentChannel({
147
+ ...config,
148
+ command: {
149
+ ...command,
150
+ operationKey: `${command.operationKey.slice(0, 500)}:replay`
151
+ }
152
+ });
153
+ if (first.kind !== "receive" || nextReceipt.kind !== "receive" || !Schema.toEquivalence(Schema.Array(EventV2))(first.events, nextReceipt.events)) return yield* new ConformanceError({
154
+ command: kind,
155
+ rule: "stable_events"
156
+ });
157
+ }
158
+ }
159
+ }, Effect.scoped);
160
+ //#endregion
161
+ export { AgentChannelConformance_exports as AgentChannelConformance, AgentChannelConformance_exports, ConformanceError, Fixture, run };
162
+
163
+ //# sourceMappingURL=AgentChannelConformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentChannelConformance.js","names":["AgentChannel.commandSchema","AgentChannel.commandSchemaV2","AgentChannel.Key","DualRuntime.Service","AgentChannel.EventV2"],"sources":["../src/AgentChannelConformance.ts"],"sourcesContent":["/** Public replay conformance suite for channel plugins, runnable with @effect/vitest. */\nimport { Effect, Schema } from \"effect\";\n\nimport * as AgentChannel from \"./AgentChannel.ts\";\nimport * as DualRuntime from \"./DualRuntime.ts\";\n\n// Either protocol: the runtime checks each command against the Channel's own protocol.\nconst Command = Schema.Union([\n AgentChannel.commandSchema(Schema.Json),\n AgentChannel.commandSchemaV2(Schema.Json),\n]);\nexport const Fixture = Schema.Struct({\n activate: Command,\n channelId: AgentChannel.Key,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n deactivate: Command,\n definitionSettings: Schema.Json,\n deliver: Command,\n deploymentSettings: Schema.Json,\n receive: Command,\n});\nexport type Fixture = typeof Fixture.Type;\nexport class ConformanceError extends Schema.TaggedError<ConformanceError>()(\n \"AgentChannelConformanceError\",\n {\n command: Schema.Literals([\"activate\", \"deactivate\", \"receive\", \"deliver\"]),\n rule: Schema.Literals([\"command_kind\", \"stable_result\", \"stable_events\", \"boundary_rejection\"]),\n },\n) {}\n\n/**\n * Replays operations that providers declare safe to replay. At-most-once delivery executes once;\n * the durable host owns its replay prohibition. Use an isolated provider test installation: this\n * suite performs provider effects. The host supplies stable keys; the plugin must recover the same\n * external subscription and emit the same provider event keys, even for a fresh receipt key.\n * Boundary rejection and feature/auth matrices are covered by the SDK's public runtime tests.\n */\nexport const run = Effect.fn(\"AgentChannelConformance.run\")(function* (input: Fixture) {\n const fixture = yield* Schema.decodeUnknownEffect(Fixture)(input, { onExcessProperty: \"error\" });\n const runtime = yield* DualRuntime.Service;\n const definition = yield* runtime.getAgentChannel({ channelId: fixture.channelId });\n const { activate, receive, deliver, deactivate, ...config } = fixture;\n const { connectionId: _connectionId, ...withoutConnection } = config;\n const probes = [\n { code: \"invalid_input\", input: { ...config, channelId: \"\", command: activate } },\n {\n // Invocation keys allow '/', but authored identifiers forbid it, so this cannot activate.\n input: { ...config, channelId: \"conformance/missing/channel\", command: activate },\n code: \"not_found\",\n },\n { code: \"invalid_input\", input: { ...config, command: { ...activate, operationKey: \"\" } } },\n {\n code: \"invalid_input\",\n input: { ...config, agent: { id: \"synthetic-authority\" }, command: activate },\n },\n {\n code: \"invalid_auth\",\n input:\n definition.authMethods.length === 0\n ? { ...config, command: activate, connectionId: \"unexpected\" }\n : { ...withoutConnection, command: activate },\n },\n ];\n for (const probe of probes) {\n const outcome = yield* Effect.suspend(() => runtime.executeAgentChannel(probe.input)).pipe(\n Effect.result,\n );\n if (outcome._tag !== \"Failure\" || outcome.failure.code !== probe.code) {\n return yield* new ConformanceError({ command: \"activate\", rule: \"boundary_rejection\" });\n }\n }\n const commands = [\n [\"activate\", activate],\n [\"receive\", receive],\n [\"deliver\", deliver],\n [\"deactivate\", deactivate],\n ] as const;\n for (const [kind, command] of commands) {\n if (command.kind !== kind) {\n return yield* new ConformanceError({ command: kind, rule: \"command_kind\" });\n }\n }\n const activated = yield* Effect.acquireRelease(\n runtime.executeAgentChannel({ ...config, command: activate }),\n result =>\n runtime\n .executeAgentChannel({\n ...config,\n command: {\n ...deactivate,\n ...(result.kind === \"activate\"\n ? { installationKey: result.installationKey, state: result.state }\n : {}),\n },\n })\n .pipe(Effect.orDie),\n );\n for (const [kind, command] of commands) {\n const first =\n kind === \"activate\" ? activated : yield* runtime.executeAgentChannel({ ...config, command });\n if (kind === \"deliver\" && definition.features.deliveryMode === \"at-most-once\") continue;\n const second = yield* runtime.executeAgentChannel({ ...config, command });\n const firstJson = yield* Schema.decodeUnknownEffect(Schema.Json)(first);\n const secondJson = yield* Schema.decodeUnknownEffect(Schema.Json)(second);\n if (!Schema.toEquivalence(Schema.Json)(firstJson, secondJson)) {\n return yield* new ConformanceError({ command: kind, rule: \"stable_result\" });\n }\n if (kind === \"receive\") {\n const nextReceipt = yield* runtime.executeAgentChannel({\n ...config,\n command: { ...command, operationKey: `${command.operationKey.slice(0, 500)}:replay` },\n });\n if (\n first.kind !== \"receive\" ||\n nextReceipt.kind !== \"receive\" ||\n !Schema.toEquivalence(Schema.Array(AgentChannel.EventV2))(first.events, nextReceipt.events)\n ) {\n return yield* new ConformanceError({ command: kind, rule: \"stable_events\" });\n }\n }\n }\n}, Effect.scoped);\n\nexport * as AgentChannelConformance from \"./AgentChannelConformance.ts\";\n"],"mappings":";;;;;;;;;;;;;AAOA,MAAM,UAAU,OAAO,MAAM,CAC3BA,cAA2B,OAAO,IAAI,GACtCC,gBAA6B,OAAO,IAAI,CAC1C,CAAC;AACD,MAAa,UAAU,OAAO,OAAO;CACnC,UAAU;CACV,WAAWC;CACX,cAAc,OAAO,YAAYA,GAAgB;CACjD,YAAY;CACZ,oBAAoB,OAAO;CAC3B,SAAS;CACT,oB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7E,IAAI,SAAS,WAAW;GACtB,MAAM,cAAc,OAAO,QAAQ,oBAAoB;IACrD,GAAG;IACH,SAAS;KAAE,GAAG;KAAS,cAAc,GAAG,QAAQ,aAAa,MAAM,GAAG,GAAG,EAAE;IAAS;GACtF,CAAC;GACD,IACE,MAAM,SAAS,aACf,YAAY,SAAS,aACrB,CAAC,OAAO,cAAc,OAAO,MAAMC,OAAoB,CAAC,CAAC,CAAC,MAAM,QAAQ,YAAY,MAAM,GAE1F,OAAO,OAAO,IAAI,iBAAiB;IAAE,SAAS;IAAM,MAAM;GAAgB,CAAC;EAE/E;CACF;AACF,GAAG,OAAO,MAAM"}
@@ -0,0 +1,78 @@
1
+ import { AccessOutcome, Any, ChannelError, CheckedResult, Definition, Handler } from "./AgentChannel.js";
2
+ import { Service as Service$1 } from "./ConnectionResolver.js";
3
+ import { AuthResolutionRequirements } from "./internal/auth-execution.js";
4
+ import { Any as Any$1 } from "./Plugin.js";
5
+ import "./AgentChannelRuntime.js";
6
+ import { Context, Effect, Layer, Schema } from "effect";
7
+ declare namespace AgentChannelRuntime_d_exports {
8
+ export { AgentChannelRuntime_d_exports as AgentChannelRuntime, ConnectionContext, Input, Interface, Pin, Requirements, Service, layer };
9
+ }
10
+ /** Host-only connection authority context. It is never included in handler inputs. */
11
+ export declare const ConnectionContext: Schema.Struct<{
12
+ readonly actor: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
13
+ readonly kind: Schema.Literal<"user">;
14
+ readonly userId: Schema.NonEmptyString;
15
+ }>, Schema.Struct<{
16
+ readonly kind: Schema.Literal<"system">;
17
+ readonly reason: Schema.optionalKey<Schema.NonEmptyString>;
18
+ }>]>>;
19
+ readonly source: Schema.optionalKey<Schema.Struct<{
20
+ readonly kind: Schema.NonEmptyString;
21
+ readonly subjectId: Schema.optionalKey<Schema.NonEmptyString>;
22
+ }>>;
23
+ readonly tenant: Schema.optionalKey<Schema.Struct<{
24
+ readonly organizationId: Schema.NonEmptyString;
25
+ readonly teamId: Schema.NonEmptyString;
26
+ }>>;
27
+ }>;
28
+ declare const Pin: Schema.Struct<{
29
+ readonly channelId: Schema.NonEmptyString;
30
+ }>;
31
+ declare const Input: Schema.Struct<{
32
+ readonly channelId: Schema.NonEmptyString;
33
+ readonly command: Schema.Unknown;
34
+ readonly connectionId: Schema.optionalKey<Schema.NonEmptyString>;
35
+ readonly context: Schema.optionalKey<Schema.Struct<{
36
+ readonly actor: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
37
+ readonly kind: Schema.Literal<"user">;
38
+ readonly userId: Schema.NonEmptyString;
39
+ }>, Schema.Struct<{
40
+ readonly kind: Schema.Literal<"system">;
41
+ readonly reason: Schema.optionalKey<Schema.NonEmptyString>;
42
+ }>]>>;
43
+ readonly source: Schema.optionalKey<Schema.Struct<{
44
+ readonly kind: Schema.NonEmptyString;
45
+ readonly subjectId: Schema.optionalKey<Schema.NonEmptyString>;
46
+ }>>;
47
+ readonly tenant: Schema.optionalKey<Schema.Struct<{
48
+ readonly organizationId: Schema.NonEmptyString;
49
+ readonly teamId: Schema.NonEmptyString;
50
+ }>>;
51
+ }>>;
52
+ readonly definitionSettings: Schema.Unknown;
53
+ readonly deploymentSettings: Schema.Unknown;
54
+ }>;
55
+ type Pin = typeof Pin.Type;
56
+ type Input = typeof Input.Type;
57
+ export interface Interface {
58
+ /** Reauthorize an already verified identity; does not verify a transport or execute provider operations. */
59
+ readonly checkAccess: (input: unknown) => Effect.Effect<AccessOutcome, ChannelError>;
60
+ readonly get: (pin: unknown) => Effect.Effect<Definition, ChannelError>;
61
+ readonly decodeDefinitionSettings: (input: unknown) => Effect.Effect<Schema.Json, ChannelError>;
62
+ readonly decodeDeploymentSettings: (input: unknown) => Effect.Effect<Schema.Json, ChannelError>;
63
+ readonly execute: (input: unknown) => Effect.Effect<CheckedResult, ChannelError>;
64
+ }
65
+ declare const Service_base: Context.ServiceClass<Service, "@dual-os/sdk/AgentChannelRuntime", Interface>;
66
+ export declare class Service extends Service_base {}
67
+ type Definitions<P extends Any$1> = P["agentChannels"][number]["definition"];
68
+ type ChannelHandlers<P extends Any$1, C> = C extends Any ? Handler<`${P["identifier"]}/${C["identifier"]}`> : never;
69
+ type PluginHandlers<P> = P extends Any$1 ? ChannelHandlers<P, P["agentChannels"][number]> : never;
70
+ type ExtensionRequirements<D> = D extends {
71
+ readonly extensions: infer Extensions extends Readonly<Record<string, Schema.Top>>;
72
+ } ? Extensions[keyof Extensions]["DecodingServices"] | Extensions[keyof Extensions]["EncodingServices"] : never;
73
+ export type Requirements<P extends Any$1> = PluginHandlers<P> | ExtensionRequirements<Definitions<P>> | Definitions<P>["definitionSettings"]["DecodingServices"] | Definitions<P>["deploymentSettings"]["DecodingServices"] | Definitions<P>["state"]["DecodingServices"] | Definitions<P>["state"]["EncodingServices"] | AuthResolutionRequirements<Definitions<P>["authMethods"]> | (Definitions<P>["authMethods"][number] extends never ? never : Service$1);
74
+ /** Build from the installed plugins. */
75
+ export declare const layer: <P extends Any$1>(plugins: readonly P[]) => Layer.Layer<Service, never, Requirements<P>>;
76
+ //#endregion
77
+ export { AgentChannelRuntime_d_exports as AgentChannelRuntime, AgentChannelRuntime_d_exports, Input, Pin };
78
+ //# sourceMappingURL=AgentChannelRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentChannelRuntime.d.ts","names":["AgentChannel.AccessOutcome","AgentChannel.ChannelError","AgentChannel.Definition","AgentChannel.CheckedResult","Plugin.Any","AgentChannel.Any","AgentChannel.Handler","ConnectionResolver.Service"],"sources":["../src/AgentChannelRuntime.ts"],"mappings":";;;;;;;;;;qBAUa,mBAAiB,OAAA;;;;;;;;;;;;;;;;;cAiBxB,KAAG,OAAA;;;cACH,OAAK,OAAA;;;;;;;;;;;;;;;;;;;;;;;;KAgBC,aAAa,IAAI;KACjB,eAAe,MAAM;iBAChB;;WAEN,cACP,mBACG,OAAO,OAAOA,eAA4BC;WACtC,MAAM,iBAAiB,OAAO,OAAOC,YAAyBD;WAC9D,2BACP,mBACG,OAAO,OAAO,OAAO,MAAMA;WACvB,2BACP,mBACG,OAAO,OAAO,OAAO,MAAMA;WACvB,UACP,mBACG,OAAO,OAAOE,eAA4BF;;;qBAEpC,gBAAgB;KAIxB,YAAY,UAAUG,SAAc;KACpC,gBAAgB,UAAUA,OAAY,KAAK,UAAUC,MACtDC,WAAwB,mBAAmB;KAE1C,eAAe,KAAK,UAAUF,QAC/B,gBAAgB,GAAG;KAElB,sBAAsB,KAAK;WACrB,kBAAkB,mBAAmB,SAAS,eAAe,OAAO;IAGvE,iBAAiB,kCACjB,iBAAiB;YAEb,aAAa,UAAUA,SAC/B,eAAe,KACf,sBAAsB,YAAY,MAClC,YAAY,+CACZ,YAAY,+CACZ,YAAY,kCACZ,YAAY,kCACZ,2BAA2B,YAAY,sBACtC,YAAY,kDAAkDG;;qBAyMtD,QAAS,UAAUH,OAAU,kBACtB,QACjB,MAAM,MAAM,gBAAgB,aAAa"}
@@ -0,0 +1,270 @@
1
+ import { __exportAll } from "./_virtual/_rolldown/runtime.js";
2
+ import { AccessOutcome, ChannelError, CheckedResult, FailureCode, Key, Verification, VerifiedIdentity, handlerKey, schemasFor, validateDefinition } from "./AgentChannel.js";
3
+ import { Service as Service$1 } from "./ConnectionResolver.js";
4
+ import { findHandler } from "./internal/handler-context.js";
5
+ import "./AgentChannelRuntime.js";
6
+ import { Cause, Context, Effect, Layer, Option, Predicate, Schema } from "effect";
7
+ //#region src/AgentChannelRuntime.ts
8
+ /** Checked execution of pinned Agent Channel capabilities. No product lifecycle or persistence. */
9
+ var AgentChannelRuntime_exports = /* @__PURE__ */ __exportAll({
10
+ AgentChannelRuntime: () => AgentChannelRuntime_exports,
11
+ ConnectionContext: () => ConnectionContext,
12
+ Service: () => Service,
13
+ layer: () => layer
14
+ });
15
+ /** Host-only connection authority context. It is never included in handler inputs. */
16
+ const ConnectionContext = Schema.Struct({
17
+ actor: Schema.optionalKey(Schema.Union([Schema.Struct({
18
+ kind: Schema.Literal("user"),
19
+ userId: Key
20
+ }), Schema.Struct({
21
+ kind: Schema.Literal("system"),
22
+ reason: Schema.optionalKey(Key)
23
+ })])),
24
+ source: Schema.optionalKey(Schema.Struct({
25
+ kind: Key,
26
+ subjectId: Schema.optionalKey(Key)
27
+ })),
28
+ tenant: Schema.optionalKey(Schema.Struct({
29
+ organizationId: Key,
30
+ teamId: Key
31
+ }))
32
+ });
33
+ const Pin = Schema.Struct({ channelId: Key });
34
+ const Input = Schema.Struct({
35
+ ...Pin.fields,
36
+ command: Schema.Unknown,
37
+ connectionId: Schema.optionalKey(Key),
38
+ context: Schema.optionalKey(ConnectionContext),
39
+ definitionSettings: Schema.Unknown,
40
+ deploymentSettings: Schema.Unknown
41
+ });
42
+ const AccessInput = Schema.Struct({
43
+ ...Pin.fields,
44
+ connectionId: Schema.optionalKey(Key),
45
+ context: Schema.optionalKey(ConnectionContext),
46
+ definitionSettings: Schema.Unknown,
47
+ deploymentSettings: Schema.Unknown,
48
+ identity: VerifiedIdentity
49
+ });
50
+ var Service = class extends Context.Service()("@dual-os/sdk/AgentChannelRuntime") {};
51
+ const fail = (code) => new ChannelError({ code });
52
+ const safe = (effect, code) => effect.pipe(Effect.catchCause((cause) => Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.fail(fail(code))));
53
+ const AssetResultJson = Schema.Json.check(Schema.makeFilter((value) => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 14680064));
54
+ const Json = Schema.Json.check(Schema.makeFilter((value) => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 2097152));
55
+ const strict = { onExcessProperty: "error" };
56
+ const decode = (schema, input, code) => safe(Effect.suspend(() => Schema.decodeUnknownEffect(schema)(input, strict)), code);
57
+ const json = (value, code) => decode(Json, value, code);
58
+ const decodeData = Effect.fn("AgentChannelRuntime.decodeData")(function* (schema, input, code, largeAssetResult = false) {
59
+ const boundary = largeAssetResult ? AssetResultJson : Json;
60
+ yield* decode(boundary, input, code);
61
+ const value = yield* decode(schema, input, code);
62
+ yield* decode(boundary, value, code);
63
+ return value;
64
+ });
65
+ const invokeHandler = (handler, effect) => effect.pipe(Effect.provideContext(handler.context), Effect.catch((error) => decode(Schema.TaggedStruct("AgentChannelHandlerError", { code: FailureCode }), Predicate.isObject(error) ? { ...error } : error, "provider_failure").pipe(Effect.flatMap((checked) => Effect.fail(new ChannelError({
66
+ code: "provider_failure",
67
+ providerCode: checked.code
68
+ }))))), Effect.catchCause((cause) => {
69
+ if (Cause.hasInterrupts(cause)) return Effect.interrupt;
70
+ const error = Cause.findErrorOption(cause);
71
+ return Option.isSome(error) && error.value instanceof ChannelError ? Effect.fail(error.value) : Effect.fail(fail("provider_failure"));
72
+ }));
73
+ const checkExtensions = Effect.fn("AgentChannelRuntime.checkExtensions")(function* (definition, extensions, code) {
74
+ for (const [key, value] of Object.entries(extensions ?? {})) {
75
+ const schema = definition.extensions?.[key];
76
+ if (schema === void 0) return yield* fail(code);
77
+ yield* decodeData(Schema.toType(schema), value, code);
78
+ }
79
+ });
80
+ const checkMessage = (features, destination, content) => (destination.kind === "direct" || features.groups) && (destination.threadKey === void 0 || features.threads) && (content.mentions === void 0 || features.mentions) && (content.assets === void 0 || features.assets) && (content.replyToMessageKey === void 0 || features.replies);
81
+ const checkDelivery = (features, command) => "content" in command ? checkMessage(features, command.destination, command.content) : checkMessage(features, command.destination, { text: "" }) && (features.operations ?? []).includes(command.operation.kind);
82
+ const Material = Schema.Struct({
83
+ connectionId: Key,
84
+ encoding: Schema.optionalKey(Schema.Literal("json")),
85
+ material: Schema.Unknown,
86
+ methodId: Key,
87
+ providerId: Key,
88
+ setup: Schema.Unknown
89
+ });
90
+ const ResolveHook = Schema.declare((value) => Predicate.isFunction(value));
91
+ const resolveAuth = Effect.fn("AgentChannelRuntime.resolveAuth")(function* (providerId, channelId, definition, connectionId, phase, context) {
92
+ if (definition.authMethods.length === 0) {
93
+ if (connectionId !== void 0) return yield* fail("invalid_auth");
94
+ return;
95
+ }
96
+ if (connectionId === void 0) return yield* fail("invalid_auth");
97
+ const resolver = yield* Effect.serviceOption(Service$1);
98
+ if (Option.isNone(resolver)) return yield* fail("invalid_auth");
99
+ const raw = yield* safe(Effect.suspend(() => resolver.value.resolve({
100
+ connectionId,
101
+ target: {
102
+ phase,
103
+ providerId,
104
+ targetId: channelId,
105
+ targetKind: "agent-channel"
106
+ },
107
+ ...context === void 0 ? {} : { context }
108
+ })), "invalid_auth");
109
+ const resolved = yield* decode(Material, raw, "invalid_auth");
110
+ if (resolved.providerId !== providerId || resolved.connectionId !== connectionId) return yield* fail("invalid_auth");
111
+ const method = definition.authMethods.find((method) => resolved.methodId === method.identifier || resolved.methodId === `${providerId}/${method.identifier}`);
112
+ if (method === void 0) return yield* fail("invalid_auth");
113
+ const decodeAuth = (schema, value) => decode(resolved.encoding === "json" ? Schema.toCodecJson(schema) : schema, value, "invalid_auth");
114
+ const setup = method.setup === void 0 ? yield* decode(Schema.Undefined, resolved.setup, "invalid_auth") : yield* decodeAuth(method.setup, resolved.setup);
115
+ const material = yield* decodeAuth(method.material, resolved.material);
116
+ let value;
117
+ if (method.resolve === void 0) value = method.material === method.value ? material : yield* decode(method.value, material, "invalid_auth");
118
+ else {
119
+ const hook = yield* decode(ResolveHook, method.resolve, "invalid_auth");
120
+ const output = yield* safe(Effect.suspend(() => {
121
+ const result = hook(material, { setup });
122
+ return Effect.isEffect(result) ? result : Effect.succeed(result);
123
+ }), "invalid_auth");
124
+ value = yield* decode(method.value, output, "invalid_auth");
125
+ }
126
+ return {
127
+ methodId: method.identifier,
128
+ value
129
+ };
130
+ });
131
+ const find = (plugins, pin) => {
132
+ for (const provider of plugins) {
133
+ const channel = provider.agentChannels.find((channel) => `${provider.identifier}/${channel.identifier}` === pin.channelId);
134
+ if (channel !== void 0) return {
135
+ definition: channel.definition,
136
+ provider
137
+ };
138
+ }
139
+ };
140
+ /** Build from the installed plugins. */
141
+ const layer = (plugins) => Layer.effect(Service, Effect.gen(function* () {
142
+ const context = yield* Effect.context();
143
+ const get = Effect.fn("AgentChannelRuntime.get")(function* (input) {
144
+ const pin = yield* decode(Pin, input, "invalid_input");
145
+ const found = find(plugins, pin);
146
+ if (found === void 0) return yield* fail("not_found");
147
+ yield* safe(Effect.sync(() => {
148
+ validateDefinition(found.definition, found.provider.identifier, found.provider.authMethods);
149
+ }), "invalid_definition");
150
+ const handler = Option.fromNullishOr(findHandler(context, found.provider.identifier, handlerKey(pin.channelId)));
151
+ if (Option.isNone(handler) || !Predicate.isObject(handler.value.runtime) || !Predicate.isFunction(handler.value.runtime.execute) || !Predicate.isFunction(handler.value.runtime.verify) || !Predicate.isFunction(handler.value.runtime.checkAccess)) return yield* fail("handler_unavailable");
152
+ return found.definition;
153
+ });
154
+ const checkAccess = Effect.fn("AgentChannelRuntime.checkAccess")(function* (input) {
155
+ yield* json(input, "invalid_input");
156
+ const request = yield* decode(AccessInput, input, "invalid_input");
157
+ const definition = yield* get({ channelId: request.channelId });
158
+ const found = find(plugins, request);
159
+ if (found === void 0) return yield* fail("not_found");
160
+ const definitionSettings = yield* decodeData(definition.definitionSettings, request.definitionSettings, "invalid_input");
161
+ const deploymentSettings = yield* decodeData(definition.deploymentSettings, request.deploymentSettings, "invalid_input");
162
+ if (!checkMessage(definition.features, request.identity.conversation, { text: "" })) return yield* fail("unsupported_feature");
163
+ const auth = yield* resolveAuth(found.provider.identifier, request.channelId, definition, request.connectionId, "check_access", request.context);
164
+ const handler = Option.fromNullishOr(findHandler(context, found.provider.identifier, handlerKey(request.channelId)));
165
+ if (Option.isNone(handler)) return yield* fail("handler_unavailable");
166
+ const output = yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.checkAccess(request.identity, {
167
+ definitionSettings,
168
+ deploymentSettings,
169
+ ...auth === void 0 ? {} : { auth }
170
+ })));
171
+ return yield* decodeData(AccessOutcome, output, "invalid_result");
172
+ });
173
+ const execute = Effect.fn("AgentChannelRuntime.execute")(function* (input) {
174
+ yield* json(input, "invalid_input");
175
+ const request = yield* decode(Input, input, "invalid_input");
176
+ const definition = yield* get({ channelId: request.channelId });
177
+ const found = find(plugins, request);
178
+ if (found === void 0) return yield* fail("not_found");
179
+ const definitionSettings = yield* decodeData(definition.definitionSettings, request.definitionSettings, "invalid_input");
180
+ const deploymentSettings = yield* decodeData(definition.deploymentSettings, request.deploymentSettings, "invalid_input");
181
+ const schemas = schemasFor(definition);
182
+ const command = yield* decodeData(schemas.command, request.command, "invalid_input");
183
+ yield* checkExtensions(definition, command.extensions, "invalid_input");
184
+ if (command.kind === "deliver" && command.operationKey !== command.deliveryKey) return yield* fail("invalid_input");
185
+ if (command.kind === "deliver" && !checkDelivery(definition.features, command)) return yield* fail("unsupported_feature");
186
+ if (command.kind === "deliver" && "operation" in command && command.operation.kind === "set_reaction" && command.operation.target.kind === "activation" && command.activationMessageKey === void 0) return yield* fail("invalid_input");
187
+ if (command.kind === "read_context" && (definition.features.readContext !== true || !checkMessage(definition.features, command.destination, { text: "" }))) return yield* fail("unsupported_feature");
188
+ const handler = Option.fromNullishOr(findHandler(context, found.provider.identifier, handlerKey(request.channelId)));
189
+ if (Option.isNone(handler)) return yield* fail("handler_unavailable");
190
+ const auth = yield* resolveAuth(found.provider.identifier, request.channelId, definition, request.connectionId, command.kind, request.context);
191
+ const operationKey = command.operationKey;
192
+ const kind = command.kind;
193
+ const deliveryKey = command.kind === "deliver" ? command.deliveryKey : void 0;
194
+ const assetKey = command.kind === "read_asset" ? command.asset.assetKey : void 0;
195
+ const adapterContext = {
196
+ definitionSettings,
197
+ deploymentSettings,
198
+ ...auth === void 0 ? {} : { auth }
199
+ };
200
+ if (!Predicate.isFunction(handler.value.runtime.execute) || !Predicate.isFunction(handler.value.runtime.verify) || !Predicate.isFunction(handler.value.runtime.checkAccess)) return yield* fail("handler_unavailable");
201
+ if (command.kind === "receive") yield* decodeData(Verification, yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext))), "invalid_result");
202
+ if (command.kind === "read_asset") {
203
+ if (!definition.features.assets) return yield* fail("unsupported_feature");
204
+ if ((yield* decodeData(AccessOutcome, yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.checkAccess(command.identity, adapterContext))), "invalid_result")).decision !== "allow") return yield* new ChannelError({
205
+ code: "provider_failure",
206
+ providerCode: "unauthorized"
207
+ });
208
+ }
209
+ const output = yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)));
210
+ const result = yield* decodeData(schemas.typeResult, output, "invalid_result", kind === "read_asset");
211
+ if (result.kind !== kind || result.operationKey !== operationKey || result.kind === "deliver" && result.deliveryKey !== deliveryKey || result.kind === "read_asset" && result.assetKey !== assetKey) return yield* fail("invalid_result");
212
+ yield* checkExtensions(definition, result.extensions, "invalid_result");
213
+ if (result.kind === "deliver" && result.status === "pending" && !definition.features.deliveryState) return yield* fail("invalid_result");
214
+ const allowedEvents = [];
215
+ const deniedEventKeys = [];
216
+ if (result.kind === "receive") {
217
+ if (result.deniedEventKeys !== void 0) return yield* fail("invalid_result");
218
+ if (result.activationProof === "verified" && (result.response === void 0 || result.events.length !== 0)) return yield* fail("invalid_result");
219
+ const eventKeys = /* @__PURE__ */ new Set();
220
+ for (const event of result.events) {
221
+ if (eventKeys.has(event.eventKey)) return yield* fail("invalid_result");
222
+ eventKeys.add(event.eventKey);
223
+ if (event.kind === "message" && !checkMessage(definition.features, event.conversation, event.content)) return yield* fail("invalid_result");
224
+ if ((event.kind === "echo" || event.kind === "stop") && !checkMessage(definition.features, event.conversation, { text: "" })) return yield* fail("invalid_result");
225
+ if (event.kind === "delivery_update" && !definition.features.deliveryState) return yield* fail("invalid_result");
226
+ yield* checkExtensions(definition, event.extensions, "invalid_result");
227
+ let denied = false;
228
+ if (event.kind === "message" || event.kind === "echo" || event.kind === "stop") {
229
+ const identity = yield* decodeData(VerifiedIdentity, {
230
+ conversation: event.conversation,
231
+ senderKey: event.senderKey
232
+ }, "invalid_result");
233
+ denied = (yield* decodeData(AccessOutcome, yield* invokeHandler(handler.value, Effect.suspend(() => handler.value.runtime.checkAccess(identity, adapterContext))), "invalid_result")).decision === "deny";
234
+ }
235
+ if (denied) {
236
+ deniedEventKeys.push(event.eventKey);
237
+ continue;
238
+ }
239
+ allowedEvents.push(event);
240
+ }
241
+ }
242
+ const encoded = yield* safe(Schema.encodeUnknownEffect(schemas.result)(result.kind === "receive" ? {
243
+ ...result,
244
+ events: allowedEvents,
245
+ ...deniedEventKeys.length === 0 ? {} : { deniedEventKeys }
246
+ } : result, strict), "invalid_result");
247
+ return yield* decodeData(CheckedResult, encoded, "invalid_result", kind === "read_asset");
248
+ });
249
+ const run = (effect) => effect.pipe(Effect.provideContext(context));
250
+ const decodeSettings = (field) => Effect.fn("AgentChannelRuntime.decodeSettings")(function* (input) {
251
+ const request = yield* decode(Schema.Struct({
252
+ ...Pin.fields,
253
+ value: Schema.Json
254
+ }), input, "invalid_input");
255
+ const schema = (yield* get({ channelId: request.channelId }))[field];
256
+ const value = yield* decodeData(schema, request.value, "invalid_input");
257
+ return yield* json(yield* safe(Schema.encodeUnknownEffect(schema)(value, strict), "invalid_input"), "invalid_input");
258
+ });
259
+ return Service.of({
260
+ checkAccess: (input) => run(checkAccess(input)),
261
+ decodeDefinitionSettings: (input) => run(decodeSettings("definitionSettings")(input)),
262
+ decodeDeploymentSettings: (input) => run(decodeSettings("deploymentSettings")(input)),
263
+ execute: (input) => run(execute(input)),
264
+ get: (input) => run(get(input))
265
+ });
266
+ }));
267
+ //#endregion
268
+ export { AgentChannelRuntime_exports as AgentChannelRuntime, AgentChannelRuntime_exports, ConnectionContext, Service, layer };
269
+
270
+ //# sourceMappingURL=AgentChannelRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentChannelRuntime.js","names":["AgentChannel.Key","AgentChannel.VerifiedIdentity","AgentChannel.ChannelError","AgentChannel.FailureCode","ConnectionResolver.Service","AgentChannel.handlerKey","AgentChannel.AccessOutcome","AgentChannel.schemasFor","AgentChannel.Verification","AgentChannel.CheckedResult"],"sources":["../src/AgentChannelRuntime.ts"],"sourcesContent":["/** Checked execution of pinned Agent Channel capabilities. No product lifecycle or persistence. */\nimport { Cause, Context, Effect, Layer, Option, Predicate, Schema } from \"effect\";\n\nimport * as AgentChannel from \"./AgentChannel.ts\";\nimport { ConnectionResolver } from \"./ConnectionResolver.ts\";\nimport type { AuthResolutionRequirements } from \"./internal/auth-execution.ts\";\nimport { findHandler } from \"./internal/handler-context.ts\";\nimport type * as Plugin from \"./Plugin.ts\";\n\n/** Host-only connection authority context. It is never included in handler inputs. */\nexport const ConnectionContext = Schema.Struct({\n actor: Schema.optionalKey(\n Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"user\"), userId: AgentChannel.Key }),\n Schema.Struct({\n kind: Schema.Literal(\"system\"),\n reason: Schema.optionalKey(AgentChannel.Key),\n }),\n ]),\n ),\n source: Schema.optionalKey(\n Schema.Struct({ kind: AgentChannel.Key, subjectId: Schema.optionalKey(AgentChannel.Key) }),\n ),\n tenant: Schema.optionalKey(\n Schema.Struct({ organizationId: AgentChannel.Key, teamId: AgentChannel.Key }),\n ),\n});\nconst Pin = Schema.Struct({ channelId: AgentChannel.Key });\nconst Input = Schema.Struct({\n ...Pin.fields,\n command: Schema.Unknown,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n});\nconst AccessInput = Schema.Struct({\n ...Pin.fields,\n connectionId: Schema.optionalKey(AgentChannel.Key),\n context: Schema.optionalKey(ConnectionContext),\n definitionSettings: Schema.Unknown,\n deploymentSettings: Schema.Unknown,\n identity: AgentChannel.VerifiedIdentity,\n});\nexport type Pin = typeof Pin.Type;\nexport type Input = typeof Input.Type;\nexport interface Interface {\n /** Reauthorize an already verified identity; does not verify a transport or execute provider operations. */\n readonly checkAccess: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.AccessOutcome, AgentChannel.ChannelError>;\n readonly get: (pin: unknown) => Effect.Effect<AgentChannel.Definition, AgentChannel.ChannelError>;\n readonly decodeDefinitionSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly decodeDeploymentSettings: (\n input: unknown,\n ) => Effect.Effect<Schema.Json, AgentChannel.ChannelError>;\n readonly execute: (\n input: unknown,\n ) => Effect.Effect<AgentChannel.CheckedResult, AgentChannel.ChannelError>;\n}\nexport class Service extends Context.Service<Service, Interface>()(\n \"@dual-os/sdk/AgentChannelRuntime\",\n) {}\n\ntype Definitions<P extends Plugin.Any> = P[\"agentChannels\"][number][\"definition\"];\ntype ChannelHandlers<P extends Plugin.Any, C> = C extends AgentChannel.Any\n ? AgentChannel.Handler<`${P[\"identifier\"]}/${C[\"identifier\"]}`>\n : never;\ntype PluginHandlers<P> = P extends Plugin.Any\n ? ChannelHandlers<P, P[\"agentChannels\"][number]>\n : never;\ntype ExtensionRequirements<D> = D extends {\n readonly extensions: infer Extensions extends Readonly<Record<string, Schema.Top>>;\n}\n ?\n | Extensions[keyof Extensions][\"DecodingServices\"]\n | Extensions[keyof Extensions][\"EncodingServices\"]\n : never;\nexport type Requirements<P extends Plugin.Any> =\n | PluginHandlers<P>\n | ExtensionRequirements<Definitions<P>>\n | Definitions<P>[\"definitionSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"deploymentSettings\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"DecodingServices\"]\n | Definitions<P>[\"state\"][\"EncodingServices\"]\n | AuthResolutionRequirements<Definitions<P>[\"authMethods\"]>\n | (Definitions<P>[\"authMethods\"][number] extends never ? never : ConnectionResolver.Service);\n\nconst fail = (code: typeof AgentChannel.ErrorCode.Type) => new AgentChannel.ChannelError({ code });\nconst safe = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n code: typeof AgentChannel.ErrorCode.Type,\n): Effect.Effect<A, AgentChannel.ChannelError, R> =>\n effect.pipe(\n Effect.catchCause(cause =>\n Cause.hasInterrupts(cause) ? Effect.interrupt : Effect.fail(fail(code)),\n ),\n );\nconst AssetResultJson = Schema.Json.check(\n Schema.makeFilter(\n value => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 14_680_064,\n ),\n);\nconst Json = Schema.Json.check(\n Schema.makeFilter(\n value => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 2_097_152,\n ),\n);\nconst strict = { onExcessProperty: \"error\" } as const;\nconst decode = <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n) =>\n safe(\n Effect.suspend(() => Schema.decodeUnknownEffect(schema)(input, strict)),\n code,\n );\nconst json = (value: unknown, code: typeof AgentChannel.ErrorCode.Type) =>\n decode(Json, value, code);\nconst decodeData = Effect.fn(\"AgentChannelRuntime.decodeData\")(function* <S extends Schema.Top>(\n schema: S,\n input: unknown,\n code: typeof AgentChannel.ErrorCode.Type,\n largeAssetResult = false,\n) {\n const boundary = largeAssetResult ? AssetResultJson : Json;\n yield* decode(boundary, input, code);\n const value = yield* decode(schema, input, code);\n yield* decode(boundary, value, code);\n return value;\n});\n\nconst invokeHandler = (\n handler: AgentChannel.Handler,\n effect: Effect.Effect<unknown, unknown, unknown>,\n) =>\n effect.pipe(\n Effect.provideContext(handler.context),\n Effect.catch(error =>\n decode(\n Schema.TaggedStruct(\"AgentChannelHandlerError\", { code: AgentChannel.FailureCode }),\n Predicate.isObject(error) ? { ...error } : error,\n \"provider_failure\",\n ).pipe(\n Effect.flatMap(checked =>\n Effect.fail(\n new AgentChannel.ChannelError({ code: \"provider_failure\", providerCode: checked.code }),\n ),\n ),\n ),\n ),\n Effect.catchCause(cause => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n const error = Cause.findErrorOption(cause);\n return Option.isSome(error) && error.value instanceof AgentChannel.ChannelError\n ? Effect.fail(error.value)\n : Effect.fail(fail(\"provider_failure\"));\n }),\n );\n\nconst checkExtensions = Effect.fn(\"AgentChannelRuntime.checkExtensions\")(function* (\n definition: AgentChannel.Definition,\n extensions: Readonly<Record<string, Schema.Json>> | undefined,\n code: typeof AgentChannel.ErrorCode.Type,\n) {\n for (const [key, value] of Object.entries(extensions ?? {})) {\n const schema = definition.extensions?.[key];\n if (schema === undefined) return yield* fail(code);\n // Extensions are checked values, not a provider payload escape hatch. No normalization.\n yield* decodeData(Schema.toType(schema), value, code);\n }\n});\nconst checkMessage = (\n features: AgentChannel.Features,\n destination: AgentChannel.Destination,\n content: AgentChannel.Content,\n): boolean =>\n (destination.kind === \"direct\" || features.groups) &&\n (destination.threadKey === undefined || features.threads) &&\n (content.mentions === undefined || features.mentions) &&\n (content.assets === undefined || features.assets) &&\n (content.replyToMessageKey === undefined || features.replies);\n\nconst checkDelivery = (\n features: AgentChannel.Features,\n command: Extract<AgentChannel.Command | AgentChannel.CommandV2, { kind: \"deliver\" }>,\n): boolean =>\n \"content\" in command\n ? checkMessage(features, command.destination, command.content)\n : checkMessage(features, command.destination, { text: \"\" }) &&\n (features.operations ?? []).includes(command.operation.kind);\n\nconst Material = Schema.Struct({\n connectionId: AgentChannel.Key,\n // The plugin worker's resolver marks its JSON-carried material.\n encoding: Schema.optionalKey(Schema.Literal(\"json\")),\n material: Schema.Unknown,\n methodId: AgentChannel.Key,\n providerId: AgentChannel.Key,\n setup: Schema.Unknown,\n});\nconst ResolveHook = Schema.declare(\n (value): value is (material: unknown, context: { readonly setup: unknown }) => unknown =>\n Predicate.isFunction(value),\n);\nconst resolveAuth = Effect.fn(\"AgentChannelRuntime.resolveAuth\")(function* (\n providerId: string,\n channelId: string,\n definition: AgentChannel.Definition,\n connectionId: string | undefined,\n phase: string,\n context: typeof ConnectionContext.Type | undefined,\n) {\n if (definition.authMethods.length === 0) {\n if (connectionId !== undefined) return yield* fail(\"invalid_auth\");\n return undefined;\n }\n // The host alone selects/authorizes the pinned connection. Its records never reach the plugin.\n if (connectionId === undefined) return yield* fail(\"invalid_auth\");\n const resolver = yield* Effect.serviceOption(ConnectionResolver.Service);\n if (Option.isNone(resolver)) return yield* fail(\"invalid_auth\");\n const raw = yield* safe(\n Effect.suspend(() =>\n resolver.value.resolve({\n connectionId,\n target: { phase, providerId, targetId: channelId, targetKind: \"agent-channel\" },\n ...(context === undefined ? {} : { context }),\n }),\n ),\n \"invalid_auth\",\n );\n const resolved = yield* decode(Material, raw, \"invalid_auth\");\n if (resolved.providerId !== providerId || resolved.connectionId !== connectionId) {\n return yield* fail(\"invalid_auth\");\n }\n const method = definition.authMethods.find(\n method =>\n resolved.methodId === method.identifier ||\n resolved.methodId === `${providerId}/${method.identifier}`,\n );\n if (method === undefined) return yield* fail(\"invalid_auth\");\n // Material the worker received as JSON decodes through each schema's JSON codec.\n const decodeAuth = <S extends Schema.Top>(schema: S, value: unknown) =>\n decode(\n resolved.encoding === \"json\" ? Schema.toCodecJson(schema) : schema,\n value,\n \"invalid_auth\",\n );\n const setup =\n method.setup === undefined\n ? yield* decode(Schema.Undefined, resolved.setup, \"invalid_auth\")\n : yield* decodeAuth(method.setup, resolved.setup);\n const material = yield* decodeAuth(method.material, resolved.material);\n let value: unknown;\n if (method.resolve === undefined) {\n value =\n method.material === method.value\n ? material\n : yield* decode(method.value, material, \"invalid_auth\");\n } else {\n const hook = yield* decode(ResolveHook, method.resolve, \"invalid_auth\");\n const output = yield* safe(\n Effect.suspend(() => {\n const result = hook(material, { setup });\n return Effect.isEffect(result) ? result : Effect.succeed(result);\n }),\n \"invalid_auth\",\n );\n value = yield* decode(method.value, output, \"invalid_auth\");\n }\n // Schemas may use Redacted for auth. Only this checked value, never material/setup/binding,\n // is exposed to the command handler.\n return { methodId: method.identifier, value };\n});\n\nconst find = (plugins: readonly Plugin.Any[], pin: Pin) => {\n for (const provider of plugins) {\n const channel = provider.agentChannels.find(\n channel => `${provider.identifier}/${channel.identifier}` === pin.channelId,\n );\n if (channel !== undefined) return { definition: channel.definition, provider };\n }\n return undefined;\n};\n\n/** Build from the installed plugins. */\nexport const layer = <P extends Plugin.Any>(\n plugins: readonly P[],\n): Layer.Layer<Service, never, Requirements<P>> =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const context = yield* Effect.context<Requirements<P>>();\n const get = Effect.fn(\"AgentChannelRuntime.get\")(function* (input: unknown) {\n const pin = yield* decode(Pin, input, \"invalid_input\");\n const found = find(plugins, pin);\n if (found === undefined) return yield* fail(\"not_found\");\n yield* safe(\n Effect.sync(() => {\n AgentChannel.validateDefinition(\n found.definition,\n found.provider.identifier,\n found.provider.authMethods,\n );\n }),\n \"invalid_definition\",\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(pin.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (\n Option.isNone(handler) ||\n !Predicate.isObject(handler.value.runtime) ||\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n return found.definition;\n });\n const checkAccess = Effect.fn(\"AgentChannelRuntime.checkAccess\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(AccessInput, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n if (!checkMessage(definition.features, request.identity.conversation, { text: \"\" })) {\n return yield* fail(\"unsupported_feature\");\n }\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n \"check_access\",\n request.context,\n );\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(request.identity, {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n }),\n ),\n );\n return yield* decodeData(AgentChannel.AccessOutcome, output, \"invalid_result\");\n });\n const execute = Effect.fn(\"AgentChannelRuntime.execute\")(function* (input: unknown) {\n yield* json(input, \"invalid_input\");\n const request = yield* decode(Input, input, \"invalid_input\");\n const definition = yield* get({ channelId: request.channelId });\n const found = find(plugins, request);\n if (found === undefined) return yield* fail(\"not_found\");\n const definitionSettings = yield* decodeData(\n definition.definitionSettings,\n request.definitionSettings,\n \"invalid_input\",\n );\n const deploymentSettings = yield* decodeData(\n definition.deploymentSettings,\n request.deploymentSettings,\n \"invalid_input\",\n );\n const schemas = AgentChannel.schemasFor(definition);\n const command: AgentChannel.Command | AgentChannel.CommandV2 = yield* decodeData(\n schemas.command,\n request.command,\n \"invalid_input\",\n );\n yield* checkExtensions(definition, command.extensions, \"invalid_input\");\n if (command.kind === \"deliver\" && command.operationKey !== command.deliveryKey) {\n return yield* fail(\"invalid_input\");\n }\n if (command.kind === \"deliver\" && !checkDelivery(definition.features, command)) {\n return yield* fail(\"unsupported_feature\");\n }\n if (\n command.kind === \"deliver\" &&\n \"operation\" in command &&\n command.operation.kind === \"set_reaction\" &&\n command.operation.target.kind === \"activation\" &&\n command.activationMessageKey === undefined\n ) {\n return yield* fail(\"invalid_input\");\n }\n if (\n command.kind === \"read_context\" &&\n (definition.features.readContext !== true ||\n !checkMessage(definition.features, command.destination, { text: \"\" }))\n ) {\n return yield* fail(\"unsupported_feature\");\n }\n const handler = Option.fromNullishOr(\n findHandler(\n context,\n found.provider.identifier,\n AgentChannel.handlerKey(request.channelId),\n ) as AgentChannel.Handler | undefined,\n );\n if (Option.isNone(handler)) return yield* fail(\"handler_unavailable\");\n const auth = yield* resolveAuth(\n found.provider.identifier,\n request.channelId,\n definition,\n request.connectionId,\n command.kind,\n request.context,\n );\n // Keep correlation facts independent of any mutation by provider code.\n const operationKey = command.operationKey;\n const kind = command.kind;\n const deliveryKey = command.kind === \"deliver\" ? command.deliveryKey : undefined;\n const assetKey = command.kind === \"read_asset\" ? command.asset.assetKey : undefined;\n const adapterContext = {\n definitionSettings,\n deploymentSettings,\n ...(auth === undefined ? {} : { auth }),\n };\n if (\n !Predicate.isFunction(handler.value.runtime.execute) ||\n !Predicate.isFunction(handler.value.runtime.verify) ||\n !Predicate.isFunction(handler.value.runtime.checkAccess)\n ) {\n return yield* fail(\"handler_unavailable\");\n }\n if (command.kind === \"receive\") {\n yield* decodeData(\n AgentChannel.Verification,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.verify(command.request, adapterContext)),\n ),\n \"invalid_result\",\n );\n }\n if (command.kind === \"read_asset\") {\n if (!definition.features.assets) return yield* fail(\"unsupported_feature\");\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() =>\n handler.value.runtime.checkAccess(command.identity, adapterContext),\n ),\n ),\n \"invalid_result\",\n );\n if (decision.decision !== \"allow\") {\n return yield* new AgentChannel.ChannelError({\n code: \"provider_failure\",\n providerCode: \"unauthorized\",\n });\n }\n }\n const output = yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.execute(command, adapterContext)),\n );\n const result: AgentChannel.Result | AgentChannel.ResultV2 = yield* decodeData(\n schemas.typeResult,\n output,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n if (\n result.kind !== kind ||\n result.operationKey !== operationKey ||\n (result.kind === \"deliver\" && result.deliveryKey !== deliveryKey) ||\n (result.kind === \"read_asset\" && result.assetKey !== assetKey)\n ) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, result.extensions, \"invalid_result\");\n if (\n result.kind === \"deliver\" &&\n result.status === \"pending\" &&\n !definition.features.deliveryState\n ) {\n return yield* fail(\"invalid_result\");\n }\n const allowedEvents: AgentChannel.EventV2[] = [];\n const deniedEventKeys: string[] = [];\n if (result.kind === \"receive\") {\n if (result.deniedEventKeys !== undefined) return yield* fail(\"invalid_result\");\n if (\n result.activationProof === \"verified\" &&\n (result.response === undefined || result.events.length !== 0)\n ) {\n return yield* fail(\"invalid_result\");\n }\n const eventKeys = new Set<string>();\n for (const event of result.events) {\n if (eventKeys.has(event.eventKey)) return yield* fail(\"invalid_result\");\n eventKeys.add(event.eventKey);\n if (\n event.kind === \"message\" &&\n !checkMessage(definition.features, event.conversation, event.content)\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (\n (event.kind === \"echo\" || event.kind === \"stop\") &&\n !checkMessage(definition.features, event.conversation, { text: \"\" })\n ) {\n return yield* fail(\"invalid_result\");\n }\n if (event.kind === \"delivery_update\" && !definition.features.deliveryState) {\n return yield* fail(\"invalid_result\");\n }\n yield* checkExtensions(definition, event.extensions, \"invalid_result\");\n let denied = false;\n if (event.kind === \"message\" || event.kind === \"echo\" || event.kind === \"stop\") {\n const identity = yield* decodeData(\n AgentChannel.VerifiedIdentity,\n { conversation: event.conversation, senderKey: event.senderKey },\n \"invalid_result\",\n );\n const decision = yield* decodeData(\n AgentChannel.AccessOutcome,\n yield* invokeHandler(\n handler.value,\n Effect.suspend(() => handler.value.runtime.checkAccess(identity, adapterContext)),\n ),\n \"invalid_result\",\n );\n denied = decision.decision === \"deny\";\n }\n if (denied) {\n deniedEventKeys.push(event.eventKey);\n continue;\n }\n allowedEvents.push(event);\n }\n }\n // Store the encoded state so subsequent pinned commands can decode it exactly once.\n const encoded = yield* safe(\n Schema.encodeUnknownEffect(schemas.result)(\n result.kind === \"receive\"\n ? {\n ...result,\n events: allowedEvents,\n ...(deniedEventKeys.length === 0 ? {} : { deniedEventKeys }),\n }\n : result,\n strict,\n ),\n \"invalid_result\",\n );\n return yield* decodeData(\n AgentChannel.CheckedResult,\n encoded,\n \"invalid_result\",\n kind === \"read_asset\",\n );\n });\n // SAFETY: Requirements above account for each schema, auth method and Channel handler. The\n // dynamic lookup erases their union; the captured application context discharges it here.\n const run = <A>(\n effect: Effect.Effect<A, AgentChannel.ChannelError, unknown>,\n ): Effect.Effect<A, AgentChannel.ChannelError> =>\n // @effect-diagnostics-next-line unsafeEffectTypeAssertion:off -- Channel handlers are checked and their captured context satisfies the declared Requirements (SAFETY above).\n effect.pipe(Effect.provideContext(context)) as Effect.Effect<A, AgentChannel.ChannelError>;\n const decodeSettings = (field: \"definitionSettings\" | \"deploymentSettings\") =>\n Effect.fn(\"AgentChannelRuntime.decodeSettings\")(function* (input: unknown) {\n const request = yield* decode(\n Schema.Struct({ ...Pin.fields, value: Schema.Json }),\n input,\n \"invalid_input\",\n );\n const definition = yield* get({ channelId: request.channelId });\n const schema = definition[field];\n const value = yield* decodeData(schema, request.value, \"invalid_input\");\n return yield* json(\n yield* safe(Schema.encodeUnknownEffect(schema)(value, strict), \"invalid_input\"),\n \"invalid_input\",\n );\n });\n return Service.of({\n checkAccess: input => run(checkAccess(input)),\n decodeDefinitionSettings: input => run(decodeSettings(\"definitionSettings\")(input)),\n decodeDeploymentSettings: input => run(decodeSettings(\"deploymentSettings\")(input)),\n execute: input => run(execute(input)),\n get: input => run(get(input)),\n });\n }),\n );\n\nexport * as AgentChannelRuntime from \"./AgentChannelRuntime.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAa,oBAAoB,OAAO,OAAO;CAC7C,OAAO,OAAO,YACZ,OAAO,MAAM,CACX,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,MAAM;EAAG,QAAQA;CAAiB,CAAC,GACxE,OAAO,OAAO;EACZ,MAAM,OAAO,QAAQ,QAAQ;EAC7B,QAAQ,OAAO,YAAYA,GAAgB;CAC7C,CAAC,CACH,CAAC,CACH;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,MAAMA;EAAkB,WAAW,OAAO,YAAYA,GAAgB;CAAE,CAAC,CAC3F;CACA,QAAQ,OAAO,YACb,OAAO,OAAO;EAAE,gBAAgBA;EAAkB,QAAQ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