@voltagent/core 2.6.3 → 2.6.4
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -9033,6 +9033,7 @@ declare class MemoryManager {
|
|
|
9033
9033
|
* Ensure conversation exists (background task)
|
|
9034
9034
|
* PRESERVED FROM ORIGINAL
|
|
9035
9035
|
*/
|
|
9036
|
+
private isConversationAlreadyExistsError;
|
|
9036
9037
|
private ensureConversationExists;
|
|
9037
9038
|
/**
|
|
9038
9039
|
* Save current input (background task)
|
package/dist/index.d.ts
CHANGED
|
@@ -9033,6 +9033,7 @@ declare class MemoryManager {
|
|
|
9033
9033
|
* Ensure conversation exists (background task)
|
|
9034
9034
|
* PRESERVED FROM ORIGINAL
|
|
9035
9035
|
*/
|
|
9036
|
+
private isConversationAlreadyExistsError;
|
|
9036
9037
|
private ensureConversationExists;
|
|
9037
9038
|
/**
|
|
9038
9039
|
* Save current input (background task)
|
package/dist/index.js
CHANGED
|
@@ -12899,6 +12899,17 @@ var MemoryManager = class {
|
|
|
12899
12899
|
});
|
|
12900
12900
|
try {
|
|
12901
12901
|
await trace13.withSpan(span, async () => {
|
|
12902
|
+
const ensuredConversation = await this.ensureConversationExists(
|
|
12903
|
+
context8,
|
|
12904
|
+
userId,
|
|
12905
|
+
conversationId,
|
|
12906
|
+
context8.input
|
|
12907
|
+
);
|
|
12908
|
+
if (!ensuredConversation) {
|
|
12909
|
+
throw new Error(
|
|
12910
|
+
`Failed to ensure conversation exists before step persistence for conversation ${conversationId}`
|
|
12911
|
+
);
|
|
12912
|
+
}
|
|
12902
12913
|
await this.conversationMemory?.saveConversationSteps?.(steps);
|
|
12903
12914
|
});
|
|
12904
12915
|
trace13.endChildSpan(span, "completed", {
|
|
@@ -13101,7 +13112,17 @@ var MemoryManager = class {
|
|
|
13101
13112
|
id: `conversation-and-input-${conversationId}-${Date.now()}`,
|
|
13102
13113
|
operation: /* @__PURE__ */ __name(async () => {
|
|
13103
13114
|
try {
|
|
13104
|
-
await this.ensureConversationExists(
|
|
13115
|
+
const ensuredConversation = await this.ensureConversationExists(
|
|
13116
|
+
context8,
|
|
13117
|
+
userId,
|
|
13118
|
+
conversationId,
|
|
13119
|
+
input
|
|
13120
|
+
);
|
|
13121
|
+
if (!ensuredConversation) {
|
|
13122
|
+
throw new Error(
|
|
13123
|
+
`Failed to ensure conversation exists before input persistence for conversation ${conversationId}`
|
|
13124
|
+
);
|
|
13125
|
+
}
|
|
13105
13126
|
await this.saveCurrentInput(context8, input, userId, conversationId);
|
|
13106
13127
|
} catch (error) {
|
|
13107
13128
|
context8.logger.error("[Memory] Failed to setup conversation and save input", {
|
|
@@ -13146,8 +13167,28 @@ var MemoryManager = class {
|
|
|
13146
13167
|
* Ensure conversation exists (background task)
|
|
13147
13168
|
* PRESERVED FROM ORIGINAL
|
|
13148
13169
|
*/
|
|
13170
|
+
isConversationAlreadyExistsError(error) {
|
|
13171
|
+
if (!error || typeof error !== "object") {
|
|
13172
|
+
return false;
|
|
13173
|
+
}
|
|
13174
|
+
const record = error;
|
|
13175
|
+
const code = typeof record.code === "string" ? record.code : "";
|
|
13176
|
+
const duplicateCodes = /* @__PURE__ */ new Set([
|
|
13177
|
+
"CONVERSATION_ALREADY_EXISTS",
|
|
13178
|
+
"23505",
|
|
13179
|
+
// PostgreSQL unique violation
|
|
13180
|
+
"SQLITE_CONSTRAINT_PRIMARYKEY",
|
|
13181
|
+
"SQLITE_CONSTRAINT_UNIQUE",
|
|
13182
|
+
"SQLITE_CONSTRAINT"
|
|
13183
|
+
]);
|
|
13184
|
+
if (duplicateCodes.has(code)) {
|
|
13185
|
+
return true;
|
|
13186
|
+
}
|
|
13187
|
+
const message = typeof record.message === "string" ? record.message.toLowerCase() : "";
|
|
13188
|
+
return message.includes("already exists") || message.includes("duplicate");
|
|
13189
|
+
}
|
|
13149
13190
|
async ensureConversationExists(context8, userId, conversationId, input) {
|
|
13150
|
-
if (!this.conversationMemory) return;
|
|
13191
|
+
if (!this.conversationMemory) return false;
|
|
13151
13192
|
try {
|
|
13152
13193
|
const existingConversation = await this.conversationMemory.getConversation(conversationId);
|
|
13153
13194
|
if (!existingConversation) {
|
|
@@ -13165,7 +13206,7 @@ var MemoryManager = class {
|
|
|
13165
13206
|
title
|
|
13166
13207
|
});
|
|
13167
13208
|
} catch (createError) {
|
|
13168
|
-
if (createError
|
|
13209
|
+
if (this.isConversationAlreadyExistsError(createError)) {
|
|
13169
13210
|
context8.logger.debug("[Memory] Conversation already exists (race condition handled)", {
|
|
13170
13211
|
conversationId
|
|
13171
13212
|
});
|
|
@@ -13178,10 +13219,12 @@ var MemoryManager = class {
|
|
|
13178
13219
|
await this.conversationMemory.updateConversation(conversationId, {});
|
|
13179
13220
|
context8.logger.trace("[Memory] Updated conversation");
|
|
13180
13221
|
}
|
|
13222
|
+
return true;
|
|
13181
13223
|
} catch (error) {
|
|
13182
13224
|
context8.logger.error("[Memory] Failed to ensure conversation exists", {
|
|
13183
13225
|
error
|
|
13184
13226
|
});
|
|
13227
|
+
return false;
|
|
13185
13228
|
}
|
|
13186
13229
|
}
|
|
13187
13230
|
/**
|
|
@@ -27047,6 +27090,12 @@ var ConversationBuffer = class {
|
|
|
27047
27090
|
return;
|
|
27048
27091
|
}
|
|
27049
27092
|
if (source === "response") {
|
|
27093
|
+
const hasSameAssistantId = typeof message.id === "string" && message.id.length > 0 && typeof lastMessage.id === "string" && lastMessage.id.length > 0 && message.id === lastMessage.id;
|
|
27094
|
+
if (hasSameAssistantId) {
|
|
27095
|
+
this.mergeAssistantMessage(message);
|
|
27096
|
+
this.activeAssistantMessageId = lastMessage.id;
|
|
27097
|
+
return;
|
|
27098
|
+
}
|
|
27050
27099
|
const isActiveTarget = this.activeAssistantMessageId !== void 0 && this.activeAssistantMessageId === lastMessage.id;
|
|
27051
27100
|
const isActiveIncoming = this.activeAssistantMessageId !== void 0 && this.activeAssistantMessageId === message.id;
|
|
27052
27101
|
if (isActiveTarget || isActiveIncoming || this.pendingMessageIds.has(lastMessage.id)) {
|