@jetcrab/pi-desk 1.1.18-dev → 1.1.20-dev
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/docs/plugins.md +1 -1
- package/next.config.ts +1 -0
- package/package.json +3 -2
- package/src/client/l2_biz/workbench/file-workspace/l2-file-workspace-runtime.ts +1 -1
- package/src/client/l2_biz/workbench/hooks/l2-workbench-chat-reload.ts +42 -0
- package/src/client/l2_biz/workbench/l2-work-session-sidebar.tsx +19 -1
- package/src/client/l2_biz/workbench/l2-workbench-chat.ts +45 -0
- package/src/client/l2_biz/workbench/l2-workbench.tsx +4 -0
- package/src/client/l3_modules/conversation/l3-conversation-markdown.tsx +10 -1
- package/src/client/l3_modules/project-files/l3-markdown-preview.tsx +10 -1
- package/src/client/l3_modules/project-files/l3-project-document-view.tsx +2 -0
- package/src/client/l3_modules/project-files/l3-project-file-browser.tsx +171 -229
- package/src/client/l3_modules/project-files/l3-project-file-runtime.ts +133 -70
- package/src/client/l3_modules/project-files/l3-project-reader.ts +4 -3
- package/src/client/l3_modules/project-files/views/l3-project-search-controls.tsx +201 -0
- package/src/client/l3_modules/project-files/views/l3-project-search-results.tsx +333 -0
- package/src/client/l4_foundation/ui/code/l4-code-preview.tsx +47 -3
- package/src/client/l4_foundation/ui/markdown/l4-markdown-remark.ts +89 -0
- package/src/client/l4_foundation/ui/markdown/l4-markdown.module.css +58 -0
- package/src/client/l4_foundation/ui/markdown/l4-markdown.tsx +108 -0
- package/src/common/l2_biz/work-session/l2-work-session-file-contract.ts +4 -3
- package/src/common/l2_biz/workbench/l2-workbench-locale-messages.ts +6 -0
- package/src/common/l3_modules/project-files/l3-project-files-contract.ts +2 -3
- package/src/common/l3_modules/project-files/l3-project-files-locale-messages.ts +56 -10
- package/src/common/l4_foundation/file/l4-project-file-contract.ts +51 -1
- package/src/common/l4_foundation/locale/l4-host-error-messages.ts +11 -0
- package/src/common/l4_foundation/locale/l4-locale-messages.ts +16 -0
- package/src/instrumentation.ts +0 -2
- package/src/server/l1_entry/api/l1-project-read-routes.ts +6 -4
- package/src/server/l1_entry/api/l1-project-route.ts +9 -8
- package/src/server/l1_entry/api/l1-work-session-file-error.ts +23 -0
- package/src/server/l2_biz/plugin-management/l2-plugin-management.ts +0 -3
- package/src/server/l2_biz/work-session/l2-work-session-chat-runtime.ts +30 -58
- package/src/server/l2_biz/work-session/l2-work-session-manage.ts +0 -4
- package/src/server/l4_foundation/file/l4-project-file-index.ts +276 -0
- package/src/server/l4_foundation/file/l4-project-search.ts +399 -0
- package/src/server/l4_foundation/file/l4-ripgrep-search.ts +192 -0
- package/src/server/l4_foundation/file/l4-work-session-project-file.ts +8 -332
- package/src/server/l4_foundation/pi/l4-pi-package-maintenance.ts +0 -6
- package/src/server/l4_foundation/pi/l4-pi-plugin-capability-probe.ts +1 -3
- package/src/server/l4_foundation/pi/l4-pi-plugin-probe.ts +1 -3
- package/src/server/l4_foundation/pi/l4-pi-runner-process.ts +2 -2
- package/src/server/l4_foundation/process/l4-process-tree.js +23 -4
- package/temp/build/pi-desk/release/.next/BUILD_ID +1 -1
- package/temp/build/pi-desk/release/.next/build-manifest.json +3 -3
- package/temp/build/pi-desk/release/.next/prerender-manifest.json +3 -3
- package/temp/build/pi-desk/release/.next/react-loadable-manifest.json +1 -1
- package/temp/build/pi-desk/release/.next/required-server-files.js +3 -2
- package/temp/build/pi-desk/release/.next/required-server-files.json +3 -2
- package/temp/build/pi-desk/release/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_global-error.html +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_global-error.rsc +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_not-found/page.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/api/health/route.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-files/get/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-files/list/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-files/reveal/route.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-files/search/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-git/get/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-git-branches/list/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-git-changes/list/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-git-diff/get/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-git-heads/get/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/api/project-git-log/list/route.js +2 -1
- package/temp/build/pi-desk/release/.next/server/app/login/page.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/temp/build/pi-desk/release/.next/server/app/page.js +77 -77
- package/temp/build/pi-desk/release/.next/server/app/page_client-reference-manifest.js +1 -1
- package/temp/build/pi-desk/release/.next/server/chunks/{33658.js → 10881.js} +8 -8
- package/temp/build/pi-desk/release/.next/server/chunks/23054.js +1 -1
- package/temp/build/pi-desk/release/.next/server/chunks/25406.js +3 -3
- package/temp/build/pi-desk/release/.next/server/chunks/35985.js +5 -5
- package/temp/build/pi-desk/release/.next/server/chunks/50520.js +2 -4
- package/temp/build/pi-desk/release/.next/server/chunks/6917.js +1 -1
- package/temp/build/pi-desk/release/.next/server/chunks/70780.js +1 -0
- package/temp/build/pi-desk/release/.next/server/chunks/74528.js +1 -1
- package/temp/build/pi-desk/release/.next/server/chunks/92386.js +1 -1
- package/temp/build/pi-desk/release/.next/server/instrumentation.js +1 -1
- package/temp/build/pi-desk/release/.next/server/middleware-build-manifest.js +1 -1
- package/temp/build/pi-desk/release/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/temp/build/pi-desk/release/.next/server/pages/500.html +1 -1
- package/temp/build/pi-desk/release/.next/server/server-reference-manifest.json +1 -1
- package/temp/build/pi-desk/release/.next/static/chunks/27611-0890482fe76bd9d6.js +238 -0
- package/temp/build/pi-desk/release/.next/static/chunks/{31087-ba426d09d6f68bfd.js → 31087-d8e5765d541d5c26.js} +1 -1
- package/temp/build/pi-desk/release/.next/static/chunks/{49516-cc4dcd84d64ab4fe.js → 51474-8dc714cb76b2e60a.js} +2 -2
- package/temp/build/pi-desk/release/.next/static/chunks/77592-5bef6acb8e7c4b96.js +13 -0
- package/temp/build/pi-desk/release/.next/static/chunks/app/layout-a50c456648537afb.js +3 -0
- package/temp/build/pi-desk/release/.next/static/chunks/app/{page-a984139e99586041.js → page-0789c43551b29dd2.js} +4 -4
- package/temp/build/pi-desk/release/.next/static/chunks/{webpack-40a782fc8a3535b9.js → webpack-d7248206b7fc7ba8.js} +1 -1
- package/temp/build/pi-desk/release/.next/static/css/250a6b93cc2222d1.css +1 -0
- package/temp/build/pi-desk/release/.next/static/css/6dbae2922f88ca31.css +1 -0
- package/temp/build/pi-desk/release/.next/static/css/a4cf28fd76c70165.css +1 -0
- package/temp/build/pi-desk/release/.next/trace-build +1 -1
- package/temp/build/pi-desk/release/.next/server/chunks/8584.js +0 -2
- package/temp/build/pi-desk/release/.next/static/chunks/39654-b5fedd762ea0312e.js +0 -238
- package/temp/build/pi-desk/release/.next/static/chunks/75130-d2ca74894aff8085.js +0 -13
- package/temp/build/pi-desk/release/.next/static/chunks/app/layout-c0e1c5cef8620cf8.js +0 -3
- package/temp/build/pi-desk/release/.next/static/css/6427d02b6edf406f.css +0 -1
- package/temp/build/pi-desk/release/.next/static/css/79e06f05df9edff0.css +0 -1
- /package/temp/build/pi-desk/release/.next/static/{n2LrXQgq8UkbH_AzhR3fw → RLKcK-RQF5FvEeDmS9uih}/_buildManifest.js +0 -0
- /package/temp/build/pi-desk/release/.next/static/{n2LrXQgq8UkbH_AzhR3fw → RLKcK-RQF5FvEeDmS9uih}/_ssgManifest.js +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";exports.id=23054,exports.ids=[23054],exports.modules={18477:(a,b,c)=>{c.d(b,{KE:()=>l,ds:()=>n,kM:()=>o});var d=c(59473),e=c(54733),f=c(58311),g=c(2364),h=c(2002);let i=d.Ik({}).strict(),j=d.Ik({workId:e.eW}).strict(),k=d.Ik({workId:e.eW}).strict(),l=d.Ik({cwd:e.ik.optional(),sessionId:e.Kx.optional(),branchId:d.Yj().min(1).optional(),projectName:d.Yj().trim().min(1).optional(),sessionTitle:d.Yj().trim().min(1).nullable().optional(),status:e.jw.optional(),messageCounts:e.AA.optional(),lastMessageUpdatedAt:g.k.nullable().optional()}).strict().refine(a=>Object.keys(a).length>0,{message:"work session changes cannot be empty"}),m=d.Ik({workSessions:d.YO(e.MY),pinnedCount:e.MT,appRuntime:f.GR}).strict().refine(a=>a.pinnedCount<=a.workSessions.length,{message:"pinnedCount cannot exceed work session count",path:["pinnedCount"]}),n=d.gM("type",[d.Ik({type:d.eu("snapshot"),workSessions:d.YO(e.MY),pinnedCount:e.MT}).strict().refine(a=>a.pinnedCount<=a.workSessions.length,{message:"pinnedCount cannot exceed work session count",path:["pinnedCount"]}),d.Ik({type:d.eu("update"),workId:e.eW,changes:l}).strict(),d.Ik({type:d.eu("delete"),workId:e.eW}).strict()]),o=Object.freeze({list:(0,h.Vc)({path:"work-sessions/list",inputSchema:i,outputSchema:m}),acknowledgeCompleted:(0,h.Vc)({path:"work-sessions/ack-completed",inputSchema:j,outputSchema:k}),update:(0,h._G)({path:"work-sessions/update",bodySchema:n})})},23024:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{E:()=>g});var e=c(72498),f=a([e]);e=(f.then?(await f)():f)[0];class g{constructor(a,b){this.workId=a,this.runtime=b}static async create(a,b,c){let d=c?await e.vC.open(b,c):e.vC.create(b);return new g(a,d)}get cwd(){return this.runtime.cwd}get sessionId(){return this.runtime.sessionId}get branchId(){return this.runtime.branchId}async branch(a){let b=await this.runtime.branch(a);return{changed:b.changed,editorText:b.editorText}}async createBranchedSession(a,b){let c=this.runtime.createBranchedSession(b);return{workSession:new g(a,c.runtime),editorText:c.editorText}}async send(a){return this.runtime.send(a)}async interrupt(){await this.runtime.interrupt()}async restoreQueuedMessages(){return this.runtime.restoreQueuedMessages()}async setTitle(a){await this.runtime.setTitle(a)}async setModel(a){await this.runtime.setModel(a)}}d()}catch(a){d(a)}})},23054:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{HK:()=>F,JJ:()=>y,Jl:()=>I,Jv:()=>G,Ki:()=>C,VH:()=>D,XM:()=>B,if:()=>H,k1:()=>A,qm:()=>x});var e=c(71473),f=c(77598),g=c(73024),h=c(76760),i=c(59473),j=c(25084),k=c(40529),l=c(77394),m=c(54733),n=c(18477),o=c(33270),p=c(23024),q=c(52913),r=c(65129),s=c(65209),t=c(72498),u=c(46524),v=c(47574),w=a([e,p,r,s,t,v]);[e,p,r,s,t,v]=w.then?(await w)():w;let z=i.Ik({workSessions:m.TO,pinnedCount:m.MT}).strict().refine(a=>a.pinnedCount<=a.workSessions.length,{message:"pinnedCount cannot exceed persisted work session count",path:["pinnedCount"]});class A extends Error{constructor(){super("WorkSession order does not match the current collection"),this.name="WorkSessionOrderConflictError"}}class B extends Error{constructor(a){super(`WorkSession not found: ${a}`),this.name="WorkSessionNotFoundError"}}class C extends Error{constructor(a,b){super(`Pi session ${a} is already bound to work session ${b}`),this.name="WorkSessionSessionConflictError"}}class D extends Error{constructor(a,b){super(`Pi session ${b} was not found in ${a}`),this.name="WorkSessionHistoryNotFoundError"}}class E extends Error{constructor(a,b,c){super(`WorkSession project changed: ${a} (${b} -> ${c})`),this.name="WorkSessionProjectChangedError"}}class F extends Error{constructor(a,b,c){super(`WorkSession binding changed: ${a} (${b} -> ${c})`),this.name="WorkSessionBindingChangedError"}}class G extends Error{constructor(a){super(`WorkSession branch entry was not found: ${a}`),this.name="WorkSessionBranchEntryNotFoundError"}}class H extends Error{constructor(a){super(a),this.name="WorkSessionBranchBlockedError"}}class I extends Error{constructor(a,b){super(b),this.kind=a,this.name="WorkSessionBranchInvalidError"}}class J extends Error{constructor(a){super(`WorkSession project directory is invalid: ${a}`),this.name="WorkSessionDirectoryInvalidError"}}function x(a){return a instanceof Error&&"WorkSessionDirectoryInvalidError"===a.name}class K{constructor(a=(0,h.join)((0,e.M)(),"work-sessions.json")){this.storePath=a,this.workSessionsById=new Map,this.updateListeners=new Set,this.chat=new v.yO,this.hydrated=!1,this.operationTail=Promise.resolve();const b=this.readPersistedState();this.restoredRecords=b.workSessions,this.pinnedCount=b.pinnedCount,this.rewriteLegacyStore=b.rewriteLegacyStore,this.chat.subscribeRecordChanges((a,b,c)=>this.publishChatRecordChange(a,b,c))}initialize(){return this.runExclusive(()=>this.ensureHydrated())}listWorkSessions(){return this.runExclusive(async()=>(await this.ensureHydrated(),this.createSnapshot()))}refreshPluginMessages(){this.chat.refreshPluginMessages()}runPluginRestart(a){return this.runExclusive(async()=>{await this.ensureHydrated();let b=await this.chat.pauseForProcessRestart();try{let b=await a();return console.info("[Pi Desk][WorkSessionManage] 全部工作会话已冻结,等待插件重载"),b}catch(a){throw b(),a}})}subscribeUpdates(a){return this.updateListeners.add(a),()=>this.updateListeners.delete(a)}subscribeMessageEvents(a){return this.chat.subscribe(a)}subscribePluginPushEvents(a){return this.chat.subscribePluginPush(a)}async prepareChatSourceSyncs(a){await this.initialize();let b=a.find(a=>!this.chat.isCurrentSource(a.source));if(b)throw new v.dM(b.source);return await Promise.all(a.map(a=>this.chat.prepareSource(a.source).catch(b=>{if(this.chat.isCurrentSource(a.source))throw b}))),a.filter(a=>this.chat.isCurrentSource(a.source)).map(a=>{let b=this.chat.createSync(a.source,a.cursor);return{source:a.source,event:b.event,watermark:b.watermark}})}async getChatMessageDetail(a){return await this.initialize(),this.chat.getMessageDetail(a)}async getChatModelContext(a){return await this.initialize(),this.chat.getModelContext(a)}async getChatImage(a){return await this.initialize(),this.chat.getImage(a)}async sendChat(a){return await this.initialize(),this.chat.send(a)}async interruptChat(a){await this.initialize(),await this.chat.interrupt(a)}async compactChat(a){await this.initialize(),await this.chat.compact(a)}async reloadChat(a,b){await this.initialize(),await this.chat.reload(a,b)}async setChatPresentation(a,b){await this.initialize(),await this.chat.setPresentation(a,b)}async restoreChatQueue(a){return await this.initialize(),this.chat.restoreQueuedMessages(a)}async setChatModel(a){await this.initialize(),await this.chat.setModel(a)}async setChatCapabilityMode(a){await this.initialize(),await this.chat.setCapabilityMode(a)}getNativeUi(a){if(!this.chat.isCurrentSource(a))throw new v.dM(a);return(0,t.ls)(a.sessionId).nativeUi}async invokeSessionPluginMethod(a){return await this.initialize(),this.chat.invokePluginMethod(a)}async listNativeCommands(a){return await this.initialize(),j.WF.parse({commands:await this.chat.listNativeCommands(a.source)})}async executeNativeCommand(a){await this.initialize(),await this.chat.executeNativeCommand(a.source,a.command,a.args??"")}async listNativeTools(a){return await this.initialize(),j.RH.parse({tools:await this.chat.listNativeTools(a.source)})}async executeDirectBash(a){return await this.initialize(),j.uU.parse(await this.chat.executeDirectBash(a.source,{command:a.command,excludeFromContext:a.excludeFromContext}))}async abortDirectBash(a){await this.initialize(),await this.chat.abortDirectBash(a.source)}async listModels(a){let b=m.eW.parse(a);await this.initialize();let c=this.workSessionsById.get(b);if(!c)throw new B(b);return k.IM.parse(await (0,t.ls)(c.sessionId).listModels())}async acknowledgeCompleted(a){let b=m.eW.parse(a);if(await this.initialize(),!this.workSessionsById.has(b))throw new B(b);return this.chat.acknowledgeCompleted(b)}setWorkSessionArrangement(a,b){let c=a.map(a=>m.eW.parse(a)),d=m.MT.parse(b);return this.runExclusive(async()=>{await this.ensureHydrated();let a=Array.from(this.workSessionsById.keys());if(c.length!==a.length||d>c.length||new Set(c).size!==c.length||c.some(a=>!this.workSessionsById.has(a)))throw new A;if(c.every((b,c)=>b===a[c])&&d===this.pinnedCount)return this.createSnapshot();let b=c.map(a=>this.workSessionsById.get(a));for(let a of(this.workSessionsById.clear(),b))this.workSessionsById.set(a.workId,a);this.pinnedCount=d,this.persist();let e=this.createSnapshot();return this.publishUpdate({type:"snapshot",...e}),console.info("[Pi Desk][WorkSessionManage] 已更新工作会话排列",{workIds:c,pinnedCount:d}),e})}getWorkSession(a){let b=m.eW.parse(a);return this.runExclusive(async()=>(await this.ensureHydrated(),this.workSessionsById.get(b)??null))}getProjectPreviewContext(a,b){return this.workSessionsById.get(a.workId)!==a?null:this.chat.getProjectPreviewContext(a,b)}async replaceProjectGitBranch(a){let b=l.Yh.parse(a),c=await this.authorizeProjectFiles(b.workId,b.cwd),d=await (0,q.Ak)(c,b.repositoryRoot,b.target);return console.info("[Pi Desk][WorkSessionManage] 已切换 Git 分支",{workId:b.workId,cwd:c,repositoryRoot:b.repositoryRoot,targetType:b.target.type,targetName:b.target.name}),l.hr.parse({repository:d})}async addProjectGitBranch(a){let b=l.XV.parse(a),c=await this.authorizeProjectFiles(b.workId,b.cwd),d=await (0,q.bV)(c,b.repositoryRoot,b.name,b.startPoint);return console.info("[Pi Desk][WorkSessionManage] 已新建并切换 Git 分支",{workId:b.workId,cwd:c,repositoryRoot:b.repositoryRoot,branchName:b.name,startPointType:b.startPoint?.type??null,startPointName:b.startPoint?.name??null}),l.hr.parse({repository:d})}createWorkSession(a,b){let c,d=m.ik.parse(a),e=void 0===b?void 0:m.Kx.parse(b);try{c=(0,r.G2)(d)}catch{throw new J(d)}return this.runExclusive(async()=>{if(await this.ensureHydrated(),e){let a=this.findBoundWorkId(e);if(a)throw new C(e,a);if(!await (0,s.vg)(c,e))throw new D(c,e)}let a=await p.E.create((0,f.randomUUID)(),c,e);this.chat.addWorkSession(a),this.insertUnpinnedWorkSession(a),this.persist();let b=this.toListItem(a),d=this.createSnapshot();return this.publishUpdate({type:"snapshot",...d}),console.info("[Pi Desk][WorkSessionManage] 已创建工作会话",{workId:a.workId,cwd:a.cwd,sessionId:a.sessionId,creationType:e?"history":"empty"}),b})}renameWorkSession(a){let b=m.qL.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b.workId);if(!a)throw new B(b.workId);this.assertSessionBinding(a,b.sessionId),await this.chat.setTitle(a,b.title)})}replaceWorkSession(a,b){let c=m.eW.parse(a),d=b?{cwd:m.ik.parse(b.cwd),sessionId:m.Kx.parse(b.sessionId)}:null;return this.runExclusive(async()=>{let a;await this.ensureHydrated();let b=this.workSessionsById.get(c);if(!b)throw new B(c);if(d&&b.cwd===d.cwd&&b.sessionId===d.sessionId)return this.createSnapshot();if(d){let a=this.findBoundWorkId(d.sessionId);if(a&&a!==c)throw new C(d.sessionId,a)}let e=this.toListItem(b);await this.chat.pauseWorkSession(c);try{a=await p.E.create(c,d?.cwd??b.cwd,d?.sessionId),await this.chat.replaceWorkSession(b,a)}catch(a){throw this.chat.resumeWorkSession(c),a}this.workSessionsById.set(c,a),this.persist();let f=this.toListItem(a),g=this.createSnapshot(),h=this.toChanges(e,f);return h&&this.publishUpdate({type:"update",workId:c,changes:h}),console.info("[Pi Desk][WorkSessionManage] 已替换 Pi 会话",{workId:c,replacementType:d?"history":"empty",previousCwd:b.cwd,previousSessionId:b.sessionId,cwd:a.cwd,sessionId:a.sessionId,branchId:a.branchId}),g})}getWorkSessionTree(a){let b=o.i0.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b.workId);if(!a)throw new B(b.workId);return this.assertSessionBinding(a,b.sessionId),o.u1.parse(await (0,t.ls)(a.sessionId).readSessionTree())})}getWorkSessionTreeEntry(a){let b=o.iW.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b.workId);if(!a)throw new B(b.workId);this.assertSessionBinding(a,b.sessionId);try{return o.Cn.parse(await (0,t.ls)(a.sessionId).readSessionTreeEntryDetail(b.entryId))}catch(a){if(a instanceof u.Ns)throw new G(b.entryId);throw a}})}branchWorkSession(a){let b=o.g$.parse(a);return this.runExclusive(async()=>{let a;await this.ensureHydrated();let c=this.workSessionsById.get(b.workId);if(!c)throw new B(b.workId);if(this.assertSessionBinding(c,b.sessionId),"tree"===b.action){let a,d=this.toListItem(c);await this.chat.pauseWorkSession(c.workId);try{(a=await c.branch(b.entryId)).changed?await this.chat.refreshWorkSession(c):this.chat.resumeWorkSession(c.workId)}catch(a){if(c.branchId!==d.branchId){await this.chat.refreshWorkSession(c);let a=this.toChanges(d,this.toListItem(c));a&&this.publishUpdate({type:"update",workId:c.workId,changes:a})}else this.chat.resumeWorkSession(c.workId);this.throwBranchError(a,b.entryId)}let e=this.toListItem(c),f=this.toChanges(d,e);f&&this.publishUpdate({type:"update",workId:c.workId,changes:f});let g=this.createSnapshot();return console.info("[Pi Desk][WorkSessionManage] 已切换当前 JSONL 分支",{workId:c.workId,cwd:c.cwd,sessionId:c.sessionId,entryId:b.entryId,branchId:c.branchId,changed:a.changed}),o.WJ.parse({...g,targetWorkId:c.workId,editorText:a.editorText})}"clone"===b.action&&await this.chat.pauseWorkSession(c.workId);try{a=await c.createBranchedSession((0,f.randomUUID)(),"fork"===b.action?{position:"before",entryId:b.entryId}:{position:"at"}),this.chat.addWorkSession(a.workSession)}catch(a){this.throwBranchError(a,"entryId"in b?b.entryId:null)}finally{"clone"===b.action&&this.chat.resumeWorkSession(c.workId)}let d=a.workSession;this.insertUnpinnedWorkSession(d),this.persist();let e=this.createSnapshot();return this.publishUpdate({type:"snapshot",...e}),console.info("[Pi Desk][WorkSessionManage] 已创建分支 WorkSession",{action:b.action,sourceWorkId:c.workId,sourceSessionId:c.sessionId,workId:d.workId,cwd:d.cwd,entryId:"entryId"in b?b.entryId:null,sessionId:d.sessionId,branchId:d.branchId}),o.WJ.parse({...e,targetWorkId:d.workId,editorText:a.editorText})})}removeWorkSession(a){let b=m.eW.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b);if(!a)return!1;let c=Array.from(this.workSessionsById.keys()).indexOf(b);return await this.chat.pauseWorkSession(b),await this.chat.removeWorkSession(a),this.workSessionsById.delete(b),c<this.pinnedCount&&(this.pinnedCount-=1),this.persist(),this.publishUpdate({type:"delete",workId:b}),console.info("[Pi Desk][WorkSessionManage] 已删除工作会话",{workId:b,pinnedCount:this.pinnedCount}),!0})}async ensureHydrated(){if(this.hydrated)return;let a=performance.now();console.info("[Pi Desk][WorkSessionManage] 开始恢复工作会话",{workSessionCount:this.restoredRecords.length});let b=await Promise.all(this.restoredRecords.map(a=>p.E.create(a.workId,a.cwd,a.sessionId))),c=performance.now();await this.chat.initialize(b);let d=performance.now();for(let e of(console.info("[Pi Desk][WorkSessionManage] 工作会话恢复完成",{workSessionCount:b.length,durationMs:Math.round(d-a),sessionOpenMs:Math.round(c-a),messageProjectionMs:Math.round(d-c)}),b))this.workSessionsById.set(e.workId,e);this.hydrated=!0,this.rewriteLegacyStore&&(this.persist(),this.rewriteLegacyStore=!1,console.info("[Pi Desk][WorkSessionManage] 已升级工作会话持久化格式",{workSessionCount:b.length,pinnedCount:this.pinnedCount}))}async authorizeProjectFiles(a,b){await this.initialize();let c=this.workSessionsById.get(a);if(!c)throw new B(a);if(c.cwd!==b)throw new E(a,b,c.cwd);return c.cwd}findBoundWorkId(a){for(let b of this.workSessionsById.values())if(b.sessionId===a)return b.workId}insertUnpinnedWorkSession(a){let b=this.orderedWorkSessions();for(let c of(b.splice(this.pinnedCount,0,a),this.workSessionsById.clear(),b))this.workSessionsById.set(c.workId,c)}assertSessionBinding(a,b){if(a.sessionId!==b)throw new F(a.workId,b,a.sessionId)}throwBranchError(a,b){if(a instanceof u.Ns)throw new G(b??"");if(a instanceof u.dX)throw new I("fork-target","只有用户消息可以 Fork");if(a instanceof t.er)throw new I("clone-empty","当前会话还没有可克隆的消息");if(a instanceof t.Wo)throw new H(a.message);throw a}orderedWorkSessions(){return Array.from(this.workSessionsById.values())}createSnapshot(){return m.kg.parse({workSessions:this.orderedWorkSessions().map(a=>this.toListItem(a)),pinnedCount:this.pinnedCount})}toRecord(a){return m.ER.parse({workId:a.workId,cwd:a.cwd,sessionId:a.sessionId})}toListItem(a){let b=this.chat.metadataFor(a);return m.MY.parse({...this.toRecord(a),branchId:a.branchId,projectName:(0,h.basename)(a.cwd)||a.cwd,sessionTitle:b.sessionTitle,status:this.chat.statusFor(a),messageCounts:b.messageCounts,lastMessageUpdatedAt:b.lastMessageUpdatedAt})}toChanges(a,b){let c={};return a.cwd!==b.cwd&&(c.cwd=b.cwd),a.sessionId!==b.sessionId&&(c.sessionId=b.sessionId),a.branchId!==b.branchId&&(c.branchId=b.branchId),a.projectName!==b.projectName&&(c.projectName=b.projectName),a.sessionTitle!==b.sessionTitle&&(c.sessionTitle=b.sessionTitle),a.status!==b.status&&(c.status=b.status),(a.messageCounts.user!==b.messageCounts.user||a.messageCounts.total!==b.messageCounts.total)&&(c.messageCounts=b.messageCounts),a.lastMessageUpdatedAt!==b.lastMessageUpdatedAt&&(c.lastMessageUpdatedAt=b.lastMessageUpdatedAt),0===Object.keys(c).length?null:n.KE.parse(c)}publishChatRecordChange(a,b,c){if(!this.hydrated)return;let d=this.workSessionsById.get(a);if(!d)return;let e=this.toListItem(d),f=this.toChanges({...e,...b,status:c},e);f&&this.publishUpdate({type:"update",workId:a,changes:f})}publishUpdate(a){let b=n.ds.parse(a);for(let a of[...this.updateListeners])try{a(b)}catch(a){console.error("[Pi Desk][WorkSessionManage] 推送工作会话变化失败",{updateType:b.type,errorName:a instanceof Error?a.name:"UnknownError"})}}readPersistedState(){if(!(0,g.existsSync)(this.storePath))return{workSessions:[],pinnedCount:0,rewriteLegacyStore:!1};let a=JSON.parse((0,g.readFileSync)(this.storePath,"utf8")),b=Array.isArray(a),c=b?z.parse({workSessions:m.TO.parse(a),pinnedCount:0}):z.parse(a),d=new Set,e=new Set;for(let a of c.workSessions){if(d.has(a.workId))throw Error(`Duplicate persisted workId: ${a.workId}`);if(e.has(a.sessionId))throw Error(`Duplicate persisted sessionId binding: ${a.sessionId}`);d.add(a.workId),e.add(a.sessionId)}return{...c,rewriteLegacyStore:b}}persist(){let a=z.parse({workSessions:this.orderedWorkSessions().map(a=>this.toRecord(a)),pinnedCount:this.pinnedCount});(0,g.mkdirSync)((0,h.dirname)(this.storePath),{recursive:!0});let b=`${this.storePath}.${process.pid}.${(0,f.randomUUID)()}.tmp`;try{(0,g.writeFileSync)(b,`${JSON.stringify(a,null,2)}
|
|
1
|
+
"use strict";exports.id=23054,exports.ids=[23054],exports.modules={18477:(a,b,c)=>{c.d(b,{KE:()=>l,ds:()=>n,kM:()=>o});var d=c(59473),e=c(54733),f=c(58311),g=c(2364),h=c(2002);let i=d.Ik({}).strict(),j=d.Ik({workId:e.eW}).strict(),k=d.Ik({workId:e.eW}).strict(),l=d.Ik({cwd:e.ik.optional(),sessionId:e.Kx.optional(),branchId:d.Yj().min(1).optional(),projectName:d.Yj().trim().min(1).optional(),sessionTitle:d.Yj().trim().min(1).nullable().optional(),status:e.jw.optional(),messageCounts:e.AA.optional(),lastMessageUpdatedAt:g.k.nullable().optional()}).strict().refine(a=>Object.keys(a).length>0,{message:"work session changes cannot be empty"}),m=d.Ik({workSessions:d.YO(e.MY),pinnedCount:e.MT,appRuntime:f.GR}).strict().refine(a=>a.pinnedCount<=a.workSessions.length,{message:"pinnedCount cannot exceed work session count",path:["pinnedCount"]}),n=d.gM("type",[d.Ik({type:d.eu("snapshot"),workSessions:d.YO(e.MY),pinnedCount:e.MT}).strict().refine(a=>a.pinnedCount<=a.workSessions.length,{message:"pinnedCount cannot exceed work session count",path:["pinnedCount"]}),d.Ik({type:d.eu("update"),workId:e.eW,changes:l}).strict(),d.Ik({type:d.eu("delete"),workId:e.eW}).strict()]),o=Object.freeze({list:(0,h.Vc)({path:"work-sessions/list",inputSchema:i,outputSchema:m}),acknowledgeCompleted:(0,h.Vc)({path:"work-sessions/ack-completed",inputSchema:j,outputSchema:k}),update:(0,h._G)({path:"work-sessions/update",bodySchema:n})})},23024:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{E:()=>g});var e=c(72498),f=a([e]);e=(f.then?(await f)():f)[0];class g{constructor(a,b){this.workId=a,this.runtime=b}static async create(a,b,c){let d=c?await e.vC.open(b,c):e.vC.create(b);return new g(a,d)}get cwd(){return this.runtime.cwd}get sessionId(){return this.runtime.sessionId}get branchId(){return this.runtime.branchId}async branch(a){let b=await this.runtime.branch(a);return{changed:b.changed,editorText:b.editorText}}async createBranchedSession(a,b){let c=this.runtime.createBranchedSession(b);return{workSession:new g(a,c.runtime),editorText:c.editorText}}async send(a){return this.runtime.send(a)}async interrupt(){await this.runtime.interrupt()}async restoreQueuedMessages(){return this.runtime.restoreQueuedMessages()}async setTitle(a){await this.runtime.setTitle(a)}async setModel(a){await this.runtime.setModel(a)}}d()}catch(a){d(a)}})},23054:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{HK:()=>F,JJ:()=>y,Jl:()=>I,Jv:()=>G,Ki:()=>C,VH:()=>D,XM:()=>B,if:()=>H,k1:()=>A,qm:()=>x});var e=c(71473),f=c(77598),g=c(73024),h=c(76760),i=c(59473),j=c(25084),k=c(40529),l=c(77394),m=c(54733),n=c(18477),o=c(33270),p=c(23024),q=c(52913),r=c(65129),s=c(65209),t=c(72498),u=c(46524),v=c(47574),w=a([e,p,r,s,t,v]);[e,p,r,s,t,v]=w.then?(await w)():w;let z=i.Ik({workSessions:m.TO,pinnedCount:m.MT}).strict().refine(a=>a.pinnedCount<=a.workSessions.length,{message:"pinnedCount cannot exceed persisted work session count",path:["pinnedCount"]});class A extends Error{constructor(){super("WorkSession order does not match the current collection"),this.name="WorkSessionOrderConflictError"}}class B extends Error{constructor(a){super(`WorkSession not found: ${a}`),this.name="WorkSessionNotFoundError"}}class C extends Error{constructor(a,b){super(`Pi session ${a} is already bound to work session ${b}`),this.name="WorkSessionSessionConflictError"}}class D extends Error{constructor(a,b){super(`Pi session ${b} was not found in ${a}`),this.name="WorkSessionHistoryNotFoundError"}}class E extends Error{constructor(a,b,c){super(`WorkSession project changed: ${a} (${b} -> ${c})`),this.name="WorkSessionProjectChangedError"}}class F extends Error{constructor(a,b,c){super(`WorkSession binding changed: ${a} (${b} -> ${c})`),this.name="WorkSessionBindingChangedError"}}class G extends Error{constructor(a){super(`WorkSession branch entry was not found: ${a}`),this.name="WorkSessionBranchEntryNotFoundError"}}class H extends Error{constructor(a){super(a),this.name="WorkSessionBranchBlockedError"}}class I extends Error{constructor(a,b){super(b),this.kind=a,this.name="WorkSessionBranchInvalidError"}}class J extends Error{constructor(a){super(`WorkSession project directory is invalid: ${a}`),this.name="WorkSessionDirectoryInvalidError"}}function x(a){return a instanceof Error&&"WorkSessionDirectoryInvalidError"===a.name}class K{constructor(a=(0,h.join)((0,e.M)(),"work-sessions.json")){this.storePath=a,this.workSessionsById=new Map,this.updateListeners=new Set,this.chat=new v.yO,this.hydrated=!1,this.operationTail=Promise.resolve();const b=this.readPersistedState();this.restoredRecords=b.workSessions,this.pinnedCount=b.pinnedCount,this.rewriteLegacyStore=b.rewriteLegacyStore,this.chat.subscribeRecordChanges((a,b,c)=>this.publishChatRecordChange(a,b,c))}initialize(){return this.runExclusive(()=>this.ensureHydrated())}listWorkSessions(){return this.runExclusive(async()=>(await this.ensureHydrated(),this.createSnapshot()))}runPluginRestart(a){return this.runExclusive(async()=>{await this.ensureHydrated();let b=await this.chat.pauseForProcessRestart();try{let b=await a();return console.info("[Pi Desk][WorkSessionManage] 全部工作会话已冻结,等待插件重载"),b}catch(a){throw b(),a}})}subscribeUpdates(a){return this.updateListeners.add(a),()=>this.updateListeners.delete(a)}subscribeMessageEvents(a){return this.chat.subscribe(a)}subscribePluginPushEvents(a){return this.chat.subscribePluginPush(a)}async prepareChatSourceSyncs(a){await this.initialize();let b=a.find(a=>!this.chat.isCurrentSource(a.source));if(b)throw new v.dM(b.source);return await Promise.all(a.map(a=>this.chat.prepareSource(a.source).catch(b=>{if(this.chat.isCurrentSource(a.source))throw b}))),a.filter(a=>this.chat.isCurrentSource(a.source)).map(a=>{let b=this.chat.createSync(a.source,a.cursor);return{source:a.source,event:b.event,watermark:b.watermark}})}async getChatMessageDetail(a){return await this.initialize(),this.chat.getMessageDetail(a)}async getChatModelContext(a){return await this.initialize(),this.chat.getModelContext(a)}async getChatImage(a){return await this.initialize(),this.chat.getImage(a)}async sendChat(a){return await this.initialize(),this.chat.send(a)}async interruptChat(a){await this.initialize(),await this.chat.interrupt(a)}async compactChat(a){await this.initialize(),await this.chat.compact(a)}async reloadChat(a,b){await this.initialize(),await this.chat.reload(a,b)}async setChatPresentation(a,b){await this.initialize(),await this.chat.setPresentation(a,b)}async restoreChatQueue(a){return await this.initialize(),this.chat.restoreQueuedMessages(a)}async setChatModel(a){await this.initialize(),await this.chat.setModel(a)}async setChatCapabilityMode(a){await this.initialize(),await this.chat.setCapabilityMode(a)}getNativeUi(a){if(!this.chat.isCurrentSource(a))throw new v.dM(a);return(0,t.ls)(a.sessionId).nativeUi}async invokeSessionPluginMethod(a){return await this.initialize(),this.chat.invokePluginMethod(a)}async listNativeCommands(a){return await this.initialize(),j.WF.parse({commands:await this.chat.listNativeCommands(a.source)})}async executeNativeCommand(a){await this.initialize(),await this.chat.executeNativeCommand(a.source,a.command,a.args??"")}async listNativeTools(a){return await this.initialize(),j.RH.parse({tools:await this.chat.listNativeTools(a.source)})}async executeDirectBash(a){return await this.initialize(),j.uU.parse(await this.chat.executeDirectBash(a.source,{command:a.command,excludeFromContext:a.excludeFromContext}))}async abortDirectBash(a){await this.initialize(),await this.chat.abortDirectBash(a.source)}async listModels(a){let b=m.eW.parse(a);await this.initialize();let c=this.workSessionsById.get(b);if(!c)throw new B(b);return k.IM.parse(await (0,t.ls)(c.sessionId).listModels())}async acknowledgeCompleted(a){let b=m.eW.parse(a);if(await this.initialize(),!this.workSessionsById.has(b))throw new B(b);return this.chat.acknowledgeCompleted(b)}setWorkSessionArrangement(a,b){let c=a.map(a=>m.eW.parse(a)),d=m.MT.parse(b);return this.runExclusive(async()=>{await this.ensureHydrated();let a=Array.from(this.workSessionsById.keys());if(c.length!==a.length||d>c.length||new Set(c).size!==c.length||c.some(a=>!this.workSessionsById.has(a)))throw new A;if(c.every((b,c)=>b===a[c])&&d===this.pinnedCount)return this.createSnapshot();let b=c.map(a=>this.workSessionsById.get(a));for(let a of(this.workSessionsById.clear(),b))this.workSessionsById.set(a.workId,a);this.pinnedCount=d,this.persist();let e=this.createSnapshot();return this.publishUpdate({type:"snapshot",...e}),console.info("[Pi Desk][WorkSessionManage] 已更新工作会话排列",{workIds:c,pinnedCount:d}),e})}getWorkSession(a){let b=m.eW.parse(a);return this.runExclusive(async()=>(await this.ensureHydrated(),this.workSessionsById.get(b)??null))}getProjectPreviewContext(a,b){return this.workSessionsById.get(a.workId)!==a?null:this.chat.getProjectPreviewContext(a,b)}async replaceProjectGitBranch(a){let b=l.Yh.parse(a),c=await this.authorizeProjectFiles(b.workId,b.cwd),d=await (0,q.Ak)(c,b.repositoryRoot,b.target);return console.info("[Pi Desk][WorkSessionManage] 已切换 Git 分支",{workId:b.workId,cwd:c,repositoryRoot:b.repositoryRoot,targetType:b.target.type,targetName:b.target.name}),l.hr.parse({repository:d})}async addProjectGitBranch(a){let b=l.XV.parse(a),c=await this.authorizeProjectFiles(b.workId,b.cwd),d=await (0,q.bV)(c,b.repositoryRoot,b.name,b.startPoint);return console.info("[Pi Desk][WorkSessionManage] 已新建并切换 Git 分支",{workId:b.workId,cwd:c,repositoryRoot:b.repositoryRoot,branchName:b.name,startPointType:b.startPoint?.type??null,startPointName:b.startPoint?.name??null}),l.hr.parse({repository:d})}createWorkSession(a,b){let c,d=m.ik.parse(a),e=void 0===b?void 0:m.Kx.parse(b);try{c=(0,r.G2)(d)}catch{throw new J(d)}return this.runExclusive(async()=>{if(await this.ensureHydrated(),e){let a=this.findBoundWorkId(e);if(a)throw new C(e,a);if(!await (0,s.vg)(c,e))throw new D(c,e)}let a=await p.E.create((0,f.randomUUID)(),c,e);this.chat.addWorkSession(a),this.insertUnpinnedWorkSession(a),this.persist();let b=this.toListItem(a),d=this.createSnapshot();return this.publishUpdate({type:"snapshot",...d}),console.info("[Pi Desk][WorkSessionManage] 已创建工作会话",{workId:a.workId,cwd:a.cwd,sessionId:a.sessionId,creationType:e?"history":"empty"}),b})}renameWorkSession(a){let b=m.qL.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b.workId);if(!a)throw new B(b.workId);this.assertSessionBinding(a,b.sessionId),await this.chat.setTitle(a,b.title)})}replaceWorkSession(a,b){let c=m.eW.parse(a),d=b?{cwd:m.ik.parse(b.cwd),sessionId:m.Kx.parse(b.sessionId)}:null;return this.runExclusive(async()=>{let a;await this.ensureHydrated();let b=this.workSessionsById.get(c);if(!b)throw new B(c);if(d&&b.cwd===d.cwd&&b.sessionId===d.sessionId)return this.createSnapshot();if(d){let a=this.findBoundWorkId(d.sessionId);if(a&&a!==c)throw new C(d.sessionId,a)}let e=this.toListItem(b);await this.chat.pauseWorkSession(c);try{a=await p.E.create(c,d?.cwd??b.cwd,d?.sessionId),await this.chat.replaceWorkSession(b,a)}catch(a){throw this.chat.resumeWorkSession(c),a}this.workSessionsById.set(c,a),this.persist();let f=this.toListItem(a),g=this.createSnapshot(),h=this.toChanges(e,f);return h&&this.publishUpdate({type:"update",workId:c,changes:h}),console.info("[Pi Desk][WorkSessionManage] 已替换 Pi 会话",{workId:c,replacementType:d?"history":"empty",previousCwd:b.cwd,previousSessionId:b.sessionId,cwd:a.cwd,sessionId:a.sessionId,branchId:a.branchId}),g})}getWorkSessionTree(a){let b=o.i0.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b.workId);if(!a)throw new B(b.workId);return this.assertSessionBinding(a,b.sessionId),o.u1.parse(await (0,t.ls)(a.sessionId).readSessionTree())})}getWorkSessionTreeEntry(a){let b=o.iW.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b.workId);if(!a)throw new B(b.workId);this.assertSessionBinding(a,b.sessionId);try{return o.Cn.parse(await (0,t.ls)(a.sessionId).readSessionTreeEntryDetail(b.entryId))}catch(a){if(a instanceof u.Ns)throw new G(b.entryId);throw a}})}branchWorkSession(a){let b=o.g$.parse(a);return this.runExclusive(async()=>{let a;await this.ensureHydrated();let c=this.workSessionsById.get(b.workId);if(!c)throw new B(b.workId);if(this.assertSessionBinding(c,b.sessionId),"tree"===b.action){let a,d=this.toListItem(c);await this.chat.pauseWorkSession(c.workId);try{(a=await c.branch(b.entryId)).changed?await this.chat.refreshWorkSession(c):this.chat.resumeWorkSession(c.workId)}catch(a){if(c.branchId!==d.branchId){await this.chat.refreshWorkSession(c);let a=this.toChanges(d,this.toListItem(c));a&&this.publishUpdate({type:"update",workId:c.workId,changes:a})}else this.chat.resumeWorkSession(c.workId);this.throwBranchError(a,b.entryId)}let e=this.toListItem(c),f=this.toChanges(d,e);f&&this.publishUpdate({type:"update",workId:c.workId,changes:f});let g=this.createSnapshot();return console.info("[Pi Desk][WorkSessionManage] 已切换当前 JSONL 分支",{workId:c.workId,cwd:c.cwd,sessionId:c.sessionId,entryId:b.entryId,branchId:c.branchId,changed:a.changed}),o.WJ.parse({...g,targetWorkId:c.workId,editorText:a.editorText})}"clone"===b.action&&await this.chat.pauseWorkSession(c.workId);try{a=await c.createBranchedSession((0,f.randomUUID)(),"fork"===b.action?{position:"before",entryId:b.entryId}:{position:"at"}),this.chat.addWorkSession(a.workSession)}catch(a){this.throwBranchError(a,"entryId"in b?b.entryId:null)}finally{"clone"===b.action&&this.chat.resumeWorkSession(c.workId)}let d=a.workSession;this.insertUnpinnedWorkSession(d),this.persist();let e=this.createSnapshot();return this.publishUpdate({type:"snapshot",...e}),console.info("[Pi Desk][WorkSessionManage] 已创建分支 WorkSession",{action:b.action,sourceWorkId:c.workId,sourceSessionId:c.sessionId,workId:d.workId,cwd:d.cwd,entryId:"entryId"in b?b.entryId:null,sessionId:d.sessionId,branchId:d.branchId}),o.WJ.parse({...e,targetWorkId:d.workId,editorText:a.editorText})})}removeWorkSession(a){let b=m.eW.parse(a);return this.runExclusive(async()=>{await this.ensureHydrated();let a=this.workSessionsById.get(b);if(!a)return!1;let c=Array.from(this.workSessionsById.keys()).indexOf(b);return await this.chat.pauseWorkSession(b),await this.chat.removeWorkSession(a),this.workSessionsById.delete(b),c<this.pinnedCount&&(this.pinnedCount-=1),this.persist(),this.publishUpdate({type:"delete",workId:b}),console.info("[Pi Desk][WorkSessionManage] 已删除工作会话",{workId:b,pinnedCount:this.pinnedCount}),!0})}async ensureHydrated(){if(this.hydrated)return;let a=performance.now();console.info("[Pi Desk][WorkSessionManage] 开始恢复工作会话",{workSessionCount:this.restoredRecords.length});let b=await Promise.all(this.restoredRecords.map(a=>p.E.create(a.workId,a.cwd,a.sessionId))),c=performance.now();await this.chat.initialize(b);let d=performance.now();for(let e of(console.info("[Pi Desk][WorkSessionManage] 工作会话恢复完成",{workSessionCount:b.length,durationMs:Math.round(d-a),sessionOpenMs:Math.round(c-a),messageProjectionMs:Math.round(d-c)}),b))this.workSessionsById.set(e.workId,e);this.hydrated=!0,this.rewriteLegacyStore&&(this.persist(),this.rewriteLegacyStore=!1,console.info("[Pi Desk][WorkSessionManage] 已升级工作会话持久化格式",{workSessionCount:b.length,pinnedCount:this.pinnedCount}))}async authorizeProjectFiles(a,b){await this.initialize();let c=this.workSessionsById.get(a);if(!c)throw new B(a);if(c.cwd!==b)throw new E(a,b,c.cwd);return c.cwd}findBoundWorkId(a){for(let b of this.workSessionsById.values())if(b.sessionId===a)return b.workId}insertUnpinnedWorkSession(a){let b=this.orderedWorkSessions();for(let c of(b.splice(this.pinnedCount,0,a),this.workSessionsById.clear(),b))this.workSessionsById.set(c.workId,c)}assertSessionBinding(a,b){if(a.sessionId!==b)throw new F(a.workId,b,a.sessionId)}throwBranchError(a,b){if(a instanceof u.Ns)throw new G(b??"");if(a instanceof u.dX)throw new I("fork-target","只有用户消息可以 Fork");if(a instanceof t.er)throw new I("clone-empty","当前会话还没有可克隆的消息");if(a instanceof t.Wo)throw new H(a.message);throw a}orderedWorkSessions(){return Array.from(this.workSessionsById.values())}createSnapshot(){return m.kg.parse({workSessions:this.orderedWorkSessions().map(a=>this.toListItem(a)),pinnedCount:this.pinnedCount})}toRecord(a){return m.ER.parse({workId:a.workId,cwd:a.cwd,sessionId:a.sessionId})}toListItem(a){let b=this.chat.metadataFor(a);return m.MY.parse({...this.toRecord(a),branchId:a.branchId,projectName:(0,h.basename)(a.cwd)||a.cwd,sessionTitle:b.sessionTitle,status:this.chat.statusFor(a),messageCounts:b.messageCounts,lastMessageUpdatedAt:b.lastMessageUpdatedAt})}toChanges(a,b){let c={};return a.cwd!==b.cwd&&(c.cwd=b.cwd),a.sessionId!==b.sessionId&&(c.sessionId=b.sessionId),a.branchId!==b.branchId&&(c.branchId=b.branchId),a.projectName!==b.projectName&&(c.projectName=b.projectName),a.sessionTitle!==b.sessionTitle&&(c.sessionTitle=b.sessionTitle),a.status!==b.status&&(c.status=b.status),(a.messageCounts.user!==b.messageCounts.user||a.messageCounts.total!==b.messageCounts.total)&&(c.messageCounts=b.messageCounts),a.lastMessageUpdatedAt!==b.lastMessageUpdatedAt&&(c.lastMessageUpdatedAt=b.lastMessageUpdatedAt),0===Object.keys(c).length?null:n.KE.parse(c)}publishChatRecordChange(a,b,c){if(!this.hydrated)return;let d=this.workSessionsById.get(a);if(!d)return;let e=this.toListItem(d),f=this.toChanges({...e,...b,status:c},e);f&&this.publishUpdate({type:"update",workId:a,changes:f})}publishUpdate(a){let b=n.ds.parse(a);for(let a of[...this.updateListeners])try{a(b)}catch(a){console.error("[Pi Desk][WorkSessionManage] 推送工作会话变化失败",{updateType:b.type,errorName:a instanceof Error?a.name:"UnknownError"})}}readPersistedState(){if(!(0,g.existsSync)(this.storePath))return{workSessions:[],pinnedCount:0,rewriteLegacyStore:!1};let a=JSON.parse((0,g.readFileSync)(this.storePath,"utf8")),b=Array.isArray(a),c=b?z.parse({workSessions:m.TO.parse(a),pinnedCount:0}):z.parse(a),d=new Set,e=new Set;for(let a of c.workSessions){if(d.has(a.workId))throw Error(`Duplicate persisted workId: ${a.workId}`);if(e.has(a.sessionId))throw Error(`Duplicate persisted sessionId binding: ${a.sessionId}`);d.add(a.workId),e.add(a.sessionId)}return{...c,rewriteLegacyStore:b}}persist(){let a=z.parse({workSessions:this.orderedWorkSessions().map(a=>this.toRecord(a)),pinnedCount:this.pinnedCount});(0,g.mkdirSync)((0,h.dirname)(this.storePath),{recursive:!0});let b=`${this.storePath}.${process.pid}.${(0,f.randomUUID)()}.tmp`;try{(0,g.writeFileSync)(b,`${JSON.stringify(a,null,2)}
|
|
2
2
|
`,"utf8"),(0,g.renameSync)(b,this.storePath)}finally{(0,g.existsSync)(b)&&(0,g.unlinkSync)(b)}}runExclusive(a){let b=this.operationTail.then(a,a);return this.operationTail=b.then(()=>void 0,()=>void 0),b}}function y(){return globalThis.__piDeskWorkSessionManage||(globalThis.__piDeskWorkSessionManage=new K),globalThis.__piDeskWorkSessionManage}d()}catch(a){d(a)}})},25084:(a,b,c)=>{c.d(b,{QV:()=>u,RH:()=>p,WF:()=>k,uU:()=>r});var d=c(59473),e=c(96089),f=c(2002),g=c(24187);let h=d.k5(["extension","prompt","skill"]),i=d.Ik({name:d.Yj().trim().min(1).max(128),description:d.Yj().max(500).nullable(),source:h}).strict(),j=d.Ik({source:e.R}).strict(),k=d.Ik({commands:d.YO(i)}).strict(),l=d.Ik({source:e.R,command:d.Yj().trim().min(1).max(128),args:d.Yj().max(32768).optional()}).strict(),m=d.Ik({}).strict(),n=d.Ik({name:d.Yj().trim().min(1).max(128),description:d.Yj(),parameters:g.Dz,active:d.zM(),exposure:d.k5(["direct","model-only","codemode","deferred","hidden"]),source:d.Yj().nullable(),blockedByMode:d.zM()}).strict(),o=d.Ik({source:e.R}).strict(),p=d.Ik({tools:d.YO(n)}).strict(),q=d.Ik({source:e.R,command:d.Yj().min(1).max(32768),excludeFromContext:d.zM()}).strict(),r=d.Ik({output:d.Yj(),exitCode:d.ai().int().nullable(),cancelled:d.zM(),truncated:d.zM(),fullOutputPath:d.Yj().nullable()}).strict(),s=d.Ik({source:e.R}).strict(),t=d.Ik({}).strict(),u=Object.freeze({commandsList:(0,f.Vc)({path:"pi/commands/list",inputSchema:j,outputSchema:k}),commandExecute:(0,f.Vc)({path:"pi/commands/execute",inputSchema:l,outputSchema:m,timeoutMs:3e5}),toolsList:(0,f.Vc)({path:"pi/tools/list",inputSchema:o,outputSchema:p}),bashExecute:(0,f.Vc)({path:"pi/bash/execute",inputSchema:q,outputSchema:r,timeoutMs:12e4}),bashAbort:(0,f.Vc)({path:"pi/bash/abort",inputSchema:s,outputSchema:t})})},33270:(a,b,c)=>{c.d(b,{Cn:()=>l,WJ:()=>n,g$:()=>m,i0:()=>i,iW:()=>k,u1:()=>j});var d=c(59473),e=c(2364),f=c(54733);let g=d.k5(["user","assistant","tool","bash","custom_message","compaction","branch_summary","custom","model_change","thinking_level_change","session_info","label"]),h=d.Ik({entryId:f.C3,parentEntryId:f.C3.nullable(),timestampMs:e.k,kind:g,preview:d.Yj(),label:d.Yj().trim().min(1).nullable()}).strict(),i=d.Ik({workId:f.eW,sessionId:f.Kx}).strict(),j=d.Ik({sessionId:f.Kx,leafEntryId:f.C3.nullable(),nodes:d.YO(h)}).strict().superRefine((a,b)=>{let c=new Set;for(let[d,e]of a.nodes.entries())c.has(e.entryId)&&b.addIssue({code:"custom",message:"work session tree entryId values must be unique",path:["nodes",d,"entryId"]}),c.add(e.entryId);null===a.leafEntryId||c.has(a.leafEntryId)||b.addIssue({code:"custom",message:"work session tree leafEntryId must reference a node",path:["leafEntryId"]})}),k=d.Ik({workId:f.eW,sessionId:f.Kx,entryId:f.C3}).strict(),l=d.Ik({entryId:f.C3,kind:g,content:d.Yj(),truncated:d.zM()}).strict();d.k5(["tree","fork","clone"]);let m=d.gM("action",[d.Ik({action:d.eu("tree"),workId:f.eW,sessionId:f.Kx,entryId:f.C3}).strict(),d.Ik({action:d.eu("fork"),workId:f.eW,sessionId:f.Kx,entryId:f.C3}).strict(),d.Ik({action:d.eu("clone"),workId:f.eW,sessionId:f.Kx}).strict()]),n=d.Ik({workSessions:d.YO(f.MY),pinnedCount:f.MT,targetWorkId:f.eW,editorText:d.Yj().nullable()}).strict().superRefine((a,b)=>{a.pinnedCount>a.workSessions.length&&b.addIssue({code:"custom",message:"pinnedCount cannot exceed work session count",path:["pinnedCount"]}),a.workSessions.some(b=>b.workId===a.targetWorkId)||b.addIssue({code:"custom",message:"targetWorkId must reference a returned work session",path:["targetWorkId"]})})},40529:(a,b,c)=>{c.d(b,{IM:()=>l,kJ:()=>k});var d=c(59473),e=c(54733),f=c(62977);let g=d.Yj().trim().min(1),h=d.Yj().trim().min(1),i=d.Ik({provider:g,modelId:h,name:d.Yj().trim().min(1),input:d.YO(d.k5(["text","image"])).min(1),kind:d.k5(["physical","virtual"]),contextWindow:d.ai().int().positive().max(Number.MAX_SAFE_INTEGER).nullable(),thinkingLevels:d.YO(f.$).min(1)}).strict(),j=d.Ik({provider:g,modelId:h,thinkingLevel:f.$,color:d.Yj().trim().min(1).nullable()}).strict(),k=d.Ik({workId:e.eW}).strict(),l=d.Ik({models:d.YO(i),presets:d.YO(j)}).strict()},58311:(a,b,c)=>{c.d(b,{$C:()=>A,A8:()=>E,GR:()=>q,MQ:()=>D,Pq:()=>B,UH:()=>j,Wh:()=>r,Xo:()=>o,YT:()=>z});var d=c(59473),e=c(41904),f=c(20369),g=c(24187),h=c(2364);let i=d.Yj().uuid(),j=d.Yj().trim().min(1).max(256),k=d.k5(["info","success","warning","error"]),l=d.Yj().trim().min(1).max(120),m=d.Yj().trim().max(320).nullable(),n=d.Ik({type:d.eu("plugin"),pluginName:g.tv,name:g.f7,data:g.Dz}).strict(),o=d.Ik({notificationId:i,level:k,title:l,description:m,createdAt:h.k,event:n.nullable()}).strict(),p=d.g1(g.tv,g.Dz),q=d.Ik({mode:d.k5(["normal","basic"]).default("normal"),notifications:d.YO(o),plugins:p,capabilityModes:f.Wu,settings:e.J.default({region:{locale:"en",timeZone:"UTC"}})}).strict(),r=d.Ik({level:k.optional(),title:l.optional(),description:m.optional(),event:n.nullable().optional()}).strict().refine(a=>Object.keys(a).length>0,{message:"notification changes cannot be empty"}),s=d.Ik({type:d.eu("add"),notification:o}).strict(),t=d.Ik({type:d.eu("update"),notificationId:i,changes:r}).strict(),u=d.Ik({type:d.eu("delete"),notificationId:i}).strict(),v=d.gM("type",[s,t,u]),w=d.Ik({pluginName:g.tv,state:g.Dz.nullable()}).strict(),x=d.Ik({key:d.eu("capabilityModes"),update:f.Wu}).strict(),y=d.Ik({key:d.eu("settings"),update:e.J}).strict();d.gM("key",[y,x,d.Ik({key:d.eu("notifications"),update:v}).strict(),d.Ik({key:d.eu("plugins"),update:w}).strict()]);let z=d.KC([y.extend({type:d.eu("update")}),x.extend({type:d.eu("update")}),d.Ik({type:d.eu("replace"),runtime:q}).strict(),d.Ik({type:d.eu("update"),key:d.eu("notifications"),update:v}).strict(),d.Ik({type:d.eu("update"),key:d.eu("plugins"),update:w}).strict()]),A=d.gM("key",[d.Ik({key:d.eu("notifications"),update:u}).strict(),d.Ik({key:d.eu("settings"),update:d.Ik({region:e.a.unwrap().partial().strict().refine(a=>Object.keys(a).length>0,"地区更新不能为空")}).strict()}).strict()]),B=d.Ik({}).strict(),C=d.Ik({name:g.f7,data:g.Dz}).strict(),D=d.Ik({key:j.optional(),level:k,title:l,description:d.Yj().trim().max(320).optional(),event:C.optional()}).strict(),E=d.Ik({level:k.optional(),title:l.optional(),description:m.optional()}).strict().refine(a=>Object.keys(a).length>0,{message:"plugin notification changes cannot be empty"})},65129:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{G2:()=>l,W1:()=>j,XO:()=>o,pm:()=>k});var e=c(51455),f=c(73024),g=c(76760),h=c(7499),i=a([h]);h=(i.then?(await i)():i)[0];class p extends Error{constructor(a){super(`Pi project directory is invalid: ${a}`),this.name="L4PiDirectoryInvalidError"}}class q extends Error{constructor(a){super(`Pi project directory cannot be read: ${a}`),this.name="L4PiDirectoryReadError"}}function j(a){return a instanceof Error&&"L4PiDirectoryInvalidError"===a.name}function k(a){return a instanceof Error&&"L4PiDirectoryReadError"===a.name}function l(a){let b=(0,g.resolve)(a);try{if(!(0,f.statSync)(b).isDirectory())throw new p(b)}catch(a){if(a instanceof p)throw a;throw new p(b)}return b}function m(){return new Set((0,h.Us)().map(h.sC))}async function n(a,b,c,d){if(c)return!0;if(!d)return!1;try{return(await (0,e.stat)((0,g.join)(a,b))).isDirectory()}catch{return!1}}async function o(a){let b;if(null===a){let a,b,c;return a=(0,g.parse)(process.cwd()).root,b="win32"===process.platform?function(){let a=[];for(let b=65;b<=90;b+=1){let c=`${String.fromCharCode(b)}:\\`;try{(0,f.statSync)(c).isDirectory()&&a.push({cwd:c,name:c})}catch{}}return a}():[{cwd:a,name:a}],c=m(),{cwd:null,parentCwd:null,directories:b.filter(a=>!c.has((0,h.sC)(a.cwd)))}}let c=l(a);try{b=await (0,e.readdir)(c,{withFileTypes:!0})}catch{throw new q(c)}let d=m(),i=(await Promise.all(b.map(async a=>{if(!await n(c,a.name,a.isDirectory(),a.isSymbolicLink()))return null;let b=(0,g.resolve)(c,a.name);return d.has((0,h.sC)(b))?null:{cwd:b,name:a.name}}))).filter(a=>null!==a).sort((a,b)=>a.name.localeCompare(b.name,void 0,{numeric:!0,sensitivity:"base"})),j=(0,g.parse)(c).root;return{cwd:c,parentCwd:(0,h.sC)(c)===(0,h.sC)(j)?null:(0,g.dirname)(c),directories:i}}d()}catch(a){d(a)}})},77394:(a,b,c)=>{c.d(b,{XV:()=>p,Yh:()=>o,hr:()=>q});var d=c(59473),e=c(66951),f=c(63719),g=c(54733);let h=e.y2,i=d.Ik({workId:g.eW,cwd:g.ik}).strict(),j=e.Ww,k=e.cP,l=e.zp,m=e.u2;d.Ik({repositories:d.YO(m).max(h)}).strict(),i.extend({repositoryRoot:j}).strict();let n=e.zt,o=i.extend({repositoryRoot:j,target:n}).strict(),p=i.extend({repositoryRoot:j,name:k,startPoint:n.nullable()}).strict(),q=d.Ik({repository:l}).strict();i.extend({repositoryRoot:j,path:f._g}).strict()}};
|