11import { randomUUID } from "node:crypto" ;
2- import type { DatabaseSync } from "node:sqlite" ;
32import {
43 executeSqliteQuerySync ,
54 executeSqliteQueryTakeFirstSync ,
@@ -12,7 +11,6 @@ import {
1211 type OpenClawAgentDatabase ,
1312 type OpenClawAgentDatabaseOptions ,
1413} from "../../state/openclaw-agent-db.js" ;
15- import { ensureOpenClawAgentSessionSharingSchemaInTransaction } from "../../state/openclaw-agent-session-sharing-schema.js" ;
1614import { SessionWorkStartInvalidatedError } from "./lifecycle.js" ;
1715import type { SessionAccessScope } from "./session-accessor.sqlite-contract.js" ;
1816import { resolveSqliteScope , toDatabaseOptions } from "./session-accessor.sqlite-scope.js" ;
@@ -31,7 +29,6 @@ export type StoredSessionSuggestion = {
3129 state : StoredSessionSuggestionState ;
3230} ;
3331
34- const ensuredDatabases = new WeakSet < DatabaseSync > ( ) ;
3532const MAX_PENDING_SESSION_SUGGESTIONS_PER_AUTHOR = 20 ;
3633const MAX_PENDING_SESSION_SUGGESTIONS_PER_SESSION = 100 ;
3734const MAX_RETAINED_RESOLVED_SESSION_SUGGESTIONS = 200 ;
@@ -41,18 +38,6 @@ function resolveDatabaseOptions(scope: SessionAccessScope): OpenClawAgentDatabas
4138 return toDatabaseOptions ( resolveSqliteScope ( scope ) ) ;
4239}
4340
44- function ensureSuggestionSchema ( options : OpenClawAgentDatabaseOptions ) : OpenClawAgentDatabase {
45- const database = openOpenClawAgentDatabase ( options ) ;
46- if ( ensuredDatabases . has ( database . db ) ) {
47- return database ;
48- }
49- runOpenClawAgentWriteTransaction ( ( transactionDatabase ) => {
50- ensureOpenClawAgentSessionSharingSchemaInTransaction ( transactionDatabase . db ) ;
51- } , options ) ;
52- ensuredDatabases . add ( database . db ) ;
53- return database ;
54- }
55-
5641function suggestionDb ( database : OpenClawAgentDatabase ) {
5742 return getNodeSqliteKysely < SuggestionDatabase > ( database . db ) ;
5843}
@@ -154,7 +139,6 @@ export function addSessionSuggestion(
154139 throw new Error ( "suggestion author and text are required" ) ;
155140 }
156141 const options = resolveDatabaseOptions ( scope ) ;
157- ensureSuggestionSchema ( options ) ;
158142 const sessionKey = resolveSqliteScope ( scope ) . sessionKey ;
159143 const suggestion : StoredSessionSuggestion = {
160144 id : params . id ?? randomUUID ( ) ,
@@ -209,7 +193,7 @@ export function listSessionSuggestions(
209193 params : { authorId ?: string ; pendingOnly ?: boolean } = { } ,
210194) : StoredSessionSuggestion [ ] {
211195 const options = resolveDatabaseOptions ( scope ) ;
212- const database = ensureSuggestionSchema ( options ) ;
196+ const database = openOpenClawAgentDatabase ( options ) ;
213197 const sessionKey = resolveSqliteScope ( scope ) . sessionKey ;
214198 let query = suggestionDb ( database )
215199 . selectFrom ( "session_suggestions" )
@@ -243,7 +227,6 @@ export function claimSessionSuggestionDispatch(
243227 } ,
244228) : SessionSuggestionDispatchClaim | null {
245229 const options = resolveDatabaseOptions ( scope ) ;
246- ensureSuggestionSchema ( options ) ;
247230 const sessionKey = resolveSqliteScope ( scope ) . sessionKey ;
248231 return runOpenClawAgentWriteTransaction ( ( database ) => {
249232 assertSessionInstance ( database , sessionKey , params . expectedSessionId ) ;
@@ -308,7 +291,6 @@ export function releaseSessionSuggestionDispatch(
308291 params : { id : string ; token : string ; expectedSessionId ?: string } ,
309292) : boolean {
310293 const options = resolveDatabaseOptions ( scope ) ;
311- ensureSuggestionSchema ( options ) ;
312294 const sessionKey = resolveSqliteScope ( scope ) . sessionKey ;
313295 return runOpenClawAgentWriteTransaction ( ( database ) => {
314296 assertSessionInstance ( database , sessionKey , params . expectedSessionId ) ;
@@ -336,7 +318,6 @@ export function finalizeSessionSuggestionClaim(
336318 } ,
337319) : StoredSessionSuggestion | null {
338320 const options = resolveDatabaseOptions ( scope ) ;
339- ensureSuggestionSchema ( options ) ;
340321 const sessionKey = resolveSqliteScope ( scope ) . sessionKey ;
341322 return runOpenClawAgentWriteTransaction ( ( database ) => {
342323 assertSessionInstance ( database , sessionKey , params . expectedSessionId ) ;
0 commit comments