(value: unknown)
| 12846 | } |
| 12847 | |
| 12848 | function parseThreadCommandSkillResult(value: unknown): ThreadCommandSkillResult | null { |
| 12849 | const parsed = parseJsonObject(value); |
| 12850 | if (!parsed) { |
| 12851 | return null; |
| 12852 | } |
| 12853 | const action = normalizeThreadCommandSkillAction(parsed.action); |
| 12854 | if (!action) { |
| 12855 | return null; |
| 12856 | } |
| 12857 | const confidence = clampAssistantConfidence(Number(parsed.confidence ?? 0.8)); |
| 12858 | if (action === 'clarify') { |
| 12859 | return { |
| 12860 | action, |
| 12861 | confidence, |
| 12862 | question: compactWhitespace(parsed.question ?? parsed.message ?? ''), |
| 12863 | candidates: Array.isArray(parsed.candidates) ? parsed.candidates.filter((entry) => entry && typeof entry === 'object') : [], |
| 12864 | }; |
| 12865 | } |
| 12866 | if (action === 'no_match' || action === 'reject' || action === 'local_only') { |
| 12867 | return { |
| 12868 | action, |
| 12869 | confidence, |
| 12870 | reason: normalizeNullableText(parsed.reason ?? parsed.message), |
| 12871 | }; |
| 12872 | } |
| 12873 | if (action === 'show_default_threads' || action === 'show_all_threads' || action === 'show_pinned_threads') { |
| 12874 | return { |
| 12875 | action, |
| 12876 | confidence, |
| 12877 | reason: normalizeNullableText(parsed.reason ?? parsed.message), |
| 12878 | }; |
| 12879 | } |
| 12880 | const candidateThreadIds = normalizeStringArray( |
| 12881 | parsed.candidateThreadIds |
| 12882 | ?? parsed.threadIds |
| 12883 | ?? parsed.thread_ids |
| 12884 | ?? parsed.targets, |
| 12885 | ); |
| 12886 | if (candidateThreadIds.length === 0) { |
| 12887 | return null; |
| 12888 | } |
| 12889 | if (action === 'search_threads' || action === 'open_thread' || action === 'peek_thread') { |
| 12890 | return { |
| 12891 | action, |
| 12892 | confidence, |
| 12893 | summary: normalizeNullableText(parsed.summary ?? parsed.reason ?? parsed.message), |
| 12894 | candidateThreadIds, |
| 12895 | }; |
| 12896 | } |
| 12897 | if (action === 'rename_thread') { |
| 12898 | const summary = compactWhitespace(parsed.summary ?? parsed.message ?? ''); |
| 12899 | const newName = compactWhitespace(parsed.newName ?? parsed.name ?? parsed.title ?? ''); |
| 12900 | if (!summary || !newName) { |
| 12901 | return null; |
| 12902 | } |
| 12903 | return { |
| 12904 | action, |
| 12905 | confidence, |
nothing calls this directly
no test coverage detected