@node-llm/core 1.5.1 → 1.5.4

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 (45) hide show
  1. package/README.md +42 -84
  2. package/dist/chat/Chat.d.ts +9 -21
  3. package/dist/chat/Chat.d.ts.map +1 -1
  4. package/dist/chat/Chat.js +83 -122
  5. package/dist/chat/ChatOptions.d.ts +3 -3
  6. package/dist/chat/ChatOptions.d.ts.map +1 -1
  7. package/dist/chat/ChatStream.d.ts +3 -21
  8. package/dist/chat/ChatStream.d.ts.map +1 -1
  9. package/dist/chat/ChatStream.js +96 -97
  10. package/dist/chat/Content.d.ts +10 -0
  11. package/dist/chat/Content.d.ts.map +1 -1
  12. package/dist/chat/Content.js +34 -1
  13. package/dist/chat/Tool.d.ts +6 -0
  14. package/dist/chat/Tool.d.ts.map +1 -1
  15. package/dist/chat/ToolHandler.d.ts +11 -0
  16. package/dist/chat/ToolHandler.d.ts.map +1 -0
  17. package/dist/chat/ToolHandler.js +42 -0
  18. package/dist/chat/Validation.d.ts +10 -0
  19. package/dist/chat/Validation.d.ts.map +1 -0
  20. package/dist/chat/Validation.js +33 -0
  21. package/dist/config.d.ts +43 -14
  22. package/dist/config.d.ts.map +1 -1
  23. package/dist/config.js +58 -13
  24. package/dist/errors/index.d.ts +8 -0
  25. package/dist/errors/index.d.ts.map +1 -1
  26. package/dist/errors/index.js +13 -0
  27. package/dist/llm.d.ts.map +1 -1
  28. package/dist/llm.js +18 -7
  29. package/dist/providers/gemini/Image.js +1 -1
  30. package/dist/providers/openai/Capabilities.d.ts +1 -0
  31. package/dist/providers/openai/Capabilities.d.ts.map +1 -1
  32. package/dist/providers/openai/Capabilities.js +3 -0
  33. package/dist/providers/openai/Chat.d.ts.map +1 -1
  34. package/dist/providers/openai/Chat.js +13 -4
  35. package/dist/providers/openai/Streaming.d.ts.map +1 -1
  36. package/dist/providers/openai/Streaming.js +7 -2
  37. package/dist/providers/openai/types.d.ts +4 -0
  38. package/dist/providers/openai/types.d.ts.map +1 -1
  39. package/dist/utils/Binary.d.ts.map +1 -1
  40. package/dist/utils/Binary.js +10 -11
  41. package/dist/utils/audio.js +1 -1
  42. package/dist/utils/fetch.d.ts.map +1 -1
  43. package/dist/utils/fetch.js +15 -4
  44. package/dist/utils/logger.js +1 -1
  45. package/package.json +1 -1
package/dist/config.js CHANGED
@@ -1,21 +1,66 @@
1
1
  import { DEFAULT_MAX_TOOL_CALLS, DEFAULT_MAX_RETRIES, DEFAULT_REQUEST_TIMEOUT, DEFAULT_MAX_TOKENS, DEFAULT_TOOL_EXECUTION, DEFAULT_OLLAMA_BASE_URL } from "./constants.js";
2
- class Configuration {
3
- openaiApiKey = process.env.OPENAI_API_KEY?.trim();
4
- openaiApiBase = process.env.OPENAI_API_BASE?.trim();
5
- anthropicApiKey = process.env.ANTHROPIC_API_KEY?.trim();
6
- anthropicApiBase = process.env.ANTHROPIC_API_BASE?.trim();
7
- geminiApiKey = process.env.GEMINI_API_KEY?.trim();
8
- geminiApiBase = process.env.GEMINI_API_BASE?.trim();
9
- deepseekApiKey = process.env.DEEPSEEK_API_KEY?.trim();
10
- deepseekApiBase = process.env.DEEPSEEK_API_BASE?.trim();
11
- ollamaApiBase = process.env.OLLAMA_API_BASE?.trim() || DEFAULT_OLLAMA_BASE_URL;
12
- openrouterApiKey = process.env.OPENROUTER_API_KEY?.trim();
13
- openrouterApiBase = process.env.OPENROUTER_API_BASE?.trim();
14
- debug = process.env.NODELLM_DEBUG === "true";
2
+ export class Configuration {
3
+ _openaiApiKey;
4
+ _openaiApiBase;
5
+ _anthropicApiKey;
6
+ _anthropicApiBase;
7
+ _geminiApiKey;
8
+ _geminiApiBase;
9
+ _deepseekApiKey;
10
+ _deepseekApiBase;
11
+ _ollamaApiBase;
12
+ _openrouterApiKey;
13
+ _openrouterApiBase;
14
+ _debug;
15
+ get openaiApiKey() { return this._openaiApiKey ?? process.env.OPENAI_API_KEY?.trim(); }
16
+ set openaiApiKey(v) { this._openaiApiKey = v; }
17
+ get openaiApiBase() { return this._openaiApiBase ?? process.env.OPENAI_API_BASE?.trim(); }
18
+ set openaiApiBase(v) { this._openaiApiBase = v; }
19
+ get anthropicApiKey() { return this._anthropicApiKey ?? process.env.ANTHROPIC_API_KEY?.trim(); }
20
+ set anthropicApiKey(v) { this._anthropicApiKey = v; }
21
+ get anthropicApiBase() { return this._anthropicApiBase ?? process.env.ANTHROPIC_API_BASE?.trim(); }
22
+ set anthropicApiBase(v) { this._anthropicApiBase = v; }
23
+ get geminiApiKey() { return this._geminiApiKey ?? process.env.GEMINI_API_KEY?.trim(); }
24
+ set geminiApiKey(v) { this._geminiApiKey = v; }
25
+ get geminiApiBase() { return this._geminiApiBase ?? process.env.GEMINI_API_BASE?.trim(); }
26
+ set geminiApiBase(v) { this._geminiApiBase = v; }
27
+ get deepseekApiKey() { return this._deepseekApiKey ?? process.env.DEEPSEEK_API_KEY?.trim(); }
28
+ set deepseekApiKey(v) { this._deepseekApiKey = v; }
29
+ get deepseekApiBase() { return this._deepseekApiBase ?? process.env.DEEPSEEK_API_BASE?.trim(); }
30
+ set deepseekApiBase(v) { this._deepseekApiBase = v; }
31
+ get ollamaApiBase() { return this._ollamaApiBase ?? process.env.OLLAMA_API_BASE?.trim() ?? DEFAULT_OLLAMA_BASE_URL; }
32
+ set ollamaApiBase(v) { this._ollamaApiBase = v; }
33
+ get openrouterApiKey() { return this._openrouterApiKey ?? process.env.OPENROUTER_API_KEY?.trim(); }
34
+ set openrouterApiKey(v) { this._openrouterApiKey = v; }
35
+ get openrouterApiBase() { return this._openrouterApiBase ?? process.env.OPENROUTER_API_BASE?.trim(); }
36
+ set openrouterApiBase(v) { this._openrouterApiBase = v; }
37
+ get debug() { return this._debug ?? process.env.NODELLM_DEBUG === "true"; }
38
+ set debug(v) { this._debug = v; }
15
39
  maxToolCalls = DEFAULT_MAX_TOOL_CALLS;
16
40
  maxRetries = DEFAULT_MAX_RETRIES;
17
41
  requestTimeout = DEFAULT_REQUEST_TIMEOUT;
18
42
  maxTokens = DEFAULT_MAX_TOKENS;
19
43
  toolExecution = DEFAULT_TOOL_EXECUTION;
44
+ /**
45
+ * Returns a plain object with all configuration values.
46
+ * This is useful for cloning or serialization.
47
+ * It handles getters (lazy-loaded values) correctly.
48
+ */
49
+ toPlainObject() {
50
+ const plain = { ...this }; // Capture all enumerable "own" properties (custom keys, overrides)
51
+ // Capture all getters from the class prototype (lazy-loaded values)
52
+ const prototype = Object.getPrototypeOf(this);
53
+ const propertyNames = Object.getOwnPropertyNames(prototype);
54
+ for (const name of propertyNames) {
55
+ if (name === "constructor")
56
+ continue;
57
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
58
+ if (descriptor && descriptor.get) {
59
+ // Trigger the getter to snapshot the live value (including env fallbacks)
60
+ plain[name] = this[name];
61
+ }
62
+ }
63
+ return plain;
64
+ }
20
65
  }
21
66
  export const config = new Configuration();
@@ -85,4 +85,12 @@ export declare class ModelCapabilityError extends LLMError {
85
85
  readonly capability: string;
86
86
  constructor(model: string, capability: string);
87
87
  }
88
+ /**
89
+ * Thrown when a tool execution fails
90
+ */
91
+ export declare class ToolError extends LLMError {
92
+ readonly toolName?: string | undefined;
93
+ readonly fatal: boolean;
94
+ constructor(message: string, toolName?: string | undefined, fatal?: boolean);
95
+ }
88
96
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aACY,IAAI,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAkB,IAAI,CAAC,EAAE,MAAM,YAAA;CAK3D;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,QAAQ;aAGlB,MAAM,EAAE,MAAM;aACd,IAAI,EAAE,GAAG;aACT,QAAQ,CAAC,EAAE,MAAM;aACjB,KAAK,CAAC,EAAE,MAAM;g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gBAF9B,OAAO,EAAE,MAAM,EACC,QAAQ,CAAC,EAAE,MAAM,YAAA,EACjB,KAAK,GAAE,OAAe;CAKzC"}
@@ -127,3 +127,16 @@ export class ModelCapabilityError extends LLMError {
127
127
  this.capability = capability;
128
128
  }
129
129
  }
130
+ /**
131
+ * Thrown when a tool execution fails
132
+ */
133
+ export class ToolError extends LLMError {
134
+ toolName;
135
+ fatal;
136
+ constructor(message, toolName, fatal = false) {
137
+ super(message, "TOOL_ERROR");
138
+ this.toolName = toolName;
139
+ this.fatal = fatal;
140
+ this.name = "ToolError";
141
+ }
142
+ }
package/dist/llm.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,QAAQ,EACR,SAAS,EAIV,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AASrD,OAAO,EAAU,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yBAAyB,CAAC,EAAE,MAAM,C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CAE/C;IAED,IAAI,qBAAqB,IAAI,MAAM,GAAG,SAAS,CAE9C;IAED,cAAc;IAIR,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAqB3I,KAAK,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GACtG,OAAO,CAAC,SAAS,CAAC;CAsBtB;AAED,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAEhD,eAAO,MAAM,OAAO,aAAoB,CAAC"}
package/dist/llm.js CHANGED
@@ -7,7 +7,8 @@ import { Moderation } from "./moderation/Moderation.js";
7
7
  import { Embedding } from "./embedding/Embedding.js";
8
8
  import { ProviderNotConfiguredError, UnsupportedFeatureError, ModelCapabilityError } from "./errors/index.js";
9
9
  import { resolveModelAlias } from "./model_aliases.js";
10
- import { config } from "./config.js";
10
+ import { logger } from "./utils/logger.js";
11
+ import { config, Configuration } from "./config.js";
11
12
  // Provider registration map
12
13
  const PROVIDER_REGISTRARS = {
13
14
  openai: ensureOpenAIRegistered,
@@ -33,7 +34,16 @@ export class NodeLLMCore {
33
34
  * Create a new LLM instance. Defaults to the global config.
34
35
  */
35
36
  constructor(customConfig) {
36
- this.config = customConfig || config;
37
+ if (customConfig instanceof Configuration) {
38
+ this.config = customConfig;
39
+ }
40
+ else if (customConfig) {
41
+ this.config = new Configuration();
42
+ Object.assign(this.config, customConfig);
43
+ }
44
+ else {
45
+ this.config = config;
46
+ }
37
47
  if (this.config.maxRetries !== undefined) {
38
48
  this.retry.attempts = this.config.maxRetries + 1;
39
49
  }
@@ -66,7 +76,8 @@ export class NodeLLMCore {
66
76
  * ```
67
77
  */
68
78
  withProvider(providerName, scopedConfig) {
69
- const scoped = new NodeLLMCore({ ...this.config, ...scopedConfig });
79
+ const baseConfig = (this.config instanceof Configuration) ? this.config.toPlainObject() : this.config;
80
+ const scoped = new NodeLLMCore({ ...baseConfig, ...scopedConfig });
70
81
  scoped.configure({ provider: providerName });
71
82
  return scoped;
72
83
  }
@@ -155,7 +166,7 @@ export class NodeLLMCore {
155
166
  const rawModel = options?.model;
156
167
  const model = resolveModelAlias(rawModel || "", provider.id);
157
168
  if (options?.assumeModelExists) {
158
- console.warn(`[NodeLLM] Skipping validation for model ${model}`);
169
+ logger.warn(`Skipping validation for model ${model}`);
159
170
  }
160
171
  else if (model && provider.capabilities && !provider.capabilities.supportsImageGeneration(model)) {
161
172
  throw new ModelCapabilityError(model, "image generation");
@@ -173,7 +184,7 @@ export class NodeLLMCore {
173
184
  const rawModel = options?.model || this.defaultTranscriptionModelId || "";
174
185
  const model = resolveModelAlias(rawModel, provider.id);
175
186
  if (options?.assumeModelExists) {
176
- console.warn(`[NodeLLM] Skipping validation for model ${model}`);
187
+ logger.warn(`Skipping validation for model ${model}`);
177
188
  }
178
189
  else if (model && provider.capabilities && !provider.capabilities.supportsTranscription(model)) {
179
190
  throw new ModelCapabilityError(model, "transcription");
@@ -203,7 +214,7 @@ export class NodeLLMCore {
203
214
  const rawModel = options?.model || this.defaultModerationModelId || "";
204
215
  const model = resolveModelAlias(rawModel, provider.id);
205
216
  if (options?.assumeModelExists) {
206
- console.warn(`[NodeLLM] Skipping validation for model ${model}`);
217
+ logger.warn(`Skipping validation for model ${model}`);
207
218
  }
208
219
  else if (model && provider.capabilities && !provider.capabilities.supportsModeration(model)) {
209
220
  throw new ModelCapabilityError(model, "moderation");
@@ -227,7 +238,7 @@ export class NodeLLMCore {
227
238
  requestTimeout: options?.requestTimeout ?? this.config.requestTimeout,
228
239
  };
229
240
  if (options?.assumeModelExists) {
230
- console.warn(`[NodeLLM] Skipping validation for model ${request.model}`);
241
+ logger.warn(`Skipping validation for model ${request.model}`);
231
242
  }
232
243
  else if (request.model && provider.capabilities && !provider.capabilities.supportsEmbeddings(request.model)) {
233
244
  throw new ModelCapabilityError(request.model, "embeddings");
@@ -11,7 +11,7 @@ export class GeminiImage {
11
11
  const modelId = request.model || "imagen-4.0-generate-001";
12
12
  const url = `${this.baseUrl}/models/${modelId}:predict?key=${this.apiKey}`;
13
13
  if (request.size) {
14
- console.log(`[Gemini] Ignoring size ${request.size}. Gemini does not support image size customization.`);
14
+ logger.warn(`[Gemini] Ignoring size ${request.size}. Gemini does not support image size customization.`);
15
15
  }
16
16
  const body = {
17
17
  instances: [
@@ -11,6 +11,7 @@ export declare class Capabilities {
11
11
  static supportsModeration(modelId: string): boolean;
12
12
  static supportsReasoning(modelId: string): boolean;
13
13
  static supportsDeveloperRole(modelId: string): boolean;
14
+ static needsMaxCompletionTokens(modelId: string): boolean;
14
15
  static getModelType(modelId: string): "embeddings" | "audio" | "moderation" | "image" | "chat" | "audio_transcription" | "audio_speech";
15
16
  static getModalities(modelId: string): {
16
17
  input: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAUvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IASzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE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AG,IAAI;IAMxG,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAOjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;CAcxC"}
@@ -76,6 +76,9 @@ export class Capabilities {
76
76
  static supportsDeveloperRole(modelId) {
77
77
  return /gpt-4o|o1|o3/.test(modelId);
78
78
  }
79
+ static needsMaxCompletionTokens(modelId) {
80
+ return /o1|o3/.test(modelId);
81
+ }
79
82
  static getModelType(modelId) {
80
83
  if (this.supportsEmbeddings(modelId))
81
84
  return "embeddings";
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AASlE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,UAAU;IAGT,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI9F,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAgE3D"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AASlE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,UAAU;IAGT,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI9F,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA2E3D"}
@@ -20,7 +20,7 @@ export class OpenAIChat {
20
20
  const supportsDeveloperRole = isMainOpenAI && (typeof this.providerOrUrl === "string"
21
21
  ? Capabilities.supportsDeveloperRole(request.model)
22
22
  : this.providerOrUrl.capabilities?.supportsDeveloperRole(request.model));
23
- const { model, messages, tools, temperature: _, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
23
+ const { model, messages, tools, temperature: _, max_tokens, response_format, headers, requestTimeout, signal, ...rest } = request;
24
24
  const mappedMessages = mapSystemMessages(messages, !!supportsDeveloperRole);
25
25
  const body = {
26
26
  model,
@@ -29,8 +29,14 @@ export class OpenAIChat {
29
29
  };
30
30
  if (temperature !== undefined && temperature !== null)
31
31
  body.temperature = temperature;
32
- if (max_tokens)
33
- body.max_tokens = max_tokens;
32
+ if (max_tokens) {
33
+ if (Capabilities.needsMaxCompletionTokens(request.model)) {
34
+ body.max_completion_tokens = max_tokens;
35
+ }
36
+ else {
37
+ body.max_tokens = max_tokens;
38
+ }
39
+ }
34
40
  if (tools)
35
41
  body.tools = tools;
36
42
  if (response_format)
@@ -45,6 +51,7 @@ export class OpenAIChat {
45
51
  ...request.headers,
46
52
  },
47
53
  body: JSON.stringify(body),
54
+ signal,
48
55
  }, request.requestTimeout);
49
56
  if (!response.ok) {
50
57
  await handleOpenAIError(response, request.model);
@@ -54,16 +61,18 @@ export class OpenAIChat {
54
61
  const message = json.choices[0]?.message;
55
62
  const content = message?.content ?? null;
56
63
  const tool_calls = message?.tool_calls;
64
+ const reasoning = message?.reasoning_content || null;
57
65
  const usage = json.usage ? {
58
66
  input_tokens: json.usage.prompt_tokens,
59
67
  output_tokens: json.usage.completion_tokens,
60
68
  total_tokens: json.usage.total_tokens,
61
69
  cached_tokens: json.usage.prompt_tokens_details?.cached_tokens,
70
+ reasoning_tokens: json.usage.completion_tokens_details?.reasoning_tokens,
62
71
  } : undefined;
63
72
  if (!content && !tool_calls) {
64
73
  throw new Error("OpenAI returned empty response");
65
74
  }
66
75
  const calculatedUsage = usage ? ModelRegistry.calculateCost(usage, model, "openai") : undefined;
67
- return { content, tool_calls, usage: calculatedUsage };
76
+ return { content, tool_calls, usage: calculatedUsage, reasoning };
68
77
  }
69
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI7F,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CA8K7B"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI7F,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAkL7B"}
@@ -15,7 +15,7 @@ export class OpenAIStreaming {
15
15
  this.baseUrl = typeof providerOrUrl === "string" ? providerOrUrl : providerOrUrl.apiBase();
16
16
  }
17
17
  async *execute(request, controller) {
18
- const abortController = controller || new AbortController();
18
+ const abortController = controller || (request.signal ? { signal: request.signal } : new AbortController());
19
19
  const temperature = Capabilities.normalizeTemperature(request.temperature, request.model);
20
20
  const isMainOpenAI = this.baseUrl.includes("api.openai.com");
21
21
  const supportsDeveloperRole = isMainOpenAI && (typeof this.providerOrUrl === "string"
@@ -31,7 +31,12 @@ export class OpenAIStreaming {
31
31
  body.temperature = temperature;
32
32
  }
33
33
  if (request.max_tokens) {
34
- body.max_tokens = request.max_tokens;
34
+ if (Capabilities.needsMaxCompletionTokens(request.model)) {
35
+ body.max_completion_tokens = request.max_tokens;
36
+ }
37
+ else {
38
+ body.max_tokens = request.max_tokens;
39
+ }
35
40
  }
36
41
  if (request.response_format) {
37
42
  body.response_format = request.response_format;
@@ -8,6 +8,7 @@ export interface OpenAIChatResponse {
8
8
  message: {
9
9
  role: string;
10
10
  content: string | null;
11
+ reasoning_content?: string | null;
11
12
  tool_calls?: Array<{
12
13
  id: string;
13
14
  type: 'function';
@@ -26,6 +27,9 @@ export interface OpenAIChatResponse {
26
27
  prompt_tokens_details?: {
27
28
  cached_tokens?: number;
28
29
  };
30
+ completion_tokens_details?: {
31
+ reasoning_tokens?: number;
32
+ };
29
33
  };
30
34
  }
31
35
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,CAAC;QACb,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;YACvB,UAAU,CAAC,EAAE,KAAK,CAAC;gBACjB,EAAE,EAAE,MAAM,CAAC;gBACX,IAAI,EAAE,UAAU,CAAC;gBACjB,QAAQ,EAAE;oBACR,IAAI,EAAE,MAAM,CAAC;oBACb,SAAS,EAAE,MAAM,CAAC;iBACnB,CAAC;aACH,CAAC,CAAC;SACJ,CAAC;QACF,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,qBAAqB,CAAC,EAAE;YACtB,aAAa,CAAC,EAAE,MAAM,CAAC;SACxB,CAAC;KACH,CAAC;CACH"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,CAAC;QACb,OAAO,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;YACvB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YAClC,UAAU,CAAC,EAAE,KAAK,CAAC;gBACjB,EAAE,EAAE,MAAM,CAAC;gBACX,IAAI,EAAE,UAAU,CAAC;gBACjB,QAAQ,EAAE;oBACR,IAAI,EAAE,MAAM,CAAC;oBACb,SAAS,EAAE,MAAM,CAAC;iBACnB,CAAC;aACH,CAAC,CAAC;SACJ,CAAC;QACF,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE;QACN,aAAa,EAAE,MAAM,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,qBAAqB,CAAC,EAAE;YACtB,aAAa,CAAC,EAAE,MAAM,CAAC;SACxB,CAAC;QACF,yBAAyB,CAAC,EAAE;YAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;SAC3B,CAAC;KACH,CAAC;CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"Binary.d.ts","sourceRoot":"","sources":["../../src/utils/Binary.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW;IACtB;;OAEG;WACU,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA4C9D,OAAO,CAAC,MAAM,CAAC,aAAa;CAgB7B"}
1
+ {"version":3,"file":"Binary.d.ts","sourceRoot":"","sources":["../../src/utils/Binary.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW;IACtB;;OAEG;WACU,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA0C9D,OAAO,CAAC,MAAM,CAAC,aAAa;CAgB7B"}
@@ -1,5 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import { logger } from "./logger.js";
3
4
  export class BinaryUtils {
4
5
  /**
5
6
  * Converts a URL (data:, http:, or local path) to a base64 string and mime type.
@@ -28,25 +29,23 @@ export class BinaryUtils {
28
29
  };
29
30
  }
30
31
  catch (e) {
31
- console.error("Error converting URL to base64:", e);
32
+ logger.error("Error converting URL to base64:", e);
32
33
  return null;
33
34
  }
34
35
  }
35
36
  else {
36
37
  // Assume local file path
37
38
  try {
38
- if (fs.existsSync(url)) {
39
- const buffer = fs.readFileSync(url);
40
- const base64 = buffer.toString("base64");
41
- const mimeType = this.guessMimeType(url);
42
- return {
43
- mimeType,
44
- data: base64,
45
- };
46
- }
39
+ const buffer = await fs.promises.readFile(url);
40
+ const base64 = buffer.toString("base64");
41
+ const mimeType = this.guessMimeType(url);
42
+ return {
43
+ mimeType,
44
+ data: base64,
45
+ };
47
46
  }
48
47
  catch (e) {
49
- console.error("Error reading local file for base64:", e);
48
+ logger.error("Error reading local file for base64:", e);
50
49
  return null;
51
50
  }
52
51
  }
@@ -15,7 +15,7 @@ export class AudioUtils {
15
15
  fileName = path.basename(urlPath) || "audio.mp3";
16
16
  }
17
17
  else {
18
- const buffer = fs.readFileSync(filePath);
18
+ const buffer = await fs.promises.readFile(filePath);
19
19
  data = new Uint8Array(buffer);
20
20
  fileName = path.basename(filePath);
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
@@ -9,24 +9,35 @@
9
9
  * @throws Error if the request times out
10
10
  */
11
11
  export async function fetchWithTimeout(url, options = {}, timeoutMs) {
12
- // If no timeout is specified, use standard fetch
12
+ const userSignal = options.signal;
13
+ // If no timeout is specified and no user signal, use standard fetch
14
+ if ((!timeoutMs || timeoutMs <= 0) && !userSignal) {
15
+ return fetch(url, options);
16
+ }
17
+ // If only user signal (no timeout), use it directly
13
18
  if (!timeoutMs || timeoutMs <= 0) {
14
19
  return fetch(url, options);
15
20
  }
16
21
  const controller = new AbortController();
17
22
  const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
23
+ if (timeoutId.unref)
24
+ timeoutId.unref();
18
25
  try {
26
+ // Merge user signal with timeout signal
27
+ const mergedSignal = userSignal
28
+ ? AbortSignal.any([userSignal, controller.signal])
29
+ : controller.signal;
19
30
  const response = await fetch(url, {
20
31
  ...options,
21
- signal: controller.signal,
32
+ signal: mergedSignal,
22
33
  });
23
34
  clearTimeout(timeoutId);
24
35
  return response;
25
36
  }
26
37
  catch (error) {
27
38
  clearTimeout(timeoutId);
28
- // Check if the error was due to abort (timeout)
29
- if (error.name === 'AbortError') {
39
+ // Check if the error was due to timeout abort
40
+ if (error.name === 'AbortError' && controller.signal.aborted) {
30
41
  throw new Error(`Request timeout after ${timeoutMs}ms`);
31
42
  }
32
43
  throw error;
@@ -1,7 +1,7 @@
1
1
  import { config } from "../config.js";
2
2
  class Logger {
3
3
  isDebugEnabled() {
4
- return process.env.NODELLM_DEBUG === "true" || config.debug === true;
4
+ return config.debug === true;
5
5
  }
6
6
  debug(message, data) {
7
7
  if (this.isDebugEnabled()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-llm/core",
3
- "version": "1.5.1",
3
+ "version": "1.5.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",