diff --git a/README.md b/README.md index e2819281d4f..354b77d1217 100644 --- a/README.md +++ b/README.md @@ -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 --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: diff --git a/scripts/check.sh b/scripts/check.sh new file mode 100755 index 00000000000..b73cfc7b0de --- /dev/null +++ b/scripts/check.sh @@ -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 diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 00000000000..2020de44f7f --- /dev/null +++ b/scripts/setup.sh @@ -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." diff --git a/scripts/toolchain.sh b/scripts/toolchain.sh new file mode 100644 index 00000000000..7dc1c18ed2c --- /dev/null +++ b/scripts/toolchain.sh @@ -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" diff --git a/t3.json b/t3.json new file mode 100644 index 00000000000..a65346461c8 --- /dev/null +++ b/t3.json @@ -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 + } + ] +} diff --git a/web/tests/providerModelOptions.test.ts b/web/tests/providerModelOptions.test.ts index d609322895d..a7bc96e63bd 100644 --- a/web/tests/providerModelOptions.test.ts +++ b/web/tests/providerModelOptions.test.ts @@ -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, @@ -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), @@ -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', () => {