experimental-a2 0.6.0 → 0.7.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 (145) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/ai-server.d.ts +4 -5
  3. package/dist/ai-server.d.ts.map +1 -1
  4. package/dist/ai-server.js +8 -7
  5. package/dist/ai-server.js.map +1 -1
  6. package/dist/ai.d.ts +334 -2
  7. package/dist/ai.d.ts.map +1 -0
  8. package/dist/ai.js +1 -1
  9. package/dist/client.d.ts +202 -2
  10. package/dist/client.d.ts.map +1 -0
  11. package/dist/client.js +1025 -1
  12. package/dist/client.js.map +1 -0
  13. package/dist/errors-BQuJpe82.js.map +1 -1
  14. package/dist/index.d.ts +22 -3
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/{internal-DstsI6Re.js → internal-DRXJ56EI.js} +5 -28
  17. package/dist/internal-DRXJ56EI.js.map +1 -0
  18. package/dist/react.d.ts +1 -1
  19. package/dist/react.js +1 -1
  20. package/dist/scheduler-qstash.d.ts +3 -3
  21. package/dist/scheduler-qstash.js +4 -5
  22. package/dist/scheduler-qstash.js.map +1 -1
  23. package/dist/scheduler-vercel.d.ts +2 -2
  24. package/dist/scheduler-vercel.js +4 -4
  25. package/dist/scheduler-vercel.js.map +1 -1
  26. package/dist/{server-Duw6MVlB.js → server-286j79Mt.js} +708 -79
  27. package/dist/server-286j79Mt.js.map +1 -0
  28. package/dist/{server-DpvjhdoE.d.ts → server-DgXmORIq.d.ts} +67 -49
  29. package/dist/server-DgXmORIq.d.ts.map +1 -0
  30. package/dist/server.d.ts +3 -3
  31. package/dist/server.js +1 -1
  32. package/dist/store-N8PXxDAS.js.map +1 -1
  33. package/dist/{store-DysUkTH3.d.ts → store-flRz1OWh.d.ts} +2 -57
  34. package/dist/store-flRz1OWh.d.ts.map +1 -0
  35. package/dist/store-memory.d.ts +1 -1
  36. package/dist/store-memory.d.ts.map +1 -1
  37. package/dist/store-memory.js +1 -59
  38. package/dist/store-memory.js.map +1 -1
  39. package/dist/{store-polling-dSeLxzfb.js → store-polling-6DW7F1DT.js} +2 -2
  40. package/dist/{store-polling-dSeLxzfb.js.map → store-polling-6DW7F1DT.js.map} +1 -1
  41. package/dist/store-postgres.d.ts +1 -1
  42. package/dist/store-postgres.js +1 -81
  43. package/dist/store-postgres.js.map +1 -1
  44. package/dist/{store-redis-core-BFLwz0Wj.js → store-redis-core-DEYO8Ryv.js} +48 -134
  45. package/dist/store-redis-core-DEYO8Ryv.js.map +1 -0
  46. package/dist/store-redis-http.d.ts +1 -1
  47. package/dist/store-redis-http.js +2 -3
  48. package/dist/store-redis-http.js.map +1 -1
  49. package/dist/store-redis.d.ts +1 -1
  50. package/dist/store-redis.js +3 -4
  51. package/dist/store-redis.js.map +1 -1
  52. package/dist/store-sqlite.d.ts +1 -1
  53. package/dist/store-sqlite.d.ts.map +1 -1
  54. package/dist/store-sqlite.js +1 -72
  55. package/dist/store-sqlite.js.map +1 -1
  56. package/dist/{wire-BFQmSJ-9.js → wire-B6te_wns.js} +4 -3
  57. package/dist/wire-B6te_wns.js.map +1 -0
  58. package/docs/guides/03-react.mdx +20 -28
  59. package/docs/guides/05-production.mdx +9 -11
  60. package/docs/guides/06-ai-agents.mdx +8 -14
  61. package/docs/guides/09-presence.mdx +14 -19
  62. package/docs/guides/10-transports.mdx +104 -86
  63. package/docs/reference/01-api.mdx +143 -277
  64. package/docs/reference/02-errors.mdx +5 -7
  65. package/package.json +1 -14
  66. package/src/ai-server.ts +9 -5
  67. package/src/client.ts +2 -2
  68. package/src/errors.ts +1 -0
  69. package/src/internal.ts +3 -62
  70. package/src/push-envelope.ts +24 -21
  71. package/src/scheduler-qstash.ts +3 -3
  72. package/src/scheduler-vercel.ts +2 -2
  73. package/src/server-fetch.ts +344 -0
  74. package/src/server.ts +73 -225
  75. package/src/session-socket.ts +36 -20
  76. package/src/sse.ts +2 -2
  77. package/src/store-memory.ts +0 -81
  78. package/src/store-postgres.ts +0 -100
  79. package/src/store-redis-core.ts +47 -211
  80. package/src/store-redis-http.ts +0 -1
  81. package/src/store-redis.ts +0 -1
  82. package/src/store-sqlite.ts +0 -119
  83. package/src/store.ts +0 -60
  84. package/src/wire.ts +2 -1
  85. package/dist/ai-D_PGS-JR.d.ts +0 -334
  86. package/dist/ai-D_PGS-JR.d.ts.map +0 -1
  87. package/dist/cli-B3VuxoDe.js +0 -599
  88. package/dist/cli-B3VuxoDe.js.map +0 -1
  89. package/dist/cli-bin.d.ts +0 -1
  90. package/dist/cli-bin.js +0 -7
  91. package/dist/cli-bin.js.map +0 -1
  92. package/dist/cli.d.ts +0 -20
  93. package/dist/cli.d.ts.map +0 -1
  94. package/dist/cli.js +0 -2
  95. package/dist/client-CdMqi7mC.d.ts +0 -202
  96. package/dist/client-CdMqi7mC.d.ts.map +0 -1
  97. package/dist/client-Dj5d3SP_.js +0 -1026
  98. package/dist/client-Dj5d3SP_.js.map +0 -1
  99. package/dist/devtools-J_jZ2vQf.d.ts +0 -152
  100. package/dist/devtools-J_jZ2vQf.d.ts.map +0 -1
  101. package/dist/devtools-kJJaORn-.js +0 -340
  102. package/dist/devtools-kJJaORn-.js.map +0 -1
  103. package/dist/devtools-server.browser.d.ts +0 -1
  104. package/dist/devtools-server.browser.js +0 -6
  105. package/dist/devtools-server.browser.js.map +0 -1
  106. package/dist/devtools-server.d.ts +0 -23
  107. package/dist/devtools-server.d.ts.map +0 -1
  108. package/dist/devtools-server.js +0 -1270
  109. package/dist/devtools-server.js.map +0 -1
  110. package/dist/devtools.d.ts +0 -2
  111. package/dist/devtools.js +0 -2
  112. package/dist/errors-W6nwJ-fm.d.ts +0 -21
  113. package/dist/errors-W6nwJ-fm.d.ts.map +0 -1
  114. package/dist/http.d.ts +0 -151
  115. package/dist/http.d.ts.map +0 -1
  116. package/dist/http.js +0 -706
  117. package/dist/http.js.map +0 -1
  118. package/dist/inspection-DaxB5jM2.js +0 -13
  119. package/dist/inspection-DaxB5jM2.js.map +0 -1
  120. package/dist/internal-DstsI6Re.js.map +0 -1
  121. package/dist/platform-B4TnJtWu.js +0 -34
  122. package/dist/platform-B4TnJtWu.js.map +0 -1
  123. package/dist/server-DpvjhdoE.d.ts.map +0 -1
  124. package/dist/server-Duw6MVlB.js.map +0 -1
  125. package/dist/store-DysUkTH3.d.ts.map +0 -1
  126. package/dist/store-redis-core-BFLwz0Wj.js.map +0 -1
  127. package/dist/testing.browser.d.ts +0 -1
  128. package/dist/testing.browser.js +0 -6
  129. package/dist/testing.browser.js.map +0 -1
  130. package/dist/testing.d.ts +0 -32
  131. package/dist/testing.d.ts.map +0 -1
  132. package/dist/testing.js +0 -103
  133. package/dist/testing.js.map +0 -1
  134. package/dist/wire-BFQmSJ-9.js.map +0 -1
  135. package/docs/guides/07-devtools.mdx +0 -229
  136. package/src/cli-bin.ts +0 -5
  137. package/src/cli.ts +0 -1046
  138. package/src/devtools-app.ts +0 -989
  139. package/src/devtools-server.browser.ts +0 -5
  140. package/src/devtools-server.ts +0 -604
  141. package/src/devtools.ts +0 -716
  142. package/src/http.ts +0 -394
  143. package/src/inspection.ts +0 -39
  144. package/src/testing.browser.ts +0 -5
  145. package/src/testing.ts +0 -185
package/dist/ai.d.ts CHANGED
@@ -1,2 +1,334 @@
1
- import { A as MessageInterruptedPayload, B as UIMessage, C as GenerationUsage, D as LanguageModelUsage, E as JSONValue, F as SessionClosedPayload, G as deriveUIMessages, H as agent, I as SessionCreatedPayload, J as inputs, K as events, L as ToolActivity, M as PendingInput, N as RetryGenerationOptions, O as MessageCompletedPayload, P as RetryRequestedPayload, R as ToolCalledPayload, S as GenerationStartedPayload, T as InputRespondedPayload, U as createEvents, V as UIMessageChunk, W as createReducer, Y as reduceAIState, _ as GenerationCompletedPayload, a as ActiveGenerationProjection, b as GenerationReason, c as AgentStatus, d as ApprovalRequestedPayload, f as ApprovalRespondedPayload, g as FinishReason, h as CompactionState, i as ActiveGeneration, j as PendingApproval, k as MessageCreatedPayload, l as AgentToolContext, m as CompactionRequestedPayload, n as AIInputs, o as AgentDefinition, p as CompactionCompletedPayload, q as handlerContext, r as AIState, s as AgentOptions, t as AIEventDefs, u as AgentToolEventDefs, v as GenerationFailedPayload, w as InputRequestedPayload, x as GenerationRequestedPayload, y as GenerationProgressPayload, z as ToolResultPayload } from "./ai-D_PGS-JR.js";
2
- export { AIEventDefs, AIInputs, AIState, ActiveGeneration, ActiveGenerationProjection, AgentDefinition, AgentOptions, AgentStatus, AgentToolContext, AgentToolEventDefs, ApprovalRequestedPayload, ApprovalRespondedPayload, CompactionCompletedPayload, CompactionRequestedPayload, CompactionState, type FinishReason, GenerationCompletedPayload, GenerationFailedPayload, GenerationProgressPayload, GenerationReason, GenerationRequestedPayload, GenerationStartedPayload, GenerationUsage, InputRequestedPayload, InputRespondedPayload, type JSONValue, type LanguageModelUsage, MessageCompletedPayload, MessageCreatedPayload, MessageInterruptedPayload, PendingApproval, PendingInput, RetryGenerationOptions, RetryRequestedPayload, SessionClosedPayload, SessionCreatedPayload, ToolActivity, ToolCalledPayload, ToolResultPayload, type UIMessage, type UIMessageChunk, agent, createEvents, createReducer, deriveUIMessages, events, handlerContext, inputs, reduceAIState };
1
+ import { a as EventDefs, h as StandardSchemaV1, n as Contract, p as Reducer, t as AppendInput } from "./contract-jIfaR085.js";
2
+ import { s as HandlerContext } from "./server-DgXmORIq.js";
3
+ import { FinishReason, JSONValue, LanguageModelUsage, UIMessage, UIMessageChunk } from "ai";
4
+ //#region src/ai.d.ts
5
+ type AgentStatus = "idle" | "generating" | "waiting" | "failed" | "closed";
6
+ type GenerationReason = "message" | "tool" | "input" | "retry";
7
+ type SessionCreatedPayload = {
8
+ metadata?: JSONValue;
9
+ };
10
+ type SessionClosedPayload = {
11
+ reason?: string;
12
+ };
13
+ type MessageCreatedPayload<M extends UIMessage> = {
14
+ message: M;
15
+ /** For user messages, false records passive context. Omission or true schedules. */
16
+ generate?: boolean;
17
+ };
18
+ type MessageCompletedPayload = {
19
+ messageId: string;
20
+ };
21
+ type MessageInterruption = {
22
+ messageId: string;
23
+ reason?: string;
24
+ /** Last confirmed event-log index visible to the interrupter. */
25
+ lastSeenIndex?: number;
26
+ };
27
+ type MessageInterruptedPayload = MessageInterruption & ({
28
+ generationId: string;
29
+ requestId?: never;
30
+ } | {
31
+ requestId: string;
32
+ generationId?: never;
33
+ });
34
+ type GenerationRequestedPayload = {
35
+ messageId: string;
36
+ reason: GenerationReason;
37
+ responseMessageId?: string;
38
+ };
39
+ type RetryGenerationOptions = {
40
+ messageId: string;
41
+ responseMessageId: string;
42
+ retryId: string;
43
+ };
44
+ type RetryRequestedPayload = RetryGenerationOptions;
45
+ type GenerationStartedPayload = {
46
+ requestId: string;
47
+ messageId: string;
48
+ generationId: string;
49
+ responseMessageId: string;
50
+ attempt: number;
51
+ model: string;
52
+ };
53
+ type GenerationProgressPayload = {
54
+ requestId: string;
55
+ messageId: string;
56
+ generationId: string;
57
+ responseMessageId: string;
58
+ sequence: number;
59
+ chunks: UIMessageChunk[];
60
+ };
61
+ type GenerationCompletedPayload = {
62
+ requestId: string;
63
+ messageId: string;
64
+ generationId: string;
65
+ responseMessageId: string;
66
+ finishReason?: FinishReason;
67
+ usage?: LanguageModelUsage;
68
+ };
69
+ type GenerationFailedPayload = {
70
+ requestId: string;
71
+ messageId: string;
72
+ generationId: string;
73
+ responseMessageId: string;
74
+ error: string;
75
+ /** True when a later attempt replaced an incomplete attempt. */
76
+ superseded?: boolean;
77
+ stepLimit?: boolean;
78
+ };
79
+ type ToolCalledPayload = {
80
+ requestId: string;
81
+ messageId: string;
82
+ generationId: string;
83
+ toolCallId: string;
84
+ toolName: string;
85
+ input: unknown;
86
+ dynamic?: boolean;
87
+ providerExecuted?: boolean;
88
+ supportsDeferredResults?: boolean;
89
+ providerMetadata?: unknown;
90
+ toolMetadata?: unknown;
91
+ title?: string;
92
+ };
93
+ type ToolResultPayload = {
94
+ requestId: string;
95
+ messageId: string;
96
+ generationId: string;
97
+ toolCallId: string;
98
+ toolName?: string;
99
+ input?: unknown;
100
+ rawInput?: unknown;
101
+ output?: unknown;
102
+ error?: string;
103
+ denied?: boolean;
104
+ preliminary?: boolean;
105
+ phase?: "input" | "execution";
106
+ dynamic?: boolean;
107
+ providerExecuted?: boolean;
108
+ providerMetadata?: unknown;
109
+ toolMetadata?: unknown;
110
+ };
111
+ type ApprovalRequestedPayload = {
112
+ messageId: string;
113
+ generationId: string;
114
+ approvalId: string;
115
+ toolCallId: string;
116
+ isAutomatic?: boolean;
117
+ signature?: string;
118
+ };
119
+ type ApprovalRespondedPayload = {
120
+ messageId: string;
121
+ generationId: string;
122
+ approvalId: string;
123
+ approved: boolean;
124
+ reason?: string;
125
+ };
126
+ type InputRequestedPayload = {
127
+ messageId: string;
128
+ generationId: string;
129
+ inputId: string;
130
+ name: string;
131
+ question?: JSONValue;
132
+ };
133
+ type InputRespondedPayload = {
134
+ messageId: string;
135
+ generationId: string;
136
+ inputId: string;
137
+ name: string;
138
+ value: JSONValue;
139
+ };
140
+ type CompactionRequestedPayload = {
141
+ generationId: string;
142
+ throughMessageId: string;
143
+ };
144
+ type CompactionCompletedPayload<M extends UIMessage> = {
145
+ generationId: string;
146
+ throughMessageId: string;
147
+ messages: M[];
148
+ retainedMessageIds?: string[];
149
+ };
150
+ type AIEventDefs<M extends UIMessage = UIMessage> = {
151
+ "ai.session.created": StandardSchemaV1<SessionCreatedPayload>;
152
+ "ai.session.closed": StandardSchemaV1<SessionClosedPayload>;
153
+ "ai.message.created": StandardSchemaV1<MessageCreatedPayload<M>>;
154
+ "ai.message.completed": StandardSchemaV1<MessageCompletedPayload>;
155
+ "ai.message.interrupted": StandardSchemaV1<MessageInterruptedPayload>;
156
+ "ai.generation.requested": StandardSchemaV1<GenerationRequestedPayload>;
157
+ "ai.retry.requested": StandardSchemaV1<RetryRequestedPayload>;
158
+ "ai.generation.started": StandardSchemaV1<GenerationStartedPayload>;
159
+ "ai.generation.progress": StandardSchemaV1<GenerationProgressPayload>;
160
+ "ai.generation.completed": StandardSchemaV1<GenerationCompletedPayload>;
161
+ "ai.generation.failed": StandardSchemaV1<GenerationFailedPayload>;
162
+ "ai.tool.called": StandardSchemaV1<ToolCalledPayload>;
163
+ "ai.tool.result": StandardSchemaV1<ToolResultPayload>;
164
+ "ai.approval.requested": StandardSchemaV1<ApprovalRequestedPayload>;
165
+ "ai.approval.responded": StandardSchemaV1<ApprovalRespondedPayload>;
166
+ "ai.input.requested": StandardSchemaV1<InputRequestedPayload>;
167
+ "ai.input.responded": StandardSchemaV1<InputRespondedPayload>;
168
+ "ai.compaction.requested": StandardSchemaV1<CompactionRequestedPayload>;
169
+ "ai.compaction.completed": StandardSchemaV1<CompactionCompletedPayload<M>>;
170
+ };
171
+ type ActiveGeneration = GenerationStartedPayload;
172
+ type ActiveGenerationProjection<M extends UIMessage = UIMessage> = {
173
+ generationId: string;
174
+ responseMessageId: string;
175
+ /** Log index of the completed model step while its response remains interruptible. */
176
+ completionIndex?: number;
177
+ baseMessage?: M;
178
+ baseCompaction?: CompactionState<M> | null;
179
+ batches: Array<{
180
+ index: number;
181
+ chunks: UIMessageChunk[];
182
+ }>;
183
+ baseTools: ToolActivity[];
184
+ toolEvents: Array<{
185
+ index: number;
186
+ type: "ai.tool.called";
187
+ payload: ToolCalledPayload;
188
+ } | {
189
+ index: number;
190
+ type: "ai.tool.result";
191
+ payload: ToolResultPayload;
192
+ }>;
193
+ approvalEvents: Array<{
194
+ index: number;
195
+ type: "ai.approval.requested";
196
+ payload: ApprovalRequestedPayload;
197
+ } | {
198
+ index: number;
199
+ type: "ai.approval.responded";
200
+ payload: ApprovalRespondedPayload;
201
+ }>;
202
+ };
203
+ type PendingApproval = ApprovalRequestedPayload;
204
+ type PendingInput = InputRequestedPayload;
205
+ type ToolActivity = {
206
+ requestId: string;
207
+ messageId: string;
208
+ generationId: string;
209
+ toolCallId: string;
210
+ toolName?: string;
211
+ input?: unknown;
212
+ rawInput?: unknown;
213
+ output?: unknown;
214
+ error?: string;
215
+ preliminary?: boolean;
216
+ phase?: "input" | "execution";
217
+ dynamic?: boolean;
218
+ providerExecuted?: boolean;
219
+ callProviderMetadata?: unknown;
220
+ resultProviderMetadata?: unknown;
221
+ toolMetadata?: unknown;
222
+ title?: string;
223
+ status: "running" | "completed" | "failed" | "denied";
224
+ };
225
+ type CompactionState<M extends UIMessage> = {
226
+ status: "running" | "completed";
227
+ generationId: string;
228
+ throughMessageId: string;
229
+ messages?: M[];
230
+ retainedMessageIds?: string[];
231
+ };
232
+ type GenerationUsage = {
233
+ generationId: string;
234
+ usage: LanguageModelUsage;
235
+ };
236
+ type AIState<M extends UIMessage = UIMessage> = {
237
+ session: {
238
+ created: boolean;
239
+ metadata?: JSONValue;
240
+ };
241
+ messages: M[];
242
+ status: AgentStatus;
243
+ activeGeneration: ActiveGeneration | null;
244
+ activeRequestId: string | null;
245
+ activeResponseMessageId: string | null;
246
+ activeProjection: ActiveGenerationProjection<M> | null;
247
+ responseGenerationIds: Record<string, string>;
248
+ terminalRequestIds?: Record<string, true>;
249
+ terminalGenerations?: Record<string, "completed" | "failed" | "interrupted" | "superseded">;
250
+ pendingApprovals: PendingApproval[];
251
+ pendingInputs: PendingInput[];
252
+ tools: ToolActivity[];
253
+ compaction: CompactionState<M> | null;
254
+ usage: GenerationUsage[];
255
+ error: string | null;
256
+ };
257
+ type AgentDefinition<M extends UIMessage = UIMessage, D extends EventDefs = AIEventDefs<M>> = {
258
+ readonly contract: Contract<D>;
259
+ readonly reducer: Reducer<D, AIState<M>>;
260
+ };
261
+ type AgentToolEventDefs = EventDefs & Pick<AIEventDefs, "ai.tool.called" | "ai.approval.responded">;
262
+ /** The durable handler context supplied when A2 executes a local AI tool. */
263
+ type AgentToolContext<D extends AgentToolEventDefs> = HandlerContext<D, "ai.tool.called"> | HandlerContext<D, "ai.approval.responded">;
264
+ type AgentOptions<M extends UIMessage, E extends EventDefs> = {
265
+ name: string;
266
+ events?: E;
267
+ /** Optional stricter schema for custom UIMessage metadata/data/tool types. */
268
+ messageSchema?: StandardSchemaV1<M>;
269
+ /** Snapshot identity. Bump when application-level projection semantics change. */
270
+ reducerName?: string;
271
+ };
272
+ type AIMessageFrom<D extends EventDefs> = D extends Record<"ai.message.created", infer S extends StandardSchemaV1> ? StandardSchemaV1.InferOutput<S> extends MessageCreatedPayload<infer M extends UIMessage> ? M : UIMessage : UIMessage;
273
+ declare function createEvents<M extends UIMessage = UIMessage>(options?: {
274
+ messageSchema?: StandardSchemaV1<M>;
275
+ }): AIEventDefs<M>;
276
+ declare const events: AIEventDefs<UIMessage>;
277
+ /** Pure projection of the built-in AI protocol. Unknown extension events are ignored. */
278
+ declare function reduceAIState<M extends UIMessage>(state: AIState<M>, event: {
279
+ type: string;
280
+ payload: unknown;
281
+ index: number;
282
+ id?: string;
283
+ }): AIState<M>;
284
+ /** Derive AI SDK UI messages directly from an A2 event history. */
285
+ declare function deriveUIMessages<M extends UIMessage = UIMessage>(history: readonly {
286
+ type: string;
287
+ payload: unknown;
288
+ index: number;
289
+ }[]): M[];
290
+ /** Build the standard AI state projection for any contract containing the protocol. */
291
+ declare function createReducer<D extends EventDefs>(options: {
292
+ contract: Contract<D>;
293
+ name?: string;
294
+ }): Reducer<D, AIState<AIMessageFrom<D>>>;
295
+ type ProtocolInput<M extends UIMessage, K extends keyof AIEventDefs<M> & string> = AppendInput<Pick<AIEventDefs<M>, K>>;
296
+ type AIInputs = {
297
+ /** Record a message. User messages schedule unless generate is false. */
298
+ message<M extends UIMessage>(message: M, options?: {
299
+ generate?: boolean;
300
+ }): ProtocolInput<M, "ai.message.created">[];
301
+ /** Record a message without requesting a generation. */
302
+ seed<M extends UIMessage>(message: M): ProtocolInput<M, "ai.message.created">[];
303
+ /** Answer an AI SDK tool approval. The tool barrier owns continuation. */
304
+ approval(response: ApprovalRespondedPayload): ProtocolInput<UIMessage, "ai.approval.responded">[];
305
+ /** Answer an application-defined input request. */
306
+ input(response: InputRespondedPayload): ProtocolInput<UIMessage, "ai.input.responded">[];
307
+ /** Record an application-defined request for input. */
308
+ requestInput(request: InputRequestedPayload): ProtocolInput<UIMessage, "ai.input.requested">[];
309
+ /** Request a fresh attempt for a failed response. */
310
+ retry(options: RetryGenerationOptions): ProtocolInput<UIMessage, "ai.retry.requested">[];
311
+ /** Interrupt the active response for a message. */
312
+ interrupt(interruption: MessageInterruptedPayload): ProtocolInput<UIMessage, "ai.message.interrupted">[];
313
+ };
314
+ /** Pure append inputs for the built-in AI protocol. */
315
+ declare const inputs: AIInputs;
316
+ /**
317
+ * Read the durable handler context ambient to the current AI tool
318
+ * execution. A2 runs each local tool's `execute` inside this scope, so
319
+ * plain AI SDK `tool()` definitions reach their `event`, `attempt`,
320
+ * `session`, and `signal` without an A2-specific wrapper. The agent (or
321
+ * contract) argument carries the event types and is verified against
322
+ * the executing server's contract.
323
+ */
324
+ declare function handlerContext<D extends AgentToolEventDefs>(agentOrContract: Contract<D> | {
325
+ readonly contract: Contract<D>;
326
+ }): AgentToolContext<D>;
327
+ /**
328
+ * Define an agent: built-in AI protocol + application events and one state
329
+ * reducer. The result is isomorphic.
330
+ */
331
+ declare function agent<M extends UIMessage = UIMessage, E extends EventDefs = Record<never, never>>(options: AgentOptions<M, E>): AgentDefinition<M, AIEventDefs<M> & E>;
332
+ //#endregion
333
+ export { AIEventDefs, AIInputs, AIState, ActiveGeneration, ActiveGenerationProjection, AgentDefinition, AgentOptions, AgentStatus, AgentToolContext, AgentToolEventDefs, ApprovalRequestedPayload, ApprovalRespondedPayload, CompactionCompletedPayload, CompactionRequestedPayload, CompactionState, type FinishReason, GenerationCompletedPayload, GenerationFailedPayload, GenerationProgressPayload, GenerationReason, GenerationRequestedPayload, GenerationStartedPayload, GenerationUsage, InputRequestedPayload, InputRespondedPayload, type JSONValue, type LanguageModelUsage, MessageCompletedPayload, MessageCreatedPayload, MessageInterruptedPayload, PendingApproval, PendingInput, RetryGenerationOptions, RetryRequestedPayload, SessionClosedPayload, SessionCreatedPayload, ToolActivity, ToolCalledPayload, ToolResultPayload, type UIMessage, type UIMessageChunk, agent, createEvents, createReducer, deriveUIMessages, events, handlerContext, inputs, reduceAIState };
334
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","names":[],"sources":["../src/ai.ts"],"mappings":"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"}
package/dist/ai.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as validateSync, t as assertSyncSchema } from "./validate-XKT4FSNn.js";
2
2
  import { t as contract } from "./contract-48bUMgcL.js";
3
- import { l as ambientToolScopeStorage } from "./internal-DstsI6Re.js";
3
+ import { l as ambientToolScopeStorage } from "./internal-DRXJ56EI.js";
4
4
  //#region src/ai-projector.ts
5
5
  const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6
6
  const cloneMessage = (messageId, base) => structuredClone(base ?? {
package/dist/client.d.ts CHANGED
@@ -1,2 +1,202 @@
1
- import { a as Connection, c as HistoryState, d as SessionClient, f as SessionClientPresence, h as createClient, i as ClientWebSocketConstructor, l as LoadHistoryOptions, m as SessionSnapshot, n as ClientApi, o as ConnectionStatus, p as SessionOptions, r as ClientWebSocket, s as CreateClientOptions, t as A2Client, u as PushResult } from "./client-CdMqi7mC.js";
2
- export { A2Client, ClientApi, ClientWebSocket, ClientWebSocketConstructor, Connection, ConnectionStatus, CreateClientOptions, HistoryState, LoadHistoryOptions, PushResult, SessionClient, SessionClientPresence, SessionOptions, SessionSnapshot, createClient };
1
+ import { a as EventDefs, c as PresencePatch, d as WithPresence, o as PresenceDefs, p as Reducer, r as ContractEvent, s as PresenceMap, t as AppendInput } from "./contract-jIfaR085.js";
2
+ //#region src/client.d.ts
3
+ type ConnectionStatus = "idle" | "connecting" | "live" | "closed";
4
+ /**
5
+ * The connection, as a discriminated union — impossible states are
6
+ * unrepresentable: an error only exists while disconnected,
7
+ * `reconnects` only once a connection has been attempted.
8
+ * "Reconnecting…" is `status === 'connecting' && reconnects > 0`.
9
+ */
10
+ type Connection = {
11
+ status: "idle";
12
+ } | {
13
+ status: "connecting";
14
+ /** Drops of an established stream so far. `0` = first connect. */
15
+ reconnects: number;
16
+ /** Why the last connection ended; `null` on the first connect. */
17
+ error: Error | null;
18
+ } | {
19
+ status: "live";
20
+ reconnects: number;
21
+ } | {
22
+ status: "closed";
23
+ };
24
+ /**
25
+ * What `push` returns: resolves at the server ack (exactly like a
26
+ * plain promise — `await push(...)` gives the acked events), and
27
+ * carries `confirmed` for the later moment when the live stream has
28
+ * delivered the whole batch back and the optimistic overlay entry
29
+ * retired — the view now shows server truth. `confirmed` is lazy:
30
+ * never accessed, never created. A rejected push rejects both.
31
+ */
32
+ type PushResult<D extends EventDefs> = Promise<ContractEvent<D>[]> & {
33
+ readonly confirmed: Promise<ContractEvent<D>[]>;
34
+ };
35
+ type LoadHistoryOptions = {
36
+ /**
37
+ * Exclusive upper bound for the fetch. Defaults to the oldest
38
+ * already-loaded index — successive calls page backward — or one
39
+ * past the hydration frontier while nothing is loaded yet.
40
+ */
41
+ before?: number;
42
+ /** Page size; defaults to 50. */
43
+ limit?: number;
44
+ };
45
+ /** Backscroll progress, derived from the raw event feed. */
46
+ type HistoryState = {
47
+ /** A `loadHistory` fetch is in flight. */
48
+ loading: boolean;
49
+ /** The feed reaches index 1 — nothing older remains to fetch. */
50
+ complete: boolean;
51
+ /** The oldest loaded index; `null` while nothing is loaded. */
52
+ oldestLoaded: number | null;
53
+ };
54
+ /** One immutable view of the session — stable identity between changes. */
55
+ type SessionSnapshot<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = WithPresence<P, {
56
+ /** The replicated presence map, this client included (local echo). */
57
+ presence: PresenceMap<P>;
58
+ }> & {
59
+ /** The live view: server events folded, optimistic pushes applied. */
60
+ state: S;
61
+ /** The raw event feed: server truth — observed, seeded, or
62
+ * backscrolled via `loadHistory` — plus pending optimistic events
63
+ * (provisional indexes past the frontier). `state` never folds
64
+ * backscrolled events; they are display data below the frontier. */
65
+ events: ContractEvent<D>[];
66
+ /** The stream frontier: the last server-confirmed index. This is the
67
+ * `lastSeenIndex` cancellation wants. */
68
+ index: number;
69
+ /** Backscroll progress — `loadHistory` moves it. */
70
+ history: HistoryState;
71
+ connection: Connection;
72
+ };
73
+ /**
74
+ * The presence member of a client session — intersected in via
75
+ * `WithPresence`, so it exists exactly when the contract declares
76
+ * presence fields.
77
+ */
78
+ type SessionClientPresence<P extends PresenceDefs> = {
79
+ /**
80
+ * Fire-and-forget presence: validates locally against the reducer's
81
+ * presence schemas, merges into the local map immediately (the
82
+ * echo), and coalesces on the wire to a fixed cadence — a leading
83
+ * send immediately, then at most one merged send per interval,
84
+ * later values winning field-wise. `null` clears a field. No ack,
85
+ * no retry, no rollback: a lost patch is repainted by the next one.
86
+ * Requires the session's `participant`.
87
+ */
88
+ setPresence(values: PresencePatch<P>["values"]): void;
89
+ };
90
+ type SessionClient<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = WithPresence<P, SessionClientPresence<P>> & {
91
+ readonly sessionId: string;
92
+ subscribe(listener: () => void): () => void;
93
+ getSnapshot(): SessionSnapshot<D, S, P>;
94
+ /**
95
+ * Optimistic append: validates locally against the reducer's event
96
+ * schemas (instant `INVALID_PAYLOAD`, no flicker), applies to the
97
+ * local fold, POSTs, swaps in the ack, rolls back on rejection.
98
+ * Auto-retries only `STORE_UNAVAILABLE`. Resolves with the appended
99
+ * events as the server recorded them. Overlapping calls on this
100
+ * handle enter the transport in invocation order without delaying
101
+ * their optimistic folds.
102
+ */
103
+ push(...events: AppendInput<D>[]): PushResult<D>;
104
+ /**
105
+ * Backscroll: fetch a bounded slice of events from below the
106
+ * frontier and merge it into `events` — deduped, ordered, shared by
107
+ * every handle of this session. Folded state and the optimistic
108
+ * overlay are never touched. Calls serialize per session and skip
109
+ * already-loaded ranges, so overlapping backscrolls never fetch the
110
+ * same range twice. Resolves with the events in the requested range.
111
+ * Requires an http api; the `ws` transport has no history lane and
112
+ * this throws a TypeError there.
113
+ */
114
+ loadHistory(options?: LoadHistoryOptions): Promise<ContractEvent<D>[]>;
115
+ /**
116
+ * Take a lease on the live stream and return its release. Leases
117
+ * refcount per handle — the first connects, releasing the last
118
+ * closes — so independent consumers of one identity-mapped handle
119
+ * (two hooks, a hook plus vanilla code) never fight over the
120
+ * stream. Releasing twice is a no-op. While any lease is held the
121
+ * stream reconnects with backoff and resumes from the frontier.
122
+ */
123
+ connect(): () => void;
124
+ /**
125
+ * The hard stop: drops every outstanding lease and closes the
126
+ * stream now. Not terminal — a later `connect()` starts fresh from
127
+ * the current frontier.
128
+ */
129
+ close(): void;
130
+ };
131
+ type SessionOptions<D extends EventDefs, S> = {
132
+ initialState?: S;
133
+ initialIndex?: number;
134
+ /** Server-rendered history through `initialIndex`. Seeds the event feed. */
135
+ initialEvents?: ContractEvent<D>[];
136
+ /** Overrides the client's `participant` for this session handle.
137
+ * Bound once per handle. */
138
+ participant?: string;
139
+ };
140
+ type A2Client<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = {
141
+ session(sessionId: string, options?: SessionOptions<D, S>): SessionClient<D, S, P>;
142
+ };
143
+ /**
144
+ * The wire the client rides. The string form is one route serving GET
145
+ * (SSE stream) + POST (push). `http` splits the verbs across two
146
+ * routes, for when platform duration limits differ per verb. `ws`
147
+ * rides everything — every session of this client — over one
148
+ * multiplexed WebSocket, served by `sessionsSocket`.
149
+ */
150
+ type ClientApi = string | {
151
+ type: "http";
152
+ push: string;
153
+ stream: string;
154
+ } | {
155
+ type: "ws";
156
+ url: string;
157
+ };
158
+ /**
159
+ * The socket surface the `ws` transport drives — satisfied structurally
160
+ * by the DOM `WebSocket` and Node's alike, and small enough to fake in
161
+ * tests.
162
+ */
163
+ type ClientWebSocket = {
164
+ readonly readyState: number;
165
+ send(data: string): void;
166
+ close(code?: number, reason?: string): void;
167
+ addEventListener(type: "open", listener: () => void): void;
168
+ addEventListener(type: "message", listener: (event: {
169
+ data: unknown;
170
+ }) => void): void;
171
+ addEventListener(type: "close", listener: (event: {
172
+ code: number;
173
+ reason: string;
174
+ }) => void): void;
175
+ addEventListener(type: "error", listener: () => void): void;
176
+ };
177
+ type ClientWebSocketConstructor = new (url: string) => ClientWebSocket;
178
+ type CreateClientOptions<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>> = {
179
+ reducer: Reducer<D, S, P>;
180
+ /** The route (or routes) the client speaks — see `ClientApi`. */
181
+ api: ClientApi;
182
+ /** Injectable fetch — defaults to the global. */
183
+ fetch?: typeof globalThis.fetch;
184
+ /** Injectable WebSocket constructor for the `ws` api — defaults to
185
+ * the global. The http transports never touch it. */
186
+ webSocket?: ClientWebSocketConstructor;
187
+ /** How long an idle session keeps its in-memory identity, in
188
+ * milliseconds. Defaults to five minutes; `Infinity` disables GC. */
189
+ gcTime?: number;
190
+ /**
191
+ * This client's presence identity — required to call `setPresence`.
192
+ * Caller-supplied (a user id, a tab nonce, a guest name): A2 does
193
+ * not invent an identity story; the app states it once here. The
194
+ * default for every session handle this client creates;
195
+ * `session(id, { participant })` overrides it per handle.
196
+ */
197
+ participant?: string;
198
+ };
199
+ declare function createClient<D extends EventDefs, S, P extends PresenceDefs = Record<never, never>>(options: CreateClientOptions<D, S, P>): A2Client<D, S, P>;
200
+ //#endregion
201
+ export { A2Client, ClientApi, ClientWebSocket, ClientWebSocketConstructor, Connection, ConnectionStatus, CreateClientOptions, HistoryState, LoadHistoryOptions, PushResult, SessionClient, SessionClientPresence, SessionOptions, SessionSnapshot, createClient };
202
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;KAoDY;;;;;;;KAQA;EACN;;EAEA;;EAEA;;EAEA,OAAO;;EAEP;EAAgB;;EAChB;;;;;;;;;;KAUM,WAAW,UAAU,aAAa,QAAQ,cAAc;WACzD,WAAW,QAAQ,cAAc;;KAGhC;;;;;;EAMV;;EAEA;;;KAIU;;EAEV;;EAEA;;EAEA;;;KAIU,gBACV,UAAU,WACV,GACA,UAAU,eAAe,wBACvB,aACF;;EAGE,UAAU,YAAY;;;EAIxB,OAAO;;;;;EAKP,QAAQ,cAAc;;;EAGtB;;EAEA,SAAS;EACT,YAAY;;;;;;;KAQF,sBAAsB,UAAU;;;;;;;;;;EAU1C,YAAY,QAAQ,cAAc;;KAGxB,cACV,UAAU,WACV,GACA,UAAU,eAAe,wBACvB,aAAa,GAAG,sBAAsB;WAC/B;EACT,UAAU;EACV,eAAe,gBAAgB,GAAG,GAAG;;;;;;;;;;EAUrC,QAAQ,QAAQ,YAAY,OAAO,WAAW;;;;;;;;;;;EAW9C,YAAY,UAAU,qBAAqB,QAAQ,cAAc;;;;;;;;;EASjE;;;;;;EAMA;;KAGU,eAAe,UAAU,WAAW;EAC9C,eAAe;EACf;;EAEA,gBAAgB,cAAc;;;EAG9B;;KAGU,SACV,UAAU,WACV,GACA,UAAU,eAAe;EAEzB,QACE,mBACA,UAAU,eAAe,GAAG,KAC3B,cAAc,GAAG,GAAG;;;;;;;;;KAUb;EAEN;EAAc;EAAc;;EAC5B;EAAY;;;;;;;KAON;WACD;EACT,KAAK;EACL,MAAM,eAAe;EACrB,iBAAiB,cAAc;EAC/B,iBACE,iBACA,WAAW;IAAS;;EAEtB,iBACE,eACA,WAAW;IAAS;IAAc;;EAEpC,iBAAiB,eAAe;;KAGtB,kCAAkC,gBAAgB;KAElD,oBACV,UAAU,WACV,GACA,UAAU,eAAe;EAEzB,SAAS,QAAQ,GAAG,GAAG;;EAEvB,KAAK;;EAEL,eAAe,WAAW;;;EAG1B,YAAY;;;EAGZ;;;;;;;;EAQA;;iBAirBc,aACd,UAAU,WACV,GACA,UAAU,eAAe,sBACzB,SAAS,oBAAoB,GAAG,GAAG,KAAK,SAAS,GAAG,GAAG"}