@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.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 (62) hide show
  1. package/README.md +19 -1
  2. package/dist/adapters/index.d.mts +4 -4
  3. package/dist/adapters/index.d.ts +4 -4
  4. package/dist/adapters/index.js +293 -23
  5. package/dist/adapters/index.mjs +293 -23
  6. package/dist/base-BYQKp9TW.d.mts +263 -0
  7. package/dist/base-Cxq3ni0t.d.ts +263 -0
  8. package/dist/fallback/index.d.mts +4 -4
  9. package/dist/fallback/index.d.ts +4 -4
  10. package/dist/index.d.mts +61 -8
  11. package/dist/index.d.ts +61 -8
  12. package/dist/index.js +71 -0
  13. package/dist/index.mjs +71 -0
  14. package/dist/providers/anthropic/index.d.mts +3 -3
  15. package/dist/providers/anthropic/index.d.ts +3 -3
  16. package/dist/providers/anthropic/index.js +360 -203
  17. package/dist/providers/anthropic/index.mjs +360 -203
  18. package/dist/providers/azure/index.d.mts +3 -3
  19. package/dist/providers/azure/index.d.ts +3 -3
  20. package/dist/providers/azure/index.js +49 -1
  21. package/dist/providers/azure/index.mjs +49 -1
  22. package/dist/providers/fireworks/index.d.mts +1 -1
  23. package/dist/providers/fireworks/index.d.ts +1 -1
  24. package/dist/providers/fireworks/index.js +56 -0
  25. package/dist/providers/fireworks/index.mjs +56 -0
  26. package/dist/providers/google/index.d.mts +3 -3
  27. package/dist/providers/google/index.d.ts +3 -3
  28. package/dist/providers/google/index.js +303 -207
  29. package/dist/providers/google/index.mjs +303 -207
  30. package/dist/providers/ollama/index.d.mts +4 -4
  31. package/dist/providers/ollama/index.d.ts +4 -4
  32. package/dist/providers/ollama/index.js +10 -2
  33. package/dist/providers/ollama/index.mjs +10 -2
  34. package/dist/providers/openai/index.d.mts +3 -3
  35. package/dist/providers/openai/index.d.ts +3 -3
  36. package/dist/providers/openai/index.js +318 -216
  37. package/dist/providers/openai/index.mjs +318 -216
  38. package/dist/providers/openrouter/index.d.mts +3 -3
  39. package/dist/providers/openrouter/index.d.ts +3 -3
  40. package/dist/providers/openrouter/index.js +308 -206
  41. package/dist/providers/openrouter/index.mjs +308 -206
  42. package/dist/providers/togetherai/index.d.mts +3 -3
  43. package/dist/providers/togetherai/index.d.ts +3 -3
  44. package/dist/providers/togetherai/index.js +308 -206
  45. package/dist/providers/togetherai/index.mjs +308 -206
  46. package/dist/providers/xai/index.d.mts +3 -3
  47. package/dist/providers/xai/index.d.ts +3 -3
  48. package/dist/providers/xai/index.js +307 -210
  49. package/dist/providers/xai/index.mjs +307 -210
  50. package/dist/{types-BctsnC3g.d.ts → types-BvkiJ1dd.d.mts} +2 -1
  51. package/dist/{types-38yolWJn.d.ts → types-ChORafYS.d.ts} +1 -1
  52. package/dist/types-D774b0dg.d.mts +1018 -0
  53. package/dist/types-D774b0dg.d.ts +1018 -0
  54. package/dist/{types-DRqxMIjF.d.mts → types-TMilS-Dz.d.ts} +2 -1
  55. package/dist/{types-D4YfrQJR.d.mts → types-mwMhCwOq.d.mts} +1 -1
  56. package/dist/yourgpt/index.d.mts +1 -1
  57. package/dist/yourgpt/index.d.ts +1 -1
  58. package/package.json +1 -1
  59. package/dist/base-D-U61JaB.d.mts +0 -788
  60. package/dist/base-iGi9Va6Z.d.ts +0 -788
  61. package/dist/types-CR8mi9I0.d.mts +0 -417
  62. package/dist/types-CR8mi9I0.d.ts +0 -417
@@ -1,788 +0,0 @@
1
- import { t as TokenUsage } from './types-CR8mi9I0.mjs';
2
-
3
- /**
4
- * Stream event types for llm-sdk
5
- * These types are used internally by the SDK for streaming responses
6
- */
7
- /**
8
- * Stream event types
9
- */
10
- type StreamEventType = "message:start" | "message:delta" | "message:end" | "thinking:start" | "thinking:delta" | "thinking:end" | "action:start" | "action:args" | "action:end" | "tool_calls" | "tool:result" | "citation" | "loop:iteration" | "loop:complete" | "error" | "thread:created" | "done";
11
- /**
12
- * Base event interface
13
- */
14
- interface BaseEvent {
15
- type: StreamEventType;
16
- }
17
- /**
18
- * Message started streaming
19
- */
20
- interface MessageStartEvent extends BaseEvent {
21
- type: "message:start";
22
- id: string;
23
- }
24
- /**
25
- * Message content delta (incremental update)
26
- */
27
- interface MessageDeltaEvent extends BaseEvent {
28
- type: "message:delta";
29
- content: string;
30
- }
31
- /**
32
- * Message finished streaming
33
- */
34
- interface MessageEndEvent extends BaseEvent {
35
- type: "message:end";
36
- }
37
- /**
38
- * Thinking/reasoning started (for models like Claude, DeepSeek)
39
- */
40
- interface ThinkingStartEvent extends BaseEvent {
41
- type: "thinking:start";
42
- }
43
- /**
44
- * Thinking content delta
45
- */
46
- interface ThinkingDeltaEvent extends BaseEvent {
47
- type: "thinking:delta";
48
- content: string;
49
- }
50
- /**
51
- * Thinking finished
52
- */
53
- interface ThinkingEndEvent extends BaseEvent {
54
- type: "thinking:end";
55
- }
56
- /**
57
- * Action/tool execution started
58
- */
59
- interface ActionStartEvent extends BaseEvent {
60
- type: "action:start";
61
- id: string;
62
- name: string;
63
- /** Whether this tool should be hidden from UI */
64
- hidden?: boolean;
65
- /** Provider-specific metadata (e.g. Gemini 3 thought_signature) */
66
- extra_content?: Record<string, unknown>;
67
- }
68
- /**
69
- * Action arguments (streaming)
70
- */
71
- interface ActionArgsEvent extends BaseEvent {
72
- type: "action:args";
73
- id: string;
74
- args: string;
75
- }
76
- /**
77
- * Action execution completed
78
- */
79
- interface ActionEndEvent extends BaseEvent {
80
- type: "action:end";
81
- id: string;
82
- name?: string;
83
- result?: unknown;
84
- error?: string;
85
- }
86
- /**
87
- * Error event
88
- */
89
- interface ErrorEvent extends BaseEvent {
90
- type: "error";
91
- message: string;
92
- code?: string;
93
- }
94
- /**
95
- * Tool call information
96
- */
97
- interface ToolCallInfo {
98
- id: string;
99
- name: string;
100
- args: Record<string, unknown>;
101
- /** Whether this tool should be hidden from UI */
102
- hidden?: boolean;
103
- /** Provider-specific metadata (e.g. Gemini 3 thought_signature) */
104
- extra_content?: Record<string, unknown>;
105
- }
106
- /**
107
- * Assistant message with tool calls
108
- */
109
- interface AssistantToolMessage {
110
- role: "assistant";
111
- content: string | null;
112
- tool_calls: Array<{
113
- id: string;
114
- type: "function";
115
- function: {
116
- name: string;
117
- arguments: string;
118
- };
119
- /** Provider-specific metadata (e.g. Gemini 3 thought_signature) */
120
- extra_content?: Record<string, unknown>;
121
- }>;
122
- }
123
- /**
124
- * Tool calls event - client should execute and send results
125
- */
126
- interface ToolCallsEvent extends BaseEvent {
127
- type: "tool_calls";
128
- toolCalls: ToolCallInfo[];
129
- assistantMessage: AssistantToolMessage;
130
- }
131
- /**
132
- * Tool result event
133
- */
134
- interface ToolResultEvent extends BaseEvent {
135
- type: "tool:result";
136
- id: string;
137
- name: string;
138
- result: ToolResponse;
139
- }
140
- /**
141
- * Loop iteration event
142
- */
143
- interface LoopIterationEvent extends BaseEvent {
144
- type: "loop:iteration";
145
- iteration: number;
146
- maxIterations: number;
147
- }
148
- /**
149
- * Loop complete event
150
- */
151
- interface LoopCompleteEvent extends BaseEvent {
152
- type: "loop:complete";
153
- iterations: number;
154
- aborted?: boolean;
155
- maxIterationsReached?: boolean;
156
- }
157
- /**
158
- * Citation from web search (unified format for all providers)
159
- */
160
- interface Citation {
161
- /** Unique citation index (1-based) */
162
- index: number;
163
- /** Source URL */
164
- url: string;
165
- /** Page title */
166
- title: string;
167
- /** Cited text snippet (optional) */
168
- citedText?: string;
169
- /** Source domain (extracted from URL) */
170
- domain?: string;
171
- /** Favicon URL (generated from domain) */
172
- favicon?: string;
173
- }
174
- /**
175
- * Citation event - web search returned citations
176
- */
177
- interface CitationEvent extends BaseEvent {
178
- type: "citation";
179
- citations: Citation[];
180
- }
181
- /**
182
- * Message format for done event (API format with snake_case)
183
- */
184
- interface DoneEventMessage {
185
- role: "assistant" | "tool";
186
- content: string | null;
187
- tool_calls?: Array<{
188
- id: string;
189
- type: "function";
190
- function: {
191
- name: string;
192
- arguments: string;
193
- };
194
- /** Provider-specific metadata (e.g. Gemini 3 thought_signature) */
195
- extra_content?: Record<string, unknown>;
196
- }>;
197
- tool_call_id?: string;
198
- }
199
- /**
200
- * Token usage (snake_case for API compatibility)
201
- */
202
- interface TokenUsageRaw {
203
- prompt_tokens: number;
204
- completion_tokens: number;
205
- total_tokens?: number;
206
- }
207
- /**
208
- * Thread/session created — emitted early in the stream, before any message events,
209
- * so the client can adopt the threadId without waiting for the done chunk.
210
- */
211
- interface ThreadCreatedEvent extends BaseEvent {
212
- type: "thread:created";
213
- threadId: string;
214
- }
215
- /**
216
- * Stream completed
217
- */
218
- interface DoneEvent extends BaseEvent {
219
- type: "done";
220
- requiresAction?: boolean;
221
- messages?: DoneEventMessage[];
222
- /** Token usage (server-side only, stripped before sending to client) */
223
- usage?: TokenUsageRaw;
224
- /** Session ID — present when storage adapter created a session for this request */
225
- threadId?: string;
226
- }
227
- /**
228
- * Union of all stream events
229
- */
230
- type StreamEvent = MessageStartEvent | MessageDeltaEvent | MessageEndEvent | ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent | ActionStartEvent | ActionArgsEvent | ActionEndEvent | ToolCallsEvent | ToolResultEvent | CitationEvent | LoopIterationEvent | LoopCompleteEvent | ErrorEvent | ThreadCreatedEvent | DoneEvent;
231
- /**
232
- * LLM configuration
233
- */
234
- interface LLMConfig {
235
- temperature?: number;
236
- maxTokens?: number;
237
- }
238
- /**
239
- * Tool call format (OpenAI style)
240
- */
241
- interface ToolCall {
242
- id: string;
243
- type: "function";
244
- function: {
245
- name: string;
246
- arguments: string;
247
- };
248
- /** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
249
- extra_content?: Record<string, unknown>;
250
- }
251
- /**
252
- * Message role
253
- */
254
- type MessageRole = "system" | "user" | "assistant" | "tool";
255
- /**
256
- * Message attachment
257
- */
258
- interface MessageAttachment {
259
- type: "image" | "file" | "audio" | "video";
260
- data?: string;
261
- url?: string;
262
- mimeType: string;
263
- filename?: string;
264
- }
265
- /**
266
- * Message metadata
267
- */
268
- interface MessageMetadata {
269
- thinking?: string;
270
- attachments?: MessageAttachment[];
271
- toolName?: string;
272
- [key: string]: unknown;
273
- }
274
- /**
275
- * Message type (simplified for llm-sdk)
276
- */
277
- interface Message {
278
- id: string;
279
- thread_id?: string;
280
- role: MessageRole;
281
- content: string | null;
282
- tool_calls?: ToolCall[];
283
- tool_call_id?: string;
284
- metadata?: MessageMetadata;
285
- created_at?: Date;
286
- }
287
- /**
288
- * Action parameter definition
289
- */
290
- interface ActionParameter {
291
- type: string;
292
- description?: string;
293
- required?: boolean;
294
- enum?: string[];
295
- items?: ActionParameter;
296
- properties?: Record<string, ActionParameter>;
297
- }
298
- /**
299
- * Action definition for tool calling
300
- */
301
- interface ActionDefinition<TParams = Record<string, unknown>> {
302
- name: string;
303
- description: string;
304
- parameters?: Record<string, ActionParameter>;
305
- handler: (params: TParams) => unknown | Promise<unknown>;
306
- }
307
- /**
308
- * Tool location (server or client)
309
- */
310
- type ToolLocation = "server" | "client";
311
- /**
312
- * Tool execution status
313
- */
314
- type ToolExecutionStatus = "pending" | "executing" | "completed" | "error";
315
- /**
316
- * Tool response
317
- */
318
- interface ToolResponse<T = unknown> {
319
- success: boolean;
320
- data?: T;
321
- error?: string;
322
- /** Internal: AI response mode override */
323
- _aiResponseMode?: AIResponseMode;
324
- /** Internal: AI content for multimodal response (images, etc.) */
325
- _aiContent?: AIContent[];
326
- /** Internal: AI context string override */
327
- _aiContext?: string;
328
- }
329
- /**
330
- * Tool context passed to handlers
331
- */
332
- interface ToolContext {
333
- userId?: string;
334
- threadId?: string;
335
- [key: string]: unknown;
336
- }
337
- /**
338
- * AI response mode for tool results
339
- */
340
- type AIResponseMode = "none" | "brief" | "full";
341
- /**
342
- * AI content structure
343
- */
344
- interface AIContent {
345
- type?: "text" | "image";
346
- text?: string;
347
- mediaType?: string;
348
- data?: string;
349
- summary?: string;
350
- details?: string;
351
- }
352
- /**
353
- * JSON Schema for tool input
354
- */
355
- interface ToolInputSchema {
356
- type: "object";
357
- properties?: Record<string, unknown>;
358
- required?: string[];
359
- }
360
- /**
361
- * Tool definition
362
- */
363
- interface ToolDefinition<TParams = Record<string, unknown>> {
364
- name: string;
365
- description: string;
366
- location: ToolLocation;
367
- /** Optional logical category for tool search and selective loading. */
368
- category?: string;
369
- /** Optional group label for related tools. */
370
- group?: string;
371
- title?: string | ((args: TParams) => string);
372
- inputSchema?: ToolInputSchema;
373
- handler?: (params: TParams, context?: ToolContext) => unknown | Promise<unknown>;
374
- render?: (props: unknown) => unknown;
375
- available?: boolean;
376
- /**
377
- * Hide this tool's execution from the chat UI.
378
- * When true, tool calls and results won't be displayed to the user,
379
- * but the tool will still execute normally.
380
- * @default false
381
- */
382
- hidden?: boolean;
383
- needsApproval?: boolean;
384
- approvalMessage?: string | ((params: TParams) => string);
385
- /** AI response mode for this tool (none, brief, full) */
386
- aiResponseMode?: AIResponseMode;
387
- /** AI context string or function to generate context */
388
- aiContext?: string | ((result: ToolResponse, args: Record<string, unknown>) => string);
389
- /** Hint that this tool should be loaded lazily when dynamic selection is active. */
390
- deferLoading?: boolean;
391
- /** Named profiles this tool belongs to (for example "coding" or "search"). */
392
- profiles?: string[];
393
- /** Extra keywords used by lightweight tool search/ranking. */
394
- searchKeywords?: string[];
395
- }
396
- interface ToolProfile {
397
- include?: string[];
398
- exclude?: string[];
399
- }
400
- interface OpenAIToolSelectionHints {
401
- /**
402
- * "single" forces the selected tool when exactly one tool remains after selection.
403
- * Otherwise the adapter falls back to automatic tool choice.
404
- */
405
- toolChoice?: "auto" | "required" | "single";
406
- /** Set false to disable parallel tool calls on OpenAI-compatible providers. */
407
- parallelToolCalls?: boolean;
408
- }
409
- interface AnthropicToolSelectionHints {
410
- /**
411
- * "single" forces the selected tool when exactly one tool remains after selection.
412
- * Otherwise the adapter falls back to Anthropic's automatic tool choice.
413
- */
414
- toolChoice?: "auto" | "any" | "single";
415
- /** Disable parallel tool use when supported by the Anthropic API. */
416
- disableParallelToolUse?: boolean;
417
- }
418
- interface ToolNativeProviderHints {
419
- openai?: OpenAIToolSelectionHints;
420
- anthropic?: AnthropicToolSelectionHints;
421
- }
422
- interface OpenAIProviderToolOptions {
423
- toolChoice?: "auto" | "required" | {
424
- type: "function";
425
- name: string;
426
- };
427
- parallelToolCalls?: boolean;
428
- nativeToolSearch?: {
429
- enabled: boolean;
430
- useResponsesApi?: boolean;
431
- };
432
- }
433
- interface AnthropicProviderToolOptions {
434
- toolChoice?: "auto" | "any" | {
435
- type: "tool";
436
- name: string;
437
- };
438
- disableParallelToolUse?: boolean;
439
- nativeToolSearch?: {
440
- enabled: boolean;
441
- variant: "bm25" | "regex";
442
- };
443
- }
444
- interface ProviderToolRuntimeOptions {
445
- openai?: OpenAIProviderToolOptions;
446
- anthropic?: AnthropicProviderToolOptions;
447
- }
448
- /**
449
- * Web search configuration for native provider search
450
- *
451
- * Enables native web search for supported providers:
452
- * - Anthropic: Uses Claude's built-in web search tool
453
- * - OpenAI: Uses GPT's web search preview
454
- * - Google: Uses Gemini's Google Search grounding
455
- *
456
- * @example
457
- * ```typescript
458
- * const runtime = createRuntime({
459
- * provider: createAnthropic({ apiKey: '...' }),
460
- * model: 'claude-sonnet-4-20250514',
461
- * webSearch: true, // Enable with defaults
462
- * });
463
- *
464
- * // Or with configuration
465
- * const runtime = createRuntime({
466
- * provider: createOpenAI({ apiKey: '...' }),
467
- * model: 'gpt-4o',
468
- * webSearch: {
469
- * maxUses: 5,
470
- * allowedDomains: ['docs.anthropic.com', 'openai.com'],
471
- * },
472
- * });
473
- * ```
474
- */
475
- interface WebSearchConfig {
476
- /** Maximum number of search uses per request (default: unlimited) */
477
- maxUses?: number;
478
- /** Only search these domains (provider-specific support) */
479
- allowedDomains?: string[];
480
- /** Exclude these domains from search (provider-specific support) */
481
- blockedDomains?: string[];
482
- /** User location for localized results (Anthropic only) */
483
- userLocation?: {
484
- type: "approximate";
485
- city?: string;
486
- region?: string;
487
- country?: string;
488
- timezone?: string;
489
- };
490
- }
491
- /**
492
- * Unified tool call format
493
- */
494
- interface UnifiedToolCall {
495
- id: string;
496
- name: string;
497
- input: Record<string, unknown>;
498
- }
499
- /**
500
- * Unified tool result format
501
- */
502
- interface UnifiedToolResult {
503
- toolCallId: string;
504
- content: string;
505
- success: boolean;
506
- error?: string;
507
- }
508
- /**
509
- * Tool execution state
510
- */
511
- interface ToolExecution {
512
- id: string;
513
- name: string;
514
- args: Record<string, unknown>;
515
- status: ToolExecutionStatus;
516
- result?: ToolResponse;
517
- }
518
- /**
519
- * Knowledge base provider
520
- */
521
- type KnowledgeBaseProvider = "pinecone" | "qdrant" | "weaviate" | "custom";
522
- /**
523
- * Knowledge base configuration
524
- */
525
- interface KnowledgeBaseConfig {
526
- id: string;
527
- name?: string;
528
- provider: KnowledgeBaseProvider;
529
- apiKey?: string;
530
- index?: string;
531
- }
532
-
533
- /**
534
- * Request-level LLM configuration overrides
535
- */
536
- interface RequestLLMConfig {
537
- model?: string;
538
- temperature?: number;
539
- maxTokens?: number;
540
- }
541
- /**
542
- * Chat completion request
543
- */
544
- interface ChatCompletionRequest {
545
- /** Conversation messages */
546
- messages: Message[];
547
- /**
548
- * Raw provider-formatted messages (for agent loop with tool calls)
549
- * When provided, these are used instead of converting from Message[]
550
- * This allows passing messages with tool_calls and tool role
551
- */
552
- rawMessages?: Array<Record<string, unknown>>;
553
- /** Available actions/tools */
554
- actions?: ActionDefinition[];
555
- /** Full tool definitions for provider-native tool search / deferred loading paths. */
556
- toolDefinitions?: ToolDefinition[];
557
- /** System prompt */
558
- systemPrompt?: string;
559
- /** LLM configuration overrides */
560
- config?: RequestLLMConfig;
561
- /** Abort signal for cancellation */
562
- signal?: AbortSignal;
563
- /**
564
- * Enable native web search for the provider.
565
- * When true or configured, the provider's native search is enabled.
566
- */
567
- webSearch?: boolean | WebSearchConfig;
568
- /** Optional provider-specific tool policy hints derived from runtime selection. */
569
- providerToolOptions?: ProviderToolRuntimeOptions;
570
- /** Enable adapter-level provider payload logging. */
571
- debug?: boolean;
572
- }
573
- /**
574
- * Non-streaming completion result
575
- */
576
- interface CompletionResult {
577
- /** Text content */
578
- content: string;
579
- /** Tool calls */
580
- toolCalls: Array<{
581
- id: string;
582
- name: string;
583
- args: Record<string, unknown>;
584
- /** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
585
- extra_content?: Record<string, unknown>;
586
- }>;
587
- /** Thinking content (if extended thinking enabled) */
588
- thinking?: string;
589
- /** Token usage for billing/tracking */
590
- usage?: TokenUsage;
591
- /** Raw provider response for debugging */
592
- rawResponse: Record<string, unknown>;
593
- }
594
- /**
595
- * Base LLM adapter interface
596
- */
597
- interface LLMAdapter {
598
- /** Provider name */
599
- readonly provider: string;
600
- /** Model name */
601
- readonly model: string;
602
- /**
603
- * Stream a chat completion
604
- */
605
- stream(request: ChatCompletionRequest): AsyncGenerator<StreamEvent>;
606
- /**
607
- * Non-streaming chat completion (for debugging/comparison)
608
- */
609
- complete?(request: ChatCompletionRequest): Promise<CompletionResult>;
610
- }
611
- /**
612
- * Adapter factory function type
613
- */
614
- type AdapterFactory = (config: LLMConfig) => LLMAdapter;
615
- /**
616
- * Convert messages to provider format (simple text only)
617
- */
618
- declare function formatMessages(messages: Message[], systemPrompt?: string): Array<{
619
- role: string;
620
- content: string;
621
- }>;
622
- /**
623
- * Convert actions to OpenAI tool format
624
- */
625
- declare function formatTools(actions: ActionDefinition[]): Array<{
626
- type: "function";
627
- function: {
628
- name: string;
629
- description: string;
630
- parameters: object;
631
- };
632
- }>;
633
- /**
634
- * Content block types for multimodal messages
635
- */
636
- type AnthropicContentBlock = {
637
- type: "text";
638
- text: string;
639
- } | {
640
- type: "image";
641
- source: {
642
- type: "base64";
643
- media_type: string;
644
- data: string;
645
- } | {
646
- type: "url";
647
- url: string;
648
- };
649
- } | {
650
- type: "document";
651
- source: {
652
- type: "base64";
653
- media_type: string;
654
- data: string;
655
- } | {
656
- type: "url";
657
- url: string;
658
- };
659
- };
660
- type OpenAIContentBlock = {
661
- type: "text";
662
- text: string;
663
- } | {
664
- type: "image_url";
665
- image_url: {
666
- url: string;
667
- detail?: "low" | "high" | "auto";
668
- };
669
- };
670
- /**
671
- * Check if a message has image attachments
672
- * Supports both new format (metadata.attachments) and legacy (attachments)
673
- */
674
- declare function hasImageAttachments(message: Message): boolean;
675
- /**
676
- * Check if a message has media attachments (images or PDFs)
677
- */
678
- declare function hasMediaAttachments(message: Message): boolean;
679
- /**
680
- * Convert MessageAttachment to Anthropic image content block
681
- *
682
- * Anthropic format:
683
- * {
684
- * type: "image",
685
- * source: {
686
- * type: "base64",
687
- * media_type: "image/png",
688
- * data: "base64data..."
689
- * }
690
- * }
691
- */
692
- declare function attachmentToAnthropicImage(attachment: MessageAttachment): AnthropicContentBlock | null;
693
- /**
694
- * Convert MessageAttachment to OpenAI image_url content block
695
- *
696
- * OpenAI format:
697
- * {
698
- * type: "image_url",
699
- * image_url: {
700
- * url: "data:image/png;base64,..."
701
- * }
702
- * }
703
- */
704
- declare function attachmentToOpenAIImage(attachment: MessageAttachment): OpenAIContentBlock | null;
705
- /**
706
- * Convert MessageAttachment (PDF) to Anthropic document content block
707
- *
708
- * Anthropic format:
709
- * {
710
- * type: "document",
711
- * source: {
712
- * type: "base64",
713
- * media_type: "application/pdf",
714
- * data: "base64data..."
715
- * }
716
- * }
717
- */
718
- declare function attachmentToAnthropicDocument(attachment: MessageAttachment): AnthropicContentBlock | null;
719
- /**
720
- * Convert a Message to Anthropic multimodal content blocks
721
- */
722
- declare function messageToAnthropicContent(message: Message): string | AnthropicContentBlock[];
723
- /**
724
- * Convert a Message to OpenAI multimodal content blocks
725
- */
726
- declare function messageToOpenAIContent(message: Message): string | OpenAIContentBlock[];
727
- /**
728
- * Anthropic content block types (extended for tools)
729
- */
730
- type AnthropicToolUseBlock = {
731
- type: "tool_use";
732
- id: string;
733
- name: string;
734
- input: Record<string, unknown>;
735
- };
736
- type AnthropicToolResultBlock = {
737
- type: "tool_result";
738
- tool_use_id: string;
739
- content: string;
740
- };
741
- type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
742
- /**
743
- * Format messages for Anthropic with full tool support
744
- * Handles: text, images, tool_use, and tool_result
745
- *
746
- * Key differences from OpenAI:
747
- * - tool_calls become tool_use blocks in assistant content
748
- * - tool results become tool_result blocks in user content
749
- */
750
- declare function formatMessagesForAnthropic(messages: Message[], systemPrompt?: string): {
751
- system: string;
752
- messages: Array<{
753
- role: "user" | "assistant";
754
- content: AnthropicMessageContent;
755
- }>;
756
- };
757
- /**
758
- * OpenAI message format with tool support
759
- */
760
- type OpenAIMessage = {
761
- role: "system";
762
- content: string;
763
- } | {
764
- role: "user";
765
- content: string | OpenAIContentBlock[];
766
- } | {
767
- role: "assistant";
768
- content: string | null;
769
- tool_calls?: Array<{
770
- id: string;
771
- type: "function";
772
- function: {
773
- name: string;
774
- arguments: string;
775
- };
776
- }>;
777
- } | {
778
- role: "tool";
779
- content: string;
780
- tool_call_id: string;
781
- };
782
- /**
783
- * Format messages for OpenAI with full tool support
784
- * Handles: text, images, tool_calls, and tool results
785
- */
786
- declare function formatMessagesForOpenAI(messages: Message[], systemPrompt?: string): OpenAIMessage[];
787
-
788
- export { type ActionDefinition as A, type AnthropicContentBlock as B, type ChatCompletionRequest as C, type DoneEventMessage as D, type OpenAIContentBlock as E, type KnowledgeBaseConfig as K, type LLMAdapter as L, type Message as M, type OpenAIToolSelectionHints as O, type ProviderToolRuntimeOptions as P, type StreamEvent as S, type ToolDefinition as T, type UnifiedToolCall as U, type WebSearchConfig as W, type ToolProfile as a, type ToolCallInfo as b, type TokenUsageRaw as c, type ToolResponse as d, type AdapterFactory as e, type LLMConfig as f, type ToolLocation as g, type UnifiedToolResult as h, type ToolExecution as i, type AnthropicToolSelectionHints as j, type ToolNativeProviderHints as k, type OpenAIProviderToolOptions as l, type AnthropicProviderToolOptions as m, type Citation as n, type CompletionResult as o, formatMessages as p, formatTools as q, formatMessagesForAnthropic as r, formatMessagesForOpenAI as s, messageToAnthropicContent as t, messageToOpenAIContent as u, hasImageAttachments as v, hasMediaAttachments as w, attachmentToAnthropicImage as x, attachmentToAnthropicDocument as y, attachmentToOpenAIImage as z };