(entry)
| 94 | } |
| 95 | |
| 96 | function validateSessionCostEvent(entry) { |
| 97 | const errors = []; |
| 98 | |
| 99 | if (!entry || typeof entry !== 'object') { |
| 100 | return { valid: false, errors: ['entry must be an object'] }; |
| 101 | } |
| 102 | |
| 103 | if (typeof entry.timestamp !== 'string' || !entry.timestamp) { |
| 104 | errors.push('timestamp must be a non-empty string (ISO 8601)'); |
| 105 | } |
| 106 | |
| 107 | if (typeof entry.agent_count !== 'number' || entry.agent_count < 0) { |
| 108 | errors.push('agent_count must be a non-negative number'); |
| 109 | } |
| 110 | |
| 111 | if (typeof entry.duration_minutes !== 'number' || entry.duration_minutes < 0) { |
| 112 | errors.push('duration_minutes must be a non-negative number'); |
| 113 | } |
| 114 | |
| 115 | if (typeof entry.estimated_cost !== 'number' || entry.estimated_cost < 0) { |
| 116 | errors.push('estimated_cost must be a non-negative number'); |
| 117 | } |
| 118 | |
| 119 | if (entry.campaign_slug !== null && entry.campaign_slug !== undefined && typeof entry.campaign_slug !== 'string') { |
| 120 | errors.push('campaign_slug must be a string or null'); |
| 121 | } |
| 122 | |
| 123 | if (entry.session_id !== null && entry.session_id !== undefined && typeof entry.session_id !== 'string') { |
| 124 | errors.push('session_id must be a string or null'); |
| 125 | } |
| 126 | |
| 127 | if (entry.override_cost !== null && entry.override_cost !== undefined && typeof entry.override_cost !== 'number') { |
| 128 | errors.push('override_cost must be a number or null'); |
| 129 | } |
| 130 | |
| 131 | const optionalNumbers = ['real_cost', 'input_tokens', 'output_tokens', |
| 132 | 'cache_creation_input_tokens', 'cache_read_input_tokens', 'messages', 'subagent_count']; |
| 133 | for (const field of optionalNumbers) { |
| 134 | if (entry[field] !== null && entry[field] !== undefined && typeof entry[field] !== 'number') { |
| 135 | errors.push(`${field} must be a number or absent`); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (entry.models !== null && entry.models !== undefined && typeof entry.models !== 'object') { |
| 140 | errors.push('models must be an object or absent'); |
| 141 | } |
| 142 | |
| 143 | return { valid: errors.length === 0, errors }; |
| 144 | } |
| 145 | |
| 146 | function validateTrustObject(trust) { |
| 147 | const errors = []; |
no outgoing calls
no test coverage detected