@@ -28,6 +28,7 @@ import {
2828 createBoardGrantSnapshot ,
2929 createBoardWidgetPutSnapshot ,
3030 type BoardStore ,
31+ type BoardSnapshotWithHtmlDocuments ,
3132 type BoardWidgetHtmlDocument ,
3233 type BoardWidgetMcpAppDocument ,
3334} from "./board-store.js" ;
@@ -161,6 +162,27 @@ function readStoredBoard(database: BoardDatabaseHandle, sessionKey: string): Sto
161162 ) ;
162163}
163164
165+ function rowToHtmlDocument (
166+ row : Pick <
167+ SelectedBoardWidgetRow ,
168+ "content_kind" | "html" | "revision" | "sha256" | "view_generation" | "grant_state" | "manifest"
169+ > ,
170+ ) : BoardWidgetHtmlDocument | undefined {
171+ if ( row . content_kind !== "html" || row . html === null || row . view_generation === null ) {
172+ return undefined ;
173+ }
174+ const manifest = parseManifest ( row . manifest ) ;
175+ const declared = manifest . declared ;
176+ return {
177+ html : Buffer . from ( row . html ) . toString ( "utf8" ) ,
178+ revision : row . revision ,
179+ sha256 : row . sha256 ,
180+ viewGeneration : row . view_generation ,
181+ grantState : effectiveGrantState ( row . grant_state as BoardWidget [ "grantState" ] , manifest ) ,
182+ ...( declared ? { declared } : { } ) ,
183+ } ;
184+ }
185+
164186function upsertTabs (
165187 database : BoardDatabaseHandle ,
166188 previous : StoredBoard ,
@@ -375,6 +397,33 @@ export class SqliteBoardStore implements BoardStore {
375397 ) ;
376398 }
377399
400+ getSnapshotWithHtmlDocuments ( sessionKey : string ) : BoardSnapshotWithHtmlDocuments {
401+ const resolved = this . resolve ( sessionKey ) ;
402+ const result = withOpenClawAgentDatabaseReadOnly (
403+ ( database ) =>
404+ hasSession ( database , resolved . sessionKey ) && boardTablesPresent ( database )
405+ ? readStoredBoard ( database , resolved . sessionKey )
406+ : undefined ,
407+ {
408+ agentId : resolved . agentId ,
409+ ...( resolved . path ? { path : resolved . path } : { } ) ,
410+ env : this . options . env ,
411+ } ,
412+ ) ;
413+ const stored = result . found ? result . value : undefined ;
414+ const htmlDocuments = new Map < string , BoardWidgetHtmlDocument > ( ) ;
415+ for ( const row of stored ?. widgetRows ?? [ ] ) {
416+ const document = rowToHtmlDocument ( row ) ;
417+ if ( document ) {
418+ htmlDocuments . set ( row . name , document ) ;
419+ }
420+ }
421+ return {
422+ snapshot : cloneBoardSnapshot ( stored ?. snapshot ?? emptyBoardSnapshot ( resolved . sessionKey ) ) ,
423+ htmlDocuments,
424+ } ;
425+ }
426+
378427 applyOps ( sessionKey : string , ops : readonly BoardOp [ ] ) : BoardSnapshot {
379428 if ( ops . length === 0 ) {
380429 return this . getSnapshot ( sessionKey ) ;
@@ -587,19 +636,7 @@ export class SqliteBoardStore implements BoardStore {
587636 if ( ! row ) {
588637 return undefined ;
589638 }
590- if ( row . content_kind === "html" && row . html !== null && row . view_generation !== null ) {
591- const manifest = parseManifest ( row . manifest ) ;
592- const declared = manifest . declared ;
593- return {
594- html : Buffer . from ( row . html ) . toString ( "utf8" ) ,
595- revision : row . revision ,
596- sha256 : row . sha256 ,
597- viewGeneration : row . view_generation ,
598- grantState : effectiveGrantState ( row . grant_state as BoardWidget [ "grantState" ] , manifest ) ,
599- ...( declared ? { declared } : { } ) ,
600- } ;
601- }
602- return undefined ;
639+ return rowToHtmlDocument ( row ) ;
603640 } ,
604641 {
605642 agentId : resolved . agentId ,
0 commit comments