main.ts 7.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Browser-only visual fixture. All /api requests stay in memory; no user data is changed.
  2. import {createApp, defineComponent, h, ref} from 'vue'
  3. import {createPinia} from 'pinia'
  4. import BotSettingsDialog from '@/components/workspace/BotSettingsDialog.vue'
  5. import BotProfileDialog from '@/components/workspace/BotProfileDialog.vue'
  6. import SettingsCenterDialog from '@/components/app/SettingsCenterDialog.vue'
  7. import {useAuthStore} from '@/stores/auth'
  8. import '@/styles/tokens.css'
  9. import '@/styles/global.css'
  10. const query=new URLSearchParams(location.search)
  11. if(query.get('view')==='desktop-mode'){
  12. let mode:'client'|'server'='client'
  13. window.yaoyaoDesktop={
  14. modeState:async()=>({mode,serverURL:mode==='client'?'http://192.168.1.200:15300':'http://127.0.0.1:15300',switching:false}),
  15. switchMode:async next=>{mode=next;return {ok:true}},openRemoteLogin:async()=>{},
  16. openComputer:async()=>false,computerClosed:async()=>{},onComputerClose:()=>()=>{},
  17. }
  18. }
  19. const names=['测试2','竹儿','测试','瑶儿']
  20. const agents=names.map((name,i)=>({id:`00000000-0000-4000-8000-00000000000${i+1}`,name,profile:'default',nodeId:'local',archived:false,avatar:'',instructions:'协助整理项目资料,检查问题并给出清晰、简洁的建议。',execution:'computer',canManageTeam:false,canCollaborate:true,memoryEnabled:true,createdAt:1,updatedAt:1}))
  21. const conversations=[{id:'group-a',name:'方案分析团队',kind:'group',memberIds:agents.map(a=>a.id),archived:false},{id:'group-b',name:'内容运营组',kind:'group',memberIds:agents.slice(0,3).map(a=>a.id),archived:false}]
  22. const projects=query.has('empty')?[]:[
  23. {id:'project-a',name:'夭夭产品开发',description:'',memberIds:agents.map(a=>a.id),groupIds:['group-a','group-b'],revision:1,archived:false,createdAt:1,updatedAt:1},
  24. {id:'project-b',name:'内容运营',description:'',memberIds:agents.slice(0,3).map(a=>a.id),groupIds:['group-b'],revision:1,archived:false,createdAt:1,updatedAt:1},
  25. ]
  26. const identity={serverId:'00000000-0000-4000-8000-000000000099',name:'我的工作空间',displayName:'我的工作空间',revision:1}
  27. const desktopHosts=[
  28. {id:'f184922a-713c-4190-9c46-6e200e6c4c01',name:'LSamienacStudio',displayName:'',enabled:true,online:false,createdAt:Date.parse('2026-09-10T09:30:00+08:00')},
  29. {id:'c791ba30-f185-4734-8e72-549bc02e7e02',name:'LSamienacStudio',displayName:'',enabled:true,online:true,createdAt:Date.parse('2026-09-19T18:05:00+08:00')},
  30. ]
  31. let localComputerName=''
  32. const realFetch=window.fetch.bind(window)
  33. window.fetch=async(input,init)=>{
  34. const url=new URL(typeof input==='string'?input:input instanceof URL?input.href:input.url,location.href)
  35. if(!url.pathname.startsWith('/api/'))return realFetch(input,init)
  36. const body=typeof init?.body==='string'?JSON.parse(init.body):{}
  37. let data:unknown
  38. if(url.pathname==='/api/app/capabilities')data={features:['bot-file-memory-v1']}
  39. else if(url.pathname==='/api/app/bootstrap')data={csrfToken:'fixture-only',userId:'fixture-user',authRequired:true}
  40. else if(url.pathname==='/api/app/agents')data={agents}
  41. else if(url.pathname==='/api/app/conversations')data={conversations}
  42. else if(url.pathname==='/api/app/models')data={provider:'custom',model:'GPT-5.6-terra',providers:[{slug:'custom',name:'Custom endpoint',models:['GPT-5.6-terra'],is_current:true}]}
  43. else if(url.pathname==='/api/app/admin/legacy-model-services')data={items:[]}
  44. else if(url.pathname.startsWith('/api/app/admin/model-services'))data={endpoints:[],services:[],current:{provider:'custom',model:'GPT-5.6-terra',base_url:''}}
  45. else if(url.pathname==='/api/app/workspace/projects'){
  46. if(init?.method==='POST'){
  47. const previous=projects.find(p=>p.id===body.id)
  48. const project={...body,id:body.id??crypto.randomUUID(),revision:(previous?.revision??0)+1,createdAt:1,updatedAt:1}
  49. if(previous)Object.assign(previous,project);else projects.push(project)
  50. data={project}
  51. }else data={projects}
  52. }else if(url.pathname.includes('/memory-jobs'))data={jobs:[]}
  53. else if(url.pathname.includes('/memories'))data={memories:[]}
  54. else if(url.pathname.includes('server-identity'))data=identity
  55. else if(url.pathname==='/api/app/computers')data={computers:[]}
  56. else if(url.pathname==='/api/app/settings/host-tools')data={approvalPolicy:'allow',scriptMachine:true,serverComputer:true,vm:true,cloud:true,...body}
  57. else if(url.pathname==='/api/app/admin/desktop-hosts')data={hosts:desktopHosts,localName:localComputerName}
  58. else if(url.pathname.startsWith('/api/app/admin/desktop-hosts/')){
  59. const id=url.pathname.split('/')[5]
  60. const host=desktopHosts.find(item=>item.id===id)
  61. if(init?.method==='PUT'&&url.pathname.endsWith('/name')){
  62. if(id==='local')localComputerName=body.name
  63. else if(host)host.displayName=body.name
  64. }else if(init?.method==='DELETE'&&host)host.enabled=false
  65. data={ok:true}
  66. }
  67. else if(url.pathname==='/api/app/admin/local-vm')data={configured:true,enabled:true,mode:'shared',maxInstances:2,idleStopMinutes:0,runtime:'docker',daemonUp:true,image:true,images:[{key:'standard',ready:true},{key:'cursor',ready:true}],instances:[]}
  68. else return new Response(JSON.stringify({error:{message:'此预览没有连接服务'}}),{status:404,headers:{'content-type':'application/json'}})
  69. return new Response(JSON.stringify(data),{headers:{'content-type':'application/json'}})
  70. }
  71. const theme=ref<'light'|'dark'|'system'>(query.get('theme')==='dark'?'dark':'light')
  72. function setTheme(value:'light'|'dark'|'system'){theme.value=value;document.documentElement.classList.toggle('dark',value==='dark')}
  73. setTheme(theme.value)
  74. const App=defineComponent({setup(){
  75. const auth=useAuthStore()
  76. auth.user={id:'fixture-user',username:'samien',role:query.has('member')?'member':'admin'} as never
  77. auth.status='authenticated';auth.serverIdentity=identity
  78. const opened=ref<'bot'|'personal'|'editor'|null>(query.get('view')==='editor'?'editor':['bubbles','appearance','profile','desktop-mode'].includes(query.get('view')??'')?'personal':'bot')
  79. return()=>h('main',{style:'min-height:100dvh;background:var(--settings-panel);padding:18px;box-sizing:border-box'},[
  80. h('div',{style:'display:flex;gap:12px;align-items:center;font:13px var(--font-ui)'},[
  81. h('span','界面验证 · 示例数据'),h('button',{onClick:()=>opened.value='bot'},'Bot 设置'),h('button',{onClick:()=>opened.value='personal'},'我的设置'),h('button',{onClick:()=>opened.value='editor'},'编辑资料'),
  82. ]),
  83. opened.value==='bot'?h(BotSettingsDialog,{isAdmin:!query.has('member'),initialPage:query.get('view')==='computers'?'computers':'projects',onClose:()=>opened.value=null}):null,
  84. opened.value==='editor'?h(BotProfileDialog,{agent:agents[0],draft:{...agents[0],source:'["local","default"]'},sources:[{nodeId:'local',profile:'default',name:'丫头'}],profiles:[{name:'default',agentName:'丫头',isDefault:true}],agents,conversations,conversationId:'fixture-chat',isAdmin:!query.has('member'),knowledgeEnabled:true,onClose:()=>opened.value=null,onSave:()=>opened.value=null} as never):null,
  85. h(SettingsCenterDialog,{open:opened.value==='personal',initialPage:query.get('view')==='bubbles'?'chat-appearance':query.get('view')==='desktop-mode'?'desktop-mode':query.get('view')==='profile'?'account-profile':'appearance',isAdmin:!query.has('member'),botMode:true,userName:'samien',theme:theme.value==='dark'?'dark':'light',themePreference:theme.value,profiles:[{name:'default',agentName:'默认机器人',isDefault:true}],activeProfile:{name:'default',agentName:'默认机器人',isDefault:true},onClose:()=>opened.value=null,'onSet-theme':setTheme}),
  86. ])
  87. }})
  88. createApp(App).use(createPinia()).mount('#app')