package protocol // ChatShown is the pushed frame type for an item a chat's model showed the // operator through the Pipelines tools (show_file, show_image, show_html, // show_diff, show_run, notify). The chat_subscribe reply carries the retained // list in the same ChatShown field. const ChatShown = "chat_shown" // The ChatShownItem kinds. const ( ChatShownFile = "file" ChatShownImage = "image" ChatShownHTML = "html" ChatShownDiff = "diff" ChatShownRun = "run" ChatShownNotify = "notify" ) // ChatShownLimit bounds the items retained per chat, and ChatShownHTMLBudget // the HTML and diff bytes kept across them: older documents and diffs beyond // it keep their entry but drop the body (Expired). const ( ChatShownLimit = 100 ChatShownHTMLBudget = 2 << 20 ) // The ChatShownItem file states, computed when a chat's items are listed. const ( // ChatShownFileChanged: the live file differs from what was shown. ChatShownFileChanged = "changed" // ChatShownFileMissing: the file (or its snapshot) no longer exists. ChatShownFileMissing = "missing" ) // ChatShownFrame is one chat's shown items, oldest first. type ChatShownFrame struct { SessionID string `json:"session_id"` Items []ChatShownItem `json:"items"` } // ChatShownItem is one entry. A file or image Path is an absolute path on the // chat's own machine, served by that machine's /files endpoint. When Snapshot // is set, Path is a copy Pipelines took when the item was shown (Source is the // path the model named; URL the https address an image was fetched from); // otherwise Path is the live file, and ModTime and SHA256 record what was // shown so State can say it changed since. A web image without Path is an // older entry the client loads from URL itself. A replaced item keeps its ID // and CreatedAt (its place in the transcript) and sets UpdatedAt. type ChatShownItem struct { ID string `json:"id"` Kind string `json:"kind"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at,omitempty"` Title string `json:"title,omitempty"` Path string `json:"path,omitempty"` Name string `json:"name,omitempty"` Size int64 `json:"size,omitempty"` Mime string `json:"mime,omitempty"` Snapshot bool `json:"snapshot,omitempty"` Source string `json:"source,omitempty"` ModTime int64 `json:"mod_time,omitempty"` SHA256 string `json:"sha256,omitempty"` // State is ChatShownFileChanged or ChatShownFileMissing, else empty. State string `json:"state,omitempty"` URL string `json:"url,omitempty"` Alt string `json:"alt,omitempty"` HTML string `json:"html,omitempty"` HTMLBytes int `json:"html_bytes,omitempty"` // Diff is a show_diff item's repository comparison; DiffBytes is the size // of its patches, counted against ChatShownHTMLBudget. Diff *ChatShownDiffBody `json:"diff,omitempty"` DiffBytes int `json:"diff_bytes,omitempty"` // Run is a show_run item's run, kept current as the run changes. Run *ChatShownRunBody `json:"run,omitempty"` // HeightHint is the model's preferred inline height in logical pixels. HeightHint int `json:"height_hint,omitempty"` Expired bool `json:"expired,omitempty"` Message string `json:"message,omitempty"` Priority string `json:"priority,omitempty"` Delivered bool `json:"delivered,omitempty"` // Detail says why a notification was not delivered (or not to the phone). Detail string `json:"detail,omitempty"` // Channels says where a delivered notification went: "apps" (the // operator's signed-in Pipelines apps) and/or "phone" (ntfy). Channels []string `json:"channels,omitempty"` } // ChatShownRunBody is the run a show_run item follows. StartedAt and // FinishedAt are epoch milliseconds (FinishedAt zero while it runs). type ChatShownRunBody struct { ID int64 `json:"id"` Pipeline string `json:"pipeline"` Title string `json:"title,omitempty"` Status string `json:"status"` Outcome string `json:"outcome,omitempty"` CurrentStage string `json:"current_stage,omitempty"` Workspace string `json:"workspace,omitempty"` StartedAt int64 `json:"started_at,omitempty"` FinishedAt int64 `json:"finished_at,omitempty"` } // ChatShownDiffBody is one Git comparison a chat's model showed: the work tree // (or HEAD when CommittedOnly, or HeadRevision when set) of Repo against // BaseCommit, which is HEAD when Base is empty and the merge base with Base // otherwise. Paths, when set, limits the comparison to those paths or globs. // Changes uses the same per-file shape as a run's recorded changes; it is nil // once Expired. type ChatShownDiffBody struct { Repo string `json:"repo"` Base string `json:"base,omitempty"` BaseCommit string `json:"base_commit,omitempty"` Head string `json:"head,omitempty"` HeadRevision string `json:"head_revision,omitempty"` Paths []string `json:"paths,omitempty"` CommittedOnly bool `json:"committed_only,omitempty"` Files int `json:"files"` Additions int `json:"additions"` Deletions int `json:"deletions"` Changes *StageFileChanges `json:"changes,omitempty"` }