@superatomai/sdk-node 0.0.16 → 0.0.18

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
@@ -429,6 +429,8 @@ var ComponentPropsSchema = z3.object({
429
429
  var ComponentSchema = z3.object({
430
430
  id: z3.string(),
431
431
  name: z3.string(),
432
+ displayName: z3.string().optional(),
433
+ isDisplayComp: z3.boolean().optional(),
432
434
  type: z3.string(),
433
435
  description: z3.string(),
434
436
  props: ComponentPropsSchema,
@@ -3411,6 +3413,26 @@ var BaseLLM = class {
3411
3413
  getApiKey(apiKey) {
3412
3414
  return apiKey || this.apiKey || this.getDefaultApiKey();
3413
3415
  }
3416
+ /**
3417
+ * Check if a component contains a Form (data_modification component)
3418
+ * Forms have hardcoded defaultValues that become stale when cached
3419
+ * This checks both single Form components and Forms inside MultiComponentContainer
3420
+ */
3421
+ containsFormComponent(component) {
3422
+ if (!component) return false;
3423
+ if (component.type === "Form" || component.name === "DynamicForm") {
3424
+ return true;
3425
+ }
3426
+ if (component.type === "Container" || component.name === "MultiComponentContainer") {
3427
+ const nestedComponents = component.props?.config?.components || [];
3428
+ for (const nested of nestedComponents) {
3429
+ if (nested.type === "Form" || nested.name === "DynamicForm") {
3430
+ return true;
3431
+ }
3432
+ }
3433
+ }
3434
+ return false;
3435
+ }
3414
3436
  /**
3415
3437
  * Match components from text response suggestions and generate follow-up questions
3416
3438
  * Takes a text response with component suggestions (c1:type format) and matches with available components
@@ -4285,9 +4307,15 @@ ${errorMsg}
4285
4307
  logCollector?.info(
4286
4308
  `\u2713 Found similar conversation (${(conversationMatch.similarity * 100).toFixed(2)}% match)`
4287
4309
  );
4288
- const component = conversationMatch.uiBlock?.component || conversationMatch.uiBlock?.generatedComponentMetadata;
4310
+ const rawComponent = conversationMatch.uiBlock?.component || conversationMatch.uiBlock?.generatedComponentMetadata;
4311
+ const isValidComponent = rawComponent && typeof rawComponent === "object" && Object.keys(rawComponent).length > 0;
4312
+ const component = isValidComponent ? rawComponent : null;
4289
4313
  const cachedTextResponse = conversationMatch.uiBlock?.analysis || conversationMatch.uiBlock?.textResponse || conversationMatch.uiBlock?.text || "";
4290
- if (!component) {
4314
+ logger.debug(`[${this.getProviderName()}] Cached component: ${component ? "present" : "null"}, cachedTextResponse: ${cachedTextResponse ? cachedTextResponse.substring(0, 50) + "..." : "empty"}`);
4315
+ if (this.containsFormComponent(component)) {
4316
+ logger.info(`[${this.getProviderName()}] Skipping cached result - Form components contain stale defaultValues, fetching fresh data`);
4317
+ logCollector?.info("Skipping cache for form - fetching current values from database...");
4318
+ } else if (!component) {
4291
4319
  if (conversationMatch.similarity >= 0.99) {
4292
4320
  const elapsedTime2 = Date.now() - startTime;
4293
4321
  logger.info(`[${this.getProviderName()}] \u2713 Exact match for general question - returning cached text response`);
@@ -5186,19 +5214,20 @@ async function handleUserPromptSuggestions(data, components, sendMessage) {
5186
5214
  }, sendMessage, wsId);
5187
5215
  return;
5188
5216
  }
5189
- if (!components || components.length === 0) {
5217
+ const displayComponents = components.filter((c) => c.isDisplayComp === true);
5218
+ if (!displayComponents || displayComponents.length === 0) {
5190
5219
  sendResponse(id, {
5191
5220
  success: true,
5192
5221
  data: {
5193
5222
  prompt,
5194
5223
  suggestions: [],
5195
5224
  count: 0,
5196
- message: "No components available"
5225
+ message: "No display components available"
5197
5226
  }
5198
5227
  }, sendMessage, wsId);
5199
5228
  return;
5200
5229
  }
5201
- const suggestions = searchComponents(prompt, components, limit);
5230
+ const suggestions = searchComponents(prompt, displayComponents, limit);
5202
5231
  sendResponse(id, {
5203
5232
  success: true,
5204
5233
  data: {
@@ -5222,6 +5251,7 @@ function searchComponents(prompt, components, limit) {
5222
5251
  const scoredComponents = components.map((component) => {
5223
5252
  let score = 0;
5224
5253
  const componentName = component.name.toLowerCase();
5254
+ const componentDisplayName = (component.displayName || "").toLowerCase();
5225
5255
  const componentDesc = component.description.toLowerCase();
5226
5256
  const componentKeywords = (component.keywords || []).map((k) => k.toLowerCase());
5227
5257
  const componentCategory = (component.category || "").toLowerCase();
@@ -5231,6 +5261,9 @@ function searchComponents(prompt, components, limit) {
5231
5261
  } else if (componentName.includes(token)) {
5232
5262
  score += 5;
5233
5263
  }
5264
+ if (componentDisplayName.includes(token)) {
5265
+ score += 6;
5266
+ }
5234
5267
  if (componentKeywords.includes(token)) {
5235
5268
  score += 8;
5236
5269
  } else if (componentKeywords.some((k) => k.includes(token))) {