forked from retoor/devplacepy
Keep composers usable, group actions and notifications, and drop the tool-count cap
Comment and post layouts stay full width on small screens. Secondary actions live in the More menu. Notifications can be grouped and throttled, and Enter can submit when that profile setting is on. Emulated-tool models accept large catalogs, with reserved names aliased on the wire and the catalog cached per owner. A dropped service-worker navigation is retried once. The test server waits 120s to finish importing before it is stopped.
This commit is contained in:
@@ -2757,6 +2757,225 @@ def test_meta_tool_names_restored_on_stream_chunks(local_db, monkeypatch):
|
||||
_teardown_responses_route_openai_gateway()
|
||||
|
||||
|
||||
def _setup_chat_meta_route_openai_gateway():
|
||||
from devplacepy.services.openai_gateway import routing
|
||||
|
||||
routing.provider_store.set(
|
||||
routing.ProviderIn(
|
||||
name="gwmetacc",
|
||||
base_url="https://api.meta.ai/v1/chat/completions",
|
||||
api_key="sk-test",
|
||||
)
|
||||
)
|
||||
routing.model_store.set(
|
||||
routing.ModelRouteIn(
|
||||
source_model="meta-chat-cc",
|
||||
provider="gwmetacc",
|
||||
target_model="muse-spark",
|
||||
kind="chat",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _teardown_chat_meta_route_openai_gateway():
|
||||
from devplacepy.services.openai_gateway import routing
|
||||
|
||||
routing.model_store.remove("meta-chat-cc")
|
||||
routing.provider_store.remove("gwmetacc")
|
||||
|
||||
|
||||
def _tai_tool_body_openai_gateway(**over):
|
||||
# Mirrors a real tai/detz turn: core tools are always sent, so "shell"
|
||||
# (a Pi-verified gate trigger missing from the denylist until
|
||||
# 2026-11-10) rides every request alongside the lazy "read_file".
|
||||
body = _chat_body_openai_gateway(**over)
|
||||
body["model"] = "meta-chat-cc"
|
||||
body["tools"] = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "shell",
|
||||
"description": "run a shell command",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "read_file",
|
||||
"description": "read a file",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "web_fetch",
|
||||
"description": "fetch a URL",
|
||||
"parameters": {"type": "object", "properties": {}},
|
||||
},
|
||||
},
|
||||
]
|
||||
return body
|
||||
|
||||
|
||||
class FakeChatMetaStreamResp_openai_gateway(FakeResp_openai_gateway):
|
||||
def __init__(self, payload):
|
||||
super().__init__(status=200, payload=payload)
|
||||
self._payload = payload
|
||||
|
||||
async def aiter_lines(self):
|
||||
calls = self._payload["choices"][0]["message"]["tool_calls"]
|
||||
yield (
|
||||
'data: {"id":"chatcmpl-x","object":"chat.completion.chunk",'
|
||||
'"model":"m","choices":[{"index":0,"delta":{"role":"assistant"}}]}'
|
||||
)
|
||||
for pos, call in enumerate(calls):
|
||||
name = call["function"]["name"]
|
||||
yield (
|
||||
'data: {"id":"chatcmpl-x","object":"chat.completion.chunk",'
|
||||
'"model":"m","choices":[{"index":0,"delta":{"tool_calls":'
|
||||
'[{"index":%d,"id":"call_%d","function":{"name":"%s",'
|
||||
'"arguments":"{}"}}]}}]}' % (pos, pos, name)
|
||||
)
|
||||
yield (
|
||||
'data: {"id":"chatcmpl-x","object":"chat.completion.chunk",'
|
||||
'"model":"m","choices":[{"index":0,"delta":{},'
|
||||
'"finish_reason":"tool_calls"}]}'
|
||||
)
|
||||
yield "data: [DONE]"
|
||||
|
||||
|
||||
class FakeChatMetaClient_openai_gateway:
|
||||
def __init__(self, *a, **k):
|
||||
self.calls = []
|
||||
|
||||
def build_request(self, method, url, headers=None, json=None, content=None):
|
||||
return FakeRequest(method, url, json, headers)
|
||||
|
||||
async def send(self, request, stream=False):
|
||||
self.calls.append((request.url, request.json_body))
|
||||
body = request.json_body or {}
|
||||
wire_names = [
|
||||
(tool.get("function") or {}).get("name")
|
||||
for tool in body.get("tools") or []
|
||||
]
|
||||
payload = {
|
||||
"id": "chatcmpl-x",
|
||||
"object": "chat.completion",
|
||||
"model": body.get("model"),
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_7",
|
||||
"type": "function",
|
||||
"function": {"name": name, "arguments": "{}"},
|
||||
}
|
||||
for name in wire_names
|
||||
],
|
||||
},
|
||||
"finish_reason": "tool_calls",
|
||||
}
|
||||
],
|
||||
"usage": {"prompt_tokens": 5, "completion_tokens": 2, "total_tokens": 7},
|
||||
}
|
||||
if stream:
|
||||
return FakeChatMetaStreamResp_openai_gateway(payload)
|
||||
return FakeResp_openai_gateway(
|
||||
payload=payload, content=json.dumps(payload).encode()
|
||||
)
|
||||
|
||||
async def post(self, url, headers=None, json=None, timeout=None):
|
||||
return await self.send(FakeRequest("POST", url, json), stream=False)
|
||||
|
||||
async def aclose(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_meta_tool_names_aliased_on_chat_completions_wire(local_db, monkeypatch):
|
||||
monkeypatch.setattr(gwmod.httpx, "AsyncClient", FakeChatMetaClient_openai_gateway)
|
||||
_setup_chat_meta_route_openai_gateway()
|
||||
try:
|
||||
svc = GatewayService()
|
||||
cfg = svc.effective_config()
|
||||
cfg["gateway_vision_enabled"] = False
|
||||
rt = svc.runtime()
|
||||
logged = []
|
||||
resp = run_async(
|
||||
rt.handle_chat(
|
||||
_tai_tool_body_openai_gateway(),
|
||||
cfg,
|
||||
("guest", "test"),
|
||||
"test",
|
||||
"default",
|
||||
log=logged.append,
|
||||
)
|
||||
)
|
||||
_, sent = rt._client.calls[-1]
|
||||
wire = [tool["function"]["name"] for tool in sent["tools"]]
|
||||
assert wire == ["ext_shell", "ext_read_file", "ext_web_fetch"]
|
||||
assert any("shell->ext_shell" in line for line in logged)
|
||||
assert any("read_file->ext_read_file" in line for line in logged)
|
||||
assert any("web_fetch->ext_web_fetch" in line for line in logged)
|
||||
assert resp.status_code == 200
|
||||
payload = json.loads(bytes(resp.body).decode())
|
||||
calls = payload["choices"][0]["message"]["tool_calls"]
|
||||
assert [call["function"]["name"] for call in calls] == [
|
||||
"shell",
|
||||
"read_file",
|
||||
"web_fetch",
|
||||
]
|
||||
assert payload["choices"][0]["finish_reason"] == "tool_calls"
|
||||
finally:
|
||||
_teardown_chat_meta_route_openai_gateway()
|
||||
|
||||
|
||||
def test_meta_tool_names_restored_on_chat_completions_stream(
|
||||
local_db, monkeypatch
|
||||
):
|
||||
monkeypatch.setattr(gwmod.httpx, "AsyncClient", FakeChatMetaClient_openai_gateway)
|
||||
_setup_chat_meta_route_openai_gateway()
|
||||
try:
|
||||
svc = GatewayService()
|
||||
cfg = svc.effective_config()
|
||||
cfg["gateway_vision_enabled"] = False
|
||||
rt = svc.runtime()
|
||||
resp = run_async(
|
||||
rt.handle_chat(
|
||||
_tai_tool_body_openai_gateway(stream=True),
|
||||
cfg,
|
||||
("guest", "test"),
|
||||
"test",
|
||||
"default",
|
||||
)
|
||||
)
|
||||
|
||||
async def drain():
|
||||
out = []
|
||||
async for chunk in resp.body_iterator:
|
||||
out.append(chunk if isinstance(chunk, str) else chunk.decode())
|
||||
return "".join(out)
|
||||
|
||||
body = run_async(drain())
|
||||
_, sent = rt._client.calls[-1]
|
||||
wire = [tool["function"]["name"] for tool in sent["tools"]]
|
||||
assert wire == ["ext_shell", "ext_read_file", "ext_web_fetch"]
|
||||
assert '"name": "shell"' in body
|
||||
assert '"name": "read_file"' in body
|
||||
assert '"name": "web_fetch"' in body
|
||||
assert "ext_shell" not in body
|
||||
assert "ext_read_file" not in body
|
||||
assert "ext_web_fetch" not in body
|
||||
assert "[DONE]" in body
|
||||
finally:
|
||||
_teardown_chat_meta_route_openai_gateway()
|
||||
|
||||
|
||||
def test_responses_protocol_stream_relays_chat_chunks(local_db, monkeypatch):
|
||||
monkeypatch.setattr(gwmod.httpx, "AsyncClient", FakeResponsesClient_openai_gateway)
|
||||
FakeResponsesClient_openai_gateway.behavior = "ok"
|
||||
@@ -3173,16 +3392,28 @@ def test_emulated_tools_convert_history_for_the_meta_transpiler(local_db, monkey
|
||||
_teardown_responses_route_openai_gateway()
|
||||
|
||||
|
||||
def test_emulated_tools_over_the_cap_is_a_400_with_no_upstream_call(local_db, monkeypatch):
|
||||
from devplacepy.services.openai_gateway import tool_emulation
|
||||
|
||||
body = _chat_body_openai_gateway(
|
||||
tools=[BASH_TOOL_openai_gateway] * (tool_emulation.MAX_TOOLS + 1)
|
||||
)
|
||||
def test_emulated_tools_serve_large_catalogs_with_no_cap(local_db, monkeypatch):
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": f"tool_{index}",
|
||||
"description": f"tool number {index}",
|
||||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||||
},
|
||||
}
|
||||
for index in range(200)
|
||||
]
|
||||
body = _chat_body_openai_gateway(tools=tools, tool_choice="auto")
|
||||
try:
|
||||
rt, resp = _emulated_chat_openai_gateway(monkeypatch, body)
|
||||
assert resp.status_code == 400
|
||||
assert rt._client.calls == []
|
||||
assert resp.status_code == 200
|
||||
assert len(rt._client.calls) == 1
|
||||
_, sent = rt._client.calls[-1]
|
||||
assert "tools" not in sent and "tool_choice" not in sent
|
||||
assert '"name": "tool_0"' in sent["instructions"]
|
||||
assert '"name": "tool_199"' in sent["instructions"]
|
||||
assert len(rt._catalog_cache._entries) == 1
|
||||
finally:
|
||||
_teardown_responses_route_openai_gateway()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user