File size: 1,464 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
40
41
42
43
44
45
/**
 * `sessionIndex` — the persisted session read model. Mirrors
 * `agent-core-v2/app/sessionIndex/sessionIndex.ts`.
 */

import { z } from 'zod';

import { maybe, pageOf } from '../helpers.js';
import type { ServiceContract } from '../types.js';

export const sessionSummarySchema = z.object({
  id: z.string(),
  workspaceId: z.string(),
  cwd: z.string().optional(),
  title: z.string().optional(),
  lastPrompt: z.string().optional(),
  createdAt: z.number(),
  updatedAt: z.number(),
  archived: z.boolean(),
  archivedAt: z.number().optional(),
  custom: z.record(z.string(), z.unknown()).optional(),
  lastTurnReason: z.enum(['completed', 'cancelled', 'failed']).optional(),
});

export const sessionListQuerySchema = z.object({
  workspaceIds: z.array(z.string()).optional(),
  sessionId: z.string().optional(),
  includeArchived: z.boolean().optional(),
  limit: z.number().optional(),
  childOf: z.string().optional(),
  before: z.string().optional(),
  after: z.string().optional(),
});

export const sessionCountQuerySchema = z.object({
  workspaceIds: z.array(z.string()).optional(),
  includeArchived: z.boolean().optional(),
});

export const sessionsContract = {
  listRecent: { input: z.tuple([sessionListQuerySchema]), output: pageOf(sessionSummarySchema) },
  get: { input: z.tuple([z.string()]), output: maybe(sessionSummarySchema) },
  count: { input: z.tuple([sessionCountQuerySchema]), output: z.number() },
} satisfies ServiceContract;