@superatomai/sdk-node 0.0.3-mds → 0.0.4-mds
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 +69 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -345,7 +345,8 @@ var UserQueryFiltersSchema = z3.object({
|
|
|
345
345
|
username: z3.string().optional(),
|
|
346
346
|
email: z3.string().optional(),
|
|
347
347
|
role: z3.string().optional(),
|
|
348
|
-
fullname: z3.string().optional()
|
|
348
|
+
fullname: z3.string().optional(),
|
|
349
|
+
id: z3.number().optional()
|
|
349
350
|
});
|
|
350
351
|
var UsersRequestPayloadSchema = z3.object({
|
|
351
352
|
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
@@ -8316,9 +8317,9 @@ ${executedToolsText}`);
|
|
|
8316
8317
|
const rawActions = result.actions || [];
|
|
8317
8318
|
const actions = convertQuestionsToActions(rawActions);
|
|
8318
8319
|
const finalComponents = matchedComponents.map((mc) => {
|
|
8319
|
-
const originalComponent = components.find((c) => c.
|
|
8320
|
+
const originalComponent = components.find((c) => c.name === mc.componentName);
|
|
8320
8321
|
if (!originalComponent) {
|
|
8321
|
-
logger.warn(`[${this.getProviderName()}] Component ${mc.
|
|
8322
|
+
logger.warn(`[${this.getProviderName()}] Component "${mc.componentName}" not found in available components`);
|
|
8322
8323
|
return null;
|
|
8323
8324
|
}
|
|
8324
8325
|
const cleanedProps = processComponentProps(
|
|
@@ -8778,7 +8779,7 @@ ${executedToolsText}`);
|
|
|
8778
8779
|
let layoutDescription = "Multi-component dashboard";
|
|
8779
8780
|
let actions = [];
|
|
8780
8781
|
if (category === "general") {
|
|
8781
|
-
logger.info(`[${this.getProviderName()}]
|
|
8782
|
+
logger.info(`[${this.getProviderName()}] General category - wrapping text response in DynamicMarkdownBlock`);
|
|
8782
8783
|
const nextQuestions = await this.generateNextQuestions(
|
|
8783
8784
|
userPrompt,
|
|
8784
8785
|
null,
|
|
@@ -8791,6 +8792,18 @@ ${executedToolsText}`);
|
|
|
8791
8792
|
// pass text response as context
|
|
8792
8793
|
);
|
|
8793
8794
|
actions = convertQuestionsToActions(nextQuestions);
|
|
8795
|
+
const markdownContent = textResponse.replace(/<DashboardComponents>[\s\S]*?<\/DashboardComponents>/g, "").trim();
|
|
8796
|
+
matchedComponents = [{
|
|
8797
|
+
id: "dynamic-markdown-block",
|
|
8798
|
+
name: "DynamicMarkdownBlock",
|
|
8799
|
+
type: "MarkdownBlock",
|
|
8800
|
+
description: "Text response rendered as markdown",
|
|
8801
|
+
props: {
|
|
8802
|
+
content: markdownContent
|
|
8803
|
+
}
|
|
8804
|
+
}];
|
|
8805
|
+
layoutTitle = "";
|
|
8806
|
+
layoutDescription = "";
|
|
8794
8807
|
} else if (components && components.length > 0) {
|
|
8795
8808
|
const componentStreamCallback = streamBuffer.hasCallback() && category === "data_analysis" ? (component) => {
|
|
8796
8809
|
const answerMarker = `__ANSWER_COMPONENT_START__${JSON.stringify(component)}__ANSWER_COMPONENT_END__`;
|
|
@@ -10715,12 +10728,13 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
|
|
|
10715
10728
|
const filters = requestData?.filters;
|
|
10716
10729
|
const limit = requestData?.limit;
|
|
10717
10730
|
const sort = requestData?.sort;
|
|
10718
|
-
|
|
10731
|
+
const readOnlyOperations = ["query", "getAll", "getOne"];
|
|
10732
|
+
if (!readOnlyOperations.includes(operation) && from.type !== "admin") {
|
|
10719
10733
|
sendResponse4(id, {
|
|
10720
10734
|
success: false,
|
|
10721
10735
|
error: "Unauthorized: Only admin can manage dashboards"
|
|
10722
10736
|
}, sendMessage, from.id);
|
|
10723
|
-
logger.warn(`Unauthorized dashboard
|
|
10737
|
+
logger.warn(`Unauthorized dashboard write attempt from: ${from.type}`);
|
|
10724
10738
|
return;
|
|
10725
10739
|
}
|
|
10726
10740
|
const dashboardManager2 = getDashboardManager();
|
|
@@ -11085,12 +11099,13 @@ async function handleReportsRequest(data, collections, sendMessage) {
|
|
|
11085
11099
|
const filters = requestData?.filters;
|
|
11086
11100
|
const limit = requestData?.limit;
|
|
11087
11101
|
const sort = requestData?.sort;
|
|
11088
|
-
|
|
11102
|
+
const readOnlyOperations = ["query", "getAll", "getOne"];
|
|
11103
|
+
if (!readOnlyOperations.includes(operation) && from.type !== "admin") {
|
|
11089
11104
|
sendResponse5(id, {
|
|
11090
11105
|
success: false,
|
|
11091
11106
|
error: "Unauthorized: Only admin can manage reports"
|
|
11092
11107
|
}, sendMessage, from.id);
|
|
11093
|
-
logger.warn(`Unauthorized report
|
|
11108
|
+
logger.warn(`Unauthorized report write attempt from: ${from.type}`);
|
|
11094
11109
|
return;
|
|
11095
11110
|
}
|
|
11096
11111
|
const reportManager2 = getReportManager();
|
|
@@ -13075,7 +13090,8 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
|
|
|
13075
13090
|
outputSchema: tool.outputSchema
|
|
13076
13091
|
});
|
|
13077
13092
|
logger.info(`[DASH_COMP_REQ] Tool ${tool.name} executed successfully`);
|
|
13078
|
-
|
|
13093
|
+
const resultJson = JSON.stringify(result2, null, 2);
|
|
13094
|
+
return resultJson + "\n\n[REMINDER: The above is tool output for verification. You MUST still respond with ONLY the JSON component selection object. Do NOT summarize or describe these results.]";
|
|
13079
13095
|
};
|
|
13080
13096
|
const result = await LLM.streamWithTools(
|
|
13081
13097
|
{
|
|
@@ -13093,18 +13109,59 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
|
|
|
13093
13109
|
5
|
|
13094
13110
|
// max iterations
|
|
13095
13111
|
);
|
|
13096
|
-
|
|
13097
|
-
|
|
13112
|
+
let jsonMatch = result.match(/\{[\s\S]*\}/);
|
|
13113
|
+
let parsedResult = jsonMatch ? (() => {
|
|
13114
|
+
try {
|
|
13115
|
+
return JSON.parse(jsonMatch[0]);
|
|
13116
|
+
} catch {
|
|
13117
|
+
return null;
|
|
13118
|
+
}
|
|
13119
|
+
})() : null;
|
|
13120
|
+
const isValidComponent = parsedResult && parsedResult.componentId && parsedResult.props;
|
|
13121
|
+
if (!isValidComponent && executedTools.length > 0) {
|
|
13122
|
+
const toolDataSummary = executedTools.map(
|
|
13123
|
+
(t) => `Tool "${t.name}" was called with params ${JSON.stringify(t.params)} and returned:
|
|
13124
|
+
${JSON.stringify(t.result, null, 2).substring(0, 5e3)}`
|
|
13125
|
+
).join("\n\n");
|
|
13126
|
+
const retryUserPrompt = `Original user request: ${prompt}
|
|
13127
|
+
|
|
13128
|
+
The following tool was already called and returned data:
|
|
13129
|
+
${toolDataSummary}
|
|
13130
|
+
|
|
13131
|
+
Using this data, select the appropriate component and respond with ONLY the JSON component selection object. No explanation, no markdown, just JSON.`;
|
|
13132
|
+
const retryResult = await LLM.text(
|
|
13133
|
+
{
|
|
13134
|
+
sys: prompts.system,
|
|
13135
|
+
user: retryUserPrompt
|
|
13136
|
+
},
|
|
13137
|
+
{
|
|
13138
|
+
model,
|
|
13139
|
+
maxTokens: 4096,
|
|
13140
|
+
temperature: 0.1,
|
|
13141
|
+
apiKey
|
|
13142
|
+
}
|
|
13143
|
+
);
|
|
13144
|
+
jsonMatch = retryResult.match(/\{[\s\S]*\}/);
|
|
13145
|
+
parsedResult = jsonMatch ? (() => {
|
|
13146
|
+
try {
|
|
13147
|
+
return JSON.parse(jsonMatch[0]);
|
|
13148
|
+
} catch {
|
|
13149
|
+
return null;
|
|
13150
|
+
}
|
|
13151
|
+
})() : null;
|
|
13152
|
+
}
|
|
13098
13153
|
if (!parsedResult) {
|
|
13099
13154
|
errors.push("Failed to parse LLM response as JSON");
|
|
13100
13155
|
errors.push(`LLM Response: ${result}`);
|
|
13156
|
+
logger.error(`[DASH_COMP_REQ] Failed to parse JSON from LLM response`);
|
|
13101
13157
|
return { success: false, errors };
|
|
13102
13158
|
}
|
|
13103
|
-
logger.
|
|
13159
|
+
logger.info(`[DASH_COMP_REQ] Parsed component: ${parsedResult.componentName} (${parsedResult.componentId})`);
|
|
13104
13160
|
logger.file("[DASH_COMP_REQ] LLM response:", JSON.stringify(parsedResult, null, 2));
|
|
13105
13161
|
if (!parsedResult.componentId || !parsedResult.props) {
|
|
13106
13162
|
errors.push("Invalid LLM response: missing componentId or props");
|
|
13107
13163
|
errors.push(`LLM Response: ${result}`);
|
|
13164
|
+
logger.error(`[DASH_COMP_REQ] Invalid structure - missing componentId: ${!parsedResult.componentId}, missing props: ${!parsedResult.props}`);
|
|
13108
13165
|
userPromptErrorLogger.logError("DASH_COMP_REQ", "Invalid LLM response structure", {
|
|
13109
13166
|
prompt,
|
|
13110
13167
|
result: parsedResult,
|