@@ -4,8 +4,6 @@ export { Sandbox }; // export the Sandbox class for the worker
44
55import { Agent , run , shellTool , applyPatchTool } from '@openai/agents' ;
66
7- import { logger } from './logger' ;
8-
97// Helper functions for error handling
108function isErrorWithProperties ( error : unknown ) : error is {
119 message ?: string ;
@@ -33,43 +31,49 @@ function getErrorStack(error: unknown): string | undefined {
3331}
3432
3533async function handleRunRequest ( request : Request , env : Env ) : Promise < Response > {
36- logger . debug ( 'handleRunRequest called' , {
34+ console . debug ( '[openai-example]' , 'handleRunRequest called' , {
3735 method : request . method ,
3836 url : request . url
3937 } ) ;
4038
4139 try {
4240 // Parse request body
43- logger . debug ( 'Parsing request body' ) ;
41+ console . debug ( '[openai-example]' , 'Parsing request body' ) ;
4442 const body = ( await request . json ( ) ) as { input ?: string } ;
4543 const input = body . input ;
4644
4745 if ( ! input || typeof input !== 'string' ) {
48- logger . warn ( 'Invalid or missing input field' , { input } ) ;
46+ console . warn ( '[openai-example]' , 'Invalid or missing input field' , {
47+ input
48+ } ) ;
4949 return new Response (
5050 JSON . stringify ( { error : 'Missing or invalid input field' } ) ,
5151 { status : 400 , headers : { 'Content-Type' : 'application/json' } }
5252 ) ;
5353 }
5454
55- logger . info ( 'Processing request' , { inputLength : input . length } ) ;
55+ console . info ( '[openai-example]' , 'Processing request' , {
56+ inputLength : input . length
57+ } ) ;
5658
5759 // Get sandbox instance (reused for both shell and editor)
58- logger . debug ( 'Getting sandbox instance' , {
60+ console . debug ( '[openai-example]' , 'Getting sandbox instance' , {
5961 sessionId : 'workspace-session'
6062 } ) ;
6163 const sandbox = getSandbox ( env . Sandbox , 'workspace-session' ) ;
6264
6365 // Create shell (automatically collects results)
64- logger . debug ( 'Creating SandboxShell' ) ;
66+ console . debug ( '[openai-example]' , 'Creating SandboxShell' ) ;
6567 const shell = new Shell ( sandbox ) ;
6668
6769 // Create workspace editor
68- logger . debug ( 'Creating WorkspaceEditor' , { root : '/workspace' } ) ;
70+ console . debug ( '[openai-example]' , 'Creating WorkspaceEditor' , {
71+ root : '/workspace'
72+ } ) ;
6973 const editor = new Editor ( sandbox , '/workspace' ) ;
7074
7175 // Create agent with both shell and patch tools, auto-approval for web API
72- logger . debug ( 'Creating Agent' , {
76+ console . debug ( '[openai-example]' , 'Creating Agent' , {
7377 name : 'Sandbox Studio' ,
7478 model : 'gpt-5.1'
7579 } ) ;
@@ -91,9 +95,9 @@ async function handleRunRequest(request: Request, env: Env): Promise<Response> {
9195 } ) ;
9296
9397 // Run the agent
94- logger . info ( 'Running agent' , { input } ) ;
98+ console . info ( '[openai-example]' , 'Running agent' , { input } ) ;
9599 const result = await run ( agent , input ) ;
96- logger . debug ( 'Agent run completed' , {
100+ console . debug ( '[openai-example]' , 'Agent run completed' , {
97101 hasOutput : ! ! result . finalOutput ,
98102 outputLength : result . finalOutput ?. length || 0
99103 } ) ;
@@ -104,7 +108,7 @@ async function handleRunRequest(request: Request, env: Env): Promise<Response> {
104108 ...editor . results . map ( ( r ) => ( { type : 'file' as const , ...r } ) )
105109 ] . sort ( ( a , b ) => a . timestamp - b . timestamp ) ;
106110
107- logger . debug ( 'Results collected' , {
111+ console . debug ( '[openai-example]' , 'Results collected' , {
108112 commandResults : shell . results . length ,
109113 fileOperations : editor . results . length ,
110114 totalResults : allResults . length
@@ -117,7 +121,7 @@ async function handleRunRequest(request: Request, env: Env): Promise<Response> {
117121 fileOperations : editor . results . sort ( ( a , b ) => a . timestamp - b . timestamp )
118122 } ;
119123
120- logger . info ( 'Request completed successfully' ) ;
124+ console . info ( '[openai-example]' , 'Request completed successfully' ) ;
121125 return new Response ( JSON . stringify ( response ) , {
122126 headers : {
123127 'Content-Type' : 'application/json'
@@ -126,7 +130,7 @@ async function handleRunRequest(request: Request, env: Env): Promise<Response> {
126130 } catch ( error : unknown ) {
127131 const errorMessage = getErrorMessage ( error ) ;
128132 const errorStack = getErrorStack ( error ) ;
129- logger . error ( 'Error handling run request' , {
133+ console . error ( '[openai-example]' , 'Error handling run request' , {
130134 error : errorMessage ,
131135 stack : errorStack
132136 } ) ;
@@ -154,7 +158,7 @@ export default {
154158 _ctx : ExecutionContext
155159 ) : Promise < Response > {
156160 const url = new URL ( request . url ) ;
157- logger . debug ( 'Fetch handler called' , {
161+ console . debug ( '[openai-example]' , 'Fetch handler called' , {
158162 pathname : url . pathname ,
159163 method : request . method
160164 } ) ;
@@ -163,7 +167,7 @@ export default {
163167 return handleRunRequest ( request , env ) ;
164168 }
165169
166- logger . warn ( 'Route not found' , {
170+ console . warn ( '[openai-example]' , 'Route not found' , {
167171 pathname : url . pathname ,
168172 method : request . method
169173 } ) ;
0 commit comments