(record: Record<string, unknown>)
| 119 | } |
| 120 | |
| 121 | function readClientConfig(record: Record<string, unknown>): AgentDeviceClientConfig { |
| 122 | const stateDir = record.stateDir; |
| 123 | const includeCost = record.includeCost; |
| 124 | const responseLevel = record.responseLevel; |
| 125 | const client: AgentDeviceClientConfig = {}; |
| 126 | if (stateDir !== undefined && (typeof stateDir !== 'string' || stateDir.length === 0)) { |
| 127 | throw new Error('Expected stateDir to be a non-empty string.'); |
| 128 | } |
| 129 | if (typeof stateDir === 'string') client.stateDir = stateDir; |
| 130 | if (includeCost !== undefined && typeof includeCost !== 'boolean') { |
| 131 | throw new Error('Expected includeCost to be a boolean.'); |
| 132 | } |
| 133 | // Only set when explicitly true so the default request shape is untouched |
| 134 | // (cost rides on response.data → structuredContent only when opted in). |
| 135 | if (includeCost === true) client.cost = true; |
| 136 | // Only set when it names a known level so the default request shape is |
| 137 | // untouched (responseLevel rides on meta.responseLevel only when opted in). |
| 138 | const level = readResponseLevel(responseLevel); |
| 139 | if (level !== undefined) client.responseLevel = level; |
| 140 | return client; |
| 141 | } |
| 142 | |
| 143 | function readResponseLevel(value: unknown): ResponseLevel | undefined { |
| 144 | if (value === undefined) return undefined; |
no test coverage detected