@inference-gateway/sdk 0.7.2 → 0.8.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/CHANGELOG.md CHANGED
@@ -2,6 +2,69 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.8.2](https://github.com/inference-gateway/typescript-sdk/compare/v0.8.1...v0.8.2) (2026-05-06)
6
+
7
+ ### 👷 CI
8
+
9
+ * Grant id-token write permission for npm Trusted Publishing ([36b2e88](https://github.com/inference-gateway/typescript-sdk/commit/36b2e881313b4b5d73ba6479eb5c7e664d4dd291))
10
+
11
+ ## [0.8.1](https://github.com/inference-gateway/typescript-sdk/compare/v0.8.0...v0.8.1) (2026-05-06)
12
+
13
+ ### 🐛 Bug Fixes
14
+
15
+ * Exclude test files from published npm tarball ([56a3f5e](https://github.com/inference-gateway/typescript-sdk/commit/56a3f5e2caeb15baa034e1b35d04f92a56ca96f2)), closes [package.json#files](https://github.com/inference-gateway/package.json/issues/files)
16
+
17
+ ## [0.8.0](https://github.com/inference-gateway/typescript-sdk/compare/v0.7.3...v0.8.0) (2026-05-06)
18
+
19
+ ### ✨ Features
20
+
21
+ * Adopt latest OpenAPI spec and preserve tool-call extra_content ([193184c](https://github.com/inference-gateway/typescript-sdk/commit/193184c5d9513fc8681606da860c409655f9453f))
22
+ * **providers:** Add Google provider support ([#21](https://github.com/inference-gateway/typescript-sdk/issues/21)) ([a6381d7](https://github.com/inference-gateway/typescript-sdk/commit/a6381d7357d22f32434599e204955fff4db2e3e0)), closes [#19](https://github.com/inference-gateway/typescript-sdk/issues/19)
23
+
24
+ ### ♻️ Improvements
25
+
26
+ * Rename all instances of deepseek-chat to deepseek-v4-flash ([465851e](https://github.com/inference-gateway/typescript-sdk/commit/465851e8f49fba153d1ded6add5d3511507ee50e))
27
+
28
+ ### 👷 CI
29
+
30
+ * Add Claude Code GitHub Workflow ([#20](https://github.com/inference-gateway/typescript-sdk/issues/20)) ([83e61a0](https://github.com/inference-gateway/typescript-sdk/commit/83e61a01fb2fcfc63f06ea2fc1cebb6076285b17))
31
+ * Bump all actions to latest ([d23eef1](https://github.com/inference-gateway/typescript-sdk/commit/d23eef13fa6f4d015059b98bd90a75c4b8f3ddf7))
32
+
33
+ ### 📚 Documentation
34
+
35
+ * Add more examples how to use this sdk ([#16](https://github.com/inference-gateway/typescript-sdk/issues/16)) ([5bddd0b](https://github.com/inference-gateway/typescript-sdk/commit/5bddd0beb693e1ed3341f8c48511dd5e9045729d))
36
+ * Add CLAUDE.md for project guidance and development instructions ([47645bf](https://github.com/inference-gateway/typescript-sdk/commit/47645bfd0f9e0f5c0c83051acbdd52253318522d))
37
+
38
+ ### 🔧 Miscellaneous
39
+
40
+ * Add .vscode to gitignore ([6e3117e](https://github.com/inference-gateway/typescript-sdk/commit/6e3117e0b6344747acc36ba21f747d10118560a2))
41
+ * Add issue templates ([769f017](https://github.com/inference-gateway/typescript-sdk/commit/769f017bf6810c687bc11795fbcb545ffaaaa446))
42
+ * Add project configuration and documentation ([f4bde02](https://github.com/inference-gateway/typescript-sdk/commit/f4bde02757e2d32512ec535e254217d3d81d76a0))
43
+ * Delete CLAUDE.md ([56bc06c](https://github.com/inference-gateway/typescript-sdk/commit/56bc06c85b061d6c7674173b60ab3dde6e0f9b69))
44
+ * **deps:** Bump all version to latest ([0d02bc5](https://github.com/inference-gateway/typescript-sdk/commit/0d02bc5045696a3046cb5460eeb1601b039accdb))
45
+ * **deps:** Install task runner for local env ([be7a77f](https://github.com/inference-gateway/typescript-sdk/commit/be7a77ffe5bcb05980a73604190661b2a079cb2e))
46
+ * **deps:** Update to their latest ([741971b](https://github.com/inference-gateway/typescript-sdk/commit/741971bd3d9f8a4ab80590b5c3b6a374dc292940))
47
+ * Download the latest oas ([9fcf5da](https://github.com/inference-gateway/typescript-sdk/commit/9fcf5da1b7cc12661e3222155c885fae77cb1931))
48
+ * Lock the versions of npm and node in package.json ([9690d75](https://github.com/inference-gateway/typescript-sdk/commit/9690d7501b8edd49bb30c9d0274247802c9bfde4))
49
+ * Remove deprecated lines from husky ([177d464](https://github.com/inference-gateway/typescript-sdk/commit/177d46459c9ffb190dbad41808e7f9ed207ed1e7))
50
+ * Replace devcontainer with Flox environment and streamline CI ([08c1eaf](https://github.com/inference-gateway/typescript-sdk/commit/08c1eaf3ac525153445ab2e1db5fc7b0c79c9457))
51
+ * Run task generate-types ([e01feff](https://github.com/inference-gateway/typescript-sdk/commit/e01feffba970085449bae28fcc49132f84e27ae8))
52
+ * Update GitHub Actions dependencies ([31006d8](https://github.com/inference-gateway/typescript-sdk/commit/31006d898f64d996d225818f3b93f38df644ae3f))
53
+
54
+ ### 🎨 Miscellaneous
55
+
56
+ * Fix markdown lint errors across all documentation ([419062d](https://github.com/inference-gateway/typescript-sdk/commit/419062d726106aa84b88f805a75f3acb48582ca7))
57
+
58
+ ## [0.7.3](https://github.com/inference-gateway/typescript-sdk/compare/v0.7.2...v0.7.3) (2025-06-01)
59
+
60
+ ### ♻️ Improvements
61
+
62
+ * Enhance stream processing with abort signal support and increase default timeout ([#18](https://github.com/inference-gateway/typescript-sdk/issues/18)) ([3778138](https://github.com/inference-gateway/typescript-sdk/commit/377813851b6635ca7aafe2a5c9888b720736c9f5))
63
+
64
+ ### 🔧 Miscellaneous
65
+
66
+ * Update MCP example README and remove unused example file ([99b34e7](https://github.com/inference-gateway/typescript-sdk/commit/99b34e70edf0c8aada1d0e0d0874481ea8381a79))
67
+
5
68
  ## [0.7.2](https://github.com/inference-gateway/typescript-sdk/compare/v0.7.1...v0.7.2) (2025-05-30)
6
69
 
7
70
  ### 📚 Documentation
package/README.md CHANGED
@@ -62,7 +62,8 @@ try {
62
62
 
63
63
  ### Listing MCP Tools
64
64
 
65
- To list available Model Context Protocol (MCP) tools (only available when EXPOSE_MCP is enabled):
65
+ To list available Model Context Protocol (MCP) tools (only available when
66
+ EXPOSE_MCP is enabled):
66
67
 
67
68
  ```typescript
68
69
  import { InferenceGatewayClient } from '@inference-gateway/sdk';
@@ -116,7 +117,7 @@ try {
116
117
  },
117
118
  ],
118
119
  },
119
- Provider.OpenAI
120
+ Provider.openai
120
121
  ); // Provider is optional
121
122
 
122
123
  console.log('Response:', response.choices[0].message.content);
@@ -159,7 +160,7 @@ try {
159
160
  onFinish: () => console.log('\nStream completed'),
160
161
  onError: (error) => console.error('Stream error:', error),
161
162
  },
162
- Provider.Groq // Provider is optional
163
+ Provider.groq // Provider is optional
163
164
  );
164
165
  } catch (error) {
165
166
  console.error('Error:', error);
@@ -241,7 +242,7 @@ const client = new InferenceGatewayClient({
241
242
  });
242
243
 
243
244
  try {
244
- const response = await client.proxy(Provider.OpenAI, 'embeddings', {
245
+ const response = await client.proxy(Provider.openai, 'embeddings', {
245
246
  method: 'POST',
246
247
  body: JSON.stringify({
247
248
  model: 'text-embedding-ada-002',
@@ -300,7 +301,8 @@ For more examples, check the [examples directory](./examples).
300
301
 
301
302
  ## Contributing
302
303
 
303
- Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file for information about how to get involved. We welcome issues, questions, and pull requests.
304
+ Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file for information
305
+ about how to get involved. We welcome issues, questions, and pull requests.
304
306
 
305
307
  ## License
306
308
 
@@ -54,8 +54,9 @@ export declare class InferenceGatewayClient {
54
54
  * @param request - Chat completion request (must include at least model and messages)
55
55
  * @param callbacks - Callbacks for handling streaming events
56
56
  * @param provider - Optional provider to use for this request
57
+ * @param abortSignal - Optional AbortSignal to cancel the request
57
58
  */
58
- streamChatCompletion(request: Omit<SchemaCreateChatCompletionRequest, 'stream' | 'stream_options'>, callbacks: ChatCompletionStreamCallbacks, provider?: Provider): Promise<void>;
59
+ streamChatCompletion(request: Omit<SchemaCreateChatCompletionRequest, 'stream' | 'stream_options'>, callbacks: ChatCompletionStreamCallbacks, provider?: Provider, abortSignal?: AbortSignal): Promise<void>;
59
60
  /**
60
61
  * Initiates a streaming request to the chat completions endpoint
61
62
  */
@@ -13,12 +13,15 @@ class StreamProcessor {
13
13
  this.callbacks = callbacks;
14
14
  this.clientProvidedTools = clientProvidedTools;
15
15
  }
16
- async processStream(body) {
16
+ async processStream(body, abortSignal) {
17
17
  const reader = body.getReader();
18
18
  const decoder = new TextDecoder();
19
19
  let buffer = '';
20
20
  try {
21
21
  while (true) {
22
+ if (abortSignal?.aborted) {
23
+ throw new Error('Stream processing was aborted');
24
+ }
22
25
  const { done, value } = await reader.read();
23
26
  if (done)
24
27
  break;
@@ -34,6 +37,10 @@ class StreamProcessor {
34
37
  }
35
38
  }
36
39
  catch (error) {
40
+ if (abortSignal?.aborted || error.name === 'AbortError') {
41
+ console.log('Stream processing was cancelled');
42
+ return;
43
+ }
37
44
  const apiError = {
38
45
  error: error.message || 'Unknown error',
39
46
  };
@@ -126,6 +133,7 @@ class StreamProcessor {
126
133
  name: toolCallChunk.function?.name || '',
127
134
  arguments: toolCallChunk.function?.arguments || '',
128
135
  },
136
+ extra_content: toolCallChunk.extra_content,
129
137
  });
130
138
  }
131
139
  else {
@@ -140,6 +148,9 @@ class StreamProcessor {
140
148
  existingToolCall.function.arguments +=
141
149
  toolCallChunk.function.arguments;
142
150
  }
151
+ if (toolCallChunk.extra_content) {
152
+ existingToolCall.extra_content = toolCallChunk.extra_content;
153
+ }
143
154
  }
144
155
  }
145
156
  }
@@ -150,10 +161,10 @@ class StreamProcessor {
150
161
  }
151
162
  }
152
163
  finalizeIncompleteToolCalls() {
153
- for (const [, toolCall] of this.incompleteToolCalls.entries()) {
164
+ this.incompleteToolCalls.forEach((toolCall) => {
154
165
  if (!toolCall.id || !toolCall.function.name) {
155
166
  globalThis.console.warn('Incomplete tool call detected:', toolCall);
156
- continue;
167
+ return;
157
168
  }
158
169
  const completedToolCall = {
159
170
  id: toolCall.id,
@@ -162,6 +173,9 @@ class StreamProcessor {
162
173
  name: toolCall.function.name,
163
174
  arguments: toolCall.function.arguments,
164
175
  },
176
+ ...(toolCall.extra_content && {
177
+ extra_content: toolCall.extra_content,
178
+ }),
165
179
  };
166
180
  if (this.isMCPTool(toolCall.function.name)) {
167
181
  try {
@@ -171,13 +185,20 @@ class StreamProcessor {
171
185
  this.callbacks.onMCPTool?.(completedToolCall);
172
186
  }
173
187
  catch (argError) {
174
- globalThis.console.warn(`Invalid MCP tool arguments for ${toolCall.function.name}:`, argError);
188
+ const isIncompleteJSON = toolCall.function.arguments &&
189
+ !toolCall.function.arguments.trim().endsWith('}');
190
+ if (isIncompleteJSON) {
191
+ globalThis.console.warn(`Incomplete MCP tool arguments for ${toolCall.function.name} (stream was likely interrupted):`, toolCall.function.arguments);
192
+ }
193
+ else {
194
+ globalThis.console.warn(`Invalid MCP tool arguments for ${toolCall.function.name}:`, argError);
195
+ }
175
196
  }
176
197
  }
177
198
  else {
178
199
  this.callbacks.onTool?.(completedToolCall);
179
200
  }
180
- }
201
+ });
181
202
  this.incompleteToolCalls.clear();
182
203
  }
183
204
  isMCPTool(toolName) {
@@ -199,7 +220,7 @@ class InferenceGatewayClient {
199
220
  this.apiKey = options.apiKey;
200
221
  this.defaultHeaders = options.defaultHeaders || {};
201
222
  this.defaultQuery = options.defaultQuery || {};
202
- this.timeout = options.timeout || 30000;
223
+ this.timeout = options.timeout || 60000; // Increased default timeout to 60 seconds
203
224
  this.fetchFn = options.fetch || globalThis.fetch;
204
225
  }
205
226
  /**
@@ -291,10 +312,11 @@ class InferenceGatewayClient {
291
312
  * @param request - Chat completion request (must include at least model and messages)
292
313
  * @param callbacks - Callbacks for handling streaming events
293
314
  * @param provider - Optional provider to use for this request
315
+ * @param abortSignal - Optional AbortSignal to cancel the request
294
316
  */
295
- async streamChatCompletion(request, callbacks, provider) {
317
+ async streamChatCompletion(request, callbacks, provider, abortSignal) {
296
318
  try {
297
- const response = await this.initiateStreamingRequest(request, provider);
319
+ const response = await this.initiateStreamingRequest(request, provider, abortSignal);
298
320
  if (!response.body) {
299
321
  const error = {
300
322
  error: 'Response body is not readable',
@@ -313,7 +335,7 @@ class InferenceGatewayClient {
313
335
  }
314
336
  }
315
337
  const streamProcessor = new StreamProcessor(callbacks, clientProvidedTools);
316
- await streamProcessor.processStream(response.body);
338
+ await streamProcessor.processStream(response.body, abortSignal);
317
339
  }
318
340
  catch (error) {
319
341
  const apiError = {
@@ -326,7 +348,7 @@ class InferenceGatewayClient {
326
348
  /**
327
349
  * Initiates a streaming request to the chat completions endpoint
328
350
  */
329
- async initiateStreamingRequest(request, provider) {
351
+ async initiateStreamingRequest(request, provider, abortSignal) {
330
352
  const query = {};
331
353
  if (provider) {
332
354
  query.provider = provider;
@@ -345,6 +367,9 @@ class InferenceGatewayClient {
345
367
  headers.set('Authorization', `Bearer ${this.apiKey}`);
346
368
  }
347
369
  const controller = new AbortController();
370
+ const combinedSignal = abortSignal
371
+ ? AbortSignal.any([abortSignal, controller.signal])
372
+ : controller.signal;
348
373
  const timeoutId = globalThis.setTimeout(() => controller.abort(), this.timeout);
349
374
  try {
350
375
  const response = await this.fetchFn(url, {
@@ -357,7 +382,7 @@ class InferenceGatewayClient {
357
382
  include_usage: true,
358
383
  },
359
384
  }),
360
- signal: controller.signal,
385
+ signal: combinedSignal,
361
386
  });
362
387
  if (!response.ok) {
363
388
  let errorMessage = `HTTP error! status: ${response.status}`;