( issueTitle: string, issueBody: string, labelTaxonomy: LabelTaxonomy )
| 173 | * Classify an issue using AWS Bedrock Claude Sonnet 4 with input validation |
| 174 | */ |
| 175 | export async function classifyIssue( |
| 176 | issueTitle: string, |
| 177 | issueBody: string, |
| 178 | labelTaxonomy: LabelTaxonomy |
| 179 | ): Promise<ClassificationResult> { |
| 180 | // Validate input lengths |
| 181 | if (issueTitle.length > MAX_TITLE_LENGTH) { |
| 182 | console.warn( |
| 183 | `Title length (${issueTitle.length}) exceeds maximum (${MAX_TITLE_LENGTH}), will be truncated` |
| 184 | ); |
| 185 | } |
| 186 | |
| 187 | if (issueBody.length > MAX_BODY_LENGTH) { |
| 188 | console.warn( |
| 189 | `Body length (${issueBody.length}) exceeds maximum (${MAX_BODY_LENGTH}), will be truncated` |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | const client = createBedrockClient(); |
| 194 | const prompt = buildClassificationPrompt( |
| 195 | issueTitle, |
| 196 | issueBody, |
| 197 | labelTaxonomy.toDict() |
| 198 | ); |
| 199 | |
| 200 | try { |
| 201 | // Use retry logic with exponential backoff |
| 202 | const responseBody = await retryWithBackoff(async () => { |
| 203 | const command = new InvokeModelCommand({ |
| 204 | modelId: MODEL_ID, |
| 205 | contentType: "application/json", |
| 206 | accept: "application/json", |
| 207 | body: JSON.stringify({ |
| 208 | anthropic_version: "bedrock-2023-05-31", |
| 209 | max_tokens: MAX_TOKENS, |
| 210 | temperature: TEMPERATURE, |
| 211 | messages: [ |
| 212 | { |
| 213 | role: "user", |
| 214 | content: prompt, |
| 215 | }, |
| 216 | ], |
| 217 | }), |
| 218 | }); |
| 219 | |
| 220 | const response = await client.send(command); |
| 221 | return new TextDecoder().decode(response.body); |
| 222 | }); |
| 223 | |
| 224 | return parseBedrockResponse(responseBody); |
| 225 | } catch (error) { |
| 226 | console.error("Error calling Bedrock API after retries:", error); |
| 227 | return { |
| 228 | recommended_labels: [], |
| 229 | confidence_scores: {}, |
| 230 | reasoning: "", |
| 231 | error: `Bedrock API error after retries: ${error}`, |
| 232 | }; |
no test coverage detected