| 447 | }; |
| 448 | |
| 449 | const paginate = <T>(all: readonly T[], offset: number, limit: number): PagedResult<T> => { |
| 450 | const total = all.length; |
| 451 | const start = Math.min(Math.max(offset, 0), total); |
| 452 | const items = all.slice(start, start + limit); |
| 453 | const consumed = start + items.length; |
| 454 | const hasMore = consumed < total; |
| 455 | return { |
| 456 | items, |
| 457 | total, |
| 458 | hasMore, |
| 459 | nextOffset: hasMore ? consumed : null, |
| 460 | }; |
| 461 | }; |
| 462 | |
| 463 | /** What `searchTools` ranks over — the sandbox-callable path plus the v2 |
| 464 | * identity fields a query can match against. */ |