Skip to content

@agentaily/web

主应用 SPA —— 「聊天 × 万物」的产品壳:/ = ChatApp(你跟 Agent 聊 → 它在背后造一个完整【应用】:aml 后端数据模型 + 一组零构建 VFS 前端文件;会话绑定的预览工作台渲染运行的成品,市场作弹窗逛 / 搜 / fork → 发布)。给不懂代码的人用 —— 绝不展示代码 / AML。Vite SPA + Cloudflare Pages Functions(/api/*,落 D1)。已上线 https://agentaily.pages.dev

主应用形态:基于 DS ChatApp 壳重做(取代旧 /build 三栏 AppBuilder + 独立 apps/market)。当前架构收敛真相源见 ../../REFACTOR.md;终态架构 / 契约的整体重写在 M8。

架构

  • 入口:main.tsx —— / 经 page-level AuthGate(/api/auth/me → checking/authed/denied/error)守卫,挂 ChatWorkbench;/signin 独立页(DS SignInPage + Google SSO,也是重置 / 邮箱验证落地)。整树包在 @agentaily/themeThemeProvider + 本地 LocaleProvider(均 cookie 持久化);index.html <head> 内联 themeInitScript() 防 FOUC。会话 / 平台态仍是 Bearer JWT + localStorage,绝不设父域 cookie(REFACTOR §5)。前端 core/{apiClient,auth}
  • ChatWorkbench(ChatWorkbench.tsx):主壳 = DS <ChatApp>(左对话列表 + 中 <ConversationThread> + 右 panel)。聊天造 app 的真实逻辑都在这:agent loop、会话 store / rehydrate / 新建 / 切换、双级模型选择、per-会话草稿、publish。UI 一律消费 @agentaily/design-system
  • 预览工作台(preview/PreviewPanel.tsx + inlinePreview.ts):会话绑定的右 panel,只显示运行的成品、绝不显示代码 / AML。布局用 DS <DocsLayout>(workbench 模式:文件侧栏 + flush 预览,无 TOC);header(ChatApp panelActions)= 文件下拉(选预览哪个文件:index.html 整页 / 某 .js 单跑)+ 侧栏开关。预览经 assembleFilePreview 把整组 VFS 文件拼成 srcdoc,喂给 sandbox="allow-scripts"(无 allow-same-origin)iframe。
  • 市场弹窗(market/*):MarketModal(DS <Dialog size="xl">)内含 MarketList / AppDetail(从已删的 apps/market 搬来、改外链为 app 内回调);读走 marketReadStore(signal-aware),fork 走 core/marketStoreD1AppStore(载入当前对话)。
  • Agent:@agentaily/agent 的 loop + app-builder 工具(appTools / APP_BUILDER_SYSTEM:write_aml/write_file/market_* 等)+ @agentaily/llm(浏览器经 /api/llm/* 边缘代理,平台注入 key)。记忆用 LocalStorageStore;会话经 core/conversationStore(D1-backed)持久化 + rehydrate。
  • 数据 / 后端:Pages Functions 在 functions/** —— /api/auth/*/api/conversations*(会话)、/api/market*(市场,含 [id]/fork)、/api/data/:id/api/forms/:id/submissions/api/llm/[[path]](LLM 代理,边缘注入平台 key)等。新端点契约登记在 ../../SPEC.md §0。D1 = 真相源

跑起来

bash
pnpm --filter @agentaily/web dev           # 主应用 → http://localhost:4173(零构建 VFS,沙箱内联预览,无单独 Studio server)

# 本地连带 Pages Functions + D1(vite dev 不接管 /api/*):
pnpm --filter @agentaily/web build
pnpm --filter @agentaily/web exec wrangler pages dev dist

后端 / D1 / 部署细节见 ../../DEVELOPMENT.md../../OPERATIONS.md。测试:仓库根 pnpm test(vitest,全工作区)。