Add manual opener tool calls to Assistant model and API

- Introduced `manual_opener_tool_calls` field in the Assistant model to support custom tool calls.
- Updated AssistantBase and AssistantUpdate schemas to include the new field.
- Implemented normalization and migration logic for handling manual opener tool calls in the API.
- Enhanced runtime metadata to include manual opener tool calls in responses.
- Updated tests to validate the new functionality and ensure proper handling of tool calls.
- Refactored tool ID normalization to support legacy tool names for backward compatibility.
This commit is contained in:
Xin Wang
2026-03-02 12:34:42 +08:00
parent b5cdb76e52
commit 00b88c5afa
14 changed files with 806 additions and 74 deletions

View File

@@ -21,6 +21,7 @@ class TestToolsAPI:
assert "turn_off_camera" in tools
assert "increase_volume" in tools
assert "decrease_volume" in tools
assert "voice_msg_prompt" in tools
assert "calculator" in tools
def test_get_tool_detail(self, client):
@@ -36,6 +37,14 @@ class TestToolsAPI:
response = client.get("/api/tools/list/non-existent-tool")
assert response.status_code == 404
def test_get_tool_detail_legacy_alias(self, client):
"""Legacy tool id should resolve to canonical tool detail."""
response = client.get("/api/tools/list/voice_message_prompt")
assert response.status_code == 200
data = response.json()
assert data["name"] == "语音消息提示"
assert "msg" in data["parameters"]["properties"]
def test_health_check(self, client):
"""Test health check endpoint"""
response = client.get("/api/tools/health")
@@ -281,6 +290,7 @@ class TestToolResourceCRUD:
assert payload["total"] >= 1
ids = [item["id"] for item in payload["list"]]
assert "calculator" in ids
assert "voice_msg_prompt" in ids
calculator = next((item for item in payload["list"] if item["id"] == "calculator"), None)
assert calculator is not None
assert calculator["parameter_schema"]["type"] == "object"