Load an attachment by ID or register a workspace file as a new attachment.
(
path_or_id: str,
*,
# mime_override: Optional[str] = None,
_context: Dict[str, Any] | None = None,
)
| 315 | |
| 316 | |
| 317 | def load_file( |
| 318 | path_or_id: str, |
| 319 | *, |
| 320 | # mime_override: Optional[str] = None, |
| 321 | _context: Dict[str, Any] | None = None, |
| 322 | ) -> List[MessageBlock]: |
| 323 | """ |
| 324 | Load an attachment by ID or register a workspace file as a new attachment. |
| 325 | """ |
| 326 | |
| 327 | ctx = FileToolContext(_context) |
| 328 | |
| 329 | # First, try existing attachment id |
| 330 | record = ctx.attachment_store.get(path_or_id) |
| 331 | if record: |
| 332 | return [record.as_message_block()] |
| 333 | |
| 334 | # Otherwise treat as workspace path |
| 335 | target = ctx.resolve_under_workspace(path_or_id) |
| 336 | if not target.exists() or not target.is_file(): |
| 337 | raise ValueError(f"Workspace file not found: {path_or_id}") |
| 338 | |
| 339 | # mime_type = mime_override or (mimetypes.guess_type(target.name)[0] or "application/octet-stream") |
| 340 | mime_type = mimetypes.guess_type(target.name)[0] or "application/octet-stream" |
| 341 | record = ctx.attachment_store.register_file( |
| 342 | target, |
| 343 | kind=MessageBlockType.from_mime_type(mime_type), |
| 344 | display_name=target.name, |
| 345 | mime_type=mime_type, |
| 346 | copy_file=False, |
| 347 | persist=False, |
| 348 | deduplicate=True, |
| 349 | extra={ |
| 350 | "source": "workspace", |
| 351 | "workspace_path": path_or_id, |
| 352 | "storage": "reference", |
| 353 | }, |
| 354 | ) |
| 355 | return [record.as_message_block()] |
| 356 | |
| 357 | |
| 358 | def save_file( |
nothing calls this directly
no test coverage detected