@yourgpt/llm-sdk 0.1.0 → 0.1.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 +61 -40
- package/dist/adapters/index.d.mts +4 -258
- package/dist/adapters/index.d.ts +4 -258
- package/dist/adapters/index.js +0 -113
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +1 -112
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/base-D_FyHFKj.d.mts +235 -0
- package/dist/base-D_FyHFKj.d.ts +235 -0
- package/dist/index.d.mts +145 -450
- package/dist/index.d.ts +145 -450
- package/dist/index.js +1837 -307
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1827 -305
- package/dist/index.mjs.map +1 -1
- package/dist/providers/anthropic/index.d.mts +61 -0
- package/dist/providers/anthropic/index.d.ts +61 -0
- package/dist/providers/anthropic/index.js +939 -0
- package/dist/providers/anthropic/index.js.map +1 -0
- package/dist/providers/anthropic/index.mjs +934 -0
- package/dist/providers/anthropic/index.mjs.map +1 -0
- package/dist/providers/azure/index.d.mts +38 -0
- package/dist/providers/azure/index.d.ts +38 -0
- package/dist/providers/azure/index.js +380 -0
- package/dist/providers/azure/index.js.map +1 -0
- package/dist/providers/azure/index.mjs +377 -0
- package/dist/providers/azure/index.mjs.map +1 -0
- package/dist/providers/google/index.d.mts +72 -0
- package/dist/providers/google/index.d.ts +72 -0
- package/dist/providers/google/index.js +790 -0
- package/dist/providers/google/index.js.map +1 -0
- package/dist/providers/google/index.mjs +785 -0
- package/dist/providers/google/index.mjs.map +1 -0
- package/dist/providers/ollama/index.d.mts +24 -0
- package/dist/providers/ollama/index.d.ts +24 -0
- package/dist/providers/ollama/index.js +235 -0
- package/dist/providers/ollama/index.js.map +1 -0
- package/dist/providers/ollama/index.mjs +232 -0
- package/dist/providers/ollama/index.mjs.map +1 -0
- package/dist/providers/openai/index.d.mts +82 -0
- package/dist/providers/openai/index.d.ts +82 -0
- package/dist/providers/openai/index.js +679 -0
- package/dist/providers/openai/index.js.map +1 -0
- package/dist/providers/openai/index.mjs +674 -0
- package/dist/providers/openai/index.mjs.map +1 -0
- package/dist/providers/xai/index.d.mts +78 -0
- package/dist/providers/xai/index.d.ts +78 -0
- package/dist/providers/xai/index.js +671 -0
- package/dist/providers/xai/index.js.map +1 -0
- package/dist/providers/xai/index.mjs +666 -0
- package/dist/providers/xai/index.mjs.map +1 -0
- package/dist/types-BBCZ3Fxy.d.mts +308 -0
- package/dist/types-CdORv1Yu.d.mts +338 -0
- package/dist/types-CdORv1Yu.d.ts +338 -0
- package/dist/types-DcoCaVVC.d.ts +308 -0
- package/package.json +34 -3
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { ToolDefinition, UnifiedToolCall, UnifiedToolResult } from '@yourgpt/copilot-sdk/core';
|
|
2
|
+
import { L as LLMAdapter } from './base-D_FyHFKj.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Provider Types
|
|
6
|
+
*
|
|
7
|
+
* Defines interfaces for:
|
|
8
|
+
* 1. Provider Formatters (for tool transformations in agent loop)
|
|
9
|
+
* 2. Multi-provider architecture (AIProvider, capabilities, configs)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Provider formatter interface
|
|
14
|
+
*
|
|
15
|
+
* Each provider implements this interface to handle:
|
|
16
|
+
* - Tool definition transformation
|
|
17
|
+
* - Tool call parsing from responses
|
|
18
|
+
* - Tool result formatting
|
|
19
|
+
* - Stop reason detection
|
|
20
|
+
*/
|
|
21
|
+
interface ProviderFormatter {
|
|
22
|
+
/**
|
|
23
|
+
* Transform unified tool definitions to provider format
|
|
24
|
+
*/
|
|
25
|
+
transformTools(tools: ToolDefinition[]): unknown[];
|
|
26
|
+
/**
|
|
27
|
+
* Parse tool calls from provider response
|
|
28
|
+
*/
|
|
29
|
+
parseToolCalls(response: unknown): UnifiedToolCall[];
|
|
30
|
+
/**
|
|
31
|
+
* Format tool results for provider
|
|
32
|
+
*/
|
|
33
|
+
formatToolResults(results: UnifiedToolResult[]): unknown[];
|
|
34
|
+
/**
|
|
35
|
+
* Check if response indicates tool use is requested
|
|
36
|
+
*/
|
|
37
|
+
isToolUseStop(response: unknown): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if response indicates end of turn
|
|
40
|
+
*/
|
|
41
|
+
isEndTurnStop(response: unknown): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get stop reason string from response
|
|
44
|
+
*/
|
|
45
|
+
getStopReason(response: unknown): string;
|
|
46
|
+
/**
|
|
47
|
+
* Extract text content from response
|
|
48
|
+
*/
|
|
49
|
+
extractTextContent(response: unknown): string;
|
|
50
|
+
/**
|
|
51
|
+
* Build assistant message with tool calls for conversation history
|
|
52
|
+
*/
|
|
53
|
+
buildAssistantToolMessage(toolCalls: UnifiedToolCall[], textContent?: string): unknown;
|
|
54
|
+
/**
|
|
55
|
+
* Build user message with tool results for conversation history
|
|
56
|
+
*/
|
|
57
|
+
buildToolResultMessage(results: UnifiedToolResult[]): unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Anthropic tool definition format
|
|
61
|
+
*/
|
|
62
|
+
interface AnthropicTool {
|
|
63
|
+
name: string;
|
|
64
|
+
description: string;
|
|
65
|
+
input_schema: {
|
|
66
|
+
type: "object";
|
|
67
|
+
properties: Record<string, unknown>;
|
|
68
|
+
required?: string[];
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Anthropic tool_use block from response
|
|
73
|
+
*/
|
|
74
|
+
interface AnthropicToolUse {
|
|
75
|
+
type: "tool_use";
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
input: Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Anthropic tool_result block
|
|
82
|
+
*/
|
|
83
|
+
interface AnthropicToolResult {
|
|
84
|
+
type: "tool_result";
|
|
85
|
+
tool_use_id: string;
|
|
86
|
+
content: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* OpenAI tool definition format
|
|
90
|
+
*/
|
|
91
|
+
interface OpenAITool {
|
|
92
|
+
type: "function";
|
|
93
|
+
function: {
|
|
94
|
+
name: string;
|
|
95
|
+
description: string;
|
|
96
|
+
parameters: {
|
|
97
|
+
type: "object";
|
|
98
|
+
properties: Record<string, unknown>;
|
|
99
|
+
required?: string[];
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* OpenAI tool call from response
|
|
105
|
+
*/
|
|
106
|
+
interface OpenAIToolCall {
|
|
107
|
+
id: string;
|
|
108
|
+
type: "function";
|
|
109
|
+
function: {
|
|
110
|
+
name: string;
|
|
111
|
+
arguments: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* OpenAI tool result message
|
|
116
|
+
*/
|
|
117
|
+
interface OpenAIToolResult {
|
|
118
|
+
role: "tool";
|
|
119
|
+
tool_call_id: string;
|
|
120
|
+
content: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Google Gemini function declaration
|
|
124
|
+
*/
|
|
125
|
+
interface GeminiFunctionDeclaration {
|
|
126
|
+
name: string;
|
|
127
|
+
description: string;
|
|
128
|
+
parameters?: {
|
|
129
|
+
type: "object";
|
|
130
|
+
properties: Record<string, unknown>;
|
|
131
|
+
required?: string[];
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Gemini function call from response
|
|
136
|
+
*/
|
|
137
|
+
interface GeminiFunctionCall {
|
|
138
|
+
name: string;
|
|
139
|
+
args: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Gemini function response
|
|
143
|
+
*/
|
|
144
|
+
interface GeminiFunctionResponse {
|
|
145
|
+
name: string;
|
|
146
|
+
response: Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Capabilities of a model for UI feature flags
|
|
150
|
+
* UI components can use this to enable/disable features
|
|
151
|
+
*/
|
|
152
|
+
interface ProviderCapabilities {
|
|
153
|
+
/** Supports image inputs */
|
|
154
|
+
supportsVision: boolean;
|
|
155
|
+
/** Supports tool/function calling */
|
|
156
|
+
supportsTools: boolean;
|
|
157
|
+
/** Supports extended thinking (Claude, DeepSeek) */
|
|
158
|
+
supportsThinking: boolean;
|
|
159
|
+
/** Supports streaming responses */
|
|
160
|
+
supportsStreaming: boolean;
|
|
161
|
+
/** Supports PDF document inputs */
|
|
162
|
+
supportsPDF: boolean;
|
|
163
|
+
/** Supports audio inputs */
|
|
164
|
+
supportsAudio: boolean;
|
|
165
|
+
/** Supports video inputs */
|
|
166
|
+
supportsVideo: boolean;
|
|
167
|
+
/** Maximum context tokens */
|
|
168
|
+
maxTokens: number;
|
|
169
|
+
/** Supported image MIME types */
|
|
170
|
+
supportedImageTypes: string[];
|
|
171
|
+
/** Supported audio MIME types */
|
|
172
|
+
supportedAudioTypes?: string[];
|
|
173
|
+
/** Supported video MIME types */
|
|
174
|
+
supportedVideoTypes?: string[];
|
|
175
|
+
/** Supports JSON mode / structured output */
|
|
176
|
+
supportsJsonMode?: boolean;
|
|
177
|
+
/** Supports system messages */
|
|
178
|
+
supportsSystemMessages?: boolean;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* AI Provider interface
|
|
182
|
+
*
|
|
183
|
+
* Wraps existing LLMAdapter with additional metadata:
|
|
184
|
+
* - Supported models list
|
|
185
|
+
* - Per-model capabilities
|
|
186
|
+
* - Provider name
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const openai = createOpenAI({ apiKey: '...' });
|
|
191
|
+
*
|
|
192
|
+
* // Get adapter for a specific model
|
|
193
|
+
* const adapter = openai.languageModel('gpt-4o');
|
|
194
|
+
*
|
|
195
|
+
* // Check capabilities
|
|
196
|
+
* const caps = openai.getCapabilities('gpt-4o');
|
|
197
|
+
* if (caps.supportsVision) {
|
|
198
|
+
* // Show image upload button
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
interface AIProvider {
|
|
203
|
+
/** Provider name (e.g., 'openai', 'anthropic') */
|
|
204
|
+
readonly name: string;
|
|
205
|
+
/** List of supported model IDs */
|
|
206
|
+
readonly supportedModels: string[];
|
|
207
|
+
/**
|
|
208
|
+
* Get a language model adapter for the given model ID
|
|
209
|
+
* Returns the existing LLMAdapter interface - no breaking changes
|
|
210
|
+
*/
|
|
211
|
+
languageModel(modelId: string): LLMAdapter;
|
|
212
|
+
/**
|
|
213
|
+
* Get capabilities for a specific model
|
|
214
|
+
* UI components use this to enable/disable features
|
|
215
|
+
*/
|
|
216
|
+
getCapabilities(modelId: string): ProviderCapabilities;
|
|
217
|
+
/**
|
|
218
|
+
* Optional: Get an embedding model (future expansion)
|
|
219
|
+
*/
|
|
220
|
+
embeddingModel?(modelId: string): EmbeddingModel;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Embedding model interface (for future expansion)
|
|
224
|
+
*/
|
|
225
|
+
interface EmbeddingModel {
|
|
226
|
+
readonly provider: string;
|
|
227
|
+
readonly modelId: string;
|
|
228
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Base provider configuration
|
|
232
|
+
*/
|
|
233
|
+
interface BaseProviderConfig {
|
|
234
|
+
/** API key (falls back to environment variable) */
|
|
235
|
+
apiKey?: string;
|
|
236
|
+
/** Custom base URL */
|
|
237
|
+
baseUrl?: string;
|
|
238
|
+
/** Request timeout in milliseconds */
|
|
239
|
+
timeout?: number;
|
|
240
|
+
/** Custom headers to include */
|
|
241
|
+
headers?: Record<string, string>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* OpenAI provider configuration
|
|
245
|
+
*/
|
|
246
|
+
interface OpenAIProviderConfig extends BaseProviderConfig {
|
|
247
|
+
/** OpenAI organization ID */
|
|
248
|
+
organization?: string;
|
|
249
|
+
/** OpenAI project ID */
|
|
250
|
+
project?: string;
|
|
251
|
+
/** Vision detail level for images */
|
|
252
|
+
imageDetail?: "auto" | "low" | "high";
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Anthropic provider configuration
|
|
256
|
+
*/
|
|
257
|
+
interface AnthropicProviderConfig extends BaseProviderConfig {
|
|
258
|
+
/** Extended thinking budget in tokens (minimum 1024) */
|
|
259
|
+
thinkingBudget?: number;
|
|
260
|
+
/** Enable prompt caching */
|
|
261
|
+
cacheControl?: boolean;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Google provider configuration
|
|
265
|
+
*/
|
|
266
|
+
interface GoogleProviderConfig extends BaseProviderConfig {
|
|
267
|
+
/** Safety settings */
|
|
268
|
+
safetySettings?: GoogleSafetySetting[];
|
|
269
|
+
/** Grounding configuration (for web search) */
|
|
270
|
+
groundingConfig?: GoogleGroundingConfig;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Google safety setting
|
|
274
|
+
*/
|
|
275
|
+
interface GoogleSafetySetting {
|
|
276
|
+
category: "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_DANGEROUS_CONTENT";
|
|
277
|
+
threshold: "BLOCK_NONE" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_HIGH_AND_ABOVE";
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Google grounding configuration
|
|
281
|
+
*/
|
|
282
|
+
interface GoogleGroundingConfig {
|
|
283
|
+
/** Enable Google Search grounding */
|
|
284
|
+
googleSearchRetrieval?: boolean;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* xAI provider configuration
|
|
288
|
+
*/
|
|
289
|
+
interface XAIProviderConfig extends BaseProviderConfig {
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Azure OpenAI provider configuration
|
|
293
|
+
*/
|
|
294
|
+
interface AzureProviderConfig extends BaseProviderConfig {
|
|
295
|
+
/** Azure resource name */
|
|
296
|
+
resourceName: string;
|
|
297
|
+
/** Deployment name */
|
|
298
|
+
deploymentName: string;
|
|
299
|
+
/** API version (default: 2024-02-15-preview) */
|
|
300
|
+
apiVersion?: string;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Ollama provider configuration
|
|
304
|
+
*/
|
|
305
|
+
interface OllamaProviderConfig extends BaseProviderConfig {
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export type { AIProvider as A, BaseProviderConfig as B, GoogleProviderConfig as G, OllamaProviderConfig as O, ProviderCapabilities as P, XAIProviderConfig as X, AzureProviderConfig as a, OpenAIProviderConfig as b, AnthropicProviderConfig as c, ProviderFormatter as d, AnthropicTool as e, AnthropicToolUse as f, AnthropicToolResult as g, OpenAITool as h, OpenAIToolCall as i, OpenAIToolResult as j, GeminiFunctionDeclaration as k, GeminiFunctionCall as l, GeminiFunctionResponse as m };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yourgpt/llm-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "LLM SDK for YourGPT - Multi-provider LLM integration",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -11,6 +11,36 @@
|
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
13
|
},
|
|
14
|
+
"./openai": {
|
|
15
|
+
"types": "./dist/providers/openai/index.d.mts",
|
|
16
|
+
"import": "./dist/providers/openai/index.mjs",
|
|
17
|
+
"require": "./dist/providers/openai/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./anthropic": {
|
|
20
|
+
"types": "./dist/providers/anthropic/index.d.mts",
|
|
21
|
+
"import": "./dist/providers/anthropic/index.mjs",
|
|
22
|
+
"require": "./dist/providers/anthropic/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./google": {
|
|
25
|
+
"types": "./dist/providers/google/index.d.mts",
|
|
26
|
+
"import": "./dist/providers/google/index.mjs",
|
|
27
|
+
"require": "./dist/providers/google/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./ollama": {
|
|
30
|
+
"types": "./dist/providers/ollama/index.d.mts",
|
|
31
|
+
"import": "./dist/providers/ollama/index.mjs",
|
|
32
|
+
"require": "./dist/providers/ollama/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./xai": {
|
|
35
|
+
"types": "./dist/providers/xai/index.d.mts",
|
|
36
|
+
"import": "./dist/providers/xai/index.mjs",
|
|
37
|
+
"require": "./dist/providers/xai/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./azure": {
|
|
40
|
+
"types": "./dist/providers/azure/index.d.mts",
|
|
41
|
+
"import": "./dist/providers/azure/index.mjs",
|
|
42
|
+
"require": "./dist/providers/azure/index.js"
|
|
43
|
+
},
|
|
14
44
|
"./adapters": {
|
|
15
45
|
"types": "./dist/adapters/index.d.ts",
|
|
16
46
|
"import": "./dist/adapters/index.mjs",
|
|
@@ -30,7 +60,7 @@
|
|
|
30
60
|
"typecheck": "tsc --noEmit"
|
|
31
61
|
},
|
|
32
62
|
"dependencies": {
|
|
33
|
-
"@yourgpt/copilot-sdk": "
|
|
63
|
+
"@yourgpt/copilot-sdk": "workspace:^",
|
|
34
64
|
"hono": "^4.3.0",
|
|
35
65
|
"zod": "^3.23.0"
|
|
36
66
|
},
|
|
@@ -71,7 +101,8 @@
|
|
|
71
101
|
"openai",
|
|
72
102
|
"anthropic",
|
|
73
103
|
"gemini",
|
|
74
|
-
"
|
|
104
|
+
"xai",
|
|
105
|
+
"grok",
|
|
75
106
|
"ollama",
|
|
76
107
|
"multi-provider",
|
|
77
108
|
"streaming"
|