feat: update types

This commit is contained in:
Tat Dat Duong
2025-03-05 15:09:10 +01:00
parent 3ee8afce9b
commit 571a170a92
6 changed files with 12 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { StockbrokerState } from "../types"; import { StockbrokerState, StockbrokerUpdate } from "../types";
import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenAI } from "@langchain/openai";
import { typedUi } from "@langchain/langgraph-sdk/react-ui/server"; import { typedUi } from "@langchain/langgraph-sdk/react-ui/server";
import type ComponentMap from "../../uis/index"; import type ComponentMap from "../../uis/index";
@@ -32,7 +32,7 @@ const STOCKBROKER_TOOLS = [
export async function callTools( export async function callTools(
state: StockbrokerState, state: StockbrokerState,
config: LangGraphRunnableConfig, config: LangGraphRunnableConfig,
): Promise<Partial<StockbrokerState>> { ): Promise<StockbrokerUpdate> {
const ui = typedUi<typeof ComponentMap>(config); const ui = typedUi<typeof ComponentMap>(config);
const message = await llm.bindTools(STOCKBROKER_TOOLS).invoke([ const message = await llm.bindTools(STOCKBROKER_TOOLS).invoke([
@@ -65,8 +65,7 @@ export async function callTools(
return { return {
messages: [message], messages: [message],
// TODO: Fix the ui return type. ui: ui.collect,
ui: ui.collect as any[],
timestamp: Date.now(), timestamp: Date.now(),
}; };
} }

View File

@@ -8,3 +8,4 @@ export const StockbrokerAnnotation = Annotation.Root({
}); });
export type StockbrokerState = typeof StockbrokerAnnotation.State; export type StockbrokerState = typeof StockbrokerAnnotation.State;
export type StockbrokerUpdate = typeof StockbrokerAnnotation.Update;

View File

@@ -1,11 +1,11 @@
import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenAI } from "@langchain/openai";
import { TripPlannerState } from "../types"; import { TripPlannerState, TripPlannerUpdate } from "../types";
import { z } from "zod"; import { z } from "zod";
import { formatMessages } from "agent/utils/format-messages"; import { formatMessages } from "agent/utils/format-messages";
export async function classify( export async function classify(
state: TripPlannerState, state: TripPlannerState,
): Promise<Partial<TripPlannerState>> { ): Promise<TripPlannerUpdate> {
if (!state.tripDetails) { if (!state.tripDetails) {
// Can not classify if tripDetails are undefined // Can not classify if tripDetails are undefined
return {}; return {};

View File

@@ -1,5 +1,5 @@
import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenAI } from "@langchain/openai";
import { TripDetails, TripPlannerState } from "../types"; import { TripDetails, TripPlannerState, TripPlannerUpdate } from "../types";
import { z } from "zod"; import { z } from "zod";
import { formatMessages } from "agent/utils/format-messages"; import { formatMessages } from "agent/utils/format-messages";
@@ -43,7 +43,7 @@ function calculateDates(
export async function extraction( export async function extraction(
state: TripPlannerState, state: TripPlannerState,
): Promise<Partial<TripPlannerState>> { ): Promise<TripPlannerUpdate> {
const schema = z.object({ const schema = z.object({
location: z location: z
.string() .string()

View File

@@ -1,4 +1,4 @@
import { TripPlannerState } from "../types"; import { TripPlannerState, TripPlannerUpdate } from "../types";
import { ChatOpenAI } from "@langchain/openai"; import { ChatOpenAI } from "@langchain/openai";
import { typedUi } from "@langchain/langgraph-sdk/react-ui/server"; import { typedUi } from "@langchain/langgraph-sdk/react-ui/server";
import type ComponentMap from "../../uis/index"; import type ComponentMap from "../../uis/index";
@@ -48,7 +48,7 @@ const schema = z.object({
export async function callTools( export async function callTools(
state: TripPlannerState, state: TripPlannerState,
config: LangGraphRunnableConfig, config: LangGraphRunnableConfig,
): Promise<Partial<TripPlannerState>> { ): Promise<TripPlannerUpdate> {
if (!state.tripDetails) { if (!state.tripDetails) {
throw new Error("No trip details found"); throw new Error("No trip details found");
} }
@@ -111,8 +111,7 @@ export async function callTools(
return { return {
messages: [response], messages: [response],
// TODO: Fix the ui return type. ui: ui.collect,
ui: ui.collect as any[],
timestamp: Date.now(), timestamp: Date.now(),
}; };
} }

View File

@@ -16,3 +16,4 @@ export const TripPlannerAnnotation = Annotation.Root({
}); });
export type TripPlannerState = typeof TripPlannerAnnotation.State; export type TripPlannerState = typeof TripPlannerAnnotation.State;
export type TripPlannerUpdate = typeof TripPlannerAnnotation.Update;