@node-llm/core 1.0.0 → 1.2.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 (65) hide show
  1. package/README.md +0 -164
  2. package/dist/aliases.json +126 -0
  3. package/dist/chat/Chat.d.ts +4 -1
  4. package/dist/chat/Chat.d.ts.map +1 -1
  5. package/dist/chat/Chat.js +2 -3
  6. package/dist/chat/ChatStream.d.ts.map +1 -1
  7. package/dist/chat/ChatStream.js +85 -34
  8. package/dist/config.d.ts +1 -1
  9. package/dist/index.d.ts +10 -18
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +10 -12
  12. package/dist/llm.d.ts +2 -2
  13. package/dist/llm.d.ts.map +1 -1
  14. package/dist/llm.js +18 -9
  15. package/dist/model_aliases.d.ts +3 -0
  16. package/dist/model_aliases.d.ts.map +1 -0
  17. package/dist/model_aliases.js +20 -0
  18. package/dist/models/models.js +3 -3
  19. package/dist/providers/BaseProvider.d.ts +2 -0
  20. package/dist/providers/BaseProvider.d.ts.map +1 -1
  21. package/dist/providers/BaseProvider.js +3 -0
  22. package/dist/providers/Provider.d.ts +2 -3
  23. package/dist/providers/Provider.d.ts.map +1 -1
  24. package/dist/providers/anthropic/Chat.d.ts.map +1 -1
  25. package/dist/providers/anthropic/Chat.js +5 -1
  26. package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
  27. package/dist/providers/anthropic/Streaming.js +49 -2
  28. package/dist/providers/deepseek/Chat.d.ts.map +1 -1
  29. package/dist/providers/deepseek/Chat.js +5 -4
  30. package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
  31. package/dist/providers/deepseek/Streaming.js +49 -3
  32. package/dist/providers/gemini/Chat.d.ts.map +1 -1
  33. package/dist/providers/gemini/Chat.js +3 -0
  34. package/dist/providers/gemini/Embeddings.d.ts.map +1 -1
  35. package/dist/providers/gemini/Embeddings.js +3 -0
  36. package/dist/providers/gemini/Image.d.ts.map +1 -1
  37. package/dist/providers/gemini/Image.js +3 -0
  38. package/dist/providers/gemini/Streaming.d.ts.map +1 -1
  39. package/dist/providers/gemini/Streaming.js +32 -1
  40. package/dist/providers/gemini/Transcription.d.ts.map +1 -1
  41. package/dist/providers/gemini/Transcription.js +3 -0
  42. package/dist/providers/gemini/index.d.ts +1 -1
  43. package/dist/providers/gemini/index.js +1 -1
  44. package/dist/providers/ollama/index.d.ts +1 -1
  45. package/dist/providers/ollama/index.js +1 -1
  46. package/dist/providers/openai/Chat.d.ts.map +1 -1
  47. package/dist/providers/openai/Chat.js +5 -4
  48. package/dist/providers/openai/Embedding.d.ts.map +1 -1
  49. package/dist/providers/openai/Embedding.js +5 -1
  50. package/dist/providers/openai/Image.d.ts.map +1 -1
  51. package/dist/providers/openai/Image.js +5 -1
  52. package/dist/providers/openai/Moderation.d.ts.map +1 -1
  53. package/dist/providers/openai/Moderation.js +12 -6
  54. package/dist/providers/openai/Streaming.d.ts.map +1 -1
  55. package/dist/providers/openai/Streaming.js +53 -4
  56. package/dist/providers/openai/Transcription.d.ts.map +1 -1
  57. package/dist/providers/openai/Transcription.js +9 -2
  58. package/dist/providers/openai/index.d.ts +1 -1
  59. package/dist/providers/openai/index.js +1 -1
  60. package/dist/providers/openrouter/index.d.ts +1 -1
  61. package/dist/providers/openrouter/index.js +1 -1
  62. package/dist/utils/logger.d.ts +8 -0
  63. package/dist/utils/logger.d.ts.map +1 -1
  64. package/dist/utils/logger.js +22 -0
  65. package/package.json +1 -1
package/dist/llm.js CHANGED
@@ -6,6 +6,7 @@ import { Transcription } from "./transcription/Transcription.js";
6
6
  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
+ import { resolveModelAlias } from "./model_aliases.js";
9
10
  import { config } from "./config.js";
10
11
  // Provider registration map
11
12
  const PROVIDER_REGISTRARS = {
@@ -16,7 +17,7 @@ const PROVIDER_REGISTRARS = {
16
17
  ollama: registerOllamaProvider,
17
18
  openrouter: registerOpenRouterProvider,
18
19
  };
19
- class LLMCore {
20
+ class NodeLLMCore {
20
21
  models = ModelRegistry;
21
22
  config = config;
22
23
  provider;
@@ -79,7 +80,9 @@ class LLMCore {
79
80
  if (!this.provider) {
80
81
  throw new ProviderNotConfiguredError();
81
82
  }
82
- return new Chat(this.provider, model, options);
83
+ // Resolve model alias based on the current provider
84
+ const resolvedModel = resolveModelAlias(model, this.provider.id);
85
+ return new Chat(this.provider, resolvedModel, options, this.retry);
83
86
  }
84
87
  async listModels() {
85
88
  const provider = this.ensureProviderSupport("listModels");
@@ -90,7 +93,9 @@ class LLMCore {
90
93
  }
91
94
  async paint(prompt, options) {
92
95
  const provider = this.ensureProviderSupport("paint");
93
- const model = options?.model;
96
+ // Default to resolving aliases
97
+ const rawModel = options?.model;
98
+ const model = resolveModelAlias(rawModel || "", provider.id);
94
99
  if (options?.assumeModelExists) {
95
100
  console.warn(`[NodeLLM] Skipping validation for model ${model}`);
96
101
  }
@@ -100,12 +105,14 @@ class LLMCore {
100
105
  const response = await provider.paint({
101
106
  prompt,
102
107
  ...options,
108
+ model,
103
109
  });
104
110
  return new GeneratedImage(response);
105
111
  }
106
112
  async transcribe(file, options) {
107
113
  const provider = this.ensureProviderSupport("transcribe");
108
- const model = options?.model || this.defaultTranscriptionModelId;
114
+ const rawModel = options?.model || this.defaultTranscriptionModelId || "";
115
+ const model = resolveModelAlias(rawModel, provider.id);
109
116
  if (options?.assumeModelExists) {
110
117
  console.warn(`[NodeLLM] Skipping validation for model ${model}`);
111
118
  }
@@ -114,8 +121,8 @@ class LLMCore {
114
121
  }
115
122
  const response = await provider.transcribe({
116
123
  file,
117
- model,
118
124
  ...options,
125
+ model,
119
126
  });
120
127
  return new Transcription(response);
121
128
  }
@@ -133,7 +140,8 @@ class LLMCore {
133
140
  }
134
141
  async moderate(input, options) {
135
142
  const provider = this.ensureProviderSupport("moderate");
136
- const model = options?.model || this.defaultModerationModelId;
143
+ const rawModel = options?.model || this.defaultModerationModelId || "";
144
+ const model = resolveModelAlias(rawModel, provider.id);
137
145
  if (options?.assumeModelExists) {
138
146
  console.warn(`[NodeLLM] Skipping validation for model ${model}`);
139
147
  }
@@ -142,14 +150,15 @@ class LLMCore {
142
150
  }
143
151
  const response = await provider.moderate({
144
152
  input,
145
- model,
146
153
  ...options,
154
+ model,
147
155
  });
148
156
  return new Moderation(response);
149
157
  }
150
158
  async embed(input, options) {
151
159
  const provider = this.ensureProviderSupport("embed");
152
- const model = options?.model || this.defaultEmbeddingModelId;
160
+ const rawModel = options?.model || this.defaultEmbeddingModelId || "";
161
+ const model = resolveModelAlias(rawModel, provider.id);
153
162
  const request = {
154
163
  input,
155
164
  model,
@@ -166,4 +175,4 @@ class LLMCore {
166
175
  }
167
176
  }
168
177
  export { Transcription, Moderation, Embedding };
169
- export const LLM = new LLMCore();
178
+ export const NodeLLM = new NodeLLMCore();
@@ -0,0 +1,3 @@
1
+ export type ProviderName = "openai" | "anthropic" | "gemini" | "vertexai" | "openrouter" | "mistral" | "deepseek" | "bedrock" | string;
2
+ export declare function resolveModelAlias(alias: string, provider?: ProviderName): string;
3
+ //# sourceMappingURL=model_aliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model_aliases.d.ts","sourceRoot":"","sources":["../src/model_aliases.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAEvI,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,MAAM,CAkBhF"}
@@ -0,0 +1,20 @@
1
+ // This file is auto-generated or manually maintained to map generic model aliases
2
+ // to provider-specific model IDs.
3
+ // @ts-ignore
4
+ import aliases from "./aliases.json" assert { type: "json" };
5
+ export function resolveModelAlias(alias, provider) {
6
+ if (!provider) {
7
+ return alias;
8
+ }
9
+ // Check if the alias exists in our registry
10
+ const aliasEntry = aliases[alias];
11
+ if (aliasEntry) {
12
+ // Check if there is a specific mapping for this provider
13
+ if (aliasEntry[provider.toLowerCase()]) {
14
+ return aliasEntry[provider.toLowerCase()];
15
+ }
16
+ }
17
+ // If no alias found or no mapping for this provider, return the original string
18
+ // This allows users to pass raw model IDs that aren't in our alias list.
19
+ return alias;
20
+ }
@@ -15197,7 +15197,7 @@ export const modelsData = [
15197
15197
  }
15198
15198
  },
15199
15199
  "metadata": {
15200
- "description": "Llama Guard 4 is a Llama 4 Scout-derived multimodal pretrained model, fine-tuned for content safety classification. Similar to previous versions, it can be used to classify content in both LLM inputs (prompt classification) and in LLM responses (response classification). It acts as an LLM—generating text in its output that indicates whether a given prompt or response is safe or unsafe, and if unsafe, it also lists the content categories violated.\n\nLlama Guard 4 was aligned to safeguard against the standardized MLCommons hazards taxonomy and designed to support multimodal Llama 4 capabilities. Specifically, it combines features from previous Llama Guard models, providing content moderation for English and multiple supported languages, along with enhanced capabilities to handle mixed text-and-image prompts, including multiple images. Additionally, Llama Guard 4 is integrated into the Llama Moderations API, extending robust safety classification to text and images.",
15200
+ "description": "Llama Guard 4 is a Llama 4 Scout-derived multimodal pretrained model, fine-tuned for content safety classification. Similar to previous versions, it can be used to classify content in both LLM inputs (prompt classification) and in LLM responses (response classification). It acts as an NodeLLM—generating text in its output that indicates whether a given prompt or response is safe or unsafe, and if unsafe, it also lists the content categories violated.\n\nLlama Guard 4 was aligned to safeguard against the standardized MLCommons hazards taxonomy and designed to support multimodal Llama 4 capabilities. Specifically, it combines features from previous Llama Guard models, providing content moderation for English and multiple supported languages, along with enhanced capabilities to handle mixed text-and-image prompts, including multiple images. Additionally, Llama Guard 4 is integrated into the Llama Moderations API, extending robust safety classification to text and images.",
15201
15201
  "architecture": {
15202
15202
  "modality": "text+image->text",
15203
15203
  "input_modalities": [
@@ -15947,7 +15947,7 @@ export const modelsData = [
15947
15947
  }
15948
15948
  },
15949
15949
  "metadata": {
15950
- "description": "MiniMax-01 is a combines MiniMax-Text-01 for text generation and MiniMax-VL-01 for image understanding. It has 456 billion parameters, with 45.9 billion parameters activated per inference, and can handle a context of up to 4 million tokens.\n\nThe text model adopts a hybrid architecture that combines Lightning Attention, Softmax Attention, and Mixture-of-Experts (MoE). The image model adopts the “ViT-MLP-LLM” framework and is trained on top of the text model.\n\nTo read more about the release, see: https://www.minimaxi.com/en/news/minimax-01-series-2",
15950
+ "description": "MiniMax-01 is a combines MiniMax-Text-01 for text generation and MiniMax-VL-01 for image understanding. It has 456 billion parameters, with 45.9 billion parameters activated per inference, and can handle a context of up to 4 million tokens.\n\nThe text model adopts a hybrid architecture that combines Lightning Attention, Softmax Attention, and Mixture-of-Experts (MoE). The image model adopts the “ViT-MLP-NodeLLM” framework and is trained on top of the text model.\n\nTo read more about the release, see: https://www.minimaxi.com/en/news/minimax-01-series-2",
15951
15951
  "architecture": {
15952
15952
  "modality": "text+image->text",
15953
15953
  "input_modalities": [
@@ -28432,7 +28432,7 @@ export const modelsData = [
28432
28432
  ],
28433
28433
  "pricing": {},
28434
28434
  "metadata": {
28435
- "description": "Venice Uncensored Dolphin Mistral 24B Venice Edition is a fine-tuned variant of Mistral-Small-24B-Instruct-2501, developed by dphn.ai in collaboration with Venice.ai. This model is designed as an “uncensored” instruct-tuned LLM, preserving user control over alignment, system prompts, and behavior. Intended for advanced and unrestricted use cases, Venice Uncensored emphasizes steerability and transparent behavior, removing default safety and alignment layers typically found in mainstream assistant models.",
28435
+ "description": "Venice Uncensored Dolphin Mistral 24B Venice Edition is a fine-tuned variant of Mistral-Small-24B-Instruct-2501, developed by dphn.ai in collaboration with Venice.ai. This model is designed as an “uncensored” instruct-tuned NodeLLM, preserving user control over alignment, system prompts, and behavior. Intended for advanced and unrestricted use cases, Venice Uncensored emphasizes steerability and transparent behavior, removing default safety and alignment layers typically found in mainstream assistant models.",
28436
28436
  "architecture": {
28437
28437
  "modality": "text->text",
28438
28438
  "input_modalities": [
@@ -7,7 +7,9 @@ import { Provider, ChatRequest, ChatResponse, ChatChunk, ModelInfo, ImageRequest
7
7
  export declare abstract class BaseProvider implements Provider {
8
8
  abstract apiBase(): string;
9
9
  abstract headers(): Record<string, string>;
10
+ abstract headers(): Record<string, string>;
10
11
  protected abstract providerName(): string;
12
+ get id(): string;
11
13
  protected throwUnsupportedError(feature: string): never;
12
14
  abstract chat(request: ChatRequest): Promise<ChatResponse>;
13
15
  abstract capabilities?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseProvider.d.ts","sourceRoot":"","sources":["../../src/providers/BaseProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAEvB;;;;GAIG;AACH,8BAAsB,YAAa,YAAW,QAAQ;aACpC,OAAO,IAAI,MAAM;aACjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACjD,SAAS,CAAC,QAAQ,CAAC,YAAY,IAAI,MAAM;IAEzC,SAAS,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK;IAIvD,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1D,QAAQ,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC;IAErB,MAAM,CAAC,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC;IAIxD,UAAU,CAAC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAInC,KAAK,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIrD,UAAU,CAAC,CAAC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AqB,CAAC;IAI1E,QAAQ,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIlE,KAAK,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGpE"}
@@ -4,6 +4,9 @@
4
4
  * Each provider must implement the abstract methods and can override default implementations.
5
5
  */
6
6
  export class BaseProvider {
7
+ get id() {
8
+ return this.providerName();
9
+ }
7
10
  throwUnsupportedError(feature) {
8
11
  throw new Error(`${this.providerName()} does not support ${feature}`);
9
12
  }
@@ -13,6 +13,7 @@ export interface ChatRequest {
13
13
  export interface ChatChunk {
14
14
  content: string;
15
15
  reasoning?: string;
16
+ tool_calls?: ToolCall[];
16
17
  done?: boolean;
17
18
  }
18
19
  export interface Usage {
@@ -122,10 +123,8 @@ export interface EmbeddingResponse {
122
123
  input_tokens: number;
123
124
  dimensions: number;
124
125
  }
125
- export interface EmbeddingProvider {
126
- embed(request: EmbeddingRequest): Promise<EmbeddingResponse>;
127
- }
128
126
  export interface Provider {
127
+ id: string;
129
128
  chat(request: ChatRequest): Promise<ChatResponse>;
130
129
  stream?(request: ChatRequest): AsyncIterable<ChatChunk>;
131
130
  listModels?(): Promise<ModelInfo[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/providers/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,GAAG,CAAC;IACt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O,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAClD,MAAM,CAAC,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACxD,UAAU,CAAC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IACpC,KAAK,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACtD,UAAU,CAAC,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC3E,QAAQ,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACnE,KAAK,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9D,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAUlE,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAwG3D"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAWlE,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA4G3D"}
@@ -1,6 +1,7 @@
1
1
  import { Capabilities } from "./Capabilities.js";
2
2
  import { handleAnthropicError } from "./Errors.js";
3
3
  import { ModelRegistry } from "../../models/ModelRegistry.js";
4
+ import { logger } from "../../utils/logger.js";
4
5
  import { formatSystemPrompt, formatMessages } from "./Utils.js";
5
6
  export class AnthropicChat {
6
7
  baseUrl;
@@ -54,7 +55,9 @@ export class AnthropicChat {
54
55
  if (hasPdf) {
55
56
  headers["anthropic-beta"] = "pdfs-2024-09-25";
56
57
  }
57
- const response = await fetch(`${this.baseUrl}/messages`, {
58
+ const url = `${this.baseUrl}/messages`;
59
+ logger.logRequest("Anthropic", "POST", url, body);
60
+ const response = await fetch(url, {
58
61
  method: "POST",
59
62
  headers: headers,
60
63
  body: JSON.stringify(body),
@@ -63,6 +66,7 @@ export class AnthropicChat {
63
66
  await handleAnthropicError(response, model);
64
67
  }
65
68
  const json = (await response.json());
69
+ logger.logResponse("Anthropic", response.status, response.statusText, json);
66
70
  const contentBlocks = json.content;
67
71
  // Extract text content and tool calls
68
72
  let content = null;
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMxD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAqJ7B"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAqM7B"}
@@ -1,6 +1,7 @@
1
1
  import { Capabilities } from "./Capabilities.js";
2
2
  import { handleAnthropicError } from "./Errors.js";
3
3
  import { formatSystemPrompt, formatMessages } from "./Utils.js";
4
+ import { logger } from "../../utils/logger.js";
4
5
  export class AnthropicStreaming {
5
6
  baseUrl;
6
7
  apiKey;
@@ -52,8 +53,13 @@ export class AnthropicStreaming {
52
53
  headers["anthropic-beta"] = "pdfs-2024-09-25";
53
54
  }
54
55
  let done = false;
56
+ // Track tool calls being built across chunks
57
+ const toolCallsMap = new Map();
58
+ let currentBlockIndex = -1;
55
59
  try {
56
- const response = await fetch(`${this.baseUrl}/messages`, {
60
+ const url = `${this.baseUrl}/messages`;
61
+ logger.logRequest("Anthropic", "POST", url, body);
62
+ const response = await fetch(url, {
57
63
  method: "POST",
58
64
  headers: headers,
59
65
  body: JSON.stringify(body),
@@ -62,6 +68,7 @@ export class AnthropicStreaming {
62
68
  if (!response.ok) {
63
69
  await handleAnthropicError(response, model);
64
70
  }
71
+ logger.debug("Anthropic streaming started", { status: response.status, statusText: response.statusText });
65
72
  if (!response.body) {
66
73
  throw new Error("No response body for streaming");
67
74
  }
@@ -97,16 +104,56 @@ export class AnthropicStreaming {
97
104
  try {
98
105
  const data = JSON.parse(dataStr);
99
106
  // Handle different event types from Anthropic
100
- if (eventType === "content_block_delta") {
107
+ if (eventType === "content_block_start") {
108
+ // Track the block index for tool use
109
+ if (data.content_block?.type === "tool_use") {
110
+ currentBlockIndex = data.index;
111
+ toolCallsMap.set(currentBlockIndex, {
112
+ id: data.content_block.id,
113
+ type: "function",
114
+ function: {
115
+ name: data.content_block.name,
116
+ arguments: ""
117
+ }
118
+ });
119
+ }
120
+ }
121
+ else if (eventType === "content_block_delta") {
101
122
  if (data.delta && data.delta.type === "text_delta") {
102
123
  yield { content: data.delta.text };
103
124
  }
125
+ else if (data.delta && data.delta.type === "input_json_delta") {
126
+ // Accumulate tool arguments
127
+ const index = data.index;
128
+ if (toolCallsMap.has(index)) {
129
+ const toolCall = toolCallsMap.get(index);
130
+ toolCall.function.arguments += data.delta.partial_json;
131
+ }
132
+ }
133
+ }
134
+ else if (eventType === "content_block_stop") {
135
+ // Block finished
104
136
  }
105
137
  else if (eventType === "message_start") {
106
138
  // Could extract initial usage here
107
139
  }
108
140
  else if (eventType === "message_delta") {
109
141
  // Update usage or stop reason
142
+ if (data.delta?.stop_reason === "end_turn" && toolCallsMap.size > 0) {
143
+ // Yield accumulated tool calls
144
+ const toolCalls = Array.from(toolCallsMap.values()).map(tc => ({
145
+ id: tc.id,
146
+ type: "function",
147
+ function: {
148
+ name: tc.function.name,
149
+ arguments: tc.function.arguments
150
+ }
151
+ }));
152
+ yield { content: "", tool_calls: toolCalls, done: true };
153
+ }
154
+ }
155
+ else if (eventType === "message_stop") {
156
+ done = true;
110
157
  }
111
158
  else if (eventType === "error") {
112
159
  throw new Error(`Stream error: ${data.error?.message}`);
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAqBlE,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAwF3D"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAsBlE,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAyF3D"}
@@ -1,4 +1,5 @@
1
1
  import { ModelRegistry } from "../../models/ModelRegistry.js";
2
+ import { logger } from "../../utils/logger.js";
2
3
  export class DeepSeekChat {
3
4
  baseUrl;
4
5
  apiKey;
@@ -46,10 +47,9 @@ export class DeepSeekChat {
46
47
  body.response_format = response_format;
47
48
  }
48
49
  }
49
- if (process.env.NODELLM_DEBUG === "true") {
50
- console.log(`[DeepSeek Request] ${JSON.stringify(body, null, 2)}`);
51
- }
52
- const response = await fetch(`${this.baseUrl}/chat/completions`, {
50
+ const url = `${this.baseUrl}/chat/completions`;
51
+ logger.logRequest("DeepSeek", "POST", url, body);
52
+ const response = await fetch(url, {
53
53
  method: "POST",
54
54
  headers: {
55
55
  "Authorization": `Bearer ${this.apiKey}`,
@@ -63,6 +63,7 @@ export class DeepSeekChat {
63
63
  throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
64
64
  }
65
65
  const json = (await response.json());
66
+ logger.logResponse("DeepSeek", response.status, response.statusText, json);
66
67
  const message = json.choices[0]?.message;
67
68
  const content = message?.content ?? null;
68
69
  const reasoning = message?.reasoning_content ?? null;
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGxD,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CA8G7B"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIxD,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CA+J7B"}
@@ -1,4 +1,5 @@
1
1
  import { APIError } from "../../errors/index.js";
2
+ import { logger } from "../../utils/logger.js";
2
3
  export class DeepSeekStreaming {
3
4
  baseUrl;
4
5
  apiKey;
@@ -22,8 +23,12 @@ export class DeepSeekStreaming {
22
23
  if (response_format)
23
24
  body.response_format = response_format;
24
25
  let done = false;
26
+ // Track tool calls being built across chunks
27
+ const toolCallsMap = new Map();
25
28
  try {
26
- const response = await fetch(`${this.baseUrl}/chat/completions`, {
29
+ const url = `${this.baseUrl}/chat/completions`;
30
+ logger.logRequest("DeepSeek", "POST", url, body);
31
+ const response = await fetch(url, {
27
32
  method: "POST",
28
33
  headers: {
29
34
  "Authorization": `Bearer ${this.apiKey}`,
@@ -37,6 +42,7 @@ export class DeepSeekStreaming {
37
42
  const errorText = await response.text();
38
43
  throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
39
44
  }
45
+ logger.debug("DeepSeek streaming started", { status: response.status, statusText: response.statusText });
40
46
  if (!response.body) {
41
47
  throw new Error("No response body for streaming");
42
48
  }
@@ -62,6 +68,18 @@ export class DeepSeekStreaming {
62
68
  const data = trimmed.replace("data: ", "").trim();
63
69
  if (data === "[DONE]") {
64
70
  done = true;
71
+ // Yield final tool calls if any were accumulated
72
+ if (toolCallsMap.size > 0) {
73
+ const toolCalls = Array.from(toolCallsMap.values()).map(tc => ({
74
+ id: tc.id,
75
+ type: "function",
76
+ function: {
77
+ name: tc.function.name,
78
+ arguments: tc.function.arguments
79
+ }
80
+ }));
81
+ yield { content: "", tool_calls: toolCalls, done: true };
82
+ }
65
83
  return;
66
84
  }
67
85
  try {
@@ -70,14 +88,42 @@ export class DeepSeekStreaming {
70
88
  if (json.error) {
71
89
  throw new APIError("DeepSeek", response.status, json.error.message || "Stream error");
72
90
  }
73
- const deltaContent = json.choices?.[0]?.delta?.content;
74
- const deltaReasoning = json.choices?.[0]?.delta?.reasoning_content;
91
+ const delta = json.choices?.[0]?.delta;
92
+ const deltaContent = delta?.content;
93
+ const deltaReasoning = delta?.reasoning_content;
75
94
  if (deltaContent || deltaReasoning) {
76
95
  yield {
77
96
  content: deltaContent || "",
78
97
  reasoning: deltaReasoning || ""
79
98
  };
80
99
  }
100
+ // Handle tool calls delta
101
+ if (delta?.tool_calls) {
102
+ for (const toolCallDelta of delta.tool_calls) {
103
+ const index = toolCallDelta.index;
104
+ if (!toolCallsMap.has(index)) {
105
+ toolCallsMap.set(index, {
106
+ id: toolCallDelta.id || "",
107
+ type: "function",
108
+ function: {
109
+ name: toolCallDelta.function?.name || "",
110
+ arguments: toolCallDelta.function?.arguments || ""
111
+ }
112
+ });
113
+ }
114
+ else {
115
+ const existing = toolCallsMap.get(index);
116
+ if (toolCallDelta.id)
117
+ existing.id = toolCallDelta.id;
118
+ if (toolCallDelta.function?.name) {
119
+ existing.function.name += toolCallDelta.function.name;
120
+ }
121
+ if (toolCallDelta.function?.arguments) {
122
+ existing.function.arguments += toolCallDelta.function.arguments;
123
+ }
124
+ }
125
+ }
126
+ }
81
127
  }
82
128
  catch (e) {
83
129
  // Re-throw APIError
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAOlE,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAyF1D,OAAO,CAAC,cAAc;CAwBvB"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAQlE,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA4F1D,OAAO,CAAC,cAAc;CAwBvB"}
@@ -2,6 +2,7 @@ import { Capabilities } from "./Capabilities.js";
2
2
  import { handleGeminiError } from "./Errors.js";
3
3
  import { GeminiChatUtils } from "./ChatUtils.js";
4
4
  import { ModelRegistry } from "../../models/ModelRegistry.js";
5
+ import { logger } from "../../utils/logger.js";
5
6
  export class GeminiChat {
6
7
  baseUrl;
7
8
  apiKey;
@@ -49,6 +50,7 @@ export class GeminiChat {
49
50
  },
50
51
  ];
51
52
  }
53
+ logger.logRequest("Gemini", "POST", url, payload);
52
54
  const response = await fetch(url, {
53
55
  method: "POST",
54
56
  headers: {
@@ -60,6 +62,7 @@ export class GeminiChat {
60
62
  await handleGeminiError(response, request.model);
61
63
  }
62
64
  const json = (await response.json());
65
+ logger.logResponse("Gemini", response.status, response.statusText, json);
63
66
  const candidate = json.candidates?.[0];
64
67
  const content = candidate?.content?.parts
65
68
  ?.filter(p => p.text)
@@ -1 +1 @@
1
- {"version":3,"file":"Embeddings.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Embeddings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIrE,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAwCrE"}
1
+ {"version":3,"file":"Embeddings.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Embeddings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKrE,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA2CrE"}
@@ -1,4 +1,5 @@
1
1
  import { handleGeminiError } from "./Errors.js";
2
+ import { logger } from "../../utils/logger.js";
2
3
  export class GeminiEmbeddings {
3
4
  baseUrl;
4
5
  apiKey;
@@ -24,6 +25,7 @@ export class GeminiEmbeddings {
24
25
  return item;
25
26
  })
26
27
  };
28
+ logger.logRequest("Gemini", "POST", url, payload);
27
29
  const response = await fetch(url, {
28
30
  method: "POST",
29
31
  headers: { "Content-Type": "application/json" },
@@ -33,6 +35,7 @@ export class GeminiEmbeddings {
33
35
  await handleGeminiError(response, modelId);
34
36
  }
35
37
  const json = (await response.json());
38
+ logger.logResponse("Gemini", response.status, response.statusText, json);
36
39
  const vectors = json.embeddings?.map(e => e.values) || [];
37
40
  return {
38
41
  model: modelId,
@@ -1 +1 @@
1
- {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG7D,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CA8C7D"}
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI7D,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAiD7D"}
@@ -1,4 +1,5 @@
1
1
  import { handleGeminiError } from "./Errors.js";
2
+ import { logger } from "../../utils/logger.js";
2
3
  export class GeminiImage {
3
4
  baseUrl;
4
5
  apiKey;
@@ -22,6 +23,7 @@ export class GeminiImage {
22
23
  sampleCount: 1,
23
24
  },
24
25
  };
26
+ logger.logRequest("Gemini", "POST", url, body);
25
27
  const response = await fetch(url, {
26
28
  method: "POST",
27
29
  headers: {
@@ -33,6 +35,7 @@ export class GeminiImage {
33
35
  await handleGeminiError(response, modelId);
34
36
  }
35
37
  const json = await response.json();
38
+ logger.logResponse("Gemini", response.status, response.statusText, json);
36
39
  const imageData = json.predictions?.[0];
37
40
  if (!imageData || !imageData.bytesBase64Encoded) {
38
41
  throw new Error("Unexpected response format from Gemini image generation API");
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMxD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;IAuG5B,OAAO,CAAC,cAAc;CAwBvB"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;IAyI5B,OAAO,CAAC,cAAc;CAwBvB"}