Documentation
¶
Overview ¶
Package listcut cuts a list response to fit a model client's context budget on whole items (#1915): the result stays valid JSON, says how many of the list's items it shows, and, where the operation declares paging parameters, names the request that reads on from the last one shown.
It holds what the api gateway and the GraphQL kind share: finding the one list a JSON value carries, cutting it, the search for the most items that render within a budget, and the continuation pagenext computes for them. Rendering is the caller's, because only the caller knows the envelope the list is wrapped in.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FitItems ¶
FitItems finds the most items of a list of total that a result renders within budget with. try renders the result holding the first n items and reports whether it fits. The count returned is below total -- a result that fits whole is not cut -- and at least one: a result that cannot hold even one item has no cut that hands the caller anything, and false is returned.
Types ¶
type Count ¶
type Count struct {
// Shown is the number of items kept: the first ones.
Shown int `json:"shown"`
// Total is the number of items in the list.
Total int `json:"total"`
}
Count is how much of a list a cut result shows.
type Cut ¶
type Cut struct {
// Body is the value holding the kept items and everything around them.
Body any
// Shown is the number of items kept: the first ones.
Shown int
// Total is the number of items in the list.
Total int
// NextQuery is the query of the request that reads on, or nil when the
// operation declares no paging that can be advanced.
NextQuery map[string]any
// Style is how NextQuery continues; empty when NextQuery is nil.
Style pagenext.Style
}
Cut is one list body cut to fit.
func Fit ¶
Fit cuts the list in body to the most items for which fits reports the rendered result within the budget. fits receives each candidate cut and renders it; the last call is made with the cut returned. It reports false when body carries no list or not even one item fits. query is the request the body answered, and plan, when not nil, how that request pages.
type Items ¶
type Items struct {
// Path is the keys walked from the value to the list; empty when the
// value is itself the list.
Path []string
// Total is the number of items in the list.
Total int
}
Items locates the one list a JSON value carries.
func FindItems ¶
FindItems locates the list v is cut on: v itself when it is an array, or the one array an object carries, found through objects that carry one object and no array (data.users.edges). An object with two arrays, or with no array within reach, has no list the cut could name, and neither has a scalar.