@superatomai/sdk-node 0.0.57 → 0.0.58

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.js CHANGED
@@ -2409,8 +2409,14 @@ var BookmarksRequestMessageSchema = import_zod3.z.object({
2409
2409
  type: import_zod3.z.literal("BOOKMARKS"),
2410
2410
  payload: BookmarksRequestPayloadSchema
2411
2411
  });
2412
+ var ArtifactsQueryFiltersSchema = import_zod3.z.object({
2413
+ createdBy: import_zod3.z.number().optional(),
2414
+ status: import_zod3.z.string().optional(),
2415
+ name: import_zod3.z.string().optional(),
2416
+ deleted: import_zod3.z.boolean().optional()
2417
+ });
2412
2418
  var ArtifactsRequestPayloadSchema = import_zod3.z.object({
2413
- operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne"]),
2419
+ operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
2414
2420
  data: import_zod3.z.object({
2415
2421
  id: import_zod3.z.number().optional(),
2416
2422
  name: import_zod3.z.string().optional(),
@@ -2418,7 +2424,10 @@ var ArtifactsRequestPayloadSchema = import_zod3.z.object({
2418
2424
  dsl: import_zod3.z.record(import_zod3.z.any()).optional(),
2419
2425
  status: import_zod3.z.string().optional(),
2420
2426
  deleted: import_zod3.z.boolean().optional(),
2421
- limit: import_zod3.z.number().optional()
2427
+ limit: import_zod3.z.number().optional(),
2428
+ // Query operation fields
2429
+ filters: ArtifactsQueryFiltersSchema.optional(),
2430
+ sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
2422
2431
  }).optional()
2423
2432
  });
2424
2433
  var ArtifactsRequestMessageSchema = import_zod3.z.object({
@@ -5947,6 +5956,9 @@ var BaseLLM = class {
5947
5956
  * @returns Object containing matched components, layout title/description, and follow-up actions
5948
5957
  */
5949
5958
  async matchComponentsFromAnalysis(analysisContent, components, apiKey, logCollector, componentStreamCallback, deferredTools, executedTools) {
5959
+ const methodStartTime = Date.now();
5960
+ const methodName = "matchComponentsFromAnalysis";
5961
+ logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")}`);
5950
5962
  try {
5951
5963
  logger.debug(`[${this.getProviderName()}] Starting component matching from text response`);
5952
5964
  let availableComponentsText = "No components available";
@@ -6253,6 +6265,8 @@ ${executedToolsText}`);
6253
6265
  }
6254
6266
  };
6255
6267
  }).filter(Boolean);
6268
+ const methodDuration = Date.now() - methodStartTime;
6269
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | components: ${finalComponents.length} | actions: ${actions.length}`);
6256
6270
  return {
6257
6271
  components: finalComponents,
6258
6272
  layoutTitle,
@@ -6260,8 +6274,9 @@ ${executedToolsText}`);
6260
6274
  actions
6261
6275
  };
6262
6276
  } catch (error) {
6277
+ const methodDuration = Date.now() - methodStartTime;
6263
6278
  const errorMsg = error instanceof Error ? error.message : String(error);
6264
- logger.error(`[${this.getProviderName()}] Error matching components: ${errorMsg}`);
6279
+ logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
6265
6280
  logCollector?.error(`Failed to match components: ${errorMsg}`);
6266
6281
  return {
6267
6282
  components: [],
@@ -6276,6 +6291,10 @@ ${executedToolsText}`);
6276
6291
  * Determines if question is for data analysis, requires external tools, or needs text response
6277
6292
  */
6278
6293
  async classifyQuestionCategory(userPrompt, apiKey, logCollector, conversationHistory, externalTools) {
6294
+ const methodStartTime = Date.now();
6295
+ const methodName = "classifyQuestionCategory";
6296
+ const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
6297
+ logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
6279
6298
  try {
6280
6299
  const schemaDoc = schema.generateSchemaDocumentation();
6281
6300
  const availableToolsDoc = externalTools && externalTools.length > 0 ? externalTools.map((tool) => {
@@ -6319,6 +6338,8 @@ ${executedToolsText}`);
6319
6338
  confidence: result.confidence
6320
6339
  }
6321
6340
  );
6341
+ const methodDuration = Date.now() - methodStartTime;
6342
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | category: ${result.category} | confidence: ${result.confidence}% | tools: ${(result.externalTools || []).length}`);
6322
6343
  return {
6323
6344
  category: result.category || "data_analysis",
6324
6345
  externalTools: result.externalTools || [],
@@ -6327,8 +6348,9 @@ ${executedToolsText}`);
6327
6348
  confidence: result.confidence || 0
6328
6349
  };
6329
6350
  } catch (error) {
6351
+ const methodDuration = Date.now() - methodStartTime;
6330
6352
  const errorMsg = error instanceof Error ? error.message : String(error);
6331
- logger.error(`[${this.getProviderName()}] Error classifying question category: ${errorMsg}`);
6353
+ logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
6332
6354
  logger.debug(`[${this.getProviderName()}] Category classification error details:`, error);
6333
6355
  throw error;
6334
6356
  }
@@ -6339,9 +6361,15 @@ ${executedToolsText}`);
6339
6361
  * Also adapts the cached text response to match the new question
6340
6362
  */
6341
6363
  async adaptUIBlockParameters(currentUserPrompt, originalUserPrompt, matchedUIBlock, apiKey, logCollector, cachedTextResponse) {
6364
+ const methodStartTime = Date.now();
6365
+ const methodName = "adaptUIBlockParameters";
6366
+ const promptPreview = currentUserPrompt.substring(0, 50) + (currentUserPrompt.length > 50 ? "..." : "");
6367
+ logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | prompt: "${promptPreview}"`);
6342
6368
  try {
6343
6369
  const component = matchedUIBlock?.generatedComponentMetadata || matchedUIBlock?.component;
6344
6370
  if (!matchedUIBlock || !component) {
6371
+ const methodDuration2 = Date.now() - methodStartTime;
6372
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: no component found`);
6345
6373
  return {
6346
6374
  success: false,
6347
6375
  explanation: "No component found in matched UI block"
@@ -6374,9 +6402,8 @@ ${executedToolsText}`);
6374
6402
  // Parse as JSON
6375
6403
  );
6376
6404
  if (!result.success) {
6377
- logger.info(
6378
- `[${this.getProviderName()}] Could not adapt UI block: ${result.reason}`
6379
- );
6405
+ const methodDuration2 = Date.now() - methodStartTime;
6406
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: adaptation failed - ${result.reason}`);
6380
6407
  logCollector?.warn(
6381
6408
  "Could not adapt matched UI block",
6382
6409
  "explanation",
@@ -6401,6 +6428,8 @@ ${executedToolsText}`);
6401
6428
  componentType: result.adaptedComponent?.type
6402
6429
  }
6403
6430
  );
6431
+ const methodDuration = Date.now() - methodStartTime;
6432
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | changes: ${(result.parametersChanged || []).length}`);
6404
6433
  return {
6405
6434
  success: true,
6406
6435
  adaptedComponent: result.adaptedComponent,
@@ -6409,8 +6438,9 @@ ${executedToolsText}`);
6409
6438
  explanation: result.explanation || "Parameters adapted successfully"
6410
6439
  };
6411
6440
  } catch (error) {
6441
+ const methodDuration = Date.now() - methodStartTime;
6412
6442
  const errorMsg = error instanceof Error ? error.message : String(error);
6413
- logger.error(`[${this.getProviderName()}] Error adapting UI block parameters: ${errorMsg}`);
6443
+ logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
6414
6444
  logger.debug(`[${this.getProviderName()}] Adaptation error details:`, error);
6415
6445
  return {
6416
6446
  success: false,
@@ -6431,6 +6461,10 @@ ${executedToolsText}`);
6431
6461
  * @param userId - Optional user ID for fetching user-specific knowledge base nodes
6432
6462
  */
6433
6463
  async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category, userId) {
6464
+ const methodStartTime = Date.now();
6465
+ const methodName = "generateTextResponse";
6466
+ const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
6467
+ logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | category: ${category} | prompt: "${promptPreview}"`);
6434
6468
  const errors = [];
6435
6469
  logger.debug(`[${this.getProviderName()}] Starting text response generation`);
6436
6470
  logger.debug(`[${this.getProviderName()}] User prompt: "${userPrompt.substring(0, 50)}..."`);
@@ -6944,7 +6978,8 @@ ${errorMsg}
6944
6978
  logger.info(`[${this.getProviderName()}] Text response stream completed`);
6945
6979
  const textResponse = fullStreamedText || result || "I apologize, but I was unable to generate a response.";
6946
6980
  if (maxAttemptsReached) {
6947
- logger.warn(`[${this.getProviderName()}] Max query attempts reached, returning failure response`);
6981
+ const methodDuration2 = Date.now() - methodStartTime;
6982
+ logger.warn(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: max attempts reached`);
6948
6983
  logCollector?.error("Failed to generate valid query after maximum attempts");
6949
6984
  return {
6950
6985
  success: false,
@@ -7047,6 +7082,8 @@ ${errorMsg}
7047
7082
  }
7048
7083
  };
7049
7084
  }
7085
+ const methodDuration = Date.now() - methodStartTime;
7086
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | components: ${matchedComponents.length} | actions: ${actions.length}`);
7050
7087
  return {
7051
7088
  success: true,
7052
7089
  data: {
@@ -7058,8 +7095,9 @@ ${errorMsg}
7058
7095
  errors: []
7059
7096
  };
7060
7097
  } catch (error) {
7098
+ const methodDuration = Date.now() - methodStartTime;
7061
7099
  const errorMsg = error instanceof Error ? error.message : String(error);
7062
- logger.error(`[${this.getProviderName()}] Error generating text response: ${errorMsg}`);
7100
+ logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
7063
7101
  logCollector?.error(`Error generating text response: ${errorMsg}`);
7064
7102
  userPromptErrorLogger.logLlmError(
7065
7103
  this.getProviderName(),
@@ -7313,6 +7351,10 @@ ${errorMsg}
7313
7351
  * For general/conversational questions without components, pass textResponse instead
7314
7352
  */
7315
7353
  async generateNextQuestions(originalUserPrompt, component, componentData, apiKey, logCollector, conversationHistory, textResponse) {
7354
+ const methodStartTime = Date.now();
7355
+ const methodName = "generateNextQuestions";
7356
+ const promptPreview = originalUserPrompt.substring(0, 50) + (originalUserPrompt.length > 50 ? "..." : "");
7357
+ logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
7316
7358
  try {
7317
7359
  let component_info;
7318
7360
  if (component) {
@@ -7361,10 +7403,13 @@ ${errorMsg}
7361
7403
  questions: nextQuestions
7362
7404
  }
7363
7405
  );
7406
+ const methodDuration = Date.now() - methodStartTime;
7407
+ logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | questions: ${nextQuestions.length}`);
7364
7408
  return nextQuestions;
7365
7409
  } catch (error) {
7410
+ const methodDuration = Date.now() - methodStartTime;
7366
7411
  const errorMsg = error instanceof Error ? error.message : String(error);
7367
- logger.error(`[${this.getProviderName()}] Error generating next questions: ${errorMsg}`);
7412
+ logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
7368
7413
  logger.debug(`[${this.getProviderName()}] Next questions generation error details:`, error);
7369
7414
  logCollector?.error(`Error generating next questions: ${errorMsg}`);
7370
7415
  return [];
@@ -10372,6 +10417,8 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
10372
10417
  const status = requestData?.status;
10373
10418
  const deleted = requestData?.deleted;
10374
10419
  const limit = requestData?.limit;
10420
+ const filters = requestData?.filters;
10421
+ const sort = requestData?.sort;
10375
10422
  switch (operation) {
10376
10423
  case "create":
10377
10424
  await handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, from.id);
@@ -10388,6 +10435,9 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
10388
10435
  case "getOne":
10389
10436
  await handleGetOne6(id, artifactId, executeCollection, sendMessage, from.id);
10390
10437
  break;
10438
+ case "query":
10439
+ await handleQuery6(id, { filters, limit, sort }, executeCollection, sendMessage, from.id);
10440
+ break;
10391
10441
  default:
10392
10442
  sendResponse8(id, {
10393
10443
  success: false,
@@ -10511,6 +10561,27 @@ async function handleGetOne6(id, artifactId, executeCollection, sendMessage, cli
10511
10561
  }, sendMessage, clientId);
10512
10562
  }
10513
10563
  }
10564
+ async function handleQuery6(id, queryParams, executeCollection, sendMessage, clientId) {
10565
+ try {
10566
+ const result = await executeCollection("artifacts", "query", {
10567
+ filters: queryParams.filters,
10568
+ limit: queryParams.limit || 50,
10569
+ sort: queryParams.sort || "DESC"
10570
+ });
10571
+ sendResponse8(id, {
10572
+ success: true,
10573
+ data: result.data,
10574
+ count: result.count,
10575
+ message: `Query returned ${result.count} artifacts`
10576
+ }, sendMessage, clientId);
10577
+ logger.info(`Query artifacts (count: ${result.count})`);
10578
+ } catch (error) {
10579
+ sendResponse8(id, {
10580
+ success: false,
10581
+ error: error instanceof Error ? error.message : "Failed to query artifacts"
10582
+ }, sendMessage, clientId);
10583
+ }
10584
+ }
10514
10585
  function sendResponse8(id, res, sendMessage, clientId) {
10515
10586
  const response = {
10516
10587
  id: id || "unknown",
@@ -11037,7 +11108,7 @@ async function handleMenusRequest(data, collections, sendMessage) {
11037
11108
  await handleGetHierarchy(id, executeCollection, sendMessage, from.id);
11038
11109
  break;
11039
11110
  case "query":
11040
- await handleQuery6(id, filters, limit, sort, executeCollection, sendMessage, from.id);
11111
+ await handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, from.id);
11041
11112
  break;
11042
11113
  case "reorder":
11043
11114
  await handleReorder(id, items, executeCollection, sendMessage, from.id);
@@ -11249,7 +11320,7 @@ async function handleGetHierarchy(id, executeCollection, sendMessage, clientId)
11249
11320
  }, sendMessage, clientId);
11250
11321
  }
11251
11322
  }
11252
- async function handleQuery6(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
11323
+ async function handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
11253
11324
  try {
11254
11325
  const result = await executeCollection("menus", "query", {
11255
11326
  filters: filters || {},