@superatomai/sdk-node 0.0.35 → 0.0.37

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.mjs CHANGED
@@ -1984,6 +1984,7 @@ var DashboardsRequestPayloadSchema = z3.object({
1984
1984
  published: z3.boolean().optional(),
1985
1985
  createdBy: z3.number().optional(),
1986
1986
  updatedBy: z3.number().optional(),
1987
+ allowedUsers: z3.array(z3.number()).optional(),
1987
1988
  dashboard: DSLRendererPropsSchema.optional(),
1988
1989
  // Query operation fields
1989
1990
  filters: DashboardQueryFiltersSchema.optional(),
@@ -3541,18 +3542,26 @@ var LLM = class {
3541
3542
  const client = new Anthropic({
3542
3543
  apiKey
3543
3544
  });
3545
+ const apiMessages = [{
3546
+ role: "user",
3547
+ content: messages.user
3548
+ }];
3549
+ const prefill = messages.prefill || (json ? "{" : void 0);
3550
+ if (prefill) {
3551
+ apiMessages.push({
3552
+ role: "assistant",
3553
+ content: prefill
3554
+ });
3555
+ }
3544
3556
  const stream = await client.messages.create({
3545
3557
  model: modelName,
3546
3558
  max_tokens: options.maxTokens || 1e3,
3547
3559
  temperature: options.temperature,
3548
3560
  system: this._normalizeSystemPrompt(messages.sys),
3549
- messages: [{
3550
- role: "user",
3551
- content: messages.user
3552
- }],
3561
+ messages: apiMessages,
3553
3562
  stream: true
3554
3563
  });
3555
- let fullText = "";
3564
+ let fullText = prefill || "";
3556
3565
  let usage = null;
3557
3566
  for await (const chunk of stream) {
3558
3567
  if (chunk.type === "content_block_delta" && chunk.delta.type === "text_delta") {
@@ -4088,40 +4097,56 @@ var LLM = class {
4088
4097
  openChar = "[";
4089
4098
  closeChar = "]";
4090
4099
  }
4091
- if (startIdx !== -1) {
4092
- let depth = 0;
4093
- let inString = false;
4094
- let endIdx = -1;
4095
- for (let i = startIdx; i < jsonText.length; i++) {
4096
- const char = jsonText[i];
4097
- const prevChar = i > 0 ? jsonText[i - 1] : "";
4098
- if (char === '"' && prevChar !== "\\") {
4099
- inString = !inString;
4100
- continue;
4101
- }
4102
- if (!inString) {
4103
- if (char === openChar) {
4104
- depth++;
4105
- } else if (char === closeChar) {
4106
- depth--;
4107
- if (depth === 0) {
4108
- endIdx = i;
4109
- break;
4110
- }
4100
+ if (startIdx === -1) {
4101
+ const preview = text.length > 500 ? text.substring(0, 500) + "..." : text;
4102
+ throw new Error(`No JSON found in response. LLM returned plain text instead of JSON.
4103
+
4104
+ Full response:
4105
+ ${preview}`);
4106
+ }
4107
+ let depth = 0;
4108
+ let inString = false;
4109
+ let endIdx = -1;
4110
+ for (let i = startIdx; i < jsonText.length; i++) {
4111
+ const char = jsonText[i];
4112
+ const prevChar = i > 0 ? jsonText[i - 1] : "";
4113
+ if (char === '"' && prevChar !== "\\") {
4114
+ inString = !inString;
4115
+ continue;
4116
+ }
4117
+ if (!inString) {
4118
+ if (char === openChar) {
4119
+ depth++;
4120
+ } else if (char === closeChar) {
4121
+ depth--;
4122
+ if (depth === 0) {
4123
+ endIdx = i;
4124
+ break;
4111
4125
  }
4112
4126
  }
4113
4127
  }
4114
- if (endIdx !== -1) {
4115
- jsonText = jsonText.substring(startIdx, endIdx + 1);
4116
- }
4128
+ }
4129
+ if (endIdx !== -1) {
4130
+ jsonText = jsonText.substring(startIdx, endIdx + 1);
4131
+ } else {
4132
+ const preview = text.length > 500 ? text.substring(0, 500) + "..." : text;
4133
+ throw new Error(`Incomplete JSON - no matching closing ${closeChar} found.
4134
+
4135
+ Full response:
4136
+ ${preview}`);
4117
4137
  }
4118
4138
  try {
4119
4139
  const repairedJson = jsonrepair(jsonText);
4120
4140
  return JSON.parse(repairedJson);
4121
4141
  } catch (error) {
4142
+ const preview = text.length > 500 ? text.substring(0, 500) + "..." : text;
4122
4143
  throw new Error(`Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}
4123
4144
 
4124
- Original text: ${jsonText.substring(0, 200)}...`);
4145
+ Extracted JSON:
4146
+ ${jsonText.substring(0, 300)}...
4147
+
4148
+ Full response:
4149
+ ${preview}`);
4125
4150
  }
4126
4151
  }
4127
4152
  };
@@ -7456,6 +7481,7 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
7456
7481
  const published = requestData?.published;
7457
7482
  const createdBy = requestData?.createdBy;
7458
7483
  const updatedBy = requestData?.updatedBy;
7484
+ const allowedUsers = requestData?.allowedUsers;
7459
7485
  const numericId = requestData?.id;
7460
7486
  const filters = requestData?.filters;
7461
7487
  const limit = requestData?.limit;
@@ -7471,10 +7497,10 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
7471
7497
  const dashboardManager2 = getDashboardManager();
7472
7498
  switch (operation) {
7473
7499
  case "create":
7474
- await handleCreate2(id, dashboardId, dashboard, projectId, name, description, published, createdBy, executeCollection, dashboardManager2, sendMessage, from.id);
7500
+ await handleCreate2(id, dashboardId, dashboard, projectId, name, description, published, createdBy, allowedUsers, executeCollection, dashboardManager2, sendMessage, from.id);
7475
7501
  break;
7476
7502
  case "update":
7477
- await handleUpdate2(id, numericId, dashboardId, dashboard, name, description, published, updatedBy, executeCollection, dashboardManager2, sendMessage, from.id);
7503
+ await handleUpdate2(id, numericId, dashboardId, dashboard, name, description, published, updatedBy, allowedUsers, executeCollection, dashboardManager2, sendMessage, from.id);
7478
7504
  break;
7479
7505
  case "delete":
7480
7506
  await handleDelete2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, from.id);
@@ -7502,7 +7528,7 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
7502
7528
  }, sendMessage);
7503
7529
  }
7504
7530
  }
7505
- async function handleCreate2(id, dashboardId, dashboard, projectId, name, description, published, createdBy, executeCollection, dashboardManager2, sendMessage, clientId) {
7531
+ async function handleCreate2(id, dashboardId, dashboard, projectId, name, description, published, createdBy, allowedUsers, executeCollection, dashboardManager2, sendMessage, clientId) {
7506
7532
  if (!dashboardId || dashboardId.trim().length === 0) {
7507
7533
  sendResponse4(id, {
7508
7534
  success: false,
@@ -7525,7 +7551,8 @@ async function handleCreate2(id, dashboardId, dashboard, projectId, name, descri
7525
7551
  description,
7526
7552
  dashboard,
7527
7553
  published,
7528
- createdBy
7554
+ createdBy,
7555
+ allowedUsers
7529
7556
  });
7530
7557
  if (result && result.success) {
7531
7558
  logger.info(`[DB] Dashboard created successfully, ID: ${result.data?.id}`);
@@ -7564,7 +7591,7 @@ async function handleCreate2(id, dashboardId, dashboard, projectId, name, descri
7564
7591
  }, sendMessage, clientId);
7565
7592
  }
7566
7593
  }
7567
- async function handleUpdate2(id, numericId, dashboardId, dashboard, name, description, published, updatedBy, executeCollection, dashboardManager2, sendMessage, clientId) {
7594
+ async function handleUpdate2(id, numericId, dashboardId, dashboard, name, description, published, updatedBy, allowedUsers, executeCollection, dashboardManager2, sendMessage, clientId) {
7568
7595
  if (!numericId) {
7569
7596
  sendResponse4(id, {
7570
7597
  success: false,
@@ -7579,7 +7606,8 @@ async function handleUpdate2(id, numericId, dashboardId, dashboard, name, descri
7579
7606
  description,
7580
7607
  dashboard,
7581
7608
  published,
7582
- updatedBy
7609
+ updatedBy,
7610
+ allowedUsers
7583
7611
  });
7584
7612
  if (result && result.success) {
7585
7613
  logger.info(`[DB] Dashboard updated successfully, ID: ${numericId}`);