S4 page by cursor: a state page continues from an opaque cursor in sequence order

The runtime's mesh/state.page takes the cursor the page before answered as
next, so a state is read once however many pages it takes; a key written
again since an earlier page comes marked seen-again.

Builds: design 47 H2 §779
This commit is contained in:
2026-11-21 23:56:07 +01:00
parent 6d290eb46b
commit 92cb6a8d6d
4 changed files with 45 additions and 18 deletions
+7 -6
View File
@@ -25,9 +25,10 @@ func (k KeptSource) Get(key string) (*Entry, bool, error) {
return &Entry{Value: e.Value, Revision: e.Revision, Written: e.At}, true, nil
}
// Page is the values after a key in one request (stdio.KeptState.Page), as FirstView prefers them to Get per key.
func (k KeptSource) Page(after string, maxBytes int, budget time.Duration) ([]KeyedEntry, string, error) {
p, err := k.State.Page(after, maxBytes, budget)
// Page is the values after the opaque cursor in one request (stdio.KeptState.Page, in the order the bus wrote them),
// as FirstView prefers them to Get per key, and the cursor that continues them.
func (k KeptSource) Page(cursor string, maxBytes int, budget time.Duration) ([]KeyedEntry, string, error) {
p, err := k.State.Page(cursor, maxBytes, budget)
if err != nil {
return nil, "", err
}
@@ -61,10 +62,10 @@ func FirstViewTool(owner, name, state, words string, values, marks Source, now f
Name: name,
Description: fmt.Sprintf("The first view of %s's state %s (novox/hq ADR 0615, ADR 0621): %s Each value whole by key, at the revision "+
"the owner said its views family up to, so a reader then follows the events on that family and asks again only on a gap in "+
"revisions. One page at a time: next is the key to ask after for the rest.",
"revisions. One page at a time: hand next back as after for the rest.",
owner, state, words),
Input: map[string]any{"type": "object", "properties": map[string]any{
"after": map[string]any{"type": "string", "description": "the key the page before ended at (its next); none starts at the first"}}},
"after": map[string]any{"type": "string", "description": "the next of the page before; none starts at the first"}}},
Run: func(args map[string]any) (any, error) {
after, _ := args["after"].(string)
return FirstView(owner, state, values, marks, strings.TrimSpace(after), now())
@@ -87,7 +88,7 @@ func ReadTool(owner, name, state, words string, values, marks Source, now func()
"key": map[string]any{"type": "string", "description": "one key: its value and revision"},
"history": map[string]any{"type": "boolean", "description": "with key: every value the state keeps for it, oldest first"},
"values": map[string]any{"type": "boolean", "description": "a page of values whole by key"},
"after": map[string]any{"type": "string", "description": "with values: the key the page before ended at"}}},
"after": map[string]any{"type": "string", "description": "with values: the next of the page before"}}},
Run: func(args map[string]any) (any, error) {
key, _ := args["key"].(string)
after, _ := args["after"].(string)