mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 00:40:45 +08:00
重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。 Made-with: Cursor
This commit is contained in:
parent
ba3836f00f
commit
4a23b715a2
498 changed files with 2760 additions and 2200 deletions
|
|
@ -1,51 +1,11 @@
|
|||
param(
|
||||
[string]$Python = "python",
|
||||
[switch]$Recreate = $false
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\bootstrap_venv.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
function Fail([string]$msg) {
|
||||
Write-Host "[ERROR] $msg" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
& $real @args
|
||||
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
Set-Location $repoRoot
|
||||
|
||||
$venvDir = Join-Path $repoRoot "oclaw/.venv"
|
||||
$venvPython = Join-Path $venvDir "Scripts/python.exe"
|
||||
|
||||
$py = Get-Command $Python -ErrorAction SilentlyContinue
|
||||
if (-not $py) {
|
||||
Fail "python not found in PATH. Please install Python 3.10+ and retry."
|
||||
}
|
||||
|
||||
if ($Recreate -and (Test-Path $venvDir)) {
|
||||
Write-Step "Removing existing venv: $venvDir"
|
||||
Remove-Item -Recurse -Force $venvDir
|
||||
}
|
||||
|
||||
if (-not (Test-Path $venvPython)) {
|
||||
Write-Step "Creating venv: $venvDir"
|
||||
& $Python -m venv $venvDir
|
||||
}
|
||||
|
||||
if (-not (Test-Path $venvPython)) {
|
||||
Fail "venv python not found after creation: $venvPython"
|
||||
}
|
||||
|
||||
Write-Step "Upgrading pip"
|
||||
& $venvPython -m pip install -U pip
|
||||
|
||||
Write-Step "Installing requirements"
|
||||
& $venvPython -m pip install -r "requirements.txt"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "OK. Next:" -ForegroundColor Green
|
||||
Write-Host " powershell -ExecutionPolicy Bypass -File .\\oclaw\\scripts\\start_gateway.ps1"
|
||||
Write-Host ""
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import secrets
|
||||
import sys
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def main() -> int:
|
||||
store = SqliteStore(db_path())
|
||||
tenants = store.list_tenants(limit=1)
|
||||
if tenants:
|
||||
tenant_id = tenants[0]["id"]
|
||||
tenant_name = tenants[0]["name"]
|
||||
else:
|
||||
created = store.create_tenant("Team")
|
||||
tenant_id = created["id"]
|
||||
tenant_name = created["name"]
|
||||
|
||||
role = "member"
|
||||
if len(sys.argv) >= 2 and str(sys.argv[1]).strip():
|
||||
role = str(sys.argv[1]).strip()
|
||||
|
||||
code = secrets.token_urlsafe(6)
|
||||
store.create_bind_code(tenant_id=tenant_id, role=role, code=code)
|
||||
|
||||
print(f"tenant={tenant_name} ({tenant_id})")
|
||||
print(f"role={role}")
|
||||
print(f"bind_code={code}")
|
||||
print(f"wecom_cmd=bind {code}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
"""One-off helper: install additional npm MCP servers into local registry (stdio / npx).
|
||||
|
||||
Run from repo root: python oclaw/scripts/install_extra_mcp_batch.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# repo root
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from oclaw.platform.config.paths import db_path # noqa: E402
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore # noqa: E402
|
||||
from oclaw.tools.mcp.installer import McpServerManifest, _safe_server_id, install_mcp_server # noqa: E402
|
||||
|
||||
|
||||
# (server_id_seed, npm package ref, entry_args for npx)
|
||||
# Note: mcp-smart-crawler was tried; stdio JSON-RPC handshake failed on Windows — not registered.
|
||||
BATCH: list[tuple[str, str, list[str]]] = [
|
||||
("mcp-git-cyanheads", "@cyanheads/git-mcp-server", ["-y", "@cyanheads/git-mcp-server"]),
|
||||
]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
store = SqliteStore(db_path())
|
||||
for seed, source_ref, entry_args in BATCH:
|
||||
server_id = _safe_server_id(seed)
|
||||
manifest = McpServerManifest(
|
||||
server_id=server_id,
|
||||
source_type="npm",
|
||||
source_ref=source_ref,
|
||||
version="",
|
||||
entry_command="npx",
|
||||
entry_args=entry_args,
|
||||
env_schema={},
|
||||
permissions=[],
|
||||
risk_level="high",
|
||||
enabled=True,
|
||||
timeout_s=60.0,
|
||||
)
|
||||
print(f"\n=== Installing {server_id} ({source_ref}) ===")
|
||||
inst = install_mcp_server(manifest, dry_run=False)
|
||||
store.upsert_mcp_server(
|
||||
server_id=manifest.server_id,
|
||||
source_type=manifest.source_type,
|
||||
source_ref=manifest.source_ref,
|
||||
version=manifest.version,
|
||||
entry_command=manifest.entry_command,
|
||||
entry_args=manifest.entry_args,
|
||||
env_schema=manifest.env_schema,
|
||||
required_permissions=manifest.permissions,
|
||||
risk_level=manifest.risk_level,
|
||||
timeout_s=manifest.timeout_s,
|
||||
enabled=manifest.enabled if inst.ok else False,
|
||||
)
|
||||
store.add_mcp_installation_log(
|
||||
server_id=manifest.server_id,
|
||||
status="ok" if inst.ok else "error",
|
||||
error_code=inst.error_code,
|
||||
detail={"error": inst.error, **(inst.details or {})},
|
||||
install_command=inst.install_command,
|
||||
)
|
||||
print("ok:", inst.ok, inst.error_code or "-", inst.install_command)
|
||||
if not inst.ok:
|
||||
print("stderr snippet:", (inst.error or "")[:400])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
"""Install MCP: Context7 (up-to-date library docs) — npm global + registry + Sync Tools + generalist binding.
|
||||
|
||||
Run from repo root: python oclaw/scripts/install_mcp_context7.py
|
||||
|
||||
Requires CONTEXT7_API_KEY in src/_local/mcp_local.env or data/mcp_local.env (or environment). Default OPS_MCP_ENV_ALLOWLIST
|
||||
now includes CONTEXT7_API_KEY when unset; restart gateway after changing env.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from oclaw.platform.config.paths import db_path # noqa: E402
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore # noqa: E402
|
||||
from oclaw.tools.mcp.installer import McpServerManifest, install_mcp_server # noqa: E402
|
||||
from oclaw.tools.mcp.runtime import McpProcessRuntime # noqa: E402
|
||||
|
||||
_BINDING_KEY = "mcp_specialist_server_binding"
|
||||
|
||||
|
||||
def _sync_tools(store: SqliteStore, server_id: str) -> bool:
|
||||
rows = store.list_mcp_servers(enabled_only=False)
|
||||
row = next((x for x in rows if str(x.get("server_id") or "") == server_id), None)
|
||||
if not row:
|
||||
return False
|
||||
cmd = str(row.get("entry_command") or "").strip()
|
||||
args = [str(x) for x in (row.get("entry_args") or []) if str(x).strip()]
|
||||
if not cmd:
|
||||
return False
|
||||
rt = McpProcessRuntime([cmd] + args, timeout_s=float(row.get("timeout_s") or 60.0))
|
||||
try:
|
||||
h = rt.health()
|
||||
if not bool(h.get("ok")):
|
||||
store.set_mcp_server_health(server_id=server_id, status="error", detail=h)
|
||||
return False
|
||||
tr = rt.tools_list()
|
||||
items = tr.get("tools") if isinstance(tr, dict) else None
|
||||
if not isinstance(items, list) or not bool(tr.get("ok")):
|
||||
store.set_mcp_server_health(
|
||||
server_id=server_id,
|
||||
status="error",
|
||||
detail=tr if isinstance(tr, dict) else {"error": "tools_list_failed"},
|
||||
)
|
||||
return False
|
||||
norm: list[dict] = []
|
||||
for it in items:
|
||||
if not isinstance(it, dict):
|
||||
continue
|
||||
tool_name = str(it.get("tool_name") or it.get("name") or "").strip()
|
||||
if not tool_name:
|
||||
continue
|
||||
norm.append(
|
||||
{
|
||||
"tool_name": tool_name,
|
||||
"description": str(it.get("description") or ""),
|
||||
"parameters": it.get("parameters") if isinstance(it.get("parameters"), dict) else {},
|
||||
}
|
||||
)
|
||||
store.replace_mcp_server_tools(server_id=server_id, tools=norm)
|
||||
store.set_mcp_server_health(server_id=server_id, status="ok", detail={"synced_tools": len(norm)})
|
||||
return True
|
||||
finally:
|
||||
rt.stop()
|
||||
|
||||
|
||||
def _append_generalist_binding(store: SqliteStore, server_id: str) -> None:
|
||||
raw = str(store.get_setting(_BINDING_KEY) or "").strip()
|
||||
try:
|
||||
obj = json.loads(raw) if raw else {}
|
||||
except json.JSONDecodeError:
|
||||
obj = {}
|
||||
if not isinstance(obj, dict):
|
||||
obj = {}
|
||||
cur = obj.get("generalist")
|
||||
gl: list[str] = list(cur) if isinstance(cur, list) else []
|
||||
sid = str(server_id or "").strip()
|
||||
if sid and sid not in gl:
|
||||
gl.append(sid)
|
||||
obj["generalist"] = gl
|
||||
store.set_setting(_BINDING_KEY, json.dumps(obj, ensure_ascii=False))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
store = SqliteStore(db_path())
|
||||
manifest = McpServerManifest(
|
||||
server_id="mcp-context7",
|
||||
source_type="npm",
|
||||
source_ref="@upstash/context7-mcp",
|
||||
version="",
|
||||
entry_command="npx",
|
||||
entry_args=["-y", "@upstash/context7-mcp"],
|
||||
env_schema={
|
||||
"CONTEXT7_API_KEY": {
|
||||
"type": "string",
|
||||
"description": "Context7 API key (https://context7.com/dashboard)",
|
||||
}
|
||||
},
|
||||
permissions=[],
|
||||
risk_level="medium",
|
||||
enabled=True,
|
||||
timeout_s=60.0,
|
||||
)
|
||||
print(f"\n=== npm install {manifest.server_id} ({manifest.source_ref}) ===")
|
||||
inst = install_mcp_server(manifest, dry_run=False)
|
||||
store.upsert_mcp_server(
|
||||
server_id=manifest.server_id,
|
||||
source_type=manifest.source_type,
|
||||
source_ref=manifest.source_ref,
|
||||
version=manifest.version,
|
||||
entry_command=manifest.entry_command,
|
||||
entry_args=manifest.entry_args,
|
||||
env_schema=manifest.env_schema,
|
||||
required_permissions=manifest.permissions,
|
||||
risk_level=manifest.risk_level,
|
||||
timeout_s=manifest.timeout_s,
|
||||
enabled=manifest.enabled if inst.ok else False,
|
||||
)
|
||||
store.add_mcp_installation_log(
|
||||
server_id=manifest.server_id,
|
||||
status="ok" if inst.ok else "error",
|
||||
error_code=inst.error_code,
|
||||
detail={"error": inst.error, **(inst.details or {})},
|
||||
install_command=inst.install_command,
|
||||
)
|
||||
print("install ok:", inst.ok, inst.install_command)
|
||||
if not inst.ok:
|
||||
return
|
||||
print(f"=== sync tools {manifest.server_id} ===")
|
||||
synced = _sync_tools(store, manifest.server_id)
|
||||
print("sync ok:", synced)
|
||||
if synced:
|
||||
_append_generalist_binding(store, manifest.server_id)
|
||||
print("binding: appended mcp-context7 to generalist")
|
||||
else:
|
||||
print("Set CONTEXT7_API_KEY in src/_local/mcp_local.env (or data/mcp_local.env), restart gateway, then Admin → Sync Tools; save binding with mcp-context7 if needed.")
|
||||
|
||||
print("\nDone.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
"""Install MCP: SQLite (project DB), Brave Search, Google Calendar — npm global + registry upsert.
|
||||
|
||||
Run from repo root: python oclaw/scripts/install_mcp_sqlite_brave_calendar.py
|
||||
|
||||
Brave Search needs BRAVE_API_KEY in environment (+ OPS_MCP_ENV_ALLOWLIST includes it).
|
||||
Google Calendar needs GOOGLE_OAUTH_CREDENTIALS=path/to/oauth.json (+ allowlist).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from oclaw.platform.config.paths import db_path # noqa: E402
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore # noqa: E402
|
||||
from oclaw.tools.mcp.installer import McpServerManifest, install_mcp_server # noqa: E402
|
||||
from oclaw.tools.mcp.runtime import McpProcessRuntime # noqa: E402
|
||||
|
||||
|
||||
def _sync_tools(store: SqliteStore, server_id: str) -> bool:
|
||||
rows = store.list_mcp_servers(enabled_only=False)
|
||||
row = next((x for x in rows if str(x.get("server_id") or "") == server_id), None)
|
||||
if not row:
|
||||
return False
|
||||
cmd = str(row.get("entry_command") or "").strip()
|
||||
args = [str(x) for x in (row.get("entry_args") or []) if str(x).strip()]
|
||||
if not cmd:
|
||||
return False
|
||||
rt = McpProcessRuntime([cmd] + args, timeout_s=float(row.get("timeout_s") or 60.0))
|
||||
try:
|
||||
h = rt.health()
|
||||
if not bool(h.get("ok")):
|
||||
store.set_mcp_server_health(server_id=server_id, status="error", detail=h)
|
||||
return False
|
||||
tr = rt.tools_list()
|
||||
items = tr.get("tools") if isinstance(tr, dict) else None
|
||||
if not isinstance(items, list) or not bool(tr.get("ok")):
|
||||
store.set_mcp_server_health(server_id=server_id, status="error", detail=tr if isinstance(tr, dict) else {"error": "tools_list_failed"})
|
||||
return False
|
||||
norm: list[dict] = []
|
||||
for it in items:
|
||||
if not isinstance(it, dict):
|
||||
continue
|
||||
tool_name = str(it.get("tool_name") or it.get("name") or "").strip()
|
||||
if not tool_name:
|
||||
continue
|
||||
norm.append(
|
||||
{
|
||||
"tool_name": tool_name,
|
||||
"description": str(it.get("description") or ""),
|
||||
"parameters": it.get("parameters") if isinstance(it.get("parameters"), dict) else {},
|
||||
}
|
||||
)
|
||||
store.replace_mcp_server_tools(server_id=server_id, tools=norm)
|
||||
store.set_mcp_server_health(server_id=server_id, status="ok", detail={"synced_tools": len(norm)})
|
||||
return True
|
||||
finally:
|
||||
rt.stop()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
store = SqliteStore(db_path())
|
||||
db_file = db_path()
|
||||
|
||||
bundles: list[McpServerManifest] = [
|
||||
McpServerManifest(
|
||||
server_id="mcp-sqlite",
|
||||
source_type="npm",
|
||||
source_ref="mcp-sqlite",
|
||||
version="",
|
||||
entry_command="npx",
|
||||
entry_args=["-y", "mcp-sqlite", db_file],
|
||||
env_schema={},
|
||||
permissions=[],
|
||||
risk_level="high",
|
||||
enabled=True,
|
||||
timeout_s=90.0,
|
||||
),
|
||||
McpServerManifest(
|
||||
server_id="mcp-brave-search",
|
||||
source_type="npm",
|
||||
source_ref="@modelcontextprotocol/server-brave-search",
|
||||
version="",
|
||||
entry_command="npx",
|
||||
entry_args=["-y", "@modelcontextprotocol/server-brave-search"],
|
||||
env_schema={
|
||||
"BRAVE_API_KEY": {
|
||||
"type": "string",
|
||||
"description": "Brave Search API key (https://brave.com/search/api/)",
|
||||
}
|
||||
},
|
||||
permissions=[],
|
||||
risk_level="high",
|
||||
enabled=True,
|
||||
timeout_s=60.0,
|
||||
),
|
||||
McpServerManifest(
|
||||
server_id="mcp-google-calendar",
|
||||
source_type="npm",
|
||||
source_ref="@cocal/google-calendar-mcp",
|
||||
version="",
|
||||
entry_command="npx",
|
||||
entry_args=["-y", "@cocal/google-calendar-mcp"],
|
||||
env_schema={
|
||||
"GOOGLE_OAUTH_CREDENTIALS": {
|
||||
"type": "string",
|
||||
"description": "Absolute path to Google Cloud OAuth client JSON (Desktop app)",
|
||||
}
|
||||
},
|
||||
permissions=[],
|
||||
risk_level="high",
|
||||
enabled=True,
|
||||
timeout_s=120.0,
|
||||
),
|
||||
]
|
||||
|
||||
for manifest in bundles:
|
||||
print(f"\n=== npm install {manifest.server_id} ({manifest.source_ref}) ===")
|
||||
inst = install_mcp_server(manifest, dry_run=False)
|
||||
store.upsert_mcp_server(
|
||||
server_id=manifest.server_id,
|
||||
source_type=manifest.source_type,
|
||||
source_ref=manifest.source_ref,
|
||||
version=manifest.version,
|
||||
entry_command=manifest.entry_command,
|
||||
entry_args=manifest.entry_args,
|
||||
env_schema=manifest.env_schema,
|
||||
required_permissions=manifest.permissions,
|
||||
risk_level=manifest.risk_level,
|
||||
timeout_s=manifest.timeout_s,
|
||||
enabled=manifest.enabled if inst.ok else False,
|
||||
)
|
||||
store.add_mcp_installation_log(
|
||||
server_id=manifest.server_id,
|
||||
status="ok" if inst.ok else "error",
|
||||
error_code=inst.error_code,
|
||||
detail={"error": inst.error, **(inst.details or {})},
|
||||
install_command=inst.install_command,
|
||||
)
|
||||
print("install ok:", inst.ok, inst.install_command)
|
||||
if not inst.ok:
|
||||
continue
|
||||
print(f"=== sync tools {manifest.server_id} ===")
|
||||
ok = _sync_tools(store, manifest.server_id)
|
||||
print("sync ok:", ok)
|
||||
|
||||
print("\nDone. If Brave/Calendar show sync errors, set env vars and OPS_MCP_ENV_ALLOWLIST, then run Check Installed from Admin.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def _iter_jsonl(path: Path):
|
||||
for i, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
|
||||
s = line.strip()
|
||||
if not s:
|
||||
continue
|
||||
try:
|
||||
yield i, json.loads(s)
|
||||
except Exception as e:
|
||||
raise SystemExit(f"{path}: invalid json at line {i}: {e}") from e
|
||||
|
||||
|
||||
def main() -> int:
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
data_dir = root / "data" / "eval"
|
||||
if not data_dir.exists():
|
||||
print("offline_eval: no data/eval directory, skip")
|
||||
return 0
|
||||
files = sorted(p for p in data_dir.glob("*.jsonl"))
|
||||
if not files:
|
||||
print("offline_eval: no eval jsonl files, skip")
|
||||
return 0
|
||||
total = 0
|
||||
for fp in files:
|
||||
for line_no, obj in _iter_jsonl(fp):
|
||||
total += 1
|
||||
if not isinstance(obj, dict):
|
||||
raise SystemExit(f"{fp}:{line_no}: expected object")
|
||||
if not str(obj.get("id") or "").strip():
|
||||
raise SystemExit(f"{fp}:{line_no}: missing id")
|
||||
# Optional lightweight schema checks used by repo's eval fixtures.
|
||||
for k in ("assert_contains", "assert_not_contains"):
|
||||
if k in obj and not isinstance(obj.get(k), list):
|
||||
raise SystemExit(f"{fp}:{line_no}: {k} must be a list")
|
||||
print(f"offline_eval: ok files={len(files)} cases={total}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
"""将 oclaw/data/mcp_registry.seed.json 中的 MCP 定义写入本地 SQLite(与管理台 Install 等价)。
|
||||
|
||||
库表被清空、换库或新环境时:在项目根执行
|
||||
python oclaw/scripts/seed_mcp_registry.py
|
||||
可选:python oclaw/scripts/seed_mcp_registry.py path/to/other.seed.json
|
||||
|
||||
随后在各 MCP 上点 Health → Sync Tools;Context7 等需在 src/_local/mcp_local.env 配密钥。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from oclaw.platform.config.paths import PROJECT_ROOT, db_path # noqa: E402
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore # noqa: E402
|
||||
from oclaw.tools.mcp.installer import McpServerManifest, _safe_server_id, install_mcp_server # noqa: E402
|
||||
|
||||
|
||||
def _subst_repo(path_str: str) -> str:
|
||||
s = str(path_str or "").strip()
|
||||
if s.startswith("__REPO_ROOT__/"):
|
||||
return str((PROJECT_ROOT / s.replace("__REPO_ROOT__/", "", 1)).resolve())
|
||||
return s
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
seed_path = Path(argv[1]).resolve() if len(argv) > 1 else (ROOT / "data" / "mcp_registry.seed.json")
|
||||
if not seed_path.is_file():
|
||||
print(f"seed file not found: {seed_path}", file=sys.stderr)
|
||||
return 2
|
||||
raw = json.loads(seed_path.read_text(encoding="utf-8"))
|
||||
items = raw.get("servers") if isinstance(raw, dict) else raw
|
||||
if not isinstance(items, list) or not items:
|
||||
print("no servers[] in seed file", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
store = SqliteStore(db_path())
|
||||
ok_n = 0
|
||||
for payload in items:
|
||||
if not isinstance(payload, dict):
|
||||
continue
|
||||
source_type = str(payload.get("source_type") or "").strip().lower()
|
||||
source_ref = str(payload.get("source_ref") or "").strip()
|
||||
if source_type not in {"github", "npm", "pypi"} or not source_ref:
|
||||
print(f"skip invalid: {payload.get('server_id')!r}")
|
||||
continue
|
||||
server_id = _safe_server_id(str(payload.get("server_id") or source_ref))
|
||||
entry_args = [_subst_repo(x) for x in (payload.get("entry_args") or []) if str(x).strip()]
|
||||
manifest = McpServerManifest(
|
||||
server_id=server_id,
|
||||
source_type=source_type,
|
||||
source_ref=source_ref,
|
||||
version=str(payload.get("version") or "").strip(),
|
||||
entry_command=str(payload.get("entry_command") or "").strip(),
|
||||
entry_args=entry_args,
|
||||
env_schema=payload.get("env_schema") if isinstance(payload.get("env_schema"), dict) else {},
|
||||
permissions=[str(x) for x in (payload.get("required_permissions") or [])],
|
||||
risk_level=str(payload.get("risk_level") or "high"),
|
||||
enabled=bool(payload.get("enabled")),
|
||||
timeout_s=float(payload.get("timeout_s") or 30.0),
|
||||
)
|
||||
dry_run = bool(payload.get("dry_run", False))
|
||||
inst = install_mcp_server(manifest, dry_run=dry_run)
|
||||
store.upsert_mcp_server(
|
||||
server_id=manifest.server_id,
|
||||
source_type=manifest.source_type,
|
||||
source_ref=manifest.source_ref,
|
||||
version=manifest.version,
|
||||
entry_command=manifest.entry_command,
|
||||
entry_args=manifest.entry_args,
|
||||
env_schema=manifest.env_schema,
|
||||
required_permissions=manifest.permissions,
|
||||
risk_level=manifest.risk_level,
|
||||
timeout_s=manifest.timeout_s,
|
||||
enabled=manifest.enabled if inst.ok else False,
|
||||
)
|
||||
store.add_mcp_installation_log(
|
||||
server_id=manifest.server_id,
|
||||
status="ok" if inst.ok else "error",
|
||||
error_code=inst.error_code,
|
||||
detail={"error": inst.error, **(inst.details or {}), "seed": True},
|
||||
install_command=inst.install_command,
|
||||
)
|
||||
print(f"{server_id}: install_ok={inst.ok} enabled={manifest.enabled if inst.ok else False} cmd={inst.install_command[:120]!r}")
|
||||
if inst.ok:
|
||||
ok_n += 1
|
||||
print(f"done: {ok_n}/{len(items)} npm/pypi install steps succeeded; rows upserted for all valid entries.")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv))
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def _to_bool(v: str) -> str:
|
||||
return "1" if str(v).strip().lower() in ("1", "true", "yes", "on") else "0"
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = [str(x).strip() for x in sys.argv[1:]]
|
||||
if not args:
|
||||
print("usage:")
|
||||
print(" python -m scripts.set_wecom_auto_bind on|off")
|
||||
print(" python -m scripts.set_wecom_auto_bind on <tenant_name> <role>")
|
||||
print(" python -m scripts.set_wecom_auto_bind show")
|
||||
return 2
|
||||
|
||||
cmd = args[0].lower()
|
||||
store = SqliteStore(db_path())
|
||||
|
||||
if cmd == "show":
|
||||
enabled = str(store.get_setting("wecom_auto_bind_enabled") or "1").strip()
|
||||
tenant_name = str(store.get_setting("wecom_auto_bind_tenant_name") or "Team").strip() or "Team"
|
||||
role = str(store.get_setting("wecom_auto_bind_role") or "member").strip() or "member"
|
||||
print("ok=1")
|
||||
print(f"enabled={enabled}")
|
||||
print(f"tenant_name={tenant_name}")
|
||||
print(f"role={role}")
|
||||
return 0
|
||||
|
||||
if cmd not in ("on", "off"):
|
||||
print("error=invalid_command")
|
||||
return 2
|
||||
|
||||
enabled = _to_bool("1" if cmd == "on" else "0")
|
||||
tenant_name = (args[1] if len(args) >= 2 else "Team").strip() or "Team"
|
||||
role = (args[2] if len(args) >= 3 else "member").strip() or "member"
|
||||
|
||||
store.set_setting("wecom_auto_bind_enabled", enabled)
|
||||
store.set_setting("wecom_auto_bind_tenant_name", tenant_name)
|
||||
store.set_setting("wecom_auto_bind_role", role)
|
||||
|
||||
print("ok=1")
|
||||
print(f"enabled={enabled}")
|
||||
print(f"tenant_name={tenant_name}")
|
||||
print(f"role={role}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = [str(x).strip() for x in sys.argv[1:]]
|
||||
if not args:
|
||||
print("usage:")
|
||||
print(" python -m scripts.set_wecom_config <bot_id> <bot_secret>")
|
||||
return 2
|
||||
|
||||
store = SqliteStore(db_path())
|
||||
if len(args) < 2:
|
||||
print("error=missing_required_args")
|
||||
return 2
|
||||
bot_id, bot_secret = args[0], args[1]
|
||||
if not bot_id or not bot_secret:
|
||||
print("error=missing_required_args")
|
||||
return 2
|
||||
store.set_setting("wecom_mode", "bot_api")
|
||||
store.set_setting("wecom_bot_id", bot_id)
|
||||
store.set_secret("wecom_bot_secret", bot_secret)
|
||||
store.delete_setting("wecom_access_token_cache")
|
||||
print("ok=1")
|
||||
print("mode=bot_api")
|
||||
print("saved=wecom_bot_id,wecom_bot_secret(secret)")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -5,45 +5,16 @@ param(
|
|||
[switch]$Background = $false,
|
||||
[switch]$WithWeixin = $false,
|
||||
[switch]$WithWikiWorker = $false,
|
||||
[string]$WeixinChannelId = "openclaw-weixin",
|
||||
[string]$WeixinChannelId = "oclaw-weixin",
|
||||
[string]$WeixinGatewayBaseUrl = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\start_all.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
Set-Location $repoRoot
|
||||
|
||||
Write-Step "Starting gateway + desktop"
|
||||
|
||||
& "$PSScriptRoot/start_gateway.ps1" -BindHost $BindHost -Port $Port -SkipInstall:$SkipInstall -Background:$Background
|
||||
|
||||
# When gateway is started in foreground, the call above blocks; desktop won't start.
|
||||
if (-not $Background) {
|
||||
Write-Host ""
|
||||
Write-Host "[INFO] Gateway started in foreground and will block. Use -Background to start both." -ForegroundColor Yellow
|
||||
exit 0
|
||||
}
|
||||
|
||||
& "$PSScriptRoot/start_desktop.ps1" -SkipInstall:$SkipInstall -Background
|
||||
|
||||
if ($WithWeixin) {
|
||||
$gwBase = ($WeixinGatewayBaseUrl | ForEach-Object { "$_".Trim() })
|
||||
if (-not $gwBase) {
|
||||
$gwBase = "http://$BindHost`:$Port"
|
||||
}
|
||||
Write-Step "Starting weixin sidecar"
|
||||
& "$PSScriptRoot/weixin_start.ps1" -ChannelId $WeixinChannelId -GatewayBaseUrl $gwBase
|
||||
}
|
||||
if ($WithWikiWorker) {
|
||||
Write-Step "Starting wiki worker"
|
||||
& "$PSScriptRoot/start_wiki_worker.ps1" -Background
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "All started." -ForegroundColor Green
|
||||
& $real -BindHost $BindHost -Port $Port -SkipInstall:$SkipInstall -Background:$Background -WithWeixin:$WithWeixin -WithWikiWorker:$WithWikiWorker -WeixinChannelId $WeixinChannelId -WeixinGatewayBaseUrl $WeixinGatewayBaseUrl
|
||||
|
||||
|
|
|
|||
|
|
@ -1,49 +1,14 @@
|
|||
param(
|
||||
[switch]$SkipInstall = $false,
|
||||
[switch]$Background = $false,
|
||||
[switch]$KeepExistingGateway = $false
|
||||
[switch]$Background = $false
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
$desktopDir = Join-Path $repoRoot "oclaw\\desktop"
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
New-Item -ItemType Directory -Force -Path $runDir | Out-Null
|
||||
$pidFile = Join-Path $runDir "desktop.pid"
|
||||
$outLog = Join-Path $runDir "desktop.out.log"
|
||||
$errLog = Join-Path $runDir "desktop.err.log"
|
||||
|
||||
if (-not (Test-Path $desktopDir)) {
|
||||
Write-Host "[ERROR] desktop directory not found: $desktopDir" -ForegroundColor Red
|
||||
exit 1
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\start_desktop.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
Set-Location $desktopDir
|
||||
& $real -SkipInstall:$SkipInstall -Background:$Background
|
||||
|
||||
if (-not $KeepExistingGateway) {
|
||||
Write-Host "==> Cleaning previous gateway listener" -ForegroundColor Cyan
|
||||
try {
|
||||
& "$PSScriptRoot/stop_gateway.ps1" -Force
|
||||
} catch {
|
||||
Write-Host "[WARN] Failed to pre-stop gateway: $($_.Exception.Message)" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $SkipInstall) {
|
||||
Write-Host "==> Installing desktop dependencies" -ForegroundColor Cyan
|
||||
npm install
|
||||
}
|
||||
|
||||
Write-Host "==> Launching desktop app" -ForegroundColor Cyan
|
||||
if ($Background) {
|
||||
# Avoid launching npm.ps1 directly (can be file-associated and open in Notepad on some setups).
|
||||
# Use hidden cmd and redirect logs to avoid black console window popup.
|
||||
$p = Start-Process -FilePath "cmd.exe" -ArgumentList @("/c","npm.cmd","run","dev") -WorkingDirectory $desktopDir -PassThru -WindowStyle Hidden -RedirectStandardOutput $outLog -RedirectStandardError $errLog
|
||||
Set-Content -Path $pidFile -Value "$($p.Id)" -Encoding ascii
|
||||
Write-Host "desktop.pid = $pidFile" -ForegroundColor DarkGray
|
||||
Write-Host "desktop.out = $outLog" -ForegroundColor DarkGray
|
||||
Write-Host "desktop.err = $errLog" -ForegroundColor DarkGray
|
||||
Write-Host "PID = $($p.Id)" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
& "npm.cmd" "run" "dev"
|
||||
|
|
|
|||
|
|
@ -7,66 +7,10 @@ param(
|
|||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\start_gateway.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
function Fail([string]$msg) {
|
||||
Write-Host "[ERROR] $msg" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
Set-Location $repoRoot
|
||||
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
New-Item -ItemType Directory -Force -Path $runDir | Out-Null
|
||||
$pidFile = Join-Path $runDir "gateway.pid"
|
||||
|
||||
Write-Step "Project root: $repoRoot"
|
||||
|
||||
$venvPython = Join-Path $repoRoot "oclaw/.venv/Scripts/python.exe"
|
||||
if (Test-Path $venvPython) {
|
||||
Write-Step "Using venv python: $venvPython"
|
||||
$pythonExe = $venvPython
|
||||
} else {
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if (-not $pythonCmd) {
|
||||
Fail "python not found in PATH. Please install Python and retry."
|
||||
}
|
||||
Write-Step "Python detected: $($pythonCmd.Source)"
|
||||
$pythonExe = "python"
|
||||
}
|
||||
|
||||
if (-not $SkipInstall) {
|
||||
Write-Step "Installing dependencies (pip install -r requirements.txt)"
|
||||
& $pythonExe -m pip install -r "requirements.txt"
|
||||
} else {
|
||||
Write-Step "Skip dependency install"
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Step "Gateway URL"
|
||||
Write-Host "Admin: http://$BindHost`:$Port/admin"
|
||||
Write-Host "Chat: http://$BindHost`:$Port/chat"
|
||||
Write-Host "WS: ws://$BindHost`:$Port/ws"
|
||||
Write-Host ""
|
||||
|
||||
$configPath = Join-Path $repoRoot "oclaw\oclaw.json"
|
||||
if (Test-Path $configPath) {
|
||||
$env:OPENCLAW_CONFIG_PATH = $configPath
|
||||
Write-Step "Using OPENCLAW_CONFIG_PATH: $configPath"
|
||||
}
|
||||
|
||||
if ($Background) {
|
||||
Write-Step "Starting gateway in background"
|
||||
$p = Start-Process -FilePath $pythonExe -ArgumentList @("-m","oclaw.ops","gateway","start","--host",$BindHost,"--port",$Port) -WorkingDirectory $repoRoot -PassThru -WindowStyle Hidden
|
||||
Set-Content -Path $pidFile -Value "$($p.Id)" -Encoding ascii
|
||||
Write-Host "gateway.pid = $pidFile" -ForegroundColor DarkGray
|
||||
Write-Host "PID = $($p.Id)" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Step "Starting gateway (foreground)"
|
||||
& $pythonExe -m oclaw.ops gateway start --host $BindHost --port $Port
|
||||
& $real -BindHost $BindHost -Port $Port -SkipInstall:$SkipInstall -Background:$Background
|
||||
|
||||
|
|
|
|||
|
|
@ -1,70 +1,16 @@
|
|||
param(
|
||||
[string]$Channel = "wecom",
|
||||
[switch]$SkipInstall = $false,
|
||||
[switch]$SkipConfigHint = $false
|
||||
[switch]$SkipConfigHint = $false,
|
||||
[switch]$Background = $false
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\start_ops.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
function Fail([string]$msg) {
|
||||
Write-Host "[ERROR] $msg" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
Set-Location $repoRoot
|
||||
|
||||
Write-Step "Project root: $repoRoot"
|
||||
|
||||
$venvPython = Join-Path $repoRoot "oclaw/.venv/Scripts/python.exe"
|
||||
if (Test-Path $venvPython) {
|
||||
Write-Step "Using venv python: $venvPython"
|
||||
$pythonExe = $venvPython
|
||||
} else {
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if (-not $pythonCmd) {
|
||||
Fail "python not found in PATH. Please install Python 3.10+ and retry."
|
||||
}
|
||||
Write-Step "Python detected: $($pythonCmd.Source)"
|
||||
$pythonExe = "python"
|
||||
}
|
||||
|
||||
if (-not $SkipInstall) {
|
||||
Write-Step "Installing dependencies (pip install -r requirements.txt)"
|
||||
& $pythonExe -m pip install -r "requirements.txt"
|
||||
} else {
|
||||
Write-Step "Skip dependency install"
|
||||
}
|
||||
|
||||
if (-not $SkipConfigHint) {
|
||||
Write-Step "Current WeCom status"
|
||||
try {
|
||||
python -m oclaw.ops channel wecom status
|
||||
} catch {
|
||||
Write-Host "[WARN] Unable to read WeCom status yet." -ForegroundColor Yellow
|
||||
}
|
||||
Write-Host ""
|
||||
Write-Host "If WeCom is not configured yet, run this first:" -ForegroundColor Yellow
|
||||
Write-Host " python -m oclaw.ops channel wecom config --help"
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
Write-Step "Stopping previous stack (safe if not running)"
|
||||
& $pythonExe -m oclaw.ops stack down
|
||||
|
||||
Write-Step "Starting stack: python -m oclaw.ops stack up --channel $Channel"
|
||||
& $pythonExe -m oclaw.ops stack up --channel $Channel
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Started successfully." -ForegroundColor Green
|
||||
Write-Host "Admin: http://127.0.0.1:8787/admin"
|
||||
Write-Host "Chat: http://127.0.0.1:8787/chat"
|
||||
Write-Host ""
|
||||
Write-Host "Useful commands:"
|
||||
Write-Host " python -m oclaw.ops stack status"
|
||||
Write-Host " python -m oclaw.ops stack down"
|
||||
& $real -Channel $Channel -SkipInstall:$SkipInstall -SkipConfigHint:$SkipConfigHint -Background:$Background
|
||||
|
||||
|
|
|
|||
|
|
@ -1,81 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
CHANNEL="wecom"
|
||||
SKIP_INSTALL=0
|
||||
SKIP_CONFIG_HINT=0
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--no-ui)
|
||||
# Kept for compatibility; stack no longer starts Streamlit.
|
||||
shift
|
||||
;;
|
||||
--channel)
|
||||
CHANNEL="${2:-wecom}"
|
||||
shift 2
|
||||
;;
|
||||
--skip-install)
|
||||
SKIP_INSTALL=1
|
||||
shift
|
||||
;;
|
||||
--skip-config-hint)
|
||||
SKIP_CONFIG_HINT=1
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown arg: $1"
|
||||
echo "Usage: $0 [--no-ui] [--channel wecom] [--skip-install] [--skip-config-hint]"
|
||||
echo "Note: --no-ui is legacy; stack does not start Streamlit. Chat: http://127.0.0.1:8787/chat"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
step() { printf '\n==> %s\n' "$1"; }
|
||||
|
||||
if ! command -v python >/dev/null 2>&1; then
|
||||
echo "[ERROR] python not found in PATH." >&2
|
||||
REAL_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../runtime/operations/scripts" && pwd)/start_ops.sh"
|
||||
if [[ ! -f "$REAL_PATH" ]]; then
|
||||
echo "[ERROR] Forward script target not found: $REAL_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
step "Project root: $ROOT_DIR"
|
||||
step "Python: $(command -v python)"
|
||||
|
||||
if [[ "$SKIP_INSTALL" -eq 0 ]]; then
|
||||
step "Installing dependencies"
|
||||
python -m pip install -r requirements.txt
|
||||
else
|
||||
step "Skip dependency install"
|
||||
fi
|
||||
|
||||
if [[ "$SKIP_CONFIG_HINT" -eq 0 ]]; then
|
||||
step "Current WeCom status"
|
||||
python -m oclaw.ops channel wecom status || true
|
||||
cat <<'EOF'
|
||||
|
||||
If WeCom is not configured yet, run:
|
||||
python -m oclaw.ops channel wecom config --help
|
||||
EOF
|
||||
fi
|
||||
|
||||
step "Stopping previous stack"
|
||||
python -m oclaw.ops stack down || true
|
||||
|
||||
step "Starting stack"
|
||||
python -m oclaw.ops stack up --channel "$CHANNEL"
|
||||
|
||||
cat <<'EOF'
|
||||
|
||||
Started successfully.
|
||||
Admin: http://127.0.0.1:8787/admin
|
||||
Chat: http://127.0.0.1:8787/chat
|
||||
|
||||
Useful commands:
|
||||
python -m oclaw.ops stack status
|
||||
python -m oclaw.ops stack down
|
||||
EOF
|
||||
exec bash "$REAL_PATH" "$@"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
param(
|
||||
[string]$BindHost = "127.0.0.1",
|
||||
[int]$Port = 8787,
|
||||
[switch]$SkipInstall = $false,
|
||||
[switch]$Background = $false
|
||||
)
|
||||
param()
|
||||
|
||||
# 网页端(/admin、/chat)由网关进程提供,这里只是一个语义化别名。
|
||||
& "$PSScriptRoot/start_gateway.ps1" -BindHost $BindHost -Port $Port -SkipInstall:$SkipInstall -Background:$Background
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\start_web.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,13 @@
|
|||
param(
|
||||
[switch]$Background = $true
|
||||
[switch]$Background = $false
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-RepoRoot {
|
||||
$here = Split-Path -Parent $PSCommandPath
|
||||
return (Resolve-Path (Join-Path $here "..")).Path
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\start_wiki_worker.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$repoRoot = Resolve-RepoRoot
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
$null = New-Item -ItemType Directory -Force -Path $runDir -ErrorAction SilentlyContinue
|
||||
$pidFile = Join-Path $runDir "wiki_worker.pid"
|
||||
$outLog = Join-Path $runDir "wiki_worker.out.log"
|
||||
$errLog = Join-Path $runDir "wiki_worker.err.log"
|
||||
& $real -Background:$Background
|
||||
|
||||
$venvPython = Join-Path $repoRoot "oclaw/.venv/Scripts/python.exe"
|
||||
if (Test-Path $venvPython) {
|
||||
$pythonExe = $venvPython
|
||||
} else {
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if (-not $pythonCmd) {
|
||||
throw "python not found in PATH"
|
||||
}
|
||||
$pythonExe = "python"
|
||||
}
|
||||
|
||||
if (-not $Background) {
|
||||
& $pythonExe -m src.wiki_worker.main
|
||||
exit 0
|
||||
}
|
||||
|
||||
$p = Start-Process -FilePath $pythonExe -ArgumentList @("-m", "src.wiki_worker.main") -WorkingDirectory $repoRoot -PassThru -WindowStyle Hidden -RedirectStandardOutput $outLog -RedirectStandardError $errLog
|
||||
Set-Content -Path $pidFile -Value $p.Id -Encoding ascii
|
||||
Write-Host "[ok] started wiki worker pid=$($p.Id) out=$outLog err=$errLog"
|
||||
|
|
|
|||
|
|
@ -1,140 +1,11 @@
|
|||
param(
|
||||
[string]$BindHost = "127.0.0.1",
|
||||
[int]$Port = 8787,
|
||||
[switch]$WithWeixin = $false,
|
||||
[switch]$WithWikiWorker = $false,
|
||||
[string]$WeixinChannelId = "openclaw-weixin"
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\status_all.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
function Warn([string]$msg) {
|
||||
Write-Host "[WARN] $msg" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
$null = New-Item -ItemType Directory -Force -Path $runDir -ErrorAction SilentlyContinue
|
||||
$gwPidFile = Join-Path $runDir "gateway.pid"
|
||||
$desktopPidFile = Join-Path $runDir "desktop.pid"
|
||||
|
||||
Write-Step "URLs"
|
||||
Write-Host "Admin: http://$BindHost`:$Port/admin"
|
||||
Write-Host "Chat: http://$BindHost`:$Port/chat"
|
||||
Write-Host "WS: ws://$BindHost`:$Port/ws"
|
||||
Write-Host ""
|
||||
|
||||
Write-Step "PID files"
|
||||
if (Test-Path $gwPidFile) {
|
||||
$gwPid = (Get-Content $gwPidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
Write-Host "gateway.pid: $gwPidFile => $gwPid"
|
||||
} else {
|
||||
Warn "gateway.pid not found: $gwPidFile"
|
||||
}
|
||||
if (Test-Path $desktopPidFile) {
|
||||
$deskPid = (Get-Content $desktopPidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
Write-Host "desktop.pid: $desktopPidFile => $deskPid"
|
||||
} else {
|
||||
Warn "desktop.pid not found: $desktopPidFile"
|
||||
}
|
||||
Write-Host ""
|
||||
|
||||
Write-Step "Port listener"
|
||||
try {
|
||||
$conns = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue
|
||||
if (-not $conns) {
|
||||
Warn "No listener on port $Port"
|
||||
exit 0
|
||||
}
|
||||
$pids = $conns | Select-Object -ExpandProperty OwningProcess -Unique
|
||||
Write-Host "Listening on port $Port; OwningProcess: $($pids -join ', ')"
|
||||
|
||||
# Self-heal: if we have a single owning pid and no gateway.pid, write it back.
|
||||
if (-not (Test-Path $gwPidFile)) {
|
||||
$pidList = @()
|
||||
foreach ($x in @($pids)) {
|
||||
$n = 0
|
||||
if ([int]::TryParse([string]$x, [ref]$n) -and $n -gt 0) {
|
||||
$pidList += $n
|
||||
}
|
||||
}
|
||||
if ($pidList.Count -eq 1) {
|
||||
$procId = [int]$pidList[0]
|
||||
try {
|
||||
$null = Get-Process -Id $procId -ErrorAction Stop
|
||||
Set-Content -Path $gwPidFile -Value "$procId" -Encoding ascii
|
||||
Write-Host "Wrote gateway.pid => $procId" -ForegroundColor Green
|
||||
} catch {
|
||||
Warn "Cannot verify process for PID=$procId; not writing pid file."
|
||||
}
|
||||
} else {
|
||||
# Heuristic: try to pick the gateway python/uvicorn process.
|
||||
$candidates = @()
|
||||
foreach ($p in $pidList) {
|
||||
try {
|
||||
$proc = Get-Process -Id $p -ErrorAction Stop
|
||||
$name = [string]$proc.ProcessName
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
$cmd = ""
|
||||
try {
|
||||
$wmi = Get-CimInstance Win32_Process -Filter "ProcessId=$p" -ErrorAction SilentlyContinue
|
||||
if ($wmi -and $wmi.CommandLine) { $cmd = [string]$wmi.CommandLine }
|
||||
} catch {
|
||||
$cmd = ""
|
||||
}
|
||||
if ($cmd) {
|
||||
$low = ([string]$cmd).ToLowerInvariant()
|
||||
} else {
|
||||
$low = ""
|
||||
}
|
||||
$score = 0
|
||||
if ($name -match "python") { $score += 2 }
|
||||
if ($low -match "uvicorn") { $score += 2 }
|
||||
if ($low -match "src\.ops") { $score += 2 }
|
||||
if ($low -match "gateway\s+start") { $score += 2 }
|
||||
if ($low -match "fastapi_app") { $score += 1 }
|
||||
$candidates += [pscustomobject]@{ Pid = [int]$p; Name = $name; Score = [int]$score; Cmd = $cmd }
|
||||
}
|
||||
$best = $candidates | Sort-Object -Property Score -Descending | Select-Object -First 1
|
||||
if ($best -and $best.Score -ge 2) {
|
||||
try {
|
||||
$null = Get-Process -Id $best.Pid -ErrorAction Stop
|
||||
Set-Content -Path $gwPidFile -Value "$($best.Pid)" -Encoding ascii
|
||||
Write-Host "Wrote gateway.pid => $($best.Pid) ($($best.Name))" -ForegroundColor Green
|
||||
} catch {
|
||||
Warn "Cannot verify process for PID=$($best.Pid); not writing pid file."
|
||||
}
|
||||
} else {
|
||||
Warn "Multiple owning processes for port $Port; cannot confidently pick gateway PID."
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Warn "Get-NetTCPConnection failed: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if ($WithWeixin) {
|
||||
Write-Host ""
|
||||
Write-Step "Weixin sidecar"
|
||||
try {
|
||||
& "$PSScriptRoot/weixin_status.ps1" -ChannelId $WeixinChannelId
|
||||
} catch {
|
||||
Warn "weixin status failed: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
if ($WithWikiWorker) {
|
||||
Write-Host ""
|
||||
Write-Step "Wiki worker"
|
||||
try {
|
||||
& "$PSScriptRoot/status_wiki_worker.ps1"
|
||||
} catch {
|
||||
Warn "wiki worker status failed: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,11 @@
|
|||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\status_ops.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
Set-Location $repoRoot
|
||||
|
||||
Write-Step "Project root: $repoRoot"
|
||||
Write-Step "Stack status"
|
||||
python -m oclaw.ops stack status
|
||||
|
||||
Write-Host ""
|
||||
Write-Step "WeCom status"
|
||||
python -m oclaw.ops channel wecom status
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Admin: http://127.0.0.1:8787/admin"
|
||||
Write-Host "Chat: http://127.0.0.1:8787/chat"
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
REAL_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../runtime/operations/scripts" && pwd)/status_ops.sh"
|
||||
if [[ ! -f "$REAL_PATH" ]]; then
|
||||
echo "[ERROR] Forward script target not found: $REAL_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '==> Project root: %s\n' "$ROOT_DIR"
|
||||
printf '==> Stack status\n'
|
||||
python -m oclaw.ops stack status
|
||||
|
||||
printf '\n==> WeCom status\n'
|
||||
python -m oclaw.ops channel wecom status
|
||||
|
||||
cat <<'EOF'
|
||||
|
||||
Admin: http://127.0.0.1:8787/admin
|
||||
Chat: http://127.0.0.1:8787/chat
|
||||
EOF
|
||||
exec bash "$REAL_PATH" "$@"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,11 @@
|
|||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
$pidFile = Join-Path $runDir "wiki_worker.pid"
|
||||
|
||||
if (-not (Test-Path $pidFile)) {
|
||||
Write-Host "status=stopped"
|
||||
exit 0
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\status_wiki_worker.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$procId = (Get-Content -Path $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
if (-not $procId) {
|
||||
Write-Host "status=stopped"
|
||||
exit 0
|
||||
}
|
||||
& $real @args
|
||||
|
||||
try {
|
||||
Get-Process -Id $procId -ErrorAction Stop | Out-Null
|
||||
Write-Host "status=running pid=$procId"
|
||||
} catch {
|
||||
Write-Host "status=stale_pid pid=$procId"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,11 @@
|
|||
param(
|
||||
[int]$Port = 8787,
|
||||
[switch]$Force = $false,
|
||||
[switch]$WithWeixin = $false,
|
||||
[switch]$WithWikiWorker = $false,
|
||||
[string]$WeixinChannelId = "openclaw-weixin"
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\stop_all.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
Write-Step "Stopping desktop"
|
||||
try {
|
||||
& "$PSScriptRoot/stop_desktop.ps1" -Force:$Force
|
||||
} catch {
|
||||
if (-not $Force) { throw }
|
||||
}
|
||||
|
||||
Write-Step "Stopping gateway/web"
|
||||
try {
|
||||
& "$PSScriptRoot/stop_gateway.ps1" -Port $Port -Force:$Force
|
||||
} catch {
|
||||
if (-not $Force) { throw }
|
||||
}
|
||||
|
||||
if ($WithWeixin) {
|
||||
Write-Step "Stopping weixin sidecar"
|
||||
try {
|
||||
& "$PSScriptRoot/weixin_stop.ps1" -ChannelId $WeixinChannelId -Force:$Force
|
||||
} catch {
|
||||
if (-not $Force) { throw }
|
||||
}
|
||||
}
|
||||
if ($WithWikiWorker) {
|
||||
Write-Step "Stopping wiki worker"
|
||||
try {
|
||||
& "$PSScriptRoot/stop_wiki_worker.ps1" -Force:$Force
|
||||
} catch {
|
||||
if (-not $Force) { throw }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "All stopped." -ForegroundColor Green
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,11 @@
|
|||
param(
|
||||
[switch]$Force = $false
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\stop_desktop.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
function Warn([string]$msg) {
|
||||
Write-Host "[WARN] $msg" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
$pidFile = Join-Path $runDir "desktop.pid"
|
||||
|
||||
Write-Step "Stopping desktop app"
|
||||
|
||||
if (-not (Test-Path $pidFile)) {
|
||||
Warn "No PID file found: $pidFile"
|
||||
if (-not $Force) { exit 0 }
|
||||
}
|
||||
|
||||
$raw = (Get-Content $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
$procId = 0
|
||||
[void][int]::TryParse([string]$raw, [ref]$procId)
|
||||
if ($procId -le 0) {
|
||||
Warn "Invalid PID in $pidFile"
|
||||
if (-not $Force) { exit 1 }
|
||||
exit 0
|
||||
}
|
||||
|
||||
try {
|
||||
# Kill the whole process tree (cmd -> npm -> electron/node)
|
||||
& taskkill /PID $procId /T /F | Out-Null
|
||||
Write-Host "Stopped PID=$procId (tree)" -ForegroundColor Green
|
||||
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
||||
exit 0
|
||||
} catch {
|
||||
Warn "Failed to stop PID=$procId : $($_.Exception.Message)"
|
||||
if (-not $Force) { exit 1 }
|
||||
exit 0
|
||||
}
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,62 +1,11 @@
|
|||
param(
|
||||
[int]$Port = 8787,
|
||||
[switch]$Force = $false
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\stop_gateway.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
function Warn([string]$msg) {
|
||||
Write-Host "[WARN] $msg" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
function Kill-ProcId([int]$procId) {
|
||||
try {
|
||||
Stop-Process -Id $procId -Force
|
||||
Write-Host "Stopped PID=$procId" -ForegroundColor Green
|
||||
return $true
|
||||
} catch {
|
||||
Warn "Failed to stop PID=$procId : $($_.Exception.Message)"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
$pidFile = Join-Path $runDir "gateway.pid"
|
||||
|
||||
Write-Step "Stopping gateway"
|
||||
|
||||
if (Test-Path $pidFile) {
|
||||
$raw = (Get-Content $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
$procId = 0
|
||||
[void][int]::TryParse([string]$raw, [ref]$procId)
|
||||
if ($procId -gt 0) {
|
||||
$ok = Kill-ProcId -procId $procId
|
||||
if ($ok) {
|
||||
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
||||
exit 0
|
||||
}
|
||||
if (-not $Force) { exit 1 }
|
||||
}
|
||||
}
|
||||
|
||||
Write-Step "No PID file; attempting to stop by port $Port"
|
||||
try {
|
||||
$conns = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue
|
||||
if (-not $conns) {
|
||||
Warn "No listener found on port $Port"
|
||||
exit 0
|
||||
}
|
||||
$pids = $conns | Select-Object -ExpandProperty OwningProcess -Unique
|
||||
foreach ($p in $pids) {
|
||||
if ($p -gt 0) { [void](Kill-ProcId -procId $p) }
|
||||
}
|
||||
exit 0
|
||||
} catch {
|
||||
Warn "Stop by port failed: $($_.Exception.Message)"
|
||||
if (-not $Force) { exit 1 }
|
||||
}
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,11 @@
|
|||
param(
|
||||
[switch]$Force = $false
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Step([string]$msg) {
|
||||
Write-Host "==> $msg" -ForegroundColor Cyan
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\stop_ops.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
|
||||
Set-Location $repoRoot
|
||||
|
||||
Write-Step "Project root: $repoRoot"
|
||||
Write-Step "Stopping stack services..."
|
||||
|
||||
try {
|
||||
python -m oclaw.ops stack down
|
||||
Write-Host "Stack stopped." -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[WARN] stack down failed: $($_.Exception.Message)" -ForegroundColor Yellow
|
||||
if (-not $Force) {
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Write-Step "Current status"
|
||||
try {
|
||||
python -m oclaw.ops stack status
|
||||
} catch {
|
||||
Write-Host "[WARN] Unable to read status after stop." -ForegroundColor Yellow
|
||||
}
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "$ROOT_DIR"
|
||||
REAL_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../runtime/operations/scripts" && pwd)/stop_ops.sh"
|
||||
if [[ ! -f "$REAL_PATH" ]]; then
|
||||
echo "[ERROR] Forward script target not found: $REAL_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '==> Project root: %s\n' "$ROOT_DIR"
|
||||
printf '==> Stopping stack services...\n'
|
||||
python -m oclaw.ops stack down || true
|
||||
|
||||
printf '\n==> Current status\n'
|
||||
python -m oclaw.ops stack status || true
|
||||
exec bash "$REAL_PATH" "$@"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
param(
|
||||
[int]$Port = 8787,
|
||||
[switch]$Force = $false
|
||||
)
|
||||
param()
|
||||
|
||||
# 网页端(/admin、/chat)由网关进程提供,这里只是一个语义化别名。
|
||||
& "$PSScriptRoot/stop_gateway.ps1" -Port $Port -Force:$Force
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\stop_web.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
& $real @args
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +1,11 @@
|
|||
param(
|
||||
[switch]$Force
|
||||
)
|
||||
param()
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$runDir = Join-Path $PSScriptRoot ".run"
|
||||
$pidFile = Join-Path $runDir "wiki_worker.pid"
|
||||
|
||||
if (-not (Test-Path $pidFile)) {
|
||||
Write-Host "[ok] not running (no pid file)"
|
||||
exit 0
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\stop_wiki_worker.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$procId = (Get-Content -Path $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
if (-not $procId) {
|
||||
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
|
||||
Write-Host "[ok] not running (empty pid file)"
|
||||
exit 0
|
||||
}
|
||||
& $real @args
|
||||
|
||||
try {
|
||||
if ($Force) {
|
||||
taskkill.exe /PID $procId /T /F | Out-Null
|
||||
} else {
|
||||
taskkill.exe /PID $procId /T | Out-Null
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
|
||||
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
|
||||
Write-Host "[ok] stopped pid=$procId"
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
_CLEAR_KEYS = [
|
||||
"wecom_access_token_cache",
|
||||
"wecom_last_msg_ts",
|
||||
"wecom_last_from_user",
|
||||
"wecom_recent_from_users",
|
||||
"wecom_last_cmd",
|
||||
"wecom_last_unknown_cmd_payload",
|
||||
"wecom_last_raw_body",
|
||||
"wecom_last_raw_from_user",
|
||||
"wecom_last_parse_error",
|
||||
]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = [str(x).strip() for x in sys.argv[1:]]
|
||||
if len(args) < 2:
|
||||
print("usage: python -m scripts.switch_wecom_bot <bot_id> <bot_secret>")
|
||||
return 2
|
||||
bot_id, bot_secret = args[0], args[1]
|
||||
if not bot_id or not bot_secret:
|
||||
print("error=missing_required_args")
|
||||
return 2
|
||||
|
||||
store = SqliteStore(db_path())
|
||||
store.set_setting("wecom_mode", "bot_api")
|
||||
store.set_setting("wecom_bot_id", bot_id)
|
||||
store.set_secret("wecom_bot_secret", bot_secret)
|
||||
for k in _CLEAR_KEYS:
|
||||
store.delete_setting(k)
|
||||
|
||||
print("ok=1")
|
||||
print("mode=bot_api")
|
||||
print(f"bot_id={bot_id}")
|
||||
print("cleared=" + ",".join(_CLEAR_KEYS))
|
||||
print("next=python -m oclaw.ops stack up --channel wecom")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
_CLEAR_KEYS = [
|
||||
"wecom_mode",
|
||||
"wecom_bot_id",
|
||||
"wecom_bot_secret",
|
||||
"wecom_corp_id",
|
||||
"wecom_agent_id",
|
||||
"wecom_agent_secret",
|
||||
"wecom_access_token_cache",
|
||||
"wecom_last_msg_ts",
|
||||
"wecom_last_from_user",
|
||||
"wecom_recent_from_users",
|
||||
"wecom_last_cmd",
|
||||
"wecom_last_unknown_cmd_payload",
|
||||
"wecom_last_raw_body",
|
||||
"wecom_last_raw_from_user",
|
||||
"wecom_last_parse_error",
|
||||
]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
store = SqliteStore(db_path())
|
||||
with store._connect() as conn: # internal cleanup script; safe to use store connection helper
|
||||
cur_ident = conn.execute("DELETE FROM channel_identity WHERE channel = ?", ("wecom",))
|
||||
ident_deleted = int(cur_ident.rowcount or 0)
|
||||
cur_sess = conn.execute("DELETE FROM channel_session WHERE channel = ?", ("wecom",))
|
||||
sess_deleted = int(cur_sess.rowcount or 0)
|
||||
|
||||
for k in _CLEAR_KEYS:
|
||||
store.delete_setting(k)
|
||||
|
||||
print("ok=1")
|
||||
print("action=unbind_wecom_bot")
|
||||
print(f"deleted_channel_identity={ident_deleted}")
|
||||
print(f"deleted_channel_session={sess_deleted}")
|
||||
print("cleared_settings=" + ",".join(_CLEAR_KEYS))
|
||||
print("next=python -m oclaw.ops channel wecom config set --type bot --bot-id <bot_id> --bot-secret <bot_secret>")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -1,60 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.integrations.wecom_client import WeComClient
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def main() -> int:
|
||||
store = SqliteStore(db_path())
|
||||
client = WeComClient(store)
|
||||
try:
|
||||
bot_id, _bot_secret = client.get_bot_credentials()
|
||||
except Exception as exc:
|
||||
print("ok=0")
|
||||
print("step=read_bot_config")
|
||||
print(f"error={type(exc).__name__}: {exc}")
|
||||
return 1
|
||||
print("ok=1")
|
||||
print("mode=bot_api")
|
||||
print(f"bot_id={bot_id}")
|
||||
if "--ws" not in sys.argv[1:]:
|
||||
print("ws_skipped=1")
|
||||
print("hint=use --ws for subscribe handshake test")
|
||||
return 0
|
||||
try:
|
||||
import websocket # type: ignore
|
||||
except Exception:
|
||||
print("ok=0")
|
||||
print("step=import_websocket_client")
|
||||
print("error=websocket-client not installed, run: pip install websocket-client")
|
||||
return 1
|
||||
try:
|
||||
ws = websocket.create_connection("wss://openws.work.weixin.qq.com", timeout=15)
|
||||
ws.send(
|
||||
json.dumps(
|
||||
{
|
||||
"cmd": "aibot_subscribe",
|
||||
"headers": {"req_id": uuid.uuid4().hex},
|
||||
"body": {"bot_id": bot_id, "secret": client.get_bot_credentials()[1]},
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
raw = ws.recv()
|
||||
ws.close()
|
||||
print("ws_subscribe_response=" + str(raw))
|
||||
return 0
|
||||
except Exception as exc:
|
||||
print("ok=0")
|
||||
print("step=ws_subscribe")
|
||||
print(f"error={type(exc).__name__}: {exc}")
|
||||
return 1
|
||||
from oclaw.runtime.operations.scripts.wecom_smoke_test import main
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
|
|
|
|||
|
|
@ -1,78 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.integrations.wecom_client import WeComClient
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def _fmt_ts(ts: str) -> str:
|
||||
try:
|
||||
n = int(str(ts).strip())
|
||||
return datetime.fromtimestamp(n, tz=timezone.utc).astimezone().isoformat()
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def main() -> int:
|
||||
store = SqliteStore(db_path())
|
||||
client = WeComClient(store)
|
||||
print("ok=1")
|
||||
print(f"mode={client.mode()}")
|
||||
bot_id = str(store.get_setting("wecom_bot_id") or "").strip()
|
||||
print(f"bot_id={bot_id}")
|
||||
|
||||
auto_bind = str(store.get_setting("wecom_auto_bind_enabled") or "1").strip()
|
||||
auto_tenant = str(store.get_setting("wecom_auto_bind_tenant_name") or "Team").strip() or "Team"
|
||||
auto_role = str(store.get_setting("wecom_auto_bind_role") or "member").strip() or "member"
|
||||
print(f"auto_bind_enabled={auto_bind}")
|
||||
print(f"auto_bind_tenant={auto_tenant}")
|
||||
print(f"auto_bind_role={auto_role}")
|
||||
|
||||
last_ts = str(store.get_setting("wecom_last_msg_ts") or "").strip()
|
||||
last_user = str(store.get_setting("wecom_last_from_user") or "").strip()
|
||||
last_cmd = str(store.get_setting("wecom_last_cmd") or "").strip()
|
||||
last_raw_from_user = str(store.get_setting("wecom_last_raw_from_user") or "").strip()
|
||||
last_parse_error = str(store.get_setting("wecom_last_parse_error") or "").strip()
|
||||
last_outbound_mode = str(store.get_setting("wecom_last_outbound_mode") or "").strip()
|
||||
last_outbound_error = str(store.get_setting("wecom_last_outbound_error") or "").strip()
|
||||
print(f"last_from_user={last_user}")
|
||||
print(f"last_raw_from_user={last_raw_from_user}")
|
||||
print(f"last_cmd={last_cmd}")
|
||||
print(f"last_parse_error={last_parse_error}")
|
||||
print(f"last_outbound_mode={last_outbound_mode}")
|
||||
print(f"last_outbound_error={last_outbound_error}")
|
||||
print(f"last_msg_ts={last_ts}")
|
||||
print(f"last_msg_local={_fmt_ts(last_ts)}")
|
||||
|
||||
raw_recent = str(store.get_setting("wecom_recent_from_users") or "[]")
|
||||
try:
|
||||
recent = json.loads(raw_recent)
|
||||
except Exception:
|
||||
recent = []
|
||||
if not isinstance(recent, list):
|
||||
recent = []
|
||||
print("recent_from_users=" + json.dumps(recent[:20], ensure_ascii=False))
|
||||
|
||||
idents = store.list_channel_identities(channel="wecom", limit=50)
|
||||
print(f"bound_identities={len(idents)}")
|
||||
for x in idents[:20]:
|
||||
print(
|
||||
"identity="
|
||||
+ json.dumps(
|
||||
{
|
||||
"external_user_id": x.get("external_user_id"),
|
||||
"display_name": x.get("display_name"),
|
||||
"role": x.get("role"),
|
||||
"tenant_id": x.get("tenant_id"),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
return 0
|
||||
from oclaw.runtime.operations.scripts.wecom_status import main
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,13 @@
|
|||
param(
|
||||
[string]$ChannelId = "openclaw-weixin",
|
||||
[string]$Package = "@tencent-weixin/openclaw-weixin@2.1.9",
|
||||
[string]$OpenClawRuntime = ""
|
||||
[string]$ChannelId = "oclaw-weixin"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-RepoRoot {
|
||||
$here = Split-Path -Parent $PSCommandPath
|
||||
return (Resolve-Path (Join-Path $here "..")).Path
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\weixin_install.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$oclawRoot = Resolve-RepoRoot
|
||||
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
|
||||
$stateDir = Join-Path $sidecarRoot "state"
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $sidecarRoot | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path (Join-Path $sidecarRoot "logs") | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path $stateDir | Out-Null
|
||||
|
||||
Push-Location $sidecarRoot
|
||||
try {
|
||||
if (-not (Test-Path (Join-Path $sidecarRoot "package.json"))) {
|
||||
npm.cmd init -y | Out-Null
|
||||
}
|
||||
if (Test-Path (Join-Path $sidecarRoot "package-lock.json")) {
|
||||
npm.cmd ci
|
||||
} else {
|
||||
# First-time setup: install exact versions for reproducible sidecar runtime.
|
||||
if ($OpenClawRuntime) {
|
||||
npm.cmd install --save-exact $Package $OpenClawRuntime tsx@4.21.0 typescript@6.0.3
|
||||
} else {
|
||||
npm.cmd install --save-exact $Package tsx@4.21.0 typescript@6.0.3
|
||||
}
|
||||
}
|
||||
Write-Host "[ok] installed $Package into $sidecarRoot"
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
& $real -ChannelId $ChannelId
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,13 @@
|
|||
param(
|
||||
[string]$ChannelId = "openclaw-weixin"
|
||||
[string]$ChannelId = "oclaw-weixin"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-RepoRoot {
|
||||
$here = Split-Path -Parent $PSCommandPath
|
||||
return (Resolve-Path (Join-Path $here "..")).Path
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\weixin_login.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$oclawRoot = Resolve-RepoRoot
|
||||
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
|
||||
$stateDir = Join-Path $sidecarRoot "state"
|
||||
|
||||
if (-not (Test-Path $sidecarRoot)) {
|
||||
throw "sidecar not installed: run .\\scripts\\weixin_install.ps1 first"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $stateDir | Out-Null
|
||||
|
||||
Push-Location $sidecarRoot
|
||||
try {
|
||||
$env:OPENCLAW_STATE_DIR = $stateDir
|
||||
if (-not (Test-Path (Join-Path $sidecarRoot "login.ts"))) {
|
||||
throw "missing login.ts"
|
||||
}
|
||||
npm.cmd exec -- tsx login.ts
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
& $real -ChannelId $ChannelId
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,14 @@
|
|||
param(
|
||||
[string]$ChannelId = "openclaw-weixin",
|
||||
[string]$GatewayBaseUrl = "http://127.0.0.1:8787"
|
||||
[string]$ChannelId = "oclaw-weixin",
|
||||
[string]$GatewayBaseUrl = "http://127.0.0.1:8787"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-RepoRoot {
|
||||
$here = Split-Path -Parent $PSCommandPath
|
||||
return (Resolve-Path (Join-Path $here "..")).Path
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\weixin_start.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$oclawRoot = Resolve-RepoRoot
|
||||
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
|
||||
$stateDir = Join-Path $sidecarRoot "state"
|
||||
$logDir = Join-Path $sidecarRoot "logs"
|
||||
$pidFile = Join-Path $sidecarRoot "pid.txt"
|
||||
|
||||
if (-not (Test-Path $sidecarRoot)) {
|
||||
throw "sidecar not installed: run .\\scripts\\weixin_install.ps1 first"
|
||||
}
|
||||
if (-not (Test-Path (Join-Path $sidecarRoot "runner.ts"))) {
|
||||
throw "missing runner.ts (sidecar code). Re-run repo sync or restore file."
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
|
||||
New-Item -ItemType Directory -Force -Path $stateDir | Out-Null
|
||||
|
||||
$logPath = Join-Path $logDir "weixin_sidecar.log"
|
||||
$errPath = Join-Path $logDir "weixin_sidecar.err.log"
|
||||
$cmd = "cmd.exe"
|
||||
$args = @(
|
||||
"/c",
|
||||
"cd /d $sidecarRoot && set OPENCLAW_STATE_DIR=$stateDir&& set AIA_GATEWAY_BASE_URL=$GatewayBaseUrl&& npm.cmd exec -- tsx runner.ts"
|
||||
)
|
||||
|
||||
$p = Start-Process -FilePath $cmd -ArgumentList $args -WorkingDirectory $sidecarRoot -PassThru -WindowStyle Hidden -RedirectStandardOutput $logPath -RedirectStandardError $errPath
|
||||
Set-Content -Path $pidFile -Value $p.Id
|
||||
Write-Host "[ok] started weixin sidecar pid=$($p.Id) out=$logPath err=$errPath"
|
||||
& $real -ChannelId $ChannelId -GatewayBaseUrl $GatewayBaseUrl
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +1,13 @@
|
|||
param(
|
||||
[string]$ChannelId = "openclaw-weixin"
|
||||
[string]$ChannelId = "oclaw-weixin"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-RepoRoot {
|
||||
$here = Split-Path -Parent $PSCommandPath
|
||||
return (Resolve-Path (Join-Path $here "..")).Path
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\weixin_status.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$oclawRoot = Resolve-RepoRoot
|
||||
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
|
||||
$pidFile = Join-Path $sidecarRoot "pid.txt"
|
||||
|
||||
if (-not (Test-Path $pidFile)) {
|
||||
Write-Host "status=stopped"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$procId = (Get-Content -Path $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
if (-not $procId) {
|
||||
Write-Host "status=stopped"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$exists = $false
|
||||
try {
|
||||
Get-Process -Id $procId -ErrorAction Stop | Out-Null
|
||||
$exists = $true
|
||||
} catch {}
|
||||
|
||||
if ($exists) {
|
||||
Write-Host "status=running pid=$procId"
|
||||
} else {
|
||||
Write-Host "status=stale_pid pid=$procId"
|
||||
}
|
||||
& $real -ChannelId $ChannelId
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,13 @@
|
|||
param(
|
||||
[string]$ChannelId = "openclaw-weixin",
|
||||
[switch]$Force
|
||||
[string]$ChannelId = "oclaw-weixin"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-RepoRoot {
|
||||
$here = Split-Path -Parent $PSCommandPath
|
||||
return (Resolve-Path (Join-Path $here "..")).Path
|
||||
$real = Join-Path $PSScriptRoot "..\\runtime\\operations\\scripts\\weixin_stop.ps1"
|
||||
if (-not (Test-Path $real)) {
|
||||
throw "Forward script target not found: $real"
|
||||
}
|
||||
|
||||
$oclawRoot = Resolve-RepoRoot
|
||||
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
|
||||
$pidFile = Join-Path $sidecarRoot "pid.txt"
|
||||
|
||||
if (-not (Test-Path $pidFile)) {
|
||||
Write-Host "[ok] not running (no pid file)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$procId = (Get-Content -Path $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
|
||||
if (-not $procId) {
|
||||
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
|
||||
Write-Host "[ok] not running (empty pid file)"
|
||||
exit 0
|
||||
}
|
||||
|
||||
try {
|
||||
if ($Force) {
|
||||
taskkill.exe /PID $procId /T /F | Out-Null
|
||||
} else {
|
||||
taskkill.exe /PID $procId /T | Out-Null
|
||||
}
|
||||
} catch {
|
||||
# Ignore if already dead.
|
||||
}
|
||||
|
||||
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
|
||||
Write-Host "[ok] stopped pid=$procId"
|
||||
& $real -ChannelId $ChannelId
|
||||
|
||||
|
|
|
|||
|
|
@ -1,100 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(_REPO_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(_REPO_ROOT))
|
||||
|
||||
from oclaw.platform.config.paths import PROJECT_ROOT, db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
|
||||
def _load_cfg() -> dict:
|
||||
cfg_file = (Path(PROJECT_ROOT) / "oclaw" / "oclaw.json").resolve()
|
||||
if not cfg_file.exists():
|
||||
return {}
|
||||
try:
|
||||
obj = json.loads(cfg_file.read_text(encoding="utf-8"))
|
||||
return obj if isinstance(obj, dict) else {}
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def _wiki_root_from_cfg(cfg: dict) -> Path:
|
||||
plugins = cfg.get("plugins") if isinstance(cfg, dict) else {}
|
||||
entries = plugins.get("entries") if isinstance(plugins, dict) else {}
|
||||
mw = entries.get("memory-wiki") if isinstance(entries, dict) else {}
|
||||
root_cfg = str((mw or {}).get("wiki_root") or "oclaw/docs/memory-system/wiki").strip()
|
||||
root = Path(root_cfg)
|
||||
if not root.is_absolute():
|
||||
root = (Path(PROJECT_ROOT) / root).resolve()
|
||||
return root
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="Smoke test for wiki auto pipeline.")
|
||||
parser.add_argument("--timeout-s", type=int, default=30, help="Task wait timeout in seconds.")
|
||||
args = parser.parse_args()
|
||||
|
||||
cfg = _load_cfg()
|
||||
wiki_root = _wiki_root_from_cfg(cfg)
|
||||
store = SqliteStore(db_path())
|
||||
|
||||
suffix = uuid.uuid4().hex[:8]
|
||||
payload = {
|
||||
"kind": "captureAfterTurn",
|
||||
"session_id": f"smoke-session-{suffix}",
|
||||
"tenant_id": "default",
|
||||
"user_id": "smoke-user",
|
||||
"turn_uuid": f"smoke-turn-{suffix}",
|
||||
"user_text": "smoke router vlan check",
|
||||
"assistant_text": "smoke response for wiki worker",
|
||||
}
|
||||
task = store.openclaw_task_create(
|
||||
tenant_id="default",
|
||||
session_id=payload["session_id"],
|
||||
task_type="wiki_capture",
|
||||
payload=payload,
|
||||
)
|
||||
print(f"[smoke] created task: {task.id}")
|
||||
|
||||
deadline = time.time() + max(5, int(args.timeout_s))
|
||||
final = task
|
||||
while time.time() < deadline:
|
||||
got = store.openclaw_task_get(task_id=task.id)
|
||||
if got is None:
|
||||
print("[smoke] task missing")
|
||||
return 2
|
||||
final = got
|
||||
if final.status in {"done", "failed"}:
|
||||
break
|
||||
time.sleep(1.0)
|
||||
|
||||
print(f"[smoke] final status: {final.status}")
|
||||
if final.status not in {"done", "failed"}:
|
||||
print("[smoke] timeout waiting for worker")
|
||||
return 3
|
||||
|
||||
artifacts = {
|
||||
"merged_turns": wiki_root / "inbox" / "merged-turns.md",
|
||||
"topic_index": wiki_root / ".oclaw" / "topic-index.json",
|
||||
"index": wiki_root / ".oclaw" / "index.json",
|
||||
"lint_report": wiki_root / ".oclaw" / "LINT_REPORT.md",
|
||||
}
|
||||
for name, fp in artifacts.items():
|
||||
print(f"[smoke] {name}: {'ok' if fp.exists() else 'missing'} ({fp})")
|
||||
|
||||
if final.status == "failed":
|
||||
print(f"[smoke] worker error: {final.last_error}")
|
||||
return 4
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import websockets
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
ws_url = "ws://127.0.0.1:8790/ws"
|
||||
t0 = time.time()
|
||||
async with websockets.connect(ws_url, open_timeout=5) as ws:
|
||||
challenge = json.loads(await ws.recv())
|
||||
print("challenge", challenge.get("event"), challenge.get("payload", {}).get("nonce"))
|
||||
nonce = challenge.get("payload", {}).get("nonce", "")
|
||||
|
||||
req_id = uuid.uuid4().hex
|
||||
await ws.send(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "req",
|
||||
"id": req_id,
|
||||
"method": "connect",
|
||||
"params": {
|
||||
"minProtocol": 3,
|
||||
"maxProtocol": 3,
|
||||
"client": {"id": "probe", "mode": "cli", "version": "0.0.0", "platform": "cli"},
|
||||
"device": {
|
||||
"id": uuid.uuid4().hex,
|
||||
"publicKey": "dummy",
|
||||
"signature": "dummy",
|
||||
"signedAt": int(time.time() * 1000),
|
||||
"nonce": nonce,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
hello = json.loads(await ws.recv())
|
||||
print("hello", hello)
|
||||
|
||||
session_key = uuid.uuid4().hex
|
||||
req_id2 = uuid.uuid4().hex
|
||||
await ws.send(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "req",
|
||||
"id": req_id2,
|
||||
"method": "chat.send",
|
||||
"params": {
|
||||
"sessionKey": session_key,
|
||||
"idempotencyKey": uuid.uuid4().hex,
|
||||
"message": "hi streaming test",
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
got_delta = False
|
||||
first_delta_at: float | None = None
|
||||
while True:
|
||||
msg = json.loads(await ws.recv())
|
||||
if msg.get("type") == "res" and msg.get("id") == req_id2:
|
||||
print("chat.send res", msg)
|
||||
continue
|
||||
if msg.get("type") == "event" and msg.get("event") == "chat":
|
||||
st = (msg.get("payload") or {}).get("state")
|
||||
if st == "delta":
|
||||
if not got_delta:
|
||||
got_delta = True
|
||||
first_delta_at = time.time() - t0
|
||||
if st in ("final", "error"):
|
||||
pl = msg.get("payload") or {}
|
||||
print(
|
||||
"final_state",
|
||||
st,
|
||||
"got_delta",
|
||||
got_delta,
|
||||
"first_delta_at",
|
||||
first_delta_at,
|
||||
"reply_preview",
|
||||
str(pl.get("reply") or "")[:120],
|
||||
)
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue