Use getattr with a None default and isinstance narrowing instead of hasattr to
unwrap prisma.Json-style configs. Pyright was flagging .data access on the
dict branch of the union; this rewrites the path so the type narrows cleanly
without an Any cast.
Verifies agent ownership before listing (404 for unknown/unowned agents).
Sessions are scoped by created_by independent of the agent check, so a
mis-owned session row cannot leak. Optional ?status= filter, same offset
cursor as GET /v2/agents. sandbox_url and sandbox_metadata stripped per
contract \xc2\xa76.2/\xc2\xa76.3.
Both scoped by created_by, ordered by created_at desc, simple offset-based
pagination via take/skip. list_sessions_for_agent supports an optional
SessionStatus filter.
Used by the new GET /v2/agents and GET /v2/agents/:agent_id/sessions
listing endpoints. Each list response carries data + next_cursor + has_more
for simple offset-based pagination.
send_message:
- assert {providerID, modelID} object body (not string)
- 'openrouter/anthropic/claude-3' splits on first '/' only
- models without '/' omit the field entirely
- model=None omits the field
list_messages: assert {info, parts} envelopes normalize to MessageRow,
with reasoning/step-start/step-finish filtered out of content and the
combined providerID/modelID showing up as our model string.
stream_events: assert text deltas route through partID -> type tracking,
the partID map persists across multiple message.part.updated events,
session.idle is enriched with the tracked assistant message_id, and
permission.asked triggers a fire-and-forget POST to
/session/:sid/permissions/:per_id with {response:'once'}.
Update fixtures to use the {info, parts} envelope, epoch-ms timestamps,
camelCase wire field names (providerID/modelID), and the message.part.delta
event shape. Add coverage for:
- filtering step-start/step-finish/reasoning parts out of content
- tool state.status branches (running/completed/error/pending)
- the part_types map populated by message.part.updated
- message.part.delta routing via part_types lookup (text vs reasoning,
unknown partID drops)
- message.updated -> message.completed when info.time.completed is set
- session.error unwrapping the nested error.data.message string
- server.heartbeat / session.created drop to None
send_message: opencode 1.14.41 rejects string-form model with 400; split
our '<provider>/<model>' on the first '/' into the {providerID, modelID}
object form. Omit the field entirely if there's no '/' so opencode falls
back to its default agent/model.
stream_events: maintain a per-stream partID -> type map populated from
message.part.updated events so message.part.delta events can be routed
to text/reasoning. Track the in-flight assistant message_id from
message.updated so session.idle events (which carry only sessionID in
real opencode) can be enriched before yielding message.completed.
permission gating: opencode emits permission.asked events that block
tool calls until granted. Auto-grant via fire-and-forget
POST /session/:sid/permissions/:per_id body {response:'once'} so MVP
tool calls don't hang. Will surface as a real event type once we expose
permission gating to v2 callers.
opencode messages are nested as {info, parts}, not flat. Field naming on
the wire is camelCase with capital-ID suffix (sessionID, messageID,
partID, callID, providerID, modelID). Timestamps are epoch ms ints.
Part types include text/reasoning/tool/step-start/step-finish — only
text parts go into content; only tool parts go into tools. Tool I/O
lives under part.state.input / part.state.output (or .error).
Streaming text deltas come via message.part.delta events with
{messageID, partID, field, delta} — the part type is NOT on the delta
event, so normalize_opencode_event now takes a part_types dict the
caller maintains across the stream. session.idle has no messageID in
real opencode payloads — emit message.completed with message_id=None
and let the adapter enrich it from tracked state. session.error
unwraps the nested error.data.message string.
Cover idle_timeout_minutes <= timeout_minutes contract \xc2\xa76.2 invariant plus
existing timeout_minutes [1, 1440] bound. New test_types.py keeps typing
concerns separate from endpoint tests in test_agents.py.
Per contract \xc2\xa76.2, idle_timeout_minutes must be in [1, timeout_minutes].
Previously only ge=1 was enforced, so idle=1440 with timeout=10 would pass.
Add a Pydantic v2 model_validator(mode="after") that raises ValueError when
idle_timeout_minutes > timeout_minutes; FastAPI surfaces it as a 422.
* feat(xai): add grok-4.3 and grok-4.3-latest to model_prices_and_context_window.json
xAI's docs page now lists grok-4.3 as the recommended chat / coding model:
"We strongly recommend all API callers use grok-4.3. It is the most
intelligent and fastest model we've built." (https://docs.x.ai/docs/models)
Pricing/specs sourced from xAI's published model metadata:
- input: $1.25 / 1M tokens (<=200k), $2.50 / 1M tokens (>200k)
- output: $2.50 / 1M tokens (<=200k), $5.00 / 1M tokens (>200k)
- cached: $0.20 / 1M tokens (<=200k), $0.40 / 1M tokens (>200k)
- context: 1,000,000 tokens
- capabilities: vision, reasoning, function calling, structured outputs,
prompt caching, web search
Adds two entries: `xai/grok-4.3` (canonical) and `xai/grok-4.3-latest` (alias),
mirroring the pattern used for the rest of the xAI/Grok-4 family.
* test(xai): add model_info test for grok-4.3 + sync backup cost map
- Mirror xai/grok-4.3 and xai/grok-4.3-latest entries into
litellm/model_prices_and_context_window_backup.json so the bundled
model cost map matches the canonical model_prices_and_context_window.json.
- Add tests/test_litellm/test_xai_grok_4_3_model_metadata.py covering
pricing tiers, capability flags, context window, provider routing,
and parity between the main and backup cost maps.
- Point 'source' at the live xAI models page (the per-model URL
https://docs.x.ai/docs/models/grok-4.3 currently 404s).
Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
---------
Co-authored-by: shin-watcher <shin-watcher@berri.ai>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
* Refactor Bedrock response stream shape handling
- Introduced a module-level constant `BEDROCK_RESPONSE_STREAM_SHAPE` to cache the response stream shape, eliminating the need for per-instance caching in `BedrockEventStreamDecoderBase`.
- Updated relevant methods to utilize the new constant, improving performance by avoiding redundant loading of the shape.
- Added tests to ensure the shape is loaded correctly at import time and is consistent across different modules.
- Added a new mock server script for testing Bedrock pass-through functionality.
* Refactor response parsing for Bedrock and SageMaker
- Improved code readability by formatting the parsing method calls in `AWSEventStreamDecoder` for both Bedrock and SageMaker response stream shapes.
- Added blank lines for better separation of code blocks in `invoke_handler.py` and `common_utils.py` to enhance maintainability.
* Enhance error handling for Bedrock and SageMaker response stream shape loading
- Wrapped the loading logic in `_load_bedrock_response_stream_shape` and `_load_sagemaker_response_stream_shape` with try-except blocks to gracefully handle exceptions.
- Added logging to warn when the response stream shape cannot be pre-loaded, ensuring the module imports cleanly.
- Updated tests to verify that loading failures return `None` instead of propagating exceptions.
* Implement error handling for missing response stream shapes in Bedrock and SageMaker
- Added checks in `_parse_message_from_event` methods to raise appropriate errors when `BEDROCK_RESPONSE_STREAM_SHAPE` or `SAGEMAKER_RESPONSE_STREAM_SHAPE` is None, ensuring clearer error reporting.
- Updated logging messages to reflect the unavailability of event-stream decoding for both Bedrock and SageMaker.
- Enhanced unit tests to verify that the correct exceptions are raised when the response stream shapes are not loaded.