mobilebridge

package
v1.5.164 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mobilebridge exposes the mobile session boundary as a small, handle-based JSON API for native hosts. It deliberately has no UI or JNI dependency: the JNI entry points live in cmd/golder-mobile, and the service can be tested on a desktop with a fake backend.

Index

Constants

View Source
const Version = "0.1"

Version identifies the bridge ABI. A host must treat a mismatch as unsupported rather than guessing at field semantics.

Variables

This section is empty.

Functions

func CatalogJSON

func CatalogJSON() (string, error)

CatalogJSON returns the chat-provider catalog from the same registry the TUI uses. Decision-only endpoints are omitted because they cannot serve a turn.

Types

type Backend

type Backend interface {
	Start(prompt string) error
	PollJSON(max int) (string, error)
	SnapshotJSON() (string, error)
	Cancel()
	Close() error
}

Backend is one live conversation. The Android implementation wraps mobileagent.Session; tests use a fake.

type Catalog

type Catalog struct {
	Providers       []CatalogProvider `json:"providers"`
	DefaultProvider string            `json:"defaultProvider"`
	DefaultModel    string            `json:"defaultModel"`
}

Catalog is the provider/model/thinking data shown by a native host.

type CatalogProvider

type CatalogProvider struct {
	Name         string   `json:"name"`
	DefaultModel string   `json:"defaultModel"`
	Models       []string `json:"models"`
	Reasoning    []string `json:"reasoning"`
}

CatalogProvider is one provider choice for the native picker. Models is intentionally small: it contains the registry default, and the host may add a custom model id. Remote model discovery can fill this list later without changing the picker contract.

type Config

type Config struct {
	Workspace     string `json:"workspace"`
	Model         string `json:"model"`
	Provider      string `json:"provider,omitempty"`
	BaseURL       string `json:"baseUrl,omitempty"`
	Protocol      string `json:"protocol,omitempty"`
	APIKey        string `json:"apiKey,omitempty"`
	SystemPrompt  string `json:"systemPrompt,omitempty"`
	ContextWindow int    `json:"contextWindow,omitempty"`
	// StateDir, when set, enables local session persistence under
	// StateDir/sessions. SessionID selects an existing session; empty generates
	// one. The host supplies an app-private directory.
	StateDir  string `json:"stateDir,omitempty"`
	SessionID string `json:"sessionId,omitempty"`
	// GitAuthor* provide the commit identity. GitToken is used only for HTTPS
	// remotes. Empty token leaves clone/fetch/push unauthenticated (or denied by
	// the remote); it never appears in output.
	GitAuthorName  string `json:"gitAuthorName,omitempty"`
	GitAuthorEmail string `json:"gitAuthorEmail,omitempty"`
	GitToken       string `json:"gitToken,omitempty"`
	// AllowNetworkGit is a session capability, not a per-call decision. When
	// false, git clone/fetch/push fail closed; local Git still works.
	AllowNetworkGit bool `json:"allowNetworkGit,omitempty"`
	// ThinkingLevel is the selected reasoning level (low, medium, high, max).
	ThinkingLevel string `json:"thinkingLevel,omitempty"`
	// PermissionMode is one of read-only, ask, auto, full-access.
	PermissionMode string `json:"permissionMode,omitempty"`
	// AndroidUseEndpoint is the app-private loopback endpoint for the Phase 1
	// AccessibilityService. Empty leaves android_use out of the catalog.
	AndroidUseEndpoint string `json:"androidUseEndpoint,omitempty"`
	// AndroidUsePhase2 enables the separately consented background-display
	// surface. It is ignored unless AndroidUseEndpoint is also present.
	AndroidUsePhase2 bool `json:"androidUsePhase2,omitempty"`
	// TavilyAPIKey and ExaAPIKey select the web-search backend. Empty values
	// leave the keyless DuckDuckGo fallback; keys are passed to the tool, never
	// written to the environment.
	TavilyAPIKey   string `json:"tavilyApiKey,omitempty"`
	ExaAPIKey      string `json:"exaApiKey,omitempty"`
	DeepSeekAPIKey string `json:"deepSeekApiKey,omitempty"`
	// DebugLog is an optional host-only diagnostic path. The Android backend
	// appends loop event types and terminal errors (never prompts or secrets)
	// to it. Empty disables the log.
	DebugLog string `json:"debugLog,omitempty"`
}

Config is the host-owned setup for one mobile conversation. Secrets are accepted but never echoed in errors or events.

type Factory

type Factory func(Config) (Backend, error)

Factory builds a backend from host config. It must not expose the API key in an error.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the handle registry behind the JNI/C ABI. Operations on different handles proceed independently; operations on one handle are serialized so a close cannot race an in-flight poll.

func NewService

func NewService(factory Factory) *Service

NewService builds a registry around factory.

func (*Service) Cancel

func (s *Service) Cancel(handle int) error

Cancel asks the backend to stop its active run.

func (*Service) CatalogJSON

func (s *Service) CatalogJSON() (string, error)

CatalogJSON exposes the provider/model catalog without opening a session.

func (*Service) Close

func (s *Service) Close(handle int) error

Close drops handle and closes its backend. It is idempotent for an unknown handle so a host's lifecycle cleanup can run twice.

func (*Service) LastError

func (s *Service) LastError() string

LastError returns the most recent failure, or "".

func (*Service) ModelsJSON

func (s *Service) ModelsJSON(providerName, baseURL, apiKey, cacheDir string, refresh bool) (string, error)

ModelsJSON returns a phone cache snapshot immediately when refresh is false, or performs a network refresh when refresh is true. A stale cache survives a failed refresh and is returned with Error set.

func (*Service) Open

func (s *Service) Open(configJSON string) (handle int, err error)

Open decodes configJSON, builds a backend, and returns a handle > 0. A failure returns 0 and records LastError.

func (*Service) PauseForTakeover added in v1.5.104

func (s *Service) PauseForTakeover(handle int) error

PauseForTakeover latches the host-only admission barrier without waiting for in-flight calls. Poll TakeoverReady before allowing the person to interact.

func (*Service) PollJSON

func (s *Service) PollJSON(handle, max int) (string, error)

PollJSON drains up to max events from handle.

func (*Service) ResumeAfterTakeover added in v1.5.104

func (s *Service) ResumeAfterTakeover(handle int) error

ResumeAfterTakeover is invoked only by the local host after handback.

func (*Service) SnapshotJSON

func (s *Service) SnapshotJSON(handle int) (string, error)

SnapshotJSON returns one consistent state snapshot.

func (*Service) Start

func (s *Service) Start(handle int, prompt string) error

Start begins one run on handle.

func (*Service) TakeoverReady added in v1.5.104

func (s *Service) TakeoverReady(handle int) (bool, error)

TakeoverReady does not grant control: it only reports a previously latched, quiescent barrier. The Android host also owns the display-level handoff.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL