@@ -8,12 +8,11 @@ import {
88 runCliJsonCommand ,
99 type SessionEnvironment as RuntimeSessionEnvironment ,
1010} from "../runtime/base" ;
11- import { getOrCreateThreadSession } from "../runtime/thread -session" ;
11+ import { createCliThreadSessionManager } from "../runtime/cli -session" ;
1212import type {
1313 OpenCodeMessage ,
1414 OpenCodeMessageContext ,
1515 OpenCodeOptions ,
16- OpenCodeSessionInfo ,
1716} from "../types" ;
1817
1918export type SessionEnvironment = RuntimeSessionEnvironment ;
@@ -82,6 +81,15 @@ function isValidKiloSessionId(value: string): boolean {
8281 return value . startsWith ( "ses" ) ;
8382}
8483
84+ export const { createSession, getOrCreateSession } = createCliThreadSessionManager ( {
85+ providerId : "kilo" ,
86+ providerName : "Kilo" ,
87+ runtime,
88+ newSessions,
89+ sessionIdFactory : buildKiloSessionId ,
90+ validateSessionId : isValidKiloSessionId ,
91+ } ) ;
92+
8593function buildModelArg ( model ?: OpenCodeOptions [ "model" ] ) : string | undefined {
8694 if ( ! model ?. modelID ) return undefined ;
8795 const providerID = model . providerID ?. trim ( ) || "openai" ;
@@ -282,53 +290,6 @@ function extractKiloFinalResponse(output: string): string {
282290 return text || cleaned . trim ( ) ;
283291}
284292
285- export async function createSession ( workingPath : string , env ?: SessionEnvironment ) : Promise < string > {
286- const sessionId = buildKiloSessionId ( ) ;
287- runtime . setSessionEnvironment ( sessionId , env ?? { } ) ;
288- newSessions . add ( sessionId ) ;
289- log . info ( "Created Kilo session" , { sessionId, workingPath } ) ;
290- return sessionId ;
291- }
292-
293- export async function getOrCreateSession (
294- channelId : string ,
295- threadId : string ,
296- workingPath : string ,
297- env : SessionEnvironment = { }
298- ) : Promise < OpenCodeSessionInfo > {
299- return getOrCreateThreadSession ( {
300- channelId,
301- threadId,
302- providerId : "kilo" ,
303- workingPath,
304- env,
305- createSession,
306- getSessionEnvironment : ( sessionId ) => runtime . getSessionEnvironment ( sessionId ) ,
307- setSessionEnvironment : ( sessionId , nextEnv ) => {
308- runtime . setSessionEnvironment ( sessionId , nextEnv ) ;
309- } ,
310- validateSessionId : isValidKiloSessionId ,
311- onInvalidSessionId : ( existingSession ) => {
312- log . info ( "Invalid Kilo session id found; generating new session" , {
313- channelId,
314- threadId,
315- workingPath,
316- existingSession,
317- } ) ;
318- } ,
319- onEnvironmentChanged : ( ) => {
320- log . info ( "Kilo session environment changed; creating new session" , {
321- channelId,
322- threadId,
323- workingPath,
324- } ) ;
325- } ,
326- onCreatingSession : ( ) => {
327- log . info ( "Creating new Kilo session for thread" , { channelId, threadId, workingPath } ) ;
328- } ,
329- } ) ;
330- }
331-
332293export async function sendMessage (
333294 channelId : string ,
334295 sessionId : string ,
0 commit comments