@yourgpt/llm-sdk 2.1.10-alpha.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 -38
- package/dist/adapters/index.d.ts +4 -38
- package/dist/adapters/index.js +158 -325
- package/dist/adapters/index.mjs +158 -325
- 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 +35 -43
- package/dist/index.mjs +35 -43
- 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 -212
- package/dist/providers/anthropic/index.mjs +271 -212
- 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 +254 -510
- package/dist/providers/google/index.mjs +254 -510
- 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 +269 -529
- package/dist/providers/openai/index.mjs +269 -529
- package/dist/providers/openrouter/index.d.mts +3 -7
- package/dist/providers/openrouter/index.d.ts +3 -7
- package/dist/providers/openrouter/index.js +365 -902
- package/dist/providers/openrouter/index.mjs +365 -902
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +259 -509
- package/dist/providers/togetherai/index.mjs +259 -509
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +258 -513
- package/dist/providers/xai/index.mjs +258 -513
- package/dist/{types-BNCmlJMs.d.mts → types-B6dhnguR.d.mts} +1 -1
- package/dist/{types-DhktekQ3.d.ts → types-BQ31QIsA.d.ts} +2 -1
- package/dist/{types-CMMQ8s2O.d.mts → types-BSSiJW2o.d.mts} +2 -1
- package/dist/{base-DN1EfKnE.d.mts → types-BkQCSiIt.d.mts} +388 -214
- package/dist/{base-DuUNxtVg.d.ts → types-BkQCSiIt.d.ts} +388 -214
- package/dist/{types-Pj-vpmoT.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-CMvvDo-E.d.mts +0 -428
- package/dist/types-CMvvDo-E.d.ts +0 -428
|
@@ -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,259 +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
|
-
reasoningEffort?: "low" | "medium" | "high";
|
|
541
|
-
}
|
|
542
|
-
/**
|
|
543
|
-
* Chat completion request
|
|
552
|
+
* A language model instance that can generate text.
|
|
553
|
+
* This is what provider functions like `openai('gpt-4o')` return.
|
|
544
554
|
*/
|
|
545
|
-
interface
|
|
546
|
-
/**
|
|
547
|
-
|
|
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;
|
|
548
562
|
/**
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
* This allows passing messages with tool_calls and tool role
|
|
563
|
+
* Generate a complete response (non-streaming)
|
|
564
|
+
* Used internally by generateText()
|
|
552
565
|
*/
|
|
553
|
-
|
|
554
|
-
/** Available actions/tools */
|
|
555
|
-
actions?: ActionDefinition[];
|
|
556
|
-
/** Full tool definitions for provider-native tool search / deferred loading paths. */
|
|
557
|
-
toolDefinitions?: ToolDefinition[];
|
|
558
|
-
/** System prompt */
|
|
559
|
-
systemPrompt?: string;
|
|
560
|
-
/** LLM configuration overrides */
|
|
561
|
-
config?: RequestLLMConfig;
|
|
562
|
-
/** Abort signal for cancellation */
|
|
563
|
-
signal?: AbortSignal;
|
|
566
|
+
doGenerate(params: DoGenerateParams): Promise<DoGenerateResult>;
|
|
564
567
|
/**
|
|
565
|
-
*
|
|
566
|
-
*
|
|
568
|
+
* Stream a response
|
|
569
|
+
* Used internally by streamText()
|
|
567
570
|
*/
|
|
568
|
-
|
|
569
|
-
/** Optional provider-specific tool policy hints derived from runtime selection. */
|
|
570
|
-
providerToolOptions?: ProviderToolRuntimeOptions;
|
|
571
|
-
/** Enable adapter-level provider payload logging. */
|
|
572
|
-
debug?: boolean;
|
|
571
|
+
doStream(params: DoGenerateParams): AsyncGenerator<StreamChunk>;
|
|
573
572
|
}
|
|
574
573
|
/**
|
|
575
|
-
*
|
|
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
|
|
576
600
|
*/
|
|
577
|
-
|
|
578
|
-
|
|
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;
|
|
579
618
|
content: string;
|
|
580
|
-
/** Tool calls */
|
|
581
|
-
toolCalls: Array<{
|
|
582
|
-
id: string;
|
|
583
|
-
name: string;
|
|
584
|
-
args: Record<string, unknown>;
|
|
585
|
-
/** Provider-specific metadata (e.g. Gemini 3 thought_signature in extra_content.google) */
|
|
586
|
-
extra_content?: Record<string, unknown>;
|
|
587
|
-
}>;
|
|
588
|
-
/** Thinking content (if extended thinking enabled) */
|
|
589
|
-
thinking?: string;
|
|
590
|
-
/** Token usage for billing/tracking */
|
|
591
|
-
usage?: TokenUsage;
|
|
592
|
-
/** Raw provider response for debugging */
|
|
593
|
-
rawResponse: Record<string, unknown>;
|
|
594
619
|
}
|
|
595
620
|
/**
|
|
596
|
-
*
|
|
621
|
+
* Content parts for multimodal user messages
|
|
597
622
|
*/
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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>;
|
|
607
652
|
/**
|
|
608
|
-
*
|
|
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
|
|
609
657
|
*/
|
|
610
|
-
|
|
658
|
+
hidden?: boolean;
|
|
611
659
|
}
|
|
612
660
|
/**
|
|
613
|
-
*
|
|
661
|
+
* Context passed to tool execute function
|
|
614
662
|
*/
|
|
615
|
-
|
|
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
|
+
}
|
|
616
671
|
/**
|
|
617
|
-
*
|
|
672
|
+
* Tool call from LLM response
|
|
618
673
|
*/
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
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
|
+
}
|
|
623
682
|
/**
|
|
624
|
-
*
|
|
683
|
+
* Tool execution result
|
|
625
684
|
*/
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
};
|
|
633
|
-
}>;
|
|
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
|
+
}
|
|
634
691
|
/**
|
|
635
|
-
*
|
|
692
|
+
* Parameters for model.doGenerate() and model.doStream()
|
|
636
693
|
*/
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
}
|
|
651
|
-
type: "document";
|
|
652
|
-
source: {
|
|
653
|
-
type: "base64";
|
|
654
|
-
media_type: string;
|
|
655
|
-
data: string;
|
|
656
|
-
} | {
|
|
657
|
-
type: "url";
|
|
658
|
-
url: string;
|
|
659
|
-
};
|
|
660
|
-
};
|
|
661
|
-
type OpenAIContentBlock = {
|
|
662
|
-
type: "text";
|
|
663
|
-
text: string;
|
|
664
|
-
} | {
|
|
665
|
-
type: "image_url";
|
|
666
|
-
image_url: {
|
|
667
|
-
url: string;
|
|
668
|
-
detail?: "low" | "high" | "auto";
|
|
669
|
-
};
|
|
670
|
-
};
|
|
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
|
+
}
|
|
671
708
|
/**
|
|
672
|
-
*
|
|
673
|
-
* Supports both new format (metadata.attachments) and legacy (attachments)
|
|
709
|
+
* Result from model.doGenerate()
|
|
674
710
|
*/
|
|
675
|
-
|
|
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
|
+
}
|
|
676
723
|
/**
|
|
677
|
-
*
|
|
724
|
+
* Finish reason for generation
|
|
678
725
|
*/
|
|
679
|
-
|
|
726
|
+
type FinishReason = "stop" | "length" | "tool-calls" | "content-filter" | "error" | "unknown";
|
|
680
727
|
/**
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
* Anthropic format:
|
|
684
|
-
* {
|
|
685
|
-
* type: "image",
|
|
686
|
-
* source: {
|
|
687
|
-
* type: "base64",
|
|
688
|
-
* media_type: "image/png",
|
|
689
|
-
* data: "base64data..."
|
|
690
|
-
* }
|
|
691
|
-
* }
|
|
692
|
-
*/
|
|
693
|
-
declare function attachmentToAnthropicImage(attachment: MessageAttachment): AnthropicContentBlock | null;
|
|
694
|
-
/**
|
|
695
|
-
* Convert MessageAttachment to OpenAI image_url content block
|
|
696
|
-
*
|
|
697
|
-
* OpenAI format:
|
|
698
|
-
* {
|
|
699
|
-
* type: "image_url",
|
|
700
|
-
* image_url: {
|
|
701
|
-
* url: "data:image/png;base64,..."
|
|
702
|
-
* }
|
|
703
|
-
* }
|
|
728
|
+
* Token usage statistics
|
|
704
729
|
*/
|
|
705
|
-
|
|
730
|
+
interface TokenUsage {
|
|
731
|
+
promptTokens: number;
|
|
732
|
+
completionTokens: number;
|
|
733
|
+
totalTokens: number;
|
|
734
|
+
}
|
|
706
735
|
/**
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
* Anthropic format:
|
|
710
|
-
* {
|
|
711
|
-
* type: "document",
|
|
712
|
-
* source: {
|
|
713
|
-
* type: "base64",
|
|
714
|
-
* media_type: "application/pdf",
|
|
715
|
-
* data: "base64data..."
|
|
716
|
-
* }
|
|
717
|
-
* }
|
|
736
|
+
* Stream chunk from model.doStream()
|
|
718
737
|
*/
|
|
719
|
-
|
|
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
|
+
}
|
|
720
761
|
/**
|
|
721
|
-
*
|
|
762
|
+
* Parameters for generateText()
|
|
722
763
|
*/
|
|
723
|
-
|
|
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
|
+
}
|
|
724
786
|
/**
|
|
725
|
-
*
|
|
787
|
+
* Result from generateText()
|
|
726
788
|
*/
|
|
727
|
-
|
|
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
|
+
}
|
|
728
807
|
/**
|
|
729
|
-
*
|
|
808
|
+
* A single step in the generation process
|
|
730
809
|
*/
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
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;
|
|
741
880
|
};
|
|
742
|
-
type AnthropicMessageContent = string | Array<AnthropicContentBlock | AnthropicToolUseBlock | AnthropicToolResultBlock>;
|
|
743
881
|
/**
|
|
744
|
-
*
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
system: string;
|
|
753
|
-
messages: Array<{
|
|
754
|
-
role: "user" | "assistant";
|
|
755
|
-
content: AnthropicMessageContent;
|
|
756
|
-
}>;
|
|
757
|
-
};
|
|
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
|
+
}
|
|
758
890
|
/**
|
|
759
|
-
*
|
|
891
|
+
* Message format for storage adapters.
|
|
892
|
+
* Intentionally simpler than LLM-specific formats — adapters convert as needed.
|
|
760
893
|
*/
|
|
761
|
-
|
|
762
|
-
role: "system";
|
|
894
|
+
interface StorageMessage {
|
|
895
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
763
896
|
content: string;
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
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<{
|
|
771
930
|
id: string;
|
|
772
|
-
type: "function";
|
|
773
|
-
function: {
|
|
774
|
-
name: string;
|
|
775
|
-
arguments: string;
|
|
776
|
-
};
|
|
777
931
|
}>;
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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
|
+
}
|
|
783
951
|
/**
|
|
784
|
-
*
|
|
785
|
-
* Handles: text, images, tool_calls, and tool results
|
|
952
|
+
* File data for upload via StorageAdapter.uploadFile()
|
|
786
953
|
*/
|
|
787
|
-
|
|
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
|
+
}
|
|
788
962
|
|
|
789
|
-
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 };
|