@yourgpt/copilot-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,870 @@
1
+ import { S as ScreenshotOptions, a as ScreenshotResult, C as ConsoleLogOptions, b as ConsoleLogResult, c as ConsoleLogEntry, N as NetworkRequestOptions, d as NetworkRequestResult, e as NetworkRequestEntry, T as ToolDefinition, f as Source, g as ToolExecutionStatus, h as ToolResponse, J as JSONSchemaProperty, i as ToolInputSchema, j as ToolLocation, k as ToolContext, M as MessageAttachment } from '../thread-C2FjuGLb.js';
2
+ export { ae as AIContent, a3 as AIProvider, ad as AIResponseMode, O as ActionDefinition, K as ActionParameter, Q as ActionRenderProps, ab as AgentLoopConfig, ac as AgentLoopState, v as CapturedContext, E as CloudConfig, q as ConsoleLogType, G as CopilotConfig, w as CustomKeywords, au as DEFAULT_MODELS, F as Extension, H as HttpMethod, I as IntentDetectionResult, Y as InternalKnowledgeBaseConfig, Z as InternalKnowledgeBaseResult, _ as InternalKnowledgeBaseSearchResponse, U as KnowledgeBaseConfig, R as KnowledgeBaseProvider, V as KnowledgeBaseResult, W as KnowledgeBaseSearchRequest, X as KnowledgeBaseSearchResponse, D as LLMConfig, L as LLMProvider, y as Message, z as MessageMetadata, x as MessageRole, P as ParameterType, af as PermissionLevel, ai as PermissionStorageAdapter, ah as PermissionStorageConfig, a1 as PersistenceConfig, $ as Thread, a0 as ThreadData, a2 as ThreadStorageAdapter, B as TokenUsage, a9 as ToolApprovalStatus, A as ToolCall, a5 as ToolConfig, t as ToolConsentRequest, u as ToolConsentResponse, aa as ToolExecution, ag as ToolPermission, a4 as ToolRenderProps, a6 as ToolSet, r as ToolType, s as ToolsConfig, a7 as UnifiedToolCall, a8 as UnifiedToolResult, as as actionToTool, am as createAssistantMessage, p as createCustomDetector, ak as createMessage, ao as createToolCall, an as createToolMessage, ay as createToolResult, al as createUserMessage, l as detectIntent, aA as failure, o as generateSuggestionReason, aj as generateThreadTitle, at as getDefaultModel, n as getPrimaryTool, aq as hasToolCalls, m as hasToolSuggestions, ar as isToolResult, ap as parseToolCallArgs, az as success, av as tool, ax as toolToAnthropicFormat, aw as toolToOpenAIFormat } from '../thread-C2FjuGLb.js';
3
+
4
+ /**
5
+ * Screenshot Capture Tool
6
+ *
7
+ * Captures screenshots of the current viewport or specific elements.
8
+ * Uses html2canvas for reliable DOM-to-canvas conversion.
9
+ */
10
+
11
+ /**
12
+ * Capture a screenshot of an element or the viewport
13
+ *
14
+ * Uses html2canvas for reliable DOM-to-canvas conversion.
15
+ * Handles complex CSS, images, flexbox, grid, etc.
16
+ *
17
+ * @param options - Screenshot options
18
+ * @returns Promise resolving to screenshot result
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Capture viewport
23
+ * const screenshot = await captureScreenshot();
24
+ *
25
+ * // Capture specific element
26
+ * const screenshot = await captureScreenshot({
27
+ * element: document.getElementById('my-element'),
28
+ * format: 'jpeg',
29
+ * quality: 0.9,
30
+ * });
31
+ * ```
32
+ */
33
+ declare function captureScreenshot(options?: ScreenshotOptions): Promise<ScreenshotResult>;
34
+ /**
35
+ * Check if screenshot capture is supported
36
+ */
37
+ declare function isScreenshotSupported(): boolean;
38
+ /**
39
+ * Resize a screenshot result
40
+ */
41
+ declare function resizeScreenshot(screenshot: ScreenshotResult, maxWidth: number, maxHeight: number): Promise<ScreenshotResult>;
42
+
43
+ /**
44
+ * Console Log Capture Tool
45
+ *
46
+ * Intercepts console methods to capture logs for AI analysis.
47
+ * Framework-agnostic implementation.
48
+ */
49
+
50
+ /**
51
+ * Start capturing console logs
52
+ *
53
+ * @param options - Capture options
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Start capturing all logs
58
+ * startConsoleCapture();
59
+ *
60
+ * // Capture only errors and warnings
61
+ * startConsoleCapture({ types: ['error', 'warn'] });
62
+ *
63
+ * // Custom filter
64
+ * startConsoleCapture({
65
+ * filter: (entry) => !entry.message.includes('[HMR]')
66
+ * });
67
+ * ```
68
+ */
69
+ declare function startConsoleCapture(options?: ConsoleLogOptions): void;
70
+ /**
71
+ * Stop capturing console logs
72
+ */
73
+ declare function stopConsoleCapture(): void;
74
+ /**
75
+ * Get captured console logs
76
+ *
77
+ * @param options - Filter options
78
+ * @returns Captured log entries
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Get all captured logs
83
+ * const { logs } = getConsoleLogs();
84
+ *
85
+ * // Get only errors from last minute
86
+ * const { logs } = getConsoleLogs({
87
+ * types: ['error'],
88
+ * filter: (entry) => entry.timestamp > Date.now() - 60000
89
+ * });
90
+ * ```
91
+ */
92
+ declare function getConsoleLogs(options?: ConsoleLogOptions): ConsoleLogResult;
93
+ /**
94
+ * Clear captured console logs
95
+ */
96
+ declare function clearConsoleLogs(): void;
97
+ /**
98
+ * Check if console capture is active
99
+ */
100
+ declare function isConsoleCaptureActive(): boolean;
101
+ /**
102
+ * Get console errors only (convenience function)
103
+ */
104
+ declare function getConsoleErrors(limit?: number): ConsoleLogEntry[];
105
+ /**
106
+ * Get console warnings only (convenience function)
107
+ */
108
+ declare function getConsoleWarnings(limit?: number): ConsoleLogEntry[];
109
+ /**
110
+ * Format console logs for AI context
111
+ *
112
+ * @param logs - Log entries to format
113
+ * @returns Formatted string for AI consumption
114
+ */
115
+ declare function formatLogsForAI(logs: ConsoleLogEntry[]): string;
116
+ /**
117
+ * Create a one-time capture of current logs
118
+ * Useful for getting logs without starting persistent capture
119
+ */
120
+ declare function captureCurrentLogs(options?: ConsoleLogOptions): ConsoleLogResult;
121
+
122
+ /**
123
+ * Network Request Capture Tool
124
+ *
125
+ * Intercepts fetch and XHR requests to capture network activity.
126
+ * Framework-agnostic implementation.
127
+ */
128
+
129
+ /**
130
+ * Start capturing network requests
131
+ *
132
+ * @param options - Capture options
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * // Start capturing failed requests only (default)
137
+ * startNetworkCapture();
138
+ *
139
+ * // Capture all requests
140
+ * startNetworkCapture({ failedOnly: false });
141
+ *
142
+ * // Capture only specific API
143
+ * startNetworkCapture({
144
+ * includeUrls: [/api\.example\.com/],
145
+ * failedOnly: false
146
+ * });
147
+ * ```
148
+ */
149
+ declare function startNetworkCapture(options?: NetworkRequestOptions): void;
150
+ /**
151
+ * Stop capturing network requests
152
+ */
153
+ declare function stopNetworkCapture(): void;
154
+ /**
155
+ * Get captured network requests
156
+ *
157
+ * @param options - Filter options
158
+ * @returns Captured requests
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * // Get all captured requests
163
+ * const { requests } = getNetworkRequests();
164
+ *
165
+ * // Get only failed POST requests
166
+ * const { requests } = getNetworkRequests({
167
+ * methods: ['POST'],
168
+ * failedOnly: true
169
+ * });
170
+ * ```
171
+ */
172
+ declare function getNetworkRequests(options?: NetworkRequestOptions): NetworkRequestResult;
173
+ /**
174
+ * Clear captured network requests
175
+ */
176
+ declare function clearNetworkRequests(): void;
177
+ /**
178
+ * Check if network capture is active
179
+ */
180
+ declare function isNetworkCaptureActive(): boolean;
181
+ /**
182
+ * Get failed requests only (convenience function)
183
+ */
184
+ declare function getFailedRequests(limit?: number): NetworkRequestEntry[];
185
+ /**
186
+ * Format network requests for AI context
187
+ *
188
+ * @param requests - Request entries to format
189
+ * @returns Formatted string for AI consumption
190
+ */
191
+ declare function formatRequestsForAI(requests: NetworkRequestEntry[]): string;
192
+
193
+ /**
194
+ * Built-in Screenshot Tool
195
+ *
196
+ * A pre-configured tool that captures screenshots of the user's viewport.
197
+ * Can be used with useTools() hook in React.
198
+ */
199
+ /**
200
+ * Screenshot tool - captures the user's screen
201
+ *
202
+ * @example
203
+ * ```tsx
204
+ * import { screenshotTool } from '@yourgpt/copilot-sdk-core';
205
+ *
206
+ * // In your component
207
+ * useTools({
208
+ * capture_screenshot: screenshotTool,
209
+ * });
210
+ * ```
211
+ */
212
+ declare const screenshotTool: Omit<ToolDefinition<{
213
+ quality?: number;
214
+ }>, "name">;
215
+ /**
216
+ * Create a custom screenshot tool with different options
217
+ */
218
+ declare function createScreenshotTool(options?: {
219
+ needsApproval?: boolean;
220
+ approvalMessage?: string;
221
+ defaultQuality?: number;
222
+ }): Omit<ToolDefinition<{
223
+ quality?: number;
224
+ }>, "name">;
225
+
226
+ /**
227
+ * Built-in Console Logs Tool
228
+ *
229
+ * A pre-configured tool that retrieves browser console logs.
230
+ * Can be used with useTools() hook in React.
231
+ */
232
+ /**
233
+ * Console logs tool - retrieves browser console output
234
+ *
235
+ * @example
236
+ * ```tsx
237
+ * import { consoleLogsTool } from '@yourgpt/copilot-sdk-core';
238
+ *
239
+ * // In your component
240
+ * useTools({
241
+ * get_console_logs: consoleLogsTool,
242
+ * });
243
+ * ```
244
+ */
245
+ declare const consoleLogsTool: Omit<ToolDefinition<{
246
+ limit?: number;
247
+ types?: string[];
248
+ }>, "name">;
249
+ /**
250
+ * Create a custom console logs tool with different options
251
+ */
252
+ declare function createConsoleLogsTool(options?: {
253
+ needsApproval?: boolean;
254
+ approvalMessage?: string;
255
+ defaultLimit?: number;
256
+ }): Omit<ToolDefinition<{
257
+ limit?: number;
258
+ types?: string[];
259
+ }>, "name">;
260
+
261
+ /**
262
+ * Built-in Network Requests Tool
263
+ *
264
+ * A pre-configured tool that retrieves browser network requests.
265
+ * Can be used with useTools() hook in React.
266
+ */
267
+ /**
268
+ * Network requests tool - retrieves browser network activity
269
+ *
270
+ * @example
271
+ * ```tsx
272
+ * import { networkRequestsTool } from '@yourgpt/copilot-sdk-core';
273
+ *
274
+ * // In your component
275
+ * useTools({
276
+ * get_network_requests: networkRequestsTool,
277
+ * });
278
+ * ```
279
+ */
280
+ declare const networkRequestsTool: Omit<ToolDefinition<{
281
+ limit?: number;
282
+ failedOnly?: boolean;
283
+ }>, "name">;
284
+ /**
285
+ * Create a custom network requests tool with different options
286
+ */
287
+ declare function createNetworkRequestsTool(options?: {
288
+ needsApproval?: boolean;
289
+ approvalMessage?: string;
290
+ defaultLimit?: number;
291
+ }): Omit<ToolDefinition<{
292
+ limit?: number;
293
+ failedOnly?: boolean;
294
+ }>, "name">;
295
+
296
+ /**
297
+ * Built-in Tools
298
+ *
299
+ * Pre-configured tools for common client-side operations.
300
+ * These can be registered using the useTools() hook.
301
+ *
302
+ * @example
303
+ * ```tsx
304
+ * import { builtinTools } from '@yourgpt/copilot-sdk-core';
305
+ *
306
+ * // Register all built-in tools
307
+ * useTools(builtinTools);
308
+ *
309
+ * // Or register specific tools
310
+ * useTools({
311
+ * capture_screenshot: builtinTools.capture_screenshot,
312
+ * });
313
+ * ```
314
+ */
315
+
316
+ /**
317
+ * All built-in tools as a ToolSet
318
+ *
319
+ * @example
320
+ * ```tsx
321
+ * import { builtinTools } from '@yourgpt/copilot-sdk-core';
322
+ *
323
+ * // Use with useTools hook
324
+ * useTools(builtinTools);
325
+ *
326
+ * // Or spread with custom tools
327
+ * useTools({
328
+ * ...builtinTools,
329
+ * my_custom_tool: myTool,
330
+ * });
331
+ * ```
332
+ */
333
+ declare const builtinTools: Record<string, ToolDefinition>;
334
+
335
+ /**
336
+ * Stream event types
337
+ */
338
+ type StreamEventType = "message:start" | "message:delta" | "message:end" | "thinking:start" | "thinking:delta" | "thinking:end" | "source:add" | "action:start" | "action:args" | "action:end" | "tool_calls" | "tool:status" | "tool:result" | "loop:iteration" | "loop:complete" | "error" | "done";
339
+ /**
340
+ * Base event interface
341
+ */
342
+ interface BaseEvent {
343
+ type: StreamEventType;
344
+ }
345
+ /**
346
+ * Message started streaming
347
+ */
348
+ interface MessageStartEvent extends BaseEvent {
349
+ type: "message:start";
350
+ /** Message ID */
351
+ id: string;
352
+ }
353
+ /**
354
+ * Message content delta (incremental update)
355
+ */
356
+ interface MessageDeltaEvent extends BaseEvent {
357
+ type: "message:delta";
358
+ /** Content chunk */
359
+ content: string;
360
+ }
361
+ /**
362
+ * Message finished streaming
363
+ */
364
+ interface MessageEndEvent extends BaseEvent {
365
+ type: "message:end";
366
+ }
367
+ /**
368
+ * Thinking/reasoning started (for models like Claude, DeepSeek)
369
+ */
370
+ interface ThinkingStartEvent extends BaseEvent {
371
+ type: "thinking:start";
372
+ }
373
+ /**
374
+ * Thinking content delta (incremental update)
375
+ */
376
+ interface ThinkingDeltaEvent extends BaseEvent {
377
+ type: "thinking:delta";
378
+ /** Thinking content chunk */
379
+ content: string;
380
+ }
381
+ /**
382
+ * Thinking finished
383
+ */
384
+ interface ThinkingEndEvent extends BaseEvent {
385
+ type: "thinking:end";
386
+ }
387
+ /**
388
+ * Knowledge base source added
389
+ */
390
+ interface SourceAddEvent extends BaseEvent {
391
+ type: "source:add";
392
+ /** Source document */
393
+ source: Source;
394
+ }
395
+ /**
396
+ * Action/tool execution started
397
+ */
398
+ interface ActionStartEvent extends BaseEvent {
399
+ type: "action:start";
400
+ /** Tool call ID */
401
+ id: string;
402
+ /** Action name */
403
+ name: string;
404
+ }
405
+ /**
406
+ * Action arguments (streaming)
407
+ */
408
+ interface ActionArgsEvent extends BaseEvent {
409
+ type: "action:args";
410
+ /** Tool call ID */
411
+ id: string;
412
+ /** Partial arguments JSON */
413
+ args: string;
414
+ }
415
+ /**
416
+ * Action execution completed
417
+ */
418
+ interface ActionEndEvent extends BaseEvent {
419
+ type: "action:end";
420
+ /** Tool call ID */
421
+ id: string;
422
+ /** Action name */
423
+ name?: string;
424
+ /** Result of the action */
425
+ result?: unknown;
426
+ /** Error if failed */
427
+ error?: string;
428
+ }
429
+ /**
430
+ * Error event
431
+ */
432
+ interface ErrorEvent extends BaseEvent {
433
+ type: "error";
434
+ /** Error message */
435
+ message: string;
436
+ /** Error code */
437
+ code?: string;
438
+ }
439
+ /**
440
+ * Message format for done event (API format with snake_case)
441
+ */
442
+ interface DoneEventMessage {
443
+ role: "assistant" | "tool";
444
+ content: string | null;
445
+ tool_calls?: Array<{
446
+ id: string;
447
+ type: "function";
448
+ function: {
449
+ name: string;
450
+ arguments: string;
451
+ };
452
+ }>;
453
+ tool_call_id?: string;
454
+ }
455
+ /**
456
+ * Stream completed
457
+ */
458
+ interface DoneEvent extends BaseEvent {
459
+ type: "done";
460
+ /**
461
+ * True when client needs to execute tools and send results in next request
462
+ * (Vercel AI SDK pattern)
463
+ */
464
+ requiresAction?: boolean;
465
+ /**
466
+ * All new messages created during this request (for client to append to state)
467
+ * This includes: assistant messages with tool_calls, tool result messages, final response
468
+ */
469
+ messages?: DoneEventMessage[];
470
+ }
471
+ /**
472
+ * Tool call information for client execution
473
+ */
474
+ interface ToolCallInfo {
475
+ /** Unique tool call ID */
476
+ id: string;
477
+ /** Tool name */
478
+ name: string;
479
+ /** Tool arguments (parsed JSON) */
480
+ args: Record<string, unknown>;
481
+ }
482
+ /**
483
+ * Assistant message with tool calls (for including in next request)
484
+ */
485
+ interface AssistantToolMessage {
486
+ role: "assistant";
487
+ content: string | null;
488
+ tool_calls: Array<{
489
+ id: string;
490
+ type: "function";
491
+ function: {
492
+ name: string;
493
+ arguments: string;
494
+ };
495
+ }>;
496
+ }
497
+ /**
498
+ * Server detected tool calls - client should execute and send results in next request
499
+ * (Vercel AI SDK pattern - replaces tool:execute)
500
+ */
501
+ interface ToolCallsEvent extends BaseEvent {
502
+ type: "tool_calls";
503
+ /** Tool calls to execute */
504
+ toolCalls: ToolCallInfo[];
505
+ /**
506
+ * Assistant message to include in next request's messages
507
+ * This preserves the tool_calls structure for the LLM
508
+ */
509
+ assistantMessage: AssistantToolMessage;
510
+ }
511
+ /**
512
+ * Tool execution status update
513
+ */
514
+ interface ToolStatusEvent extends BaseEvent {
515
+ type: "tool:status";
516
+ /** Tool call ID */
517
+ id: string;
518
+ /** Execution status */
519
+ status: ToolExecutionStatus;
520
+ }
521
+ /**
522
+ * Tool result received (from client or server)
523
+ */
524
+ interface ToolResultEvent extends BaseEvent {
525
+ type: "tool:result";
526
+ /** Tool call ID */
527
+ id: string;
528
+ /** Tool name */
529
+ name: string;
530
+ /** Tool result */
531
+ result: ToolResponse;
532
+ }
533
+ /**
534
+ * Loop iteration progress
535
+ */
536
+ interface LoopIterationEvent extends BaseEvent {
537
+ type: "loop:iteration";
538
+ /** Current iteration number (1-based) */
539
+ iteration: number;
540
+ /** Maximum iterations allowed */
541
+ maxIterations: number;
542
+ }
543
+ /**
544
+ * Loop completed
545
+ */
546
+ interface LoopCompleteEvent extends BaseEvent {
547
+ type: "loop:complete";
548
+ /** Total iterations executed */
549
+ iterations: number;
550
+ /** Whether loop was aborted by user */
551
+ aborted?: boolean;
552
+ /** Whether max iterations was reached */
553
+ maxIterationsReached?: boolean;
554
+ }
555
+ /**
556
+ * Union of all stream events
557
+ */
558
+ type StreamEvent = MessageStartEvent | MessageDeltaEvent | MessageEndEvent | ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent | SourceAddEvent | ActionStartEvent | ActionArgsEvent | ActionEndEvent | ToolCallsEvent | ToolStatusEvent | ToolResultEvent | LoopIterationEvent | LoopCompleteEvent | ErrorEvent | DoneEvent;
559
+ /**
560
+ * Parse a stream event from JSON
561
+ */
562
+ declare function parseStreamEvent(data: string): StreamEvent | null;
563
+ /**
564
+ * Serialize a stream event to JSON
565
+ */
566
+ declare function serializeStreamEvent(event: StreamEvent): string;
567
+ /**
568
+ * Format event for SSE
569
+ */
570
+ declare function formatSSE(event: StreamEvent): string;
571
+
572
+ /**
573
+ * Parse SSE stream data
574
+ */
575
+ declare function parseSSELine(line: string): StreamEvent | null;
576
+ /**
577
+ * Create an async iterator from SSE response
578
+ */
579
+ declare function streamSSE(response: Response): AsyncGenerator<StreamEvent, void, undefined>;
580
+ /**
581
+ * Create SSE response from async generator
582
+ */
583
+ declare function createSSEStream(generator: AsyncGenerator<StreamEvent, void, undefined>): ReadableStream<Uint8Array>;
584
+
585
+ /**
586
+ * Generate a unique ID with optional prefix
587
+ */
588
+ declare function generateId(prefix?: string): string;
589
+ /**
590
+ * Generate a message ID
591
+ */
592
+ declare function generateMessageId(): string;
593
+ /**
594
+ * Generate a conversation/thread ID
595
+ */
596
+ declare function generateThreadId(): string;
597
+ /**
598
+ * Generate a tool call ID
599
+ */
600
+ declare function generateToolCallId(): string;
601
+
602
+ /**
603
+ * Zod to JSON Schema conversion utilities
604
+ *
605
+ * Provides helpers to convert Zod schemas to JSON Schema format
606
+ * for use with LLM tool definitions.
607
+ */
608
+
609
+ /**
610
+ * Convert a Zod schema to JSON Schema property
611
+ */
612
+ declare function zodToJsonSchema(schema: unknown): JSONSchemaProperty;
613
+ /**
614
+ * Convert a Zod object schema to ToolInputSchema
615
+ *
616
+ * Note: For Zod 4.x+, the react package uses z.toJSONSchema() directly.
617
+ * This fallback implementation is for older Zod versions.
618
+ */
619
+ declare function zodObjectToInputSchema(schema: unknown): ToolInputSchema;
620
+ /**
621
+ * Configuration for defining a tool with Zod schema
622
+ */
623
+ interface DefineToolConfig<TSchema extends {
624
+ _output: Record<string, unknown>;
625
+ }> {
626
+ /** Unique tool name */
627
+ name: string;
628
+ /** Tool description for LLM */
629
+ description: string;
630
+ /** Where the tool executes */
631
+ location: ToolLocation;
632
+ /** Zod schema for parameters */
633
+ schema: TSchema;
634
+ /** Handler function */
635
+ handler?: (params: TSchema["_output"], context?: ToolContext) => Promise<ToolResponse> | ToolResponse;
636
+ /** Optional render function */
637
+ render?: (props: {
638
+ status: "pending" | "executing" | "completed" | "error";
639
+ args: TSchema["_output"];
640
+ result?: ToolResponse;
641
+ error?: string;
642
+ }) => unknown;
643
+ /** Whether the tool is available */
644
+ available?: boolean;
645
+ /**
646
+ * Human-readable title for UI display.
647
+ * Can be a static string or a function that generates title from args.
648
+ */
649
+ title?: string | ((args: TSchema["_output"]) => string);
650
+ /**
651
+ * Title shown while executing (present tense with "...").
652
+ */
653
+ executingTitle?: string | ((args: TSchema["_output"]) => string);
654
+ /**
655
+ * Title shown after completion.
656
+ */
657
+ completedTitle?: string | ((args: TSchema["_output"]) => string);
658
+ /**
659
+ * How the AI should respond when this tool's result is rendered as UI.
660
+ * - 'none': AI generates minimal response
661
+ * - 'brief': AI receives summary context, gives brief acknowledgment
662
+ * - 'full': AI receives complete data (default)
663
+ */
664
+ aiResponseMode?: "none" | "brief" | "full";
665
+ /**
666
+ * Context/summary sent to AI instead of (or along with) full result.
667
+ */
668
+ aiContext?: string | ((result: ToolResponse, args: Record<string, unknown>) => string);
669
+ /**
670
+ * Require user approval before execution.
671
+ * - true: Always require approval
672
+ * - false: No approval needed (default)
673
+ * - function: Conditional approval based on input
674
+ */
675
+ needsApproval?: boolean | ((params: TSchema["_output"]) => boolean | Promise<boolean>);
676
+ /**
677
+ * Custom message shown in the approval UI.
678
+ */
679
+ approvalMessage?: string | ((params: TSchema["_output"]) => string);
680
+ }
681
+ /**
682
+ * Define a tool using a Zod schema
683
+ *
684
+ * @example
685
+ * ```ts
686
+ * import { z } from "zod";
687
+ * import { defineTool } from "@yourgpt/copilot-sdk-core";
688
+ *
689
+ * const navigateTool = defineTool({
690
+ * name: "navigate",
691
+ * description: "Navigate to a page",
692
+ * location: "client",
693
+ * schema: z.object({
694
+ * path: z.string().describe("The path to navigate to"),
695
+ * }),
696
+ * handler: async ({ path }) => {
697
+ * router.push(path);
698
+ * return { success: true, message: `Navigated to ${path}` };
699
+ * },
700
+ * });
701
+ * ```
702
+ */
703
+ declare function defineTool<TSchema extends {
704
+ _output: Record<string, unknown>;
705
+ }>(config: DefineToolConfig<TSchema>): ToolDefinition<TSchema["_output"]>;
706
+ /**
707
+ * Define a client-side tool using a Zod schema
708
+ *
709
+ * Shorthand for defineTool with location: "client".
710
+ * Client tools run in the browser and can interact with UI.
711
+ *
712
+ * @example
713
+ * ```ts
714
+ * const navigateTool = defineClientTool({
715
+ * name: "navigate",
716
+ * description: "Navigate to a page",
717
+ * schema: z.object({ path: z.string() }),
718
+ * handler: async ({ path }) => {
719
+ * router.push(path);
720
+ * return { success: true };
721
+ * },
722
+ * });
723
+ * ```
724
+ */
725
+ declare function defineClientTool<TSchema extends {
726
+ _output: Record<string, unknown>;
727
+ }>(config: Omit<DefineToolConfig<TSchema>, "location">): ToolDefinition<TSchema["_output"]>;
728
+ /**
729
+ * Define a server-side (backend) tool using a Zod schema
730
+ *
731
+ * Server tools run on your backend with full access to:
732
+ * - Environment variables and secrets
733
+ * - Database connections
734
+ * - Internal microservices
735
+ * - External APIs with server-side authentication
736
+ *
737
+ * The handler receives a context object with request headers for auth.
738
+ *
739
+ * @example
740
+ * ```ts
741
+ * const getOrderTool = defineServerTool({
742
+ * name: "get_order",
743
+ * description: "Get order details by ID",
744
+ * schema: z.object({
745
+ * orderId: z.string().describe("Order ID"),
746
+ * }),
747
+ * handler: async ({ orderId }, context) => {
748
+ * // Access auth from context
749
+ * const token = context?.headers?.authorization;
750
+ * if (!token) return failure("Authentication required");
751
+ *
752
+ * const order = await orderService.get(orderId, token);
753
+ * return success(order);
754
+ * },
755
+ * });
756
+ * ```
757
+ *
758
+ * @example
759
+ * ```ts
760
+ * // With AI response control
761
+ * const sensitiveDataTool = defineServerTool({
762
+ * name: "get_sensitive_data",
763
+ * description: "Fetch sensitive records",
764
+ * schema: z.object({ id: z.string() }),
765
+ * aiResponseMode: "brief",
766
+ * aiContext: (result) => `Retrieved record - displayed to user`,
767
+ * handler: async ({ id }) => {
768
+ * const data = await db.sensitiveRecords.findUnique({ where: { id } });
769
+ * return success(data);
770
+ * },
771
+ * });
772
+ * ```
773
+ */
774
+ declare function defineServerTool<TSchema extends {
775
+ _output: Record<string, unknown>;
776
+ }>(config: Omit<DefineToolConfig<TSchema>, "location">): ToolDefinition<TSchema["_output"]>;
777
+
778
+ /**
779
+ * System Prompt Utilities
780
+ *
781
+ * Default system message generation for Copilot SDK.
782
+ */
783
+ /**
784
+ * Function type for generating system messages
785
+ */
786
+ type SystemMessageFunction = (contextString: string, additionalInstructions?: string) => string;
787
+ /**
788
+ * Default system message for Copilot SDK
789
+ *
790
+ * @param contextString - Context from useReadable hooks
791
+ * @param additionalInstructions - Additional instructions from user
792
+ */
793
+ declare function defaultSystemMessage(contextString: string, additionalInstructions?: string): string;
794
+
795
+ /**
796
+ * Cloud Storage Service
797
+ *
798
+ * Provides managed file storage for premium users.
799
+ * Files are uploaded to managed cloud via presigned URLs.
800
+ */
801
+
802
+ /**
803
+ * Upload result from storage service
804
+ */
805
+ interface UploadResult {
806
+ /** Public URL of the uploaded file */
807
+ url: string;
808
+ /** Expiration timestamp (if applicable) */
809
+ expiresAt?: number;
810
+ }
811
+ /**
812
+ * Upload options
813
+ */
814
+ interface UploadOptions {
815
+ /** Progress callback */
816
+ onProgress?: (progress: number) => void;
817
+ }
818
+ /**
819
+ * Storage service interface
820
+ */
821
+ interface StorageService {
822
+ /** Check if cloud storage is available */
823
+ isAvailable(): boolean;
824
+ /** Upload file and get URL */
825
+ upload(file: File, options?: UploadOptions): Promise<UploadResult>;
826
+ }
827
+ /**
828
+ * Storage configuration
829
+ */
830
+ interface StorageConfig {
831
+ /** Cloud API key (must start with "ygpt_" for premium) */
832
+ apiKey: string;
833
+ /** Custom API endpoint */
834
+ endpoint?: string;
835
+ /** Maximum file size in bytes (default: 25MB for premium) */
836
+ maxFileSize?: number;
837
+ }
838
+ /** Default max file size for cloud storage (25MB) */
839
+ declare const CLOUD_MAX_FILE_SIZE: number;
840
+ /** Default Cloud API endpoint */
841
+ declare const DEFAULT_YOURGPT_ENDPOINT = "https://api.yourgpt.ai";
842
+ /**
843
+ * Create managed cloud storage service
844
+ *
845
+ * @example
846
+ * ```ts
847
+ * const storage = createCloudStorage({
848
+ * apiKey: "ygpt_...",
849
+ * });
850
+ *
851
+ * if (storage.isAvailable()) {
852
+ * const { url } = await storage.upload(file);
853
+ * // url = "https://cdn.yourgpt.ai/..."
854
+ * }
855
+ * ```
856
+ */
857
+ declare function createCloudStorage(config: StorageConfig): StorageService;
858
+ /**
859
+ * Helper to get attachment type from MIME type
860
+ */
861
+ declare function getAttachmentTypeFromMime(mimeType: string): "image" | "file" | "audio" | "video";
862
+ /**
863
+ * Process file to MessageAttachment using storage service
864
+ *
865
+ * - If storage is available, uploads to cloud and returns URL-based attachment
866
+ * - Otherwise, converts to base64 (fallback for free tier)
867
+ */
868
+ declare function processFileToAttachment(file: File, storage?: StorageService | null): Promise<MessageAttachment>;
869
+
870
+ export { type ActionArgsEvent, type ActionEndEvent, type ActionStartEvent, type AssistantToolMessage, CLOUD_MAX_FILE_SIZE, ConsoleLogEntry, ConsoleLogOptions, ConsoleLogResult, DEFAULT_YOURGPT_ENDPOINT, type DefineToolConfig, type DoneEvent, type DoneEventMessage, type ErrorEvent, JSONSchemaProperty, type LoopCompleteEvent, type LoopIterationEvent, MessageAttachment, type MessageDeltaEvent, type MessageEndEvent, type MessageStartEvent, NetworkRequestEntry, NetworkRequestOptions, NetworkRequestResult, ScreenshotOptions, ScreenshotResult, Source, type SourceAddEvent, type StorageConfig, type StorageService, type StreamEvent, type StreamEventType, type SystemMessageFunction, type ToolCallInfo, type ToolCallsEvent, ToolContext, ToolDefinition, ToolExecutionStatus, ToolInputSchema, ToolLocation, ToolResponse, type ToolResultEvent, type ToolStatusEvent, type UploadOptions, type UploadResult, builtinTools, captureCurrentLogs, captureScreenshot, clearConsoleLogs, clearNetworkRequests, consoleLogsTool, createCloudStorage, createConsoleLogsTool, createNetworkRequestsTool, createSSEStream, createScreenshotTool, defaultSystemMessage, defineClientTool, defineServerTool, defineTool, formatLogsForAI, formatRequestsForAI, formatSSE, generateId, generateMessageId, generateThreadId, generateToolCallId, getAttachmentTypeFromMime, getConsoleErrors, getConsoleLogs, getConsoleWarnings, getFailedRequests, getNetworkRequests, isConsoleCaptureActive, isNetworkCaptureActive, isScreenshotSupported, networkRequestsTool, parseSSELine, parseStreamEvent, processFileToAttachment, resizeScreenshot, screenshotTool, serializeStreamEvent, startConsoleCapture, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, streamSSE, zodObjectToInputSchema, zodToJsonSchema };