@voltagent/core 0.1.73 → 0.1.74

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
@@ -9997,8 +9997,8 @@ var TelemetryServiceApiClient = class {
9997
9997
  );
9998
9998
  }
9999
9999
  }
10000
- async request(method, path3, body) {
10001
- const url = `${this.baseUrl}${path3}`;
10000
+ async request(method, path4, body) {
10001
+ const url = `${this.baseUrl}${path4}`;
10002
10002
  const headers = {
10003
10003
  "Content-Type": "application/json",
10004
10004
  "x-public-key": this.publicKey,
@@ -12651,11 +12651,14 @@ ${retrieverContext}`;
12651
12651
  options.parentAgentId,
12652
12652
  options.parentHistoryEntryId
12653
12653
  );
12654
+ const userContextToUse = options.parentOperationContext?.userContext || options.userContext || this.defaultUserContext;
12655
+ const userContextObject = userContextToUse ? Object.fromEntries(userContextToUse.entries()) : {};
12654
12656
  const methodLogger = contextualLogger.child({
12655
12657
  userId: options.userId,
12656
12658
  conversationId: options.conversationId,
12657
12659
  executionId: historyEntry.id,
12658
12660
  operationName: options.operationName,
12661
+ userContext: userContextObject,
12659
12662
  // Preserve parent execution ID if present in contextual logger
12660
12663
  ...options.parentHistoryEntryId && {
12661
12664
  parentExecutionId: options.parentHistoryEntryId
@@ -12663,7 +12666,7 @@ ${retrieverContext}`;
12663
12666
  });
12664
12667
  const opContext = {
12665
12668
  operationId: historyEntry.id,
12666
- userContext: (options.parentOperationContext?.userContext || options.userContext || this.defaultUserContext) ?? /* @__PURE__ */ new Map(),
12669
+ userContext: userContextToUse ?? /* @__PURE__ */ new Map(),
12667
12670
  historyEntry,
12668
12671
  isActive: true,
12669
12672
  parentAgentId: options.parentAgentId,
@@ -15847,6 +15850,8 @@ var MCPConfiguration = class {
15847
15850
  };
15848
15851
 
15849
15852
  // src/server/api.ts
15853
+ var import_promises = __toESM(require("fs/promises"));
15854
+ var import_node_path4 = __toESM(require("path"));
15850
15855
  var import_swagger_ui = require("@hono/swagger-ui");
15851
15856
  var import_zod_openapi3 = require("@hono/zod-openapi");
15852
15857
  var import_cors = require("hono/cors");
@@ -17973,6 +17978,88 @@ app.post("/updates/:packageName", async (c) => {
17973
17978
  );
17974
17979
  }
17975
17980
  });
17981
+ app.post("/setup-observability", async (c) => {
17982
+ try {
17983
+ const body = await c.req.json();
17984
+ const { publicKey, secretKey } = body;
17985
+ if (!publicKey || !secretKey) {
17986
+ return c.json(
17987
+ {
17988
+ success: false,
17989
+ error: "Missing publicKey or secretKey"
17990
+ },
17991
+ 400
17992
+ );
17993
+ }
17994
+ const envPath = import_node_path4.default.join(process.cwd(), ".env");
17995
+ try {
17996
+ let envContent = "";
17997
+ try {
17998
+ envContent = await import_promises.default.readFile(envPath, "utf-8");
17999
+ } catch (_error) {
18000
+ logger.debug(".env file not found, will create new one");
18001
+ }
18002
+ const lines = envContent.split("\n");
18003
+ let publicKeyUpdated = false;
18004
+ let secretKeyUpdated = false;
18005
+ const updatedLines = lines.map((line) => {
18006
+ const trimmedLine = line.trim();
18007
+ if (trimmedLine.startsWith("# VOLTAGENT_PUBLIC_KEY=")) {
18008
+ publicKeyUpdated = true;
18009
+ return `VOLTAGENT_PUBLIC_KEY=${publicKey}`;
18010
+ }
18011
+ if (trimmedLine.startsWith("# VOLTAGENT_SECRET_KEY=")) {
18012
+ secretKeyUpdated = true;
18013
+ return `VOLTAGENT_SECRET_KEY=${secretKey}`;
18014
+ }
18015
+ return line;
18016
+ });
18017
+ envContent = updatedLines.join("\n");
18018
+ if (!publicKeyUpdated || !secretKeyUpdated) {
18019
+ if (!envContent.endsWith("\n") && envContent.length > 0) {
18020
+ envContent += "\n";
18021
+ }
18022
+ if (!publicKeyUpdated && !secretKeyUpdated) {
18023
+ envContent += `
18024
+ # VoltAgent Observability
18025
+ VOLTAGENT_PUBLIC_KEY=${publicKey}
18026
+ VOLTAGENT_SECRET_KEY=${secretKey}
18027
+ `;
18028
+ } else if (!publicKeyUpdated) {
18029
+ envContent += `VOLTAGENT_PUBLIC_KEY=${publicKey}
18030
+ `;
18031
+ } else if (!secretKeyUpdated) {
18032
+ envContent += `VOLTAGENT_SECRET_KEY=${secretKey}
18033
+ `;
18034
+ }
18035
+ }
18036
+ await import_promises.default.writeFile(envPath, envContent);
18037
+ logger.info("Observability configuration updated in .env file");
18038
+ return c.json({
18039
+ success: true,
18040
+ message: "Observability configured successfully. Please restart your application."
18041
+ });
18042
+ } catch (error) {
18043
+ logger.error("Failed to update .env file:", { error });
18044
+ return c.json(
18045
+ {
18046
+ success: false,
18047
+ error: "Failed to update .env file"
18048
+ },
18049
+ 500
18050
+ );
18051
+ }
18052
+ } catch (error) {
18053
+ logger.error("Failed to setup observability:", { error });
18054
+ return c.json(
18055
+ {
18056
+ success: false,
18057
+ error: error instanceof Error ? error.message : "Failed to setup observability"
18058
+ },
18059
+ 500
18060
+ );
18061
+ }
18062
+ });
17976
18063
  app.doc("/doc", {
17977
18064
  openapi: "3.1.0",
17978
18065
  info: {
@@ -17985,25 +18072,25 @@ app.doc("/doc", {
17985
18072
  function registerCustomEndpoint(endpoint) {
17986
18073
  try {
17987
18074
  const validatedEndpoint = validateCustomEndpoint(endpoint);
17988
- const { path: path3, method, handler } = validatedEndpoint;
18075
+ const { path: path4, method, handler } = validatedEndpoint;
17989
18076
  switch (method) {
17990
18077
  case "get":
17991
- app.get(path3, handler);
18078
+ app.get(path4, handler);
17992
18079
  break;
17993
18080
  case "post":
17994
- app.post(path3, handler);
18081
+ app.post(path4, handler);
17995
18082
  break;
17996
18083
  case "put":
17997
- app.put(path3, handler);
18084
+ app.put(path4, handler);
17998
18085
  break;
17999
18086
  case "patch":
18000
- app.patch(path3, handler);
18087
+ app.patch(path4, handler);
18001
18088
  break;
18002
18089
  case "delete":
18003
- app.delete(path3, handler);
18090
+ app.delete(path4, handler);
18004
18091
  break;
18005
18092
  case "options":
18006
- app.options(path3, handler);
18093
+ app.options(path4, handler);
18007
18094
  break;
18008
18095
  default:
18009
18096
  throw new CustomEndpointError(`Unsupported HTTP method: ${method}`);
@@ -18029,25 +18116,25 @@ function registerCustomEndpoints(endpoints) {
18029
18116
  return;
18030
18117
  }
18031
18118
  for (const endpoint of validatedEndpoints) {
18032
- const { path: path3, method, handler } = endpoint;
18119
+ const { path: path4, method, handler } = endpoint;
18033
18120
  switch (method) {
18034
18121
  case "get":
18035
- app.get(path3, handler);
18122
+ app.get(path4, handler);
18036
18123
  break;
18037
18124
  case "post":
18038
- app.post(path3, handler);
18125
+ app.post(path4, handler);
18039
18126
  break;
18040
18127
  case "put":
18041
- app.put(path3, handler);
18128
+ app.put(path4, handler);
18042
18129
  break;
18043
18130
  case "patch":
18044
- app.patch(path3, handler);
18131
+ app.patch(path4, handler);
18045
18132
  break;
18046
18133
  case "delete":
18047
- app.delete(path3, handler);
18134
+ app.delete(path4, handler);
18048
18135
  break;
18049
18136
  case "options":
18050
- app.options(path3, handler);
18137
+ app.options(path4, handler);
18051
18138
  break;
18052
18139
  default:
18053
18140
  throw new CustomEndpointError(`Unsupported HTTP method: ${method}`);
@@ -18363,9 +18450,9 @@ var printServerStartup = /* @__PURE__ */ __name((port, config) => {
18363
18450
  const methodOrder = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
18364
18451
  methodOrder.forEach((method) => {
18365
18452
  if (methodGroups[method]) {
18366
- methodGroups[method].forEach((path3) => {
18453
+ methodGroups[method].forEach((path4) => {
18367
18454
  console.log(
18368
- `${colors.dim} ${method.padEnd(6)} ${colors.reset}${colors.white}${path3}${colors.reset}`
18455
+ `${colors.dim} ${method.padEnd(6)} ${colors.reset}${colors.white}${path4}${colors.reset}`
18369
18456
  );
18370
18457
  });
18371
18458
  }
@@ -18419,8 +18506,8 @@ var startServer = /* @__PURE__ */ __name(async (config) => {
18419
18506
  const ws = createWebSocketServer();
18420
18507
  server.addListener("upgrade", (req, socket, head) => {
18421
18508
  const url = new URL(req.url || "", "http://localhost");
18422
- const path3 = url.pathname;
18423
- if (path3.startsWith("/ws")) {
18509
+ const path4 = url.pathname;
18510
+ if (path4.startsWith("/ws")) {
18424
18511
  ws.handleUpgrade(req, socket, head, (websocket) => {
18425
18512
  ws.emit("connection", websocket, req);
18426
18513
  });
@@ -18449,6 +18536,15 @@ var startServer = /* @__PURE__ */ __name(async (config) => {
18449
18536
  );
18450
18537
  }, "startServer");
18451
18538
 
18539
+ // src/utils/voltops-validation.ts
18540
+ function isValidVoltOpsKeys(publicKey, secretKey) {
18541
+ if (!publicKey || !secretKey) {
18542
+ return false;
18543
+ }
18544
+ return publicKey.startsWith("pk_") && secretKey.startsWith("sk_");
18545
+ }
18546
+ __name(isValidVoltOpsKeys, "isValidVoltOpsKeys");
18547
+
18452
18548
  // src/voltagent.ts
18453
18549
  var isTelemetryInitializedByVoltAgent = false;
18454
18550
  var registeredProvider = null;
@@ -18477,7 +18573,8 @@ var VoltAgent = class {
18477
18573
  }
18478
18574
  if (options.logger) {
18479
18575
  this.registry.setGlobalLogger(options.logger);
18480
- } else if (options.telemetryExporter) {
18576
+ }
18577
+ if (options.telemetryExporter) {
18481
18578
  this.logger.warn(
18482
18579
  `\u26A0\uFE0F DEPRECATION WARNING: 'telemetryExporter' parameter is deprecated!
18483
18580
 
@@ -18501,6 +18598,26 @@ https://voltagent.dev/docs/observability/developer-console/#migration-guide-from
18501
18598
  }
18502
18599
  this.initializeGlobalTelemetry(options.telemetryExporter);
18503
18600
  }
18601
+ if (!options.voltOpsClient && !options.telemetryExporter) {
18602
+ const publicKey = process.env.VOLTAGENT_PUBLIC_KEY;
18603
+ const secretKey = process.env.VOLTAGENT_SECRET_KEY;
18604
+ if (publicKey && secretKey && isValidVoltOpsKeys(publicKey, secretKey)) {
18605
+ try {
18606
+ const autoClient = new VoltOpsClient({
18607
+ publicKey,
18608
+ secretKey
18609
+ });
18610
+ this.registry.setGlobalVoltOpsClient(autoClient);
18611
+ if (autoClient.observability) {
18612
+ this.registry.setGlobalVoltAgentExporter(autoClient.observability);
18613
+ this.initializeGlobalTelemetry(autoClient.observability);
18614
+ }
18615
+ this.logger.debug("VoltOpsClient auto-configured from environment variables");
18616
+ } catch (error) {
18617
+ this.logger.debug("Could not auto-configure VoltOpsClient", { error });
18618
+ }
18619
+ }
18620
+ }
18504
18621
  this.registerAgents(options.agents);
18505
18622
  if (options.workflows) {
18506
18623
  this.registerWorkflows(options.workflows);