agents 0.26.0 → 0.27.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 (233) hide show
  1. package/README.md +8 -9
  2. package/dist/{agent-routing-0DR0Tk2v.d.ts → agent-routing-Bhdbvf7s.d.ts} +13 -8
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +1 -1
  5. package/dist/{agent-tools-YrATZJu2.d.ts → agent-tools-bJZwBMfq.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/ai-sdk-OoGkFy3s.js +2444 -0
  8. package/dist/ai-sdk-OoGkFy3s.js.map +1 -0
  9. package/dist/apply-chunks-1FheRb9W.js +99 -0
  10. package/dist/apply-chunks-1FheRb9W.js.map +1 -0
  11. package/dist/broadcast-state-CEyI4uAK.js +69 -0
  12. package/dist/broadcast-state-CEyI4uAK.js.map +1 -0
  13. package/dist/browser/ai-sdk.d.ts +1 -1
  14. package/dist/browser/ai-sdk.js +2 -2
  15. package/dist/browser/ai-sdk.js.map +1 -1
  16. package/dist/browser/index.d.ts +1 -1
  17. package/dist/browser/tanstack-ai.d.ts +1 -1
  18. package/dist/browser/tanstack-ai.js +1 -1
  19. package/dist/{browser-DE3d-RLk.d.ts → browser-tmkcAAI3.d.ts} +2 -2
  20. package/dist/{browser-tool-DuNdlwZ9.d.ts → browser-tool-Bn-nzJQI.d.ts} +3 -3
  21. package/dist/{browser-tool-CQ10e6Kj.js → browser-tool-CBqs6hqa.js} +58 -18
  22. package/dist/browser-tool-CBqs6hqa.js.map +1 -0
  23. package/dist/capability-B4WbF81e.js.map +1 -1
  24. package/dist/{capability-runner-DBAnGr6L.d.ts → capability-runner-O5VbQzqg.d.ts} +9 -1
  25. package/dist/channel-Bak_6zDP.d.ts +333 -0
  26. package/dist/chat/index.d.ts +11 -9
  27. package/dist/chat/index.js +5 -194
  28. package/dist/chat/index.js.map +1 -1
  29. package/dist/chat/react.d.ts +2 -4
  30. package/dist/chat/react.js +3 -1
  31. package/dist/chat/react.js.map +1 -1
  32. package/dist/chat-sdk/index.d.ts +1 -1
  33. package/dist/chat-sdk/index.js +1 -1
  34. package/dist/cli.js +144 -0
  35. package/dist/{client-fyQrLGkD.js → client-1tEQ1Oqz.js} +27 -2
  36. package/dist/{client-fyQrLGkD.js.map → client-1tEQ1Oqz.js.map} +1 -1
  37. package/dist/{client-je3koD9Z.d.ts → client-DS3Dz9l0.d.ts} +2 -2
  38. package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
  39. package/dist/client.d.ts +1 -1
  40. package/dist/conversations-DH0ut_8n.d.ts +192 -0
  41. package/dist/{current-agent-vAk_5JMt.d.ts → current-agent-C07C5o5Y.d.ts} +3 -3
  42. package/dist/daemon-core-Buubj-y1.js +481 -0
  43. package/dist/daemon-core-Buubj-y1.js.map +1 -0
  44. package/dist/daemon-core-CbohVPAu.d.ts +132 -0
  45. package/dist/{do-oauth-client-provider-Tmf1vgKz.d.ts → do-oauth-client-provider-DfsUcpc3.d.ts} +7 -1
  46. package/dist/{durable-object-lifecycle-HhgOMWq9.d.ts → durable-object-lifecycle-DRqp475_.d.ts} +2 -2
  47. package/dist/{channels/email.d.ts → experimental/channels/email/index.d.ts} +25 -12
  48. package/dist/{channels/email.js → experimental/channels/email/index.js} +13 -35
  49. package/dist/experimental/channels/email/index.js.map +1 -0
  50. package/dist/experimental/channels/index.d.ts +270 -0
  51. package/dist/experimental/channels/index.js +1186 -0
  52. package/dist/experimental/channels/index.js.map +1 -0
  53. package/dist/{channels/slack.d.ts → experimental/channels/slack/index.d.ts} +19 -9
  54. package/dist/experimental/channels/slack/index.js +267 -0
  55. package/dist/experimental/channels/slack/index.js.map +1 -0
  56. package/dist/{channels/telegram.d.ts → experimental/channels/telegram/index.d.ts} +19 -9
  57. package/dist/experimental/channels/telegram/index.js +198 -0
  58. package/dist/experimental/channels/telegram/index.js.map +1 -0
  59. package/dist/experimental/channels/web/ai-sdk.d.ts +55 -0
  60. package/dist/experimental/channels/web/ai-sdk.js +266 -0
  61. package/dist/experimental/channels/web/ai-sdk.js.map +1 -0
  62. package/dist/experimental/channels/web/client.d.ts +97 -0
  63. package/dist/experimental/channels/web/client.js +349 -0
  64. package/dist/experimental/channels/web/client.js.map +1 -0
  65. package/dist/experimental/channels/web/index.d.ts +189 -0
  66. package/dist/experimental/channels/web/index.js +332 -0
  67. package/dist/experimental/channels/web/index.js.map +1 -0
  68. package/dist/gateway-BDC07gYO.d.ts +100 -0
  69. package/dist/handle-zAzh0UW2.d.ts +460 -0
  70. package/dist/harness/ai-sdk/index.d.ts +175 -0
  71. package/dist/harness/ai-sdk/index.js +605 -0
  72. package/dist/harness/ai-sdk/index.js.map +1 -0
  73. package/dist/harness/container/daemon/index.d.ts +76 -0
  74. package/dist/harness/container/daemon/index.js +3 -0
  75. package/dist/harness/container/index.d.ts +740 -0
  76. package/dist/harness/container/index.js +2152 -0
  77. package/dist/harness/container/index.js.map +1 -0
  78. package/dist/harness/container/runtime/index.d.ts +144 -0
  79. package/dist/harness/container/runtime/index.js +1082 -0
  80. package/dist/harness/container/runtime/index.js.map +1 -0
  81. package/dist/harness/opencode/index.d.ts +369 -0
  82. package/dist/harness/opencode/index.js +1072 -0
  83. package/dist/harness/opencode/index.js.map +1 -0
  84. package/dist/harness/pi/index.d.ts +2 -1
  85. package/dist/harness/store/index.d.ts +24 -0
  86. package/dist/harness/store/index.js +2 -0
  87. package/dist/harness/think/index.d.ts +821 -0
  88. package/dist/harness/think/index.js +2529 -0
  89. package/dist/harness/think/index.js.map +1 -0
  90. package/dist/harness-B6B9S3rb.d.ts +203 -0
  91. package/dist/{images-iiTDSyRu.js → images-Ce9SCu3X.js} +2 -248
  92. package/dist/images-Ce9SCu3X.js.map +1 -0
  93. package/dist/{index-BreL0YrQ.d.ts → index-D0A5tbWu.d.ts} +2 -2
  94. package/dist/index-Ib_4dwOo.d.ts +200 -0
  95. package/dist/index.d.ts +5 -5
  96. package/dist/index.js +2 -2
  97. package/dist/ingress-EFbrS547.js +9 -0
  98. package/dist/ingress-EFbrS547.js.map +1 -0
  99. package/dist/input-schema-DNrpTu49.js +23 -0
  100. package/dist/input-schema-DNrpTu49.js.map +1 -0
  101. package/dist/internal-kmw70xwR.js +46 -0
  102. package/dist/internal-kmw70xwR.js.map +1 -0
  103. package/dist/internal_context.d.ts +1 -1
  104. package/dist/lifecycle/index.d.ts +3 -3
  105. package/dist/mcp/client/do-oauth-client-provider.d.ts +1 -1
  106. package/dist/mcp/client/do-oauth-client-provider.js +9 -0
  107. package/dist/mcp/client/do-oauth-client-provider.js.map +1 -1
  108. package/dist/mcp/client/index.d.ts +1 -1
  109. package/dist/mcp/client/index.js +1 -1
  110. package/dist/mcp/client/x402.d.ts +35 -4
  111. package/dist/mcp/client/x402.js +24 -3
  112. package/dist/mcp/client/x402.js.map +1 -1
  113. package/dist/mcp/index.d.ts +1 -1
  114. package/dist/mcp/index.js +2 -2
  115. package/dist/models/ai-sdk/index.d.ts +16 -14
  116. package/dist/models/ai-sdk/index.js +1 -2442
  117. package/dist/models/opencode/index.d.ts +65 -0
  118. package/dist/models/opencode/index.js +285 -0
  119. package/dist/models/opencode/index.js.map +1 -0
  120. package/dist/models/pi-ai/index.d.ts +9 -7
  121. package/dist/models/pi-ai/index.js +2 -1
  122. package/dist/models/pi-ai/index.js.map +1 -1
  123. package/dist/options-pwTNq9z6.d.ts +134 -0
  124. package/dist/protocol-BEgrJYC5.d.ts +331 -0
  125. package/dist/protocol-CukuI73M.d.ts +386 -0
  126. package/dist/protocol-cOklVBBD.js +227 -0
  127. package/dist/protocol-cOklVBBD.js.map +1 -0
  128. package/dist/{protocol-kHsr-f0X.js → protocol-eXeJxhgu.js} +2 -67
  129. package/dist/protocol-eXeJxhgu.js.map +1 -0
  130. package/dist/protocol-y2sSY584.js +148 -0
  131. package/dist/protocol-y2sSY584.js.map +1 -0
  132. package/dist/queue/index.d.ts +1 -1
  133. package/dist/react.d.ts +2 -2
  134. package/dist/routing/index.d.ts +2 -2
  135. package/dist/{scheduler-RdACNXDP.d.ts → scheduler-CrFCnv_J.d.ts} +2 -2
  136. package/dist/schedules/index.d.ts +1 -1
  137. package/dist/serializable.d.ts +1 -1
  138. package/dist/sessions/index.d.ts +11 -434
  139. package/dist/sessions/index.js +1 -2271
  140. package/dist/sessions-B9pNuxdT.js +2272 -0
  141. package/dist/sessions-B9pNuxdT.js.map +1 -0
  142. package/dist/settings-C45hDliX.js +253 -0
  143. package/dist/settings-C45hDliX.js.map +1 -0
  144. package/dist/{transport-PfFnt-Ld.d.ts → settings-NgGwF7Qt.d.ts} +14 -208
  145. package/dist/{src-BZeu-SCD.js → src-DgCbZtIR.js} +4 -4
  146. package/dist/{src-BZeu-SCD.js.map → src-DgCbZtIR.js.map} +1 -1
  147. package/dist/stall-watchdog-BpRF2uwG.js +195 -0
  148. package/dist/stall-watchdog-BpRF2uwG.js.map +1 -0
  149. package/dist/state/index.d.ts +1 -1
  150. package/dist/store-DLeqKuj3.d.ts +310 -0
  151. package/dist/store-vgcPYo8K.js +432 -0
  152. package/dist/store-vgcPYo8K.js.map +1 -0
  153. package/dist/streams/index.d.ts +1 -1
  154. package/dist/streams/index.js +1 -1
  155. package/dist/{streams-DW-UCOUc.js → streams-CITClVer.js} +16 -3
  156. package/dist/streams-CITClVer.js.map +1 -0
  157. package/dist/{streams-Cmkj9QfW.d.ts → streams-fbG61qM8.d.ts} +2 -2
  158. package/dist/sub-routing.d.ts +1 -1
  159. package/dist/tasks/index.d.ts +1 -1
  160. package/dist/tasks/index.js +1 -1
  161. package/dist/{tasks-68DESxf0.js → tasks-CkTZNaV1.js} +2 -1
  162. package/dist/tasks-CkTZNaV1.js.map +1 -0
  163. package/dist/{tasks-9YxYtByh.d.ts → tasks-PtlB4Uyn.d.ts} +2 -2
  164. package/dist/tool-3PA8xjB_.js +421 -0
  165. package/dist/tool-3PA8xjB_.js.map +1 -0
  166. package/dist/tool-BPJEbwaX.d.ts +278 -0
  167. package/dist/transport-k2mFrtL8.d.ts +200 -0
  168. package/dist/turns-DCV3ycDl.js +317 -0
  169. package/dist/turns-DCV3ycDl.js.map +1 -0
  170. package/dist/voice/client.js +1 -1
  171. package/dist/voice/index.d.ts +2 -2
  172. package/dist/voice/index.js +1 -1
  173. package/dist/websearch/index.d.ts +58 -0
  174. package/dist/websearch/index.js +2 -0
  175. package/dist/websearch/tools/ai-sdk.d.ts +77 -0
  176. package/dist/websearch/tools/ai-sdk.js +46 -0
  177. package/dist/websearch/tools/ai-sdk.js.map +1 -0
  178. package/dist/websearch/tools/pi.d.ts +82 -0
  179. package/dist/websearch/tools/pi.js +89 -0
  180. package/dist/websearch/tools/pi.js.map +1 -0
  181. package/dist/websearch/tools/tanstack-ai.d.ts +71 -0
  182. package/dist/websearch/tools/tanstack-ai.js +46 -0
  183. package/dist/websearch/tools/tanstack-ai.js.map +1 -0
  184. package/dist/websockets/index.d.ts +12 -296
  185. package/dist/websockets/index.js +1 -1
  186. package/dist/{websockets-Ci-LZFHH.js → websockets-CmENGb-Z.js} +18 -4
  187. package/dist/websockets-CmENGb-Z.js.map +1 -0
  188. package/dist/{wire-types-CrjKvDyi.d.ts → wire-types-Cv0iwjk5.d.ts} +3 -51
  189. package/dist/workflow-types.d.ts +1 -1
  190. package/dist/workflows.d.ts +1 -1
  191. package/dist/workflows.js +1 -1
  192. package/docs/browse-the-web.md +3 -0
  193. package/docs/harnesses/think.md +215 -0
  194. package/docs/index.md +2 -1
  195. package/docs/lifecycle.md +40 -0
  196. package/docs/search-the-web.md +133 -0
  197. package/package.json +117 -38
  198. package/dist/browser-tool-CQ10e6Kj.js.map +0 -1
  199. package/dist/channel-Bnm4S7T2.d.ts +0 -491
  200. package/dist/channels/ai-sdk.d.ts +0 -46
  201. package/dist/channels/ai-sdk.js +0 -120
  202. package/dist/channels/ai-sdk.js.map +0 -1
  203. package/dist/channels/email.js.map +0 -1
  204. package/dist/channels/index.d.ts +0 -233
  205. package/dist/channels/index.js +0 -608
  206. package/dist/channels/index.js.map +0 -1
  207. package/dist/channels/slack.js +0 -614
  208. package/dist/channels/slack.js.map +0 -1
  209. package/dist/channels/tanstack-ai.d.ts +0 -39
  210. package/dist/channels/tanstack-ai.js +0 -17
  211. package/dist/channels/tanstack-ai.js.map +0 -1
  212. package/dist/channels/telegram.js +0 -427
  213. package/dist/channels/telegram.js.map +0 -1
  214. package/dist/channels/voice.d.ts +0 -45
  215. package/dist/channels/voice.js +0 -122
  216. package/dist/channels/voice.js.map +0 -1
  217. package/dist/images-iiTDSyRu.js.map +0 -1
  218. package/dist/index-BB0kqhIz.d.ts +0 -101
  219. package/dist/ingress-BfetZbMO.js +0 -83
  220. package/dist/ingress-BfetZbMO.js.map +0 -1
  221. package/dist/internal-CYlgHl1l.js +0 -59
  222. package/dist/internal-CYlgHl1l.js.map +0 -1
  223. package/dist/models/ai-sdk/index.js.map +0 -1
  224. package/dist/protocol-kHsr-f0X.js.map +0 -1
  225. package/dist/sessions/index.js.map +0 -1
  226. package/dist/streams-DW-UCOUc.js.map +0 -1
  227. package/dist/surface-bZZJqBka.js +0 -17
  228. package/dist/surface-bZZJqBka.js.map +0 -1
  229. package/dist/tasks-68DESxf0.js.map +0 -1
  230. package/dist/tool-schema-CBjGPrsQ.js +0 -31
  231. package/dist/tool-schema-CBjGPrsQ.js.map +0 -1
  232. package/dist/websockets-Ci-LZFHH.js.map +0 -1
  233. package/docs/channels.md +0 -323
@@ -80,6 +80,12 @@ declare class DurableObjectOAuthClientProvider implements AgentMcpOAuthProvider
80
80
  invalidateCredentials(
81
81
  scope: "all" | "client" | "tokens" | "verifier" | "discovery"
82
82
  ): Promise<void>;
83
+ /**
84
+ * Delete every key this provider stores for its server: tokens and client
85
+ * info for any client ID, verifiers, pending states and discovery state.
86
+ * Used when the server is removed. Other servers' keys are untouched.
87
+ */
88
+ clearServerStorage(): Promise<void>;
83
89
  codeVerifierKey(clientId: string): string;
84
90
  stateCodeVerifierPrefix(clientId: string): string;
85
91
  stateCodeVerifierKey(clientId: string, nonce: string): string;
@@ -107,4 +113,4 @@ export {
107
113
  DurableObjectOAuthClientProvider as r,
108
114
  AgentMcpOAuthProvider as t
109
115
  };
110
- //# sourceMappingURL=do-oauth-client-provider-Tmf1vgKz.d.ts.map
116
+ //# sourceMappingURL=do-oauth-client-provider-DfsUcpc3.d.ts.map
@@ -3,7 +3,7 @@ import {
3
3
  b as LifecycleJobs,
4
4
  i as DurableObjectCapability,
5
5
  u as LifecycleRouteAddress
6
- } from "./capability-runner-DBAnGr6L.js";
6
+ } from "./capability-runner-O5VbQzqg.js";
7
7
  import { DurableObject } from "cloudflare:workers";
8
8
 
9
9
  //#region src/lifecycle/durable-object-lifecycle.d.ts
@@ -162,4 +162,4 @@ declare class Lifecycle<
162
162
  }
163
163
  //#endregion
164
164
  export { LifecycleOptions as n, LifecycleRouteEnvelope as r, Lifecycle as t };
165
- //# sourceMappingURL=durable-object-lifecycle-HhgOMWq9.d.ts.map
165
+ //# sourceMappingURL=durable-object-lifecycle-DRqp475_.d.ts.map
@@ -1,13 +1,16 @@
1
1
  import {
2
- F as ChannelMessageSurface,
3
- I as ChannelMessageSurfaceInput,
4
- S as ChannelEmailIngress,
5
- d as ChannelRoute,
6
- n as Channel
7
- } from "../channel-Bnm4S7T2.js";
2
+ b as ChannelEmailIngress,
3
+ c as ChannelRoute,
4
+ n as Channel,
5
+ s as ChannelParticipant
6
+ } from "../../../channel-Bak_6zDP.js";
7
+ import {
8
+ b as ChannelMessageSurface,
9
+ x as ChannelMessageSurfaceInput
10
+ } from "../../../protocol-CukuI73M.js";
8
11
  import { Email } from "postal-mime";
9
12
 
10
- //#region src/channels/adapters/email/email-surface.d.ts
13
+ //#region src/experimental/channels/email/email-surface.d.ts
11
14
  type EmailSurfaceAddress =
12
15
  | string
13
16
  | {
@@ -31,7 +34,7 @@ type EmailMessageAddress = {
31
34
  type EmailMessageSurface = ChannelMessageSurface<string, EmailMessageAddress>;
32
35
  type EmailMessageSurfaceInput = ChannelMessageSurfaceInput<EmailMessageAddress>;
33
36
  //#endregion
34
- //#region src/channels/adapters/email/inbound-email.d.ts
37
+ //#region src/experimental/channels/email/inbound-email.d.ts
35
38
  /** Parsed, provider-specific email retained while selecting an application route. */
36
39
  type InboundEmailRaw = Email;
37
40
  type InboundEmailOptions = {
@@ -46,7 +49,7 @@ declare function inboundEmail(
46
49
  options?: InboundEmailOptions
47
50
  ): ChannelEmailIngress<InboundEmailRaw>;
48
51
  //#endregion
49
- //#region src/channels/adapters/email/email.d.ts
52
+ //#region src/experimental/channels/email/email.d.ts
50
53
  type EmailAddress = EmailSurfaceAddress;
51
54
  type EmailRecipients = EmailSurfaceRecipients;
52
55
  type ChannelEmailMessage = {
@@ -69,8 +72,18 @@ interface EmailSendBinding {
69
72
  type EmailChannelOptions = {
70
73
  binding: EmailSendBinding;
71
74
  from: EmailAddress /** Subject used when a message does not provide a title. */;
72
- defaultTitle?: string /** Select an application route from the event, parsed email, and Host context. */;
73
- route?: ChannelRoute<InboundEmailRaw> /** Override inferred Workers Email ingress addresses. */;
75
+ defaultTitle?: string;
76
+ /**
77
+ * Who sent an inbound email. Set it to receive email. The envelope sender
78
+ * is not authenticated, so decide how far to trust it. Return null to drop
79
+ * the email.
80
+ */
81
+ participant?: ChannelParticipant<InboundEmailRaw>;
82
+ /**
83
+ * Pick the agent object an email reaches. Default: a room of the
84
+ * participant's own.
85
+ */
86
+ route?: ChannelRoute<InboundEmailRaw> /** Override inferred Workers Email ingress addresses. Needs `participant`. */;
74
87
  inbound?: InboundEmailOptions;
75
88
  };
76
89
  /** Create a configured email Channel. */
@@ -92,4 +105,4 @@ export {
92
105
  email,
93
106
  inboundEmail
94
107
  };
95
- //# sourceMappingURL=email.d.ts.map
108
+ //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
- import { l as utf8ByteLength, o as renderInput } from "../internal-CYlgHl1l.js";
1
+ import { s as utf8ByteLength } from "../../../internal-kmw70xwR.js";
2
2
  import PostalMime from "postal-mime";
3
- //#region src/channels/adapters/email/inbound-email.ts
3
+ //#region src/experimental/channels/email/inbound-email.ts
4
4
  const EMAIL_HEADER_VALUE_LIMIT$1 = 2048;
5
5
  function normalizeReference(value) {
6
6
  return value?.trim().replace(/^<|>$/g, "") || void 0;
@@ -132,19 +132,9 @@ function inboundEmail(options = {}) {
132
132
  } };
133
133
  }
134
134
  //#endregion
135
- //#region src/channels/adapters/email/email.ts
135
+ //#region src/experimental/channels/email/email.ts
136
136
  const DEFAULT_EMAIL_TITLE = "Agent message";
137
137
  const EMAIL_HEADER_VALUE_LIMIT = 2048;
138
- function approvalLinksUnavailable(retryable = false) {
139
- return {
140
- status: "failed",
141
- retryable,
142
- error: {
143
- code: "APPROVAL_LINKS_UNAVAILABLE",
144
- message: "Email approval requests require caller-supplied approval links"
145
- }
146
- };
147
- }
148
138
  const PERMANENT_EMAIL_ERRORS = /* @__PURE__ */ new Set([
149
139
  "E_VALIDATION_ERROR",
150
140
  "E_FIELD_MISSING",
@@ -278,13 +268,17 @@ function email(options) {
278
268
  return classifyEmailDeliveryError(error);
279
269
  }
280
270
  }
271
+ if (options.inbound && !options.participant) throw new Error("participant is required to receive email");
281
272
  return {
273
+ ...options.participant && {
274
+ participant: options.participant,
275
+ emailIngress: inboundEmail({
276
+ to: options.inbound?.to,
277
+ from: options.inbound?.from,
278
+ replyFrom: options.from
279
+ })
280
+ },
282
281
  ...options.route && { route: options.route },
283
- emailIngress: inboundEmail({
284
- to: options.inbound?.to,
285
- from: options.inbound?.from,
286
- replyFrom: options.from
287
- }),
288
282
  contactSurface(identity) {
289
283
  if ((identity.scope ?? "default") !== "default") return null;
290
284
  return {
@@ -298,26 +292,10 @@ function email(options) {
298
292
  },
299
293
  deliver(destination, message) {
300
294
  return send(destination, message.title, message.markdown);
301
- },
302
- async requestApproval(destination, { request, getApprovalLinks }) {
303
- if (!getApprovalLinks) return approvalLinksUnavailable();
304
- let links;
305
- try {
306
- links = await getApprovalLinks();
307
- } catch {
308
- return approvalLinksUnavailable(true);
309
- }
310
- const text = [
311
- request.summary,
312
- `Input:\n${renderInput(request.input)}`,
313
- `Approve: ${links.approve}`,
314
- `Reject: ${links.reject}`
315
- ].join("\n\n");
316
- return send(destination, request.title, text);
317
295
  }
318
296
  };
319
297
  }
320
298
  //#endregion
321
299
  export { email, inboundEmail };
322
300
 
323
- //# sourceMappingURL=email.js.map
301
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["EMAIL_HEADER_VALUE_LIMIT"],"sources":["../../../../src/experimental/channels/email/inbound-email.ts","../../../../src/experimental/channels/email/email.ts"],"sourcesContent":["import PostalMime from \"postal-mime\";\nimport type {\n Attachment as PostalMimeAttachment,\n Email as PostalMimeEmail,\n Header as PostalMimeHeader\n} from \"postal-mime\";\nimport type {\n EmailMessageSurfaceInput,\n EmailSurfaceAddress,\n EmailSurfaceRecipients\n} from \"./email-surface\";\nimport { utf8ByteLength } from \"../internal\";\nimport type {\n ChannelAttachment,\n ChannelEmailIngress,\n ChannelEmailInput,\n ChannelInboundMessageInput\n} from \"../ingress\";\n\n/** Parsed, provider-specific email retained while selecting an application route. */\nexport type InboundEmailRaw = PostalMimeEmail;\n\nconst EMAIL_HEADER_VALUE_LIMIT = 2048;\n\nexport type InboundEmailOptions = {\n /** Only accept messages delivered to this address. */\n to?: string;\n /** Only accept these envelope senders. */\n from?: string | readonly string[];\n /** Outbound sender to retain in normalized reply surfaces. */\n replyFrom?: EmailSurfaceAddress;\n};\n\nfunction normalizeReference(value: string | undefined): string | undefined {\n const normalized = value?.trim().replace(/^<|>$/g, \"\");\n return normalized || undefined;\n}\n\nfunction emailReferences(value: string | undefined): string[] {\n const bracketed = value?.match(/<([^<>]+)>/g);\n const values = bracketed ?? value?.trim().split(/\\s+/) ?? [];\n return values.flatMap((reference) => {\n const normalized = normalizeReference(reference);\n return normalized ? [normalized] : [];\n });\n}\n\nfunction firstReference(value: string | undefined): string | undefined {\n return emailReferences(value)[0];\n}\n\nfunction boundedReferences(references: readonly string[]): string[] {\n const unique = [...new Set(references.filter(Boolean))];\n if (unique.length < 2) return unique;\n const selected = [unique[0]!];\n for (let index = unique.length - 1; index > 0; index -= 1) {\n const candidate = unique[index]!;\n const header = [...selected, candidate]\n .map((reference) => `<${reference}>`)\n .join(\" \");\n if (utf8ByteLength(header) <= EMAIL_HEADER_VALUE_LIMIT) {\n selected.splice(1, 0, candidate);\n }\n }\n return selected;\n}\n\nfunction isAutoReply(headers: readonly PostalMimeHeader[]): boolean {\n return headers.some((header) => {\n const key = header.key.toLowerCase();\n const value = header.value.trim().toLowerCase();\n if (key === \"auto-submitted\") return value !== \"no\";\n if (key === \"x-auto-response-suppress\") return true;\n return (\n key === \"precedence\" &&\n (value === \"bulk\" || value === \"junk\" || value === \"list\")\n );\n });\n}\n\nfunction attachmentSize(content: PostalMimeAttachment[\"content\"]): number {\n return typeof content === \"string\"\n ? utf8ByteLength(content)\n : content.byteLength;\n}\n\nfunction normalizedAttachment(\n attachment: PostalMimeAttachment\n): ChannelAttachment {\n return {\n ...(normalizeReference(attachment.contentId) && {\n id: normalizeReference(attachment.contentId)\n }),\n mediaType: attachment.mimeType,\n ...(attachment.filename && { name: attachment.filename }),\n size: attachmentSize(attachment.content),\n ...(typeof attachment.content === \"string\" &&\n attachment.mimeType.startsWith(\"text/\") && {\n text: attachment.content\n })\n };\n}\n\nfunction replyRecipients(\n replyTo: InboundEmailRaw[\"replyTo\"]\n): EmailSurfaceRecipients | undefined {\n const recipients = (replyTo ?? []).flatMap((entry) =>\n entry.address\n ? [{ email: entry.address, name: entry.name }]\n : (entry.group ?? []).map((mailbox) => ({\n email: mailbox.address,\n name: mailbox.name\n }))\n );\n return recipients.length > 0 ? recipients : undefined;\n}\n\nfunction recipientLabel(recipients: EmailSurfaceRecipients): string {\n const values = Array.isArray(recipients) ? recipients : [recipients];\n return values\n .map((recipient) =>\n typeof recipient === \"string\"\n ? recipient\n : recipient.name\n ? `${recipient.name} <${recipient.email}>`\n : recipient.email\n )\n .join(\", \");\n}\n\nfunction normalizedDate(value: string | undefined): string | undefined {\n if (!value) return undefined;\n const timestamp = Date.parse(value);\n return Number.isFinite(timestamp)\n ? new Date(timestamp).toISOString()\n : undefined;\n}\n\nasync function rawEmail(email: ChannelEmailInput): Promise<Uint8Array> {\n if (email.getRaw) return email.getRaw();\n if (email.raw) {\n return new Uint8Array(await new Response(email.raw).arrayBuffer());\n }\n throw new Error(\"Inbound email must provide raw or getRaw()\");\n}\n\nasync function contentReference(content: Uint8Array): Promise<string> {\n const bytes = new Uint8Array(content.byteLength);\n bytes.set(content);\n const digest = await crypto.subtle.digest(\"SHA-256\", bytes);\n return `sha256:${Array.from(new Uint8Array(digest), (byte) =>\n byte.toString(16).padStart(2, \"0\")\n ).join(\"\")}`;\n}\n\n/** Parse Workers Email events into normalized Channel ingress events. */\nexport function inboundEmail(\n options: InboundEmailOptions = {}\n): ChannelEmailIngress<InboundEmailRaw> {\n const recipient = options.to?.toLowerCase();\n const senders = new Set(\n (typeof options.from === \"string\"\n ? [options.from]\n : (options.from ?? [])\n ).map((sender) => sender.toLowerCase())\n );\n\n return {\n async receive(email) {\n const accepted =\n (!recipient || email.to.toLowerCase() === recipient) &&\n (senders.size === 0 || senders.has(email.from.toLowerCase()));\n if (!accepted) return null;\n\n const content = await rawEmail(email);\n const parsed = await PostalMime.parse(content);\n const text = parsed.text?.trim() ?? \"\";\n const reference =\n normalizeReference(parsed.messageId) ??\n (await contentReference(content));\n const replyReference = normalizeReference(parsed.inReplyTo);\n const threadRoot =\n firstReference(parsed.references) ?? replyReference ?? reference;\n const senderAddress = parsed.from?.address ?? email.from;\n const sentAt = normalizedDate(parsed.date);\n const references = boundedReferences([\n ...emailReferences(parsed.references),\n reference\n ]);\n const replyTo = replyRecipients(parsed.replyTo) ?? senderAddress;\n const replySurface: EmailMessageSurfaceInput = {\n version: 1,\n address: {\n from: options.replyFrom ?? email.to,\n to: replyTo,\n ...(parsed.subject && { subject: parsed.subject }),\n inReplyTo: reference,\n references: [...new Set(references)]\n },\n label: `Email · ${recipientLabel(replyTo)}`\n };\n\n const event: ChannelInboundMessageInput = {\n type: \"message\",\n eventId: reference,\n thread: {\n id: threadRoot,\n isDirectMessage: \"unknown\"\n },\n replySurface,\n actor: {\n id: senderAddress,\n identity: {\n subject: senderAddress.toLowerCase()\n },\n ...(parsed.from?.name && { fullName: parsed.from.name })\n },\n message: {\n id: reference,\n text,\n ...(parsed.subject && { title: parsed.subject }),\n attachments: parsed.attachments.map(normalizedAttachment),\n ...(replyReference && { reply: { id: replyReference } }),\n metadata: {\n ...(sentAt && { sentAt }),\n autoReply: isAutoReply(parsed.headers)\n }\n }\n };\n return { events: [{ event, raw: parsed }] };\n }\n };\n}\n","import type {\n Channel,\n ChannelParticipant,\n ChannelRoute,\n DeliveryFailure,\n DeliveryResult\n} from \"../channel\";\nimport type { ChannelIdentity } from \"../identity\";\nimport type { ChannelMessageSurface } from \"../surface\";\nimport type {\n EmailMessageSurface,\n EmailSurfaceAddress,\n EmailSurfaceRecipients\n} from \"./email-surface\";\nimport {\n inboundEmail,\n type InboundEmailOptions,\n type InboundEmailRaw\n} from \"./inbound-email\";\nimport { utf8ByteLength } from \"../internal\";\n\nexport type EmailAddress = EmailSurfaceAddress;\nexport type EmailRecipients = EmailSurfaceRecipients;\n\nexport type ChannelEmailMessage = {\n from: EmailAddress;\n to: EmailAddress | EmailAddress[];\n subject: string;\n text: string;\n replyTo?: EmailAddress;\n cc?: EmailAddress | EmailAddress[];\n bcc?: EmailAddress | EmailAddress[];\n headers?: Record<string, string>;\n};\n\n/** The structural subset of a Cloudflare Email Service binding used here. */\nexport interface EmailSendBinding {\n send(message: ChannelEmailMessage): Promise<{ messageId: string }>;\n}\n\n/** Configuration for an email Channel. */\nexport type EmailChannelOptions = {\n binding: EmailSendBinding;\n from: EmailAddress;\n /** Subject used when a message does not provide a title. */\n defaultTitle?: string;\n /**\n * Who sent an inbound email. Set it to receive email. The envelope sender\n * is not authenticated, so decide how far to trust it. Return null to drop\n * the email.\n */\n participant?: ChannelParticipant<InboundEmailRaw>;\n /**\n * Pick the agent object an email reaches. Default: a room of the\n * participant's own.\n */\n route?: ChannelRoute<InboundEmailRaw>;\n /** Override inferred Workers Email ingress addresses. Needs `participant`. */\n inbound?: InboundEmailOptions;\n};\n\nconst DEFAULT_EMAIL_TITLE = \"Agent message\";\nconst EMAIL_HEADER_VALUE_LIMIT = 2048;\n\nconst PERMANENT_EMAIL_ERRORS = new Set([\n \"E_VALIDATION_ERROR\",\n \"E_FIELD_MISSING\",\n \"E_TOO_MANY_RECIPIENTS\",\n \"E_TOO_MANY_ATTACHMENTS\",\n \"E_SENDER_NOT_VERIFIED\",\n \"E_RECIPIENT_NOT_ALLOWED\",\n \"E_RECIPIENT_SUPPRESSED\",\n \"E_SENDER_DOMAIN_NOT_AVAILABLE\",\n \"E_CONTENT_TOO_LARGE\",\n \"E_DELIVERY_FAILED\",\n \"E_HEADER_NOT_ALLOWED\",\n \"E_HEADER_USE_API_FIELD\",\n \"E_HEADER_VALUE_INVALID\",\n \"E_HEADER_VALUE_TOO_LONG\",\n \"E_HEADER_NAME_INVALID\",\n \"E_HEADERS_TOO_LARGE\",\n \"E_HEADERS_TOO_MANY\"\n]);\n\nconst RETRYABLE_EMAIL_ERRORS = new Set([\n \"E_RATE_LIMIT_EXCEEDED\",\n \"E_DAILY_LIMIT_EXCEEDED\"\n]);\n\nconst EMAIL_ERROR_MESSAGES = new Map<string, string>([\n [\n 'Email must have at least one recipient in \"to\", \"cc\", or \"bcc\".',\n \"E_FIELD_MISSING\"\n ]\n]);\n\nfunction emailFailure(error: unknown): DeliveryFailure {\n if (error !== null && typeof error === \"object\") {\n const value = error as { code?: unknown; message?: unknown };\n return {\n code:\n typeof value.code === \"string\" ? value.code : \"EMAIL_DELIVERY_ERROR\",\n message:\n typeof value.message === \"string\"\n ? value.message\n : \"Email delivery failed\"\n };\n }\n\n return {\n code: \"EMAIL_DELIVERY_ERROR\",\n message: typeof error === \"string\" ? error : \"Email delivery failed\"\n };\n}\n\n/** Classify an Email Service binding error as a model-visible result. */\nfunction classifyEmailDeliveryError(error: unknown): DeliveryResult {\n const failure = emailFailure(error);\n const inferredCode = EMAIL_ERROR_MESSAGES.get(failure.message);\n if (inferredCode) {\n return {\n status: \"failed\",\n retryable: false,\n error: { ...failure, code: inferredCode }\n };\n }\n\n if (RETRYABLE_EMAIL_ERRORS.has(failure.code)) {\n return { status: \"failed\", retryable: true, error: failure };\n }\n\n if (PERMANENT_EMAIL_ERRORS.has(failure.code)) {\n return { status: \"failed\", retryable: false, error: failure };\n }\n\n return { status: \"uncertain\", error: failure };\n}\n\nfunction emailSurface(surface: ChannelMessageSurface): EmailMessageSurface {\n return surface as EmailMessageSurface;\n}\n\nfunction mutableRecipients(\n value: EmailRecipients\n): EmailAddress | EmailAddress[] {\n return Array.isArray(value) ? [...value] : (value as EmailAddress);\n}\n\nfunction replySubject(subject: string | undefined): string | undefined {\n if (!subject) return undefined;\n return /^re:/i.test(subject) ? subject : `Re: ${subject}`;\n}\n\nfunction referenceHeader(references: readonly string[]): string | undefined {\n const unique = [...new Set(references.filter(Boolean))];\n if (unique.length === 0) return undefined;\n const root = `<${unique[0]}>`;\n if (utf8ByteLength(root) > EMAIL_HEADER_VALUE_LIMIT) return undefined;\n\n const selected = [root];\n for (let index = unique.length - 1; index > 0; index -= 1) {\n const candidate = `<${unique[index]}>`;\n if (\n utf8ByteLength([...selected, candidate].join(\" \")) <=\n EMAIL_HEADER_VALUE_LIMIT\n ) {\n selected.splice(1, 0, candidate);\n }\n }\n return selected.join(\" \");\n}\n\n/** Create a configured email Channel. */\nexport function email(options: EmailChannelOptions): Channel<InboundEmailRaw> {\n if (!options.binding) {\n throw new Error(\"binding is required to create an email channel\");\n }\n\n async function send(\n destinationValue: ChannelMessageSurface,\n title: string | undefined,\n text: string\n ): Promise<DeliveryResult> {\n const destination = emailSurface(destinationValue);\n const inReplyTo = destination.address.inReplyTo;\n const inReplyToHeader = inReplyTo ? `<${inReplyTo}>` : undefined;\n if (\n inReplyToHeader &&\n utf8ByteLength(inReplyToHeader) > EMAIL_HEADER_VALUE_LIMIT\n ) {\n return {\n status: \"failed\",\n retryable: false,\n error: {\n code: \"EMAIL_SURFACE_INVALID\",\n message: \"Email reply metadata exceeds provider header limits\"\n }\n };\n }\n const references = destination.address.references;\n const referencesHeader = references\n ? referenceHeader(references)\n : undefined;\n if (references?.length && !referencesHeader) {\n return {\n status: \"failed\",\n retryable: false,\n error: {\n code: \"EMAIL_SURFACE_INVALID\",\n message: \"Email reply metadata exceeds provider header limits\"\n }\n };\n }\n const replyHeaders = {\n ...(inReplyToHeader && { \"In-Reply-To\": inReplyToHeader }),\n ...(referencesHeader && { References: referencesHeader })\n };\n try {\n const result = await options.binding.send({\n from: destination.address.from,\n to: mutableRecipients(destination.address.to),\n subject:\n title ??\n replySubject(destination.address.subject) ??\n options.defaultTitle ??\n DEFAULT_EMAIL_TITLE,\n text,\n replyTo: destination.address.replyTo,\n cc:\n destination.address.cc === undefined\n ? undefined\n : mutableRecipients(destination.address.cc),\n bcc:\n destination.address.bcc === undefined\n ? undefined\n : mutableRecipients(destination.address.bcc),\n headers: {\n ...destination.address.headers,\n ...replyHeaders\n }\n });\n\n return { status: \"delivered\" as const, reference: result.messageId };\n } catch (error) {\n return classifyEmailDeliveryError(error);\n }\n }\n\n if (options.inbound && !options.participant) {\n throw new Error(\"participant is required to receive email\");\n }\n\n return {\n ...(options.participant && {\n participant: options.participant,\n emailIngress: inboundEmail({\n to: options.inbound?.to,\n from: options.inbound?.from,\n replyFrom: options.from\n })\n }),\n ...(options.route && { route: options.route }),\n contactSurface(identity: ChannelIdentity) {\n if ((identity.scope ?? \"default\") !== \"default\") return null;\n return {\n version: 1,\n address: { from: options.from, to: identity.subject },\n label: `Email · ${identity.subject}`\n };\n },\n deliver(destination, message) {\n return send(destination, message.title, message.markdown);\n }\n };\n}\n"],"mappings":";;;AAsBA,MAAMA,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ACzC;CACF;CAEA,IAAI,QAAQ,WAAW,CAAC,QAAQ,aAC9B,MAAM,IAAI,MAAM,0CAA0C;CAG5D,OAAO;EACL,GAAI,QAAQ,eAAe;GACzB,aAAa,QAAQ;GACrB,cAAc,aAAa;IACzB,IAAI,QAAQ,SAAS;IACrB,MAAM,QAAQ,SAAS;IACvB,WAAW,QAAQ;GACrB,CAAC;EACH;EACA,GAAI,QAAQ,SAAS,EAAE,OAAO,QAAQ,MAAM;EAC5C,eAAe,UAA2B;GACxC,KAAK,SAAS,SAAS,eAAe,WAAW,OAAO;GACxD,OAAO;IACL,SAAS;IACT,SAAS;KAAE,MAAM,QAAQ;KAAM,IAAI,SAAS;IAAQ;IACpD,OAAO,WAAW,SAAS;GAC7B;EACF;EACA,QAAQ,aAAa,SAAS;GAC5B,OAAO,KAAK,aAAa,QAAQ,OAAO,QAAQ,QAAQ;EAC1D;CACF;AACF"}
@@ -0,0 +1,270 @@
1
+ import {
2
+ A as ChannelIngressEventInput,
3
+ C as ChannelEventContext,
4
+ D as ChannelIngress,
5
+ E as ChannelInboundMessageInput,
6
+ F as identityKey,
7
+ M as matchesPath,
8
+ N as ChannelIdentity,
9
+ O as ChannelIngressEnvelope,
10
+ P as ChannelIdentityInput,
11
+ S as ChannelEmailInput,
12
+ T as ChannelInboundMessage,
13
+ _ as ChannelApprovalResponse,
14
+ a as ChannelDeliveryOptions,
15
+ b as ChannelEmailIngress,
16
+ c as ChannelRoute,
17
+ d as ChannelUpgradeMatch,
18
+ f as DeliveryFailure,
19
+ g as ChannelActorInput,
20
+ h as ChannelActor,
21
+ i as ChannelDeliveryContext,
22
+ j as ChannelIngressResult,
23
+ k as ChannelIngressEvent,
24
+ l as ChannelStreamOptions,
25
+ m as ParticipantResult,
26
+ n as Channel,
27
+ o as ChannelMessage,
28
+ p as DeliveryResult,
29
+ r as ChannelChunkSource,
30
+ s as ChannelParticipant,
31
+ t as Awaitable,
32
+ u as ChannelUpgrade,
33
+ v as ChannelApprovalResponseInput,
34
+ w as ChannelEventContextInput,
35
+ x as ChannelEmailIngressResult,
36
+ y as ChannelAttachment
37
+ } from "../../channel-Bak_6zDP.js";
38
+ import {
39
+ C as ChannelSurfaceObject,
40
+ S as ChannelSurfaceArray,
41
+ T as isChannelMessageSurface,
42
+ _ as TranscriptMessage,
43
+ a as DispatchResult,
44
+ b as ChannelMessageSurface,
45
+ c as InboundEvent,
46
+ d as JsonObject,
47
+ f as MessagePart,
48
+ g as ToolState,
49
+ h as ToolPart,
50
+ i as ConversationSnapshot,
51
+ l as Json,
52
+ m as ResponseChunk,
53
+ n as ConversationInfo,
54
+ o as EventOrigin,
55
+ p as Participant,
56
+ r as ConversationOperation,
57
+ s as GatewayOrigin,
58
+ t as ClientTool,
59
+ u as JsonArray,
60
+ v as TurnOutcome,
61
+ w as ChannelSurfaceValue,
62
+ x as ChannelMessageSurfaceInput,
63
+ y as TurnStatus
64
+ } from "../../protocol-CukuI73M.js";
65
+ import {
66
+ a as HarnessSessions,
67
+ c as OperationStatus,
68
+ d as SessionId,
69
+ f as SessionInfo,
70
+ g as ToolAnswer,
71
+ h as SubmitOptions,
72
+ i as HarnessSession,
73
+ l as Receipt,
74
+ m as SessionWatch,
75
+ n as HarnessInput,
76
+ o as InputPart,
77
+ p as SessionState,
78
+ r as HarnessInputFrom,
79
+ s as OperationResult,
80
+ t as AgentHarness,
81
+ u as SessionEvent
82
+ } from "../../harness-B6B9S3rb.js";
83
+ import {
84
+ a as ConversationChannel,
85
+ c as GatewayEvent,
86
+ i as ChannelsOptions,
87
+ l as ResponseEnding,
88
+ n as Channels,
89
+ o as ConversationUpdate,
90
+ r as ChannelsHost,
91
+ s as ForHarnessOptions,
92
+ t as ChannelState,
93
+ u as ResponseReadOptions
94
+ } from "../../conversations-DH0ut_8n.js";
95
+ import {
96
+ i as GatewayAgent,
97
+ n as ChannelGatewayOptions,
98
+ r as ChannelRouteEvent,
99
+ t as ChannelGateway
100
+ } from "../../gateway-BDC07gYO.js";
101
+
102
+ //#region src/experimental/channels/apply-chunks.d.ts
103
+ /** Apply a response's chunks to the message it builds or extends. */
104
+ declare function applyChunks(
105
+ message: TranscriptMessage,
106
+ chunks: readonly ResponseChunk[]
107
+ ): TranscriptMessage;
108
+ //#endregion
109
+ //#region src/experimental/channels/routes.d.ts
110
+ /**
111
+ * Common deterministic routing policies for normalized Channel events.
112
+ *
113
+ * Each one maps an event to a namespaced agent object. That object is the
114
+ * authorization boundary: anyone routed to it may use every conversation in
115
+ * it. Deciding whether an event is relevant at all is application policy:
116
+ * write that in your own `route` function and return `null` to ignore it.
117
+ */
118
+ declare const routes: {
119
+ /**
120
+ * Give each participant an agent object of their own. The default for every
121
+ * Channel, so that a group chat never shares an object by accident.
122
+ *
123
+ * A surface that names no conversation, such as a Slack thread or an
124
+ * email, joins the object's default conversation, so a participant keeps
125
+ * one history wherever they write from.
126
+ */
127
+ perParticipant(
128
+ _event: ChannelIngressEvent,
129
+ _raw: unknown,
130
+ participant: Participant
131
+ ): string;
132
+ /**
133
+ * Give every event its own application route. Useful to kick off a
134
+ * new conversation for each ingress, and where you don't want subsequent
135
+ * messages routed back to that same conversation.
136
+ **/
137
+ perEvent(event: ChannelIngressEvent): string;
138
+ /**
139
+ * Send every event in the same thread to the same object, whoever sent
140
+ * it. Everyone in the thread can then use that object's conversations.
141
+ */
142
+ perThread(event: ChannelIngressEvent): string;
143
+ };
144
+ //#endregion
145
+ //#region src/experimental/channels/stream.d.ts
146
+ /** Why a consumption loop stopped reading. */
147
+ type StreamOutcome =
148
+ | {
149
+ interrupted: false;
150
+ }
151
+ | {
152
+ interrupted: true;
153
+ error: unknown;
154
+ };
155
+ type ChunkConsumer<TChunk, TResult> = {
156
+ onChunk(
157
+ chunk: TChunk
158
+ ): Awaitable<void> /** Runs exactly once, whether the stream closed or ended abnormally. */;
159
+ onFinish(outcome: StreamOutcome): Awaitable<TResult>;
160
+ };
161
+ /**
162
+ * Read a stream to completion, then finalize exactly once.
163
+ *
164
+ * `onFinish` runs whether the stream closed normally, errored because the
165
+ * generation failed, or stopped because `onChunk` threw. A Channel that
166
+ * finalizes here cannot lose a terminal provider call to an early ending.
167
+ */
168
+ declare function consumeChunks<TChunk, TResult>(
169
+ chunks: ReadableStream<TChunk>,
170
+ consumer: ChunkConsumer<TChunk, TResult>
171
+ ): Promise<TResult>;
172
+ //#endregion
173
+ export {
174
+ type AgentHarness,
175
+ Awaitable,
176
+ Channel,
177
+ ChannelActor,
178
+ ChannelActorInput,
179
+ ChannelApprovalResponse,
180
+ ChannelApprovalResponseInput,
181
+ ChannelAttachment,
182
+ ChannelChunkSource,
183
+ ChannelDeliveryContext,
184
+ ChannelDeliveryOptions,
185
+ ChannelEmailIngress,
186
+ ChannelEmailIngressResult,
187
+ ChannelEmailInput,
188
+ ChannelEventContext,
189
+ ChannelEventContextInput,
190
+ ChannelGateway,
191
+ ChannelGatewayOptions,
192
+ ChannelIdentity,
193
+ ChannelIdentityInput,
194
+ ChannelInboundMessage,
195
+ ChannelInboundMessageInput,
196
+ ChannelIngress,
197
+ ChannelIngressEnvelope,
198
+ ChannelIngressEvent,
199
+ ChannelIngressEventInput,
200
+ ChannelIngressResult,
201
+ ChannelMessage,
202
+ ChannelMessageSurface,
203
+ ChannelMessageSurfaceInput,
204
+ ChannelParticipant,
205
+ ChannelRoute,
206
+ ChannelRouteEvent,
207
+ ChannelState,
208
+ ChannelStreamOptions,
209
+ ChannelSurfaceArray,
210
+ ChannelSurfaceObject,
211
+ ChannelSurfaceValue,
212
+ ChannelUpgrade,
213
+ ChannelUpgradeMatch,
214
+ Channels,
215
+ ChannelsHost,
216
+ ChannelsOptions,
217
+ type ChunkConsumer,
218
+ ClientTool,
219
+ ConversationChannel,
220
+ ConversationInfo,
221
+ ConversationOperation,
222
+ ConversationSnapshot,
223
+ ConversationUpdate,
224
+ DeliveryFailure,
225
+ DeliveryResult,
226
+ DispatchResult,
227
+ EventOrigin,
228
+ ForHarnessOptions,
229
+ GatewayAgent,
230
+ GatewayEvent,
231
+ GatewayOrigin,
232
+ type HarnessInput,
233
+ type HarnessInputFrom,
234
+ type HarnessSession,
235
+ type HarnessSessions,
236
+ InboundEvent,
237
+ type InputPart,
238
+ Json,
239
+ JsonArray,
240
+ JsonObject,
241
+ MessagePart,
242
+ type OperationResult,
243
+ type OperationStatus,
244
+ Participant,
245
+ ParticipantResult,
246
+ type Receipt,
247
+ ResponseChunk,
248
+ ResponseEnding,
249
+ ResponseReadOptions,
250
+ type SessionEvent,
251
+ type SessionId,
252
+ type SessionInfo,
253
+ type SessionState,
254
+ type SessionWatch,
255
+ type StreamOutcome,
256
+ type SubmitOptions,
257
+ type ToolAnswer,
258
+ ToolPart,
259
+ ToolState,
260
+ TranscriptMessage,
261
+ TurnOutcome,
262
+ TurnStatus,
263
+ applyChunks,
264
+ consumeChunks,
265
+ identityKey,
266
+ isChannelMessageSurface,
267
+ matchesPath,
268
+ routes
269
+ };
270
+ //# sourceMappingURL=index.d.ts.map