Skip to content

Commit fda1127

Browse files
committed
Merge branch 'main' of https://github.com/CopilotKit/OpenBot into claude/flat-rows-sections-8f2829
# Conflicts: # .claude/skills/openbot-screen-layout/SKILL.md
2 parents f92d48f + 7e097af commit fda1127

28 files changed

Lines changed: 2066 additions & 575 deletions

‎.claude/skills/openbot-screen-layout/SKILL.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ PageShell the page: header (title, one-sentence description, action, back
5454
`PageShell` takes a `width`: `prose` (`max-w-3xl`, 768px) is the default, and every
5555
configuration screen uses it so no screen is wider than another. Sentences inside it are held to
5656
`max-w-prose`, so the column has room for a label beside its control without stretching the text.
57-
`wide` (`max-w-5xl`) exists for one screen — `admin/audit.tsx`, because an audit log is a table to be
58-
scanned and prose width would wrap every row. It is not a licence for anything else to be wide.
57+
`wide` (`max-w-4xl`, 896px) is for a grid of cards picked out by how they look: the Artifacts
58+
gallery, three cards a row on a desktop window. `full` (no column) exists for one screen, the audit
59+
log (`manage/audit-page.tsx`), because it is a table to be scanned and prose width would wrap every
60+
row. Neither is a licence for rows or forms to be wide.
5961

6062
## The Rhythm
6163

@@ -242,7 +244,8 @@ is actually on screen. The root was once 15px, and every constant taken from the
242244
- A width, ratio or scale needs a number in pixels → the Units section. Measure, do not assume.
243245
- Choosing a margin or gap between blocks → the Rhythm table. If the frame already gives it, set none.
244246
- The screen genuinely does not fit this shape → say so in the response and comment the reason in the
245-
code. There are two accepted precedents: a table (`admin/audit.tsx`, `width="wide"`), and the
247+
code. There are three accepted precedents: a table (the audit log, `width="full"`), the
248+
Artifacts gallery (`width="wide"`, a grid of cards), and the
246249
Connections tiles (`connections.index.tsx`), a grid of separate `variant="outline"` cards, 56px
247250
tall and 12px apart, because apps are picked out by their mark rather than read down as a list.
248251
- The question is which states the screen renders while loading or failing → not this skill;
@@ -256,7 +259,7 @@ is actually on screen. The root was once 15px, and every constant taken from the
256259
| Rows separated by `gap-*` instead of `<Separator />` | A stack of cards rather than one list of rows | `<Separator />` between rows, none after the last |
257260
| `ItemMedia variant="icon"` on rows whose icons are one per kind of setting | A tile that repeats the title, the look this layout dropped | No media; keep tiles for app marks and file kinds |
258261
| A page or section description of two or more sentences | A paragraph between the title and the rows | One sentence; the rest in `learnMore` |
259-
| `width="wide"` on anything that is not a table | Prose width is the default for a reason; wide was for the audit log | Leave `width` alone |
262+
| `width="wide"` or `"full"` on rows or a form | Prose width is the default for a reason; the others are for a grid of cards and a table | Leave `width` alone |
260263
| A `max-w-*`, `p-*` or text size invented for one screen | A fifth container width, which is what this layout exists to stop | Reach for the existing component |
261264
| Children on an element passed to `Item`'s `render` | They replace the row's own children; the row draws empty | Pass a childless element |
262265
| `bg-card` on a row inside a dialog | `--card` equals `--popover`; the row is invisible | `variant="muted"` |

‎agent-claude-sdk/src/adapter.py‎

Lines changed: 279 additions & 131 deletions
Large diffs are not rendered by default.

‎agent-claude-sdk/src/main.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ def _refuse_both_credentials() -> None:
4848

4949
app = FastAPI()
5050
# Each run's model calls carry its own gateway token, in its organization. See run_model_proxy.py.
51-
app.add_middleware(RunModelKey)
51+
# Not on the model calls Claude Code sends back through here: they are no run, carry no props of
52+
# the server's, and are the largest bodies this harness takes, the whole conversation every step,
53+
# which the middleware would read whole and parse for nothing.
54+
app.add_middleware(RunModelKey, skip_paths=(PROXY_PATH,))
5255

5356

5457
@app.middleware("http")
5558
async def refuse_without_the_server_token(request: Request, call_next):
56-
# Claude Code's own model calls come back here on a secret path of their query's, from this
59+
# Claude Code's own model calls come back here with a secret of their query's, from this
5760
# container's loopback, and carry no server token. See run_model_proxy.py.
5861
if request.url.path != "/health" and not request.url.path.startswith(PROXY_PATH):
5962
expected = (os.environ.get("MANAGED_AGENT_TOKEN") or "").strip()
@@ -68,9 +71,9 @@ async def health():
6871
return {"ok": True, "harness": "claude-agent-sdk"}
6972

7073

71-
@app.api_route(PROXY_PATH + "{secret}/{path:path}", methods=["GET", "POST"])
72-
async def run_model(request: Request, secret: str, path: str):
73-
return await forward(request, secret, path)
74+
@app.api_route(PROXY_PATH + "{path:path}", methods=["GET", "POST"])
75+
async def run_model(request: Request, path: str):
76+
return await forward(request, path)
7477

7578

7679
add_claude_fastapi_endpoint(

‎agent-claude-sdk/src/replay.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
person's first and latest messages (see `conversation_content`).
1010
1111
Client-tool continuations do not take this path: the adapter resolves their PostToolUse hook in the
12-
same SDK query that emitted the tool use. The exceptions are answered by a fresh query from here: a
13-
model-endpoint step sent other tools than that query holds, and a result whose query is no longer
14-
running (it outlived the query's bound, or the process restarted); see `OpenBotClaudeAgentAdapter.run`.
12+
same SDK query that emitted the tool use, adding to it any tool the step brings that it does not
13+
hold (`OpenBotClaudeAgentAdapter._hold_step`). The exceptions are answered by a fresh query from
14+
here: a result whose query is no longer running (it outlived the query's bound, or the process
15+
restarted), a step after the person wrote again, and a step whose tools could not be added to the
16+
running query; see `OpenBotClaudeAgentAdapter.run`.
1517
"""
1618

1719
import asyncio
@@ -671,8 +673,8 @@ async def run_replayed_query(adapter, input_data, fit_results=False):
671673
)
672674
# A fresh worker receives the current Bot instructions and granted schemas.
673675
# Tool-boundary HTTP continuations consume this still-running query instead
674-
# of creating a second worker or changing its identity, unless the model
675-
# endpoint sends them other tools than this query holds (see `adapter.run`).
676+
# of creating a second worker or changing its identity; a tool one brings is
677+
# added to it (see `adapter._hold_step`).
676678
options = adapter.build_options(input_data, thread)
677679
prompt_file = system_prompt_in_file(options)
678680
worker = SessionWorker(thread, options)

‎agent-claude-sdk/src/run_model_proxy.py‎

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
Here Claude Code sends them, from a process of its own that lives across runs: a query waits on a
1111
tool's result while the person decides, and the next run carries it on. A key fixed in its
1212
environment would be the first run's, past its ten minutes. So a query on the gateway is pointed at
13-
this harness instead, on a path only it knows (`/_run-model/<secret>`), and every call it makes is
14-
passed on to the gateway with the newest token any run of that thread brought.
13+
this harness instead (`/_run-model/`), with a secret only it knows in a header of its own
14+
(`SECRET_HEADER`), and every call it makes is passed on to the gateway with the newest token any run
15+
of that thread brought.
16+
17+
The secret is in a header, not the path: uvicorn writes every request's path to its access log, and
18+
with the secret in it every model call of every query wrote the secret to the logs.
1519
1620
Only where the configured address is the gateway's (`/api/model-provider/`) and a run brought a
1721
token. Otherwise Claude Code is given what it always was.
@@ -30,6 +34,10 @@
3034
from run_model_key import GATEWAY_PATH, run_key # noqa: E402
3135

3236
PROXY_PATH = "/_run-model/"
37+
# The header a query's model calls carry their secret in, set through Claude Code's
38+
# `ANTHROPIC_CUSTOM_HEADERS` (code.claude.com/docs/en/env-vars: "Name: Value", one a line).
39+
SECRET_HEADER = "x-openbot-run-model"
40+
CUSTOM_HEADERS = "ANTHROPIC_CUSTOM_HEADERS"
3341

3442
# A thread's slot outlives a run: its query may wait on a person for hours. One a day old is gone.
3543
SLOT_SECONDS = 24 * 60 * 60
@@ -77,8 +85,14 @@ def query_environment(thread_id: str | None) -> dict[str, str]:
7785
_by_secret[slot.secret] = slot
7886
slot.key, slot.at = key, now
7987
port = (os.environ.get("PORT") or "4212").strip()
88+
# Headers the container already sends with its model calls go on being sent, as the SDK lays
89+
# a query's environment over the container's own.
90+
custom = (os.environ.get(CUSTOM_HEADERS) or "").strip()
8091
return {
81-
"ANTHROPIC_BASE_URL": f"http://127.0.0.1:{port}{PROXY_PATH}{slot.secret}",
92+
"ANTHROPIC_BASE_URL": f"http://127.0.0.1:{port}{PROXY_PATH.rstrip('/')}",
93+
CUSTOM_HEADERS: "\n".join(
94+
line for line in (custom, f"{SECRET_HEADER}: {slot.secret}") if line
95+
),
8296
# Claude Code needs a key to start; the one it sends is replaced on the way out.
8397
"ANTHROPIC_API_KEY": "openbot-run-model",
8498
}
@@ -97,22 +111,33 @@ def slot_key(secret: str) -> str | None:
97111
return slot.key if slot is not None else None
98112

99113

100-
# What is not passed on to the gateway: how this hop was made, and the key Claude Code was given.
101-
_REQUEST_DROPPED = {"host", "content-length", "connection", "authorization", "x-api-key"}
114+
# What is not passed on to the gateway: how this hop was made, the key Claude Code was given, and
115+
# the secret that let it back in.
116+
_REQUEST_DROPPED = {
117+
"host",
118+
"content-length",
119+
"connection",
120+
"authorization",
121+
"x-api-key",
122+
SECRET_HEADER,
123+
}
102124
# What is not passed back: how the gateway's answer was framed, which this hop frames again.
103125
_RESPONSE_DROPPED = {"content-length", "transfer-encoding", "connection"}
104126

105127
_client = None
106128

107129

108-
async def forward(request, secret: str, path: str):
109-
"""One of Claude Code's model calls, passed on to the gateway with its thread's newest token."""
130+
async def forward(request, path: str):
131+
"""One of Claude Code's model calls, passed on to the gateway with its thread's newest token.
132+
133+
Turned away before its body is read when it names no query of this process.
134+
"""
110135
import httpx
111136
from fastapi.responses import JSONResponse, StreamingResponse
112137
from starlette.background import BackgroundTask
113138

114139
global _client
115-
key = slot_key(secret)
140+
key = slot_key((request.headers.get(SECRET_HEADER) or "").strip())
116141
base = _gateway_base()
117142
client_host = request.client.host if request.client else ""
118143
if not key or not base or client_host not in ("127.0.0.1", "::1"):

‎agent-claude-sdk/tests/test_model_mode.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ def test_model_mode_disables_native_and_ambient_tools():
3939
}
4040
)
4141
options = adapter.build_options(request, request.thread_id)
42-
assert options.tools == []
42+
# None of Claude Code's own tools but its tool search, which loads the definition of a tool
43+
# the step offers (see test_query_kept_across_steps.py).
44+
assert options.tools == ["ToolSearch"]
45+
assert options.env["ENABLE_TOOL_SEARCH"] == "true"
4346
options.cli_path = "/not-executed/claude"
4447
command = SubprocessCLITransport(
4548
prompt="contract only", options=options
4649
)._build_command()
47-
assert command[command.index("--tools") + 1] == ""
50+
assert command[command.index("--tools") + 1] == "ToolSearch"
4851
assert options.strict_mcp_config is True
4952
assert options.setting_sources == []
5053
assert options.permission_mode == "dontAsk"
5154
assert set(options.mcp_servers) == {"ag_ui"}
52-
# Claude Code may call the `ag_ui` server's tools, which are only the offered ones; the hook
53-
# below is what refuses anything else.
54-
assert options.allowed_tools == ["mcp__ag_ui__*"]
55+
# Claude Code may call the `ag_ui` server's tools, which are only the offered ones, and search
56+
# them; the hook below is what refuses anything else.
57+
assert options.allowed_tools == ["mcp__ag_ui__*", "ToolSearch"]
5558
assert "You are Knowledge. Cite sources." in options.system_prompt
5659
assert "Discard Knowledge" not in options.system_prompt
5760

@@ -61,6 +64,7 @@ async def check_permission():
6164
await check({"tool_name": "mcp__ag_ui__knowledge_search"}, "granted", {})
6265
== {}
6366
)
67+
assert await check({"tool_name": "ToolSearch"}, "search", {}) == {}
6468
for name in [
6569
"Bash",
6670
"Read",

0 commit comments

Comments
 (0)