@@ -15,14 +15,12 @@ import { Database, NotFoundError, eq, and, or, gte, isNull, desc, like, inArray,
1515import type { SQL } from "../storage/db"
1616import { SessionTable , MessageTable , PartTable } from "./session.sql"
1717import { ProjectTable } from "../project/project.sql"
18- import { Storage } from "@/storage/storage"
1918import { Log } from "../util/log"
2019import { MessageV2 } from "./message-v2"
2120import { Instance } from "../project/instance"
2221import { SessionPrompt } from "./prompt"
2322import { fn } from "@/util/fn"
2423import { Command } from "../command"
25- import { Snapshot } from "@/snapshot"
2624
2725import type { Provider } from "@/provider/provider"
2826import { PermissionNext } from "@/permission/next"
@@ -49,17 +47,7 @@ export namespace Session {
4947 type SessionRow = typeof SessionTable . $inferSelect
5048
5149 export function fromRow ( row : SessionRow ) : Info {
52- const summary =
53- row . summary_additions !== null || row . summary_deletions !== null || row . summary_files !== null
54- ? {
55- additions : row . summary_additions ?? 0 ,
56- deletions : row . summary_deletions ?? 0 ,
57- files : row . summary_files ?? 0 ,
58- diffs : row . summary_diffs ?? undefined ,
59- }
60- : undefined
6150 const share = row . share_url ? { url : row . share_url } : undefined
62- const revert = row . revert ?? undefined
6351 return {
6452 id : row . id ,
6553 slug : row . slug ,
@@ -69,9 +57,7 @@ export namespace Session {
6957 parentID : row . parent_id ?? undefined ,
7058 title : row . title ,
7159 version : row . version ,
72- summary,
7360 share,
74- revert,
7561 permission : row . permission ?? undefined ,
7662 time : {
7763 created : row . time_created ,
@@ -93,11 +79,6 @@ export namespace Session {
9379 title : info . title ,
9480 version : info . version ,
9581 share_url : info . share ?. url ,
96- summary_additions : info . summary ?. additions ,
97- summary_deletions : info . summary ?. deletions ,
98- summary_files : info . summary ?. files ,
99- summary_diffs : info . summary ?. diffs ,
100- revert : info . revert ?? null ,
10182 permission : info . permission ,
10283 time_created : info . time . created ,
10384 time_updated : info . time . updated ,
@@ -124,14 +105,6 @@ export namespace Session {
124105 workspaceID : z . string ( ) . optional ( ) ,
125106 directory : z . string ( ) ,
126107 parentID : Identifier . schema ( "session" ) . optional ( ) ,
127- summary : z
128- . object ( {
129- additions : z . number ( ) ,
130- deletions : z . number ( ) ,
131- files : z . number ( ) ,
132- diffs : Snapshot . FileDiff . array ( ) . optional ( ) ,
133- } )
134- . optional ( ) ,
135108 share : z
136109 . object ( {
137110 url : z . string ( ) ,
@@ -146,14 +119,6 @@ export namespace Session {
146119 archived : z . number ( ) . optional ( ) ,
147120 } ) ,
148121 permission : PermissionNext . Ruleset . optional ( ) ,
149- revert : z
150- . object ( {
151- messageID : z . string ( ) ,
152- partID : z . string ( ) . optional ( ) ,
153- snapshot : z . string ( ) . optional ( ) ,
154- diff : z . string ( ) . optional ( ) ,
155- } )
156- . optional ( ) ,
157122 } )
158123 . meta ( {
159124 ref : "Session" ,
@@ -210,13 +175,6 @@ export namespace Session {
210175 info : Info ,
211176 } ) ,
212177 ) ,
213- Diff : BusEvent . define (
214- "session.diff" ,
215- z . object ( {
216- sessionID : z . string ( ) ,
217- diff : Snapshot . FileDiff . array ( ) ,
218- } ) ,
219- ) ,
220178 Error : BusEvent . define (
221179 "session.error" ,
222180 z . object ( {
@@ -471,86 +429,6 @@ export namespace Session {
471429 } ,
472430 )
473431
474- export const setRevert = fn (
475- z . object ( {
476- sessionID : Identifier . schema ( "session" ) ,
477- revert : Info . shape . revert ,
478- summary : Info . shape . summary ,
479- } ) ,
480- async ( input ) => {
481- return Database . use ( ( db ) => {
482- const row = db
483- . update ( SessionTable )
484- . set ( {
485- revert : input . revert ?? null ,
486- summary_additions : input . summary ?. additions ,
487- summary_deletions : input . summary ?. deletions ,
488- summary_files : input . summary ?. files ,
489- time_updated : Date . now ( ) ,
490- } )
491- . where ( eq ( SessionTable . id , input . sessionID ) )
492- . returning ( )
493- . get ( )
494- if ( ! row ) throw new NotFoundError ( { message : `Session not found: ${ input . sessionID } ` } )
495- const info = fromRow ( row )
496- Database . effect ( ( ) => Bus . publish ( Event . Updated , { info } ) )
497- return info
498- } )
499- } ,
500- )
501-
502- export const clearRevert = fn ( Identifier . schema ( "session" ) , async ( sessionID ) => {
503- return Database . use ( ( db ) => {
504- const row = db
505- . update ( SessionTable )
506- . set ( {
507- revert : null ,
508- time_updated : Date . now ( ) ,
509- } )
510- . where ( eq ( SessionTable . id , sessionID ) )
511- . returning ( )
512- . get ( )
513- if ( ! row ) throw new NotFoundError ( { message : `Session not found: ${ sessionID } ` } )
514- const info = fromRow ( row )
515- Database . effect ( ( ) => Bus . publish ( Event . Updated , { info } ) )
516- return info
517- } )
518- } )
519-
520- export const setSummary = fn (
521- z . object ( {
522- sessionID : Identifier . schema ( "session" ) ,
523- summary : Info . shape . summary ,
524- } ) ,
525- async ( input ) => {
526- return Database . use ( ( db ) => {
527- const row = db
528- . update ( SessionTable )
529- . set ( {
530- summary_additions : input . summary ?. additions ,
531- summary_deletions : input . summary ?. deletions ,
532- summary_files : input . summary ?. files ,
533- time_updated : Date . now ( ) ,
534- } )
535- . where ( eq ( SessionTable . id , input . sessionID ) )
536- . returning ( )
537- . get ( )
538- if ( ! row ) throw new NotFoundError ( { message : `Session not found: ${ input . sessionID } ` } )
539- const info = fromRow ( row )
540- Database . effect ( ( ) => Bus . publish ( Event . Updated , { info } ) )
541- return info
542- } )
543- } ,
544- )
545-
546- export const diff = fn ( Identifier . schema ( "session" ) , async ( sessionID ) => {
547- try {
548- return await Storage . read < Snapshot . FileDiff [ ] > ( [ "session_diff" , sessionID ] )
549- } catch {
550- return [ ]
551- }
552- } )
553-
554432 export const messages = fn (
555433 z . object ( {
556434 sessionID : Identifier . schema ( "session" ) ,
0 commit comments