Reach the first-party mobile client's everyday features: - sessions: a search button opens a field; typing asks the server with its search parameter (350 ms settle) and clearing restores the list - composer: attach photos or files (up to five, 10 MB each) as data URLs with the prompt; attachments show as removable chips and are named under the sent message - turn menu: read the answer aloud with the system voice, or stop it - chat: a "latest" button appears after scrolling up and returns to the end of the conversation - reset a live search when a connection ends Bump version to 0.2.0 (build 14).
71 lines
2.5 KiB
Go
71 lines
2.5 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)
|
|
}
|
|
|
|
// 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)
|
|
}
|