@@ -22,62 +22,11 @@ const DEFAULT_PERMISSION_CONFIG: NonNullable<OpencodeConfig["permission"]> = {
2222 webfetch : "allow" ,
2323} ;
2424
25- // Custom fetch with focused error logging and extended timeout
25+ // Custom fetch with 25-minute timeout
2626const customFetch = async ( request : Request ) : Promise < Response > => {
27- const startTime = Date . now ( ) ;
28-
29- try {
30- // Create AbortController with 25-minute timeout
31- const controller = new AbortController ( ) ;
32- const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 1_500_000 ) ;
33-
34- try {
35- const response = await fetch ( request , { signal : controller . signal } ) ;
36- clearTimeout ( timeoutId ) ;
37- const duration = Date . now ( ) - startTime ;
38-
39- // Only log non-OK responses or slow requests
40- if ( ! response . ok || duration > 60000 ) {
41- console . error (
42- `[opencode] Request to ${ request . url } - Status: ${ response . status } , Duration: ${ duration } ms` ,
43- ) ;
44-
45- if ( ! response . ok ) {
46- try {
47- const clonedResponse = response . clone ( ) ;
48- const responseText = await clonedResponse . text ( ) ;
49- console . error ( `[opencode] Full error response body:` , responseText ) ;
50- } catch ( e ) {
51- console . error ( `[opencode] Could not read error response body` ) ;
52- }
53- }
54- }
55-
56- return response ;
57- } catch ( fetchError ) {
58- clearTimeout ( timeoutId ) ;
59- throw fetchError ;
60- }
61- } catch ( error ) {
62- const duration = Date . now ( ) - startTime ;
63- console . error (
64- `[opencode] FETCH FAILED - URL: ${ request . url } , Duration: ${ duration } ms` ,
65- ) ;
66-
67- if ( error instanceof Error && error . name === "AbortError" ) {
68- console . error ( `[opencode] Error: Request timed out after 25 minutes` ) ;
69- } else {
70- console . error (
71- `[opencode] Error: ${ error instanceof Error ? error . message : String ( error ) } ` ,
72- ) ;
73- }
74-
75- if ( error instanceof Error && error . stack ) {
76- console . error ( `[opencode] Stack:` , error . stack ) ;
77- }
78-
79- throw error ;
80- }
27+ return fetch ( request , {
28+ signal : AbortSignal . timeout ( 1_500_000 ) ,
29+ } ) ;
8130} ;
8231
8332const opencodePort = await detectPort ( 4096 ) ;
@@ -88,14 +37,18 @@ const opencodeConfig = {
8837 provider : {
8938 opencode : {
9039 options : {
91- timeout : false as const , // Disable timeout for OpenCode provider requests
40+ timeout : false as false , // Disable timeout for OpenCode provider requests
9241 } ,
9342 } ,
9443 } ,
95- } ;
44+ } satisfies OpencodeConfig ;
45+
46+ // CRITICAL: Set via environment variable BEFORE importing/creating anything
47+ // The SDK reads this when spawning the server process
48+ const configJson = JSON . stringify ( opencodeConfig ) ;
49+ process . env . OPENCODE_CONFIG_CONTENT = configJson ;
9650
97- // Set via environment variable to ensure it's picked up by the server
98- process . env . OPENCODE_CONFIG_CONTENT = JSON . stringify ( opencodeConfig ) ;
51+ console . error ( `[opencode] Setting config: ${ configJson } ` ) ;
9952
10053const opencode = await createOpencode ( {
10154 port : opencodePort ,
0 commit comments