@langgraph-js/sdk 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.env +0 -0
  2. package/README.md +163 -0
  3. package/dist/LangGraphClient.d.ts +101 -0
  4. package/dist/LangGraphClient.js +401 -0
  5. package/dist/SpendTime.d.ts +9 -0
  6. package/dist/SpendTime.js +32 -0
  7. package/dist/ToolManager.d.ts +63 -0
  8. package/dist/ToolManager.js +93 -0
  9. package/dist/index.d.ts +5 -0
  10. package/dist/index.js +5 -0
  11. package/dist/tool/copilotkit-actions.d.ts +66 -0
  12. package/dist/tool/copilotkit-actions.js +1 -0
  13. package/dist/tool/createTool.d.ts +47 -0
  14. package/dist/tool/createTool.js +61 -0
  15. package/dist/tool/index.d.ts +2 -0
  16. package/dist/tool/index.js +2 -0
  17. package/dist/tool/utils.d.ts +36 -0
  18. package/dist/tool/utils.js +120 -0
  19. package/dist/ui-store/UnionStore.d.ts +11 -0
  20. package/dist/ui-store/UnionStore.js +9 -0
  21. package/dist/ui-store/createChatStore.d.ts +43 -0
  22. package/dist/ui-store/createChatStore.js +145 -0
  23. package/dist/ui-store/index.d.ts +2 -0
  24. package/dist/ui-store/index.js +2 -0
  25. package/index.html +12 -0
  26. package/package.json +35 -7
  27. package/src/LangGraphClient.ts +461 -0
  28. package/src/SpendTime.ts +29 -0
  29. package/src/ToolManager.ts +100 -0
  30. package/src/index.ts +5 -0
  31. package/src/tool/copilotkit-actions.ts +72 -0
  32. package/src/tool/createTool.ts +78 -0
  33. package/src/tool/index.ts +2 -0
  34. package/src/tool/utils.ts +158 -0
  35. package/src/ui-store/UnionStore.ts +20 -0
  36. package/src/ui-store/createChatStore.ts +153 -0
  37. package/src/ui-store/index.ts +2 -0
  38. package/test/testResponse.json +5418 -0
  39. package/tsconfig.json +112 -0
  40. package/ui/index.ts +182 -0
  41. package/ui/tool.ts +55 -0
@@ -0,0 +1,32 @@
1
+ export class SpendTime {
2
+ constructor() {
3
+ this.timeCounter = new Map();
4
+ }
5
+ start(key) {
6
+ this.timeCounter.set(key, [new Date()]);
7
+ }
8
+ end(key) {
9
+ var _a;
10
+ this.timeCounter.set(key, [((_a = this.timeCounter.get(key)) === null || _a === void 0 ? void 0 : _a[0]) || new Date(), new Date()]);
11
+ }
12
+ setSpendTime(key) {
13
+ if (this.timeCounter.has(key)) {
14
+ this.end(key);
15
+ }
16
+ else {
17
+ this.start(key);
18
+ }
19
+ }
20
+ getStartTime(key) {
21
+ var _a;
22
+ return ((_a = this.timeCounter.get(key)) === null || _a === void 0 ? void 0 : _a[0]) || new Date();
23
+ }
24
+ getEndTime(key) {
25
+ var _a;
26
+ return ((_a = this.timeCounter.get(key)) === null || _a === void 0 ? void 0 : _a[1]) || new Date();
27
+ }
28
+ getSpendTime(key) {
29
+ const [start, end = new Date()] = this.timeCounter.get(key) || [new Date(), new Date()];
30
+ return end.getTime() - start.getTime();
31
+ }
32
+ }
@@ -0,0 +1,63 @@
1
+ import { ToolMessage } from "@langchain/langgraph-sdk";
2
+ import { LangGraphClient } from "./LangGraphClient";
3
+ import { CallToolResult, UnionTool } from "./tool/createTool";
4
+ export declare class ToolManager {
5
+ private tools;
6
+ /**
7
+ * 注册一个工具
8
+ * @param tool 要注册的工具
9
+ */
10
+ bindTool(tool: UnionTool<any>): void;
11
+ /**
12
+ * 注册多个工具
13
+ * @param tools 要注册的工具数组
14
+ */
15
+ bindTools(tools: UnionTool<any>[]): void;
16
+ /**
17
+ * 获取所有已注册的工具
18
+ * @returns 工具数组
19
+ */
20
+ getAllTools(): UnionTool<any>[];
21
+ /**
22
+ * 获取指定名称的工具
23
+ * @param name 工具名称
24
+ * @returns 工具实例或 undefined
25
+ */
26
+ getTool(name: string): UnionTool<any> | undefined;
27
+ /**
28
+ * 移除指定名称的工具
29
+ * @param name 工具名称
30
+ * @returns 是否成功移除
31
+ */
32
+ removeTool(name: string): boolean;
33
+ /**
34
+ * 清空所有工具
35
+ */
36
+ clearTools(): void;
37
+ callTool(name: string, args: any, context: {
38
+ client: LangGraphClient;
39
+ message: ToolMessage;
40
+ }): Promise<CallToolResult>;
41
+ toJSON(): {
42
+ name: string;
43
+ description: string;
44
+ parameters: import("zod-to-json-schema").JsonSchema7Type & {
45
+ $schema?: string | undefined;
46
+ definitions?: {
47
+ [key: string]: import("zod-to-json-schema").JsonSchema7Type;
48
+ } | undefined;
49
+ };
50
+ }[];
51
+ private waitingMap;
52
+ doneWaiting(id: string, value: CallToolResult): boolean;
53
+ waitForDone(id: string): Promise<unknown> | ((value: CallToolResult) => void) | undefined;
54
+ /** 等待用户输入
55
+ * @example
56
+ * // 继续 chat 流
57
+ * client.tools.doneWaiting(message.id!, (e.target as any).value);
58
+ */
59
+ static waitForUIDone<T>(_: T, context: {
60
+ client: LangGraphClient;
61
+ message: ToolMessage;
62
+ }): Promise<unknown> | ((value: CallToolResult) => void) | undefined;
63
+ }
@@ -0,0 +1,93 @@
1
+ import { createJSONDefineTool } from "./tool/createTool";
2
+ export class ToolManager {
3
+ constructor() {
4
+ this.tools = new Map();
5
+ // === 专门为前端设计的异步触发结构
6
+ this.waitingMap = new Map();
7
+ }
8
+ /**
9
+ * 注册一个工具
10
+ * @param tool 要注册的工具
11
+ */
12
+ bindTool(tool) {
13
+ if (this.tools.has(tool.name)) {
14
+ throw new Error(`Tool with name ${tool.name} already exists`);
15
+ }
16
+ this.tools.set(tool.name, tool);
17
+ }
18
+ /**
19
+ * 注册多个工具
20
+ * @param tools 要注册的工具数组
21
+ */
22
+ bindTools(tools) {
23
+ tools.forEach((tool) => this.bindTool(tool));
24
+ }
25
+ /**
26
+ * 获取所有已注册的工具
27
+ * @returns 工具数组
28
+ */
29
+ getAllTools() {
30
+ return Array.from(this.tools.values());
31
+ }
32
+ /**
33
+ * 获取指定名称的工具
34
+ * @param name 工具名称
35
+ * @returns 工具实例或 undefined
36
+ */
37
+ getTool(name) {
38
+ return this.tools.get(name);
39
+ }
40
+ /**
41
+ * 移除指定名称的工具
42
+ * @param name 工具名称
43
+ * @returns 是否成功移除
44
+ */
45
+ removeTool(name) {
46
+ return this.tools.delete(name);
47
+ }
48
+ /**
49
+ * 清空所有工具
50
+ */
51
+ clearTools() {
52
+ this.tools.clear();
53
+ }
54
+ async callTool(name, args, context) {
55
+ const tool = this.getTool(name);
56
+ if (!tool) {
57
+ throw new Error(`Tool with name ${name} not found`);
58
+ }
59
+ return await tool.execute(args, context);
60
+ }
61
+ toJSON() {
62
+ return Array.from(this.tools.values()).map((i) => createJSONDefineTool(i));
63
+ }
64
+ doneWaiting(id, value) {
65
+ if (this.waitingMap.has(id)) {
66
+ this.waitingMap.get(id)(value);
67
+ this.waitingMap.delete(id);
68
+ return true;
69
+ }
70
+ else {
71
+ console.warn(`Waiting for tool ${id} not found`);
72
+ return false;
73
+ }
74
+ }
75
+ waitForDone(id) {
76
+ if (this.waitingMap.has(id)) {
77
+ return this.waitingMap.get(id);
78
+ }
79
+ const promise = new Promise((resolve, reject) => {
80
+ this.waitingMap.set(id, resolve);
81
+ });
82
+ return promise;
83
+ }
84
+ /** 等待用户输入
85
+ * @example
86
+ * // 继续 chat 流
87
+ * client.tools.doneWaiting(message.id!, (e.target as any).value);
88
+ */
89
+ static waitForUIDone(_, context) {
90
+ // console.log(context.message);
91
+ return context.client.tools.waitForDone(context.message.id);
92
+ }
93
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./LangGraphClient";
2
+ export * from "./tool";
3
+ export * from "@langchain/langgraph-sdk";
4
+ export * from "./ui-store";
5
+ export * from "./ToolManager";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./LangGraphClient";
2
+ export * from "./tool";
3
+ export * from "@langchain/langgraph-sdk";
4
+ export * from "./ui-store";
5
+ export * from "./ToolManager";
@@ -0,0 +1,66 @@
1
+ import { Message } from "@langchain/langgraph-sdk";
2
+ /**
3
+ * copy and modify from copilotkit
4
+ * https://github.com/copilotkit/copilotkit
5
+ *
6
+ * MIT License
7
+ */
8
+ type TypeMap = {
9
+ string: string;
10
+ number: number;
11
+ boolean: boolean;
12
+ object: object;
13
+ "string[]": string[];
14
+ "number[]": number[];
15
+ "boolean[]": boolean[];
16
+ "object[]": object[];
17
+ };
18
+ type AbstractParameter = {
19
+ name: string;
20
+ type?: keyof TypeMap;
21
+ description?: string;
22
+ required?: boolean;
23
+ };
24
+ interface StringParameter extends AbstractParameter {
25
+ type: "string";
26
+ enum?: string[];
27
+ }
28
+ interface ObjectParameter extends AbstractParameter {
29
+ type: "object";
30
+ attributes?: Parameter[];
31
+ }
32
+ interface ObjectArrayParameter extends AbstractParameter {
33
+ type: "object[]";
34
+ attributes?: Parameter[];
35
+ }
36
+ type SpecialParameters = StringParameter | ObjectParameter | ObjectArrayParameter;
37
+ interface BaseParameter extends AbstractParameter {
38
+ type?: Exclude<AbstractParameter["type"], SpecialParameters["type"]>;
39
+ }
40
+ export type Parameter = BaseParameter | SpecialParameters;
41
+ type OptionalParameterType<P extends AbstractParameter> = P["required"] extends false ? undefined : never;
42
+ type StringParameterType<P> = P extends StringParameter ? (P extends {
43
+ enum?: Array<infer E>;
44
+ } ? E : string) : never;
45
+ type ObjectParameterType<P> = P extends ObjectParameter ? (P extends {
46
+ attributes?: infer Attributes extends Parameter[];
47
+ } ? MappedParameterTypes<Attributes> : object) : never;
48
+ type ObjectArrayParameterType<P> = P extends ObjectArrayParameter ? (P extends {
49
+ attributes?: infer Attributes extends Parameter[];
50
+ } ? MappedParameterTypes<Attributes>[] : any[]) : never;
51
+ type MappedTypeOrString<T> = T extends keyof TypeMap ? TypeMap[T] : string;
52
+ type BaseParameterType<P extends AbstractParameter> = P extends {
53
+ type: infer T;
54
+ } ? (T extends BaseParameter["type"] ? MappedTypeOrString<T> : never) : string;
55
+ export type MappedParameterTypes<T extends Parameter[] | [] = []> = T extends [] ? Record<string, any> : {
56
+ [P in T[number] as P["name"]]: OptionalParameterType<P> | StringParameterType<P> | ObjectParameterType<P> | ObjectArrayParameterType<P> | BaseParameterType<P>;
57
+ };
58
+ export type Action<T extends Parameter[] | [] = []> = {
59
+ name: string;
60
+ description?: string;
61
+ parameters?: T;
62
+ handler?: T extends [] ? () => any | Promise<any> : (args: MappedParameterTypes<T>, context?: any) => any | Promise<any>;
63
+ returnDirect?: boolean;
64
+ callbackMessage?: () => Message[];
65
+ };
66
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import { z, ZodRawShape, ZodTypeAny } from "zod";
2
+ import { Action, Parameter } from "./copilotkit-actions";
3
+ import { Message } from "@langchain/langgraph-sdk";
4
+ export interface UnionTool<Args extends ZodRawShape> {
5
+ name: string;
6
+ description: string;
7
+ parameters: Args;
8
+ /** 是否直接返回工具结果,而不是通过消息返回 */
9
+ returnDirect?: boolean;
10
+ execute: ToolCallback<Args>;
11
+ /** 工具执行成功后触发的附加消息 */
12
+ callbackMessage?: (result: CallToolResult) => Message[];
13
+ }
14
+ export type ToolCallback<Args extends ZodRawShape> = (args: z.objectOutputType<Args, ZodTypeAny>, context?: any) => CallToolResult | Promise<CallToolResult>;
15
+ export type CallToolResult = string | {
16
+ type: "text";
17
+ text: string;
18
+ }[];
19
+ /** 用于格式校验 */
20
+ export declare const createTool: <Args extends ZodRawShape>(tool: UnionTool<Args>) => UnionTool<Args>;
21
+ /** 提供一种兼容 copilotkit 的定义方式,简化定义形式
22
+ * 来自 copilotkit 的 frontend action
23
+ */
24
+ export declare const createFETool: <const T extends Parameter[], Args extends ZodRawShape>(tool: Action<T>) => UnionTool<Args>;
25
+ export declare const createJSONDefineTool: <Args extends ZodRawShape>(tool: UnionTool<Args>) => {
26
+ name: string;
27
+ description: string;
28
+ parameters: import("zod-to-json-schema").JsonSchema7Type & {
29
+ $schema?: string | undefined;
30
+ definitions?: {
31
+ [key: string]: import("zod-to-json-schema").JsonSchema7Type;
32
+ } | undefined;
33
+ };
34
+ };
35
+ export declare const createMCPTool: <Args extends ZodRawShape>(tool: UnionTool<Args>) => (string | Args | ((args: z.objectOutputType<Args, ZodTypeAny>) => Promise<{
36
+ content: {
37
+ type: string;
38
+ text: string;
39
+ }[];
40
+ isError?: undefined;
41
+ } | {
42
+ content: {
43
+ type: string;
44
+ text: string;
45
+ }[];
46
+ isError: boolean;
47
+ }>))[];
@@ -0,0 +1,61 @@
1
+ import { actionParametersToJsonSchema, convertJsonSchemaToZodRawShape } from "./utils";
2
+ import { z } from "zod";
3
+ import { zodToJsonSchema } from "zod-to-json-schema";
4
+ /** 用于格式校验 */
5
+ export const createTool = (tool) => {
6
+ return tool;
7
+ };
8
+ /** 提供一种兼容 copilotkit 的定义方式,简化定义形式
9
+ * 来自 copilotkit 的 frontend action
10
+ */
11
+ export const createFETool = (tool) => {
12
+ return {
13
+ name: tool.name,
14
+ description: tool.description || "",
15
+ parameters: convertJsonSchemaToZodRawShape(actionParametersToJsonSchema(tool.parameters || [])),
16
+ returnDirect: tool.returnDirect,
17
+ callbackMessage: tool.callbackMessage,
18
+ async execute(args, context) {
19
+ var _a;
20
+ try {
21
+ const result = await ((_a = tool.handler) === null || _a === void 0 ? void 0 : _a.call(tool, args, context));
22
+ if (typeof result === "string") {
23
+ return [{ type: "text", text: result }];
24
+ }
25
+ return [{ type: "text", text: JSON.stringify(result) }];
26
+ }
27
+ catch (error) {
28
+ return [{ type: "text", text: `Error: ${error}` }];
29
+ }
30
+ },
31
+ };
32
+ };
33
+ ///======= UnionTool 到 各种工具的辅助函数
34
+ export const createJSONDefineTool = (tool) => {
35
+ return {
36
+ name: tool.name,
37
+ description: tool.description,
38
+ parameters: zodToJsonSchema(z.object(tool.parameters)),
39
+ };
40
+ };
41
+ export const createMCPTool = (tool) => {
42
+ return [
43
+ tool.name,
44
+ tool.description,
45
+ tool.parameters,
46
+ async (args) => {
47
+ try {
48
+ const result = await tool.execute(args);
49
+ if (typeof result === "string") {
50
+ return { content: [{ type: "text", text: result }] };
51
+ }
52
+ return {
53
+ content: result,
54
+ };
55
+ }
56
+ catch (error) {
57
+ return { content: [{ type: "text", text: `Error: ${error}` }], isError: true };
58
+ }
59
+ },
60
+ ];
61
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./createTool";
2
+ export * from "./copilotkit-actions";
@@ -0,0 +1,2 @@
1
+ export * from "./createTool";
2
+ export * from "./copilotkit-actions";
@@ -0,0 +1,36 @@
1
+ /**
2
+ * copy and modify from copilotkit
3
+ * https://github.com/copilotkit/copilotkit
4
+ *
5
+ * MIT License
6
+ */
7
+ import { z, ZodRawShape } from "zod";
8
+ import { Parameter } from "./copilotkit-actions";
9
+ export type JSONSchemaString = {
10
+ type: "string";
11
+ description?: string;
12
+ enum?: string[];
13
+ };
14
+ export type JSONSchemaNumber = {
15
+ type: "number";
16
+ description?: string;
17
+ };
18
+ export type JSONSchemaBoolean = {
19
+ type: "boolean";
20
+ description?: string;
21
+ };
22
+ export type JSONSchemaObject = {
23
+ type: "object";
24
+ properties?: Record<string, JSONSchema>;
25
+ required?: string[];
26
+ description?: string;
27
+ };
28
+ export type JSONSchemaArray = {
29
+ type: "array";
30
+ items: JSONSchema;
31
+ description?: string;
32
+ };
33
+ export type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaBoolean | JSONSchemaObject | JSONSchemaArray;
34
+ export declare function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema;
35
+ export declare function convertJsonSchemaToZodRawShape(jsonSchema: any): ZodRawShape;
36
+ export declare function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * copy and modify from copilotkit
3
+ * https://github.com/copilotkit/copilotkit
4
+ *
5
+ * MIT License
6
+ */
7
+ import { z } from "zod";
8
+ export function actionParametersToJsonSchema(actionParameters) {
9
+ // Create the parameters object based on the argumentAnnotations
10
+ let parameters = {};
11
+ for (let parameter of actionParameters || []) {
12
+ parameters[parameter.name] = convertAttribute(parameter);
13
+ }
14
+ let requiredParameterNames = [];
15
+ for (let arg of actionParameters || []) {
16
+ if (arg.required !== false) {
17
+ requiredParameterNames.push(arg.name);
18
+ }
19
+ }
20
+ // Create the ChatCompletionFunctions object
21
+ return {
22
+ type: "object",
23
+ properties: parameters,
24
+ required: requiredParameterNames,
25
+ };
26
+ }
27
+ function convertAttribute(attribute) {
28
+ var _a, _b, _c;
29
+ switch (attribute.type) {
30
+ case "string":
31
+ return {
32
+ type: "string",
33
+ description: attribute.description,
34
+ ...(attribute.enum && { enum: attribute.enum }),
35
+ };
36
+ case "number":
37
+ case "boolean":
38
+ return {
39
+ type: attribute.type,
40
+ description: attribute.description,
41
+ };
42
+ case "object":
43
+ case "object[]":
44
+ const properties = (_a = attribute.attributes) === null || _a === void 0 ? void 0 : _a.reduce((acc, attr) => {
45
+ acc[attr.name] = convertAttribute(attr);
46
+ return acc;
47
+ }, {});
48
+ const required = (_b = attribute.attributes) === null || _b === void 0 ? void 0 : _b.filter((attr) => attr.required !== false).map((attr) => attr.name);
49
+ if (attribute.type === "object[]") {
50
+ return {
51
+ type: "array",
52
+ items: {
53
+ type: "object",
54
+ ...(properties && { properties }),
55
+ ...(required && required.length > 0 && { required }),
56
+ },
57
+ description: attribute.description,
58
+ };
59
+ }
60
+ return {
61
+ type: "object",
62
+ description: attribute.description,
63
+ ...(properties && { properties }),
64
+ ...(required && required.length > 0 && { required }),
65
+ };
66
+ default:
67
+ // Handle arrays of primitive types and undefined attribute.type
68
+ if ((_c = attribute.type) === null || _c === void 0 ? void 0 : _c.endsWith("[]")) {
69
+ const itemType = attribute.type.slice(0, -2);
70
+ return {
71
+ type: "array",
72
+ items: { type: itemType },
73
+ description: attribute.description,
74
+ };
75
+ }
76
+ // Fallback for undefined type or any other unexpected type
77
+ return {
78
+ type: "string",
79
+ description: attribute.description,
80
+ };
81
+ }
82
+ }
83
+ export function convertJsonSchemaToZodRawShape(jsonSchema) {
84
+ const spec = {};
85
+ for (const [key, value] of Object.entries(jsonSchema.properties)) {
86
+ spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
87
+ }
88
+ return spec;
89
+ }
90
+ export function convertJsonSchemaToZodSchema(jsonSchema, required) {
91
+ if (jsonSchema.type === "object") {
92
+ const spec = {};
93
+ if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
94
+ return !required ? z.object(spec).optional() : z.object(spec);
95
+ }
96
+ for (const [key, value] of Object.entries(jsonSchema.properties)) {
97
+ spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
98
+ }
99
+ let schema = z.object(spec).describe(jsonSchema.description);
100
+ return required ? schema : schema.optional();
101
+ }
102
+ else if (jsonSchema.type === "string") {
103
+ let schema = z.string().describe(jsonSchema.description);
104
+ return required ? schema : schema.optional();
105
+ }
106
+ else if (jsonSchema.type === "number") {
107
+ let schema = z.number().describe(jsonSchema.description);
108
+ return required ? schema : schema.optional();
109
+ }
110
+ else if (jsonSchema.type === "boolean") {
111
+ let schema = z.boolean().describe(jsonSchema.description);
112
+ return required ? schema : schema.optional();
113
+ }
114
+ else if (jsonSchema.type === "array") {
115
+ let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
116
+ let schema = z.array(itemSchema).describe(jsonSchema.description);
117
+ return required ? schema : schema.optional();
118
+ }
119
+ throw new Error("Invalid JSON schema");
120
+ }
@@ -0,0 +1,11 @@
1
+ import { PreinitializedWritableAtom, StoreValue } from "nanostores";
2
+ export type UnionStore<T extends {
3
+ data: Record<string, PreinitializedWritableAtom<any>>;
4
+ mutations: Record<string, any>;
5
+ }> = {
6
+ [k in keyof T["data"]]: StoreValue<T["data"][k]>;
7
+ } & T["mutations"];
8
+ export declare const useUnionStore: <T extends {
9
+ data: Record<string, any>;
10
+ mutations: Record<string, any>;
11
+ }>(store: T, useStore: (store: PreinitializedWritableAtom<any>) => StoreValue<T["data"][keyof T["data"]]>) => UnionStore<T>;
@@ -0,0 +1,9 @@
1
+ export const useUnionStore = (store, useStore) => {
2
+ const data = Object.fromEntries(Object.entries(store.data).map(([key, value]) => {
3
+ return [key, useStore(value)];
4
+ }));
5
+ return {
6
+ ...data,
7
+ ...store.mutations,
8
+ };
9
+ };
@@ -0,0 +1,43 @@
1
+ import { LangGraphClient, LangGraphClientConfig, RenderMessage } from "../LangGraphClient";
2
+ import { Message, Thread } from "@langchain/langgraph-sdk";
3
+ export declare const formatTime: (date: Date) => string;
4
+ export declare const formatTokens: (tokens: number) => string;
5
+ export declare const getMessageContent: (content: any) => string;
6
+ export declare const createChatStore: (initClientName: string, config: LangGraphClientConfig, context?: {
7
+ onInit?: (client: LangGraphClient) => void;
8
+ }) => {
9
+ data: {
10
+ client: import("nanostores").PreinitializedWritableAtom<LangGraphClient | null> & object;
11
+ renderMessages: import("nanostores").PreinitializedWritableAtom<RenderMessage[]> & object;
12
+ userInput: import("nanostores").PreinitializedWritableAtom<string> & object;
13
+ loading: import("nanostores").PreinitializedWritableAtom<boolean> & object;
14
+ inChatError: import("nanostores").PreinitializedWritableAtom<string | null> & object;
15
+ currentAgent: import("nanostores").PreinitializedWritableAtom<string> & object;
16
+ collapsedTools: import("nanostores").PreinitializedWritableAtom<string[]> & object;
17
+ showHistory: import("nanostores").PreinitializedWritableAtom<boolean> & object;
18
+ historyList: import("nanostores").PreinitializedWritableAtom<Thread<{
19
+ messages: Message[];
20
+ }>[]> & object;
21
+ currentChatId: import("nanostores").PreinitializedWritableAtom<string | null> & object;
22
+ };
23
+ mutations: {
24
+ initClient: () => Promise<void>;
25
+ sendMessage: () => Promise<void>;
26
+ interruptMessage: () => void;
27
+ toggleToolCollapse: (toolId: string) => void;
28
+ toggleHistoryVisible: () => void;
29
+ refreshHistoryList: () => Promise<void>;
30
+ addToHistory: (thread: Thread<{
31
+ messages: Message[];
32
+ }>) => void;
33
+ setUserInput(input: string): void;
34
+ setCurrentAgent(agent: string): Promise<void>;
35
+ createNewChat(): void;
36
+ toHistoryChat(thread: Thread<{
37
+ messages: Message[];
38
+ }>): void;
39
+ deleteHistoryChat(thread: Thread<{
40
+ messages: Message[];
41
+ }>): Promise<void>;
42
+ };
43
+ };