MCPcopy Create free account
hub / github.com/Noumena-Network/code / decisionReasonToOTelSource

Function decisionReasonToOTelSource

src/services/tools/toolExecution.ts:208–251  ·  view source on GitHub ↗

* 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',
)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 1

ruleSourceToOTelSourceFunction · 0.85

Tested by

no test coverage detected