- sent images keep a local copy and render as rounded thumbnails in the message, surviving later page reloads - a prompt's menu can revert it and everything after it: confirm, then stage and commit the server-side revert - the app icon is OpenChamber's own (packages/mobile/assets/icon-only.png) - document a terminal assessment (native view vs Go ANSI vs xterm.js in a WebView) for the next decision Bump version to 0.2.1 (build 15).
85 lines
3.2 KiB
Go
85 lines
3.2 KiB
Go
package ocapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// PromptOptions configures Prompt.
|
|
type PromptOptions struct {
|
|
Directory string
|
|
// MessageID is an optional client-minted id (msg_…), which makes a
|
|
// retry after a lost response a no-op instead of a duplicate.
|
|
MessageID string
|
|
Text string
|
|
// Files ride with the prompt as data URLs (or URIs the server can
|
|
// read), as the web client sends them.
|
|
Files []PromptFile
|
|
}
|
|
|
|
// Prompt sends a user message to a session. The reply arrives through the
|
|
// event stream, not this call.
|
|
func (c *Client) Prompt(ctx context.Context, sessionID string, o PromptOptions) error {
|
|
body := map[string]any{"text": o.Text}
|
|
if o.MessageID != "" {
|
|
body["id"] = o.MessageID
|
|
}
|
|
if len(o.Files) > 0 {
|
|
body["files"] = o.Files
|
|
}
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/prompt"
|
|
return c.do(ctx, http.MethodPost, path, requestOptions{directory: o.Directory}, body, nil)
|
|
}
|
|
|
|
// StageRevert marks a reversible boundary at a message: everything after it
|
|
// can be dropped with CommitRevert.
|
|
func (c *Client) StageRevert(ctx context.Context, sessionID, directory, messageID string) error {
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/revert/stage"
|
|
return c.do(ctx, http.MethodPost, path, requestOptions{directory: directory},
|
|
map[string]any{"messageID": messageID}, nil)
|
|
}
|
|
|
|
// CommitRevert drops the messages a staged revert marked.
|
|
func (c *Client) CommitRevert(ctx context.Context, sessionID, directory string) error {
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/revert/commit"
|
|
return c.do(ctx, http.MethodPost, path, requestOptions{directory: directory}, map[string]any{}, nil)
|
|
}
|
|
|
|
// ForkSession copies the session's history before a message into a new
|
|
// session. An empty before copies the whole history.
|
|
func (c *Client) ForkSession(ctx context.Context, sessionID, directory, before string) (Session, error) {
|
|
body := map[string]any{}
|
|
if before != "" {
|
|
body["before"] = before
|
|
}
|
|
var payload struct {
|
|
Data Session `json:"data"`
|
|
}
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/fork"
|
|
err := c.do(ctx, http.MethodPost, path, requestOptions{directory: directory}, body, &payload)
|
|
return payload.Data, err
|
|
}
|
|
|
|
// Interrupt stops the turn the session is running.
|
|
func (c *Client) Interrupt(ctx context.Context, sessionID, directory string) (bool, error) {
|
|
var payload struct {
|
|
Interrupted bool `json:"interrupted"`
|
|
}
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/interrupt"
|
|
err := c.do(ctx, http.MethodPost, path, requestOptions{directory: directory}, map[string]any{}, &payload)
|
|
return payload.Interrupted, err
|
|
}
|
|
|
|
// SwitchModel changes the model later turns run on.
|
|
func (c *Client) SwitchModel(ctx context.Context, sessionID, directory string, model ModelRef) error {
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/model"
|
|
return c.do(ctx, http.MethodPost, path, requestOptions{directory: directory}, map[string]any{"model": model}, nil)
|
|
}
|
|
|
|
// SwitchAgent changes the agent later turns run with.
|
|
func (c *Client) SwitchAgent(ctx context.Context, sessionID, directory, agent string) error {
|
|
path := "/api/session/" + url.PathEscape(sessionID) + "/agent"
|
|
return c.do(ctx, http.MethodPost, path, requestOptions{directory: directory}, map[string]any{"agent": agent}, nil)
|
|
}
|