@murphai/contracts 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +24 -0
- package/dist/bank-entities.d.ts +35 -0
- package/dist/bank-entities.d.ts.map +1 -0
- package/dist/bank-entities.js +164 -0
- package/dist/bank-entities.js.map +1 -0
- package/dist/command-capabilities.d.ts +50 -0
- package/dist/command-capabilities.d.ts.map +1 -0
- package/dist/command-capabilities.js +149 -0
- package/dist/command-capabilities.js.map +1 -0
- package/dist/constants.d.ts +149 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +232 -0
- package/dist/constants.js.map +1 -0
- package/dist/examples.d.ts +31 -0
- package/dist/examples.d.ts.map +1 -0
- package/dist/examples.js +943 -0
- package/dist/examples.js.map +1 -0
- package/dist/frontmatter.d.ts +28 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +272 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/health-entities.d.ts +87 -0
- package/dist/health-entities.d.ts.map +1 -0
- package/dist/health-entities.js +349 -0
- package/dist/health-entities.js.map +1 -0
- package/dist/ids.d.ts +10 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +27 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/registry-helpers.d.ts +31 -0
- package/dist/registry-helpers.d.ts.map +1 -0
- package/dist/registry-helpers.js +53 -0
- package/dist/registry-helpers.js.map +1 -0
- package/dist/schemas.d.ts +47 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +50 -0
- package/dist/schemas.js.map +1 -0
- package/dist/scripts/generate-json-schema.js +13 -0
- package/dist/scripts/generate-json-schema.js.map +1 -0
- package/dist/scripts/verify.js +230 -0
- package/dist/scripts/verify.js.map +1 -0
- package/dist/shares.d.ts +715 -0
- package/dist/shares.d.ts.map +1 -0
- package/dist/shares.js +469 -0
- package/dist/shares.js.map +1 -0
- package/dist/time.d.ts +25 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +241 -0
- package/dist/time.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types.d.ts +34 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +18 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +129 -0
- package/dist/validate.js.map +1 -0
- package/dist/zod.d.ts +1626 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +834 -0
- package/dist/zod.js.map +1 -0
- package/generated/assessment-response.schema.json +101 -0
- package/generated/audit-record.schema.json +141 -0
- package/generated/event-record.schema.json +2708 -0
- package/generated/frontmatter-allergy.schema.json +82 -0
- package/generated/frontmatter-condition.schema.json +101 -0
- package/generated/frontmatter-core.schema.json +51 -0
- package/generated/frontmatter-experiment.schema.json +70 -0
- package/generated/frontmatter-family-member.schema.json +68 -0
- package/generated/frontmatter-food.schema.json +128 -0
- package/generated/frontmatter-genetic-variant.schema.json +81 -0
- package/generated/frontmatter-goal.schema.json +116 -0
- package/generated/frontmatter-journal-day.schema.json +52 -0
- package/generated/frontmatter-profile-current.schema.json +55 -0
- package/generated/frontmatter-protocol.schema.json +153 -0
- package/generated/frontmatter-provider.schema.json +81 -0
- package/generated/frontmatter-recipe.schema.json +124 -0
- package/generated/frontmatter-workout-format.schema.json +163 -0
- package/generated/inbox-capture-record.schema.json +332 -0
- package/generated/profile-snapshot.schema.json +131 -0
- package/generated/sample-record.schema.json +726 -0
- package/generated/vault-metadata.schema.json +324 -0
- package/package.json +69 -0
package/dist/zod.js
ADDED
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { ADVERSE_EFFECT_SEVERITIES, ALLERGY_CRITICALITIES, ALLERGY_STATUSES, ASSESSMENT_SOURCES, AUDIT_ACTIONS, AUDIT_ACTORS, AUDIT_STATUSES, BLOOD_TEST_FASTING_STATUSES, BLOOD_TEST_RESULT_FLAGS, CONDITION_CLINICAL_STATUSES, CONDITION_SEVERITIES, CONDITION_VERIFICATION_STATUSES, CONTRACT_ID_FORMAT, CONTRACT_SCHEMA_VERSION, ERROR_CODE_VALUES, EVENT_KINDS, EVENT_SOURCES, EXPERIMENT_PHASES, EXPERIMENT_STATUSES, FILE_CHANGE_OPERATIONS, FOOD_STATUSES, FRONTMATTER_DOC_TYPES, GOAL_HORIZONS, GOAL_STATUSES, ID_PREFIXES, PROFILE_SNAPSHOT_SOURCES, RAW_IMPORT_KINDS, RECIPE_STATUSES, PROTOCOL_KINDS, PROTOCOL_STATUSES, WORKOUT_FORMAT_STATUSES, SAMPLE_QUALITIES, SAMPLE_SOURCES, SAMPLE_STREAMS, SLEEP_STAGES, TEST_RESULT_STATUSES, VARIANT_SIGNIFICANCES, VARIANT_ZYGOSITIES, } from "./constants.js";
|
|
3
|
+
import { GENERIC_CONTRACT_ID_PATTERN, idPattern } from "./ids.js";
|
|
4
|
+
import { isStrictIsoDate, isStrictIsoDateTime, isValidIanaTimeZone, } from "./time.js";
|
|
5
|
+
const DAY_KEY_PATTERN = "^\\d{4}-\\d{2}-\\d{2}$";
|
|
6
|
+
const RAW_PATH_PATTERN = "^raw/[A-Za-z0-9._/-]+$";
|
|
7
|
+
const RAW_DOCUMENT_PATH_PATTERN = "^raw/documents/[A-Za-z0-9._/-]+$";
|
|
8
|
+
const RAW_MEAL_PATH_PATTERN = "^raw/meals/[A-Za-z0-9._/-]+$";
|
|
9
|
+
const RAW_ASSESSMENT_SOURCE_PATTERN = "^raw/assessments/[A-Za-z0-9._/-]+/source\\.json$";
|
|
10
|
+
const RELATIVE_PATH_PATTERN = "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))[A-Za-z0-9._/-]+$";
|
|
11
|
+
const SHA256_HEX_PATTERN = "^[a-f0-9]{64}$";
|
|
12
|
+
const SLUG_PATTERN = "^[a-z0-9]+(?:-[a-z0-9]+)*$";
|
|
13
|
+
const DAILY_TIME_PATTERN = "^(?:[01]\\d|2[0-3]):[0-5]\\d$";
|
|
14
|
+
const UNIT_PATTERN = "^[A-Za-z0-9._/%-]+$";
|
|
15
|
+
export const FAMILY_MEMBER_LIMITS = Object.freeze({
|
|
16
|
+
title: 160,
|
|
17
|
+
relationship: 120,
|
|
18
|
+
condition: 160,
|
|
19
|
+
note: 4000,
|
|
20
|
+
});
|
|
21
|
+
export const GENETIC_VARIANT_LIMITS = Object.freeze({
|
|
22
|
+
title: 160,
|
|
23
|
+
gene: 40,
|
|
24
|
+
inheritance: 120,
|
|
25
|
+
note: 4000,
|
|
26
|
+
});
|
|
27
|
+
function withContractMetadata(schema, id, title) {
|
|
28
|
+
return schema.meta({
|
|
29
|
+
$id: id,
|
|
30
|
+
title,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function boundedString(minLength, maxLength) {
|
|
34
|
+
return z.string().min(minLength).max(maxLength);
|
|
35
|
+
}
|
|
36
|
+
function patternedString(pattern, minLength, maxLength) {
|
|
37
|
+
let schema = z.string();
|
|
38
|
+
if (minLength !== undefined) {
|
|
39
|
+
schema = schema.min(minLength);
|
|
40
|
+
}
|
|
41
|
+
if (maxLength !== undefined) {
|
|
42
|
+
schema = schema.max(maxLength);
|
|
43
|
+
}
|
|
44
|
+
return schema.regex(new RegExp(pattern));
|
|
45
|
+
}
|
|
46
|
+
function isoDateTimeString() {
|
|
47
|
+
return z
|
|
48
|
+
.string()
|
|
49
|
+
.meta({ format: "date-time" })
|
|
50
|
+
.refine((value) => isStrictIsoDateTime(value), "Invalid ISO date-time string.");
|
|
51
|
+
}
|
|
52
|
+
function isoDateString() {
|
|
53
|
+
return z
|
|
54
|
+
.string()
|
|
55
|
+
.meta({ format: "date" })
|
|
56
|
+
.refine((value) => isStrictIsoDate(value), "Invalid ISO date string.");
|
|
57
|
+
}
|
|
58
|
+
function timeZoneString(options = {}) {
|
|
59
|
+
const schema = boundedString(3, 64).refine((value) => isValidIanaTimeZone(value), "Invalid IANA time zone.");
|
|
60
|
+
return options.optional ? schema.optional() : schema;
|
|
61
|
+
}
|
|
62
|
+
function integerSchema(minimum, maximum) {
|
|
63
|
+
let schema = z.number();
|
|
64
|
+
if (minimum !== undefined) {
|
|
65
|
+
schema = schema.min(minimum);
|
|
66
|
+
}
|
|
67
|
+
if (maximum !== undefined) {
|
|
68
|
+
schema = schema.max(maximum);
|
|
69
|
+
}
|
|
70
|
+
return schema
|
|
71
|
+
.meta({ type: "integer" })
|
|
72
|
+
.refine((value) => Number.isInteger(value), "Expected an integer.");
|
|
73
|
+
}
|
|
74
|
+
function numberSchema(minimum, maximum) {
|
|
75
|
+
let schema = z.number();
|
|
76
|
+
if (minimum !== undefined) {
|
|
77
|
+
schema = schema.min(minimum);
|
|
78
|
+
}
|
|
79
|
+
if (maximum !== undefined) {
|
|
80
|
+
schema = schema.max(maximum);
|
|
81
|
+
}
|
|
82
|
+
return schema;
|
|
83
|
+
}
|
|
84
|
+
function uniqueArray(itemSchema, options = {}) {
|
|
85
|
+
let schema = z.array(itemSchema);
|
|
86
|
+
if (options.minItems !== undefined) {
|
|
87
|
+
schema = schema.min(options.minItems);
|
|
88
|
+
}
|
|
89
|
+
if (options.maxItems !== undefined) {
|
|
90
|
+
schema = schema.max(options.maxItems);
|
|
91
|
+
}
|
|
92
|
+
if (options.uniqueItems) {
|
|
93
|
+
schema = schema
|
|
94
|
+
.meta({ uniqueItems: true })
|
|
95
|
+
.superRefine((values, context) => {
|
|
96
|
+
const serialized = values.map((value) => JSON.stringify(value));
|
|
97
|
+
if (new Set(serialized).size !== serialized.length) {
|
|
98
|
+
context.addIssue({
|
|
99
|
+
code: z.ZodIssueCode.custom,
|
|
100
|
+
message: "Expected unique array items.",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return schema;
|
|
106
|
+
}
|
|
107
|
+
function idSchema(prefix) {
|
|
108
|
+
return patternedString(idPattern(prefix));
|
|
109
|
+
}
|
|
110
|
+
const jsonValueSchema = z.lazy(() => z.union([
|
|
111
|
+
z.string(),
|
|
112
|
+
z.number(),
|
|
113
|
+
z.boolean(),
|
|
114
|
+
z.null(),
|
|
115
|
+
z.array(jsonValueSchema),
|
|
116
|
+
z.object({}).catchall(jsonValueSchema),
|
|
117
|
+
]));
|
|
118
|
+
export const jsonObjectSchema = z.object({}).catchall(jsonValueSchema);
|
|
119
|
+
export const externalRefSchema = z
|
|
120
|
+
.object({
|
|
121
|
+
system: patternedString(SLUG_PATTERN),
|
|
122
|
+
resourceType: patternedString(SLUG_PATTERN),
|
|
123
|
+
resourceId: boundedString(1, 200),
|
|
124
|
+
version: boundedString(1, 200).optional(),
|
|
125
|
+
facet: patternedString(SLUG_PATTERN).optional(),
|
|
126
|
+
})
|
|
127
|
+
.strict();
|
|
128
|
+
const activityStrengthExerciseBaseShape = {
|
|
129
|
+
exercise: boundedString(1, 160),
|
|
130
|
+
setCount: integerSchema(1),
|
|
131
|
+
repsPerSet: integerSchema(1),
|
|
132
|
+
loadDescription: boundedString(1, 240).optional(),
|
|
133
|
+
};
|
|
134
|
+
const activityStrengthExerciseWithoutLoadSchema = z
|
|
135
|
+
.object(activityStrengthExerciseBaseShape)
|
|
136
|
+
.strict();
|
|
137
|
+
const activityStrengthExerciseWithLoadSchema = z
|
|
138
|
+
.object({
|
|
139
|
+
...activityStrengthExerciseBaseShape,
|
|
140
|
+
load: numberSchema(0),
|
|
141
|
+
loadUnit: z.enum(["lb", "kg"]),
|
|
142
|
+
})
|
|
143
|
+
.strict();
|
|
144
|
+
export const activityStrengthExerciseSchema = z.union([
|
|
145
|
+
activityStrengthExerciseWithoutLoadSchema,
|
|
146
|
+
activityStrengthExerciseWithLoadSchema,
|
|
147
|
+
]);
|
|
148
|
+
const bloodTestResultComparatorSchema = z.enum(["<", "<=", ">", ">="]);
|
|
149
|
+
export const bloodTestReferenceRangeSchema = z
|
|
150
|
+
.object({
|
|
151
|
+
low: numberSchema().optional(),
|
|
152
|
+
high: numberSchema().optional(),
|
|
153
|
+
text: boundedString(1, 160).optional(),
|
|
154
|
+
})
|
|
155
|
+
.strict()
|
|
156
|
+
.refine((value) => value.low !== undefined || value.high !== undefined || value.text !== undefined, {
|
|
157
|
+
message: "Blood-test reference ranges must include at least one boundary or a text range.",
|
|
158
|
+
});
|
|
159
|
+
export const bloodTestResultSchema = z
|
|
160
|
+
.object({
|
|
161
|
+
analyte: boundedString(1, 160),
|
|
162
|
+
slug: patternedString(SLUG_PATTERN).optional(),
|
|
163
|
+
value: numberSchema().optional(),
|
|
164
|
+
textValue: boundedString(1, 160).optional(),
|
|
165
|
+
comparator: bloodTestResultComparatorSchema.optional(),
|
|
166
|
+
unit: boundedString(1, 64).optional(),
|
|
167
|
+
flag: z.enum(BLOOD_TEST_RESULT_FLAGS).optional(),
|
|
168
|
+
biomarkerSlug: patternedString(SLUG_PATTERN).optional(),
|
|
169
|
+
referenceRange: bloodTestReferenceRangeSchema.optional(),
|
|
170
|
+
note: boundedString(1, 240).optional(),
|
|
171
|
+
})
|
|
172
|
+
.strict()
|
|
173
|
+
.superRefine((value, context) => {
|
|
174
|
+
if (value.value === undefined && value.textValue === undefined) {
|
|
175
|
+
context.addIssue({
|
|
176
|
+
code: z.ZodIssueCode.custom,
|
|
177
|
+
message: "Blood-test results require either a numeric value or a textValue.",
|
|
178
|
+
path: ["value"],
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const baseEventShape = {
|
|
183
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.event),
|
|
184
|
+
id: idSchema(ID_PREFIXES.event),
|
|
185
|
+
occurredAt: isoDateTimeString(),
|
|
186
|
+
recordedAt: isoDateTimeString(),
|
|
187
|
+
dayKey: patternedString(DAY_KEY_PATTERN),
|
|
188
|
+
source: z.enum(EVENT_SOURCES),
|
|
189
|
+
title: boundedString(1, 160),
|
|
190
|
+
};
|
|
191
|
+
const eventLifecycleSchema = z
|
|
192
|
+
.object({
|
|
193
|
+
revision: integerSchema(1),
|
|
194
|
+
state: z.enum(["deleted"]).optional(),
|
|
195
|
+
})
|
|
196
|
+
.strict();
|
|
197
|
+
const baseEventOptionalShape = {
|
|
198
|
+
tags: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
199
|
+
relatedIds: uniqueArray(patternedString(GENERIC_CONTRACT_ID_PATTERN), { uniqueItems: true }).optional(),
|
|
200
|
+
rawRefs: uniqueArray(patternedString(RAW_PATH_PATTERN), { uniqueItems: true }).optional(),
|
|
201
|
+
externalRef: externalRefSchema.optional(),
|
|
202
|
+
lifecycle: eventLifecycleSchema.optional(),
|
|
203
|
+
timeZone: timeZoneString({ optional: true }),
|
|
204
|
+
};
|
|
205
|
+
function eventSchema(kind, extraShape) {
|
|
206
|
+
return z
|
|
207
|
+
.object({
|
|
208
|
+
...baseEventShape,
|
|
209
|
+
kind: z.literal(kind),
|
|
210
|
+
note: boundedString(1, 4000).optional(),
|
|
211
|
+
...baseEventOptionalShape,
|
|
212
|
+
...extraShape,
|
|
213
|
+
})
|
|
214
|
+
.strict();
|
|
215
|
+
}
|
|
216
|
+
const baseSampleShape = {
|
|
217
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.sample),
|
|
218
|
+
id: idSchema(ID_PREFIXES.sample),
|
|
219
|
+
recordedAt: isoDateTimeString(),
|
|
220
|
+
dayKey: patternedString(DAY_KEY_PATTERN),
|
|
221
|
+
source: z.enum(SAMPLE_SOURCES),
|
|
222
|
+
quality: z.enum(SAMPLE_QUALITIES),
|
|
223
|
+
};
|
|
224
|
+
const baseSampleOptionalShape = {
|
|
225
|
+
externalRef: externalRefSchema.optional(),
|
|
226
|
+
timeZone: timeZoneString({ optional: true }),
|
|
227
|
+
};
|
|
228
|
+
function sampleSchema(stream, extraShape) {
|
|
229
|
+
return z
|
|
230
|
+
.object({
|
|
231
|
+
...baseSampleShape,
|
|
232
|
+
stream: z.literal(stream),
|
|
233
|
+
...baseSampleOptionalShape,
|
|
234
|
+
...extraShape,
|
|
235
|
+
})
|
|
236
|
+
.strict();
|
|
237
|
+
}
|
|
238
|
+
export const vaultMetadataSchema = withContractMetadata(z
|
|
239
|
+
.object({
|
|
240
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.vault),
|
|
241
|
+
vaultId: idSchema(ID_PREFIXES.vault),
|
|
242
|
+
createdAt: isoDateTimeString(),
|
|
243
|
+
title: boundedString(1, 120),
|
|
244
|
+
timezone: timeZoneString(),
|
|
245
|
+
idPolicy: z
|
|
246
|
+
.object({
|
|
247
|
+
format: z.literal(CONTRACT_ID_FORMAT),
|
|
248
|
+
prefixes: z
|
|
249
|
+
.object({
|
|
250
|
+
allergy: z.literal(ID_PREFIXES.allergy),
|
|
251
|
+
assessment: z.literal(ID_PREFIXES.assessment),
|
|
252
|
+
audit: z.literal(ID_PREFIXES.audit),
|
|
253
|
+
condition: z.literal(ID_PREFIXES.condition),
|
|
254
|
+
document: z.literal(ID_PREFIXES.document),
|
|
255
|
+
event: z.literal(ID_PREFIXES.event),
|
|
256
|
+
experiment: z.literal(ID_PREFIXES.experiment),
|
|
257
|
+
family: z.literal(ID_PREFIXES.family),
|
|
258
|
+
food: z.literal(ID_PREFIXES.food),
|
|
259
|
+
goal: z.literal(ID_PREFIXES.goal),
|
|
260
|
+
meal: z.literal(ID_PREFIXES.meal),
|
|
261
|
+
pack: z.literal(ID_PREFIXES.pack),
|
|
262
|
+
profileSnapshot: z.literal(ID_PREFIXES.profileSnapshot),
|
|
263
|
+
provider: z.literal(ID_PREFIXES.provider),
|
|
264
|
+
recipe: z.literal(ID_PREFIXES.recipe),
|
|
265
|
+
protocol: z.literal(ID_PREFIXES.protocol),
|
|
266
|
+
sample: z.literal(ID_PREFIXES.sample),
|
|
267
|
+
transform: z.literal(ID_PREFIXES.transform),
|
|
268
|
+
variant: z.literal(ID_PREFIXES.variant),
|
|
269
|
+
vault: z.literal(ID_PREFIXES.vault),
|
|
270
|
+
workoutFormat: z.literal(ID_PREFIXES.workoutFormat),
|
|
271
|
+
})
|
|
272
|
+
.strict(),
|
|
273
|
+
})
|
|
274
|
+
.strict(),
|
|
275
|
+
paths: z
|
|
276
|
+
.object({
|
|
277
|
+
allergiesRoot: z.literal("bank/allergies"),
|
|
278
|
+
assessmentLedgerRoot: z.literal("ledger/assessments"),
|
|
279
|
+
conditionsRoot: z.literal("bank/conditions"),
|
|
280
|
+
coreDocument: z.literal("CORE.md"),
|
|
281
|
+
familyRoot: z.literal("bank/family"),
|
|
282
|
+
foodsRoot: z.literal("bank/foods"),
|
|
283
|
+
geneticsRoot: z.literal("bank/genetics"),
|
|
284
|
+
goalsRoot: z.literal("bank/goals"),
|
|
285
|
+
journalRoot: z.literal("journal"),
|
|
286
|
+
experimentsRoot: z.literal("bank/experiments"),
|
|
287
|
+
profileCurrentDocument: z.literal("bank/profile/current.md"),
|
|
288
|
+
profileRoot: z.literal("bank/profile"),
|
|
289
|
+
profileSnapshotsRoot: z.literal("ledger/profile-snapshots"),
|
|
290
|
+
providersRoot: z.literal("bank/providers"),
|
|
291
|
+
recipesRoot: z.literal("bank/recipes"),
|
|
292
|
+
workoutFormatsRoot: z.literal("bank/workout-formats"),
|
|
293
|
+
rawAssessmentsRoot: z.literal("raw/assessments"),
|
|
294
|
+
rawRoot: z.literal("raw"),
|
|
295
|
+
eventsRoot: z.literal("ledger/events"),
|
|
296
|
+
protocolsRoot: z.literal("bank/protocols"),
|
|
297
|
+
samplesRoot: z.literal("ledger/samples"),
|
|
298
|
+
auditRoot: z.literal("audit"),
|
|
299
|
+
exportsRoot: z.literal("exports"),
|
|
300
|
+
})
|
|
301
|
+
.strict(),
|
|
302
|
+
shards: z
|
|
303
|
+
.object({
|
|
304
|
+
assessments: z.literal("ledger/assessments/YYYY/YYYY-MM.jsonl"),
|
|
305
|
+
events: z.literal("ledger/events/YYYY/YYYY-MM.jsonl"),
|
|
306
|
+
profileSnapshots: z.literal("ledger/profile-snapshots/YYYY/YYYY-MM.jsonl"),
|
|
307
|
+
samples: z.literal("ledger/samples/<stream>/YYYY/YYYY-MM.jsonl"),
|
|
308
|
+
audit: z.literal("audit/YYYY/YYYY-MM.jsonl"),
|
|
309
|
+
})
|
|
310
|
+
.strict(),
|
|
311
|
+
})
|
|
312
|
+
.strict(), "@murphai/contracts/vault-metadata.schema.json", "Murph Vault Metadata");
|
|
313
|
+
export const eventRecordSchema = withContractMetadata(z.discriminatedUnion("kind", [
|
|
314
|
+
eventSchema("document", {
|
|
315
|
+
documentId: idSchema(ID_PREFIXES.document),
|
|
316
|
+
documentPath: patternedString(RAW_DOCUMENT_PATH_PATTERN),
|
|
317
|
+
mimeType: boundedString(3, 120),
|
|
318
|
+
providerId: idSchema(ID_PREFIXES.provider).optional(),
|
|
319
|
+
}),
|
|
320
|
+
eventSchema("encounter", {
|
|
321
|
+
encounterType: boundedString(1, 160),
|
|
322
|
+
location: boundedString(1, 160).optional(),
|
|
323
|
+
providerId: idSchema(ID_PREFIXES.provider).optional(),
|
|
324
|
+
}),
|
|
325
|
+
eventSchema("meal", {
|
|
326
|
+
mealId: idSchema(ID_PREFIXES.meal),
|
|
327
|
+
photoPaths: uniqueArray(patternedString(RAW_MEAL_PATH_PATTERN), { uniqueItems: true }),
|
|
328
|
+
audioPaths: z.array(patternedString(RAW_MEAL_PATH_PATTERN)),
|
|
329
|
+
ingredients: uniqueArray(boundedString(1, 4000), { maxItems: 100 }).optional(),
|
|
330
|
+
}),
|
|
331
|
+
eventSchema("symptom", {
|
|
332
|
+
symptom: boundedString(1, 120),
|
|
333
|
+
intensity: integerSchema(0, 10),
|
|
334
|
+
bodySite: boundedString(1, 120).optional(),
|
|
335
|
+
}),
|
|
336
|
+
z
|
|
337
|
+
.object({
|
|
338
|
+
...baseEventShape,
|
|
339
|
+
kind: z.literal("note"),
|
|
340
|
+
...baseEventOptionalShape,
|
|
341
|
+
note: boundedString(1, 4000),
|
|
342
|
+
})
|
|
343
|
+
.strict(),
|
|
344
|
+
eventSchema("observation", {
|
|
345
|
+
metric: patternedString(SLUG_PATTERN),
|
|
346
|
+
value: numberSchema(),
|
|
347
|
+
unit: patternedString(UNIT_PATTERN),
|
|
348
|
+
}),
|
|
349
|
+
eventSchema("experiment_event", {
|
|
350
|
+
experimentId: idSchema(ID_PREFIXES.experiment),
|
|
351
|
+
experimentSlug: patternedString(SLUG_PATTERN),
|
|
352
|
+
phase: z.enum(EXPERIMENT_PHASES),
|
|
353
|
+
}),
|
|
354
|
+
eventSchema("medication_intake", {
|
|
355
|
+
medicationName: boundedString(1, 160),
|
|
356
|
+
dose: numberSchema(0),
|
|
357
|
+
unit: patternedString(UNIT_PATTERN),
|
|
358
|
+
}),
|
|
359
|
+
eventSchema("procedure", {
|
|
360
|
+
procedure: boundedString(1, 160),
|
|
361
|
+
status: boundedString(1, 64),
|
|
362
|
+
}),
|
|
363
|
+
eventSchema("supplement_intake", {
|
|
364
|
+
supplementName: boundedString(1, 160),
|
|
365
|
+
dose: numberSchema(0),
|
|
366
|
+
unit: patternedString(UNIT_PATTERN),
|
|
367
|
+
}),
|
|
368
|
+
eventSchema("test", {
|
|
369
|
+
testName: boundedString(1, 160),
|
|
370
|
+
resultStatus: z.enum(TEST_RESULT_STATUSES),
|
|
371
|
+
summary: boundedString(1, 4000).optional(),
|
|
372
|
+
testCategory: boundedString(1, 64).optional(),
|
|
373
|
+
specimenType: boundedString(1, 64).optional(),
|
|
374
|
+
labName: boundedString(1, 160).optional(),
|
|
375
|
+
labPanelId: boundedString(1, 120).optional(),
|
|
376
|
+
collectedAt: isoDateTimeString().optional(),
|
|
377
|
+
reportedAt: isoDateTimeString().optional(),
|
|
378
|
+
fastingStatus: z.enum(BLOOD_TEST_FASTING_STATUSES).optional(),
|
|
379
|
+
results: z.array(bloodTestResultSchema).min(1).max(500).optional(),
|
|
380
|
+
}),
|
|
381
|
+
eventSchema("activity_session", {
|
|
382
|
+
activityType: patternedString(SLUG_PATTERN),
|
|
383
|
+
durationMinutes: integerSchema(1),
|
|
384
|
+
distanceKm: numberSchema(0).optional(),
|
|
385
|
+
strengthExercises: z.array(activityStrengthExerciseSchema).min(1).max(50).optional(),
|
|
386
|
+
}),
|
|
387
|
+
eventSchema("sleep_session", {
|
|
388
|
+
startAt: isoDateTimeString(),
|
|
389
|
+
endAt: isoDateTimeString(),
|
|
390
|
+
durationMinutes: integerSchema(1),
|
|
391
|
+
}),
|
|
392
|
+
eventSchema("intervention_session", {
|
|
393
|
+
interventionType: patternedString(SLUG_PATTERN),
|
|
394
|
+
durationMinutes: integerSchema(1).optional(),
|
|
395
|
+
protocolId: idSchema(ID_PREFIXES.protocol).optional(),
|
|
396
|
+
}),
|
|
397
|
+
eventSchema("adverse_effect", {
|
|
398
|
+
substance: boundedString(1, 160),
|
|
399
|
+
effect: boundedString(1, 160),
|
|
400
|
+
severity: z.enum(ADVERSE_EFFECT_SEVERITIES),
|
|
401
|
+
}),
|
|
402
|
+
eventSchema("exposure", {
|
|
403
|
+
exposureType: boundedString(1, 160),
|
|
404
|
+
substance: boundedString(1, 160),
|
|
405
|
+
duration: boundedString(1, 120).optional(),
|
|
406
|
+
}),
|
|
407
|
+
]), "@murphai/contracts/event-record.schema.json", "Murph Event Record");
|
|
408
|
+
export const sampleRecordSchema = withContractMetadata(z.discriminatedUnion("stream", [
|
|
409
|
+
sampleSchema("heart_rate", {
|
|
410
|
+
value: integerSchema(0),
|
|
411
|
+
unit: z.literal("bpm"),
|
|
412
|
+
}),
|
|
413
|
+
sampleSchema("hrv", {
|
|
414
|
+
value: numberSchema(0),
|
|
415
|
+
unit: z.literal("ms"),
|
|
416
|
+
}),
|
|
417
|
+
sampleSchema("steps", {
|
|
418
|
+
value: integerSchema(0),
|
|
419
|
+
unit: z.literal("count"),
|
|
420
|
+
}),
|
|
421
|
+
sampleSchema("sleep_stage", {
|
|
422
|
+
stage: z.enum(SLEEP_STAGES),
|
|
423
|
+
startAt: isoDateTimeString(),
|
|
424
|
+
endAt: isoDateTimeString(),
|
|
425
|
+
durationMinutes: integerSchema(1),
|
|
426
|
+
unit: z.literal("stage"),
|
|
427
|
+
}),
|
|
428
|
+
sampleSchema("respiratory_rate", {
|
|
429
|
+
value: numberSchema(0),
|
|
430
|
+
unit: z.literal("breaths_per_minute"),
|
|
431
|
+
}),
|
|
432
|
+
sampleSchema("temperature", {
|
|
433
|
+
value: numberSchema(),
|
|
434
|
+
unit: z.literal("celsius"),
|
|
435
|
+
}),
|
|
436
|
+
sampleSchema("glucose", {
|
|
437
|
+
value: numberSchema(0),
|
|
438
|
+
unit: z.literal("mg_dL"),
|
|
439
|
+
}),
|
|
440
|
+
]), "@murphai/contracts/sample-record.schema.json", "Murph Sample Record");
|
|
441
|
+
export const auditRecordSchema = withContractMetadata(z
|
|
442
|
+
.object({
|
|
443
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.audit),
|
|
444
|
+
id: idSchema(ID_PREFIXES.audit),
|
|
445
|
+
action: z.enum(AUDIT_ACTIONS),
|
|
446
|
+
status: z.enum(AUDIT_STATUSES),
|
|
447
|
+
occurredAt: isoDateTimeString(),
|
|
448
|
+
actor: z.enum(AUDIT_ACTORS),
|
|
449
|
+
commandName: boundedString(1, 160),
|
|
450
|
+
summary: boundedString(1, 4000),
|
|
451
|
+
targetIds: uniqueArray(patternedString(GENERIC_CONTRACT_ID_PATTERN), { uniqueItems: true }).optional(),
|
|
452
|
+
errorCode: z.enum(ERROR_CODE_VALUES).optional(),
|
|
453
|
+
changes: z.array(z
|
|
454
|
+
.object({
|
|
455
|
+
path: patternedString(RELATIVE_PATH_PATTERN),
|
|
456
|
+
op: z.enum(FILE_CHANGE_OPERATIONS),
|
|
457
|
+
})
|
|
458
|
+
.strict()),
|
|
459
|
+
})
|
|
460
|
+
.strict(), "@murphai/contracts/audit-record.schema.json", "Murph Audit Record");
|
|
461
|
+
const INBOX_CAPTURE_ID_PATTERN = "^[A-Za-z0-9][A-Za-z0-9_-]*$";
|
|
462
|
+
const INBOX_ATTACHMENT_ID_PATTERN = "^att_[A-Za-z0-9][A-Za-z0-9_-]*_[0-9]{2}$";
|
|
463
|
+
const INBOX_CAPTURE_ATTACHMENT_KIND_VALUES = ["image", "audio", "video", "document", "other"];
|
|
464
|
+
const HEX_SHA256_PATTERN = "^[a-f0-9]{64}$";
|
|
465
|
+
const inboxCaptureThreadSchema = z
|
|
466
|
+
.object({
|
|
467
|
+
id: boundedString(1, 4000),
|
|
468
|
+
title: boundedString(1, 4000).nullable().optional(),
|
|
469
|
+
isDirect: z.boolean().nullable(),
|
|
470
|
+
})
|
|
471
|
+
.strict();
|
|
472
|
+
const inboxCaptureActorSchema = z
|
|
473
|
+
.object({
|
|
474
|
+
id: boundedString(1, 255).nullable().optional(),
|
|
475
|
+
displayName: boundedString(1, 255).nullable().optional(),
|
|
476
|
+
isSelf: z.boolean(),
|
|
477
|
+
})
|
|
478
|
+
.strict();
|
|
479
|
+
const inboxCaptureAttachmentSchema = z
|
|
480
|
+
.object({
|
|
481
|
+
attachmentId: patternedString(INBOX_ATTACHMENT_ID_PATTERN),
|
|
482
|
+
ordinal: integerSchema(1),
|
|
483
|
+
externalId: boundedString(1, 255).nullable().optional(),
|
|
484
|
+
kind: z.enum(INBOX_CAPTURE_ATTACHMENT_KIND_VALUES),
|
|
485
|
+
mime: boundedString(1, 255).nullable().optional(),
|
|
486
|
+
originalPath: z.null().optional(),
|
|
487
|
+
fileName: boundedString(1, 255).nullable().optional(),
|
|
488
|
+
byteSize: integerSchema(0).nullable().optional(),
|
|
489
|
+
storedPath: patternedString(RELATIVE_PATH_PATTERN).nullable().optional(),
|
|
490
|
+
sha256: patternedString(HEX_SHA256_PATTERN).nullable().optional(),
|
|
491
|
+
})
|
|
492
|
+
.strict();
|
|
493
|
+
export const inboxCaptureRecordSchema = withContractMetadata(z
|
|
494
|
+
.object({
|
|
495
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.inboxCapture),
|
|
496
|
+
captureId: patternedString(INBOX_CAPTURE_ID_PATTERN),
|
|
497
|
+
identityKey: boundedString(1, 1024),
|
|
498
|
+
eventId: idSchema(ID_PREFIXES.event),
|
|
499
|
+
auditId: idSchema(ID_PREFIXES.audit),
|
|
500
|
+
source: boundedString(1, 160),
|
|
501
|
+
accountId: boundedString(1, 255).nullable().optional(),
|
|
502
|
+
externalId: boundedString(1, 255),
|
|
503
|
+
thread: inboxCaptureThreadSchema,
|
|
504
|
+
actor: inboxCaptureActorSchema,
|
|
505
|
+
occurredAt: isoDateTimeString(),
|
|
506
|
+
recordedAt: isoDateTimeString(),
|
|
507
|
+
receivedAt: isoDateTimeString().nullable().optional(),
|
|
508
|
+
text: boundedString(1, 4000).nullable().optional(),
|
|
509
|
+
raw: jsonObjectSchema,
|
|
510
|
+
sourceDirectory: patternedString(RELATIVE_PATH_PATTERN),
|
|
511
|
+
envelopePath: patternedString(RELATIVE_PATH_PATTERN),
|
|
512
|
+
rawRefs: uniqueArray(patternedString(RELATIVE_PATH_PATTERN), { uniqueItems: true }),
|
|
513
|
+
attachments: z.array(inboxCaptureAttachmentSchema),
|
|
514
|
+
})
|
|
515
|
+
.strict(), "@murphai/contracts/inbox-capture-record.schema.json", "Murph Inbox Capture Record");
|
|
516
|
+
export const coreFrontmatterSchema = withContractMetadata(z
|
|
517
|
+
.object({
|
|
518
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.coreFrontmatter),
|
|
519
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.core),
|
|
520
|
+
vaultId: idSchema(ID_PREFIXES.vault),
|
|
521
|
+
title: boundedString(1, 160),
|
|
522
|
+
timezone: timeZoneString(),
|
|
523
|
+
updatedAt: isoDateTimeString(),
|
|
524
|
+
activeExperimentSlugs: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
525
|
+
})
|
|
526
|
+
.strict(), "@murphai/contracts/frontmatter-core.schema.json", "Murph CORE Frontmatter");
|
|
527
|
+
export const journalDayFrontmatterSchema = withContractMetadata(z
|
|
528
|
+
.object({
|
|
529
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.journalDayFrontmatter),
|
|
530
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.journalDay),
|
|
531
|
+
dayKey: patternedString(DAY_KEY_PATTERN),
|
|
532
|
+
eventIds: uniqueArray(idSchema(ID_PREFIXES.event), { uniqueItems: true }),
|
|
533
|
+
sampleStreams: uniqueArray(z.enum(SAMPLE_STREAMS), { uniqueItems: true }),
|
|
534
|
+
})
|
|
535
|
+
.strict(), "@murphai/contracts/frontmatter-journal-day.schema.json", "Murph Journal Day Frontmatter");
|
|
536
|
+
export const experimentFrontmatterSchema = withContractMetadata(z
|
|
537
|
+
.object({
|
|
538
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.experimentFrontmatter),
|
|
539
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.experiment),
|
|
540
|
+
experimentId: idSchema(ID_PREFIXES.experiment),
|
|
541
|
+
slug: patternedString(SLUG_PATTERN),
|
|
542
|
+
status: z.enum(EXPERIMENT_STATUSES),
|
|
543
|
+
title: boundedString(1, 160),
|
|
544
|
+
startedOn: isoDateString(),
|
|
545
|
+
endedOn: isoDateString().optional(),
|
|
546
|
+
hypothesis: boundedString(1, 4000).optional(),
|
|
547
|
+
tags: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
548
|
+
})
|
|
549
|
+
.strict(), "@murphai/contracts/frontmatter-experiment.schema.json", "Murph Experiment Frontmatter");
|
|
550
|
+
export const providerFrontmatterSchema = withContractMetadata(z
|
|
551
|
+
.object({
|
|
552
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.providerFrontmatter),
|
|
553
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.provider),
|
|
554
|
+
providerId: idSchema(ID_PREFIXES.provider),
|
|
555
|
+
slug: patternedString(SLUG_PATTERN),
|
|
556
|
+
title: boundedString(1, 160),
|
|
557
|
+
status: boundedString(1, 64).optional(),
|
|
558
|
+
specialty: boundedString(1, 160).optional(),
|
|
559
|
+
organization: boundedString(1, 160).optional(),
|
|
560
|
+
location: boundedString(1, 160).optional(),
|
|
561
|
+
website: boundedString(1, 240).optional(),
|
|
562
|
+
phone: boundedString(1, 64).optional(),
|
|
563
|
+
note: boundedString(1, 4000).optional(),
|
|
564
|
+
aliases: uniqueArray(boundedString(1, 160), { uniqueItems: true }).optional(),
|
|
565
|
+
})
|
|
566
|
+
.strict(), "@murphai/contracts/frontmatter-provider.schema.json", "Murph Provider Frontmatter");
|
|
567
|
+
export const foodFrontmatterSchema = withContractMetadata(z
|
|
568
|
+
.object({
|
|
569
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.foodFrontmatter),
|
|
570
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.food),
|
|
571
|
+
foodId: idSchema(ID_PREFIXES.food),
|
|
572
|
+
slug: patternedString(SLUG_PATTERN),
|
|
573
|
+
title: boundedString(1, 160),
|
|
574
|
+
status: z.enum(FOOD_STATUSES),
|
|
575
|
+
summary: boundedString(1, 4000).optional(),
|
|
576
|
+
kind: boundedString(1, 160).optional(),
|
|
577
|
+
brand: boundedString(1, 160).optional(),
|
|
578
|
+
vendor: boundedString(1, 160).optional(),
|
|
579
|
+
location: boundedString(1, 160).optional(),
|
|
580
|
+
serving: boundedString(1, 160).optional(),
|
|
581
|
+
aliases: uniqueArray(boundedString(1, 160), { uniqueItems: true }).optional(),
|
|
582
|
+
ingredients: uniqueArray(boundedString(1, 4000), { maxItems: 100 }).optional(),
|
|
583
|
+
tags: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
584
|
+
note: boundedString(1, 4000).optional(),
|
|
585
|
+
attachedProtocolIds: uniqueArray(idSchema(ID_PREFIXES.protocol), {
|
|
586
|
+
maxItems: 32,
|
|
587
|
+
uniqueItems: true,
|
|
588
|
+
}).optional(),
|
|
589
|
+
autoLogDaily: z
|
|
590
|
+
.object({
|
|
591
|
+
time: patternedString(DAILY_TIME_PATTERN),
|
|
592
|
+
})
|
|
593
|
+
.strict()
|
|
594
|
+
.optional(),
|
|
595
|
+
})
|
|
596
|
+
.strict(), "@murphai/contracts/frontmatter-food.schema.json", "Murph Food Frontmatter");
|
|
597
|
+
export const recipeFrontmatterSchema = withContractMetadata(z
|
|
598
|
+
.object({
|
|
599
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.recipeFrontmatter),
|
|
600
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.recipe),
|
|
601
|
+
recipeId: idSchema(ID_PREFIXES.recipe),
|
|
602
|
+
slug: patternedString(SLUG_PATTERN),
|
|
603
|
+
title: boundedString(1, 160),
|
|
604
|
+
status: z.enum(RECIPE_STATUSES),
|
|
605
|
+
summary: boundedString(1, 4000).optional(),
|
|
606
|
+
cuisine: boundedString(1, 160).optional(),
|
|
607
|
+
dishType: boundedString(1, 160).optional(),
|
|
608
|
+
source: boundedString(1, 240).optional(),
|
|
609
|
+
servings: numberSchema(0).optional(),
|
|
610
|
+
prepTimeMinutes: integerSchema(0).optional(),
|
|
611
|
+
cookTimeMinutes: integerSchema(0).optional(),
|
|
612
|
+
totalTimeMinutes: integerSchema(0).optional(),
|
|
613
|
+
tags: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
614
|
+
ingredients: uniqueArray(boundedString(1, 4000), { maxItems: 100 }).optional(),
|
|
615
|
+
steps: uniqueArray(boundedString(1, 4000), { maxItems: 100 }).optional(),
|
|
616
|
+
relatedGoalIds: uniqueArray(idSchema(ID_PREFIXES.goal), { uniqueItems: true }).optional(),
|
|
617
|
+
relatedConditionIds: uniqueArray(idSchema(ID_PREFIXES.condition), { uniqueItems: true }).optional(),
|
|
618
|
+
})
|
|
619
|
+
.strict(), "@murphai/contracts/frontmatter-recipe.schema.json", "Murph Recipe Frontmatter");
|
|
620
|
+
export const workoutFormatFrontmatterSchema = withContractMetadata(z
|
|
621
|
+
.object({
|
|
622
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.workoutFormatFrontmatter),
|
|
623
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.workoutFormat),
|
|
624
|
+
workoutFormatId: idSchema(ID_PREFIXES.workoutFormat),
|
|
625
|
+
slug: patternedString(SLUG_PATTERN),
|
|
626
|
+
title: boundedString(1, 160),
|
|
627
|
+
status: z.enum(WORKOUT_FORMAT_STATUSES),
|
|
628
|
+
summary: boundedString(1, 4000).optional(),
|
|
629
|
+
activityType: patternedString(SLUG_PATTERN),
|
|
630
|
+
durationMinutes: integerSchema(1, 24 * 60).optional(),
|
|
631
|
+
distanceKm: numberSchema(0, 1_000).optional(),
|
|
632
|
+
strengthExercises: z.array(activityStrengthExerciseSchema).min(1).max(50).optional(),
|
|
633
|
+
tags: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
634
|
+
note: boundedString(1, 4000).optional(),
|
|
635
|
+
templateText: boundedString(1, 4000).optional(),
|
|
636
|
+
})
|
|
637
|
+
.strict(), "@murphai/contracts/frontmatter-workout-format.schema.json", "Murph Workout Format Frontmatter");
|
|
638
|
+
export const assessmentResponseSchema = withContractMetadata(z
|
|
639
|
+
.object({
|
|
640
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.assessmentResponse),
|
|
641
|
+
id: idSchema(ID_PREFIXES.assessment),
|
|
642
|
+
assessmentType: patternedString(SLUG_PATTERN),
|
|
643
|
+
recordedAt: isoDateTimeString(),
|
|
644
|
+
source: z.enum(ASSESSMENT_SOURCES),
|
|
645
|
+
rawPath: patternedString(RAW_ASSESSMENT_SOURCE_PATTERN),
|
|
646
|
+
title: boundedString(1, 160).optional(),
|
|
647
|
+
questionnaireSlug: patternedString(SLUG_PATTERN).optional(),
|
|
648
|
+
responses: jsonObjectSchema,
|
|
649
|
+
relatedIds: uniqueArray(patternedString(GENERIC_CONTRACT_ID_PATTERN), { uniqueItems: true }).optional(),
|
|
650
|
+
})
|
|
651
|
+
.strict(), "@murphai/contracts/assessment-response.schema.json", "Murph Assessment Response");
|
|
652
|
+
export const rawImportManifestArtifactSchema = z
|
|
653
|
+
.object({
|
|
654
|
+
role: boundedString(1, 160),
|
|
655
|
+
relativePath: patternedString(RAW_PATH_PATTERN),
|
|
656
|
+
originalFileName: boundedString(1, 255),
|
|
657
|
+
mediaType: boundedString(1, 255),
|
|
658
|
+
byteSize: integerSchema(0),
|
|
659
|
+
sha256: patternedString(SHA256_HEX_PATTERN, 64, 64),
|
|
660
|
+
})
|
|
661
|
+
.strict();
|
|
662
|
+
export const rawImportManifestSchema = z
|
|
663
|
+
.object({
|
|
664
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.rawImportManifest),
|
|
665
|
+
importId: patternedString(GENERIC_CONTRACT_ID_PATTERN),
|
|
666
|
+
importKind: z.enum(RAW_IMPORT_KINDS),
|
|
667
|
+
importedAt: isoDateTimeString(),
|
|
668
|
+
source: boundedString(1, 160).nullable(),
|
|
669
|
+
rawDirectory: patternedString(RAW_PATH_PATTERN),
|
|
670
|
+
artifacts: uniqueArray(rawImportManifestArtifactSchema, { uniqueItems: true }),
|
|
671
|
+
provenance: jsonObjectSchema,
|
|
672
|
+
})
|
|
673
|
+
.strict();
|
|
674
|
+
export const profileSnapshotNarrativeSchema = z
|
|
675
|
+
.object({
|
|
676
|
+
summary: boundedString(1, 4000).optional(),
|
|
677
|
+
highlights: uniqueArray(boundedString(1, 240), { maxItems: 25, uniqueItems: true }).optional(),
|
|
678
|
+
})
|
|
679
|
+
.strict();
|
|
680
|
+
export const profileSnapshotGoalsSchema = z
|
|
681
|
+
.object({
|
|
682
|
+
topGoalIds: uniqueArray(idSchema(ID_PREFIXES.goal), { uniqueItems: true }).optional(),
|
|
683
|
+
})
|
|
684
|
+
.strict();
|
|
685
|
+
export const profileSnapshotProfileSchema = z
|
|
686
|
+
.object({
|
|
687
|
+
narrative: profileSnapshotNarrativeSchema.optional(),
|
|
688
|
+
goals: profileSnapshotGoalsSchema.optional(),
|
|
689
|
+
custom: jsonObjectSchema.optional(),
|
|
690
|
+
})
|
|
691
|
+
.strict();
|
|
692
|
+
export const profileSnapshotSchema = withContractMetadata(z
|
|
693
|
+
.object({
|
|
694
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.profileSnapshot),
|
|
695
|
+
id: idSchema(ID_PREFIXES.profileSnapshot),
|
|
696
|
+
recordedAt: isoDateTimeString(),
|
|
697
|
+
source: z.enum(PROFILE_SNAPSHOT_SOURCES),
|
|
698
|
+
sourceAssessmentIds: uniqueArray(idSchema(ID_PREFIXES.assessment), { uniqueItems: true }).optional(),
|
|
699
|
+
sourceEventIds: uniqueArray(idSchema(ID_PREFIXES.event), { uniqueItems: true }).optional(),
|
|
700
|
+
profile: profileSnapshotProfileSchema,
|
|
701
|
+
})
|
|
702
|
+
.strict(), "@murphai/contracts/profile-snapshot.schema.json", "Murph Profile Snapshot");
|
|
703
|
+
export const profileCurrentFrontmatterSchema = withContractMetadata(z
|
|
704
|
+
.object({
|
|
705
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.profileCurrentFrontmatter),
|
|
706
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.profileCurrent),
|
|
707
|
+
snapshotId: idSchema(ID_PREFIXES.profileSnapshot),
|
|
708
|
+
updatedAt: isoDateTimeString(),
|
|
709
|
+
sourceAssessmentIds: uniqueArray(idSchema(ID_PREFIXES.assessment), { uniqueItems: true }).optional(),
|
|
710
|
+
sourceEventIds: uniqueArray(idSchema(ID_PREFIXES.event), { uniqueItems: true }).optional(),
|
|
711
|
+
topGoalIds: uniqueArray(idSchema(ID_PREFIXES.goal), { uniqueItems: true }).optional(),
|
|
712
|
+
})
|
|
713
|
+
.strict(), "@murphai/contracts/frontmatter-profile-current.schema.json", "Murph Profile Current Frontmatter");
|
|
714
|
+
export const goalFrontmatterSchema = withContractMetadata(z
|
|
715
|
+
.object({
|
|
716
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.goalFrontmatter),
|
|
717
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.goal),
|
|
718
|
+
goalId: idSchema(ID_PREFIXES.goal),
|
|
719
|
+
slug: patternedString(SLUG_PATTERN),
|
|
720
|
+
title: boundedString(1, 160),
|
|
721
|
+
status: z.enum(GOAL_STATUSES),
|
|
722
|
+
horizon: z.enum(GOAL_HORIZONS),
|
|
723
|
+
priority: integerSchema(1, 10),
|
|
724
|
+
window: z
|
|
725
|
+
.object({
|
|
726
|
+
startAt: isoDateString(),
|
|
727
|
+
targetAt: isoDateString().optional(),
|
|
728
|
+
})
|
|
729
|
+
.strict(),
|
|
730
|
+
parentGoalId: z.union([idSchema(ID_PREFIXES.goal), z.null()]).optional(),
|
|
731
|
+
relatedGoalIds: uniqueArray(idSchema(ID_PREFIXES.goal), { uniqueItems: true }).optional(),
|
|
732
|
+
relatedExperimentIds: uniqueArray(idSchema(ID_PREFIXES.experiment), { uniqueItems: true }).optional(),
|
|
733
|
+
domains: uniqueArray(patternedString(SLUG_PATTERN), { uniqueItems: true }).optional(),
|
|
734
|
+
})
|
|
735
|
+
.strict(), "@murphai/contracts/frontmatter-goal.schema.json", "Murph Goal Frontmatter");
|
|
736
|
+
export const conditionFrontmatterSchema = withContractMetadata(z
|
|
737
|
+
.object({
|
|
738
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.conditionFrontmatter),
|
|
739
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.condition),
|
|
740
|
+
conditionId: idSchema(ID_PREFIXES.condition),
|
|
741
|
+
slug: patternedString(SLUG_PATTERN),
|
|
742
|
+
title: boundedString(1, 160),
|
|
743
|
+
clinicalStatus: z.enum(CONDITION_CLINICAL_STATUSES),
|
|
744
|
+
verificationStatus: z.enum(CONDITION_VERIFICATION_STATUSES).optional(),
|
|
745
|
+
assertedOn: isoDateString().optional(),
|
|
746
|
+
resolvedOn: isoDateString().optional(),
|
|
747
|
+
severity: z.enum(CONDITION_SEVERITIES).optional(),
|
|
748
|
+
bodySites: uniqueArray(boundedString(1, 120), { uniqueItems: true }).optional(),
|
|
749
|
+
relatedGoalIds: uniqueArray(idSchema(ID_PREFIXES.goal), { uniqueItems: true }).optional(),
|
|
750
|
+
relatedProtocolIds: uniqueArray(idSchema(ID_PREFIXES.protocol), { uniqueItems: true }).optional(),
|
|
751
|
+
note: boundedString(1, 4000).optional(),
|
|
752
|
+
})
|
|
753
|
+
.strict(), "@murphai/contracts/frontmatter-condition.schema.json", "Murph Condition Frontmatter");
|
|
754
|
+
export const allergyFrontmatterSchema = withContractMetadata(z
|
|
755
|
+
.object({
|
|
756
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.allergyFrontmatter),
|
|
757
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.allergy),
|
|
758
|
+
allergyId: idSchema(ID_PREFIXES.allergy),
|
|
759
|
+
slug: patternedString(SLUG_PATTERN),
|
|
760
|
+
title: boundedString(1, 160),
|
|
761
|
+
substance: boundedString(1, 160),
|
|
762
|
+
status: z.enum(ALLERGY_STATUSES),
|
|
763
|
+
criticality: z.enum(ALLERGY_CRITICALITIES).optional(),
|
|
764
|
+
reaction: boundedString(1, 160).optional(),
|
|
765
|
+
recordedOn: isoDateString().optional(),
|
|
766
|
+
relatedConditionIds: uniqueArray(idSchema(ID_PREFIXES.condition), { uniqueItems: true }).optional(),
|
|
767
|
+
note: boundedString(1, 4000).optional(),
|
|
768
|
+
})
|
|
769
|
+
.strict(), "@murphai/contracts/frontmatter-allergy.schema.json", "Murph Allergy Frontmatter");
|
|
770
|
+
export const protocolFrontmatterSchema = withContractMetadata((() => {
|
|
771
|
+
const supplementIngredientSchema = z
|
|
772
|
+
.object({
|
|
773
|
+
compound: boundedString(1, 160),
|
|
774
|
+
label: boundedString(1, 160).optional(),
|
|
775
|
+
amount: numberSchema(0).optional(),
|
|
776
|
+
unit: patternedString(UNIT_PATTERN).optional(),
|
|
777
|
+
active: z.boolean().optional(),
|
|
778
|
+
note: boundedString(1, 4000).optional(),
|
|
779
|
+
})
|
|
780
|
+
.strict();
|
|
781
|
+
return z
|
|
782
|
+
.object({
|
|
783
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.protocolFrontmatter),
|
|
784
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.protocol),
|
|
785
|
+
protocolId: idSchema(ID_PREFIXES.protocol),
|
|
786
|
+
slug: patternedString(SLUG_PATTERN),
|
|
787
|
+
title: boundedString(1, 160),
|
|
788
|
+
kind: z.enum(PROTOCOL_KINDS),
|
|
789
|
+
status: z.enum(PROTOCOL_STATUSES),
|
|
790
|
+
startedOn: isoDateString(),
|
|
791
|
+
stoppedOn: isoDateString().optional(),
|
|
792
|
+
substance: boundedString(1, 160).optional(),
|
|
793
|
+
dose: numberSchema(0).optional(),
|
|
794
|
+
unit: patternedString(UNIT_PATTERN).optional(),
|
|
795
|
+
schedule: boundedString(1, 160).optional(),
|
|
796
|
+
brand: boundedString(1, 160).optional(),
|
|
797
|
+
manufacturer: boundedString(1, 160).optional(),
|
|
798
|
+
servingSize: boundedString(1, 160).optional(),
|
|
799
|
+
ingredients: z.array(supplementIngredientSchema).optional(),
|
|
800
|
+
relatedGoalIds: uniqueArray(idSchema(ID_PREFIXES.goal), { uniqueItems: true }).optional(),
|
|
801
|
+
relatedConditionIds: uniqueArray(idSchema(ID_PREFIXES.condition), { uniqueItems: true }).optional(),
|
|
802
|
+
})
|
|
803
|
+
.strict();
|
|
804
|
+
})(), "@murphai/contracts/frontmatter-protocol.schema.json", "Murph Protocol Frontmatter");
|
|
805
|
+
export const familyMemberFrontmatterSchema = withContractMetadata(z
|
|
806
|
+
.object({
|
|
807
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.familyMemberFrontmatter),
|
|
808
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.familyMember),
|
|
809
|
+
familyMemberId: idSchema(ID_PREFIXES.family),
|
|
810
|
+
slug: patternedString(SLUG_PATTERN),
|
|
811
|
+
title: boundedString(1, FAMILY_MEMBER_LIMITS.title),
|
|
812
|
+
relationship: boundedString(1, FAMILY_MEMBER_LIMITS.relationship),
|
|
813
|
+
conditions: uniqueArray(boundedString(1, FAMILY_MEMBER_LIMITS.condition), { uniqueItems: true }).optional(),
|
|
814
|
+
deceased: z.boolean().optional(),
|
|
815
|
+
note: boundedString(1, FAMILY_MEMBER_LIMITS.note).optional(),
|
|
816
|
+
relatedVariantIds: uniqueArray(idSchema(ID_PREFIXES.variant), { uniqueItems: true }).optional(),
|
|
817
|
+
})
|
|
818
|
+
.strict(), "@murphai/contracts/frontmatter-family-member.schema.json", "Murph Family Member Frontmatter");
|
|
819
|
+
export const geneticVariantFrontmatterSchema = withContractMetadata(z
|
|
820
|
+
.object({
|
|
821
|
+
schemaVersion: z.literal(CONTRACT_SCHEMA_VERSION.geneticVariantFrontmatter),
|
|
822
|
+
docType: z.literal(FRONTMATTER_DOC_TYPES.geneticVariant),
|
|
823
|
+
variantId: idSchema(ID_PREFIXES.variant),
|
|
824
|
+
slug: patternedString(SLUG_PATTERN),
|
|
825
|
+
title: boundedString(1, GENETIC_VARIANT_LIMITS.title),
|
|
826
|
+
gene: boundedString(1, GENETIC_VARIANT_LIMITS.gene),
|
|
827
|
+
zygosity: z.enum(VARIANT_ZYGOSITIES).optional(),
|
|
828
|
+
significance: z.enum(VARIANT_SIGNIFICANCES).optional(),
|
|
829
|
+
inheritance: boundedString(1, GENETIC_VARIANT_LIMITS.inheritance).optional(),
|
|
830
|
+
sourceFamilyMemberIds: uniqueArray(idSchema(ID_PREFIXES.family), { uniqueItems: true }).optional(),
|
|
831
|
+
note: boundedString(1, GENETIC_VARIANT_LIMITS.note).optional(),
|
|
832
|
+
})
|
|
833
|
+
.strict(), "@murphai/contracts/frontmatter-genetic-variant.schema.json", "Murph Genetic Variant Frontmatter");
|
|
834
|
+
//# sourceMappingURL=zod.js.map
|