| 463 | }; |
| 464 | |
| 465 | const paginate = <T>(all: readonly T[], offset: number, limit: number): PagedResult<T> => { |
| 466 | const total = all.length; |
| 467 | const start = Math.min(Math.max(offset, 0), total); |
| 468 | const items = all.slice(start, start + limit); |
| 469 | const consumed = start + items.length; |
| 470 | const hasMore = consumed < total; |
| 471 | return { |
| 472 | items, |
| 473 | total, |
| 474 | hasMore, |
| 475 | nextOffset: hasMore ? consumed : null, |
| 476 | }; |
| 477 | }; |
| 478 | |
| 479 | /** What `searchTools` ranks over — the sandbox-callable path plus the v2 |
| 480 | * identity fields a query can match against. */ |