@langgraph-js/sdk
Version:
The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces
203 lines (202 loc) • 9.12 kB
TypeScript
import { type PropType, Ref } from "vue";
import { createChatStore } from "../ui-store/index.js";
import { PreinitializedWritableAtom, StoreValue } from "nanostores";
import { ILangGraphClient } from "@langgraph-js/pure-graph/dist/types.js";
/**
* @zh UnionStore 类型用于合并 store 的 data 和 mutations,使其可以直接访问。
* @en The UnionStore type is used to merge the data and mutations of a store, allowing direct access.
*/
export type UnionStoreVue<T extends {
data: Record<string, PreinitializedWritableAtom<any>>;
mutations: Record<string, any>;
}> = {
[k in keyof T["data"]]: Readonly<Ref<StoreValue<T["data"][k]>>>;
} & T["mutations"];
/**
* @zh useUnionStore Hook 用于将 nanostores 的 store 结构转换为更易于在 UI 组件中使用的扁平结构。
* @en The useUnionStore Hook is used to transform the nanostores store structure into a flatter structure that is easier to use in UI components.
*/
export declare const useUnionStoreVue: <T extends {
data: Record<string, any>;
mutations: Record<string, any>;
}>(store: T, useStore: (store: PreinitializedWritableAtom<any>) => Readonly<Ref<any>>) => UnionStoreVue<T>;
/**
* 使用 Chat Store 的组合式函数
* @throws {Error} 如果在 ChatProvider 外部使用会抛出错误
*/
export declare const useChat: () => UnionStoreVue<ReturnType<typeof createChatStore>>;
export interface ChatProviderProps {
defaultAgent?: string;
apiUrl?: string;
defaultHeaders?: Record<string, string>;
withCredentials?: boolean;
fetch?: typeof fetch;
showHistory?: boolean;
showGraph?: boolean;
fallbackToAvailableAssistants?: boolean;
/** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
autoRestoreLastSession?: boolean;
onInitError?: (error: any, currentAgent: string) => void;
client?: ILangGraphClient;
legacyMode?: boolean;
}
/**
* @zh Chat Provider Hook,用于在 setup 中直接使用
* @en Chat Provider Hook, used directly in setup
*/
export declare const useChatProvider: (props: ChatProviderProps) => {
unionStore: UnionStoreVue<{
data: {
artifacts: PreinitializedWritableAtom<import("../index.js").ComposedArtifact[]> & object;
currentArtifactId: PreinitializedWritableAtom<[string, string] | null> & object;
showArtifact: PreinitializedWritableAtom<boolean> & object;
client: PreinitializedWritableAtom<import("../LangGraphClient.js").LangGraphClient<unknown> | null> & object;
history: PreinitializedWritableAtom<import("../History.js").History | null> & object;
sessions: PreinitializedWritableAtom<import("../History.js").SessionInfo[]> & object;
renderMessages: PreinitializedWritableAtom<import("../LangGraphClient.js").RenderMessage[]> & object;
userInput: PreinitializedWritableAtom<string> & object;
loading: PreinitializedWritableAtom<boolean> & object;
inChatError: PreinitializedWritableAtom<string | null> & object;
currentAgent: PreinitializedWritableAtom<string> & object;
currentChatId: PreinitializedWritableAtom<string | null> & object;
currentNodeName: PreinitializedWritableAtom<string> & object;
currentStatus: PreinitializedWritableAtom<string> & object;
interruptData: PreinitializedWritableAtom<import("../humanInTheLoop.js").InterruptData | null> & object;
isInterrupted: PreinitializedWritableAtom<boolean> & object;
tools: PreinitializedWritableAtom<import("../index.js").UnionTool<any, Object, any>[]> & object;
collapsedTools: PreinitializedWritableAtom<string[]> & object;
showGraph: PreinitializedWritableAtom<boolean> & object;
graphVisualize: PreinitializedWritableAtom<import("@langchain/langgraph-sdk").AssistantGraph | null> & object;
showHistory: PreinitializedWritableAtom<boolean> & object;
historyList: PreinitializedWritableAtom<import("@langchain/langgraph-sdk").Thread<{
messages: import("@langchain/langgraph-sdk").Message[];
}>[]> & object;
};
mutations: {
setCurrentArtifactById: (id: string, tool_id: string) => void;
setShowArtifact: (show: boolean) => void;
initClient: () => Promise<import("../History.js").History>;
getClient: () => import("../LangGraphClient.js").LangGraphClient<unknown> | null;
getHistory: () => import("../History.js").History | null;
activateSession: (sessionId: string, mustResetStream?: boolean) => Promise<void>;
createNewSession: () => Promise<void>;
refreshSessionList: () => Promise<void>;
refreshHistoryList: () => Promise<void>;
sendMessage: (message?: import("@langchain/langgraph-sdk").Message[], extraData?: import("../LangGraphClient.js").SendMessageOptions, withoutCheck?: boolean, isResume?: boolean) => Promise<void>;
stopGeneration: () => void;
setUserInput: (input: string) => void;
revertChatTo(messageId: string, resend?: boolean, sendOptions?: import("../LangGraphClient.js").SendMessageOptions & import("../time-travel/index.js").RevertChatToOptions): Promise<void>;
refreshTools: () => Promise<void>;
setTools(new_tools: import("../index.js").UnionTool<any>[]): void;
toggleToolCollapse: (toolId: string) => void;
getToolUIRender: (tool_name: string) => ((message: import("../LangGraphClient.js").RenderMessage) => Object) | null;
isFELocking: () => boolean | undefined;
toggleHistoryVisible: () => void;
toggleGraphVisible(): void;
refreshGraph: () => Promise<void>;
setCurrentAgent(agent: string): Promise<import("../History.js").History>;
resumeFromInterrupt(data: any): Promise<void>;
addToHistory: (thread: import("@langchain/langgraph-sdk").Thread<{
messages: import("@langchain/langgraph-sdk").Message[];
}>) => void;
createNewChat: () => Promise<void>;
toHistoryChat: (thread: import("@langchain/langgraph-sdk").Thread<{
messages: import("@langchain/langgraph-sdk").Message[];
}>) => Promise<void>;
deleteHistoryChat(thread: import("@langchain/langgraph-sdk").Thread<{
messages: import("@langchain/langgraph-sdk").Message[];
}>): Promise<void>;
};
}>;
};
/**
* Chat Provider 组件
* 提供 Chat Store 的上下文
*/
export declare const ChatProvider: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
defaultAgent: {
type: PropType<string>;
default: string;
};
apiUrl: {
type: PropType<string>;
default: string;
};
defaultHeaders: {
type: PropType<Record<string, string>>;
default: () => {};
};
withCredentials: {
type: PropType<boolean>;
default: boolean;
};
fetch: {
type: PropType<typeof fetch>;
default: undefined;
};
showHistory: {
type: PropType<boolean>;
default: boolean;
};
showGraph: {
type: PropType<boolean>;
default: boolean;
};
autoRestoreLastSession: {
type: PropType<boolean>;
default: boolean;
};
onInitError: {
type: PropType<(error: any, currentAgent: string) => void>;
default: undefined;
};
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
[key: string]: any;
}>[] | undefined, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
defaultAgent: {
type: PropType<string>;
default: string;
};
apiUrl: {
type: PropType<string>;
default: string;
};
defaultHeaders: {
type: PropType<Record<string, string>>;
default: () => {};
};
withCredentials: {
type: PropType<boolean>;
default: boolean;
};
fetch: {
type: PropType<typeof fetch>;
default: undefined;
};
showHistory: {
type: PropType<boolean>;
default: boolean;
};
showGraph: {
type: PropType<boolean>;
default: boolean;
};
autoRestoreLastSession: {
type: PropType<boolean>;
default: boolean;
};
onInitError: {
type: PropType<(error: any, currentAgent: string) => void>;
default: undefined;
};
}>> & Readonly<{}>, {
apiUrl: string;
defaultHeaders: Record<string, string>;
showGraph: boolean;
showHistory: boolean;
defaultAgent: string;
withCredentials: boolean;
fetch: typeof fetch;
autoRestoreLastSession: boolean;
onInitError: (error: any, currentAgent: string) => void;
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;