@voltagent/server-core 1.0.5 → 1.0.7-next.1

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,7 +991,10 @@ __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");
995
+ var import_zod2 = require("zod");
994
996
  var import_zod_from_json_schema = require("zod-from-json-schema");
997
+ var import_zod_from_json_schema_v3 = require("zod-from-json-schema-v3");
995
998
 
996
999
  // src/utils/options.ts
997
1000
  function processAgentOptions(body, signal) {
@@ -1098,7 +1101,7 @@ async function handleStreamText(agentId, body, deps, logger, signal) {
1098
1101
  const agent = deps.agentRegistry.getAgent(agentId);
1099
1102
  if (!agent) {
1100
1103
  return new Response(
1101
- JSON.stringify({
1104
+ (0, import_internal.safeStringify)({
1102
1105
  error: `Agent ${agentId} not found`,
1103
1106
  message: `Agent ${agentId} not found`
1104
1107
  }),
@@ -1119,14 +1122,14 @@ async function handleStreamText(agentId, body, deps, logger, signal) {
1119
1122
  async start(controller) {
1120
1123
  try {
1121
1124
  for await (const part of fullStream) {
1122
- const data = `data: ${JSON.stringify(part)}
1125
+ const data = `data: ${(0, import_internal.safeStringify)(part)}
1123
1126
 
1124
1127
  `;
1125
1128
  controller.enqueue(encoder.encode(data));
1126
1129
  }
1127
1130
  } catch (error) {
1128
1131
  logger.error("Error in fullStream iteration", { error });
1129
- const errorData = `data: ${JSON.stringify({ type: "error", error: error instanceof Error ? error.message : "Unknown error" })}
1132
+ const errorData = `data: ${(0, import_internal.safeStringify)({ type: "error", error: error instanceof Error ? error.message : "Unknown error" })}
1130
1133
 
1131
1134
  `;
1132
1135
  controller.enqueue(encoder.encode(errorData));
@@ -1147,7 +1150,7 @@ async function handleStreamText(agentId, body, deps, logger, signal) {
1147
1150
  logger.error("Failed to handle stream text request", { error });
1148
1151
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1149
1152
  return new Response(
1150
- JSON.stringify({
1153
+ (0, import_internal.safeStringify)({
1151
1154
  error: errorMessage,
1152
1155
  message: errorMessage
1153
1156
  }),
@@ -1166,7 +1169,7 @@ async function handleChatStream(agentId, body, deps, logger, signal) {
1166
1169
  const agent = deps.agentRegistry.getAgent(agentId);
1167
1170
  if (!agent) {
1168
1171
  return new Response(
1169
- JSON.stringify({
1172
+ (0, import_internal.safeStringify)({
1170
1173
  error: `Agent ${agentId} not found`,
1171
1174
  message: `Agent ${agentId} not found`
1172
1175
  }),
@@ -1189,7 +1192,7 @@ async function handleChatStream(agentId, body, deps, logger, signal) {
1189
1192
  logger.error("Failed to handle chat stream request", { error });
1190
1193
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1191
1194
  return new Response(
1192
- JSON.stringify({
1195
+ (0, import_internal.safeStringify)({
1193
1196
  error: errorMessage,
1194
1197
  message: errorMessage
1195
1198
  }),
@@ -1214,7 +1217,9 @@ async function handleGenerateObject(agentId, body, deps, logger, signal) {
1214
1217
  }
1215
1218
  const { input, schema: jsonSchema } = body;
1216
1219
  const options = processAgentOptions(body, signal);
1217
- const zodSchema = (0, import_zod_from_json_schema.convertJsonSchemaToZod)(jsonSchema);
1220
+ const zodSchema = ("toJSONSchema" in import_zod2.z ? import_zod_from_json_schema.convertJsonSchemaToZod : import_zod_from_json_schema_v3.convertJsonSchemaToZod)(
1221
+ jsonSchema
1222
+ );
1218
1223
  const result = await agent.generateObject(input, zodSchema, options);
1219
1224
  return {
1220
1225
  success: true,
@@ -1234,7 +1239,7 @@ async function handleStreamObject(agentId, body, deps, logger, signal) {
1234
1239
  const agent = deps.agentRegistry.getAgent(agentId);
1235
1240
  if (!agent) {
1236
1241
  return new Response(
1237
- JSON.stringify({
1242
+ (0, import_internal.safeStringify)({
1238
1243
  error: `Agent ${agentId} not found`,
1239
1244
  message: `Agent ${agentId} not found`
1240
1245
  }),
@@ -1248,14 +1253,16 @@ async function handleStreamObject(agentId, body, deps, logger, signal) {
1248
1253
  }
1249
1254
  const { input, schema: jsonSchema } = body;
1250
1255
  const options = processAgentOptions(body, signal);
1251
- const zodSchema = (0, import_zod_from_json_schema.convertJsonSchemaToZod)(jsonSchema);
1256
+ const zodSchema = ("toJSONSchema" in import_zod2.z ? import_zod_from_json_schema.convertJsonSchemaToZod : import_zod_from_json_schema_v3.convertJsonSchemaToZod)(
1257
+ jsonSchema
1258
+ );
1252
1259
  const result = await agent.streamObject(input, zodSchema, options);
1253
1260
  return result.toTextStreamResponse();
1254
1261
  } catch (error) {
1255
1262
  logger.error("Failed to handle stream object request", { error });
1256
1263
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
1257
1264
  return new Response(
1258
- JSON.stringify({
1265
+ (0, import_internal.safeStringify)({
1259
1266
  error: errorMessage,
1260
1267
  message: errorMessage
1261
1268
  }),
@@ -1339,6 +1346,7 @@ __name(handleGetAgentHistory, "handleGetAgentHistory");
1339
1346
 
1340
1347
  // src/handlers/workflow.handlers.ts
1341
1348
  var import_core2 = require("@voltagent/core");
1349
+ var import_internal2 = require("@voltagent/internal");
1342
1350
  async function handleGetWorkflows(deps, logger) {
1343
1351
  try {
1344
1352
  const workflows = deps.workflowRegistry.getWorkflowsForApi();
@@ -1534,7 +1542,7 @@ async function handleStreamWorkflow(workflowId, body, deps, logger) {
1534
1542
  deps.workflowRegistry.activeExecutions.set(executionId, suspendController);
1535
1543
  }
1536
1544
  for await (const event of workflowStream) {
1537
- const sseEvent = `data: ${JSON.stringify(event)}
1545
+ const sseEvent = `data: ${(0, import_internal2.safeStringify)(event)}
1538
1546
 
1539
1547
  `;
1540
1548
  controller.enqueue(encoder.encode(sseEvent));
@@ -1549,7 +1557,7 @@ async function handleStreamWorkflow(workflowId, body, deps, logger) {
1549
1557
  result,
1550
1558
  endAt: endAt instanceof Date ? endAt.toISOString() : endAt
1551
1559
  };
1552
- const sseFinalEvent = `data: ${JSON.stringify(finalEvent)}
1560
+ const sseFinalEvent = `data: ${(0, import_internal2.safeStringify)(finalEvent)}
1553
1561
 
1554
1562
  `;
1555
1563
  controller.enqueue(encoder.encode(sseFinalEvent));
@@ -1563,7 +1571,7 @@ async function handleStreamWorkflow(workflowId, body, deps, logger) {
1563
1571
  type: "error",
1564
1572
  error: error instanceof Error ? error.message : "Stream failed"
1565
1573
  };
1566
- const sseError = `data: ${JSON.stringify(errorEvent)}
1574
+ const sseError = `data: ${(0, import_internal2.safeStringify)(errorEvent)}
1567
1575
 
1568
1576
  `;
1569
1577
  controller.enqueue(encoder.encode(sseError));
@@ -2711,6 +2719,7 @@ function getResponseStatus(response) {
2711
2719
  __name(getResponseStatus, "getResponseStatus");
2712
2720
 
2713
2721
  // src/utils/sse.ts
2722
+ var import_internal3 = require("@voltagent/internal");
2714
2723
  function formatSSE(data, event, id) {
2715
2724
  let message = "";
2716
2725
  if (id) {
@@ -2721,7 +2730,7 @@ function formatSSE(data, event, id) {
2721
2730
  message += `event: ${event}
2722
2731
  `;
2723
2732
  }
2724
- const dataStr = typeof data === "string" ? data : JSON.stringify(data);
2733
+ const dataStr = typeof data === "string" ? data : (0, import_internal3.safeStringify)(data);
2725
2734
  const lines = dataStr.split("\n");
2726
2735
  for (const line of lines) {
2727
2736
  message += `data: ${line}
@@ -2794,6 +2803,9 @@ function createSSEResponse(stream, status = 200) {
2794
2803
  }
2795
2804
  __name(createSSEResponse, "createSSEResponse");
2796
2805
 
2806
+ // src/websocket/handlers.ts
2807
+ var import_internal5 = require("@voltagent/internal");
2808
+
2797
2809
  // src/websocket/log-stream.ts
2798
2810
  var import_core6 = require("@voltagent/core");
2799
2811
  var import_utils = require("@voltagent/internal/utils");
@@ -2908,6 +2920,7 @@ var LogStreamManager = class {
2908
2920
 
2909
2921
  // src/websocket/observability-handler.ts
2910
2922
  var import_core7 = require("@voltagent/core");
2923
+ var import_internal4 = require("@voltagent/internal");
2911
2924
  var observabilityConnections = /* @__PURE__ */ new Map();
2912
2925
  var observabilityListenersInitialized = false;
2913
2926
  var logUnsubscribe = null;
@@ -2921,7 +2934,7 @@ function setupObservabilityListeners() {
2921
2934
  }
2922
2935
  const emitter = getWebSocketEventEmitter();
2923
2936
  emitter.on("websocket:event", (event) => {
2924
- const message = JSON.stringify({
2937
+ const message = (0, import_internal4.safeStringify)({
2925
2938
  type: "OBSERVABILITY_EVENT",
2926
2939
  success: true,
2927
2940
  data: event
@@ -2946,7 +2959,7 @@ function setupObservabilityListeners() {
2946
2959
  });
2947
2960
  });
2948
2961
  logUnsubscribe = import_core7.WebSocketLogProcessor.subscribe((logRecord) => {
2949
- const message = JSON.stringify({
2962
+ const message = (0, import_internal4.safeStringify)({
2950
2963
  type: "OBSERVABILITY_LOG",
2951
2964
  success: true,
2952
2965
  data: logRecord
@@ -2989,7 +3002,7 @@ function handleObservabilityConnection(ws, request, _deps) {
2989
3002
  entityType
2990
3003
  });
2991
3004
  ws.send(
2992
- JSON.stringify({
3005
+ (0, import_internal4.safeStringify)({
2993
3006
  type: "CONNECTION_SUCCESS",
2994
3007
  success: true,
2995
3008
  data: {
@@ -3005,11 +3018,11 @@ function handleObservabilityConnection(ws, request, _deps) {
3005
3018
  const msg = JSON.parse(data.toString());
3006
3019
  switch (msg.type) {
3007
3020
  case "PING":
3008
- ws.send(JSON.stringify({ type: "PONG", success: true }));
3021
+ ws.send((0, import_internal4.safeStringify)({ type: "PONG", success: true }));
3009
3022
  break;
3010
3023
  case "SUBSCRIBE":
3011
3024
  ws.send(
3012
- JSON.stringify({
3025
+ (0, import_internal4.safeStringify)({
3013
3026
  type: "SUBSCRIPTION_SUCCESS",
3014
3027
  success: true,
3015
3028
  data: { subscribed: true }
@@ -3019,7 +3032,7 @@ function handleObservabilityConnection(ws, request, _deps) {
3019
3032
  }
3020
3033
  } catch (_) {
3021
3034
  ws.send(
3022
- JSON.stringify({
3035
+ (0, import_internal4.safeStringify)({
3023
3036
  type: "ERROR",
3024
3037
  success: false,
3025
3038
  error: "Invalid message format"
@@ -3073,7 +3086,7 @@ async function handleWebSocketConnection(ws, req, deps, logger) {
3073
3086
  __name(handleWebSocketConnection, "handleWebSocketConnection");
3074
3087
  function handleTestConnection(ws, logger) {
3075
3088
  ws.send(
3076
- JSON.stringify({
3089
+ (0, import_internal5.safeStringify)({
3077
3090
  type: "CONNECTION_TEST",
3078
3091
  success: true,
3079
3092
  data: {
@@ -3086,7 +3099,7 @@ function handleTestConnection(ws, logger) {
3086
3099
  try {
3087
3100
  const data = JSON.parse(message.toString());
3088
3101
  ws.send(
3089
- JSON.stringify({
3102
+ (0, import_internal5.safeStringify)({
3090
3103
  type: "ECHO",
3091
3104
  success: true,
3092
3105
  data