@copilotkit/sdk-js 1.56.4-canary.1777538870 → 1.56.5
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/dist/langgraph/middleware.cjs +44 -2
- package/dist/langgraph/middleware.cjs.map +1 -1
- package/dist/langgraph/middleware.d.cts +32 -1
- package/dist/langgraph/middleware.d.cts.map +1 -1
- package/dist/langgraph/middleware.d.mts +32 -1
- package/dist/langgraph/middleware.d.mts.map +1 -1
- package/dist/langgraph/middleware.mjs +44 -3
- package/dist/langgraph/middleware.mjs.map +1 -1
- package/dist/langgraph/state-schema.d.cts +22 -16
- package/dist/langgraph/state-schema.d.cts.map +1 -1
- package/dist/langgraph/state-schema.d.mts +22 -16
- package/dist/langgraph/state-schema.d.mts.map +1 -1
- package/dist/langgraph/types.d.cts +107 -50
- package/dist/langgraph/types.d.cts.map +1 -1
- package/dist/langgraph/types.d.mts +107 -50
- package/dist/langgraph/types.d.mts.map +1 -1
- package/dist/langgraph.cjs +2 -1
- package/dist/langgraph.d.cts +2 -2
- package/dist/langgraph.d.mts +2 -2
- package/dist/langgraph.mjs +2 -2
- package/package.json +6 -6
- package/src/langgraph/__tests__/middleware.test.ts +114 -0
- package/src/langgraph/middleware.ts +80 -8
|
@@ -30,223 +30,280 @@ interface StandardSerializableSchema<Input, Output = Input> {
|
|
|
30
30
|
}
|
|
31
31
|
declare const CopilotKitPropertiesAnnotation: _langchain_langgraph0.AnnotationRoot<{
|
|
32
32
|
actions: {
|
|
33
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
33
34
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
34
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
35
35
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
36
36
|
};
|
|
37
37
|
context: {
|
|
38
|
-
(): _langchain_langgraph0.LastValue<{
|
|
39
|
-
description: string;
|
|
40
|
-
value: string;
|
|
41
|
-
}[]>;
|
|
42
38
|
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
43
39
|
description: string;
|
|
44
40
|
value: string;
|
|
45
41
|
}[], {
|
|
46
42
|
description: string;
|
|
47
43
|
value: string;
|
|
48
|
-
}[]>): _langchain_langgraph0.
|
|
44
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
49
45
|
description: string;
|
|
50
46
|
value: string;
|
|
51
47
|
}[], {
|
|
52
48
|
description: string;
|
|
53
49
|
value: string;
|
|
50
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
51
|
+
description: string;
|
|
52
|
+
value: string;
|
|
53
|
+
}[]>, unknown>;
|
|
54
|
+
(): _langchain_langgraph0.LastValue<{
|
|
55
|
+
description: string;
|
|
56
|
+
value: string;
|
|
54
57
|
}[]>;
|
|
55
58
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
56
59
|
};
|
|
57
60
|
interceptedToolCalls: {
|
|
61
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
58
62
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
59
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
60
63
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
61
64
|
};
|
|
62
65
|
originalAIMessageId: {
|
|
66
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
63
67
|
(): _langchain_langgraph0.LastValue<string>;
|
|
64
|
-
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BinaryOperatorAggregate<string, string>;
|
|
65
68
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
66
69
|
};
|
|
67
70
|
}>;
|
|
68
71
|
declare const CopilotKitStateAnnotation: _langchain_langgraph0.AnnotationRoot<{
|
|
69
|
-
messages: _langchain_langgraph0.
|
|
72
|
+
messages: _langchain_langgraph0.BaseChannel<langchain.BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[], _langchain_langgraph0.OverwriteValue<langchain.BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[]> | _langchain_langgraph0.Messages, unknown>;
|
|
70
73
|
copilotkit: {
|
|
71
|
-
(
|
|
74
|
+
(annotation: _langchain_langgraph0.SingleReducer<_langchain_langgraph0.StateType<{
|
|
72
75
|
actions: {
|
|
76
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
73
77
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
74
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
75
78
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
76
79
|
};
|
|
77
80
|
context: {
|
|
78
|
-
(): _langchain_langgraph0.LastValue<{
|
|
79
|
-
description: string;
|
|
80
|
-
value: string;
|
|
81
|
-
}[]>;
|
|
82
81
|
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
83
82
|
description: string;
|
|
84
83
|
value: string;
|
|
85
84
|
}[], {
|
|
86
85
|
description: string;
|
|
87
86
|
value: string;
|
|
88
|
-
}[]>): _langchain_langgraph0.
|
|
87
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
89
88
|
description: string;
|
|
90
89
|
value: string;
|
|
91
90
|
}[], {
|
|
92
91
|
description: string;
|
|
93
92
|
value: string;
|
|
93
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
94
|
+
description: string;
|
|
95
|
+
value: string;
|
|
96
|
+
}[]>, unknown>;
|
|
97
|
+
(): _langchain_langgraph0.LastValue<{
|
|
98
|
+
description: string;
|
|
99
|
+
value: string;
|
|
94
100
|
}[]>;
|
|
95
101
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
96
102
|
};
|
|
97
103
|
interceptedToolCalls: {
|
|
104
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
98
105
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
99
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
100
106
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
101
107
|
};
|
|
102
108
|
originalAIMessageId: {
|
|
109
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
103
110
|
(): _langchain_langgraph0.LastValue<string>;
|
|
104
|
-
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BinaryOperatorAggregate<string, string>;
|
|
105
111
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
106
112
|
};
|
|
107
|
-
}
|
|
108
|
-
(annotation: _langchain_langgraph0.SingleReducer<_langchain_langgraph0.StateType<{
|
|
113
|
+
}>, _langchain_langgraph0.StateType<{
|
|
109
114
|
actions: {
|
|
115
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
110
116
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
111
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
112
117
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
113
118
|
};
|
|
114
119
|
context: {
|
|
120
|
+
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
121
|
+
description: string;
|
|
122
|
+
value: string;
|
|
123
|
+
}[], {
|
|
124
|
+
description: string;
|
|
125
|
+
value: string;
|
|
126
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
127
|
+
description: string;
|
|
128
|
+
value: string;
|
|
129
|
+
}[], {
|
|
130
|
+
description: string;
|
|
131
|
+
value: string;
|
|
132
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
133
|
+
description: string;
|
|
134
|
+
value: string;
|
|
135
|
+
}[]>, unknown>;
|
|
115
136
|
(): _langchain_langgraph0.LastValue<{
|
|
116
137
|
description: string;
|
|
117
138
|
value: string;
|
|
118
139
|
}[]>;
|
|
140
|
+
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
141
|
+
};
|
|
142
|
+
interceptedToolCalls: {
|
|
143
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
144
|
+
(): _langchain_langgraph0.LastValue<any[]>;
|
|
145
|
+
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
146
|
+
};
|
|
147
|
+
originalAIMessageId: {
|
|
148
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
149
|
+
(): _langchain_langgraph0.LastValue<string>;
|
|
150
|
+
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
151
|
+
};
|
|
152
|
+
}>>): _langchain_langgraph0.BaseChannel<_langchain_langgraph0.StateType<{
|
|
153
|
+
actions: {
|
|
154
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
155
|
+
(): _langchain_langgraph0.LastValue<any[]>;
|
|
156
|
+
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
157
|
+
};
|
|
158
|
+
context: {
|
|
119
159
|
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
120
160
|
description: string;
|
|
121
161
|
value: string;
|
|
122
162
|
}[], {
|
|
123
163
|
description: string;
|
|
124
164
|
value: string;
|
|
125
|
-
}[]>): _langchain_langgraph0.
|
|
165
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
126
166
|
description: string;
|
|
127
167
|
value: string;
|
|
128
168
|
}[], {
|
|
129
169
|
description: string;
|
|
130
170
|
value: string;
|
|
171
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
172
|
+
description: string;
|
|
173
|
+
value: string;
|
|
174
|
+
}[]>, unknown>;
|
|
175
|
+
(): _langchain_langgraph0.LastValue<{
|
|
176
|
+
description: string;
|
|
177
|
+
value: string;
|
|
131
178
|
}[]>;
|
|
132
179
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
133
180
|
};
|
|
134
181
|
interceptedToolCalls: {
|
|
182
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
135
183
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
136
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
137
184
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
138
185
|
};
|
|
139
186
|
originalAIMessageId: {
|
|
187
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
140
188
|
(): _langchain_langgraph0.LastValue<string>;
|
|
141
|
-
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BinaryOperatorAggregate<string, string>;
|
|
142
189
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
143
190
|
};
|
|
144
191
|
}>, _langchain_langgraph0.StateType<{
|
|
145
192
|
actions: {
|
|
193
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
146
194
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
147
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
148
195
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
149
196
|
};
|
|
150
197
|
context: {
|
|
151
|
-
(): _langchain_langgraph0.LastValue<{
|
|
152
|
-
description: string;
|
|
153
|
-
value: string;
|
|
154
|
-
}[]>;
|
|
155
198
|
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
156
199
|
description: string;
|
|
157
200
|
value: string;
|
|
158
201
|
}[], {
|
|
159
202
|
description: string;
|
|
160
203
|
value: string;
|
|
161
|
-
}[]>): _langchain_langgraph0.
|
|
204
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
162
205
|
description: string;
|
|
163
206
|
value: string;
|
|
164
207
|
}[], {
|
|
165
208
|
description: string;
|
|
166
209
|
value: string;
|
|
210
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
211
|
+
description: string;
|
|
212
|
+
value: string;
|
|
213
|
+
}[]>, unknown>;
|
|
214
|
+
(): _langchain_langgraph0.LastValue<{
|
|
215
|
+
description: string;
|
|
216
|
+
value: string;
|
|
167
217
|
}[]>;
|
|
168
218
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
169
219
|
};
|
|
170
220
|
interceptedToolCalls: {
|
|
221
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
171
222
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
172
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
173
223
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
174
224
|
};
|
|
175
225
|
originalAIMessageId: {
|
|
226
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
176
227
|
(): _langchain_langgraph0.LastValue<string>;
|
|
177
|
-
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BinaryOperatorAggregate<string, string>;
|
|
178
228
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
179
229
|
};
|
|
180
|
-
}
|
|
230
|
+
}> | _langchain_langgraph0.OverwriteValue<_langchain_langgraph0.StateType<{
|
|
181
231
|
actions: {
|
|
232
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
182
233
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
183
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
184
234
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
185
235
|
};
|
|
186
236
|
context: {
|
|
187
|
-
(): _langchain_langgraph0.LastValue<{
|
|
188
|
-
description: string;
|
|
189
|
-
value: string;
|
|
190
|
-
}[]>;
|
|
191
237
|
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
192
238
|
description: string;
|
|
193
239
|
value: string;
|
|
194
240
|
}[], {
|
|
195
241
|
description: string;
|
|
196
242
|
value: string;
|
|
197
|
-
}[]>): _langchain_langgraph0.
|
|
243
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
198
244
|
description: string;
|
|
199
245
|
value: string;
|
|
200
246
|
}[], {
|
|
201
247
|
description: string;
|
|
202
248
|
value: string;
|
|
249
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
250
|
+
description: string;
|
|
251
|
+
value: string;
|
|
252
|
+
}[]>, unknown>;
|
|
253
|
+
(): _langchain_langgraph0.LastValue<{
|
|
254
|
+
description: string;
|
|
255
|
+
value: string;
|
|
203
256
|
}[]>;
|
|
204
257
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
205
258
|
};
|
|
206
259
|
interceptedToolCalls: {
|
|
260
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
207
261
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
208
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
209
262
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
210
263
|
};
|
|
211
264
|
originalAIMessageId: {
|
|
265
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
212
266
|
(): _langchain_langgraph0.LastValue<string>;
|
|
213
|
-
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BinaryOperatorAggregate<string, string>;
|
|
214
267
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
215
268
|
};
|
|
216
|
-
}
|
|
269
|
+
}>>, unknown>;
|
|
270
|
+
(): _langchain_langgraph0.LastValue<_langchain_langgraph0.StateType<{
|
|
217
271
|
actions: {
|
|
272
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
218
273
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
219
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
220
274
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
221
275
|
};
|
|
222
276
|
context: {
|
|
223
|
-
(): _langchain_langgraph0.LastValue<{
|
|
224
|
-
description: string;
|
|
225
|
-
value: string;
|
|
226
|
-
}[]>;
|
|
227
277
|
(annotation: _langchain_langgraph0.SingleReducer<{
|
|
228
278
|
description: string;
|
|
229
279
|
value: string;
|
|
230
280
|
}[], {
|
|
231
281
|
description: string;
|
|
232
282
|
value: string;
|
|
233
|
-
}[]>): _langchain_langgraph0.
|
|
283
|
+
}[]>): _langchain_langgraph0.BaseChannel<{
|
|
234
284
|
description: string;
|
|
235
285
|
value: string;
|
|
236
286
|
}[], {
|
|
237
287
|
description: string;
|
|
238
288
|
value: string;
|
|
289
|
+
}[] | _langchain_langgraph0.OverwriteValue<{
|
|
290
|
+
description: string;
|
|
291
|
+
value: string;
|
|
292
|
+
}[]>, unknown>;
|
|
293
|
+
(): _langchain_langgraph0.LastValue<{
|
|
294
|
+
description: string;
|
|
295
|
+
value: string;
|
|
239
296
|
}[]>;
|
|
240
297
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
241
298
|
};
|
|
242
299
|
interceptedToolCalls: {
|
|
300
|
+
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BaseChannel<any[], any[] | _langchain_langgraph0.OverwriteValue<any[]>, unknown>;
|
|
243
301
|
(): _langchain_langgraph0.LastValue<any[]>;
|
|
244
|
-
(annotation: _langchain_langgraph0.SingleReducer<any[], any[]>): _langchain_langgraph0.BinaryOperatorAggregate<any[], any[]>;
|
|
245
302
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
246
303
|
};
|
|
247
304
|
originalAIMessageId: {
|
|
305
|
+
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BaseChannel<string, string | _langchain_langgraph0.OverwriteValue<string>, unknown>;
|
|
248
306
|
(): _langchain_langgraph0.LastValue<string>;
|
|
249
|
-
(annotation: _langchain_langgraph0.SingleReducer<string, string>): _langchain_langgraph0.BinaryOperatorAggregate<string, string>;
|
|
250
307
|
Root: <S extends _langchain_langgraph0.StateDefinition>(sd: S) => _langchain_langgraph0.AnnotationRoot<S>;
|
|
251
308
|
};
|
|
252
309
|
}>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/langgraph/types.ts"],"mappings":";;;;;UAEiB,0BAAA,iBAA2C,KAAA;EAAA,SACjD,WAAA;IAAA,SACE,OAAA;IAAA,SACA,MAAA;IAAA,SACA,QAAA,GACP,KAAA;MACK,KAAA,EAAO,MAAA;IAAA;MAAa,MAAA,EAAQ,aAAA;QAAgB,OAAA;MAAA;IAAA;IAAA,SAC1C,KAAA;MAAA,SAAmB,KAAA,EAAO,KAAA;MAAA,SAAgB,MAAA,EAAQ,MAAA;IAAA;IAAA,SAClD,UAAA;MAAA,SACE,KAAA,GAAQ,OAAA;QAAW,MAAA;MAAA,MAAqB,MAAA;MAAA,SACxC,MAAA,GAAS,OAAA;QAAW,MAAA;MAAA,MAAqB,MAAA;IAAA;EAAA;AAAA;AAAA,cAK3C,8BAAA,wBAA8B,cAAA;;
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/langgraph/types.ts"],"mappings":";;;;;UAEiB,0BAAA,iBAA2C,KAAA;EAAA,SACjD,WAAA;IAAA,SACE,OAAA;IAAA,SACA,MAAA;IAAA,SACA,QAAA,GACP,KAAA;MACK,KAAA,EAAO,MAAA;IAAA;MAAa,MAAA,EAAQ,aAAA;QAAgB,OAAA;MAAA;IAAA;IAAA,SAC1C,KAAA;MAAA,SAAmB,KAAA,EAAO,KAAA;MAAA,SAAgB,MAAA,EAAQ,MAAA;IAAA;IAAA,SAClD,UAAA;MAAA,SACE,KAAA,GAAQ,OAAA;QAAW,MAAA;MAAA,MAAqB,MAAA;MAAA,SACxC,MAAA,GAAS,OAAA;QAAW,MAAA;MAAA,MAAqB,MAAA;IAAA;EAAA;AAAA;AAAA,cAK3C,8BAAA,wBAA8B,cAAA;;iBAKzC,qBAAA,CAAA,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEW,yBAAA,wBAAyB,cAAA;+GAGpC,yBAAA,CAAA,cAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4BW,0BAAA,EAA4B,0BAAA,QAChC,8BAAA,CAA+B,KAAA;AAAA,UAevB,uBAAA;EACf,QAAA;EACA,IAAA;EACA,YAAA;AAAA;AAAA,UAGe,aAAA;EACf,aAAA;EACA,YAAA;EACA,OAAA;EACA,qBAAA,GAAwB,uBAAA;AAAA;AAAA,KAGd,eAAA,UAAyB,yBAAA,CAA0B,KAAA;AAAA,KACnD,oBAAA,UAA8B,8BAAA,CAA+B,KAAA"}
|
package/dist/langgraph.cjs
CHANGED
|
@@ -17,4 +17,5 @@ exports.copilotkitEmitState = require_utils.copilotkitEmitState;
|
|
|
17
17
|
exports.copilotkitEmitToolCall = require_utils.copilotkitEmitToolCall;
|
|
18
18
|
exports.copilotkitExit = require_utils.copilotkitExit;
|
|
19
19
|
exports.copilotkitMiddleware = require_middleware.copilotkitMiddleware;
|
|
20
|
-
exports.createCopilotkitMiddleware = require_middleware.createCopilotkitMiddleware;
|
|
20
|
+
exports.createCopilotkitMiddleware = require_middleware.createCopilotkitMiddleware;
|
|
21
|
+
exports.zodState = require_middleware.zodState;
|
package/dist/langgraph.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitState, CopilotKitStateAnnotation, IntermediateStateConfig, OptionsConfig, StandardSerializableSchema } from "./langgraph/types.cjs";
|
|
2
2
|
import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.cjs";
|
|
3
|
-
import { ExposeStateOption, copilotkitMiddleware, createCopilotkitMiddleware } from "./langgraph/middleware.cjs";
|
|
3
|
+
import { ExposeStateOption, copilotkitMiddleware, createCopilotkitMiddleware, zodState } from "./langgraph/middleware.cjs";
|
|
4
4
|
import { CopilotKitSchemaState, CopilotKitSchemaUpdate, CopilotKitStateSchema } from "./langgraph/state-schema.cjs";
|
|
5
|
-
export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitSchemaState, CopilotKitSchemaUpdate, CopilotKitState, CopilotKitStateAnnotation, CopilotKitStateSchema, ExposeStateOption, IntermediateStateConfig, OptionsConfig, StandardSerializableSchema, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware, createCopilotkitMiddleware };
|
|
5
|
+
export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitSchemaState, CopilotKitSchemaUpdate, CopilotKitState, CopilotKitStateAnnotation, CopilotKitStateSchema, ExposeStateOption, IntermediateStateConfig, OptionsConfig, StandardSerializableSchema, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware, createCopilotkitMiddleware, zodState };
|
package/dist/langgraph.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitState, CopilotKitStateAnnotation, IntermediateStateConfig, OptionsConfig, StandardSerializableSchema } from "./langgraph/types.mjs";
|
|
2
2
|
import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.mjs";
|
|
3
|
-
import { ExposeStateOption, copilotkitMiddleware, createCopilotkitMiddleware } from "./langgraph/middleware.mjs";
|
|
3
|
+
import { ExposeStateOption, copilotkitMiddleware, createCopilotkitMiddleware, zodState } from "./langgraph/middleware.mjs";
|
|
4
4
|
import { CopilotKitSchemaState, CopilotKitSchemaUpdate, CopilotKitStateSchema } from "./langgraph/state-schema.mjs";
|
|
5
|
-
export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitSchemaState, CopilotKitSchemaUpdate, CopilotKitState, CopilotKitStateAnnotation, CopilotKitStateSchema, ExposeStateOption, IntermediateStateConfig, OptionsConfig, StandardSerializableSchema, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware, createCopilotkitMiddleware };
|
|
5
|
+
export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitSchemaState, CopilotKitSchemaUpdate, CopilotKitState, CopilotKitStateAnnotation, CopilotKitStateSchema, ExposeStateOption, IntermediateStateConfig, OptionsConfig, StandardSerializableSchema, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware, createCopilotkitMiddleware, zodState };
|
package/dist/langgraph.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitStateAnnotation } from "./langgraph/types.mjs";
|
|
2
2
|
import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.mjs";
|
|
3
|
-
import { copilotkitMiddleware, createCopilotkitMiddleware } from "./langgraph/middleware.mjs";
|
|
3
|
+
import { copilotkitMiddleware, createCopilotkitMiddleware, zodState } from "./langgraph/middleware.mjs";
|
|
4
4
|
import { CopilotKitStateSchema } from "./langgraph/state-schema.mjs";
|
|
5
5
|
|
|
6
|
-
export { CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitStateAnnotation, CopilotKitStateSchema, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware, createCopilotkitMiddleware };
|
|
6
|
+
export { CopilotKitPropertiesAnnotation, CopilotKitPropertiesSchema, CopilotKitStateAnnotation, CopilotKitStateSchema, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware, createCopilotkitMiddleware, zodState };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/sdk-js",
|
|
3
|
-
"version": "1.56.
|
|
3
|
+
"version": "1.56.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@ag-ui/langgraph": "0.0.
|
|
52
|
-
"@copilotkit/shared": "1.56.
|
|
51
|
+
"@ag-ui/langgraph": "0.0.31",
|
|
52
|
+
"@copilotkit/shared": "1.56.5"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@langchain/core": "^1.1.
|
|
56
|
-
"@langchain/langgraph": "^1.
|
|
55
|
+
"@langchain/core": "^1.1.41",
|
|
56
|
+
"@langchain/langgraph": "^1.2.9",
|
|
57
57
|
"@swc/core": "1.5.28",
|
|
58
58
|
"@types/express": "^4.17.21",
|
|
59
59
|
"@types/node": "^18.11.17",
|
|
60
60
|
"@whatwg-node/server": "^0.9.34",
|
|
61
61
|
"eslint": "^8.56.0",
|
|
62
|
-
"langchain": "^1.
|
|
62
|
+
"langchain": "^1.3.4",
|
|
63
63
|
"nodemon": "^3.1.3",
|
|
64
64
|
"ts-node": "^10.9.2",
|
|
65
65
|
"tsdown": "^0.20.3",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { describe, it, expect } from "vitest";
|
|
21
|
+
import * as z from "zod";
|
|
21
22
|
import {
|
|
22
23
|
AIMessage,
|
|
23
24
|
HumanMessage,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
import {
|
|
28
29
|
copilotkitMiddleware,
|
|
29
30
|
createCopilotkitMiddleware,
|
|
31
|
+
zodState,
|
|
30
32
|
} from "../middleware";
|
|
31
33
|
|
|
32
34
|
// ---------------------------------------------------------------------------
|
|
@@ -495,3 +497,115 @@ describe("afterAgent", () => {
|
|
|
495
497
|
expect(result!.copilotkit.originalAIMessageId).toBeUndefined();
|
|
496
498
|
});
|
|
497
499
|
});
|
|
500
|
+
|
|
501
|
+
// ---------------------------------------------------------------------------
|
|
502
|
+
// zodState — Standard-Schema JSON-schema augmentation
|
|
503
|
+
// ---------------------------------------------------------------------------
|
|
504
|
+
//
|
|
505
|
+
// Contract: a Zod v4 schema only carries `~standard.validate` + `vendor`, so
|
|
506
|
+
// LangGraph's `isStandardJSONSchema()` returns false and the field is dropped
|
|
507
|
+
// from `output_schema`. `zodState` patches `~standard.jsonSchema.input` onto
|
|
508
|
+
// the schema so the field survives serialization and reaches the frontend
|
|
509
|
+
// via AG-UI `STATE_SNAPSHOT` events.
|
|
510
|
+
|
|
511
|
+
type JsonSchema = {
|
|
512
|
+
type?: string;
|
|
513
|
+
properties?: Record<string, unknown>;
|
|
514
|
+
};
|
|
515
|
+
type StdJson = { jsonSchema?: { input: () => JsonSchema } };
|
|
516
|
+
const standardOf = (s: object): StdJson | undefined =>
|
|
517
|
+
(s as { "~standard"?: StdJson })["~standard"];
|
|
518
|
+
const hasZodV4ToJsonSchema = (): boolean =>
|
|
519
|
+
typeof (z as { toJSONSchema?: unknown }).toJSONSchema === "function";
|
|
520
|
+
|
|
521
|
+
describe("zodState", () => {
|
|
522
|
+
it("attaches a ~standard.jsonSchema.input hook to a Zod schema", () => {
|
|
523
|
+
const schema = z.object({ name: z.string() });
|
|
524
|
+
expect(standardOf(schema)?.jsonSchema).toBeUndefined();
|
|
525
|
+
|
|
526
|
+
const wrapped = zodState(schema);
|
|
527
|
+
|
|
528
|
+
const std = standardOf(wrapped);
|
|
529
|
+
expect(std?.jsonSchema).toBeDefined();
|
|
530
|
+
expect(typeof std?.jsonSchema?.input).toBe("function");
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("returns a plain object from input() (real JSON Schema when zod v4 is available, else `{}`)", () => {
|
|
534
|
+
// The contract langgraph cares about is just "input() returns an
|
|
535
|
+
// object" — `isStandardJSONSchema()` doesn't introspect the shape.
|
|
536
|
+
// When zod v4's `toJSONSchema` is present we get the real schema;
|
|
537
|
+
// otherwise we get `{}`, which is still enough for the field to
|
|
538
|
+
// appear in `output_schema` (langgraph-api treats it as opaque).
|
|
539
|
+
const schema = z.object({ todos: z.array(z.string()) });
|
|
540
|
+
const wrapped = zodState(schema);
|
|
541
|
+
|
|
542
|
+
const json = standardOf(wrapped)?.jsonSchema?.input();
|
|
543
|
+
|
|
544
|
+
expect(json).toBeTypeOf("object");
|
|
545
|
+
expect(json).not.toBeNull();
|
|
546
|
+
if (hasZodV4ToJsonSchema()) {
|
|
547
|
+
expect(json?.type).toBe("object");
|
|
548
|
+
expect(json?.properties?.todos).toBeDefined();
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it("caches the JSON Schema across calls (input() returns the same object)", () => {
|
|
553
|
+
const schema = z.object({ x: z.string() });
|
|
554
|
+
const wrapped = zodState(schema);
|
|
555
|
+
const std = standardOf(wrapped);
|
|
556
|
+
|
|
557
|
+
const a = std?.jsonSchema?.input();
|
|
558
|
+
const b = std?.jsonSchema?.input();
|
|
559
|
+
|
|
560
|
+
expect(a).toBe(b);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
it("does not overwrite an existing jsonSchema hook", () => {
|
|
564
|
+
const schema = z.object({ x: z.string() });
|
|
565
|
+
const preset: StdJson["jsonSchema"] = { input: () => ({}) };
|
|
566
|
+
const std = standardOf(schema);
|
|
567
|
+
expect(std).toBeDefined();
|
|
568
|
+
std!.jsonSchema = preset;
|
|
569
|
+
|
|
570
|
+
zodState(schema);
|
|
571
|
+
|
|
572
|
+
expect(standardOf(schema)?.jsonSchema).toBe(preset);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it("returns the same reference (mutates rather than copies)", () => {
|
|
576
|
+
const schema = z.object({ x: z.string() });
|
|
577
|
+
expect(zodState(schema)).toBe(schema);
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("is a no-op for a value without ~standard metadata", () => {
|
|
581
|
+
const plain = { foo: "bar" };
|
|
582
|
+
expect(() => zodState(plain)).not.toThrow();
|
|
583
|
+
expect(zodState(plain)).toBe(plain);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it("works on optional / array / default-wrapped schemas (state-field shapes)", () => {
|
|
587
|
+
const todos = zodState(
|
|
588
|
+
z.array(z.object({ id: z.string(), text: z.string() })).default(() => []),
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
const std = standardOf(todos);
|
|
592
|
+
expect(std).toBeDefined();
|
|
593
|
+
expect(std?.jsonSchema).toBeDefined();
|
|
594
|
+
const json = std?.jsonSchema?.input();
|
|
595
|
+
expect(json).toBeTypeOf("object");
|
|
596
|
+
if (hasZodV4ToJsonSchema()) {
|
|
597
|
+
expect(json?.type).toBe("array");
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it("makes the wrapped field pass a StandardJSONSchemaV1-style probe", () => {
|
|
602
|
+
// Mirrors what LangGraph's isStandardJSONSchema() looks for: an `input`
|
|
603
|
+
// function on `~standard.jsonSchema` that returns a plain object.
|
|
604
|
+
const schema = zodState(z.object({ liked: z.array(z.string()) }));
|
|
605
|
+
const std = standardOf(schema);
|
|
606
|
+
|
|
607
|
+
expect(std?.jsonSchema).toBeDefined();
|
|
608
|
+
expect(typeof std?.jsonSchema?.input).toBe("function");
|
|
609
|
+
expect(typeof std?.jsonSchema?.input()).toBe("object");
|
|
610
|
+
});
|
|
611
|
+
});
|
|
@@ -1,7 +1,77 @@
|
|
|
1
1
|
import { createMiddleware, AIMessage, SystemMessage } from "langchain";
|
|
2
2
|
import type { InteropZodObject } from "@langchain/core/utils/types";
|
|
3
|
+
import type {
|
|
4
|
+
StandardJSONSchemaV1,
|
|
5
|
+
StandardSchemaV1,
|
|
6
|
+
} from "@standard-schema/spec";
|
|
3
7
|
import * as z from "zod";
|
|
4
8
|
|
|
9
|
+
type WithJsonSchema<T> = T extends { "~standard": infer S }
|
|
10
|
+
? Omit<T, "~standard"> & {
|
|
11
|
+
"~standard": S &
|
|
12
|
+
StandardJSONSchemaV1.Props<
|
|
13
|
+
S extends StandardSchemaV1.Props<infer I, any> ? I : unknown,
|
|
14
|
+
S extends StandardSchemaV1.Props<any, infer O> ? O : unknown
|
|
15
|
+
>;
|
|
16
|
+
}
|
|
17
|
+
: T;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Augment a Standard-Schema–compatible schema (e.g. Zod) with a
|
|
21
|
+
* `~standard.jsonSchema.input` hook so LangGraph's
|
|
22
|
+
* `getJsonSchemaFromSchema` (called from `StateSchema.getJsonSchema`)
|
|
23
|
+
* can serialize the field.
|
|
24
|
+
*
|
|
25
|
+
* Without this, Zod v4 fields carry `~standard.validate` + `vendor` only,
|
|
26
|
+
* and `isStandardJSONSchema()` returns false, so the field is silently
|
|
27
|
+
* dropped from the graph's `output_schema`. That makes AG-UI
|
|
28
|
+
* `STATE_SNAPSHOT` events filter the field out of the payload sent to
|
|
29
|
+
* the frontend even though the underlying thread state has the value.
|
|
30
|
+
*
|
|
31
|
+
* Use this on any custom state field you want visible to the frontend
|
|
32
|
+
* via `useAgent().state.*`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { zodState } from "@copilotkit/sdk-js/langgraph";
|
|
37
|
+
*
|
|
38
|
+
* const stateSchema = z.object({
|
|
39
|
+
* todos: zodState(z.array(TodoSchema).default(() => [])),
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function zodState<T extends object>(schema: T): WithJsonSchema<T> {
|
|
44
|
+
const std = (schema as { "~standard"?: { jsonSchema?: unknown } })[
|
|
45
|
+
"~standard"
|
|
46
|
+
];
|
|
47
|
+
if (std && typeof std === "object" && !("jsonSchema" in std)) {
|
|
48
|
+
let cached: Record<string, unknown> | undefined;
|
|
49
|
+
std.jsonSchema = {
|
|
50
|
+
input: () => {
|
|
51
|
+
if (cached) return cached;
|
|
52
|
+
// Prefer zod-v4's native `toJSONSchema` when available. Falls back to
|
|
53
|
+
// an empty object, which is sufficient for the field to appear in the
|
|
54
|
+
// graph's output_schema (langgraph-api treats it as an opaque field).
|
|
55
|
+
try {
|
|
56
|
+
const maybeV4ToJsonSchema = (
|
|
57
|
+
z as unknown as {
|
|
58
|
+
toJSONSchema?: (s: unknown) => Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
).toJSONSchema;
|
|
61
|
+
cached =
|
|
62
|
+
typeof maybeV4ToJsonSchema === "function"
|
|
63
|
+
? maybeV4ToJsonSchema(schema)
|
|
64
|
+
: {};
|
|
65
|
+
} catch {
|
|
66
|
+
cached = {};
|
|
67
|
+
}
|
|
68
|
+
return cached;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return schema as WithJsonSchema<T>;
|
|
73
|
+
}
|
|
74
|
+
|
|
5
75
|
/**
|
|
6
76
|
* Internal/framework state keys that should never be auto-surfaced to the
|
|
7
77
|
* LLM as user-facing state. These are reducer-managed message buckets,
|
|
@@ -215,14 +285,16 @@ const createAppContextBeforeAgent = (state, runtime) => {
|
|
|
215
285
|
* ```
|
|
216
286
|
*/
|
|
217
287
|
const copilotKitStateSchema = z.object({
|
|
218
|
-
copilotkit:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
288
|
+
copilotkit: zodState(
|
|
289
|
+
z
|
|
290
|
+
.object({
|
|
291
|
+
actions: z.array(z.any()),
|
|
292
|
+
context: z.any().optional(),
|
|
293
|
+
interceptedToolCalls: z.array(z.any()).optional(),
|
|
294
|
+
originalAIMessageId: z.string().optional(),
|
|
295
|
+
})
|
|
296
|
+
.optional(),
|
|
297
|
+
),
|
|
226
298
|
});
|
|
227
299
|
|
|
228
300
|
const buildMiddlewareInput = (exposeState: ExposeStateOption) => ({
|