@voltagent/core 1.1.1 → 1.1.2

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/README.md CHANGED
@@ -95,10 +95,10 @@ This command guides you through setup.
95
95
  You'll see the starter code in `src/index.ts`, which now registers both an agent and a comprehensive workflow example found in `src/workflows/index.ts`.
96
96
 
97
97
  ```typescript
98
- import { VoltAgent, Agent } from "@voltagent/core";
99
- import { LibSQLStorage } from "@voltagent/libsql";
98
+ import { VoltAgent, Agent, Memory } from "@voltagent/core";
99
+ import { LibSQLMemoryAdapter } from "@voltagent/libsql";
100
100
  import { createPinoLogger } from "@voltagent/logger";
101
- import { VercelAIProvider } from "@voltagent/vercel-ai";
101
+ import { honoServer } from "@voltagent/server-hono";
102
102
  import { openai } from "@ai-sdk/openai";
103
103
  import { expenseApprovalWorkflow } from "./workflows";
104
104
  import { weatherTool } from "./tools";
@@ -109,17 +109,18 @@ const logger = createPinoLogger({
109
109
  level: "info",
110
110
  });
111
111
 
112
+ // Optional persistent memory (remove to use default in-memory)
113
+ const memory = new Memory({
114
+ storage: new LibSQLMemoryAdapter({ url: "file:./.voltagent/memory.db" }),
115
+ });
116
+
112
117
  // A simple, general-purpose agent for the project.
113
118
  const agent = new Agent({
114
119
  name: "my-agent",
115
120
  instructions: "A helpful assistant that can check weather and help with various tasks",
116
- llm: new VercelAIProvider(),
117
121
  model: openai("gpt-4o-mini"),
118
122
  tools: [weatherTool],
119
- memory: new LibSQLStorage({
120
- url: "file:./.voltagent/memory.db",
121
- logger: logger.child({ component: "libsql" }),
122
- }),
123
+ memory,
123
124
  });
124
125
 
125
126
  // Initialize VoltAgent with your agent(s) and workflow(s)
@@ -130,6 +131,7 @@ new VoltAgent({
130
131
  workflows: {
131
132
  expenseApprovalWorkflow,
132
133
  },
134
+ server: honoServer(),
133
135
  logger,
134
136
  });
135
137
  ```
package/dist/index.d.mts CHANGED
@@ -1209,6 +1209,9 @@ declare class Memory {
1209
1209
  currentQuery?: string;
1210
1210
  traceId?: string;
1211
1211
  logger?: Logger;
1212
+ semanticLimit?: number;
1213
+ semanticThreshold?: number;
1214
+ mergeStrategy?: "prepend" | "append" | "interleave";
1212
1215
  }): Promise<UIMessage[]>;
1213
1216
  /**
1214
1217
  * Internal: Set resource ID (agent ID)
@@ -4792,7 +4795,7 @@ type AgentConfig<SCHEMA extends z.ZodTypeAny> = {
4792
4795
  * purpose: "Process user data and generate personalized content",
4793
4796
  * input: z.object({ userId: z.string(), userType: z.enum(["admin", "user"]) }),
4794
4797
  * result: z.object({ processed: z.boolean(), content: z.string() }),
4795
- * memory: new LibSQLStorage({ url: "file:memory.db" }) // Optional workflow-specific memory
4798
+ * memory: new Memory({ storage: new LibSQLMemoryAdapter({ url: "file:memory.db" }) }) // Optional workflow-specific memory
4796
4799
  * })
4797
4800
  * .andThen({
4798
4801
  * id: "fetch-user",
@@ -4822,7 +4825,7 @@ type AgentConfig<SCHEMA extends z.ZodTypeAny> = {
4822
4825
  * // Run with optional memory override
4823
4826
  * const result = await workflow.run(
4824
4827
  * { userId: "123", userType: "admin" },
4825
- * { memory: new LibSQLStorage({ url: "file:memory.db" }) }
4828
+ * { memory: new Memory({ storage: new LibSQLMemoryAdapter({ url: "file:memory.db" }) }) }
4826
4829
  * );
4827
4830
  * ```
4828
4831
  */
package/dist/index.d.ts CHANGED
@@ -1209,6 +1209,9 @@ declare class Memory {
1209
1209
  currentQuery?: string;
1210
1210
  traceId?: string;
1211
1211
  logger?: Logger;
1212
+ semanticLimit?: number;
1213
+ semanticThreshold?: number;
1214
+ mergeStrategy?: "prepend" | "append" | "interleave";
1212
1215
  }): Promise<UIMessage[]>;
1213
1216
  /**
1214
1217
  * Internal: Set resource ID (agent ID)
@@ -4792,7 +4795,7 @@ type AgentConfig<SCHEMA extends z.ZodTypeAny> = {
4792
4795
  * purpose: "Process user data and generate personalized content",
4793
4796
  * input: z.object({ userId: z.string(), userType: z.enum(["admin", "user"]) }),
4794
4797
  * result: z.object({ processed: z.boolean(), content: z.string() }),
4795
- * memory: new LibSQLStorage({ url: "file:memory.db" }) // Optional workflow-specific memory
4798
+ * memory: new Memory({ storage: new LibSQLMemoryAdapter({ url: "file:memory.db" }) }) // Optional workflow-specific memory
4796
4799
  * })
4797
4800
  * .andThen({
4798
4801
  * id: "fetch-user",
@@ -4822,7 +4825,7 @@ type AgentConfig<SCHEMA extends z.ZodTypeAny> = {
4822
4825
  * // Run with optional memory override
4823
4826
  * const result = await workflow.run(
4824
4827
  * { userId: "123", userType: "admin" },
4825
- * { memory: new LibSQLStorage({ url: "file:memory.db" }) }
4828
+ * { memory: new Memory({ storage: new LibSQLMemoryAdapter({ url: "file:memory.db" }) }) }
4826
4829
  * );
4827
4830
  * ```
4828
4831
  */
package/dist/index.js CHANGED
@@ -1345,6 +1345,7 @@ function andWorkflow(workflow) {
1345
1345
  __name(andWorkflow, "andWorkflow");
1346
1346
 
1347
1347
  // src/workflow/core.ts
1348
+ var import_node_crypto = __toESM(require("crypto"));
1348
1349
  var import_zod = require("zod");
1349
1350
 
1350
1351
  // src/memory/errors.ts
@@ -1757,7 +1758,7 @@ var Memory = class {
1757
1758
  try {
1758
1759
  const queryVector = await this.getEmbedding(currentQuery);
1759
1760
  const semanticResults = await this.vector.search(queryVector, {
1760
- limit: options?.semanticLimit || 5,
1761
+ limit: options?.semanticLimit ?? 5,
1761
1762
  filter: { userId, conversationId },
1762
1763
  threshold: options?.semanticThreshold
1763
1764
  });
@@ -1769,7 +1770,7 @@ var Memory = class {
1769
1770
  return this.mergeMessages(
1770
1771
  recentMessages,
1771
1772
  semanticMessages,
1772
- options?.mergeStrategy || "prepend"
1773
+ options?.mergeStrategy ?? "append"
1773
1774
  );
1774
1775
  } catch (error) {
1775
1776
  console.warn("Semantic search failed, returning recent messages only:", error);
@@ -1781,12 +1782,14 @@ var Memory = class {
1781
1782
  */
1782
1783
  async getMessagesByIds(userId, conversationId, messageIds) {
1783
1784
  const allMessages = await this.storage.getMessages(userId, conversationId);
1784
- return allMessages.filter((msg) => messageIds.includes(msg.id));
1785
+ const byId = new Map(allMessages.map((m) => [m.id, m]));
1786
+ const ordered = messageIds.map((id) => byId.get(id)).filter((m) => Boolean(m));
1787
+ return ordered;
1785
1788
  }
1786
1789
  /**
1787
1790
  * Merge two arrays of messages, removing duplicates
1788
1791
  */
1789
- mergeMessages(recentMessages, semanticMessages, strategy = "prepend") {
1792
+ mergeMessages(recentMessages, semanticMessages, strategy = "append") {
1790
1793
  const recentIds = new Set(recentMessages.map((m) => m.id));
1791
1794
  const uniqueSemanticMessages = semanticMessages.filter((m) => !recentIds.has(m.id));
1792
1795
  switch (strategy) {
@@ -2197,9 +2200,9 @@ Remember:
2197
2200
  options.currentQuery,
2198
2201
  {
2199
2202
  limit: options.limit,
2200
- semanticLimit: 5,
2201
- semanticThreshold: 0.7,
2202
- mergeStrategy: "prepend"
2203
+ semanticLimit: options.semanticLimit ?? 5,
2204
+ semanticThreshold: options.semanticThreshold ?? 0.7,
2205
+ mergeStrategy: options.mergeStrategy ?? "append"
2203
2206
  }
2204
2207
  );
2205
2208
  } else {
@@ -4725,7 +4728,7 @@ function createWorkflow({
4725
4728
  if (options?.resumeFrom?.executionId) {
4726
4729
  executionId = options.resumeFrom.executionId;
4727
4730
  } else {
4728
- executionId = options?.executionId || crypto.randomUUID();
4731
+ executionId = options?.executionId || import_node_crypto.default.randomUUID();
4729
4732
  }
4730
4733
  const streamController = externalStreamController || null;
4731
4734
  const observability = getObservability();
@@ -5348,7 +5351,7 @@ function createWorkflow({
5348
5351
  }, "run"),
5349
5352
  stream: /* @__PURE__ */ __name((input2, options) => {
5350
5353
  const streamController = new WorkflowStreamController();
5351
- const executionId = options?.executionId || crypto.randomUUID();
5354
+ const executionId = options?.executionId || import_node_crypto.default.randomUUID();
5352
5355
  const originalInput = input2;
5353
5356
  let resultResolve;
5354
5357
  let resultReject;
@@ -5858,14 +5861,14 @@ function createSuspendController() {
5858
5861
  __name(createSuspendController, "createSuspendController");
5859
5862
 
5860
5863
  // src/agent/agent.ts
5861
- var crypto4 = __toESM(require("crypto"));
5864
+ var crypto5 = __toESM(require("crypto"));
5862
5865
  var import_api8 = require("@opentelemetry/api");
5863
5866
  var import_utils13 = require("@voltagent/internal/utils");
5864
5867
  var import_ai = require("ai");
5865
5868
  var import_zod3 = require("zod");
5866
5869
 
5867
5870
  // src/memory/manager/memory-manager.ts
5868
- var import_node_crypto = __toESM(require("crypto"));
5871
+ var import_node_crypto2 = __toESM(require("crypto"));
5869
5872
 
5870
5873
  // src/utils/node-utils.ts
5871
5874
  var NodeType = /* @__PURE__ */ ((NodeType2) => {
@@ -6174,6 +6177,9 @@ var MemoryManager = class {
6174
6177
  conversationId,
6175
6178
  options.currentQuery,
6176
6179
  options.semanticLimit || limit,
6180
+ options.semanticLimit,
6181
+ options.semanticThreshold,
6182
+ options.mergeStrategy,
6177
6183
  memoryLogger,
6178
6184
  options.traceContext,
6179
6185
  options.parentMemorySpan
@@ -6280,7 +6286,7 @@ var MemoryManager = class {
6280
6286
  * PRESERVED FROM ORIGINAL
6281
6287
  */
6282
6288
  async prepareConversationContext(context5, input, userId, conversationIdParam, contextLimit = 10) {
6283
- const conversationId = conversationIdParam || import_node_crypto.default.randomUUID();
6289
+ const conversationId = conversationIdParam || import_node_crypto2.default.randomUUID();
6284
6290
  if (contextLimit === 0) {
6285
6291
  return { messages: [], conversationId };
6286
6292
  }
@@ -6385,7 +6391,7 @@ var MemoryManager = class {
6385
6391
  try {
6386
6392
  if (typeof input === "string") {
6387
6393
  const userMessage = {
6388
- id: import_node_crypto.default.randomUUID(),
6394
+ id: import_node_crypto2.default.randomUUID(),
6389
6395
  role: "user",
6390
6396
  parts: [{ type: "text", text: input }]
6391
6397
  };
@@ -6507,7 +6513,7 @@ var MemoryManager = class {
6507
6513
  * Perform semantic search with proper span hierarchy
6508
6514
  * Extracted from getMessages for clarity
6509
6515
  */
6510
- async performSemanticSearch(userId, conversationId, query, limit, logger, traceContext, parentMemorySpan) {
6516
+ async performSemanticSearch(userId, conversationId, query, limit, semanticLimit, semanticThreshold, mergeStrategy, logger, traceContext, parentMemorySpan) {
6511
6517
  if (!this.conversationMemory?.hasVectorSupport?.()) {
6512
6518
  logger.debug("Vector support not available, falling back to regular retrieval");
6513
6519
  return this.conversationMemory?.getMessages(userId, conversationId, { limit }) || [];
@@ -6560,7 +6566,10 @@ var MemoryManager = class {
6560
6566
  limit,
6561
6567
  useSemanticSearch: true,
6562
6568
  currentQuery: query,
6563
- logger
6569
+ logger,
6570
+ semanticLimit,
6571
+ semanticThreshold,
6572
+ mergeStrategy
6564
6573
  });
6565
6574
  });
6566
6575
  traceContext.endChildSpan(vectorSpan, "completed", {
@@ -6584,7 +6593,10 @@ var MemoryManager = class {
6584
6593
  limit,
6585
6594
  useSemanticSearch: true,
6586
6595
  currentQuery: query,
6587
- logger
6596
+ logger,
6597
+ semanticLimit,
6598
+ semanticThreshold,
6599
+ mergeStrategy
6588
6600
  }) || [];
6589
6601
  }
6590
6602
  /**
@@ -7074,10 +7086,10 @@ __name(createTool, "createTool");
7074
7086
  var tool = createTool;
7075
7087
 
7076
7088
  // src/utils/message-converter.ts
7077
- var crypto3 = __toESM(require("crypto"));
7089
+ var crypto4 = __toESM(require("crypto"));
7078
7090
  async function convertResponseMessagesToUIMessages(responseMessages) {
7079
7091
  const uiMessage = {
7080
- id: crypto3.randomUUID(),
7092
+ id: crypto4.randomUUID(),
7081
7093
  role: "assistant",
7082
7094
  parts: []
7083
7095
  };
@@ -7205,7 +7217,7 @@ function convertModelMessagesToUIMessages(messages) {
7205
7217
  for (const part of message.content) {
7206
7218
  if (part.type === "tool-result") {
7207
7219
  uiMessages.push({
7208
- id: crypto3.randomUUID(),
7220
+ id: crypto4.randomUUID(),
7209
7221
  role: "assistant",
7210
7222
  parts: [
7211
7223
  {
@@ -7224,7 +7236,7 @@ function convertModelMessagesToUIMessages(messages) {
7224
7236
  continue;
7225
7237
  }
7226
7238
  const ui = {
7227
- id: crypto3.randomUUID(),
7239
+ id: crypto4.randomUUID(),
7228
7240
  role: message.role,
7229
7241
  parts: []
7230
7242
  };
@@ -9374,7 +9386,7 @@ var Agent = class {
9374
9386
  });
9375
9387
  if (oc.userId && oc.conversationId) {
9376
9388
  const message = {
9377
- id: crypto4.randomUUID(),
9389
+ id: crypto5.randomUUID(),
9378
9390
  role: "assistant",
9379
9391
  parts: [
9380
9392
  {
@@ -9385,7 +9397,7 @@ var Agent = class {
9385
9397
  };
9386
9398
  await this.memoryManager.saveMessage(oc, message, oc.userId, oc.conversationId);
9387
9399
  const step = {
9388
- id: crypto4.randomUUID(),
9400
+ id: crypto5.randomUUID(),
9389
9401
  type: "text",
9390
9402
  content: (0, import_utils13.safeStringify)(result.object),
9391
9403
  role: "assistant",
@@ -9524,7 +9536,7 @@ var Agent = class {
9524
9536
  onFinish: /* @__PURE__ */ __name(async (finalResult) => {
9525
9537
  if (oc.userId && oc.conversationId) {
9526
9538
  const message = {
9527
- id: crypto4.randomUUID(),
9539
+ id: crypto5.randomUUID(),
9528
9540
  role: "assistant",
9529
9541
  parts: [
9530
9542
  {
@@ -9535,7 +9547,7 @@ var Agent = class {
9535
9547
  };
9536
9548
  await this.memoryManager.saveMessage(oc, message, oc.userId, oc.conversationId);
9537
9549
  const step = {
9538
- id: crypto4.randomUUID(),
9550
+ id: crypto5.randomUUID(),
9539
9551
  type: "text",
9540
9552
  content: (0, import_utils13.safeStringify)(finalResult.object),
9541
9553
  role: "assistant",
@@ -9633,7 +9645,7 @@ var Agent = class {
9633
9645
  * Transitional helper to gradually adopt OperationContext across methods
9634
9646
  */
9635
9647
  createOperationContext(input, options) {
9636
- const operationId = crypto4.randomUUID();
9648
+ const operationId = crypto5.randomUUID();
9637
9649
  const startTimeDate = /* @__PURE__ */ new Date();
9638
9650
  const runtimeContext = toContextMap(options?.context);
9639
9651
  const context5 = new Map([
@@ -9790,7 +9802,7 @@ var Agent = class {
9790
9802
  const systemMessage = await this.getSystemMessage(input, oc, options);
9791
9803
  if (systemMessage) {
9792
9804
  const systemUIMessage = {
9793
- id: crypto4.randomUUID(),
9805
+ id: crypto5.randomUUID(),
9794
9806
  role: "system",
9795
9807
  parts: [
9796
9808
  {
@@ -9809,8 +9821,8 @@ var Agent = class {
9809
9821
  const useSemanticSearch = options?.semanticMemory?.enabled ?? this.hasSemanticSearchSupport();
9810
9822
  const currentQuery = useSemanticSearch ? this.extractUserQuery(input) : void 0;
9811
9823
  const semanticLimit = options?.semanticMemory?.semanticLimit ?? 5;
9812
- const semanticThreshold = options?.semanticMemory?.semanticThreshold ?? 0;
9813
- const mergeStrategy = options?.semanticMemory?.mergeStrategy ?? "prepend";
9824
+ const semanticThreshold = options?.semanticMemory?.semanticThreshold ?? 0.7;
9825
+ const mergeStrategy = options?.semanticMemory?.mergeStrategy ?? "append";
9814
9826
  const isSemanticSearch = useSemanticSearch && currentQuery;
9815
9827
  const traceContext = oc.traceContext;
9816
9828
  if (traceContext) {
@@ -9869,7 +9881,7 @@ var Agent = class {
9869
9881
  }
9870
9882
  });
9871
9883
  if (isSemanticSearch && !oc.conversationId) {
9872
- oc.conversationId = crypto4.randomUUID();
9884
+ oc.conversationId = crypto5.randomUUID();
9873
9885
  }
9874
9886
  messages.push(...memoryResult);
9875
9887
  if (isSemanticSearch && oc.userId && oc.conversationId) {
@@ -9889,7 +9901,7 @@ var Agent = class {
9889
9901
  }
9890
9902
  if (typeof input === "string") {
9891
9903
  messages.push({
9892
- id: crypto4.randomUUID(),
9904
+ id: crypto5.randomUUID(),
9893
9905
  role: "user",
9894
9906
  parts: [{ type: "text", text: input }]
9895
9907
  });
@@ -10230,7 +10242,7 @@ ${toolkit.instructions}`;
10230
10242
  label: tool2.name,
10231
10243
  attributes: {
10232
10244
  "tool.name": tool2.name,
10233
- "tool.call.id": crypto4.randomUUID(),
10245
+ "tool.call.id": crypto5.randomUUID(),
10234
10246
  input: args ? (0, import_utils13.safeStringify)(args) : void 0
10235
10247
  },
10236
10248
  kind: import_api8.SpanKind.CLIENT
@@ -11339,7 +11351,7 @@ var import_node_fs2 = __toESM(require("fs"));
11339
11351
  var import_node_path2 = __toESM(require("path"));
11340
11352
 
11341
11353
  // src/utils/update/cache.ts
11342
- var import_node_crypto2 = __toESM(require("crypto"));
11354
+ var import_node_crypto3 = __toESM(require("crypto"));
11343
11355
  var import_node_fs = __toESM(require("fs"));
11344
11356
  var import_node_os = __toESM(require("os"));
11345
11357
  var import_node_path = __toESM(require("path"));
@@ -11374,7 +11386,7 @@ var getSystemCacheDir = /* @__PURE__ */ __name(() => {
11374
11386
  }, "getSystemCacheDir");
11375
11387
  var getCacheFilePath = /* @__PURE__ */ __name((projectPath) => {
11376
11388
  const normalizedPath = import_node_path.default.resolve(projectPath);
11377
- const projectHash = import_node_crypto2.default.createHash("sha256").update(normalizedPath).digest("hex").substring(0, 12);
11389
+ const projectHash = import_node_crypto3.default.createHash("sha256").update(normalizedPath).digest("hex").substring(0, 12);
11378
11390
  const cacheDir = getSystemCacheDir();
11379
11391
  return import_node_path.default.join(cacheDir, `update-check-${projectHash}.json`);
11380
11392
  }, "getCacheFilePath");
@@ -11387,7 +11399,7 @@ var ensureCacheDir = /* @__PURE__ */ __name(() => {
11387
11399
  var getPackageJsonHash = /* @__PURE__ */ __name((packageJsonPath) => {
11388
11400
  try {
11389
11401
  const content = import_node_fs.default.readFileSync(packageJsonPath, "utf8");
11390
- return import_node_crypto2.default.createHash("md5").update(content).digest("hex");
11402
+ return import_node_crypto3.default.createHash("md5").update(content).digest("hex");
11391
11403
  } catch (error) {
11392
11404
  const logger = new LoggerProxy({ component: "update-cache" });
11393
11405
  logger.error("Error reading package.json for hash", { error });