@superatomai/sdk-node 0.0.27 → 0.0.28

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.mjs CHANGED
@@ -2892,7 +2892,9 @@ If adaptation is not possible or would fundamentally change the component:
2892
2892
  var PromptLoader = class {
2893
2893
  constructor(config) {
2894
2894
  this.promptCache = /* @__PURE__ */ new Map();
2895
+ this.databaseRulesCache = /* @__PURE__ */ new Map();
2895
2896
  this.isInitialized = false;
2897
+ this.databaseType = "postgresql";
2896
2898
  logger.debug("Initializing PromptLoader...");
2897
2899
  this.promptsDir = config?.promptsDir || path3.join(process.cwd(), ".prompts");
2898
2900
  logger.debug(`Prompts directory set to: ${this.promptsDir}`);
@@ -3038,6 +3040,76 @@ var PromptLoader = class {
3038
3040
  getCacheSize() {
3039
3041
  return this.promptCache.size;
3040
3042
  }
3043
+ /**
3044
+ * Set the database type for SQL rules loading
3045
+ * @param type - Database type ('postgresql' | 'mssql')
3046
+ */
3047
+ setDatabaseType(type) {
3048
+ this.databaseType = type;
3049
+ this.databaseRulesCache.clear();
3050
+ logger.debug(`Database type set to: ${type}`);
3051
+ }
3052
+ /**
3053
+ * Get current database type
3054
+ * @returns Database type string
3055
+ */
3056
+ getDatabaseType() {
3057
+ return this.databaseType;
3058
+ }
3059
+ /**
3060
+ * Load database-specific SQL rules from file system
3061
+ * Falls back to minimal default rules if file not found
3062
+ * @returns Database rules as a string
3063
+ */
3064
+ async loadDatabaseRules() {
3065
+ if (this.databaseRulesCache.has(this.databaseType)) {
3066
+ logger.debug(`\u2713 Database rules for '${this.databaseType}' loaded from cache`);
3067
+ return this.databaseRulesCache.get(this.databaseType);
3068
+ }
3069
+ const rulesPath = path3.join(this.promptsDir, "database-rules", `${this.databaseType}.md`);
3070
+ try {
3071
+ if (fs4.existsSync(rulesPath)) {
3072
+ const rules = fs4.readFileSync(rulesPath, "utf-8");
3073
+ this.databaseRulesCache.set(this.databaseType, rules);
3074
+ logger.info(`\u2713 Loaded database rules for '${this.databaseType}' from ${rulesPath}`);
3075
+ return rules;
3076
+ }
3077
+ } catch (error) {
3078
+ logger.warn(`Could not load database rules for '${this.databaseType}' from file system: ${error}`);
3079
+ }
3080
+ const defaultRules = this.getDefaultDatabaseRules();
3081
+ this.databaseRulesCache.set(this.databaseType, defaultRules);
3082
+ logger.warn(`Using default database rules for '${this.databaseType}' (file not found at ${rulesPath})`);
3083
+ return defaultRules;
3084
+ }
3085
+ /**
3086
+ * Get default database rules as fallback
3087
+ * @returns Minimal database rules
3088
+ */
3089
+ getDefaultDatabaseRules() {
3090
+ if (this.databaseType === "mssql") {
3091
+ return `**Database Type: Microsoft SQL Server**
3092
+
3093
+ **SQL Query Rules:**
3094
+ - Use \`TOP N\` for row limiting (e.g., \`SELECT TOP 32 * FROM table\`)
3095
+ - Use \`1\` for true, \`0\` for false (no native boolean)
3096
+ - Use \`+\` or \`CONCAT()\` for string concatenation
3097
+ - Use \`GETDATE()\` for current timestamp
3098
+ - Use \`CAST()\` or \`CONVERT()\` for type casting
3099
+ - Use \`OUTPUT INSERTED.*\` instead of \`RETURNING\`
3100
+ - NULL values: Use \`NULL\` keyword without quotes`;
3101
+ }
3102
+ return `**Database Type: PostgreSQL**
3103
+
3104
+ **SQL Query Rules:**
3105
+ - Use \`LIMIT N\` for row limiting (e.g., \`SELECT * FROM table LIMIT 32\`)
3106
+ - Use \`true\` / \`false\` for boolean values
3107
+ - Use \`||\` for string concatenation
3108
+ - Use \`NOW()\` for current timestamp
3109
+ - Use \`::TYPE\` or \`CAST()\` for type casting
3110
+ - Use \`RETURNING\` clause for mutations
3111
+ - NULL values: Use \`NULL\` keyword without quotes`;
3112
+ }
3041
3113
  };
3042
3114
  var defaultPromptsPath = process.env.PROMPTS_DIR || path3.join(process.cwd(), ".prompts");
3043
3115
  var promptLoader = new PromptLoader({
@@ -4196,6 +4268,7 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4196
4268
  }).join("\n\n");
4197
4269
  }
4198
4270
  const schemaDoc = schema.generateSchemaDocumentation();
4271
+ const databaseRules = await promptLoader.loadDatabaseRules();
4199
4272
  logger.file("\n=============================\nText analysis response:", analysisContent);
4200
4273
  logger.file("\n=============================\nDeferred tools:", deferredToolsText);
4201
4274
  logger.file("\n=============================\nExecuted tools:", executedToolsText);
@@ -4203,6 +4276,7 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4203
4276
  ANALYSIS_CONTENT: analysisContent,
4204
4277
  AVAILABLE_COMPONENTS: availableComponentsText,
4205
4278
  SCHEMA_DOC: schemaDoc,
4279
+ DATABASE_RULES: databaseRules,
4206
4280
  DEFERRED_TOOLS: deferredToolsText,
4207
4281
  EXECUTED_TOOLS: executedToolsText
4208
4282
  });
@@ -4463,12 +4537,14 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4463
4537
  };
4464
4538
  }
4465
4539
  const schemaDoc = schema.generateSchemaDocumentation();
4540
+ const databaseRules = await promptLoader.loadDatabaseRules();
4466
4541
  const prompts = await promptLoader.loadPrompts("adapt-ui-block-params", {
4467
4542
  ORIGINAL_USER_PROMPT: originalUserPrompt,
4468
4543
  CURRENT_USER_PROMPT: currentUserPrompt,
4469
4544
  MATCHED_UI_BLOCK_COMPONENT: JSON.stringify(component, null, 2),
4470
4545
  COMPONENT_PROPS: JSON.stringify(component.props, null, 2),
4471
- SCHEMA_DOC: schemaDoc || "No schema available"
4546
+ SCHEMA_DOC: schemaDoc || "No schema available",
4547
+ DATABASE_RULES: databaseRules
4472
4548
  });
4473
4549
  const result = await LLM.stream(
4474
4550
  {
@@ -4587,6 +4663,7 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4587
4663
  availableToolsDoc = toolsDocParts.join("\n\n---\n\n");
4588
4664
  }
4589
4665
  const schemaDoc = schema.generateSchemaDocumentation();
4666
+ const databaseRules = await promptLoader.loadDatabaseRules();
4590
4667
  const knowledgeBaseContext = await knowledge_base_default.getKnowledgeBase({
4591
4668
  prompt: userPrompt,
4592
4669
  collections,
@@ -4597,6 +4674,7 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
4597
4674
  USER_PROMPT: userPrompt,
4598
4675
  CONVERSATION_HISTORY: conversationHistory || "No previous conversation",
4599
4676
  SCHEMA_DOC: schemaDoc,
4677
+ DATABASE_RULES: databaseRules,
4600
4678
  KNOWLEDGE_BASE_CONTEXT: knowledgeBaseContext || "No additional knowledge base context available.",
4601
4679
  AVAILABLE_EXTERNAL_TOOLS: availableToolsDoc
4602
4680
  });
@@ -9555,7 +9633,8 @@ var SuperatomSDK = class {
9555
9633
  this.geminiApiKey = config.GEMINI_API_KEY || process.env.GEMINI_API_KEY || "";
9556
9634
  this.openaiApiKey = config.OPENAI_API_KEY || process.env.OPENAI_API_KEY || "";
9557
9635
  this.llmProviders = config.LLM_PROVIDERS || getLLMProviders();
9558
- logger.info(`Initializing Superatom SDK v${SDK_VERSION} for project ${this.projectId}, llm providers: ${this.llmProviders.join(", ")}, config llm providers: ${config.LLM_PROVIDERS}`);
9636
+ this.databaseType = config.databaseType || "postgresql";
9637
+ logger.info(`Initializing Superatom SDK v${SDK_VERSION} for project ${this.projectId}, llm providers: ${this.llmProviders.join(", ")}, database type: ${this.databaseType}`);
9559
9638
  this.userManager = new UserManager(this.projectId, 5e3);
9560
9639
  this.dashboardManager = new DashboardManager(this.projectId);
9561
9640
  this.reportManager = new ReportManager(this.projectId);
@@ -9577,8 +9656,9 @@ var SuperatomSDK = class {
9577
9656
  if (promptsDir) {
9578
9657
  promptLoader.setPromptsDir(promptsDir);
9579
9658
  }
9659
+ promptLoader.setDatabaseType(this.databaseType);
9580
9660
  await promptLoader.initialize();
9581
- logger.info(`PromptLoader initialized with ${promptLoader.getCacheSize()} prompts from ${promptLoader.getPromptsDir()}`);
9661
+ logger.info(`PromptLoader initialized with ${promptLoader.getCacheSize()} prompts from ${promptLoader.getPromptsDir()}, database type: ${this.databaseType}`);
9582
9662
  } catch (error) {
9583
9663
  logger.error("Failed to initialize PromptLoader:", error);
9584
9664
  throw error;