@autotest/agent 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +7 -0
  2. package/dist/.buildstamp +1 -0
  3. package/dist/api/agent_api.d.ts +2 -2
  4. package/dist/autotest-cli.js +1 -397
  5. package/dist/common/config/config.yaml +4 -0
  6. package/dist/common/config/manager.d.ts +4 -4
  7. package/dist/common/config/types.d.ts +5 -0
  8. package/dist/common/dfx/index.d.ts +1 -1
  9. package/dist/core/agent/single_agent/agent.d.ts +1 -0
  10. package/dist/core/device/device_protocol.d.ts +1 -1
  11. package/dist/core/device/hdc/device.d.ts +5 -2
  12. package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
  13. package/dist/core/knowledge/vectordb.d.ts +5 -5
  14. package/dist/core/mcp/harmony_hdc_adapter.d.ts +2 -0
  15. package/dist/core/mcp/mcp_tools.d.ts +1 -0
  16. package/dist/core/mcp/verify_tool.d.ts +12 -0
  17. package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
  18. package/dist/data_types/device.d.ts +1 -1
  19. package/dist/data_types/index.d.ts +1 -1
  20. package/dist/index.d.ts +4 -4
  21. package/dist/index.js +1 -163
  22. package/dist/tools/batch_runner.js +1 -745
  23. package/dist/tools/case_runner/runner.js +1 -410
  24. package/dist/tools/config/config_tool.js +1 -339
  25. package/dist/tools/prompt_compare/compare_runner.js +1 -360
  26. package/package.json +2 -2
  27. package/dist/api/agent_api.js +0 -550
  28. package/dist/api/autotest_agent.js +0 -205
  29. package/dist/api/types.js +0 -11
  30. package/dist/common/case_manager.js +0 -91
  31. package/dist/common/collect_case.js +0 -128
  32. package/dist/common/common_errors.js +0 -66
  33. package/dist/common/config/config_validator.js +0 -28
  34. package/dist/common/config/manager.js +0 -257
  35. package/dist/common/config/output.js +0 -59
  36. package/dist/common/config/types.js +0 -185
  37. package/dist/common/dfx/client_factory.js +0 -62
  38. package/dist/common/dfx/context.js +0 -23
  39. package/dist/common/dfx/index.js +0 -15
  40. package/dist/common/dfx/recorder.js +0 -191
  41. package/dist/common/dfx/recording_fetch.js +0 -228
  42. package/dist/common/dfx/source.js +0 -13
  43. package/dist/common/image_cacher.js +0 -36
  44. package/dist/common/image_helper.js +0 -128
  45. package/dist/common/image_similarity.js +0 -171
  46. package/dist/common/llm_cache/cache_transport.js +0 -102
  47. package/dist/common/llm_cache/prompt_cache.js +0 -113
  48. package/dist/common/logger.js +0 -158
  49. package/dist/common/model/custom_model.js +0 -487
  50. package/dist/common/model/index.js +0 -5
  51. package/dist/common/path_utils.js +0 -88
  52. package/dist/common/result_parser.js +0 -49
  53. package/dist/common/usage/token_usage.js +0 -117
  54. package/dist/common/utils.js +0 -125
  55. package/dist/core/agent/layered_agent/ability_helper.js +0 -125
  56. package/dist/core/agent/layered_agent/agent.js +0 -37
  57. package/dist/core/agent/layered_agent/agent_registry.js +0 -82
  58. package/dist/core/agent/layered_agent/decision.js +0 -518
  59. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
  60. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
  61. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
  62. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
  63. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
  64. package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
  65. package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
  66. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
  67. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
  68. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
  69. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
  70. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
  71. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
  72. package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
  73. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
  74. package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
  75. package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
  76. package/dist/core/agent/report_analyzer_agent/config.js +0 -22
  77. package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
  78. package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
  79. package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
  80. package/dist/core/agent/report_analyzer_agent/index.js +0 -52
  81. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
  82. package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
  83. package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
  84. package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
  85. package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
  86. package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
  87. package/dist/core/agent/report_analyzer_agent/types.js +0 -274
  88. package/dist/core/agent/rewrite_agent/agent.js +0 -209
  89. package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
  90. package/dist/core/agent/rewrite_agent/mapping.js +0 -56
  91. package/dist/core/agent/rewrite_agent/parse.js +0 -121
  92. package/dist/core/agent/rewrite_agent/types.js +0 -37
  93. package/dist/core/agent/single_agent/agent.js +0 -801
  94. package/dist/core/agent/single_agent/hook_manager.js +0 -59
  95. package/dist/core/agent/single_agent/hooks.js +0 -288
  96. package/dist/core/agent/single_agent/image_utils.js +0 -158
  97. package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
  98. package/dist/core/agent/single_agent/subagent_manager.js +0 -72
  99. package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
  100. package/dist/core/agent/types.js +0 -2
  101. package/dist/core/agent/utils/message_builder.js +0 -138
  102. package/dist/core/device/device_protocol.js +0 -2
  103. package/dist/core/device/hdc/apps.js +0 -437
  104. package/dist/core/device/hdc/device.js +0 -219
  105. package/dist/core/device/hdc/index.js +0 -31
  106. package/dist/core/device/hdc/input.js +0 -74
  107. package/dist/core/device/hdc/screenshot.js +0 -171
  108. package/dist/core/device/index.js +0 -70
  109. package/dist/core/device/types.js +0 -2
  110. package/dist/core/knowledge/knowledge_manager.js +0 -70
  111. package/dist/core/knowledge/vectordb.js +0 -283
  112. package/dist/core/mcp/adapter_factory.js +0 -99
  113. package/dist/core/mcp/android_adapter.js +0 -286
  114. package/dist/core/mcp/base_adapter.js +0 -86
  115. package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
  116. package/dist/core/mcp/ios_adapter.js +0 -286
  117. package/dist/core/mcp/local_tools.js +0 -41
  118. package/dist/core/mcp/mcp_tools.js +0 -473
  119. package/dist/core/mcp/types.js +0 -6
  120. package/dist/core/memory/_utils.js +0 -140
  121. package/dist/core/memory/compressed_session.js +0 -182
  122. package/dist/core/memory/context_compressor.js +0 -176
  123. package/dist/core/memory/index.js +0 -22
  124. package/dist/core/memory/memory_manager.js +0 -28
  125. package/dist/core/memory/reflector.js +0 -95
  126. package/dist/core/memory/replan_manager.js +0 -12
  127. package/dist/core/memory/session_factory.js +0 -29
  128. package/dist/core/memory/tool_player.js +0 -225
  129. package/dist/core/memory/tool_player_popup.js +0 -276
  130. package/dist/core/memory/tool_player_replan.js +0 -226
  131. package/dist/core/memory/tool_player_xpath.js +0 -139
  132. package/dist/core/memory/tool_recorder.js +0 -126
  133. package/dist/core/preprocessor/task_splitter.js +0 -112
  134. package/dist/core/prompt/prompt_loader.js +0 -315
  135. package/dist/core/skill/skill_manager.js +0 -302
  136. package/dist/data_types/action.js +0 -2
  137. package/dist/data_types/agent.js +0 -2
  138. package/dist/data_types/case.js +0 -57
  139. package/dist/data_types/device.js +0 -2
  140. package/dist/data_types/index.js +0 -11
  141. package/dist/data_types/report.js +0 -6
  142. package/dist/data_types/screen.js +0 -23
  143. package/dist/data_types/task.js +0 -2
  144. package/dist/loop/cli.js +0 -127
  145. package/dist/loop/orchestrator.js +0 -314
  146. package/dist/loop/result_writer.js +0 -260
  147. package/dist/loop/types.js +0 -82
  148. package/dist/mcp-server/server.js +0 -341
  149. package/dist/mcp-server/types.js +0 -224
  150. package/dist/reporter/batch_summary.js +0 -197
  151. package/dist/reporter/generator.js +0 -286
  152. package/dist/reporter/html_template/index.js +0 -529
  153. package/dist/reporter/json_report.js +0 -6
  154. package/dist/reporter/types.js +0 -45
  155. package/dist/tools/case_runner/report.js +0 -264
@@ -1,375 +0,0 @@
1
- "use strict";
2
- // LLM text output -> RootCauseResult parser.
3
- // Extracts structured data from the LLM's raw Markdown text and maps it to RootCauseResult.
4
- // Supports Markdown format (## sections + key-value + tables + bullet lists).
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseMarkdownToDict = parseMarkdownToDict;
7
- exports.parseRootCauseResult = parseRootCauseResult;
8
- const logger_1 = require("../../../common/logger");
9
- const types_1 = require("./types");
10
- // ---- Markdown parsing ----
11
- // Confidence text -> float value mapping
12
- const CONFIDENCE_TEXT_TO_FLOAT = {
13
- High: 0.85, '高': 0.85,
14
- Medium: 0.6, '中': 0.6,
15
- Low: 0.3, '低': 0.3,
16
- };
17
- // Verdict section key-value map: Markdown key -> RootCauseResult field
18
- const VERDICT_KEY_MAP = {
19
- Accuracy: 'accuracy', '判定准确度': 'accuracy', '准确性': 'accuracy',
20
- 'Primary Cause': 'rootCauseCategory', '一级根因': 'rootCauseCategory',
21
- 'Secondary Cause': 'rootCauseSubCategory', '二级根因': 'rootCauseSubCategory',
22
- 'Root Cause': 'rootCauseReason', '根本原因': 'rootCauseReason',
23
- Confidence: 'confidence', '置信度': 'confidence',
24
- };
25
- // Parse a Markdown-formatted text into a dict (aligned with main_agent.md output format).
26
- // Splits by level-2 headings (##), extracts each section and maps to fields.
27
- // New format section names take priority; legacy names are fallback-compatible.
28
- function parseMarkdownToDict(text) {
29
- if (!text || !text.trim())
30
- return null;
31
- // Split by ## sections (skip content before the first ##)
32
- const sections = {};
33
- const parts = text.split(/^## /m);
34
- for (let i = 1; i < parts.length; i++) {
35
- const part = parts[i];
36
- const lines = part.split('\n');
37
- const heading = lines[0].trim();
38
- const body = lines.slice(1).join('\n').trim();
39
- sections[heading] = body;
40
- }
41
- // Must have a "Verdict" section (兼容 "判定结果"/"判定" 标题)
42
- const verdictText = sections['Verdict'] ?? sections['Verdict Result'] ?? sections['判定结果'] ?? sections['判定'] ?? '';
43
- if (!verdictText) {
44
- logger_1.logger.debug("[parseMarkdown] no 'Verdict' section, not a Markdown format");
45
- return null;
46
- }
47
- const result = {};
48
- // Parse verdict section: key-value pairs (- key: value format)
49
- for (const line of verdictText.split('\n')) {
50
- const trimmed = line.trim();
51
- if (trimmed.startsWith('- ')) {
52
- const m = trimmed.match(/^-\s*(.+?):\s*(.+)/);
53
- if (m) {
54
- const mdKey = m[1].trim();
55
- const mdVal = m[2].trim();
56
- const fieldName = VERDICT_KEY_MAP[mdKey];
57
- if (fieldName) {
58
- result[fieldName] = mdVal;
59
- }
60
- }
61
- }
62
- }
63
- // Must have accuracy field, otherwise not a valid Markdown output
64
- if (!('accuracy' in result)) {
65
- logger_1.logger.debug("[parseMarkdown] verdict section missing 'Accuracy' field");
66
- return null;
67
- }
68
- // Normalize primary cause -> English label
69
- if ('rootCauseCategory' in result) {
70
- result['rootCauseCategory'] = normalizeCategory(result['rootCauseCategory']);
71
- }
72
- // Normalize secondary cause -> canonical name
73
- if ('rootCauseSubCategory' in result) {
74
- const subText = result['rootCauseSubCategory'];
75
- const catLabel = result['rootCauseCategory'] ?? '';
76
- result['rootCauseSubCategory'] = (0, types_1.resolveSubCategory)(subText, catLabel);
77
- }
78
- // Convert confidence text -> float
79
- if ('confidence' in result) {
80
- const confText = result['confidence'].trim();
81
- result['confidence'] = CONFIDENCE_TEXT_TO_FLOAT[confText] ?? 0.5;
82
- }
83
- // Parse task intent section (new format: standalone section; legacy: key-value in verdict)
84
- const taskIntentSection = (sections['Task Intent'] ?? sections['任务意图'] ?? '').trim();
85
- // Parse analysis summary section (new name "Analysis Summary", legacy "Analysis Reasoning", Chinese "分析摘要")
86
- const summaryText = sections['Analysis Summary'] || sections['Analysis Reasoning'] || sections['分析摘要'] || sections['分析推理'] || '';
87
- // Parse checkpoints section: markdown table -> checkpoints standalone field
88
- const checkpointsText = sections['Checkpoints'] ?? sections['检查点'] ?? '';
89
- // Parse evidence list section (new name "Evidence List", legacy "Facts", Chinese "证据列表"/"事实")
90
- const evidenceSection = sections['Evidence List'] || sections['Facts'] || sections['证据列表'] || sections['事实'] || '';
91
- // Parse missing evidence section (Chinese "缺失证据")
92
- const missingEvidenceSection = sections['Missing Evidence'] ?? sections['缺失证据'] ?? '';
93
- // Parse problem list section (Chinese "问题列表")
94
- const problemListSection = sections['Problem List'] ?? sections['问题列表'] ?? '';
95
- // Parse improvement suggestions section (Chinese "改进建议")
96
- const improvementSection = sections['Improvement Suggestions'] ?? sections['改进建议'] ?? '';
97
- // Parse reverse verification section (Chinese "反向验证")
98
- const reverseVerificationSection = sections['Reverse Verification'] ?? sections['反向验证'] ?? '';
99
- // Parse checkpoints: markdown table -> checkpoints standalone field
100
- const checkpointsParsed = parseCheckpointTable(checkpointsText);
101
- result['checkpoints'] = checkpointsParsed;
102
- // Parse evidence list
103
- result['evidence'] = parseBulletList(evidenceSection);
104
- // Append checkpoint mismatch info to evidence
105
- for (const cp of checkpointsParsed) {
106
- if (!cp['matched']) {
107
- result['evidence'] = [
108
- ...result['evidence'],
109
- `Checkpoint '${cp['check']}' does not match actual '${cp['actual_observed']}'`,
110
- ];
111
- }
112
- }
113
- // Parse missing evidence section (legacy compat): bullet list
114
- const missingEvidence = parseBulletList(missingEvidenceSection);
115
- if (missingEvidence.length > 0 && !(missingEvidence.length === 1 && missingEvidence[0] === 'None')) {
116
- result['evidence'] = [...result['evidence'], ...missingEvidence];
117
- }
118
- // Parse problem list section — extract "Problem N: ..." format entries
119
- const problemsSection = sections['Problem List'] ?? sections['Problems'] ?? '';
120
- result['problems'] = parseProblemList(problemListSection || (sections['Problems'] ?? ''));
121
- // Parse improvement suggestions section + reverse verification
122
- const tips = improvementSection.trim();
123
- if (tips === 'None' || tips === '(None)' || tips === '') {
124
- result['improvementSuggestions'] = [];
125
- result['reverseVerification'] = '';
126
- }
127
- else {
128
- let reverseVerification = '';
129
- const suggestionsLines = [];
130
- for (const rawLine of tips.split('\n')) {
131
- const line = rawLine.trim();
132
- if (line.toLowerCase().includes('reverse verification')) {
133
- // Strip numbering prefix, extract reverse verification content
134
- const m = line.match(/^\d+\.\s*reverse\s*verification\s*[::]\s*(.+)/i);
135
- if (m) {
136
- reverseVerification = m[1].trim();
137
- }
138
- else {
139
- const m2 = line.match(/^reverse\s*verification\s*[::]\s*(.+)/i);
140
- if (m2) {
141
- reverseVerification = m2[1].trim();
142
- }
143
- else {
144
- reverseVerification = line;
145
- }
146
- }
147
- }
148
- else if (line.startsWith('- ')) {
149
- suggestionsLines.push(line.slice(2).trim());
150
- }
151
- else if (line && !line.startsWith('|')) {
152
- // Numbered suggestion (e.g. "1. suggestion content")
153
- const m = line.match(/^\d+\.\s*(.+)/);
154
- if (m) {
155
- suggestionsLines.push(m[1].trim());
156
- }
157
- else {
158
- suggestionsLines.push(line);
159
- }
160
- }
161
- }
162
- result['improvementSuggestions'] = suggestionsLines;
163
- result['reverseVerification'] = reverseVerification;
164
- }
165
- // Fill defaults required by RootCauseResult
166
- if (!('taskIntent' in result))
167
- result['taskIntent'] = '';
168
- if (!('checkpoints' in result))
169
- result['checkpoints'] = [];
170
- if (!('reverseVerification' in result))
171
- result['reverseVerification'] = '';
172
- return result;
173
- }
174
- // Parse a bullet list from markdown text. 'None' -> [].
175
- function parseBulletList(text) {
176
- const trimmed = text.trim();
177
- if (!trimmed || trimmed === 'None' || trimmed === '(None)')
178
- return [];
179
- const items = [];
180
- for (const rawLine of trimmed.split('\n')) {
181
- const line = rawLine.trim();
182
- if (line.startsWith('- ')) {
183
- items.push(line.slice(2).trim());
184
- }
185
- else if (line && !line.startsWith('|')) {
186
- items.push(line);
187
- }
188
- }
189
- return items;
190
- }
191
- // Parse problem list from markdown ("Problem N: ..." format).
192
- function parseProblemList(text) {
193
- const trimmed = text.trim();
194
- if (!trimmed || trimmed === 'None' || trimmed === '(None)')
195
- return [];
196
- const problems = [];
197
- for (const rawLine of trimmed.split('\n')) {
198
- const line = rawLine.trim();
199
- const m = line.match(/(?:Problem|问题)\s*\d+\s*[::]\s*(.+)/i);
200
- if (m) {
201
- problems.push(m[1].trim());
202
- }
203
- }
204
- return problems;
205
- }
206
- // Parse a checkpoint table from markdown.
207
- // Table format: | Checkpoint | Actual Observed | Matched |
208
- function parseCheckpointTable(text) {
209
- const result = [];
210
- const lines = text.trim().split('\n');
211
- for (const rawLine of lines) {
212
- const line = rawLine.trim();
213
- if (!line.startsWith('|') || line.includes('---'))
214
- continue;
215
- // Skip header (contains "Checkpoint" and "Actual")
216
- if (line.toLowerCase().includes('checkpoint') && line.toLowerCase().includes('actual'))
217
- continue;
218
- const cells = line.split('|').slice(1, -1).map((c) => c.trim());
219
- if (cells.length >= 3) {
220
- const matchedRaw = cells[2].trim();
221
- const matched = ['yes', 'true', 'true', String.fromCharCode(10003), String.fromCharCode(8730)].includes(matchedRaw.toLowerCase());
222
- result.push({
223
- check: cells[0],
224
- actual_observed: cells[1],
225
- matched,
226
- });
227
- }
228
- }
229
- return result;
230
- }
231
- // Normalize a category identifier to an English label.
232
- // Direct English label lookup + fuzzy alias match.
233
- const _CATEGORY_CN_TO_EN = {
234
- '应用问题': 'Application Issue',
235
- 'Agent问题': 'Agent Issue',
236
- '用例问题': 'Test Case Issue',
237
- '环境问题': 'Environment Issue',
238
- '无问题': 'No Issue',
239
- };
240
- function normalizeCategory(code) {
241
- if (!code)
242
- return code;
243
- if (_CATEGORY_CN_TO_EN[code]) {
244
- return _CATEGORY_CN_TO_EN[code];
245
- }
246
- const validLabels = new Set([
247
- 'Application Issue',
248
- 'Agent Issue',
249
- 'Test Case Issue',
250
- 'Environment Issue',
251
- 'No Issue',
252
- ]);
253
- if (validLabels.has(code)) {
254
- return code;
255
- }
256
- // Fuzzy alias match
257
- for (const label of validLabels) {
258
- if (code.includes(label) || label.includes(code)) {
259
- return label;
260
- }
261
- }
262
- for (const cn of Object.keys(_CATEGORY_CN_TO_EN)) {
263
- if (code.includes(cn)) {
264
- return _CATEGORY_CN_TO_EN[cn];
265
- }
266
- }
267
- // Unmappable, return original (guardrail will validate)
268
- return code;
269
- }
270
- // Parse a RootCauseResult from the LLM Markdown text.
271
- // Only supports Markdown format (## sections + key-value + tables + bullet lists).
272
- function parseRootCauseResult(text) {
273
- if (!text || !text.trim())
274
- return null;
275
- const mdDict = parseMarkdownToDict(text);
276
- if (mdDict !== null) {
277
- logger_1.logger.info('[parse] Markdown format parsed successfully');
278
- return mapDictToRootCauseResult(mdDict);
279
- }
280
- logger_1.logger.warn('[parse] Markdown parsing failed');
281
- return null;
282
- }
283
- // Field name aliases (LLM may use different key names)
284
- const FIELD_ALIASES = {
285
- rootCauseCategory: ['rootCauseCategory', 'category', 'root_cause_category', 'rootCauseCategory'],
286
- rootCauseSubCategory: [
287
- 'rootCauseSubCategory',
288
- 'subCategory',
289
- 'root_cause_sub_category',
290
- 'sub_category',
291
- ],
292
- rootCauseReason: ['rootCauseReason', 'reason', 'root_cause_reason', 'root_cause'],
293
- confidence: ['confidence'],
294
- accuracy: ['accuracy', 'Accuracy', 'AccuracyVerdict'],
295
- evidence: ['evidence', 'facts', 'Evidence List'],
296
- checkpoints: ['checkpoints', 'Checkpoints'],
297
- summary: ['summary', 'reasoning', 'Analysis Reasoning', 'Analysis Summary'],
298
- improvementSuggestions: [
299
- 'improvementSuggestions',
300
- 'suggestions',
301
- 'improvement_suggestions',
302
- 'tips',
303
- 'Improvement Suggestions',
304
- ],
305
- reverseVerification: ['reverseVerification', 'reverse_verification', 'Reverse Verification'],
306
- taskIntent: ['taskIntent', 'task_intent', 'Task Intent'],
307
- problems: ['problems', 'Problem List', 'Problems'],
308
- };
309
- // Look up a field value from the raw dict, trying multiple aliases.
310
- function resolveField(raw, fieldName, defaultValue = null) {
311
- const aliases = FIELD_ALIASES[fieldName] ?? [fieldName];
312
- for (const alias of aliases) {
313
- if (alias in raw) {
314
- return raw[alias];
315
- }
316
- }
317
- return defaultValue;
318
- }
319
- // Map a dict (from Markdown parsing) to a RootCauseResult.
320
- // Type-tolerant: confidence allows int/float/text; evidence/suggestions allow str->list[str].
321
- function mapDictToRootCauseResult(raw) {
322
- // category normalization (Markdown parse already produced English; re-normalize as fallback)
323
- const rawCategory = String(resolveField(raw, 'rootCauseCategory', ''));
324
- const normalizedCategory = normalizeCategory(rawCategory);
325
- // sub_category normalization
326
- const rawSub = String(resolveField(raw, 'rootCauseSubCategory', ''));
327
- const normalizedSub = (0, types_1.resolveSubCategory)(rawSub, normalizedCategory);
328
- // confidence type fix: support text/int/float
329
- let confidence = resolveField(raw, 'confidence', 0.5);
330
- if (typeof confidence === 'string') {
331
- confidence = CONFIDENCE_TEXT_TO_FLOAT[confidence.trim()] ?? 0.5;
332
- }
333
- else if (typeof confidence === 'number') {
334
- confidence = Number(confidence);
335
- }
336
- if (typeof confidence !== 'number' || Number.isNaN(confidence)) {
337
- confidence = 0.5;
338
- }
339
- // evidence type fix: str -> list[str]
340
- let evidence = resolveField(raw, 'evidence', []);
341
- if (typeof evidence === 'string') {
342
- evidence = [evidence];
343
- }
344
- // checkpoints type fix: str -> list[dict]
345
- let checkpoints = resolveField(raw, 'checkpoints', []);
346
- if (typeof checkpoints === 'string') {
347
- checkpoints = [{ check: checkpoints }];
348
- }
349
- // improvement_suggestions type fix
350
- let suggestions = resolveField(raw, 'improvementSuggestions', []);
351
- if (typeof suggestions === 'string') {
352
- suggestions = [suggestions];
353
- }
354
- // problems type fix: str -> list[str]
355
- let problems = resolveField(raw, 'problems', []);
356
- if (typeof problems === 'string') {
357
- problems = [problems];
358
- }
359
- const reverseVerification = String(resolveField(raw, 'reverseVerification', ''));
360
- const accuracy = String(resolveField(raw, 'accuracy', ''));
361
- return (0, types_1.createRootCauseResult)({
362
- rootCauseCategory: normalizedCategory,
363
- rootCauseSubCategory: normalizedSub,
364
- rootCauseReason: String(resolveField(raw, 'rootCauseReason', '')),
365
- confidence: confidence,
366
- accuracy,
367
- evidence: evidence,
368
- checkpoints: checkpoints,
369
- summary: String(resolveField(raw, 'summary', '')),
370
- taskIntent: String(resolveField(raw, 'taskIntent', '')),
371
- improvementSuggestions: suggestions,
372
- reverseVerification,
373
- problems: problems,
374
- });
375
- }