@makaio/adapter-anthropic-sdk 1.0.0-dev-1779051654000

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.
@@ -0,0 +1,1828 @@
1
+
2
+ import { AIAdapter, AIAdapterConfig, AIReasoningLevel, BaseAgentConnectorConfig, ConformanceTestConfig, CreateConformanceTestConfigOptions, MessageHandle, MessageResult, NormalizedCallUsage, ProceduralConnectorTurn, ReasoningLevelMap, UserMessageQueue, WireSessionSubjects } from "@makaio/framework/adapters";
3
+ import Anthropic from "@anthropic-ai/sdk";
4
+ import { BaseStreamAgent, BaseStreamConnector, BaseStreamSession, StreamAdapterSubjectSpec, StreamSessionTurnState } from "@makaio/framework/adapters/stream-session";
5
+ import { z } from "zod";
6
+ import * as _$_makaio_core0 from "@makaio/framework/core";
7
+ import { ScopedSubjectDefinition } from "@makaio/framework/core";
8
+ import { AgentToolApproveRequest, AgentToolApproveResponse, MakaioNodeExtension, SessionMessageBlock, ToolListItem } from "@makaio/framework/contracts";
9
+ import * as _$_makaio_bus_core0 from "@makaio/framework/bus";
10
+ import { IMakaioBus, ScopedBus } from "@makaio/framework/bus";
11
+ import { RawMessageStreamEvent, Tool } from "@anthropic-ai/sdk/resources/messages/messages.js";
12
+ import * as _$_anthropic_ai_sdk_resources_js0 from "@anthropic-ai/sdk/resources.js";
13
+
14
+ //#region src/schemas.d.ts
15
+ /**
16
+ * Zod schema for Anthropic SDK provider-specific configuration.
17
+ *
18
+ * Used for:
19
+ * 1. Type-safe config resolution
20
+ * 2. Serialization to JSON Schema for web-ui form generation
21
+ * 3. Runtime validation
22
+ */
23
+ declare const AnthropicSdkProviderConfigSchema: z.ZodObject<{
24
+ baseUrl: z.ZodOptional<z.ZodString>;
25
+ maxTokens: z.ZodOptional<z.ZodNumber>;
26
+ }, z.core.$strip>;
27
+ /**
28
+ * Provider settings input type (pre-validation, fields optional).
29
+ */
30
+ type AnthropicSdkProviderSettings = z.input<typeof AnthropicSdkProviderConfigSchema>;
31
+ //#endregion
32
+ //#region src/namespaces/schemas/tool-calls.d.ts
33
+ /**
34
+ * Schema for a single tool call.
35
+ * Normalized from Anthropic ToolUseBlock structure.
36
+ * Extends the base schema with `blockIndex` for stable cross-event ordering.
37
+ */
38
+ declare const ToolCallSchema$1: z.ZodObject<{
39
+ id: z.ZodString;
40
+ type: z.ZodLiteral<"function">;
41
+ function: z.ZodObject<{
42
+ name: z.ZodString;
43
+ arguments: z.ZodString;
44
+ }, z.core.$strip>;
45
+ blockIndex: z.ZodNumber;
46
+ }, z.core.$strip>;
47
+ /**
48
+ * Schema for tool calls event.
49
+ * Emitted when the model requests tool/function execution.
50
+ */
51
+ type ToolCall = z.infer<typeof ToolCallSchema$1>;
52
+ //#endregion
53
+ //#region src/namespaces/schemas/message.d.ts
54
+ /**
55
+ * Schema for message complete event.
56
+ * Emitted when a full assistant message has been assembled from streaming chunks.
57
+ * Extends the base schema with Anthropic-specific `finish_reason` values
58
+ * (including `pause_turn`) and the `blockIndex` field on tool calls.
59
+ */
60
+ declare const MessageCompleteEventSchema$1: z.ZodObject<{
61
+ eventType: z.ZodLiteral<"message_complete">;
62
+ content: z.ZodNullable<z.ZodString>;
63
+ reasoning: z.ZodOptional<z.ZodString>;
64
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
65
+ id: z.ZodString;
66
+ blockIndex: z.ZodNumber;
67
+ type: z.ZodLiteral<"function">;
68
+ function: z.ZodObject<{
69
+ name: z.ZodString;
70
+ arguments: z.ZodString;
71
+ }, z.core.$strip>;
72
+ }, z.core.$strip>>>;
73
+ finish_reason: z.ZodNullable<z.ZodEnum<{
74
+ end_turn: "end_turn";
75
+ max_tokens: "max_tokens";
76
+ stop_sequence: "stop_sequence";
77
+ tool_use: "tool_use";
78
+ pause_turn: "pause_turn";
79
+ }>>;
80
+ }, z.core.$strip>;
81
+ type MessageCompleteEvent = z.infer<typeof MessageCompleteEventSchema$1>;
82
+ //#endregion
83
+ //#region src/namespaces/index.d.ts
84
+ /**
85
+ * Discriminated union of all SDK event types.
86
+ * Uses discriminatedUnion for type-safe event routing based on eventType.
87
+ * Turn lifecycle events use dedicated `turn.*` subjects below because the shared
88
+ * stream-session state schema is keyed by state transition fields, not `eventType`.
89
+ */
90
+ declare const SdkEventMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
91
+ eventType: z.ZodLiteral<"chunk">;
92
+ index: z.ZodNumber;
93
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
94
+ type: z.ZodLiteral<"text_delta">;
95
+ text: z.ZodString;
96
+ }, z.core.$strip>, z.ZodObject<{
97
+ type: z.ZodLiteral<"thinking_delta">;
98
+ thinking: z.ZodString;
99
+ }, z.core.$strip>, z.ZodObject<{
100
+ type: z.ZodLiteral<"input_json_delta">;
101
+ partial_json: z.ZodString;
102
+ }, z.core.$strip>], "type">;
103
+ }, z.core.$strip>, z.ZodObject<{
104
+ eventType: z.ZodLiteral<"usage">;
105
+ prompt_tokens: z.ZodNumber;
106
+ completion_tokens: z.ZodNumber;
107
+ total_tokens: z.ZodNumber;
108
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
109
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
110
+ }, z.core.$strip>, z.ZodObject<{
111
+ eventType: z.ZodLiteral<"tool_calls">;
112
+ toolCalls: z.ZodArray<z.ZodObject<{
113
+ id: z.ZodString;
114
+ type: z.ZodLiteral<"function">;
115
+ function: z.ZodObject<{
116
+ name: z.ZodString;
117
+ arguments: z.ZodString;
118
+ }, z.core.$strip>;
119
+ blockIndex: z.ZodNumber;
120
+ }, z.core.$strip>>;
121
+ }, z.core.$strip>, z.ZodObject<{
122
+ eventType: z.ZodLiteral<"message_complete">;
123
+ content: z.ZodNullable<z.ZodString>;
124
+ reasoning: z.ZodOptional<z.ZodString>;
125
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
126
+ id: z.ZodString;
127
+ blockIndex: z.ZodNumber;
128
+ type: z.ZodLiteral<"function">;
129
+ function: z.ZodObject<{
130
+ name: z.ZodString;
131
+ arguments: z.ZodString;
132
+ }, z.core.$strip>;
133
+ }, z.core.$strip>>>;
134
+ finish_reason: z.ZodNullable<z.ZodEnum<{
135
+ end_turn: "end_turn";
136
+ max_tokens: "max_tokens";
137
+ stop_sequence: "stop_sequence";
138
+ tool_use: "tool_use";
139
+ pause_turn: "pause_turn";
140
+ }>>;
141
+ }, z.core.$strip>, z.ZodObject<{
142
+ eventType: z.ZodLiteral<"reasoning_delta">;
143
+ content: z.ZodString;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ eventType: z.ZodLiteral<"reasoning_complete">;
146
+ content: z.ZodString;
147
+ signature: z.ZodOptional<z.ZodString>;
148
+ }, z.core.$strip>, z.ZodObject<{
149
+ eventType: z.ZodLiteral<"agent_started">;
150
+ model: z.ZodOptional<z.ZodString>;
151
+ }, z.core.$strip>, z.ZodObject<{
152
+ eventType: z.ZodLiteral<"agent_complete">;
153
+ message: z.ZodOptional<z.ZodString>;
154
+ error: z.ZodOptional<z.ZodString>;
155
+ }, z.core.$strip>, z.ZodObject<{
156
+ eventType: z.ZodLiteral<"error">;
157
+ message: z.ZodString;
158
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
159
+ type: z.ZodOptional<z.ZodString>;
160
+ }, z.core.$strip>, z.ZodObject<{
161
+ eventType: z.ZodLiteral<"tool_started">;
162
+ toolName: z.ZodString;
163
+ toolCallId: z.ZodString;
164
+ }, z.core.$strip>, z.ZodObject<{
165
+ eventType: z.ZodLiteral<"tool_completed">;
166
+ toolName: z.ZodString;
167
+ toolCallId: z.ZodString;
168
+ result: z.ZodString;
169
+ success: z.ZodBoolean;
170
+ }, z.core.$strip>], "eventType">;
171
+ type SdkEventMessage = z.infer<typeof SdkEventMessageSchema>;
172
+ /**
173
+ * Envelope schema for sdk.event catch-all subject.
174
+ * Wraps the discriminated union in an envelope for proper TypeScript narrowing at emit time.
175
+ * Pattern matches codex-mcp's \{ id, msg \} envelope.
176
+ */
177
+ declare const SdkEventSchema: z.ZodObject<{
178
+ event: z.ZodDiscriminatedUnion<[z.ZodObject<{
179
+ eventType: z.ZodLiteral<"chunk">;
180
+ index: z.ZodNumber;
181
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
182
+ type: z.ZodLiteral<"text_delta">;
183
+ text: z.ZodString;
184
+ }, z.core.$strip>, z.ZodObject<{
185
+ type: z.ZodLiteral<"thinking_delta">;
186
+ thinking: z.ZodString;
187
+ }, z.core.$strip>, z.ZodObject<{
188
+ type: z.ZodLiteral<"input_json_delta">;
189
+ partial_json: z.ZodString;
190
+ }, z.core.$strip>], "type">;
191
+ }, z.core.$strip>, z.ZodObject<{
192
+ eventType: z.ZodLiteral<"usage">;
193
+ prompt_tokens: z.ZodNumber;
194
+ completion_tokens: z.ZodNumber;
195
+ total_tokens: z.ZodNumber;
196
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
197
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
198
+ }, z.core.$strip>, z.ZodObject<{
199
+ eventType: z.ZodLiteral<"tool_calls">;
200
+ toolCalls: z.ZodArray<z.ZodObject<{
201
+ id: z.ZodString;
202
+ type: z.ZodLiteral<"function">;
203
+ function: z.ZodObject<{
204
+ name: z.ZodString;
205
+ arguments: z.ZodString;
206
+ }, z.core.$strip>;
207
+ blockIndex: z.ZodNumber;
208
+ }, z.core.$strip>>;
209
+ }, z.core.$strip>, z.ZodObject<{
210
+ eventType: z.ZodLiteral<"message_complete">;
211
+ content: z.ZodNullable<z.ZodString>;
212
+ reasoning: z.ZodOptional<z.ZodString>;
213
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
214
+ id: z.ZodString;
215
+ blockIndex: z.ZodNumber;
216
+ type: z.ZodLiteral<"function">;
217
+ function: z.ZodObject<{
218
+ name: z.ZodString;
219
+ arguments: z.ZodString;
220
+ }, z.core.$strip>;
221
+ }, z.core.$strip>>>;
222
+ finish_reason: z.ZodNullable<z.ZodEnum<{
223
+ end_turn: "end_turn";
224
+ max_tokens: "max_tokens";
225
+ stop_sequence: "stop_sequence";
226
+ tool_use: "tool_use";
227
+ pause_turn: "pause_turn";
228
+ }>>;
229
+ }, z.core.$strip>, z.ZodObject<{
230
+ eventType: z.ZodLiteral<"reasoning_delta">;
231
+ content: z.ZodString;
232
+ }, z.core.$strip>, z.ZodObject<{
233
+ eventType: z.ZodLiteral<"reasoning_complete">;
234
+ content: z.ZodString;
235
+ signature: z.ZodOptional<z.ZodString>;
236
+ }, z.core.$strip>, z.ZodObject<{
237
+ eventType: z.ZodLiteral<"agent_started">;
238
+ model: z.ZodOptional<z.ZodString>;
239
+ }, z.core.$strip>, z.ZodObject<{
240
+ eventType: z.ZodLiteral<"agent_complete">;
241
+ message: z.ZodOptional<z.ZodString>;
242
+ error: z.ZodOptional<z.ZodString>;
243
+ }, z.core.$strip>, z.ZodObject<{
244
+ eventType: z.ZodLiteral<"error">;
245
+ message: z.ZodString;
246
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
247
+ type: z.ZodOptional<z.ZodString>;
248
+ }, z.core.$strip>, z.ZodObject<{
249
+ eventType: z.ZodLiteral<"tool_started">;
250
+ toolName: z.ZodString;
251
+ toolCallId: z.ZodString;
252
+ }, z.core.$strip>, z.ZodObject<{
253
+ eventType: z.ZodLiteral<"tool_completed">;
254
+ toolName: z.ZodString;
255
+ toolCallId: z.ZodString;
256
+ result: z.ZodString;
257
+ success: z.ZodBoolean;
258
+ }, z.core.$strip>], "eventType">;
259
+ adapterName: z.ZodOptional<z.ZodString>;
260
+ agentId: z.ZodOptional<z.ZodString>;
261
+ adapterId: z.ZodOptional<z.ZodString>;
262
+ adapterSessionId: z.ZodOptional<z.ZodString>;
263
+ sessionId: z.ZodOptional<z.ZodString>;
264
+ }, z.core.$strip>;
265
+ type SdkEvent = z.infer<typeof SdkEventSchema>;
266
+ /**
267
+ * Anthropic SDK Adapter Namespace with semantic subjects.
268
+ *
269
+ * Provides typed subjects for:
270
+ * - sdk.event: Catch-all for raw SDK events (for observability/debugging)
271
+ * - tool_approval: RPC for tool execution approval
272
+ * - Semantic subjects: Individual typed events for agent layer processing
273
+ */
274
+ declare const AnthropicSdkConnectorNamespace: _$_makaio_bus_core0.BusNamespace<"adapter:anthropic-sdk", _$_makaio_core0.SubjectRecordFromSchemaRecord<{
275
+ 'sdk.raw': z.ZodCustom<RawMessageStreamEvent, RawMessageStreamEvent>;
276
+ 'sdk.event': z.ZodObject<{
277
+ event: z.ZodDiscriminatedUnion<[z.ZodObject<{
278
+ eventType: z.ZodLiteral<"chunk">;
279
+ index: z.ZodNumber;
280
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
281
+ type: z.ZodLiteral<"text_delta">;
282
+ text: z.ZodString;
283
+ }, z.core.$strip>, z.ZodObject<{
284
+ type: z.ZodLiteral<"thinking_delta">;
285
+ thinking: z.ZodString;
286
+ }, z.core.$strip>, z.ZodObject<{
287
+ type: z.ZodLiteral<"input_json_delta">;
288
+ partial_json: z.ZodString;
289
+ }, z.core.$strip>], "type">;
290
+ }, z.core.$strip>, z.ZodObject<{
291
+ eventType: z.ZodLiteral<"usage">;
292
+ prompt_tokens: z.ZodNumber;
293
+ completion_tokens: z.ZodNumber;
294
+ total_tokens: z.ZodNumber;
295
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
296
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
297
+ }, z.core.$strip>, z.ZodObject<{
298
+ eventType: z.ZodLiteral<"tool_calls">;
299
+ toolCalls: z.ZodArray<z.ZodObject<{
300
+ id: z.ZodString;
301
+ type: z.ZodLiteral<"function">;
302
+ function: z.ZodObject<{
303
+ name: z.ZodString;
304
+ arguments: z.ZodString;
305
+ }, z.core.$strip>;
306
+ blockIndex: z.ZodNumber;
307
+ }, z.core.$strip>>;
308
+ }, z.core.$strip>, z.ZodObject<{
309
+ eventType: z.ZodLiteral<"message_complete">;
310
+ content: z.ZodNullable<z.ZodString>;
311
+ reasoning: z.ZodOptional<z.ZodString>;
312
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
313
+ id: z.ZodString;
314
+ blockIndex: z.ZodNumber;
315
+ type: z.ZodLiteral<"function">;
316
+ function: z.ZodObject<{
317
+ name: z.ZodString;
318
+ arguments: z.ZodString;
319
+ }, z.core.$strip>;
320
+ }, z.core.$strip>>>;
321
+ finish_reason: z.ZodNullable<z.ZodEnum<{
322
+ end_turn: "end_turn";
323
+ max_tokens: "max_tokens";
324
+ stop_sequence: "stop_sequence";
325
+ tool_use: "tool_use";
326
+ pause_turn: "pause_turn";
327
+ }>>;
328
+ }, z.core.$strip>, z.ZodObject<{
329
+ eventType: z.ZodLiteral<"reasoning_delta">;
330
+ content: z.ZodString;
331
+ }, z.core.$strip>, z.ZodObject<{
332
+ eventType: z.ZodLiteral<"reasoning_complete">;
333
+ content: z.ZodString;
334
+ signature: z.ZodOptional<z.ZodString>;
335
+ }, z.core.$strip>, z.ZodObject<{
336
+ eventType: z.ZodLiteral<"agent_started">;
337
+ model: z.ZodOptional<z.ZodString>;
338
+ }, z.core.$strip>, z.ZodObject<{
339
+ eventType: z.ZodLiteral<"agent_complete">;
340
+ message: z.ZodOptional<z.ZodString>;
341
+ error: z.ZodOptional<z.ZodString>;
342
+ }, z.core.$strip>, z.ZodObject<{
343
+ eventType: z.ZodLiteral<"error">;
344
+ message: z.ZodString;
345
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
346
+ type: z.ZodOptional<z.ZodString>;
347
+ }, z.core.$strip>, z.ZodObject<{
348
+ eventType: z.ZodLiteral<"tool_started">;
349
+ toolName: z.ZodString;
350
+ toolCallId: z.ZodString;
351
+ }, z.core.$strip>, z.ZodObject<{
352
+ eventType: z.ZodLiteral<"tool_completed">;
353
+ toolName: z.ZodString;
354
+ toolCallId: z.ZodString;
355
+ result: z.ZodString;
356
+ success: z.ZodBoolean;
357
+ }, z.core.$strip>], "eventType">;
358
+ adapterName: z.ZodOptional<z.ZodString>;
359
+ agentId: z.ZodOptional<z.ZodString>;
360
+ adapterId: z.ZodOptional<z.ZodString>;
361
+ adapterSessionId: z.ZodOptional<z.ZodString>;
362
+ sessionId: z.ZodOptional<z.ZodString>;
363
+ }, z.core.$strip>;
364
+ tool_approval: {
365
+ request: z.ZodObject<{
366
+ agentId: z.ZodString;
367
+ adapterId: z.ZodString;
368
+ adapterName: z.ZodString;
369
+ adapterSessionId: z.ZodString;
370
+ messageId: z.ZodOptional<z.ZodString>;
371
+ turnId: z.ZodOptional<z.ZodString>;
372
+ clientId: z.ZodOptional<z.ZodString>;
373
+ providerConfigId: z.ZodOptional<z.ZodString>;
374
+ occurredAt: z.ZodOptional<z.ZodNumber>;
375
+ toolName: z.ZodOptional<z.ZodString>;
376
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
377
+ toolCallId: z.ZodString;
378
+ reasoning: z.ZodOptional<z.ZodString>;
379
+ sessionId: z.ZodOptional<z.ZodString>;
380
+ }, z.core.$strip>;
381
+ response: z.ZodDiscriminatedUnion<[z.ZodObject<{
382
+ action: z.ZodLiteral<"allow">;
383
+ updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
384
+ updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
385
+ }, z.core.$strip>, z.ZodObject<{
386
+ action: z.ZodLiteral<"deny">;
387
+ message: z.ZodString;
388
+ shouldAbort: z.ZodOptional<z.ZodBoolean>;
389
+ }, z.core.$strip>], "action">;
390
+ };
391
+ chunk: z.ZodObject<{
392
+ eventType: z.ZodLiteral<"chunk">;
393
+ index: z.ZodNumber;
394
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
395
+ type: z.ZodLiteral<"text_delta">;
396
+ text: z.ZodString;
397
+ }, z.core.$strip>, z.ZodObject<{
398
+ type: z.ZodLiteral<"thinking_delta">;
399
+ thinking: z.ZodString;
400
+ }, z.core.$strip>, z.ZodObject<{
401
+ type: z.ZodLiteral<"input_json_delta">;
402
+ partial_json: z.ZodString;
403
+ }, z.core.$strip>], "type">;
404
+ }, z.core.$strip>;
405
+ usage: z.ZodObject<{
406
+ eventType: z.ZodLiteral<"usage">;
407
+ prompt_tokens: z.ZodNumber;
408
+ completion_tokens: z.ZodNumber;
409
+ total_tokens: z.ZodNumber;
410
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
411
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
412
+ }, z.core.$strip>;
413
+ message_complete: z.ZodObject<{
414
+ eventType: z.ZodLiteral<"message_complete">;
415
+ content: z.ZodNullable<z.ZodString>;
416
+ reasoning: z.ZodOptional<z.ZodString>;
417
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
418
+ id: z.ZodString;
419
+ blockIndex: z.ZodNumber;
420
+ type: z.ZodLiteral<"function">;
421
+ function: z.ZodObject<{
422
+ name: z.ZodString;
423
+ arguments: z.ZodString;
424
+ }, z.core.$strip>;
425
+ }, z.core.$strip>>>;
426
+ finish_reason: z.ZodNullable<z.ZodEnum<{
427
+ end_turn: "end_turn";
428
+ max_tokens: "max_tokens";
429
+ stop_sequence: "stop_sequence";
430
+ tool_use: "tool_use";
431
+ pause_turn: "pause_turn";
432
+ }>>;
433
+ }, z.core.$strip>;
434
+ reasoning_delta: z.ZodObject<{
435
+ eventType: z.ZodLiteral<"reasoning_delta">;
436
+ content: z.ZodString;
437
+ }, z.core.$strip>;
438
+ reasoning_complete: z.ZodObject<{
439
+ eventType: z.ZodLiteral<"reasoning_complete">;
440
+ content: z.ZodString;
441
+ signature: z.ZodOptional<z.ZodString>;
442
+ }, z.core.$strip>;
443
+ tool_calls: z.ZodObject<{
444
+ eventType: z.ZodLiteral<"tool_calls">;
445
+ toolCalls: z.ZodArray<z.ZodObject<{
446
+ id: z.ZodString;
447
+ type: z.ZodLiteral<"function">;
448
+ function: z.ZodObject<{
449
+ name: z.ZodString;
450
+ arguments: z.ZodString;
451
+ }, z.core.$strip>;
452
+ blockIndex: z.ZodNumber;
453
+ }, z.core.$strip>>;
454
+ }, z.core.$strip>;
455
+ tool_started: z.ZodObject<{
456
+ eventType: z.ZodLiteral<"tool_started">;
457
+ toolName: z.ZodString;
458
+ toolCallId: z.ZodString;
459
+ }, z.core.$strip>;
460
+ tool_completed: z.ZodObject<{
461
+ eventType: z.ZodLiteral<"tool_completed">;
462
+ toolName: z.ZodString;
463
+ toolCallId: z.ZodString;
464
+ result: z.ZodString;
465
+ success: z.ZodBoolean;
466
+ }, z.core.$strip>;
467
+ agent_started: z.ZodObject<{
468
+ eventType: z.ZodLiteral<"agent_started">;
469
+ model: z.ZodOptional<z.ZodString>;
470
+ }, z.core.$strip>;
471
+ agent_complete: z.ZodObject<{
472
+ eventType: z.ZodLiteral<"agent_complete">;
473
+ message: z.ZodOptional<z.ZodString>;
474
+ error: z.ZodOptional<z.ZodString>;
475
+ }, z.core.$strip>;
476
+ error: z.ZodObject<{
477
+ eventType: z.ZodLiteral<"error">;
478
+ message: z.ZodString;
479
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
480
+ type: z.ZodOptional<z.ZodString>;
481
+ }, z.core.$strip>;
482
+ 'turn.state_changed': z.ZodObject<{
483
+ adapterId: z.ZodString;
484
+ agentId: z.ZodString;
485
+ oldState: z.ZodEnum<{
486
+ idle: "idle";
487
+ turn_started: "turn_started";
488
+ step_started: "step_started";
489
+ step_finished: "step_finished";
490
+ turn_finished: "turn_finished";
491
+ }>;
492
+ newState: z.ZodEnum<{
493
+ idle: "idle";
494
+ turn_started: "turn_started";
495
+ step_started: "step_started";
496
+ step_finished: "step_finished";
497
+ turn_finished: "turn_finished";
498
+ }>;
499
+ timestamp: z.ZodNumber;
500
+ }, z.core.$strip>;
501
+ 'turn.turn_started': z.ZodObject<{
502
+ adapterId: z.ZodString;
503
+ agentId: z.ZodString;
504
+ oldState: z.ZodEnum<{
505
+ idle: "idle";
506
+ turn_started: "turn_started";
507
+ step_started: "step_started";
508
+ step_finished: "step_finished";
509
+ turn_finished: "turn_finished";
510
+ }>;
511
+ newState: z.ZodEnum<{
512
+ idle: "idle";
513
+ turn_started: "turn_started";
514
+ step_started: "step_started";
515
+ step_finished: "step_finished";
516
+ turn_finished: "turn_finished";
517
+ }>;
518
+ timestamp: z.ZodNumber;
519
+ }, z.core.$strip>;
520
+ 'turn.step_started': z.ZodObject<{
521
+ adapterId: z.ZodString;
522
+ agentId: z.ZodString;
523
+ oldState: z.ZodEnum<{
524
+ idle: "idle";
525
+ turn_started: "turn_started";
526
+ step_started: "step_started";
527
+ step_finished: "step_finished";
528
+ turn_finished: "turn_finished";
529
+ }>;
530
+ newState: z.ZodEnum<{
531
+ idle: "idle";
532
+ turn_started: "turn_started";
533
+ step_started: "step_started";
534
+ step_finished: "step_finished";
535
+ turn_finished: "turn_finished";
536
+ }>;
537
+ timestamp: z.ZodNumber;
538
+ }, z.core.$strip>;
539
+ 'turn.step_finished': z.ZodObject<{
540
+ adapterId: z.ZodString;
541
+ agentId: z.ZodString;
542
+ oldState: z.ZodEnum<{
543
+ idle: "idle";
544
+ turn_started: "turn_started";
545
+ step_started: "step_started";
546
+ step_finished: "step_finished";
547
+ turn_finished: "turn_finished";
548
+ }>;
549
+ newState: z.ZodEnum<{
550
+ idle: "idle";
551
+ turn_started: "turn_started";
552
+ step_started: "step_started";
553
+ step_finished: "step_finished";
554
+ turn_finished: "turn_finished";
555
+ }>;
556
+ timestamp: z.ZodNumber;
557
+ }, z.core.$strip>;
558
+ 'turn.turn_finished': z.ZodObject<{
559
+ adapterId: z.ZodString;
560
+ agentId: z.ZodString;
561
+ oldState: z.ZodEnum<{
562
+ idle: "idle";
563
+ turn_started: "turn_started";
564
+ step_started: "step_started";
565
+ step_finished: "step_finished";
566
+ turn_finished: "turn_finished";
567
+ }>;
568
+ newState: z.ZodEnum<{
569
+ idle: "idle";
570
+ turn_started: "turn_started";
571
+ step_started: "step_started";
572
+ step_finished: "step_finished";
573
+ turn_finished: "turn_finished";
574
+ }>;
575
+ timestamp: z.ZodNumber;
576
+ }, z.core.$strip>;
577
+ }>, {
578
+ eventType: "chunk" | "usage" | "tool_calls" | "error" | "message_complete" | "reasoning_delta" | "reasoning_complete" | "agent_started" | "agent_complete" | "tool_started" | "tool_completed";
579
+ delta: {
580
+ type: "text_delta";
581
+ text: string;
582
+ } | {
583
+ type: "thinking_delta";
584
+ thinking: string;
585
+ } | {
586
+ type: "input_json_delta";
587
+ partial_json: string;
588
+ } | _$_anthropic_ai_sdk_resources_js0.RawMessageDeltaEvent.Delta | _$_anthropic_ai_sdk_resources_js0.RawContentBlockDelta;
589
+ index: number;
590
+ type: "message_start" | "message_delta" | "message_stop" | "content_block_start" | "content_block_delta" | "content_block_stop";
591
+ success: boolean;
592
+ usage: _$_anthropic_ai_sdk_resources_js0.MessageDeltaUsage;
593
+ prompt_tokens: number;
594
+ completion_tokens: number;
595
+ total_tokens: number;
596
+ cache_read_input_tokens: never;
597
+ cache_creation_input_tokens: never;
598
+ tool_calls: never;
599
+ toolCalls: {
600
+ id: string;
601
+ type: "function";
602
+ function: {
603
+ name: string;
604
+ arguments: string;
605
+ };
606
+ blockIndex: number;
607
+ }[];
608
+ message: string | _$_anthropic_ai_sdk_resources_js0.Message;
609
+ code: never;
610
+ error: never;
611
+ content: string | null;
612
+ reasoning: never;
613
+ finish_reason: "end_turn" | "max_tokens" | "stop_sequence" | "tool_use" | "pause_turn" | null;
614
+ signature: never;
615
+ model: never;
616
+ toolName: string;
617
+ toolCallId: string;
618
+ result: string;
619
+ event: {
620
+ eventType: "chunk";
621
+ index: number;
622
+ delta: {
623
+ type: "text_delta";
624
+ text: string;
625
+ } | {
626
+ type: "thinking_delta";
627
+ thinking: string;
628
+ } | {
629
+ type: "input_json_delta";
630
+ partial_json: string;
631
+ };
632
+ } | {
633
+ eventType: "usage";
634
+ prompt_tokens: number;
635
+ completion_tokens: number;
636
+ total_tokens: number;
637
+ cache_read_input_tokens?: number | undefined;
638
+ cache_creation_input_tokens?: number | undefined;
639
+ } | {
640
+ eventType: "tool_calls";
641
+ toolCalls: {
642
+ id: string;
643
+ type: "function";
644
+ function: {
645
+ name: string;
646
+ arguments: string;
647
+ };
648
+ blockIndex: number;
649
+ }[];
650
+ } | {
651
+ eventType: "message_complete";
652
+ content: string | null;
653
+ finish_reason: "end_turn" | "max_tokens" | "stop_sequence" | "tool_use" | "pause_turn" | null;
654
+ reasoning?: string | undefined;
655
+ tool_calls?: {
656
+ id: string;
657
+ blockIndex: number;
658
+ type: "function";
659
+ function: {
660
+ name: string;
661
+ arguments: string;
662
+ };
663
+ }[] | undefined;
664
+ } | {
665
+ eventType: "reasoning_delta";
666
+ content: string;
667
+ } | {
668
+ eventType: "reasoning_complete";
669
+ content: string;
670
+ signature?: string | undefined;
671
+ } | {
672
+ eventType: "agent_started";
673
+ model?: string | undefined;
674
+ } | {
675
+ eventType: "agent_complete";
676
+ message?: string | undefined;
677
+ error?: string | undefined;
678
+ } | {
679
+ eventType: "error";
680
+ message: string;
681
+ code?: string | number | undefined;
682
+ type?: string | undefined;
683
+ } | {
684
+ eventType: "tool_started";
685
+ toolName: string;
686
+ toolCallId: string;
687
+ } | {
688
+ eventType: "tool_completed";
689
+ toolName: string;
690
+ toolCallId: string;
691
+ result: string;
692
+ success: boolean;
693
+ };
694
+ adapterName: string;
695
+ agentId: string;
696
+ adapterId: string;
697
+ adapterSessionId: string;
698
+ sessionId: never;
699
+ messageId: never;
700
+ turnId: never;
701
+ clientId: never;
702
+ providerConfigId: never;
703
+ occurredAt: never;
704
+ args: never;
705
+ oldState: "idle" | "turn_started" | "step_started" | "step_finished" | "turn_finished";
706
+ newState: "idle" | "turn_started" | "step_started" | "step_finished" | "turn_finished";
707
+ timestamp: number;
708
+ content_block: _$_anthropic_ai_sdk_resources_js0.TextBlock | _$_anthropic_ai_sdk_resources_js0.ThinkingBlock | _$_anthropic_ai_sdk_resources_js0.RedactedThinkingBlock | _$_anthropic_ai_sdk_resources_js0.ToolUseBlock | _$_anthropic_ai_sdk_resources_js0.ServerToolUseBlock | _$_anthropic_ai_sdk_resources_js0.WebSearchToolResultBlock | _$_anthropic_ai_sdk_resources_js0.WebFetchToolResultBlock | _$_anthropic_ai_sdk_resources_js0.CodeExecutionToolResultBlock | _$_anthropic_ai_sdk_resources_js0.BashCodeExecutionToolResultBlock | _$_anthropic_ai_sdk_resources_js0.TextEditorCodeExecutionToolResultBlock | _$_anthropic_ai_sdk_resources_js0.ToolSearchToolResultBlock | _$_anthropic_ai_sdk_resources_js0.ContainerUploadBlock;
709
+ }, {
710
+ 'sdk.raw': z.ZodCustom<RawMessageStreamEvent, RawMessageStreamEvent>;
711
+ 'sdk.event': z.ZodObject<{
712
+ event: z.ZodDiscriminatedUnion<[z.ZodObject<{
713
+ eventType: z.ZodLiteral<"chunk">;
714
+ index: z.ZodNumber;
715
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
716
+ type: z.ZodLiteral<"text_delta">;
717
+ text: z.ZodString;
718
+ }, z.core.$strip>, z.ZodObject<{
719
+ type: z.ZodLiteral<"thinking_delta">;
720
+ thinking: z.ZodString;
721
+ }, z.core.$strip>, z.ZodObject<{
722
+ type: z.ZodLiteral<"input_json_delta">;
723
+ partial_json: z.ZodString;
724
+ }, z.core.$strip>], "type">;
725
+ }, z.core.$strip>, z.ZodObject<{
726
+ eventType: z.ZodLiteral<"usage">;
727
+ prompt_tokens: z.ZodNumber;
728
+ completion_tokens: z.ZodNumber;
729
+ total_tokens: z.ZodNumber;
730
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
731
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
732
+ }, z.core.$strip>, z.ZodObject<{
733
+ eventType: z.ZodLiteral<"tool_calls">;
734
+ toolCalls: z.ZodArray<z.ZodObject<{
735
+ id: z.ZodString;
736
+ type: z.ZodLiteral<"function">;
737
+ function: z.ZodObject<{
738
+ name: z.ZodString;
739
+ arguments: z.ZodString;
740
+ }, z.core.$strip>;
741
+ blockIndex: z.ZodNumber;
742
+ }, z.core.$strip>>;
743
+ }, z.core.$strip>, z.ZodObject<{
744
+ eventType: z.ZodLiteral<"message_complete">;
745
+ content: z.ZodNullable<z.ZodString>;
746
+ reasoning: z.ZodOptional<z.ZodString>;
747
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
748
+ id: z.ZodString;
749
+ blockIndex: z.ZodNumber;
750
+ type: z.ZodLiteral<"function">;
751
+ function: z.ZodObject<{
752
+ name: z.ZodString;
753
+ arguments: z.ZodString;
754
+ }, z.core.$strip>;
755
+ }, z.core.$strip>>>;
756
+ finish_reason: z.ZodNullable<z.ZodEnum<{
757
+ end_turn: "end_turn";
758
+ max_tokens: "max_tokens";
759
+ stop_sequence: "stop_sequence";
760
+ tool_use: "tool_use";
761
+ pause_turn: "pause_turn";
762
+ }>>;
763
+ }, z.core.$strip>, z.ZodObject<{
764
+ eventType: z.ZodLiteral<"reasoning_delta">;
765
+ content: z.ZodString;
766
+ }, z.core.$strip>, z.ZodObject<{
767
+ eventType: z.ZodLiteral<"reasoning_complete">;
768
+ content: z.ZodString;
769
+ signature: z.ZodOptional<z.ZodString>;
770
+ }, z.core.$strip>, z.ZodObject<{
771
+ eventType: z.ZodLiteral<"agent_started">;
772
+ model: z.ZodOptional<z.ZodString>;
773
+ }, z.core.$strip>, z.ZodObject<{
774
+ eventType: z.ZodLiteral<"agent_complete">;
775
+ message: z.ZodOptional<z.ZodString>;
776
+ error: z.ZodOptional<z.ZodString>;
777
+ }, z.core.$strip>, z.ZodObject<{
778
+ eventType: z.ZodLiteral<"error">;
779
+ message: z.ZodString;
780
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
781
+ type: z.ZodOptional<z.ZodString>;
782
+ }, z.core.$strip>, z.ZodObject<{
783
+ eventType: z.ZodLiteral<"tool_started">;
784
+ toolName: z.ZodString;
785
+ toolCallId: z.ZodString;
786
+ }, z.core.$strip>, z.ZodObject<{
787
+ eventType: z.ZodLiteral<"tool_completed">;
788
+ toolName: z.ZodString;
789
+ toolCallId: z.ZodString;
790
+ result: z.ZodString;
791
+ success: z.ZodBoolean;
792
+ }, z.core.$strip>], "eventType">;
793
+ adapterName: z.ZodOptional<z.ZodString>;
794
+ agentId: z.ZodOptional<z.ZodString>;
795
+ adapterId: z.ZodOptional<z.ZodString>;
796
+ adapterSessionId: z.ZodOptional<z.ZodString>;
797
+ sessionId: z.ZodOptional<z.ZodString>;
798
+ }, z.core.$strip>;
799
+ tool_approval: {
800
+ request: z.ZodObject<{
801
+ agentId: z.ZodString;
802
+ adapterId: z.ZodString;
803
+ adapterName: z.ZodString;
804
+ adapterSessionId: z.ZodString;
805
+ messageId: z.ZodOptional<z.ZodString>;
806
+ turnId: z.ZodOptional<z.ZodString>;
807
+ clientId: z.ZodOptional<z.ZodString>;
808
+ providerConfigId: z.ZodOptional<z.ZodString>;
809
+ occurredAt: z.ZodOptional<z.ZodNumber>;
810
+ toolName: z.ZodOptional<z.ZodString>;
811
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
812
+ toolCallId: z.ZodString;
813
+ reasoning: z.ZodOptional<z.ZodString>;
814
+ sessionId: z.ZodOptional<z.ZodString>;
815
+ }, z.core.$strip>;
816
+ response: z.ZodDiscriminatedUnion<[z.ZodObject<{
817
+ action: z.ZodLiteral<"allow">;
818
+ updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
819
+ updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
820
+ }, z.core.$strip>, z.ZodObject<{
821
+ action: z.ZodLiteral<"deny">;
822
+ message: z.ZodString;
823
+ shouldAbort: z.ZodOptional<z.ZodBoolean>;
824
+ }, z.core.$strip>], "action">;
825
+ };
826
+ chunk: z.ZodObject<{
827
+ eventType: z.ZodLiteral<"chunk">;
828
+ index: z.ZodNumber;
829
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
830
+ type: z.ZodLiteral<"text_delta">;
831
+ text: z.ZodString;
832
+ }, z.core.$strip>, z.ZodObject<{
833
+ type: z.ZodLiteral<"thinking_delta">;
834
+ thinking: z.ZodString;
835
+ }, z.core.$strip>, z.ZodObject<{
836
+ type: z.ZodLiteral<"input_json_delta">;
837
+ partial_json: z.ZodString;
838
+ }, z.core.$strip>], "type">;
839
+ }, z.core.$strip>;
840
+ usage: z.ZodObject<{
841
+ eventType: z.ZodLiteral<"usage">;
842
+ prompt_tokens: z.ZodNumber;
843
+ completion_tokens: z.ZodNumber;
844
+ total_tokens: z.ZodNumber;
845
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
846
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
847
+ }, z.core.$strip>;
848
+ message_complete: z.ZodObject<{
849
+ eventType: z.ZodLiteral<"message_complete">;
850
+ content: z.ZodNullable<z.ZodString>;
851
+ reasoning: z.ZodOptional<z.ZodString>;
852
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
853
+ id: z.ZodString;
854
+ blockIndex: z.ZodNumber;
855
+ type: z.ZodLiteral<"function">;
856
+ function: z.ZodObject<{
857
+ name: z.ZodString;
858
+ arguments: z.ZodString;
859
+ }, z.core.$strip>;
860
+ }, z.core.$strip>>>;
861
+ finish_reason: z.ZodNullable<z.ZodEnum<{
862
+ end_turn: "end_turn";
863
+ max_tokens: "max_tokens";
864
+ stop_sequence: "stop_sequence";
865
+ tool_use: "tool_use";
866
+ pause_turn: "pause_turn";
867
+ }>>;
868
+ }, z.core.$strip>;
869
+ reasoning_delta: z.ZodObject<{
870
+ eventType: z.ZodLiteral<"reasoning_delta">;
871
+ content: z.ZodString;
872
+ }, z.core.$strip>;
873
+ reasoning_complete: z.ZodObject<{
874
+ eventType: z.ZodLiteral<"reasoning_complete">;
875
+ content: z.ZodString;
876
+ signature: z.ZodOptional<z.ZodString>;
877
+ }, z.core.$strip>;
878
+ tool_calls: z.ZodObject<{
879
+ eventType: z.ZodLiteral<"tool_calls">;
880
+ toolCalls: z.ZodArray<z.ZodObject<{
881
+ id: z.ZodString;
882
+ type: z.ZodLiteral<"function">;
883
+ function: z.ZodObject<{
884
+ name: z.ZodString;
885
+ arguments: z.ZodString;
886
+ }, z.core.$strip>;
887
+ blockIndex: z.ZodNumber;
888
+ }, z.core.$strip>>;
889
+ }, z.core.$strip>;
890
+ tool_started: z.ZodObject<{
891
+ eventType: z.ZodLiteral<"tool_started">;
892
+ toolName: z.ZodString;
893
+ toolCallId: z.ZodString;
894
+ }, z.core.$strip>;
895
+ tool_completed: z.ZodObject<{
896
+ eventType: z.ZodLiteral<"tool_completed">;
897
+ toolName: z.ZodString;
898
+ toolCallId: z.ZodString;
899
+ result: z.ZodString;
900
+ success: z.ZodBoolean;
901
+ }, z.core.$strip>;
902
+ agent_started: z.ZodObject<{
903
+ eventType: z.ZodLiteral<"agent_started">;
904
+ model: z.ZodOptional<z.ZodString>;
905
+ }, z.core.$strip>;
906
+ agent_complete: z.ZodObject<{
907
+ eventType: z.ZodLiteral<"agent_complete">;
908
+ message: z.ZodOptional<z.ZodString>;
909
+ error: z.ZodOptional<z.ZodString>;
910
+ }, z.core.$strip>;
911
+ error: z.ZodObject<{
912
+ eventType: z.ZodLiteral<"error">;
913
+ message: z.ZodString;
914
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
915
+ type: z.ZodOptional<z.ZodString>;
916
+ }, z.core.$strip>;
917
+ 'turn.state_changed': z.ZodObject<{
918
+ adapterId: z.ZodString;
919
+ agentId: z.ZodString;
920
+ oldState: z.ZodEnum<{
921
+ idle: "idle";
922
+ turn_started: "turn_started";
923
+ step_started: "step_started";
924
+ step_finished: "step_finished";
925
+ turn_finished: "turn_finished";
926
+ }>;
927
+ newState: z.ZodEnum<{
928
+ idle: "idle";
929
+ turn_started: "turn_started";
930
+ step_started: "step_started";
931
+ step_finished: "step_finished";
932
+ turn_finished: "turn_finished";
933
+ }>;
934
+ timestamp: z.ZodNumber;
935
+ }, z.core.$strip>;
936
+ 'turn.turn_started': z.ZodObject<{
937
+ adapterId: z.ZodString;
938
+ agentId: z.ZodString;
939
+ oldState: z.ZodEnum<{
940
+ idle: "idle";
941
+ turn_started: "turn_started";
942
+ step_started: "step_started";
943
+ step_finished: "step_finished";
944
+ turn_finished: "turn_finished";
945
+ }>;
946
+ newState: z.ZodEnum<{
947
+ idle: "idle";
948
+ turn_started: "turn_started";
949
+ step_started: "step_started";
950
+ step_finished: "step_finished";
951
+ turn_finished: "turn_finished";
952
+ }>;
953
+ timestamp: z.ZodNumber;
954
+ }, z.core.$strip>;
955
+ 'turn.step_started': z.ZodObject<{
956
+ adapterId: z.ZodString;
957
+ agentId: z.ZodString;
958
+ oldState: z.ZodEnum<{
959
+ idle: "idle";
960
+ turn_started: "turn_started";
961
+ step_started: "step_started";
962
+ step_finished: "step_finished";
963
+ turn_finished: "turn_finished";
964
+ }>;
965
+ newState: z.ZodEnum<{
966
+ idle: "idle";
967
+ turn_started: "turn_started";
968
+ step_started: "step_started";
969
+ step_finished: "step_finished";
970
+ turn_finished: "turn_finished";
971
+ }>;
972
+ timestamp: z.ZodNumber;
973
+ }, z.core.$strip>;
974
+ 'turn.step_finished': z.ZodObject<{
975
+ adapterId: z.ZodString;
976
+ agentId: z.ZodString;
977
+ oldState: z.ZodEnum<{
978
+ idle: "idle";
979
+ turn_started: "turn_started";
980
+ step_started: "step_started";
981
+ step_finished: "step_finished";
982
+ turn_finished: "turn_finished";
983
+ }>;
984
+ newState: z.ZodEnum<{
985
+ idle: "idle";
986
+ turn_started: "turn_started";
987
+ step_started: "step_started";
988
+ step_finished: "step_finished";
989
+ turn_finished: "turn_finished";
990
+ }>;
991
+ timestamp: z.ZodNumber;
992
+ }, z.core.$strip>;
993
+ 'turn.turn_finished': z.ZodObject<{
994
+ adapterId: z.ZodString;
995
+ agentId: z.ZodString;
996
+ oldState: z.ZodEnum<{
997
+ idle: "idle";
998
+ turn_started: "turn_started";
999
+ step_started: "step_started";
1000
+ step_finished: "step_finished";
1001
+ turn_finished: "turn_finished";
1002
+ }>;
1003
+ newState: z.ZodEnum<{
1004
+ idle: "idle";
1005
+ turn_started: "turn_started";
1006
+ step_started: "step_started";
1007
+ step_finished: "step_finished";
1008
+ turn_finished: "turn_finished";
1009
+ }>;
1010
+ timestamp: z.ZodNumber;
1011
+ }, z.core.$strip>;
1012
+ }>;
1013
+ /**
1014
+ * Typed subject literals for Anthropic SDK adapter.
1015
+ * Use these constants to subscribe to specific message types with full type safety.
1016
+ * @example
1017
+ * ```typescript
1018
+ * connector.on(AnthropicSdkSubjects.chunk, (ctx) => {
1019
+ * // ctx.payload is typed as ChunkEvent
1020
+ * console.debug(ctx.payload.delta);
1021
+ * });
1022
+ * ```
1023
+ */
1024
+ declare const AnthropicSdkConnectorSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.FlatSubjectDefinitions<"adapter:anthropic-sdk", {
1025
+ 'sdk.raw': z.ZodCustom<RawMessageStreamEvent, RawMessageStreamEvent>;
1026
+ 'sdk.event': z.ZodObject<{
1027
+ event: z.ZodDiscriminatedUnion<[z.ZodObject<{
1028
+ eventType: z.ZodLiteral<"chunk">;
1029
+ index: z.ZodNumber;
1030
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
1031
+ type: z.ZodLiteral<"text_delta">;
1032
+ text: z.ZodString;
1033
+ }, z.core.$strip>, z.ZodObject<{
1034
+ type: z.ZodLiteral<"thinking_delta">;
1035
+ thinking: z.ZodString;
1036
+ }, z.core.$strip>, z.ZodObject<{
1037
+ type: z.ZodLiteral<"input_json_delta">;
1038
+ partial_json: z.ZodString;
1039
+ }, z.core.$strip>], "type">;
1040
+ }, z.core.$strip>, z.ZodObject<{
1041
+ eventType: z.ZodLiteral<"usage">;
1042
+ prompt_tokens: z.ZodNumber;
1043
+ completion_tokens: z.ZodNumber;
1044
+ total_tokens: z.ZodNumber;
1045
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
1046
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
1047
+ }, z.core.$strip>, z.ZodObject<{
1048
+ eventType: z.ZodLiteral<"tool_calls">;
1049
+ toolCalls: z.ZodArray<z.ZodObject<{
1050
+ id: z.ZodString;
1051
+ type: z.ZodLiteral<"function">;
1052
+ function: z.ZodObject<{
1053
+ name: z.ZodString;
1054
+ arguments: z.ZodString;
1055
+ }, z.core.$strip>;
1056
+ blockIndex: z.ZodNumber;
1057
+ }, z.core.$strip>>;
1058
+ }, z.core.$strip>, z.ZodObject<{
1059
+ eventType: z.ZodLiteral<"message_complete">;
1060
+ content: z.ZodNullable<z.ZodString>;
1061
+ reasoning: z.ZodOptional<z.ZodString>;
1062
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
1063
+ id: z.ZodString;
1064
+ blockIndex: z.ZodNumber;
1065
+ type: z.ZodLiteral<"function">;
1066
+ function: z.ZodObject<{
1067
+ name: z.ZodString;
1068
+ arguments: z.ZodString;
1069
+ }, z.core.$strip>;
1070
+ }, z.core.$strip>>>;
1071
+ finish_reason: z.ZodNullable<z.ZodEnum<{
1072
+ end_turn: "end_turn";
1073
+ max_tokens: "max_tokens";
1074
+ stop_sequence: "stop_sequence";
1075
+ tool_use: "tool_use";
1076
+ pause_turn: "pause_turn";
1077
+ }>>;
1078
+ }, z.core.$strip>, z.ZodObject<{
1079
+ eventType: z.ZodLiteral<"reasoning_delta">;
1080
+ content: z.ZodString;
1081
+ }, z.core.$strip>, z.ZodObject<{
1082
+ eventType: z.ZodLiteral<"reasoning_complete">;
1083
+ content: z.ZodString;
1084
+ signature: z.ZodOptional<z.ZodString>;
1085
+ }, z.core.$strip>, z.ZodObject<{
1086
+ eventType: z.ZodLiteral<"agent_started">;
1087
+ model: z.ZodOptional<z.ZodString>;
1088
+ }, z.core.$strip>, z.ZodObject<{
1089
+ eventType: z.ZodLiteral<"agent_complete">;
1090
+ message: z.ZodOptional<z.ZodString>;
1091
+ error: z.ZodOptional<z.ZodString>;
1092
+ }, z.core.$strip>, z.ZodObject<{
1093
+ eventType: z.ZodLiteral<"error">;
1094
+ message: z.ZodString;
1095
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
1096
+ type: z.ZodOptional<z.ZodString>;
1097
+ }, z.core.$strip>, z.ZodObject<{
1098
+ eventType: z.ZodLiteral<"tool_started">;
1099
+ toolName: z.ZodString;
1100
+ toolCallId: z.ZodString;
1101
+ }, z.core.$strip>, z.ZodObject<{
1102
+ eventType: z.ZodLiteral<"tool_completed">;
1103
+ toolName: z.ZodString;
1104
+ toolCallId: z.ZodString;
1105
+ result: z.ZodString;
1106
+ success: z.ZodBoolean;
1107
+ }, z.core.$strip>], "eventType">;
1108
+ adapterName: z.ZodOptional<z.ZodString>;
1109
+ agentId: z.ZodOptional<z.ZodString>;
1110
+ adapterId: z.ZodOptional<z.ZodString>;
1111
+ adapterSessionId: z.ZodOptional<z.ZodString>;
1112
+ sessionId: z.ZodOptional<z.ZodString>;
1113
+ }, z.core.$strip>;
1114
+ tool_approval: {
1115
+ request: z.ZodObject<{
1116
+ agentId: z.ZodString;
1117
+ adapterId: z.ZodString;
1118
+ adapterName: z.ZodString;
1119
+ adapterSessionId: z.ZodString;
1120
+ messageId: z.ZodOptional<z.ZodString>;
1121
+ turnId: z.ZodOptional<z.ZodString>;
1122
+ clientId: z.ZodOptional<z.ZodString>;
1123
+ providerConfigId: z.ZodOptional<z.ZodString>;
1124
+ occurredAt: z.ZodOptional<z.ZodNumber>;
1125
+ toolName: z.ZodOptional<z.ZodString>;
1126
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1127
+ toolCallId: z.ZodString;
1128
+ reasoning: z.ZodOptional<z.ZodString>;
1129
+ sessionId: z.ZodOptional<z.ZodString>;
1130
+ }, z.core.$strip>;
1131
+ response: z.ZodDiscriminatedUnion<[z.ZodObject<{
1132
+ action: z.ZodLiteral<"allow">;
1133
+ updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
1134
+ updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
1135
+ }, z.core.$strip>, z.ZodObject<{
1136
+ action: z.ZodLiteral<"deny">;
1137
+ message: z.ZodString;
1138
+ shouldAbort: z.ZodOptional<z.ZodBoolean>;
1139
+ }, z.core.$strip>], "action">;
1140
+ };
1141
+ chunk: z.ZodObject<{
1142
+ eventType: z.ZodLiteral<"chunk">;
1143
+ index: z.ZodNumber;
1144
+ delta: z.ZodDiscriminatedUnion<[z.ZodObject<{
1145
+ type: z.ZodLiteral<"text_delta">;
1146
+ text: z.ZodString;
1147
+ }, z.core.$strip>, z.ZodObject<{
1148
+ type: z.ZodLiteral<"thinking_delta">;
1149
+ thinking: z.ZodString;
1150
+ }, z.core.$strip>, z.ZodObject<{
1151
+ type: z.ZodLiteral<"input_json_delta">;
1152
+ partial_json: z.ZodString;
1153
+ }, z.core.$strip>], "type">;
1154
+ }, z.core.$strip>;
1155
+ usage: z.ZodObject<{
1156
+ eventType: z.ZodLiteral<"usage">;
1157
+ prompt_tokens: z.ZodNumber;
1158
+ completion_tokens: z.ZodNumber;
1159
+ total_tokens: z.ZodNumber;
1160
+ cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
1161
+ cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
1162
+ }, z.core.$strip>;
1163
+ message_complete: z.ZodObject<{
1164
+ eventType: z.ZodLiteral<"message_complete">;
1165
+ content: z.ZodNullable<z.ZodString>;
1166
+ reasoning: z.ZodOptional<z.ZodString>;
1167
+ tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
1168
+ id: z.ZodString;
1169
+ blockIndex: z.ZodNumber;
1170
+ type: z.ZodLiteral<"function">;
1171
+ function: z.ZodObject<{
1172
+ name: z.ZodString;
1173
+ arguments: z.ZodString;
1174
+ }, z.core.$strip>;
1175
+ }, z.core.$strip>>>;
1176
+ finish_reason: z.ZodNullable<z.ZodEnum<{
1177
+ end_turn: "end_turn";
1178
+ max_tokens: "max_tokens";
1179
+ stop_sequence: "stop_sequence";
1180
+ tool_use: "tool_use";
1181
+ pause_turn: "pause_turn";
1182
+ }>>;
1183
+ }, z.core.$strip>;
1184
+ reasoning_delta: z.ZodObject<{
1185
+ eventType: z.ZodLiteral<"reasoning_delta">;
1186
+ content: z.ZodString;
1187
+ }, z.core.$strip>;
1188
+ reasoning_complete: z.ZodObject<{
1189
+ eventType: z.ZodLiteral<"reasoning_complete">;
1190
+ content: z.ZodString;
1191
+ signature: z.ZodOptional<z.ZodString>;
1192
+ }, z.core.$strip>;
1193
+ tool_calls: z.ZodObject<{
1194
+ eventType: z.ZodLiteral<"tool_calls">;
1195
+ toolCalls: z.ZodArray<z.ZodObject<{
1196
+ id: z.ZodString;
1197
+ type: z.ZodLiteral<"function">;
1198
+ function: z.ZodObject<{
1199
+ name: z.ZodString;
1200
+ arguments: z.ZodString;
1201
+ }, z.core.$strip>;
1202
+ blockIndex: z.ZodNumber;
1203
+ }, z.core.$strip>>;
1204
+ }, z.core.$strip>;
1205
+ tool_started: z.ZodObject<{
1206
+ eventType: z.ZodLiteral<"tool_started">;
1207
+ toolName: z.ZodString;
1208
+ toolCallId: z.ZodString;
1209
+ }, z.core.$strip>;
1210
+ tool_completed: z.ZodObject<{
1211
+ eventType: z.ZodLiteral<"tool_completed">;
1212
+ toolName: z.ZodString;
1213
+ toolCallId: z.ZodString;
1214
+ result: z.ZodString;
1215
+ success: z.ZodBoolean;
1216
+ }, z.core.$strip>;
1217
+ agent_started: z.ZodObject<{
1218
+ eventType: z.ZodLiteral<"agent_started">;
1219
+ model: z.ZodOptional<z.ZodString>;
1220
+ }, z.core.$strip>;
1221
+ agent_complete: z.ZodObject<{
1222
+ eventType: z.ZodLiteral<"agent_complete">;
1223
+ message: z.ZodOptional<z.ZodString>;
1224
+ error: z.ZodOptional<z.ZodString>;
1225
+ }, z.core.$strip>;
1226
+ error: z.ZodObject<{
1227
+ eventType: z.ZodLiteral<"error">;
1228
+ message: z.ZodString;
1229
+ code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
1230
+ type: z.ZodOptional<z.ZodString>;
1231
+ }, z.core.$strip>;
1232
+ 'turn.state_changed': z.ZodObject<{
1233
+ adapterId: z.ZodString;
1234
+ agentId: z.ZodString;
1235
+ oldState: z.ZodEnum<{
1236
+ idle: "idle";
1237
+ turn_started: "turn_started";
1238
+ step_started: "step_started";
1239
+ step_finished: "step_finished";
1240
+ turn_finished: "turn_finished";
1241
+ }>;
1242
+ newState: z.ZodEnum<{
1243
+ idle: "idle";
1244
+ turn_started: "turn_started";
1245
+ step_started: "step_started";
1246
+ step_finished: "step_finished";
1247
+ turn_finished: "turn_finished";
1248
+ }>;
1249
+ timestamp: z.ZodNumber;
1250
+ }, z.core.$strip>;
1251
+ 'turn.turn_started': z.ZodObject<{
1252
+ adapterId: z.ZodString;
1253
+ agentId: z.ZodString;
1254
+ oldState: z.ZodEnum<{
1255
+ idle: "idle";
1256
+ turn_started: "turn_started";
1257
+ step_started: "step_started";
1258
+ step_finished: "step_finished";
1259
+ turn_finished: "turn_finished";
1260
+ }>;
1261
+ newState: z.ZodEnum<{
1262
+ idle: "idle";
1263
+ turn_started: "turn_started";
1264
+ step_started: "step_started";
1265
+ step_finished: "step_finished";
1266
+ turn_finished: "turn_finished";
1267
+ }>;
1268
+ timestamp: z.ZodNumber;
1269
+ }, z.core.$strip>;
1270
+ 'turn.step_started': z.ZodObject<{
1271
+ adapterId: z.ZodString;
1272
+ agentId: z.ZodString;
1273
+ oldState: z.ZodEnum<{
1274
+ idle: "idle";
1275
+ turn_started: "turn_started";
1276
+ step_started: "step_started";
1277
+ step_finished: "step_finished";
1278
+ turn_finished: "turn_finished";
1279
+ }>;
1280
+ newState: z.ZodEnum<{
1281
+ idle: "idle";
1282
+ turn_started: "turn_started";
1283
+ step_started: "step_started";
1284
+ step_finished: "step_finished";
1285
+ turn_finished: "turn_finished";
1286
+ }>;
1287
+ timestamp: z.ZodNumber;
1288
+ }, z.core.$strip>;
1289
+ 'turn.step_finished': z.ZodObject<{
1290
+ adapterId: z.ZodString;
1291
+ agentId: z.ZodString;
1292
+ oldState: z.ZodEnum<{
1293
+ idle: "idle";
1294
+ turn_started: "turn_started";
1295
+ step_started: "step_started";
1296
+ step_finished: "step_finished";
1297
+ turn_finished: "turn_finished";
1298
+ }>;
1299
+ newState: z.ZodEnum<{
1300
+ idle: "idle";
1301
+ turn_started: "turn_started";
1302
+ step_started: "step_started";
1303
+ step_finished: "step_finished";
1304
+ turn_finished: "turn_finished";
1305
+ }>;
1306
+ timestamp: z.ZodNumber;
1307
+ }, z.core.$strip>;
1308
+ 'turn.turn_finished': z.ZodObject<{
1309
+ adapterId: z.ZodString;
1310
+ agentId: z.ZodString;
1311
+ oldState: z.ZodEnum<{
1312
+ idle: "idle";
1313
+ turn_started: "turn_started";
1314
+ step_started: "step_started";
1315
+ step_finished: "step_finished";
1316
+ turn_finished: "turn_finished";
1317
+ }>;
1318
+ newState: z.ZodEnum<{
1319
+ idle: "idle";
1320
+ turn_started: "turn_started";
1321
+ step_started: "step_started";
1322
+ step_finished: "step_finished";
1323
+ turn_finished: "turn_finished";
1324
+ }>;
1325
+ timestamp: z.ZodNumber;
1326
+ }, z.core.$strip>;
1327
+ }>, "adapter:anthropic-sdk">;
1328
+ /**
1329
+ * Scoped bus type for Anthropic SDK adapter namespace subjects.
1330
+ * Re-exported here for convenience alongside connector subjects.
1331
+ */
1332
+ type AnthropicSdkConnectorBus = ScopedBus<typeof ANTHROPIC_SDK_NAMESPACE>;
1333
+ //#endregion
1334
+ //#region src/types/index.d.ts
1335
+ /**
1336
+ * Anthropic SDK adapter namespace identifier.
1337
+ */
1338
+ declare const ANTHROPIC_SDK_NAMESPACE: "adapter:anthropic-sdk";
1339
+ /**
1340
+ * Scoped bus type for Anthropic SDK adapter.
1341
+ */
1342
+ type AnthropicSdkBus = ScopedBus<typeof ANTHROPIC_SDK_NAMESPACE>;
1343
+ /**
1344
+ * Provider-specific configuration for the Anthropic SDK connector.
1345
+ *
1346
+ * Contains only non-credential settings. Credentials (e.g., `apiKey`) are
1347
+ * resolved at runtime from `providerContext.credentialRefs` via
1348
+ * `resolveConnectorCredentials()` and never appear in this type.
1349
+ */
1350
+ type AnthropicSdkProviderConfig = AnthropicSdkProviderSettings;
1351
+ /**
1352
+ * Configuration for an Anthropic SDK agent connector session.
1353
+ */
1354
+ type AnthropicSdkAgentConfig = BaseAgentConnectorConfig<AnthropicSdkBus, AnthropicSdkProviderConfig>;
1355
+ /** Tool approval payload type (excludes identity context injected by the connector) */
1356
+ type AnthropicToolApprovalPayload = Omit<AgentToolApproveRequest, 'adapterName' | 'adapterId' | 'agentId' | 'adapterSessionId' | 'sessionId'>;
1357
+ /** Tool approval response type */
1358
+ type AnthropicToolApprovalResponse = AgentToolApproveResponse;
1359
+ /**
1360
+ * Session configuration for Anthropic SDK lifecycle management.
1361
+ */
1362
+ interface AnthropicSdkSessionConfig {
1363
+ bus: AnthropicSdkBus;
1364
+ adapterId: string;
1365
+ adapterName: string;
1366
+ /** Agent ID for tool execution attribution */
1367
+ agentId: string;
1368
+ /** Makaio session ID for tool execution context */
1369
+ sessionId?: string;
1370
+ cwd: string;
1371
+ model: string;
1372
+ reasoningEffort?: AIReasoningLevel;
1373
+ /** Maximum number of tokens to generate per request. Falls back to DEFAULT_MAX_TOKENS when not set. */
1374
+ maxTokens?: number;
1375
+ /** Timeout for obtaining a stream from messages.create (ms) */
1376
+ streamStartTimeoutMs?: number;
1377
+ env: Record<string, string>;
1378
+ client: Anthropic;
1379
+ /** Anthropic-format tools to pass to messages.create */
1380
+ anthropicTools: Tool[];
1381
+ /** Resolved system prompt string to prepend to messages */
1382
+ systemPrompt?: string;
1383
+ /**
1384
+ * Reasoning levels supported by the active model.
1385
+ * Populated by the config factory from the resolved ProviderRecord's model catalog.
1386
+ * Absent when the model does not declare reasoning support.
1387
+ */
1388
+ supportedReasoningLevels?: ReasoningLevelMap;
1389
+ /**
1390
+ * Directory restrictions for file-system tool execution.
1391
+ * Forwarded as `constraints.allowedDirectories` in every tool call.
1392
+ */
1393
+ allowedDirectories?: string[];
1394
+ /** Emit a typed SDK event to the connector bus */
1395
+ emitSdkEvent: (event: SdkEventMessage) => Promise<void>;
1396
+ /** Handle a connector-level error */
1397
+ handleError: (error: Error, rethrow: boolean) => void;
1398
+ /** Request tool approval via bus RPC */
1399
+ requestToolApproval: (payload: AnthropicToolApprovalPayload) => Promise<AnthropicToolApprovalResponse>;
1400
+ logLowLevelEvent?: (event: unknown) => void;
1401
+ onTurnStart?: (handle: MessageHandle) => void;
1402
+ onTurnComplete?: (handle: MessageHandle, result: MessageResult) => void;
1403
+ /**
1404
+ * Record one mcp_call invocation in the session tool ledger.
1405
+ * Bound by the connector as a closure over its ledger and current turn number.
1406
+ * @param toolFullName - Namespaced target tool name from the mcp_call args
1407
+ */
1408
+ recordMcpCall?: (toolFullName: string) => void;
1409
+ }
1410
+ //#endregion
1411
+ //#region src/turn.d.ts
1412
+ /**
1413
+ * Turn state machine for the Anthropic SDK adapter.
1414
+ *
1415
+ * Tracks state transitions for a single user message.
1416
+ * Unlike Claude Code, the Anthropic SDK adapter has no true pause/resume —
1417
+ * we abort and restart the request with merged content instead.
1418
+ *
1419
+ * State flow:
1420
+ * idle → turn_started → step_started → step_finished → turn_finished
1421
+ *
1422
+ * On immediate: abort current turn, merge content, start new turn.
1423
+ */
1424
+ declare class AnthropicSdkConnectorTurn extends ProceduralConnectorTurn<StreamSessionTurnState, AnthropicSdkConnectorBus> {
1425
+ private abortController;
1426
+ constructor(bus: AnthropicSdkConnectorBus, adapterId: string, adapterName: string, agentId: string, messageHandle: MessageHandle);
1427
+ /**
1428
+ * Get the AbortSignal for this turn.
1429
+ * Pass to the Anthropic client stream for cancellation.
1430
+ * @returns The abort signal for this turn
1431
+ */
1432
+ getAbortSignal(): AbortSignal;
1433
+ /**
1434
+ * Pause (abort) at next opportunity.
1435
+ * The Anthropic SDK adapter does not support true pause — caller restarts
1436
+ * with merged content when a replacement turn arrives.
1437
+ * @returns Pause result indicating turn state
1438
+ */
1439
+ pause(): ReturnType<ProceduralConnectorTurn['pause']>;
1440
+ }
1441
+ //#endregion
1442
+ //#region src/session.d.ts
1443
+ /**
1444
+ * Session for Anthropic SDK lifecycle management.
1445
+ *
1446
+ * Manages Anthropic client calls across multiple user messages:
1447
+ * - Creates Turn instances for each user message
1448
+ * - Handles immediate mode via abort+restart (no true pause)
1449
+ * - Processes message queue with merge support
1450
+ *
1451
+ * Key difference from Claude Code: Anthropic SDK adapter has no server-side
1452
+ * session. Each turn rebuilds the messages[] array with full history.
1453
+ */
1454
+ declare class AnthropicSdkSession extends BaseStreamSession<AnthropicSdkSessionConfig, AnthropicSdkConnectorTurn, MessageCompleteEvent> {
1455
+ private messages;
1456
+ /**
1457
+ * Runtime reasoning effort level; updated by `updateReasoning()`.
1458
+ * Initialized from `config.reasoningEffort` at session construction.
1459
+ */
1460
+ protected currentReasoningEffort: AIReasoningLevel | undefined;
1461
+ /**
1462
+ * Mutable tool list for this session.
1463
+ * Rebuilt whenever either `nativeTools` or `mcpTools` changes.
1464
+ */
1465
+ private currentTools;
1466
+ /** Latest native registry tools for this live session. */
1467
+ private nativeTools;
1468
+ /**
1469
+ * Latest MCP direct-inject tools converted to Anthropic format.
1470
+ * Stored separately so that `replaceNativeTools` can rebuild `currentTools`
1471
+ * without losing the MCP tool set.
1472
+ */
1473
+ private mcpTools;
1474
+ /**
1475
+ * Create an Anthropic SDK connector session.
1476
+ * @param config - Session configuration (bus identity, model/cwd defaults, Anthropic client/tools, and lifecycle hooks).
1477
+ */
1478
+ constructor(config: AnthropicSdkSessionConfig);
1479
+ /**
1480
+ * Replace the native registry tool set used for subsequent turns.
1481
+ *
1482
+ * Rebuilds `currentTools` so that MCP tools registered via `updateTools`
1483
+ * are preserved alongside the new native tools.
1484
+ * @param tools - Fresh Anthropic-formatted native tools
1485
+ */
1486
+ replaceNativeTools(tools: Tool[]): void;
1487
+ /**
1488
+ * Update the session's tool set for the next API call.
1489
+ *
1490
+ * Converts generic `ToolListItem[]` (MCP direct-inject tools) to
1491
+ * Anthropic `Tool[]` format and merges them with the existing native tools.
1492
+ * @param tools - New MCP direct-inject tools in generic format
1493
+ */
1494
+ updateTools(tools: ToolListItem[]): void;
1495
+ /**
1496
+ * Update the reasoning effort level used for subsequent API calls.
1497
+ *
1498
+ * Called by the connector's `changeReasoningInPlace()` to sync the session
1499
+ * with the requested reasoning level without requiring a full session swap.
1500
+ * The updated value is picked up by `executeApiCall` on the next turn.
1501
+ * @internal Direct calls bypass capability validation — only the mutation
1502
+ * manager should call this (via the connector's `changeReasoningInPlace`).
1503
+ * @param level - New reasoning effort level
1504
+ */
1505
+ updateReasoning(level: AIReasoningLevel): void;
1506
+ /**
1507
+ * Return the names of all tools that would be sent in the next API call.
1508
+ *
1509
+ * Reflects the merged set of native and MCP tools after any `replaceNativeTools`
1510
+ * or `updateTools` calls.
1511
+ * @returns Ordered list of tool names matching the next API request
1512
+ */
1513
+ protected getEffectiveToolNames(): string[];
1514
+ /**
1515
+ * Create an Anthropic SDK turn for the given message handle.
1516
+ * @param handle - The message handle this turn will process
1517
+ * @returns A new `AnthropicSdkConnectorTurn` instance
1518
+ */
1519
+ protected createTurn(handle: MessageHandle): AnthropicSdkConnectorTurn;
1520
+ /**
1521
+ * Build the messages array from handle history and optional merged content.
1522
+ * @param handle - The message handle containing history
1523
+ * @param mergedContent - Optional content from superseded/merged messages
1524
+ */
1525
+ protected buildMessages(handle: MessageHandle, mergedContent?: string[]): void;
1526
+ /**
1527
+ * Execute the Anthropic streaming API call.
1528
+ *
1529
+ * Calls `client.messages.create` with the current messages array and
1530
+ * pipes the resulting stream through the stream-bridge event emitter.
1531
+ * @param turn - Captured turn instance for this run loop
1532
+ * @param abortSignal - Combined abort signal (turn abort + stream timeout)
1533
+ * @param adapterSessionId - Turn-scoped adapter session ID for event correlation
1534
+ */
1535
+ protected executeApiCall(turn: AnthropicSdkConnectorTurn, abortSignal: AbortSignal, adapterSessionId: string): Promise<void>;
1536
+ /**
1537
+ * Return the Anthropic SDK event bus subject for `message_complete` waiting.
1538
+ * @returns The `sdk.event` subject for the Anthropic adapter namespace
1539
+ */
1540
+ protected getSdkEventSubject(): ScopedSubjectDefinition<string>;
1541
+ /**
1542
+ * Apply a `message_complete` event to the Anthropic messages array and
1543
+ * recurse for tool calls.
1544
+ *
1545
+ * Appends assistant content as Anthropic `MessageParam[]` blocks. When
1546
+ * `finish_reason` is `'tool_use'`, executes tools and continues the loop.
1547
+ * @param result - The parsed Anthropic `message_complete` event
1548
+ * @param currentHandle - The active message handle
1549
+ * @param toolCallIteration - Current tool recursion depth
1550
+ * @param turn - Captured turn instance for this run loop
1551
+ */
1552
+ protected applyMessageComplete(result: MessageCompleteEvent, currentHandle: MessageHandle, toolCallIteration: number, turn: AnthropicSdkConnectorTurn): Promise<void>;
1553
+ /**
1554
+ * Classify an Anthropic SDK error into the appropriate Makaio error type.
1555
+ * @param error - The raw error from the Anthropic SDK
1556
+ * @returns A classified `Error` instance
1557
+ */
1558
+ protected classifyError(error: unknown): Error;
1559
+ }
1560
+ //#endregion
1561
+ //#region src/connector.d.ts
1562
+ /**
1563
+ * Anthropic SDK Connector — Wraps the Anthropic SDK for agentic message creation.
1564
+ *
1565
+ * Implements the agentic loop pattern:
1566
+ * 1. Send user message to Anthropic via messages.create (streaming)
1567
+ * 2. Process streaming response via stream-bridge
1568
+ * 3. If tool_use blocks present, execute tools via Bus RPC and recurse
1569
+ * 4. When no tool_use blocks, mark turn complete
1570
+ *
1571
+ * Tools are fetched from ToolRegistry via MakaioBus.request(ToolSubjects.list)
1572
+ * on the first turn. Tool execution routes through MakaioBus.request(ToolSubjects.execute)
1573
+ * to the ToolRegistry, which validates input and executes the tool handler.
1574
+ *
1575
+ * Credential resolution happens in `fetchTools()` (the first async lifecycle hook)
1576
+ * via `resolveConnectorCredentials()`. Plaintext credentials are stored in instance
1577
+ * fields and never leave the connector.
1578
+ */
1579
+ declare class AnthropicSdkConnector extends BaseStreamConnector<AnthropicSdkBus, AnthropicSdkSession, AnthropicSdkAgentConfig> {
1580
+ /** Resolved API key (populated in fetchTools before createSession is called). */
1581
+ private resolvedApiKey;
1582
+ private client?;
1583
+ /** Anthropic-format tools for messages.create (fetched from bus on first turn) */
1584
+ private anthropicTools;
1585
+ /**
1586
+ * Emit an SDK event wrapped in envelope for type-safe discriminated union handling.
1587
+ * @param event - The typed SDK event message to emit
1588
+ */
1589
+ private emitSdkEvent;
1590
+ constructor(config: AnthropicSdkAgentConfig & {
1591
+ adapterId?: string;
1592
+ });
1593
+ /**
1594
+ * Resolve credentials and fetch available tools from the bus.
1595
+ *
1596
+ * Resolves `apiKey` from `providerContext.credentialRefs` via the encrypted
1597
+ * credential channel, then initializes the Anthropic SDK client. Called once
1598
+ * by `BaseStreamConnector.initializeSession()` before `createSession()`.
1599
+ *
1600
+ * Also converts fetched tools to Anthropic format and caches them in
1601
+ * `this.anthropicTools` for use in `createSession`.
1602
+ */
1603
+ protected fetchTools(): Promise<void>;
1604
+ /**
1605
+ * Re-fetch native tools and re-resolve MCP direct-inject tools.
1606
+ *
1607
+ * Called at turn boundary when `hasPendingToolRefresh` is true.
1608
+ * Re-fetches Anthropic-format tools from the registry, re-prepares MCP
1609
+ * direct tools (and arms the ledger injection flag via `super.refreshTools()`),
1610
+ * then notifies the active session so the next API call uses the updated
1611
+ * merged tool list. The ledger `recordInjection` is deferred to
1612
+ * `onTurnStarted` so it uses the canonical turn number.
1613
+ */
1614
+ protected refreshTools(): Promise<void>;
1615
+ /**
1616
+ * Construct the Anthropic SDK session with all required config.
1617
+ *
1618
+ * Called by `BaseStreamConnector.initializeSession()` after `fetchTools()`
1619
+ * has resolved credentials and initialized `this.client`.
1620
+ * @returns A new `AnthropicSdkSession` instance
1621
+ */
1622
+ protected createSession(): AnthropicSdkSession;
1623
+ /**
1624
+ * Get Anthropic namespace turn subjects.
1625
+ * @returns Turn subject definitions
1626
+ */
1627
+ protected getTurnSubjects(): WireSessionSubjects<AnthropicSdkBus['namespace']>;
1628
+ }
1629
+ //#endregion
1630
+ //#region src/agent.d.ts
1631
+ /**
1632
+ * Subject spec for the Anthropic SDK adapter, satisfying `StreamAdapterSubjectSpec`.
1633
+ *
1634
+ * Scoped to the Anthropic SDK connector namespace. Passed as the `TSpec` type parameter
1635
+ * to `BaseStreamAgent` so shared wire methods resolve handler types correctly.
1636
+ */
1637
+ type AnthropicSubjectSpec = StreamAdapterSubjectSpec<typeof AnthropicSdkConnectorSubjects.chunk.$meta.namespace>;
1638
+ /**
1639
+ * Anthropic SDK Agent — Middle layer between AnthropicSdkAdapter and AnthropicSdkConnector.
1640
+ *
1641
+ * Responsibilities:
1642
+ * 1. Wire connector's scoped bus events to global agent.* subjects
1643
+ * 2. Auto-enrich payloads with AgentContext via emitGlobal()
1644
+ *
1645
+ * Event Flow:
1646
+ * - AnthropicSdkConnector emits to semantic subjects (chunk, usage, etc.)
1647
+ * - AnthropicSdkAgent subscribes to semantic subjects and emits to global bus (agent.*)
1648
+ * - Downstream consumers subscribe to normalized agent.* subjects
1649
+ *
1650
+ * Extends `BaseStreamAgent` which provides all shared wiring logic. This class only
1651
+ * implements the adapter-specific abstract hooks.
1652
+ */
1653
+ declare class AnthropicSdkAgent extends BaseStreamAgent<AnthropicSdkConnectorBus, AnthropicSdkConnector, AnthropicSubjectSpec> {
1654
+ /**
1655
+ * Keep AIAgent's internal block index counter in sync with provider block indices.
1656
+ *
1657
+ * Some steps (tool_use) emit provider-native indices directly instead of going through
1658
+ * emitStepStarted/emitStepFinished, so we advance the local counter to avoid reusing
1659
+ * stale indices for later text/reasoning steps in the same turn.
1660
+ * @param blockIndex - Provider block index that has been reserved/emitted
1661
+ */
1662
+ private reconcileInternalBlockIndex;
1663
+ /**
1664
+ * Tier 1: Route sdk.event catch-all to typed semantic subjects.
1665
+ *
1666
+ * Uses `createConnectorEventMapping` for type-safe discriminated union routing.
1667
+ * The envelope `'event'` field carries the discriminated union keyed on `'eventType'`.
1668
+ */
1669
+ protected wireSdkEvents(): void;
1670
+ /**
1671
+ * Return the Anthropic SDK adapter's connector subject spec.
1672
+ *
1673
+ * Maps adapter subject constants to the `StreamAdapterSubjectSpec` interface used
1674
+ * by `BaseStreamAgent` to subscribe to semantic events.
1675
+ * @returns Anthropic-specific subject spec
1676
+ */
1677
+ protected getConnectorSubjects(): AnthropicSubjectSpec;
1678
+ /**
1679
+ * Extract plain text from an Anthropic chunk event payload.
1680
+ *
1681
+ * Anthropic chunk events carry a discriminated `delta` union. Text content is
1682
+ * only present when `delta.type === 'text_delta'`.
1683
+ * @param payload - Anthropic chunk event payload
1684
+ * @returns The text content, or empty string for non-text deltas
1685
+ */
1686
+ protected extractChunkText(payload: Record<string, unknown>): string;
1687
+ /**
1688
+ * Map an Anthropic usage event payload to the shared `NormalizedCallUsage` format.
1689
+ *
1690
+ * Reads Anthropic-specific cache fields: `cache_read_input_tokens` and
1691
+ * `cache_creation_input_tokens`.
1692
+ * @param payload - Anthropic usage event payload
1693
+ * @returns Normalized usage metrics
1694
+ */
1695
+ protected extractUsagePayload(payload: Record<string, unknown>): NormalizedCallUsage;
1696
+ /**
1697
+ * Emit context window update after Anthropic usage tracking.
1698
+ *
1699
+ * Uses `cache_read_input_tokens` for the cached token count and
1700
+ * defaults to `DEFAULT_CONTEXT_WINDOW_SIZE` (200,000) for Claude models.
1701
+ * @param payload - Anthropic usage event payload
1702
+ */
1703
+ protected emitUsageContextWindowUpdate(payload: Record<string, unknown>): Promise<void>;
1704
+ /**
1705
+ * Reserve a block index for a tool call using Anthropic's provider-native block index.
1706
+ *
1707
+ * Anthropic sends `blockIndex` on each tool call entry in the tool_calls event.
1708
+ * Using the provider index preserves the correct ordering in persisted step history,
1709
+ * even when tool_calls events arrive before text step events.
1710
+ * @param tc - Anthropic tool call entry (carries `blockIndex`)
1711
+ * @returns Provider-native block index from the tool call
1712
+ */
1713
+ protected reserveToolCallBlockIndex(tc: ToolCall): number;
1714
+ /**
1715
+ * Reconcile internal block index after emitting a tool call step.
1716
+ *
1717
+ * Advances the internal block index counter to stay ahead of the provider-native
1718
+ * index, so subsequent text/reasoning steps don't reuse stale indices.
1719
+ * @param blockIndex - The provider block index just emitted
1720
+ */
1721
+ protected afterToolCallStepEmitted(blockIndex: number): void;
1722
+ /**
1723
+ * Return the fallback block index when no map entry exists for a toolCallId.
1724
+ *
1725
+ * Allocates the current block index and immediately increments the counter to keep
1726
+ * block indices monotonic and non-negative.
1727
+ * @returns Current block index (before increment)
1728
+ */
1729
+ protected getFallbackToolCompletedBlockIndex(): number;
1730
+ /**
1731
+ * Reconcile internal block index after emitting a tool_completed step.
1732
+ *
1733
+ * Ensures the internal counter is ahead of the resolved block index so later
1734
+ * text/reasoning steps receive fresh, non-conflicting indices.
1735
+ * @param resolvedBlockIndex - The block index used for this tool's step.finished
1736
+ */
1737
+ protected afterToolCompletedStepEmitted(resolvedBlockIndex: number): void;
1738
+ /**
1739
+ * Build the reasoning `SessionMessageBlock` from an Anthropic reasoning_complete payload.
1740
+ *
1741
+ * Includes the `signature` field in block metadata when present. Anthropic requires
1742
+ * the signature for native history round-trip (persisted extended thinking blocks
1743
+ * must include the signature for subsequent API calls).
1744
+ * @param payload - Anthropic reasoning complete event payload
1745
+ * @returns Reasoning block with optional signature metadata
1746
+ */
1747
+ protected buildReasoningBlock(payload: Record<string, unknown>): SessionMessageBlock;
1748
+ /**
1749
+ * Wire tool approval RPC from connector's scoped bus to global AgentSubjects.toolApprove.
1750
+ *
1751
+ * Uses centralized tool-handling helper for consistent approval flow.
1752
+ * Uses lazy callback to resolve adapterSessionId at request time (not constructor time).
1753
+ * @param connector - The AnthropicSdkConnector to wire RPC from
1754
+ */
1755
+ protected wireToolApprovalRpc(connector: AnthropicSdkConnector): void;
1756
+ }
1757
+ //#endregion
1758
+ //#region src/constants.d.ts
1759
+ /** Stable adapter type name for bus routing and persistence. */
1760
+ declare const AnthropicSdkAdapterName = "anthropic-sdk";
1761
+ //#endregion
1762
+ //#region src/adapter.d.ts
1763
+ /**
1764
+ * Anthropic SDK Adapter — Domain-level adapter using the three-layer architecture.
1765
+ *
1766
+ * Architecture:
1767
+ * ```
1768
+ * AnthropicSdkAdapter extends AIAdapter
1769
+ * -> creates via agentFactory()
1770
+ * AnthropicSdkAgent extends AIAgent
1771
+ * -> creates via connectorFactory()
1772
+ * AnthropicSdkConnector extends ProceduralAgentConnector
1773
+ * ```
1774
+ *
1775
+ * Responsibilities:
1776
+ * - Handle adapter.startAgent RPC (inherited from AIAdapter)
1777
+ * - Create AnthropicSdkAgent instances with proper configuration
1778
+ * - Emit adapter.initialized and adapter.session.created events
1779
+ * - Manage agent lifecycle (tracking, disposal)
1780
+ * @example
1781
+ * ```typescript
1782
+ * // Using the class directly
1783
+ * const adapter = new AnthropicSdkAdapter();
1784
+ * await adapter.init();
1785
+ *
1786
+ * // Using the convenience factory
1787
+ * const adapter = await createAnthropicSdkAdapter();
1788
+ * ```
1789
+ */
1790
+ declare class AnthropicSdkAdapter extends AIAdapter<AnthropicSdkConnectorBus, AnthropicSdkConnector, AnthropicSdkAgent> {
1791
+ constructor(config?: Partial<AIAdapterConfig>);
1792
+ }
1793
+ /**
1794
+ * Factory function to create and initialize an Anthropic SDK adapter.
1795
+ *
1796
+ * Convenience wrapper that creates the adapter and calls init() for you.
1797
+ * @param config - Optional adapter configuration
1798
+ * @returns Initialized AnthropicSdkAdapter instance
1799
+ * @example
1800
+ * ```typescript
1801
+ * const adapter = await createAnthropicSdkAdapter();
1802
+ *
1803
+ * // Adapter is ready to handle requests via bus
1804
+ * // e.g., MakaioBus.request(AdapterSubjects.startAgent, { adapterId: adapter.adapterId, ... })
1805
+ * ```
1806
+ */
1807
+ declare function createAnthropicSdkAdapter(config?: Partial<AIAdapterConfig>): Promise<AnthropicSdkAdapter>;
1808
+ //#endregion
1809
+ //#region src/package.d.ts
1810
+ /**
1811
+ * Package descriptor for the Anthropic SDK adapter.
1812
+ *
1813
+ * API-only adapter (no client binary dependency). Declares the `anthropic`
1814
+ * wire protocol, which covers the native Anthropic Messages API as well as
1815
+ * compatible proxies (Z.ai, Alibaba, opencode-go).
1816
+ */
1817
+ declare const anthropicSdkPackage: MakaioNodeExtension<IMakaioBus>;
1818
+ //#endregion
1819
+ //#region src/index.d.ts
1820
+ /**
1821
+ * Creates test configuration for conformance test suite.
1822
+ * Sets up scoped bus and tool approval proxy.
1823
+ * @param options - Provider definitions supplied by the conformance harness
1824
+ * @returns Configuration for running conformance tests against this adapter
1825
+ */
1826
+ declare const createTestConfig: (options?: CreateConformanceTestConfigOptions) => Promise<ConformanceTestConfig<AnthropicSdkConnectorBus, AnthropicSdkConnector, AnthropicSdkAgent>>;
1827
+ //#endregion
1828
+ export { ANTHROPIC_SDK_NAMESPACE, AnthropicSdkAdapter, AnthropicSdkAdapterName, AnthropicSdkAgent, AnthropicSdkConnector, type AnthropicSdkConnectorBus, AnthropicSdkConnectorNamespace, AnthropicSdkConnectorSubjects, AnthropicSdkConnectorTurn, AnthropicSdkSession, type AnthropicSdkSessionConfig, type SdkEvent, type SdkEventMessage, UserMessageQueue, anthropicSdkPackage, createAnthropicSdkAdapter, createTestConfig };