feat: bootstrap OpenChamber native Android client
Add a Go client for OpenChamber built with Asuka's native widgets. - internal/ocapi: health, password-to-device-token auth, session and message paging, prompt/interrupt/model/agent, permissions, SSE events, HTTP/SOCKS5 proxies and certificate pinning - internal/storage: connection settings plus a device token in the platform keystore, with a per-install id for server-side dedupe - internal/appui: connect, session list and chat screens with streaming Markdown, reasoning/tool folding, permission cards and session actions - netcfg: native module that enables cleartext HTTP in release builds - cmd/ocprobe: terminal probe for the API - headless UI tests (uitest) and the research/plan document
This commit is contained in:
commit
254d08b1bd
35 files changed
+4922
No files matched your search
@@ -0,0 +1,49 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user