|
| 1 | +// Source-of-truth mirror of factory-mono-alpha session source schemas. |
| 2 | +// Faithful copy of packages/common/src/session/sources/schema.ts. |
| 3 | + |
| 4 | +import { z } from 'zod'; |
| 5 | + |
| 6 | +import { SessionPlatform } from './enums.js'; |
| 7 | + |
| 8 | +// ------------------------------------------------------------- |
| 9 | +// Platform source schemas (used for messages and sessions) |
| 10 | +// ------------------------------------------------------------- |
| 11 | + |
| 12 | +const SlackSourceSchema = z.object({ |
| 13 | + platform: z.literal(SessionPlatform.Slack), |
| 14 | + teamId: z.string().nullish(), |
| 15 | + channel: z.string().nullish(), |
| 16 | + threadTs: z.string().nullish(), |
| 17 | + userId: z.string().nullish(), |
| 18 | +}); |
| 19 | + |
| 20 | +const WebSourceSchema = z.object({ |
| 21 | + platform: z.literal(SessionPlatform.Web), |
| 22 | +}); |
| 23 | + |
| 24 | +const ApiSourceSchema = z.object({ |
| 25 | + platform: z.literal(SessionPlatform.Api), |
| 26 | +}); |
| 27 | + |
| 28 | +const SessionsApiSourceSchema = z.object({ |
| 29 | + platform: z.literal(SessionPlatform.SessionsApi), |
| 30 | +}); |
| 31 | + |
| 32 | +const LinearSourceSchema = z.object({ |
| 33 | + platform: z.literal(SessionPlatform.Linear), |
| 34 | + agentSessionId: z.string(), |
| 35 | + issueId: z.string().nullish(), |
| 36 | + issueUrl: z.string().nullish(), |
| 37 | + issueIdentifier: z.string().nullish(), |
| 38 | + organizationId: z.string().nullish(), |
| 39 | + userId: z.string().nullish(), |
| 40 | +}); |
| 41 | + |
| 42 | +const ReadinessRemediationSourceSchema = z.object({ |
| 43 | + platform: z.literal(SessionPlatform.ReadinessRemediation), |
| 44 | + reportId: z.string(), |
| 45 | + repoUrl: z.string(), |
| 46 | + criterionId: z.string(), |
| 47 | +}); |
| 48 | + |
| 49 | +const ReadinessEvaluationSourceSchema = z.object({ |
| 50 | + platform: z.literal(SessionPlatform.ReadinessEvaluation), |
| 51 | + repoUrl: z.string(), |
| 52 | +}); |
| 53 | + |
| 54 | +const AutomationSourceSchema = z.object({ |
| 55 | + platform: z.literal(SessionPlatform.Automation), |
| 56 | + automationId: z.string(), |
| 57 | + computerId: z.string(), |
| 58 | +}); |
| 59 | + |
| 60 | +const WikiGenerationSourceSchema = z.object({ |
| 61 | + platform: z.literal(SessionPlatform.WikiGeneration), |
| 62 | + repoUrl: z.string(), |
| 63 | +}); |
| 64 | + |
| 65 | +const WikiCISetupSourceSchema = z.object({ |
| 66 | + platform: z.literal(SessionPlatform.WikiCISetup), |
| 67 | + repoUrl: z.string(), |
| 68 | +}); |
| 69 | + |
| 70 | +// ------------------------------------------------------------- |
| 71 | +// Session-specific source schemas (adds delegationSessionId) |
| 72 | +// ------------------------------------------------------------- |
| 73 | + |
| 74 | +const SlackSessionSourceSchema = SlackSourceSchema.extend({ |
| 75 | + delegationSessionId: z.string(), |
| 76 | +}); |
| 77 | + |
| 78 | +const WebSessionSourceSchema = WebSourceSchema.extend({ |
| 79 | + delegationSessionId: z.string(), |
| 80 | +}); |
| 81 | + |
| 82 | +const ApiSessionSourceSchema = ApiSourceSchema.extend({ |
| 83 | + delegationSessionId: z.string(), |
| 84 | +}); |
| 85 | + |
| 86 | +const SessionsApiSessionSourceSchema = SessionsApiSourceSchema.extend({ |
| 87 | + delegationSessionId: z.string(), |
| 88 | +}); |
| 89 | + |
| 90 | +const LinearSessionSourceSchema = LinearSourceSchema.extend({ |
| 91 | + delegationSessionId: z.string(), |
| 92 | +}); |
| 93 | + |
| 94 | +export const SessionSourceSchema = z.discriminatedUnion('platform', [ |
| 95 | + SlackSessionSourceSchema, |
| 96 | + WebSessionSourceSchema, |
| 97 | + ApiSessionSourceSchema, |
| 98 | + SessionsApiSessionSourceSchema, |
| 99 | + LinearSessionSourceSchema, |
| 100 | + ReadinessRemediationSourceSchema, // No delegationSessionId needed |
| 101 | + ReadinessEvaluationSourceSchema, // No delegationSessionId needed |
| 102 | + AutomationSourceSchema, // No delegationSessionId needed |
| 103 | + WikiGenerationSourceSchema, // No delegationSessionId needed |
| 104 | + WikiCISetupSourceSchema, // No delegationSessionId needed |
| 105 | +]); |
| 106 | + |
| 107 | +// ------------------------------------------------------------- |
| 108 | +// Inferred types (single source of truth) |
| 109 | +// ------------------------------------------------------------- |
| 110 | + |
| 111 | +export type SlackSource = z.infer<typeof SlackSourceSchema>; |
| 112 | +export type WebSource = z.infer<typeof WebSourceSchema>; |
| 113 | +export type ApiSource = z.infer<typeof ApiSourceSchema>; |
| 114 | +export type SessionsApiSource = z.infer<typeof SessionsApiSourceSchema>; |
| 115 | +export type LinearSource = z.infer<typeof LinearSourceSchema>; |
| 116 | +export type ReadinessRemediationSource = z.infer< |
| 117 | + typeof ReadinessRemediationSourceSchema |
| 118 | +>; |
| 119 | +export type ReadinessEvaluationSource = z.infer< |
| 120 | + typeof ReadinessEvaluationSourceSchema |
| 121 | +>; |
| 122 | +export type AutomationSource = z.infer<typeof AutomationSourceSchema>; |
| 123 | +export type WikiGenerationSource = z.infer<typeof WikiGenerationSourceSchema>; |
| 124 | +export type WikiCISetupSource = z.infer<typeof WikiCISetupSourceSchema>; |
| 125 | +export type PlatformSource = |
| 126 | + | SlackSource |
| 127 | + | WebSource |
| 128 | + | ApiSource |
| 129 | + | SessionsApiSource |
| 130 | + | LinearSource |
| 131 | + | ReadinessRemediationSource |
| 132 | + | ReadinessEvaluationSource |
| 133 | + | AutomationSource |
| 134 | + | WikiGenerationSource |
| 135 | + | WikiCISetupSource; |
| 136 | +export type SessionSource = z.infer<typeof SessionSourceSchema>; |
0 commit comments