Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env python32"""Run every xAI inference example once, patch its STATUS header, write examples/manifest-xai-inference.json."""3from __future__ import annotations4import json, re, subprocess, sys, time5from pathlib import Path6ROOT = Path(__file__).resolve().parents[2]7AREAS = ["chat", "responses", "messages-compat", "streaming", "structured-output", "files", "collections", "batches", "deferred", "tools"]8TODAY = "2026-09-19"9only = set(sys.argv[1:])10files = sorted(p for a in AREAS for p in (ROOT / "examples/xai" / a).rglob("*") if p.suffix in (".sh", ".py", ".ts") and p.is_file())11records = []12for p in files:13 rel = str(p.relative_to(ROOT))14 if only and not any(o in rel for o in only):15 continue16 if p.suffix == ".sh": cmd = ["bash", str(p)]17 elif p.suffix == ".py": cmd = [str(ROOT / ".venv/bin/python"), str(p)]18 else: cmd = ["node", "--env-file=.env", "--experimental-strip-types", str(p)]19 t0 = time.time()20 try:21 r = subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True, timeout=420)22 code, out, err = r.returncode, r.stdout, r.stderr23 except subprocess.TimeoutExpired as e:24 code, out, err = 124, (e.stdout or b"").decode() if isinstance(e.stdout, bytes) else (e.stdout or ""), "timeout"25 dt = round(time.time() - t0, 1)26 status = "LIVE_VERIFIED" if code == 0 else "FAILED_VERIFICATION"27 tail = re.sub(r"xai-[A-Za-z0-9_-]{16,}", "xai-***", (out.strip().splitlines() or [""])[-1])[:300]28 errtail = re.sub(r"xai-[A-Za-z0-9_-]{16,}", "xai-***", "\n".join(err.strip().splitlines()[-3:]))[:400]29 lang = {"sh": "bash/curl", "py": "python", "ts": "typescript"}[p.suffix[1:]]30 area = rel.split("/")[2] if not rel.startswith("examples/xai/tools") else "tools/" + rel.split("/")[3]31 records.append({"provider": "xai", "area": area, "file": rel, "language": lang, "status": status, "verified_at": TODAY, "notes": f"exit {code} in {dt}s" + (f"; stderr: {errtail}" if code else ""), "stdout_tail": tail})32 src = p.read_text()33 marker = "# STATUS:" if p.suffix != ".ts" else "// STATUS:"34 new = f"{marker} {status} — executed {TODAY} (exit {code} in {dt}s)"35 src = re.sub(rf"^{re.escape(marker)}.*$", new, src, count=1, flags=re.M)36 p.write_text(src)37 print(f"[{status[:4]}] {rel} exit={code} {dt}s :: {tail[:120]}" + (f" :: {errtail[:200]}" if code else ""))38mp = ROOT / "examples/manifest-xai-inference.json"39old = json.load(open(mp))["examples"] if mp.exists() else []40merged = {r["file"]: r for r in old}41for r in records: merged[r["file"]] = r42mp.write_text(json.dumps({"_generated_by": "tmp/xai-inference/run_examples.py", "generated_at": TODAY, "examples": sorted(merged.values(), key=lambda r: r["file"])}, indent=1, ensure_ascii=False))43print("manifest", len(merged))44