@superatomai/sdk-node 0.0.46-mds → 0.0.47-mds
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/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +65 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5606,8 +5606,10 @@ var LLM = class {
|
|
|
5606
5606
|
return this._geminiText(messages, modelName, options);
|
|
5607
5607
|
} else if (provider === "openai") {
|
|
5608
5608
|
return this._openaiText(messages, modelName, options);
|
|
5609
|
+
} else if (provider === "openrouter") {
|
|
5610
|
+
return this._openrouterText(messages, modelName, options);
|
|
5609
5611
|
} else {
|
|
5610
|
-
throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", or "
|
|
5612
|
+
throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", "openai", or "openrouter"`);
|
|
5611
5613
|
}
|
|
5612
5614
|
}
|
|
5613
5615
|
/* Stream response from an LLM (Anthropic or Groq) */
|
|
@@ -5622,8 +5624,10 @@ var LLM = class {
|
|
|
5622
5624
|
return this._geminiStream(messages, modelName, options, json);
|
|
5623
5625
|
} else if (provider === "openai") {
|
|
5624
5626
|
return this._openaiStream(messages, modelName, options, json);
|
|
5627
|
+
} else if (provider === "openrouter") {
|
|
5628
|
+
return this._openrouterStream(messages, modelName, options, json);
|
|
5625
5629
|
} else {
|
|
5626
|
-
throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", or "
|
|
5630
|
+
throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", "openai", or "openrouter"`);
|
|
5627
5631
|
}
|
|
5628
5632
|
}
|
|
5629
5633
|
/* Stream response with tool calling support (Anthropic and Gemini) */
|
|
@@ -5636,8 +5640,10 @@ var LLM = class {
|
|
|
5636
5640
|
return this._geminiStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations);
|
|
5637
5641
|
} else if (provider === "openai") {
|
|
5638
5642
|
return this._openaiStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations);
|
|
5643
|
+
} else if (provider === "openrouter") {
|
|
5644
|
+
return this._openrouterStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations);
|
|
5639
5645
|
} else {
|
|
5640
|
-
throw new Error(`Tool calling is only supported for Anthropic, Gemini, and
|
|
5646
|
+
throw new Error(`Tool calling is only supported for Anthropic, Gemini, OpenAI, and OpenRouter models`);
|
|
5641
5647
|
}
|
|
5642
5648
|
}
|
|
5643
5649
|
// ============================================================
|
|
@@ -5743,16 +5749,62 @@ var LLM = class {
|
|
|
5743
5749
|
* "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
|
|
5744
5750
|
*/
|
|
5745
5751
|
static _parseModel(modelString) {
|
|
5752
|
+
let provider;
|
|
5753
|
+
let model;
|
|
5746
5754
|
if (!modelString) {
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
if (modelString.includes("/")) {
|
|
5755
|
+
provider = "anthropic";
|
|
5756
|
+
model = "claude-sonnet-4-5";
|
|
5757
|
+
} else if (modelString.includes("/")) {
|
|
5750
5758
|
const firstSlashIndex = modelString.indexOf("/");
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5759
|
+
provider = modelString.substring(0, firstSlashIndex).toLowerCase().trim();
|
|
5760
|
+
model = modelString.substring(firstSlashIndex + 1).trim();
|
|
5761
|
+
} else {
|
|
5762
|
+
provider = "anthropic";
|
|
5763
|
+
model = modelString;
|
|
5754
5764
|
}
|
|
5755
|
-
|
|
5765
|
+
if (provider === "anthropic" && !process.env.ANTHROPIC_API_KEY && process.env.OPENROUTER_API_KEY) {
|
|
5766
|
+
return ["openrouter", "anthropic/" + this._toOpenRouterSlug(model)];
|
|
5767
|
+
}
|
|
5768
|
+
return [provider, model];
|
|
5769
|
+
}
|
|
5770
|
+
/**
|
|
5771
|
+
* Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
|
|
5772
|
+
* (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
|
|
5773
|
+
*/
|
|
5774
|
+
static _toOpenRouterSlug(model) {
|
|
5775
|
+
const map = {
|
|
5776
|
+
"claude-sonnet-4-5-20250929": "claude-sonnet-4.5",
|
|
5777
|
+
"claude-sonnet-4-5": "claude-sonnet-4.5",
|
|
5778
|
+
"claude-haiku-4-5-20251001": "claude-haiku-4.5",
|
|
5779
|
+
"claude-haiku-4-5": "claude-haiku-4.5",
|
|
5780
|
+
"claude-opus-4-1-20250805": "claude-opus-4.1",
|
|
5781
|
+
"claude-opus-4-1": "claude-opus-4.1"
|
|
5782
|
+
};
|
|
5783
|
+
if (map[model]) return map[model];
|
|
5784
|
+
let m = model.replace(/-\d{8}$/, "");
|
|
5785
|
+
m = m.replace(/-(\d+)-(\d+)$/, "-$1.$2");
|
|
5786
|
+
return m;
|
|
5787
|
+
}
|
|
5788
|
+
// ============================================================
|
|
5789
|
+
// OPENROUTER IMPLEMENTATION
|
|
5790
|
+
// OpenRouter is OpenAI-API-compatible, so these delegate to the OpenAI methods
|
|
5791
|
+
// but force OpenRouter's own key + base URL. The real OpenAI path is untouched.
|
|
5792
|
+
// ============================================================
|
|
5793
|
+
static _openrouterOptions(options) {
|
|
5794
|
+
return {
|
|
5795
|
+
...options,
|
|
5796
|
+
apiKey: process.env.OPENROUTER_API_KEY || options.apiKey,
|
|
5797
|
+
baseURL: process.env.OPENROUTER_BASE_URL || "https://openrouter.ai/api/v1"
|
|
5798
|
+
};
|
|
5799
|
+
}
|
|
5800
|
+
static async _openrouterText(messages, modelName, options) {
|
|
5801
|
+
return this._openaiText(messages, modelName, this._openrouterOptions(options));
|
|
5802
|
+
}
|
|
5803
|
+
static async _openrouterStream(messages, modelName, options, json) {
|
|
5804
|
+
return this._openaiStream(messages, modelName, this._openrouterOptions(options), json);
|
|
5805
|
+
}
|
|
5806
|
+
static async _openrouterStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations) {
|
|
5807
|
+
return this._openaiStreamWithTools(messages, tools, toolHandler, modelName, this._openrouterOptions(options), maxIterations);
|
|
5756
5808
|
}
|
|
5757
5809
|
// ============================================================
|
|
5758
5810
|
// ANTHROPIC IMPLEMENTATION
|
|
@@ -6628,7 +6680,7 @@ var LLM = class {
|
|
|
6628
6680
|
const startTime = Date.now();
|
|
6629
6681
|
const requestId = llmUsageLogger.generateRequestId();
|
|
6630
6682
|
const apiKey = options.apiKey || process.env.OPENAI_API_KEY || "";
|
|
6631
|
-
const openai = new OpenAI({ apiKey });
|
|
6683
|
+
const openai = new OpenAI({ apiKey, baseURL: options.baseURL });
|
|
6632
6684
|
const systemPrompt = typeof messages.sys === "string" ? messages.sys : messages.sys.map((block) => block.text).join("\n");
|
|
6633
6685
|
try {
|
|
6634
6686
|
const response = await openai.chat.completions.create({
|
|
@@ -6682,7 +6734,7 @@ var LLM = class {
|
|
|
6682
6734
|
const startTime = Date.now();
|
|
6683
6735
|
const requestId = llmUsageLogger.generateRequestId();
|
|
6684
6736
|
const apiKey = options.apiKey || process.env.OPENAI_API_KEY || "";
|
|
6685
|
-
const openai = new OpenAI({ apiKey });
|
|
6737
|
+
const openai = new OpenAI({ apiKey, baseURL: options.baseURL });
|
|
6686
6738
|
const systemPrompt = typeof messages.sys === "string" ? messages.sys : messages.sys.map((block) => block.text).join("\n");
|
|
6687
6739
|
try {
|
|
6688
6740
|
const stream = await openai.chat.completions.create({
|
|
@@ -6760,7 +6812,7 @@ var LLM = class {
|
|
|
6760
6812
|
}
|
|
6761
6813
|
static async _openaiStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations) {
|
|
6762
6814
|
const apiKey = options.apiKey || process.env.OPENAI_API_KEY || "";
|
|
6763
|
-
const openai = new OpenAI({ apiKey });
|
|
6815
|
+
const openai = new OpenAI({ apiKey, baseURL: options.baseURL });
|
|
6764
6816
|
const systemPrompt = typeof messages.sys === "string" ? messages.sys : messages.sys.map((block) => block.text).join("\n");
|
|
6765
6817
|
const openaiTools = tools.map((tool) => ({
|
|
6766
6818
|
type: "function",
|