File size: 899 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { z } from 'zod';

const ISO_8601_REGEX =
  /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}(?::?\d{2})?)$/;

export const isoDateTimeSchema = z
  .string()
  .refine((value) => ISO_8601_REGEX.test(value), {
    message: 'must be an ISO 8601 datetime string',
  })
  .transform((value, ctx) => {
    const ms = Date.parse(value);
    if (Number.isNaN(ms)) {
      ctx.addIssue({
        code: 'custom',
        message: 'invalid ISO 8601 datetime',
      });
      return z.NEVER;
    }
    return new Date(ms).toISOString();
  });

export const epochMsSchema = z.number();

export const timelineMessageBase = {
  session_id: z.string().min(1),
  agent_id: z.string().min(1),
  timestamp: epochMsSchema,
};

export const sessionMessageBase = {
  session_id: z.string().min(1),
  timestamp: epochMsSchema,
};

export const globalMessageBase = {
  timestamp: epochMsSchema,
};