Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c298933
fix(sdk): prepend default http scheme to schemeless AGENTA_API_URL in…
itsgintoki Sep 1, 2026
48a9a16
Merge branch 'main' into fix/sdk-schemeless-api-url
itsgintoki Sep 1, 2026
a669008
fix(sdk): default schemeless non-local urls to https
itsgintoki Sep 1, 2026
2f522e6
fix(sdk): default all schemeless urls to http to mirror api
itsgintoki Oct 1, 2026
ae1be9c
ci(web): run office viewer bundle check as an independent CI job (#7771)
yunusarda-sudo Oct 24, 2026
1dcbcf3
docs(ci): add architecture diagram for office viewer check
yunusarda-sudo Oct 24, 2026
a4f9382
ci: set persist-credentials false on office bundle checkout
yunusarda-sudo Oct 25, 2026
ce842a7
fix(comments): drop dangling colon when a CSV cell's column has no he…
mosifu Oct 25, 2026
3314535
docs(design): built-in Gemini over Google's native protocol
Oct 25, 2026
08cbdb5
feat(api): serve built-in Gemini over Google's native streamGenerateC…
Oct 25, 2026
017a8e7
feat(runner): drive the built-in Gemini route with Pi's Google client…
Oct 25, 2026
52a7986
fix(api): check nested native Gemini fields, malformed bodies and nul…
Oct 25, 2026
f2233de
test(runner,sdk): native Gemini golden, pinned identities, Pi's Googl…
Oct 25, 2026
72046f2
fix(runner): keep built-in Gemini unmarked as reasoning on the native…
Oct 25, 2026
5dfe7dd
test(api): pin every refusal of the native Gemini allowlist; align th…
Oct 25, 2026
2792163
fix(sdk): pass cloud credentials per call instead of through the proc…
mmabrouk Oct 26, 2026
4a0139b
docs(api): update API reference from production OpenAPI spec
github-actions[bot] Oct 26, 2026
a04ea39
docs(docs): add the v0.125.0 changelog entry for private agents and c…
mmabrouk Oct 26, 2026
131c326
v0.125.1
mmabrouk Oct 26, 2026
06f6f2d
test(api): the legacy workspace lookup test reads only its own seeded…
Oct 26, 2026
ed00b5b
fix(sdk): keep the host AWS session token off a connection's own key …
Oct 26, 2026
ee2dc8e
Merge pull request #7812 from Agenta-AI/fix/sdk-per-call-cloud-creden…
mmabrouk Oct 26, 2026
5d39d4c
Merge pull request #7815 from Agenta-AI/tests/m4b-accept-test-isolation
mmabrouk Oct 26, 2026
4e26fbb
Merge pull request #7814 from Agenta-AI/docs/changelog-v0.125.0
mmabrouk Oct 26, 2026
a1a7ac5
chore(web): remove the PR diagram from the entity-ui package
Oct 26, 2026
b1ddda7
docs(changelog): add the seven October changelog entries and their si…
mmabrouk Oct 26, 2026
24b4c14
Merge pull request #7799 from mosifu/fix/csv-comment-label-empty-header
mmabrouk Oct 26, 2026
23adb4e
Merge pull request #7788 from yunusarda-sudo/ci/office-viewer-bundle-…
mmabrouk Oct 26, 2026
8ba030a
Merge pull request #7816 from Agenta-AI/docs/changelog-october-entries
mmabrouk Oct 26, 2026
1e42a95
docs: add mosifu and yunusarda-sudo to the contributors list
Oct 26, 2026
5178dfb
Merge pull request #7770 from Agenta-AI/automated/update-api-docs
mmabrouk Oct 26, 2026
7962423
Merge pull request #7817 from Agenta-AI/docs/all-contributors-01251
mmabrouk Oct 26, 2026
9110bfc
fix(api): let Pi retry a gateway timeout and a cut-off event on the n…
mmabrouk Oct 26, 2026
a000db7
style(sdk): apply ruff format to the parse_url tests
Oct 26, 2026
4b05f07
docs: add itsgintoki to the contributors list
Oct 26, 2026
e7c0ad7
Merge pull request #6453 from itsgintoki/fix/sdk-schemeless-api-url
mmabrouk Oct 26, 2026
bdfc4e5
Merge pull request #7818 from Agenta-AI/docs/all-contributors-itsgintoki
mmabrouk Oct 26, 2026
552e65e
fix(api): end a native Gemini stream's last event when the upstream l…
mmabrouk Oct 26, 2026
b4d92c9
Merge pull request #7806 from Agenta-AI/feat/gemini-native-door
mmabrouk Oct 26, 2026
616ec51
fix(runner): classify Google-shaped gateway errors from the native Ge…
Oct 26, 2026
0183a62
fix(runner): read only marked Google gateway bodies, and keep the marker
Oct 26, 2026
e396846
Merge pull request #7819 from Agenta-AI/fix/runner-google-gateway-errors
mmabrouk Oct 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,33 @@
"contributions": [
"doc"
]
},
{
"login": "mosifu",
"name": "mosifu",
"avatar_url": "https://avatars.githubusercontent.com/u/256577176?v=4",
"profile": "https://github.com/mosifu",
"contributions": [
"code"
]
},
{
"login": "yunusarda-sudo",
"name": "Yunus Arda Güney",
"avatar_url": "https://avatars.githubusercontent.com/u/64425746?v=4",
"profile": "https://github.com/yunusarda-sudo",
"contributions": [
"code"
]
},
{
"login": "itsgintoki",
"name": "Gin",
"avatar_url": "https://avatars.githubusercontent.com/u/237295543?v=4",
"profile": "https://github.com/itsgintoki",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/12-check-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,58 @@ jobs:
working-directory: web
run: pnpm --filter @agenta/storybook build-storybook

check-office-viewer-bundles:
# Ensures the office viewer script bundles stay in sync with their source frames.
# An independent job ensures failures cannot be hidden by unit tests failing in another package.
if: |
github.event_name == 'workflow_dispatch' ||
!github.event.pull_request.draft
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false

- name: Skip when package selection excludes web
if: github.event_name == 'workflow_dispatch' && !contains(fromJSON('["all","web-only"]'), inputs.packages)
run: exit 0

- name: Set up Node.js
if: github.event_name != 'workflow_dispatch' || contains(fromJSON('["all","web-only"]'), inputs.packages)
uses: actions/setup-node@v4
with:
node-version: '24'

- name: Enable Corepack
if: github.event_name != 'workflow_dispatch' || contains(fromJSON('["all","web-only"]'), inputs.packages)
run: corepack enable

- name: Cache pnpm store
if: github.event_name != 'workflow_dispatch' || contains(fromJSON('["all","web-only"]'), inputs.packages)
uses: actions/cache@v4
with:
path: |
~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('web/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-

- name: Set up pnpm store
if: github.event_name != 'workflow_dispatch' || contains(fromJSON('["all","web-only"]'), inputs.packages)
run: pnpm config set store-dir ~/.pnpm-store

- name: Install dependencies
if: github.event_name != 'workflow_dispatch' || contains(fromJSON('["all","web-only"]'), inputs.packages)
working-directory: web
run: pnpm install

- name: Check office viewer bundles
if: github.event_name != 'workflow_dispatch' || contains(fromJSON('["all","web-only"]'), inputs.packages)
working-directory: web/packages/agenta-entity-ui
run: node scripts/build-office-viewers.mjs --check

run-sdk-unit-tests:
if: |
github.event_name == 'workflow_dispatch' ||
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ repos:
language: system
files: ^web/.*\.(js|jsx|cjs|mjs|ts|tsx|cts|mts|mdx)$
pass_filenames: false
- id: check-office-viewers
name: check office viewer bundles (web)
entry: bash -c 'cd web/packages/agenta-entity-ui && node scripts/build-office-viewers.mjs --check'
language: system
files: ^web/packages/agenta-entity-ui/src/drive/officeViewer/
pass_filenames: false
- id: gitleaks-pre-commit
name: gitleaks git (staged only)
entry: bash -c 'gitleaks --config .gitleaks.toml --exit-code 1 --verbose git --staged'
Expand Down
5 changes: 4 additions & 1 deletion README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Agenta 是基于 MIT 许可证的开源项目。你可以查看代码、自行
## 贡献者 ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

感谢这些了不起的贡献者([emoji 说明](https://allcontributors.org/docs/en/emoji-key)):
Expand Down Expand Up @@ -379,6 +379,9 @@ Agenta 是基于 MIT 许可证的开源项目。你可以查看代码、自行
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/demonroute1"><img src="https://avatars.githubusercontent.com/u/340640589?v=4?s=100" width="100px;" alt="Demon Route "/><br /><sub><b>Demon Route </b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=demonroute1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mosifu"><img src="https://avatars.githubusercontent.com/u/256577176?v=4?s=100" width="100px;" alt="mosifu"/><br /><sub><b>mosifu</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=mosifu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yunusarda-sudo"><img src="https://avatars.githubusercontent.com/u/64425746?v=4?s=100" width="100px;" alt="Yunus Arda Güney"/><br /><sub><b>Yunus Arda Güney</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=yunusarda-sudo" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/itsgintoki"><img src="https://avatars.githubusercontent.com/u/237295543?v=4?s=100" width="100px;" alt="Gin"/><br /><sub><b>Gin</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=itsgintoki" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 4 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Agenta が役に立ったら、リポジトリにスターを付けて、あな
## コントリビューター ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

すばらしいコントリビューターの皆さんに感謝します([絵文字の凡例](https://allcontributors.org/docs/en/emoji-key)):
Expand Down Expand Up @@ -379,6 +379,9 @@ Agenta が役に立ったら、リポジトリにスターを付けて、あな
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/demonroute1"><img src="https://avatars.githubusercontent.com/u/340640589?v=4?s=100" width="100px;" alt="Demon Route "/><br /><sub><b>Demon Route </b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=demonroute1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mosifu"><img src="https://avatars.githubusercontent.com/u/256577176?v=4?s=100" width="100px;" alt="mosifu"/><br /><sub><b>mosifu</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=mosifu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yunusarda-sudo"><img src="https://avatars.githubusercontent.com/u/64425746?v=4?s=100" width="100px;" alt="Yunus Arda Güney"/><br /><sub><b>Yunus Arda Güney</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=yunusarda-sudo" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/itsgintoki"><img src="https://avatars.githubusercontent.com/u/237295543?v=4?s=100" width="100px;" alt="Gin"/><br /><sub><b>Gin</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=itsgintoki" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 4 additions & 1 deletion README.kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Agenta가 도움이 되었다면 저장소에 스타를 눌러 주시고, 무엇
## 기여자 ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

멋진 기여자 여러분께 감사드립니다([이모지 안내](https://allcontributors.org/docs/en/emoji-key)):
Expand Down Expand Up @@ -379,6 +379,9 @@ Agenta가 도움이 되었다면 저장소에 스타를 눌러 주시고, 무엇
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/demonroute1"><img src="https://avatars.githubusercontent.com/u/340640589?v=4?s=100" width="100px;" alt="Demon Route "/><br /><sub><b>Demon Route </b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=demonroute1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mosifu"><img src="https://avatars.githubusercontent.com/u/256577176?v=4?s=100" width="100px;" alt="mosifu"/><br /><sub><b>mosifu</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=mosifu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yunusarda-sudo"><img src="https://avatars.githubusercontent.com/u/64425746?v=4?s=100" width="100px;" alt="Yunus Arda Güney"/><br /><sub><b>Yunus Arda Güney</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=yunusarda-sudo" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/itsgintoki"><img src="https://avatars.githubusercontent.com/u/237295543?v=4?s=100" width="100px;" alt="Gin"/><br /><sub><b>Gin</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=itsgintoki" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ If Agenta is useful to you, star the repository and tell us what you build.
## Contributors ✨

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down Expand Up @@ -382,6 +382,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/demonroute1"><img src="https://avatars.githubusercontent.com/u/340640589?v=4?s=100" width="100px;" alt="Demon Route "/><br /><sub><b>Demon Route </b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=demonroute1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mosifu"><img src="https://avatars.githubusercontent.com/u/256577176?v=4?s=100" width="100px;" alt="mosifu"/><br /><sub><b>mosifu</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=mosifu" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yunusarda-sudo"><img src="https://avatars.githubusercontent.com/u/64425746?v=4?s=100" width="100px;" alt="Yunus Arda Güney"/><br /><sub><b>Yunus Arda Güney</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=yunusarda-sudo" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/itsgintoki"><img src="https://avatars.githubusercontent.com/u/237295543?v=4?s=100" width="100px;" alt="Gin"/><br /><sub><b>Gin</b></sub></a><br /><a href="https://github.com/Agenta-AI/agenta/commits?author=itsgintoki" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
107 changes: 106 additions & 1 deletion api/oss/src/apis/fastapi/gateways/llms/proxy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Protocol-shaped LLM gateway proxy responses."""

import json
import re
from typing import TYPE_CHECKING, Any, AsyncIterator, Callable, Dict, List, Optional

import httpx
Expand All @@ -10,6 +11,7 @@
from oss.src.utils.logging import get_module_logger
from oss.src.apis.fastapi.gateways.exceptions import log_plane_disabled
from oss.src.apis.fastapi.gateways.llms.utils import (
parse_gemini_call_context,
LLMRequestBodyError,
parse_llm_call_context,
parse_messages_call_context,
Expand All @@ -25,7 +27,11 @@
from oss.src.core.gateways.cleanup import run_shielded
from oss.src.core.gateways.egress import classify_transport_error
from oss.src.core.gateways.llms.dtos import LLMCallContext, LLMProtocol
from oss.src.core.gateways.llms.errors import UPSTREAM_ERROR, connection_lost_message
from oss.src.core.gateways.llms.errors import (
UPSTREAM_ERROR,
connection_lost_message,
google_error,
)
from oss.src.core.gateways.types import (
GatewayEndpointInactiveError,
GatewayPlaneDisabledError,
Expand Down Expand Up @@ -141,6 +147,50 @@ def _refuse_builtin_outside_agent_run(
)


# A bare Gemini model id, safe in a URL path: no slash, no dot segment, no escape.
_BARE_GEMINI_MODEL = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,127}")


def _google_error_response(*, status_code: int, message: str) -> JSONResponse:
return JSONResponse(
status_code=status_code,
content=google_error(status=status_code, message=message),
)


def _as_google_error(response: Response) -> Response:
"""A refusal the gateway answered in OpenAI's shape, in Google's shape instead, with the
same status and the same (marked) message."""
try:
payload = json.loads(response.body)
except (AttributeError, ValueError):
payload = None
error = payload.get("error") if isinstance(payload, dict) else None
message = error.get("message") if isinstance(error, dict) else None
status_code = response.status_code
if isinstance(error, dict) and error.get("code") == "upstream_timeout":
# The gateway gave up waiting. Google's client drops the string code, so the native
# caller gets what a timeout mid-stream says: 504 and the marked upstream sentence,
# which Pi retries and the runner reads as an upstream error.
status_code = 504
message = with_code_marker(
"The model provider did not answer in time.", UPSTREAM_ERROR
)
headers = {
key: value
for key, value in response.headers.items()
if key.lower() not in ("content-length", "content-type")
}
return JSONResponse(
status_code=status_code,
content=google_error(
status=status_code,
message=message if isinstance(message, str) else "request refused",
),
headers=headers,
)


def _request_body_detail(exc: ValueError) -> str:
"""What to tell a caller about a body the gateway could not route.

Expand Down Expand Up @@ -308,6 +358,11 @@ def _stream_error_frame(protocol: LLMProtocol, exc: Exception) -> bytes:
code = UPSTREAM_ERROR
message = connection_lost_message()

if protocol == LLMProtocol.GEMINI:
status = 504 if isinstance(exc, LLMUpstreamTimeoutError) else 502
error = google_error(status=status, message=message)
return b"\n\ndata: " + json.dumps(error, ensure_ascii=False).encode() + b"\n\n"

if protocol == LLMProtocol.MESSAGES:
event = b"error"
data = {"type": "error", "error": {"type": "api_error", "message": message}}
Expand Down Expand Up @@ -427,6 +482,12 @@ def __init__(self, *, llm_gateway_service: "LLMGatewayService") -> None:
methods=["POST"],
operation_id="llm_gateway_messages_custom",
)
self.router.add_api_route(
"/builtin/{provider}/v1beta/models/{model}:streamGenerateContent",
self.gemini_stream_builtin,
methods=["POST"],
operation_id="llm_gateway_gemini_stream_builtin",
)
self.router.add_api_route(
"/builtin/{provider}/v1/models",
self.list_models_builtin,
Expand Down Expand Up @@ -537,6 +598,30 @@ async def messages_custom(self, request: Request, slug: str) -> Response:
protocol=LLMProtocol.MESSAGES,
)

# --- gemini (native) ---------------------------------------------------------- #

async def gemini_stream_builtin(
self, request: Request, provider: str, model: str
) -> Response:
"""Google's native `streamGenerateContent`, for the built-in Gemini models only.

Pi's Google client calls this with the bare model id in the path
(`docs/design/gemini-native-door`). The model is named `google/<model>` so the
allowlist and the rate card read it as they read the chat door's. Query parameters
(`alt`, `key`) are not forwarded: the upstream URL sets `alt=sse` itself.
"""
if not _BARE_GEMINI_MODEL.fullmatch(model):
return _google_error_response(
status_code=400, message="The model must be a bare Gemini model id."
)
return await self._relay(
request,
namespace=GatewayEndpointNamespace.BUILTIN,
name=provider,
parser=lambda body: parse_gemini_call_context(body=body, model=model),
protocol=LLMProtocol.GEMINI,
)

# Shared relay

async def _relay(
Expand All @@ -547,6 +632,23 @@ async def _relay(
name: str,
parser: Callable[..., LLMCallContext],
protocol: LLMProtocol,
) -> Response:
response = await self._relay_protocol(
request, namespace=namespace, name=name, parser=parser, protocol=protocol
)
# A native Gemini caller reads only Google's error shape.
if protocol == LLMProtocol.GEMINI and response.status_code >= 400:
return _as_google_error(response)
return response

async def _relay_protocol(
self,
request: Request,
*,
namespace: GatewayEndpointNamespace,
name: str,
parser: Callable[..., LLMCallContext],
protocol: LLMProtocol,
) -> Response:
# Checked before the body is read: with the plane off there is nothing to relay to,
# and a harness that pointed at this base URL needs the refusal, not a parse error.
Expand Down Expand Up @@ -584,6 +686,9 @@ async def _relay(
protocol=protocol,
run_id=gateway_run_id(request),
run_labels=gateway_run_labels(request),
# The native door's model is in its URL, so it hands over the context it
# built; every other door's is read from the body by the service.
**({"context": context} if protocol == LLMProtocol.GEMINI else {}),
)

if context.stream and result.status_code < 400:
Expand Down
18 changes: 18 additions & 0 deletions api/oss/src/apis/fastapi/gateways/llms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ def _parse(*, body: bytes, protocol: LLMProtocol) -> LLMCallContext:
return LLMCallContext(model=model, stream=stream, protocol=protocol)


def parse_gemini_call_context(*, body: bytes, model: str) -> LLMCallContext:
"""Check a native Gemini request's body; its model comes from the URL path, named
`google/<model>` as the built-in endpoint's allowlist spells it."""
try:
payload = json.loads(body) if body else None
except ValueError as exc:
raise LLMRequestBodyError(
cause="invalid_json", detail="request body is not valid JSON"
) from exc
if not isinstance(payload, dict):
raise LLMRequestBodyError(
cause="not_an_object", detail="request body must be a JSON object"
)
return LLMCallContext(
model=f"google/{model}", stream=True, protocol=LLMProtocol.GEMINI
)


def parse_llm_call_context(*, body: bytes) -> LLMCallContext:
"""Parse a Chat Completions request."""
return _parse(body=body, protocol=LLMProtocol.CHAT_COMPLETIONS)
Expand Down
Loading
Loading