101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
import { z } from "zod";
|
|
|
|
export const feedbackMessageSchema = z.object({
|
|
id: z.string().max(180),
|
|
role: z.enum(["user", "assistant"]),
|
|
text: z.string().max(16000),
|
|
createdAt: z.string().max(64).optional(),
|
|
requestId: z.string().max(180).optional(),
|
|
status: z.string().max(64).optional(),
|
|
error: z.string().max(2000).optional(),
|
|
userMessageId: z.string().max(180).optional(),
|
|
});
|
|
export const feedbackClientSchema = z.object({
|
|
chatId: z.string().uuid().nullable(),
|
|
messages: z.array(feedbackMessageSchema).max(12),
|
|
pageVersion: z.string().max(100),
|
|
capturedAt: z.string().datetime(),
|
|
viewport: z.object({
|
|
width: z.number().int().min(0).max(30000),
|
|
height: z.number().int().min(0).max(30000),
|
|
}),
|
|
online: z.boolean(),
|
|
errors: z.array(z.string().max(2000)).max(5),
|
|
nodes: z
|
|
.array(
|
|
z.object({
|
|
id: z.string().max(180),
|
|
type: z.string().max(64),
|
|
title: z.string().max(256),
|
|
status: z.string().max(64),
|
|
taskId: z.string().max(180),
|
|
width: z.number().optional(),
|
|
height: z.number().optional(),
|
|
}),
|
|
)
|
|
.max(20)
|
|
.default([]),
|
|
});
|
|
export const feedbackCommandSchema = z.discriminatedUnion("action", [
|
|
z.object({ action: z.literal("context"), client: feedbackClientSchema }),
|
|
z.object({
|
|
action: z.literal("submit"),
|
|
id: z.string().uuid(),
|
|
description: z.string().trim().max(2000),
|
|
selection: z.string().max(220).nullable(),
|
|
client: feedbackClientSchema,
|
|
}),
|
|
]);
|
|
export type FeedbackClient = z.infer<typeof feedbackClientSchema>;
|
|
export type FeedbackMessage = z.infer<typeof feedbackMessageSchema>;
|
|
export type FeedbackRequest = {
|
|
key: string;
|
|
kind: "message" | "agent" | "capability" | "image";
|
|
id: string;
|
|
requestId: string | null;
|
|
createdAt: string;
|
|
prompt: string;
|
|
status: string;
|
|
model: string | null;
|
|
error: string | null;
|
|
durationMs?: number | null;
|
|
parameters?: Record<string, unknown>;
|
|
evidence: "server" | "browser";
|
|
};
|
|
export type FeedbackContext = {
|
|
reporter: { id: string; name: string; email: string; department: string | null };
|
|
project: { id: string; title: string };
|
|
requests: FeedbackRequest[];
|
|
};
|
|
export type FeedbackSnapshot = Omit<FeedbackContext, "requests"> & {
|
|
request: FeedbackRequest | null;
|
|
client: FeedbackClient;
|
|
userAgent: string;
|
|
};
|
|
export type FeedbackReceipt = {
|
|
id: string;
|
|
status: string;
|
|
deliveryId: string | null;
|
|
message: string;
|
|
};
|
|
|
|
export function feedbackStatusMessage(status: string, errorCode?: string | null) {
|
|
if (["sent", "unread", "read"].includes(status)) return "反馈已投递给魔礼红。";
|
|
if (status === "failed")
|
|
return errorCode === "DELIVERY_OUTCOME_UNKNOWN"
|
|
? "反馈已保存,但钉钉投递结果暂无法确认。请保留反馈编号,避免重复提交。"
|
|
: "反馈已保存,但钉钉通知投递失败。请保留反馈编号并联系管理员。";
|
|
if (status === "pending") return "反馈已保存,正在提交通知;短暂故障会自动重试,无需再次反馈。";
|
|
return "反馈已保存,通知中心已受理,等待投递给魔礼红。";
|
|
}
|
|
|
|
export function formatFeedbackTime(value: string) {
|
|
if (!Number.isFinite(Date.parse(value))) return "未记录";
|
|
return new Intl.DateTimeFormat("zh-CN", {
|
|
timeZone: "Asia/Shanghai",
|
|
dateStyle: "short",
|
|
timeStyle: "medium",
|
|
hour12: false,
|
|
}).format(new Date(value));
|
|
}
|