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:
blumia committed 2026-11-16 09:09:09 +08:00
commit 254d08b1bd
35 files changed
+4922

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
// swift-tools-version:5.9
// The netcfg package's Swift, for iOS and macOS: the Asuka CLI builds it
// with the apps that import the package. Its dependencies (Swift
// packages) go here, as any package's.
import PackageDescription
let package = Package(
name: "NetcfgNative",
platforms: [.iOS("16.0"), .macOS("11.0")],
products: [.library(name: "NetcfgNative", targets: ["NetcfgNative"])],
dependencies: [
.package(url: "https://github.com/egoist/asuka", from: "0.1.0"),
],
targets: [
.target(name: "NetcfgNative", dependencies: [.product(name: "Asuka", package: "asuka")], path: "swift"),
]
)
+15
View File
@@ -0,0 +1,15 @@
// The netcfg package's Kotlin for Android: a library module the Asuka CLI
// builds into the apps that import the package. Its Kotlin is in its
// namespace; its dependencies (Maven's) go here, its permissions and
// services in src/main/AndroidManifest.xml.
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
android {
namespace = "com.github.openchamber.openchamber_native.netcfg"
}
dependencies {
}
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- OpenChamber servers are often self-hosted on a LAN over plain HTTP.
Asuka's own debug manifest enables cleartext, but a release build
would block it, so this library module merges the flag into every
variant. Remove this module to require HTTPS everywhere. -->
<application android:usesCleartextTraffic="true" />
</manifest>
@@ -0,0 +1,72 @@
// Code generated by asuka native. DO NOT EDIT.
// asuka:native f84252246ecd432c
// What the package's Go declares (package netcfg), as its Kotlin implements
// it. The Kotlin (in this package) writes the functions that make each:
//
// fun makeNetcfg(): Netcfg
@file:Suppress("unused", "RedundantVisibilityModifier")
package com.github.openchamber.openchamber_native.netcfg
import dev.asuka.AsukaModuleProvider
import dev.asuka.AsukaModules
import dev.asuka.AsukaNativeContext
import dev.asuka.AsukaNativeReader
import dev.asuka.AsukaNativeView
import dev.asuka.AsukaNativeWriter
import dev.asuka.AsukaDeclaredError
import dev.asuka.AsukaUnsupportedException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
/**
* Netcfg greets in each platform's own code.
*/
public interface Netcfg {
/**
* Hello greets name.
*/
fun hello(name: String): String
}
/** The package's native code as the host finds it (by its class's name): what makes, calls and shows what the package declares. */
public object AsukaModule : AsukaModuleProvider {
override fun make(iface: Int): Any = when (iface) {
0 -> makeNetcfg()
else -> throw AsukaUnsupportedException("no interface $iface")
}
override fun call(obj: Any, iface: Int, method: Int, r: AsukaNativeReader, w: AsukaNativeWriter) {
when (iface) {
0 -> {
val o = obj as Netcfg
when (method) {
1 -> { // Hello
val name = r.string()
r.check()
val v = o.hello(name)
w.string(v)
}
else -> throw AsukaUnsupportedException("no method $iface.$method")
}
}
else -> throw AsukaUnsupportedException("no interface $iface")
}
}
override fun start(obj: Any, iface: Int, method: Int, r: AsukaNativeReader, done: (Result<AsukaNativeWriter>) -> kotlin.Unit): Job? {
when (iface) {
}
throw AsukaUnsupportedException("no method $iface.$method")
}
override fun makeView(name: String, ctx: AsukaNativeContext): AsukaNativeView? = when (name) {
else -> null
}
}
/** The package's values on the wire (package native's format). */
private object Wire {
}
@@ -0,0 +1,9 @@
// The netcfg package's Kotlin: what its Go declares, implemented on
// Android (Netcfg.asuka.kt, beside it, is what asuka native generates).
package com.github.openchamber.openchamber_native.netcfg
private class KotlinNetcfg : Netcfg {
override fun hello(name: String) = "Hello, $name, from Kotlin"
}
fun makeNetcfg(): Netcfg = KotlinNetcfg()
+11
View File
@@ -0,0 +1,11 @@
// Package netcfg is a native module: Netcfg, which each platform's native
// code implements (asuka native).
package netcfg
// Netcfg greets in each platform's own code.
//
//asuka:native
type Netcfg interface {
// Hello greets name.
Hello(name string) (string, error)
}
+13
View File
@@ -0,0 +1,13 @@
//go:build windows || (linux && !android)
package netcfg
// On Windows and Linux the package's native code is Go: NewNetcfg returns
// this.
func init() {
implementNetcfg(func() (Netcfg, error) { return goHello{}, nil })
}
type goHello struct{}
func (goHello) Hello(name string) (string, error) { return "Hello, " + name + ", from Go", nil }
+50
View File
@@ -0,0 +1,50 @@
// Code generated by asuka native. DO NOT EDIT.
// asuka:native f84252246ecd432c
package netcfg
import (
"github.com/egoist/asuka/native"
)
// nativeModule is the package's native code, as the hosts find it.
var nativeModule = &native.Module{ID: "github.com/openchamber/openchamber-native/netcfg", Swift: "AsukaModule_github_com_openchamber_openchamber_native_netcfg", Kotlin: "com.github.openchamber.openchamber_native.netcfg.AsukaModule", Errors: []error{}}
// NewNetcfg makes the platform's Netcfg: Go's, where the package implements it
// in Go (implementNetcfg), else its native code's (Swift on iOS and macOS,
// Kotlin on Android, JavaScript on the web). Without one, it returns an
// error that is errors.ErrUnsupported.
func NewNetcfg() (Netcfg, error) {
if nativeImplNetcfg != nil {
return nativeImplNetcfg()
}
o, err := nativeModule.New(0, "Netcfg")
if err != nil {
return nil, err
}
return &nativeNetcfg{o}, nil
}
var nativeImplNetcfg func() (Netcfg, error)
// implementNetcfg makes NewNetcfg return Go's implementation: call it from an
// init function of a file built for the platforms where the package's
// native code is Go (Windows, Linux).
func implementNetcfg(make func() (Netcfg, error)) { nativeImplNetcfg = make }
// nativeNetcfg is a Netcfg on the platform's side.
type nativeNetcfg struct{ o *native.Object }
func (x *nativeNetcfg) Hello(name string) (string, error) {
w := native.NewWriter()
w.String(name)
r, err := x.o.Call(1, w)
if err != nil {
return "", err
}
v := r.String()
if err := r.Done(); err != nil {
return "", err
}
return v, nil
}
+58
View File
@@ -0,0 +1,58 @@
// Code generated by asuka native. DO NOT EDIT.
// asuka:native f84252246ecd432c
// What the package's Go declares (package netcfg), as its Swift implements
// it. The Swift writes the functions that make each:
//
// func makeNetcfg() throws -> any Netcfg
import Foundation
import Asuka
/// Netcfg greets in each platform's own code.
public protocol Netcfg: AnyObject {
/// Hello greets name.
func hello(name: String) throws -> String
}
/// The package's native code as the host finds it (by its Objective-C
/// name): what makes, calls and shows what the package declares.
@objc(AsukaModule_github_com_openchamber_openchamber_native_netcfg) public final class AsukaModule_github_com_openchamber_openchamber_native_netcfg: NSObject, AsukaModuleProvider {
public static func make(_ iface: UInt32) throws -> AnyObject {
switch iface {
case 0: return try makeNetcfg()
default: throw AsukaNativeError.unsupported("no interface \(iface)")
}
}
public static func call(_ object: AnyObject, _ iface: UInt32, _ method: UInt32, _ r: inout AsukaNativeReader, _ w: inout AsukaNativeWriter) throws {
switch (iface, method) {
case (0, 1): // Netcfg.Hello
let o = object as! any Netcfg
let name = r.string()
try r.check()
let v = try o.hello(name: name)
w.string(v)
default: throw AsukaNativeError.unsupported("no method \(iface).\(method)")
}
}
public static func start(_ object: AnyObject, _ iface: UInt32, _ method: UInt32, _ input: AsukaNativeReader, _ done: @escaping (Result<AsukaNativeWriter, Error>) -> Void) -> Task<Void, Never>? {
var r = input
switch (iface, method) {
default:
done(.failure(AsukaNativeError.unsupported("no method \(iface).\(method)")))
return nil
}
}
@MainActor public static func makeView(_ name: String, _ ctx: AsukaNativeContext) -> AsukaNativeView? {
switch name {
default: return nil
}
}
}
/// The package's values on the wire (package native's format).
fileprivate enum Wire {
}
+10
View File
@@ -0,0 +1,10 @@
// The netcfg package's Swift: what its Go declares, implemented on iOS
// and macOS (Netcfg.asuka.swift, beside it, is what asuka native generates).
import Asuka
import Foundation
final class SwiftNetcfg: Netcfg {
func hello(name: String) throws -> String { "Hello, \(name), from Swift" }
}
func makeNetcfg() throws -> any Netcfg { SwiftNetcfg() }
+55
View File
@@ -0,0 +1,55 @@
// Code generated by asuka native. DO NOT EDIT.
// asuka:native f84252246ecd432c
// What the package's Go declares (package netcfg), as its JavaScript
// implements it. netcfg.js exports the functions that make each:
//
// export function makeNetcfg() // returns its methods (lowerCamelCase)
//
// A method that takes a context in Go is async, and gets an AbortSignal
// first. int64 and uint64 are BigInts; a time is a Date; a duration is
// milliseconds; a []byte is a Uint8Array.
import * as impl from "./netcfg.js";
const { NativeWriter, NativeReader, DeclaredError, UnsupportedError, registerModule, retain, object } = globalThis.asuka.native;
const provider = {
make(iface) {
switch (iface) {
case 0: return impl.makeNetcfg();
}
throw new UnsupportedError(`no interface ${iface}`);
},
call(o, iface, method, r, w) {
switch (iface * 65536 + method) {
case 1: { // Netcfg.Hello
const name = r.string();
r.check();
const v = o.hello(name);
w.string(v);
return;
}
}
throw new UnsupportedError(`no method ${iface}.${method}`);
},
start(o, iface, method, r, signal) {
switch (iface * 65536 + method) {
}
throw new UnsupportedError(`no method ${iface}.${method}`);
},
makeView(name, ctx) {
switch (name) {
}
return null;
},
};
registerModule("github.com/openchamber/openchamber-native/netcfg", provider);
// The package's values on the wire (package native's format).
const Wire = {
};
+8
View File
@@ -0,0 +1,8 @@
// The netcfg package's JavaScript: what its Go declares, implemented on
// the web (netcfg.asuka.js, beside it, is what asuka native generates).
export function makeNetcfg() {
return {
hello: (name) => `Hello, ${name}, from the web`,
};
}