mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
feat: enhance chat functionality with flowchart tools integration and improved UI interactions
This commit is contained in:
@@ -1,13 +1,40 @@
|
||||
import { google } from "@ai-sdk/google";
|
||||
import { Message } from "ai/react";
|
||||
import { streamText } from "ai";
|
||||
|
||||
import { z } from "zod";
|
||||
export const maxDuration = 30;
|
||||
|
||||
// Define tool interfaces
|
||||
interface DisplayFlowChartArgs {
|
||||
xml: string;
|
||||
}
|
||||
|
||||
interface ToolContext {
|
||||
getCurrentXML: () => string;
|
||||
displayChart: (xml: string) => void;
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const { messages } = await req.json();
|
||||
const result = streamText({
|
||||
const response = streamText({
|
||||
model: google("gemini-2.0-flash"),
|
||||
messages,
|
||||
tools: {
|
||||
display_flow_chart: {
|
||||
description: "Display a flowchart on draw.io",
|
||||
parameters: z.object(
|
||||
{
|
||||
xml: z.string().describe("XML string to be displayed on draw.io"),
|
||||
},
|
||||
)
|
||||
},
|
||||
fetch_flow_chart: {
|
||||
description: "Get the current flowchart XML from draw.io",
|
||||
parameters: z.object({}),
|
||||
}
|
||||
},
|
||||
temperature: 0,
|
||||
});
|
||||
return result.toDataStreamResponse();
|
||||
}
|
||||
|
||||
return response.toDataStreamResponse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user