feat: add shared dashboard API contracts
This commit is contained in:
1 parent
939cf408a0
commit
59c3a61a88
14 files changed
+648
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { z } from 'zod';
|
||||
import { SyncProgressSchema } from './chats.js';
|
||||
|
||||
const EventBase = {
|
||||
id: z.string(),
|
||||
occurredAt: z.number(),
|
||||
};
|
||||
|
||||
export const DashboardEventSchema = z.discriminatedUnion('type', [
|
||||
z.strictObject({
|
||||
...EventBase,
|
||||
type: z.literal('stream.connected'),
|
||||
payload: z.strictObject({}),
|
||||
}),
|
||||
z.strictObject({
|
||||
...EventBase,
|
||||
type: z.literal('log.created'),
|
||||
payload: z.strictObject({
|
||||
level: z.union([z.literal('info'), z.literal('warn'), z.literal('error'), z.literal('debug')]),
|
||||
message: z.string(),
|
||||
data: z.unknown().optional(),
|
||||
}),
|
||||
}),
|
||||
z.strictObject({
|
||||
...EventBase,
|
||||
type: z.literal('sync.progress'),
|
||||
payload: SyncProgressSchema,
|
||||
}),
|
||||
z.strictObject({
|
||||
...EventBase,
|
||||
type: z.literal('sync.completed'),
|
||||
payload: z.strictObject({ kind: z.union([z.literal('full'), z.literal('delta')]) }),
|
||||
}),
|
||||
]);
|
||||
|
||||
/** Existing `/api/logs/stream` frames, retained for an incremental migration. */
|
||||
export const LegacyDashboardStreamEventSchema = z.discriminatedUnion('type', [
|
||||
z.strictObject({
|
||||
type: z.literal('connected'),
|
||||
timestamp: z.number(),
|
||||
}),
|
||||
z.strictObject({
|
||||
type: z.literal('log'),
|
||||
timestamp: z.number(),
|
||||
level: z.union([z.literal('info'), z.literal('warn'), z.literal('error'), z.literal('debug')]),
|
||||
message: z.string(),
|
||||
data: z.unknown().optional(),
|
||||
}),
|
||||
z.strictObject({
|
||||
type: z.literal('sync-progress'),
|
||||
progress: SyncProgressSchema.nullable(),
|
||||
}),
|
||||
]);
|
||||
|
||||
export type DashboardEvent = z.infer<typeof DashboardEventSchema>;
|
||||
export type LegacyDashboardStreamEvent = z.infer<typeof LegacyDashboardStreamEventSchema>;
|
||||
Reference in new issue
Block a user