koishi-plugin-newapi-status 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +31 -0
- package/lib/api/index.d.ts +10 -0
- package/lib/api/index.js +26 -0
- package/lib/api/models.d.ts +9 -0
- package/lib/api/models.js +20 -0
- package/lib/api/network.d.ts +20 -0
- package/lib/api/network.js +42 -0
- package/lib/api/notice.d.ts +8 -0
- package/lib/api/notice.js +17 -0
- package/lib/api/perf.d.ts +31 -0
- package/lib/api/perf.js +52 -0
- package/lib/api/pricing.d.ts +9 -0
- package/lib/api/pricing.js +24 -0
- package/lib/api/ratio.d.ts +10 -0
- package/lib/api/ratio.js +29 -0
- package/lib/api/relay.d.ts +43 -0
- package/lib/api/relay.js +178 -0
- package/lib/api/shared.d.ts +60 -0
- package/lib/api/shared.js +123 -0
- package/lib/api/status.d.ts +12 -0
- package/lib/api/status.js +13 -0
- package/lib/api/uptime.d.ts +9 -0
- package/lib/api/uptime.js +18 -0
- package/lib/config.d.ts +59 -0
- package/lib/config.js +112 -0
- package/lib/format.d.ts +76 -0
- package/lib/format.js +242 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +567 -0
- package/lib/log.d.ts +39 -0
- package/lib/log.js +39 -0
- package/lib/monitor.d.ts +39 -0
- package/lib/monitor.js +186 -0
- package/lib/render/ChannelCard.d.ts +6 -0
- package/lib/render/ChannelCard.js +12 -0
- package/lib/render/StatusCard.d.ts +6 -0
- package/lib/render/StatusCard.js +18 -0
- package/lib/render/index.d.ts +12 -0
- package/lib/render/index.js +71 -0
- package/lib/render/styles.d.ts +23 -0
- package/lib/render/styles.js +192 -0
- package/lib/text.d.ts +10 -0
- package/lib/text.js +107 -0
- package/lib/types.d.ts +201 -0
- package/lib/types.js +6 -0
- package/lib/view.d.ts +149 -0
- package/lib/view.js +360 -0
- package/package.json +73 -4
- package/readme.md +225 -0
- package/README.md +0 -3
package/lib/monitor.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Context } from 'koishi';
|
|
2
|
+
import type { Config } from './config';
|
|
3
|
+
import { getSiteStatus } from './api';
|
|
4
|
+
import { renderError } from './text';
|
|
5
|
+
/** 与控制台日志页一致的命名空间;任何模块都用这一个,别自己拼字符串 */
|
|
6
|
+
export declare const loggerName = "newapi-status";
|
|
7
|
+
export interface MonitorState {
|
|
8
|
+
/** 连续失败次数 */
|
|
9
|
+
failures: number;
|
|
10
|
+
/** 上次发送告警的时间戳,用于抑制重复告警 */
|
|
11
|
+
lastAlertAt: number;
|
|
12
|
+
/** 站点当前是否可用(用于判断「恢复」) */
|
|
13
|
+
online: boolean;
|
|
14
|
+
lastLatencyMs: number;
|
|
15
|
+
/** 上一次 /v1/models 快照;null = 还没取过(首次只建基线,不告警) */
|
|
16
|
+
models: string[] | null;
|
|
17
|
+
/** 已告警为「消失」、尚未恢复的模型名 */
|
|
18
|
+
missing: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function normalizeChannels(channels: string[]): string[];
|
|
21
|
+
export interface MonitorHandle {
|
|
22
|
+
state: MonitorState;
|
|
23
|
+
/** 立即执行一次巡检(测试与手动触发共用) */
|
|
24
|
+
check: () => Promise<void>;
|
|
25
|
+
/** 停止巡检 */
|
|
26
|
+
dispose: () => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 定时巡检。
|
|
30
|
+
* - 站点可用性:探无需鉴权的 /api/status;
|
|
31
|
+
* - 模型/渠道状态:用 sk- 调用令牌读 GET /v1/models 做差集轮询。
|
|
32
|
+
* 渠道被管理员禁用后,对应模型会从这份清单里消失 —— 这是唯一不需要 AdminAuth 的观测口径;
|
|
33
|
+
* 面板的 /api/channel/* 全部挂在 AdminAuth 后面,普通令牌拿不到。
|
|
34
|
+
*/
|
|
35
|
+
export declare function createMonitor(ctx: Context, config: Config, channels: string[]): MonitorHandle;
|
|
36
|
+
export declare function startMonitor(ctx: Context, config: Config): () => void;
|
|
37
|
+
/** /status 里附带展示的运行时长摘要,供 monitor 复用避免重复请求。 */
|
|
38
|
+
export declare function describeUptime(startTime: number | undefined): string;
|
|
39
|
+
export { renderError, getSiteStatus };
|
package/lib/monitor.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSiteStatus = exports.renderError = exports.loggerName = void 0;
|
|
4
|
+
exports.normalizeChannels = normalizeChannels;
|
|
5
|
+
exports.createMonitor = createMonitor;
|
|
6
|
+
exports.startMonitor = startMonitor;
|
|
7
|
+
exports.describeUptime = describeUptime;
|
|
8
|
+
const api_1 = require("./api");
|
|
9
|
+
Object.defineProperty(exports, "getSiteStatus", { enumerable: true, get: function () { return api_1.getSiteStatus; } });
|
|
10
|
+
const format_1 = require("./format");
|
|
11
|
+
const log_1 = require("./log");
|
|
12
|
+
const text_1 = require("./text");
|
|
13
|
+
Object.defineProperty(exports, "renderError", { enumerable: true, get: function () { return text_1.renderError; } });
|
|
14
|
+
/** 与控制台日志页一致的命名空间;任何模块都用这一个,别自己拼字符串 */
|
|
15
|
+
exports.loggerName = log_1.LOGGER_NAME;
|
|
16
|
+
function normalizeChannels(channels) {
|
|
17
|
+
return channels.map(channel => channel.trim()).filter(Boolean);
|
|
18
|
+
}
|
|
19
|
+
/** 本次要关注的模型:配置了 models 就只看这些,否则看整份清单 */
|
|
20
|
+
function watchList(all, wanted) {
|
|
21
|
+
if (!wanted.length)
|
|
22
|
+
return all;
|
|
23
|
+
const available = new Set(all);
|
|
24
|
+
// 只返回盯的模型里真实存在于清单中的,避免把「本来就没了」误报成「刚刚消失」
|
|
25
|
+
return wanted.filter(name => available.has(name));
|
|
26
|
+
}
|
|
27
|
+
function shortList(names, limit = 12) {
|
|
28
|
+
if (names.length <= limit)
|
|
29
|
+
return names.join('、');
|
|
30
|
+
return names.slice(0, limit).join('、') + ` 等 ${names.length} 个`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 定时巡检。
|
|
34
|
+
* - 站点可用性:探无需鉴权的 /api/status;
|
|
35
|
+
* - 模型/渠道状态:用 sk- 调用令牌读 GET /v1/models 做差集轮询。
|
|
36
|
+
* 渠道被管理员禁用后,对应模型会从这份清单里消失 —— 这是唯一不需要 AdminAuth 的观测口径;
|
|
37
|
+
* 面板的 /api/channel/* 全部挂在 AdminAuth 后面,普通令牌拿不到。
|
|
38
|
+
*/
|
|
39
|
+
function createMonitor(ctx, config, channels) {
|
|
40
|
+
const logger = ctx.logger(exports.loggerName);
|
|
41
|
+
const client = {
|
|
42
|
+
baseUrl: config.baseUrl,
|
|
43
|
+
token: config.accessToken?.trim() || undefined,
|
|
44
|
+
userId: Number(config.userId) > 0 ? Number(config.userId) : undefined,
|
|
45
|
+
timeout: config.timeout,
|
|
46
|
+
};
|
|
47
|
+
const apiKey = config.monitor.apiKey?.trim() || '';
|
|
48
|
+
const wanted = (config.monitor.models || []).map(name => name.trim()).filter(Boolean);
|
|
49
|
+
const state = {
|
|
50
|
+
failures: 0,
|
|
51
|
+
lastAlertAt: 0,
|
|
52
|
+
online: true,
|
|
53
|
+
lastLatencyMs: 0,
|
|
54
|
+
models: null,
|
|
55
|
+
missing: [],
|
|
56
|
+
};
|
|
57
|
+
const checkSite = async () => {
|
|
58
|
+
const result = await (0, api_1.probeSite)(ctx, client);
|
|
59
|
+
if (result.ok) {
|
|
60
|
+
const recovered = !state.online;
|
|
61
|
+
state.online = true;
|
|
62
|
+
state.failures = 0;
|
|
63
|
+
state.lastLatencyMs = result.latencyMs;
|
|
64
|
+
if (recovered) {
|
|
65
|
+
await notify(ctx, channels, [
|
|
66
|
+
'✅ New API 已恢复访问',
|
|
67
|
+
`地址:${config.baseUrl}`,
|
|
68
|
+
`本次探测延迟:${(0, format_1.formatLatency)(result.latencyMs)}`,
|
|
69
|
+
].join('\n'));
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
state.failures += 1;
|
|
74
|
+
logger.warn('巡检失败(连续 %d 次):%s', state.failures, result.error ?? '未知错误');
|
|
75
|
+
const threshold = Math.max(1, config.monitor.threshold);
|
|
76
|
+
if (state.failures < threshold)
|
|
77
|
+
return false;
|
|
78
|
+
// 只在「可用 → 不可用」的状态跃迁时告警一次,避免每次巡检都刷屏
|
|
79
|
+
if (!state.online)
|
|
80
|
+
return false;
|
|
81
|
+
state.online = false;
|
|
82
|
+
state.lastAlertAt = Date.now();
|
|
83
|
+
await notify(ctx, channels, [
|
|
84
|
+
'⚠️ New API 无法访问',
|
|
85
|
+
`地址:${config.baseUrl}`,
|
|
86
|
+
`连续失败:${state.failures} 次`,
|
|
87
|
+
`原因:${result.error ?? '请求失败'}`,
|
|
88
|
+
].join('\n'));
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
91
|
+
const checkModels = async () => {
|
|
92
|
+
if (!apiKey)
|
|
93
|
+
return;
|
|
94
|
+
const result = await (0, api_1.listRelayModels)(ctx, { baseUrl: config.baseUrl, apiKey, timeout: config.timeout });
|
|
95
|
+
if (!result.ok) {
|
|
96
|
+
logger.warn('拉取 /v1/models 失败:%s', result.error ?? '未知错误');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const current = [...new Set(result.models)].sort();
|
|
100
|
+
const previous = state.models;
|
|
101
|
+
state.models = current;
|
|
102
|
+
// 首次只建基线:没有上一份快照就没有「消失」可言
|
|
103
|
+
if (!previous) {
|
|
104
|
+
logger.info('模型清单基线已建立:%d 个模型。', current.length);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const before = new Set(watchList(previous, wanted));
|
|
108
|
+
const after = new Set(watchList(current, wanted));
|
|
109
|
+
const disappeared = [...before].filter(name => !after.has(name));
|
|
110
|
+
const recovered = state.missing.filter(name => after.has(name));
|
|
111
|
+
state.missing = state.missing.filter(name => !after.has(name));
|
|
112
|
+
for (const name of disappeared)
|
|
113
|
+
if (!state.missing.includes(name))
|
|
114
|
+
state.missing.push(name);
|
|
115
|
+
if (disappeared.length) {
|
|
116
|
+
state.lastAlertAt = Date.now();
|
|
117
|
+
await notify(ctx, channels, [
|
|
118
|
+
`⚠️ 有 ${disappeared.length} 个模型从 /v1/models 消失(可能是渠道被禁用或无可用渠道)`,
|
|
119
|
+
`站点:${config.baseUrl}`,
|
|
120
|
+
`模型:${shortList(disappeared)}`,
|
|
121
|
+
`当前可用模型:${current.length} 个(上次 ${previous.length} 个)`,
|
|
122
|
+
].join('\n'));
|
|
123
|
+
}
|
|
124
|
+
if (recovered.length) {
|
|
125
|
+
await notify(ctx, channels, [
|
|
126
|
+
`✅ 有 ${recovered.length} 个模型恢复可用`,
|
|
127
|
+
`站点:${config.baseUrl}`,
|
|
128
|
+
`模型:${shortList(recovered)}`,
|
|
129
|
+
`当前可用模型:${current.length} 个`,
|
|
130
|
+
].join('\n'));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const check = async () => {
|
|
134
|
+
try {
|
|
135
|
+
const online = await checkSite();
|
|
136
|
+
if (online)
|
|
137
|
+
await checkModels();
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
logger.warn('巡检异常:%s', error?.message);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return { state, check, dispose: () => { } };
|
|
144
|
+
}
|
|
145
|
+
function startMonitor(ctx, config) {
|
|
146
|
+
const logger = ctx.logger(exports.loggerName);
|
|
147
|
+
const channels = normalizeChannels(config.monitor.channels);
|
|
148
|
+
if (!channels.length) {
|
|
149
|
+
logger.warn('已开启定时巡检,但 monitor.channels 为空,不会发送任何告警。请在配置里填写形如 onebot:123456789 的频道。');
|
|
150
|
+
return () => { };
|
|
151
|
+
}
|
|
152
|
+
const handle = createMonitor(ctx, config, channels);
|
|
153
|
+
const interval = Math.max(30, config.monitor.interval) * 1000;
|
|
154
|
+
const cron = config.monitor.cron?.trim();
|
|
155
|
+
let dispose;
|
|
156
|
+
if (cron && typeof ctx.cron === 'function') {
|
|
157
|
+
dispose = ctx.cron(cron, () => { void handle.check(); });
|
|
158
|
+
logger.info('巡检已按 cron 表达式启动:%s', cron);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if (cron)
|
|
162
|
+
logger.warn('未安装 koishi-plugin-cron,已改为固定间隔 %d 秒巡检。', interval / 1000);
|
|
163
|
+
dispose = ctx.setInterval(() => { void handle.check(); }, interval);
|
|
164
|
+
logger.info('巡检已启动,间隔 %d 秒,告警频道 %s。', interval / 1000, channels.join(', '));
|
|
165
|
+
}
|
|
166
|
+
return () => {
|
|
167
|
+
handle.dispose();
|
|
168
|
+
dispose();
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async function notify(ctx, channels, content) {
|
|
172
|
+
try {
|
|
173
|
+
// ctx.broadcast 会把命中的频道从传入数组里 splice 掉,必须传副本,
|
|
174
|
+
// 否则第一次告警之后同一个频道再也收不到任何消息。
|
|
175
|
+
await ctx.broadcast([...channels], content);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
ctx.logger(exports.loggerName).warn('发送告警失败:%s', error?.message);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** /status 里附带展示的运行时长摘要,供 monitor 复用避免重复请求。 */
|
|
182
|
+
function describeUptime(startTime) {
|
|
183
|
+
if (!startTime || startTime <= 0)
|
|
184
|
+
return '--';
|
|
185
|
+
return (0, format_1.formatDuration)(Math.max(0, Math.floor(Date.now() / 1000) - startTime), true);
|
|
186
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelCard = ChannelCard;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
function ChannelCard({ list }) {
|
|
6
|
+
// 列表可能很长(真实站点有 30+ 分组、86 个模型),超出 limit 的部分折叠成一行提示,
|
|
7
|
+
// 否则截图会变成一张几千像素高的图,客户端加载不动。
|
|
8
|
+
const limit = list.limit && list.limit > 0 ? list.limit : 24;
|
|
9
|
+
const rows = list.rows.slice(0, limit);
|
|
10
|
+
const hidden = list.rows.length - rows.length;
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "card-head", children: [(0, jsx_runtime_1.jsx)("div", { className: "logo", children: (list.title || 'L').slice(0, 1).toUpperCase() }), (0, jsx_runtime_1.jsxs)("div", { className: "head-main", children: [(0, jsx_runtime_1.jsx)("div", { className: "site-name", children: list.title }), (0, jsx_runtime_1.jsx)("div", { className: "site-sub", children: list.subtitle || list.note || '' })] }), list.note && list.subtitle ? (0, jsx_runtime_1.jsx)("div", { className: "badges", children: (0, jsx_runtime_1.jsx)("span", { className: "badge", children: list.note }) }) : null] }), (0, jsx_runtime_1.jsx)("div", { className: "section", children: rows.length ? ((0, jsx_runtime_1.jsxs)("div", { className: "list", children: [rows.map((row, index) => ((0, jsx_runtime_1.jsxs)("div", { className: `list-row${row.wrap ? ' wrap' : ''}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `dot ${row.level || 'unknown'}` }), (0, jsx_runtime_1.jsx)("span", { className: "list-name", children: row.name }), row.tag ? (0, jsx_runtime_1.jsx)("span", { className: "list-tag", children: row.tag }) : null, row.value ? (0, jsx_runtime_1.jsx)("span", { className: "list-value", children: row.value }) : null] }, index))), hidden > 0 ? (0, jsx_runtime_1.jsxs)("div", { className: "list-more", children: ["\u8FD8\u6709 ", hidden, " \u6761\u672A\u663E\u793A\uFF0C\u7528\u5173\u952E\u8BCD\u7B5B\u9009"] }) : null] })) : ((0, jsx_runtime_1.jsx)("div", { className: "empty", children: list.empty || '暂无数据' })) }), (0, jsx_runtime_1.jsxs)("div", { className: "card-foot", children: [(0, jsx_runtime_1.jsx)("span", { children: list.footerLeft }), (0, jsx_runtime_1.jsx)("span", { children: list.footerRight })] })] }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StatusCard = StatusCard;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const styles_1 = require("./styles");
|
|
6
|
+
function Badge({ tone, text }) {
|
|
7
|
+
return (0, jsx_runtime_1.jsx)("span", { className: `badge ${tone}`, children: text });
|
|
8
|
+
}
|
|
9
|
+
function Blocks({ blocks }) {
|
|
10
|
+
if (!blocks.length)
|
|
11
|
+
return null;
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "blocks", children: blocks.map((block, index) => ((0, jsx_runtime_1.jsx)("div", { className: `block ${block.level}`, title: block.label || '' }, index))) }));
|
|
13
|
+
}
|
|
14
|
+
function StatusCard({ card }) {
|
|
15
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "card-head", children: [(0, jsx_runtime_1.jsx)("div", { className: "logo", children: (card.siteName || 'N').slice(0, 1).toUpperCase() }), (0, jsx_runtime_1.jsxs)("div", { className: "head-main", children: [(0, jsx_runtime_1.jsx)("div", { className: "site-name", children: card.siteName }), (0, jsx_runtime_1.jsx)("div", { className: "site-sub", children: card.sub })] }), card.badges.length ? ((0, jsx_runtime_1.jsx)("div", { className: "badges", children: card.badges.map((badge, index) => (0, jsx_runtime_1.jsx)(Badge, { tone: badge.tone, text: badge.text }, index)) })) : null] }), card.metrics.length ? ((0, jsx_runtime_1.jsx)("div", { className: "metrics", children: card.metrics.map((metric, index) => ((0, jsx_runtime_1.jsxs)("div", { className: "metric", children: [(0, jsx_runtime_1.jsx)("div", { className: "metric-k", children: metric.key }), (0, jsx_runtime_1.jsx)("div", { className: `metric-v${metric.level ? ' ' + metric.level : ''}`, children: metric.value }), metric.sub ? (0, jsx_runtime_1.jsx)("div", { className: "metric-sub", children: metric.sub }) : null] }, index))) })) : null, card.sections.map((section, index) => ((0, jsx_runtime_1.jsxs)("div", { className: "section", children: [(0, jsx_runtime_1.jsxs)("div", { className: "section-head", children: [(0, jsx_runtime_1.jsx)("div", { className: "section-title", children: section.title }), section.note ? (0, jsx_runtime_1.jsx)("div", { className: "section-note", children: section.note }) : null] }), section.rows && section.rows.length ? (section.rows.map((row, rowIndex) => ((0, jsx_runtime_1.jsxs)("div", { className: "row", children: [(0, jsx_runtime_1.jsx)("div", { className: "row-name", children: row.name }), row.ratio === undefined ? null : ((0, jsx_runtime_1.jsx)("div", { className: `row-bar${row.level ? ' ' + row.level : ''}`, children: (0, jsx_runtime_1.jsx)("i", { style: { width: `${Math.max(2, Math.min(100, Math.round(row.ratio * 100)))}%` } }) })), (0, jsx_runtime_1.jsx)("div", { className: "row-value", children: row.value })] }, rowIndex)))) : null, section.blocks && section.blocks.length ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Blocks, { blocks: section.blocks }), section.axis && section.axis.length ? ((0, jsx_runtime_1.jsx)("div", { className: "axis", children: section.axis.map((label, axisIndex) => (0, jsx_runtime_1.jsx)("span", { children: label }, axisIndex)) })) : null, section.legend ? ((0, jsx_runtime_1.jsxs)("div", { className: "legend", children: [(0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("i", { style: { background: styles_1.COLORS.ok } }), "\u6B63\u5E38"] }), (0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("i", { style: { background: styles_1.COLORS.warn } }), "\u6CE2\u52A8"] }), (0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("i", { style: { background: styles_1.COLORS.fail } }), "\u5F02\u5E38"] }), (0, jsx_runtime_1.jsxs)("span", { children: [(0, jsx_runtime_1.jsx)("i", { style: { background: 'rgba(255,255,255,0.16)' } }), "\u65E0\u6570\u636E"] })] })) : null] })) : null, section.chips && section.chips.length ? ((0, jsx_runtime_1.jsx)("div", { className: "chips", children: section.chips.map((chip, chipIndex) => (0, jsx_runtime_1.jsx)("span", { className: "chip", children: chip }, chipIndex)) })) : null, !section.rows?.length && !section.blocks?.length && !section.chips?.length
|
|
16
|
+
? (0, jsx_runtime_1.jsx)("div", { className: "empty", children: section.empty })
|
|
17
|
+
: null] }, index))), card.notice ? ((0, jsx_runtime_1.jsxs)("div", { className: "notice", children: [(0, jsx_runtime_1.jsx)("div", { className: "notice-tag", children: "\u516C\u544A" }), (0, jsx_runtime_1.jsx)("div", { className: "notice-body", children: card.notice.body })] })) : null, (0, jsx_runtime_1.jsxs)("div", { className: "card-foot", children: [(0, jsx_runtime_1.jsx)("span", { children: card.footerLeft }), (0, jsx_runtime_1.jsx)("span", { children: card.footerRight })] })] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context, h } from 'koishi';
|
|
2
|
+
import type { CardView, ListView } from '../view';
|
|
3
|
+
import { CARD_WIDTH } from './styles';
|
|
4
|
+
export type RenderMode = 'auto' | 'image' | 'text';
|
|
5
|
+
export interface RenderOptions {
|
|
6
|
+
mode: RenderMode;
|
|
7
|
+
/** 关闭时即使装了 puppeteer 也只输出文字 */
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function renderCard(ctx: Context, card: CardView, options: RenderOptions): Promise<h.Fragment>;
|
|
11
|
+
export declare function renderList(ctx: Context, list: ListView, options: RenderOptions): Promise<h.Fragment>;
|
|
12
|
+
export { CARD_WIDTH };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CARD_WIDTH = void 0;
|
|
4
|
+
exports.renderCard = renderCard;
|
|
5
|
+
exports.renderList = renderList;
|
|
6
|
+
const koishi_1 = require("koishi");
|
|
7
|
+
const server_1 = require("react-dom/server");
|
|
8
|
+
const text_1 = require("../text");
|
|
9
|
+
const ChannelCard_1 = require("./ChannelCard");
|
|
10
|
+
const StatusCard_1 = require("./StatusCard");
|
|
11
|
+
const log_1 = require("../log");
|
|
12
|
+
const styles_1 = require("./styles");
|
|
13
|
+
Object.defineProperty(exports, "CARD_WIDTH", { enumerable: true, get: function () { return styles_1.CARD_WIDTH; } });
|
|
14
|
+
function puppeteerOf(ctx) {
|
|
15
|
+
try {
|
|
16
|
+
return ctx.puppeteer ?? undefined;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function wrap(body, title) {
|
|
23
|
+
return [
|
|
24
|
+
'<!DOCTYPE html><html><head><meta charset="utf-8">',
|
|
25
|
+
`<title>${escapeHtml(title)}</title>`,
|
|
26
|
+
`<style>${styles_1.CSS}</style>`,
|
|
27
|
+
'</head><body>',
|
|
28
|
+
body,
|
|
29
|
+
'</body></html>',
|
|
30
|
+
].join('');
|
|
31
|
+
}
|
|
32
|
+
function escapeHtml(text) {
|
|
33
|
+
return String(text).replace(/[&<>"']/g, (char) => ({
|
|
34
|
+
'&': '&',
|
|
35
|
+
'<': '<',
|
|
36
|
+
'>': '>',
|
|
37
|
+
'"': '"',
|
|
38
|
+
"'": ''',
|
|
39
|
+
})[char]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 把视图渲染成消息元素。
|
|
43
|
+
* image 分支返回 puppeteer 给的图片标记(字符串形式,交给 h 解析);
|
|
44
|
+
* text 分支必须用 h.text 包裹,避免正文里的尖括号被当成元素标记。
|
|
45
|
+
*/
|
|
46
|
+
async function render(ctx, mode, body, title, fallback) {
|
|
47
|
+
if (mode === 'text')
|
|
48
|
+
return koishi_1.h.text(fallback());
|
|
49
|
+
const puppeteer = puppeteerOf(ctx);
|
|
50
|
+
if (!puppeteer) {
|
|
51
|
+
const text = fallback();
|
|
52
|
+
if (mode === 'image')
|
|
53
|
+
return koishi_1.h.text(`${text}\n\n(未启用 puppeteer 服务,已降级为文字)`);
|
|
54
|
+
return koishi_1.h.text(text);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return await puppeteer.render(wrap(body, title));
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
ctx.logger(log_1.LOGGER_NAME).warn('卡片渲染失败,降级为文字输出:%s', error?.message);
|
|
61
|
+
return koishi_1.h.text(`${fallback()}\n\n(卡片渲染失败,已降级为文字)`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function renderCard(ctx, card, options) {
|
|
65
|
+
const body = (0, server_1.renderToStaticMarkup)((0, StatusCard_1.StatusCard)({ card }));
|
|
66
|
+
return render(ctx, options.enabled ? options.mode : 'text', body, card.siteName, () => (0, text_1.renderCardText)(card));
|
|
67
|
+
}
|
|
68
|
+
async function renderList(ctx, list, options) {
|
|
69
|
+
const body = (0, server_1.renderToStaticMarkup)((0, ChannelCard_1.ChannelCard)({ list }));
|
|
70
|
+
return render(ctx, options.enabled ? options.mode : 'text', body, list.title, () => (0, text_1.renderListText)(list));
|
|
71
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 暗色玻璃拟态(dark glassmorphism)样式。
|
|
3
|
+
* 视觉基线取自用户确认的站内「渠道状态」大屏:深色底 + 半透明玻璃卡 + 彩色状态点 + 双色度量块。
|
|
4
|
+
* puppeteer 用 Chrome headless 渲染,backdrop-filter / 渐变 / 阴影都支持。
|
|
5
|
+
*/
|
|
6
|
+
export declare const CARD_WIDTH = 660;
|
|
7
|
+
export declare const COLORS: {
|
|
8
|
+
readonly bg: "#0b0c10";
|
|
9
|
+
readonly surface: "rgba(255,255,255,0.055)";
|
|
10
|
+
readonly surfaceStrong: "rgba(255,255,255,0.085)";
|
|
11
|
+
readonly border: "rgba(255,255,255,0.10)";
|
|
12
|
+
readonly borderSoft: "rgba(255,255,255,0.07)";
|
|
13
|
+
readonly text: "#f2f4f8";
|
|
14
|
+
readonly textSecondary: "rgba(232,236,244,0.64)";
|
|
15
|
+
readonly textFaint: "rgba(232,236,244,0.40)";
|
|
16
|
+
readonly accent: "#0a84ff";
|
|
17
|
+
readonly accent2: "#5ac8fa";
|
|
18
|
+
readonly ok: "#30d158";
|
|
19
|
+
readonly warn: "#ffd60a";
|
|
20
|
+
readonly fail: "#ff453a";
|
|
21
|
+
readonly orange: "#ff9f0a";
|
|
22
|
+
};
|
|
23
|
+
export declare const CSS: string;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CSS = exports.COLORS = exports.CARD_WIDTH = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 暗色玻璃拟态(dark glassmorphism)样式。
|
|
6
|
+
* 视觉基线取自用户确认的站内「渠道状态」大屏:深色底 + 半透明玻璃卡 + 彩色状态点 + 双色度量块。
|
|
7
|
+
* puppeteer 用 Chrome headless 渲染,backdrop-filter / 渐变 / 阴影都支持。
|
|
8
|
+
*/
|
|
9
|
+
exports.CARD_WIDTH = 660;
|
|
10
|
+
exports.COLORS = {
|
|
11
|
+
bg: '#0b0c10',
|
|
12
|
+
surface: 'rgba(255,255,255,0.055)',
|
|
13
|
+
surfaceStrong: 'rgba(255,255,255,0.085)',
|
|
14
|
+
border: 'rgba(255,255,255,0.10)',
|
|
15
|
+
borderSoft: 'rgba(255,255,255,0.07)',
|
|
16
|
+
text: '#f2f4f8',
|
|
17
|
+
textSecondary: 'rgba(232,236,244,0.64)',
|
|
18
|
+
textFaint: 'rgba(232,236,244,0.40)',
|
|
19
|
+
accent: '#0a84ff',
|
|
20
|
+
accent2: '#5ac8fa',
|
|
21
|
+
ok: '#30d158',
|
|
22
|
+
warn: '#ffd60a',
|
|
23
|
+
fail: '#ff453a',
|
|
24
|
+
orange: '#ff9f0a',
|
|
25
|
+
};
|
|
26
|
+
exports.CSS = `
|
|
27
|
+
* { box-sizing: border-box; }
|
|
28
|
+
html, body { margin: 0; padding: 0; background: ${exports.COLORS.bg}; }
|
|
29
|
+
body {
|
|
30
|
+
display: inline-block; min-width: ${exports.CARD_WIDTH + 48}px;
|
|
31
|
+
background:
|
|
32
|
+
radial-gradient(900px 420px at 10% -12%, rgba(10,132,255,0.22), transparent 62%),
|
|
33
|
+
radial-gradient(760px 380px at 108% 6%, rgba(48,209,88,0.14), transparent 64%),
|
|
34
|
+
radial-gradient(620px 320px at 50% 116%, rgba(255,159,10,0.10), transparent 66%),
|
|
35
|
+
linear-gradient(180deg, #12141a 0%, #0b0c10 62%, #07080b 100%);
|
|
36
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
|
|
37
|
+
color: ${exports.COLORS.text};
|
|
38
|
+
-webkit-font-smoothing: antialiased;
|
|
39
|
+
}
|
|
40
|
+
.card {
|
|
41
|
+
width: ${exports.CARD_WIDTH}px;
|
|
42
|
+
margin: 20px;
|
|
43
|
+
border-radius: 20px;
|
|
44
|
+
background: linear-gradient(180deg, rgba(255,255,255,0.075), rgba(255,255,255,0.032));
|
|
45
|
+
border: 1px solid ${exports.COLORS.border};
|
|
46
|
+
box-shadow: 0 26px 64px rgba(0,0,0,0.58), inset 0 1px 0 rgba(255,255,255,0.09);
|
|
47
|
+
backdrop-filter: blur(26px) saturate(150%);
|
|
48
|
+
-webkit-backdrop-filter: blur(26px) saturate(150%);
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
}
|
|
51
|
+
.card-head {
|
|
52
|
+
display: flex; align-items: center; gap: 13px;
|
|
53
|
+
padding: 19px 22px 16px;
|
|
54
|
+
}
|
|
55
|
+
.logo {
|
|
56
|
+
width: 40px; height: 40px; border-radius: 13px; flex: none;
|
|
57
|
+
display: flex; align-items: center; justify-content: center;
|
|
58
|
+
font-size: 18px; font-weight: 650; color: #fff;
|
|
59
|
+
background: linear-gradient(150deg, #0a84ff, #6a5cff 54%, #30d158);
|
|
60
|
+
box-shadow: 0 8px 22px rgba(10,132,255,0.42), inset 0 1px 0 rgba(255,255,255,0.35);
|
|
61
|
+
}
|
|
62
|
+
.head-main { flex: 1; min-width: 0; }
|
|
63
|
+
.site-name { font-size: 17.5px; font-weight: 650; letter-spacing: .2px; line-height: 1.25; }
|
|
64
|
+
.site-sub { font-size: 11.5px; color: ${exports.COLORS.textFaint}; margin-top: 4px; letter-spacing: .2px; }
|
|
65
|
+
.badges { display: flex; align-items: center; gap: 7px; flex: none; }
|
|
66
|
+
.badge {
|
|
67
|
+
font-size: 11.5px; padding: 4px 11px; border-radius: 999px; white-space: nowrap;
|
|
68
|
+
border: 1px solid ${exports.COLORS.borderSoft}; color: ${exports.COLORS.textSecondary};
|
|
69
|
+
background: rgba(255,255,255,0.045); font-variant-numeric: tabular-nums;
|
|
70
|
+
}
|
|
71
|
+
.badge.ok { color: #6ff0a0; background: rgba(48,209,88,0.13); border-color: rgba(48,209,88,0.30); }
|
|
72
|
+
.badge.warn { color: ${exports.COLORS.warn}; background: rgba(255,214,10,0.12); border-color: rgba(255,214,10,0.28); }
|
|
73
|
+
.badge.fail { color: #ff8b83; background: rgba(255,69,58,0.14); border-color: rgba(255,69,58,0.32); }
|
|
74
|
+
.metrics {
|
|
75
|
+
display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
|
|
76
|
+
padding: 0 18px 16px;
|
|
77
|
+
}
|
|
78
|
+
.metric {
|
|
79
|
+
padding: 12px 14px 13px; border-radius: 15px;
|
|
80
|
+
background: rgba(255,255,255,0.048);
|
|
81
|
+
border: 1px solid ${exports.COLORS.borderSoft};
|
|
82
|
+
box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
|
|
83
|
+
min-width: 0;
|
|
84
|
+
}
|
|
85
|
+
.metric-k { font-size: 10.5px; color: ${exports.COLORS.textFaint}; letter-spacing: .3px; }
|
|
86
|
+
.metric-v {
|
|
87
|
+
font-size: 20px; font-weight: 620; margin-top: 7px; line-height: 1.15;
|
|
88
|
+
font-variant-numeric: tabular-nums; letter-spacing: .2px;
|
|
89
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
90
|
+
}
|
|
91
|
+
.metric-v.ok { color: #5ef08f; }
|
|
92
|
+
.metric-v.warn { color: ${exports.COLORS.warn}; }
|
|
93
|
+
.metric-v.fail { color: #ff6f66; }
|
|
94
|
+
.metric-sub { font-size: 10.5px; color: ${exports.COLORS.textFaint}; margin-top: 5px; }
|
|
95
|
+
.section { padding: 15px 22px 17px; border-top: 1px solid ${exports.COLORS.borderSoft}; }
|
|
96
|
+
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 11px; gap: 10px; }
|
|
97
|
+
.section-title { font-size: 12.5px; font-weight: 600; letter-spacing: .3px; color: rgba(255,255,255,0.88); }
|
|
98
|
+
.section-note { font-size: 10.5px; color: ${exports.COLORS.textFaint}; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
99
|
+
.row { display: flex; align-items: center; gap: 11px; padding: 5px 0; }
|
|
100
|
+
.row-name {
|
|
101
|
+
font-size: 12.5px; flex: none; width: 176px; color: rgba(255,255,255,0.82);
|
|
102
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
103
|
+
}
|
|
104
|
+
.row-bar { flex: 1; height: 7px; border-radius: 999px; background: rgba(255,255,255,0.07); overflow: hidden; }
|
|
105
|
+
.row-bar > i {
|
|
106
|
+
display: block; height: 100%; border-radius: 999px;
|
|
107
|
+
background: linear-gradient(90deg, ${exports.COLORS.accent}, ${exports.COLORS.accent2});
|
|
108
|
+
box-shadow: 0 0 12px rgba(10,132,255,0.55);
|
|
109
|
+
}
|
|
110
|
+
.row-bar.warn > i { background: linear-gradient(90deg, ${exports.COLORS.orange}, ${exports.COLORS.warn}); box-shadow: 0 0 12px rgba(255,159,10,0.5); }
|
|
111
|
+
.row-bar.fail > i { background: linear-gradient(90deg, #ff453a, #ff9f0a); box-shadow: 0 0 12px rgba(255,69,58,0.5); }
|
|
112
|
+
.row-value {
|
|
113
|
+
font-size: 11.5px; color: ${exports.COLORS.textSecondary}; font-variant-numeric: tabular-nums;
|
|
114
|
+
min-width: 88px; text-align: right; white-space: nowrap;
|
|
115
|
+
}
|
|
116
|
+
.blocks { display: flex; gap: 3px; margin-top: 2px; }
|
|
117
|
+
.block { flex: 1; height: 30px; border-radius: 5px; background: rgba(255,255,255,0.09); }
|
|
118
|
+
.block.ok { background: linear-gradient(180deg, #4ff08b, #22b24b); box-shadow: 0 0 14px rgba(48,209,88,0.42); }
|
|
119
|
+
.block.warn { background: linear-gradient(180deg, #ffe066, #e0a800); box-shadow: 0 0 14px rgba(255,214,10,0.35); }
|
|
120
|
+
.block.fail { background: linear-gradient(180deg, #ff7369, #d92a1f); box-shadow: 0 0 14px rgba(255,69,58,0.45); }
|
|
121
|
+
.axis {
|
|
122
|
+
display: flex; justify-content: space-between; font-size: 10px;
|
|
123
|
+
color: ${exports.COLORS.textFaint}; margin-top: 8px; font-variant-numeric: tabular-nums;
|
|
124
|
+
}
|
|
125
|
+
.legend { display: flex; gap: 15px; font-size: 10.5px; color: ${exports.COLORS.textSecondary}; margin-top: 11px; }
|
|
126
|
+
.legend i { display: inline-block; width: 7px; height: 7px; border-radius: 5px; margin-right: 6px; vertical-align: 1px; }
|
|
127
|
+
.notice {
|
|
128
|
+
display: flex; gap: 11px; padding: 13px 22px;
|
|
129
|
+
background: rgba(255,214,10,0.075);
|
|
130
|
+
border-top: 1px solid rgba(255,214,10,0.18);
|
|
131
|
+
border-bottom: 1px solid rgba(255,214,10,0.10);
|
|
132
|
+
}
|
|
133
|
+
.notice-tag {
|
|
134
|
+
/* align-self:否则 flex 布局默认 stretch,标签会被拉到和公告正文一样高,变成一个竖椭圆 */
|
|
135
|
+
align-self: flex-start; white-space: nowrap;
|
|
136
|
+
flex: none; font-size: 10.5px; color: ${exports.COLORS.warn};
|
|
137
|
+
background: rgba(255,214,10,0.15); border: 1px solid rgba(255,214,10,0.30);
|
|
138
|
+
border-radius: 999px; padding: 2px 9px; line-height: 15px; letter-spacing: .3px;
|
|
139
|
+
}
|
|
140
|
+
.notice-body { font-size: 11.5px; color: rgba(255,236,180,0.86); line-height: 19px; }
|
|
141
|
+
.card-foot {
|
|
142
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
143
|
+
padding: 10px 22px; background: rgba(0,0,0,0.22);
|
|
144
|
+
font-size: 10px; color: ${exports.COLORS.textFaint}; letter-spacing: .3px;
|
|
145
|
+
font-variant-numeric: tabular-nums;
|
|
146
|
+
}
|
|
147
|
+
.list { display: flex; flex-direction: column; }
|
|
148
|
+
.list-row {
|
|
149
|
+
display: flex; align-items: center; gap: 11px; padding: 9px 0;
|
|
150
|
+
border-bottom: 1px solid rgba(255,255,255,0.05);
|
|
151
|
+
}
|
|
152
|
+
.list-row:last-child { border-bottom: none; }
|
|
153
|
+
.dot {
|
|
154
|
+
width: 7px; height: 7px; border-radius: 50%; flex: none;
|
|
155
|
+
background: rgba(255,255,255,0.22);
|
|
156
|
+
}
|
|
157
|
+
.dot.ok { background: ${exports.COLORS.ok}; box-shadow: 0 0 10px rgba(48,209,88,0.75); }
|
|
158
|
+
.dot.warn { background: ${exports.COLORS.warn}; box-shadow: 0 0 10px rgba(255,214,10,0.7); }
|
|
159
|
+
.dot.fail { background: ${exports.COLORS.fail}; box-shadow: 0 0 10px rgba(255,69,58,0.75); }
|
|
160
|
+
.list-name {
|
|
161
|
+
font-size: 12.5px; flex: 1; min-width: 0; color: rgba(255,255,255,0.85);
|
|
162
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
163
|
+
}
|
|
164
|
+
.list-tag {
|
|
165
|
+
flex: none; font-size: 10px; color: ${exports.COLORS.textSecondary};
|
|
166
|
+
background: rgba(255,255,255,0.06); border: 1px solid ${exports.COLORS.borderSoft};
|
|
167
|
+
border-radius: 999px; padding: 2px 8px; max-width: 210px;
|
|
168
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
169
|
+
}
|
|
170
|
+
.list-value {
|
|
171
|
+
flex: none; font-size: 11px; font-variant-numeric: tabular-nums;
|
|
172
|
+
color: ${exports.COLORS.textSecondary}; white-space: nowrap; max-width: 400px;
|
|
173
|
+
overflow: hidden; text-overflow: ellipsis;
|
|
174
|
+
}
|
|
175
|
+
.list-row.wrap { align-items: flex-start; }
|
|
176
|
+
.list-row.wrap .list-name { flex: none; width: 64px; color: ${exports.COLORS.textFaint}; font-size: 11px; padding-top: 1px; }
|
|
177
|
+
.list-row.wrap .list-value {
|
|
178
|
+
flex: 1; max-width: none; text-align: left; white-space: normal;
|
|
179
|
+
line-height: 1.62; color: rgba(255,255,255,0.80);
|
|
180
|
+
}
|
|
181
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
182
|
+
.chip {
|
|
183
|
+
font-size: 11px; color: rgba(255,255,255,0.80);
|
|
184
|
+
background: rgba(255,255,255,0.055); border: 1px solid ${exports.COLORS.borderSoft};
|
|
185
|
+
border-radius: 999px; padding: 3px 10px; font-variant-numeric: tabular-nums;
|
|
186
|
+
}
|
|
187
|
+
.list-more {
|
|
188
|
+
font-size: 10.5px; color: ${exports.COLORS.textFaint}; padding: 10px 0 2px; letter-spacing: .2px;
|
|
189
|
+
border-top: 1px dashed rgba(255,255,255,0.08); margin-top: 6px;
|
|
190
|
+
}
|
|
191
|
+
.empty { font-size: 11.5px; color: ${exports.COLORS.textFaint}; padding: 4px 0; }
|
|
192
|
+
`;
|
package/lib/text.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CardBlock, CardView, ListView } from './view';
|
|
2
|
+
export declare function renderCardText(card: CardView): string;
|
|
3
|
+
export declare function blocksToText(blocks: CardBlock[]): string;
|
|
4
|
+
export declare function renderListText(list: ListView): string;
|
|
5
|
+
/** 指令列表(/newapi help)用文本表格,不渲染卡片。 */
|
|
6
|
+
export declare function renderHelp(prefix: string, items: Array<{
|
|
7
|
+
usage: string;
|
|
8
|
+
desc: string;
|
|
9
|
+
}>): string;
|
|
10
|
+
export declare function renderError(title: string, detail: string): string;
|