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 Answer
- type ArchiveOptions
- type ArchiveValue
- type Client
- func (c Client) Archive(ctx context.Context, sessionID string, opts ArchiveOptions) (ArchiveValue, error)
- func (c Client) CompactIntoNew(ctx context.Context, sessionID string) (string, error)
- 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) EditMessages(ctx context.Context, sessionID, requestID string, ...) (EditResult, error)
- func (c Client) Fork(ctx context.Context, opts ForkOptions) (string, error)
- func (c Client) InjectMessages(ctx context.Context, sessionID, requestID string, messages []InjectedMessage) (InjectResult, error)
- func (c Client) ModelCatalog(ctx context.Context) (ModelCatalog, error)
- func (c Client) Open(sessionID, browser string) error
- func (c Client) RefreshModelCatalog(ctx context.Context) (ModelCatalog, error)
- func (c Client) SelectModel(ctx context.Context, sessionID, provider, model, reasoningEffort string) (ModelSelection, 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)
- func (c Client) Unarchive(ctx context.Context, sessionID string) (ArchiveValue, error)
- type CreateOptions
- type CreatedSession
- type EditResult
- type EditedMessageChange
- type FileStore
- type ForkOptions
- type InjectResult
- type InjectedMessage
- type Listen
- type ModelCatalog
- type ModelCatalogFailure
- type ModelCatalogModel
- type ModelProviderGroup
- type ModelReasoning
- type ModelReasoningEffort
- type ModelSelection
- type RPCError
- 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 Answer ¶ added in v0.0.236
Answer is the session/status answer about one id: whether the RPC succeeded, whether the id was in the map, whether that entry is running, and when the batch was sampled.
At is the instant the request was sent, so it never claims to be fresher than the answer. A cache hit reports the batch's instant, not the lookup's: that is what lets a reader decide whether the answer could have seen a turn the log already has.
type ArchiveOptions ¶ added in v0.0.250
type ArchiveOptions struct {
// StopActivity stops the Session's running work -- its turn, subagent
// descendants, owned background jobs and active schedules -- instead of
// letting DSH refuse the archive as `workspace/session-active`.
//
// It defaults to false on purpose: archiving is a grouping decision, and
// silently killing a working agent as a side effect of tidying a list is a
// worse surprise than a refusal the caller can explain and retry.
StopActivity bool
}
ArchiveOptions tunes one archive request.
type ArchiveValue ¶ added in v0.0.250
type ArchiveValue struct {
ArchivedSessionIDs []string
}
ArchiveValue is DSH's complete archived-Session set after a mutation.
It is the whole set, not the row just touched: DSH's archive is registry-wide, so a caller that keeps its own mirror can replace it instead of guessing.
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) Archive ¶ added in v0.0.250
func (c Client) Archive(ctx context.Context, sessionID string, opts ArchiveOptions) (ArchiveValue, error)
Archive hides one Session from Workspace grouping surfaces.
The Session stays readable; nothing on disk is deleted, and Unarchive brings it back. DSH refuses a Session with running work as `workspace/session-active` (returned here as *RPCError, whose Code names the refusal) unless ArchiveOptions.StopActivity is set, so a caller can decide whether stopping that work is part of its intent.
One Session is one call. A thread that also has a verifier is two Sessions and therefore two calls: the verifier is not mounted on the main session.
func (Client) CompactIntoNew ¶ added in v0.0.248
CompactIntoNew resets one Session into a new one whose seed is its compacted context: the Host compacts the source, materializes the resulting surface (summary plus the retained tail) as the child's log, and returns the child identity. The child log starts at the compacted size instead of copying the source transcript, which is what Fork does.
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) EditMessages ¶ added in v0.0.245
func (c Client) EditMessages(ctx context.Context, sessionID, requestID string, changes []EditedMessageChange) (EditResult, error)
EditMessages rewrites or removes messages the session already produced.
Unlike injection this targets existing history, so every change must name a current message; the batch is one DSH transaction and an invalid change rejects the whole batch. A running agent picks the change up at its next step rather than mid-step, and an idle one is woken.
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) InjectMessages ¶ added in v0.0.243
func (c Client) InjectMessages(ctx context.Context, sessionID, requestID string, messages []InjectedMessage) (InjectResult, error)
InjectMessages commits one batch of transcript messages in a single DSH transaction: the whole batch lands or none of it does, and DSH then lets the agent act on it — continuing the running turn, or opening one when idle.
The caller supplies requestID so an ambiguous transport failure can be retried without committing the batch twice.
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) RefreshModelCatalog ¶ added in v0.0.241
func (c Client) RefreshModelCatalog(ctx context.Context) (ModelCatalog, error)
RefreshModelCatalog re-probes live listings on the Host, then returns the same catalog document as ModelCatalog.
func (Client) SelectModel ¶ added in v0.0.246
func (c Client) SelectModel(ctx context.Context, sessionID, provider, model, reasoningEffort string) (ModelSelection, error)
SelectModel switches one Session's route without launching anything.
It is the runtime counterpart of CreateOptions.ModelSelection: that one seeds a brand new Session, this one changes a Session that already exists, including one that is running right now. A running Session picks the new route up at its next step rather than mid-step, because a model swap inside one request would cut the reasoning and tool-call semantics it already committed to.
The change is durable: DSH records it as a model/selection event, so closing and reopening the Session keeps it.
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 EditResult ¶ added in v0.0.245
type EditResult struct {
// Seq is the committed edit record.
Seq int64
// Started reports whether the agent runs on the edited history without
// another call.
Started bool
}
EditResult reports what one edit batch committed.
type EditedMessageChange ¶ added in v0.0.245
type EditedMessageChange struct {
// Seq names the message by its original surface seq; it is preserved.
Seq int64
// Text replaces the message content. Ignored when Delete is set.
Text string
// Delete removes the message from the model-visible history.
Delete bool
}
EditedMessageChange is one change to an already-produced message.
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 InjectResult ¶ added in v0.0.243
type InjectResult struct {
// Seqs are the committed event sequence numbers, in batch order.
Seqs []int64
// CallSeqs are the committed tool/call sequence numbers, in batch order. A
// call is a log event, so it appears here and not on the model-visible surface.
CallSeqs []int64
// ResultSeqs are the committed tool/result sequence numbers, in batch order.
ResultSeqs []int64
// Started reports whether the agent runs on the batch without another call.
Started bool
}
InjectResult reports what an injected batch committed.
type InjectedMessage ¶ added in v0.0.243
type InjectedMessage struct {
// Kind selects the transcript role: "user", "thinking", "assistant",
// "tool-call" or "tool-result".
Kind string
// Text is the message body. Blank text is rejected for the text kinds and
// for tool-result; a tool-call carries Arguments instead.
Text string
// Tool is the tool name for a tool-call.
Tool string
// Arguments is the raw JSON argument object for a tool-call.
Arguments string
// Call is the call seq a tool-result answers.
Call int64
// IsError marks a failed tool-result.
IsError bool
}
InjectedMessage is one transcript entry of an injected batch, in authored order: a user message, or an assistant message carrying reasoning (thinking) or text.
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 RPCError ¶ added in v0.0.245
type RPCError struct {
// Method is the RPC that was refused, e.g. "session/edit".
Method string
// Code is DSH's own error code, e.g. "session/edit-rejected".
Code string
}
RPCError is a refusal DSH itself produced, as opposed to a transport failure.
Only the code is carried: the server's message can quote request content, and callers log what this renders.
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.