@@ -81,10 +81,10 @@ export const RESERVED = [
81
81
export const CHECKPOINT_NAMESPACE_SEPARATOR = "|" ;
82
82
export const CHECKPOINT_NAMESPACE_END = ":" ;
83
83
84
- export interface SendInterface {
85
- node : string ;
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- args : any ;
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ export interface SendInterface < Node extends string = string , Args = any > {
86
+ node : Node ;
87
+ args : Args ;
88
88
}
89
89
90
90
export function _isSendInterface ( x : unknown ) : x is SendInterface {
@@ -143,26 +143,23 @@ export function _isSendInterface(x: unknown): x is SendInterface {
143
143
* // { subjects: ["cats", "dogs"], jokes: [`Joke about cats`, `Joke about dogs`] }
144
144
* ```
145
145
*/
146
- export class Send implements SendInterface {
146
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
+ export class Send < Node extends string = string , Args = any >
148
+ implements SendInterface < Node , Args >
149
+ {
147
150
lg_name = "Send" ;
148
151
149
- public node : string ;
152
+ public node : Node ;
150
153
151
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
- public args : any ;
154
+ public args : Args ;
153
155
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
- constructor ( node : string , args : any ) {
156
+ constructor ( node : Node , args : Args ) {
156
157
this . node = node ;
157
- this . args = _deserializeCommandSendObjectGraph ( args ) ;
158
+ this . args = _deserializeCommandSendObjectGraph ( args ) as Args ;
158
159
}
159
160
160
161
toJSON ( ) {
161
- return {
162
- lg_name : this . lg_name ,
163
- node : this . node ,
164
- args : this . args ,
165
- } ;
162
+ return { lg_name : this . lg_name , node : this . node , args : this . args } ;
166
163
}
167
164
}
168
165
@@ -180,7 +177,11 @@ export type Interrupt = {
180
177
ns ?: string [ ] ;
181
178
} ;
182
179
183
- export type CommandParams < R > = {
180
+ export type CommandParams <
181
+ Resume = unknown ,
182
+ Update extends Record < string , unknown > = Record < string , unknown > ,
183
+ Nodes extends string = string
184
+ > = {
184
185
/**
185
186
* A discriminator field used to identify the type of object. Must be populated when serializing.
186
187
*
@@ -192,7 +193,7 @@ export type CommandParams<R> = {
192
193
/**
193
194
* Value to resume execution with. To be used together with {@link interrupt}.
194
195
*/
195
- resume ?: R ;
196
+ resume ?: Resume ;
196
197
/**
197
198
* Graph to send the command to. Supported values are:
198
199
* - None: the current graph (default)
@@ -204,7 +205,7 @@ export type CommandParams<R> = {
204
205
/**
205
206
* Update to apply to the graph's state.
206
207
*/
207
- update ?: Record < string , unknown > | [ string , unknown ] [ ] ;
208
+ update ?: Update | [ string , unknown ] [ ] ;
208
209
209
210
/**
210
211
* Can be one of the following:
@@ -213,7 +214,10 @@ export type CommandParams<R> = {
213
214
* - `Send` object (to execute a node with the input provided)
214
215
* - sequence of `Send` objects
215
216
*/
216
- goto ?: string | SendInterface | ( string | SendInterface ) [ ] ;
217
+ goto ?:
218
+ | Nodes
219
+ | SendInterface < Nodes > // eslint-disable-line @typescript-eslint/no-explicit-any
220
+ | ( Nodes | SendInterface < Nodes > ) [ ] ; // eslint-disable-line @typescript-eslint/no-explicit-any
217
221
} ;
218
222
219
223
/**
@@ -278,7 +282,11 @@ export type CommandParams<R> = {
278
282
* // { foo: 'a|c' } and { foo: 'a|b' }
279
283
* ```
280
284
*/
281
- export class Command < R = unknown > {
285
+ export class Command <
286
+ Resume = unknown ,
287
+ Update extends Record < string , unknown > = Record < string , unknown > ,
288
+ Nodes extends string = string
289
+ > {
282
290
readonly lg_name = "Command" ;
283
291
284
292
lc_direct_tool_output = true ;
@@ -295,12 +303,12 @@ export class Command<R = unknown> {
295
303
* Update to apply to the graph's state as a result of executing the node that is returning the command.
296
304
* Written to the state as if the node had simply returned this value instead of the Command object.
297
305
*/
298
- update ?: Record < string , unknown > | [ string , unknown ] [ ] ;
306
+ update ?: Update | [ string , unknown ] [ ] ;
299
307
300
308
/**
301
309
* Value to resume execution with. To be used together with {@link interrupt}.
302
310
*/
303
- resume ?: R ;
311
+ resume ?: Resume ;
304
312
305
313
/**
306
314
* Can be one of the following:
@@ -309,18 +317,20 @@ export class Command<R = unknown> {
309
317
* - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)
310
318
* - sequence of {@link Send} objects
311
319
*/
312
- goto ?: string | Send | ( string | Send ) [ ] = [ ] ;
320
+ goto ?: Nodes | Send < Nodes > | ( Nodes | Send < Nodes > ) [ ] = [ ] ;
313
321
314
322
static PARENT = "__parent__" ;
315
323
316
- constructor ( args : CommandParams < R > ) {
324
+ constructor ( args : CommandParams < Resume , Update , Nodes > ) {
317
325
this . resume = args . resume ;
318
326
this . graph = args . graph ;
319
327
this . update = args . update ;
320
328
if ( args . goto ) {
329
+ type ValidArg = Nodes | Send < Nodes , Update > ;
330
+
321
331
this . goto = Array . isArray ( args . goto )
322
- ? ( _deserializeCommandSendObjectGraph ( args . goto ) as ( string | Send ) [ ] )
323
- : [ _deserializeCommandSendObjectGraph ( args . goto ) as string | Send ] ;
332
+ ? ( _deserializeCommandSendObjectGraph ( args . goto ) as ValidArg [ ] )
333
+ : [ _deserializeCommandSendObjectGraph ( args . goto ) as ValidArg ] ;
324
334
}
325
335
}
326
336
0 commit comments