diff options
| author | Dhravya Shah <[email protected]> | 2026-01-23 17:42:47 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2026-01-23 17:42:47 -0700 |
| commit | 4ca0f593a5d89695e101569f09debda5617c0ec6 (patch) | |
| tree | 60517a8e898965cf8120cc01c56f69baaff0d06e /packages | |
| parent | extract metadata ourselves (diff) | |
| parent | fix: cf build (#700) (diff) | |
| download | supermemory-4ca0f593a5d89695e101569f09debda5617c0ec6.tar.xz supermemory-4ca0f593a5d89695e101569f09debda5617c0ec6.zip | |
fix: merge conflicts
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/tools/README.md | 33 | ||||
| -rw-r--r-- | packages/tools/src/ai-sdk.ts | 31 | ||||
| -rw-r--r-- | packages/tools/src/types.ts | 15 |
3 files changed, 69 insertions, 10 deletions
diff --git a/packages/tools/README.md b/packages/tools/README.md index e859ede7..a2390ad7 100644 --- a/packages/tools/README.md +++ b/packages/tools/README.md @@ -414,12 +414,45 @@ interface SupermemoryToolsConfig { baseUrl?: string containerTags?: string[] projectId?: string + strict?: boolean } ``` - **baseUrl**: Custom base URL for the supermemory API - **containerTags**: Array of custom container tags (mutually exclusive with projectId) - **projectId**: Project ID which gets converted to container tag format (mutually exclusive with containerTags) +- **strict**: Enable strict schema mode for OpenAI strict validation. When `true`, all schema properties are required (satisfies OpenAI strict mode). When `false` (default), optional fields remain optional for maximum compatibility with all models. + +### OpenAI Strict Mode Compatibility + +When using OpenAI-compatible providers with strict schema validation (e.g., OpenRouter with Azure OpenAI backend), enable strict mode to ensure all schema properties are included in the `required` array: + +```typescript +import { searchMemoriesTool, addMemoryTool } from "@supermemory/tools/ai-sdk" +import { createOpenRouter } from "@openrouter/ai-sdk-provider" +import { streamText } from "ai" + +const openrouter = createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY }) + +const tools = { + searchMemories: searchMemoriesTool(apiKey, { + containerTags: [userId], + strict: true // ✅ Required for OpenAI strict mode + }), + addMemory: addMemoryTool(apiKey, { + containerTags: [userId], + strict: true + }), +} + +const result = streamText({ + model: openrouter.chat("openai/gpt-5-nano"), + messages: [...], + tools, +}) +``` + +Without `strict: true`, optional fields like `includeFullDocs` and `limit` won't be in the `required` array, which will cause validation errors with OpenAI strict mode. ### withSupermemory Middleware Options diff --git a/packages/tools/src/ai-sdk.ts b/packages/tools/src/ai-sdk.ts index 0f2d5fe0..b931d325 100644 --- a/packages/tools/src/ai-sdk.ts +++ b/packages/tools/src/ai-sdk.ts @@ -20,6 +20,7 @@ export const searchMemoriesTool = ( }) const containerTags = getContainerTags(config) + const strict = config?.strict ?? false return tool({ description: TOOL_DESCRIPTIONS.searchMemories, @@ -27,16 +28,26 @@ export const searchMemoriesTool = ( informationToGet: z .string() .describe(PARAMETER_DESCRIPTIONS.informationToGet), - includeFullDocs: z - .boolean() - .optional() - .default(DEFAULT_VALUES.includeFullDocs) - .describe(PARAMETER_DESCRIPTIONS.includeFullDocs), - limit: z - .number() - .optional() - .default(DEFAULT_VALUES.limit) - .describe(PARAMETER_DESCRIPTIONS.limit), + includeFullDocs: strict + ? z + .boolean() + .default(DEFAULT_VALUES.includeFullDocs) + .describe(PARAMETER_DESCRIPTIONS.includeFullDocs) + : z + .boolean() + .optional() + .default(DEFAULT_VALUES.includeFullDocs) + .describe(PARAMETER_DESCRIPTIONS.includeFullDocs), + limit: strict + ? z + .number() + .default(DEFAULT_VALUES.limit) + .describe(PARAMETER_DESCRIPTIONS.limit) + : z + .number() + .optional() + .default(DEFAULT_VALUES.limit) + .describe(PARAMETER_DESCRIPTIONS.limit), }), execute: async ({ informationToGet, diff --git a/packages/tools/src/types.ts b/packages/tools/src/types.ts index dfff0f00..9d05f6f1 100644 --- a/packages/tools/src/types.ts +++ b/packages/tools/src/types.ts @@ -3,7 +3,22 @@ * Only one of `projectId` or `containerTags` can be provided. */ export interface SupermemoryToolsConfig { + /** + * Custom base URL for the supermemory API + */ baseUrl?: string + /** + * Array of custom container tags (mutually exclusive with projectId) + */ containerTags?: string[] + /** + * Project ID which gets converted to container tag format (mutually exclusive with containerTags) + */ projectId?: string + /** + * Enable strict schema mode for OpenAI strict validation. + * When true, all schema properties are required (satisfies OpenAI strict mode). + * When false (default), optional fields remain optional for maximum compatibility. + */ + strict?: boolean } |