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