@librechat/agents-types 2.4.49 → 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.
- package/graph.ts +119 -89
- package/package.json +1 -1
- package/tools.ts +16 -10
package/graph.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
// src/types/graph.ts
|
2
|
-
import type {
|
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(
|
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> =
|
39
|
+
export type GraphStateChannels<T extends BaseGraphState> =
|
40
|
+
StateGraphArgs<T>['channels'];
|
29
41
|
|
30
|
-
export type Workflow<
|
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<
|
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 =
|
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 =
|
37
|
-
|
38
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
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 =
|
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
package/tools.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// src/types/tools.ts
|
2
|
-
import type { RunnableToolLike } from '@langchain/core/runnables';
|
3
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';
|
@@ -13,9 +13,10 @@ export type CustomToolCall = {
|
|
13
13
|
id?: string;
|
14
14
|
type?: 'tool_call';
|
15
15
|
output?: string;
|
16
|
-
}
|
16
|
+
};
|
17
17
|
|
18
18
|
export type GenericTool = StructuredToolInterface | RunnableToolLike;
|
19
|
+
|
19
20
|
export type ToolMap = Map<string, GenericTool>;
|
20
21
|
export type ToolRefs = {
|
21
22
|
tools: GenericTool[];
|
@@ -30,7 +31,10 @@ export type ToolNodeOptions = {
|
|
30
31
|
handleToolErrors?: boolean;
|
31
32
|
loadRuntimeTools?: ToolRefGenerator;
|
32
33
|
toolCallStepIds?: Map<string, string>;
|
33
|
-
errorHandler?: (
|
34
|
+
errorHandler?: (
|
35
|
+
data: ToolErrorData,
|
36
|
+
metadata?: Record<string, unknown>
|
37
|
+
) => void;
|
34
38
|
};
|
35
39
|
|
36
40
|
export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
|
@@ -50,13 +54,15 @@ export type CodeEnvFile = {
|
|
50
54
|
session_id: string;
|
51
55
|
};
|
52
56
|
|
53
|
-
export type CodeExecutionToolParams =
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
export type CodeExecutionToolParams =
|
58
|
+
| undefined
|
59
|
+
| {
|
60
|
+
session_id?: string;
|
61
|
+
user_id?: string;
|
62
|
+
apiKey?: string;
|
63
|
+
files?: CodeEnvFile[];
|
64
|
+
[EnvVar.CODE_API_KEY]?: string;
|
65
|
+
};
|
60
66
|
|
61
67
|
export type FileRef = {
|
62
68
|
id: string;
|