ReMe/reme_studio/client/scripts/client-contract.py
jinliyl ae55e2e570
Some checks are pending
CI / Python packages / Build and verify distributions (push) Waiting to run
CI / Python quality / GitHub Actions (push) Waiting to run
CI / Python quality / Pre-commit (push) Waiting to run
CI / Python tests / Hermes embedded - ubuntu-latest (push) Waiting to run
CI / Python tests / Hermes embedded - windows-latest (push) Waiting to run
CI / Python tests / Unit Tests - py3.11 (push) Waiting to run
CI / Python tests / Unit Tests - py3.12 (push) Waiting to run
CI / Python tests / Unit Tests - py3.13 (push) Waiting to run
CI / Python tests / Unit Tests - py3.14 (push) Waiting to run
CI / ReMe Studio / Studio checks (push) Waiting to run
CI / Windows / CLI smoke - py3.11 (push) Waiting to run
Deploy / Documentation / Build documentation (push) Waiting to run
Deploy / Documentation / deploy (push) Blocked by required conditions
Security / CodeQL / Analyze javascript-typescript (push) Waiting to run
Security / CodeQL / Analyze python (push) Waiting to run
feat!: split proactive runtimes and add Studio backend management (#776)
* refactor(proactive)!: separate runtime ownership and unify delivery

* refactor(proactive): finish runtime and Studio migration

* test(proactive): make scheduled skip coverage deterministic

* refactor(studio): unify navigation and notebook resource loading

* feat(studio): edit workspace documents and update proactive task names

* refactor(studio): simplify task settings and navigation

* feat(studio): secure and supervise backend settings

* feat(studio): unify workbench timelines and refine desktop updates

Use shared timeline panes for notebook, memory, and resources. Add Todo creation ordering, persist companion visibility, and align desktop update handling and release artifacts.

Recheck editor file versions at read and publication boundaries. Retry reminder detail requests from the resource view.

* fix(studio): support unsigned GitHub preview releases

* fix: verify container state and isolate proactive view errors

Mount private supervisor state in Docker smoke tests and verify token and settings persistence. Exercise Studio startup with a loopback-only model fixture, and exclude packaged desktop output from Docker contexts.

Keep Remy subscriptions and healthy tasks available when an individual task has an invalid workspace path or session history.

* fix(home): align candidate Docker context exclusions

* chore(deps): update openai-codex dependency to v0.172.0

- Bump openai-codex from version 0.169.0 to 0.172.0 in pyproject.toml
- Keep other dependencies unchanged
- Ensure compatibility with latest openai-codex features and fixes

* fix(daemon): discover parent dotenv and isolate listeners

Restore parent-directory environment discovery in workers while retaining system precedence. Partition the default supervisor profile and lock by the configured bind address and port.
2026-11-25 21:33:16 +08:00

123 lines
4.9 KiB
Python

"""Generate the client wire types from the public Python schemas; --check detects drift."""
import argparse
import json
from pathlib import Path
from pydantic import TypeAdapter
from reme.schema.agent_message import AgentMessage
from reme.schema.proactive_agent import ProactiveRuntimeSettings
from reme.schema.agent_view import AgentSnapshot, AgentUpdate, AgentHeartbeat, AgentView, ClientInfo
from reme.schema.stream_chunk import StreamChunk
from reme.utils.agent_transcript import TranscriptProjector
def typescript(schema):
"""Translate the JSON Schema constructs used by the client contract."""
if "$ref" in schema:
return schema["$ref"].rsplit("/", 1)[-1]
if "const" in schema or "enum" in schema:
values = schema["enum"] if "enum" in schema else [schema["const"]]
return " | ".join(json.dumps(value) for value in values)
for key in ("anyOf", "oneOf"):
if key in schema:
return " | ".join(typescript(value) for value in schema[key])
kind = schema.get("type")
if kind == "array":
return f"Array<{typescript(schema['items'])}>"
if kind == "object":
if "properties" not in schema:
result = f"Record<string, {typescript(schema.get('additionalProperties', {}))}>"
else:
required = set(schema.get("required", []))
result = (
"{\n"
+ "\n".join(
f" {key}{'' if key in required else '?'}: {typescript(value)};"
for key, value in schema["properties"].items()
)
+ "\n}"
)
return result
return {"string": "string", "number": "number", "integer": "number", "boolean": "boolean", "null": "null"}.get(
kind,
"unknown",
)
def render():
"""One adapter exports every transitively referenced schema exactly once."""
schema = TypeAdapter(
AgentMessage | AgentSnapshot | AgentUpdate | AgentHeartbeat | ClientInfo | ProactiveRuntimeSettings,
).json_schema(mode="serialization")
declarations = [f"export type {name} = {typescript(value)};" for name, value in sorted(schema["$defs"].items())]
exports = [
"export type AgentEvent = AgentSnapshot | AgentUpdate | AgentHeartbeat;",
'export type TranscriptItem = AgentMessage["items"][number];',
"export type Activities = Record<string, ClientActivity>;",
'export type SessionStatus = AgentView["status"];',
'export type ItemStatus = TranscriptItem["status"];',
]
enums = {
name: schema["$defs"][model]["properties"][field]["enum"]
for name, model, field in (
("sessionStatus", "AgentView", "status"),
("activityPhase", "ClientActivity", "phase"),
("activitySource", "ClientActivity", "source"),
("itemStatus", "TextItem", "status"),
("messageRole", "AgentMessage", "role"),
("messageSource", "AgentMessage", "source"),
("messageDelivery", "AgentMessage", "delivery"),
("toolAction", "ToolAction", "kind"),
)
}
return (
"// Generated by scripts/client-contract.py. Edit the Python schemas.\n\n"
+ "\n\n".join(declarations)
+ "\n\n"
+ "\n".join(exports)
+ "\n\nexport const clientEnums = "
+ json.dumps(enums, indent=2)
+ " as const;\n"
)
def fixture():
"""Exercise actual backend projection and serialization in the client tests."""
projector = TranscriptProjector("session", "turn")
projector.update(StreamChunk(chunk_type="content", block_id="answer", chunk="Hello", event="end"))
projector.update(StreamChunk(chunk_type="reply_end", chunk={"result": "Hello"}, status="completed"))
snapshot = AgentSnapshot(
agent=AgentView(
agent_name="Remy",
agent_type="chat",
session_id="session",
directory="reme_agents/Remy",
memory_path="reme_agents/Remy/MEMORY.md",
),
messages=[projector.message()],
)
return (
"// Generated by scripts/client-contract.py.\n"
'import type { AgentSnapshot } from "../src/wire.ts";\n\n'
"export const contract = "
+ json.dumps(snapshot.model_dump(mode="json"), ensure_ascii=False, indent=2)
+ " satisfies AgentSnapshot;\n"
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--check", action="store_true")
args = parser.parse_args()
root = Path(__file__).resolve().parents[1]
for target, output in (
(root / "src/wire.ts", render()),
(root / "tests/contract-fixture.ts", fixture()),
):
if args.check:
if not target.exists() or target.read_text() != output:
raise SystemExit("Client contract changed; run python reme_studio/client/scripts/client-contract.py")
else:
target.write_text(output)