@@ -2,6 +2,24 @@ import { useEffect, useCallback, useRef, useState } from "react"
22import { createOpencodeClient , type Event } from "@opencode-ai/sdk/v2"
33import type { Action } from "@/cli/ink/state/reducer"
44import type { Dispatch } from "react"
5+ import { Server } from "@/server/server"
6+ import { Flag } from "@/flag/flag"
7+
8+ function getAuthorizationHeader ( ) : string | undefined {
9+ const password = Flag . OPENCODE_SERVER_PASSWORD
10+ if ( ! password ) return undefined
11+ const username = Flag . OPENCODE_SERVER_USERNAME ?? "opencode"
12+ return `Basic ${ btoa ( `${ username } :${ password } ` ) } `
13+ }
14+
15+ function createInProcessFetch ( ) {
16+ return ( async ( input : RequestInfo | URL , init ?: RequestInit ) => {
17+ const request = new Request ( input , init )
18+ const auth = getAuthorizationHeader ( )
19+ if ( auth ) request . headers . set ( "Authorization" , auth )
20+ return Server . App ( ) . fetch ( request )
21+ } ) as typeof globalThis . fetch
22+ }
523
624export function useSDKEvents ( sessionId : string | null , dispatch : Dispatch < Action > ) {
725 const sdkRef = useRef < ReturnType < typeof createOpencodeClient > | null > ( null )
@@ -12,7 +30,8 @@ export function useSDKEvents(sessionId: string | null, dispatch: Dispatch<Action
1230
1331 const abortController = new AbortController ( )
1432 const sdk = createOpencodeClient ( {
15- baseUrl : process . env . OPENCODE_API_URL || "http://localhost:4096" ,
33+ baseUrl : "http://opencode.internal" ,
34+ fetch : createInProcessFetch ( ) ,
1635 signal : abortController . signal ,
1736 } )
1837
0 commit comments