Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ if (ENV.VAPID.PUBLIC_KEY && ENV.VAPID.PRIVATE_KEY) {
})
}

sseAggregator.setPendingActionsFetcher(openCodeClient)
sseAggregator.start()

void scheduleRunnerInstance.start()

app.route('/api/auth', createAuthRoutes(auth))
Expand Down
9 changes: 9 additions & 0 deletions backend/src/services/opencode/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ENV } from '@opencode-manager/shared/config/env'

export function buildOpenCodeBasicAuthHeader(): string | null {
const password = ENV.OPENCODE.SERVER_PASSWORD
const username = ENV.OPENCODE.SERVER_USERNAME
if (!password) return null
const token = Buffer.from(`${username}:${password}`).toString('base64')
return `Basic ${token}`
}
9 changes: 3 additions & 6 deletions backend/src/services/opencode/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logger } from '../../utils/logger'
import { ENV } from '@opencode-manager/shared/config/env'
import { buildOpenCodeBasicAuthHeader } from './auth'

export interface ForwardRequest {
method: string
Expand Down Expand Up @@ -40,7 +41,7 @@ export interface OpenCodeClient {

export interface FetchOpenCodeClientConfig {
baseUrl: string
basicAuth: string
basicAuth: string | null
fetchFn?: typeof fetch
}

Expand Down Expand Up @@ -239,11 +240,7 @@ export class FetchOpenCodeClient implements OpenCodeClient {

export function createOpenCodeClient(): OpenCodeClient {
const baseUrl = `http://${ENV.OPENCODE.HOST}:${ENV.OPENCODE.PORT}`
const password = ENV.OPENCODE.SERVER_PASSWORD
const username = ENV.OPENCODE.SERVER_USERNAME
const basicAuth = password
? `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`
: ''
const basicAuth = buildOpenCodeBasicAuthHeader()

return new FetchOpenCodeClient({ baseUrl, basicAuth })
}
7 changes: 1 addition & 6 deletions backend/src/services/schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,9 @@ function getSessionStatusType(event: SSEEvent): string | null {
}

function createSessionMonitor(directory: string, sessionId: string): SessionMonitor {
const clientId = `schedule-monitor-${sessionId}-${Date.now()}`
let errorText: string | null = null
let idle = false

const removeClient = sseAggregator.addClient(clientId, () => {}, [directory])
const unsubscribe = sseAggregator.onEvent((eventDirectory, event) => {
if (eventDirectory !== directory) {
return
Expand Down Expand Up @@ -347,10 +345,7 @@ function createSessionMonitor(directory: string, sessionId: string): SessionMoni
return {
getErrorText: () => errorText,
isIdle: () => idle,
dispose: () => {
unsubscribe()
removeClient()
},
dispose: unsubscribe,
}
}

Expand Down
Loading
Loading