@voltagent/core 0.1.73 → 0.1.75

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.d.mts CHANGED
@@ -4390,6 +4390,10 @@ declare class VoltOpsClient implements VoltOpsClient$1 {
4390
4390
  * Check if observability is enabled and configured
4391
4391
  */
4392
4392
  isObservabilityEnabled(): boolean;
4393
+ /**
4394
+ * Check if the client has valid API keys
4395
+ */
4396
+ hasValidKeys(): boolean;
4393
4397
  /**
4394
4398
  * Check if prompt management is enabled and configured
4395
4399
  */
@@ -4408,10 +4412,6 @@ declare class VoltOpsClient implements VoltOpsClient$1 {
4408
4412
  * Priority: Agent VoltOpsClient > Global VoltOpsClient > Fallback instructions
4409
4413
  */
4410
4414
  static createPromptHelperWithFallback(agentId: string, agentName: string, fallbackInstructions: string, agentVoltOpsClient?: VoltOpsClient): PromptHelper;
4411
- /**
4412
- * Validate API keys and provide helpful error messages
4413
- */
4414
- private validateApiKeys;
4415
4415
  /**
4416
4416
  * Cleanup resources when client is no longer needed
4417
4417
  */
package/dist/index.d.ts CHANGED
@@ -4390,6 +4390,10 @@ declare class VoltOpsClient implements VoltOpsClient$1 {
4390
4390
  * Check if observability is enabled and configured
4391
4391
  */
4392
4392
  isObservabilityEnabled(): boolean;
4393
+ /**
4394
+ * Check if the client has valid API keys
4395
+ */
4396
+ hasValidKeys(): boolean;
4393
4397
  /**
4394
4398
  * Check if prompt management is enabled and configured
4395
4399
  */
@@ -4408,10 +4412,6 @@ declare class VoltOpsClient implements VoltOpsClient$1 {
4408
4412
  * Priority: Agent VoltOpsClient > Global VoltOpsClient > Fallback instructions
4409
4413
  */
4410
4414
  static createPromptHelperWithFallback(agentId: string, agentName: string, fallbackInstructions: string, agentVoltOpsClient?: VoltOpsClient): PromptHelper;
4411
- /**
4412
- * Validate API keys and provide helpful error messages
4413
- */
4414
- private validateApiKeys;
4415
4415
  /**
4416
4416
  * Cleanup resources when client is no longer needed
4417
4417
  */
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,
@@ -10647,24 +10647,26 @@ var VoltOpsClient = class {
10647
10647
  }
10648
10648
  };
10649
10649
  this.logger = new LoggerProxy({ component: "voltops-client" });
10650
- this.validateApiKeys(options);
10651
- if (this.options.observability !== false) {
10652
- try {
10653
- this.observability = new VoltAgentExporter({
10654
- baseUrl: this.options.baseUrl,
10655
- publicKey: this.options.publicKey || "",
10656
- secretKey: this.options.secretKey || "",
10657
- fetch: this.options.fetch
10658
- });
10659
- } catch (error) {
10660
- this.logger.error("Failed to initialize observability exporter", { error });
10650
+ const hasValidKeys = this.options.publicKey && this.options.publicKey.trim() !== "" && this.options.publicKey.startsWith("pk_") && this.options.secretKey && this.options.secretKey.trim() !== "" && this.options.secretKey.startsWith("sk_");
10651
+ if (hasValidKeys) {
10652
+ if (this.options.observability !== false) {
10653
+ try {
10654
+ this.observability = new VoltAgentExporter({
10655
+ baseUrl: this.options.baseUrl,
10656
+ publicKey: this.options.publicKey || "",
10657
+ secretKey: this.options.secretKey || "",
10658
+ fetch: this.options.fetch
10659
+ });
10660
+ } catch (error) {
10661
+ this.logger.error("Failed to initialize observability exporter", { error });
10662
+ }
10661
10663
  }
10662
- }
10663
- if (this.options.prompts !== false) {
10664
- try {
10665
- this.prompts = new VoltOpsPromptManagerImpl(this.options);
10666
- } catch (error) {
10667
- this.logger.error("Failed to initialize prompt manager", { error });
10664
+ if (this.options.prompts !== false) {
10665
+ try {
10666
+ this.prompts = new VoltOpsPromptManagerImpl(this.options);
10667
+ } catch (error) {
10668
+ this.logger.error("Failed to initialize prompt manager", { error });
10669
+ }
10668
10670
  }
10669
10671
  }
10670
10672
  this.logger.debug(
@@ -10719,6 +10721,12 @@ var VoltOpsClient = class {
10719
10721
  isObservabilityEnabled() {
10720
10722
  return this.observability !== void 0;
10721
10723
  }
10724
+ /**
10725
+ * Check if the client has valid API keys
10726
+ */
10727
+ hasValidKeys() {
10728
+ return !!(this.options.publicKey && this.options.publicKey.trim() !== "" && this.options.publicKey.startsWith("pk_") && this.options.secretKey && this.options.secretKey.trim() !== "" && this.options.secretKey.startsWith("sk_"));
10729
+ }
10722
10730
  /**
10723
10731
  * Check if prompt management is enabled and configured
10724
10732
  */
@@ -10796,48 +10804,6 @@ var VoltOpsClient = class {
10796
10804
  }, "getPrompt")
10797
10805
  };
10798
10806
  }
10799
- /**
10800
- * Validate API keys and provide helpful error messages
10801
- */
10802
- validateApiKeys(options) {
10803
- const { publicKey, secretKey } = options;
10804
- if (!publicKey || publicKey.trim() === "") {
10805
- this.logger.warn(`
10806
- \u26A0\uFE0F VoltOps Warning: Missing publicKey
10807
-
10808
- VoltOps features will be disabled. To enable:
10809
-
10810
- 1. Get your API keys: https://console.voltagent.dev/settings/projects
10811
- 2. Add to environment:
10812
- VOLTOPS_PUBLIC_KEY=pk_your_public_key_here
10813
-
10814
- 3. Initialize VoltOpsClient:
10815
- const voltOpsClient = new VoltOpsClient({
10816
- publicKey: process.env.VOLTOPS_PUBLIC_KEY!,
10817
- secretKey: process.env.VOLTOPS_SECRET_KEY!
10818
- });
10819
- `);
10820
- return;
10821
- }
10822
- if (!secretKey || secretKey.trim() === "") {
10823
- this.logger.warn(`
10824
- \u26A0\uFE0F VoltOps Warning: Missing secretKey
10825
-
10826
- VoltOps features will be disabled. To enable:
10827
-
10828
- 1. Get your API keys: https://console.voltagent.dev/settings/projects
10829
- 2. Add to environment:
10830
- VOLTOPS_SECRET_KEY=sk_your_secret_key_here
10831
- `);
10832
- return;
10833
- }
10834
- if (!publicKey.startsWith("pk_")) {
10835
- this.logger.warn("\u26A0\uFE0F VoltOps Warning: publicKey should start with 'pk_'");
10836
- }
10837
- if (!secretKey.startsWith("sk_")) {
10838
- this.logger.warn("\u26A0\uFE0F VoltOps Warning: secretKey should start with 'sk_'");
10839
- }
10840
- }
10841
10807
  /**
10842
10808
  * Cleanup resources when client is no longer needed
10843
10809
  */
@@ -12651,11 +12617,14 @@ ${retrieverContext}`;
12651
12617
  options.parentAgentId,
12652
12618
  options.parentHistoryEntryId
12653
12619
  );
12620
+ const userContextToUse = options.parentOperationContext?.userContext || options.userContext || this.defaultUserContext;
12621
+ const userContextObject = userContextToUse ? Object.fromEntries(userContextToUse.entries()) : {};
12654
12622
  const methodLogger = contextualLogger.child({
12655
12623
  userId: options.userId,
12656
12624
  conversationId: options.conversationId,
12657
12625
  executionId: historyEntry.id,
12658
12626
  operationName: options.operationName,
12627
+ userContext: userContextObject,
12659
12628
  // Preserve parent execution ID if present in contextual logger
12660
12629
  ...options.parentHistoryEntryId && {
12661
12630
  parentExecutionId: options.parentHistoryEntryId
@@ -12663,7 +12632,7 @@ ${retrieverContext}`;
12663
12632
  });
12664
12633
  const opContext = {
12665
12634
  operationId: historyEntry.id,
12666
- userContext: (options.parentOperationContext?.userContext || options.userContext || this.defaultUserContext) ?? /* @__PURE__ */ new Map(),
12635
+ userContext: userContextToUse ?? /* @__PURE__ */ new Map(),
12667
12636
  historyEntry,
12668
12637
  isActive: true,
12669
12638
  parentAgentId: options.parentAgentId,
@@ -15847,6 +15816,8 @@ var MCPConfiguration = class {
15847
15816
  };
15848
15817
 
15849
15818
  // src/server/api.ts
15819
+ var import_promises = __toESM(require("fs/promises"));
15820
+ var import_node_path4 = __toESM(require("path"));
15850
15821
  var import_swagger_ui = require("@hono/swagger-ui");
15851
15822
  var import_zod_openapi3 = require("@hono/zod-openapi");
15852
15823
  var import_cors = require("hono/cors");
@@ -17973,6 +17944,88 @@ app.post("/updates/:packageName", async (c) => {
17973
17944
  );
17974
17945
  }
17975
17946
  });
17947
+ app.post("/setup-observability", async (c) => {
17948
+ try {
17949
+ const body = await c.req.json();
17950
+ const { publicKey, secretKey } = body;
17951
+ if (!publicKey || !secretKey) {
17952
+ return c.json(
17953
+ {
17954
+ success: false,
17955
+ error: "Missing publicKey or secretKey"
17956
+ },
17957
+ 400
17958
+ );
17959
+ }
17960
+ const envPath = import_node_path4.default.join(process.cwd(), ".env");
17961
+ try {
17962
+ let envContent = "";
17963
+ try {
17964
+ envContent = await import_promises.default.readFile(envPath, "utf-8");
17965
+ } catch (_error) {
17966
+ logger.debug(".env file not found, will create new one");
17967
+ }
17968
+ const lines = envContent.split("\n");
17969
+ let publicKeyUpdated = false;
17970
+ let secretKeyUpdated = false;
17971
+ const updatedLines = lines.map((line) => {
17972
+ const trimmedLine = line.trim();
17973
+ if (trimmedLine.startsWith("VOLTAGENT_PUBLIC_KEY=") || trimmedLine.startsWith("# VOLTAGENT_PUBLIC_KEY=") || trimmedLine.startsWith("#VOLTAGENT_PUBLIC_KEY=")) {
17974
+ publicKeyUpdated = true;
17975
+ return `VOLTAGENT_PUBLIC_KEY=${publicKey}`;
17976
+ }
17977
+ if (trimmedLine.startsWith("VOLTAGENT_SECRET_KEY=") || trimmedLine.startsWith("# VOLTAGENT_SECRET_KEY=") || trimmedLine.startsWith("#VOLTAGENT_SECRET_KEY=")) {
17978
+ secretKeyUpdated = true;
17979
+ return `VOLTAGENT_SECRET_KEY=${secretKey}`;
17980
+ }
17981
+ return line;
17982
+ });
17983
+ envContent = updatedLines.join("\n");
17984
+ if (!publicKeyUpdated || !secretKeyUpdated) {
17985
+ if (!envContent.endsWith("\n") && envContent.length > 0) {
17986
+ envContent += "\n";
17987
+ }
17988
+ if (!publicKeyUpdated && !secretKeyUpdated) {
17989
+ envContent += `
17990
+ # VoltAgent Observability
17991
+ VOLTAGENT_PUBLIC_KEY=${publicKey}
17992
+ VOLTAGENT_SECRET_KEY=${secretKey}
17993
+ `;
17994
+ } else if (!publicKeyUpdated) {
17995
+ envContent += `VOLTAGENT_PUBLIC_KEY=${publicKey}
17996
+ `;
17997
+ } else if (!secretKeyUpdated) {
17998
+ envContent += `VOLTAGENT_SECRET_KEY=${secretKey}
17999
+ `;
18000
+ }
18001
+ }
18002
+ await import_promises.default.writeFile(envPath, envContent);
18003
+ logger.info("Observability configuration updated in .env file");
18004
+ return c.json({
18005
+ success: true,
18006
+ message: "Observability configured successfully. Please restart your application."
18007
+ });
18008
+ } catch (error) {
18009
+ logger.error("Failed to update .env file:", { error });
18010
+ return c.json(
18011
+ {
18012
+ success: false,
18013
+ error: "Failed to update .env file"
18014
+ },
18015
+ 500
18016
+ );
18017
+ }
18018
+ } catch (error) {
18019
+ logger.error("Failed to setup observability:", { error });
18020
+ return c.json(
18021
+ {
18022
+ success: false,
18023
+ error: error instanceof Error ? error.message : "Failed to setup observability"
18024
+ },
18025
+ 500
18026
+ );
18027
+ }
18028
+ });
17976
18029
  app.doc("/doc", {
17977
18030
  openapi: "3.1.0",
17978
18031
  info: {
@@ -17985,25 +18038,25 @@ app.doc("/doc", {
17985
18038
  function registerCustomEndpoint(endpoint) {
17986
18039
  try {
17987
18040
  const validatedEndpoint = validateCustomEndpoint(endpoint);
17988
- const { path: path3, method, handler } = validatedEndpoint;
18041
+ const { path: path4, method, handler } = validatedEndpoint;
17989
18042
  switch (method) {
17990
18043
  case "get":
17991
- app.get(path3, handler);
18044
+ app.get(path4, handler);
17992
18045
  break;
17993
18046
  case "post":
17994
- app.post(path3, handler);
18047
+ app.post(path4, handler);
17995
18048
  break;
17996
18049
  case "put":
17997
- app.put(path3, handler);
18050
+ app.put(path4, handler);
17998
18051
  break;
17999
18052
  case "patch":
18000
- app.patch(path3, handler);
18053
+ app.patch(path4, handler);
18001
18054
  break;
18002
18055
  case "delete":
18003
- app.delete(path3, handler);
18056
+ app.delete(path4, handler);
18004
18057
  break;
18005
18058
  case "options":
18006
- app.options(path3, handler);
18059
+ app.options(path4, handler);
18007
18060
  break;
18008
18061
  default:
18009
18062
  throw new CustomEndpointError(`Unsupported HTTP method: ${method}`);
@@ -18029,25 +18082,25 @@ function registerCustomEndpoints(endpoints) {
18029
18082
  return;
18030
18083
  }
18031
18084
  for (const endpoint of validatedEndpoints) {
18032
- const { path: path3, method, handler } = endpoint;
18085
+ const { path: path4, method, handler } = endpoint;
18033
18086
  switch (method) {
18034
18087
  case "get":
18035
- app.get(path3, handler);
18088
+ app.get(path4, handler);
18036
18089
  break;
18037
18090
  case "post":
18038
- app.post(path3, handler);
18091
+ app.post(path4, handler);
18039
18092
  break;
18040
18093
  case "put":
18041
- app.put(path3, handler);
18094
+ app.put(path4, handler);
18042
18095
  break;
18043
18096
  case "patch":
18044
- app.patch(path3, handler);
18097
+ app.patch(path4, handler);
18045
18098
  break;
18046
18099
  case "delete":
18047
- app.delete(path3, handler);
18100
+ app.delete(path4, handler);
18048
18101
  break;
18049
18102
  case "options":
18050
- app.options(path3, handler);
18103
+ app.options(path4, handler);
18051
18104
  break;
18052
18105
  default:
18053
18106
  throw new CustomEndpointError(`Unsupported HTTP method: ${method}`);
@@ -18363,9 +18416,9 @@ var printServerStartup = /* @__PURE__ */ __name((port, config) => {
18363
18416
  const methodOrder = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
18364
18417
  methodOrder.forEach((method) => {
18365
18418
  if (methodGroups[method]) {
18366
- methodGroups[method].forEach((path3) => {
18419
+ methodGroups[method].forEach((path4) => {
18367
18420
  console.log(
18368
- `${colors.dim} ${method.padEnd(6)} ${colors.reset}${colors.white}${path3}${colors.reset}`
18421
+ `${colors.dim} ${method.padEnd(6)} ${colors.reset}${colors.white}${path4}${colors.reset}`
18369
18422
  );
18370
18423
  });
18371
18424
  }
@@ -18419,8 +18472,8 @@ var startServer = /* @__PURE__ */ __name(async (config) => {
18419
18472
  const ws = createWebSocketServer();
18420
18473
  server.addListener("upgrade", (req, socket, head) => {
18421
18474
  const url = new URL(req.url || "", "http://localhost");
18422
- const path3 = url.pathname;
18423
- if (path3.startsWith("/ws")) {
18475
+ const path4 = url.pathname;
18476
+ if (path4.startsWith("/ws")) {
18424
18477
  ws.handleUpgrade(req, socket, head, (websocket) => {
18425
18478
  ws.emit("connection", websocket, req);
18426
18479
  });
@@ -18449,6 +18502,15 @@ var startServer = /* @__PURE__ */ __name(async (config) => {
18449
18502
  );
18450
18503
  }, "startServer");
18451
18504
 
18505
+ // src/utils/voltops-validation.ts
18506
+ function isValidVoltOpsKeys(publicKey, secretKey) {
18507
+ if (!publicKey || !secretKey) {
18508
+ return false;
18509
+ }
18510
+ return publicKey.startsWith("pk_") && secretKey.startsWith("sk_");
18511
+ }
18512
+ __name(isValidVoltOpsKeys, "isValidVoltOpsKeys");
18513
+
18452
18514
  // src/voltagent.ts
18453
18515
  var isTelemetryInitializedByVoltAgent = false;
18454
18516
  var registeredProvider = null;
@@ -18477,7 +18539,8 @@ var VoltAgent = class {
18477
18539
  }
18478
18540
  if (options.logger) {
18479
18541
  this.registry.setGlobalLogger(options.logger);
18480
- } else if (options.telemetryExporter) {
18542
+ }
18543
+ if (options.telemetryExporter) {
18481
18544
  this.logger.warn(
18482
18545
  `\u26A0\uFE0F DEPRECATION WARNING: 'telemetryExporter' parameter is deprecated!
18483
18546
 
@@ -18501,6 +18564,26 @@ https://voltagent.dev/docs/observability/developer-console/#migration-guide-from
18501
18564
  }
18502
18565
  this.initializeGlobalTelemetry(options.telemetryExporter);
18503
18566
  }
18567
+ if (!options.voltOpsClient && !options.telemetryExporter) {
18568
+ const publicKey = process.env.VOLTAGENT_PUBLIC_KEY;
18569
+ const secretKey = process.env.VOLTAGENT_SECRET_KEY;
18570
+ if (publicKey && secretKey && isValidVoltOpsKeys(publicKey, secretKey)) {
18571
+ try {
18572
+ const autoClient = new VoltOpsClient({
18573
+ publicKey,
18574
+ secretKey
18575
+ });
18576
+ this.registry.setGlobalVoltOpsClient(autoClient);
18577
+ if (autoClient.observability) {
18578
+ this.registry.setGlobalVoltAgentExporter(autoClient.observability);
18579
+ this.initializeGlobalTelemetry(autoClient.observability);
18580
+ }
18581
+ this.logger.debug("VoltOpsClient auto-configured from environment variables");
18582
+ } catch (error) {
18583
+ this.logger.debug("Could not auto-configure VoltOpsClient", { error });
18584
+ }
18585
+ }
18586
+ }
18504
18587
  this.registerAgents(options.agents);
18505
18588
  if (options.workflows) {
18506
18589
  this.registerWorkflows(options.workflows);