Add data source ids to copilot request

This commit is contained in:
akhisud3195 2025-05-12 20:40:02 +05:30
parent 9c712250fb
commit 462a2fb651
5 changed files with 70 additions and 13 deletions

View file

@ -38,7 +38,24 @@ export async function getCopilotResponse(
workflow_schema: JSON.stringify(zodToJsonSchema(CopilotWorkflow)),
current_workflow_config: JSON.stringify(convertToCopilotWorkflow(current_workflow_config)),
context: context ? convertToCopilotApiChatContext(context) : null,
dataSources: dataSources ? dataSources.map(ds => CopilotDataSource.parse(ds)) : undefined,
dataSources: dataSources ? dataSources.map(ds => {
console.log('Original data source:', JSON.stringify(ds));
// First parse to validate, then ensure _id is included
CopilotDataSource.parse(ds); // validate but don't use the result
// Cast to any to handle the WithStringId type
const withId = ds as any;
const result = {
_id: withId._id,
name: withId.name,
description: withId.description,
active: withId.active,
status: withId.status,
error: withId.error,
data: withId.data
};
console.log('Processed data source:', JSON.stringify(result));
return result;
}) : undefined,
};
console.log(`sending copilot request`, JSON.stringify(request));

View file

@ -6,14 +6,33 @@ import { convertToAgenticAPIChatMessages } from "./agents_api_types";
import { DataSource } from "./datasource_types";
// Create a filtered version of DataSource for copilot
export const CopilotDataSource = DataSource.omit({
projectId: true,
version: true,
attempts: true,
createdAt: true,
lastUpdatedAt: true,
pendingRefresh: true,
});
export const CopilotDataSource = z.object({
_id: z.string(),
name: z.string(),
description: z.string().optional(),
active: z.boolean().default(true),
status: z.union([
z.literal('pending'),
z.literal('ready'),
z.literal('error'),
z.literal('deleted'),
]),
error: z.string().optional(),
data: z.discriminatedUnion('type', [
z.object({
type: z.literal('urls'),
}),
z.object({
type: z.literal('files_local'),
}),
z.object({
type: z.literal('files_s3'),
}),
z.object({
type: z.literal('text'),
})
]),
}).passthrough();
export const CopilotWorkflow = Workflow.omit({
lastUpdatedAt: true,