@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.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.
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +156 -13
- package/dist/adapters/index.mjs +156 -13
- package/dist/base-C58Dsr9p.d.ts +259 -0
- package/dist/base-tNgbBaSo.d.mts +259 -0
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +12 -0
- package/dist/index.mjs +12 -0
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +271 -195
- package/dist/providers/anthropic/index.mjs +271 -195
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +49 -1
- package/dist/providers/azure/index.mjs +49 -1
- package/dist/providers/fireworks/index.d.mts +1 -1
- package/dist/providers/fireworks/index.d.ts +1 -1
- package/dist/providers/fireworks/index.js +56 -0
- package/dist/providers/fireworks/index.mjs +56 -0
- package/dist/providers/google/index.d.mts +3 -3
- package/dist/providers/google/index.d.ts +3 -3
- package/dist/providers/google/index.js +252 -205
- package/dist/providers/google/index.mjs +252 -205
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +10 -2
- package/dist/providers/ollama/index.mjs +10 -2
- package/dist/providers/openai/index.d.mts +3 -3
- package/dist/providers/openai/index.d.ts +3 -3
- package/dist/providers/openai/index.js +267 -214
- package/dist/providers/openai/index.mjs +267 -214
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +257 -204
- package/dist/providers/openrouter/index.mjs +257 -204
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +257 -204
- package/dist/providers/togetherai/index.mjs +257 -204
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +256 -208
- package/dist/providers/xai/index.mjs +256 -208
- package/dist/{types-D4YfrQJR.d.mts → types-B6dhnguR.d.mts} +1 -1
- package/dist/{types-DRqxMIjF.d.mts → types-BQ31QIsA.d.ts} +2 -1
- package/dist/{types-BctsnC3g.d.ts → types-BSSiJW2o.d.mts} +2 -1
- package/dist/{base-D-U61JaB.d.mts → types-BkQCSiIt.d.mts} +388 -213
- package/dist/{base-iGi9Va6Z.d.ts → types-BkQCSiIt.d.ts} +388 -213
- package/dist/{types-38yolWJn.d.ts → types-CCxPmkmK.d.ts} +1 -1
- package/dist/yourgpt/index.d.mts +1 -1
- package/dist/yourgpt/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/types-CR8mi9I0.d.mts +0 -417
- package/dist/types-CR8mi9I0.d.ts +0 -417
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Stream event types for llm-sdk
|
|
@@ -228,17 +228,35 @@ interface DoneEvent extends BaseEvent {
|
|
|
228
228
|
* Union of all stream events
|
|
229
229
|
*/
|
|
230
230
|
type StreamEvent = MessageStartEvent | MessageDeltaEvent | MessageEndEvent | ThinkingStartEvent | ThinkingDeltaEvent | ThinkingEndEvent | ActionStartEvent | ActionArgsEvent | ActionEndEvent | ToolCallsEvent | ToolResultEvent | CitationEvent | LoopIterationEvent | LoopCompleteEvent | ErrorEvent | ThreadCreatedEvent | DoneEvent;
|
|
231
|
+
/**
|
|
232
|
+
* Structured-output / JSON-mode request format.
|
|
233
|
+
*
|
|
234
|
+
* Uses OpenAI's `response_format` shape as the unified surface; each adapter
|
|
235
|
+
* translates to its provider's native field (Anthropic `output_config`,
|
|
236
|
+
* Gemini `responseJsonSchema`, Ollama `format`, etc.).
|
|
237
|
+
*/
|
|
238
|
+
type ResponseFormat = {
|
|
239
|
+
type: "json_object";
|
|
240
|
+
} | {
|
|
241
|
+
type: "json_schema";
|
|
242
|
+
json_schema: {
|
|
243
|
+
name: string;
|
|
244
|
+
schema: Record<string, unknown>;
|
|
245
|
+
strict?: boolean;
|
|
246
|
+
};
|
|
247
|
+
};
|
|
231
248
|
/**
|
|
232
249
|
* LLM configuration
|
|
233
250
|
*/
|
|
234
251
|
interface LLMConfig {
|
|
235
252
|
temperature?: number;
|
|
236
253
|
maxTokens?: number;
|
|
254
|
+
responseFormat?: ResponseFormat;
|
|
237
255
|
}
|
|
238
256
|
/**
|
|
239
257
|
* Tool call format (OpenAI style)
|
|
240
258
|
*/
|
|
241
|
-
interface ToolCall {
|
|
259
|
+
interface ToolCall$1 {
|
|
242
260
|
id: string;
|
|
243
261
|
type: "function";
|
|
244
262
|
function: {
|
|
@@ -279,7 +297,7 @@ interface Message {
|
|
|
279
297
|
thread_id?: string;
|
|
280
298
|
role: MessageRole;
|
|
281
299
|
content: string | null;
|
|
282
|
-
tool_calls?: ToolCall[];
|
|
300
|
+
tool_calls?: ToolCall$1[];
|
|
283
301
|
tool_call_id?: string;
|
|
284
302
|
metadata?: MessageMetadata;
|
|
285
303
|
created_at?: Date;
|
|
@@ -329,7 +347,7 @@ interface ToolResponse<T = unknown> {
|
|
|
329
347
|
/**
|
|
330
348
|
* Tool context passed to handlers
|
|
331
349
|
*/
|
|
332
|
-
interface ToolContext {
|
|
350
|
+
interface ToolContext$1 {
|
|
333
351
|
userId?: string;
|
|
334
352
|
threadId?: string;
|
|
335
353
|
[key: string]: unknown;
|
|
@@ -370,7 +388,7 @@ interface ToolDefinition<TParams = Record<string, unknown>> {
|
|
|
370
388
|
group?: string;
|
|
371
389
|
title?: string | ((args: TParams) => string);
|
|
372
390
|
inputSchema?: ToolInputSchema;
|
|
373
|
-
handler?: (params: TParams, context?: ToolContext) => unknown | Promise<unknown>;
|
|
391
|
+
handler?: (params: TParams, context?: ToolContext$1) => unknown | Promise<unknown>;
|
|
374
392
|
render?: (props: unknown) => unknown;
|
|
375
393
|
available?: boolean;
|
|
376
394
|
/**
|
|
@@ -531,258 +549,415 @@ interface KnowledgeBaseConfig {
|
|
|
531
549
|
}
|
|
532
550
|
|
|
533
551
|
/**
|
|
534
|
-
*
|
|
535
|
-
|
|
536
|
-
interface RequestLLMConfig {
|
|
537
|
-
model?: string;
|
|
538
|
-
temperature?: number;
|
|
539
|
-
maxTokens?: number;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Chat completion request
|
|
552
|
+
* A language model instance that can generate text.
|
|
553
|
+
* This is what provider functions like `openai('gpt-4o')` return.
|
|
543
554
|
*/
|
|
544
|
-
interface
|
|
545
|
-
/**
|
|
546
|
-
|
|
555
|
+
interface LanguageModel {
|
|
556
|
+
/** Provider identifier (e.g., 'openai', 'anthropic') */
|
|
557
|
+
readonly provider: string;
|
|
558
|
+
/** Model identifier (e.g., 'gpt-4o', 'claude-3-5-sonnet') */
|
|
559
|
+
readonly modelId: string;
|
|
560
|
+
/** Model capabilities for feature detection */
|
|
561
|
+
readonly capabilities: ModelCapabilities;
|
|
547
562
|
/**
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
* This allows passing messages with tool_calls and tool role
|
|
563
|
+
* Generate a complete response (non-streaming)
|
|
564
|
+
* Used internally by generateText()
|
|
551
565
|
*/
|
|
552
|
-
|
|
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;
|
|
566
|
+
doGenerate(params: DoGenerateParams): Promise<DoGenerateResult>;
|
|
563
567
|
/**
|
|
564
|
-
*
|
|
565
|
-
*
|
|
568
|
+
* Stream a response
|
|
569
|
+
* Used internally by streamText()
|
|
566
570
|
*/
|
|
567
|
-
|
|
568
|
-
/** Optional provider-specific tool policy hints derived from runtime selection. */
|
|
569
|
-
providerToolOptions?: ProviderToolRuntimeOptions;
|
|
570
|
-
/** Enable adapter-level provider payload logging. */
|
|
571
|
-
debug?: boolean;
|
|
571
|
+
doStream(params: DoGenerateParams): AsyncGenerator<StreamChunk>;
|
|
572
572
|
}
|
|
573
573
|
/**
|
|
574
|
-
*
|
|
574
|
+
* Model capabilities for UI feature flags
|
|
575
|
+
*/
|
|
576
|
+
interface ModelCapabilities {
|
|
577
|
+
/** Supports image inputs */
|
|
578
|
+
supportsVision: boolean;
|
|
579
|
+
/** Supports tool/function calling */
|
|
580
|
+
supportsTools: boolean;
|
|
581
|
+
/** Supports streaming responses */
|
|
582
|
+
supportsStreaming: boolean;
|
|
583
|
+
/** Supports JSON mode / structured output */
|
|
584
|
+
supportsJsonMode: boolean;
|
|
585
|
+
/** Supports extended thinking (Claude) */
|
|
586
|
+
supportsThinking: boolean;
|
|
587
|
+
/** Supports PDF document inputs */
|
|
588
|
+
supportsPDF: boolean;
|
|
589
|
+
/** Maximum context tokens */
|
|
590
|
+
maxTokens: number;
|
|
591
|
+
/** Supported image MIME types */
|
|
592
|
+
supportedImageTypes: string[];
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Default capabilities for unknown models
|
|
596
|
+
*/
|
|
597
|
+
declare const DEFAULT_CAPABILITIES: ModelCapabilities;
|
|
598
|
+
/**
|
|
599
|
+
* Core message types for LLM conversations
|
|
575
600
|
*/
|
|
576
|
-
|
|
577
|
-
|
|
601
|
+
type CoreMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
|
|
602
|
+
interface SystemMessage {
|
|
603
|
+
role: "system";
|
|
604
|
+
content: string;
|
|
605
|
+
}
|
|
606
|
+
interface UserMessage {
|
|
607
|
+
role: "user";
|
|
608
|
+
content: string | UserContentPart[];
|
|
609
|
+
}
|
|
610
|
+
interface AssistantMessage {
|
|
611
|
+
role: "assistant";
|
|
612
|
+
content: string | null;
|
|
613
|
+
toolCalls?: ToolCall[];
|
|
614
|
+
}
|
|
615
|
+
interface ToolMessage {
|
|
616
|
+
role: "tool";
|
|
617
|
+
toolCallId: string;
|
|
578
618
|
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
619
|
}
|
|
594
620
|
/**
|
|
595
|
-
*
|
|
621
|
+
* Content parts for multimodal user messages
|
|
596
622
|
*/
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
623
|
+
type UserContentPart = TextPart | ImagePart | FilePart;
|
|
624
|
+
interface TextPart {
|
|
625
|
+
type: "text";
|
|
626
|
+
text: string;
|
|
627
|
+
}
|
|
628
|
+
interface ImagePart {
|
|
629
|
+
type: "image";
|
|
630
|
+
/** Base64 data or URL */
|
|
631
|
+
image: string | Uint8Array;
|
|
632
|
+
/** MIME type (e.g., 'image/png') */
|
|
633
|
+
mimeType?: string;
|
|
634
|
+
}
|
|
635
|
+
interface FilePart {
|
|
636
|
+
type: "file";
|
|
637
|
+
/** Base64 data or URL */
|
|
638
|
+
data: string;
|
|
639
|
+
/** MIME type (e.g., 'application/pdf') */
|
|
640
|
+
mimeType: string;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Tool definition with Zod schema support
|
|
644
|
+
*/
|
|
645
|
+
interface Tool<TParams = unknown, TResult = unknown> {
|
|
646
|
+
/** Tool description for the LLM */
|
|
647
|
+
description: string;
|
|
648
|
+
/** Zod schema for parameters */
|
|
649
|
+
parameters: z.ZodType<TParams>;
|
|
650
|
+
/** Execute function */
|
|
651
|
+
execute: (params: TParams, context: ToolContext) => Promise<TResult>;
|
|
606
652
|
/**
|
|
607
|
-
*
|
|
653
|
+
* Hide this tool's execution from the chat UI.
|
|
654
|
+
* When true, tool calls and results won't be displayed to the user,
|
|
655
|
+
* but the tool will still execute normally.
|
|
656
|
+
* @default false
|
|
608
657
|
*/
|
|
609
|
-
|
|
658
|
+
hidden?: boolean;
|
|
610
659
|
}
|
|
611
660
|
/**
|
|
612
|
-
*
|
|
661
|
+
* Context passed to tool execute function
|
|
613
662
|
*/
|
|
614
|
-
|
|
663
|
+
interface ToolContext {
|
|
664
|
+
/** Abort signal for cancellation */
|
|
665
|
+
abortSignal?: AbortSignal;
|
|
666
|
+
/** Unique tool call ID */
|
|
667
|
+
toolCallId: string;
|
|
668
|
+
/** Optional: messages in conversation */
|
|
669
|
+
messages?: CoreMessage[];
|
|
670
|
+
}
|
|
615
671
|
/**
|
|
616
|
-
*
|
|
672
|
+
* Tool call from LLM response
|
|
617
673
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
674
|
+
interface ToolCall {
|
|
675
|
+
/** Unique ID for this tool call */
|
|
676
|
+
id: string;
|
|
677
|
+
/** Tool name */
|
|
678
|
+
name: string;
|
|
679
|
+
/** Parsed arguments */
|
|
680
|
+
args: Record<string, unknown>;
|
|
681
|
+
}
|
|
622
682
|
/**
|
|
623
|
-
*
|
|
683
|
+
* Tool execution result
|
|
624
684
|
*/
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
};
|
|
632
|
-
}>;
|
|
685
|
+
interface ToolResult {
|
|
686
|
+
/** Tool call ID this result corresponds to */
|
|
687
|
+
toolCallId: string;
|
|
688
|
+
/** Result data (will be JSON stringified for LLM) */
|
|
689
|
+
result: unknown;
|
|
690
|
+
}
|
|
633
691
|
/**
|
|
634
|
-
*
|
|
692
|
+
* Parameters for model.doGenerate() and model.doStream()
|
|
635
693
|
*/
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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
|
-
};
|
|
694
|
+
interface DoGenerateParams {
|
|
695
|
+
/** Messages to send to LLM */
|
|
696
|
+
messages: CoreMessage[];
|
|
697
|
+
/** Tools available to the LLM (already formatted for provider) */
|
|
698
|
+
tools?: unknown[];
|
|
699
|
+
/** Temperature (0-2) */
|
|
700
|
+
temperature?: number;
|
|
701
|
+
/** Maximum tokens to generate */
|
|
702
|
+
maxTokens?: number;
|
|
703
|
+
/** Structured-output / JSON-mode request format (provider-translated) */
|
|
704
|
+
responseFormat?: ResponseFormat;
|
|
705
|
+
/** Abort signal */
|
|
706
|
+
signal?: AbortSignal;
|
|
707
|
+
}
|
|
670
708
|
/**
|
|
671
|
-
*
|
|
672
|
-
* Supports both new format (metadata.attachments) and legacy (attachments)
|
|
709
|
+
* Result from model.doGenerate()
|
|
673
710
|
*/
|
|
674
|
-
|
|
711
|
+
interface DoGenerateResult {
|
|
712
|
+
/** Generated text content */
|
|
713
|
+
text: string;
|
|
714
|
+
/** Tool calls requested by the LLM */
|
|
715
|
+
toolCalls: ToolCall[];
|
|
716
|
+
/** Why generation stopped */
|
|
717
|
+
finishReason: FinishReason;
|
|
718
|
+
/** Token usage */
|
|
719
|
+
usage: TokenUsage;
|
|
720
|
+
/** Raw provider response (for debugging) */
|
|
721
|
+
rawResponse?: unknown;
|
|
722
|
+
}
|
|
675
723
|
/**
|
|
676
|
-
*
|
|
724
|
+
* Finish reason for generation
|
|
677
725
|
*/
|
|
678
|
-
|
|
726
|
+
type FinishReason = "stop" | "length" | "tool-calls" | "content-filter" | "error" | "unknown";
|
|
679
727
|
/**
|
|
680
|
-
*
|
|
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
|
-
* }
|
|
728
|
+
* Token usage statistics
|
|
703
729
|
*/
|
|
704
|
-
|
|
730
|
+
interface TokenUsage {
|
|
731
|
+
promptTokens: number;
|
|
732
|
+
completionTokens: number;
|
|
733
|
+
totalTokens: number;
|
|
734
|
+
}
|
|
705
735
|
/**
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* Anthropic format:
|
|
709
|
-
* {
|
|
710
|
-
* type: "document",
|
|
711
|
-
* source: {
|
|
712
|
-
* type: "base64",
|
|
713
|
-
* media_type: "application/pdf",
|
|
714
|
-
* data: "base64data..."
|
|
715
|
-
* }
|
|
716
|
-
* }
|
|
736
|
+
* Stream chunk from model.doStream()
|
|
717
737
|
*/
|
|
718
|
-
|
|
738
|
+
type StreamChunk = TextDeltaChunk | ToolCallChunk | ToolResultChunk | FinishChunk | ErrorChunk;
|
|
739
|
+
interface TextDeltaChunk {
|
|
740
|
+
type: "text-delta";
|
|
741
|
+
text: string;
|
|
742
|
+
}
|
|
743
|
+
interface ToolCallChunk {
|
|
744
|
+
type: "tool-call";
|
|
745
|
+
toolCall: ToolCall;
|
|
746
|
+
}
|
|
747
|
+
interface ToolResultChunk {
|
|
748
|
+
type: "tool-result";
|
|
749
|
+
toolCallId: string;
|
|
750
|
+
result: unknown;
|
|
751
|
+
}
|
|
752
|
+
interface FinishChunk {
|
|
753
|
+
type: "finish";
|
|
754
|
+
finishReason: FinishReason;
|
|
755
|
+
usage?: TokenUsage;
|
|
756
|
+
}
|
|
757
|
+
interface ErrorChunk {
|
|
758
|
+
type: "error";
|
|
759
|
+
error: Error;
|
|
760
|
+
}
|
|
719
761
|
/**
|
|
720
|
-
*
|
|
762
|
+
* Parameters for generateText()
|
|
721
763
|
*/
|
|
722
|
-
|
|
764
|
+
interface GenerateTextParams {
|
|
765
|
+
/** Language model to use */
|
|
766
|
+
model: LanguageModel;
|
|
767
|
+
/** Simple prompt (converted to user message) */
|
|
768
|
+
prompt?: string;
|
|
769
|
+
/** System prompt */
|
|
770
|
+
system?: string;
|
|
771
|
+
/** Full message history */
|
|
772
|
+
messages?: CoreMessage[];
|
|
773
|
+
/** Tools available to the LLM */
|
|
774
|
+
tools?: Record<string, Tool>;
|
|
775
|
+
/** Maximum agentic steps (tool call loops) */
|
|
776
|
+
maxSteps?: number;
|
|
777
|
+
/** Temperature (0-2) */
|
|
778
|
+
temperature?: number;
|
|
779
|
+
/** Maximum tokens to generate */
|
|
780
|
+
maxTokens?: number;
|
|
781
|
+
/** Structured-output / JSON-mode request format */
|
|
782
|
+
responseFormat?: ResponseFormat;
|
|
783
|
+
/** Abort signal */
|
|
784
|
+
signal?: AbortSignal;
|
|
785
|
+
}
|
|
723
786
|
/**
|
|
724
|
-
*
|
|
787
|
+
* Result from generateText()
|
|
725
788
|
*/
|
|
726
|
-
|
|
789
|
+
interface GenerateTextResult {
|
|
790
|
+
/** Final text output */
|
|
791
|
+
text: string;
|
|
792
|
+
/** Token usage */
|
|
793
|
+
usage: TokenUsage;
|
|
794
|
+
/** Why generation stopped */
|
|
795
|
+
finishReason: FinishReason;
|
|
796
|
+
/** All steps taken (for agentic workflows) */
|
|
797
|
+
steps: GenerateStep[];
|
|
798
|
+
/** All tool calls made across all steps */
|
|
799
|
+
toolCalls: ToolCall[];
|
|
800
|
+
/** All tool results across all steps */
|
|
801
|
+
toolResults: ToolResult[];
|
|
802
|
+
/** Final message list including tool interactions */
|
|
803
|
+
response: {
|
|
804
|
+
messages: CoreMessage[];
|
|
805
|
+
};
|
|
806
|
+
}
|
|
727
807
|
/**
|
|
728
|
-
*
|
|
808
|
+
* A single step in the generation process
|
|
729
809
|
*/
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
810
|
+
interface GenerateStep {
|
|
811
|
+
/** Text generated in this step */
|
|
812
|
+
text: string;
|
|
813
|
+
/** Tool calls made in this step */
|
|
814
|
+
toolCalls: ToolCall[];
|
|
815
|
+
/** Tool results from this step */
|
|
816
|
+
toolResults: ToolResult[];
|
|
817
|
+
/** Finish reason for this step */
|
|
818
|
+
finishReason: FinishReason;
|
|
819
|
+
/** Token usage for this step */
|
|
820
|
+
usage: TokenUsage;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Parameters for streamText() - same as generateText
|
|
824
|
+
*/
|
|
825
|
+
type StreamTextParams = GenerateTextParams;
|
|
826
|
+
/**
|
|
827
|
+
* Result from streamText()
|
|
828
|
+
*/
|
|
829
|
+
interface StreamTextResult {
|
|
830
|
+
/** Async iterable of text chunks only */
|
|
831
|
+
textStream: AsyncIterable<string>;
|
|
832
|
+
/** Async iterable of all stream parts */
|
|
833
|
+
fullStream: AsyncIterable<StreamPart>;
|
|
834
|
+
/** Promise that resolves to full text when complete */
|
|
835
|
+
readonly text: Promise<string>;
|
|
836
|
+
/** Promise that resolves to usage when complete */
|
|
837
|
+
readonly usage: Promise<TokenUsage>;
|
|
838
|
+
/** Promise that resolves to finish reason when complete */
|
|
839
|
+
readonly finishReason: Promise<FinishReason>;
|
|
840
|
+
/** Convert to plain text streaming Response */
|
|
841
|
+
toTextStreamResponse(options?: ResponseOptions): Response;
|
|
842
|
+
/** Convert to data stream Response (SSE with tool calls) */
|
|
843
|
+
toDataStreamResponse(options?: ResponseOptions): Response;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Stream part for fullStream
|
|
847
|
+
*/
|
|
848
|
+
type StreamPart = {
|
|
849
|
+
type: "text-delta";
|
|
850
|
+
text: string;
|
|
851
|
+
} | {
|
|
852
|
+
type: "tool-call-start";
|
|
853
|
+
toolCallId: string;
|
|
854
|
+
toolName: string;
|
|
855
|
+
} | {
|
|
856
|
+
type: "tool-call-delta";
|
|
857
|
+
toolCallId: string;
|
|
858
|
+
argsText: string;
|
|
859
|
+
} | {
|
|
860
|
+
type: "tool-call-complete";
|
|
861
|
+
toolCall: ToolCall;
|
|
862
|
+
} | {
|
|
863
|
+
type: "tool-result";
|
|
864
|
+
toolCallId: string;
|
|
865
|
+
result: unknown;
|
|
866
|
+
} | {
|
|
867
|
+
type: "step-start";
|
|
868
|
+
step: number;
|
|
869
|
+
} | {
|
|
870
|
+
type: "step-finish";
|
|
871
|
+
step: number;
|
|
872
|
+
finishReason: FinishReason;
|
|
873
|
+
} | {
|
|
874
|
+
type: "finish";
|
|
875
|
+
finishReason: FinishReason;
|
|
876
|
+
usage: TokenUsage;
|
|
877
|
+
} | {
|
|
878
|
+
type: "error";
|
|
879
|
+
error: Error;
|
|
740
880
|
};
|
|
741
|
-
type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
|
|
742
881
|
/**
|
|
743
|
-
*
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
system: string;
|
|
752
|
-
messages: Array<{
|
|
753
|
-
role: "user" | "assistant";
|
|
754
|
-
content: AnthropicMessageContent;
|
|
755
|
-
}>;
|
|
756
|
-
};
|
|
882
|
+
* Options for Response helpers
|
|
883
|
+
*/
|
|
884
|
+
interface ResponseOptions {
|
|
885
|
+
/** Additional headers */
|
|
886
|
+
headers?: Record<string, string>;
|
|
887
|
+
/** Response status (default: 200) */
|
|
888
|
+
status?: number;
|
|
889
|
+
}
|
|
757
890
|
/**
|
|
758
|
-
*
|
|
891
|
+
* Message format for storage adapters.
|
|
892
|
+
* Intentionally simpler than LLM-specific formats — adapters convert as needed.
|
|
759
893
|
*/
|
|
760
|
-
|
|
761
|
-
role: "system";
|
|
894
|
+
interface StorageMessage {
|
|
895
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
762
896
|
content: string;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
897
|
+
toolCalls?: unknown[];
|
|
898
|
+
toolCallId?: string;
|
|
899
|
+
/** Content type for the message — determines how it's stored in the backend */
|
|
900
|
+
contentType?: "text" | "image" | "file";
|
|
901
|
+
/** URL for image/file attachments */
|
|
902
|
+
url?: string;
|
|
903
|
+
metadata?: Record<string, unknown>;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Generic storage adapter interface for session + message persistence.
|
|
907
|
+
*
|
|
908
|
+
* `createYourGPT()` is the default implementation for YourGPT platform.
|
|
909
|
+
* Third-party developers can implement this interface for custom backends.
|
|
910
|
+
*
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* import { createRuntime } from '@yourgpt/llm-sdk'
|
|
914
|
+
* import { createYourGPT } from '@yourgpt/llm-sdk/yourgpt'
|
|
915
|
+
*
|
|
916
|
+
* const runtime = createRuntime({
|
|
917
|
+
* provider: anthropic,
|
|
918
|
+
* model: 'claude-haiku-4-5',
|
|
919
|
+
* storage: createYourGPT({ apiKey, widgetUid }),
|
|
920
|
+
* })
|
|
921
|
+
* // runtime.chat() and runtime.stream() now auto-persist messages
|
|
922
|
+
* ```
|
|
923
|
+
*/
|
|
924
|
+
interface StorageAdapter {
|
|
925
|
+
/** Create a new session. Returns session ID to use as threadId. */
|
|
926
|
+
createSession(data?: {
|
|
927
|
+
title?: string;
|
|
928
|
+
metadata?: Record<string, unknown>;
|
|
929
|
+
}): Promise<{
|
|
770
930
|
id: string;
|
|
771
|
-
type: "function";
|
|
772
|
-
function: {
|
|
773
|
-
name: string;
|
|
774
|
-
arguments: string;
|
|
775
|
-
};
|
|
776
931
|
}>;
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
932
|
+
/** Append messages to a session (called sequentially — input before output). */
|
|
933
|
+
saveMessages(sessionId: string, messages: StorageMessage[]): Promise<void>;
|
|
934
|
+
/** List sessions (optional — used for thread picker sync in future). */
|
|
935
|
+
getSessions?(): Promise<{
|
|
936
|
+
id: string;
|
|
937
|
+
title?: string;
|
|
938
|
+
updatedAt?: Date;
|
|
939
|
+
}[]>;
|
|
940
|
+
/** Get messages for a session (optional — used for thread restore in future). */
|
|
941
|
+
getMessages?(sessionId: string): Promise<StorageMessage[]>;
|
|
942
|
+
/**
|
|
943
|
+
* Upload a file to storage. Returns a URL the LLM can reference.
|
|
944
|
+
* When present, the server exposes a /upload endpoint and the client
|
|
945
|
+
* uses it instead of embedding base64 in the message body.
|
|
946
|
+
*/
|
|
947
|
+
uploadFile?(file: StorageFile): Promise<{
|
|
948
|
+
url: string;
|
|
949
|
+
}>;
|
|
950
|
+
}
|
|
782
951
|
/**
|
|
783
|
-
*
|
|
784
|
-
* Handles: text, images, tool_calls, and tool results
|
|
952
|
+
* File data for upload via StorageAdapter.uploadFile()
|
|
785
953
|
*/
|
|
786
|
-
|
|
954
|
+
interface StorageFile {
|
|
955
|
+
/** Base64-encoded file data (with or without data URI prefix) */
|
|
956
|
+
data: string;
|
|
957
|
+
/** MIME type (e.g., "image/png", "application/pdf") */
|
|
958
|
+
mimeType: string;
|
|
959
|
+
/** Original filename */
|
|
960
|
+
filename?: string;
|
|
961
|
+
}
|
|
787
962
|
|
|
788
|
-
export { type ActionDefinition as A, type
|
|
963
|
+
export { type ToolExecution as $, type ActionDefinition as A, type ToolResultChunk as B, type CoreMessage as C, type DoneEventMessage as D, type FinishChunk as E, type FilePart as F, type GenerateTextParams as G, type ErrorChunk as H, type ImagePart as I, type TokenUsage as J, type KnowledgeBaseConfig as K, type LanguageModel as L, type Message as M, type FinishReason as N, type ResponseOptions as O, type ProviderToolRuntimeOptions as P, type StorageFile as Q, type ResponseFormat as R, type StreamTextParams as S, type ToolContext as T, type UserMessage as U, DEFAULT_CAPABILITIES as V, type WebSearchConfig as W, type LLMConfig as X, type ToolLocation as Y, type UnifiedToolCall as Z, type UnifiedToolResult as _, type GenerateTextResult as a, type OpenAIToolSelectionHints as a0, type AnthropicToolSelectionHints as a1, type ToolNativeProviderHints as a2, type OpenAIProviderToolOptions as a3, type AnthropicProviderToolOptions as a4, type Citation as a5, type MessageAttachment as a6, type StreamTextResult as b, type Tool as c, type ToolDefinition as d, type ToolProfile as e, type StorageAdapter as f, type StreamEvent as g, type ToolCallInfo as h, type TokenUsageRaw as i, type ToolResponse as j, type StorageMessage as k, type ModelCapabilities as l, type DoGenerateParams as m, type DoGenerateResult as n, type SystemMessage as o, type AssistantMessage as p, type ToolMessage as q, type UserContentPart as r, type TextPart as s, type ToolCall as t, type ToolResult as u, type GenerateStep as v, type StreamPart as w, type StreamChunk as x, type TextDeltaChunk as y, type ToolCallChunk as z };
|