parse relevant datasource fields in copilot

This commit is contained in:
Ramnique Singh 2025-08-17 10:28:21 +05:30
parent 4b33b20e76
commit 3755e76474
3 changed files with 13 additions and 7 deletions

View file

@ -2,10 +2,10 @@
import {
CopilotAPIRequest,
CopilotChatContext, CopilotMessage,
DataSourceSchemaForCopilot,
} from "../lib/types/copilot_types";
import {
Workflow} from "../lib/types/workflow_types";
import { DataSource } from "@/src/entities/models/data-source";
import { z } from 'zod';
import { projectAuthCheck } from "./project.actions";
import { redisClient } from "../lib/redis";
@ -23,7 +23,7 @@ export async function getCopilotResponseStream(
messages: z.infer<typeof CopilotMessage>[],
current_workflow_config: z.infer<typeof Workflow>,
context: z.infer<typeof CopilotChatContext> | null,
dataSources?: z.infer<typeof DataSource>[]
dataSources?: z.infer<typeof DataSourceSchemaForCopilot>[]
): Promise<{
streamId: string;
} | { billingError: string }> {

View file

@ -2,8 +2,7 @@ import z from "zod";
import { createOpenAI } from "@ai-sdk/openai";
import { generateObject, streamText, tool } from "ai";
import { Workflow, WorkflowTool } from "../types/workflow_types";
import { CopilotChatContext, CopilotMessage } from "../types/copilot_types";
import { DataSource } from "@/src/entities/models/data-source";
import { CopilotChatContext, CopilotMessage, DataSourceSchemaForCopilot } from "../types/copilot_types";
import { PrefixLogger } from "../utils";
import zodToJsonSchema from "zod-to-json-schema";
import { COPILOT_INSTRUCTIONS_EDIT_AGENT } from "./copilot_edit_agent";
@ -101,7 +100,7 @@ ${JSON.stringify(workflow)}
`;
}
function getDataSourcesPrompt(dataSources: z.infer<typeof DataSource>[]): string {
function getDataSourcesPrompt(dataSources: z.infer<typeof DataSourceSchemaForCopilot>[]): string {
let prompt = '';
if (dataSources.length > 0) {
const simplifiedDataSources = dataSources.map(ds => ({
@ -273,7 +272,7 @@ export async function* streamMultiAgentResponse(
context: z.infer<typeof CopilotChatContext> | null,
messages: z.infer<typeof CopilotMessage>[],
workflow: z.infer<typeof Workflow>,
dataSources: z.infer<typeof DataSource>[]
dataSources: z.infer<typeof DataSourceSchemaForCopilot>[]
): AsyncIterable<z.infer<typeof ZEvent>> {
const logger = new PrefixLogger('copilot /stream');
logger.log('context', context);

View file

@ -3,6 +3,13 @@ import { Workflow } from "./workflow_types";
import { Message } from "./types";
import { DataSource } from "@/src/entities/models/data-source";
export const DataSourceSchemaForCopilot = DataSource.pick({
id: true,
name: true,
description: true,
data: true,
});
export const CopilotUserMessage = z.object({
role: z.literal('user'),
content: z.string(),
@ -52,7 +59,7 @@ export const CopilotAPIRequest = z.object({
messages: z.array(CopilotMessage),
workflow: Workflow,
context: CopilotChatContext.nullable(),
dataSources: z.array(DataSource).optional(),
dataSources: z.array(DataSourceSchemaForCopilot).optional(),
});
export const CopilotAPIResponse = z.union([
z.object({