2026-07-20 11:31:41 +08:00
|
|
|
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;
|
|
|
|
|
}
|