@raingor/pi-web-switch 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +137 -0
- package/README.md +277 -0
- package/README.zh-CN.md +176 -0
- package/index.html +13 -0
- package/package.json +44 -0
- package/pi-package/index.ts +100 -0
- package/pi-package/skills/pi-web-switch/SKILL.md +60 -0
- package/public/pi.svg +4 -0
- package/server/pi-reader.ts +678 -0
- package/src/App.tsx +25 -0
- package/src/components/dashboard/DashboardPage.tsx +607 -0
- package/src/components/layout/AppShell.tsx +18 -0
- package/src/components/layout/Sidebar.tsx +116 -0
- package/src/components/models/ModelsPage.tsx +570 -0
- package/src/components/providers/ProvidersPage.tsx +466 -0
- package/src/components/sessions/MemoryPage.tsx +177 -0
- package/src/components/sessions/SessionsPage.tsx +347 -0
- package/src/components/settings/SettingsPage.tsx +351 -0
- package/src/components/ui/Badge.tsx +29 -0
- package/src/components/ui/EmptyState.tsx +20 -0
- package/src/components/ui/Modal.tsx +41 -0
- package/src/components/ui/StatCard.tsx +37 -0
- package/src/data/builtin-providers.ts +148 -0
- package/src/data/mock-config.ts +261 -0
- package/src/data/mock-usage.ts +153 -0
- package/src/index.css +217 -0
- package/src/lib/config.ts +56 -0
- package/src/lib/currency.ts +48 -0
- package/src/lib/i18n.tsx +98 -0
- package/src/lib/translations/en.ts +168 -0
- package/src/lib/translations/index.ts +14 -0
- package/src/lib/translations/ja.ts +158 -0
- package/src/lib/translations/zh-CN.ts +158 -0
- package/src/lib/translations/zh-TW.ts +158 -0
- package/src/lib/utils.ts +51 -0
- package/src/main.tsx +106 -0
- package/src/store/config-store.ts +459 -0
- package/src/types/index.ts +187 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +24 -0
- package/vite.config.ts +172 -0
package/README.ja.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="public/pi.svg" width="80" height="80" alt="pi-switch logo" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">pi-web-switch</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>pi コーディングエージェントの Web 管理パネル — リアルタイム設定管理、セッションブラウザ、メモリビューア</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="README.md">🇬🇧 English</a> ·
|
|
13
|
+
<a href="README.zh-CN.md">🇨🇳 中文</a> ·
|
|
14
|
+
<a href="README.ja.md">🇯🇵 日本語</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src="https://img.shields.io/badge/React-19-61DAFB?logo=react" alt="React 19" />
|
|
19
|
+
<img src="https://img.shields.io/badge/TypeScript-5.8-3178C6?logo=typescript" alt="TypeScript" />
|
|
20
|
+
<img src="https://img.shields.io/badge/Tailwind-4-06B6D4?logo=tailwindcss" alt="Tailwind v4" />
|
|
21
|
+
<img src="https://img.shields.io/badge/Vite-6-646CFF?logo=vite" alt="Vite 6" />
|
|
22
|
+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License" />
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<a href="https://github.com/farion1231/cc-switch">cc-switch</a> にインスパイアされた、<a href="https://pi.dev">pi コーディングエージェント</a>のプロバイダー、モデル、トークン使用量、セッション、設定を管理するビジュアルダッシュボード。
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<strong><code>~/.pi/agent/</code> から直接データを読み取り</strong> — モックデータ、データベース、追加バックエンド不要。
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ✨ 機能
|
|
36
|
+
|
|
37
|
+
### 📊 ダッシュボード
|
|
38
|
+
- **使用統計** — 今日/7日/30日/カスタム日付範囲 + 自動更新(5s/10s/30s/60s)
|
|
39
|
+
- **トークン明細** — 正確な値 + 概算表示(例 `1,631,022 ≈ 163.1万`)、入出力/キャッシュ内訳
|
|
40
|
+
- **コスト追跡** — 日次コストチャート + Provider/Model 統計タブ
|
|
41
|
+
- **キャッシュヒット率** — 進行状況バーで表示
|
|
42
|
+
- **リクエストログ** — 時間、プロバイダー、モデル、トークン、コストの詳細表
|
|
43
|
+
- **通貨切替** — USD/CNY リアルタイム換算(1 USD = 7.2 CNY)
|
|
44
|
+
- **時間粒度** — 今日は時間別、7日/30日は日別表示
|
|
45
|
+
|
|
46
|
+
### 📦 モデル管理
|
|
47
|
+
- **モデルグリッド** — 全プロバイダーのモデルを検索・フィルターで閲覧
|
|
48
|
+
- **有効/無効** — モデルのオン/オフ切り替え
|
|
49
|
+
- **モデル編集** — 機能、コスト、コンテキストウィンドウ、最大トークンを更新
|
|
50
|
+
- **モデル追加** — 任意のプロバイダーに新しいモデルを作成
|
|
51
|
+
- **モデル削除** — カスタムモデルを削除
|
|
52
|
+
|
|
53
|
+
### 🔌 プロバイダー管理
|
|
54
|
+
- **プロバイダー一覧** — 全ビルトイン・カスタムプロバイダーを表示
|
|
55
|
+
- **カスタムプロバイダー** — Ollama、vLLM、LM Studio 等を追加
|
|
56
|
+
- **API キー管理** — プロバイダーごとに API キーを設定/削除
|
|
57
|
+
- **プロバイダー設定** — baseUrl、API タイプ、カスタムヘッダー
|
|
58
|
+
|
|
59
|
+
### 💬 セッション
|
|
60
|
+
- **プロジェクトグループ化** — ディレクトリ名を自動デコード
|
|
61
|
+
- **セッションブラウザ** — 100+ の全セッションを表示
|
|
62
|
+
- **セッション詳細** — 名前、時間、メッセージ数、所要時間、使用モデル
|
|
63
|
+
- **検索とフィルター** — プロジェクト名で絞り込み
|
|
64
|
+
- **セッション削除** — 3日以内に更新されたものは保護
|
|
65
|
+
|
|
66
|
+
### 🧠 メモリ (pi-hermes-memory)
|
|
67
|
+
- プロジェクトメモリ / ユーザープロファイル / 障害記録を Markdown 表示
|
|
68
|
+
|
|
69
|
+
### 🌐 多言語
|
|
70
|
+
- English 🇬🇧 / 简体中文 🇨🇳 / 繁體中文 🇭🇰 / 日本語 🇯🇵
|
|
71
|
+
- サイドバー下部の言語切替器、セッション間で保持
|
|
72
|
+
|
|
73
|
+
### ⚙️ 設定
|
|
74
|
+
- デフォルト値、テーマ(Light/Dark/System)、有効モデル、パッケージ管理
|
|
75
|
+
- インポート/エクスポート、リセット
|
|
76
|
+
|
|
77
|
+
## 🚀 始め方
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
git clone https://github.com/Raingor/pi-web-switch.git
|
|
81
|
+
cd pi-web-switch
|
|
82
|
+
npm install
|
|
83
|
+
npm run dev # 開発サーバー起動(~/.pi/agent/ を自動読込)
|
|
84
|
+
npm run build # プロダクションビルド
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 🏗️ 技術スタック
|
|
88
|
+
|
|
89
|
+
React 19 + TypeScript 5.8 + Vite 6 + Tailwind CSS v4 + Zustand + Recharts + Lucide React + React Router v7
|
|
90
|
+
|
|
91
|
+
## 📦 Pi パッケージ
|
|
92
|
+
|
|
93
|
+
pi-web-switch は **pi コーディングエージェント拡張** としてインストール可能で、pi セッションから直接ダッシュボードを起動・停止できます。
|
|
94
|
+
|
|
95
|
+
### インストール
|
|
96
|
+
|
|
97
|
+
`~/.pi/agent/settings.json` の packages に `npm:pi-web-switch` を追加:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"packages": ["npm:pi-web-switch"]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### コマンド
|
|
106
|
+
|
|
107
|
+
インストール後、pi セッションで以下のコマンドが使用可能:
|
|
108
|
+
|
|
109
|
+
| コマンド | 説明 |
|
|
110
|
+
|---------|------|
|
|
111
|
+
| `/pi-web-switch start` | ダッシュボード起動 http://localhost:5173 |
|
|
112
|
+
| `/pi-web-switch stop` | サーバー停止 |
|
|
113
|
+
| `/pi-web-switch status` | 実行状態を確認 |
|
|
114
|
+
|
|
115
|
+
### パッケージ構造
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
pi-web-switch/
|
|
119
|
+
├── package.json # npm パッケージ + pi.extensions + pi.skills
|
|
120
|
+
├── pi-package/
|
|
121
|
+
│ ├── index.ts # 拡張エントリ:/pi-web-switch コマンド登録
|
|
122
|
+
│ └── skills/
|
|
123
|
+
│ └── pi-web-switch/
|
|
124
|
+
│ └── SKILL.md # 使用ドキュメント
|
|
125
|
+
├── server/
|
|
126
|
+
│ └── pi-reader.ts # サーバーサイド:~/.pi/agent/ 読み取り
|
|
127
|
+
└── src/ # React フロントエンド
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 🔗 リンク
|
|
131
|
+
|
|
132
|
+
- **ホームページ:** [raingor.github.io/my-blog](https://raingor.github.io/my-blog/)
|
|
133
|
+
- **GitHub:** [github.com/Raingor](https://github.com/Raingor)
|
|
134
|
+
|
|
135
|
+
## 📄 ライセンス
|
|
136
|
+
|
|
137
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="public/pi.svg" width="80" height="80" alt="pi-switch logo" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">pi-web-switch</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Web UI for pi coding agent — live configuration management, session browser, and memory viewer</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="README.md">🇬🇧 English</a> ·
|
|
13
|
+
<a href="README.zh-CN.md">🇨🇳 中文</a> ·
|
|
14
|
+
<a href="README.ja.md">🇯🇵 日本語</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src="https://img.shields.io/badge/React-19-61DAFB?logo=react" alt="React 19" />
|
|
19
|
+
<img src="https://img.shields.io/badge/TypeScript-5.8-3178C6?logo=typescript" alt="TypeScript" />
|
|
20
|
+
<img src="https://img.shields.io/badge/Tailwind-4-06B6D4?logo=tailwindcss" alt="Tailwind v4" />
|
|
21
|
+
<img src="https://img.shields.io/badge/Vite-6-646CFF?logo=vite" alt="Vite 6" />
|
|
22
|
+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License" />
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
Inspired by <a href="https://github.com/farion1231/cc-switch">cc-switch</a> — a visual dashboard for managing your <a href="https://pi.dev">pi coding agent</a> providers, models, token usage, sessions, and settings.
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<strong>Reads data directly from <code>~/.pi/agent/</code></strong> — no mock data, no database, no backend setup required.
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ✨ Features
|
|
36
|
+
|
|
37
|
+
### 📊 Dashboard
|
|
38
|
+
- **Usage Statistics** — Today / 7 days / 30 days / Custom date range selector with auto-refresh (5s/10s/30s/60s)
|
|
39
|
+
- **Token Breakdown** — Exact token count with approximate display (e.g. `1,631,022 ≈ 1.6M`) and Input/Output/Cache Hit/Cache Create breakdown
|
|
40
|
+
- **Cost Tracking** — Daily cost chart + Provider/Model stats tabs with aggregated data
|
|
41
|
+
- **Cache Hit Rate** — Visual progress bar showing cache efficiency
|
|
42
|
+
- **Request Log** — Detailed log table with time, provider, model, tokens, cost
|
|
43
|
+
- **Currency Switch** — Toggle between USD and CNY with real-time conversion (1 USD = 7.2 CNY)
|
|
44
|
+
- **Hourly/Daily Granularity** — Today view shows per-hour data; 7d/30d views show per-day data
|
|
45
|
+
- All data sourced from **real pi session files** (`~/.pi/agent/sessions/*.jsonl`)
|
|
46
|
+
|
|
47
|
+
### 📦 Models
|
|
48
|
+
- **Model Grid** — Browse all built-in and custom models with search and filter
|
|
49
|
+
- **Enable/Disable** — Toggle models on/off to match your `enabledModels` config
|
|
50
|
+
- **Edit Model** — Update capabilities, cost, context window, max tokens
|
|
51
|
+
- **Add Model** — Create new models for any provider
|
|
52
|
+
- **Delete Model** — Remove custom models
|
|
53
|
+
|
|
54
|
+
### 🔌 Providers
|
|
55
|
+
- **Provider List** — Expandable cards for all built-in and custom providers
|
|
56
|
+
- **Custom Providers** — Add Ollama, vLLM, LM Studio, or any OpenAI-compatible provider
|
|
57
|
+
- **API Key Management** — Set/remove API keys per provider (saved to `auth.json`)
|
|
58
|
+
- **Provider Configuration** — baseUrl, API type, custom headers, auth method
|
|
59
|
+
|
|
60
|
+
### 💬 Sessions
|
|
61
|
+
- **Project Grouping** — Auto-decodes session directory names into project paths
|
|
62
|
+
- **Session Browser** — View all 100+ sessions across projects
|
|
63
|
+
- **Session Details** — Name, timestamp, message count, duration, provider/model used
|
|
64
|
+
- **Search & Filter** — Filter sessions by project name
|
|
65
|
+
- **Delete Sessions** — Remove old session files (sessions updated within 3 days are protected)
|
|
66
|
+
|
|
67
|
+
### 🧠 Memory (pi-hermes-memory)
|
|
68
|
+
- **Project Memories** — View `MEMORY.md` content with Markdown rendering
|
|
69
|
+
- **User Profile** — Display `USER.md` preferences and settings
|
|
70
|
+
- **Failure Records** — Browse `failures.md` known issues
|
|
71
|
+
- **Live Sync** — Content updates immediately when memory files change on disk
|
|
72
|
+
|
|
73
|
+
### 🌐 Multi-language
|
|
74
|
+
- **English** 🇬🇧 — Default
|
|
75
|
+
- **Simplified Chinese** 🇨🇳 — 简体中文
|
|
76
|
+
- **Traditional Chinese** 🇭🇰 — 繁體中文
|
|
77
|
+
- **Japanese** 🇯🇵 — 日本語
|
|
78
|
+
- Language switcher in sidebar footer, persists across sessions
|
|
79
|
+
|
|
80
|
+
### ⚙️ Settings
|
|
81
|
+
- **Defaults** — Default provider, model, thinking level, project trust
|
|
82
|
+
- **Theme** — Light / Dark / System with immediate toggle (CSS variables for both modes)
|
|
83
|
+
- **Enabled Models** — View and manage the full enabled models list
|
|
84
|
+
- **Extensions & Packages** — Manage pi packages list
|
|
85
|
+
- **Import/Export** — Download full config as JSON, restore from backup
|
|
86
|
+
- **Reset** — Factory reset to blank configuration
|
|
87
|
+
|
|
88
|
+
## 🌗 Theme Support
|
|
89
|
+
|
|
90
|
+
Full light and dark mode with system-follow support. Theme toggles instantly via CSS custom properties — no page reload needed. All components adapt including sidebar, modals, forms, charts, and scrollbars.
|
|
91
|
+
|
|
92
|
+
## 🧱 Built-in Providers
|
|
93
|
+
|
|
94
|
+
The app ships with definitions for **11 built-in providers** and **26 models** (hardcoded from pi's Rust source):
|
|
95
|
+
|
|
96
|
+
| Provider | Models |
|
|
97
|
+
|----------|--------|
|
|
98
|
+
| Anthropic | Claude Sonnet 4, Sonnet 4.5, Opus 4, Haiku 3.5 |
|
|
99
|
+
| OpenAI | GPT-4o, GPT-4o-mini, GPT-5.1, o3-mini |
|
|
100
|
+
| DeepSeek | DeepSeek V3, DeepSeek R1 |
|
|
101
|
+
| OpenCode | DeepSeek V4 Flash (Free), DeepSeek V4 Flash |
|
|
102
|
+
| OpenCode Go | DeepSeek V4 Flash, V4 Pro, GLM 5.1, Qwen 3.7 Max, MiMo V2.5 |
|
|
103
|
+
| SenseNova | GLM 5.2, DeepSeek V4 Flash |
|
|
104
|
+
| Google Gemini | Gemini 2.5 Flash, Gemini 2.5 Pro |
|
|
105
|
+
| OpenRouter | Claude Sonnet 4, DeepSeek R1 |
|
|
106
|
+
| Mistral | Mistral Large |
|
|
107
|
+
| GitHub Copilot | Copilot GPT-4o |
|
|
108
|
+
| Groq | Llama 3.3 70B |
|
|
109
|
+
|
|
110
|
+
## 🚀 Getting Started
|
|
111
|
+
|
|
112
|
+
### Prerequisites
|
|
113
|
+
|
|
114
|
+
- **pi coding agent** installed and configured (so `~/.pi/agent/` exists)
|
|
115
|
+
- Node.js 18+
|
|
116
|
+
|
|
117
|
+
### Setup
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Clone
|
|
121
|
+
git clone https://github.com/Raingor/pi-web-switch.git
|
|
122
|
+
cd pi-web-switch
|
|
123
|
+
|
|
124
|
+
# Install dependencies
|
|
125
|
+
npm install
|
|
126
|
+
|
|
127
|
+
# Start dev server (reads ~/.pi/agent/ automatically)
|
|
128
|
+
npm run dev
|
|
129
|
+
|
|
130
|
+
# Build for production
|
|
131
|
+
npm run build
|
|
132
|
+
|
|
133
|
+
# Preview production build
|
|
134
|
+
npm run preview
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The dev server automatically serves pi configuration via Vite middleware at `/api/pi/*` — no separate backend process needed.
|
|
138
|
+
|
|
139
|
+
## 🏗️ Tech Stack
|
|
140
|
+
|
|
141
|
+
| Layer | Technology |
|
|
142
|
+
|-------|-----------|
|
|
143
|
+
| Framework | [React 19](https://react.dev/) |
|
|
144
|
+
| Language | [TypeScript 5.8](https://www.typescriptlang.org/) |
|
|
145
|
+
| Build | [Vite 6](https://vitejs.dev/) |
|
|
146
|
+
| Styling | [Tailwind CSS v4](https://tailwindcss.com/) |
|
|
147
|
+
| State | [Zustand](https://github.com/pmndrs/zustand) |
|
|
148
|
+
| Charts | [Recharts](https://recharts.org/) |
|
|
149
|
+
| Icons | [Lucide React](https://lucide.dev/) |
|
|
150
|
+
| Routing | [React Router v7](https://reactrouter.com/) |
|
|
151
|
+
|
|
152
|
+
## 🗂️ Project Structure
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
pi-web-switch/
|
|
156
|
+
├── index.html
|
|
157
|
+
├── package.json
|
|
158
|
+
├── vite.config.ts # Vite config + pi API plugin (middleware)
|
|
159
|
+
├── tsconfig.json
|
|
160
|
+
├── server/
|
|
161
|
+
│ └── pi-reader.ts # Server-side module: reads ~/.pi/agent/ files + parses sessions
|
|
162
|
+
├── public/
|
|
163
|
+
│ └── pi.svg
|
|
164
|
+
└── src/
|
|
165
|
+
├── main.tsx # Entry point + theme sync + init gate + i18n provider
|
|
166
|
+
├── App.tsx # Router setup (6 routes)
|
|
167
|
+
├── index.css # Tailwind + CSS theme variables (light/dark)
|
|
168
|
+
├── types/index.ts # All TypeScript interfaces
|
|
169
|
+
├── data/
|
|
170
|
+
│ └── builtin-providers.ts # Hardcoded built-in provider definitions
|
|
171
|
+
├── store/
|
|
172
|
+
│ └── config-store.ts # Zustand store (fetches from /api/pi/*)
|
|
173
|
+
├── lib/
|
|
174
|
+
│ ├── utils.ts # Formatting helpers (tokens, cost with USD/CNY)
|
|
175
|
+
│ ├── i18n.tsx # Multi-language system (React Context + hook)
|
|
176
|
+
│ ├── currency.ts # Currency switching (USD/CNY toggle)
|
|
177
|
+
│ ├── config.ts # Config import/export helpers
|
|
178
|
+
│ └── translations/ # Translation files (en, zh-CN, zh-TW, ja)
|
|
179
|
+
└── components/
|
|
180
|
+
├── layout/ # AppShell, Sidebar (6 nav items + language switcher)
|
|
181
|
+
├── ui/ # StatCard, Badge, Modal, EmptyState
|
|
182
|
+
├── dashboard/ # DashboardPage + charts (hourly/daily granularity)
|
|
183
|
+
├── models/ # ModelsPage + forms
|
|
184
|
+
├── providers/ # ProvidersPage + forms
|
|
185
|
+
├── sessions/ # SessionsPage + MemoryPage
|
|
186
|
+
└── settings/ # SettingsPage
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## 💾 Data Source
|
|
190
|
+
|
|
191
|
+
All data is read directly from **`~/.pi/agent/`** on your machine via a Vite middleware API plugin — no mock data, no database, no external service.
|
|
192
|
+
|
|
193
|
+
| File | Purpose |
|
|
194
|
+
|------|---------|
|
|
195
|
+
| `~/.pi/agent/settings.json` | Default provider, model, theme, enabled models, packages |
|
|
196
|
+
| `~/.pi/agent/auth.json` | API keys per provider |
|
|
197
|
+
| `~/.pi/agent/models.json` | Custom provider definitions (baseUrl, API type, models) |
|
|
198
|
+
| `~/.pi/agent/sessions/*.jsonl` | Session history with token usage, model, provider per message |
|
|
199
|
+
| `~/.pi/agent/pi-hermes-memory/*.md` | Hermes memory (MEMORY.md, USER.md, failures.md) |
|
|
200
|
+
|
|
201
|
+
Changes made in the UI are written back to these files in real time — the pi agent picks them up on next reload.
|
|
202
|
+
|
|
203
|
+
### Sessions & Usage
|
|
204
|
+
|
|
205
|
+
- The app parses **106+ JSONL session files** from `sessions/` directory
|
|
206
|
+
- Each assistant message's API usage data (tokens, cost) is extracted and aggregated
|
|
207
|
+
- Dashboard shows real token consumption, costs, and request volumes across all sessions
|
|
208
|
+
- Sessions list groups by project (decoded from directory names) with 24+ project groups
|
|
209
|
+
|
|
210
|
+
## 🧩 API Routes
|
|
211
|
+
|
|
212
|
+
The Vite dev server exposes these endpoints at `/api/pi/*`:
|
|
213
|
+
|
|
214
|
+
| Method | Path | Description |
|
|
215
|
+
|--------|------|-------------|
|
|
216
|
+
| GET | `/api/pi/settings` | Read `settings.json` |
|
|
217
|
+
| POST | `/api/pi/settings` | Write `settings.json` |
|
|
218
|
+
| GET | `/api/pi/auth` | Read `auth.json` |
|
|
219
|
+
| POST | `/api/pi/auth` | Write `auth.json` |
|
|
220
|
+
| GET | `/api/pi/models` | Read `models.json` |
|
|
221
|
+
| POST | `/api/pi/models` | Write `models.json` |
|
|
222
|
+
| GET | `/api/pi/builtin-providers` | List hardcoded built-in providers |
|
|
223
|
+
| GET | `/api/pi/usage` | Aggregated token/cost/request data from sessions |
|
|
224
|
+
| GET | `/api/pi/usage-range` | Date-range filtered usage with hourly/daily breakdown |
|
|
225
|
+
| GET | `/api/pi/sessions` | Session list grouped by project |
|
|
226
|
+
| DELETE | `/api/pi/session?path=` | Delete a session file (path must be under sessions/) |
|
|
227
|
+
| GET | `/api/pi/memory` | Read MEMORY.md, USER.md, failures.md |
|
|
228
|
+
|
|
229
|
+
## 📦 Pi Package
|
|
230
|
+
|
|
231
|
+
pi-web-switch can be installed as a **pi coding agent extension**, allowing you to start/stop the dashboard directly from your pi session.
|
|
232
|
+
|
|
233
|
+
### Install
|
|
234
|
+
|
|
235
|
+
Add `npm:pi-web-switch` to your `~/.pi/agent/settings.json` packages list:
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
{
|
|
239
|
+
"packages": ["npm:pi-web-switch"]
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Or use the Settings page in the dashboard to add it.
|
|
244
|
+
|
|
245
|
+
### Commands
|
|
246
|
+
|
|
247
|
+
Once installed, the following commands are available in your pi session:
|
|
248
|
+
|
|
249
|
+
| Command | Description |
|
|
250
|
+
|---------|-------------|
|
|
251
|
+
| `/pi-web-switch start` | Launch the dashboard at `http://localhost:5173` |
|
|
252
|
+
| `/pi-web-switch stop` | Stop the server |
|
|
253
|
+
| `/pi-web-switch status` | Check if the dashboard is running |
|
|
254
|
+
|
|
255
|
+
### Package Structure
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
pi-web-switch/
|
|
259
|
+
├── package.json # npm package with pi.extensions + pi.skills
|
|
260
|
+
├── pi-package/
|
|
261
|
+
│ ├── index.ts # Extension entry: registers /pi-web-switch command
|
|
262
|
+
│ └── skills/
|
|
263
|
+
│ └── pi-web-switch/
|
|
264
|
+
│ └── SKILL.md # Usage documentation
|
|
265
|
+
├── server/
|
|
266
|
+
│ └── pi-reader.ts # Server-side: reads ~/.pi/agent/ files
|
|
267
|
+
└── src/ # React frontend
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## 🔗 Links
|
|
271
|
+
|
|
272
|
+
- **Homepage:** [raingor.github.io/my-blog](https://raingor.github.io/my-blog/)
|
|
273
|
+
- **GitHub:** [github.com/Raingor](https://github.com/Raingor)
|
|
274
|
+
|
|
275
|
+
## 📄 License
|
|
276
|
+
|
|
277
|
+
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="public/pi.svg" width="80" height="80" alt="pi-switch logo" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">pi-web-switch</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>pi 编码代理的 Web 管理面板 — 实时配置管理、会话浏览与记忆查看</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="README.md">🇬🇧 English</a> ·
|
|
13
|
+
<a href="README.zh-CN.md">🇨🇳 中文</a> ·
|
|
14
|
+
<a href="README.ja.md">🇯🇵 日本語</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src="https://img.shields.io/badge/React-19-61DAFB?logo=react" alt="React 19" />
|
|
19
|
+
<img src="https://img.shields.io/badge/TypeScript-5.8-3178C6?logo=typescript" alt="TypeScript" />
|
|
20
|
+
<img src="https://img.shields.io/badge/Tailwind-4-06B6D4?logo=tailwindcss" alt="Tailwind v4" />
|
|
21
|
+
<img src="https://img.shields.io/badge/Vite-6-646CFF?logo=vite" alt="Vite 6" />
|
|
22
|
+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License" />
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
灵感来源于 <a href="https://github.com/farion1231/cc-switch">cc-switch</a> —— 可视化管理你的 <a href="https://pi.dev">pi 编码代理</a>的提供商、模型、Token 用量、会话和设置。
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<strong>直接从 <code>~/.pi/agent/</code> 读取真实数据</strong> —— 无需模拟数据、无需数据库、无需额外后端。
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ✨ 功能特性
|
|
36
|
+
|
|
37
|
+
### 📊 仪表盘
|
|
38
|
+
- **使用统计** — 当天/7天/30天/自定义日期范围 + 自动刷新(5s/10s/30s/60s)
|
|
39
|
+
- **Token 明细** — 精确值 + 约等于显示(如 `1,631,022 ≈ 163.1万`),含输入/输出/缓存命中/缓存创建占比
|
|
40
|
+
- **成本追踪** — 逐日成本图 + Provider/Model 统计选项卡
|
|
41
|
+
- **缓存命中率** — 直观的进度条展示缓存效率
|
|
42
|
+
- **请求日志** — 详细日志表(时间、供应商、模型、Token、成本)
|
|
43
|
+
- **货币切换** — 美元/人民币实时换算(1 USD = 7.2 CNY)
|
|
44
|
+
- **小时/天粒度** — 当天视图按小时展示;7天/30天按天展示
|
|
45
|
+
|
|
46
|
+
### 📦 模型管理
|
|
47
|
+
- **模型网格** — 按提供商浏览所有模型,支持搜索和筛选
|
|
48
|
+
- **启用/禁用** — 切换模型开关,对应 `enabledModels` 配置
|
|
49
|
+
- **编辑模型** — 更新能力、成本、上下文窗口、最大 Token
|
|
50
|
+
- **添加模型** — 创建新模型,绑定到任意提供商
|
|
51
|
+
- **删除模型** — 移除自定义模型
|
|
52
|
+
|
|
53
|
+
### 🔌 提供商管理
|
|
54
|
+
- **提供商列表** — 可展开卡片展示所有内置和自定义提供商
|
|
55
|
+
- **自定义提供商** — 添加 Ollama、vLLM、LM Studio 或任意 OpenAI 兼容提供商
|
|
56
|
+
- **API Key 管理** — 为每个提供商设置/删除 API Key(保存到 `auth.json`)
|
|
57
|
+
- **提供商配置** — baseUrl、API 类型、自定义请求头、认证方式
|
|
58
|
+
|
|
59
|
+
### 💬 会话浏览
|
|
60
|
+
- **项目分组** — 自动将会话目录名解码为项目路径
|
|
61
|
+
- **会话浏览器** — 查看所有 100+ 个会话
|
|
62
|
+
- **会话详情** — 名称、时间、消息数、持续时间、使用的提供商/模型
|
|
63
|
+
- **搜索筛选** — 按项目名称过滤会话
|
|
64
|
+
- **删除会话** — 删除旧的会话文件(近 3 天有更新的会话受保护)
|
|
65
|
+
|
|
66
|
+
### 🧠 记忆查看 (pi-hermes-memory)
|
|
67
|
+
- **项目记忆** — 查看 `MEMORY.md` 内容,支持 Markdown 渲染
|
|
68
|
+
- **用户画像** — 显示 `USER.md` 偏好和设置
|
|
69
|
+
- **故障记录** — 浏览 `failures.md` 已知问题
|
|
70
|
+
- **实时同步** — 记忆文件在磁盘变更时内容即时更新
|
|
71
|
+
|
|
72
|
+
### 🌐 多语言
|
|
73
|
+
- **English** 🇬🇧 — 英文
|
|
74
|
+
- **简体中文** 🇨🇳 — 中文
|
|
75
|
+
- **繁體中文** 🇭🇰 — 繁体中文
|
|
76
|
+
- **日本語** 🇯🇵 — 日文
|
|
77
|
+
- 侧栏底部语言切换器,选择后跨会话保持
|
|
78
|
+
|
|
79
|
+
### ⚙️ 设置
|
|
80
|
+
- **默认值** — 默认提供商、模型、思考级别、项目信任级别
|
|
81
|
+
- **主题** — 浅色 / 深色 / 跟随系统,即时切换(CSS 变量双主题)
|
|
82
|
+
- **已启用模型** — 查看和管理完整的启用模型列表
|
|
83
|
+
- **扩展与包** — 管理 pi 的 packages 列表
|
|
84
|
+
- **导入/导出** — 下载完整配置为 JSON,从备份恢复
|
|
85
|
+
- **重置** — 恢复空白默认配置
|
|
86
|
+
|
|
87
|
+
## 🌗 主题支持
|
|
88
|
+
|
|
89
|
+
完整的浅色和深色模式,支持跟随系统。主题通过 CSS 自定义属性即时切换——无需刷新页面。所有组件均适配,包括侧栏、弹窗、表单、图表和滚动条。
|
|
90
|
+
|
|
91
|
+
## 🧱 内置提供商
|
|
92
|
+
|
|
93
|
+
应用内置了 **11 个内置提供商** 和 **26 个模型** 的定义(从 pi 的 Rust 源码硬编码):
|
|
94
|
+
|
|
95
|
+
| 提供商 | 模型 |
|
|
96
|
+
|--------|------|
|
|
97
|
+
| Anthropic | Claude Sonnet 4, Sonnet 4.5, Opus 4, Haiku 3.5 |
|
|
98
|
+
| OpenAI | GPT-4o, GPT-4o-mini, GPT-5.1, o3-mini |
|
|
99
|
+
| DeepSeek | DeepSeek V3, DeepSeek R1 |
|
|
100
|
+
| OpenCode | DeepSeek V4 Flash (免费), DeepSeek V4 Flash |
|
|
101
|
+
| OpenCode Go | DeepSeek V4 Flash, V4 Pro, GLM 5.1, Qwen 3.7 Max, MiMo V2.5 |
|
|
102
|
+
| SenseNova | GLM 5.2, DeepSeek V4 Flash |
|
|
103
|
+
| Google Gemini | Gemini 2.5 Flash, Gemini 2.5 Pro |
|
|
104
|
+
| OpenRouter | Claude Sonnet 4, DeepSeek R1 |
|
|
105
|
+
| Mistral | Mistral Large |
|
|
106
|
+
| GitHub Copilot | Copilot GPT-4o |
|
|
107
|
+
| Groq | Llama 3.3 70B |
|
|
108
|
+
|
|
109
|
+
## 🚀 快速开始
|
|
110
|
+
|
|
111
|
+
### 前置要求
|
|
112
|
+
- **pi 编码代理** 已安装并配置(确保 `~/.pi/agent/` 目录存在)
|
|
113
|
+
- Node.js 18+
|
|
114
|
+
|
|
115
|
+
### 安装与运行
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
git clone https://github.com/Raingor/pi-web-switch.git
|
|
119
|
+
cd pi-web-switch
|
|
120
|
+
npm install
|
|
121
|
+
npm run dev # 启动开发服务器(自动读取 ~/.pi/agent/)
|
|
122
|
+
npm run build # 构建生产版本
|
|
123
|
+
npm run preview # 预览生产构建
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 🏗️ 技术栈
|
|
127
|
+
|
|
128
|
+
React 19 + TypeScript 5.8 + Vite 6 + Tailwind CSS v4 + Zustand + Recharts + Lucide React + React Router v7
|
|
129
|
+
|
|
130
|
+
## 📦 Pi 扩展包
|
|
131
|
+
|
|
132
|
+
pi-web-switch 可安装为 **pi 编码代理扩展**,在 pi 会话中直接启动/停止仪表盘。
|
|
133
|
+
|
|
134
|
+
### 安装
|
|
135
|
+
|
|
136
|
+
在 `~/.pi/agent/settings.json` 的 packages 列表中添加 `npm:pi-web-switch`:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"packages": ["npm:pi-web-switch"]
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 命令
|
|
145
|
+
|
|
146
|
+
安装后在 pi 会话中可用以下命令:
|
|
147
|
+
|
|
148
|
+
| 命令 | 说明 |
|
|
149
|
+
|------|------|
|
|
150
|
+
| `/pi-web-switch start` | 启动仪表盘 http://localhost:5173 |
|
|
151
|
+
| `/pi-web-switch stop` | 停止服务器 |
|
|
152
|
+
| `/pi-web-switch status` | 查看运行状态 |
|
|
153
|
+
|
|
154
|
+
### 包结构
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
pi-web-switch/
|
|
158
|
+
├── package.json # npm 包 + pi.extensions + pi.skills
|
|
159
|
+
├── pi-package/
|
|
160
|
+
│ ├── index.ts # 扩展入口:注册 /pi-web-switch 命令
|
|
161
|
+
│ └── skills/
|
|
162
|
+
│ └── pi-web-switch/
|
|
163
|
+
│ └── SKILL.md # 使用文档
|
|
164
|
+
├── server/
|
|
165
|
+
│ └── pi-reader.ts # 服务端:读取 ~/.pi/agent/ 文件
|
|
166
|
+
└── src/ # React 前端
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 🔗 相关链接
|
|
170
|
+
|
|
171
|
+
- **个人主页:** [raingor.github.io/my-blog](https://raingor.github.io/my-blog/)
|
|
172
|
+
- **GitHub:** [github.com/Raingor](https://github.com/Raingor)
|
|
173
|
+
|
|
174
|
+
## 📄 许可证
|
|
175
|
+
|
|
176
|
+
MIT
|
package/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>pi-switch — pi Configuration Manager</title>
|
|
7
|
+
<link rel="icon" type="image/svg+xml" href="/pi.svg" />
|
|
8
|
+
</head>
|
|
9
|
+
<body class="bg-gray-950 text-gray-100 antialiased">
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raingor/pi-web-switch",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Web UI for pi coding agent — live configuration management, session browser, and memory viewer",
|
|
7
|
+
"keywords": ["pi-package", "pi", "pi-coding-agent", "dashboard", "configuration", "web-ui"],
|
|
8
|
+
"author": "Raingor",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Raingor/pi-web-switch.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Raingor/pi-web-switch/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/Raingor/pi-web-switch#readme",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "vite",
|
|
20
|
+
"build": "tsc -b && vite build",
|
|
21
|
+
"preview": "vite preview"
|
|
22
|
+
},
|
|
23
|
+
"pi": {
|
|
24
|
+
"extensions": ["./pi-package/index.ts"],
|
|
25
|
+
"skills": ["./pi-package/skills"]
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"lucide-react": "^0.487.0",
|
|
29
|
+
"react": "^19.1.0",
|
|
30
|
+
"react-dom": "^19.1.0",
|
|
31
|
+
"react-router-dom": "^7.5.0",
|
|
32
|
+
"recharts": "^2.15.3",
|
|
33
|
+
"zustand": "^5.0.4"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@tailwindcss/vite": "^4.1.4",
|
|
37
|
+
"@types/react": "^19.1.2",
|
|
38
|
+
"@types/react-dom": "^19.1.2",
|
|
39
|
+
"@vitejs/plugin-react": "^4.4.1",
|
|
40
|
+
"tailwindcss": "^4.1.4",
|
|
41
|
+
"typescript": "~5.8.3",
|
|
42
|
+
"vite": "^6.3.2"
|
|
43
|
+
}
|
|
44
|
+
}
|