补齐平台模板与场景 DSL、预算控制、执行看板和企业场景脚本,增强 Windows 启动/迁移与前端代理和聊天会话记忆,修复执行创建阶段 500 与异步链路排障体验。 Made-with: Cursor
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
路线图场景模板:研发 / 代码助手 — 通过 API 从模板创建 Agent。
|
|
|
|
用法:
|
|
cd backend && .\\venv\\Scripts\\python.exe scripts/templates/template_dev_codegen.py
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
import requests
|
|
|
|
BASE = os.getenv("PLATFORM_BASE_URL", "http://127.0.0.1:8037").rstrip("/")
|
|
USER = os.getenv("PLATFORM_USERNAME", "admin")
|
|
PWD = os.getenv("PLATFORM_PASSWORD", "123456")
|
|
TEMPLATE_ID = "template_dev_codegen"
|
|
DEFAULT_NAME = os.getenv("TARGET_NAME") or f"场景模板_研发_{int(time.time())}"
|
|
|
|
|
|
def main() -> int:
|
|
r = requests.post(
|
|
f"{BASE}/api/v1/auth/login",
|
|
data={"username": USER, "password": PWD},
|
|
headers={"Content-Type": "application/x-www-form-urlencoded"},
|
|
timeout=15,
|
|
)
|
|
if r.status_code != 200:
|
|
print("登录失败:", r.status_code, r.text[:500], file=sys.stderr)
|
|
return 1
|
|
token = r.json().get("access_token")
|
|
if not token:
|
|
print("无 access_token", file=sys.stderr)
|
|
return 1
|
|
h = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
|
|
|
body = {
|
|
"template_id": TEMPLATE_ID,
|
|
"name": DEFAULT_NAME,
|
|
"description": "由 scripts/templates/template_dev_codegen.py 创建",
|
|
"parameters": {"preferred_language": "Python", "temperature": 0.25},
|
|
}
|
|
cr = requests.post(f"{BASE}/api/v1/agents/from-scene-template", json=body, headers=h, timeout=60)
|
|
if cr.status_code not in (200, 201):
|
|
print("创建失败:", cr.status_code, cr.text[:800], file=sys.stderr)
|
|
return 1
|
|
print(cr.json().get("id"), cr.json().get("name"))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|