session

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package session holds the product-neutral conversational working state that helps resolve requests such as "move it to Friday": the focused entity, the current selection, sidebar pins, and the pending and previous actions.

It stores stable entity references, never rendered snapshots. Products define entity types and key names ("happening" + spaceID/happeningID in Sneat, "recordset" + ... in DataTug).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Kind   string            `json:"kind"` // e.g. "calendar.reschedule_happening"
	Target *EntityRef        `json:"target,omitempty"`
	Args   map[string]string `json:"args,omitempty"`
	// Summary is the human confirmation text ("Move Dentist to Fri 16:00?").
	Summary string `json:"summary,omitempty"`
	// Undo, when set, is the action that reverses this one.
	Undo *Action `json:"undo,omitempty"`
}

Action is a semantic, product-defined operation (never a storage write).

type EntityRef

type EntityRef struct {
	Type string            `json:"type" yaml:"type"`
	Keys map[string]string `json:"keys" yaml:"keys"` // e.g. {"spaceID": "...", "happeningID": "..."}
	// Title is a display hint for prompts and the sidebar. It may be stale;
	// products re-resolve the entity by Keys before acting on it.
	Title string `json:"title,omitempty" yaml:"title,omitempty"`
}

EntityRef is a stable reference to a product entity.

func (EntityRef) Same

func (r EntityRef) Same(o EntityRef) bool

Same reports whether two refs point at the same entity (Title ignored).

type State

type State struct {
	Focused   *EntityRef  `json:"focused,omitempty"`
	Selection []EntityRef `json:"selection,omitempty"`
	Sidebar   []EntityRef `json:"sidebar,omitempty"`
	// Pending is an action awaiting user confirmation.
	Pending *Action `json:"pending,omitempty"`
	// Previous is the last executed action (for "undo", "that").
	Previous   *Action   `json:"previous,omitempty"`
	PreviousAt time.Time `json:"previousAt,omitzero"`
	// LastShown are the entities of the most recent structured output, in
	// display order, so "the second one" can resolve.
	LastShown []EntityRef `json:"lastShown,omitempty"`
}

State is the working context of one chat session.

func (*State) Candidates

func (s *State) Candidates() []EntityRef

Candidates returns the entities a pronoun ("it", "that") most plausibly refers to, most likely first: focused, selection, the sole last-shown entity, the previous action's target, then sidebar pins (newest first). Duplicates are removed. Products filter by type.

func (*State) Focus

func (s *State) Focus(ref *EntityRef)

Focus sets the focused entity (nil clears it).

func (*State) Pin

func (s *State) Pin(ref EntityRef) bool

Pin adds ref to the sidebar unless already present. It reports whether the sidebar changed.

func (*State) Unpin

func (s *State) Unpin(ref EntityRef) bool

Unpin removes ref from the sidebar and reports whether it was there.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL