forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha2ui_fixed_schema.ts
More file actions
56 lines (52 loc) · 1.61 KB
/
Copy patha2ui_fixed_schema.ts
File metadata and controls
56 lines (52 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { z } from "zod";
import { tool } from "@langchain/core/tools";
import {
createSurface,
loadSchema,
render,
updateComponents,
updateDataModel,
} from "./a2ui.js";
const CATALOG_ID = "copilotkit://app-dashboard-catalog";
const SURFACE_ID = "flight-search-results";
const FlightSchema = z.object({
id: z.string(),
airline: z.string(),
airlineLogo: z.string(),
flightNumber: z.string(),
origin: z.string(),
destination: z.string(),
date: z.string(),
departureTime: z.string(),
arrivalTime: z.string(),
duration: z.string(),
status: z.string(),
statusIcon: z.string(),
price: z.string(),
});
let _cachedSchema: unknown[] | null = null;
async function flightSchema(): Promise<unknown[]> {
if (_cachedSchema === null) {
_cachedSchema = await loadSchema("a2ui/schemas/flight_schema.json");
}
return _cachedSchema;
}
export const search_flights = tool(
async (input: { flights: z.infer<typeof FlightSchema>[] }) => {
const schema = await flightSchema();
return render([
createSurface(SURFACE_ID, CATALOG_ID),
updateComponents(SURFACE_ID, schema),
updateDataModel(SURFACE_ID, { flights: input.flights }),
]);
},
{
name: "search_flights",
description:
"Search for flights and display the results as rich cards. Return exactly 2 flights. " +
"Each flight must have id, airline, airlineLogo (Google favicon API URL), flightNumber, " +
"origin, destination, date (short readable), departureTime, arrivalTime, duration, " +
"status, statusIcon (colored dot URL), and price.",
schema: z.object({ flights: z.array(FlightSchema) }),
},
);