@voltagent/server-core 1.0.4 → 1.0.6

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
@@ -991,6 +991,7 @@ __name(getRoutesByTag, "getRoutesByTag");
991
991
 
992
992
  // src/handlers/agent.handlers.ts
993
993
  var import_core = require("@voltagent/core");
994
+ var import_internal = require("@voltagent/internal");
994
995
  var import_zod_from_json_schema = require("zod-from-json-schema");
995
996
 
996
997
  // src/utils/options.ts
@@ -1098,7 +1099,7 @@ async function handleStreamText(agentId, body, deps, logger, signal) {
1098
1099
  const agent = deps.agentRegistry.getAgent(agentId);
1099
1100
  if (!agent) {
1100
1101
  return new Response(
1101
- JSON.stringify({
1102
+ (0, import_internal.safeStringify)({
1102
1103
  error: `Agent ${agentId} not found`,
1103
1104
  message: `Agent ${agentId} not found`
1104
1105
  }),
@@ -1119,14 +1120,14 @@ async function handleStreamText(agentId, body, deps, logger, signal) {
1119
1120
  async start(controller) {
1120
1121
  try {
1121
1122
  for await (const part of fullStream) {
1122
- const data = `data: ${JSON.stringify(part)}
1123
+ const data = `data: ${(0, import_internal.safeStringify)(part)}
1123
1124
 
1124
1125
  `;
1125
1126
  controller.enqueue(encoder.encode(data));
1126
1127
  }
1127
1128
  } catch (error) {
1128
1129
  logger.error("Error in fullStream iteration", { error });
1129
- const errorData = `data: ${JSON.stringify({ type: "error", error: error instanceof Error ? error.message : "Unknown error" })}
1130
+ const errorData = `data: ${(0, import_internal.safeStringify)({ type: "error", error: error instanceof Error ? error.message : "Unknown error" })}
1130
1131
 
1131
1132
  `;
1132
1133
  controller.enqueue(encoder.encode(errorData));
@@ -1147,7 +1148,7 @@ async function handleStreamText(agentId, body, deps, logger, signal) {
1147
1148
  logger.error("Failed to handle stream text request", { error });
1148
1149
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1149
1150
  return new Response(
1150
- JSON.stringify({
1151
+ (0, import_internal.safeStringify)({
1151
1152
  error: errorMessage,
1152
1153
  message: errorMessage
1153
1154
  }),
@@ -1166,7 +1167,7 @@ async function handleChatStream(agentId, body, deps, logger, signal) {
1166
1167
  const agent = deps.agentRegistry.getAgent(agentId);
1167
1168
  if (!agent) {
1168
1169
  return new Response(
1169
- JSON.stringify({
1170
+ (0, import_internal.safeStringify)({
1170
1171
  error: `Agent ${agentId} not found`,
1171
1172
  message: `Agent ${agentId} not found`
1172
1173
  }),
@@ -1189,7 +1190,7 @@ async function handleChatStream(agentId, body, deps, logger, signal) {
1189
1190
  logger.error("Failed to handle chat stream request", { error });
1190
1191
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1191
1192
  return new Response(
1192
- JSON.stringify({
1193
+ (0, import_internal.safeStringify)({
1193
1194
  error: errorMessage,
1194
1195
  message: errorMessage
1195
1196
  }),
@@ -1234,7 +1235,7 @@ async function handleStreamObject(agentId, body, deps, logger, signal) {
1234
1235
  const agent = deps.agentRegistry.getAgent(agentId);
1235
1236
  if (!agent) {
1236
1237
  return new Response(
1237
- JSON.stringify({
1238
+ (0, import_internal.safeStringify)({
1238
1239
  error: `Agent ${agentId} not found`,
1239
1240
  message: `Agent ${agentId} not found`
1240
1241
  }),
@@ -1255,7 +1256,7 @@ async function handleStreamObject(agentId, body, deps, logger, signal) {
1255
1256
  logger.error("Failed to handle stream object request", { error });
1256
1257
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1257
1258
  return new Response(
1258
- JSON.stringify({
1259
+ (0, import_internal.safeStringify)({
1259
1260
  error: errorMessage,
1260
1261
  message: errorMessage
1261
1262
  }),
@@ -1339,6 +1340,7 @@ __name(handleGetAgentHistory, "handleGetAgentHistory");
1339
1340
 
1340
1341
  // src/handlers/workflow.handlers.ts
1341
1342
  var import_core2 = require("@voltagent/core");
1343
+ var import_internal2 = require("@voltagent/internal");
1342
1344
  async function handleGetWorkflows(deps, logger) {
1343
1345
  try {
1344
1346
  const workflows = deps.workflowRegistry.getWorkflowsForApi();
@@ -1534,7 +1536,7 @@ async function handleStreamWorkflow(workflowId, body, deps, logger) {
1534
1536
  deps.workflowRegistry.activeExecutions.set(executionId, suspendController);
1535
1537
  }
1536
1538
  for await (const event of workflowStream) {
1537
- const sseEvent = `data: ${JSON.stringify(event)}
1539
+ const sseEvent = `data: ${(0, import_internal2.safeStringify)(event)}
1538
1540
 
1539
1541
  `;
1540
1542
  controller.enqueue(encoder.encode(sseEvent));
@@ -1549,7 +1551,7 @@ async function handleStreamWorkflow(workflowId, body, deps, logger) {
1549
1551
  result,
1550
1552
  endAt: endAt instanceof Date ? endAt.toISOString() : endAt
1551
1553
  };
1552
- const sseFinalEvent = `data: ${JSON.stringify(finalEvent)}
1554
+ const sseFinalEvent = `data: ${(0, import_internal2.safeStringify)(finalEvent)}
1553
1555
 
1554
1556
  `;
1555
1557
  controller.enqueue(encoder.encode(sseFinalEvent));
@@ -1563,7 +1565,7 @@ async function handleStreamWorkflow(workflowId, body, deps, logger) {
1563
1565
  type: "error",
1564
1566
  error: error instanceof Error ? error.message : "Stream failed"
1565
1567
  };
1566
- const sseError = `data: ${JSON.stringify(errorEvent)}
1568
+ const sseError = `data: ${(0, import_internal2.safeStringify)(errorEvent)}
1567
1569
 
1568
1570
  `;
1569
1571
  controller.enqueue(encoder.encode(sseError));
@@ -2711,6 +2713,7 @@ function getResponseStatus(response) {
2711
2713
  __name(getResponseStatus, "getResponseStatus");
2712
2714
 
2713
2715
  // src/utils/sse.ts
2716
+ var import_internal3 = require("@voltagent/internal");
2714
2717
  function formatSSE(data, event, id) {
2715
2718
  let message = "";
2716
2719
  if (id) {
@@ -2721,7 +2724,7 @@ function formatSSE(data, event, id) {
2721
2724
  message += `event: ${event}
2722
2725
  `;
2723
2726
  }
2724
- const dataStr = typeof data === "string" ? data : JSON.stringify(data);
2727
+ const dataStr = typeof data === "string" ? data : (0, import_internal3.safeStringify)(data);
2725
2728
  const lines = dataStr.split("\n");
2726
2729
  for (const line of lines) {
2727
2730
  message += `data: ${line}
@@ -2794,6 +2797,9 @@ function createSSEResponse(stream, status = 200) {
2794
2797
  }
2795
2798
  __name(createSSEResponse, "createSSEResponse");
2796
2799
 
2800
+ // src/websocket/handlers.ts
2801
+ var import_internal5 = require("@voltagent/internal");
2802
+
2797
2803
  // src/websocket/log-stream.ts
2798
2804
  var import_core6 = require("@voltagent/core");
2799
2805
  var import_utils = require("@voltagent/internal/utils");
@@ -2908,6 +2914,7 @@ var LogStreamManager = class {
2908
2914
 
2909
2915
  // src/websocket/observability-handler.ts
2910
2916
  var import_core7 = require("@voltagent/core");
2917
+ var import_internal4 = require("@voltagent/internal");
2911
2918
  var observabilityConnections = /* @__PURE__ */ new Map();
2912
2919
  var observabilityListenersInitialized = false;
2913
2920
  var logUnsubscribe = null;
@@ -2921,7 +2928,7 @@ function setupObservabilityListeners() {
2921
2928
  }
2922
2929
  const emitter = getWebSocketEventEmitter();
2923
2930
  emitter.on("websocket:event", (event) => {
2924
- const message = JSON.stringify({
2931
+ const message = (0, import_internal4.safeStringify)({
2925
2932
  type: "OBSERVABILITY_EVENT",
2926
2933
  success: true,
2927
2934
  data: event
@@ -2946,7 +2953,7 @@ function setupObservabilityListeners() {
2946
2953
  });
2947
2954
  });
2948
2955
  logUnsubscribe = import_core7.WebSocketLogProcessor.subscribe((logRecord) => {
2949
- const message = JSON.stringify({
2956
+ const message = (0, import_internal4.safeStringify)({
2950
2957
  type: "OBSERVABILITY_LOG",
2951
2958
  success: true,
2952
2959
  data: logRecord
@@ -2989,7 +2996,7 @@ function handleObservabilityConnection(ws, request, _deps) {
2989
2996
  entityType
2990
2997
  });
2991
2998
  ws.send(
2992
- JSON.stringify({
2999
+ (0, import_internal4.safeStringify)({
2993
3000
  type: "CONNECTION_SUCCESS",
2994
3001
  success: true,
2995
3002
  data: {
@@ -3005,11 +3012,11 @@ function handleObservabilityConnection(ws, request, _deps) {
3005
3012
  const msg = JSON.parse(data.toString());
3006
3013
  switch (msg.type) {
3007
3014
  case "PING":
3008
- ws.send(JSON.stringify({ type: "PONG", success: true }));
3015
+ ws.send((0, import_internal4.safeStringify)({ type: "PONG", success: true }));
3009
3016
  break;
3010
3017
  case "SUBSCRIBE":
3011
3018
  ws.send(
3012
- JSON.stringify({
3019
+ (0, import_internal4.safeStringify)({
3013
3020
  type: "SUBSCRIPTION_SUCCESS",
3014
3021
  success: true,
3015
3022
  data: { subscribed: true }
@@ -3019,7 +3026,7 @@ function handleObservabilityConnection(ws, request, _deps) {
3019
3026
  }
3020
3027
  } catch (_) {
3021
3028
  ws.send(
3022
- JSON.stringify({
3029
+ (0, import_internal4.safeStringify)({
3023
3030
  type: "ERROR",
3024
3031
  success: false,
3025
3032
  error: "Invalid message format"
@@ -3073,7 +3080,7 @@ async function handleWebSocketConnection(ws, req, deps, logger) {
3073
3080
  __name(handleWebSocketConnection, "handleWebSocketConnection");
3074
3081
  function handleTestConnection(ws, logger) {
3075
3082
  ws.send(
3076
- JSON.stringify({
3083
+ (0, import_internal5.safeStringify)({
3077
3084
  type: "CONNECTION_TEST",
3078
3085
  success: true,
3079
3086
  data: {
@@ -3086,7 +3093,7 @@ function handleTestConnection(ws, logger) {
3086
3093
  try {
3087
3094
  const data = JSON.parse(message.toString());
3088
3095
  ws.send(
3089
- JSON.stringify({
3096
+ (0, import_internal5.safeStringify)({
3090
3097
  type: "ECHO",
3091
3098
  success: true,
3092
3099
  data