@librechat/agents-types 2.4.50 → 2.4.51

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 (3) hide show
  1. package/graph.ts +119 -89
  2. package/package.json +1 -1
  3. package/tools.ts +4 -3
package/graph.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  // src/types/graph.ts
2
- import type { StateGraphArgs, StateGraph, CompiledStateGraph } from '@langchain/langgraph';
2
+ import type {
3
+ StateGraphArgs,
4
+ StateGraph,
5
+ CompiledStateGraph,
6
+ } from '@langchain/langgraph';
7
+ import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
3
8
  import type { BaseMessage, AIMessageChunk } from '@langchain/core/messages';
4
9
  import type { ChatGenerationChunk } from '@langchain/core/outputs';
10
+ import type { GoogleAIToolType } from '@langchain/google-common';
5
11
  import type { RunnableConfig } from '@langchain/core/runnables';
6
12
  import type { ToolMap, GenericTool } from '@/types/tools';
7
13
  import type { ClientOptions } from '@/types/llm';
@@ -22,56 +28,78 @@ export type IState = BaseGraphState;
22
28
  // }
23
29
 
24
30
  export interface EventHandler {
25
- handle(event: string, data: StreamEventData | ModelEndData, metadata?: Record<string, unknown>, graph?: Graph): void;
31
+ handle(
32
+ event: string,
33
+ data: StreamEventData | ModelEndData,
34
+ metadata?: Record<string, unknown>,
35
+ graph?: Graph
36
+ ): void;
26
37
  }
27
38
 
28
- export type GraphStateChannels<T extends BaseGraphState> = StateGraphArgs<T>['channels'];
39
+ export type GraphStateChannels<T extends BaseGraphState> =
40
+ StateGraphArgs<T>['channels'];
29
41
 
30
- export type Workflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = StateGraph<T, U, N>;
42
+ export type Workflow<
43
+ T extends BaseGraphState = BaseGraphState,
44
+ U extends Partial<T> = Partial<T>,
45
+ N extends string = string,
46
+ > = StateGraph<T, U, N>;
31
47
 
32
- export type CompiledWorkflow<T extends BaseGraphState = BaseGraphState, U extends Partial<T> = Partial<T>, N extends string = string> = CompiledStateGraph<T, U, N>;
48
+ export type CompiledWorkflow<
49
+ T extends BaseGraphState = BaseGraphState,
50
+ U extends Partial<T> = Partial<T>,
51
+ N extends string = string,
52
+ > = CompiledStateGraph<T, U, N>;
33
53
 
34
- export type EventStreamCallbackHandlerInput = Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<infer T, 'autoClose'> ? T : never;
54
+ export type EventStreamCallbackHandlerInput =
55
+ Parameters<CompiledWorkflow['streamEvents']>[2] extends Omit<
56
+ infer T,
57
+ 'autoClose'
58
+ >
59
+ ? T
60
+ : never;
35
61
 
36
- export type StreamChunk = ChatGenerationChunk & {
37
- message: AIMessageChunk;
38
- } | AIMessageChunk;
62
+ export type StreamChunk =
63
+ | (ChatGenerationChunk & {
64
+ message: AIMessageChunk;
65
+ })
66
+ | AIMessageChunk;
39
67
 
40
68
  /**
41
69
  * Data associated with a StreamEvent.
42
70
  */
43
71
  export type StreamEventData = {
44
- /**
45
- * The input passed to the runnable that generated the event.
46
- * Inputs will sometimes be available at the *START* of the runnable, and
47
- * sometimes at the *END* of the runnable.
48
- * If a runnable is able to stream its inputs, then its input by definition
49
- * won't be known until the *END* of the runnable when it has finished streaming
50
- * its inputs.
51
- */
52
- input?: unknown;
53
- /**
54
- * The output of the runnable that generated the event.
55
- * Outputs will only be available at the *END* of the runnable.
56
- * For most runnables, this field can be inferred from the `chunk` field,
57
- * though there might be some exceptions for special cased runnables (e.g., like
58
- * chat models), which may return more information.
59
- */
60
- output?: unknown;
61
- /**
62
- * A streaming chunk from the output that generated the event.
63
- * chunks support addition in general, and adding them up should result
64
- * in the output of the runnable that generated the event.
65
- */
66
- chunk?: StreamChunk;
67
- /**
68
- * Runnable config for invoking other runnables within handlers.
69
- */
70
- config?: RunnableConfig;
71
- /**
72
- * Custom result from the runnable that generated the event.
73
- */
74
- result?: unknown;
72
+ /**
73
+ * The input passed to the runnable that generated the event.
74
+ * Inputs will sometimes be available at the *START* of the runnable, and
75
+ * sometimes at the *END* of the runnable.
76
+ * If a runnable is able to stream its inputs, then its input by definition
77
+ * won't be known until the *END* of the runnable when it has finished streaming
78
+ * its inputs.
79
+ */
80
+ input?: unknown;
81
+ /**
82
+ * The output of the runnable that generated the event.
83
+ * Outputs will only be available at the *END* of the runnable.
84
+ * For most runnables, this field can be inferred from the `chunk` field,
85
+ * though there might be some exceptions for special cased runnables (e.g., like
86
+ * chat models), which may return more information.
87
+ */
88
+ output?: unknown;
89
+ /**
90
+ * A streaming chunk from the output that generated the event.
91
+ * chunks support addition in general, and adding them up should result
92
+ * in the output of the runnable that generated the event.
93
+ */
94
+ chunk?: StreamChunk;
95
+ /**
96
+ * Runnable config for invoking other runnables within handlers.
97
+ */
98
+ config?: RunnableConfig;
99
+ /**
100
+ * Custom result from the runnable that generated the event.
101
+ */
102
+ result?: unknown;
75
103
  };
76
104
 
77
105
  /**
@@ -80,54 +108,54 @@ export type StreamEventData = {
80
108
  * Schema of a streaming event which is produced from the streamEvents method.
81
109
  */
82
110
  export type StreamEvent = {
83
- /**
84
- * Event names are of the format: on_[runnable_type]_(start|stream|end).
85
- *
86
- * Runnable types are one of:
87
- * - llm - used by non chat models
88
- * - chat_model - used by chat models
89
- * - prompt -- e.g., ChatPromptTemplate
90
- * - tool -- LangChain tools
91
- * - chain - most Runnables are of this type
92
- *
93
- * Further, the events are categorized as one of:
94
- * - start - when the runnable starts
95
- * - stream - when the runnable is streaming
96
- * - end - when the runnable ends
97
- *
98
- * start, stream and end are associated with slightly different `data` payload.
99
- *
100
- * Please see the documentation for `EventData` for more details.
101
- */
102
- event: string;
103
- /** The name of the runnable that generated the event. */
104
- name: string;
105
- /**
106
- * An randomly generated ID to keep track of the execution of the given runnable.
107
- *
108
- * Each child runnable that gets invoked as part of the execution of a parent runnable
109
- * is assigned its own unique ID.
110
- */
111
- run_id: string;
112
- /**
113
- * Tags associated with the runnable that generated this event.
114
- * Tags are always inherited from parent runnables.
115
- */
116
- tags?: string[];
117
- /** Metadata associated with the runnable that generated this event. */
118
- metadata: Record<string, unknown>;
119
- /**
120
- * Event data.
121
- *
122
- * The contents of the event data depend on the event type.
123
- */
124
- data: StreamEventData;
111
+ /**
112
+ * Event names are of the format: on_[runnable_type]_(start|stream|end).
113
+ *
114
+ * Runnable types are one of:
115
+ * - llm - used by non chat models
116
+ * - chat_model - used by chat models
117
+ * - prompt -- e.g., ChatPromptTemplate
118
+ * - tool -- LangChain tools
119
+ * - chain - most Runnables are of this type
120
+ *
121
+ * Further, the events are categorized as one of:
122
+ * - start - when the runnable starts
123
+ * - stream - when the runnable is streaming
124
+ * - end - when the runnable ends
125
+ *
126
+ * start, stream and end are associated with slightly different `data` payload.
127
+ *
128
+ * Please see the documentation for `EventData` for more details.
129
+ */
130
+ event: string;
131
+ /** The name of the runnable that generated the event. */
132
+ name: string;
133
+ /**
134
+ * An randomly generated ID to keep track of the execution of the given runnable.
135
+ *
136
+ * Each child runnable that gets invoked as part of the execution of a parent runnable
137
+ * is assigned its own unique ID.
138
+ */
139
+ run_id: string;
140
+ /**
141
+ * Tags associated with the runnable that generated this event.
142
+ * Tags are always inherited from parent runnables.
143
+ */
144
+ tags?: string[];
145
+ /** Metadata associated with the runnable that generated this event. */
146
+ metadata: Record<string, unknown>;
147
+ /**
148
+ * Event data.
149
+ *
150
+ * The contents of the event data depend on the event type.
151
+ */
152
+ data: StreamEventData;
125
153
  };
126
154
 
127
155
  export type GraphConfig = {
128
- provider: string;
129
- thread_id?: string;
130
- run_id?: string;
156
+ provider: string;
157
+ thread_id?: string;
158
+ run_id?: string;
131
159
  };
132
160
 
133
161
  export type PartMetadata = {
@@ -138,8 +166,10 @@ export type PartMetadata = {
138
166
  output?: string;
139
167
  };
140
168
 
141
- export type ModelEndData = StreamEventData & { output: AIMessageChunk | undefined } | undefined;
142
-
169
+ export type ModelEndData =
170
+ | (StreamEventData & { output: AIMessageChunk | undefined })
171
+ | undefined;
172
+ export type GraphTools = GenericTool[] | BindToolsInput[] | GoogleAIToolType[];
143
173
  export type StandardGraphInput = {
144
174
  runId?: string;
145
175
  toolEnd?: boolean;
@@ -148,8 +178,8 @@ export type StandardGraphInput = {
148
178
  signal?: AbortSignal;
149
179
  instructions?: string;
150
180
  streamBuffer?: number;
151
- tools?: GenericTool[];
152
181
  clientOptions: ClientOptions;
153
182
  additional_instructions?: string;
154
183
  reasoningKey?: 'reasoning_content' | 'reasoning';
155
- };
184
+ tools?: GraphTools;
185
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents-types",
3
- "version": "2.4.50",
3
+ "version": "2.4.51",
4
4
  "description": "Type definitions for @librechat/agents",
5
5
  "types": "index.d.ts",
6
6
  "scripts": {
package/tools.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/types/tools.ts
2
- import type { BindToolsInput } from '@langchain/core/language_models/chat_models';
3
- import type { GoogleAIToolType } from '@langchain/google-common';
2
+ import type { StructuredToolInterface } from '@langchain/core/tools';
3
+ import type { RunnableToolLike } from '@langchain/core/runnables';
4
4
  import type { ToolCall } from '@langchain/core/messages/tool';
5
5
  import type { ToolErrorData } from './stream';
6
6
  import { EnvVar } from '@/common';
@@ -15,7 +15,8 @@ export type CustomToolCall = {
15
15
  output?: string;
16
16
  };
17
17
 
18
- export type GenericTool = BindToolsInput | GoogleAIToolType;
18
+ export type GenericTool = StructuredToolInterface | RunnableToolLike;
19
+
19
20
  export type ToolMap = Map<string, GenericTool>;
20
21
  export type ToolRefs = {
21
22
  tools: GenericTool[];