Skip to content

Commit 29b1ac5

Browse files
fixes
1 parent cb6404a commit 29b1ac5

5 files changed

Lines changed: 21 additions & 11 deletions

File tree

apps/docs/ai-sdk/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const result = await generateText({
4040

4141
```typescript
4242
const modelWithMemory = withSupermemory(openai("gpt-5"), "user-123", {
43+
conversationId: "conv-1",
4344
addMemory: "always"
4445
})
4546
```

apps/docs/ai-sdk/user-profiles.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ All of this happens transparently - you write code as if using a normal model, b
5050

5151
```typescript
5252
const model = withSupermemory(openai("gpt-5"), "user-123", {
53+
conversationId: "conv-1",
5354
addMemory: "always"
5455
})
5556
```

apps/docs/integrations/ai-sdk.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const result = await generateText({
4848

4949
```typescript
5050
const modelWithMemory = withSupermemory(openai("gpt-5"), "user-123", {
51+
conversationId: "conv-1",
5152
addMemory: "always"
5253
})
5354
```

packages/tools/src/vercel/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import {
1313
import type { PromptTemplate, MemoryPromptData } from "./memory-prompt"
1414

1515
interface WrapVercelLanguageModelOptions {
16-
/** Conversation ID to group messages into a single document (maps to customId in Supermemory). Ensures related messages are added to the same document rather than creating new ones. */
17-
conversationId: string
16+
/** Conversation ID to group messages into a single document (maps to customId in Supermemory). Required when addMemory is "always". */
17+
conversationId?: string
1818
/** Enable detailed logging of memory search and injection */
1919
verbose?: boolean
2020
/**
@@ -35,8 +35,8 @@ interface WrapVercelLanguageModelOptions {
3535
searchLimit?: number
3636
/**
3737
* Memory persistence mode:
38-
* - "always": Automatically save conversations as memories
39-
* - "never": Only retrieve memories, don't store new ones
38+
* - "always": Automatically save conversations as memories (requires conversationId)
39+
* - "never": Only retrieve memories, don't store new ones (default)
4040
*/
4141
addMemory?: "always" | "never"
4242
/** Supermemory API key (falls back to SUPERMEMORY_API_KEY env var) */
@@ -80,7 +80,7 @@ interface WrapVercelLanguageModelOptions {
8080
* @param options.mode - Optional mode for memory search: "profile", "query", or "full" (default: "profile")
8181
* @param options.searchMode - Optional search mode: "memories" (default), "hybrid" (memories + chunks), or "documents" (chunks only)
8282
* @param options.searchLimit - Optional maximum number of search results when using hybrid/documents mode (default: 10)
83-
* @param options.addMemory - Optional mode for memory persistence: "always", "never" (default: "never")
83+
* @param options.addMemory - Optional mode for memory persistence: "always" (requires conversationId), "never" (default)
8484
* @param options.apiKey - Optional Supermemory API key to use instead of the environment variable
8585
* @param options.baseUrl - Optional base URL for the Supermemory API (default: "https://api.supermemory.ai")
8686
*
@@ -118,7 +118,7 @@ interface WrapVercelLanguageModelOptions {
118118
const wrapVercelLanguageModel = <T extends LanguageModel>(
119119
model: T,
120120
containerTag: string,
121-
options: WrapVercelLanguageModelOptions,
121+
options?: WrapVercelLanguageModelOptions,
122122
): T => {
123123
const providedApiKey = options?.apiKey ?? process.env.SUPERMEMORY_API_KEY
124124

@@ -128,10 +128,16 @@ const wrapVercelLanguageModel = <T extends LanguageModel>(
128128
)
129129
}
130130

131+
if ((options?.addMemory ?? "never") === "always" && !options?.conversationId) {
132+
throw new Error(
133+
"conversationId is required when addMemory is \"always\" — provide it via options.conversationId to group messages into a single document",
134+
)
135+
}
136+
131137
const ctx = createSupermemoryContext({
132138
containerTag,
133139
apiKey: providedApiKey,
134-
conversationId: options.conversationId,
140+
conversationId: options?.conversationId,
135141
verbose: options?.verbose ?? false,
136142
mode: options?.mode ?? "profile",
137143
searchMode: options?.searchMode ?? "memories",
@@ -152,7 +158,7 @@ const wrapVercelLanguageModel = <T extends LanguageModel>(
152158
const result = await model.doGenerate(transformedParams as any)
153159

154160
const userMessage = getLastUserMessage(params)
155-
if (ctx.addMemory === "always" && userMessage && userMessage.trim()) {
161+
if (ctx.addMemory === "always" && ctx.conversationId && userMessage && userMessage.trim()) {
156162
const assistantResponseText = extractAssistantResponseText(
157163
result.content as unknown[],
158164
)
@@ -202,6 +208,7 @@ const wrapVercelLanguageModel = <T extends LanguageModel>(
202208
const userMessage = getLastUserMessage(params)
203209
if (
204210
ctx.addMemory === "always" &&
211+
ctx.conversationId &&
205212
userMessage &&
206213
userMessage.trim()
207214
) {

packages/tools/src/vercel/middleware.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ interface SupermemoryMiddlewareOptions {
144144
containerTag: string
145145
/** Supermemory API key */
146146
apiKey: string
147-
/** Conversation ID to group messages into a single document (maps to customId in Supermemory) */
148-
conversationId: string
147+
/** Conversation ID to group messages into a single document (maps to customId in Supermemory). Required when addMemory is "always". */
148+
conversationId?: string
149149
/** Enable detailed logging of memory search and injection */
150150
verbose?: boolean
151151
/**
@@ -180,7 +180,7 @@ interface SupermemoryMiddlewareContext {
180180
client: Supermemory
181181
logger: Logger
182182
containerTag: string
183-
conversationId: string
183+
conversationId?: string
184184
mode: MemoryMode
185185
searchMode: SearchMode
186186
searchLimit: number

0 commit comments

Comments
 (0)