Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,41 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file

## Local custom build

### Source worktree setup

On macOS or Linux, install Go 1.26+ and the frontend's pinned Bun 1.3.14.
Then run `bash scripts/setup.sh` from a fresh checkout of this fork's `custom`
branch. It downloads Go modules, verifies their checksums, installs frozen Bun
dependencies, builds and embeds the custom panel, and builds `./cli-proxy-api`.
Generated output is ignored by Git. Repeating setup leaves tracked source files
alone. Setup does not install a service or copy credentials.

The commands use Bun 1.3.14 from PATH, or the machine's dedicated
`~/.local/share/codingbox/toolchains/bun/1.3.14/bin/bun`. Override that selection
with `BUN_BIN=/absolute/path/to/bun`. They leave other projects' Bun versions
alone. Go must be on PATH or installed at `~/.local/bin/go`.

Import the actions from `t3.json` into each T3 project and environment. Setup runs
when T3 creates a worktree and waits before the agent starts. `bash scripts/check.sh` runs
`bun run verify` in `web`, `go test -mod=readonly -p 2 ./...`, and a Go build.
A checked-in action still needs importing before it runs automatically.

Independent tasks use separate branches and worktrees. Each checkout owns its
`web/node_modules`, `web/dist`, embedded panel, and binary. Do not run
`scripts/install-local.sh` as worktree setup; it replaces the Mac's installed
binary and restarts a service.

For a development proxy, create a private, ignored config from
`config.example.yaml` with `server.host: "127.0.0.1"`, an unused `server.port`,
and a separate `oauth.auth-dir`.
Provider login callbacks also need unused ports; the CLI supports
`--oauth-callback-port`. Use `bun run dev -- --port <unused-port> --strictPort`
in `web` for a separate frontend. Never attach a test worktree to the production
proxy's config, account store, database, or Docker Compose project. Keep the
codingbox service and its existing port 8317 out of development runs.

### Service installation

`scripts/install-local.sh` builds the bundled `web/` management UI, embeds it into the Go binary, and installs a launchd agent (`dev.local.cliproxyapi`) that runs the local build with `CPA_TRUST_LOCAL_PANEL=1`, which lets the panel served by this binary use the management API without a key from the same loopback origin. It stops the Homebrew `cliproxyapi` service first (the formula is left installed).

Update flow:
Expand Down
9 changes: 9 additions & 0 deletions scripts/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
source scripts/toolchain.sh

(cd web && bun run verify)
cp web/dist/index.html internal/managementasset/panel/management.html
go test -mod=readonly -p 2 ./...
go build -mod=readonly -p 2 -o cli-proxy-api ./cmd/server
14 changes: 14 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."

source scripts/toolchain.sh

go mod download
go mod verify
(cd web && bun install --frozen-lockfile && bun run build)
cp web/dist/index.html internal/managementasset/panel/management.html
go build -mod=readonly -p 2 -o cli-proxy-api ./cmd/server

echo "Built ./cli-proxy-api with the custom management UI. No service was started."
24 changes: 24 additions & 0 deletions scripts/toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Sourced by the worktree setup and check commands.
if [[ -z "${BUN_BIN:-}" ]]; then
BUN_BIN=bun
if ! command -v bun >/dev/null 2>&1 || [[ "$(bun --version)" != "1.3.14" ]]; then
BUN_BIN="$HOME/.local/share/codingbox/toolchains/bun/1.3.14/bin/bun"
fi
fi
if ! command -v "$BUN_BIN" >/dev/null 2>&1 || [[ "$("$BUN_BIN" --version)" != "1.3.14" ]]; then
echo "Select Bun 1.3.14 with BUN_BIN=/path/to/bun." >&2
echo 'Install it with: curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.14"' >&2
exit 1
fi

if ! command -v go >/dev/null 2>&1; then
export PATH="$HOME/.local/bin:$PATH"
fi
if ! command -v go >/dev/null 2>&1; then
echo "Install Go 1.26+ first: https://go.dev/doc/install" >&2
exit 1
fi

# Bun package scripts invoke bun again, so use the selected runtime throughout.
export PATH="$(dirname "$(command -v "$BUN_BIN")"):$PATH"
20 changes: 20 additions & 0 deletions t3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://t3.codes/schema/t3.json",
"defaultThreadEnvMode": "worktree",
"scripts": [
{
"name": "Setup",
"command": "bash scripts/setup.sh",
"icon": "configure",
"runOnWorktreeCreate": true,
"async": false
},
{
"name": "Check",
"command": "bash scripts/check.sh",
"icon": "test",
"runOnWorktreeCreate": false,
"async": false
}
]
}
23 changes: 16 additions & 7 deletions web/tests/providerModelOptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, test } from 'bun:test';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { createInstance } from 'i18next';
import { I18nextProvider } from 'react-i18next';
import {
readModelOptions,
buildModelOptions,
Expand All @@ -10,6 +12,9 @@ import { ModelAdvancedFields } from '@/features/providers/sheets/forms/ModelAdva
import type { ModelEntryInput, ProviderBrand } from '@/features/providers/types';
import type { ModelAlias } from '@/types';

const i18n = createInstance();
await i18n.init({ lng: 'en', resources: { en: { translation: {} } } });

const draft = (model: ModelAlias): ModelEntryInput => ({
name: model.name,
thinkingJson: model.thinking === undefined ? undefined : JSON.stringify(model.thinking),
Expand Down Expand Up @@ -174,13 +179,17 @@ describe('provider model options', () => {

const render = (brand: ProviderBrand, disabled = false, enabled = true) =>
renderToStaticMarkup(
createElement(ModelAdvancedFields, {
entry: { name: 'model', thinkingEnabled: enabled },
providerBrand: brand,
disabled,
supportsThinking: true,
onUpdate: () => {},
})
createElement(
I18nextProvider,
{ i18n },
createElement(ModelAdvancedFields, {
entry: { name: 'model', thinkingEnabled: enabled },
providerBrand: brand,
disabled,
supportsThinking: true,
onUpdate: () => {},
})
)
);

test('gates fields by provider capability', () => {
Expand Down
Loading