-
Notifications
You must be signed in to change notification settings - Fork 433
feat(api): add configurable --max-request-size flag to serve api #3938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,6 +192,7 @@ docker agent serve api <agent-file>|<agents-dir> [flags] | |
| | ------------------ | ---------------- | ------------------------------------------------ | | ||
| | `-l, --listen` | `127.0.0.1:8080` | Address to listen on | | ||
| | `--auth-token` | (none) | Bearer token required for all API requests. Leave empty to disable authentication (safe when listening on loopback interfaces only). Recommended when `--listen` binds to a network-reachable interface. | | ||
| | `--max-request-size <bytes>` | `1048576` (1 MiB) | Maximum request body size in bytes. Requests whose body exceeds this limit are rejected with HTTP 413 (Request Entity Too Large). | | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [major] The canonical CLI reference is missing this flag.
This PR updates only this file, so the CLI reference now under-documents |
||
| | `-s, --session-db` | `session.db` | Path to the SQLite session database | | ||
| | `--pull-interval` | `0` (disabled) | Auto-pull OCI reference every N minutes | | ||
| | `--fake` | (none) | Replay AI responses from cassette file (testing) | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,19 +43,42 @@ type Server struct { | |
| heartbeatInterval time.Duration | ||
| } | ||
|
|
||
| func New(ctx context.Context, sessionStore session.Store, runConfig *config.RuntimeConfig, refreshInterval time.Duration, agentSources config.Sources, authToken string) (*Server, error) { | ||
| return NewWithManager(NewSessionManager(ctx, agentSources, sessionStore, refreshInterval, runConfig), authToken), nil | ||
| func New(ctx context.Context, sessionStore session.Store, runConfig *config.RuntimeConfig, refreshInterval time.Duration, agentSources config.Sources, authToken string, opts ...Option) (*Server, error) { | ||
| return NewWithManager(NewSessionManager(ctx, agentSources, sessionStore, refreshInterval, runConfig), authToken, opts...), nil | ||
| } | ||
|
|
||
| const defaultMaxRequestBytes int64 = 1 << 20 // 1 MiB | ||
|
|
||
| // Option configures a [Server] at construction time. | ||
| type Option func(*serverOptions) | ||
|
|
||
| type serverOptions struct { | ||
| maxRequestBytes int64 | ||
| } | ||
|
|
||
| // WithMaxRequestBytes sets the maximum request body size in bytes. Requests | ||
| // whose body exceeds the limit are rejected with HTTP 413. Zero or negative | ||
| // values fall back to the default (1 MiB). | ||
| func WithMaxRequestBytes(n int64) Option { | ||
| return func(o *serverOptions) { o.maxRequestBytes = n } | ||
| } | ||
|
|
||
| // NewWithManager builds a Server around an already-constructed SessionManager. | ||
| // Useful when the runtime is owned by another component (e.g. the TUI) and | ||
| // only needs to be exposed over HTTP. | ||
| func NewWithManager(sm *SessionManager, authToken string) *Server { | ||
| func NewWithManager(sm *SessionManager, authToken string, opts ...Option) *Server { | ||
| var o serverOptions | ||
| for _, opt := range opts { | ||
| opt(&o) | ||
| } | ||
| maxBytes := o.maxRequestBytes | ||
| if maxBytes <= 0 { | ||
| maxBytes = defaultMaxRequestBytes | ||
| } | ||
|
Comment on lines
+74
to
+77
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Duplicated default/fallback logic across the two servers. This repeats the |
||
|
|
||
| e := echo.New() | ||
| e.Use(echolog.RedactedRequestLogger()) | ||
| e.Use(middleware.BodyLimit(strconv.FormatInt(defaultMaxRequestBytes, 10))) | ||
| e.Use(middleware.BodyLimit(strconv.FormatInt(maxBytes, 10))) | ||
| e.Use(echo.WrapMiddleware(upstream.Handler)) | ||
|
|
||
| // Add bearer token middleware if token is configured | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Help-string double default.
(default 1 MiB)renders alongside Cobra's auto-appended(default 1048576). You already called this out as intentional for consistency withserve chat(cmd/root/chat.go:51) — agreed, no change needed. Noting it only so the next reader doesn't re-file it.