Repository navigation
fix(discovery): Bytez unfiltered fallback, registered-only Experiential key, OpenCode Go endpoint table #1256
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
Draft
seonghobae
wants to merge
3
commits into
main
Choose a base branch
from
fix/model-discovery-bytez-explabs-go
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed three provider-discovery gaps. Bytez discovery now makes one last unfiltered catalog request when both task-filtered list calls fail or come back empty, keeping only rows whose own `task` is `chat` or `text-generation`, so a Bytez HTTP 500 on the filtered endpoint no longer empties the pool. The Experiential Labs key is read from `EXPERIENTIAL_LABS_API_KEY` first, then the historical `EXPERIENTAL_LABS_API_KEY`, then the provider-documented `EXPLABS_API_KEY`, in provider bootstrap, the review gateway, and the seeded CI gateway (the KV label is unchanged). OpenCode Go now carries the documented per-model endpoint table (`OPENCODE_GO_MODEL_ENDPOINTS`, from https://opencode.ai/docs/go/#endpoints): `chat/completions` models are served, while `responses` and `messages` models stay evidence-only until those adapters exist. Added `contextual_orchestrator.opencode_headers.opencode_request_headers`, which builds the identifying `user-agent` and stable per-conversation `x-opencode-session` header the OpenCode Go docs ask for; wiring it into the `ModelClient` send paths lands separately with the orchestrator fallback change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """Client identification headers OpenCode Zen and Go ask integrators to send. | ||
|
|
||
| The OpenCode Go documentation (https://opencode.ai/docs/go/#where-can-i-use-it, | ||
| checked 2026-09-26) asks every client to identify itself with its own user | ||
| agent instead of a generic HTTP-library name, and to send a stable session ID | ||
| in ``x-opencode-session`` for each conversation so OpenCode can route and | ||
| prompt-cache it. Requests to any other provider get no extra headers. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| import json | ||
| from collections.abc import Mapping | ||
| from typing import Any | ||
| from urllib.parse import urlsplit | ||
|
|
||
| OPENCODE_PROVIDER_NAMES = frozenset({"opencode_zen", "opencode_go"}) | ||
| OPENCODE_HOST = "opencode.ai" | ||
| OPENCODE_SESSION_HEADER = "x-opencode-session" | ||
| OPENCODE_USER_AGENT = ( | ||
| "contextual-orchestrator/0.2.0 " | ||
| "(+https://github.com/ContextualWisdomLab/contextual-orchestrator)" | ||
| ) | ||
| _MAX_CALLER_SESSION_CHARS = 128 | ||
|
|
||
|
|
||
| def _is_opencode_agent(agent: Any) -> bool: | ||
| if getattr(agent, "provider_name", None) in OPENCODE_PROVIDER_NAMES: | ||
| return True | ||
| base_url = getattr(agent, "base_url", "") | ||
| if not isinstance(base_url, str) or not base_url: | ||
| return False | ||
| host = (urlsplit(base_url).hostname or "").casefold() | ||
| return host == OPENCODE_HOST or host.endswith("." + OPENCODE_HOST) | ||
|
|
||
|
|
||
| def _caller_session_id(payload: Mapping[str, Any]) -> str | None: | ||
| """Return a caller-chosen conversation key when the request carries one.""" | ||
| for field in ("prompt_cache_key", "session_id"): | ||
| value = payload.get(field) | ||
| if isinstance(value, str) and value.strip(): | ||
| return value.strip()[:_MAX_CALLER_SESSION_CHARS] | ||
| metadata = payload.get("metadata") | ||
| if isinstance(metadata, Mapping): | ||
| value = metadata.get("session_id") | ||
| if isinstance(value, str) and value.strip(): | ||
| return value.strip()[:_MAX_CALLER_SESSION_CHARS] | ||
| return None | ||
|
|
||
|
|
||
| def _conversation_prefix(payload: Mapping[str, Any]) -> Any: | ||
| """Return the part of a request that stays fixed across one conversation. | ||
|
|
||
| Every turn of a chat conversation resends the same opening system and | ||
| first user message, so hashing that prefix yields the same ID on each | ||
| turn without storing any state. Responses-style ``instructions`` and the | ||
| first ``input`` item play the same role there. | ||
| """ | ||
| messages = payload.get("messages") | ||
| if isinstance(messages, list) and messages: | ||
| prefix: list[Any] = [] | ||
| for message in messages: | ||
| prefix.append(message) | ||
| if isinstance(message, Mapping) and message.get("role") == "user": | ||
| break | ||
| return {"messages": prefix} | ||
| input_value = payload.get("input") | ||
| if isinstance(input_value, list) and input_value: | ||
| input_value = input_value[0] | ||
| return {"instructions": payload.get("instructions"), "input": input_value} | ||
|
|
||
|
|
||
| def opencode_session_id(payload: Mapping[str, Any]) -> str: | ||
| """Return a stable, non-reversible session ID for one conversation.""" | ||
| caller = _caller_session_id(payload) | ||
| if caller is not None: | ||
| return caller | ||
| canonical = json.dumps( | ||
| _conversation_prefix(payload), | ||
| sort_keys=True, | ||
| separators=(",", ":"), | ||
| ensure_ascii=False, | ||
| default=str, | ||
| ) | ||
| digest = hashlib.sha256(canonical.encode("utf-8")).hexdigest()[:32] | ||
| return f"co-{digest}" | ||
|
|
||
|
|
||
| def opencode_request_headers(agent: Any, payload: Mapping[str, Any]) -> dict[str, str]: | ||
| """Return the OpenCode identification headers for one provider request.""" | ||
| if not _is_opencode_agent(agent): | ||
| return {} | ||
| return { | ||
| "user-agent": OPENCODE_USER_AGENT, | ||
| OPENCODE_SESSION_HEADER: opencode_session_id(payload), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.