fix(phase2): restore agent streams and persist extension installations

This commit is contained in:
2026-09-06 02:21:27 +08:00
parent 9497519e8b
commit 7001794a22
35 changed files with 870 additions and 39 deletions
+8
View File
@@ -0,0 +1,8 @@
"""Development reload watches application code, never imported extension packages."""
from pathlib import Path
import uvicorn
if __name__ == '__main__':
backend = Path(__file__).resolve().parents[1]
uvicorn.run('app.main:app', host='127.0.0.1', port=8000, app_dir=str(backend),
reload=True, reload_dirs=[str(backend / 'app')])
+49
View File
@@ -0,0 +1,49 @@
"""Explicit, bounded connection smoke against an already configured local Provider.
Defaults to a plan. --execute performs one test request, never reads credentials.
The output deliberately keeps untested protocol scenarios pending.
"""
import argparse
from datetime import datetime, timezone
import json
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.parse import urlparse
from urllib.request import Request, urlopen
SCENARIOS = ['model_discovery', 'tool_roundtrip', 'stream_reasoning_and_content',
'stream_cancel', 'cache_hit_and_miss', 'context_limit', 'context_compression']
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--base-url', default='http://127.0.0.1:8000')
parser.add_argument('--provider', required=True)
parser.add_argument('--model', required=True)
parser.add_argument('--output', required=True, type=Path)
parser.add_argument('--execute', action='store_true', help='Perform one provider connection test; may incur provider charges')
args = parser.parse_args()
target = urlparse(args.base_url)
if target.scheme != 'http' or target.hostname not in ('127.0.0.1', 'localhost', '::1') or target.username or target.password or target.query or target.fragment:
parser.error('Use a local HTTP AI Core address without credentials or query parameters')
result = {'date': datetime.now(timezone.utc).isoformat(), 'provider': args.provider, 'model': args.model,
'max_test_requests': 1, 'connection': 'pending',
'scenarios': {name: 'pending' for name in SCENARIOS}, 'overall': 'not_accepted'}
if args.execute:
body = json.dumps({'provider_id': args.provider, 'model': args.model}).encode()
request = Request(args.base_url.rstrip('/') + '/api/providers/test', data=body, headers={'Content-Type': 'application/json'}, method='POST')
try:
with urlopen(request, timeout=60) as response:
payload = json.load(response)
result['connection'] = 'passed' if payload.get('success') is True else 'failed'
result['latency_ms'] = payload.get('latency_ms')
except HTTPError as error:
result['connection'] = 'failed'
result['http_status'] = error.code # Do not persist remote error bodies or headers.
except (URLError, TimeoutError, ValueError):
result['connection'] = 'unavailable'
args.output.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8')
if __name__ == '__main__':
main()
+16
View File
@@ -0,0 +1,16 @@
"""Score authorized reference/hypothesis JSON segment arrays without a model or network."""
import argparse
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from app.acceptance import score
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('reference', type=Path)
parser.add_argument('hypothesis', type=Path)
parser.add_argument('--output', required=True, type=Path)
args = parser.parse_args()
result = score(json.loads(args.reference.read_text(encoding='utf-8-sig')), json.loads(args.hypothesis.read_text(encoding='utf-8-sig')))
args.output.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8')