| 396 | }; |
| 397 | |
| 398 | const paginate = <T>(all: readonly T[], offset: number, limit: number): PagedResult<T> => { |
| 399 | const total = all.length; |
| 400 | const start = Math.min(Math.max(offset, 0), total); |
| 401 | const items = all.slice(start, start + limit); |
| 402 | const consumed = start + items.length; |
| 403 | const hasMore = consumed < total; |
| 404 | return { |
| 405 | items, |
| 406 | total, |
| 407 | hasMore, |
| 408 | nextOffset: hasMore ? consumed : null, |
| 409 | }; |
| 410 | }; |
| 411 | |
| 412 | /** What `searchTools` ranks over — the sandbox-callable path plus the v2 |
| 413 | * identity fields a query can match against. */ |