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/src/store.ts CHANGED
@@ -67,20 +67,6 @@ export type StoredEvent = Event & {
67
67
  failedAt: Date | null
68
68
  }
69
69
 
70
- /** Durable, read-only session metadata for administrative inspection. */
71
- export type StoredSessionSummary = {
72
- sessionId: string
73
- eventCount: number
74
- pendingCount: number
75
- failedCount: number
76
- /** Durable dispatch claims across every event in the session. */
77
- attemptCount: number
78
- /** Caught handler failures across every event in the session. */
79
- failureCount: number
80
- firstEventAt: Date
81
- updatedAt: Date
82
- }
83
-
84
70
  /**
85
71
  * One live presence value, as `A2Store.presence.read` returns it. The
86
72
  * row is the LWW unit — one participant's one field. `at` is the
@@ -97,13 +83,6 @@ export type PresenceRow = {
97
83
  expiresAt: Date
98
84
  }
99
85
 
100
- /** Metadata for the latest cached fold of one reducer. */
101
- export type StoredSnapshot = {
102
- reducerName: string
103
- index: number
104
- updatedAt: Date
105
- }
106
-
107
86
  /** One consistent cache-plus-tail read for a reducer fold. */
108
87
  export type StoreStateRead = {
109
88
  /** The latest cached fold for this reducer, if one exists. */
@@ -112,42 +91,6 @@ export type StoreStateRead = {
112
91
  events: Event[]
113
92
  }
114
93
 
115
- export type StoredSessionPage = {
116
- sessions: StoredSessionSummary[]
117
- /** Opaque backend cursor; null means there is no next page. */
118
- cursor: string | null
119
- }
120
-
121
- export type StoredEventPage = {
122
- events: StoredEvent[]
123
- /** Fixed inclusive log frontier shared by every page in one inspection. */
124
- throughIndex: number
125
- }
126
-
127
- /**
128
- * Optional read-only administration implemented by A2's shipped stores.
129
- * It is separate from the correctness contract so custom stores do not
130
- * need to expose storage-wide discovery merely to process events.
131
- */
132
- export type A2StoreInspection = {
133
- listSessions(options: {
134
- /** Storage namespace prefix, including the contract separator. */
135
- prefix: string
136
- cursor?: string
137
- limit: number
138
- }): Promise<StoredSessionPage>
139
- /**
140
- * A bounded event page for read-only administration. The first page captures
141
- * `throughIndex`; callers pass it back so concurrent appends cannot extend a
142
- * walk indefinitely. Optional for custom stores; A2 falls back to `read()`.
143
- */
144
- readEvents?(
145
- sessionId: string,
146
- options: { afterIndex: number; throughIndex?: number; limit: number },
147
- ): Promise<StoredEventPage>
148
- listSnapshots(sessionId: string): Promise<StoredSnapshot[]>
149
- }
150
-
151
94
  /** The result of atomically claiming every currently eligible event. */
152
95
  export type StoreClaimAvailableResult =
153
96
  | { outcome: 'claimed'; events: StoredEvent[] }
@@ -368,9 +311,6 @@ export interface A2Store {
368
311
  subscribe?(ns: string, onPatch: (patch: PresencePatch) => void): () => void
369
312
  }
370
313
 
371
- /** Read-only operational data used by `experimental-a2/devtools/server`. */
372
- inspect?: A2StoreInspection
373
-
374
314
  /**
375
315
  * A live feed of one session's events, starting after `startAfter`
376
316
  * (exclusive). Transport is the backend's choice — in-process pub/sub,
package/src/wire.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The wire format shared by experimental-a2/http (server side) and experimental-a2/client
2
+ * The wire format shared by server.fetch and experimental-a2/client
3
3
  * (browser side): events as JSON with ISO timestamps, and the A2Error
4
4
  * envelope. Internal module — both entry points re-export what's
5
5
  * public.
@@ -176,6 +176,7 @@ export type WireError = {
176
176
 
177
177
  const ERROR_STATUS: Record<A2ErrorCode, number> = {
178
178
  INVALID_PAYLOAD: 400,
179
+ FORBIDDEN: 403,
179
180
  UNKNOWN_EVENT_TYPE: 400,
180
181
  PARTIAL_DUPLICATE_BATCH: 400,
181
182
  SUPERSEDED_ATTEMPT: 409,
@@ -1,334 +0,0 @@
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-DpvjhdoE.js";
3
- import { FinishReason, JSONValue, LanguageModelUsage, UIMessage as UIMessage$1, UIMessageChunk as UIMessageChunk$1 } 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$1> = {
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$1[];
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$1> = {
145
- generationId: string;
146
- throughMessageId: string;
147
- messages: M[];
148
- retainedMessageIds?: string[];
149
- };
150
- type AIEventDefs<M extends UIMessage$1 = UIMessage$1> = {
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$1 = UIMessage$1> = {
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$1[];
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$1> = {
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$1 = UIMessage$1> = {
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$1 = UIMessage$1, 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$1, 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$1> ? M : UIMessage$1 : UIMessage$1;
273
- declare function createEvents<M extends UIMessage$1 = UIMessage$1>(options?: {
274
- messageSchema?: StandardSchemaV1<M>;
275
- }): AIEventDefs<M>;
276
- declare const events: AIEventDefs<UIMessage$1>;
277
- /** Pure projection of the built-in AI protocol. Unknown extension events are ignored. */
278
- declare function reduceAIState<M extends UIMessage$1>(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$1 = UIMessage$1>(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$1, 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$1>(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$1>(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$1, "ai.approval.responded">[];
305
- /** Answer an application-defined input request. */
306
- input(response: InputRespondedPayload): ProtocolInput<UIMessage$1, "ai.input.responded">[];
307
- /** Record an application-defined request for input. */
308
- requestInput(request: InputRequestedPayload): ProtocolInput<UIMessage$1, "ai.input.requested">[];
309
- /** Request a fresh attempt for a failed response. */
310
- retry(options: RetryGenerationOptions): ProtocolInput<UIMessage$1, "ai.retry.requested">[];
311
- /** Interrupt the active response for a message. */
312
- interrupt(interruption: MessageInterruptedPayload): ProtocolInput<UIMessage$1, "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$1 = UIMessage$1, E extends EventDefs = Record<never, never>>(options: AgentOptions<M, E>): AgentDefinition<M, AIEventDefs<M> & E>;
332
- //#endregion
333
- export { MessageInterruptedPayload as A, UIMessage$1 as B, GenerationUsage as C, LanguageModelUsage as D, JSONValue as E, SessionClosedPayload as F, deriveUIMessages as G, agent as H, SessionCreatedPayload as I, inputs as J, events as K, ToolActivity as L, PendingInput as M, RetryGenerationOptions as N, MessageCompletedPayload as O, RetryRequestedPayload as P, ToolCalledPayload as R, GenerationStartedPayload as S, InputRespondedPayload as T, createEvents as U, UIMessageChunk$1 as V, createReducer as W, reduceAIState as Y, GenerationCompletedPayload as _, ActiveGenerationProjection as a, GenerationReason as b, AgentStatus as c, ApprovalRequestedPayload as d, ApprovalRespondedPayload as f, FinishReason as g, CompactionState as h, ActiveGeneration as i, PendingApproval as j, MessageCreatedPayload as k, AgentToolContext as l, CompactionRequestedPayload as m, AIInputs as n, AgentDefinition as o, CompactionCompletedPayload as p, handlerContext as q, AIState as r, AgentOptions as s, AIEventDefs as t, AgentToolEventDefs as u, GenerationFailedPayload as v, InputRequestedPayload as w, GenerationRequestedPayload as x, GenerationProgressPayload as y, ToolResultPayload as z };
334
- //# sourceMappingURL=ai-D_PGS-JR.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ai-D_PGS-JR.d.ts","names":[],"sources":["../src/ai.ts"],"mappings":";;;;KAwBY;KAGA;KAEA;EAA0B,WAAW;;KACrC;EAAyB;;KACzB,sBAAsB,UAAU;EAC1C,SAAS;;EAET;;KAEU;EAA4B;;KACnC;EACH;EACA;;EAEA;;KAEU,4BAA4B;EAEhC;EAAsB;;EACtB;EAAmB;;KAEf;EACV;EACA,QAAQ;EACR;;KAEU;EACV;EACA;EACA;;KAEU,wBAAwB;KACxB;EACV;EACA;EACA;EACA;EACA;EACA;;KAEU;EACV;E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