@chucky.cloud/sdk 0.2.7 → 0.3.1

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 (94) hide show
  1. package/dist/browser.cjs +1371 -0
  2. package/dist/browser.cjs.map +1 -0
  3. package/dist/browser.d.cts +1 -0
  4. package/dist/browser.d.ts +1 -8
  5. package/dist/browser.js +1288 -11
  6. package/dist/browser.js.map +1 -1
  7. package/dist/index.cjs +1371 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +1991 -0
  10. package/dist/index.d.ts +1971 -48
  11. package/dist/index.js +1288 -72
  12. package/dist/index.js.map +1 -1
  13. package/dist/node.cjs +1371 -0
  14. package/dist/node.cjs.map +1 -0
  15. package/dist/node.d.cts +1 -0
  16. package/dist/node.d.ts +1 -8
  17. package/dist/node.js +1288 -10
  18. package/dist/node.js.map +1 -1
  19. package/package.json +13 -7
  20. package/dist/browser.d.ts.map +0 -1
  21. package/dist/client/ChuckyClient.d.ts +0 -141
  22. package/dist/client/ChuckyClient.d.ts.map +0 -1
  23. package/dist/client/ChuckyClient.js +0 -209
  24. package/dist/client/ChuckyClient.js.map +0 -1
  25. package/dist/client/Session.d.ts +0 -167
  26. package/dist/client/Session.d.ts.map +0 -1
  27. package/dist/client/Session.js +0 -392
  28. package/dist/client/Session.js.map +0 -1
  29. package/dist/client/index.d.ts +0 -10
  30. package/dist/client/index.d.ts.map +0 -1
  31. package/dist/client/index.js +0 -9
  32. package/dist/client/index.js.map +0 -1
  33. package/dist/index.d.ts.map +0 -1
  34. package/dist/node.d.ts.map +0 -1
  35. package/dist/tools/McpServer.d.ts +0 -117
  36. package/dist/tools/McpServer.d.ts.map +0 -1
  37. package/dist/tools/McpServer.js +0 -142
  38. package/dist/tools/McpServer.js.map +0 -1
  39. package/dist/tools/index.d.ts +0 -9
  40. package/dist/tools/index.d.ts.map +0 -1
  41. package/dist/tools/index.js +0 -8
  42. package/dist/tools/index.js.map +0 -1
  43. package/dist/tools/tool.d.ts +0 -146
  44. package/dist/tools/tool.d.ts.map +0 -1
  45. package/dist/tools/tool.js +0 -232
  46. package/dist/tools/tool.js.map +0 -1
  47. package/dist/transport/Transport.d.ts +0 -82
  48. package/dist/transport/Transport.d.ts.map +0 -1
  49. package/dist/transport/Transport.js +0 -47
  50. package/dist/transport/Transport.js.map +0 -1
  51. package/dist/transport/WebSocketTransport.d.ts +0 -78
  52. package/dist/transport/WebSocketTransport.d.ts.map +0 -1
  53. package/dist/transport/WebSocketTransport.js +0 -258
  54. package/dist/transport/WebSocketTransport.js.map +0 -1
  55. package/dist/transport/index.d.ts +0 -10
  56. package/dist/transport/index.d.ts.map +0 -1
  57. package/dist/transport/index.js +0 -8
  58. package/dist/transport/index.js.map +0 -1
  59. package/dist/types/index.d.ts +0 -12
  60. package/dist/types/index.d.ts.map +0 -1
  61. package/dist/types/index.js +0 -8
  62. package/dist/types/index.js.map +0 -1
  63. package/dist/types/messages.d.ts +0 -327
  64. package/dist/types/messages.d.ts.map +0 -1
  65. package/dist/types/messages.js +0 -133
  66. package/dist/types/messages.js.map +0 -1
  67. package/dist/types/options.d.ts +0 -212
  68. package/dist/types/options.d.ts.map +0 -1
  69. package/dist/types/options.js +0 -8
  70. package/dist/types/options.js.map +0 -1
  71. package/dist/types/results.d.ts +0 -186
  72. package/dist/types/results.d.ts.map +0 -1
  73. package/dist/types/results.js +0 -7
  74. package/dist/types/results.js.map +0 -1
  75. package/dist/types/token.d.ts +0 -124
  76. package/dist/types/token.d.ts.map +0 -1
  77. package/dist/types/token.js +0 -7
  78. package/dist/types/token.js.map +0 -1
  79. package/dist/types/tools.d.ts +0 -234
  80. package/dist/types/tools.d.ts.map +0 -1
  81. package/dist/types/tools.js +0 -31
  82. package/dist/types/tools.js.map +0 -1
  83. package/dist/utils/errors.d.ts +0 -80
  84. package/dist/utils/errors.d.ts.map +0 -1
  85. package/dist/utils/errors.js +0 -158
  86. package/dist/utils/errors.js.map +0 -1
  87. package/dist/utils/index.d.ts +0 -8
  88. package/dist/utils/index.d.ts.map +0 -1
  89. package/dist/utils/index.js +0 -8
  90. package/dist/utils/index.js.map +0 -1
  91. package/dist/utils/token.d.ts +0 -104
  92. package/dist/utils/token.d.ts.map +0 -1
  93. package/dist/utils/token.js +0 -209
  94. package/dist/utils/token.js.map +0 -1
@@ -0,0 +1,1991 @@
1
+ /**
2
+ * Tool Definition Types
3
+ *
4
+ * Types for defining tools that can be executed by Claude.
5
+ * Supports both server-side and browser-side execution.
6
+ */
7
+ /**
8
+ * JSON Schema property types
9
+ */
10
+ type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
11
+ /**
12
+ * JSON Schema property definition
13
+ */
14
+ interface JsonSchemaProperty {
15
+ /** Property type */
16
+ type: JsonSchemaType;
17
+ /** Human-readable description */
18
+ description?: string;
19
+ /** Enumeration of allowed values */
20
+ enum?: string[];
21
+ /** Default value */
22
+ default?: unknown;
23
+ /** For arrays: schema of array items */
24
+ items?: JsonSchemaProperty;
25
+ /** For objects: nested properties */
26
+ properties?: Record<string, JsonSchemaProperty>;
27
+ /** For objects: required property names */
28
+ required?: string[];
29
+ /** Minimum value (for numbers) */
30
+ minimum?: number;
31
+ /** Maximum value (for numbers) */
32
+ maximum?: number;
33
+ /** Minimum length (for strings/arrays) */
34
+ minLength?: number;
35
+ /** Maximum length (for strings/arrays) */
36
+ maxLength?: number;
37
+ /** Pattern (for strings) */
38
+ pattern?: string;
39
+ }
40
+ /**
41
+ * JSON Schema for tool input
42
+ */
43
+ interface ToolInputSchema {
44
+ /** Always 'object' for tool inputs */
45
+ type: 'object';
46
+ /** Property definitions */
47
+ properties: Record<string, JsonSchemaProperty>;
48
+ /** Required property names */
49
+ required?: string[];
50
+ /** Allow additional properties */
51
+ additionalProperties?: boolean;
52
+ }
53
+ /**
54
+ * Tool content types for results
55
+ */
56
+ type ToolContentType = 'text' | 'image' | 'resource';
57
+ /**
58
+ * Text content in tool result (MCP format)
59
+ */
60
+ interface ToolTextContent {
61
+ type: 'text';
62
+ text: string;
63
+ }
64
+ /**
65
+ * Image content in tool result (MCP format)
66
+ */
67
+ interface ToolImageContent {
68
+ type: 'image';
69
+ /** Base64-encoded image data */
70
+ data: string;
71
+ /** MIME type (e.g., 'image/png') */
72
+ mimeType: string;
73
+ }
74
+ /**
75
+ * Resource content in tool result
76
+ */
77
+ interface ResourceContent {
78
+ type: 'resource';
79
+ /** Resource URI */
80
+ uri: string;
81
+ /** MIME type */
82
+ mimeType?: string;
83
+ /** Resource text content */
84
+ text?: string;
85
+ /** Resource binary data (base64) */
86
+ blob?: string;
87
+ }
88
+ /**
89
+ * Union type for all tool content
90
+ */
91
+ type ToolContent = ToolTextContent | ToolImageContent | ResourceContent;
92
+ /**
93
+ * Tool execution result
94
+ */
95
+ interface ToolResult {
96
+ /** Result content */
97
+ content: ToolContent[];
98
+ /** Whether this is an error result */
99
+ isError?: boolean;
100
+ }
101
+ /**
102
+ * Where the tool should be executed
103
+ */
104
+ type ToolExecutionLocation = 'server' | 'browser';
105
+ /**
106
+ * Tool handler function type
107
+ */
108
+ type ToolHandler<TInput = Record<string, unknown>> = (input: TInput) => ToolResult | Promise<ToolResult>;
109
+ /**
110
+ * Tool definition
111
+ */
112
+ interface ToolDefinition<TInput = Record<string, unknown>> {
113
+ /** Unique tool name */
114
+ name: string;
115
+ /** Human-readable description of what the tool does */
116
+ description: string;
117
+ /** JSON Schema defining the input parameters */
118
+ inputSchema: ToolInputSchema;
119
+ /**
120
+ * Where the tool should be executed
121
+ * @default 'server'
122
+ */
123
+ executeIn?: ToolExecutionLocation;
124
+ /**
125
+ * Handler function (required for browser tools, optional for server tools)
126
+ */
127
+ handler?: ToolHandler<TInput>;
128
+ }
129
+ /**
130
+ * MCP Server with client-side tools (handlers run in your app)
131
+ * This is our custom format - bridge converts to SDK format
132
+ */
133
+ interface McpClientToolsServer {
134
+ /** Server name */
135
+ name: string;
136
+ /** Server version */
137
+ version?: string;
138
+ /** Tools with handlers that execute client-side */
139
+ tools: ToolDefinition[];
140
+ }
141
+ /**
142
+ * MCP Stdio server configuration
143
+ */
144
+ interface McpStdioServerConfig {
145
+ /** Server name */
146
+ name: string;
147
+ /** Server type */
148
+ type?: 'stdio';
149
+ /** Command to run */
150
+ command: string;
151
+ /** Command arguments */
152
+ args?: string[];
153
+ /** Environment variables */
154
+ env?: Record<string, string>;
155
+ }
156
+ /**
157
+ * MCP SSE server configuration
158
+ */
159
+ interface McpSSEServerConfig {
160
+ /** Server name */
161
+ name: string;
162
+ /** Server type */
163
+ type: 'sse';
164
+ /** SSE endpoint URL */
165
+ url: string;
166
+ /** Request headers */
167
+ headers?: Record<string, string>;
168
+ }
169
+ /**
170
+ * MCP HTTP server configuration
171
+ */
172
+ interface McpHttpServerConfig {
173
+ /** Server name */
174
+ name: string;
175
+ /** Server type */
176
+ type: 'http';
177
+ /** HTTP endpoint URL */
178
+ url: string;
179
+ /** Request headers */
180
+ headers?: Record<string, string>;
181
+ }
182
+ /**
183
+ * MCP Server definition - all supported server types
184
+ * Array format - bridge converts to Record<string, config> for official SDK
185
+ */
186
+ type McpServerDefinition = McpClientToolsServer | McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig;
187
+ /**
188
+ * Tool preset configuration
189
+ */
190
+ interface ToolPreset {
191
+ type: 'preset';
192
+ preset: 'claude_code';
193
+ }
194
+ /**
195
+ * Tools configuration - either allowlist of names or preset
196
+ */
197
+ type ToolsConfig = string[] | ToolPreset;
198
+ /**
199
+ * Tool call from the model
200
+ */
201
+ interface ToolCall {
202
+ /** Unique call ID */
203
+ callId: string;
204
+ /** Tool name */
205
+ toolName: string;
206
+ /** Input arguments */
207
+ input: Record<string, unknown>;
208
+ }
209
+ /**
210
+ * Tool call response
211
+ */
212
+ interface ToolCallResponse {
213
+ /** Call ID (must match the tool call) */
214
+ callId: string;
215
+ /** Tool execution result */
216
+ result: ToolResult;
217
+ }
218
+
219
+ /**
220
+ * SDK Options Types
221
+ *
222
+ * These types define all configuration options for sessions and prompts.
223
+ * Designed for both browser and Node.js environments.
224
+ */
225
+
226
+ /**
227
+ * Available Claude models
228
+ */
229
+ type Model = 'claude-sonnet-4-5-20250929' | 'claude-opus-4-5-20251101' | 'claude-3-5-sonnet-20241022' | 'claude-3-5-haiku-20241022' | 'claude-3-opus-20240229' | (string & {});
230
+ /**
231
+ * System prompt configuration
232
+ */
233
+ type SystemPrompt = string | {
234
+ /** Use a preset system prompt */
235
+ type: 'preset';
236
+ /** The preset name */
237
+ preset: 'claude_code';
238
+ /** Additional text to append to the preset */
239
+ append?: string;
240
+ };
241
+ /**
242
+ * Output format configuration for structured outputs
243
+ */
244
+ interface OutputFormat {
245
+ /** Output format type */
246
+ type: 'json_schema';
247
+ /** JSON Schema definition for the expected output */
248
+ schema: Record<string, unknown>;
249
+ }
250
+ /**
251
+ * Agent definition for sub-agents
252
+ */
253
+ interface AgentDefinition {
254
+ /** Agent name */
255
+ name: string;
256
+ /** Agent description */
257
+ description?: string;
258
+ /** Model to use for this agent */
259
+ model?: Model;
260
+ /** System prompt for this agent */
261
+ systemPrompt?: SystemPrompt;
262
+ /** Tools available to this agent */
263
+ tools?: string[];
264
+ /** Maximum turns for this agent */
265
+ maxTurns?: number;
266
+ }
267
+ /**
268
+ * Base options shared between sessions and prompts
269
+ */
270
+ interface BaseOptions {
271
+ /**
272
+ * The model to use for generation
273
+ * @default 'claude-sonnet-4-5-20250929'
274
+ */
275
+ model?: Model;
276
+ /**
277
+ * Fallback model if primary model is unavailable
278
+ */
279
+ fallbackModel?: Model;
280
+ /**
281
+ * Maximum number of conversation turns
282
+ */
283
+ maxTurns?: number;
284
+ /**
285
+ * Maximum budget in USD for this session/prompt
286
+ */
287
+ maxBudgetUsd?: number;
288
+ /**
289
+ * Maximum thinking tokens (for extended thinking)
290
+ */
291
+ maxThinkingTokens?: number;
292
+ /**
293
+ * System prompt or preset configuration
294
+ */
295
+ systemPrompt?: SystemPrompt;
296
+ /**
297
+ * Tool configuration - allowlist of tool names or preset
298
+ * Pass an array of tool names or use the preset to get Claude Code's default tools
299
+ */
300
+ tools?: ToolsConfig;
301
+ /**
302
+ * List of tool names that are allowed
303
+ */
304
+ allowedTools?: string[];
305
+ /**
306
+ * List of tool names that are blocked
307
+ */
308
+ disallowedTools?: string[];
309
+ /**
310
+ * MCP server definitions (array format)
311
+ * Bridge translates to Record format for official SDK
312
+ */
313
+ mcpServers?: McpServerDefinition[];
314
+ /**
315
+ * Sub-agent definitions
316
+ */
317
+ agents?: Record<string, AgentDefinition>;
318
+ /**
319
+ * Beta features to enable
320
+ */
321
+ betas?: string[];
322
+ /**
323
+ * Permission mode for sandbox operations
324
+ */
325
+ permissionMode?: 'default' | 'plan' | 'bypassPermissions';
326
+ /**
327
+ * Allow dangerous operations (use with caution)
328
+ */
329
+ allowDangerouslySkipPermissions?: boolean;
330
+ /**
331
+ * Custom environment variables
332
+ */
333
+ env?: Record<string, string>;
334
+ /**
335
+ * Output format for structured responses
336
+ */
337
+ outputFormat?: OutputFormat;
338
+ /**
339
+ * Include partial messages in the stream
340
+ */
341
+ includePartialMessages?: boolean;
342
+ }
343
+ /**
344
+ * Session-specific options
345
+ */
346
+ interface SessionOptions extends BaseOptions {
347
+ /**
348
+ * Session ID for resuming an existing session
349
+ */
350
+ sessionId?: string;
351
+ /**
352
+ * Fork from an existing session instead of resuming
353
+ */
354
+ forkSession?: boolean;
355
+ /**
356
+ * Resume session at a specific conversation ID
357
+ */
358
+ resumeSessionAt?: string;
359
+ /**
360
+ * Continue from where the session left off
361
+ */
362
+ continue?: boolean;
363
+ /**
364
+ * Settings sources for configuration
365
+ */
366
+ settingSources?: Array<'user' | 'project' | 'local'>;
367
+ /**
368
+ * Job ID for tracking background/deferred executions
369
+ */
370
+ jobId?: string;
371
+ }
372
+ /**
373
+ * Prompt-specific options (stateless, one-shot)
374
+ */
375
+ interface PromptOptions extends BaseOptions {
376
+ /**
377
+ * The prompt message to send
378
+ */
379
+ message: string;
380
+ }
381
+ /**
382
+ * Client configuration options
383
+ */
384
+ interface ClientOptions {
385
+ /**
386
+ * Base URL for the Chucky service
387
+ * @default 'wss://box.chucky.cloud'
388
+ */
389
+ baseUrl?: string;
390
+ /**
391
+ * Authentication token (JWT)
392
+ */
393
+ token: string;
394
+ /**
395
+ * Enable debug logging
396
+ */
397
+ debug?: boolean;
398
+ /**
399
+ * Connection timeout in milliseconds
400
+ * @default 30000
401
+ */
402
+ timeout?: number;
403
+ /**
404
+ * Keep-alive interval in milliseconds
405
+ * @default 300000 (5 minutes)
406
+ */
407
+ keepAliveInterval?: number;
408
+ /**
409
+ * Auto-reconnect on disconnect
410
+ * @default true
411
+ */
412
+ autoReconnect?: boolean;
413
+ /**
414
+ * Maximum reconnect attempts
415
+ * @default 5
416
+ */
417
+ maxReconnectAttempts?: number;
418
+ }
419
+ /**
420
+ * Connection status
421
+ */
422
+ type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'error';
423
+ /**
424
+ * Event handlers for client events
425
+ */
426
+ interface ClientEventHandlers {
427
+ /** Called when connection status changes */
428
+ onStatusChange?: (status: ConnectionStatus) => void;
429
+ /** Called when a raw message is sent or received (for debugging) */
430
+ onRawMessage?: (direction: 'in' | 'out', message: unknown) => void;
431
+ /** Called when an error occurs */
432
+ onError?: (error: Error) => void;
433
+ }
434
+
435
+ /**
436
+ * WebSocket Message Types
437
+ *
438
+ * Matches the official Claude Agent SDK message format.
439
+ * See: https://platform.claude.com/docs/en/agent-sdk/typescript
440
+ */
441
+
442
+ type UUID = string;
443
+ /**
444
+ * Anthropic API message content types
445
+ */
446
+ type TextContent = {
447
+ type: 'text';
448
+ text: string;
449
+ };
450
+ type ImageContent = {
451
+ type: 'image';
452
+ source: {
453
+ type: 'base64';
454
+ media_type: string;
455
+ data: string;
456
+ };
457
+ };
458
+ type DocumentContent = {
459
+ type: 'document';
460
+ source: {
461
+ type: 'base64';
462
+ media_type: string;
463
+ data: string;
464
+ };
465
+ };
466
+ type ToolUseContent = {
467
+ type: 'tool_use';
468
+ id: string;
469
+ name: string;
470
+ input: Record<string, unknown>;
471
+ };
472
+ type ToolResultContent = {
473
+ type: 'tool_result';
474
+ tool_use_id: string;
475
+ content: string | Array<TextContent | ImageContent>;
476
+ is_error?: boolean;
477
+ };
478
+ type ContentBlock$1 = TextContent | ImageContent | DocumentContent | ToolUseContent | ToolResultContent;
479
+ /**
480
+ * Anthropic API User Message
481
+ */
482
+ interface APIUserMessage {
483
+ role: 'user';
484
+ content: string | ContentBlock$1[];
485
+ }
486
+ /**
487
+ * Anthropic API Assistant Message
488
+ */
489
+ interface APIAssistantMessage {
490
+ role: 'assistant';
491
+ content: ContentBlock$1[];
492
+ }
493
+ /**
494
+ * User message - sent by the client
495
+ */
496
+ interface SDKUserMessage {
497
+ type: 'user';
498
+ uuid?: UUID;
499
+ session_id: string;
500
+ message: APIUserMessage;
501
+ parent_tool_use_id: string | null;
502
+ }
503
+ /**
504
+ * Assistant message - response from Claude
505
+ */
506
+ interface SDKAssistantMessage {
507
+ type: 'assistant';
508
+ uuid: UUID;
509
+ session_id: string;
510
+ message: APIAssistantMessage;
511
+ parent_tool_use_id: string | null;
512
+ }
513
+ /**
514
+ * Result message subtypes
515
+ */
516
+ type ResultSubtype = 'success' | 'error_max_turns' | 'error_during_execution' | 'error_max_budget_usd' | 'error_max_structured_output_retries';
517
+ /**
518
+ * Success result message
519
+ */
520
+ interface SDKResultMessageSuccess {
521
+ type: 'result';
522
+ subtype: 'success';
523
+ uuid: UUID;
524
+ session_id: string;
525
+ duration_ms: number;
526
+ duration_api_ms: number;
527
+ is_error: boolean;
528
+ num_turns: number;
529
+ result: string;
530
+ total_cost_usd: number;
531
+ usage: {
532
+ input_tokens: number;
533
+ output_tokens: number;
534
+ cache_creation_input_tokens: number;
535
+ cache_read_input_tokens: number;
536
+ };
537
+ structured_output?: unknown;
538
+ }
539
+ /**
540
+ * Error result message
541
+ */
542
+ interface SDKResultMessageError {
543
+ type: 'result';
544
+ subtype: Exclude<ResultSubtype, 'success'>;
545
+ uuid: UUID;
546
+ session_id: string;
547
+ duration_ms: number;
548
+ duration_api_ms: number;
549
+ is_error: boolean;
550
+ num_turns: number;
551
+ total_cost_usd: number;
552
+ usage: {
553
+ input_tokens: number;
554
+ output_tokens: number;
555
+ cache_creation_input_tokens: number;
556
+ cache_read_input_tokens: number;
557
+ };
558
+ errors: string[];
559
+ }
560
+ type SDKResultMessage = SDKResultMessageSuccess | SDKResultMessageError;
561
+ /**
562
+ * System message subtypes
563
+ */
564
+ type SystemSubtype = 'init' | 'compact_boundary';
565
+ /**
566
+ * System init message
567
+ */
568
+ interface SDKSystemMessageInit {
569
+ type: 'system';
570
+ subtype: 'init';
571
+ uuid: UUID;
572
+ session_id: string;
573
+ cwd: string;
574
+ tools: string[];
575
+ mcp_servers: Array<{
576
+ name: string;
577
+ status: string;
578
+ }>;
579
+ model: string;
580
+ permissionMode: string;
581
+ }
582
+ /**
583
+ * System compact boundary message
584
+ */
585
+ interface SDKSystemMessageCompact {
586
+ type: 'system';
587
+ subtype: 'compact_boundary';
588
+ uuid: UUID;
589
+ session_id: string;
590
+ compact_metadata: {
591
+ trigger: 'manual' | 'auto';
592
+ pre_tokens: number;
593
+ };
594
+ }
595
+ type SDKSystemMessage = SDKSystemMessageInit | SDKSystemMessageCompact;
596
+ /**
597
+ * Partial assistant message (streaming)
598
+ */
599
+ interface SDKPartialAssistantMessage {
600
+ type: 'stream_event';
601
+ event: unknown;
602
+ parent_tool_use_id: string | null;
603
+ uuid: UUID;
604
+ session_id: string;
605
+ }
606
+ /**
607
+ * All SDK message types (matching official SDK)
608
+ */
609
+ type SDKMessage = SDKUserMessage | SDKAssistantMessage | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage;
610
+ /**
611
+ * WebSocket envelope types for our transport
612
+ */
613
+ type WsEnvelopeType = 'init' | 'user' | 'assistant' | 'result' | 'system' | 'stream_event' | 'control' | 'error' | 'ping' | 'pong' | 'tool_call' | 'tool_result';
614
+ /**
615
+ * Init message payload (session initialization)
616
+ */
617
+ interface InitPayload extends Omit<SessionOptions, 'mcpServers'> {
618
+ mcpServers?: unknown[];
619
+ }
620
+ /**
621
+ * Control message actions
622
+ */
623
+ type ControlAction = 'ready' | 'session_info' | 'end_input' | 'close';
624
+ /**
625
+ * Control message payload
626
+ */
627
+ interface ControlPayload {
628
+ action: ControlAction;
629
+ data?: Record<string, unknown>;
630
+ }
631
+ /**
632
+ * Error message payload
633
+ */
634
+ interface ErrorPayload {
635
+ message: string;
636
+ code?: string;
637
+ details?: Record<string, unknown>;
638
+ }
639
+ /**
640
+ * Ping/Pong payload
641
+ */
642
+ interface PingPongPayload {
643
+ timestamp: number;
644
+ }
645
+ /**
646
+ * Tool call payload (server -> client)
647
+ */
648
+ interface ToolCallPayload extends ToolCall {
649
+ }
650
+ /**
651
+ * Tool result payload (client -> server)
652
+ */
653
+ interface ToolResultPayload {
654
+ callId: string;
655
+ result: ToolResult;
656
+ }
657
+ interface InitEnvelope {
658
+ type: 'init';
659
+ payload: InitPayload;
660
+ }
661
+ interface ControlEnvelope {
662
+ type: 'control';
663
+ payload: ControlPayload;
664
+ }
665
+ interface ErrorEnvelope {
666
+ type: 'error';
667
+ payload: ErrorPayload;
668
+ }
669
+ interface PingEnvelope {
670
+ type: 'ping';
671
+ payload: PingPongPayload;
672
+ }
673
+ interface PongEnvelope {
674
+ type: 'pong';
675
+ payload: PingPongPayload;
676
+ }
677
+ interface ToolCallEnvelope {
678
+ type: 'tool_call';
679
+ payload: ToolCallPayload;
680
+ }
681
+ interface ToolResultEnvelope {
682
+ type: 'tool_result';
683
+ payload: ToolResultPayload;
684
+ }
685
+ /**
686
+ * Outgoing messages (client -> server)
687
+ */
688
+ type OutgoingMessage = InitEnvelope | SDKUserMessage | ControlEnvelope | PingEnvelope | ToolResultEnvelope;
689
+ /**
690
+ * Incoming messages (server -> client)
691
+ */
692
+ type IncomingMessage = SDKAssistantMessage | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage | ControlEnvelope | ErrorEnvelope | PongEnvelope | ToolCallEnvelope;
693
+ /**
694
+ * All messages
695
+ */
696
+ type AnyMessage = OutgoingMessage | IncomingMessage;
697
+ /**
698
+ * Create an init message
699
+ */
700
+ declare function createInitMessage(payload: InitPayload): InitEnvelope;
701
+ /**
702
+ * Create a user message (official SDK format)
703
+ */
704
+ declare function createUserMessage(content: string | ContentBlock$1[], sessionId: string, options?: {
705
+ uuid?: UUID;
706
+ parentToolUseId?: string | null;
707
+ }): SDKUserMessage;
708
+ /**
709
+ * Create a control message
710
+ */
711
+ declare function createControlMessage(action: ControlAction, data?: Record<string, unknown>): ControlEnvelope;
712
+ /**
713
+ * Create a ping message
714
+ */
715
+ declare function createPingMessage(): PingEnvelope;
716
+ /**
717
+ * Create a tool result message
718
+ */
719
+ declare function createToolResultMessage(callId: string, result: ToolResult): ToolResultEnvelope;
720
+ /**
721
+ * Check if message is a user message
722
+ */
723
+ declare function isUserMessage(message: AnyMessage): message is SDKUserMessage;
724
+ /**
725
+ * Check if message is an assistant message
726
+ */
727
+ declare function isAssistantMessage(message: AnyMessage): message is SDKAssistantMessage;
728
+ /**
729
+ * Check if message is a result message
730
+ */
731
+ declare function isResultMessage(message: AnyMessage): message is SDKResultMessage;
732
+ /**
733
+ * Check if message is a success result
734
+ */
735
+ declare function isSuccessResult(message: AnyMessage): message is SDKResultMessageSuccess;
736
+ /**
737
+ * Check if message is an error result
738
+ */
739
+ declare function isErrorResult(message: AnyMessage): message is SDKResultMessageError;
740
+ /**
741
+ * Check if message is a system message
742
+ */
743
+ declare function isSystemMessage(message: AnyMessage): message is SDKSystemMessage;
744
+ /**
745
+ * Check if message is a stream event
746
+ */
747
+ declare function isStreamEvent(message: AnyMessage): message is SDKPartialAssistantMessage;
748
+ /**
749
+ * Check if message is a tool call
750
+ */
751
+ declare function isToolCallMessage(message: AnyMessage): message is ToolCallEnvelope;
752
+ /**
753
+ * Check if message is a control message
754
+ */
755
+ declare function isControlMessage(message: AnyMessage): message is ControlEnvelope;
756
+ /**
757
+ * Check if message is an error message
758
+ */
759
+ declare function isErrorMessage(message: AnyMessage): message is ErrorEnvelope;
760
+
761
+ /**
762
+ * Result Types
763
+ *
764
+ * Types for responses from sessions and prompts.
765
+ */
766
+ /**
767
+ * Message role
768
+ */
769
+ type MessageRole = 'user' | 'assistant' | 'system';
770
+ /**
771
+ * Content block types
772
+ */
773
+ type ContentBlockType = 'text' | 'tool_use' | 'tool_result' | 'thinking' | 'image';
774
+ /**
775
+ * Text content block
776
+ */
777
+ interface TextBlock {
778
+ type: 'text';
779
+ text: string;
780
+ }
781
+ /**
782
+ * Tool use content block
783
+ */
784
+ interface ToolUseBlock {
785
+ type: 'tool_use';
786
+ id: string;
787
+ name: string;
788
+ input: Record<string, unknown>;
789
+ }
790
+ /**
791
+ * Tool result content block
792
+ */
793
+ interface ToolResultBlock {
794
+ type: 'tool_result';
795
+ tool_use_id: string;
796
+ content: string | Array<{
797
+ type: 'text';
798
+ text: string;
799
+ }>;
800
+ is_error?: boolean;
801
+ }
802
+ /**
803
+ * Thinking content block (extended thinking)
804
+ */
805
+ interface ThinkingBlock {
806
+ type: 'thinking';
807
+ thinking: string;
808
+ }
809
+ /**
810
+ * Image content block
811
+ */
812
+ interface ImageBlock {
813
+ type: 'image';
814
+ source: {
815
+ type: 'base64';
816
+ media_type: string;
817
+ data: string;
818
+ };
819
+ }
820
+ /**
821
+ * Union type for all content blocks
822
+ */
823
+ type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock | ImageBlock;
824
+ /**
825
+ * A message in the conversation
826
+ */
827
+ interface Message {
828
+ /** Message role */
829
+ role: MessageRole;
830
+ /** Message content */
831
+ content: ContentBlock[] | string;
832
+ }
833
+ /**
834
+ * Usage statistics
835
+ */
836
+ interface Usage {
837
+ /** Input tokens used */
838
+ input_tokens: number;
839
+ /** Output tokens generated */
840
+ output_tokens: number;
841
+ /** Cache creation input tokens */
842
+ cache_creation_input_tokens?: number;
843
+ /** Cache read input tokens */
844
+ cache_read_input_tokens?: number;
845
+ }
846
+ /**
847
+ * Cost breakdown
848
+ */
849
+ interface CostBreakdown {
850
+ /** Input cost in USD */
851
+ input_cost_usd: number;
852
+ /** Output cost in USD */
853
+ output_cost_usd: number;
854
+ /** Total cost in USD */
855
+ total_cost_usd: number;
856
+ }
857
+ /**
858
+ * Session result (returned when session completes)
859
+ */
860
+ interface SessionResult {
861
+ /** Result type */
862
+ type: 'result';
863
+ /** Result subtype */
864
+ subtype?: 'success' | 'error' | 'interrupted';
865
+ /** Final response text */
866
+ text?: string;
867
+ /** Conversation messages */
868
+ messages?: Message[];
869
+ /** Total cost in USD */
870
+ total_cost_usd?: number;
871
+ /** Session duration in seconds */
872
+ duration_secs?: number;
873
+ /** Number of conversation turns */
874
+ turn_count?: number;
875
+ /** Usage statistics */
876
+ usage?: Usage;
877
+ /** Session ID (for resuming) */
878
+ session_id?: string;
879
+ /** Error message (if subtype is 'error') */
880
+ error?: string;
881
+ }
882
+ /**
883
+ * Prompt result (returned from one-shot prompts)
884
+ */
885
+ interface PromptResult {
886
+ /** Result type */
887
+ type: 'result';
888
+ /** Result subtype */
889
+ subtype?: 'success' | 'error';
890
+ /** Response text */
891
+ text?: string;
892
+ /** Structured output (if outputFormat was specified) */
893
+ output?: unknown;
894
+ /** Total cost in USD */
895
+ total_cost_usd?: number;
896
+ /** Duration in seconds */
897
+ duration_secs?: number;
898
+ /** Usage statistics */
899
+ usage?: Usage;
900
+ /** Error message (if subtype is 'error') */
901
+ error?: string;
902
+ }
903
+ /**
904
+ * Streaming message event
905
+ */
906
+ interface StreamEvent {
907
+ /** Event type */
908
+ type: 'message_start' | 'content_block_start' | 'content_block_delta' | 'content_block_stop' | 'message_delta' | 'message_stop' | 'tool_use' | 'tool_result' | 'error';
909
+ /** Event data */
910
+ data: unknown;
911
+ }
912
+ /**
913
+ * Partial message (during streaming)
914
+ */
915
+ interface PartialMessage {
916
+ /** Message role */
917
+ role: MessageRole;
918
+ /** Partial content accumulated so far */
919
+ content: ContentBlock[];
920
+ /** Whether the message is complete */
921
+ complete: boolean;
922
+ }
923
+ /**
924
+ * Session state
925
+ */
926
+ type SessionState = 'idle' | 'initializing' | 'ready' | 'processing' | 'waiting_tool' | 'completed' | 'error';
927
+ /**
928
+ * Session info (returned when connecting/resuming)
929
+ */
930
+ interface SessionInfo {
931
+ /** Session ID */
932
+ sessionId?: string;
933
+ /** Current state */
934
+ state?: SessionState;
935
+ /** Number of messages in conversation */
936
+ messageCount?: number;
937
+ /** Session creation time (ISO 8601) */
938
+ createdAt?: string;
939
+ /** Last activity time (ISO 8601) */
940
+ lastActivityAt?: string;
941
+ /** Model being used */
942
+ model?: string;
943
+ /** Available tools */
944
+ tools?: string[];
945
+ }
946
+
947
+ /**
948
+ * Transport Interface
949
+ *
950
+ * Abstract interface for communication between the SDK and Chucky server.
951
+ * Implementations can use WebSocket (browser/Node.js) or other protocols.
952
+ */
953
+
954
+ /**
955
+ * Transport event types
956
+ */
957
+ interface TransportEvents extends ClientEventHandlers {
958
+ /** Called when a message is received */
959
+ onMessage?: (message: IncomingMessage) => void;
960
+ /** Called when the transport is closed */
961
+ onClose?: (code?: number, reason?: string) => void;
962
+ }
963
+ /**
964
+ * Transport configuration
965
+ */
966
+ interface TransportConfig {
967
+ /** Server URL */
968
+ url: string;
969
+ /** Authentication token */
970
+ token: string;
971
+ /** Connection timeout in milliseconds */
972
+ timeout?: number;
973
+ /** Keep-alive interval in milliseconds */
974
+ keepAliveInterval?: number;
975
+ /** Auto-reconnect on disconnect */
976
+ autoReconnect?: boolean;
977
+ /** Maximum reconnect attempts */
978
+ maxReconnectAttempts?: number;
979
+ /** Debug mode */
980
+ debug?: boolean;
981
+ }
982
+ /**
983
+ * Abstract transport interface
984
+ */
985
+ interface Transport {
986
+ /** Current connection status */
987
+ readonly status: ConnectionStatus;
988
+ /**
989
+ * Connect to the server
990
+ */
991
+ connect(): Promise<void>;
992
+ /**
993
+ * Disconnect from the server
994
+ */
995
+ disconnect(): Promise<void>;
996
+ /**
997
+ * Send a message to the server
998
+ */
999
+ send(message: OutgoingMessage): Promise<void>;
1000
+ /**
1001
+ * Set event handlers
1002
+ */
1003
+ setEventHandlers(handlers: TransportEvents): void;
1004
+ /**
1005
+ * Wait for connection to be ready
1006
+ */
1007
+ waitForReady(): Promise<void>;
1008
+ }
1009
+ /**
1010
+ * Base transport class with common functionality
1011
+ */
1012
+ declare abstract class BaseTransport implements Transport {
1013
+ protected _status: ConnectionStatus;
1014
+ protected handlers: TransportEvents;
1015
+ protected config: TransportConfig;
1016
+ constructor(config: TransportConfig);
1017
+ get status(): ConnectionStatus;
1018
+ protected setStatus(status: ConnectionStatus): void;
1019
+ protected log(...args: unknown[]): void;
1020
+ protected logError(...args: unknown[]): void;
1021
+ setEventHandlers(handlers: TransportEvents): void;
1022
+ abstract connect(): Promise<void>;
1023
+ abstract disconnect(): Promise<void>;
1024
+ abstract send(message: OutgoingMessage): Promise<void>;
1025
+ abstract waitForReady(): Promise<void>;
1026
+ }
1027
+
1028
+ /**
1029
+ * Session
1030
+ *
1031
+ * Represents a conversation session with the Chucky sandbox.
1032
+ * Matches the official Claude Agent SDK V2 interface.
1033
+ *
1034
+ * @example
1035
+ * ```typescript
1036
+ * const session = createSession({ token, model: 'claude-sonnet-4-5-20250929' });
1037
+ *
1038
+ * await session.send('Hello!');
1039
+ * for await (const msg of session.stream()) {
1040
+ * if (msg.type === 'assistant') {
1041
+ * console.log(getAssistantText(msg));
1042
+ * }
1043
+ * }
1044
+ * ```
1045
+ */
1046
+
1047
+ /**
1048
+ * Session event handlers
1049
+ */
1050
+ interface SessionEventHandlers {
1051
+ onSessionInfo?: (info: SessionInfo) => void;
1052
+ onError?: (error: Error) => void;
1053
+ }
1054
+ /**
1055
+ * Internal session configuration
1056
+ */
1057
+ interface SessionConfig {
1058
+ debug?: boolean;
1059
+ }
1060
+ /**
1061
+ * Session class - matches official V2 SDK interface
1062
+ *
1063
+ * Usage:
1064
+ * ```typescript
1065
+ * const session = createSession({ token, model: 'claude-sonnet-4-5-20250929' });
1066
+ *
1067
+ * // Multi-turn conversation
1068
+ * await session.send('What is 5 + 3?');
1069
+ * for await (const msg of session.stream()) {
1070
+ * if (msg.type === 'result') console.log(msg.result);
1071
+ * }
1072
+ *
1073
+ * await session.send('Multiply that by 2');
1074
+ * for await (const msg of session.stream()) {
1075
+ * if (msg.type === 'result') console.log(msg.result);
1076
+ * }
1077
+ *
1078
+ * session.close();
1079
+ * ```
1080
+ */
1081
+ declare class Session {
1082
+ private transport;
1083
+ private options;
1084
+ private config;
1085
+ private eventHandlers;
1086
+ private toolHandlers;
1087
+ private messageBuffer;
1088
+ private _state;
1089
+ private _sessionId;
1090
+ private messageResolvers;
1091
+ private connected;
1092
+ private connectPromise;
1093
+ constructor(transport: Transport, options: SessionOptions, config?: SessionConfig);
1094
+ /**
1095
+ * Get the session ID
1096
+ */
1097
+ get sessionId(): string;
1098
+ /**
1099
+ * Set event handlers
1100
+ */
1101
+ on(handlers: SessionEventHandlers): this;
1102
+ /**
1103
+ * Connect and initialize the session (called automatically on first send)
1104
+ */
1105
+ private ensureConnected;
1106
+ private connect;
1107
+ /**
1108
+ * Send a message to the session
1109
+ *
1110
+ * Matches V2 SDK: send() returns Promise<void>
1111
+ * Use stream() to get the response.
1112
+ *
1113
+ * Supports both text-only messages and multimodal content (text + images).
1114
+ *
1115
+ * @example
1116
+ * ```typescript
1117
+ * // Text-only message
1118
+ * await session.send('Hello!');
1119
+ *
1120
+ * // Multimodal message with image
1121
+ * await session.send([
1122
+ * { type: 'text', text: 'What is in this image?' },
1123
+ * { type: 'image', source: { type: 'base64', media_type: 'image/png', data: '...' } }
1124
+ * ]);
1125
+ *
1126
+ * for await (const msg of session.stream()) {
1127
+ * // Handle messages
1128
+ * }
1129
+ * ```
1130
+ */
1131
+ send(message: string | ContentBlock$1[]): Promise<void>;
1132
+ /**
1133
+ * Stream the response after sending a message
1134
+ *
1135
+ * Matches V2 SDK: Returns AsyncGenerator<SDKMessage>
1136
+ *
1137
+ * @example
1138
+ * ```typescript
1139
+ * await session.send('Hello!');
1140
+ * for await (const msg of session.stream()) {
1141
+ * if (msg.type === 'assistant') {
1142
+ * const text = msg.message.content
1143
+ * .filter(b => b.type === 'text')
1144
+ * .map(b => b.text)
1145
+ * .join('');
1146
+ * console.log(text);
1147
+ * }
1148
+ * if (msg.type === 'result') {
1149
+ * console.log('Done:', msg.result);
1150
+ * }
1151
+ * }
1152
+ * ```
1153
+ */
1154
+ stream(): AsyncGenerator<SDKMessage, void, unknown>;
1155
+ /**
1156
+ * Receive messages (alias for stream for V2 compatibility)
1157
+ */
1158
+ receive(): AsyncGenerator<SDKMessage, void, unknown>;
1159
+ /**
1160
+ * Close the session
1161
+ */
1162
+ close(): void;
1163
+ /**
1164
+ * Support for `await using` (TypeScript 5.2+)
1165
+ */
1166
+ [Symbol.asyncDispose](): Promise<void>;
1167
+ /**
1168
+ * Build init payload from options
1169
+ */
1170
+ private buildInitPayload;
1171
+ /**
1172
+ * Handle incoming message
1173
+ */
1174
+ private handleMessage;
1175
+ /**
1176
+ * Wait for session to be ready
1177
+ */
1178
+ private waitForReady;
1179
+ /**
1180
+ * Wait for next message
1181
+ */
1182
+ private waitForNextMessage;
1183
+ /**
1184
+ * Handle a tool call
1185
+ */
1186
+ private handleToolCall;
1187
+ /**
1188
+ * Log debug messages
1189
+ */
1190
+ private log;
1191
+ }
1192
+ /**
1193
+ * Extract text from an assistant message
1194
+ */
1195
+ declare function getAssistantText(msg: SDKMessage): string | null;
1196
+ /**
1197
+ * Extract result from a result message
1198
+ */
1199
+ declare function getResultText(msg: SDKMessage): string | null;
1200
+
1201
+ /**
1202
+ * Chucky Client
1203
+ *
1204
+ * Main entry point for the Chucky SDK.
1205
+ * Provides methods to create sessions and execute prompts.
1206
+ * Matches the official Claude Agent SDK V2 interface.
1207
+ */
1208
+
1209
+ /**
1210
+ * Chucky client for interacting with the sandbox service
1211
+ *
1212
+ * Matches the official Claude Agent SDK V2 interface.
1213
+ *
1214
+ * @example
1215
+ * ```typescript
1216
+ * import { ChuckyClient } from '@chucky.cloud/sdk';
1217
+ *
1218
+ * const client = new ChuckyClient({
1219
+ * token: 'your-jwt-token',
1220
+ * });
1221
+ *
1222
+ * // Create a session (V2 style)
1223
+ * const session = client.createSession({
1224
+ * model: 'claude-sonnet-4-5-20250929',
1225
+ * systemPrompt: 'You are a helpful assistant.',
1226
+ * });
1227
+ *
1228
+ * // Send messages and stream responses
1229
+ * await session.send('Hello, world!');
1230
+ * for await (const msg of session.stream()) {
1231
+ * if (msg.type === 'assistant') {
1232
+ * const text = getAssistantText(msg);
1233
+ * console.log(text);
1234
+ * }
1235
+ * if (msg.type === 'result') {
1236
+ * console.log('Done:', msg);
1237
+ * }
1238
+ * }
1239
+ *
1240
+ * session.close();
1241
+ * ```
1242
+ */
1243
+ declare class ChuckyClient {
1244
+ private readonly options;
1245
+ private eventHandlers;
1246
+ private activeSessions;
1247
+ /**
1248
+ * Create a new Chucky client
1249
+ */
1250
+ constructor(options: ClientOptions);
1251
+ /**
1252
+ * Set event handlers
1253
+ */
1254
+ on(handlers: ClientEventHandlers): this;
1255
+ /**
1256
+ * Create a new session
1257
+ *
1258
+ * Matches V2 SDK: createSession() returns a Session immediately.
1259
+ * Connection happens automatically on first send().
1260
+ *
1261
+ * @param options - Session configuration options
1262
+ * @returns A new session instance
1263
+ *
1264
+ * @example
1265
+ * ```typescript
1266
+ * const session = client.createSession({
1267
+ * model: 'claude-sonnet-4-5-20250929',
1268
+ * systemPrompt: 'You are a helpful coding assistant.',
1269
+ * });
1270
+ *
1271
+ * await session.send('Hello!');
1272
+ * for await (const msg of session.stream()) {
1273
+ * // Handle messages
1274
+ * }
1275
+ * ```
1276
+ */
1277
+ createSession(options?: SessionOptions): Session;
1278
+ /**
1279
+ * Resume an existing session
1280
+ *
1281
+ * @param sessionId - The session ID to resume
1282
+ * @param options - Additional session options
1283
+ * @returns The resumed session
1284
+ *
1285
+ * @example
1286
+ * ```typescript
1287
+ * const session = client.resumeSession('session-123');
1288
+ * await session.send('Continue our conversation');
1289
+ * ```
1290
+ */
1291
+ resumeSession(sessionId: string, options?: Omit<SessionOptions, 'sessionId'>): Session;
1292
+ /**
1293
+ * Execute a one-shot prompt (stateless)
1294
+ *
1295
+ * Supports two call signatures:
1296
+ * - `prompt('message', { model: '...' })` - positional style
1297
+ * - `prompt({ message: '...', model: '...' })` - object style
1298
+ *
1299
+ * @param messageOrOptions - The message string OR an options object with message
1300
+ * @param options - Prompt configuration (only used with positional style)
1301
+ * @returns The result message
1302
+ *
1303
+ * @example
1304
+ * ```typescript
1305
+ * // Positional style
1306
+ * const result = await client.prompt(
1307
+ * 'Explain quantum computing in simple terms',
1308
+ * { model: 'claude-sonnet-4-5-20250929' }
1309
+ * );
1310
+ *
1311
+ * // Object style
1312
+ * const result = await client.prompt({
1313
+ * message: 'Explain quantum computing in simple terms',
1314
+ * model: 'claude-sonnet-4-5-20250929',
1315
+ * });
1316
+ *
1317
+ * if (result.subtype === 'success') {
1318
+ * console.log(result.result);
1319
+ * }
1320
+ * ```
1321
+ */
1322
+ prompt(messageOrOptions: string | PromptOptions, options?: SessionOptions): Promise<SDKResultMessage>;
1323
+ /**
1324
+ * Close all active sessions and disconnect
1325
+ */
1326
+ close(): void;
1327
+ /**
1328
+ * Create a new transport instance
1329
+ */
1330
+ private createTransport;
1331
+ }
1332
+ /**
1333
+ * Create a Chucky client
1334
+ *
1335
+ * @param options - Client configuration
1336
+ * @returns A new ChuckyClient instance
1337
+ *
1338
+ * @example
1339
+ * ```typescript
1340
+ * import { createClient } from '@chucky.cloud/sdk';
1341
+ *
1342
+ * const client = createClient({
1343
+ * token: 'your-jwt-token',
1344
+ * });
1345
+ * ```
1346
+ */
1347
+ declare function createClient(options: ClientOptions): ChuckyClient;
1348
+
1349
+ /**
1350
+ * Tool Helper
1351
+ *
1352
+ * Helper functions for defining tools with type safety.
1353
+ * Supports both JSON Schema and Zod for input validation.
1354
+ */
1355
+
1356
+ /**
1357
+ * Options for creating a tool
1358
+ */
1359
+ interface CreateToolOptions<TInput = Record<string, unknown>> {
1360
+ /** Tool name (must be unique) */
1361
+ name: string;
1362
+ /** Human-readable description */
1363
+ description: string;
1364
+ /** Input schema (JSON Schema or Zod schema) */
1365
+ inputSchema: ToolInputSchema | ZodLikeSchema;
1366
+ /** Where to execute the tool */
1367
+ executeIn?: ToolExecutionLocation;
1368
+ /** Handler function */
1369
+ handler?: ToolHandler<TInput>;
1370
+ }
1371
+ /**
1372
+ * Zod-like schema interface for compatibility
1373
+ */
1374
+ interface ZodLikeSchema {
1375
+ _def?: unknown;
1376
+ shape?: unknown;
1377
+ safeParse?: (data: unknown) => {
1378
+ success: boolean;
1379
+ data?: unknown;
1380
+ error?: unknown;
1381
+ };
1382
+ }
1383
+ /**
1384
+ * Create a tool definition
1385
+ *
1386
+ * @param options - Tool configuration
1387
+ * @returns Tool definition ready to use
1388
+ *
1389
+ * @example
1390
+ * ```typescript
1391
+ * // With JSON Schema
1392
+ * const weatherTool = createTool({
1393
+ * name: 'get_weather',
1394
+ * description: 'Get current weather for a city',
1395
+ * inputSchema: {
1396
+ * type: 'object',
1397
+ * properties: {
1398
+ * city: { type: 'string', description: 'City name' },
1399
+ * unit: { type: 'string', enum: ['celsius', 'fahrenheit'] },
1400
+ * },
1401
+ * required: ['city'],
1402
+ * },
1403
+ * handler: async ({ city, unit }) => ({
1404
+ * content: [{ type: 'text', text: `Weather in ${city}: Sunny, 72°${unit === 'celsius' ? 'C' : 'F'}` }],
1405
+ * }),
1406
+ * });
1407
+ *
1408
+ * // With Zod (optional peer dependency)
1409
+ * import { z } from 'zod';
1410
+ *
1411
+ * const calculatorTool = createTool({
1412
+ * name: 'calculate',
1413
+ * description: 'Perform a calculation',
1414
+ * inputSchema: z.object({
1415
+ * expression: z.string().describe('Math expression to evaluate'),
1416
+ * }),
1417
+ * handler: async ({ expression }) => ({
1418
+ * content: [{ type: 'text', text: `Result: ${eval(expression)}` }],
1419
+ * }),
1420
+ * });
1421
+ * ```
1422
+ */
1423
+ declare function createTool<TInput = Record<string, unknown>>(options: CreateToolOptions<TInput>): ToolDefinition<TInput>;
1424
+ /**
1425
+ * Shorthand for creating a tool
1426
+ *
1427
+ * @param name - Tool name
1428
+ * @param description - Tool description
1429
+ * @param inputSchema - Input schema
1430
+ * @param handler - Handler function
1431
+ * @returns Tool definition
1432
+ *
1433
+ * @example
1434
+ * ```typescript
1435
+ * const greetTool = tool(
1436
+ * 'greet',
1437
+ * 'Greet a person by name',
1438
+ * {
1439
+ * type: 'object',
1440
+ * properties: { name: { type: 'string' } },
1441
+ * required: ['name'],
1442
+ * },
1443
+ * async ({ name }) => ({
1444
+ * content: [{ type: 'text', text: `Hello, ${name}!` }],
1445
+ * })
1446
+ * );
1447
+ * ```
1448
+ */
1449
+ declare function tool<TInput = Record<string, unknown>>(name: string, description: string, inputSchema: ToolInputSchema | ZodLikeSchema, handler?: ToolHandler<TInput>): ToolDefinition<TInput>;
1450
+ /**
1451
+ * Create a browser-executed tool
1452
+ *
1453
+ * @param options - Tool configuration
1454
+ * @returns Tool definition that executes in the browser
1455
+ *
1456
+ * @example
1457
+ * ```typescript
1458
+ * const alertTool = browserTool({
1459
+ * name: 'show_alert',
1460
+ * description: 'Show an alert dialog',
1461
+ * inputSchema: {
1462
+ * type: 'object',
1463
+ * properties: { message: { type: 'string' } },
1464
+ * required: ['message'],
1465
+ * },
1466
+ * handler: async ({ message }) => {
1467
+ * alert(message);
1468
+ * return { content: [{ type: 'text', text: 'Alert shown' }] };
1469
+ * },
1470
+ * });
1471
+ * ```
1472
+ */
1473
+ declare function browserTool<TInput = Record<string, unknown>>(options: Omit<CreateToolOptions<TInput>, 'executeIn'>): ToolDefinition<TInput>;
1474
+ /**
1475
+ * Create a server-executed tool
1476
+ *
1477
+ * @param options - Tool configuration (handler is optional for server tools)
1478
+ * @returns Tool definition that executes on the server
1479
+ */
1480
+ declare function serverTool<TInput = Record<string, unknown>>(options: Omit<CreateToolOptions<TInput>, 'executeIn' | 'handler'>): ToolDefinition<TInput>;
1481
+ /**
1482
+ * Helper to create text content for tool results
1483
+ */
1484
+ declare function textResult(text: string): ToolResult;
1485
+ /**
1486
+ * Helper to create error result for tools
1487
+ */
1488
+ declare function errorResult(message: string): ToolResult;
1489
+ /**
1490
+ * Helper to create image content for tool results
1491
+ */
1492
+ declare function imageResult(data: string, mimeType: string): ToolResult;
1493
+
1494
+ /**
1495
+ * MCP Server Builder
1496
+ *
1497
+ * Builder pattern for creating MCP server definitions with multiple tools.
1498
+ */
1499
+
1500
+ /**
1501
+ * MCP Server builder for creating server definitions
1502
+ *
1503
+ * @example
1504
+ * ```typescript
1505
+ * const myServer = new McpServerBuilder('my-tools', '1.0.0')
1506
+ * .addTool({
1507
+ * name: 'greet',
1508
+ * description: 'Greet someone',
1509
+ * inputSchema: {
1510
+ * type: 'object',
1511
+ * properties: { name: { type: 'string' } },
1512
+ * required: ['name'],
1513
+ * },
1514
+ * handler: async ({ name }) => ({
1515
+ * content: [{ type: 'text', text: `Hello, ${name}!` }],
1516
+ * }),
1517
+ * })
1518
+ * .addTool({
1519
+ * name: 'farewell',
1520
+ * description: 'Say goodbye',
1521
+ * inputSchema: {
1522
+ * type: 'object',
1523
+ * properties: { name: { type: 'string' } },
1524
+ * required: ['name'],
1525
+ * },
1526
+ * handler: async ({ name }) => ({
1527
+ * content: [{ type: 'text', text: `Goodbye, ${name}!` }],
1528
+ * }),
1529
+ * })
1530
+ * .build();
1531
+ * ```
1532
+ */
1533
+ declare class McpServerBuilder {
1534
+ private name;
1535
+ private version;
1536
+ private tools;
1537
+ /**
1538
+ * Create a new MCP server builder
1539
+ *
1540
+ * @param name - Server name
1541
+ * @param version - Server version (default: '1.0.0')
1542
+ */
1543
+ constructor(name: string, version?: string);
1544
+ /**
1545
+ * Add a tool to the server
1546
+ *
1547
+ * @param options - Tool configuration
1548
+ * @returns This builder for chaining
1549
+ */
1550
+ addTool<TInput = Record<string, unknown>>(options: CreateToolOptions<TInput>): this;
1551
+ /**
1552
+ * Add an existing tool definition
1553
+ *
1554
+ * @param tool - Tool definition
1555
+ * @returns This builder for chaining
1556
+ */
1557
+ add(tool: ToolDefinition): this;
1558
+ /**
1559
+ * Add multiple tools at once
1560
+ *
1561
+ * @param tools - Array of tool definitions
1562
+ * @returns This builder for chaining
1563
+ */
1564
+ addTools(tools: ToolDefinition[]): this;
1565
+ /**
1566
+ * Build the MCP server definition
1567
+ *
1568
+ * @returns Complete MCP server definition
1569
+ */
1570
+ build(): McpServerDefinition;
1571
+ }
1572
+ /**
1573
+ * Create an MCP server definition
1574
+ *
1575
+ * @param name - Server name
1576
+ * @param tools - Array of tool definitions
1577
+ * @param version - Server version
1578
+ * @returns MCP server definition
1579
+ *
1580
+ * @example
1581
+ * ```typescript
1582
+ * const server = createMcpServer('my-server', [
1583
+ * tool('greet', 'Greet someone', { type: 'object', properties: { name: { type: 'string' } } }),
1584
+ * tool('farewell', 'Say goodbye', { type: 'object', properties: { name: { type: 'string' } } }),
1585
+ * ]);
1586
+ * ```
1587
+ */
1588
+ declare function createMcpServer(name: string, tools: ToolDefinition[], version?: string): McpServerDefinition;
1589
+ /**
1590
+ * Create an MCP server using the builder pattern
1591
+ *
1592
+ * @param name - Server name
1593
+ * @param version - Server version
1594
+ * @returns MCP server builder
1595
+ *
1596
+ * @example
1597
+ * ```typescript
1598
+ * const server = mcpServer('my-tools')
1599
+ * .addTool({
1600
+ * name: 'hello',
1601
+ * description: 'Say hello',
1602
+ * inputSchema: { type: 'object', properties: {} },
1603
+ * handler: async () => ({ content: [{ type: 'text', text: 'Hello!' }] }),
1604
+ * })
1605
+ * .build();
1606
+ * ```
1607
+ */
1608
+ declare function mcpServer(name: string, version?: string): McpServerBuilder;
1609
+
1610
+ /**
1611
+ * Budget Token Types
1612
+ *
1613
+ * Types for JWT tokens used for authentication and budget control.
1614
+ */
1615
+ /**
1616
+ * Budget window types
1617
+ */
1618
+ type BudgetWindow = 'hour' | 'day' | 'week' | 'month';
1619
+ /**
1620
+ * Budget configuration in a token
1621
+ */
1622
+ interface TokenBudget {
1623
+ /** AI budget in microdollars (1 USD = 1,000,000 microdollars) */
1624
+ ai: number;
1625
+ /** Compute budget in seconds */
1626
+ compute: number;
1627
+ /** Budget window period */
1628
+ window: BudgetWindow;
1629
+ /** When current period started (ISO 8601) */
1630
+ windowStart: string;
1631
+ }
1632
+ /**
1633
+ * Permission configuration in a token
1634
+ */
1635
+ interface TokenPermissions {
1636
+ /** Allowed tool names */
1637
+ tools?: string[];
1638
+ /** Blocked tool names */
1639
+ blockedTools?: string[];
1640
+ /** Maximum turns per conversation */
1641
+ maxTurns?: number;
1642
+ /** Model restriction */
1643
+ model?: string;
1644
+ }
1645
+ /**
1646
+ * SDK configuration overrides in a token
1647
+ * When present, these values SUPERSEDE options provided by the SDK client
1648
+ */
1649
+ interface TokenSdkConfig {
1650
+ /** Model to use */
1651
+ model?: string;
1652
+ /** System prompt */
1653
+ systemPrompt?: string;
1654
+ /** Tools configuration */
1655
+ tools?: unknown;
1656
+ /** Allowed tools */
1657
+ allowedTools?: string[];
1658
+ /** Disallowed tools */
1659
+ disallowedTools?: string[];
1660
+ /** Maximum turns */
1661
+ maxTurns?: number;
1662
+ /** Maximum budget in USD */
1663
+ maxBudgetUsd?: number;
1664
+ /** Maximum thinking tokens */
1665
+ maxThinkingTokens?: number;
1666
+ /** Permission mode */
1667
+ permissionMode?: string;
1668
+ /** Allow dangerous skip permissions */
1669
+ allowDangerouslySkipPermissions?: boolean;
1670
+ /** MCP servers configuration */
1671
+ mcpServers?: unknown[];
1672
+ /** Agents configuration */
1673
+ agents?: unknown;
1674
+ /** Betas configuration */
1675
+ betas?: string[];
1676
+ /** Output format */
1677
+ outputFormat?: string;
1678
+ /** Environment variables */
1679
+ env?: Record<string, string>;
1680
+ }
1681
+ /**
1682
+ * Budget token payload (JWT claims)
1683
+ */
1684
+ interface BudgetTokenPayload {
1685
+ /** User ID - unique identifier for the end user */
1686
+ sub: string;
1687
+ /** Project/Issuer ID - identifies which project */
1688
+ iss: string;
1689
+ /** Token expiry timestamp (Unix seconds) */
1690
+ exp: number;
1691
+ /** Issued at timestamp (Unix seconds) */
1692
+ iat?: number;
1693
+ /** Budget declaration */
1694
+ budget: TokenBudget;
1695
+ /** Permission configuration (optional) */
1696
+ permissions?: TokenPermissions;
1697
+ /** SDK config overrides (optional) */
1698
+ sdkConfig?: TokenSdkConfig;
1699
+ }
1700
+ /**
1701
+ * Options for creating a budget token
1702
+ */
1703
+ interface CreateTokenOptions {
1704
+ /** User ID */
1705
+ userId: string;
1706
+ /** Project/Issuer ID (UUID) */
1707
+ projectId: string;
1708
+ /** HMAC secret key for signing */
1709
+ secret: string;
1710
+ /** Token expiry duration in seconds (default: 3600 = 1 hour) */
1711
+ expiresIn?: number;
1712
+ /** Budget configuration */
1713
+ budget: TokenBudget;
1714
+ /** Permission configuration */
1715
+ permissions?: TokenPermissions;
1716
+ /** SDK config overrides */
1717
+ sdkConfig?: TokenSdkConfig;
1718
+ }
1719
+ /**
1720
+ * Decoded token result
1721
+ */
1722
+ interface DecodedToken {
1723
+ /** Token header */
1724
+ header: {
1725
+ alg: string;
1726
+ typ: string;
1727
+ };
1728
+ /** Token payload */
1729
+ payload: BudgetTokenPayload;
1730
+ /** Token signature (base64url) */
1731
+ signature: string;
1732
+ }
1733
+
1734
+ /**
1735
+ * Token Utilities
1736
+ *
1737
+ * Helpers for creating and decoding JWT tokens for authentication.
1738
+ * These are primarily for server-side use (Node.js).
1739
+ */
1740
+
1741
+ /**
1742
+ * Create a budget token (JWT) for authenticating with Chucky
1743
+ *
1744
+ * @param options - Token creation options
1745
+ * @returns Signed JWT token
1746
+ *
1747
+ * @example
1748
+ * ```typescript
1749
+ * // Server-side token creation
1750
+ * const token = await createToken({
1751
+ * userId: 'user-123',
1752
+ * projectId: '550e8400-e29b-41d4-a716-446655440000',
1753
+ * secret: 'your-hmac-secret',
1754
+ * budget: {
1755
+ * ai: 1_000_000, // $1 in microdollars
1756
+ * compute: 3600, // 1 hour
1757
+ * window: 'day',
1758
+ * windowStart: new Date().toISOString(),
1759
+ * },
1760
+ * });
1761
+ * ```
1762
+ */
1763
+ declare function createToken(options: CreateTokenOptions): Promise<string>;
1764
+ /**
1765
+ * Decode a token without verification
1766
+ *
1767
+ * @param token - JWT token to decode
1768
+ * @returns Decoded token parts
1769
+ *
1770
+ * @example
1771
+ * ```typescript
1772
+ * const decoded = decodeToken(token);
1773
+ * console.log(decoded.payload.sub); // User ID
1774
+ * console.log(decoded.payload.budget); // Budget limits
1775
+ * ```
1776
+ */
1777
+ declare function decodeToken(token: string): DecodedToken;
1778
+ /**
1779
+ * Verify a token signature
1780
+ *
1781
+ * @param token - JWT token to verify
1782
+ * @param secret - HMAC secret for verification
1783
+ * @returns True if signature is valid
1784
+ *
1785
+ * @example
1786
+ * ```typescript
1787
+ * const isValid = await verifyToken(token, 'your-hmac-secret');
1788
+ * if (!isValid) {
1789
+ * throw new Error('Invalid token');
1790
+ * }
1791
+ * ```
1792
+ */
1793
+ declare function verifyToken(token: string, secret: string): Promise<boolean>;
1794
+ /**
1795
+ * Check if a token is expired
1796
+ *
1797
+ * @param token - JWT token to check
1798
+ * @returns True if token is expired
1799
+ */
1800
+ declare function isTokenExpired(token: string): boolean;
1801
+ /**
1802
+ * @deprecated The project ID is now separate from the HMAC key for security reasons.
1803
+ * Get your project ID from the Chucky portal (app.chucky.cloud) instead.
1804
+ *
1805
+ * Previously, the HMAC key embedded the project ID, but this exposed the secret
1806
+ * in JWT tokens. Project IDs are now Convex document IDs visible in the portal.
1807
+ *
1808
+ * @param _hmacKey - Ignored (previously used to extract project ID)
1809
+ * @throws Always throws an error directing users to get project ID from portal
1810
+ */
1811
+ declare function extractProjectId(_hmacKey: string): never;
1812
+ /**
1813
+ * Create a simple budget configuration
1814
+ *
1815
+ * @param options - Budget options
1816
+ * @returns Budget configuration
1817
+ *
1818
+ * @example
1819
+ * ```typescript
1820
+ * const budget = createBudget({
1821
+ * aiDollars: 1.00, // $1 AI budget
1822
+ * computeHours: 1, // 1 hour compute
1823
+ * window: 'day',
1824
+ * });
1825
+ * ```
1826
+ */
1827
+ declare function createBudget(options: {
1828
+ /** AI budget in dollars */
1829
+ aiDollars: number;
1830
+ /** Compute budget in hours */
1831
+ computeHours: number;
1832
+ /** Budget window */
1833
+ window: 'hour' | 'day' | 'week' | 'month';
1834
+ /** Window start (default: now) */
1835
+ windowStart?: Date;
1836
+ }): TokenBudget;
1837
+
1838
+ /**
1839
+ * Error Classes
1840
+ *
1841
+ * Custom error types for the Chucky SDK.
1842
+ */
1843
+ /**
1844
+ * Base error class for Chucky SDK errors
1845
+ */
1846
+ declare class ChuckyError extends Error {
1847
+ /** Error code */
1848
+ readonly code: string;
1849
+ /** Additional error details */
1850
+ readonly details?: Record<string, unknown>;
1851
+ constructor(message: string, code: string, details?: Record<string, unknown>);
1852
+ }
1853
+ /**
1854
+ * Connection error
1855
+ */
1856
+ declare class ConnectionError extends ChuckyError {
1857
+ constructor(message: string, details?: Record<string, unknown>);
1858
+ }
1859
+ /**
1860
+ * Authentication error
1861
+ */
1862
+ declare class AuthenticationError extends ChuckyError {
1863
+ constructor(message: string, details?: Record<string, unknown>);
1864
+ }
1865
+ /**
1866
+ * Budget exceeded error
1867
+ */
1868
+ declare class BudgetExceededError extends ChuckyError {
1869
+ constructor(message: string, details?: Record<string, unknown>);
1870
+ }
1871
+ /**
1872
+ * Concurrency limit error
1873
+ */
1874
+ declare class ConcurrencyLimitError extends ChuckyError {
1875
+ constructor(message: string, details?: Record<string, unknown>);
1876
+ }
1877
+ /**
1878
+ * Rate limit error
1879
+ */
1880
+ declare class RateLimitError extends ChuckyError {
1881
+ constructor(message: string, details?: Record<string, unknown>);
1882
+ }
1883
+ /**
1884
+ * Session error
1885
+ */
1886
+ declare class SessionError extends ChuckyError {
1887
+ constructor(message: string, details?: Record<string, unknown>);
1888
+ }
1889
+ /**
1890
+ * Tool execution error
1891
+ */
1892
+ declare class ToolExecutionError extends ChuckyError {
1893
+ /** Tool name */
1894
+ readonly toolName: string;
1895
+ constructor(message: string, toolName: string, details?: Record<string, unknown>);
1896
+ }
1897
+ /**
1898
+ * Timeout error
1899
+ */
1900
+ declare class TimeoutError extends ChuckyError {
1901
+ constructor(message: string, details?: Record<string, unknown>);
1902
+ }
1903
+ /**
1904
+ * Validation error
1905
+ */
1906
+ declare class ValidationError extends ChuckyError {
1907
+ constructor(message: string, details?: Record<string, unknown>);
1908
+ }
1909
+ /**
1910
+ * Create appropriate error from message and optional code
1911
+ */
1912
+ declare function createError(message: string, code?: string): ChuckyError;
1913
+
1914
+ /**
1915
+ * WebSocket Transport
1916
+ *
1917
+ * WebSocket-based transport that works in both browser and Node.js.
1918
+ * Handles connection management, keep-alive, and reconnection.
1919
+ */
1920
+
1921
+ /**
1922
+ * WebSocket transport configuration
1923
+ */
1924
+ interface WebSocketTransportConfig extends TransportConfig {
1925
+ /** Protocol to use (default: determined from URL) */
1926
+ protocol?: 'ws' | 'wss';
1927
+ }
1928
+ /**
1929
+ * WebSocket transport implementation
1930
+ */
1931
+ declare class WebSocketTransport extends BaseTransport {
1932
+ private ws;
1933
+ private keepAliveTimer;
1934
+ private reconnectAttempts;
1935
+ private reconnectTimer;
1936
+ private readyPromise;
1937
+ private readyResolve;
1938
+ private readyReject;
1939
+ private messageQueue;
1940
+ constructor(config: WebSocketTransportConfig);
1941
+ /**
1942
+ * Build the WebSocket URL with token
1943
+ */
1944
+ private buildUrl;
1945
+ /**
1946
+ * Connect to the WebSocket server
1947
+ */
1948
+ connect(): Promise<void>;
1949
+ /**
1950
+ * Disconnect from the server
1951
+ */
1952
+ disconnect(): Promise<void>;
1953
+ /**
1954
+ * Send a message to the server
1955
+ */
1956
+ send(message: OutgoingMessage): Promise<void>;
1957
+ /**
1958
+ * Send a message immediately
1959
+ */
1960
+ private sendImmediate;
1961
+ /**
1962
+ * Wait for the connection to be ready
1963
+ */
1964
+ waitForReady(): Promise<void>;
1965
+ /**
1966
+ * Handle incoming message
1967
+ */
1968
+ private handleMessage;
1969
+ /**
1970
+ * Start keep-alive ping
1971
+ */
1972
+ private startKeepAlive;
1973
+ /**
1974
+ * Stop keep-alive ping
1975
+ */
1976
+ private stopKeepAlive;
1977
+ /**
1978
+ * Schedule a reconnection attempt
1979
+ */
1980
+ private scheduleReconnect;
1981
+ /**
1982
+ * Clear reconnect timer
1983
+ */
1984
+ private clearReconnectTimer;
1985
+ /**
1986
+ * Flush queued messages
1987
+ */
1988
+ private flushMessageQueue;
1989
+ }
1990
+
1991
+ export { type APIAssistantMessage, type APIUserMessage, type AgentDefinition, AuthenticationError, type BaseOptions, BudgetExceededError, type BudgetTokenPayload, type BudgetWindow, ChuckyClient, ChuckyError, type ClientEventHandlers, type ClientOptions, ConcurrencyLimitError, ConnectionError, type ConnectionStatus, type ContentBlock$1 as ContentBlock, type ContentBlockType, type ControlAction, type ControlPayload, type CostBreakdown, type CreateTokenOptions, type CreateToolOptions, type DecodedToken, type ErrorPayload, type ImageBlock, type ImageContent, type IncomingMessage, type InitPayload, type JsonSchemaProperty, type JsonSchemaType, McpServerBuilder, type McpServerDefinition, type Message, type MessageRole, type Model, type OutgoingMessage, type OutputFormat, type PartialMessage, type PromptOptions, type PromptResult, RateLimitError, type ResourceContent, type ResultSubtype, type SDKAssistantMessage, type ImageContent as SDKImageContent, type SDKMessage, type SDKPartialAssistantMessage, type SDKResultMessage, type SDKResultMessageError, type SDKResultMessageSuccess, type SDKSystemMessage, type SDKSystemMessageCompact, type SDKSystemMessageInit, type TextContent as SDKTextContent, type SDKUserMessage, Session, SessionError, type SessionEventHandlers, type SessionInfo, type SessionOptions, type SessionResult, type SessionState, type StreamEvent, type SystemPrompt, type SystemSubtype, type TextBlock, type TextContent, type ThinkingBlock, TimeoutError, type TokenBudget, type TokenPermissions, type TokenSdkConfig, type ToolCall, type ToolCallResponse, type ToolContent, type ToolContentType, type ToolDefinition, ToolExecutionError, type ToolExecutionLocation, type ToolHandler, type ToolImageContent, type ToolInputSchema, type ToolResult, type ToolResultBlock, type ToolResultContent, type ToolTextContent, type ToolUseBlock, type ToolUseContent, type Transport, type TransportConfig, type TransportEvents, type UUID, type Usage, ValidationError, WebSocketTransport, type WsEnvelopeType, browserTool, createBudget, createClient, createControlMessage, createError, createInitMessage, createMcpServer, createPingMessage, createToken, createTool, createToolResultMessage, createUserMessage, decodeToken, errorResult, extractProjectId, getAssistantText, getResultText, imageResult, isAssistantMessage, isControlMessage, isErrorMessage, isErrorResult, isResultMessage, isStreamEvent, isSuccessResult, isSystemMessage, isTokenExpired, isToolCallMessage, isUserMessage, mcpServer, serverTool, textResult, tool, verifyToken };