universal-llm-client 4.2.0 → 4.5.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/CHANGELOG.md +142 -103
- package/LICENSE +21 -21
- package/README.md +640 -591
- package/dist/ai-model.d.ts +12 -1
- package/dist/ai-model.d.ts.map +1 -1
- package/dist/ai-model.js +36 -1
- package/dist/ai-model.js.map +1 -1
- package/dist/gemma-channel.d.ts +14 -0
- package/dist/gemma-channel.d.ts.map +1 -0
- package/dist/gemma-channel.js +38 -0
- package/dist/gemma-channel.js.map +1 -0
- package/dist/gemma-diffusion.d.ts +49 -0
- package/dist/gemma-diffusion.d.ts.map +1 -0
- package/dist/gemma-diffusion.js +147 -0
- package/dist/gemma-diffusion.js.map +1 -0
- package/dist/http.d.ts +4 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +14 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +183 -7
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +28 -3
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google.d.ts +22 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +225 -13
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/ollama.d.ts +2 -0
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +59 -30
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts +14 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +200 -22
- package/dist/providers/openai.js.map +1 -1
- package/dist/router.d.ts +2 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +4 -0
- package/dist/router.js.map +1 -1
- package/dist/stream-decoder.d.ts +12 -0
- package/dist/stream-decoder.d.ts.map +1 -1
- package/dist/stream-decoder.js +182 -5
- package/dist/stream-decoder.js.map +1 -1
- package/dist/thinking.d.ts +36 -0
- package/dist/thinking.d.ts.map +1 -0
- package/dist/thinking.js +52 -0
- package/dist/thinking.js.map +1 -0
- package/package.json +118 -116
- package/src/ai-model.ts +400 -350
- package/src/auditor.ts +213 -213
- package/src/client.ts +402 -402
- package/src/debug/debug-google-streaming.ts +1 -1
- package/src/demos/basic/universal-llm-examples.ts +3 -3
- package/src/demos/diffusion-gemma/.env +29 -0
- package/src/demos/diffusion-gemma/.env.example +27 -0
- package/src/demos/diffusion-gemma/CLAUDE.md +95 -0
- package/src/demos/diffusion-gemma/README.md +59 -0
- package/src/demos/diffusion-gemma/canvas.ts +1606 -0
- package/src/demos/diffusion-gemma/docker-compose.yml +29 -0
- package/src/demos/diffusion-gemma/probe-stream.ts +51 -0
- package/src/demos/diffusion-gemma/probe-tools.ts +55 -0
- package/src/demos/diffusion-gemma/server.ts +1205 -0
- package/src/demos/diffusion-gemma/start-vllm.sh +98 -0
- package/src/gemma-channel.ts +47 -0
- package/src/gemma-diffusion.ts +167 -0
- package/src/http.ts +261 -247
- package/src/index.ts +180 -161
- package/src/interfaces.ts +843 -657
- package/src/mcp.ts +345 -345
- package/src/providers/anthropic.ts +796 -762
- package/src/providers/google.ts +840 -620
- package/src/providers/index.ts +8 -8
- package/src/providers/ollama.ts +503 -469
- package/src/providers/openai.ts +587 -392
- package/src/router.ts +785 -780
- package/src/stream-decoder.ts +535 -361
- package/src/structured-output.ts +759 -759
- package/src/test-scripts/test-google-deep-research.ts +33 -0
- package/src/test-scripts/test-google-streaming-enhanced.ts +147 -147
- package/src/test-scripts/test-google-streaming.ts +1 -1
- package/src/test-scripts/test-google-system-prompt-comprehensive.ts +189 -189
- package/src/test-scripts/test-google-thinking.ts +46 -0
- package/src/test-scripts/test-system-message-positions.ts +163 -163
- package/src/test-scripts/test-system-prompt-improvement-demo.ts +83 -83
- package/src/test-scripts/test-vllm-qwen36.ts +256 -0
- package/src/tests/ai-model.test.ts +1614 -1614
- package/src/tests/auditor.test.ts +224 -224
- package/src/tests/gemma-diffusion.test.ts +115 -0
- package/src/tests/http.test.ts +200 -200
- package/src/tests/interfaces.test.ts +117 -117
- package/src/tests/providers/anthropic.test.ts +118 -0
- package/src/tests/providers/google.test.ts +841 -660
- package/src/tests/providers/ollama.test.ts +1034 -954
- package/src/tests/providers/openai.test.ts +1511 -1122
- package/src/tests/router.test.ts +254 -254
- package/src/tests/stream-decoder.test.ts +263 -179
- package/src/tests/structured-output.test.ts +1450 -1450
- package/src/tests/thinking.test.ts +65 -0
- package/src/tests/tools.test.ts +175 -175
- package/src/thinking.ts +73 -0
- package/src/tools.ts +246 -246
- package/src/zod-adapter.ts +72 -72
package/src/index.ts
CHANGED
|
@@ -1,161 +1,180 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Universal LLM Client v3
|
|
3
|
-
*
|
|
4
|
-
* A universal LLM client with transparent provider failover,
|
|
5
|
-
* streaming tool execution, pluggable reasoning, and native observability.
|
|
6
|
-
*
|
|
7
|
-
* @module universal-llm-client
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Public API — The Universal Client
|
|
12
|
-
// ============================================================================
|
|
13
|
-
|
|
14
|
-
export { AIModel } from './ai-model.js';
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Types & Interfaces
|
|
18
|
-
// ============================================================================
|
|
19
|
-
|
|
20
|
-
export {
|
|
21
|
-
// Enums
|
|
22
|
-
AIModelApiType,
|
|
23
|
-
AIModelType,
|
|
24
|
-
// Config
|
|
25
|
-
type AIModelConfig,
|
|
26
|
-
type ProviderConfig,
|
|
27
|
-
type LLMClientOptions,
|
|
28
|
-
// Messages
|
|
29
|
-
type LLMChatMessage,
|
|
30
|
-
type LLMMessageContent,
|
|
31
|
-
type LLMContentPart,
|
|
32
|
-
type LLMTextContent,
|
|
33
|
-
type LLMImageContent,
|
|
34
|
-
type LLMAudioContent,
|
|
35
|
-
// Responses
|
|
36
|
-
type LLMChatResponse,
|
|
37
|
-
type TokenUsageInfo,
|
|
38
|
-
// Tools
|
|
39
|
-
type LLMToolCall,
|
|
40
|
-
type LLMToolDefinition,
|
|
41
|
-
type LLMFunction,
|
|
42
|
-
type ToolHandler,
|
|
43
|
-
type ToolExecutionResult,
|
|
44
|
-
type ToolRegistry,
|
|
45
|
-
type ToolRegistryEntry,
|
|
46
|
-
// Options
|
|
47
|
-
type ChatOptions,
|
|
48
|
-
type ResponseFormat,
|
|
49
|
-
type OutputOptions,
|
|
50
|
-
//
|
|
51
|
-
type
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
type
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
type
|
|
161
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Universal LLM Client v3
|
|
3
|
+
*
|
|
4
|
+
* A universal LLM client with transparent provider failover,
|
|
5
|
+
* streaming tool execution, pluggable reasoning, and native observability.
|
|
6
|
+
*
|
|
7
|
+
* @module universal-llm-client
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Public API — The Universal Client
|
|
12
|
+
// ============================================================================
|
|
13
|
+
|
|
14
|
+
export { AIModel } from './ai-model.js';
|
|
15
|
+
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Types & Interfaces
|
|
18
|
+
// ============================================================================
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
// Enums
|
|
22
|
+
AIModelApiType,
|
|
23
|
+
AIModelType,
|
|
24
|
+
// Config
|
|
25
|
+
type AIModelConfig,
|
|
26
|
+
type ProviderConfig,
|
|
27
|
+
type LLMClientOptions,
|
|
28
|
+
// Messages
|
|
29
|
+
type LLMChatMessage,
|
|
30
|
+
type LLMMessageContent,
|
|
31
|
+
type LLMContentPart,
|
|
32
|
+
type LLMTextContent,
|
|
33
|
+
type LLMImageContent,
|
|
34
|
+
type LLMAudioContent,
|
|
35
|
+
// Responses
|
|
36
|
+
type LLMChatResponse,
|
|
37
|
+
type TokenUsageInfo,
|
|
38
|
+
// Tools
|
|
39
|
+
type LLMToolCall,
|
|
40
|
+
type LLMToolDefinition,
|
|
41
|
+
type LLMFunction,
|
|
42
|
+
type ToolHandler,
|
|
43
|
+
type ToolExecutionResult,
|
|
44
|
+
type ToolRegistry,
|
|
45
|
+
type ToolRegistryEntry,
|
|
46
|
+
// Options
|
|
47
|
+
type ChatOptions,
|
|
48
|
+
type ResponseFormat,
|
|
49
|
+
type OutputOptions,
|
|
50
|
+
// Thinking / reasoning
|
|
51
|
+
type ThinkingLevel,
|
|
52
|
+
// Deep Research (Gemini)
|
|
53
|
+
type DeepResearchOptions,
|
|
54
|
+
type DeepResearchResult,
|
|
55
|
+
type DeepResearchStep,
|
|
56
|
+
type DeepResearchEvent,
|
|
57
|
+
// Model info
|
|
58
|
+
type ModelMetadata,
|
|
59
|
+
// Helpers
|
|
60
|
+
textContent,
|
|
61
|
+
imageContent,
|
|
62
|
+
multimodalMessage,
|
|
63
|
+
extractTextContent,
|
|
64
|
+
hasImages,
|
|
65
|
+
audioContent,
|
|
66
|
+
hasAudio,
|
|
67
|
+
} from './interfaces.js';
|
|
68
|
+
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Observability
|
|
71
|
+
// ============================================================================
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
type Auditor,
|
|
75
|
+
type AuditEvent,
|
|
76
|
+
type AuditEventType,
|
|
77
|
+
NoopAuditor,
|
|
78
|
+
ConsoleAuditor,
|
|
79
|
+
BufferedAuditor,
|
|
80
|
+
} from './auditor.js';
|
|
81
|
+
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Stream Decoding
|
|
84
|
+
// ============================================================================
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
type StreamDecoder,
|
|
88
|
+
type DecodedEvent,
|
|
89
|
+
type DecoderCallback,
|
|
90
|
+
type DecoderType,
|
|
91
|
+
type DecoderOptions,
|
|
92
|
+
type DecoderFactory,
|
|
93
|
+
createDecoder,
|
|
94
|
+
registerDecoder,
|
|
95
|
+
getRegisteredDecoders,
|
|
96
|
+
PassthroughDecoder,
|
|
97
|
+
StandardChatDecoder,
|
|
98
|
+
InterleavedReasoningDecoder,
|
|
99
|
+
} from './stream-decoder.js';
|
|
100
|
+
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// Tool Utilities
|
|
103
|
+
// ============================================================================
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
ToolBuilder,
|
|
107
|
+
ToolExecutor,
|
|
108
|
+
createTimeTool,
|
|
109
|
+
createRandomNumberTool,
|
|
110
|
+
} from './tools.js';
|
|
111
|
+
|
|
112
|
+
// ============================================================================
|
|
113
|
+
// HTTP Utilities (for advanced use cases)
|
|
114
|
+
// ============================================================================
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
httpRequest,
|
|
118
|
+
httpStream,
|
|
119
|
+
parseNDJSON,
|
|
120
|
+
parseSSE,
|
|
121
|
+
buildHeaders,
|
|
122
|
+
type HttpRequestOptions,
|
|
123
|
+
type HttpResponse,
|
|
124
|
+
} from './http.js';
|
|
125
|
+
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// DiffusionGemma Native Protocol (vLLM without server-side parsers)
|
|
128
|
+
// ============================================================================
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
isGemmaDiffusionModel,
|
|
132
|
+
parseGemmaDiffusionOutput,
|
|
133
|
+
gemmaArgsToJson,
|
|
134
|
+
type GemmaDiffusionParsed,
|
|
135
|
+
type GemmaParsedToolCall,
|
|
136
|
+
} from './gemma-diffusion.js';
|
|
137
|
+
|
|
138
|
+
// ============================================================================
|
|
139
|
+
// MCP Integration
|
|
140
|
+
// ============================================================================
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
MCPToolBridge,
|
|
144
|
+
type MCPBridgeConfig,
|
|
145
|
+
type MCPServerConfig,
|
|
146
|
+
type MCPTool,
|
|
147
|
+
} from './mcp.js';
|
|
148
|
+
|
|
149
|
+
// ============================================================================
|
|
150
|
+
// Structured Output
|
|
151
|
+
// ============================================================================
|
|
152
|
+
|
|
153
|
+
export {
|
|
154
|
+
StructuredOutputError,
|
|
155
|
+
type StructuredOutputErrorOptions,
|
|
156
|
+
type StructuredOutputOptions,
|
|
157
|
+
type StructuredOutputResult,
|
|
158
|
+
type StructuredOutputSuccess,
|
|
159
|
+
type StructuredOutputFailure,
|
|
160
|
+
type JSONSchema,
|
|
161
|
+
type SchemaProvider,
|
|
162
|
+
type ProviderSchema,
|
|
163
|
+
type SchemaConfig,
|
|
164
|
+
isStructuredOutputSuccess,
|
|
165
|
+
isStructuredOutputFailure,
|
|
166
|
+
// Schema conversion utilities
|
|
167
|
+
normalizeJsonSchema,
|
|
168
|
+
convertToProviderSchema,
|
|
169
|
+
stripUnsupportedFeatures,
|
|
170
|
+
getJsonSchema,
|
|
171
|
+
getJsonSchemaFromConfig,
|
|
172
|
+
// Validation functions
|
|
173
|
+
parseStructured,
|
|
174
|
+
tryParseStructured,
|
|
175
|
+
validateStructuredOutput,
|
|
176
|
+
stripJsonFences,
|
|
177
|
+
// Streaming parser
|
|
178
|
+
StreamingJsonParser,
|
|
179
|
+
type StreamingStructuredResult,
|
|
180
|
+
} from './structured-output.js';
|