(source)
| 17 | } |
| 18 | |
| 19 | function normalizeIssueIntentMetadata(source) { |
| 20 | if (!source || typeof source !== "object") { |
| 21 | return {}; |
| 22 | } |
| 23 | |
| 24 | /** @type {{ rationale?: string, confidence?: "LOW"|"MEDIUM"|"HIGH", suggest?: boolean }} */ |
| 25 | const metadata = {}; |
| 26 | |
| 27 | if (typeof source.rationale === "string") { |
| 28 | const sanitizedRationale = sanitizeContent(source.rationale, { maxLength: ISSUE_INTENT_RATIONALE_MAX_LENGTH }).trim(); |
| 29 | // sanitizeContent appends "\n[Content truncated due to length]" when it truncates, |
| 30 | // so clamp again to guarantee the GitHub API hard limit. |
| 31 | const rationale = sanitizedRationale.length > ISSUE_INTENT_RATIONALE_MAX_LENGTH ? sanitizedRationale.slice(0, ISSUE_INTENT_RATIONALE_MAX_LENGTH) : sanitizedRationale; |
| 32 | if (rationale) { |
| 33 | metadata.rationale = rationale; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if (source.confidence !== undefined && source.confidence !== null && source.confidence !== "") { |
| 38 | const confidenceRaw = String(source.confidence).trim().toUpperCase(); |
| 39 | /** @type {"LOW"|"MEDIUM"|"HIGH"} */ |
| 40 | let confidence; |
| 41 | switch (confidenceRaw) { |
| 42 | case "LOW": |
| 43 | confidence = "LOW"; |
| 44 | break; |
| 45 | case "MEDIUM": |
| 46 | confidence = "MEDIUM"; |
| 47 | break; |
| 48 | case "HIGH": |
| 49 | confidence = "HIGH"; |
| 50 | break; |
| 51 | default: |
| 52 | throw new Error(`Invalid confidence ${JSON.stringify(source.confidence)}. Expected one of: LOW, MEDIUM, HIGH.`); |
| 53 | } |
| 54 | metadata.confidence = confidence; |
| 55 | } |
| 56 | |
| 57 | if (source.suggest !== undefined) { |
| 58 | if (typeof source.suggest !== "boolean") { |
| 59 | throw new Error(`Invalid suggest ${JSON.stringify(source.suggest)}. Expected a boolean value.`); |
| 60 | } |
| 61 | if (source.suggest) { |
| 62 | metadata.suggest = true; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return metadata; |
| 67 | } |
| 68 | |
| 69 | function normalizeIssueIntentLabelSpecs(labels) { |
| 70 | if (labels === undefined) { |
no test coverage detected