@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 CHANGED
@@ -1686,6 +1686,7 @@ interface LLMOptions {
1686
1686
  temperature?: number;
1687
1687
  topP?: number;
1688
1688
  apiKey?: string;
1689
+ baseURL?: string;
1689
1690
  partial?: (chunk: string) => void;
1690
1691
  }
1691
1692
  interface Tool {
@@ -1734,6 +1735,15 @@ declare class LLM {
1734
1735
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
1735
1736
  */
1736
1737
  private static _parseModel;
1738
+ /**
1739
+ * Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
1740
+ * (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
1741
+ */
1742
+ private static _toOpenRouterSlug;
1743
+ private static _openrouterOptions;
1744
+ private static _openrouterText;
1745
+ private static _openrouterStream;
1746
+ private static _openrouterStreamWithTools;
1737
1747
  private static _anthropicText;
1738
1748
  private static _anthropicStream;
1739
1749
  private static _anthropicStreamWithTools;
package/dist/index.d.ts CHANGED
@@ -1686,6 +1686,7 @@ interface LLMOptions {
1686
1686
  temperature?: number;
1687
1687
  topP?: number;
1688
1688
  apiKey?: string;
1689
+ baseURL?: string;
1689
1690
  partial?: (chunk: string) => void;
1690
1691
  }
1691
1692
  interface Tool {
@@ -1734,6 +1735,15 @@ declare class LLM {
1734
1735
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
1735
1736
  */
1736
1737
  private static _parseModel;
1738
+ /**
1739
+ * Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
1740
+ * (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
1741
+ */
1742
+ private static _toOpenRouterSlug;
1743
+ private static _openrouterOptions;
1744
+ private static _openrouterText;
1745
+ private static _openrouterStream;
1746
+ private static _openrouterStreamWithTools;
1737
1747
  private static _anthropicText;
1738
1748
  private static _anthropicStream;
1739
1749
  private static _anthropicStreamWithTools;
package/dist/index.js CHANGED
@@ -5666,8 +5666,10 @@ var LLM = class {
5666
5666
  return this._geminiText(messages, modelName, options);
5667
5667
  } else if (provider === "openai") {
5668
5668
  return this._openaiText(messages, modelName, options);
5669
+ } else if (provider === "openrouter") {
5670
+ return this._openrouterText(messages, modelName, options);
5669
5671
  } else {
5670
- throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", or "openai"`);
5672
+ throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", "openai", or "openrouter"`);
5671
5673
  }
5672
5674
  }
5673
5675
  /* Stream response from an LLM (Anthropic or Groq) */
@@ -5682,8 +5684,10 @@ var LLM = class {
5682
5684
  return this._geminiStream(messages, modelName, options, json);
5683
5685
  } else if (provider === "openai") {
5684
5686
  return this._openaiStream(messages, modelName, options, json);
5687
+ } else if (provider === "openrouter") {
5688
+ return this._openrouterStream(messages, modelName, options, json);
5685
5689
  } else {
5686
- throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", or "openai"`);
5690
+ throw new Error(`Unsupported provider: ${provider}. Use "anthropic", "groq", "gemini", "openai", or "openrouter"`);
5687
5691
  }
5688
5692
  }
5689
5693
  /* Stream response with tool calling support (Anthropic and Gemini) */
@@ -5696,8 +5700,10 @@ var LLM = class {
5696
5700
  return this._geminiStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations);
5697
5701
  } else if (provider === "openai") {
5698
5702
  return this._openaiStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations);
5703
+ } else if (provider === "openrouter") {
5704
+ return this._openrouterStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations);
5699
5705
  } else {
5700
- throw new Error(`Tool calling is only supported for Anthropic, Gemini, and OpenAI models`);
5706
+ throw new Error(`Tool calling is only supported for Anthropic, Gemini, OpenAI, and OpenRouter models`);
5701
5707
  }
5702
5708
  }
5703
5709
  // ============================================================
@@ -5803,16 +5809,62 @@ var LLM = class {
5803
5809
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
5804
5810
  */
5805
5811
  static _parseModel(modelString) {
5812
+ let provider;
5813
+ let model;
5806
5814
  if (!modelString) {
5807
- return ["anthropic", "claude-sonnet-4-5"];
5808
- }
5809
- if (modelString.includes("/")) {
5815
+ provider = "anthropic";
5816
+ model = "claude-sonnet-4-5";
5817
+ } else if (modelString.includes("/")) {
5810
5818
  const firstSlashIndex = modelString.indexOf("/");
5811
- const provider = modelString.substring(0, firstSlashIndex).toLowerCase().trim();
5812
- const model = modelString.substring(firstSlashIndex + 1).trim();
5813
- return [provider, model];
5819
+ provider = modelString.substring(0, firstSlashIndex).toLowerCase().trim();
5820
+ model = modelString.substring(firstSlashIndex + 1).trim();
5821
+ } else {
5822
+ provider = "anthropic";
5823
+ model = modelString;
5814
5824
  }
5815
- return ["anthropic", modelString];
5825
+ if (provider === "anthropic" && !process.env.ANTHROPIC_API_KEY && process.env.OPENROUTER_API_KEY) {
5826
+ return ["openrouter", "anthropic/" + this._toOpenRouterSlug(model)];
5827
+ }
5828
+ return [provider, model];
5829
+ }
5830
+ /**
5831
+ * Map an Anthropic model id (e.g. "claude-sonnet-4-5-20250929") to the OpenRouter slug
5832
+ * (e.g. "claude-sonnet-4.5"). OpenRouter slugs drop the date suffix and use dotted versions.
5833
+ */
5834
+ static _toOpenRouterSlug(model) {
5835
+ const map = {
5836
+ "claude-sonnet-4-5-20250929": "claude-sonnet-4.5",
5837
+ "claude-sonnet-4-5": "claude-sonnet-4.5",
5838
+ "claude-haiku-4-5-20251001": "claude-haiku-4.5",
5839
+ "claude-haiku-4-5": "claude-haiku-4.5",
5840
+ "claude-opus-4-1-20250805": "claude-opus-4.1",
5841
+ "claude-opus-4-1": "claude-opus-4.1"
5842
+ };
5843
+ if (map[model]) return map[model];
5844
+ let m = model.replace(/-\d{8}$/, "");
5845
+ m = m.replace(/-(\d+)-(\d+)$/, "-$1.$2");
5846
+ return m;
5847
+ }
5848
+ // ============================================================
5849
+ // OPENROUTER IMPLEMENTATION
5850
+ // OpenRouter is OpenAI-API-compatible, so these delegate to the OpenAI methods
5851
+ // but force OpenRouter's own key + base URL. The real OpenAI path is untouched.
5852
+ // ============================================================
5853
+ static _openrouterOptions(options) {
5854
+ return {
5855
+ ...options,
5856
+ apiKey: process.env.OPENROUTER_API_KEY || options.apiKey,
5857
+ baseURL: process.env.OPENROUTER_BASE_URL || "https://openrouter.ai/api/v1"
5858
+ };
5859
+ }
5860
+ static async _openrouterText(messages, modelName, options) {
5861
+ return this._openaiText(messages, modelName, this._openrouterOptions(options));
5862
+ }
5863
+ static async _openrouterStream(messages, modelName, options, json) {
5864
+ return this._openaiStream(messages, modelName, this._openrouterOptions(options), json);
5865
+ }
5866
+ static async _openrouterStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations) {
5867
+ return this._openaiStreamWithTools(messages, tools, toolHandler, modelName, this._openrouterOptions(options), maxIterations);
5816
5868
  }
5817
5869
  // ============================================================
5818
5870
  // ANTHROPIC IMPLEMENTATION
@@ -6688,7 +6740,7 @@ var LLM = class {
6688
6740
  const startTime = Date.now();
6689
6741
  const requestId = llmUsageLogger.generateRequestId();
6690
6742
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY || "";
6691
- const openai = new import_openai.default({ apiKey });
6743
+ const openai = new import_openai.default({ apiKey, baseURL: options.baseURL });
6692
6744
  const systemPrompt = typeof messages.sys === "string" ? messages.sys : messages.sys.map((block) => block.text).join("\n");
6693
6745
  try {
6694
6746
  const response = await openai.chat.completions.create({
@@ -6742,7 +6794,7 @@ var LLM = class {
6742
6794
  const startTime = Date.now();
6743
6795
  const requestId = llmUsageLogger.generateRequestId();
6744
6796
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY || "";
6745
- const openai = new import_openai.default({ apiKey });
6797
+ const openai = new import_openai.default({ apiKey, baseURL: options.baseURL });
6746
6798
  const systemPrompt = typeof messages.sys === "string" ? messages.sys : messages.sys.map((block) => block.text).join("\n");
6747
6799
  try {
6748
6800
  const stream = await openai.chat.completions.create({
@@ -6820,7 +6872,7 @@ var LLM = class {
6820
6872
  }
6821
6873
  static async _openaiStreamWithTools(messages, tools, toolHandler, modelName, options, maxIterations) {
6822
6874
  const apiKey = options.apiKey || process.env.OPENAI_API_KEY || "";
6823
- const openai = new import_openai.default({ apiKey });
6875
+ const openai = new import_openai.default({ apiKey, baseURL: options.baseURL });
6824
6876
  const systemPrompt = typeof messages.sys === "string" ? messages.sys : messages.sys.map((block) => block.text).join("\n");
6825
6877
  const openaiTools = tools.map((tool) => ({
6826
6878
  type: "function",