33from pathlib import Path
44
55from pydantic import BaseModel , Field
6+ from typing import TYPE_CHECKING
67
7- from .context import ToolContext
8+ if TYPE_CHECKING :
9+ from .context import ToolContext
810from .registry import ToolRegistry
911
1012
@@ -92,7 +94,7 @@ def register_filesystem_tools(
9294) -> ToolRegistry :
9395 """Register sandboxed filesystem tools."""
9496
95- def _get_files (ctx : ToolContext | None ) -> FileSandbox :
97+ def _get_files (ctx : " ToolContext" | None ) -> FileSandbox :
9698 if ctx is not None :
9799 return ctx .files
98100 if sandbox is not None :
@@ -105,7 +107,7 @@ def _get_files(ctx: ToolContext | None) -> FileSandbox:
105107 output_model = ReadFileOutput ,
106108 description = "Read a file from the sandbox." ,
107109 )
108- async def read_file (ctx : ToolContext | None , params : ReadFileInput ) -> ReadFileOutput :
110+ async def read_file (ctx : " ToolContext" | None , params : ReadFileInput ) -> ReadFileOutput :
109111 files = _get_files (ctx )
110112 return ReadFileOutput (content = files .read_text (params .path ))
111113
@@ -115,7 +117,7 @@ async def read_file(ctx: ToolContext | None, params: ReadFileInput) -> ReadFileO
115117 output_model = WriteFileOutput ,
116118 description = "Write a file to the sandbox." ,
117119 )
118- async def write_file (ctx : ToolContext | None , params : WriteFileInput ) -> WriteFileOutput :
120+ async def write_file (ctx : " ToolContext" | None , params : WriteFileInput ) -> WriteFileOutput :
119121 files = _get_files (ctx )
120122 written = files .write_text (params .path , params .content , overwrite = params .overwrite )
121123 return WriteFileOutput (path = params .path , bytes_written = written )
@@ -126,7 +128,7 @@ async def write_file(ctx: ToolContext | None, params: WriteFileInput) -> WriteFi
126128 output_model = AppendFileOutput ,
127129 description = "Append text to a file in the sandbox." ,
128130 )
129- async def append_file (ctx : ToolContext | None , params : AppendFileInput ) -> AppendFileOutput :
131+ async def append_file (ctx : " ToolContext" | None , params : AppendFileInput ) -> AppendFileOutput :
130132 files = _get_files (ctx )
131133 written = files .append_text (params .path , params .content )
132134 return AppendFileOutput (path = params .path , bytes_written = written )
@@ -137,7 +139,7 @@ async def append_file(ctx: ToolContext | None, params: AppendFileInput) -> Appen
137139 output_model = ReplaceFileOutput ,
138140 description = "Replace text in a file in the sandbox." ,
139141 )
140- async def replace_file (ctx : ToolContext | None , params : ReplaceFileInput ) -> ReplaceFileOutput :
142+ async def replace_file (ctx : " ToolContext" | None , params : ReplaceFileInput ) -> ReplaceFileOutput :
141143 files = _get_files (ctx )
142144 replaced = files .replace_text (params .path , params .old , params .new )
143145 return ReplaceFileOutput (path = params .path , replaced = replaced )
0 commit comments