Use streaming in Copilot

This commit is contained in:
Ramnique Singh 2025-04-15 00:56:15 +05:30
parent ba14bc9bd8
commit 49ca5a7154
19 changed files with 1303 additions and 839 deletions

View file

@ -1,6 +1,73 @@
import { WorkflowTool, WorkflowAgent, WorkflowPrompt } from "./types/workflow_types";
import { z } from "zod";
export class QueryLimitError extends Error {
constructor(message: string = 'Query limit exceeded') {
super(message);
this.name = 'QueryLimitError';
}
}
}
export function validateConfigChanges(configType: string, configChanges: Record<string, unknown>, name: string) {
let testObject: any;
let schema: z.ZodType<any>;
switch (configType) {
case 'tool': {
testObject = {
name: 'test',
description: 'test',
parameters: {
type: 'object',
properties: {},
required: [],
},
} as z.infer<typeof WorkflowTool>;
schema = WorkflowTool;
break;
}
case 'agent': {
testObject = {
name: 'test',
description: 'test',
type: 'conversation',
instructions: 'test',
prompts: [],
tools: [],
model: 'gpt-4o',
ragReturnType: 'chunks',
ragK: 10,
connectedAgents: [],
controlType: 'retain',
} as z.infer<typeof WorkflowAgent>;
schema = WorkflowAgent;
break;
}
case 'prompt': {
testObject = {
name: 'test',
type: 'base_prompt',
prompt: "test",
} as z.infer<typeof WorkflowPrompt>;
schema = WorkflowPrompt;
break;
}
default:
return { error: `Unknown config type: ${configType}` };
}
// Validate each field and remove invalid ones
const validatedChanges = { ...configChanges };
for (const [key, value] of Object.entries(configChanges)) {
const result = schema.safeParse({
...testObject,
[key]: value,
});
if (!result.success) {
console.log(`discarding field ${key} from ${configType}: ${name}`, result.error.message);
delete validatedChanges[key];
}
}
return { changes: validatedChanges };
}