waypoi 0.7.0-alpha.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.
Files changed (233) hide show
  1. package/.github/agents/waypoint.md +419 -0
  2. package/.github/instructions/ui.instructions.md +42 -0
  3. package/.github/workflows/ci.yml +35 -0
  4. package/.github/workflows/release.yml +77 -0
  5. package/.gitmodules +3 -0
  6. package/.vscode/settings.json +7 -0
  7. package/AGENTS.md +41 -0
  8. package/CHANGELOG.md +113 -0
  9. package/README.md +545 -0
  10. package/assets/agent-mode.png +0 -0
  11. package/assets/categorize.png +0 -0
  12. package/assets/dashboard.png +0 -0
  13. package/assets/endpoint-proxy.png +0 -0
  14. package/assets/icon.png +0 -0
  15. package/assets/mcp-generate-image.png +0 -0
  16. package/assets/mcp-understand-image.png +0 -0
  17. package/assets/peek-token-flow.png +0 -0
  18. package/assets/playground.png +0 -0
  19. package/assets/sankey.png +0 -0
  20. package/cli/index.ts +2772 -0
  21. package/cli/legacyRewrite.ts +108 -0
  22. package/cli/modelRef.ts +24 -0
  23. package/dist/cli/index.js +2503 -0
  24. package/dist/cli/legacyRewrite.js +92 -0
  25. package/dist/cli/modelRef.js +20 -0
  26. package/dist/scripts/seed.js +24 -0
  27. package/dist/src/benchmark/artifacts.js +131 -0
  28. package/dist/src/benchmark/capabilityClassifier.js +81 -0
  29. package/dist/src/benchmark/capabilityStore.js +144 -0
  30. package/dist/src/benchmark/config.js +180 -0
  31. package/dist/src/benchmark/gates.js +118 -0
  32. package/dist/src/benchmark/jobs.js +252 -0
  33. package/dist/src/benchmark/runner.js +1823 -0
  34. package/dist/src/benchmark/schema.js +313 -0
  35. package/dist/src/benchmark/suites.js +390 -0
  36. package/dist/src/benchmark/types.js +25 -0
  37. package/dist/src/index.js +168 -0
  38. package/dist/src/mcp/client.js +215 -0
  39. package/dist/src/mcp/discovery.js +177 -0
  40. package/dist/src/mcp/policy.js +122 -0
  41. package/dist/src/mcp/registry.js +129 -0
  42. package/dist/src/mcp/service.js +410 -0
  43. package/dist/src/middleware/auth.js +179 -0
  44. package/dist/src/middleware/requestCapture.js +192 -0
  45. package/dist/src/middleware/requestStats.js +118 -0
  46. package/dist/src/pools/builder.js +87 -0
  47. package/dist/src/pools/repository.js +69 -0
  48. package/dist/src/pools/scheduler.js +320 -0
  49. package/dist/src/pools/types.js +2 -0
  50. package/dist/src/protocols/adapters/inferenceV2.js +346 -0
  51. package/dist/src/protocols/adapters/openai.js +27 -0
  52. package/dist/src/protocols/registry.js +66 -0
  53. package/dist/src/protocols/types.js +2 -0
  54. package/dist/src/providers/health.js +153 -0
  55. package/dist/src/providers/importer.js +272 -0
  56. package/dist/src/providers/modelRegistry.js +320 -0
  57. package/dist/src/providers/repository.js +361 -0
  58. package/dist/src/providers/types.js +2 -0
  59. package/dist/src/routes/admin.js +404 -0
  60. package/dist/src/routes/audio.js +295 -0
  61. package/dist/src/routes/chat.js +240 -0
  62. package/dist/src/routes/embeddings.js +157 -0
  63. package/dist/src/routes/images.js +288 -0
  64. package/dist/src/routes/mcp.js +220 -0
  65. package/dist/src/routes/mcpService.js +100 -0
  66. package/dist/src/routes/models.js +48 -0
  67. package/dist/src/routes/responses.js +706 -0
  68. package/dist/src/routes/sessions.js +450 -0
  69. package/dist/src/routes/stats.js +263 -0
  70. package/dist/src/routes/ui.js +94 -0
  71. package/dist/src/routing/router.js +338 -0
  72. package/dist/src/services/imageGeneration.js +280 -0
  73. package/dist/src/services/imageUnderstanding.js +352 -0
  74. package/dist/src/storage/captureRepository.js +1350 -0
  75. package/dist/src/storage/files.js +157 -0
  76. package/dist/src/storage/imageCache.js +362 -0
  77. package/dist/src/storage/repositories.js +388 -0
  78. package/dist/src/storage/sessionRepository.js +370 -0
  79. package/dist/src/storage/statsRepository.js +204 -0
  80. package/dist/src/transport/httpClient.js +126 -0
  81. package/dist/src/types.js +2 -0
  82. package/dist/src/utils/messageMedia.js +285 -0
  83. package/dist/src/utils/modelCapabilities.js +97 -0
  84. package/dist/src/utils/modelDiscovery.js +170 -0
  85. package/dist/src/workers/captureRetention.js +16 -0
  86. package/dist/src/workers/configWatcher.js +91 -0
  87. package/dist/src/workers/healthChecker.js +12 -0
  88. package/dist/src/workers/statsRotation.js +41 -0
  89. package/docs/LLM/output_schema.md +312 -0
  90. package/docs/benchmark.md +192 -0
  91. package/docs/mcp-guidelines.md +129 -0
  92. package/docs/mcp-service.md +148 -0
  93. package/docs/opencode.md +86 -0
  94. package/docs/providers.md +79 -0
  95. package/examples/benchmark.config.yaml +26 -0
  96. package/examples/providers/inference-v2-ray.yaml +29 -0
  97. package/examples/scenarios/assets/omni-call-sample.wav +0 -0
  98. package/examples/scenarios/custom.jsonl +5 -0
  99. package/examples/scenarios/custom.yaml +40 -0
  100. package/package.json +59 -0
  101. package/reference/test.py +48 -0
  102. package/scripts/capture-screenshots.js +118 -0
  103. package/scripts/manual-test.sh +11 -0
  104. package/scripts/release/IMPLEMENTATION-SUMMARY.md +135 -0
  105. package/scripts/release/PRE-RELEASE-CHECKLIST.md +126 -0
  106. package/scripts/release/github-release-body-zh.md +65 -0
  107. package/scripts/release/github-release-body.md +65 -0
  108. package/scripts/release/reddit-post.md +45 -0
  109. package/scripts/seed.ts +24 -0
  110. package/src/benchmark/artifacts.ts +149 -0
  111. package/src/benchmark/capabilityClassifier.ts +99 -0
  112. package/src/benchmark/capabilityStore.ts +174 -0
  113. package/src/benchmark/config.ts +242 -0
  114. package/src/benchmark/gates.ts +164 -0
  115. package/src/benchmark/jobs.ts +312 -0
  116. package/src/benchmark/runner.ts +2481 -0
  117. package/src/benchmark/schema.ts +387 -0
  118. package/src/benchmark/suites.ts +395 -0
  119. package/src/benchmark/types.ts +411 -0
  120. package/src/index.ts +182 -0
  121. package/src/mcp/client.ts +305 -0
  122. package/src/mcp/discovery.ts +213 -0
  123. package/src/mcp/policy.ts +202 -0
  124. package/src/mcp/registry.ts +164 -0
  125. package/src/mcp/service.ts +558 -0
  126. package/src/middleware/auth.ts +251 -0
  127. package/src/middleware/requestCapture.ts +245 -0
  128. package/src/middleware/requestStats.ts +163 -0
  129. package/src/pools/builder.ts +107 -0
  130. package/src/pools/repository.ts +71 -0
  131. package/src/pools/scheduler.ts +383 -0
  132. package/src/pools/types.ts +103 -0
  133. package/src/protocols/adapters/inferenceV2.ts +428 -0
  134. package/src/protocols/adapters/openai.ts +32 -0
  135. package/src/protocols/registry.ts +74 -0
  136. package/src/protocols/types.ts +80 -0
  137. package/src/providers/health.ts +207 -0
  138. package/src/providers/importer.ts +385 -0
  139. package/src/providers/modelRegistry.ts +424 -0
  140. package/src/providers/repository.ts +439 -0
  141. package/src/providers/types.ts +109 -0
  142. package/src/routes/admin.ts +527 -0
  143. package/src/routes/audio.ts +372 -0
  144. package/src/routes/chat.ts +301 -0
  145. package/src/routes/embeddings.ts +197 -0
  146. package/src/routes/images.ts +356 -0
  147. package/src/routes/mcp.ts +278 -0
  148. package/src/routes/mcpService.ts +114 -0
  149. package/src/routes/models.ts +50 -0
  150. package/src/routes/responses.ts +867 -0
  151. package/src/routes/sessions.ts +558 -0
  152. package/src/routes/stats.ts +305 -0
  153. package/src/routes/ui.ts +94 -0
  154. package/src/routing/router.ts +501 -0
  155. package/src/services/imageGeneration.ts +396 -0
  156. package/src/services/imageUnderstanding.ts +449 -0
  157. package/src/storage/captureRepository.ts +1583 -0
  158. package/src/storage/files.ts +178 -0
  159. package/src/storage/imageCache.ts +425 -0
  160. package/src/storage/repositories.ts +494 -0
  161. package/src/storage/sessionRepository.ts +419 -0
  162. package/src/storage/statsRepository.ts +238 -0
  163. package/src/transport/httpClient.ts +145 -0
  164. package/src/types.ts +286 -0
  165. package/src/utils/messageMedia.ts +293 -0
  166. package/src/utils/modelCapabilities.ts +146 -0
  167. package/src/utils/modelDiscovery.ts +203 -0
  168. package/src/workers/captureRetention.ts +15 -0
  169. package/src/workers/configWatcher.ts +115 -0
  170. package/src/workers/healthChecker.ts +12 -0
  171. package/src/workers/statsRotation.ts +49 -0
  172. package/test.py +97 -0
  173. package/tests/benchmarkBasics.test.ts +82 -0
  174. package/tests/captureAdminRoutes.test.ts +333 -0
  175. package/tests/captureRepository.test.ts +369 -0
  176. package/tests/cliLegacyRewrite.test.ts +45 -0
  177. package/tests/imageGeneration.service.test.ts +107 -0
  178. package/tests/imageUnderstanding.service.test.ts +123 -0
  179. package/tests/mcpPolicy.test.ts +158 -0
  180. package/tests/mcpService.test.ts +1381 -0
  181. package/tests/modelRef.test.ts +23 -0
  182. package/tests/modelsRoutes.test.ts +154 -0
  183. package/tests/sessionMediaCache.test.ts +167 -0
  184. package/tests/statsRoutes.test.ts +289 -0
  185. package/text +0 -0
  186. package/tsconfig.json +15 -0
  187. package/ui/index.html +16 -0
  188. package/ui/package-lock.json +8405 -0
  189. package/ui/package.json +53 -0
  190. package/ui/postcss.config.js +6 -0
  191. package/ui/public/assets/apple-touch-icon.png +0 -0
  192. package/ui/public/assets/favicon-16.png +0 -0
  193. package/ui/public/assets/favicon-32.png +0 -0
  194. package/ui/public/assets/icon-192.png +0 -0
  195. package/ui/public/assets/icon-512.png +0 -0
  196. package/ui/src/App.tsx +27 -0
  197. package/ui/src/api/client.ts +1377 -0
  198. package/ui/src/components/EndpointUsageGuide.tsx +361 -0
  199. package/ui/src/components/Layout.tsx +124 -0
  200. package/ui/src/components/MessageContent.tsx +336 -0
  201. package/ui/src/components/ToolCallMessage.tsx +179 -0
  202. package/ui/src/components/ToolPicker.tsx +419 -0
  203. package/ui/src/components/messageContentParser.test.ts +41 -0
  204. package/ui/src/components/messageContentParser.ts +73 -0
  205. package/ui/src/components/ui/button.tsx +58 -0
  206. package/ui/src/components/ui/input.tsx +21 -0
  207. package/ui/src/components/ui/textarea.tsx +21 -0
  208. package/ui/src/lib/utils.ts +6 -0
  209. package/ui/src/main.tsx +9 -0
  210. package/ui/src/pages/AgentPlayground.tsx +1785 -0
  211. package/ui/src/pages/Benchmark.tsx +743 -0
  212. package/ui/src/pages/Dashboard.tsx +575 -0
  213. package/ui/src/pages/Peek.tsx +826 -0
  214. package/ui/src/pages/Playground.tsx +1288 -0
  215. package/ui/src/pages/Settings.tsx +1231 -0
  216. package/ui/src/pages/agentPlaygroundPayload.test.ts +109 -0
  217. package/ui/src/pages/agentPlaygroundPayload.ts +97 -0
  218. package/ui/src/pages/agentThinkingContent.test.ts +50 -0
  219. package/ui/src/pages/agentThinkingContent.ts +57 -0
  220. package/ui/src/pages/dashboardTokenUsage.test.ts +66 -0
  221. package/ui/src/pages/dashboardTokenUsage.ts +36 -0
  222. package/ui/src/pages/imageUpload.test.ts +39 -0
  223. package/ui/src/pages/imageUpload.ts +71 -0
  224. package/ui/src/pages/peekMedia.test.ts +58 -0
  225. package/ui/src/pages/peekMedia.ts +148 -0
  226. package/ui/src/pages/sessionAutoTitle.test.ts +128 -0
  227. package/ui/src/pages/sessionAutoTitle.ts +106 -0
  228. package/ui/src/stores/settings.ts +58 -0
  229. package/ui/src/styles/globals.css +223 -0
  230. package/ui/src/vite-env.d.ts +8 -0
  231. package/ui/tailwind.config.js +106 -0
  232. package/ui/tsconfig.json +32 -0
  233. package/ui/vite.config.ts +37 -0
@@ -0,0 +1,419 @@
1
+ # AGENTS.md — Waypoi Phase 2 Contributor Guide (Humans + AI Agents)
2
+
3
+ This file defines how to work in the Waypoi repo safely and consistently. It’s written for both human contributors and AI coding agents.
4
+
5
+ ## Project goal
6
+
7
+ Waypoi is evolving from a CLI-managed reverse proxy into a **local AI gateway** that provides:
8
+
9
+ - OpenAI-compatible proxy routes (LLM + diffusion + audio)
10
+ - A React/shadcn playground UI (served by Fastify)
11
+ - MCP-powered agentic workflows (tool discovery + tool execution)
12
+ - File-based persistence (sessions, stats, images)
13
+ - Real-time statistics dashboard
14
+ - **Backward compatibility** with existing CLI + proxy behavior
15
+
16
+ ---
17
+
18
+ ## Expected repository layout
19
+
20
+ ```
21
+
22
+ waypoi/
23
+ ├── ui/ # NEW: React frontend
24
+ │ ├── src/
25
+ │ │ ├── api/ # API client layer
26
+ │ │ ├── components/ # Reusable UI components
27
+ │ │ ├── pages/ # Playground, Dashboard, Settings
28
+ │ │ ├── hooks/ # Custom React hooks
29
+ │ │ ├── stores/ # State management
30
+ │ │ └── styles/ # Design system, Tailwind config
31
+ │ ├── package.json
32
+ │ └── vite.config.ts
33
+ ├── src/
34
+ │ ├── routes/
35
+ │ │ ├── images.ts # NEW: /v1/images/*
36
+ │ │ ├── audio.ts # NEW: /v1/audio/*
37
+ │ │ ├── responses.ts # NEW: /v1/responses shim
38
+ │ │ ├── sessions.ts # NEW: Playground sessions API
39
+ │ │ ├── mcp.ts # NEW: MCP server management
40
+ │ │ └── stats.ts # ENHANCED: Detailed statistics
41
+ │ ├── middleware/
42
+ │ │ ├── requestStats.ts # NEW: Metrics collection
43
+ │ │ └── auth.ts # NEW: Auth placeholder
44
+ │ ├── mcp/
45
+ │ │ ├── client.ts # NEW: MCP HTTP client
46
+ │ │ ├── registry.ts # NEW: Server registry
47
+ │ │ └── discovery.ts # NEW: Tool discovery
48
+ │ ├── workers/
49
+ │ │ ├── configWatcher.ts # NEW: Hot-reload
50
+ │ │ └── statsRotation.ts # NEW: Log cleanup
51
+ │ └── storage/
52
+ │ ├── statsRepository.ts # NEW: Stats persistence
53
+ │ ├── sessionRepository.ts # NEW: Chat sessions
54
+ │ └── imageCache.ts # NEW: AIGC image LRU cache
55
+ └── cli/
56
+ └── index.ts # ENHANCED: mcp, logs, stats commands
57
+
58
+ ````
59
+
60
+ If the actual structure differs, adapt these guidelines to match the codebase, but keep concepts consistent.
61
+
62
+ ---
63
+
64
+ ## Non-negotiable principles
65
+
66
+ 1. **Backward compatibility first**
67
+ - Existing CLI commands and proxy behavior must continue to work.
68
+ - If behavior must change, gate it behind config flags and keep defaults compatible.
69
+
70
+ 2. **Cross-platform filesystem safety**
71
+ - Use `os.homedir()` + `path.join(...)`.
72
+ - Ensure directories exist before writing.
73
+ - Prefer atomic writes (write temp → rename) for JSON/YAML where practical.
74
+
75
+ 3. **No secrets in logs**
76
+ - Never log API keys, auth headers, full prompts, or user content by default.
77
+ - Debug logging must be opt-in and redact aggressively.
78
+
79
+ 4. **Deterministic, observable behavior**
80
+ - Prefer structured logs and explicit error responses.
81
+ - Be careful with watchers, streaming, and retries (avoid infinite loops).
82
+
83
+ ---
84
+
85
+ ## Development workflow
86
+
87
+ ### Install & run (use the repo’s lockfile)
88
+ Use the package manager indicated by the lockfile:
89
+ - `pnpm-lock.yaml` → `pnpm i`
90
+ - `package-lock.json` → `npm ci`
91
+ - `yarn.lock` → `yarn install --frozen-lockfile`
92
+
93
+ Typical scripts you should prefer (if present):
94
+ - `lint`, `format`, `typecheck`, `test`
95
+ - `dev` / `start` for server
96
+ - `ui:dev` / `ui:build` for UI (or `cd ui && ...`)
97
+
98
+ ### Before you open a PR
99
+ - Run lint + typecheck + tests (or closest equivalents).
100
+ - Validate:
101
+ - proxy routes still work for existing paths
102
+ - CLI commands still function (especially add/edit/rm flow)
103
+ - UI builds and is served at `/ui/*` with SPA fallback
104
+
105
+ ---
106
+
107
+ ## Implementation guidelines by subsystem
108
+
109
+ ## 1) Routes & OpenAI-compat coverage
110
+
111
+ **Pattern:** each route file should mirror `src/routes/chat.ts` style and error conventions.
112
+
113
+ - `src/routes/images.ts`
114
+ - `POST /v1/images/generations` → diffusion endpoints
115
+ - `src/routes/audio.ts`
116
+ - `POST /v1/audio/transcriptions`
117
+ - `POST /v1/audio/speech`
118
+ - `src/routes/responses.ts`
119
+ - Compatibility shim translating “responses” API semantics to chat completions - **SSE Streaming**: When `stream: true`, returns proper Server-Sent Events:
120
+ - `event: response.created` - initial response metadata
121
+ - `event: response.output_item.done` - for each output (messages, tool calls)
122
+ - `event: response.completed` - final response with usage stats
123
+ - **Tool format transformation**: Converts Codex tools to OpenAI function calling format
124
+ - **Content type mapping**: Uses `output_text` (Codex) instead of `text` (OpenAI)- Extend shared types (e.g., `src/types.ts`)
125
+ - `ImageGenerationRequest`
126
+ - `AudioRequest` / transcription + speech request shapes
127
+ - Response types matching OpenAI expectations where possible
128
+ - Update router selection logic (e.g., `src/router.ts`)
129
+ - Add endpoint type filtering: `llm | diffusion | audio`
130
+ - Ensure default behavior remains unchanged unless explicitly configured
131
+
132
+ **Error handling**
133
+ - Preserve OpenAI-like error envelope where possible:
134
+ - consistent `error.message`, `error.type`, `error.code`
135
+ - Avoid leaking upstream/internal URLs in user-facing errors unless debug mode is enabled.
136
+
137
+ ---
138
+
139
+ ## 2) Statistics tracking (7-day window, 30-day rotation)
140
+
141
+ **Middleware**
142
+ - `src/middleware/requestStats.ts`
143
+ - Capture:
144
+ - latency (start/end)
145
+ - request/response byte sizes
146
+ - token usage:
147
+ - prefer `usage` fields when available
148
+ - otherwise estimate from text length (method must be stable + documented)
149
+ - Must not break streaming responses.
150
+
151
+ **Storage**
152
+ - `src/storage/statsRepository.ts`
153
+ - Store JSONL under `~/.cache/waypoi/` with daily rotation (e.g., `stats-YYYY-MM-DD.jsonl`)
154
+ - Writes should be append-only and resilient to partial lines.
155
+
156
+ **API**
157
+ - `src/routes/stats.ts`
158
+ - `GET /admin/stats`
159
+ - Aggregations:
160
+ - p50/p95/p99 latency
161
+ - tokens/hour
162
+ - error rates
163
+ - per-model breakdown
164
+ - Keep it fast: avoid loading 30 days into memory if not needed.
165
+
166
+ **Rotation**
167
+ - `src/workers/statsRotation.ts`
168
+ - Purge files older than 30 days
169
+ - Must tolerate missing dirs/files and continue safely
170
+
171
+ ---
172
+
173
+ ## 3) Config hot-reload
174
+
175
+ - `src/workers/configWatcher.ts`
176
+ - Use `fs.watch()` with debounce (~500ms)
177
+ - Handle “rename” events and editor atomic-save patterns
178
+ - Repositories / config loader should expose `reload()` and emit `config:updated`
179
+ - Router selection logic should subscribe to config updates and refresh endpoint cache
180
+ - CLI changes (`cli/index.ts`)
181
+ - `add/edit/rm` should not prompt for restart when hot-reload is active
182
+
183
+ **Watchers are fragile**
184
+ - Don’t assume one event == one change.
185
+ - Always re-read config on debounce fire, validate, then swap in.
186
+
187
+ ---
188
+
189
+ ## 4) UI package scaffold (Vite + React + shadcn/ui)
190
+
191
+ - UI lives in `ui/`
192
+ - Follow `ui.instructions.md` design direction:
193
+ - bold typography
194
+ - distinctive palette
195
+ - refined animations
196
+ - Fastify serves built assets:
197
+ - `@fastify/static` at `/ui/*`
198
+ - SPA fallback for client routes
199
+
200
+ **API client**
201
+ - `ui/src/api/` should wrap:
202
+ - proxy endpoints (`/v1/...`)
203
+ - admin endpoints (`/admin/...`)
204
+ - Centralize:
205
+ - base URL handling
206
+ - JSON parsing
207
+ - error normalization
208
+ - SSE/stream helpers for chat streaming
209
+
210
+ ---
211
+
212
+ ## 5) Playground (chat + sessions + AIGC)
213
+
214
+ - `ui/src/pages/Playground.tsx`
215
+ - model selector
216
+ - message composer
217
+ - streaming display
218
+ - image input (drag/drop/paste/file → base64 for VL models)
219
+
220
+ **Sessions**
221
+ - Stored under: `~/.cache/waypoi/sessions/{sessionId}.json`
222
+ - Backend CRUD:
223
+ - `src/routes/sessions.ts` + `src/storage/sessionRepository.ts`
224
+
225
+ **AIGC outputs**
226
+ - Detect image responses
227
+ - Save image to `~/.cache/waypoi/images/{hash}.png`
228
+ - Record local path in session
229
+ - Implement LRU eviction:
230
+ - configurable max size (default 1GB)
231
+ - UI warning/alert when eviction occurs
232
+ - Prefer storing metadata (hash, size, createdAt, model) to support dashboard stats later.
233
+
234
+ ---
235
+
236
+ ## 6) Dashboard (real-time stats)
237
+
238
+ - `ui/src/pages/Dashboard.tsx`
239
+ - latency distributions
240
+ - request volume
241
+ - token usage
242
+ - error rates
243
+ - Use Recharts or lightweight SVG charts
244
+ - Auto-refresh:
245
+ - configurable interval (default 30s)
246
+ - Health cards:
247
+ - consume existing `/admin/health`
248
+ - live/degraded/down status
249
+
250
+ ---
251
+
252
+ ## 7) MCP client + registry + discovery
253
+
254
+ - `src/mcp/client.ts`
255
+ - MCP streamable-HTTP client protocol
256
+ - auto-reconnect (bounded backoff)
257
+ - `src/mcp/registry.ts`
258
+ - store server list in `~/.cache/waypoi/mcp-servers.yaml`
259
+ - `src/mcp/discovery.ts`
260
+ - on connect: `tools/list` discovery
261
+ - cache discovered tools with source server metadata
262
+ - `src/routes/mcp.ts`
263
+ - `/admin/mcp/servers` CRUD
264
+ - `/admin/mcp/tools` list discovered tools
265
+
266
+ CLI additions (`cli/index.ts`)
267
+ - `waypoi mcp add <url>`
268
+ - `waypoi mcp list`
269
+ - `waypoi mcp rm <id>`
270
+
271
+ **MCP safety**
272
+ - Validate tool schemas.
273
+ - Bound payload sizes and timeouts.
274
+ - Surface tool execution errors clearly to the user.
275
+
276
+ ---
277
+
278
+ ## 8) Agentic playground mode (UI)
279
+
280
+ - `ui/src/components/AgentMode.tsx`
281
+ - toggle tool usage
282
+ - Tool call rendering:
283
+ - tool name + args
284
+ - streaming execution progress
285
+ - final result block
286
+ - Tool picker sidebar:
287
+ - list tools from `/admin/mcp/tools`
288
+ - Agentic loop:
289
+ - LLM response → tool call → MCP execute → append result → continue
290
+
291
+ **Loop control**
292
+ - Hard cap tool-call iterations per user message.
293
+ - Allow user to cancel.
294
+ - Record tool calls/results in session history.
295
+
296
+ ---
297
+
298
+ ## 9) CLI upgrades
299
+
300
+ - `waypoi logs [-f]` tail `~/.cache/waypoi/waypoi.log`
301
+ - `waypoi stats [--window=7d]` stats summary in terminal
302
+ - Service process:
303
+ - graceful shutdown on SIGTERM
304
+ - Startup banner:
305
+ - listening URL
306
+ - registered endpoints count
307
+
308
+ ---
309
+
310
+ ## 10) Auth-ready architecture (no-op today)
311
+
312
+ - `src/middleware/auth.ts`
313
+ - no-op middleware
314
+ - include `req.user` typing placeholder
315
+ - Config:
316
+ - add `authEnabled: boolean` default `false`
317
+ - Wrap:
318
+ - `/admin/*` and `/ui/*` behind auth check (enforced only when enabled)
319
+ - Document extension points in README
320
+
321
+ ---
322
+
323
+ ## Coding conventions
324
+
325
+ - TypeScript:
326
+ - prefer explicit types at module boundaries (routes, storage, MCP)
327
+ - avoid `any` (use `unknown` + validation)
328
+ - Fastify:
329
+ - routes should be isolated plugins
330
+ - keep handlers thin; move logic to services/repositories
331
+ - Streaming:
332
+ - don’t buffer large responses in memory
333
+ - always handle client disconnects
334
+ - Storage:
335
+ - prefer append-only JSONL for metrics
336
+ - use stable JSON shapes for sessions
337
+
338
+ ---
339
+
340
+ ## Definition of Done (per change)
341
+
342
+ A change is “done” when:
343
+ - Typecheck passes
344
+ - Lint passes (if configured)
345
+ - Basic runtime sanity check succeeds:
346
+ - server boots
347
+ - at least one proxy request works
348
+ - UI builds (if UI touched)
349
+ - Backward compatibility preserved or guarded by config flag
350
+ - New endpoints documented (README or route docs as appropriate)
351
+
352
+ ---
353
+
354
+ ## AI agent capability: frontend-design
355
+
356
+ Use this capability when building **web components, pages, or applications** under `ui/` (or when adjusting UI aesthetics). The goal is to produce **distinctive, production-grade** interfaces that avoid generic “AI slop” aesthetics.
357
+
358
+ ```markdown
359
+ ---
360
+ name: frontend-design
361
+ description: Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
362
+ license: Complete terms in LICENSE.txt
363
+ ---
364
+
365
+ This skill guides creation of distinctive, production-grade frontend interfaces that avoid generic "AI slop" aesthetics. Implement real working code with exceptional attention to aesthetic details and creative choices.
366
+
367
+ The user provides frontend requirements: a component, page, application, or interface to build. They may include context about the purpose, audience, or technical constraints.
368
+
369
+ ## Design Thinking
370
+
371
+ Before coding, understand the context and commit to a BOLD aesthetic direction:
372
+ - **Purpose**: What problem does this interface solve? Who uses it?
373
+ - **Tone**: Pick an extreme: brutally minimal, maximalist chaos, retro-futuristic, organic/natural, luxury/refined, playful/toy-like, editorial/magazine, brutalist/raw, art deco/geometric, soft/pastel, industrial/utilitarian, etc. There are so many flavors to choose from. Use these for inspiration but design one that is true to the aesthetic direction.
374
+ - **Constraints**: Technical requirements (framework, performance, accessibility).
375
+ - **Differentiation**: What makes this UNFORGETTABLE? What's the one thing someone will remember?
376
+
377
+ **CRITICAL**: Choose a clear conceptual direction and execute it with precision. Bold maximalism and refined minimalism both work - the key is intentionality, not intensity.
378
+
379
+ Then implement working code (HTML/CSS/JS, React, Vue, etc.) that is:
380
+ - Production-grade and functional
381
+ - Visually striking and memorable
382
+ - Cohesive with a clear aesthetic point-of-view
383
+ - Meticulously refined in every detail
384
+
385
+ ## Frontend Aesthetics Guidelines
386
+
387
+ Focus on:
388
+ - **Typography**: Choose fonts that are beautiful, unique, and interesting. Avoid generic fonts like Arial and Inter; opt instead for distinctive choices that elevate the frontend's aesthetics; unexpected, characterful font choices. Pair a distinctive display font with a refined body font.
389
+ - **Color & Theme**: Commit to a cohesive aesthetic. Use CSS variables for consistency. Dominant colors with sharp accents outperform timid, evenly-distributed palettes.
390
+ - **Motion**: Use animations for effects and micro-interactions. Prioritize CSS-only solutions for HTML. Use Motion library for React when available. Focus on high-impact moments: one well-orchestrated page load with staggered reveals (animation-delay) creates more delight than scattered micro-interactions. Use scroll-triggering and hover states that surprise.
391
+ - **Spatial Composition**: Unexpected layouts. Asymmetry. Overlap. Diagonal flow. Grid-breaking elements. Generous negative space OR controlled density.
392
+ - **Backgrounds & Visual Details**: Create atmosphere and depth rather than defaulting to solid colors. Add contextual effects and textures that match the overall aesthetic. Apply creative forms like gradient meshes, noise textures, geometric patterns, layered transparencies, dramatic shadows, decorative borders, custom cursors, and grain overlays.
393
+
394
+ NEVER use generic AI-generated aesthetics like overused font families (Inter, Roboto, Arial, system fonts), cliched color schemes (particularly purple gradients on white backgrounds), predictable layouts and component patterns, and cookie-cutter design that lacks context-specific character.
395
+
396
+ Interpret creatively and make unexpected choices that feel genuinely designed for the context. No design should be the same. Vary between light and dark themes, different fonts, different aesthetics. NEVER converge on common choices (Space Grotesk, for example) across generations.
397
+
398
+ **IMPORTANT**: Match implementation complexity to the aesthetic vision. Maximalist designs need elaborate code with extensive animations and effects. Minimalist or refined designs need restraint, precision, and careful attention to spacing, typography, and subtle details. Elegance comes from executing the vision well.
399
+
400
+ Remember: AI agents are capable of extraordinary creative work. Don't hold back—commit fully to a distinctive vision.
401
+ ````
402
+
403
+ ---
404
+
405
+ ## Notes for AI agents
406
+
407
+ * Prefer small, reviewable commits.
408
+ * Don’t refactor unrelated code “for cleanliness” unless it removes real duplication blocking the plan.
409
+ * When extending OpenAI compatibility:
410
+
411
+ * mirror request/response shapes
412
+ * document intentional deviations
413
+ * If uncertain about existing patterns, inspect:
414
+
415
+ * `src/routes/chat.ts`
416
+ * router selection logic
417
+ * existing storage helpers in `src/storage/*`
418
+
419
+ ```
@@ -0,0 +1,42 @@
1
+ ---
2
+ name: frontend-design
3
+ description: Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
4
+ license: Complete terms in LICENSE.txt
5
+ ---
6
+
7
+ This skill guides creation of distinctive, production-grade frontend interfaces that avoid generic "AI slop" aesthetics. Implement real working code with exceptional attention to aesthetic details and creative choices.
8
+
9
+ The user provides frontend requirements: a component, page, application, or interface to build. They may include context about the purpose, audience, or technical constraints.
10
+
11
+ ## Design Thinking
12
+
13
+ Before coding, understand the context and commit to a BOLD aesthetic direction:
14
+ - **Purpose**: What problem does this interface solve? Who uses it?
15
+ - **Tone**: Pick an extreme: brutally minimal, maximalist chaos, retro-futuristic, organic/natural, luxury/refined, playful/toy-like, editorial/magazine, brutalist/raw, art deco/geometric, soft/pastel, industrial/utilitarian, etc. There are so many flavors to choose from. Use these for inspiration but design one that is true to the aesthetic direction.
16
+ - **Constraints**: Technical requirements (framework, performance, accessibility).
17
+ - **Differentiation**: What makes this UNFORGETTABLE? What's the one thing someone will remember?
18
+
19
+ **CRITICAL**: Choose a clear conceptual direction and execute it with precision. Bold maximalism and refined minimalism both work - the key is intentionality, not intensity.
20
+
21
+ Then implement working code (HTML/CSS/JS, React, Vue, etc.) that is:
22
+ - Production-grade and functional
23
+ - Visually striking and memorable
24
+ - Cohesive with a clear aesthetic point-of-view
25
+ - Meticulously refined in every detail
26
+
27
+ ## Frontend Aesthetics Guidelines
28
+
29
+ Focus on:
30
+ - **Typography**: Choose fonts that are beautiful, unique, and interesting. Avoid generic fonts like Arial and Inter; opt instead for distinctive choices that elevate the frontend's aesthetics; unexpected, characterful font choices. Pair a distinctive display font with a refined body font.
31
+ - **Color & Theme**: Commit to a cohesive aesthetic. Use CSS variables for consistency. Dominant colors with sharp accents outperform timid, evenly-distributed palettes.
32
+ - **Motion**: Use animations for effects and micro-interactions. Prioritize CSS-only solutions for HTML. Use Motion library for React when available. Focus on high-impact moments: one well-orchestrated page load with staggered reveals (animation-delay) creates more delight than scattered micro-interactions. Use scroll-triggering and hover states that surprise.
33
+ - **Spatial Composition**: Unexpected layouts. Asymmetry. Overlap. Diagonal flow. Grid-breaking elements. Generous negative space OR controlled density.
34
+ - **Backgrounds & Visual Details**: Create atmosphere and depth rather than defaulting to solid colors. Add contextual effects and textures that match the overall aesthetic. Apply creative forms like gradient meshes, noise textures, geometric patterns, layered transparencies, dramatic shadows, decorative borders, custom cursors, and grain overlays.
35
+
36
+ NEVER use generic AI-generated aesthetics like overused font families (Inter, Roboto, Arial, system fonts), cliched color schemes (particularly purple gradients on white backgrounds), predictable layouts and component patterns, and cookie-cutter design that lacks context-specific character.
37
+
38
+ Interpret creatively and make unexpected choices that feel genuinely designed for the context. No design should be the same. Vary between light and dark themes, different fonts, different aesthetics. NEVER converge on common choices (Space Grotesk, for example) across generations.
39
+
40
+ **IMPORTANT**: Match implementation complexity to the aesthetic vision. Maximalist designs need elaborate code with extensive animations and effects. Minimalist or refined designs need restraint, precision, and careful attention to spacing, typography, and subtle details. Elegance comes from executing the vision well.
41
+
42
+ Remember: You are capable of extraordinary creative work. Don't hold back, show what can truly be created when thinking outside the box and committing fully to a distinctive vision.
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ check:
11
+ name: Type-check & Test
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Setup Node.js
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: '20'
20
+ cache: 'npm'
21
+
22
+ - name: Install root dependencies
23
+ run: npm ci
24
+
25
+ - name: Install UI dependencies
26
+ run: cd ui && npm ci && cd ..
27
+
28
+ - name: Type-check (backend)
29
+ run: npm run typecheck
30
+
31
+ - name: Type-check (UI)
32
+ run: cd ui && npx tsc --noEmit && cd ..
33
+
34
+ - name: Run tests
35
+ run: npm test
@@ -0,0 +1,77 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*.*.*'
7
+ - 'v*.*.*-alpha.*'
8
+ - 'v*.*.*-beta.*'
9
+ - 'v*.*.*-rc.*'
10
+
11
+ permissions:
12
+ contents: write
13
+ id-token: write
14
+
15
+ jobs:
16
+ release:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0
22
+
23
+ - name: Setup Node.js
24
+ uses: actions/setup-node@v4
25
+ with:
26
+ node-version: '20'
27
+ cache: 'npm'
28
+ registry-url: 'https://registry.npmjs.org'
29
+
30
+ - name: Install dependencies
31
+ run: |
32
+ npm ci
33
+ cd ui && npm ci && cd ..
34
+
35
+ - name: Type-check
36
+ run: npm run typecheck
37
+
38
+ - name: Build
39
+ run: npm run build:all
40
+
41
+ - name: Determine npm tag
42
+ id: npm_tag
43
+ run: |
44
+ TAG="${GITHUB_REF#refs/tags/v}"
45
+ if echo "$TAG" | grep -qE '-(alpha|beta|rc)\.'; then
46
+ echo "tag=alpha" >> $GITHUB_OUTPUT
47
+ echo "prerelease=true" >> $GITHUB_OUTPUT
48
+ else
49
+ echo "tag=latest" >> $GITHUB_OUTPUT
50
+ echo "prerelease=false" >> $GITHUB_OUTPUT
51
+ fi
52
+
53
+ - name: Publish to npm
54
+ run: npm publish --tag ${{ steps.npm_tag.outputs.tag }} --provenance --access public
55
+ env:
56
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
57
+
58
+ - name: Extract changelog section
59
+ id: changelog
60
+ run: |
61
+ VERSION="${GITHUB_REF#refs/tags/v}"
62
+ # Extract section between ## [VERSION] and next ## heading
63
+ BODY=$(awk "/^## \[${VERSION}\]/{found=1; next} found && /^## /{exit} found{print}" CHANGELOG.md)
64
+ if [ -z "$BODY" ]; then
65
+ BODY="See [CHANGELOG.md](https://github.com/zziang/waypoi/blob/main/CHANGELOG.md) for details."
66
+ fi
67
+ # Write to a temp file to avoid quoting issues
68
+ echo "$BODY" > /tmp/release_body.md
69
+
70
+ - name: Create GitHub Release
71
+ uses: softprops/action-gh-release@v2
72
+ with:
73
+ prerelease: ${{ steps.npm_tag.outputs.prerelease }}
74
+ generate_release_notes: false
75
+ body_path: /tmp/release_body.md
76
+ env:
77
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "archive/codex"]
2
+ path = archive/codex
3
+ url = https://github.com/openai/codex.git
@@ -0,0 +1,7 @@
1
+ {
2
+ "chat.tools.terminal.autoApprove": {
3
+ "mkdir": true,
4
+ "npm install": true,
5
+ "git add": true
6
+ }
7
+ }
package/AGENTS.md ADDED
@@ -0,0 +1,41 @@
1
+ # Waypoi Contributor Guardrails
2
+
3
+ Purpose and scope:
4
+ - Applies to the entire repo.
5
+ - Preserve core functionality while evolving features.
6
+
7
+ Core invariants (must not break):
8
+ - MCP:
9
+ - `/mcp` endpoint exists and is localhost-only.
10
+ - File-first policy remains default for binary tools.
11
+ - Tool outputs remain structured as `{ ok: true|false, ... }`.
12
+ - File outputs must be workspace-relative (no `/tmp` by default).
13
+ - Playground UI:
14
+ - Image/chat upload flows remain functional.
15
+ - Thinking/streaming behaviors are preserved.
16
+ - No regressions to basic chat/call flows.
17
+ - Reverse proxy:
18
+ - `/v1/*` stays OpenAI-compatible.
19
+ - No breaking request/response changes without migration notes.
20
+ - Providers/pools:
21
+ - Capability routing remains consistent (input/output requirements).
22
+ - Model selection logic unchanged unless updated with tests.
23
+
24
+ Change discipline:
25
+ - MCP tool contract changes must update:
26
+ - `docs/mcp-service.md`
27
+ - `docs/mcp-guidelines.md`
28
+ - relevant tests in `tests/mcp*.test.ts`
29
+ - OpenAI route changes must update relevant docs and regression tests.
30
+ - UI changes affecting chat/call/image flows must add a targeted test or a manual verification checklist in PR notes.
31
+
32
+ Default output path rule:
33
+ - Tool outputs must write under the workspace (default `./.waypoi/generated-images`).
34
+ - Reject `output_path`/`output_dir` outside the workspace.
35
+
36
+ Quick pointers (where to look first):
37
+ - MCP service: `src/mcp/service.ts`
38
+ - MCP policy: `src/mcp/policy.ts`
39
+ - Playground: `ui/src/pages/AgentPlayground.tsx`
40
+ - Reverse proxy: `src/routing/router.ts` and `src/routes/*`
41
+ - Providers/pools: `src/providers/*`, `src/pools/*`