971e555ceb
Add a server-side close for operator chats, so finishing with a chat takes it out of the active list for every client without deleting anything. The brokered protocol gains chat_close and chat_reopen; chat_close stops a running turn by reusing the existing broker interrupt (its result carries an interrupted flag, so a stream is never left running into nothing) and then sets closed_at on the session's operator_sessions row. The session, its transcript and its history survive, and because the closed state lives in the registry chat_sessions reports it to every client, not just the one that asked. An id that is not a recorded operator session, including a pipeline-owned run session, is refused before anything is written. chat_reopen clears the state again, and simply prompting a closed session also clears it (the store clears closed_at on touch). The registry gains closed_at for a fresh database and an idempotent migration for one created before it existed. The app renders closed sessions under a labelled Closed section with a Closed chip, offers a Close action with a confirmation that says it stops a running turn, marks the chat closed on every device and deletes nothing, and a Reopen action on each closed row. The device-local hide is renamed Hide on this device, with a snackbar saying the chat stays on the server, so it is never confused with the real close. No new dependency, the installer and Docker files are untouched, and no run is started from the app. Checked before committing: the packaged templates carry no chat surface and need no update, and internal/author/install.go's managed inventory needs none either (this adds no reference file). The packaged authoring skill reference internal/author/skill/references/operations.md and the shared docs/cli.md and android/README.md are stale because of this change, but an item no longer edits a shared document: what is stale and what should change there is recorded in docs/notes/chat-close.md for the docs-fold writer, which is committed here with the change. Checks: gofmt clean, go build ./... and go vet ./... clean, and go test ./internal/protocol/... ./internal/pipeline/... ./internal/server/... ./internal/author/... pass. The app side is verified with :app:assembleDebug and :app:testDebugUnitTest (--offline --no-daemon, BUILD SUCCESSFUL); the on-device close, second-client and reopen check is deferred to visual review. Not deployed; deploying is the operator's step.
184 lines
8.3 KiB
Go
184 lines
8.3 KiB
Go
package protocol
|
|
|
|
import "git.a-wan.net/alan/pipelines/internal/buildinfo"
|
|
|
|
const (
|
|
Ping = "ping"
|
|
Pong = "pong"
|
|
Error = "error"
|
|
Submit = "submit"
|
|
Submitted = "submitted"
|
|
List = "list_pipelines"
|
|
PipelineList = "pipelines"
|
|
GetPipeline = "get_pipeline"
|
|
Pipeline = "pipeline"
|
|
ListTemplates = "list_templates"
|
|
Templates = "templates"
|
|
Validate = "validate"
|
|
Validated = "validated"
|
|
)
|
|
|
|
type Stage struct {
|
|
Limits *StageLimits `json:"limits,omitempty"`
|
|
Memory map[string]string `json:"memory,omitempty"`
|
|
Notify *NotificationPolicy `json:"notify,omitempty"`
|
|
Key string `json:"key"`
|
|
Type string `json:"type,omitempty"`
|
|
Output string `json:"output"`
|
|
Prompt string `json:"prompt"`
|
|
Configs map[string]string `json:"configs"`
|
|
Edges map[string]string `json:"edges"`
|
|
FallbackError bool `json:"fallback_error"`
|
|
// Additional type-specific Markdown blocks; legacy model fields remain above.
|
|
Blocks map[string]string `json:"blocks,omitempty"`
|
|
}
|
|
|
|
// Limits are enforced by the runner and never included in the model prompt.
|
|
type StageLimits struct {
|
|
MaxVisits int `json:"max_visits"`
|
|
On []string `json:"on,omitempty"`
|
|
}
|
|
|
|
type NotificationPolicy struct {
|
|
On []string `json:"on"`
|
|
Destination string `json:"destination"`
|
|
Artifacts []string `json:"artifacts,omitempty"`
|
|
}
|
|
|
|
// Public phone setup only. Never include publishing endpoints or credentials.
|
|
type NotificationEndpoint struct {
|
|
Destination string `json:"destination"`
|
|
ServerURL string `json:"server_url,omitempty"`
|
|
Topic string `json:"topic"`
|
|
}
|
|
|
|
type Template struct {
|
|
Key string `json:"key"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Source string `json:"source"`
|
|
Scheduled bool `json:"scheduled"`
|
|
}
|
|
|
|
type Graph struct {
|
|
Stages []Stage `json:"stages"`
|
|
Settings *Settings `json:"settings,omitempty"`
|
|
}
|
|
|
|
type Settings struct {
|
|
Prompt string `json:"prompt"`
|
|
Schedules []Schedule `json:"schedules"`
|
|
}
|
|
|
|
type Schedule struct {
|
|
Days []string `json:"days,omitempty"`
|
|
Times []string `json:"times,omitempty"`
|
|
Every string `json:"every,omitempty"`
|
|
Timezone string `json:"timezone,omitempty"`
|
|
}
|
|
|
|
type VersionSummary struct {
|
|
Version int `json:"version"`
|
|
Stages int `json:"stages"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
type PipelineDetail struct {
|
|
PipelineSummary
|
|
LatestVersion int `json:"latest_version"`
|
|
VersionCreatedAt string `json:"version_created_at"`
|
|
ContentHash string `json:"content_hash"`
|
|
Source string `json:"source"`
|
|
Graph Graph `json:"graph"`
|
|
Versions []VersionSummary `json:"versions"`
|
|
}
|
|
|
|
type PipelineSummary struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Version int `json:"version"`
|
|
Stages int `json:"stages"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
// Message is the JSON envelope shared by the server and client. It also brokers
|
|
// omni search: a client sends Type "search" with an ID, Query text, an optional
|
|
// Kind type filter and an optional Limit, and the server replies with Type
|
|
// "search_results", the echoed ID and a ranked SearchResponse. Both search fields
|
|
// are optional so older peers ignore them. See search.go for the per-type payloads
|
|
// and the ranking/kind/bound vocabulary.
|
|
type Message struct {
|
|
DefaultHarness string `json:"default_harness,omitempty"`
|
|
Build *buildinfo.Info `json:"build,omitempty"`
|
|
Protocol int `json:"protocol,omitempty"`
|
|
DefaultModel string `json:"default_model,omitempty"`
|
|
Evidence []SessionEvidence `json:"evidence,omitempty"`
|
|
Usage *UsageStats `json:"usage,omitempty"`
|
|
Status *SystemStatus `json:"status,omitempty"`
|
|
Graph *Graph `json:"graph,omitempty"`
|
|
ExpectedVersion int `json:"expected_version,omitempty"`
|
|
Templates []Template `json:"templates,omitempty"`
|
|
CreateOnly bool `json:"create_only,omitempty"`
|
|
NotificationEndpoints []NotificationEndpoint `json:"notification_endpoints,omitempty"`
|
|
Type string `json:"type"`
|
|
ID string `json:"id,omitempty"`
|
|
Time string `json:"time,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
Source string `json:"source,omitempty"`
|
|
Title string `json:"title,omitempty"`
|
|
Version int `json:"version,omitempty"`
|
|
Pipelines []PipelineSummary `json:"pipelines,omitempty"`
|
|
PipelineID int64 `json:"pipeline_id,omitempty"`
|
|
Detail *PipelineDetail `json:"detail,omitempty"`
|
|
RunID int64 `json:"run_id,omitempty"`
|
|
RunDetail *RunDetail `json:"run_detail,omitempty"`
|
|
Runs []RunSummary `json:"runs,omitempty"`
|
|
Stage string `json:"stage,omitempty"`
|
|
Option string `json:"option,omitempty"`
|
|
Feedback string `json:"feedback,omitempty"`
|
|
Input map[string]any `json:"input,omitempty"`
|
|
AllowTools bool `json:"allow_tools,omitempty"`
|
|
WritePaths []string `json:"write_paths,omitempty"`
|
|
RequestKey string `json:"request_key,omitempty"`
|
|
Workspace string `json:"workspace,omitempty"`
|
|
// Model and StageModels are the launch-time model overrides: Model applies to
|
|
// every model stage of the run and StageModels overrides individual stages by
|
|
// key (per-stage wins over whole-run). Both are optional so older peers ignore
|
|
// them; the same fields are echoed on the run record.
|
|
Model string `json:"model,omitempty"`
|
|
StageModels map[string]string `json:"stage_models,omitempty"`
|
|
// Search is the broad, read-only search traffic over pipelines, versions,
|
|
// runs, steps, field text and artifacts. See search.go for the per-type
|
|
// payloads and the ranking/kind/bound vocabulary.
|
|
Search *SearchRequest `json:"search,omitempty"`
|
|
SearchResults *SearchResponse `json:"search_results,omitempty"`
|
|
// Chat is the brokered OpenCode chat traffic (route B). See chat.go for the
|
|
// per-type payload structs and the wire shapes they mirror.
|
|
ChatSessions []ChatSession `json:"chat_sessions,omitempty"`
|
|
ChatSession *ChatSession `json:"chat_session,omitempty"`
|
|
ChatCreate *ChatCreateRequest `json:"chat_create,omitempty"`
|
|
ChatAdopt *ChatAdoptRequest `json:"chat_adopt,omitempty"`
|
|
ChatQuery *ChatQuery `json:"chat_query,omitempty"`
|
|
ChatPrompt *ChatPromptRequest `json:"chat_prompt,omitempty"`
|
|
ChatMessages []ChatMessage `json:"chat_messages,omitempty"`
|
|
ChatEvent *ChatEventFrame `json:"chat_event,omitempty"`
|
|
ChatPermission *ChatPermissionFrame `json:"chat_permission,omitempty"`
|
|
ChatReply *ChatReplyRequest `json:"chat_reply,omitempty"`
|
|
// ChatClose carries the outcome of a chat_close; the close and reopen
|
|
// requests themselves ride on ChatQuery (the session id), matching
|
|
// chat_messages/chat_interrupt.
|
|
ChatClose *ChatCloseResult `json:"chat_close,omitempty"`
|
|
// ChatDirectories carries the operator's directory choices on a
|
|
// chat_directories response (home first, then recent operator-session
|
|
// directories, deduplicated and bounded). Additive/omitempty so older peers
|
|
// ignore it.
|
|
ChatDirectories []string `json:"chat_directories,omitempty"`
|
|
// RunEvent is the server-pushed run state delta (see runevents.go) and
|
|
// RunIDs the optional subscribe scope, so a client asks for the runs it
|
|
// displays. Both are optional so older peers ignore them.
|
|
RunEvent *RunEventFrame `json:"run_event,omitempty"`
|
|
RunIDs []int64 `json:"run_ids,omitempty"`
|
|
}
|