Skip to content

Commit 19d0208

Browse files
committed
fix(notion): clamp page_size to 1-100 at the tool layer for list comments/users and block children
Adds a shared clampNotionPageSize helper so the agent-direct path is bounded to Notion's range, not just the block path.
1 parent 786c646 commit 19d0208

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

apps/sim/tools/notion/list_comments.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NotionListCommentsParams } from '@/tools/notion/types'
22
import { COMMENT_LIST_RESULTS_OUTPUT, PAGINATION_OUTPUT_PROPERTIES } from '@/tools/notion/types'
3+
import { clampNotionPageSize } from '@/tools/notion/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
interface NotionListCommentsResponse {
@@ -57,7 +58,8 @@ export const notionListCommentsTool: ToolConfig<
5758
const url = new URL('https://api.notion.com/v1/comments')
5859
url.searchParams.set('block_id', params.blockId.trim())
5960
if (params.startCursor) url.searchParams.set('start_cursor', params.startCursor.trim())
60-
if (params.pageSize != null) url.searchParams.set('page_size', String(params.pageSize))
61+
const pageSize = clampNotionPageSize(params.pageSize)
62+
if (pageSize != null) url.searchParams.set('page_size', String(pageSize))
6163
return url.toString()
6264
},
6365
method: 'GET',

apps/sim/tools/notion/list_users.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NotionListUsersParams } from '@/tools/notion/types'
22
import { PAGINATION_OUTPUT_PROPERTIES, USER_LIST_RESULTS_OUTPUT } from '@/tools/notion/types'
3+
import { clampNotionPageSize } from '@/tools/notion/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
interface NotionListUsersResponse {
@@ -47,7 +48,8 @@ export const notionListUsersTool: ToolConfig<NotionListUsersParams, NotionListUs
4748
url: (params: NotionListUsersParams) => {
4849
const url = new URL('https://api.notion.com/v1/users')
4950
if (params.startCursor) url.searchParams.set('start_cursor', params.startCursor.trim())
50-
if (params.pageSize != null) url.searchParams.set('page_size', String(params.pageSize))
51+
const pageSize = clampNotionPageSize(params.pageSize)
52+
if (pageSize != null) url.searchParams.set('page_size', String(pageSize))
5153
return url.toString()
5254
},
5355
method: 'GET',

apps/sim/tools/notion/retrieve_block_children.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NotionRetrieveBlockChildrenParams } from '@/tools/notion/types'
22
import { BLOCK_LIST_RESULTS_OUTPUT, PAGINATION_OUTPUT_PROPERTIES } from '@/tools/notion/types'
3+
import { clampNotionPageSize } from '@/tools/notion/utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
interface NotionRetrieveBlockChildrenResponse {
@@ -56,7 +57,8 @@ export const notionRetrieveBlockChildrenTool: ToolConfig<
5657
url: (params: NotionRetrieveBlockChildrenParams) => {
5758
const url = new URL(`https://api.notion.com/v1/blocks/${params.blockId.trim()}/children`)
5859
if (params.startCursor) url.searchParams.set('start_cursor', params.startCursor.trim())
59-
if (params.pageSize != null) url.searchParams.set('page_size', String(params.pageSize))
60+
const pageSize = clampNotionPageSize(params.pageSize)
61+
if (pageSize != null) url.searchParams.set('page_size', String(pageSize))
6062
return url.toString()
6163
},
6264
method: 'GET',

apps/sim/tools/notion/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Clamp a Notion `page_size` value to the API's supported 1-100 range. Returns
3+
* undefined when the input isn't a finite number so callers can omit the param.
4+
*/
5+
export function clampNotionPageSize(value: unknown): number | undefined {
6+
if (value == null || value === '') return undefined
7+
const parsed = Number(value)
8+
if (!Number.isFinite(parsed)) return undefined
9+
return Math.min(Math.max(Math.trunc(parsed), 1), 100)
10+
}
11+
112
export function formatPropertyValue(property: any): string {
213
switch (property.type) {
314
case 'title':

0 commit comments

Comments
 (0)