Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/tools/src/ai-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const searchMemoriesTool = (
.default(DEFAULT_VALUES.includeFullDocs)
.describe(PARAMETER_DESCRIPTIONS.includeFullDocs),
limit: strict
? z
? z.coerce

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z.coerce.number() applies Number(...) before .default(), so inputs like null or "" parse as 0 instead of using DEFAULT_VALUES.limit or being rejected. AI tool calls often emit optional fields as null; here that 0 can be passed to client.search.execute, causing empty or invalid searches. Consider preprocessing only numeric strings while mapping null/empty strings to undefined before the default applies, or rejecting them explicitly.

.number()
.default(DEFAULT_VALUES.limit)
.describe(PARAMETER_DESCRIPTIONS.limit)
: z
: z.coerce
.number()
.optional()
.default(DEFAULT_VALUES.limit)
Expand Down Expand Up @@ -182,16 +182,19 @@ export const documentListTool = (
.optional()
.describe(PARAMETER_DESCRIPTIONS.containerTag),
limit: strict
? z
? z.coerce
.number()
.default(DEFAULT_VALUES.limit)
.describe(PARAMETER_DESCRIPTIONS.limit)
: z
: z.coerce
.number()
.optional()
.default(DEFAULT_VALUES.limit)
.describe(PARAMETER_DESCRIPTIONS.limit),
offset: z.number().optional().describe(PARAMETER_DESCRIPTIONS.offset),
offset: z.coerce
.number()
.optional()
.describe(PARAMETER_DESCRIPTIONS.offset),
status: z.string().optional().describe(PARAMETER_DESCRIPTIONS.status),
}),
execute: async ({ containerTag, limit, offset, status }) => {
Expand Down