* Map a PermissionDecisionReason to the OTel `source` label for the * non-interactive tool_decision path, staying within the documented * vocabulary (config, hook, user_permanent, user_temporary, user_reject). * * For permissionPromptTool, the SDK host may set decisionClassification on * the Pe
( reason: PermissionDecisionReason | undefined, behavior: 'allow' | 'deny', )
| 205 | * deny → user_reject. |
| 206 | */ |
| 207 | function decisionReasonToOTelSource( |
| 208 | reason: PermissionDecisionReason | undefined, |
| 209 | behavior: 'allow' | 'deny', |
| 210 | ): string { |
| 211 | if (!reason) { |
| 212 | return 'config' |
| 213 | } |
| 214 | switch (reason.type) { |
| 215 | case 'permissionPromptTool': { |
| 216 | // toolResult is typed `unknown` on PermissionDecisionReason but carries |
| 217 | // the parsed Output from PermissionPromptToolResultSchema. Narrow at |
| 218 | // runtime rather than widen the cross-file type. |
| 219 | const toolResult = reason.toolResult as |
| 220 | | { decisionClassification?: string } |
| 221 | | undefined |
| 222 | const classified = toolResult?.decisionClassification |
| 223 | if ( |
| 224 | classified === 'user_temporary' || |
| 225 | classified === 'user_permanent' || |
| 226 | classified === 'user_reject' |
| 227 | ) { |
| 228 | return classified |
| 229 | } |
| 230 | return behavior === 'allow' ? 'user_temporary' : 'user_reject' |
| 231 | } |
| 232 | case 'rule': |
| 233 | return ruleSourceToOTelSource(reason.rule.source, behavior) |
| 234 | case 'hook': |
| 235 | return 'hook' |
| 236 | case 'mode': |
| 237 | case 'classifier': |
| 238 | case 'subcommandResults': |
| 239 | case 'asyncAgent': |
| 240 | case 'sandboxOverride': |
| 241 | case 'workingDir': |
| 242 | case 'safetyCheck': |
| 243 | case 'other': |
| 244 | return 'config' |
| 245 | default: { |
| 246 | const _exhaustive: never = reason |
| 247 | return 'config' |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | function getNextImagePasteId(messages: Message[]): number { |
| 253 | let maxId = 0 |
no test coverage detected