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.
Files changed (108) hide show
  1. package/CHANGELOG.md +142 -103
  2. package/LICENSE +21 -21
  3. package/README.md +640 -591
  4. package/dist/ai-model.d.ts +12 -1
  5. package/dist/ai-model.d.ts.map +1 -1
  6. package/dist/ai-model.js +36 -1
  7. package/dist/ai-model.js.map +1 -1
  8. package/dist/gemma-channel.d.ts +14 -0
  9. package/dist/gemma-channel.d.ts.map +1 -0
  10. package/dist/gemma-channel.js +38 -0
  11. package/dist/gemma-channel.js.map +1 -0
  12. package/dist/gemma-diffusion.d.ts +49 -0
  13. package/dist/gemma-diffusion.d.ts.map +1 -0
  14. package/dist/gemma-diffusion.js +147 -0
  15. package/dist/gemma-diffusion.js.map +1 -0
  16. package/dist/http.d.ts +4 -0
  17. package/dist/http.d.ts.map +1 -1
  18. package/dist/http.js +14 -1
  19. package/dist/http.js.map +1 -1
  20. package/dist/index.d.ts +2 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +4 -0
  23. package/dist/index.js.map +1 -1
  24. package/dist/interfaces.d.ts +183 -7
  25. package/dist/interfaces.d.ts.map +1 -1
  26. package/dist/interfaces.js.map +1 -1
  27. package/dist/providers/anthropic.d.ts.map +1 -1
  28. package/dist/providers/anthropic.js +28 -3
  29. package/dist/providers/anthropic.js.map +1 -1
  30. package/dist/providers/google.d.ts +22 -1
  31. package/dist/providers/google.d.ts.map +1 -1
  32. package/dist/providers/google.js +225 -13
  33. package/dist/providers/google.js.map +1 -1
  34. package/dist/providers/ollama.d.ts +2 -0
  35. package/dist/providers/ollama.d.ts.map +1 -1
  36. package/dist/providers/ollama.js +59 -30
  37. package/dist/providers/ollama.js.map +1 -1
  38. package/dist/providers/openai.d.ts +14 -0
  39. package/dist/providers/openai.d.ts.map +1 -1
  40. package/dist/providers/openai.js +200 -22
  41. package/dist/providers/openai.js.map +1 -1
  42. package/dist/router.d.ts +2 -0
  43. package/dist/router.d.ts.map +1 -1
  44. package/dist/router.js +4 -0
  45. package/dist/router.js.map +1 -1
  46. package/dist/stream-decoder.d.ts +12 -0
  47. package/dist/stream-decoder.d.ts.map +1 -1
  48. package/dist/stream-decoder.js +182 -5
  49. package/dist/stream-decoder.js.map +1 -1
  50. package/dist/thinking.d.ts +36 -0
  51. package/dist/thinking.d.ts.map +1 -0
  52. package/dist/thinking.js +52 -0
  53. package/dist/thinking.js.map +1 -0
  54. package/package.json +118 -116
  55. package/src/ai-model.ts +400 -350
  56. package/src/auditor.ts +213 -213
  57. package/src/client.ts +402 -402
  58. package/src/debug/debug-google-streaming.ts +1 -1
  59. package/src/demos/basic/universal-llm-examples.ts +3 -3
  60. package/src/demos/diffusion-gemma/.env +29 -0
  61. package/src/demos/diffusion-gemma/.env.example +27 -0
  62. package/src/demos/diffusion-gemma/CLAUDE.md +95 -0
  63. package/src/demos/diffusion-gemma/README.md +59 -0
  64. package/src/demos/diffusion-gemma/canvas.ts +1606 -0
  65. package/src/demos/diffusion-gemma/docker-compose.yml +29 -0
  66. package/src/demos/diffusion-gemma/probe-stream.ts +51 -0
  67. package/src/demos/diffusion-gemma/probe-tools.ts +55 -0
  68. package/src/demos/diffusion-gemma/server.ts +1205 -0
  69. package/src/demos/diffusion-gemma/start-vllm.sh +98 -0
  70. package/src/gemma-channel.ts +47 -0
  71. package/src/gemma-diffusion.ts +167 -0
  72. package/src/http.ts +261 -247
  73. package/src/index.ts +180 -161
  74. package/src/interfaces.ts +843 -657
  75. package/src/mcp.ts +345 -345
  76. package/src/providers/anthropic.ts +796 -762
  77. package/src/providers/google.ts +840 -620
  78. package/src/providers/index.ts +8 -8
  79. package/src/providers/ollama.ts +503 -469
  80. package/src/providers/openai.ts +587 -392
  81. package/src/router.ts +785 -780
  82. package/src/stream-decoder.ts +535 -361
  83. package/src/structured-output.ts +759 -759
  84. package/src/test-scripts/test-google-deep-research.ts +33 -0
  85. package/src/test-scripts/test-google-streaming-enhanced.ts +147 -147
  86. package/src/test-scripts/test-google-streaming.ts +1 -1
  87. package/src/test-scripts/test-google-system-prompt-comprehensive.ts +189 -189
  88. package/src/test-scripts/test-google-thinking.ts +46 -0
  89. package/src/test-scripts/test-system-message-positions.ts +163 -163
  90. package/src/test-scripts/test-system-prompt-improvement-demo.ts +83 -83
  91. package/src/test-scripts/test-vllm-qwen36.ts +256 -0
  92. package/src/tests/ai-model.test.ts +1614 -1614
  93. package/src/tests/auditor.test.ts +224 -224
  94. package/src/tests/gemma-diffusion.test.ts +115 -0
  95. package/src/tests/http.test.ts +200 -200
  96. package/src/tests/interfaces.test.ts +117 -117
  97. package/src/tests/providers/anthropic.test.ts +118 -0
  98. package/src/tests/providers/google.test.ts +841 -660
  99. package/src/tests/providers/ollama.test.ts +1034 -954
  100. package/src/tests/providers/openai.test.ts +1511 -1122
  101. package/src/tests/router.test.ts +254 -254
  102. package/src/tests/stream-decoder.test.ts +263 -179
  103. package/src/tests/structured-output.test.ts +1450 -1450
  104. package/src/tests/thinking.test.ts +65 -0
  105. package/src/tests/tools.test.ts +175 -175
  106. package/src/thinking.ts +73 -0
  107. package/src/tools.ts +246 -246
  108. 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
- // Model info
51
- type ModelMetadata,
52
- // Helpers
53
- textContent,
54
- imageContent,
55
- multimodalMessage,
56
- extractTextContent,
57
- hasImages,
58
- audioContent,
59
- hasAudio,
60
- } from './interfaces.js';
61
-
62
- // ============================================================================
63
- // Observability
64
- // ============================================================================
65
-
66
- export {
67
- type Auditor,
68
- type AuditEvent,
69
- type AuditEventType,
70
- NoopAuditor,
71
- ConsoleAuditor,
72
- BufferedAuditor,
73
- } from './auditor.js';
74
-
75
- // ============================================================================
76
- // Stream Decoding
77
- // ============================================================================
78
-
79
- export {
80
- type StreamDecoder,
81
- type DecodedEvent,
82
- type DecoderCallback,
83
- type DecoderType,
84
- type DecoderOptions,
85
- type DecoderFactory,
86
- createDecoder,
87
- registerDecoder,
88
- getRegisteredDecoders,
89
- PassthroughDecoder,
90
- StandardChatDecoder,
91
- InterleavedReasoningDecoder,
92
- } from './stream-decoder.js';
93
-
94
- // ============================================================================
95
- // Tool Utilities
96
- // ============================================================================
97
-
98
- export {
99
- ToolBuilder,
100
- ToolExecutor,
101
- createTimeTool,
102
- createRandomNumberTool,
103
- } from './tools.js';
104
-
105
- // ============================================================================
106
- // HTTP Utilities (for advanced use cases)
107
- // ============================================================================
108
-
109
- export {
110
- httpRequest,
111
- httpStream,
112
- parseNDJSON,
113
- parseSSE,
114
- buildHeaders,
115
- type HttpRequestOptions,
116
- type HttpResponse,
117
- } from './http.js';
118
-
119
- // ============================================================================
120
- // MCP Integration
121
- // ============================================================================
122
-
123
- export {
124
- MCPToolBridge,
125
- type MCPBridgeConfig,
126
- type MCPServerConfig,
127
- type MCPTool,
128
- } from './mcp.js';
129
-
130
- // ============================================================================
131
- // Structured Output
132
- // ============================================================================
133
-
134
- export {
135
- StructuredOutputError,
136
- type StructuredOutputErrorOptions,
137
- type StructuredOutputOptions,
138
- type StructuredOutputResult,
139
- type StructuredOutputSuccess,
140
- type StructuredOutputFailure,
141
- type JSONSchema,
142
- type SchemaProvider,
143
- type ProviderSchema,
144
- type SchemaConfig,
145
- isStructuredOutputSuccess,
146
- isStructuredOutputFailure,
147
- // Schema conversion utilities
148
- normalizeJsonSchema,
149
- convertToProviderSchema,
150
- stripUnsupportedFeatures,
151
- getJsonSchema,
152
- getJsonSchemaFromConfig,
153
- // Validation functions
154
- parseStructured,
155
- tryParseStructured,
156
- validateStructuredOutput,
157
- stripJsonFences,
158
- // Streaming parser
159
- StreamingJsonParser,
160
- type StreamingStructuredResult,
161
- } from './structured-output.js';
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';