| 434 | }; |
| 435 | |
| 436 | const paginate = <T>(all: readonly T[], offset: number, limit: number): PagedResult<T> => { |
| 437 | const total = all.length; |
| 438 | const start = Math.min(Math.max(offset, 0), total); |
| 439 | const items = all.slice(start, start + limit); |
| 440 | const consumed = start + items.length; |
| 441 | const hasMore = consumed < total; |
| 442 | return { |
| 443 | items, |
| 444 | total, |
| 445 | hasMore, |
| 446 | nextOffset: hasMore ? consumed : null, |
| 447 | }; |
| 448 | }; |
| 449 | |
| 450 | /** What `searchTools` ranks over — the sandbox-callable path plus the v2 |
| 451 | * identity fields a query can match against. */ |