(source: unknown)
| 34 | } |
| 35 | |
| 36 | function getSubagentKind(source: unknown): string | null { |
| 37 | if (typeof source === "string") { |
| 38 | const normalized = normalizeSubagentKind(source); |
| 39 | return normalized || null; |
| 40 | } |
| 41 | |
| 42 | const sourceRecord = asRecord(source); |
| 43 | if (!sourceRecord) { |
| 44 | return null; |
| 45 | } |
| 46 | |
| 47 | const subAgentRaw = |
| 48 | sourceRecord.subAgent ?? sourceRecord.sub_agent ?? sourceRecord.subagent; |
| 49 | if (typeof subAgentRaw === "string") { |
| 50 | const normalized = normalizeSubagentKind(subAgentRaw); |
| 51 | return normalized || null; |
| 52 | } |
| 53 | |
| 54 | const subAgentRecord = asRecord(subAgentRaw); |
| 55 | if (!subAgentRecord) { |
| 56 | return null; |
| 57 | } |
| 58 | |
| 59 | const explicitKind = asString( |
| 60 | subAgentRecord.kind ?? |
| 61 | subAgentRecord.type ?? |
| 62 | subAgentRecord.name ?? |
| 63 | subAgentRecord.id, |
| 64 | ); |
| 65 | if (explicitKind) { |
| 66 | const normalized = normalizeSubagentKind(explicitKind); |
| 67 | return normalized || null; |
| 68 | } |
| 69 | |
| 70 | const candidateKeys = Object.keys(subAgentRecord).filter( |
| 71 | (key) => key !== "thread_spawn" && key !== "threadSpawn", |
| 72 | ); |
| 73 | if (candidateKeys.length !== 1) { |
| 74 | return null; |
| 75 | } |
| 76 | const normalized = normalizeSubagentKind(candidateKeys[0] ?? ""); |
| 77 | return normalized || null; |
| 78 | } |
| 79 | |
| 80 | export function isSubagentThreadSource(source: unknown): boolean { |
| 81 | if (typeof source === "string") { |
no test coverage detected