Files
openchamber-android-native/internal/ocapi/turn.go
T

49 lines
1.8 KiB
Go
Raw Normal View History

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
}
// 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
}
path := "/api/session/" + url.PathEscape(sessionID) + "/prompt"
return c.do(ctx, http.MethodPost, path, requestOptions{directory: o.Directory}, body, nil)
}
// 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)
}