AstrBot-Desktop/src/types/profile.ts
YokiiroBW 3d1d962461
一些检测仍在等待运行
ci / Portable quality checks (push) Waiting to run
ci / Windows Tauri build (push) Waiting to run
feat(chat): add AstrBot dual-slot chat foundation
2026-07-20 11:31:41 +08:00

67 行
2.3 KiB
TypeScript

import { z } from "zod";
export const profileRoleSchema = z.enum(["companion", "operations", "general"]);
export const authenticationTypeSchema = z.enum(["device-token", "api-key"]);
export const transportKindSchema = z.enum(["desktop-v1", "astrbot-openapi"]);
export const activeSlotKindSchema = z.enum(["companion", "operations"]);
const optionalIdentifier = z.string().min(1).optional();
export const connectionProfileSchema = z
.object({
id: z.uuid(),
displayName: z.string().min(1).max(80),
role: profileRoleSchema,
baseUrl: z.url(),
eventStreamUrl: z.url().optional(),
authenticationType: authenticationTypeSchema,
transportKind: transportKindSchema.default("desktop-v1"),
credentialReference: optionalIdentifier,
allowInsecureHttp: z.boolean(),
pinnedCertificateFingerprint: z
.string()
.regex(/^[A-F0-9]{64}$/)
.optional(),
autoConnectSlot: activeSlotKindSchema.optional(),
autoConnect: z.boolean(),
serverInstanceId: optionalIdentifier,
serverVersion: optionalIdentifier,
protocolVersion: optionalIdentifier,
localToolPolicyId: optionalIdentifier,
lastConnectedAt: optionalIdentifier,
remoteUsername: optionalIdentifier,
stickySessionId: optionalIdentifier,
createdAt: z.string().min(1),
updatedAt: z.string().min(1),
})
.strict();
export const connectionProfileListSchema = z.array(connectionProfileSchema);
export type ProfileRole = z.infer<typeof profileRoleSchema>;
export type AuthenticationType = z.infer<typeof authenticationTypeSchema>;
export type TransportKind = z.infer<typeof transportKindSchema>;
export type ConnectionProfile = z.infer<typeof connectionProfileSchema>;
export type ActiveSlotKind = z.infer<typeof activeSlotKindSchema>;
export interface ConnectionProfileInput {
displayName: string;
role: ProfileRole;
baseUrl: string;
eventStreamUrl?: string;
authenticationType: AuthenticationType;
transportKind?: TransportKind;
allowInsecureHttp: boolean;
remoteUsername?: string;
pinnedCertificateFingerprint?: string;
autoConnect: boolean;
autoConnectSlot?: ActiveSlotKind;
}
export interface UpdateConnectionProfileRequest {
id: string;
profile: ConnectionProfileInput;
}