fixture.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. import { NativeSideNoteFixture } from "./sidenote-native-fixture"
  2. import { createStore } from "solid-js/store"
  3. import { Show } from "solid-js"
  4. import { render } from "solid-js/web"
  5. import { AppBaseProviders } from "../../src/app"
  6. import { PlatformProvider, type Platform } from "../../src/context/platform"
  7. import PaasWorkspace from "../../src/pages/paas"
  8. import type { PaasProjectBackup, PaasPlatform, PaasRequest, PaasProgress, PaasUploadProgress } from "../../src/paas"
  9. import { PanelFixture } from "./panel-fixture"
  10. import "../../src/index.css"
  11. // Synthetic transport, real workbench. No model or developer service is started.
  12. document.body.setAttribute("data-lambda-workbench", "")
  13. const calls: PaasRequest[] = []
  14. const query = new URLSearchParams(location.search)
  15. const filesMode = query.has("files")
  16. const completedMode = query.has("completed")
  17. const agent = { id: "research", name: "科研助手", description: "研究规划与验证", current_version: 1 }
  18. const unusedAgent = { id: "unused", name: "未使用智能体", description: "从未开始过会话", current_version: 1 }
  19. const workspaceAgent = { id: "workspace", name: "工作区助手", description: "文件与命令", current_version: 1 }
  20. const groupedAgents = [
  21. agent,
  22. { id: "data67", name: "data67", description: "数据分析", current_version: 1 },
  23. workspaceAgent,
  24. { id: "reviewer", name: "顶刊审稿助手", description: "论文评审", current_version: 1 },
  25. { id: "pipeline", name: "Research67 三阶段研究草稿流水线", description: "完整研究流程", current_version: 1 },
  26. { id: "internal-evidence", name: "本体证据补全员", description: "补充证据", current_version: 1 },
  27. ]
  28. const agents = query.has("groups")
  29. ? [agent, unusedAgent]
  30. : query.has("agent-groups")
  31. ? groupedAgents
  32. : query.has("workspace")
  33. ? [agent, workspaceAgent]
  34. : [agent]
  35. const run: Record<string, unknown> = {
  36. run_id: "run_1",
  37. agent_id: agent.id,
  38. thread_id: "thread_1",
  39. created_at: "2026-11-29T09:00:00Z",
  40. status: completedMode ? "completed" : "waiting_human",
  41. ...(completedMode ? { completed_at: "2026-11-29T09:00:30Z" } : {}),
  42. output: [
  43. "## 研究计划",
  44. "已整理材料并生成以下步骤:",
  45. "",
  46. "1. 明确验证假设与指标",
  47. "2. 复核数据来源与样本量",
  48. "",
  49. "> 执行完成不代表科研结论已验证。",
  50. "",
  51. "| 阶段 | 产出 |",
  52. "| --- | --- |",
  53. "| 探索 | 证据清单 |",
  54. "| 验证 | 对照实验 |",
  55. "",
  56. "```python",
  57. 'print("研究计划")',
  58. "```",
  59. "",
  60. "[查看平台任务](https://research.example/tasks/run_1)",
  61. ].join("\n"),
  62. pending_approval: { approval_id: "approval_1", prompt: "是否执行验证?" },
  63. artifacts: filesMode
  64. ? [
  65. { artifact_id: "artifact_1", name: "研究计划成果.pdf" },
  66. { artifact_id: "artifact_2", name: "manifest.json" },
  67. { artifact_id: "artifact_3", name: "manifest.json" },
  68. ]
  69. : [{ artifact_id: "artifact_1", name: "研究计划成果.pdf" }],
  70. events: [
  71. { type: "tool_call", tool: "file_search", content: "查找材料目录" },
  72. { type: "tool_result", tool: "file_search", content: "找到 2 份材料" },
  73. ],
  74. }
  75. if (query.has("sidenotes")) {
  76. run.output = [
  77. "## 搜索更新", "", "已将 `search.ts` 改为子序列匹配,并加入快捷键。", "",
  78. "无需迁移数据。仅完成单元测试,界面交互尚未验证。", "", "```sidenotes",
  79. "- 做法 | search.ts | 使用子序列匹配处理非连续字符。",
  80. "- 假设 | 快捷键 | 默认使用系统常见的组合键。",
  81. "- 依据 | 无需迁移数据 | 只改动匹配函数,未修改存储结构。",
  82. "- 存疑 | 界面交互尚未验证 | 尚未运行浏览器端到端测试。",
  83. "- 取舍 | 子序列匹配 | 优先选择易维护的实现,未引入编辑距离。",
  84. ...(query.has("malformed-notes") ? ["unknown | 正文 | 保留这段未知格式"] : []),
  85. "```",
  86. ].join("\n")
  87. }
  88. if (query.has("recovery")) {
  89. run.status = "failed"
  90. run.error = { code: "SERVICE_RESTARTED", message: "服务中断" }
  91. run.recovery_available = true
  92. run.pending_approval = null
  93. }
  94. const progress = new Set<(event: PaasProgress) => void>()
  95. const uploads = new Set<(event: PaasUploadProgress) => void>()
  96. const uxRuns = new Map<string, Record<string, unknown>>()
  97. const ux = {
  98. enabled: new URLSearchParams(location.search).has("ux"),
  99. uploads: 0,
  100. holdRun: "",
  101. holdThread: "",
  102. threadError: "",
  103. held: false,
  104. connectError: "",
  105. catalogError: "",
  106. emptyCatalog: false,
  107. configVersion: "version-1",
  108. configError: false,
  109. draftError: false,
  110. permissions: undefined as string[] | undefined,
  111. verifyError: "",
  112. receiptError: "",
  113. previewError: "",
  114. previewText: "",
  115. filesError: "",
  116. previewName: "",
  117. directoryError: "",
  118. directories: [] as string[],
  119. scopeError: false,
  120. holdDirectory: false,
  121. releaseDirectory: () => {},
  122. checks: [{ kind: "model", name: "test-model", required: true, status: "not_checked" }] as Record<string, unknown>[],
  123. external: [] as string[],
  124. release: () => {},
  125. add: (value: Record<string, unknown>) => uxRuns.set(String(value.run_id), value),
  126. update: (id: string, value: Record<string, unknown>) => Object.assign(uxRuns.get(id) || {}, value),
  127. progress: (event: PaasProgress) => progress.forEach((listener) => listener(event)),
  128. run: (id: string) => uxRuns.get(id),
  129. }
  130. Object.assign(window, { paasUX: ux })
  131. let researchConfig = {
  132. researchWorkflow: "research67-scientific-v1",
  133. model: { provider: "deepseek", name: "deepseek-chat" },
  134. scientific: { token_budget: 500000, max_actual_tokens: 1000000, max_rounds: 4, max_wall_seconds: 3600 },
  135. }
  136. const plugin = {
  137. managerProjects: {} as Record<string, unknown>,
  138. localTools: [] as Record<string, unknown>[],
  139. packageVersion: "1.0.0",
  140. blocked: false,
  141. inspectError: false,
  142. failRefreshAfterSave: false,
  143. failPackRefresh: false,
  144. failManagerRefresh: false,
  145. failAfterLocalSave: false,
  146. inspectTools: [{name:"echo",description:"本地回显"}] as Record<string,unknown>[],
  147. packsError: false,
  148. version: 1,
  149. config: {
  150. type: "react",
  151. mcp: { localTools: ["read_file"], onlineTool: { original: ["existing"] } },
  152. app: { mcp: { custom: { nodes: { original: { url: "https://original.example/mcp" } } } } },
  153. } as Record<string, unknown>,
  154. added: [] as Record<string, unknown>[],
  155. packs: [
  156. {
  157. id: "literature",
  158. version: "1.0.0",
  159. name: "文献助手",
  160. description: "检索材料,整理有出处的阅读报告。",
  161. permission_summary: "读取选定材料、检索文献",
  162. dependencies: [{ kind:"mcp",name: "模型连接", required: true }],
  163. },
  164. ],
  165. }
  166. Object.assign(window, { paasPlugins: plugin })
  167. const artifactUX = { failFiles: false, holdFiles: false, held: false, release: () => {} }
  168. Object.assign(window, { artifactUX })
  169. const setupUX = { started: false, fail: "", saved: false }
  170. const transferUX = { backup: undefined as PaasProjectBackup | undefined, runs: [] as { agentID: string; runID: string }[] }
  171. Object.assign(window, { transferUX })
  172. const api: PaasPlatform = {
  173. ...(query.has("transfer") ? {
  174. backupProject: async (data: PaasProjectBackup, runs: { agentID: string; runID: string }[]) => { transferUX.backup = data; transferUX.runs = runs; return { path: "/backup/project.zip", missing: [] } },
  175. restoreProject: async () => ({ data: transferUX.backup || { format: "lambda-agent-project" as const, version: 1 as const, name: "备份项目", chats: [{ title: "历史研究", agentID: "research", name: "科研助手", draft: "下一步", messages: [{ role: "assistant" as const, text: "备份中的成果" }] }] }, path: "/backup/restored", missing: [] }),
  176. } : {}),
  177. ...(query.has("setup")
  178. ? {
  179. localRuntime: {
  180. status: async () => ({
  181. phase: setupUX.started ? ("ready" as const) : ("idle" as const),
  182. available: true,
  183. message: setupUX.started ? "本机服务已就绪。" : "尚未启动本机服务。",
  184. }),
  185. start: async () => {
  186. setupUX.started = true
  187. },
  188. choose: async () => true,
  189. },
  190. }
  191. : {}),
  192. readDraft: async (kind, id, scope) => {
  193. if (ux.draftError) throw new Error("草稿暂不可读")
  194. return JSON.parse(localStorage.getItem(`test-draft:${scope}:${kind}:${id}`) || "null")
  195. },
  196. writeDraft: async (kind, id, value, scope) => {
  197. const key = `test-draft:${scope}:${kind}:${id}`
  198. if (value == null) localStorage.removeItem(key)
  199. else localStorage.setItem(key, JSON.stringify(value))
  200. },
  201. connect: async (input) => {
  202. if (!input && setupUX.started) input = { url: "http://127.0.0.1:8400", apiKey: "setup" }
  203. if (!input) throw new Error("未找到本机 AgentPaaS 凭证,请手动连接。")
  204. if (ux.connectError) throw new Error(ux.connectError)
  205. return { url: input.url, remembered: true, scope: `test-${input.apiKey}`, permissions: ux.permissions }
  206. },
  207. disconnect: async () => {},
  208. onProgress: (listener) => {
  209. progress.add(listener)
  210. return () => progress.delete(listener)
  211. },
  212. onUploadProgress: (listener) => {
  213. uploads.add(listener)
  214. return () => uploads.delete(listener)
  215. },
  216. ...(ux.enabled
  217. ? {
  218. selectFiles: async () => [
  219. { selectionID: "one", name: "成功.txt", size: 10 },
  220. { selectionID: "two", name: "重试.txt", size: 10 },
  221. ],
  222. }
  223. : {}),
  224. chooseFiles: async () => [{ file_id: "file_1", name: "材料.pdf" }],
  225. request: async (request) => {
  226. calls.push(request)
  227. if (request.action === "delete-agent") return {ok:true}
  228. if (request.action === "attach-artifact") return { file_id: "continued-file", name: request.name }
  229. if (request.action === "recover") {
  230. if (!request.retryInterrupted) throw new Error("PIPELINE_RETRY_REQUIRES_ACK:请核对中断步骤")
  231. run.status = "running"
  232. run.recovery_available = false
  233. run.pending_approval = null
  234. return { ...run }
  235. }
  236. if (request.action === "desktop-self-check") return { checked_at: "2026-12-02T08:00:00Z", sha256: "fixture-digest", checks: [{ name: "执行服务认证", status: "passed" }, { name: "独立目录写入、列举与读取", status: "passed" }, { name: "真实模型与科研质量", status: "not_checked" }] }
  237. if (request.action === "desktop-setup")
  238. return {
  239. version: 1,
  240. executor_linked: true,
  241. providers: [
  242. ...(query.has("fresh-models") ? [
  243. {id: "anthropic", name: "Anthropic", models: [], base_url: "https://api.anthropic.com", configured: false, credential_source: "none"},
  244. {id: "ollama", name: "Ollama", models: [], base_url: "http://127.0.0.1:11434", configured: false, no_key_required: true},
  245. ] : []),
  246. {
  247. id: "deepseek",
  248. name: "DeepSeek",
  249. models: ["deepseek-chat"],
  250. base_url: "https://api.deepseek.com/v1",
  251. configured: setupUX.saved,
  252. },
  253. ],
  254. }
  255. if (request.action === "save-provider") {
  256. setupUX.saved = true
  257. return { ok: true }
  258. }
  259. if (request.action === "apply-model") {
  260. if (request.agentID === "unused") throw new Error("配置版本已变更,请重试")
  261. return { ok: true }
  262. }
  263. if (request.action === "save-tool-credential") return { name: "DESKTOP_TOOL_" + "A".repeat(64) }
  264. if (request.action === "download-batch")
  265. return { saved: request.files.length, results: request.files.map((file) => ({ name: file.name, saved: true })) }
  266. if (request.action === "run-files") {
  267. if (artifactUX.failFiles) throw new Error("测试:文件列表暂不可用")
  268. if (artifactUX.holdFiles) {
  269. artifactUX.held = true
  270. await new Promise<void>((resolve) => {
  271. artifactUX.release = () => {
  272. artifactUX.held = false
  273. resolve()
  274. }
  275. })
  276. }
  277. }
  278. if (request.action === "verify") {
  279. if (ux.verifyError) throw new Error(ux.verifyError)
  280. return { checks: ux.checks }
  281. }
  282. if (request.action === "agents" && ux.catalogError) throw new Error(ux.catalogError)
  283. if (request.action === "agents" && ux.emptyCatalog) return { agents: [] }
  284. if (query.has("plugins")) {
  285. if(request.action === "plugin-resources") return {knowledge:[{id:"kb-demo",name:"演示知识库"}],skill:[],mcp:[{id:"original",name:"已有连接"}]}
  286. if(request.action === "plugin-detail" && plugin.failManagerRefresh) throw new Error("详情暂不可用")
  287. if(request.action === "plugin-detail") return {agent_id:request.agentID,updated_at:String(plugin.version),pack:{id:"literature",version:plugin.packageVersion},latest_version:"2.0.0",installed_versions:[{version:"1.0.0"},{version:"2.0.0"}],versions:[{version:plugin.version,is_current:true,changelog:"当前配置"},{version:0,is_current:false,changelog:"初始配置"}],projects:plugin.managerProjects,connections:["original","literature"],local_tools:plugin.localTools,resources:[{kind:"知识库",name:"演示知识库"}],desktop_ui:{panels:[{id:"help",title:"使用说明",text:"所有结果在当前工作台交付。"}],commands:[{id:"review",title:"审阅材料",prompt:"请审阅 {{topic}}",fields:[{id:"topic",label:"研究主题",required:true}]}]}}
  288. if(request.action === "plugin-project") {if(request.expectedUpdatedAt!==String(plugin.version))throw new Error("版本已变化,请刷新。"); if(request.inherit)delete plugin.managerProjects[request.projectID];else plugin.managerProjects[request.projectID]={enabled:request.enabled,connections:request.connections};plugin.version++;return {ok:true}}
  289. if(request.action === "plugin-version") {plugin.packageVersion=request.version || "1.0.0";plugin.version++;return {ok:true}}
  290. if(request.action === "plugin-export") return request.preview === false ? {saved:true,name:"demo.zip"} : {files:[{name:"manifest.yml",size:300},{name:"agent.yml",size:500}],removed:["model.apiKey"]}
  291. if(request.action === "local-tool") {
  292. if(plugin.inspectError)throw new Error("本地工具未正常响应")
  293. if(request.save){
  294. const id=request.connectionID || `desktop_local${plugin.localTools.length}`
  295. plugin.localTools=[...plugin.localTools.filter((t)=>t.id!==id),{id,name:request.name,command_argv:request.commandArgv,enabled:request.enabled,tools:request.tools}]
  296. plugin.version++
  297. if(plugin.failAfterLocalSave)plugin.failManagerRefresh=true
  298. }
  299. return {tools:plugin.inspectTools,message:"启动检测通过,检测进程已关闭。"}
  300. }
  301. if(request.action === "plugin-local-state") {plugin.localTools=request.remove?[]:plugin.localTools.map((t)=>({...t,enabled:request.enabled}));plugin.version++;return {ok:true}}
  302. if (request.action === "agents") return { agents: [...agents, ...plugin.added] }
  303. if (request.action === "packs") {
  304. if (plugin.packsError) throw new Error("目录暂不可用")
  305. return { agentpacks: plugin.packs }
  306. }
  307. if (request.action === "preflight-pack")
  308. return { ready: !plugin.blocked, missing: plugin.blocked ? [{ name: "模型连接", reason: "尚未配置" }] : [] }
  309. if (request.action === "create-agent") {
  310. const id = `added_${plugin.added.length + 1}`
  311. plugin.added.push({
  312. id,
  313. name: request.name,
  314. description: "文献阅读与报告",
  315. agent_template: request.packID,
  316. current_version: 1,
  317. })
  318. return { agent_id: id }
  319. }
  320. if (request.action === "install-pack") {
  321. if (plugin.failPackRefresh) plugin.packsError = true
  322. return { installed: { id: "literature", version: "1.0.0" } }
  323. }
  324. if (request.action === "remove-pack") {
  325. plugin.packs = []
  326. if (plugin.failPackRefresh) plugin.packsError = true
  327. return { deleted: true }
  328. }
  329. if (request.action === "inspect-tool")
  330. return plugin.inspectError
  331. ? { status: "unreachable", message: "未能读取工具清单,请检查地址后重试。" }
  332. : {
  333. status: "ok",
  334. tools: [
  335. { name: "papers", description: "按关键词查找文献" },
  336. { name: "metadata", description: "读取文献元数据" },
  337. ],
  338. }
  339. if (request.action === "agent") {
  340. if (ux.configError) throw new Error("配置服务暂时不可用")
  341. return {
  342. ...agent,
  343. id: request.agentID,
  344. config: structuredClone(plugin.config),
  345. updated_at: String(plugin.version),
  346. }
  347. }
  348. if (request.action === "update-agent") {
  349. if (request.update.expected_updated_at !== String(plugin.version))
  350. throw new Error("配置版本已更新,请重新读取。")
  351. plugin.config = structuredClone(request.update.config || {})
  352. plugin.version++
  353. if (plugin.failRefreshAfterSave) ux.configError = true
  354. return { saved: true }
  355. }
  356. }
  357. if (request.action === "task-scope") {
  358. if (ux.scopeError) throw new Error("scope unavailable")
  359. return { agent_id: request.agentID, version: "1", local_tools: ["ReadFile", "WriteFile", "Bash"], external_tools: [{ connection: "literature", name: "Search" }], shell_access: true, shared_across_projects: true }
  360. }
  361. if (ux.enabled) {
  362. if (request.action === "agent" && ux.configError) throw new Error("配置服务暂时不可用")
  363. if (request.action === "agent")
  364. return {
  365. ...agent,
  366. config: structuredClone(researchConfig),
  367. updated_at: ux.configVersion,
  368. can_update_metadata: true,
  369. }
  370. if (request.action === "update-agent") {
  371. if (request.update.expected_updated_at !== ux.configVersion) throw new Error("配置版本已更新,请重新读取。")
  372. researchConfig = request.update.config as typeof researchConfig
  373. return { saved: true }
  374. }
  375. if (request.action === "knowledge") return { items: [] }
  376. if (request.action === "upload-selected" || request.action === "upload-file") {
  377. ux.uploads++
  378. uploads.forEach((listener) => listener({ uploadID: request.uploadID!, sent: 10, total: 10 }))
  379. if (request.action === "upload-selected" && request.selectionID === "two" && ux.uploads === 2)
  380. throw new Error("上传暂时失败")
  381. return {
  382. file_id: `file_${ux.uploads}`,
  383. name:
  384. request.action === "upload-file" ? request.name : request.selectionID === "one" ? "成功.txt" : "重试.txt",
  385. }
  386. }
  387. if (request.action === "file-capabilities") return { direct_upload_max_bytes: 100000 }
  388. if (request.action === "threads") return { threads: [] }
  389. if (request.action === "thread-runs") {
  390. if (ux.threadError) throw new Error(ux.threadError)
  391. const value = structuredClone({
  392. thread_id: request.threadID,
  393. runs: [...uxRuns.values()].filter((row) => row.thread_id === request.threadID),
  394. })
  395. if (ux.holdThread === request.threadID) {
  396. ux.holdThread = ""
  397. ux.held = true
  398. await new Promise<void>((resolve) => {
  399. ux.release = () => {
  400. ux.held = false
  401. resolve()
  402. }
  403. })
  404. }
  405. return value
  406. }
  407. if (request.action === "lookup-request") {
  408. if (ux.receiptError) throw new Error(ux.receiptError)
  409. const run = [...uxRuns.values()].find((row) => row.request_key === request.requestID)
  410. return run ? { found: true, run: { ...run } } : { found: false, state: "not_observed", retry_safe: false }
  411. }
  412. if (request.action === "execute") {
  413. if (request.input === "模拟网络中断") throw new Error("连接中断,提交结果未知")
  414. const id = `ux_${uxRuns.size + 1}`
  415. const value = {
  416. run_id: id,
  417. thread_id: request.threadID || `thread_${id}`,
  418. agent_id: request.agentID,
  419. status: "running",
  420. input: request.input,
  421. output: "",
  422. created_at: new Date().toISOString(),
  423. request_key: request.requestID,
  424. }
  425. uxRuns.set(id, value)
  426. if (request.input === "回执丢失但任务已创建") throw new Error("连接中断,回执未收到")
  427. progress.forEach((listener) =>
  428. listener({ executionID: request.executionID!, type: "started", runID: id, threadID: value.thread_id }),
  429. )
  430. return { ...value }
  431. }
  432. if (request.action === "history") {
  433. const all = [...uxRuns.values()].reverse(),
  434. offset = request.offset || 0
  435. const recent = all.slice(offset, offset + 20)
  436. const active = request.includeActive
  437. ? all.filter(
  438. (row) =>
  439. !["completed", "failed", "partial", "cancelled", "needs_clarification"].includes(String(row.status)),
  440. )
  441. : []
  442. return {
  443. runs: [...new Map([...recent, ...active].map((row) => [row.run_id, { ...row }])).values()],
  444. pagination_supported: true,
  445. active_included: !!request.includeActive,
  446. next_offset: offset + 20 < all.length ? offset + 20 : null,
  447. }
  448. }
  449. if (request.action === "run") {
  450. const value = structuredClone(uxRuns.get(request.runID))
  451. if (ux.holdRun === request.runID) {
  452. ux.holdRun = ""
  453. ux.held = true
  454. await new Promise<void>((resolve) => {
  455. ux.release = () => {
  456. ux.held = false
  457. resolve()
  458. }
  459. })
  460. }
  461. return value || {}
  462. }
  463. }
  464. if (request.action === "verify")
  465. return { checks: [{ kind: "model", name: "科研模型", status: request.checkModel ? "passed" : "not_checked" }] }
  466. if (request.action === "agents") return { agents }
  467. if (request.action === "run-options") throw new Error("HTTP 404")
  468. if (request.action === "threads")
  469. return {
  470. threads: request.agentID === unusedAgent.id ? [] : [{ id: "thread_1", title: "已有研究" }],
  471. }
  472. if (request.action === "thread-runs") return { thread_id: "thread_1", runs: [{ ...run, input: "分析材料" }] }
  473. if (request.action === "execute" && request.input === "持续研究") {
  474. run.status = "running"
  475. run.pending_approval = null
  476. }
  477. if (request.action === "execute") {
  478. progress.forEach((listener) =>
  479. listener({
  480. executionID: request.executionID ?? "",
  481. type: "tool_call",
  482. tool: "file_search",
  483. content: "查找材料目录",
  484. }),
  485. )
  486. progress.forEach((listener) =>
  487. listener({
  488. executionID: request.executionID ?? "",
  489. type: "tool_result",
  490. tool: "file_search",
  491. content: "找到 2 份材料",
  492. }),
  493. )
  494. }
  495. if (request.action === "execute" || request.action === "run") return { ...run }
  496. if (request.action === "pause") {
  497. run.status = "paused"
  498. run.checkpoint_id = "checkpoint_1"
  499. return { ...run }
  500. }
  501. if (request.action === "resume") {
  502. run.status = "running"
  503. return { ...run }
  504. }
  505. if (request.action === "cancel") {
  506. run.status = "cancelled"
  507. return { ...run }
  508. }
  509. if (request.action === "confirm") {
  510. run.status = "completed"
  511. run.pending_approval = null
  512. run.output = "研究计划已完成"
  513. return { ...run }
  514. }
  515. if (request.action === "run-files" && ux.filesError) throw new Error(ux.filesError)
  516. if (request.action === "run-files")
  517. return {
  518. files: [
  519. { name: "研究计划.pdf", path: "final/研究计划.pdf" },
  520. { name: ux.previewName || "研究计划.md", path: "final/研究计划.md" },
  521. ...(filesMode
  522. ? [
  523. { name: "config.yml", path: "work/config.yml" },
  524. { name: "sample-input.csv", path: "input/sample-input.csv", purpose: "input", downloadable: true },
  525. { name: "trace.json", path: "work/trace.json" },
  526. { name: "analysis.py", path: "work/analysis.py" },
  527. ]
  528. : []),
  529. ],
  530. }
  531. if (request.action === "preview-file") {
  532. if (ux.previewError) throw new Error(ux.previewError)
  533. if (/\.md$/i.test(request.name))
  534. return {
  535. name: request.name,
  536. mime: "text/markdown",
  537. size: 46,
  538. text: ux.previewText || "## 可预览的研究计划\n\n这是 Agent 生成并保存在工作区的 Markdown 文档。",
  539. }
  540. return { name: request.name, mime: "application/pdf", size: 4, data: new Uint8Array([37, 80, 68, 70]) }
  541. }
  542. if (request.action === "export-report")
  543. return {
  544. saved: true,
  545. name: `研究报告.${request.format || "md"}`,
  546. path: `/tmp/研究报告.${request.format || "md"}`,
  547. }
  548. if (request.action === "download") return { saved: true, name: "研究计划.pdf", path: "/tmp/研究计划.pdf" }
  549. if (request.action === "history") return { runs: [{ ...run, input: "分析材料" }] }
  550. return {}
  551. },
  552. }
  553. Object.assign(window, { paasTestCalls: calls })
  554. const platform: Platform = {
  555. revealPath: async () => true,
  556. platform: "desktop",
  557. os: new URLSearchParams(location.search).get("os") === "windows" ? "windows" : "macos",
  558. openDirectoryPickerDialog: async () => {
  559. if (ux.directoryError) throw new Error(ux.directoryError)
  560. if (ux.directories.length) return ux.directories.shift()
  561. if (ux.holdDirectory)
  562. await new Promise<void>((resolve) => {
  563. ux.releaseDirectory = resolve
  564. })
  565. return "D:/Research/optics"
  566. },
  567. paas: api,
  568. openExternal: (url) => {
  569. ux.external.push(url)
  570. },
  571. restart: async () => {},
  572. notify: async () => {},
  573. }
  574. const [code, setCode] = createStore({ active: false, mounted: false, directory: "" })
  575. const managed = new URLSearchParams(location.search).has("managed")
  576. render(
  577. () => (
  578. <PlatformProvider value={platform}>
  579. <AppBaseProviders locale="zh">
  580. {query.has("native-sidenote") ? <NativeSideNoteFixture /> : new URLSearchParams(location.search).has("panel") ? (
  581. <PanelFixture />
  582. ) : (
  583. <PaasWorkspace
  584. standalone
  585. developerActive={code.active}
  586. onCloseDeveloper={() => setCode("active", false)}
  587. onOpenDeveloper={
  588. query.has("unified")
  589. ? (directory) => setCode({ active: true, mounted: true, directory: directory || "" })
  590. : undefined
  591. }
  592. developerContent={
  593. <Show when={code.mounted}>
  594. <section aria-label="代码测试区">
  595. <span>{code.directory}</span>
  596. <input aria-label="代码草稿" />
  597. </section>
  598. </Show>
  599. }
  600. deployment={
  601. managed
  602. ? {
  603. edition: "team",
  604. platformUrl: "https://team.example",
  605. allowCustomPlatform: false,
  606. modelPolicy: "managed",
  607. permissionsDefault: "allow",
  608. }
  609. : undefined
  610. }
  611. />
  612. )}
  613. </AppBaseProviders>
  614. </PlatformProvider>
  615. ),
  616. document.getElementById("root")!,
  617. )