@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/dist/index.js CHANGED
@@ -402,7 +402,8 @@ var UserQueryFiltersSchema = import_zod3.z.object({
402
402
  username: import_zod3.z.string().optional(),
403
403
  email: import_zod3.z.string().optional(),
404
404
  role: import_zod3.z.string().optional(),
405
- fullname: import_zod3.z.string().optional()
405
+ fullname: import_zod3.z.string().optional(),
406
+ id: import_zod3.z.number().optional()
406
407
  });
407
408
  var UsersRequestPayloadSchema = import_zod3.z.object({
408
409
  operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
@@ -8373,9 +8374,9 @@ ${executedToolsText}`);
8373
8374
  const rawActions = result.actions || [];
8374
8375
  const actions = convertQuestionsToActions(rawActions);
8375
8376
  const finalComponents = matchedComponents.map((mc) => {
8376
- const originalComponent = components.find((c) => c.id === mc.componentId);
8377
+ const originalComponent = components.find((c) => c.name === mc.componentName);
8377
8378
  if (!originalComponent) {
8378
- logger.warn(`[${this.getProviderName()}] Component ${mc.componentId} not found in available components`);
8379
+ logger.warn(`[${this.getProviderName()}] Component "${mc.componentName}" not found in available components`);
8379
8380
  return null;
8380
8381
  }
8381
8382
  const cleanedProps = processComponentProps(
@@ -8835,7 +8836,7 @@ ${executedToolsText}`);
8835
8836
  let layoutDescription = "Multi-component dashboard";
8836
8837
  let actions = [];
8837
8838
  if (category === "general") {
8838
- logger.info(`[${this.getProviderName()}] Skipping component generation for general/conversational question`);
8839
+ logger.info(`[${this.getProviderName()}] General category - wrapping text response in DynamicMarkdownBlock`);
8839
8840
  const nextQuestions = await this.generateNextQuestions(
8840
8841
  userPrompt,
8841
8842
  null,
@@ -8848,6 +8849,18 @@ ${executedToolsText}`);
8848
8849
  // pass text response as context
8849
8850
  );
8850
8851
  actions = convertQuestionsToActions(nextQuestions);
8852
+ const markdownContent = textResponse.replace(/<DashboardComponents>[\s\S]*?<\/DashboardComponents>/g, "").trim();
8853
+ matchedComponents = [{
8854
+ id: "dynamic-markdown-block",
8855
+ name: "DynamicMarkdownBlock",
8856
+ type: "MarkdownBlock",
8857
+ description: "Text response rendered as markdown",
8858
+ props: {
8859
+ content: markdownContent
8860
+ }
8861
+ }];
8862
+ layoutTitle = "";
8863
+ layoutDescription = "";
8851
8864
  } else if (components && components.length > 0) {
8852
8865
  const componentStreamCallback = streamBuffer.hasCallback() && category === "data_analysis" ? (component) => {
8853
8866
  const answerMarker = `__ANSWER_COMPONENT_START__${JSON.stringify(component)}__ANSWER_COMPONENT_END__`;
@@ -10772,12 +10785,13 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
10772
10785
  const filters = requestData?.filters;
10773
10786
  const limit = requestData?.limit;
10774
10787
  const sort = requestData?.sort;
10775
- if (from.type !== "admin") {
10788
+ const readOnlyOperations = ["query", "getAll", "getOne"];
10789
+ if (!readOnlyOperations.includes(operation) && from.type !== "admin") {
10776
10790
  sendResponse4(id, {
10777
10791
  success: false,
10778
10792
  error: "Unauthorized: Only admin can manage dashboards"
10779
10793
  }, sendMessage, from.id);
10780
- logger.warn(`Unauthorized dashboard management attempt from: ${from.type}`);
10794
+ logger.warn(`Unauthorized dashboard write attempt from: ${from.type}`);
10781
10795
  return;
10782
10796
  }
10783
10797
  const dashboardManager2 = getDashboardManager();
@@ -11142,12 +11156,13 @@ async function handleReportsRequest(data, collections, sendMessage) {
11142
11156
  const filters = requestData?.filters;
11143
11157
  const limit = requestData?.limit;
11144
11158
  const sort = requestData?.sort;
11145
- if (from.type !== "admin") {
11159
+ const readOnlyOperations = ["query", "getAll", "getOne"];
11160
+ if (!readOnlyOperations.includes(operation) && from.type !== "admin") {
11146
11161
  sendResponse5(id, {
11147
11162
  success: false,
11148
11163
  error: "Unauthorized: Only admin can manage reports"
11149
11164
  }, sendMessage, from.id);
11150
- logger.warn(`Unauthorized report management attempt from: ${from.type}`);
11165
+ logger.warn(`Unauthorized report write attempt from: ${from.type}`);
11151
11166
  return;
11152
11167
  }
11153
11168
  const reportManager2 = getReportManager();
@@ -13132,7 +13147,8 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
13132
13147
  outputSchema: tool.outputSchema
13133
13148
  });
13134
13149
  logger.info(`[DASH_COMP_REQ] Tool ${tool.name} executed successfully`);
13135
- return JSON.stringify(result2, null, 2);
13150
+ const resultJson = JSON.stringify(result2, null, 2);
13151
+ 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.]";
13136
13152
  };
13137
13153
  const result = await LLM.streamWithTools(
13138
13154
  {
@@ -13150,18 +13166,59 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
13150
13166
  5
13151
13167
  // max iterations
13152
13168
  );
13153
- const jsonMatch = result.match(/\{[\s\S]*\}/);
13154
- const parsedResult = jsonMatch ? JSON.parse(jsonMatch[0]) : null;
13169
+ let jsonMatch = result.match(/\{[\s\S]*\}/);
13170
+ let parsedResult = jsonMatch ? (() => {
13171
+ try {
13172
+ return JSON.parse(jsonMatch[0]);
13173
+ } catch {
13174
+ return null;
13175
+ }
13176
+ })() : null;
13177
+ const isValidComponent = parsedResult && parsedResult.componentId && parsedResult.props;
13178
+ if (!isValidComponent && executedTools.length > 0) {
13179
+ const toolDataSummary = executedTools.map(
13180
+ (t) => `Tool "${t.name}" was called with params ${JSON.stringify(t.params)} and returned:
13181
+ ${JSON.stringify(t.result, null, 2).substring(0, 5e3)}`
13182
+ ).join("\n\n");
13183
+ const retryUserPrompt = `Original user request: ${prompt}
13184
+
13185
+ The following tool was already called and returned data:
13186
+ ${toolDataSummary}
13187
+
13188
+ Using this data, select the appropriate component and respond with ONLY the JSON component selection object. No explanation, no markdown, just JSON.`;
13189
+ const retryResult = await LLM.text(
13190
+ {
13191
+ sys: prompts.system,
13192
+ user: retryUserPrompt
13193
+ },
13194
+ {
13195
+ model,
13196
+ maxTokens: 4096,
13197
+ temperature: 0.1,
13198
+ apiKey
13199
+ }
13200
+ );
13201
+ jsonMatch = retryResult.match(/\{[\s\S]*\}/);
13202
+ parsedResult = jsonMatch ? (() => {
13203
+ try {
13204
+ return JSON.parse(jsonMatch[0]);
13205
+ } catch {
13206
+ return null;
13207
+ }
13208
+ })() : null;
13209
+ }
13155
13210
  if (!parsedResult) {
13156
13211
  errors.push("Failed to parse LLM response as JSON");
13157
13212
  errors.push(`LLM Response: ${result}`);
13213
+ logger.error(`[DASH_COMP_REQ] Failed to parse JSON from LLM response`);
13158
13214
  return { success: false, errors };
13159
13215
  }
13160
- logger.debug("[DASH_COMP_REQ] LLM response received");
13216
+ logger.info(`[DASH_COMP_REQ] Parsed component: ${parsedResult.componentName} (${parsedResult.componentId})`);
13161
13217
  logger.file("[DASH_COMP_REQ] LLM response:", JSON.stringify(parsedResult, null, 2));
13162
13218
  if (!parsedResult.componentId || !parsedResult.props) {
13163
13219
  errors.push("Invalid LLM response: missing componentId or props");
13164
13220
  errors.push(`LLM Response: ${result}`);
13221
+ logger.error(`[DASH_COMP_REQ] Invalid structure - missing componentId: ${!parsedResult.componentId}, missing props: ${!parsedResult.props}`);
13165
13222
  userPromptErrorLogger.logError("DASH_COMP_REQ", "Invalid LLM response structure", {
13166
13223
  prompt,
13167
13224
  result: parsedResult,