/** 既有权限业务与数字人运营的统一后台接口。 */ import { http } from "@/utils/http"; /** * 门店权限后台的业务接口层。 * * 页面只依赖这里导出的类型和方法,避免在视图组件中散落接口路径、 * 响应结构和状态枚举。后端统一挂在 `/api` 前缀下,由 Vite 代理转发。 */ const API_PREFIX = "/api"; const EMPLOYEE_OPTION_PAGE_SIZE = 100; /** 后端员工与门店共用的启停状态枚举。 */ export type EmployeeStatus = "ACTIVE" | "INACTIVE"; export type StoreStatus = "ACTIVE" | "INACTIVE"; export type EmployeeStatusTagVariant = "success" | "warning" | "default"; export interface EmployeeStatusTag { code: "EMPLOYEE_ACTIVE" | "EMPLOYEE_INACTIVE" | "STORE_INACTIVE"; label: string; variant: EmployeeStatusTagVariant; } /** 员工列表中展示的角色摘要。 */ export interface RoleSummary { id: number; code: string; name: string; } export interface Employee { id: number; storeId: number; storeName: string; storeStatus: StoreStatus; name: string; phone: string; status: EmployeeStatus; statusTags: EmployeeStatusTag[]; remark: string | null; roles: RoleSummary[]; createdAt: string; updatedAt: string; } export interface StoreOption { id: number; name: string; address: string | null; phone: string | null; } export interface RoleOption { id: number; code: string; name: string; description: string | null; isSystem: boolean; } export interface Store extends StoreOption { status: StoreStatus; createdAt: string; updatedAt: string; } export interface StoreDetail extends Store { employees: Employee[]; } export interface Role extends RoleOption { createdAt: string; updatedAt: string; } export interface PermissionPolicyMenu { key: string; title: string; actions: string[]; } export interface PermissionPolicy { roleId: number; roleCode: string; roleName: string; roleDescription: string | null; isSystem: boolean; editable: boolean; scope: string; permissions: string[]; menus: PermissionPolicyMenu[]; } export interface PermissionDefinition { code: string; title: string; description: string; groupKey: string; groupTitle: string; } export interface PermissionDefinitionGroup { key: string; title: string; permissions: PermissionDefinition[]; } export interface PermissionDefinitionMenu { key: string; title: string; icon?: string; permission: string; actions: string[]; actionLabels: Record; } export interface PermissionDefinitions { permissions: PermissionDefinition[]; groups: PermissionDefinitionGroup[]; menus: PermissionDefinitionMenu[]; } /** 列表接口是服务端分页,筛选条件统一通过查询参数传递。 */ export interface PageParams { page: number; pageSize: number; } export interface EmployeeListParams extends PageParams { storeId?: number; status?: EmployeeStatus; keyword?: string; } export type EmployeeOptionParams = Partial< Pick >; export interface StoreListParams extends PageParams { includeInactive?: boolean; status?: StoreStatus; keyword?: string; } export interface RoleListParams extends PageParams { keyword?: string; isSystem?: boolean; } export interface StorePayload { name: string; address?: string | null; phone?: string | null; status: StoreStatus; } export interface RolePayload { code: string; name: string; description?: string | null; } export interface EmployeePayload { storeId: number; name: string; phone: string; status: EmployeeStatus; remark?: string | null; roleIds: number[]; } export interface EmployeePasswordPayload { oldPassword: string; newPassword: string; } export interface EmployeePasswordResetPayload { reason: string; } export interface EmployeePasswordResetResult { employeeId: number; temporaryPassword: string; } export type AnnouncementImportance = "NORMAL" | "IMPORTANT" | "URGENT"; export type AnnouncementStatus = "DRAFT" | "PUBLISHED" | "ARCHIVED"; export type AnnouncementTargetScope = | "ALL_STORES" | "STORES" | "ROLES" | "EMPLOYEES"; export interface Announcement { id: number; title: string; content: string; importance: AnnouncementImportance; targetScope: AnnouncementTargetScope; targetStoreIds: number[]; targetRoleIds: number[]; targetEmployeeIds: number[]; status: AnnouncementStatus; publisherName: string | null; publishedAt: string | null; readCount: number; createdAt: string; updatedAt: string; } export interface AnnouncementListParams extends PageParams { status?: AnnouncementStatus; importance?: AnnouncementImportance; keyword?: string; } export interface AnnouncementPayload { title: string; content: string; importance: AnnouncementImportance; targetScope: AnnouncementTargetScope; targetStoreIds: number[]; targetRoleIds: number[]; targetEmployeeIds: number[]; } export type TaskStatus = "PENDING" | "IN_PROGRESS" | "COMPLETED" | "CANCELLED"; export type TaskPriority = "LOW" | "NORMAL" | "HIGH" | "URGENT"; export interface TaskEvent { id: number; action: string; remark: string | null; operatorName: string | null; createdAt: string; } export interface Task { id: number; title: string; description: string | null; storeId: number; storeName: string; assigneeIds: number[]; assigneeNames: string[]; status: TaskStatus; priority: TaskPriority; deadlineAt: string | null; creatorName: string | null; events?: TaskEvent[]; createdAt: string; updatedAt: string; } export interface TaskListParams extends PageParams { storeId?: number; employeeId?: number; status?: TaskStatus; priority?: TaskPriority; keyword?: string; } export interface TaskPayload { title: string; description?: string | null; storeId: number; assigneeIds: number[]; priority: TaskPriority; deadlineAt?: string | null; } export type ShiftStatus = "SCHEDULED" | "CANCELLED" | "COMPLETED"; export interface Shift { id: number; storeId: number; storeName: string; employeeId: number; employeeName: string; position: string; startAt: string; endAt: string; status: ShiftStatus; createdAt: string; updatedAt: string; } export interface ShiftListParams extends PageParams { storeId?: number; employeeId?: number; startDate?: string; endDate?: string; } export interface ShiftPayload { storeId: number; employeeId: number; position: string; startAt: string; endAt: string; } export interface CredentialAudit { id: number; operatorName: string; targetEmployeeName: string; targetEmployeePhone: string | null; storeName: string | null; action: string; operatedAt: string; ip: string | null; userAgent: string | null; reason: string; } export interface CredentialAuditListParams extends PageParams { operatorId?: number; targetEmployeeId?: number; storeId?: number; startDate?: string; endDate?: string; } /** access-manage 后端普通响应包裹结构。 */ export interface ApiResult { success: boolean; data: T; } export interface Pagination { page: number; pageSize: number; total: number; totalPages: number; } export interface PaginatedData { items: T[]; pagination: Pagination; } type LegacyAnnouncementImportance = "LOW" | "HIGH"; type BackendAnnouncementTargetType = "ALL" | "STORE" | "ROLE" | "EMPLOYEE"; type BackendConcreteAnnouncementTargetType = Exclude< BackendAnnouncementTargetType, "ALL" >; interface BackendAnnouncementTarget { type: BackendConcreteAnnouncementTargetType; id: number; } interface BackendAnnouncement { id: number; title: string; content: string; level?: AnnouncementImportance | LegacyAnnouncementImportance; importance?: AnnouncementImportance | LegacyAnnouncementImportance; status: AnnouncementStatus; targetType?: BackendAnnouncementTargetType; targetScope?: AnnouncementTargetScope; targets?: BackendAnnouncementTarget[]; targetStoreIds?: number[]; targetRoleIds?: number[]; targetEmployeeIds?: number[]; publisherName?: string | null; publishedAt: string | null; readCount?: number; createdAt: string; updatedAt: string; } type BackendAnnouncementPayload = Omit< AnnouncementPayload, | "importance" | "targetScope" | "targetStoreIds" | "targetRoleIds" | "targetEmployeeIds" > & { level: AnnouncementImportance; targetType: BackendAnnouncementTargetType; targets: BackendAnnouncementTarget[]; }; type BackendTaskStatus = TaskStatus | "CANCELED"; interface BackendTaskAssignee { id: number; name: string; phone?: string | null; } interface BackendTaskEvent { id: number; action?: string; eventType?: string; remark?: string | null; comment?: string | null; operatorName?: string | null; createdAt: string; } interface BackendTask { id: number; title: string; description: string | null; storeId: number | null; storeName: string | null; assignees?: BackendTaskAssignee[]; assigneeIds?: number[]; assigneeNames?: string[]; status: BackendTaskStatus; priority: TaskPriority; dueAt?: string | null; deadlineAt?: string | null; creatorName?: string | null; events?: BackendTaskEvent[]; createdAt: string; updatedAt: string; } type BackendTaskPayload = Omit & { dueAt?: string | null; assignees?: number[]; }; type BackendShiftStatus = ShiftStatus | "CANCELED"; interface BackendShift { id: number; storeId: number; storeName: string; employeeId: number; employeeName: string; roleName?: string | null; position?: string | null; startAt: string; endAt: string; status: BackendShiftStatus; createdAt: string; updatedAt: string; } type BackendShiftPayload = Omit & { roleName?: string | null; status?: "SCHEDULED"; }; interface BackendCredentialAudit { id: number; actorName?: string | null; operatorName?: string | null; targetEmployeeName: string; targetEmployeePhone?: string | null; storeName?: string | null; action: string; createdAt?: string; operatedAt?: string; ip: string | null; userAgent: string | null; reason: string | null; } function mapApiResult( result: ApiResult, mapper: (data: T) => R ): ApiResult { return { ...result, data: mapper(result.data) }; } function mapPaginatedData( data: PaginatedData, mapper: (item: T) => R ): PaginatedData { return { ...data, items: data.items.map(mapper) }; } function hasOwn(data: T, key: keyof T) { return Object.prototype.hasOwnProperty.call(data, key); } function toBackendDateTime(value?: string | null) { if (value === undefined) return undefined; if (!value) return null; const normalizedValue = value.includes("T") ? value : value.replace(" ", "T"); const date = new Date(normalizedValue); return Number.isNaN(date.getTime()) ? value : date.toISOString(); } function normalizeAnnouncementImportance( value?: AnnouncementImportance | LegacyAnnouncementImportance | null ): AnnouncementImportance { if (value === "URGENT" || value === "IMPORTANT" || value === "NORMAL") { return value; } return value === "HIGH" ? "IMPORTANT" : "NORMAL"; } function toBackendAnnouncementTargetType( scope: AnnouncementTargetScope ): BackendAnnouncementTargetType { const scopeMap: Record< AnnouncementTargetScope, BackendAnnouncementTargetType > = { ALL_STORES: "ALL", STORES: "STORE", ROLES: "ROLE", EMPLOYEES: "EMPLOYEE" }; return scopeMap[scope]; } function toAnnouncementTargetScope( targetType?: BackendAnnouncementTargetType ): AnnouncementTargetScope { const targetTypeMap: Record< BackendAnnouncementTargetType, AnnouncementTargetScope > = { ALL: "ALL_STORES", STORE: "STORES", ROLE: "ROLES", EMPLOYEE: "EMPLOYEES" }; return targetTypeMap[targetType ?? "ALL"]; } function getAnnouncementTargetIds( targets: BackendAnnouncementTarget[], type: BackendConcreteAnnouncementTargetType ) { return targets .filter(target => target.type === type) .map(target => target.id); } function toBackendAnnouncementPayload( data: Partial ): Partial { const payload: Partial = {}; if (hasOwn(data, "title")) payload.title = data.title; if (hasOwn(data, "content")) payload.content = data.content; if (hasOwn(data, "importance")) { payload.level = normalizeAnnouncementImportance(data.importance); } if (hasOwn(data, "targetScope")) { payload.targetType = toBackendAnnouncementTargetType( data.targetScope ?? "ALL_STORES" ); } if ( hasOwn(data, "targetScope") || hasOwn(data, "targetStoreIds") || hasOwn(data, "targetRoleIds") || hasOwn(data, "targetEmployeeIds") ) { const targetType = payload.targetType ?? toBackendAnnouncementTargetType(data.targetScope ?? "ALL_STORES"); const targetIds = targetType === "STORE" ? (data.targetStoreIds ?? []) : targetType === "ROLE" ? (data.targetRoleIds ?? []) : targetType === "EMPLOYEE" ? (data.targetEmployeeIds ?? []) : []; payload.targets = targetType === "ALL" ? [] : targetIds.map(id => ({ type: targetType, id })); } return payload; } function normalizeAnnouncement( announcement: BackendAnnouncement ): Announcement { const targets = announcement.targets ?? []; const targetScope = announcement.targetScope ?? toAnnouncementTargetScope(announcement.targetType); return { id: announcement.id, title: announcement.title, content: announcement.content, importance: normalizeAnnouncementImportance( announcement.level ?? announcement.importance ), targetScope, targetStoreIds: announcement.targetStoreIds ?? getAnnouncementTargetIds(targets, "STORE"), targetRoleIds: announcement.targetRoleIds ?? getAnnouncementTargetIds(targets, "ROLE"), targetEmployeeIds: announcement.targetEmployeeIds ?? getAnnouncementTargetIds(targets, "EMPLOYEE"), status: announcement.status, publisherName: announcement.publisherName ?? null, publishedAt: announcement.publishedAt, readCount: announcement.readCount ?? 0, createdAt: announcement.createdAt, updatedAt: announcement.updatedAt }; } function normalizeTaskStatus(status: BackendTaskStatus): TaskStatus { return status === "CANCELED" ? "CANCELLED" : status; } function normalizeShiftStatus(status: BackendShiftStatus): ShiftStatus { return status === "CANCELED" ? "CANCELLED" : status; } function toBackendTaskStatus(status?: BackendTaskStatus) { return status === "CANCELED" ? "CANCELLED" : status; } function normalizeTask(task: BackendTask): Task { const assignees = task.assignees ?? []; return { id: task.id, title: task.title, description: task.description, storeId: task.storeId ?? 0, storeName: task.storeName ?? "-", assigneeIds: task.assigneeIds ?? assignees.map(assignee => assignee.id), assigneeNames: task.assigneeNames ?? assignees.map(assignee => assignee.name), status: normalizeTaskStatus(task.status), priority: task.priority, deadlineAt: task.deadlineAt ?? task.dueAt ?? null, creatorName: task.creatorName ?? null, events: task.events?.map(event => ({ id: event.id, action: event.action ?? event.eventType ?? "", remark: event.remark ?? event.comment ?? null, operatorName: event.operatorName ?? null, createdAt: event.createdAt })), createdAt: task.createdAt, updatedAt: task.updatedAt }; } function toBackendTaskPayload( data: Partial ): Partial { const payload = { ...data } as Partial & Partial; delete payload.deadlineAt; if (hasOwn(data, "deadlineAt")) { payload.dueAt = toBackendDateTime(data.deadlineAt); } if (hasOwn(data, "assigneeIds")) { payload.assignees = data.assigneeIds; } return payload; } function normalizeShift(shift: BackendShift): Shift { return { id: shift.id, storeId: shift.storeId, storeName: shift.storeName, employeeId: shift.employeeId, employeeName: shift.employeeName, position: shift.position ?? shift.roleName ?? "", startAt: shift.startAt, endAt: shift.endAt, status: normalizeShiftStatus(shift.status), createdAt: shift.createdAt, updatedAt: shift.updatedAt }; } function toBackendShiftPayload( data: Partial ): Partial { const payload = { ...data } as Partial & Partial; delete payload.position; if (hasOwn(data, "position")) { payload.roleName = data.position?.trim() || null; } if (hasOwn(data, "startAt")) { payload.startAt = toBackendDateTime(data.startAt) ?? ""; } if (hasOwn(data, "endAt")) { payload.endAt = toBackendDateTime(data.endAt) ?? ""; } return payload; } function normalizeCredentialAudit( audit: BackendCredentialAudit ): CredentialAudit { return { id: audit.id, operatorName: audit.operatorName ?? audit.actorName ?? "-", targetEmployeeName: audit.targetEmployeeName, targetEmployeePhone: audit.targetEmployeePhone ?? null, storeName: audit.storeName ?? null, action: audit.action, operatedAt: audit.operatedAt ?? audit.createdAt ?? "", ip: audit.ip, userAgent: audit.userAgent, reason: audit.reason ?? "" }; } export type PermissionPolicyResult = ApiResult; export type PermissionDefinitionsResult = ApiResult; /** 门店接口:管理门店基础资料,并给员工下拉选项提供数据源。 */ export const listStoreOptions = () => { return http.request>("get", `${API_PREFIX}/stores`); }; export const listAllStores = ( params?: Pick ) => { return http.request>("get", `${API_PREFIX}/stores`, { params }); }; export const listStores = (params: StoreListParams) => { return http.request>>( "get", `${API_PREFIX}/stores`, { params } ); }; export const listRoles = () => { return http.request>("get", `${API_PREFIX}/roles`); }; export const listRolePage = (params: RoleListParams) => { return http.request>>( "get", `${API_PREFIX}/roles`, { params } ); }; export const getStore = (id: number) => { return http.request>( "get", `${API_PREFIX}/stores/${id}` ); }; export const createStore = (data: StorePayload) => { return http.request>("post", `${API_PREFIX}/stores`, { data }); }; export const updateStore = (id: number, data: Partial) => { return http.request>("patch", `${API_PREFIX}/stores/${id}`, { data }); }; export const deleteStore = (id: number) => { return http.request("delete", `${API_PREFIX}/stores/${id}`); }; export const removeStoreEmployee = (storeId: number, employeeId: number) => { return http.request( "delete", `${API_PREFIX}/stores/${storeId}/employees/${employeeId}` ); }; /** 角色接口:维护员工可绑定的权限角色。 */ export const getRole = (id: number) => { return http.request>("get", `${API_PREFIX}/roles/${id}`); }; export const createRole = (data: RolePayload) => { return http.request>("post", `${API_PREFIX}/roles`, { data }); }; export const updateRole = (id: number, data: Partial) => { return http.request>("patch", `${API_PREFIX}/roles/${id}`, { data }); }; export const deleteRole = (id: number) => { return http.request("delete", `${API_PREFIX}/roles/${id}`); }; /** 员工接口:员工列表由后端分页,编辑时按 id 重新拉取完整角色绑定。 */ export const listEmployees = (params: EmployeeListParams) => { return http.request>>( "get", `${API_PREFIX}/employees`, { params } ); }; export const listEmployeeOptions = async ( params: EmployeeOptionParams = {} ): Promise> => { const items: Employee[] = []; let page = 1; let totalPages = 1; do { const result = await listEmployees({ ...params, page, pageSize: EMPLOYEE_OPTION_PAGE_SIZE }); items.push(...result.data.items); totalPages = result.data.pagination.totalPages; page += 1; } while (page <= totalPages); return { success: true, data: items }; }; export const getEmployee = (id: number) => { return http.request>( "get", `${API_PREFIX}/employees/${id}` ); }; export const createEmployee = (data: EmployeePayload) => { return http.request>("post", `${API_PREFIX}/employees`, { data }); }; export const updateEmployee = (id: number, data: Partial) => { return http.request>( "patch", `${API_PREFIX}/employees/${id}`, { data } ); }; export const updateEmployeeStatus = (id: number, status: EmployeeStatus) => { return http.request>( "patch", `${API_PREFIX}/employees/${id}/status`, { data: { status } } ); }; export const updateEmployeePassword = ( id: number, data: EmployeePasswordPayload ) => { return http.request>( "patch", `${API_PREFIX}/employees/${id}/password`, { data } ); }; export const resetEmployeePassword = ( id: number, data: EmployeePasswordResetPayload ) => { return http.request>( "post", `${API_PREFIX}/admin/employees/${id}/password/reset`, { data } ); }; export const deleteEmployee = (id: number) => { return http.request("delete", `${API_PREFIX}/employees/${id}`); }; /** 权限接口:读取权限定义、查看角色策略,并把权限点分配给角色。 */ export const getPermissionPolicies = () => { return http.request( "get", `${API_PREFIX}/permissions/policies` ); }; export const getPermissionDefinitions = () => { return http.request( "get", `${API_PREFIX}/permissions/definitions` ); }; export const updateRolePermissions = ( roleId: number, permissions: string[] ) => { return http.request>( "put", `${API_PREFIX}/permissions/roles/${roleId}`, { data: { permissions } } ); }; /** 员工工作台运营接口:公告、任务、排班和凭据审计均按后台 admin 路径对接。 */ export const listAnnouncements = (params: AnnouncementListParams) => { const { importance, ...restParams } = params; return http .request>>( "get", `${API_PREFIX}/admin/announcements`, { params: { ...restParams, level: importance } } ) .then(result => mapApiResult(result, data => mapPaginatedData(data, normalizeAnnouncement) ) ); }; export const createAnnouncement = (data: AnnouncementPayload) => { return http .request< ApiResult >("post", `${API_PREFIX}/admin/announcements`, { data: toBackendAnnouncementPayload(data) }) .then(result => mapApiResult(result, normalizeAnnouncement)); }; export const updateAnnouncement = ( id: number, data: Partial ) => { return http .request< ApiResult >("patch", `${API_PREFIX}/admin/announcements/${id}`, { data: toBackendAnnouncementPayload(data) }) .then(result => mapApiResult(result, normalizeAnnouncement)); }; export const publishAnnouncement = (id: number) => { return http .request< ApiResult >("post", `${API_PREFIX}/admin/announcements/${id}/publish`) .then(result => mapApiResult(result, normalizeAnnouncement)); }; export const archiveAnnouncement = (id: number) => { return http .request< ApiResult >("post", `${API_PREFIX}/admin/announcements/${id}/archive`) .then(result => mapApiResult(result, normalizeAnnouncement)); }; export const listTasks = (params: TaskListParams) => { return http .request>>( "get", `${API_PREFIX}/admin/tasks`, { params: { ...params, status: toBackendTaskStatus(params.status) } } ) .then(result => mapApiResult(result, data => mapPaginatedData(data, normalizeTask)) ); }; export const createTask = (data: TaskPayload) => { return http .request>("post", `${API_PREFIX}/admin/tasks`, { data: toBackendTaskPayload(data) }) .then(result => mapApiResult(result, normalizeTask)); }; export const updateTask = (id: number, data: Partial) => { return http .request< ApiResult >("patch", `${API_PREFIX}/admin/tasks/${id}`, { data: toBackendTaskPayload(data) }) .then(result => mapApiResult(result, normalizeTask)); }; export const cancelTask = (id: number) => { return http .request< ApiResult >("post", `${API_PREFIX}/admin/tasks/${id}/cancel`) .then(result => mapApiResult(result, normalizeTask)); }; export const listShifts = (params: ShiftListParams) => { return http .request< ApiResult> >("get", `${API_PREFIX}/admin/shifts`, { params }) .then(result => mapApiResult(result, data => mapPaginatedData(data, normalizeShift)) ); }; export const createShift = (data: ShiftPayload) => { return http .request>("post", `${API_PREFIX}/admin/shifts`, { data: toBackendShiftPayload(data) }) .then(result => mapApiResult(result, normalizeShift)); }; export const updateShift = (id: number, data: Partial) => { return http .request< ApiResult >("patch", `${API_PREFIX}/admin/shifts/${id}`, { data: toBackendShiftPayload(data) }) .then(result => mapApiResult(result, normalizeShift)); }; export const cancelShift = (id: number) => { return http.request("delete", `${API_PREFIX}/admin/shifts/${id}`); }; export const listCredentialAudits = (params: CredentialAuditListParams) => { return http .request< ApiResult> >("get", `${API_PREFIX}/admin/credential-audits`, { params }) .then(result => mapApiResult(result, data => mapPaginatedData(data, normalizeCredentialAudit) ) ); }; /** 数字人运营接口,管理配置不进入前台 BFF。 */ /** 统一响应结构。 */ export type Result = { success: boolean; data: T }; /** 数字人后台 API,复用已有 JWT 拦截器。 */ export async function digital( path: string, method: "get" | "post" | "put" | "delete" = "get", data?: unknown ): Promise { try { const result = await http.request>( method, `/api/digital-admin/${path}`, data === undefined ? undefined : { data } ); return result.data; } catch (error) { const response = ( error as { response?: { data?: { error?: { message?: string } } } } ).response; throw new Error( response?.data?.error?.message ?? (error instanceof Error ? error.message : "请求失败") ); } } /** 内容编辑表单,保留完整协议字段。 */ export type Content = { id: string; kind: "character" | "worldbook" | "preset"; name: string; status: string; version?: number; body: { description: string; personality: string; scenario: string; greeting: string; alternateGreetings: string[]; examples: string; systemPrompt: string; gender: string; age: number; cover: string; tags: string[]; bookIds: string[]; presetId?: string; entries: Entry[]; temperature: number; maxTokens: number; contextBudget: number; worldBudget: number; source: string; }; }; /** 世界书条目。 */ export type Entry = { id: string; name: string; keys: string[]; secondaryKeys: string[]; content: string; constant: boolean; enabled: boolean; priority: number; position: string; caseSensitive: boolean; scanDepth: number; }; /** 账号实验:A/B 对应旧/新 UI 或两种后台预设。 */ export type Experiment = { id: string; name: string; scope: "ui" | "chat"; state: "draft" | "running" | "paused" | "finished"; revision?: number; config: { audience: "all" | "new" | "existing" | "specified"; cutoff?: string; accounts: string[]; traffic: number; weightB: number; baseline: "A" | "B"; winner?: "A" | "B"; presetA?: string; presetB?: string; description: string; }; };