@superatomai/sdk-node 0.0.6-mds → 0.0.7-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.mjs CHANGED
@@ -6777,6 +6777,7 @@ ${formatted}`;
6777
6777
  Analyze the error and try again with a corrected query.`;
6778
6778
  }
6779
6779
  };
6780
+ const maxIterations = this.config.maxRetries + 2;
6780
6781
  await LLM.streamWithTools(
6781
6782
  { sys: prompts.system, user: prompts.user },
6782
6783
  [llmTool],
@@ -6787,7 +6788,7 @@ Analyze the error and try again with a corrected query.`;
6787
6788
  temperature: 0,
6788
6789
  apiKey: this.config.apiKey
6789
6790
  },
6790
- this.config.maxRetries
6791
+ maxIterations
6791
6792
  );
6792
6793
  const executionTimeMs = Date.now() - startTime;
6793
6794
  if (!executedTool) {
@@ -10170,21 +10171,25 @@ var get_user_request = async (data, components, sendMessage, anthropicApiKey, gr
10170
10171
  if (responseMode === "text") {
10171
10172
  streamCallback = (chunk) => {
10172
10173
  accumulatedStreamResponse += chunk;
10173
- const streamMessage = {
10174
- id: `stream_${existingUiBlockId}`,
10175
- // Different ID pattern for streaming
10176
- type: "USER_PROMPT_STREAM",
10177
- from: { type: "data-agent" },
10178
- to: {
10179
- type: "runtime",
10180
- id: wsId
10181
- },
10182
- payload: {
10183
- uiBlockId: existingUiBlockId,
10184
- chunk
10185
- }
10186
- };
10187
- sendMessage(streamMessage);
10174
+ try {
10175
+ const streamMessage = {
10176
+ id: `stream_${existingUiBlockId}`,
10177
+ // Different ID pattern for streaming
10178
+ type: "USER_PROMPT_STREAM",
10179
+ from: { type: "data-agent" },
10180
+ to: {
10181
+ type: "runtime",
10182
+ id: wsId
10183
+ },
10184
+ payload: {
10185
+ uiBlockId: existingUiBlockId,
10186
+ chunk
10187
+ }
10188
+ };
10189
+ sendMessage(streamMessage);
10190
+ } catch (err) {
10191
+ logger.warn(`[UserPromptRequest] Stream send failed (WebSocket may be closed): ${err instanceof Error ? err.message : String(err)}`);
10192
+ }
10188
10193
  };
10189
10194
  }
10190
10195
  const userResponse = await get_agent_user_response(
@@ -15419,17 +15424,27 @@ var SuperatomSDK = class {
15419
15424
  }
15420
15425
  }
15421
15426
  /**
15422
- * Send a message to the Superatom service
15427
+ * Send a message to the Superatom service.
15428
+ * Returns true if the message was sent, false if the WebSocket is not connected.
15429
+ * Does NOT throw on closed connections — callers can check the return value if needed.
15423
15430
  */
15424
15431
  send(message) {
15425
15432
  if (!this.ws || !this.connected) {
15426
- throw new Error("WebSocket is not connected. Call connect() first.");
15433
+ logger.warn("WebSocket is not connected, message not sent:", message.type);
15434
+ return false;
15427
15435
  }
15428
15436
  if (this.ws.readyState !== this.ws.OPEN) {
15429
- throw new Error("WebSocket is not ready to send messages.");
15437
+ logger.warn("WebSocket is not in OPEN state, message not sent:", message.type);
15438
+ return false;
15439
+ }
15440
+ try {
15441
+ const payload = JSON.stringify(message);
15442
+ this.ws.send(payload);
15443
+ return true;
15444
+ } catch (error) {
15445
+ logger.warn(`Failed to send WebSocket message (${message.type}):`, error instanceof Error ? error.message : String(error));
15446
+ return false;
15430
15447
  }
15431
- const payload = JSON.stringify(message);
15432
- this.ws.send(payload);
15433
15448
  }
15434
15449
  /**
15435
15450
  * Register a message handler to receive all messages