Documentation
¶
Overview ¶
Package pagenext names the request that reads on from a list response cut to fit a model client's context budget (#1915).
A cut keeps the first items of a page. Where the rest are is decided by the paging parameters the operation declares, and each style continues differently:
- offset (offset/skip/$skip/start): the next request is the same one with the offset advanced past the items kept.
- page (page with per_page/page_size/limit/...): page+1 would skip the items cut from this one, so the next request asks for a page size that divides the items read through this cut, and the page that starts right after them. The cut and that size are chosen together, near what fits: requiring the size to equal the count kept degenerates to one item a call when the items already read are a prime count.
- cursor (cursor/after/page_token/...): the response's cursor points past the whole page, so following it would skip the items cut. The next request is this one again, same cursor, with the page size set to the items kept: that response holds what was shown here and carries a cursor that continues from it.
A page or cursor operation that declares no size parameter cannot be continued this way, and has no plan.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Param ¶
type Param struct {
Name string
// Default is the declared default, or "" when none is declared.
Default string
// Minimum is the declared minimum, or nil when none is declared. A page
// parameter with a minimum of 0 is numbered from 0.
Minimum *float64
}
Param is a query parameter an operation declares.
func FromOpenAPI ¶
func FromOpenAPI(lists ...openapi3.Parameters) []Param
FromOpenAPI reads the query parameters of an OpenAPI operation -- its path item's and its own, in that order -- with their declared defaults and minimums.
type Plan ¶
type Plan struct {
Style Style
Cursor Param // StyleCursor: the parameter the cursor is sent as
Offset Param // StyleOffset: the parameter advanced
Page Param // StylePage: the page number
Size Param // the page size; Name is "" when an offset operation declares none
}
Plan is how one operation continues after a cut.
func Detect ¶
Detect reads the paging plan from an operation's declared query parameters. Offset is preferred where an operation declares more than one style, because it continues without changing the page size.
func (Plan) Cut ¶
func (p Plan) Cut(query map[string]any, pageLen, fit int) (keep int, next map[string]any, err error)
Cut is where a cut of a page of pageLen items, the first fit of which render within the budget, ends -- how many items it keeps, at most fit -- and the query of the request that reads on from there. The caller's other parameters are carried unchanged.