@superatomai/sdk-node 0.0.63 → 0.0.65

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
@@ -943,9 +943,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
943
943
  } | undefined;
944
944
  createdBy?: number | undefined;
945
945
  updatedBy?: number | undefined;
946
+ offset?: number | undefined;
946
947
  tags?: string[] | undefined;
947
948
  content?: string | undefined;
948
- offset?: number | undefined;
949
949
  }, {
950
950
  id?: number | undefined;
951
951
  type?: "query" | "user" | "global" | undefined;
@@ -963,9 +963,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
963
963
  } | undefined;
964
964
  createdBy?: number | undefined;
965
965
  updatedBy?: number | undefined;
966
+ offset?: number | undefined;
966
967
  tags?: string[] | undefined;
967
968
  content?: string | undefined;
968
- offset?: number | undefined;
969
969
  }>>;
970
970
  }, "strip", z.ZodTypeAny, {
971
971
  operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
@@ -986,9 +986,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
986
986
  } | undefined;
987
987
  createdBy?: number | undefined;
988
988
  updatedBy?: number | undefined;
989
+ offset?: number | undefined;
989
990
  tags?: string[] | undefined;
990
991
  content?: string | undefined;
991
- offset?: number | undefined;
992
992
  } | undefined;
993
993
  }, {
994
994
  operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
@@ -1009,9 +1009,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
1009
1009
  } | undefined;
1010
1010
  createdBy?: number | undefined;
1011
1011
  updatedBy?: number | undefined;
1012
+ offset?: number | undefined;
1012
1013
  tags?: string[] | undefined;
1013
1014
  content?: string | undefined;
1014
- offset?: number | undefined;
1015
1015
  } | undefined;
1016
1016
  }>;
1017
1017
  type KbNodesRequestPayload = z.infer<typeof KbNodesRequestPayloadSchema>;
package/dist/index.d.ts CHANGED
@@ -943,9 +943,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
943
943
  } | undefined;
944
944
  createdBy?: number | undefined;
945
945
  updatedBy?: number | undefined;
946
+ offset?: number | undefined;
946
947
  tags?: string[] | undefined;
947
948
  content?: string | undefined;
948
- offset?: number | undefined;
949
949
  }, {
950
950
  id?: number | undefined;
951
951
  type?: "query" | "user" | "global" | undefined;
@@ -963,9 +963,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
963
963
  } | undefined;
964
964
  createdBy?: number | undefined;
965
965
  updatedBy?: number | undefined;
966
+ offset?: number | undefined;
966
967
  tags?: string[] | undefined;
967
968
  content?: string | undefined;
968
- offset?: number | undefined;
969
969
  }>>;
970
970
  }, "strip", z.ZodTypeAny, {
971
971
  operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
@@ -986,9 +986,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
986
986
  } | undefined;
987
987
  createdBy?: number | undefined;
988
988
  updatedBy?: number | undefined;
989
+ offset?: number | undefined;
989
990
  tags?: string[] | undefined;
990
991
  content?: string | undefined;
991
- offset?: number | undefined;
992
992
  } | undefined;
993
993
  }, {
994
994
  operation: "create" | "getOne" | "update" | "delete" | "getAll" | "search" | "getByCategory" | "getByUser" | "getCategories" | "getTags";
@@ -1009,9 +1009,9 @@ declare const KbNodesRequestPayloadSchema: z.ZodObject<{
1009
1009
  } | undefined;
1010
1010
  createdBy?: number | undefined;
1011
1011
  updatedBy?: number | undefined;
1012
+ offset?: number | undefined;
1012
1013
  tags?: string[] | undefined;
1013
1014
  content?: string | undefined;
1014
- offset?: number | undefined;
1015
1015
  } | undefined;
1016
1016
  }>;
1017
1017
  type KbNodesRequestPayload = z.infer<typeof KbNodesRequestPayloadSchema>;
package/dist/index.js CHANGED
@@ -2529,9 +2529,11 @@ var BookmarksRequestMessageSchema = import_zod3.z.object({
2529
2529
  });
2530
2530
  var ArtifactsQueryFiltersSchema = import_zod3.z.object({
2531
2531
  createdBy: import_zod3.z.number().optional(),
2532
+ type: import_zod3.z.string().optional(),
2532
2533
  status: import_zod3.z.string().optional(),
2533
2534
  name: import_zod3.z.string().optional(),
2534
- deleted: import_zod3.z.boolean().optional()
2535
+ deleted: import_zod3.z.boolean().optional(),
2536
+ createdAt: import_zod3.z.string().optional()
2535
2537
  });
2536
2538
  var ArtifactsRequestPayloadSchema = import_zod3.z.object({
2537
2539
  operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
@@ -2543,6 +2545,7 @@ var ArtifactsRequestPayloadSchema = import_zod3.z.object({
2543
2545
  status: import_zod3.z.string().optional(),
2544
2546
  deleted: import_zod3.z.boolean().optional(),
2545
2547
  limit: import_zod3.z.number().optional(),
2548
+ offset: import_zod3.z.number().optional(),
2546
2549
  // Query operation fields
2547
2550
  filters: ArtifactsQueryFiltersSchema.optional(),
2548
2551
  sort: import_zod3.z.enum(["ASC", "DESC"]).optional(),
@@ -6372,11 +6375,11 @@ Fixed SQL query:`;
6372
6375
  logger.info(`[${this.getProviderName()}] Passing ${deferredTools.length} deferred tools to component matching`);
6373
6376
  deferredToolsText = "The following external tools need user input via a Form component.\n**IMPORTANT: Use these EXACT values when generating Form externalTool prop.**\n\n" + deferredTools.map((tool, idx) => {
6374
6377
  return `${idx + 1}. **${tool.name}**
6375
- toolId: "${tool.id}" (USE THIS EXACT VALUE - do not modify!)
6376
- toolName: "${tool.name}"
6377
- parameters: ${JSON.stringify(tool.params || {})}
6378
- requiredFields:
6379
- ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
6378
+ toolId: "${tool.id}" (USE THIS EXACT VALUE - do not modify!)
6379
+ toolName: "${tool.name}"
6380
+ parameters: ${JSON.stringify(tool.params || {})}
6381
+ requiredFields:
6382
+ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
6380
6383
  }).join("\n\n");
6381
6384
  }
6382
6385
  let executedToolsText = "No external tools were executed for data fetching.";
@@ -6392,8 +6395,8 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
6392
6395
  const numericFields = fields.filter((f) => f.type === "number").map((f) => f.name);
6393
6396
  const stringFields = fields.filter((f) => f.type === "string").map((f) => f.name);
6394
6397
  fieldNamesList = `
6395
- \u{1F4CA} NUMERIC FIELDS (use for yAxisKey, valueKey, aggregationField): ${numericFields.join(", ") || "none"}
6396
- \u{1F4DD} STRING FIELDS (use for xAxisKey, groupBy, nameKey): ${stringFields.join(", ") || "none"}`;
6398
+ \u{1F4CA} NUMERIC FIELDS (use for yAxisKey, valueKey, aggregationField): ${numericFields.join(", ") || "none"}
6399
+ \u{1F4DD} STRING FIELDS (use for xAxisKey, groupBy, nameKey): ${stringFields.join(", ") || "none"}`;
6397
6400
  const fieldsText = fields.map(
6398
6401
  (f) => ` "${f.name}" (${f.type}): ${f.description}`
6399
6402
  ).join("\n");
@@ -6402,11 +6405,11 @@ ${JSON.stringify(tool.requiredFields || [], null, 2)}`;
6402
6405
  ${fieldsText}`;
6403
6406
  }
6404
6407
  return `${idx + 1}. **${tool.name}**
6405
- toolId: "${tool.id}"
6406
- toolName: "${tool.name}"
6407
- parameters: ${JSON.stringify(tool.params || {})}
6408
- recordCount: ${recordCount} rows returned
6409
- outputSchema: ${outputSchemaText}${fieldNamesList}`;
6408
+ toolId: "${tool.id}"
6409
+ toolName: "${tool.name}"
6410
+ parameters: ${JSON.stringify(tool.params || {})}
6411
+ recordCount: ${recordCount} rows returned
6412
+ outputSchema: ${outputSchemaText}${fieldNamesList}`;
6410
6413
  }).join("\n\n");
6411
6414
  }
6412
6415
  const schemaDoc = schema.generateSchemaDocumentation();
@@ -6457,6 +6460,7 @@ ${executedToolsText}`);
6457
6460
  logCollector?.info("Matching components from text response...");
6458
6461
  let fullResponseText = "";
6459
6462
  let answerComponentExtracted = false;
6463
+ let validatedAnswerComponent = null;
6460
6464
  const answerCallback = componentStreamCallback;
6461
6465
  const partialCallback = answerCallback ? (chunk) => {
6462
6466
  fullResponseText += chunk;
@@ -6515,8 +6519,8 @@ ${executedToolsText}`);
6515
6519
  }
6516
6520
  };
6517
6521
  const streamTime = (/* @__PURE__ */ new Date()).toISOString();
6518
- logger.info(`[${this.getProviderName()}] \u2713 [${streamTime}] Answer component detected in stream: ${answerComponent.name} (${answerComponent.type}) - STREAMING TO FRONTEND NOW`);
6519
- logCollector?.info(`\u2713 Answer component: ${answerComponent.name} (${answerComponent.type}) - streaming to frontend at ${streamTime}`);
6522
+ logger.info(`[${this.getProviderName()}] \u2713 [${streamTime}] Answer component detected in stream: ${answerComponent.name} (${answerComponent.type})`);
6523
+ logCollector?.info(`\u2713 Answer component: ${answerComponent.name} (${answerComponent.type}) - detected at ${streamTime}`);
6520
6524
  if (answerComponentData.props?.query) {
6521
6525
  logCollector?.logQuery(
6522
6526
  "Answer component query",
@@ -6524,7 +6528,79 @@ ${executedToolsText}`);
6524
6528
  { componentName: answerComponent.name, componentType: answerComponent.type, reasoning: answerComponentData.reasoning }
6525
6529
  );
6526
6530
  }
6527
- answerCallback(answerComponent);
6531
+ const answerQuery = answerComponent.props?.query;
6532
+ logger.info(`[${this.getProviderName()}] Answer component detected: ${answerComponent.name} (${answerComponent.type}), hasQuery: ${!!answerQuery}, hasDbExecute: ${!!collections?.["database"]?.["execute"]}`);
6533
+ if (answerQuery && collections?.["database"]?.["execute"]) {
6534
+ (async () => {
6535
+ const MAX_RETRIES = 3;
6536
+ let attempts = 0;
6537
+ let validated = false;
6538
+ let currentQuery = answerQuery;
6539
+ let currentQueryStr = typeof answerQuery === "string" ? answerQuery : answerQuery?.sql || "";
6540
+ let lastError = "";
6541
+ logger.info(`[${this.getProviderName()}] Validating answer component query before streaming...`);
6542
+ while (attempts < MAX_RETRIES && !validated) {
6543
+ attempts++;
6544
+ try {
6545
+ const cacheKey = this.getQueryCacheKey(currentQuery);
6546
+ if (cacheKey) {
6547
+ logger.debug(`[${this.getProviderName()}] Answer component query validation attempt ${attempts}/${MAX_RETRIES}`);
6548
+ const result2 = await collections["database"]["execute"]({ sql: cacheKey });
6549
+ queryCache.set(cacheKey, result2);
6550
+ validated = true;
6551
+ if (currentQuery !== answerQuery) {
6552
+ answerComponent.props.query = currentQuery;
6553
+ }
6554
+ validatedAnswerComponent = {
6555
+ componentId: answerComponentData.componentId,
6556
+ validatedQuery: currentQuery
6557
+ };
6558
+ logger.info(`[${this.getProviderName()}] \u2713 Answer component query validated (attempt ${attempts}) - STREAMING TO FRONTEND NOW`);
6559
+ logCollector?.info(`\u2713 Answer component query validated - streaming to frontend`);
6560
+ logger.info(`[${this.getProviderName()}] Calling answerCallback for: ${answerComponent.name}`);
6561
+ answerCallback(answerComponent);
6562
+ logger.info(`[${this.getProviderName()}] answerCallback completed for: ${answerComponent.name}`);
6563
+ }
6564
+ } catch (validationError) {
6565
+ lastError = validationError instanceof Error ? validationError.message : String(validationError);
6566
+ logger.warn(`[${this.getProviderName()}] Answer component query validation failed (attempt ${attempts}/${MAX_RETRIES}): ${lastError}`);
6567
+ if (attempts < MAX_RETRIES) {
6568
+ try {
6569
+ logger.info(`[${this.getProviderName()}] Requesting LLM to fix answer component query...`);
6570
+ const fixedQueryStr = await this.requestQueryFix(
6571
+ currentQueryStr,
6572
+ lastError,
6573
+ {
6574
+ name: answerComponent.name,
6575
+ type: answerComponent.type,
6576
+ title: answerComponent.props?.title
6577
+ },
6578
+ apiKey
6579
+ );
6580
+ if (typeof currentQuery === "string") {
6581
+ currentQuery = fixedQueryStr;
6582
+ } else {
6583
+ currentQuery = { ...currentQuery, sql: fixedQueryStr };
6584
+ }
6585
+ currentQueryStr = fixedQueryStr;
6586
+ logger.info(`[${this.getProviderName()}] LLM provided fixed query for answer component, retrying...`);
6587
+ } catch (fixError) {
6588
+ const fixErrorMsg = fixError instanceof Error ? fixError.message : String(fixError);
6589
+ logger.error(`[${this.getProviderName()}] Failed to get LLM query fix for answer component: ${fixErrorMsg}`);
6590
+ break;
6591
+ }
6592
+ }
6593
+ }
6594
+ }
6595
+ if (!validated) {
6596
+ logger.warn(`[${this.getProviderName()}] Answer component query validation failed after ${attempts} attempts - skipping early stream`);
6597
+ logCollector?.warn(`Answer component query validation failed: ${lastError} - will be handled in batch validation`);
6598
+ }
6599
+ })();
6600
+ } else {
6601
+ logger.info(`[${this.getProviderName()}] Answer component has no query - STREAMING TO FRONTEND NOW`);
6602
+ answerCallback(answerComponent);
6603
+ }
6528
6604
  answerComponentExtracted = true;
6529
6605
  }
6530
6606
  }
@@ -6578,6 +6654,10 @@ ${executedToolsText}`);
6578
6654
  return null;
6579
6655
  }
6580
6656
  let cleanedProps = { ...mc.props };
6657
+ if (validatedAnswerComponent && mc.componentId === validatedAnswerComponent.componentId) {
6658
+ logger.info(`[${this.getProviderName()}] Using pre-validated query for answer component: ${mc.componentId}`);
6659
+ cleanedProps.query = validatedAnswerComponent.validatedQuery;
6660
+ }
6581
6661
  if (cleanedProps.externalTool) {
6582
6662
  const toolId = cleanedProps.externalTool.toolId;
6583
6663
  const validToolIds = (executedTools || []).map((t) => t.id);
@@ -7623,11 +7703,14 @@ ${errorMsg}
7623
7703
  logger.info(`[${this.getProviderName()}] Generated ${actions.length} follow-up actions for general question`);
7624
7704
  } else if (components && components.length > 0) {
7625
7705
  logger.info(`[${this.getProviderName()}] Matching components from text response...`);
7706
+ logger.info(`[${this.getProviderName()}] componentStreamCallback setup: wrappedStreamCallback=${!!wrappedStreamCallback}, category=${category}`);
7626
7707
  const componentStreamCallback = wrappedStreamCallback && category !== "data_modification" ? (component) => {
7708
+ logger.info(`[${this.getProviderName()}] componentStreamCallback INVOKED for: ${component.name} (${component.type})`);
7627
7709
  const answerMarker = `__ANSWER_COMPONENT_START__${JSON.stringify(component)}__ANSWER_COMPONENT_END__`;
7628
7710
  wrappedStreamCallback(answerMarker);
7629
7711
  logger.info(`[${this.getProviderName()}] Streamed answer component to frontend: ${component.name} (${component.type})`);
7630
7712
  } : void 0;
7713
+ logger.info(`[${this.getProviderName()}] componentStreamCallback created: ${!!componentStreamCallback}`);
7631
7714
  const deferredTools = externalTools?.filter((t) => {
7632
7715
  if (t.executionType === "deferred" && !t.userProvidedData) return true;
7633
7716
  if (category === "data_modification" && !t.userProvidedData) {
@@ -10995,30 +11078,25 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
10995
11078
  const name = requestData?.name;
10996
11079
  const createdBy = requestData?.createdBy;
10997
11080
  const dsl = requestData?.dsl;
11081
+ const type = requestData?.type;
11082
+ const filters = requestData?.filters;
10998
11083
  const status = requestData?.status;
10999
11084
  const deleted = requestData?.deleted;
11000
11085
  const limit = requestData?.limit;
11001
- const filters = requestData?.filters;
11086
+ const offset = requestData?.offset;
11002
11087
  const sort = requestData?.sort;
11003
- const type = requestData?.type;
11004
- const menuId = requestData?.menuId;
11005
- const artifactGroupName = requestData?.artifactGroupName;
11006
- const artifactGroupId = requestData?.artifactGroupId;
11007
- const artifactGroupIcon = requestData?.artifactGroupIcon;
11008
- logger.info("[SDK-NODEJS] Extracted params for create:", JSON.stringify({
11088
+ logger.info("[SDK-NODEJS] Extracted params:", JSON.stringify({
11009
11089
  name,
11010
11090
  type,
11011
- menuId,
11012
- artifactGroupName,
11013
- artifactGroupId,
11014
- artifactGroupIcon
11091
+ filters: filters ? "present" : "undefined"
11015
11092
  }, null, 2));
11093
+ logger.info("[SDK-NODEJS] Full requestData.filters:", JSON.stringify(filters, null, 2));
11016
11094
  switch (operation) {
11017
11095
  case "create":
11018
- await handleCreate6(id, name, createdBy, dsl, status, type, menuId, artifactGroupName, artifactGroupId, artifactGroupIcon, executeCollection, sendMessage, from.id);
11096
+ await handleCreate6(id, name, createdBy, dsl, type, filters, status, executeCollection, sendMessage, from.id);
11019
11097
  break;
11020
11098
  case "update":
11021
- await handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, from.id);
11099
+ await handleUpdate6(id, artifactId, name, dsl, type, filters, status, deleted, executeCollection, sendMessage, from.id);
11022
11100
  break;
11023
11101
  case "delete":
11024
11102
  await handleDelete6(id, artifactId, executeCollection, sendMessage, from.id);
@@ -11030,7 +11108,7 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
11030
11108
  await handleGetOne6(id, artifactId, executeCollection, sendMessage, from.id);
11031
11109
  break;
11032
11110
  case "query":
11033
- await handleQuery6(id, { filters, limit, sort }, executeCollection, sendMessage, from.id);
11111
+ await handleQuery6(id, { filters, limit, offset, sort }, executeCollection, sendMessage, from.id);
11034
11112
  break;
11035
11113
  default:
11036
11114
  sendResponse8(id, {
@@ -11046,7 +11124,7 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
11046
11124
  }, sendMessage);
11047
11125
  }
11048
11126
  }
11049
- async function handleCreate6(id, name, createdBy, dsl, status, type, menuId, artifactGroupName, artifactGroupId, artifactGroupIcon, executeCollection, sendMessage, clientId) {
11127
+ async function handleCreate6(id, name, createdBy, dsl, type, filters, status, executeCollection, sendMessage, clientId) {
11050
11128
  if (!name) {
11051
11129
  sendResponse8(id, {
11052
11130
  success: false,
@@ -11059,12 +11137,9 @@ async function handleCreate6(id, name, createdBy, dsl, status, type, menuId, art
11059
11137
  name,
11060
11138
  createdBy,
11061
11139
  dsl,
11062
- status,
11063
11140
  type,
11064
- menuId,
11065
- artifactGroupName,
11066
- artifactGroupId,
11067
- artifactGroupIcon
11141
+ filters,
11142
+ status
11068
11143
  });
11069
11144
  sendResponse8(id, {
11070
11145
  success: true,
@@ -11079,7 +11154,7 @@ async function handleCreate6(id, name, createdBy, dsl, status, type, menuId, art
11079
11154
  }, sendMessage, clientId);
11080
11155
  }
11081
11156
  }
11082
- async function handleUpdate6(id, artifactId, name, dsl, status, deleted, executeCollection, sendMessage, clientId) {
11157
+ async function handleUpdate6(id, artifactId, name, dsl, type, filters, status, deleted, executeCollection, sendMessage, clientId) {
11083
11158
  if (!artifactId) {
11084
11159
  sendResponse8(id, {
11085
11160
  success: false,
@@ -11088,7 +11163,7 @@ async function handleUpdate6(id, artifactId, name, dsl, status, deleted, execute
11088
11163
  return;
11089
11164
  }
11090
11165
  try {
11091
- const result = await executeCollection("artifacts", "update", { id: artifactId, name, dsl, status, deleted });
11166
+ const result = await executeCollection("artifacts", "update", { id: artifactId, name, dsl, type, filters, status, deleted });
11092
11167
  sendResponse8(id, {
11093
11168
  success: true,
11094
11169
  data: result.data,
@@ -11167,11 +11242,15 @@ async function handleGetOne6(id, artifactId, executeCollection, sendMessage, cli
11167
11242
  }
11168
11243
  async function handleQuery6(id, queryParams, executeCollection, sendMessage, clientId) {
11169
11244
  try {
11245
+ logger.info("[SDK-NODEJS] handleQuery - queryParams:", JSON.stringify(queryParams, null, 2));
11246
+ logger.info("[SDK-NODEJS] handleQuery - filters.type:", queryParams.filters?.type);
11170
11247
  const result = await executeCollection("artifacts", "query", {
11171
11248
  filters: queryParams.filters,
11172
11249
  limit: queryParams.limit || 50,
11250
+ offset: queryParams.offset || 0,
11173
11251
  sort: queryParams.sort || "DESC"
11174
11252
  });
11253
+ logger.info("[SDK-NODEJS] handleQuery - executeCollection result count:", result.count);
11175
11254
  sendResponse8(id, {
11176
11255
  success: true,
11177
11256
  data: result.data,