Skip to content

Commit 0e790bf

Browse files
committed
fix(google-drive): let an agent feed the page token back in
A page token is an opaque continuation value produced by a previous tool response, not an account-specific id the user has to supply, so 'user-only' hid it from agent blocks: they saw nextPageToken in the result and could not send it back, silently reporting page one as the whole answer. Every other pagination token in the tool set is 'user-or-llm'. Also covers the case the mapper guard actually defends — a per-operation page token surviving an operation switch, which reaches inputs because shouldSerializeSubBlock skips condition evaluation for advanced fields.
1 parent 5d74dcb commit 0e790bf

7 files changed

Lines changed: 52 additions & 12 deletions

File tree

apps/sim/blocks/blocks/google_drive.test.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ describe('GoogleDriveBlock pagination', () => {
3434
})
3535
})
3636

37-
it('forwards the page token to the tool', () => {
38-
expect(
39-
buildParams({ operation, [subBlockId]: 'token-abc' }, undefined as never)
40-
).toMatchObject({ pageToken: 'token-abc' })
37+
/**
38+
* `pageToken` is the canonical tool param, so the `list` case would forward
39+
* through `...rest` even without the mapper. The per-operation ids are the
40+
* ones the mapper has to translate, and none of them may survive as-is.
41+
*/
42+
it('forwards the page token to the tool under its own id', () => {
43+
const params = buildParams({ operation, [subBlockId]: 'token-abc' }, undefined as never)
44+
45+
expect(params).toMatchObject({ pageToken: 'token-abc' })
46+
if (subBlockId !== 'pageToken') expect(params[subBlockId]).toBeUndefined()
4147
})
4248

43-
it('declares pageToken as a user-settable tool param', () => {
44-
expect(tool.params.pageToken?.visibility).toBe('user-only')
49+
it('lets an agent feed a nextPageToken back in', () => {
50+
expect(tool.params.pageToken?.visibility).toBe('user-or-llm')
4551
})
4652
})
4753

@@ -51,6 +57,40 @@ describe('GoogleDriveBlock pagination', () => {
5157
).toBeUndefined()
5258
})
5359

60+
/**
61+
* `shouldSerializeSubBlock` short-circuits for `advanced` fields in basic display
62+
* mode without evaluating `condition`, so a page token typed under one operation
63+
* genuinely reaches `inputs` after the user switches to another. The mapper must
64+
* pick the token belonging to the operation being run and drop the rest.
65+
*/
66+
describe.each(paginationCases.filter(({ subBlockId }) => subBlockId !== 'pageToken'))(
67+
'$subBlockId left over from a previous operation',
68+
({ subBlockId }) => {
69+
it.each(['upload', 'get_file', 'list'])('is dropped under %s', (operation) => {
70+
const params = buildParams({ operation, [subBlockId]: 'stale' }, undefined as never)
71+
72+
expect(params.pageToken).toBeUndefined()
73+
expect(params[subBlockId]).toBeUndefined()
74+
})
75+
}
76+
)
77+
78+
it('prefers the operation-owned token when a stale sibling is also present', () => {
79+
const params = buildParams(
80+
{
81+
operation: 'search',
82+
searchPageToken: 'search-token',
83+
commentsPageToken: 'stale',
84+
pageToken: 'stale-canonical',
85+
},
86+
undefined as never
87+
)
88+
89+
expect(params.pageToken).toBe('search-token')
90+
expect(params.commentsPageToken).toBeUndefined()
91+
expect(params.searchPageToken).toBeUndefined()
92+
})
93+
5494
it('declares pageToken as a block input', () => {
5595
expect(GoogleDriveBlock.inputs.pageToken).toBeDefined()
5696
})

apps/sim/tools/generated/tool-metadata.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/sim/tools/google_drive/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const listTool: ToolConfig<GoogleDriveToolParams, GoogleDriveListResponse
4848
pageToken: {
4949
type: 'string',
5050
required: false,
51-
visibility: 'user-only',
51+
visibility: 'user-or-llm',
5252
description: 'The page token to use for pagination',
5353
},
5454
},

apps/sim/tools/google_drive/list_comments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const listCommentsTool: ToolConfig<
6565
pageToken: {
6666
type: 'string',
6767
required: false,
68-
visibility: 'user-only',
68+
visibility: 'user-or-llm',
6969
description: 'The page token to use for pagination',
7070
},
7171
},

apps/sim/tools/google_drive/list_permissions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const listPermissionsTool: ToolConfig<
4343
pageToken: {
4444
type: 'string',
4545
required: false,
46-
visibility: 'user-only',
46+
visibility: 'user-or-llm',
4747
description: 'The page token to use for pagination',
4848
},
4949
},

apps/sim/tools/google_drive/list_revisions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const listRevisionsTool: ToolConfig<
5151
pageToken: {
5252
type: 'string',
5353
required: false,
54-
visibility: 'user-only',
54+
visibility: 'user-or-llm',
5555
description: 'The page token to use for pagination',
5656
},
5757
},

apps/sim/tools/google_drive/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const searchTool: ToolConfig<GoogleDriveSearchParams, GoogleDriveSearchRe
5050
pageToken: {
5151
type: 'string',
5252
required: false,
53-
visibility: 'user-only',
53+
visibility: 'user-or-llm',
5454
description: 'Token for fetching the next page of results',
5555
},
5656
},

0 commit comments

Comments
 (0)