@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.
- package/README.md +19 -1
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +293 -23
- package/dist/adapters/index.mjs +293 -23
- package/dist/base-BYQKp9TW.d.mts +263 -0
- package/dist/base-Cxq3ni0t.d.ts +263 -0
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +61 -8
- package/dist/index.d.ts +61 -8
- package/dist/index.js +71 -0
- package/dist/index.mjs +71 -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 +360 -203
- package/dist/providers/anthropic/index.mjs +360 -203
- 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 +303 -207
- package/dist/providers/google/index.mjs +303 -207
- 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 +318 -216
- package/dist/providers/openai/index.mjs +318 -216
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +308 -206
- package/dist/providers/openrouter/index.mjs +308 -206
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +308 -206
- package/dist/providers/togetherai/index.mjs +308 -206
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +307 -210
- package/dist/providers/xai/index.mjs +307 -210
- package/dist/{types-BctsnC3g.d.ts → types-BvkiJ1dd.d.mts} +2 -1
- package/dist/{types-38yolWJn.d.ts → types-ChORafYS.d.ts} +1 -1
- package/dist/types-D774b0dg.d.mts +1018 -0
- package/dist/types-D774b0dg.d.ts +1018 -0
- package/dist/{types-DRqxMIjF.d.mts → types-TMilS-Dz.d.ts} +2 -1
- package/dist/{types-D4YfrQJR.d.mts → types-mwMhCwOq.d.mts} +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/base-D-U61JaB.d.mts +0 -788
- package/dist/base-iGi9Va6Z.d.ts +0 -788
- package/dist/types-CR8mi9I0.d.mts +0 -417
- package/dist/types-CR8mi9I0.d.ts +0 -417
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, d as
|
|
2
|
-
export {
|
|
1
|
+
import { G as GenerateTextParams, a as GenerateTextResult, S as StreamTextParams, b as StreamTextResult, T as ToolContext, c as Tool, A as ActionDefinition, d as ToolDefinition, e as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, f as StorageAdapter, R as ResponseFormat, M as McpServerConfig, g as ReasoningEffort, D as DoneEventMessage, h as StreamEvent, i as ToolCallInfo, j as TokenUsageRaw, P as ProviderToolRuntimeOptions, k as Message, l as ToolResponse, m as StorageMessage } from './types-D774b0dg.js';
|
|
2
|
+
export { a6 as AnthropicProviderToolOptions, a3 as AnthropicToolSelectionHints, r as AssistantMessage, a7 as Citation, C as CoreMessage, Y as DEFAULT_CAPABILITIES, o as DoGenerateParams, p as DoGenerateResult, N as ErrorChunk, F as FilePart, J as FinishChunk, Q as FinishReason, x as GenerateStep, I as ImagePart, Z as LLMConfig, L as LanguageModel, n as ModelCapabilities, a5 as OpenAIProviderToolOptions, a2 as OpenAIToolSelectionHints, V as ResponseOptions, X as StorageFile, z as StreamChunk, y as StreamPart, q as SystemMessage, B as TextDeltaChunk, u as TextPart, O as TokenUsage, v as ToolCall, E as ToolCallChunk, a1 as ToolExecution, _ as ToolLocation, s as ToolMessage, a4 as ToolNativeProviderHints, w as ToolResult, H as ToolResultChunk, $ as UnifiedToolCall, a0 as UnifiedToolResult, t as UserContentPart, U as UserMessage } from './types-D774b0dg.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as
|
|
5
|
-
export {
|
|
6
|
-
import {
|
|
7
|
-
export {
|
|
4
|
+
import { A as AIProvider } from './types-TMilS-Dz.js';
|
|
5
|
+
export { a as AnthropicProviderConfig, f as AnthropicTool, h as AnthropicToolResult, g as AnthropicToolUse, b as AzureProviderConfig, B as BaseProviderConfig, m as GeminiFunctionCall, l as GeminiFunctionDeclaration, n as GeminiFunctionResponse, G as GoogleProviderConfig, d as OllamaModelOptions, c as OllamaProviderConfig, O as OpenAIProviderConfig, i as OpenAITool, j as OpenAIToolCall, k as OpenAIToolResult, P as ProviderCapabilities, e as ProviderFormatter, X as XAIProviderConfig } from './types-TMilS-Dz.js';
|
|
6
|
+
import { L as LLMAdapter } from './base-Cxq3ni0t.js';
|
|
7
|
+
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-Cxq3ni0t.js';
|
|
8
8
|
import * as hono from 'hono';
|
|
9
9
|
import { Hono } from 'hono';
|
|
10
|
-
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-
|
|
10
|
+
export { F as FallbackChainConfig, c as FallbackFailure, d as FallbackInfo, b as RetryBackoff, e as RetryInfo, R as RoutingStore, a as RoutingStrategy } from './types-ChORafYS.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* generateText - Generate text using a language model
|
|
@@ -388,6 +388,9 @@ interface ChatRequest {
|
|
|
388
388
|
config?: {
|
|
389
389
|
temperature?: number;
|
|
390
390
|
maxTokens?: number;
|
|
391
|
+
responseFormat?: ResponseFormat;
|
|
392
|
+
mcpServers?: McpServerConfig[];
|
|
393
|
+
reasoningEffort?: ReasoningEffort;
|
|
391
394
|
};
|
|
392
395
|
/** System prompt override */
|
|
393
396
|
systemPrompt?: string;
|
|
@@ -797,6 +800,11 @@ declare function createStreamResult(generator: AsyncGenerator<StreamEvent>): Str
|
|
|
797
800
|
* ```
|
|
798
801
|
*/
|
|
799
802
|
|
|
803
|
+
interface GenerateUsage {
|
|
804
|
+
promptTokens: number;
|
|
805
|
+
completionTokens: number;
|
|
806
|
+
totalTokens: number;
|
|
807
|
+
}
|
|
800
808
|
interface GenerateResultData {
|
|
801
809
|
text: string;
|
|
802
810
|
messages: DoneEventMessage[];
|
|
@@ -810,6 +818,7 @@ interface GenerateResultData {
|
|
|
810
818
|
result: unknown;
|
|
811
819
|
}>;
|
|
812
820
|
requiresAction: boolean;
|
|
821
|
+
usage?: GenerateUsage;
|
|
813
822
|
error?: {
|
|
814
823
|
message: string;
|
|
815
824
|
code?: string;
|
|
@@ -863,6 +872,12 @@ declare class GenerateResult {
|
|
|
863
872
|
* Whether client action is required (e.g., tool approval)
|
|
864
873
|
*/
|
|
865
874
|
get requiresAction(): boolean;
|
|
875
|
+
/**
|
|
876
|
+
* Token usage for the call — present when the underlying provider emitted
|
|
877
|
+
* a usage payload on the `done` event. May be undefined for streaming
|
|
878
|
+
* responses that don't yield usage (e.g. mid-stream errors).
|
|
879
|
+
*/
|
|
880
|
+
get usage(): GenerateUsage | undefined;
|
|
866
881
|
/**
|
|
867
882
|
* Error if generation failed
|
|
868
883
|
*/
|
|
@@ -1122,6 +1137,44 @@ declare class Runtime {
|
|
|
1122
1137
|
* ```
|
|
1123
1138
|
*/
|
|
1124
1139
|
generate(request: ChatRequest, options?: GenerateOptions): Promise<GenerateResult>;
|
|
1140
|
+
/**
|
|
1141
|
+
* One-shot non-streaming call bundling MCP servers, reasoning effort, and
|
|
1142
|
+
* structured output. Thin ergonomic wrapper around `generate()` — uses the
|
|
1143
|
+
* same adapter chain and the same translators, just expressed as a single
|
|
1144
|
+
* prompt-in / text-out call.
|
|
1145
|
+
*
|
|
1146
|
+
* @example
|
|
1147
|
+
* ```ts
|
|
1148
|
+
* const result = await runtime.response({
|
|
1149
|
+
* prompt: "Extract FAQs from this conversation.",
|
|
1150
|
+
* mcpServers: [{ label: "kb", url: "https://kb.example.com/sse", headers: { Authorization: token } }],
|
|
1151
|
+
* reasoningEffort: "high",
|
|
1152
|
+
* responseFormat: { type: "json_schema", json_schema: { name: "faqs", schema } },
|
|
1153
|
+
* });
|
|
1154
|
+
* const data = JSON.parse(result.text);
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
1157
|
+
response(request: {
|
|
1158
|
+
prompt: string;
|
|
1159
|
+
systemPrompt?: string;
|
|
1160
|
+
mcpServers?: McpServerConfig[];
|
|
1161
|
+
reasoningEffort?: ReasoningEffort;
|
|
1162
|
+
responseFormat?: ResponseFormat;
|
|
1163
|
+
maxTokens?: number;
|
|
1164
|
+
temperature?: number;
|
|
1165
|
+
}): Promise<{
|
|
1166
|
+
text: string;
|
|
1167
|
+
toolCalls: Array<{
|
|
1168
|
+
id: string;
|
|
1169
|
+
name: string;
|
|
1170
|
+
args: Record<string, unknown>;
|
|
1171
|
+
}>;
|
|
1172
|
+
usage?: {
|
|
1173
|
+
promptTokens: number;
|
|
1174
|
+
completionTokens: number;
|
|
1175
|
+
totalTokens: number;
|
|
1176
|
+
};
|
|
1177
|
+
}>;
|
|
1125
1178
|
/**
|
|
1126
1179
|
* Create Express-compatible handler middleware
|
|
1127
1180
|
*
|
|
@@ -1536,4 +1589,4 @@ declare function generateThreadId(): string;
|
|
|
1536
1589
|
*/
|
|
1537
1590
|
declare function generateToolCallId(): string;
|
|
1538
1591
|
|
|
1539
|
-
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, Message, ProviderToolRuntimeOptions, type RequestContext, Runtime, type RuntimeConfig, StorageAdapter, StorageMessage, StreamEvent, StreamResult, type StreamResultOptions, StreamTextParams, StreamTextResult, TokenUsageRaw, Tool, ToolCallInfo, ToolContext, ToolDefinition, ToolProfile, ToolResponse, type ToolSearchMatch, WebSearchConfig, buildProviderToolOptions, createEventStream, createExpressHandler, createExpressMiddleware, createHonoApp, createNextHandler, createNodeHandler, createRuntime, createSSEHeaders, createSSEResponse, createStreamResult, createTextStreamHeaders, createTextStreamResponse, extractInputMessages, formatSSEData, formatToolsForAnthropic, formatToolsForGoogle, formatToolsForOpenAI, generateMessageId, generateText, generateThreadId, generateToolCallId, mapOutputMessages, pipeSSEToResponse, pipeTextToResponse, runAgentLoop, searchTools, selectTools, shouldExposeToolSearch, streamText, tool };
|
|
1592
|
+
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter, McpServerConfig, Message, ProviderToolRuntimeOptions, ReasoningEffort, type RequestContext, ResponseFormat, Runtime, type RuntimeConfig, StorageAdapter, StorageMessage, StreamEvent, StreamResult, type StreamResultOptions, StreamTextParams, StreamTextResult, TokenUsageRaw, Tool, ToolCallInfo, ToolContext, ToolDefinition, ToolProfile, ToolResponse, type ToolSearchMatch, WebSearchConfig, buildProviderToolOptions, createEventStream, createExpressHandler, createExpressMiddleware, createHonoApp, createNextHandler, createNodeHandler, createRuntime, createSSEHeaders, createSSEResponse, createStreamResult, createTextStreamHeaders, createTextStreamResponse, extractInputMessages, formatSSEData, formatToolsForAnthropic, formatToolsForGoogle, formatToolsForOpenAI, generateMessageId, generateText, generateThreadId, generateToolCallId, mapOutputMessages, pipeSSEToResponse, pipeTextToResponse, runAgentLoop, searchTools, selectTools, shouldExposeToolSearch, streamText, tool };
|
package/dist/index.js
CHANGED
|
@@ -135,6 +135,11 @@ function formatToolsForGoogle(tools) {
|
|
|
135
135
|
// src/core/generate-text.ts
|
|
136
136
|
async function generateText(params) {
|
|
137
137
|
const { model, tools, maxSteps = 1, signal } = params;
|
|
138
|
+
if (params.responseFormat && model.capabilities.supportsJsonMode === false) {
|
|
139
|
+
console.warn(
|
|
140
|
+
`[llm-sdk] ${model.provider}/${model.modelId} does not support structured output (responseFormat); the request will be sent but the provider may ignore it.`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
138
143
|
let messages = buildMessages(params);
|
|
139
144
|
const steps = [];
|
|
140
145
|
const allToolCalls = [];
|
|
@@ -149,6 +154,9 @@ async function generateText(params) {
|
|
|
149
154
|
tools: formattedTools,
|
|
150
155
|
temperature: params.temperature,
|
|
151
156
|
maxTokens: params.maxTokens,
|
|
157
|
+
responseFormat: params.responseFormat,
|
|
158
|
+
mcpServers: params.mcpServers,
|
|
159
|
+
reasoningEffort: params.reasoningEffort,
|
|
152
160
|
signal
|
|
153
161
|
});
|
|
154
162
|
const stepToolResults = [];
|
|
@@ -266,6 +274,11 @@ function sumUsage(steps) {
|
|
|
266
274
|
// src/core/stream-text.ts
|
|
267
275
|
async function streamText(params) {
|
|
268
276
|
const { model, tools, maxSteps = 1, signal } = params;
|
|
277
|
+
if (params.responseFormat && model.capabilities.supportsJsonMode === false) {
|
|
278
|
+
console.warn(
|
|
279
|
+
`[llm-sdk] ${model.provider}/${model.modelId} does not support structured output (responseFormat); the request will be sent but the provider may ignore it.`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
269
282
|
let fullText = "";
|
|
270
283
|
let finalUsage = {
|
|
271
284
|
promptTokens: 0,
|
|
@@ -291,6 +304,9 @@ async function streamText(params) {
|
|
|
291
304
|
tools: formattedTools,
|
|
292
305
|
temperature: params.temperature,
|
|
293
306
|
maxTokens: params.maxTokens,
|
|
307
|
+
responseFormat: params.responseFormat,
|
|
308
|
+
mcpServers: params.mcpServers,
|
|
309
|
+
reasoningEffort: params.reasoningEffort,
|
|
294
310
|
signal
|
|
295
311
|
})) {
|
|
296
312
|
switch (chunk.type) {
|
|
@@ -1159,6 +1175,14 @@ var GenerateResult = class {
|
|
|
1159
1175
|
get requiresAction() {
|
|
1160
1176
|
return this.data.requiresAction;
|
|
1161
1177
|
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Token usage for the call — present when the underlying provider emitted
|
|
1180
|
+
* a usage payload on the `done` event. May be undefined for streaming
|
|
1181
|
+
* responses that don't yield usage (e.g. mid-stream errors).
|
|
1182
|
+
*/
|
|
1183
|
+
get usage() {
|
|
1184
|
+
return this.data.usage;
|
|
1185
|
+
}
|
|
1162
1186
|
/**
|
|
1163
1187
|
* Error if generation failed
|
|
1164
1188
|
*/
|
|
@@ -2945,6 +2969,7 @@ var Runtime = class {
|
|
|
2945
2969
|
const toolResults = [];
|
|
2946
2970
|
let messages = [];
|
|
2947
2971
|
let requiresAction = false;
|
|
2972
|
+
let usage;
|
|
2948
2973
|
let error;
|
|
2949
2974
|
try {
|
|
2950
2975
|
for await (const event of generator) {
|
|
@@ -2975,6 +3000,13 @@ var Runtime = class {
|
|
|
2975
3000
|
case "done":
|
|
2976
3001
|
messages = event.messages || [];
|
|
2977
3002
|
requiresAction = event.requiresAction || false;
|
|
3003
|
+
if (event.usage) {
|
|
3004
|
+
usage = {
|
|
3005
|
+
promptTokens: event.usage.prompt_tokens,
|
|
3006
|
+
completionTokens: event.usage.completion_tokens,
|
|
3007
|
+
totalTokens: event.usage.total_tokens ?? event.usage.prompt_tokens + event.usage.completion_tokens
|
|
3008
|
+
};
|
|
3009
|
+
}
|
|
2978
3010
|
break;
|
|
2979
3011
|
case "error":
|
|
2980
3012
|
error = { message: event.message, code: event.code };
|
|
@@ -3006,9 +3038,48 @@ var Runtime = class {
|
|
|
3006
3038
|
toolCalls,
|
|
3007
3039
|
toolResults,
|
|
3008
3040
|
requiresAction,
|
|
3041
|
+
usage,
|
|
3009
3042
|
error
|
|
3010
3043
|
});
|
|
3011
3044
|
}
|
|
3045
|
+
/**
|
|
3046
|
+
* One-shot non-streaming call bundling MCP servers, reasoning effort, and
|
|
3047
|
+
* structured output. Thin ergonomic wrapper around `generate()` — uses the
|
|
3048
|
+
* same adapter chain and the same translators, just expressed as a single
|
|
3049
|
+
* prompt-in / text-out call.
|
|
3050
|
+
*
|
|
3051
|
+
* @example
|
|
3052
|
+
* ```ts
|
|
3053
|
+
* const result = await runtime.response({
|
|
3054
|
+
* prompt: "Extract FAQs from this conversation.",
|
|
3055
|
+
* mcpServers: [{ label: "kb", url: "https://kb.example.com/sse", headers: { Authorization: token } }],
|
|
3056
|
+
* reasoningEffort: "high",
|
|
3057
|
+
* responseFormat: { type: "json_schema", json_schema: { name: "faqs", schema } },
|
|
3058
|
+
* });
|
|
3059
|
+
* const data = JSON.parse(result.text);
|
|
3060
|
+
* ```
|
|
3061
|
+
*/
|
|
3062
|
+
async response(request) {
|
|
3063
|
+
const result = await this.generate({
|
|
3064
|
+
messages: [{ role: "user", content: request.prompt }],
|
|
3065
|
+
systemPrompt: request.systemPrompt,
|
|
3066
|
+
config: {
|
|
3067
|
+
temperature: request.temperature,
|
|
3068
|
+
maxTokens: request.maxTokens,
|
|
3069
|
+
responseFormat: request.responseFormat,
|
|
3070
|
+
mcpServers: request.mcpServers,
|
|
3071
|
+
reasoningEffort: request.reasoningEffort
|
|
3072
|
+
}
|
|
3073
|
+
});
|
|
3074
|
+
if (result.error) {
|
|
3075
|
+
throw new Error(`[llm-sdk] response() failed: ${result.error.message}`);
|
|
3076
|
+
}
|
|
3077
|
+
return {
|
|
3078
|
+
text: result.text,
|
|
3079
|
+
toolCalls: result.toolCalls,
|
|
3080
|
+
usage: result.usage
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3012
3083
|
/**
|
|
3013
3084
|
* Create Express-compatible handler middleware
|
|
3014
3085
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -133,6 +133,11 @@ function formatToolsForGoogle(tools) {
|
|
|
133
133
|
// src/core/generate-text.ts
|
|
134
134
|
async function generateText(params) {
|
|
135
135
|
const { model, tools, maxSteps = 1, signal } = params;
|
|
136
|
+
if (params.responseFormat && model.capabilities.supportsJsonMode === false) {
|
|
137
|
+
console.warn(
|
|
138
|
+
`[llm-sdk] ${model.provider}/${model.modelId} does not support structured output (responseFormat); the request will be sent but the provider may ignore it.`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
136
141
|
let messages = buildMessages(params);
|
|
137
142
|
const steps = [];
|
|
138
143
|
const allToolCalls = [];
|
|
@@ -147,6 +152,9 @@ async function generateText(params) {
|
|
|
147
152
|
tools: formattedTools,
|
|
148
153
|
temperature: params.temperature,
|
|
149
154
|
maxTokens: params.maxTokens,
|
|
155
|
+
responseFormat: params.responseFormat,
|
|
156
|
+
mcpServers: params.mcpServers,
|
|
157
|
+
reasoningEffort: params.reasoningEffort,
|
|
150
158
|
signal
|
|
151
159
|
});
|
|
152
160
|
const stepToolResults = [];
|
|
@@ -264,6 +272,11 @@ function sumUsage(steps) {
|
|
|
264
272
|
// src/core/stream-text.ts
|
|
265
273
|
async function streamText(params) {
|
|
266
274
|
const { model, tools, maxSteps = 1, signal } = params;
|
|
275
|
+
if (params.responseFormat && model.capabilities.supportsJsonMode === false) {
|
|
276
|
+
console.warn(
|
|
277
|
+
`[llm-sdk] ${model.provider}/${model.modelId} does not support structured output (responseFormat); the request will be sent but the provider may ignore it.`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
267
280
|
let fullText = "";
|
|
268
281
|
let finalUsage = {
|
|
269
282
|
promptTokens: 0,
|
|
@@ -289,6 +302,9 @@ async function streamText(params) {
|
|
|
289
302
|
tools: formattedTools,
|
|
290
303
|
temperature: params.temperature,
|
|
291
304
|
maxTokens: params.maxTokens,
|
|
305
|
+
responseFormat: params.responseFormat,
|
|
306
|
+
mcpServers: params.mcpServers,
|
|
307
|
+
reasoningEffort: params.reasoningEffort,
|
|
292
308
|
signal
|
|
293
309
|
})) {
|
|
294
310
|
switch (chunk.type) {
|
|
@@ -1157,6 +1173,14 @@ var GenerateResult = class {
|
|
|
1157
1173
|
get requiresAction() {
|
|
1158
1174
|
return this.data.requiresAction;
|
|
1159
1175
|
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Token usage for the call — present when the underlying provider emitted
|
|
1178
|
+
* a usage payload on the `done` event. May be undefined for streaming
|
|
1179
|
+
* responses that don't yield usage (e.g. mid-stream errors).
|
|
1180
|
+
*/
|
|
1181
|
+
get usage() {
|
|
1182
|
+
return this.data.usage;
|
|
1183
|
+
}
|
|
1160
1184
|
/**
|
|
1161
1185
|
* Error if generation failed
|
|
1162
1186
|
*/
|
|
@@ -2943,6 +2967,7 @@ var Runtime = class {
|
|
|
2943
2967
|
const toolResults = [];
|
|
2944
2968
|
let messages = [];
|
|
2945
2969
|
let requiresAction = false;
|
|
2970
|
+
let usage;
|
|
2946
2971
|
let error;
|
|
2947
2972
|
try {
|
|
2948
2973
|
for await (const event of generator) {
|
|
@@ -2973,6 +2998,13 @@ var Runtime = class {
|
|
|
2973
2998
|
case "done":
|
|
2974
2999
|
messages = event.messages || [];
|
|
2975
3000
|
requiresAction = event.requiresAction || false;
|
|
3001
|
+
if (event.usage) {
|
|
3002
|
+
usage = {
|
|
3003
|
+
promptTokens: event.usage.prompt_tokens,
|
|
3004
|
+
completionTokens: event.usage.completion_tokens,
|
|
3005
|
+
totalTokens: event.usage.total_tokens ?? event.usage.prompt_tokens + event.usage.completion_tokens
|
|
3006
|
+
};
|
|
3007
|
+
}
|
|
2976
3008
|
break;
|
|
2977
3009
|
case "error":
|
|
2978
3010
|
error = { message: event.message, code: event.code };
|
|
@@ -3004,9 +3036,48 @@ var Runtime = class {
|
|
|
3004
3036
|
toolCalls,
|
|
3005
3037
|
toolResults,
|
|
3006
3038
|
requiresAction,
|
|
3039
|
+
usage,
|
|
3007
3040
|
error
|
|
3008
3041
|
});
|
|
3009
3042
|
}
|
|
3043
|
+
/**
|
|
3044
|
+
* One-shot non-streaming call bundling MCP servers, reasoning effort, and
|
|
3045
|
+
* structured output. Thin ergonomic wrapper around `generate()` — uses the
|
|
3046
|
+
* same adapter chain and the same translators, just expressed as a single
|
|
3047
|
+
* prompt-in / text-out call.
|
|
3048
|
+
*
|
|
3049
|
+
* @example
|
|
3050
|
+
* ```ts
|
|
3051
|
+
* const result = await runtime.response({
|
|
3052
|
+
* prompt: "Extract FAQs from this conversation.",
|
|
3053
|
+
* mcpServers: [{ label: "kb", url: "https://kb.example.com/sse", headers: { Authorization: token } }],
|
|
3054
|
+
* reasoningEffort: "high",
|
|
3055
|
+
* responseFormat: { type: "json_schema", json_schema: { name: "faqs", schema } },
|
|
3056
|
+
* });
|
|
3057
|
+
* const data = JSON.parse(result.text);
|
|
3058
|
+
* ```
|
|
3059
|
+
*/
|
|
3060
|
+
async response(request) {
|
|
3061
|
+
const result = await this.generate({
|
|
3062
|
+
messages: [{ role: "user", content: request.prompt }],
|
|
3063
|
+
systemPrompt: request.systemPrompt,
|
|
3064
|
+
config: {
|
|
3065
|
+
temperature: request.temperature,
|
|
3066
|
+
maxTokens: request.maxTokens,
|
|
3067
|
+
responseFormat: request.responseFormat,
|
|
3068
|
+
mcpServers: request.mcpServers,
|
|
3069
|
+
reasoningEffort: request.reasoningEffort
|
|
3070
|
+
}
|
|
3071
|
+
});
|
|
3072
|
+
if (result.error) {
|
|
3073
|
+
throw new Error(`[llm-sdk] response() failed: ${result.error.message}`);
|
|
3074
|
+
}
|
|
3075
|
+
return {
|
|
3076
|
+
text: result.text,
|
|
3077
|
+
toolCalls: result.toolCalls,
|
|
3078
|
+
usage: result.usage
|
|
3079
|
+
};
|
|
3080
|
+
}
|
|
3010
3081
|
/**
|
|
3011
3082
|
* Create Express-compatible handler middleware
|
|
3012
3083
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LanguageModel } from '../../types-
|
|
2
|
-
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-
|
|
1
|
+
import { L as LanguageModel } from '../../types-D774b0dg.mjs';
|
|
2
|
+
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-BvkiJ1dd.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-BYQKp9TW.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Anthropic Provider - Modern Pattern
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { L as LanguageModel } from '../../types-
|
|
2
|
-
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-
|
|
1
|
+
import { L as LanguageModel } from '../../types-D774b0dg.js';
|
|
2
|
+
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-TMilS-Dz.js';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-Cxq3ni0t.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Anthropic Provider - Modern Pattern
|