universal-llm-client 3.0.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/LICENSE +21 -0
- package/README.md +414 -0
- package/dist/ai-model.d.ts +53 -0
- package/dist/ai-model.d.ts.map +1 -0
- package/dist/ai-model.js +159 -0
- package/dist/ai-model.js.map +1 -0
- package/dist/auditor.d.ts +78 -0
- package/dist/auditor.d.ts.map +1 -0
- package/dist/auditor.js +104 -0
- package/dist/auditor.js.map +1 -0
- package/dist/client.d.ts +75 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +240 -0
- package/dist/client.js.map +1 -0
- package/dist/http.d.ts +47 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +186 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +324 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +63 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/mcp.d.ts +85 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +255 -0
- package/dist/mcp.js.map +1 -0
- package/dist/providers/google.d.ts +33 -0
- package/dist/providers/google.d.ts.map +1 -0
- package/dist/providers/google.js +426 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/index.d.ts +7 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +7 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/ollama.d.ts +26 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +304 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +20 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +251 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/router.d.ts +87 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +260 -0
- package/dist/router.js.map +1 -0
- package/dist/stream-decoder.d.ts +112 -0
- package/dist/stream-decoder.d.ts.map +1 -0
- package/dist/stream-decoder.js +238 -0
- package/dist/stream-decoder.js.map +1 -0
- package/dist/tools.d.ts +78 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +207 -0
- package/dist/tools.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal LLM Client v3 — Stream Decoder
|
|
3
|
+
*
|
|
4
|
+
* Pluggable interface for decoding raw LLM token streams into typed events.
|
|
5
|
+
* Consumers select their strategy per-call: passthrough for raw speed,
|
|
6
|
+
* standard-chat for structured tool calls, or interleaved-reasoning
|
|
7
|
+
* for models that emit <think>/<progress> tags.
|
|
8
|
+
*/
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Passthrough Decoder
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Bare-bones decoder for raw text completions.
|
|
14
|
+
* No parsing, no tag awareness. All tokens → text events.
|
|
15
|
+
*/
|
|
16
|
+
export class PassthroughDecoder {
|
|
17
|
+
content = '';
|
|
18
|
+
callback;
|
|
19
|
+
constructor(callback) {
|
|
20
|
+
this.callback = callback;
|
|
21
|
+
}
|
|
22
|
+
push(token) {
|
|
23
|
+
this.content += token;
|
|
24
|
+
this.callback({ type: 'text', content: token });
|
|
25
|
+
}
|
|
26
|
+
flush() {
|
|
27
|
+
// Nothing to flush — all tokens emitted immediately
|
|
28
|
+
}
|
|
29
|
+
getCleanContent() {
|
|
30
|
+
return this.content;
|
|
31
|
+
}
|
|
32
|
+
getReasoning() {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Standard Chat Decoder
|
|
38
|
+
// ============================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Decoder for standard LLM chat patterns — text streaming with native
|
|
41
|
+
* reasoning and structured API tool calls. No text-level tag parsing.
|
|
42
|
+
*
|
|
43
|
+
* Streamed tokens are clean text → emitted as `text` events.
|
|
44
|
+
* Native reasoning tokens → accepted via `pushReasoning()`.
|
|
45
|
+
* Structured tool calls → accepted via `pushToolCalls()`.
|
|
46
|
+
*/
|
|
47
|
+
export class StandardChatDecoder {
|
|
48
|
+
content = '';
|
|
49
|
+
reasoning = '';
|
|
50
|
+
callback;
|
|
51
|
+
constructor(callback) {
|
|
52
|
+
this.callback = callback;
|
|
53
|
+
}
|
|
54
|
+
push(token) {
|
|
55
|
+
this.content += token;
|
|
56
|
+
this.callback({ type: 'text', content: token });
|
|
57
|
+
}
|
|
58
|
+
/** Feed native reasoning tokens from the provider */
|
|
59
|
+
pushReasoning(content) {
|
|
60
|
+
this.reasoning += content;
|
|
61
|
+
this.callback({ type: 'thinking', content });
|
|
62
|
+
}
|
|
63
|
+
/** Feed structured tool calls from the provider API response */
|
|
64
|
+
pushToolCalls(calls) {
|
|
65
|
+
this.callback({ type: 'tool_call', calls });
|
|
66
|
+
}
|
|
67
|
+
flush() {
|
|
68
|
+
// Nothing to flush — all events emitted as they arrive
|
|
69
|
+
}
|
|
70
|
+
getCleanContent() {
|
|
71
|
+
return this.content;
|
|
72
|
+
}
|
|
73
|
+
getReasoning() {
|
|
74
|
+
return this.reasoning || undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Interleaved Reasoning Decoder
|
|
79
|
+
// ============================================================================
|
|
80
|
+
/**
|
|
81
|
+
* Decoder for models that emit interleaved reasoning tags in text.
|
|
82
|
+
* Parses <think>...</think> and <progress>...</progress> tags from the
|
|
83
|
+
* raw token stream and emits typed events for each.
|
|
84
|
+
*
|
|
85
|
+
* Handles streaming where tags may be split across chunks.
|
|
86
|
+
*/
|
|
87
|
+
export class InterleavedReasoningDecoder {
|
|
88
|
+
buffer = '';
|
|
89
|
+
content = '';
|
|
90
|
+
reasoning = '';
|
|
91
|
+
callback;
|
|
92
|
+
inThink = false;
|
|
93
|
+
inProgress = false;
|
|
94
|
+
constructor(callback) {
|
|
95
|
+
this.callback = callback;
|
|
96
|
+
}
|
|
97
|
+
push(token) {
|
|
98
|
+
this.buffer += token;
|
|
99
|
+
this.processBuffer();
|
|
100
|
+
}
|
|
101
|
+
flush() {
|
|
102
|
+
// Emit any remaining buffer content as text
|
|
103
|
+
if (this.buffer.length > 0) {
|
|
104
|
+
if (this.inThink) {
|
|
105
|
+
this.reasoning += this.buffer;
|
|
106
|
+
this.callback({ type: 'thinking', content: this.buffer });
|
|
107
|
+
}
|
|
108
|
+
else if (this.inProgress) {
|
|
109
|
+
this.callback({ type: 'progress', content: this.buffer });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.content += this.buffer;
|
|
113
|
+
this.callback({ type: 'text', content: this.buffer });
|
|
114
|
+
}
|
|
115
|
+
this.buffer = '';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
getCleanContent() {
|
|
119
|
+
return this.content;
|
|
120
|
+
}
|
|
121
|
+
getReasoning() {
|
|
122
|
+
return this.reasoning || undefined;
|
|
123
|
+
}
|
|
124
|
+
processBuffer() {
|
|
125
|
+
let safety = 0;
|
|
126
|
+
while (this.buffer.length > 0 && safety++ < 200) {
|
|
127
|
+
if (this.inThink) {
|
|
128
|
+
const closeIdx = this.buffer.indexOf('</think>');
|
|
129
|
+
if (closeIdx === -1) {
|
|
130
|
+
// Might have partial closing tag at end
|
|
131
|
+
if (this.buffer.endsWith('<') || this.buffer.endsWith('</') ||
|
|
132
|
+
this.buffer.endsWith('</t') || this.buffer.endsWith('</th') ||
|
|
133
|
+
this.buffer.endsWith('</thi') || this.buffer.endsWith('</thin') ||
|
|
134
|
+
this.buffer.endsWith('</think')) {
|
|
135
|
+
return; // Wait for more data
|
|
136
|
+
}
|
|
137
|
+
this.reasoning += this.buffer;
|
|
138
|
+
this.callback({ type: 'thinking', content: this.buffer });
|
|
139
|
+
this.buffer = '';
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const thinkContent = this.buffer.slice(0, closeIdx);
|
|
143
|
+
if (thinkContent) {
|
|
144
|
+
this.reasoning += thinkContent;
|
|
145
|
+
this.callback({ type: 'thinking', content: thinkContent });
|
|
146
|
+
}
|
|
147
|
+
this.buffer = this.buffer.slice(closeIdx + 8); // '</think>'.length
|
|
148
|
+
this.inThink = false;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (this.inProgress) {
|
|
152
|
+
const closeIdx = this.buffer.indexOf('</progress>');
|
|
153
|
+
if (closeIdx === -1) {
|
|
154
|
+
if (this.couldBePartialTag(this.buffer, '</progress>'))
|
|
155
|
+
return;
|
|
156
|
+
this.callback({ type: 'progress', content: this.buffer });
|
|
157
|
+
this.buffer = '';
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const progressContent = this.buffer.slice(0, closeIdx);
|
|
161
|
+
if (progressContent) {
|
|
162
|
+
this.callback({ type: 'progress', content: progressContent });
|
|
163
|
+
}
|
|
164
|
+
this.buffer = this.buffer.slice(closeIdx + 11); // '</progress>'.length
|
|
165
|
+
this.inProgress = false;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
// Look for opening tags
|
|
169
|
+
const thinkIdx = this.buffer.indexOf('<think>');
|
|
170
|
+
const progressIdx = this.buffer.indexOf('<progress>');
|
|
171
|
+
// Find earliest tag
|
|
172
|
+
const nextTag = this.findEarliest(thinkIdx, progressIdx);
|
|
173
|
+
if (nextTag === -1) {
|
|
174
|
+
// No complete opening tags — check for partial tag at end
|
|
175
|
+
const lastAngle = this.buffer.lastIndexOf('<');
|
|
176
|
+
if (lastAngle >= 0 && lastAngle > this.buffer.length - 12) {
|
|
177
|
+
// Potential partial tag — emit text before it, keep the rest
|
|
178
|
+
const textBefore = this.buffer.slice(0, lastAngle);
|
|
179
|
+
if (textBefore) {
|
|
180
|
+
this.content += textBefore;
|
|
181
|
+
this.callback({ type: 'text', content: textBefore });
|
|
182
|
+
}
|
|
183
|
+
this.buffer = this.buffer.slice(lastAngle);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// No partial tags — emit all as text
|
|
187
|
+
this.content += this.buffer;
|
|
188
|
+
this.callback({ type: 'text', content: this.buffer });
|
|
189
|
+
this.buffer = '';
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// Emit text before the tag
|
|
193
|
+
const textBefore = this.buffer.slice(0, nextTag);
|
|
194
|
+
if (textBefore) {
|
|
195
|
+
this.content += textBefore;
|
|
196
|
+
this.callback({ type: 'text', content: textBefore });
|
|
197
|
+
}
|
|
198
|
+
if (nextTag === thinkIdx) {
|
|
199
|
+
this.buffer = this.buffer.slice(nextTag + 7); // '<think>'.length
|
|
200
|
+
this.inThink = true;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
this.buffer = this.buffer.slice(nextTag + 10); // '<progress>'.length
|
|
204
|
+
this.inProgress = true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
findEarliest(a, b) {
|
|
209
|
+
if (a === -1)
|
|
210
|
+
return b;
|
|
211
|
+
if (b === -1)
|
|
212
|
+
return a;
|
|
213
|
+
return Math.min(a, b);
|
|
214
|
+
}
|
|
215
|
+
couldBePartialTag(buffer, tag) {
|
|
216
|
+
for (let i = 1; i < tag.length; i++) {
|
|
217
|
+
if (buffer.endsWith(tag.slice(0, i)))
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Create a stream decoder by type.
|
|
225
|
+
*/
|
|
226
|
+
export function createDecoder(type, callback, _options) {
|
|
227
|
+
switch (type) {
|
|
228
|
+
case 'passthrough':
|
|
229
|
+
return new PassthroughDecoder(callback);
|
|
230
|
+
case 'standard-chat':
|
|
231
|
+
return new StandardChatDecoder(callback);
|
|
232
|
+
case 'interleaved-reasoning':
|
|
233
|
+
return new InterleavedReasoningDecoder(callback);
|
|
234
|
+
default:
|
|
235
|
+
throw new Error(`Unknown decoder type: ${type}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=stream-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-decoder.js","sourceRoot":"","sources":["../src/stream-decoder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgDH,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACnB,OAAO,GAAG,EAAE,CAAC;IACJ,QAAQ,CAAkB;IAE3C,YAAY,QAAyB;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,KAAa;QACd,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,KAAK;QACD,oDAAoD;IACxD,CAAC;IAED,eAAe;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,YAAY;QACR,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACpB,OAAO,GAAG,EAAE,CAAC;IACb,SAAS,GAAG,EAAE,CAAC;IACN,QAAQ,CAAkB;IAE3C,YAAY,QAAyB;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,KAAa;QACd,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,C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AC,CAAC;QACvB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1B,CAAC;IAEO,iBAAiB,CAAC,MAAc,EAAE,GAAW;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;QACtD,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAWD;;GAEG;AACH,MAAM,UAAU,aAAa,CACzB,IAAiB,EACjB,QAAyB,EACzB,QAAyB;IAEzB,QAAQ,IAAI,EAAE,CAAC;QACX,KAAK,aAAa;YACd,OAAO,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC5C,KAAK,eAAe;YAChB,OAAO,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC7C,KAAK,uBAAuB;YACxB,OAAO,IAAI,2BAA2B,CAAC,QAAQ,CAAC,CAAC;QACrD;YACI,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACL,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal LLM Client v3 — Tool Utilities
|
|
3
|
+
*
|
|
4
|
+
* ToolBuilder: Type-safe tool definition builder with fluent API.
|
|
5
|
+
* ToolExecutor: Execution wrappers with timeout and validation.
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMFunction, LLMToolDefinition, ToolHandler } from './interfaces.js';
|
|
8
|
+
/**
|
|
9
|
+
* Fluent builder for LLM tool definitions.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const tool = new ToolBuilder('get_weather')
|
|
13
|
+
* .description('Get current weather for a location')
|
|
14
|
+
* .addParameter('location', 'string', 'City name', true)
|
|
15
|
+
* .addParameter('units', 'string', 'Temperature units', false, { enum: ['celsius', 'fahrenheit'] })
|
|
16
|
+
* .build();
|
|
17
|
+
*/
|
|
18
|
+
export declare class ToolBuilder {
|
|
19
|
+
private name;
|
|
20
|
+
private desc;
|
|
21
|
+
private properties;
|
|
22
|
+
private required;
|
|
23
|
+
constructor(name: string);
|
|
24
|
+
description(desc: string): this;
|
|
25
|
+
addParameter(name: string, type: string, description: string, isRequired?: boolean, extra?: Record<string, unknown>): this;
|
|
26
|
+
build(): LLMToolDefinition;
|
|
27
|
+
/** Build and return the function definition only */
|
|
28
|
+
buildFunction(): LLMFunction;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Utility wrappers for creating safe tool handlers.
|
|
32
|
+
*/
|
|
33
|
+
export declare class ToolExecutor {
|
|
34
|
+
/**
|
|
35
|
+
* Wrap a handler with a timeout.
|
|
36
|
+
* Rejects if the handler doesn't complete within the specified ms.
|
|
37
|
+
*/
|
|
38
|
+
static withTimeout(handler: ToolHandler, timeoutMs: number): ToolHandler;
|
|
39
|
+
/**
|
|
40
|
+
* Wrap a handler to catch errors and return them as strings
|
|
41
|
+
* instead of throwing.
|
|
42
|
+
*/
|
|
43
|
+
static safe(handler: ToolHandler): ToolHandler;
|
|
44
|
+
/**
|
|
45
|
+
* Wrap a handler with argument validation.
|
|
46
|
+
* Checks that required fields are present before execution.
|
|
47
|
+
*/
|
|
48
|
+
static withValidation(handler: ToolHandler, requiredFields: string[]): ToolHandler;
|
|
49
|
+
/**
|
|
50
|
+
* Create a handler that measures execution time and
|
|
51
|
+
* returns both the result and duration.
|
|
52
|
+
*/
|
|
53
|
+
static timed(handler: ToolHandler): ToolHandler;
|
|
54
|
+
/**
|
|
55
|
+
* Compose multiple wrappers around a handler.
|
|
56
|
+
* Applied from right to left (innermost to outermost).
|
|
57
|
+
*/
|
|
58
|
+
static compose(handler: ToolHandler, ...wrappers: Array<(h: ToolHandler) => ToolHandler>): ToolHandler;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a get_current_time tool definition and handler.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createTimeTool(): {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
parameters: LLMFunction['parameters'];
|
|
67
|
+
handler: ToolHandler;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Create a random_number tool definition and handler.
|
|
71
|
+
*/
|
|
72
|
+
export declare function createRandomNumberTool(): {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
parameters: LLMFunction['parameters'];
|
|
76
|
+
handler: ToolHandler;
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAMnF;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAc;IAC1B,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,IAAI,EAAE,MAAM;IAIxB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK/B,YAAY,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,OAAe,EAC3B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,IAAI;IAYP,KAAK,IAAI,iBAAiB;IAe1B,qDAAqD;IACrD,aAAa,IAAI,WAAW;CAG/B;AAMD;;GAEG;AACH,qBAAa,YAAY;IACrB;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,WAAW;IAYxE;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW;IAY9C;;;OAGG;IACH,MAAM,CAAC,cAAc,CACjB,OAAO,EAAE,WAAW,EACpB,cAAc,EAAE,MAAM,EAAE,GACzB,WAAW;IAed;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW;IAW/C;;;OAGG;IACH,MAAM,CAAC,OAAO,CACV,OAAO,EAAE,WAAW,EACpB,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,WAAW,CAAC,GACpD,WAAW;CAGjB;AAMD;;GAEG;AACH,wBAAgB,cAAc,IAAI;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACtC,OAAO,EAAE,WAAW,CAAC;CACxB,CAqCA;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IACtC,OAAO,EAAE,WAAW,CAAC;CACxB,CAoBA"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal LLM Client v3 — Tool Utilities
|
|
3
|
+
*
|
|
4
|
+
* ToolBuilder: Type-safe tool definition builder with fluent API.
|
|
5
|
+
* ToolExecutor: Execution wrappers with timeout and validation.
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// ToolBuilder
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Fluent builder for LLM tool definitions.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* const tool = new ToolBuilder('get_weather')
|
|
15
|
+
* .description('Get current weather for a location')
|
|
16
|
+
* .addParameter('location', 'string', 'City name', true)
|
|
17
|
+
* .addParameter('units', 'string', 'Temperature units', false, { enum: ['celsius', 'fahrenheit'] })
|
|
18
|
+
* .build();
|
|
19
|
+
*/
|
|
20
|
+
export class ToolBuilder {
|
|
21
|
+
name;
|
|
22
|
+
desc = '';
|
|
23
|
+
properties = {};
|
|
24
|
+
required = [];
|
|
25
|
+
constructor(name) {
|
|
26
|
+
this.name = name;
|
|
27
|
+
}
|
|
28
|
+
description(desc) {
|
|
29
|
+
this.desc = desc;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
addParameter(name, type, description, isRequired = false, extra) {
|
|
33
|
+
this.properties[name] = {
|
|
34
|
+
type,
|
|
35
|
+
description,
|
|
36
|
+
...extra,
|
|
37
|
+
};
|
|
38
|
+
if (isRequired) {
|
|
39
|
+
this.required.push(name);
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
build() {
|
|
44
|
+
return {
|
|
45
|
+
type: 'function',
|
|
46
|
+
function: {
|
|
47
|
+
name: this.name,
|
|
48
|
+
description: this.desc,
|
|
49
|
+
parameters: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: this.properties,
|
|
52
|
+
required: this.required.length > 0 ? this.required : undefined,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Build and return the function definition only */
|
|
58
|
+
buildFunction() {
|
|
59
|
+
return this.build().function;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// ToolExecutor
|
|
64
|
+
// ============================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Utility wrappers for creating safe tool handlers.
|
|
67
|
+
*/
|
|
68
|
+
export class ToolExecutor {
|
|
69
|
+
/**
|
|
70
|
+
* Wrap a handler with a timeout.
|
|
71
|
+
* Rejects if the handler doesn't complete within the specified ms.
|
|
72
|
+
*/
|
|
73
|
+
static withTimeout(handler, timeoutMs) {
|
|
74
|
+
return async (args) => {
|
|
75
|
+
const result = await Promise.race([
|
|
76
|
+
Promise.resolve(handler(args)),
|
|
77
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(`Tool execution timeout after ${timeoutMs}ms`)), timeoutMs)),
|
|
78
|
+
]);
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Wrap a handler to catch errors and return them as strings
|
|
84
|
+
* instead of throwing.
|
|
85
|
+
*/
|
|
86
|
+
static safe(handler) {
|
|
87
|
+
return async (args) => {
|
|
88
|
+
try {
|
|
89
|
+
return await handler(args);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return {
|
|
93
|
+
error: error instanceof Error ? error.message : String(error),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Wrap a handler with argument validation.
|
|
100
|
+
* Checks that required fields are present before execution.
|
|
101
|
+
*/
|
|
102
|
+
static withValidation(handler, requiredFields) {
|
|
103
|
+
return async (args) => {
|
|
104
|
+
if (!args || typeof args !== 'object') {
|
|
105
|
+
throw new Error('Tool arguments must be an object');
|
|
106
|
+
}
|
|
107
|
+
const obj = args;
|
|
108
|
+
for (const field of requiredFields) {
|
|
109
|
+
if (obj[field] === undefined || obj[field] === null) {
|
|
110
|
+
throw new Error(`Missing required argument: ${field}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return handler(args);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a handler that measures execution time and
|
|
118
|
+
* returns both the result and duration.
|
|
119
|
+
*/
|
|
120
|
+
static timed(handler) {
|
|
121
|
+
return async (args) => {
|
|
122
|
+
const start = Date.now();
|
|
123
|
+
const result = await handler(args);
|
|
124
|
+
return {
|
|
125
|
+
result,
|
|
126
|
+
duration: Date.now() - start,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Compose multiple wrappers around a handler.
|
|
132
|
+
* Applied from right to left (innermost to outermost).
|
|
133
|
+
*/
|
|
134
|
+
static compose(handler, ...wrappers) {
|
|
135
|
+
return wrappers.reduceRight((h, wrapper) => wrapper(h), handler);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// ============================================================================
|
|
139
|
+
// Common Tool Definitions
|
|
140
|
+
// ============================================================================
|
|
141
|
+
/**
|
|
142
|
+
* Create a get_current_time tool definition and handler.
|
|
143
|
+
*/
|
|
144
|
+
export function createTimeTool() {
|
|
145
|
+
return {
|
|
146
|
+
name: 'get_current_time',
|
|
147
|
+
description: 'Get the current date and time',
|
|
148
|
+
parameters: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: {
|
|
151
|
+
timezone: {
|
|
152
|
+
type: 'string',
|
|
153
|
+
description: 'IANA timezone (e.g. "America/New_York"). Defaults to UTC.',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
handler: (args) => {
|
|
158
|
+
const { timezone } = (args ?? {});
|
|
159
|
+
const now = new Date();
|
|
160
|
+
try {
|
|
161
|
+
return {
|
|
162
|
+
iso: now.toISOString(),
|
|
163
|
+
formatted: now.toLocaleString('en-US', {
|
|
164
|
+
timeZone: timezone || 'UTC',
|
|
165
|
+
dateStyle: 'full',
|
|
166
|
+
timeStyle: 'long',
|
|
167
|
+
}),
|
|
168
|
+
timezone: timezone || 'UTC',
|
|
169
|
+
timestamp: now.getTime(),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return {
|
|
174
|
+
iso: now.toISOString(),
|
|
175
|
+
formatted: now.toUTCString(),
|
|
176
|
+
timezone: 'UTC',
|
|
177
|
+
timestamp: now.getTime(),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Create a random_number tool definition and handler.
|
|
185
|
+
*/
|
|
186
|
+
export function createRandomNumberTool() {
|
|
187
|
+
return {
|
|
188
|
+
name: 'random_number',
|
|
189
|
+
description: 'Generate a random number within a range',
|
|
190
|
+
parameters: {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
min: { type: 'number', description: 'Minimum value (default 0)' },
|
|
194
|
+
max: { type: 'number', description: 'Maximum value (default 100)' },
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
handler: (args) => {
|
|
198
|
+
const { min = 0, max = 100 } = (args ?? {});
|
|
199
|
+
return {
|
|
200
|
+
value: Math.floor(Math.random() * (max - min + 1)) + min,
|
|
201
|
+
min,
|
|
202
|
+
max,
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;;;;;;;;GASG;AACH,MAAM,OAAO,WAAW;IACZ,IAAI,CAAS;IACb,IAAI,GAAW,EAAE,CAAC;IAClB,UAAU,GAA4B,EAAE,CAAC;IACzC,QAAQ,GAAa,EAAE,CAAC;IAEhC,YAAY,IAAY;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,WAAW,CAAC,IAAY;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,YAAY,CACR,IAAY,EACZ,IAAY,EACZ,WAAmB,EACnB,aAAsB,KAAK,EAC3B,KAA+B;QAE/B,IAAI,CAAC,UAAU,CAA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AK;oBACf,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE;iBAC3B,CAAC;YACN,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IAMlC,OAAO;QACH,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,yCAAyC;QACtD,UAAU,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACR,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B,EAAE;gBACjE,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,6BAA6B,EAAE;aACtE;SACJ;QACD,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE;YACvB,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAmC,CAAC;YAC9E,OAAO;gBACH,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;gBACxD,GAAG;gBACH,GAAG;aACN,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "universal-llm-client",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A universal LLM client with transparent provider failover, streaming tool execution, pluggable reasoning, and native observability.",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./interfaces": {
|
|
14
|
+
"import": "./dist/interfaces.js",
|
|
15
|
+
"types": "./dist/interfaces.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./tools": {
|
|
18
|
+
"import": "./dist/tools.js",
|
|
19
|
+
"types": "./dist/tools.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./auditor": {
|
|
22
|
+
"import": "./dist/auditor.js",
|
|
23
|
+
"types": "./dist/auditor.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./stream-decoder": {
|
|
26
|
+
"import": "./dist/stream-decoder.js",
|
|
27
|
+
"types": "./dist/stream-decoder.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./http": {
|
|
30
|
+
"import": "./dist/http.js",
|
|
31
|
+
"types": "./dist/http.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bun run clean && bun run compile",
|
|
41
|
+
"clean": "rimraf dist",
|
|
42
|
+
"compile": "tsc --project tsconfig.json",
|
|
43
|
+
"dev": "tsc --watch --project tsconfig.json",
|
|
44
|
+
"prepublishOnly": "bun run build",
|
|
45
|
+
"test": "bun test",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"lint": "tsc --noEmit --strict",
|
|
48
|
+
"prepack": "bun run build"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"llm",
|
|
52
|
+
"ai",
|
|
53
|
+
"artificial-intelligence",
|
|
54
|
+
"openai",
|
|
55
|
+
"ollama",
|
|
56
|
+
"google-gemini",
|
|
57
|
+
"vertex-ai",
|
|
58
|
+
"universal",
|
|
59
|
+
"failover",
|
|
60
|
+
"streaming",
|
|
61
|
+
"tool-calling",
|
|
62
|
+
"function-calling",
|
|
63
|
+
"mcp",
|
|
64
|
+
"observability",
|
|
65
|
+
"typescript",
|
|
66
|
+
"esm"
|
|
67
|
+
],
|
|
68
|
+
"dependencies": {},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@types/node": "^22.0.0",
|
|
71
|
+
"rimraf": "^6.0.1",
|
|
72
|
+
"typescript": "^5.8.3"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@modelcontextprotocol/sdk": ">=1.24.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@modelcontextprotocol/sdk": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=22.0.0",
|
|
84
|
+
"bun": ">=1.0.0"
|
|
85
|
+
},
|
|
86
|
+
"license": "MIT",
|
|
87
|
+
"repository": {
|
|
88
|
+
"type": "git",
|
|
89
|
+
"url": "https://github.com/igorls/universal-llm-client.git"
|
|
90
|
+
}
|
|
91
|
+
}
|