@node-llm/core 0.5.0 → 0.7.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 (107) hide show
  1. package/README.md +83 -421
  2. package/dist/chat/Chat.d.ts +5 -0
  3. package/dist/chat/Chat.d.ts.map +1 -1
  4. package/dist/chat/Chat.js +31 -7
  5. package/dist/chat/ChatOptions.d.ts +3 -0
  6. package/dist/chat/ChatOptions.d.ts.map +1 -1
  7. package/dist/chat/ChatResponse.d.ts +5 -1
  8. package/dist/chat/ChatResponse.d.ts.map +1 -1
  9. package/dist/chat/ChatResponse.js +6 -1
  10. package/dist/chat/Stream.d.ts.map +1 -1
  11. package/dist/chat/Stream.js +7 -1
  12. package/dist/config.d.ts +29 -0
  13. package/dist/config.d.ts.map +1 -0
  14. package/dist/config.js +11 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -0
  18. package/dist/llm.d.ts +20 -10
  19. package/dist/llm.d.ts.map +1 -1
  20. package/dist/llm.js +52 -23
  21. package/dist/models/ModelRegistry.d.ts +39 -12
  22. package/dist/models/ModelRegistry.d.ts.map +1 -1
  23. package/dist/models/ModelRegistry.js +50 -40
  24. package/dist/models/models.d.ts +972 -0
  25. package/dist/models/models.d.ts.map +1 -0
  26. package/dist/models/models.js +7076 -0
  27. package/dist/models/types.d.ts +50 -0
  28. package/dist/models/types.d.ts.map +1 -0
  29. package/dist/models/types.js +1 -0
  30. package/dist/providers/Provider.d.ts +7 -0
  31. package/dist/providers/Provider.d.ts.map +1 -1
  32. package/dist/providers/anthropic/AnthropicProvider.d.ts +1 -0
  33. package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
  34. package/dist/providers/anthropic/AnthropicProvider.js +2 -3
  35. package/dist/providers/anthropic/Capabilities.d.ts +1 -37
  36. package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
  37. package/dist/providers/anthropic/Capabilities.js +59 -130
  38. package/dist/providers/anthropic/Chat.d.ts.map +1 -1
  39. package/dist/providers/anthropic/Chat.js +6 -2
  40. package/dist/providers/anthropic/Models.d.ts +1 -0
  41. package/dist/providers/anthropic/Models.d.ts.map +1 -1
  42. package/dist/providers/anthropic/Models.js +36 -41
  43. package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
  44. package/dist/providers/anthropic/Streaming.js +10 -1
  45. package/dist/providers/anthropic/index.d.ts.map +1 -1
  46. package/dist/providers/anthropic/index.js +3 -2
  47. package/dist/providers/deepseek/Capabilities.d.ts +14 -0
  48. package/dist/providers/deepseek/Capabilities.d.ts.map +1 -0
  49. package/dist/providers/deepseek/Capabilities.js +52 -0
  50. package/dist/providers/deepseek/Chat.d.ts +8 -0
  51. package/dist/providers/deepseek/Chat.d.ts.map +1 -0
  52. package/dist/providers/deepseek/Chat.js +89 -0
  53. package/dist/providers/deepseek/DeepSeekProvider.d.ts +28 -0
  54. package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -0
  55. package/dist/providers/deepseek/DeepSeekProvider.js +38 -0
  56. package/dist/providers/deepseek/Models.d.ts +8 -0
  57. package/dist/providers/deepseek/Models.d.ts.map +1 -0
  58. package/dist/providers/deepseek/Models.js +67 -0
  59. package/dist/providers/deepseek/Streaming.d.ts +8 -0
  60. package/dist/providers/deepseek/Streaming.d.ts.map +1 -0
  61. package/dist/providers/deepseek/Streaming.js +74 -0
  62. package/dist/providers/deepseek/index.d.ts +7 -0
  63. package/dist/providers/deepseek/index.d.ts.map +1 -0
  64. package/dist/providers/deepseek/index.js +22 -0
  65. package/dist/providers/gemini/Capabilities.d.ts +28 -7
  66. package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
  67. package/dist/providers/gemini/Capabilities.js +32 -20
  68. package/dist/providers/gemini/Chat.d.ts.map +1 -1
  69. package/dist/providers/gemini/Chat.js +9 -11
  70. package/dist/providers/gemini/GeminiProvider.d.ts +1 -0
  71. package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
  72. package/dist/providers/gemini/GeminiProvider.js +1 -0
  73. package/dist/providers/gemini/Models.d.ts +1 -0
  74. package/dist/providers/gemini/Models.d.ts.map +1 -1
  75. package/dist/providers/gemini/Models.js +46 -26
  76. package/dist/providers/gemini/index.d.ts.map +1 -1
  77. package/dist/providers/gemini/index.js +3 -2
  78. package/dist/providers/openai/Capabilities.d.ts +4 -11
  79. package/dist/providers/openai/Capabilities.d.ts.map +1 -1
  80. package/dist/providers/openai/Capabilities.js +124 -121
  81. package/dist/providers/openai/Chat.d.ts.map +1 -1
  82. package/dist/providers/openai/Chat.js +19 -17
  83. package/dist/providers/openai/Embedding.d.ts.map +1 -1
  84. package/dist/providers/openai/Embedding.js +2 -1
  85. package/dist/providers/openai/Image.d.ts.map +1 -1
  86. package/dist/providers/openai/Image.js +2 -1
  87. package/dist/providers/openai/ModelDefinitions.d.ts +1 -24
  88. package/dist/providers/openai/ModelDefinitions.d.ts.map +1 -1
  89. package/dist/providers/openai/ModelDefinitions.js +1 -211
  90. package/dist/providers/openai/Models.d.ts +1 -0
  91. package/dist/providers/openai/Models.d.ts.map +1 -1
  92. package/dist/providers/openai/Models.js +46 -22
  93. package/dist/providers/openai/Moderation.d.ts.map +1 -1
  94. package/dist/providers/openai/Moderation.js +2 -1
  95. package/dist/providers/openai/OpenAIProvider.d.ts +1 -0
  96. package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
  97. package/dist/providers/openai/OpenAIProvider.js +1 -0
  98. package/dist/providers/openai/Streaming.d.ts.map +1 -1
  99. package/dist/providers/openai/Streaming.js +5 -1
  100. package/dist/providers/openai/Transcription.d.ts.map +1 -1
  101. package/dist/providers/openai/Transcription.js +3 -2
  102. package/dist/providers/openai/index.d.ts.map +1 -1
  103. package/dist/providers/openai/index.js +5 -3
  104. package/dist/providers/openai/utils.d.ts +20 -0
  105. package/dist/providers/openai/utils.d.ts.map +1 -0
  106. package/dist/providers/openai/utils.js +25 -0
  107. package/package.json +1 -1
@@ -1,54 +1,64 @@
1
+ import { modelsData } from "./models.js";
1
2
  export class ModelRegistry {
2
- models = new Map();
3
- static API_URL = "https://api.parsera.org/v1/llm-specs";
3
+ static models = modelsData;
4
4
  /**
5
- * Refresh model information from the Parsera API
5
+ * Find a model by its ID.
6
6
  */
7
- async refresh() {
8
- try {
9
- const response = await fetch(ModelRegistry.API_URL);
10
- if (!response.ok) {
11
- throw new Error(`Failed to refresh models: ${response.statusText}`);
12
- }
13
- const specs = await response.json();
14
- this.models.clear();
15
- for (const spec of specs) {
16
- this.models.set(spec.id, {
17
- id: spec.id,
18
- name: spec.name || spec.id,
19
- provider: spec.provider,
20
- family: spec.family || spec.provider,
21
- context_window: spec.context_window,
22
- max_output_tokens: spec.max_output_tokens,
23
- modalities: spec.modalities || { input: ["text"], output: ["text"] },
24
- capabilities: spec.capabilities || [],
25
- pricing: spec.pricing || {},
26
- metadata: spec.metadata || {}
27
- });
28
- }
29
- }
30
- catch (error) {
31
- console.error("Error refreshing model registry:", error);
32
- throw error;
33
- }
7
+ static find(modelId, provider) {
8
+ return this.models.find(m => (m.id === modelId || m.family === modelId) && (!provider || m.provider === provider));
9
+ }
10
+ /**
11
+ * Get all available models.
12
+ */
13
+ static all() {
14
+ return this.models;
34
15
  }
35
16
  /**
36
- * Find a model by ID
17
+ * Get output tokens limit for a model.
37
18
  */
38
- find(id) {
39
- return this.models.get(id);
19
+ static getMaxOutputTokens(modelId, provider) {
20
+ const model = this.find(modelId, provider);
21
+ return model?.max_output_tokens ?? undefined;
40
22
  }
41
23
  /**
42
- * List all known models
24
+ * Check if a model supports a capability.
43
25
  */
44
- all() {
45
- return Array.from(this.models.values());
26
+ static supports(modelId, capability, provider) {
27
+ const model = this.find(modelId, provider);
28
+ return model?.capabilities.includes(capability) ?? false;
46
29
  }
47
30
  /**
48
- * Filter models by provider
31
+ * Get context window size.
49
32
  */
50
- byProvider(provider) {
51
- return this.all().filter(m => m.provider === provider);
33
+ static getContextWindow(modelId, provider) {
34
+ const model = this.find(modelId, provider);
35
+ return model?.context_window ?? undefined;
36
+ }
37
+ /**
38
+ * Calculate cost for usage.
39
+ */
40
+ static calculateCost(usage, modelId, provider) {
41
+ const model = this.find(modelId, provider);
42
+ if (!model || !model.pricing?.text_tokens?.standard) {
43
+ return usage;
44
+ }
45
+ const prices = model.pricing.text_tokens.standard;
46
+ const inputPrice = prices.input_per_million || 0;
47
+ const outputPrice = prices.output_per_million || 0;
48
+ const reasoningPrice = prices.reasoning_output_per_million || outputPrice;
49
+ const cachedPrice = prices.cached_input_per_million ?? (inputPrice / 2);
50
+ const inputCost = ((usage.input_tokens - (usage.cached_tokens || 0)) / 1_000_000) * inputPrice +
51
+ ((usage.cached_tokens || 0) / 1_000_000) * cachedPrice;
52
+ const outputTokens = usage.output_tokens - (usage.reasoning_tokens || 0);
53
+ const reasoningTokens = usage.reasoning_tokens || 0;
54
+ const outputCost = (outputTokens / 1_000_000) * outputPrice +
55
+ (reasoningTokens / 1_000_000) * reasoningPrice;
56
+ const totalCost = inputCost + outputCost;
57
+ return {
58
+ ...usage,
59
+ input_cost: Number(inputCost.toFixed(6)),
60
+ output_cost: Number(outputCost.toFixed(6)),
61
+ cost: Number(totalCost.toFixed(6))
62
+ };
52
63
  }
53
64
  }
54
- export const models = new ModelRegistry();