MCPcopy Create free account
hub / github.com/SethGammon/Citadel / validateAgentRunEvent

Function validateAgentRunEvent

core/telemetry/schema.js:20–64  ·  view source on GitHub ↗
(entry)

Source from the content-addressed store, hash-verified

18const TRUST_OVERRIDE_VALUES = ['novice', 'familiar', 'trusted'];
19
20function validateAgentRunEvent(entry) {
21 const errors = [];
22
23 if (!entry || typeof entry !== 'object') {
24 return { valid: false, errors: ['entry must be an object'] };
25 }
26
27 if (typeof entry.timestamp !== 'string' || !entry.timestamp) {
28 errors.push('timestamp must be a non-empty string (ISO 8601)');
29 }
30
31 if (!AGENT_RUN_EVENT_TYPES.includes(entry.event)) {
32 errors.push(`event must be one of: ${AGENT_RUN_EVENT_TYPES.join(', ')} — got: ${entry.event}`);
33 }
34
35 if (typeof entry.agent !== 'string' || !entry.agent) {
36 errors.push('agent must be a non-empty string');
37 }
38
39 if (entry.session !== null && entry.session !== undefined && typeof entry.session !== 'string') {
40 errors.push('session must be a string or null');
41 }
42
43 if (entry.campaign_slug !== null && entry.campaign_slug !== undefined && typeof entry.campaign_slug !== 'string') {
44 errors.push('campaign_slug must be a string or null');
45 }
46
47 if (entry.duration_ms !== null && entry.duration_ms !== undefined && typeof entry.duration_ms !== 'number') {
48 errors.push('duration_ms must be a number or null');
49 }
50
51 if (
52 entry.status !== null &&
53 entry.status !== undefined &&
54 !AGENT_RUN_STATUS_VALUES.includes(entry.status)
55 ) {
56 errors.push(`status must be one of: ${AGENT_RUN_STATUS_VALUES.join(', ')} or null — got: ${entry.status}`);
57 }
58
59 if (entry.meta !== null && entry.meta !== undefined && typeof entry.meta !== 'object') {
60 errors.push('meta must be an object or null');
61 }
62
63 return { valid: errors.length === 0, errors };
64}
65
66function validateHookTimingEvent(entry) {
67 const errors = [];

Callers 2

logAgentRunEventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected