Skip to content

Commit 1af2375

Browse files
auto-pagination with Redis cache for paginated tool outputs
1 parent e8f7fe0 commit 1af2375

File tree

17 files changed

+1071
-21
lines changed

17 files changed

+1071
-21
lines changed

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from '@/lib/execution/manual-cancellation'
3636
import { preprocessExecution } from '@/lib/execution/preprocessing'
3737
import { LoggingSession } from '@/lib/logs/execution/logging-session'
38+
import { cleanupPaginatedCache } from '@/lib/paginated-cache/paginate'
3839
import {
3940
cleanupExecutionBase64Cache,
4041
hydrateUserFilesWithBase64,
@@ -988,6 +989,9 @@ async function handleExecutePost(
988989
void cleanupExecutionBase64Cache(executionId).catch((error) => {
989990
reqLogger.error('Failed to cleanup base64 cache', { error })
990991
})
992+
void cleanupPaginatedCache(executionId).catch((error) => {
993+
reqLogger.error('Failed to cleanup paginated cache', { error })
994+
})
991995
}
992996
}
993997
}
@@ -1483,6 +1487,7 @@ async function handleExecutePost(
14831487
timeoutController.cleanup()
14841488
if (executionId) {
14851489
await cleanupExecutionBase64Cache(executionId)
1490+
await cleanupPaginatedCache(executionId)
14861491
}
14871492
if (!isStreamClosed) {
14881493
try {

apps/sim/blocks/blocks/zendesk.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ Return ONLY the search query - no explanations.`,
496496
condition: {
497497
field: 'operation',
498498
value: [
499-
'get_tickets',
500499
'get_users',
501500
'get_organizations',
502501
'search_users',
@@ -514,7 +513,7 @@ Return ONLY the search query - no explanations.`,
514513
description: 'Cursor value from a previous response to fetch the next page of results',
515514
condition: {
516515
field: 'operation',
517-
value: ['get_tickets', 'get_users', 'get_organizations', 'search'],
516+
value: ['get_users', 'get_organizations', 'search'],
518517
},
519518
mode: 'advanced',
520519
},

apps/sim/executor/execution/block-executor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createLogger, type Logger } from '@sim/logger'
22
import { redactApiKeys } from '@/lib/core/security/redaction'
3+
import { hydrateCacheReferences } from '@/lib/paginated-cache/paginate'
34
import { getBaseUrl } from '@/lib/core/utils/urls'
45
import {
56
containsUserFileWithMetadata,
@@ -109,6 +110,7 @@ export class BlockExecutor {
109110
}
110111

111112
resolvedInputs = this.resolver.resolveInputs(ctx, node.id, block.config.params, block)
113+
resolvedInputs = await hydrateCacheReferences(resolvedInputs)
112114

113115
if (blockLog) {
114116
blockLog.input = this.sanitizeInputsForLog(resolvedInputs)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { CachedPage, CacheMetadata } from '@/lib/paginated-cache/types'
2+
3+
/**
4+
* Storage-agnostic interface for paginated cache operations.
5+
* TTL and other storage-specific concerns belong in implementations.
6+
*/
7+
export interface PaginatedCacheStorageAdapter {
8+
/** Store a single page of items */
9+
storePage(cacheId: string, pageIndex: number, items: unknown[]): Promise<void>
10+
/** Store cache metadata */
11+
storeMetadata(cacheId: string, metadata: CacheMetadata): Promise<void>
12+
/** Retrieve a single page. Returns null if not found or expired. */
13+
getPage(cacheId: string, pageIndex: number): Promise<CachedPage | null>
14+
/** Retrieve cache metadata. Returns null if not found or expired. */
15+
getMetadata(cacheId: string): Promise<CacheMetadata | null>
16+
/** Retrieve all pages in order. Throws if any page is missing. */
17+
getAllPages(cacheId: string, totalPages: number): Promise<CachedPage[]>
18+
/** Delete all data for a cache entry */
19+
delete(cacheId: string): Promise<void>
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type { PaginatedCacheStorageAdapter } from '@/lib/paginated-cache/adapter'
2+
export { RedisPaginatedCache } from '@/lib/paginated-cache/redis-cache'
3+
export {
4+
autoPaginate,
5+
cleanupPaginatedCache,
6+
hydrateCacheReferences,
7+
} from '@/lib/paginated-cache/paginate'
8+
export {
9+
isPaginatedCacheReference,
10+
type CachedPage,
11+
type CacheMetadata,
12+
type PaginatedCacheReference,
13+
type ToolPaginationConfig,
14+
} from '@/lib/paginated-cache/types'

0 commit comments

Comments
 (0)