trading_agent.gateway.routes.attachment_routes
¶
Routes for the files the user sends with chat messages.
POST /api/desks/{desk}/attachments upload one file (a form with a "file" field); answers its attachment GET /api/desks/{desk}/attachments/{id} the uploaded file itself, for showing a picture or opening a document GET /api/desks/{desk}/pictures/{path} a picture in the desk's folder, such as a screenshot shown in a tool's card
Sending a message with files takes two steps: each file is uploaded here first, and the message then names the uploads by their identifiers in POST /api/desks/{desk}/messages. Each upload can then fail or succeed on its own, with its own explanation, before anything reaches the desk.
Typical usage example:
application.include_router(AttachmentRoutes(desks, store, layout, guard).router())
AttachmentRoutes
¶
Bases: RouteGroup
The /api/desks/{desk}/attachments routes.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desks
|
Mapping[str, DeskRuntime]
|
The running desks, keyed by name. |
required |
store
|
AttachmentStore
|
Where uploads are kept. |
required |
layout
|
WorkspaceLayout
|
Where the desk folders are. |
required |
guard
|
AccessGuard
|
Checks the access token. |
required |
Source code in src/trading_agent/gateway/routes/attachment_routes.py
upload
async
¶
Stores one uploaded file for a desk, reading a document's text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
file
|
UploadFile
|
The uploaded file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The stored attachment. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
There is no such desk (404), or the file is refused (413 when too large, otherwise 422), with the reason. |
Source code in src/trading_agent/gateway/routes/attachment_routes.py
download
¶
Answers an uploaded file, shown in the browser rather than saved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
attachment_id
|
str
|
The upload's identifier. |
required |
Returns:
| Type | Description |
|---|---|
FileResponse
|
The file, with its media type and name. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
There is no such desk or upload, or its file is gone (404). |
Source code in src/trading_agent/gateway/routes/attachment_routes.py
picture
¶
Answers a picture inside a desk's folder, such as a browser screenshot.
Only real PNG, JPEG, WebP and GIF pictures are answered, judged by their contents, and only from inside the desk's own folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
picture_path
|
str
|
The picture's path relative to the desk folder. |
required |
Returns:
| Type | Description |
|---|---|
FileResponse
|
The picture, with its media type. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
There is no such desk (404), the path leads outside the desk folder or is not a picture (404), or the file is gone (404). |