mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-13 17:22:37 +02:00
discard invalid copilot fields
This commit is contained in:
parent
c08b82b6ad
commit
4b404a2daa
1 changed files with 36 additions and 14 deletions
|
|
@ -523,7 +523,6 @@ export async function getCopilotResponse(
|
||||||
content: json.response.replace(/^```json\n/, '').replace(/\n```$/, ''),
|
content: json.response.replace(/^```json\n/, '').replace(/\n```$/, ''),
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
// validate response schema
|
// validate response schema
|
||||||
assert(msg.role === 'assistant');
|
assert(msg.role === 'assistant');
|
||||||
if (msg.role === 'assistant') {
|
if (msg.role === 'assistant') {
|
||||||
|
|
@ -534,11 +533,19 @@ export async function getCopilotResponse(
|
||||||
const test = {
|
const test = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
description: 'test',
|
description: 'test',
|
||||||
...part.content.config_changes,
|
|
||||||
} as z.infer<typeof WorkflowTool>;
|
} as z.infer<typeof WorkflowTool>;
|
||||||
const result = WorkflowTool.safeParse(test);
|
// iterate over each field in part.content.config_changes
|
||||||
if (!result.success) {
|
// and test if the final object schema is valid
|
||||||
part.content.error = result.error.message;
|
// if not, discard that field
|
||||||
|
for (const [key, value] of Object.entries(part.content.config_changes)) {
|
||||||
|
const result = WorkflowTool.safeParse({
|
||||||
|
...test,
|
||||||
|
[key]: value,
|
||||||
|
});
|
||||||
|
if (!result.success) {
|
||||||
|
console.log(`discarding field ${key} from ${part.content.config_type}: ${part.content.name}`, result.error.message);
|
||||||
|
delete part.content.config_changes[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -555,11 +562,19 @@ export async function getCopilotResponse(
|
||||||
ragK: 10,
|
ragK: 10,
|
||||||
connectedAgents: [],
|
connectedAgents: [],
|
||||||
controlType: 'retain',
|
controlType: 'retain',
|
||||||
...part.content.config_changes,
|
|
||||||
} as z.infer<typeof WorkflowAgent>;
|
} as z.infer<typeof WorkflowAgent>;
|
||||||
const result = WorkflowAgent.safeParse(test);
|
// iterate over each field in part.content.config_changes
|
||||||
if (!result.success) {
|
// and test if the final object schema is valid
|
||||||
part.content.error = result.error.message;
|
// if not, discard that field
|
||||||
|
for (const [key, value] of Object.entries(part.content.config_changes)) {
|
||||||
|
const result = WorkflowAgent.safeParse({
|
||||||
|
...test,
|
||||||
|
[key]: value,
|
||||||
|
});
|
||||||
|
if (!result.success) {
|
||||||
|
console.log(`discarding field ${key} from ${part.content.config_type}: ${part.content.name}`, result.error.message);
|
||||||
|
delete part.content.config_changes[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -568,11 +583,19 @@ export async function getCopilotResponse(
|
||||||
name: 'test',
|
name: 'test',
|
||||||
type: 'base_prompt',
|
type: 'base_prompt',
|
||||||
prompt: "test",
|
prompt: "test",
|
||||||
...part.content.config_changes,
|
|
||||||
} as z.infer<typeof WorkflowPrompt>;
|
} as z.infer<typeof WorkflowPrompt>;
|
||||||
const result = WorkflowPrompt.safeParse(test);
|
// iterate over each field in part.content.config_changes
|
||||||
if (!result.success) {
|
// and test if the final object schema is valid
|
||||||
part.content.error = result.error.message;
|
// if not, discard that field
|
||||||
|
for (const [key, value] of Object.entries(part.content.config_changes)) {
|
||||||
|
const result = WorkflowPrompt.safeParse({
|
||||||
|
...test,
|
||||||
|
[key]: value,
|
||||||
|
});
|
||||||
|
if (!result.success) {
|
||||||
|
console.log(`discarding field ${key} from ${part.content.config_type}: ${part.content.name}`, result.error.message);
|
||||||
|
delete part.content.config_changes[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -584,7 +607,6 @@ export async function getCopilotResponse(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: msg as z.infer<typeof CopilotAssistantMessage>,
|
message: msg as z.infer<typeof CopilotAssistantMessage>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue