copilot: fixed response

This commit is contained in:
arkml 2025-02-21 16:45:22 +05:30
parent a7975ff4ff
commit be3eb610a0
2 changed files with 7 additions and 2 deletions

View file

@ -480,7 +480,7 @@ You are responsible for providing delivery information to the user.
output format:
```json
{
"response": "<new agent instructions with relevant changes>"
"agent_instructions": "<new agent instructions with relevant changes>"
}
```
"""

View file

@ -200,10 +200,15 @@ export async function getCopilotAgentInstructions(
// parse and return response
const json = await response.json();
console.log(`copilot response`, JSON.stringify(json, null, 2));
let copilotResponse: z.infer<typeof CopilotAPIResponse>;
let agent_instructions: string;
try {
copilotResponse = CopilotAPIResponse.parse(json);
const content = json.response.replace(/^```json\n/, '').replace(/\n```$/, '');
agent_instructions = JSON.parse(content).agent_instructions;
} catch (e) {
console.error('Failed to parse copilot response', e);
throw new Error(`Failed to parse copilot response: ${e}`);
@ -213,5 +218,5 @@ export async function getCopilotAgentInstructions(
}
// return response
return copilotResponse.response;
return agent_instructions;
}