Initial import of streamline
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "../styles.css";
|
||||
import { api, type OpenApiUsageStats } from "../lib/api";
|
||||
import OpenPlatformUsagePanel from "../components/OpenPlatformUsagePanel";
|
||||
|
||||
/**
|
||||
* 本地演示:管理台「开放平台 → 使用情况」。不连任何接口 —— api.openApiUsage 换成按窗口生成的假数据
|
||||
* (Skill 从窗口中段才开始有人用,模拟刚上线后爬坡)。
|
||||
*
|
||||
* 打开方式:control-web 下 `API_TARGET=http://127.0.0.1:9 bun x vite --port 8092`,访问
|
||||
* /demo-openapi-usage.html。`?empty=1` 看刚上线还没有调用的样子,`?dark=1` 看深色。
|
||||
*/
|
||||
const q = new URLSearchParams(location.search);
|
||||
const empty = q.has("empty");
|
||||
if (q.has("dark")) document.documentElement.dataset.theme = "dark";
|
||||
|
||||
const DAY = 86_400_000;
|
||||
const now = Date.now();
|
||||
const bj = (ms: number) => new Date(ms + 8 * 3_600_000).toISOString().slice(0, 10);
|
||||
// 固定种子,刷新不跳。
|
||||
let seed = 7;
|
||||
const rnd = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
|
||||
|
||||
function fake(days: number): OpenApiUsageStats {
|
||||
seed = 7 + days;
|
||||
const daily = Array.from({ length: days }, (_, k) => {
|
||||
const i = days - 1 - k, t = now - i * DAY, dow = new Date(t).getUTCDay(), weekend = dow === 0 || dow === 6;
|
||||
const ramp = Math.max(0, 1 - i / Math.min(days, 21)); // 越近越多
|
||||
const web = empty ? Math.round((weekend ? 3 : 14) * (0.7 + rnd() * 0.6)) : Math.round((weekend ? 3 : 14) * (0.7 + rnd() * 0.6));
|
||||
const openapi = empty ? 0 : Math.round((weekend ? 0.3 : 2.2) * rnd() * 1.6);
|
||||
const cli = empty ? 0 : Math.round((weekend ? 0.5 : 5) * ramp * (0.5 + rnd()));
|
||||
return { date: bj(t), web, openapi, cli, calls: empty ? 0 : (openapi + cli) * 6 + Math.round(rnd() * 10), activeActors: empty ? 0 : Math.min(9, openapi + Math.ceil(cli * 0.8)) };
|
||||
});
|
||||
const sum = (k: "web" | "openapi" | "cli") => daily.reduce((a, d) => a + d[k], 0);
|
||||
const tasks = { web: sum("web"), openapi: sum("openapi"), cli: sum("cli"), total: 0 };
|
||||
tasks.total = tasks.web + tasks.openapi + tasks.cli;
|
||||
const calls = daily.reduce((a, d) => a + d.calls, 0);
|
||||
return {
|
||||
days, from: now - days * DAY, to: now,
|
||||
summary: {
|
||||
tasks, nonWebShare: tasks.total ? (tasks.openapi + tasks.cli) / tasks.total : null, prevNonWebShare: empty ? 0 : 0.06,
|
||||
calls: { total: calls, openapi: Math.round(calls * 0.3), cli: calls - Math.round(calls * 0.3), errors: Math.round(calls * 0.03) },
|
||||
activeKeys: empty ? 0 : 3, totalKeys: 5, activeCliUsers: empty ? 0 : 14, authorizedCliUsers: empty ? 1 : 21, newCliUsers: empty ? 1 : 9,
|
||||
},
|
||||
daily,
|
||||
actors: empty ? [] : [
|
||||
{ channel: "cli", id: "zhangsan@bytedance.com", name: "zhangsan", owner: "zhangsan@bytedance.com", calls: 86, errors: 2, tasks: 11, executes: 7, lastAt: now - 40 * 60_000, agents: ["claude-code"] },
|
||||
{ channel: "openapi", id: "opk_1", name: "Meego 工单同步", owner: "jiuyu.zhou@bytedance.com", calls: 240, errors: 9, tasks: Math.round(tasks.openapi * 0.7), executes: 18, lastAt: now - 2 * 3_600_000, agents: [] },
|
||||
{ channel: "cli", id: "lisi@bytedance.com", name: "lisi", owner: "lisi@bytedance.com", calls: 41, errors: 0, tasks: 6, executes: 2, lastAt: now - 5 * 3_600_000, agents: ["cursor"] },
|
||||
{ channel: "cli", id: "wangwu@bytedance.com", name: "wangwu", owner: "wangwu@bytedance.com", calls: 22, errors: 4, tasks: 3, executes: 0, lastAt: now - 26 * 3_600_000, agents: ["codex", "terminal"] },
|
||||
{ channel: "openapi", id: "opk_2", name: "Spoton", owner: "me@bytedance.com", calls: 57, errors: 1, tasks: Math.round(tasks.openapi * 0.3), executes: 0, lastAt: now - 3 * DAY, agents: [] },
|
||||
],
|
||||
routes: empty ? [] : [
|
||||
{ channel: "cli", route: "GET /cli/v1/tasks/:taskId", calls: 310, errors: 3 },
|
||||
{ channel: "openapi", route: "POST /openapi/v1/meego-import", calls: 196, errors: 7 },
|
||||
{ channel: "cli", route: "POST /cli/v1/meego-import", calls: 88, errors: 2 },
|
||||
{ channel: "cli", route: "POST /cli/v1/tasks", calls: 64, errors: 1 },
|
||||
{ channel: "cli", route: "POST /cli/v1/handoff", calls: 19, errors: 1 },
|
||||
{ channel: "cli", route: "POST /cli/v1/tasks/:taskId/execute", calls: 31, errors: 9 },
|
||||
{ channel: "openapi", route: "GET /openapi/v1/tasks/:taskId", calls: 22, errors: 0 },
|
||||
{ channel: "openapi", route: "POST /openapi/v1/features", calls: 9, errors: 0 },
|
||||
],
|
||||
agents: empty ? [] : [
|
||||
{ agent: "claude-code", users: 9, calls: 402 }, { agent: "cursor", users: 4, calls: 121 }, { agent: "codex", users: 2, calls: 37 }, { agent: "terminal", users: 3, calls: 12 },
|
||||
],
|
||||
outcomes: [
|
||||
{ channel: "web" as const, total: tasks.web, evaluating: Math.round(tasks.web * 0.18), running: Math.round(tasks.web * 0.08), fixed: Math.round(tasks.web * 0.42), notFixed: Math.round(tasks.web * 0.2), closed: 0 },
|
||||
{ channel: "openapi" as const, total: tasks.openapi, evaluating: Math.round(tasks.openapi * 0.55), running: Math.round(tasks.openapi * 0.05), fixed: Math.round(tasks.openapi * 0.25), notFixed: Math.round(tasks.openapi * 0.1), closed: 0 },
|
||||
{ channel: "cli" as const, total: tasks.cli, evaluating: Math.round(tasks.cli * 0.3), running: Math.round(tasks.cli * 0.15), fixed: Math.round(tasks.cli * 0.35), notFixed: Math.round(tasks.cli * 0.15), closed: 0 },
|
||||
{ channel: "handoff" as const, total: Math.round(tasks.cli * 0.4), evaluating: Math.round(tasks.cli * 0.08), running: Math.round(tasks.cli * 0.06), fixed: Math.round(tasks.cli * 0.2), notFixed: Math.round(tasks.cli * 0.04), closed: 0 },
|
||||
].map((o) => ({ ...o, closed: Math.max(0, o.total - o.evaluating - o.running - o.fixed - o.notFixed) })),
|
||||
integrations: { webhooks: empty ? 0 : 2, larkBots: empty ? 0 : 1 },
|
||||
};
|
||||
}
|
||||
|
||||
(api as { openApiUsage: (days: number) => Promise<OpenApiUsageStats> }).openApiUsage = async (days) => {
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
return fake(days);
|
||||
};
|
||||
|
||||
createRoot(document.getElementById("root")!).render(
|
||||
// 应用的全局样式关掉了 body 滚动(真实页面由各自的面板容器滚),演示页自己给一个滚动容器。
|
||||
<div style={{ height: "100vh", overflow: "auto" }}>
|
||||
<div style={{ maxWidth: 980, margin: "24px auto", padding: "0 16px" }}>
|
||||
<OpenPlatformUsagePanel />
|
||||
</div>
|
||||
</div>,
|
||||
);
|
||||
Reference in New Issue
Block a user