@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/README.md +942 -942
- package/dist/index.js +84 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2359,8 +2359,14 @@ var BookmarksRequestMessageSchema = z3.object({
|
|
|
2359
2359
|
type: z3.literal("BOOKMARKS"),
|
|
2360
2360
|
payload: BookmarksRequestPayloadSchema
|
|
2361
2361
|
});
|
|
2362
|
+
var ArtifactsQueryFiltersSchema = z3.object({
|
|
2363
|
+
createdBy: z3.number().optional(),
|
|
2364
|
+
status: z3.string().optional(),
|
|
2365
|
+
name: z3.string().optional(),
|
|
2366
|
+
deleted: z3.boolean().optional()
|
|
2367
|
+
});
|
|
2362
2368
|
var ArtifactsRequestPayloadSchema = z3.object({
|
|
2363
|
-
operation: z3.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
2369
|
+
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
2364
2370
|
data: z3.object({
|
|
2365
2371
|
id: z3.number().optional(),
|
|
2366
2372
|
name: z3.string().optional(),
|
|
@@ -2368,7 +2374,10 @@ var ArtifactsRequestPayloadSchema = z3.object({
|
|
|
2368
2374
|
dsl: z3.record(z3.any()).optional(),
|
|
2369
2375
|
status: z3.string().optional(),
|
|
2370
2376
|
deleted: z3.boolean().optional(),
|
|
2371
|
-
limit: z3.number().optional()
|
|
2377
|
+
limit: z3.number().optional(),
|
|
2378
|
+
// Query operation fields
|
|
2379
|
+
filters: ArtifactsQueryFiltersSchema.optional(),
|
|
2380
|
+
sort: z3.enum(["ASC", "DESC"]).optional()
|
|
2372
2381
|
}).optional()
|
|
2373
2382
|
});
|
|
2374
2383
|
var ArtifactsRequestMessageSchema = z3.object({
|
|
@@ -5897,6 +5906,9 @@ var BaseLLM = class {
|
|
|
5897
5906
|
* @returns Object containing matched components, layout title/description, and follow-up actions
|
|
5898
5907
|
*/
|
|
5899
5908
|
async matchComponentsFromAnalysis(analysisContent, components, apiKey, logCollector, componentStreamCallback, deferredTools, executedTools) {
|
|
5909
|
+
const methodStartTime = Date.now();
|
|
5910
|
+
const methodName = "matchComponentsFromAnalysis";
|
|
5911
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")}`);
|
|
5900
5912
|
try {
|
|
5901
5913
|
logger.debug(`[${this.getProviderName()}] Starting component matching from text response`);
|
|
5902
5914
|
let availableComponentsText = "No components available";
|
|
@@ -6203,6 +6215,8 @@ ${executedToolsText}`);
|
|
|
6203
6215
|
}
|
|
6204
6216
|
};
|
|
6205
6217
|
}).filter(Boolean);
|
|
6218
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6219
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | components: ${finalComponents.length} | actions: ${actions.length}`);
|
|
6206
6220
|
return {
|
|
6207
6221
|
components: finalComponents,
|
|
6208
6222
|
layoutTitle,
|
|
@@ -6210,8 +6224,9 @@ ${executedToolsText}`);
|
|
|
6210
6224
|
actions
|
|
6211
6225
|
};
|
|
6212
6226
|
} catch (error) {
|
|
6227
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6213
6228
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6214
|
-
logger.error(`[${this.getProviderName()}]
|
|
6229
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6215
6230
|
logCollector?.error(`Failed to match components: ${errorMsg}`);
|
|
6216
6231
|
return {
|
|
6217
6232
|
components: [],
|
|
@@ -6226,6 +6241,10 @@ ${executedToolsText}`);
|
|
|
6226
6241
|
* Determines if question is for data analysis, requires external tools, or needs text response
|
|
6227
6242
|
*/
|
|
6228
6243
|
async classifyQuestionCategory(userPrompt, apiKey, logCollector, conversationHistory, externalTools) {
|
|
6244
|
+
const methodStartTime = Date.now();
|
|
6245
|
+
const methodName = "classifyQuestionCategory";
|
|
6246
|
+
const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
|
|
6247
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
|
|
6229
6248
|
try {
|
|
6230
6249
|
const schemaDoc = schema.generateSchemaDocumentation();
|
|
6231
6250
|
const availableToolsDoc = externalTools && externalTools.length > 0 ? externalTools.map((tool) => {
|
|
@@ -6269,6 +6288,8 @@ ${executedToolsText}`);
|
|
|
6269
6288
|
confidence: result.confidence
|
|
6270
6289
|
}
|
|
6271
6290
|
);
|
|
6291
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6292
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | category: ${result.category} | confidence: ${result.confidence}% | tools: ${(result.externalTools || []).length}`);
|
|
6272
6293
|
return {
|
|
6273
6294
|
category: result.category || "data_analysis",
|
|
6274
6295
|
externalTools: result.externalTools || [],
|
|
@@ -6277,8 +6298,9 @@ ${executedToolsText}`);
|
|
|
6277
6298
|
confidence: result.confidence || 0
|
|
6278
6299
|
};
|
|
6279
6300
|
} catch (error) {
|
|
6301
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6280
6302
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6281
|
-
logger.error(`[${this.getProviderName()}]
|
|
6303
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6282
6304
|
logger.debug(`[${this.getProviderName()}] Category classification error details:`, error);
|
|
6283
6305
|
throw error;
|
|
6284
6306
|
}
|
|
@@ -6289,9 +6311,15 @@ ${executedToolsText}`);
|
|
|
6289
6311
|
* Also adapts the cached text response to match the new question
|
|
6290
6312
|
*/
|
|
6291
6313
|
async adaptUIBlockParameters(currentUserPrompt, originalUserPrompt, matchedUIBlock, apiKey, logCollector, cachedTextResponse) {
|
|
6314
|
+
const methodStartTime = Date.now();
|
|
6315
|
+
const methodName = "adaptUIBlockParameters";
|
|
6316
|
+
const promptPreview = currentUserPrompt.substring(0, 50) + (currentUserPrompt.length > 50 ? "..." : "");
|
|
6317
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | prompt: "${promptPreview}"`);
|
|
6292
6318
|
try {
|
|
6293
6319
|
const component = matchedUIBlock?.generatedComponentMetadata || matchedUIBlock?.component;
|
|
6294
6320
|
if (!matchedUIBlock || !component) {
|
|
6321
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6322
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: no component found`);
|
|
6295
6323
|
return {
|
|
6296
6324
|
success: false,
|
|
6297
6325
|
explanation: "No component found in matched UI block"
|
|
@@ -6324,9 +6352,8 @@ ${executedToolsText}`);
|
|
|
6324
6352
|
// Parse as JSON
|
|
6325
6353
|
);
|
|
6326
6354
|
if (!result.success) {
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
);
|
|
6355
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6356
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: adaptation failed - ${result.reason}`);
|
|
6330
6357
|
logCollector?.warn(
|
|
6331
6358
|
"Could not adapt matched UI block",
|
|
6332
6359
|
"explanation",
|
|
@@ -6351,6 +6378,8 @@ ${executedToolsText}`);
|
|
|
6351
6378
|
componentType: result.adaptedComponent?.type
|
|
6352
6379
|
}
|
|
6353
6380
|
);
|
|
6381
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6382
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | changes: ${(result.parametersChanged || []).length}`);
|
|
6354
6383
|
return {
|
|
6355
6384
|
success: true,
|
|
6356
6385
|
adaptedComponent: result.adaptedComponent,
|
|
@@ -6359,8 +6388,9 @@ ${executedToolsText}`);
|
|
|
6359
6388
|
explanation: result.explanation || "Parameters adapted successfully"
|
|
6360
6389
|
};
|
|
6361
6390
|
} catch (error) {
|
|
6391
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
6362
6392
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
6363
|
-
logger.error(`[${this.getProviderName()}]
|
|
6393
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
6364
6394
|
logger.debug(`[${this.getProviderName()}] Adaptation error details:`, error);
|
|
6365
6395
|
return {
|
|
6366
6396
|
success: false,
|
|
@@ -6381,6 +6411,10 @@ ${executedToolsText}`);
|
|
|
6381
6411
|
* @param userId - Optional user ID for fetching user-specific knowledge base nodes
|
|
6382
6412
|
*/
|
|
6383
6413
|
async generateTextResponse(userPrompt, apiKey, logCollector, conversationHistory, streamCallback, collections, components, externalTools, category, userId) {
|
|
6414
|
+
const methodStartTime = Date.now();
|
|
6415
|
+
const methodName = "generateTextResponse";
|
|
6416
|
+
const promptPreview = userPrompt.substring(0, 50) + (userPrompt.length > 50 ? "..." : "");
|
|
6417
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("complex")} | category: ${category} | prompt: "${promptPreview}"`);
|
|
6384
6418
|
const errors = [];
|
|
6385
6419
|
logger.debug(`[${this.getProviderName()}] Starting text response generation`);
|
|
6386
6420
|
logger.debug(`[${this.getProviderName()}] User prompt: "${userPrompt.substring(0, 50)}..."`);
|
|
@@ -6894,7 +6928,8 @@ ${errorMsg}
|
|
|
6894
6928
|
logger.info(`[${this.getProviderName()}] Text response stream completed`);
|
|
6895
6929
|
const textResponse = fullStreamedText || result || "I apologize, but I was unable to generate a response.";
|
|
6896
6930
|
if (maxAttemptsReached) {
|
|
6897
|
-
|
|
6931
|
+
const methodDuration2 = Date.now() - methodStartTime;
|
|
6932
|
+
logger.warn(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration2}ms | result: max attempts reached`);
|
|
6898
6933
|
logCollector?.error("Failed to generate valid query after maximum attempts");
|
|
6899
6934
|
return {
|
|
6900
6935
|
success: false,
|
|
@@ -6997,6 +7032,8 @@ ${errorMsg}
|
|
|
6997
7032
|
}
|
|
6998
7033
|
};
|
|
6999
7034
|
}
|
|
7035
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7036
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | result: success | components: ${matchedComponents.length} | actions: ${actions.length}`);
|
|
7000
7037
|
return {
|
|
7001
7038
|
success: true,
|
|
7002
7039
|
data: {
|
|
@@ -7008,8 +7045,9 @@ ${errorMsg}
|
|
|
7008
7045
|
errors: []
|
|
7009
7046
|
};
|
|
7010
7047
|
} catch (error) {
|
|
7048
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7011
7049
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
7012
|
-
logger.error(`[${this.getProviderName()}]
|
|
7050
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
7013
7051
|
logCollector?.error(`Error generating text response: ${errorMsg}`);
|
|
7014
7052
|
userPromptErrorLogger.logLlmError(
|
|
7015
7053
|
this.getProviderName(),
|
|
@@ -7263,6 +7301,10 @@ ${errorMsg}
|
|
|
7263
7301
|
* For general/conversational questions without components, pass textResponse instead
|
|
7264
7302
|
*/
|
|
7265
7303
|
async generateNextQuestions(originalUserPrompt, component, componentData, apiKey, logCollector, conversationHistory, textResponse) {
|
|
7304
|
+
const methodStartTime = Date.now();
|
|
7305
|
+
const methodName = "generateNextQuestions";
|
|
7306
|
+
const promptPreview = originalUserPrompt.substring(0, 50) + (originalUserPrompt.length > 50 ? "..." : "");
|
|
7307
|
+
logger.info(`[${this.getProviderName()}] [TIMING] START ${methodName} | model: ${this.getModelForTask("simple")} | prompt: "${promptPreview}"`);
|
|
7266
7308
|
try {
|
|
7267
7309
|
let component_info;
|
|
7268
7310
|
if (component) {
|
|
@@ -7311,10 +7353,13 @@ ${errorMsg}
|
|
|
7311
7353
|
questions: nextQuestions
|
|
7312
7354
|
}
|
|
7313
7355
|
);
|
|
7356
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7357
|
+
logger.info(`[${this.getProviderName()}] [TIMING] DONE ${methodName} in ${methodDuration}ms | questions: ${nextQuestions.length}`);
|
|
7314
7358
|
return nextQuestions;
|
|
7315
7359
|
} catch (error) {
|
|
7360
|
+
const methodDuration = Date.now() - methodStartTime;
|
|
7316
7361
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
7317
|
-
logger.error(`[${this.getProviderName()}]
|
|
7362
|
+
logger.error(`[${this.getProviderName()}] [TIMING] FAILED ${methodName} in ${methodDuration}ms | error: ${errorMsg}`);
|
|
7318
7363
|
logger.debug(`[${this.getProviderName()}] Next questions generation error details:`, error);
|
|
7319
7364
|
logCollector?.error(`Error generating next questions: ${errorMsg}`);
|
|
7320
7365
|
return [];
|
|
@@ -10322,6 +10367,8 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
|
|
|
10322
10367
|
const status = requestData?.status;
|
|
10323
10368
|
const deleted = requestData?.deleted;
|
|
10324
10369
|
const limit = requestData?.limit;
|
|
10370
|
+
const filters = requestData?.filters;
|
|
10371
|
+
const sort = requestData?.sort;
|
|
10325
10372
|
switch (operation) {
|
|
10326
10373
|
case "create":
|
|
10327
10374
|
await handleCreate6(id, name, createdBy, dsl, status, executeCollection, sendMessage, from.id);
|
|
@@ -10338,6 +10385,9 @@ async function handleArtifactsRequest(data, collections, sendMessage) {
|
|
|
10338
10385
|
case "getOne":
|
|
10339
10386
|
await handleGetOne6(id, artifactId, executeCollection, sendMessage, from.id);
|
|
10340
10387
|
break;
|
|
10388
|
+
case "query":
|
|
10389
|
+
await handleQuery6(id, { filters, limit, sort }, executeCollection, sendMessage, from.id);
|
|
10390
|
+
break;
|
|
10341
10391
|
default:
|
|
10342
10392
|
sendResponse8(id, {
|
|
10343
10393
|
success: false,
|
|
@@ -10461,6 +10511,27 @@ async function handleGetOne6(id, artifactId, executeCollection, sendMessage, cli
|
|
|
10461
10511
|
}, sendMessage, clientId);
|
|
10462
10512
|
}
|
|
10463
10513
|
}
|
|
10514
|
+
async function handleQuery6(id, queryParams, executeCollection, sendMessage, clientId) {
|
|
10515
|
+
try {
|
|
10516
|
+
const result = await executeCollection("artifacts", "query", {
|
|
10517
|
+
filters: queryParams.filters,
|
|
10518
|
+
limit: queryParams.limit || 50,
|
|
10519
|
+
sort: queryParams.sort || "DESC"
|
|
10520
|
+
});
|
|
10521
|
+
sendResponse8(id, {
|
|
10522
|
+
success: true,
|
|
10523
|
+
data: result.data,
|
|
10524
|
+
count: result.count,
|
|
10525
|
+
message: `Query returned ${result.count} artifacts`
|
|
10526
|
+
}, sendMessage, clientId);
|
|
10527
|
+
logger.info(`Query artifacts (count: ${result.count})`);
|
|
10528
|
+
} catch (error) {
|
|
10529
|
+
sendResponse8(id, {
|
|
10530
|
+
success: false,
|
|
10531
|
+
error: error instanceof Error ? error.message : "Failed to query artifacts"
|
|
10532
|
+
}, sendMessage, clientId);
|
|
10533
|
+
}
|
|
10534
|
+
}
|
|
10464
10535
|
function sendResponse8(id, res, sendMessage, clientId) {
|
|
10465
10536
|
const response = {
|
|
10466
10537
|
id: id || "unknown",
|
|
@@ -10987,7 +11058,7 @@ async function handleMenusRequest(data, collections, sendMessage) {
|
|
|
10987
11058
|
await handleGetHierarchy(id, executeCollection, sendMessage, from.id);
|
|
10988
11059
|
break;
|
|
10989
11060
|
case "query":
|
|
10990
|
-
await
|
|
11061
|
+
await handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
10991
11062
|
break;
|
|
10992
11063
|
case "reorder":
|
|
10993
11064
|
await handleReorder(id, items, executeCollection, sendMessage, from.id);
|
|
@@ -11199,7 +11270,7 @@ async function handleGetHierarchy(id, executeCollection, sendMessage, clientId)
|
|
|
11199
11270
|
}, sendMessage, clientId);
|
|
11200
11271
|
}
|
|
11201
11272
|
}
|
|
11202
|
-
async function
|
|
11273
|
+
async function handleQuery7(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
11203
11274
|
try {
|
|
11204
11275
|
const result = await executeCollection("menus", "query", {
|
|
11205
11276
|
filters: filters || {},
|