@superatomai/sdk-node 0.0.1 → 0.0.2

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
@@ -718,7 +718,7 @@ declare class LLM {
718
718
  *
719
719
  * @example
720
720
  * "anthropic/claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"]
721
- * "groq/gpt-oss-120b" → ["groq", "gpt-oss-120b"]
721
+ * "groq/openai/gpt-oss-120b" → ["groq", "openai/gpt-oss-120b"]
722
722
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
723
723
  */
724
724
  private static _parseModel;
package/dist/index.d.ts CHANGED
@@ -718,7 +718,7 @@ declare class LLM {
718
718
  *
719
719
  * @example
720
720
  * "anthropic/claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"]
721
- * "groq/gpt-oss-120b" → ["groq", "gpt-oss-120b"]
721
+ * "groq/openai/gpt-oss-120b" → ["groq", "openai/gpt-oss-120b"]
722
722
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
723
723
  */
724
724
  private static _parseModel;
package/dist/index.js CHANGED
@@ -1883,6 +1883,7 @@ var import_fs2 = __toESM(require("fs"));
1883
1883
  var import_path2 = __toESM(require("path"));
1884
1884
  var PromptLoader = class {
1885
1885
  constructor(config) {
1886
+ logger.debug("Initializing PromptLoader...", process.cwd());
1886
1887
  this.promptsDir = config?.promptsDir || import_path2.default.join(process.cwd(), ".prompts");
1887
1888
  }
1888
1889
  /**
@@ -1899,6 +1900,7 @@ var PromptLoader = class {
1899
1900
  promptName,
1900
1901
  `${promptType}.md`
1901
1902
  );
1903
+ logger.debug(`Loading prompt '${promptName}/${promptType}.md' from ${promptPath} process path: ${process.cwd()}`);
1902
1904
  let content = import_fs2.default.readFileSync(promptPath, "utf-8");
1903
1905
  for (const [key, value] of Object.entries(variables)) {
1904
1906
  const pattern = new RegExp(`{{${key}}}`, "g");
@@ -1977,7 +1979,7 @@ var LLM = class {
1977
1979
  *
1978
1980
  * @example
1979
1981
  * "anthropic/claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"]
1980
- * "groq/gpt-oss-120b" → ["groq", "gpt-oss-120b"]
1982
+ * "groq/openai/gpt-oss-120b" → ["groq", "openai/gpt-oss-120b"]
1981
1983
  * "claude-sonnet-4-5" → ["anthropic", "claude-sonnet-4-5"] (default)
1982
1984
  */
1983
1985
  static _parseModel(modelString) {
@@ -1985,8 +1987,10 @@ var LLM = class {
1985
1987
  return ["anthropic", "claude-sonnet-4-5"];
1986
1988
  }
1987
1989
  if (modelString.includes("/")) {
1988
- const [provider, model] = modelString.split("/");
1989
- return [provider.toLowerCase().trim(), model.trim()];
1990
+ const firstSlashIndex = modelString.indexOf("/");
1991
+ const provider = modelString.substring(0, firstSlashIndex).toLowerCase().trim();
1992
+ const model = modelString.substring(firstSlashIndex + 1).trim();
1993
+ return [provider, model];
1990
1994
  }
1991
1995
  return ["anthropic", modelString];
1992
1996
  }
@@ -1994,8 +1998,11 @@ var LLM = class {
1994
1998
  // ANTHROPIC IMPLEMENTATION
1995
1999
  // ============================================================
1996
2000
  static async _anthropicText(messages, modelName, options) {
2001
+ const apiKey = options.apiKey || process.env.ANTHROPIC_API_KEY || "";
2002
+ console.log("[LLM DEBUG] Anthropic Text - apiKey from options:", options.apiKey ? `${options.apiKey.substring(0, 10)}...` : "NOT SET");
2003
+ console.log("[LLM DEBUG] Anthropic Text - final apiKey:", apiKey ? `${apiKey.substring(0, 10)}...` : "EMPTY STRING");
1997
2004
  const client = new import_sdk.default({
1998
- apiKey: options.apiKey || process.env.ANTHROPIC_API_KEY || ""
2005
+ apiKey
1999
2006
  });
2000
2007
  const response = await client.messages.create({
2001
2008
  model: modelName,
@@ -2011,8 +2018,12 @@ var LLM = class {
2011
2018
  return textBlock?.type === "text" ? textBlock.text : "";
2012
2019
  }
2013
2020
  static async _anthropicStream(messages, modelName, options, json) {
2021
+ const apiKey = options.apiKey || process.env.ANTHROPIC_API_KEY || "";
2022
+ console.log("[LLM DEBUG] Anthropic - apiKey from options:", options.apiKey ? `${options.apiKey.substring(0, 10)}...` : "NOT SET");
2023
+ console.log("[LLM DEBUG] Anthropic - apiKey from env:", process.env.ANTHROPIC_API_KEY ? `${process.env.ANTHROPIC_API_KEY.substring(0, 10)}...` : "NOT SET");
2024
+ console.log("[LLM DEBUG] Anthropic - final apiKey:", apiKey ? `${apiKey.substring(0, 10)}...` : "EMPTY STRING");
2014
2025
  const client = new import_sdk.default({
2015
- apiKey: options.apiKey || process.env.ANTHROPIC_API_KEY || ""
2026
+ apiKey
2016
2027
  });
2017
2028
  const stream = await client.messages.create({
2018
2029
  model: modelName,
@@ -2059,8 +2070,12 @@ var LLM = class {
2059
2070
  return response.choices[0]?.message?.content || "";
2060
2071
  }
2061
2072
  static async _groqStream(messages, modelName, options, json) {
2073
+ const apiKey = options.apiKey || process.env.GROQ_API_KEY || "";
2074
+ console.log("[LLM DEBUG] Groq - apiKey from options:", options.apiKey ? `${options.apiKey.substring(0, 10)}...` : "NOT SET");
2075
+ console.log("[LLM DEBUG] Groq - model:", modelName);
2076
+ console.log("[LLM DEBUG] Groq - final apiKey:", apiKey ? `${apiKey.substring(0, 10)}...` : "EMPTY STRING");
2062
2077
  const client = new import_groq_sdk.default({
2063
- apiKey: options.apiKey || process.env.GROQ_API_KEY || ""
2078
+ apiKey
2064
2079
  });
2065
2080
  const stream = await client.chat.completions.create({
2066
2081
  model: modelName,
@@ -2131,6 +2146,7 @@ var BaseLLM = class {
2131
2146
  */
2132
2147
  async classifyUserQuestion(userPrompt, apiKey, logCollector, conversationHistory) {
2133
2148
  const schemaDoc = schema.generateSchemaDocumentation();
2149
+ logger.info("Generating prompts...", userPrompt, conversationHistory);
2134
2150
  try {
2135
2151
  const prompts = await promptLoader.loadPrompts("classify", {
2136
2152
  SCHEMA_DOC: schemaDoc || "No schema available",
@@ -2787,8 +2803,15 @@ var useAnthropicMethod = async (prompt, components, apiKey, logCollector, conver
2787
2803
  logCollector?.error(emptyMsg);
2788
2804
  return { success: false, reason: emptyMsg };
2789
2805
  }
2790
- const matchResult = await anthropicLLM.handleUserRequest(prompt, components, apiKey, logCollector, conversationHistory);
2791
- return { success: true, data: matchResult };
2806
+ try {
2807
+ const matchResult = await anthropicLLM.handleUserRequest(prompt, components, apiKey, logCollector, conversationHistory);
2808
+ logger.debug(`Anthropic method success: ${matchResult}`);
2809
+ return { success: true, data: matchResult };
2810
+ } catch (error) {
2811
+ const errorMsg = error instanceof Error ? error.message : String(error);
2812
+ logCollector?.error(`Anthropic method failed: ${errorMsg}`);
2813
+ throw error;
2814
+ }
2792
2815
  };
2793
2816
  var useGroqMethod = async (prompt, components, apiKey, logCollector, conversationHistory) => {
2794
2817
  const msg = "Using Groq LLM matching method...";
@@ -2799,8 +2822,14 @@ var useGroqMethod = async (prompt, components, apiKey, logCollector, conversatio
2799
2822
  logCollector?.error(emptyMsg);
2800
2823
  return { success: false, reason: emptyMsg };
2801
2824
  }
2802
- const matchResult = await groqLLM.handleUserRequest(prompt, components, apiKey, logCollector, conversationHistory);
2803
- return { success: true, data: matchResult };
2825
+ try {
2826
+ const matchResult = await groqLLM.handleUserRequest(prompt, components, apiKey, logCollector, conversationHistory);
2827
+ return { success: true, data: matchResult };
2828
+ } catch (error) {
2829
+ const errorMsg = error instanceof Error ? error.message : String(error);
2830
+ logCollector?.error(`Groq method failed: ${errorMsg}`);
2831
+ throw error;
2832
+ }
2804
2833
  };
2805
2834
  var getUserResponseFromCache = async (prompt) => {
2806
2835
  return false;
@@ -2830,6 +2859,7 @@ var get_user_response = async (prompt, components, anthropicApiKey, groqApiKey,
2830
2859
  let result;
2831
2860
  if (provider === "anthropic") {
2832
2861
  result = await useAnthropicMethod(prompt, components, anthropicApiKey, logCollector, conversationHistory);
2862
+ logger.debug("Anthropic result:", result);
2833
2863
  } else if (provider === "groq") {
2834
2864
  result = await useGroqMethod(prompt, components, groqApiKey, logCollector, conversationHistory);
2835
2865
  } else {
@@ -3021,6 +3051,7 @@ var CONTEXT_CONFIG = {
3021
3051
  };
3022
3052
 
3023
3053
  // src/handlers/user-prompt-request.ts
3054
+ var processedMessageIds = /* @__PURE__ */ new Set();
3024
3055
  async function handleUserPromptRequest(data, components, sendMessage, anthropicApiKey, groqApiKey, llmProviders) {
3025
3056
  try {
3026
3057
  const userPromptRequest = UserPromptRequestMessageSchema.parse(data);
@@ -3028,6 +3059,19 @@ async function handleUserPromptRequest(data, components, sendMessage, anthropicA
3028
3059
  const prompt = payload.prompt;
3029
3060
  const SA_RUNTIME = payload.SA_RUNTIME;
3030
3061
  const wsId = userPromptRequest.from.id || "unknown";
3062
+ logger.info(`[REQUEST ${id}] Processing user prompt: "${prompt.substring(0, 50)}..."`);
3063
+ logger.info(`[REQUEST ${id}] Providers: ${llmProviders?.join(", ")}, Anthropic key: ${anthropicApiKey ? "SET" : "NOT SET"}, Groq key: ${groqApiKey ? "SET" : "NOT SET"}`);
3064
+ if (processedMessageIds.has(id)) {
3065
+ logger.warn(`[REQUEST ${id}] Duplicate request detected - ignoring`);
3066
+ return;
3067
+ }
3068
+ processedMessageIds.add(id);
3069
+ if (processedMessageIds.size > 100) {
3070
+ const firstId = processedMessageIds.values().next().value;
3071
+ if (firstId) {
3072
+ processedMessageIds.delete(firstId);
3073
+ }
3074
+ }
3031
3075
  if (!SA_RUNTIME) {
3032
3076
  sendDataResponse4(id, {
3033
3077
  success: false,
@@ -3077,6 +3121,7 @@ async function handleUserPromptRequest(data, components, sendMessage, anthropicA
3077
3121
  const conversationHistory = thread.getConversationContext(CONTEXT_CONFIG.MAX_CONVERSATION_CONTEXT_BLOCKS, existingUiBlockId);
3078
3122
  const userResponse = await get_user_response(prompt, components, anthropicApiKey, groqApiKey, llmProviders, logCollector, conversationHistory);
3079
3123
  logCollector.info("User prompt request completed");
3124
+ logger.info(`[REQUEST ${id}] Response success: ${userResponse.success}, reason: ${userResponse.success ? "N/A" : userResponse}`);
3080
3125
  if (userResponse.success && userResponse.data && typeof userResponse.data === "object" && "component" in userResponse.data) {
3081
3126
  const component = userResponse.data.component;
3082
3127
  const uiBlockId = existingUiBlockId;
@@ -3118,6 +3163,10 @@ function sendDataResponse4(id, res, sendMessage, clientId) {
3118
3163
  ...res
3119
3164
  }
3120
3165
  };
3166
+ logger.info(`[REQUEST ${id}] Sending USER_PROMPT_RES with success=${res.success}`);
3167
+ if (!res.success && res.reason) {
3168
+ logger.info(`[REQUEST ${id}] Error reason: ${res.reason}`);
3169
+ }
3121
3170
  sendMessage(response);
3122
3171
  }
3123
3172
 
@@ -4227,6 +4276,9 @@ var UserManager = class {
4227
4276
  if (!user) {
4228
4277
  return false;
4229
4278
  }
4279
+ if (!user.wsIds || !Array.isArray(user.wsIds)) {
4280
+ user.wsIds = [];
4281
+ }
4230
4282
  if (!user.wsIds.includes(wsId)) {
4231
4283
  user.wsIds.push(wsId);
4232
4284
  this.hasChanged = true;
@@ -4245,6 +4297,9 @@ var UserManager = class {
4245
4297
  if (!user) {
4246
4298
  return false;
4247
4299
  }
4300
+ if (!user.wsIds || !Array.isArray(user.wsIds)) {
4301
+ return false;
4302
+ }
4248
4303
  const initialLength = user.wsIds.length;
4249
4304
  user.wsIds = user.wsIds.filter((id) => id !== wsId);
4250
4305
  if (user.wsIds.length < initialLength) {