Documentation
¶
Overview ¶
Package web controls sessions on a running DSH Web instance. Unlike the one-shot CLI handoff, callers can persist a session ID before submitting input and reuse it for follow-ups and browser-launch retries.
Index ¶
- Constants
- func IsRunner(runner string) bool
- func NormalizeBrowser(raw string) (string, error)
- type Client
- func (c Client) Create(ctx context.Context, directory, sessionID string) (string, error)
- func (c Client) CreateWithOptions(ctx context.Context, opts CreateOptions) (CreatedSession, error)
- func (c Client) Fork(ctx context.Context, opts ForkOptions) (string, error)
- func (c Client) ModelCatalog(ctx context.Context) (ModelCatalog, error)
- func (c Client) Open(sessionID, browser string) error
- func (c Client) Send(ctx context.Context, sessionID, requestID, text string, noSubmit bool) error
- func (c Client) SessionModel(ctx context.Context, sessionID string) (SessionModel, error)
- func (c Client) SetDraft(ctx context.Context, sessionID, text string) error
- func (c Client) Status(ctx context.Context, ids []string) (map[string]bool, error)
- type CreateOptions
- type CreatedSession
- type FileStore
- type ForkOptions
- type Listen
- type ModelCatalog
- type ModelCatalogFailure
- type ModelCatalogModel
- type ModelProviderGroup
- type ModelReasoning
- type ModelReasoningEffort
- type ModelSelection
- type Record
- type Result
- type RunStatus
- type SendOptions
- type Service
- type SessionModel
- type SessionOptions
- type State
- type Store
- type Warning
Constants ¶
const BrowserNone = "none"
BrowserNone disables automatic session-window opening while retaining normal session creation and prompt delivery. It is a persisted browser preference.
const DefaultRunStatusTTL = time.Second
DefaultRunStatusTTL bounds how stale a cached run-status answer may be. The daemon answers every loaded Session in one round trip, so a short window collapses a burst of per-Session lookups into one RPC while still following a turn that starts or ends within the second.
const Runner = "dsh-web"
Variables ¶
This section is empty.
Functions ¶
func NormalizeBrowser ¶
Types ¶
type Client ¶
type Client struct {
Home string
ReadListen func() (Listen, error)
HTTPClient *http.Client
OpenBrowser func(rawURL, browser string) error
}
Client has injectable transport/discovery/opener boundaries for in-process tests. Its zero value uses DSH_HOME (or ~/.dsh), a bounded HTTP client, and the OS opener.
func (Client) Create ¶
Create registers a workspace and an empty session under a caller-persisted identity. A retry can reuse that blank session. No prompt is submitted and no browser is opened: the caller must durably save the returned ID first.
func (Client) CreateWithOptions ¶
func (c Client) CreateWithOptions(ctx context.Context, opts CreateOptions) (CreatedSession, error)
CreateWithOptions initializes a reserved session and verifies the Host accepted an explicit model before any caller can submit input or open the browser.
func (Client) Fork ¶ added in v0.0.220
Fork creates a child session and returns its ID. It neither seeds a draft nor opens a browser; agent/dsh/fork composes both so the child can be reviewed before its first turn.
func (Client) ModelCatalog ¶
func (c Client) ModelCatalog(ctx context.Context) (ModelCatalog, error)
ModelCatalog reads the live registry through the existing authenticated Web API. Provider failures are data, not a reason to discard healthy groups.
func (Client) Open ¶
Open opens the existing session, or does nothing for BrowserNone without discovering the server or invoking the OS opener. Service.Open is the explicit manual-opening operation. Opener errors redact the authenticated URL.
func (Client) Send ¶
Send queues a prompt (or stores a draft). A caller-supplied requestID is reused across retries so an ambiguous transport failure does not enqueue twice.
func (Client) SessionModel ¶ added in v0.0.228
SessionModel reads session/projections and returns only modelSelection.
func (Client) SetDraft ¶ added in v0.0.220
SetDraft stores text in the session composer without submitting a turn, so a caller can hand a prepared prompt to the operator for review. It is the transport behind Send(noSubmit) and the seeding step of a fork.
func (Client) Status ¶ added in v0.0.225
Status asks the daemon which Sessions are executing a turn.
A nil ids asks about every Session the daemon has loaded; an empty slice asks about none. An id is absent from the result when the daemon never loaded it, denies it to this caller, or does not know it, so absence means unknown here rather than idle — a Session opened by a plain `dsh` TUI is not in the daemon's registry at all.
type CreateOptions ¶
type CreateOptions struct {
Workspace string
SessionID string
ModelSelection *ModelSelection
}
CreateOptions describes a reserved blank session. ModelSelection, if present, initializes only this session; it never calls session/selectModel.
type CreatedSession ¶
type CreatedSession struct {
SessionID string `json:"sessionId"`
ModelSelection *ModelSelection `json:"modelSelection,omitempty"`
}
CreatedSession echoes the Host's installed initial selection when requested. The echo prevents an older Host silently ignoring an explicit override.
type FileStore ¶
FileStore uses <Dir>/<key>/<FileName>. The caller chooses Dir; there is no implicit Marcus, agent-run, or global home. An empty FileName means session.json. Existing flat binding records remain readable, including non-DSH runner pins.
func (FileStore) WithSession ¶
WithSession holds a filesystem lock across network operations AND intermediate saves. Distinct Service/FileStore objects and separate processes share the same lock; an OS-released lock is not mistaken for a completed checkpoint.
type ForkOptions ¶ added in v0.0.220
type ForkOptions struct {
// SessionID is the fork source and is required.
SessionID string
// AtSeq is the inclusive cut; 0 lets the Host keep the latest completed turn.
AtSeq int64
// Cwd is the child checkout. It must be fully qualified: the Host matches it
// against its workspace registry and silently keeps the source for an
// unknown directory, so callers verify the returned child.
Cwd string
}
ForkOptions describes a child conversation seeded from another session. The Host copies the source transcript up to AtSeq and starts the child in Cwd.
type Listen ¶
Listen contains discovery credentials. Never persist or log Token in a consumer's session binding; read the current record on each operation.
type ModelCatalog ¶
type ModelCatalog struct {
Default ModelSelection `json:"default"`
RoutableProviders []string `json:"routableProviders"`
Groups []ModelProviderGroup `json:"groups"`
Failures []ModelCatalogFailure `json:"failures"`
}
ModelCatalog describes this running DSH deployment, including partial failures. A listed model is selectable only when Unavailable is empty. Listing does not create a session, open a browser, or save global/default configuration.
type ModelCatalogFailure ¶
type ModelCatalogModel ¶
type ModelCatalogModel struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Reasoning *ModelReasoning `json:"reasoning,omitempty"`
}
type ModelProviderGroup ¶
type ModelProviderGroup struct {
ID string `json:"id"`
Name string `json:"name"`
Models []ModelCatalogModel `json:"models"`
}
type ModelReasoning ¶
type ModelReasoning struct {
Efforts []ModelReasoningEffort `json:"efforts"`
DefaultEffort string `json:"defaultEffort,omitempty"`
}
type ModelReasoningEffort ¶
type ModelSelection ¶
type ModelSelection struct {
Provider string `json:"provider"`
Model string `json:"model"`
ReasoningEffort string `json:"reasoningEffort,omitempty"`
}
ModelSelection identifies an exact DSH provider route. Empty ReasoningEffort follows that model's adapter default; it is not a Codex effort alias.
type Record ¶
Record permits multiple durable checkpoints while its store holds a session lock. Implementations must leave the last committed checkpoint intact on error.
type Result ¶
type Result struct {
SessionID string
Created bool // a provider session was created during this operation
Accepted bool // submitted input or a draft was accepted (not agent completion)
BrowserOpened bool // this operation opened a browser
Warnings []Warning
}
Result distinguishes input admission from browser opening. A browser failure after admission is a warning, not a delivery error. Libraries never print logs.
type RunStatus ¶ added in v0.0.225
type RunStatus struct {
Client Client
TTL time.Duration
// Timeout overrides how long one status RPC may take. Zero uses
// runStatusTimeout.
Timeout time.Duration
// Now overrides the clock in tests. Nil uses time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
RunStatus is the liveness hook a phase reader installs: Running reports whether one Session is executing a turn, and whether the daemon could answer at all.
It is shaped to match sessionactivity.RunStatus without importing it, so the activity package keeps its dependency-free contract and this package stays transport-only. Install it with sessionactivity.SetDefaultRunStatus.
One RPC per TTL covers every Session, because the daemon's answer is batch. A failed refresh reports unknown for everything instead of replaying the last good map: a dead daemon must degrade to the caller's process-lease liveness, never to a stale "running".
func NewRunStatus ¶ added in v0.0.225
NewRunStatus returns the hook for one DSH web instance, refreshing at most once per DefaultRunStatusTTL.
type SendOptions ¶
type Service ¶
Service owns DSH Web session lifecycle. It never starts a terminal, agent-run, dsh CLI, or readiness probe. Client transport and Store are independently injectable; separate services using the same Store share durable checkpoints.
func (Service) Open ¶
Open only opens an existing, created DSH session. A BrowserNone binding uses the system default browser for this explicit action without changing its pin. It never creates a provider session, submits/retries pending input, or consults a terminal runner.
func (Service) OpenSession ¶
OpenSession creates/reuses a caller-keyed DSH conversation, admits its first input once, and opens the selected browser unless NoOpen or BrowserNone. Repeated calls do not resubmit an admitted initial prompt. Use Send for a subsequent message.
type SessionModel ¶ added in v0.0.228
type SessionModel struct {
Next *ModelSelection `json:"next"`
LastUsed *ModelSelection `json:"lastUsed"`
}
SessionModel is the durable model-selection fold for one Session. Next is the pending route for the next request; LastUsed is the last consumed route. Both nil means a new Session that has never selected a model.
type SessionOptions ¶
type SessionOptions struct {
// ModelSelection is pinned only when a new binding is reserved.
ModelSelection *ModelSelection
Key string
Workspace string
Browser string
Prompt string
NoSubmit bool
NoOpen bool
}
SessionOptions identifies one caller-owned conversation and its first input. Workspace/Browser are pinned on first creation; later preference changes do not silently relocate an existing session. NoOpen suppresses automatic browser opening for this call, but never changes prompt delivery semantics. BrowserNone instead pins automatic opening off across retries and restarts.
type State ¶
type State struct {
InitialModelSelection *ModelSelection `json:"initial_model_selection,omitempty"`
Runner string `json:"runner"`
Browser string `json:"browser,omitempty"`
Workspace string `json:"workspace,omitempty"`
DSHSessionID string `json:"dsh_session_id,omitempty"`
Created bool `json:"created,omitempty"`
InitialDelivered bool `json:"initial_delivered,omitempty"`
BrowserOpened bool `json:"browser_opened,omitempty"`
PendingRequestID string `json:"pending_request_id,omitempty"`
PendingHash string `json:"pending_hash,omitempty"`
PendingPrompt string `json:"pending_prompt,omitempty"`
PendingNoSubmit bool `json:"pending_no_submit,omitempty"`
}
State is a durable DSH conversation binding, not a business conversation. JSON names retain compatibility with the original Marcus binding records. Runner is a discriminator so a shared storage location cannot turn an existing terminal conversation into a DSH session. No launch tokens belong here.
type Store ¶
type Store interface {
Read(context.Context, string) (State, bool, error)
WithSession(context.Context, string, func(Record) error) error
}
Store separates application-chosen persistence from DSH orchestration. WithSession serializes a key across all instances sharing the same storage; Read observes the last atomic checkpoint without taking a delivery lock.