@yourgpt/llm-sdk 2.5.1-beta.1 → 2.5.1-beta.2
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 +1 -19
- package/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/adapters/index.js +14 -139
- package/dist/adapters/index.mjs +14 -139
- package/dist/{base-Cxq3ni0t.d.ts → base-C58Dsr9p.d.ts} +1 -5
- package/dist/{base-BYQKp9TW.d.mts → base-tNgbBaSo.d.mts} +1 -5
- package/dist/fallback/index.d.mts +4 -4
- package/dist/fallback/index.d.ts +4 -4
- package/dist/index.d.mts +8 -60
- package/dist/index.d.ts +8 -60
- package/dist/index.js +0 -59
- package/dist/index.mjs +0 -59
- package/dist/providers/anthropic/index.d.mts +3 -3
- package/dist/providers/anthropic/index.d.ts +3 -3
- package/dist/providers/anthropic/index.js +10 -91
- package/dist/providers/anthropic/index.mjs +10 -91
- package/dist/providers/azure/index.d.mts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +1 -0
- package/dist/providers/azure/index.mjs +1 -0
- package/dist/providers/fireworks/index.d.mts +1 -1
- package/dist/providers/fireworks/index.d.ts +1 -1
- package/dist/providers/fireworks/index.js +1 -0
- package/dist/providers/fireworks/index.mjs +1 -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 +3 -51
- package/dist/providers/google/index.mjs +3 -51
- package/dist/providers/ollama/index.d.mts +4 -4
- package/dist/providers/ollama/index.d.ts +4 -4
- package/dist/providers/ollama/index.js +1 -0
- package/dist/providers/ollama/index.mjs +1 -0
- package/dist/providers/openai/index.d.mts +3 -3
- package/dist/providers/openai/index.d.ts +3 -3
- package/dist/providers/openai/index.js +3 -51
- package/dist/providers/openai/index.mjs +3 -51
- package/dist/providers/openrouter/index.d.mts +3 -3
- package/dist/providers/openrouter/index.d.ts +3 -3
- package/dist/providers/openrouter/index.js +3 -51
- package/dist/providers/openrouter/index.mjs +3 -51
- package/dist/providers/togetherai/index.d.mts +3 -3
- package/dist/providers/togetherai/index.d.ts +3 -3
- package/dist/providers/togetherai/index.js +3 -51
- package/dist/providers/togetherai/index.mjs +3 -51
- package/dist/providers/xai/index.d.mts +3 -3
- package/dist/providers/xai/index.d.ts +3 -3
- package/dist/providers/xai/index.js +3 -51
- package/dist/providers/xai/index.mjs +3 -51
- package/dist/{types-mwMhCwOq.d.mts → types-B6dhnguR.d.mts} +1 -1
- package/dist/{types-TMilS-Dz.d.ts → types-BQ31QIsA.d.ts} +2 -2
- package/dist/{types-BvkiJ1dd.d.mts → types-BSSiJW2o.d.mts} +2 -2
- package/dist/{types-D774b0dg.d.mts → types-BkQCSiIt.d.mts} +2 -57
- package/dist/{types-D774b0dg.d.ts → types-BkQCSiIt.d.ts} +2 -57
- package/dist/{types-ChORafYS.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/index.d.mts
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, A as ActionDefinition, d as ToolDefinition, e as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, f as StorageAdapter, R as ResponseFormat,
|
|
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, D as DoneEventMessage, g as StreamEvent, h as ToolCallInfo, i as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, j as ToolResponse, k as StorageMessage } from './types-BkQCSiIt.mjs';
|
|
2
|
+
export { a4 as AnthropicProviderToolOptions, a1 as AnthropicToolSelectionHints, p as AssistantMessage, a5 as Citation, C as CoreMessage, V as DEFAULT_CAPABILITIES, m as DoGenerateParams, n as DoGenerateResult, H as ErrorChunk, F as FilePart, E as FinishChunk, N as FinishReason, v as GenerateStep, I as ImagePart, X as LLMConfig, L as LanguageModel, l as ModelCapabilities, a3 as OpenAIProviderToolOptions, a0 as OpenAIToolSelectionHints, O as ResponseOptions, Q as StorageFile, x as StreamChunk, w as StreamPart, o as SystemMessage, y as TextDeltaChunk, s as TextPart, J as TokenUsage, t as ToolCall, z as ToolCallChunk, $ as ToolExecution, Y as ToolLocation, q as ToolMessage, a2 as ToolNativeProviderHints, u as ToolResult, B as ToolResultChunk, Z as UnifiedToolCall, _ as UnifiedToolResult, r as UserContentPart, U as UserMessage } from './types-BkQCSiIt.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as AIProvider } from './types-
|
|
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-
|
|
6
|
-
import { L as LLMAdapter } from './base-
|
|
7
|
-
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-
|
|
4
|
+
import { A as AIProvider } from './types-BSSiJW2o.mjs';
|
|
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-BSSiJW2o.mjs';
|
|
6
|
+
import { L as LLMAdapter } from './base-tNgbBaSo.mjs';
|
|
7
|
+
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-tNgbBaSo.mjs';
|
|
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-B6dhnguR.mjs';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* generateText - Generate text using a language model
|
|
@@ -389,8 +389,6 @@ interface ChatRequest {
|
|
|
389
389
|
temperature?: number;
|
|
390
390
|
maxTokens?: number;
|
|
391
391
|
responseFormat?: ResponseFormat;
|
|
392
|
-
mcpServers?: McpServerConfig[];
|
|
393
|
-
reasoningEffort?: ReasoningEffort;
|
|
394
392
|
};
|
|
395
393
|
/** System prompt override */
|
|
396
394
|
systemPrompt?: string;
|
|
@@ -800,11 +798,6 @@ declare function createStreamResult(generator: AsyncGenerator<StreamEvent>): Str
|
|
|
800
798
|
* ```
|
|
801
799
|
*/
|
|
802
800
|
|
|
803
|
-
interface GenerateUsage {
|
|
804
|
-
promptTokens: number;
|
|
805
|
-
completionTokens: number;
|
|
806
|
-
totalTokens: number;
|
|
807
|
-
}
|
|
808
801
|
interface GenerateResultData {
|
|
809
802
|
text: string;
|
|
810
803
|
messages: DoneEventMessage[];
|
|
@@ -818,7 +811,6 @@ interface GenerateResultData {
|
|
|
818
811
|
result: unknown;
|
|
819
812
|
}>;
|
|
820
813
|
requiresAction: boolean;
|
|
821
|
-
usage?: GenerateUsage;
|
|
822
814
|
error?: {
|
|
823
815
|
message: string;
|
|
824
816
|
code?: string;
|
|
@@ -872,12 +864,6 @@ declare class GenerateResult {
|
|
|
872
864
|
* Whether client action is required (e.g., tool approval)
|
|
873
865
|
*/
|
|
874
866
|
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;
|
|
881
867
|
/**
|
|
882
868
|
* Error if generation failed
|
|
883
869
|
*/
|
|
@@ -1137,44 +1123,6 @@ declare class Runtime {
|
|
|
1137
1123
|
* ```
|
|
1138
1124
|
*/
|
|
1139
1125
|
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
|
-
}>;
|
|
1178
1126
|
/**
|
|
1179
1127
|
* Create Express-compatible handler middleware
|
|
1180
1128
|
*
|
|
@@ -1589,4 +1537,4 @@ declare function generateThreadId(): string;
|
|
|
1589
1537
|
*/
|
|
1590
1538
|
declare function generateToolCallId(): string;
|
|
1591
1539
|
|
|
1592
|
-
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter,
|
|
1540
|
+
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 };
|
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, A as ActionDefinition, d as ToolDefinition, e as ToolProfile, K as KnowledgeBaseConfig, W as WebSearchConfig, f as StorageAdapter, R as ResponseFormat,
|
|
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, D as DoneEventMessage, g as StreamEvent, h as ToolCallInfo, i as TokenUsageRaw, P as ProviderToolRuntimeOptions, M as Message, j as ToolResponse, k as StorageMessage } from './types-BkQCSiIt.js';
|
|
2
|
+
export { a4 as AnthropicProviderToolOptions, a1 as AnthropicToolSelectionHints, p as AssistantMessage, a5 as Citation, C as CoreMessage, V as DEFAULT_CAPABILITIES, m as DoGenerateParams, n as DoGenerateResult, H as ErrorChunk, F as FilePart, E as FinishChunk, N as FinishReason, v as GenerateStep, I as ImagePart, X as LLMConfig, L as LanguageModel, l as ModelCapabilities, a3 as OpenAIProviderToolOptions, a0 as OpenAIToolSelectionHints, O as ResponseOptions, Q as StorageFile, x as StreamChunk, w as StreamPart, o as SystemMessage, y as TextDeltaChunk, s as TextPart, J as TokenUsage, t as ToolCall, z as ToolCallChunk, $ as ToolExecution, Y as ToolLocation, q as ToolMessage, a2 as ToolNativeProviderHints, u as ToolResult, B as ToolResultChunk, Z as UnifiedToolCall, _ as UnifiedToolResult, r as UserContentPart, U as UserMessage } from './types-BkQCSiIt.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { A as AIProvider } from './types-
|
|
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-
|
|
6
|
-
import { L as LLMAdapter } from './base-
|
|
7
|
-
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-
|
|
4
|
+
import { A as AIProvider } from './types-BQ31QIsA.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-BQ31QIsA.js';
|
|
6
|
+
import { L as LLMAdapter } from './base-C58Dsr9p.js';
|
|
7
|
+
export { A as AdapterFactory, C as ChatCompletionRequest } from './base-C58Dsr9p.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-CCxPmkmK.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* generateText - Generate text using a language model
|
|
@@ -389,8 +389,6 @@ interface ChatRequest {
|
|
|
389
389
|
temperature?: number;
|
|
390
390
|
maxTokens?: number;
|
|
391
391
|
responseFormat?: ResponseFormat;
|
|
392
|
-
mcpServers?: McpServerConfig[];
|
|
393
|
-
reasoningEffort?: ReasoningEffort;
|
|
394
392
|
};
|
|
395
393
|
/** System prompt override */
|
|
396
394
|
systemPrompt?: string;
|
|
@@ -800,11 +798,6 @@ declare function createStreamResult(generator: AsyncGenerator<StreamEvent>): Str
|
|
|
800
798
|
* ```
|
|
801
799
|
*/
|
|
802
800
|
|
|
803
|
-
interface GenerateUsage {
|
|
804
|
-
promptTokens: number;
|
|
805
|
-
completionTokens: number;
|
|
806
|
-
totalTokens: number;
|
|
807
|
-
}
|
|
808
801
|
interface GenerateResultData {
|
|
809
802
|
text: string;
|
|
810
803
|
messages: DoneEventMessage[];
|
|
@@ -818,7 +811,6 @@ interface GenerateResultData {
|
|
|
818
811
|
result: unknown;
|
|
819
812
|
}>;
|
|
820
813
|
requiresAction: boolean;
|
|
821
|
-
usage?: GenerateUsage;
|
|
822
814
|
error?: {
|
|
823
815
|
message: string;
|
|
824
816
|
code?: string;
|
|
@@ -872,12 +864,6 @@ declare class GenerateResult {
|
|
|
872
864
|
* Whether client action is required (e.g., tool approval)
|
|
873
865
|
*/
|
|
874
866
|
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;
|
|
881
867
|
/**
|
|
882
868
|
* Error if generation failed
|
|
883
869
|
*/
|
|
@@ -1137,44 +1123,6 @@ declare class Runtime {
|
|
|
1137
1123
|
* ```
|
|
1138
1124
|
*/
|
|
1139
1125
|
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
|
-
}>;
|
|
1178
1126
|
/**
|
|
1179
1127
|
* Create Express-compatible handler middleware
|
|
1180
1128
|
*
|
|
@@ -1589,4 +1537,4 @@ declare function generateThreadId(): string;
|
|
|
1589
1537
|
*/
|
|
1590
1538
|
declare function generateToolCallId(): string;
|
|
1591
1539
|
|
|
1592
|
-
export { AIProvider, ActionDefinition, type ActionRequest, type AgentLoopOptions, type ChatRequest, type CollectedResult, type CopilotChatResponse, DEFAULT_MAX_ITERATIONS, DoneEventMessage, GenerateResult, type GenerateResultData, GenerateTextParams, GenerateTextResult, LLMAdapter,
|
|
1540
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -155,8 +155,6 @@ async function generateText(params) {
|
|
|
155
155
|
temperature: params.temperature,
|
|
156
156
|
maxTokens: params.maxTokens,
|
|
157
157
|
responseFormat: params.responseFormat,
|
|
158
|
-
mcpServers: params.mcpServers,
|
|
159
|
-
reasoningEffort: params.reasoningEffort,
|
|
160
158
|
signal
|
|
161
159
|
});
|
|
162
160
|
const stepToolResults = [];
|
|
@@ -305,8 +303,6 @@ async function streamText(params) {
|
|
|
305
303
|
temperature: params.temperature,
|
|
306
304
|
maxTokens: params.maxTokens,
|
|
307
305
|
responseFormat: params.responseFormat,
|
|
308
|
-
mcpServers: params.mcpServers,
|
|
309
|
-
reasoningEffort: params.reasoningEffort,
|
|
310
306
|
signal
|
|
311
307
|
})) {
|
|
312
308
|
switch (chunk.type) {
|
|
@@ -1175,14 +1171,6 @@ var GenerateResult = class {
|
|
|
1175
1171
|
get requiresAction() {
|
|
1176
1172
|
return this.data.requiresAction;
|
|
1177
1173
|
}
|
|
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
|
-
}
|
|
1186
1174
|
/**
|
|
1187
1175
|
* Error if generation failed
|
|
1188
1176
|
*/
|
|
@@ -2969,7 +2957,6 @@ var Runtime = class {
|
|
|
2969
2957
|
const toolResults = [];
|
|
2970
2958
|
let messages = [];
|
|
2971
2959
|
let requiresAction = false;
|
|
2972
|
-
let usage;
|
|
2973
2960
|
let error;
|
|
2974
2961
|
try {
|
|
2975
2962
|
for await (const event of generator) {
|
|
@@ -3000,13 +2987,6 @@ var Runtime = class {
|
|
|
3000
2987
|
case "done":
|
|
3001
2988
|
messages = event.messages || [];
|
|
3002
2989
|
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
|
-
}
|
|
3010
2990
|
break;
|
|
3011
2991
|
case "error":
|
|
3012
2992
|
error = { message: event.message, code: event.code };
|
|
@@ -3038,48 +3018,9 @@ var Runtime = class {
|
|
|
3038
3018
|
toolCalls,
|
|
3039
3019
|
toolResults,
|
|
3040
3020
|
requiresAction,
|
|
3041
|
-
usage,
|
|
3042
3021
|
error
|
|
3043
3022
|
});
|
|
3044
3023
|
}
|
|
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
|
-
}
|
|
3083
3024
|
/**
|
|
3084
3025
|
* Create Express-compatible handler middleware
|
|
3085
3026
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -153,8 +153,6 @@ async function generateText(params) {
|
|
|
153
153
|
temperature: params.temperature,
|
|
154
154
|
maxTokens: params.maxTokens,
|
|
155
155
|
responseFormat: params.responseFormat,
|
|
156
|
-
mcpServers: params.mcpServers,
|
|
157
|
-
reasoningEffort: params.reasoningEffort,
|
|
158
156
|
signal
|
|
159
157
|
});
|
|
160
158
|
const stepToolResults = [];
|
|
@@ -303,8 +301,6 @@ async function streamText(params) {
|
|
|
303
301
|
temperature: params.temperature,
|
|
304
302
|
maxTokens: params.maxTokens,
|
|
305
303
|
responseFormat: params.responseFormat,
|
|
306
|
-
mcpServers: params.mcpServers,
|
|
307
|
-
reasoningEffort: params.reasoningEffort,
|
|
308
304
|
signal
|
|
309
305
|
})) {
|
|
310
306
|
switch (chunk.type) {
|
|
@@ -1173,14 +1169,6 @@ var GenerateResult = class {
|
|
|
1173
1169
|
get requiresAction() {
|
|
1174
1170
|
return this.data.requiresAction;
|
|
1175
1171
|
}
|
|
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
|
-
}
|
|
1184
1172
|
/**
|
|
1185
1173
|
* Error if generation failed
|
|
1186
1174
|
*/
|
|
@@ -2967,7 +2955,6 @@ var Runtime = class {
|
|
|
2967
2955
|
const toolResults = [];
|
|
2968
2956
|
let messages = [];
|
|
2969
2957
|
let requiresAction = false;
|
|
2970
|
-
let usage;
|
|
2971
2958
|
let error;
|
|
2972
2959
|
try {
|
|
2973
2960
|
for await (const event of generator) {
|
|
@@ -2998,13 +2985,6 @@ var Runtime = class {
|
|
|
2998
2985
|
case "done":
|
|
2999
2986
|
messages = event.messages || [];
|
|
3000
2987
|
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
|
-
}
|
|
3008
2988
|
break;
|
|
3009
2989
|
case "error":
|
|
3010
2990
|
error = { message: event.message, code: event.code };
|
|
@@ -3036,48 +3016,9 @@ var Runtime = class {
|
|
|
3036
3016
|
toolCalls,
|
|
3037
3017
|
toolResults,
|
|
3038
3018
|
requiresAction,
|
|
3039
|
-
usage,
|
|
3040
3019
|
error
|
|
3041
3020
|
});
|
|
3042
3021
|
}
|
|
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
|
-
}
|
|
3081
3022
|
/**
|
|
3082
3023
|
* Create Express-compatible handler middleware
|
|
3083
3024
|
*
|
|
@@ -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-BkQCSiIt.mjs';
|
|
2
|
+
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-BSSiJW2o.mjs';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-tNgbBaSo.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-BkQCSiIt.js';
|
|
2
|
+
import { a as AnthropicProviderConfig, A as AIProvider } from '../../types-BQ31QIsA.js';
|
|
3
3
|
import 'zod';
|
|
4
|
-
import '../../base-
|
|
4
|
+
import '../../base-C58Dsr9p.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Anthropic Provider - Modern Pattern
|
|
@@ -89,63 +89,6 @@ function toAnthropicOutputConfig(rf) {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
function toAnthropicMcp(mcpServers) {
|
|
93
|
-
if (!mcpServers || mcpServers.length === 0) {
|
|
94
|
-
return { mcpServers: [], tools: [], betas: [] };
|
|
95
|
-
}
|
|
96
|
-
const serverEntries = [];
|
|
97
|
-
const toolEntries = [];
|
|
98
|
-
for (const mcp of mcpServers) {
|
|
99
|
-
const authHeader = mcp.headers?.Authorization ?? mcp.headers?.authorization;
|
|
100
|
-
const token = authHeader?.replace(/^Bearer\s+/i, "");
|
|
101
|
-
serverEntries.push({
|
|
102
|
-
type: "url",
|
|
103
|
-
url: mcp.url,
|
|
104
|
-
name: mcp.label,
|
|
105
|
-
...token ? { authorization_token: token } : {}
|
|
106
|
-
});
|
|
107
|
-
if (mcp.allowedTools && mcp.allowedTools.length > 0) {
|
|
108
|
-
toolEntries.push({
|
|
109
|
-
type: "mcp_toolset",
|
|
110
|
-
mcp_server_name: mcp.label,
|
|
111
|
-
configs: Object.fromEntries(
|
|
112
|
-
mcp.allowedTools.map((toolName) => [toolName, {}])
|
|
113
|
-
)
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
mcpServers: serverEntries,
|
|
119
|
-
tools: toolEntries,
|
|
120
|
-
betas: ["mcp-client-2025-11-20"]
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function isStringEffort(effort) {
|
|
124
|
-
return typeof effort === "string" && (effort === "minimal" || effort === "low" || effort === "medium" || effort === "high");
|
|
125
|
-
}
|
|
126
|
-
var ANTHROPIC_ADAPTIVE_MODELS = /(claude-opus-4-7|claude-opus-4-6|claude-sonnet-4-6)/i;
|
|
127
|
-
function toAnthropicThinking(effort, modelId) {
|
|
128
|
-
if (!effort) return {};
|
|
129
|
-
if (typeof effort === "object" && "raw" in effort) {
|
|
130
|
-
return { thinking: effort.raw };
|
|
131
|
-
}
|
|
132
|
-
const isAdaptive = !!modelId && ANTHROPIC_ADAPTIVE_MODELS.test(modelId);
|
|
133
|
-
if (typeof effort === "object" && "budgetTokens" in effort) {
|
|
134
|
-
return {
|
|
135
|
-
thinking: { type: "enabled", budget_tokens: effort.budgetTokens }
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (!isStringEffort(effort)) return {};
|
|
139
|
-
if (isAdaptive) {
|
|
140
|
-
const mapped = effort === "minimal" ? "low" : effort;
|
|
141
|
-
return {
|
|
142
|
-
thinking: { type: "adaptive" },
|
|
143
|
-
outputConfigEffort: mapped
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
const budget = effort === "high" ? 16e3 : effort === "medium" ? 8e3 : effort === "low" ? 4e3 : 2048;
|
|
147
|
-
return { thinking: { type: "enabled", budget_tokens: budget } };
|
|
148
|
-
}
|
|
149
92
|
function hasMediaAttachments(message) {
|
|
150
93
|
const attachments = message.metadata?.attachments;
|
|
151
94
|
return attachments?.some(
|
|
@@ -981,58 +924,36 @@ var AnthropicAdapter = class {
|
|
|
981
924
|
if (serverToolConfiguration) {
|
|
982
925
|
options.server_tool_configuration = serverToolConfiguration;
|
|
983
926
|
}
|
|
984
|
-
const modelForThinking = request.config?.model || this.model;
|
|
985
|
-
const thinkingTranslation = toAnthropicThinking(
|
|
986
|
-
request.config?.reasoningEffort,
|
|
987
|
-
modelForThinking
|
|
988
|
-
);
|
|
989
927
|
const outputConfig = toAnthropicOutputConfig(responseFormat);
|
|
990
|
-
if (outputConfig
|
|
991
|
-
options.output_config =
|
|
992
|
-
...outputConfig ?? {},
|
|
993
|
-
...thinkingTranslation.outputConfigEffort ? { effort: thinkingTranslation.outputConfigEffort } : {}
|
|
994
|
-
};
|
|
928
|
+
if (outputConfig) {
|
|
929
|
+
options.output_config = outputConfig;
|
|
995
930
|
}
|
|
996
|
-
if (
|
|
997
|
-
options.thinking = thinkingTranslation.thinking;
|
|
998
|
-
} else if (this.config.thinking?.type === "enabled") {
|
|
931
|
+
if (this.config.thinking?.type === "enabled") {
|
|
999
932
|
options.thinking = {
|
|
1000
933
|
type: "enabled",
|
|
1001
934
|
budget_tokens: this.config.thinking.budgetTokens || 1e4
|
|
1002
935
|
};
|
|
1003
936
|
}
|
|
1004
|
-
|
|
1005
|
-
const betas = [];
|
|
1006
|
-
if (mcp.mcpServers.length > 0) {
|
|
1007
|
-
options.mcp_servers = mcp.mcpServers;
|
|
1008
|
-
betas.push(...mcp.betas);
|
|
1009
|
-
if (mcp.tools.length > 0) {
|
|
1010
|
-
const existingTools = Array.isArray(options.tools) ? options.tools : [];
|
|
1011
|
-
options.tools = [...existingTools, ...mcp.tools];
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
return { options, messages, betas };
|
|
937
|
+
return { options, messages };
|
|
1015
938
|
}
|
|
1016
939
|
/**
|
|
1017
940
|
* Non-streaming completion (for debugging/comparison with original studio-ai)
|
|
1018
941
|
*/
|
|
1019
942
|
async complete(request) {
|
|
1020
943
|
const client = await this.getClient();
|
|
1021
|
-
const { options
|
|
944
|
+
const { options } = this.buildRequestOptions(request);
|
|
1022
945
|
const nonStreamingOptions = {
|
|
1023
946
|
...options,
|
|
1024
947
|
stream: false
|
|
1025
948
|
};
|
|
1026
949
|
try {
|
|
1027
|
-
const finalOptions = betas.length > 0 ? { ...nonStreamingOptions, betas } : nonStreamingOptions;
|
|
1028
|
-
const messagesApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1029
950
|
logProviderPayload(
|
|
1030
951
|
"anthropic",
|
|
1031
952
|
"request payload",
|
|
1032
|
-
|
|
953
|
+
nonStreamingOptions,
|
|
1033
954
|
request.debug
|
|
1034
955
|
);
|
|
1035
|
-
const response = await
|
|
956
|
+
const response = await client.messages.create(nonStreamingOptions);
|
|
1036
957
|
logProviderPayload(
|
|
1037
958
|
"anthropic",
|
|
1038
959
|
"response payload",
|
|
@@ -1067,19 +988,17 @@ var AnthropicAdapter = class {
|
|
|
1067
988
|
}
|
|
1068
989
|
async *stream(request) {
|
|
1069
990
|
const client = await this.getClient();
|
|
1070
|
-
const { options
|
|
991
|
+
const { options } = this.buildRequestOptions(request);
|
|
1071
992
|
const messageId = generateMessageId();
|
|
1072
993
|
yield { type: "message:start", id: messageId };
|
|
1073
994
|
try {
|
|
1074
|
-
const finalOptions = betas.length > 0 ? { ...options, betas } : options;
|
|
1075
|
-
const streamApi = betas.length > 0 ? client.beta.messages : client.messages;
|
|
1076
995
|
logProviderPayload(
|
|
1077
996
|
"anthropic",
|
|
1078
997
|
"request payload",
|
|
1079
|
-
|
|
998
|
+
options,
|
|
1080
999
|
request.debug
|
|
1081
1000
|
);
|
|
1082
|
-
const stream = await
|
|
1001
|
+
const stream = await client.messages.stream(options);
|
|
1083
1002
|
let currentToolUse = null;
|
|
1084
1003
|
let isInThinkingBlock = false;
|
|
1085
1004
|
const collectedCitations = [];
|