@avaprotocol/sdk-js 2.1.1 → 2.2.0
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/CHANGELOG.md +11 -0
- package/dist/index.d.ts +39 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +264 -27
- package/dist/index.mjs +268 -29
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @avaprotocol/sdk-js
|
|
2
2
|
|
|
3
|
+
## 2.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 52a1d86: Added timeout option and strategy to the client
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [52a1d86]
|
|
12
|
+
- @avaprotocol/types@2.1.0
|
|
13
|
+
|
|
3
14
|
## 2.1.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import Step from "./models/step";
|
|
|
8
8
|
import NodeFactory from "./models/node/factory";
|
|
9
9
|
import TriggerFactory from "./models/trigger/factory";
|
|
10
10
|
import Secret from "./models/secret";
|
|
11
|
-
import { type WorkflowProps, type GetKeyResponse, type RequestOptions, type ClientOption, type SmartWallet, type GetWalletRequest, type GetExecutionsOptions, type GetWorkflowsOptions, type GetSignatureFormatResponse, type RunNodeWithInputsRequest, type RunNodeWithInputsResponse, type RunTriggerRequest, type RunTriggerResponse, type SecretProps, type PageInfo, type GetSecretsOptions, type SecretOptions, type TriggerDataProps, type SimulateWorkflowRequest, type ExecutionProps, type GetTokenMetadataRequest, type GetTokenMetadataResponse } from "@avaprotocol/types";
|
|
11
|
+
import { type WorkflowProps, type GetKeyResponse, type RequestOptions, type ClientOption, type SmartWallet, type GetWalletRequest, type GetExecutionsOptions, type GetWorkflowsOptions, type GetSignatureFormatResponse, type RunNodeWithInputsRequest, type RunNodeWithInputsResponse, type RunTriggerRequest, type RunTriggerResponse, type SecretProps, type PageInfo, type GetSecretsOptions, type SecretOptions, type TriggerDataProps, type SimulateWorkflowRequest, type ExecutionProps, type GetTokenMetadataRequest, type GetTokenMetadataResponse, type TimeoutConfig } from "@avaprotocol/types";
|
|
12
12
|
import { ExecutionStatus } from "@/grpc_codegen/avs_pb";
|
|
13
13
|
declare class BaseClient {
|
|
14
14
|
readonly endpoint: string;
|
|
@@ -16,7 +16,42 @@ declare class BaseClient {
|
|
|
16
16
|
protected metadata: Metadata;
|
|
17
17
|
protected factoryAddress?: string;
|
|
18
18
|
protected authKey?: string;
|
|
19
|
+
protected timeoutConfig: TimeoutConfig;
|
|
19
20
|
constructor(opts: ClientOption);
|
|
21
|
+
/**
|
|
22
|
+
* Set default timeout configuration for all requests
|
|
23
|
+
* @param config - The timeout configuration
|
|
24
|
+
*/
|
|
25
|
+
setTimeoutConfig(config: TimeoutConfig): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the current timeout configuration
|
|
28
|
+
* @returns {TimeoutConfig} - The current timeout configuration
|
|
29
|
+
*/
|
|
30
|
+
getTimeoutConfig(): TimeoutConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Send a fast gRPC request using FAST preset (5s timeout, 2 retries)
|
|
33
|
+
* @param method - The method name to call
|
|
34
|
+
* @param request - The request object
|
|
35
|
+
* @param options - Request options
|
|
36
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
37
|
+
*/
|
|
38
|
+
protected sendFastRequest<TResponse, TRequest>(method: string, request: TRequest | any, options?: RequestOptions): Promise<TResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Send a slow gRPC request using SLOW preset (2min timeout, 2 retries)
|
|
41
|
+
* @param method - The method name to call
|
|
42
|
+
* @param request - The request object
|
|
43
|
+
* @param options - Request options
|
|
44
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
45
|
+
*/
|
|
46
|
+
protected sendSlowRequest<TResponse, TRequest>(method: string, request: TRequest | any, options?: RequestOptions): Promise<TResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Send a no-retry gRPC request using NO_RETRY preset (30s timeout, no retries)
|
|
49
|
+
* @param method - The method name to call
|
|
50
|
+
* @param request - The request object
|
|
51
|
+
* @param options - Request options
|
|
52
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
53
|
+
*/
|
|
54
|
+
protected sendNoRetryRequest<TResponse, TRequest>(method: string, request: TRequest | any, options?: RequestOptions): Promise<TResponse>;
|
|
20
55
|
/**
|
|
21
56
|
* Check if the auth key is valid by decoding the JWT token and checking the expiration
|
|
22
57
|
* @param key - The auth key
|
|
@@ -71,10 +106,10 @@ declare class BaseClient {
|
|
|
71
106
|
*/
|
|
72
107
|
getFactoryAddress(): string | undefined;
|
|
73
108
|
/**
|
|
74
|
-
* Send a gRPC request with authentication and error handling
|
|
109
|
+
* Send a gRPC request with authentication, timeout support, and error handling
|
|
75
110
|
* @param method - The method name to call
|
|
76
111
|
* @param request - The request object
|
|
77
|
-
* @param options - Request options
|
|
112
|
+
* @param options - Request options including timeout configuration
|
|
78
113
|
* @returns {Promise<TResponse>} - The response from the server
|
|
79
114
|
*/
|
|
80
115
|
protected sendGrpcRequest<TResponse, TRequest>(method: string, request: TRequest | any, options?: RequestOptions): Promise<TResponse>;
|
|
@@ -302,4 +337,5 @@ export * from "./models/node/factory";
|
|
|
302
337
|
export * from "./models/trigger/factory";
|
|
303
338
|
export { Client, Workflow, Edge, Execution, Step, NodeFactory, TriggerFactory, Secret, };
|
|
304
339
|
export type { TokenMetadata, GetTokenMetadataRequest, GetTokenMetadataResponse, TokenSource } from "@avaprotocol/types";
|
|
340
|
+
export { TimeoutPresets, type TimeoutConfig, type TimeoutError } from "@avaprotocol/types";
|
|
305
341
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"m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GACvB,OAAO,CAAC,cAAc,CAAC;IAuC1B;;;;;;OAMG;IACG,gBAAgB,CACpB,EAAE,OAAO,EAAE,EAAE,uBAAuB,EACpC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,wBAAwB,CAAC;CAsBrC;AAED,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AAEzC,OAAO,EACL,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,WAAW,EACX,cAAc,EACd,MAAM,GACP,CAAC;AAGF,YAAY,EACV,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14894,6 +14894,7 @@ __export(index_exports, {
|
|
|
14894
14894
|
RestAPINode: () => restApi_default,
|
|
14895
14895
|
Secret: () => secret_default,
|
|
14896
14896
|
Step: () => step_default,
|
|
14897
|
+
TimeoutPresets: () => import_types21.TimeoutPresets,
|
|
14897
14898
|
Trigger: () => interface_default,
|
|
14898
14899
|
TriggerFactory: () => factory_default,
|
|
14899
14900
|
Workflow: () => workflow_default
|
|
@@ -16139,7 +16140,7 @@ var factory_default2 = NodeFactory;
|
|
|
16139
16140
|
|
|
16140
16141
|
// src/models/workflow.ts
|
|
16141
16142
|
var import_types19 = require("@avaprotocol/types");
|
|
16142
|
-
function convertStatusToString(
|
|
16143
|
+
function convertStatusToString(status2) {
|
|
16143
16144
|
const conversionMap = {
|
|
16144
16145
|
[avs_pb19.TaskStatus.ACTIVE]: import_types19.WorkflowStatus.Active,
|
|
16145
16146
|
[avs_pb19.TaskStatus.COMPLETED]: import_types19.WorkflowStatus.Completed,
|
|
@@ -16147,7 +16148,7 @@ function convertStatusToString(status) {
|
|
|
16147
16148
|
[avs_pb19.TaskStatus.CANCELED]: import_types19.WorkflowStatus.Canceled,
|
|
16148
16149
|
[avs_pb19.TaskStatus.EXECUTING]: import_types19.WorkflowStatus.Executing
|
|
16149
16150
|
};
|
|
16150
|
-
return conversionMap[
|
|
16151
|
+
return conversionMap[status2];
|
|
16151
16152
|
}
|
|
16152
16153
|
var Workflow = class _Workflow {
|
|
16153
16154
|
/**
|
|
@@ -16492,6 +16493,7 @@ var secret_default = Secret;
|
|
|
16492
16493
|
|
|
16493
16494
|
// src/index.ts
|
|
16494
16495
|
var import_types20 = require("@avaprotocol/types");
|
|
16496
|
+
var import_types21 = require("@avaprotocol/types");
|
|
16495
16497
|
var BaseClient = class {
|
|
16496
16498
|
constructor(opts) {
|
|
16497
16499
|
this.endpoint = opts.endpoint;
|
|
@@ -16500,8 +16502,67 @@ var BaseClient = class {
|
|
|
16500
16502
|
import_grpc_js.credentials.createInsecure()
|
|
16501
16503
|
);
|
|
16502
16504
|
this.factoryAddress = opts.factoryAddress;
|
|
16505
|
+
this.timeoutConfig = {
|
|
16506
|
+
timeout: 3e4,
|
|
16507
|
+
retries: 0,
|
|
16508
|
+
retryDelay: 0,
|
|
16509
|
+
...opts.timeout
|
|
16510
|
+
};
|
|
16503
16511
|
this.metadata = new import_grpc_js.Metadata();
|
|
16504
16512
|
}
|
|
16513
|
+
/**
|
|
16514
|
+
* Set default timeout configuration for all requests
|
|
16515
|
+
* @param config - The timeout configuration
|
|
16516
|
+
*/
|
|
16517
|
+
setTimeoutConfig(config) {
|
|
16518
|
+
this.timeoutConfig = { ...this.timeoutConfig, ...config };
|
|
16519
|
+
}
|
|
16520
|
+
/**
|
|
16521
|
+
* Get the current timeout configuration
|
|
16522
|
+
* @returns {TimeoutConfig} - The current timeout configuration
|
|
16523
|
+
*/
|
|
16524
|
+
getTimeoutConfig() {
|
|
16525
|
+
return { ...this.timeoutConfig };
|
|
16526
|
+
}
|
|
16527
|
+
/**
|
|
16528
|
+
* Send a fast gRPC request using FAST preset (5s timeout, 2 retries)
|
|
16529
|
+
* @param method - The method name to call
|
|
16530
|
+
* @param request - The request object
|
|
16531
|
+
* @param options - Request options
|
|
16532
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
16533
|
+
*/
|
|
16534
|
+
sendFastRequest(method, request, options) {
|
|
16535
|
+
return this.sendGrpcRequest(method, request, {
|
|
16536
|
+
...options,
|
|
16537
|
+
timeout: import_types20.TimeoutPresets.FAST
|
|
16538
|
+
});
|
|
16539
|
+
}
|
|
16540
|
+
/**
|
|
16541
|
+
* Send a slow gRPC request using SLOW preset (2min timeout, 2 retries)
|
|
16542
|
+
* @param method - The method name to call
|
|
16543
|
+
* @param request - The request object
|
|
16544
|
+
* @param options - Request options
|
|
16545
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
16546
|
+
*/
|
|
16547
|
+
sendSlowRequest(method, request, options) {
|
|
16548
|
+
return this.sendGrpcRequest(method, request, {
|
|
16549
|
+
...options,
|
|
16550
|
+
timeout: import_types20.TimeoutPresets.SLOW
|
|
16551
|
+
});
|
|
16552
|
+
}
|
|
16553
|
+
/**
|
|
16554
|
+
* Send a no-retry gRPC request using NO_RETRY preset (30s timeout, no retries)
|
|
16555
|
+
* @param method - The method name to call
|
|
16556
|
+
* @param request - The request object
|
|
16557
|
+
* @param options - Request options
|
|
16558
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
16559
|
+
*/
|
|
16560
|
+
sendNoRetryRequest(method, request, options) {
|
|
16561
|
+
return this.sendGrpcRequest(method, request, {
|
|
16562
|
+
...options,
|
|
16563
|
+
timeout: import_types20.TimeoutPresets.NO_RETRY
|
|
16564
|
+
});
|
|
16565
|
+
}
|
|
16505
16566
|
/**
|
|
16506
16567
|
* Check if the auth key is valid by decoding the JWT token and checking the expiration
|
|
16507
16568
|
* @param key - The auth key
|
|
@@ -16594,30 +16655,126 @@ var BaseClient = class {
|
|
|
16594
16655
|
return this.factoryAddress;
|
|
16595
16656
|
}
|
|
16596
16657
|
/**
|
|
16597
|
-
* Send a gRPC request with authentication and error handling
|
|
16658
|
+
* Send a gRPC request with authentication, timeout support, and error handling
|
|
16598
16659
|
* @param method - The method name to call
|
|
16599
16660
|
* @param request - The request object
|
|
16600
|
-
* @param options - Request options
|
|
16661
|
+
* @param options - Request options including timeout configuration
|
|
16601
16662
|
* @returns {Promise<TResponse>} - The response from the server
|
|
16602
16663
|
*/
|
|
16603
16664
|
sendGrpcRequest(method, request, options) {
|
|
16604
16665
|
return new Promise((resolve, reject) => {
|
|
16605
|
-
const
|
|
16606
|
-
|
|
16607
|
-
|
|
16608
|
-
|
|
16609
|
-
|
|
16610
|
-
|
|
16611
|
-
|
|
16612
|
-
|
|
16613
|
-
|
|
16614
|
-
if (
|
|
16615
|
-
|
|
16616
|
-
} else {
|
|
16617
|
-
resolve(response);
|
|
16666
|
+
const debugMode = process.env.GRPC_DEBUG === "true";
|
|
16667
|
+
if (debugMode) {
|
|
16668
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Starting ${method} request:`, {
|
|
16669
|
+
method,
|
|
16670
|
+
hasAuthKey: !!(options?.authKey || this.authKey),
|
|
16671
|
+
endpoint: this.endpoint
|
|
16672
|
+
});
|
|
16673
|
+
try {
|
|
16674
|
+
const serializedRequest = request.serializeBinary?.();
|
|
16675
|
+
if (serializedRequest) {
|
|
16676
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Request serialized, size: ${serializedRequest.length} bytes`);
|
|
16618
16677
|
}
|
|
16678
|
+
} catch (error) {
|
|
16679
|
+
console.error(`\u274C [GRPC-DEBUG] Failed to serialize request for logging:`, error);
|
|
16619
16680
|
}
|
|
16620
|
-
|
|
16681
|
+
}
|
|
16682
|
+
const timeoutConfig = {
|
|
16683
|
+
...this.timeoutConfig,
|
|
16684
|
+
...options?.timeout
|
|
16685
|
+
};
|
|
16686
|
+
const {
|
|
16687
|
+
timeout = timeoutConfig.timeout || 3e4,
|
|
16688
|
+
retries = timeoutConfig.retries || 3,
|
|
16689
|
+
retryDelay = timeoutConfig.retryDelay || 1e3
|
|
16690
|
+
} = timeoutConfig;
|
|
16691
|
+
if (debugMode) {
|
|
16692
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Timeout configuration:`, {
|
|
16693
|
+
timeout,
|
|
16694
|
+
retries,
|
|
16695
|
+
retryDelay
|
|
16696
|
+
});
|
|
16697
|
+
}
|
|
16698
|
+
let attempt = 0;
|
|
16699
|
+
const executeRequest = () => {
|
|
16700
|
+
attempt++;
|
|
16701
|
+
let timeoutId;
|
|
16702
|
+
const timeoutPromise = new Promise((_4, timeoutReject) => {
|
|
16703
|
+
timeoutId = setTimeout(() => {
|
|
16704
|
+
const error = new Error(`gRPC request timeout after ${timeout}ms for method ${method}`);
|
|
16705
|
+
error.isTimeout = true;
|
|
16706
|
+
error.attemptsMade = attempt;
|
|
16707
|
+
error.methodName = method;
|
|
16708
|
+
timeoutReject(error);
|
|
16709
|
+
}, timeout);
|
|
16710
|
+
});
|
|
16711
|
+
const grpcPromise = new Promise((grpcResolve, grpcReject) => {
|
|
16712
|
+
const metadata = new import_grpc_js.Metadata();
|
|
16713
|
+
const authKey = options?.authKey || this.authKey;
|
|
16714
|
+
if (authKey) {
|
|
16715
|
+
metadata.set(import_types20.AUTH_KEY_HEADER, authKey);
|
|
16716
|
+
}
|
|
16717
|
+
if (debugMode) {
|
|
16718
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Making gRPC call for ${method}, attempt ${attempt}`);
|
|
16719
|
+
}
|
|
16720
|
+
const call = this.rpcClient[method](
|
|
16721
|
+
request,
|
|
16722
|
+
metadata,
|
|
16723
|
+
(error, response) => {
|
|
16724
|
+
if (error) {
|
|
16725
|
+
if (debugMode) {
|
|
16726
|
+
console.error(`\u274C [GRPC-DEBUG] gRPC call failed for ${method}:`, {
|
|
16727
|
+
code: error.code,
|
|
16728
|
+
message: error.message,
|
|
16729
|
+
details: error.details,
|
|
16730
|
+
metadata: error.metadata?.getMap ? error.metadata.getMap() : error.metadata
|
|
16731
|
+
});
|
|
16732
|
+
}
|
|
16733
|
+
grpcReject(error);
|
|
16734
|
+
} else {
|
|
16735
|
+
if (debugMode) {
|
|
16736
|
+
try {
|
|
16737
|
+
const responseObj = response?.toObject ? response.toObject() : response;
|
|
16738
|
+
console.log(`\u2705 [GRPC-DEBUG] gRPC call succeeded for ${method}:`, {
|
|
16739
|
+
responseType: typeof response,
|
|
16740
|
+
hasToObject: !!response?.toObject,
|
|
16741
|
+
sampleResponse: JSON.stringify(responseObj).substring(0, 500) + (JSON.stringify(responseObj).length > 500 ? "..." : "")
|
|
16742
|
+
});
|
|
16743
|
+
} catch (parseError) {
|
|
16744
|
+
console.log(`\u2705 [GRPC-DEBUG] gRPC call succeeded for ${method}, but failed to parse response for logging:`, parseError);
|
|
16745
|
+
}
|
|
16746
|
+
}
|
|
16747
|
+
grpcResolve(response);
|
|
16748
|
+
}
|
|
16749
|
+
}
|
|
16750
|
+
);
|
|
16751
|
+
timeoutPromise.catch(() => {
|
|
16752
|
+
if (call && call.cancel) {
|
|
16753
|
+
call.cancel();
|
|
16754
|
+
}
|
|
16755
|
+
});
|
|
16756
|
+
});
|
|
16757
|
+
Promise.race([grpcPromise, timeoutPromise]).then((result) => {
|
|
16758
|
+
clearTimeout(timeoutId);
|
|
16759
|
+
resolve(result);
|
|
16760
|
+
}).catch((error) => {
|
|
16761
|
+
clearTimeout(timeoutId);
|
|
16762
|
+
const isTimeoutError = error.isTimeout || error.message?.includes("timeout");
|
|
16763
|
+
const isRetryableError = isTimeoutError || error.code === import_grpc_js.status.UNAVAILABLE || error.code === import_grpc_js.status.DEADLINE_EXCEEDED || error.code === import_grpc_js.status.RESOURCE_EXHAUSTED;
|
|
16764
|
+
if (isRetryableError && attempt < retries) {
|
|
16765
|
+
console.warn(`gRPC ${method} attempt ${attempt} failed, retrying in ${retryDelay}ms:`, error.message);
|
|
16766
|
+
setTimeout(executeRequest, retryDelay);
|
|
16767
|
+
} else {
|
|
16768
|
+
if (isTimeoutError && !error.isTimeout) {
|
|
16769
|
+
error.isTimeout = true;
|
|
16770
|
+
error.attemptsMade = attempt;
|
|
16771
|
+
error.methodName = method;
|
|
16772
|
+
}
|
|
16773
|
+
reject(error);
|
|
16774
|
+
}
|
|
16775
|
+
});
|
|
16776
|
+
};
|
|
16777
|
+
executeRequest();
|
|
16621
16778
|
});
|
|
16622
16779
|
}
|
|
16623
16780
|
};
|
|
@@ -17124,6 +17281,14 @@ var Client = class extends BaseClient {
|
|
|
17124
17281
|
* @returns {Promise<RunNodeWithInputsResponse>} - The response from running the node
|
|
17125
17282
|
*/
|
|
17126
17283
|
async runNodeWithInputs({ nodeType, nodeConfig, inputVariables = {} }, options) {
|
|
17284
|
+
const debugMode = process.env.GRPC_DEBUG === "true";
|
|
17285
|
+
if (debugMode) {
|
|
17286
|
+
console.log("\u{1F50D} [GRPC-DEBUG] runNodeWithInputs called with:", {
|
|
17287
|
+
nodeType,
|
|
17288
|
+
nodeConfig: JSON.stringify(nodeConfig, null, 2),
|
|
17289
|
+
inputVariables: JSON.stringify(inputVariables, null, 2)
|
|
17290
|
+
});
|
|
17291
|
+
}
|
|
17127
17292
|
const triggerTypes = [
|
|
17128
17293
|
import_types20.TriggerType.Block,
|
|
17129
17294
|
import_types20.TriggerType.FixedTime,
|
|
@@ -17141,23 +17306,94 @@ var Client = class extends BaseClient {
|
|
|
17141
17306
|
const request = new avs_pb22.RunNodeWithInputsReq();
|
|
17142
17307
|
const protobufNodeType = import_types20.NodeTypeGoConverter.fromGoString(nodeType);
|
|
17143
17308
|
request.setNodeType(protobufNodeType);
|
|
17309
|
+
if (debugMode) {
|
|
17310
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Converted nodeType:", {
|
|
17311
|
+
original: nodeType,
|
|
17312
|
+
protobuf: protobufNodeType
|
|
17313
|
+
});
|
|
17314
|
+
}
|
|
17144
17315
|
const nodeConfigMap = request.getNodeConfigMap();
|
|
17145
17316
|
for (const [key, value] of Object.entries(nodeConfig)) {
|
|
17146
|
-
|
|
17317
|
+
try {
|
|
17318
|
+
const protobufValue = convertJSValueToProtobuf(value);
|
|
17319
|
+
nodeConfigMap.set(key, protobufValue);
|
|
17320
|
+
if (debugMode) {
|
|
17321
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Converted nodeConfig[${key}]:`, {
|
|
17322
|
+
original: value,
|
|
17323
|
+
protobuf: protobufValue?.toObject ? protobufValue.toObject() : protobufValue
|
|
17324
|
+
});
|
|
17325
|
+
}
|
|
17326
|
+
} catch (error) {
|
|
17327
|
+
console.error(`\u274C [GRPC-DEBUG] Failed to convert nodeConfig[${key}]:`, error);
|
|
17328
|
+
throw error;
|
|
17329
|
+
}
|
|
17147
17330
|
}
|
|
17148
17331
|
if (inputVariables && Object.keys(inputVariables).length > 0) {
|
|
17149
17332
|
const inputVarsMap = request.getInputVariablesMap();
|
|
17150
17333
|
for (const [key, value] of Object.entries(inputVariables)) {
|
|
17151
|
-
|
|
17334
|
+
try {
|
|
17335
|
+
const protobufValue = convertJSValueToProtobuf(value);
|
|
17336
|
+
inputVarsMap.set(key, protobufValue);
|
|
17337
|
+
if (debugMode) {
|
|
17338
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Converted inputVariable[${key}]:`, {
|
|
17339
|
+
original: value,
|
|
17340
|
+
protobuf: protobufValue?.toObject ? protobufValue.toObject() : protobufValue
|
|
17341
|
+
});
|
|
17342
|
+
}
|
|
17343
|
+
} catch (error) {
|
|
17344
|
+
console.error(`\u274C [GRPC-DEBUG] Failed to convert inputVariable[${key}]:`, error);
|
|
17345
|
+
throw error;
|
|
17346
|
+
}
|
|
17152
17347
|
}
|
|
17153
17348
|
}
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17158
|
-
|
|
17159
|
-
|
|
17160
|
-
|
|
17349
|
+
if (debugMode) {
|
|
17350
|
+
try {
|
|
17351
|
+
const serializedRequest = request.serializeBinary();
|
|
17352
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Request serialized successfully, size:", serializedRequest.length, "bytes");
|
|
17353
|
+
} catch (error) {
|
|
17354
|
+
console.error("\u274C [GRPC-DEBUG] Failed to serialize request:", error);
|
|
17355
|
+
throw error;
|
|
17356
|
+
}
|
|
17357
|
+
}
|
|
17358
|
+
try {
|
|
17359
|
+
const result = await this.sendGrpcRequest("runNodeWithInputs", request, options);
|
|
17360
|
+
if (debugMode) {
|
|
17361
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Response received successfully:", {
|
|
17362
|
+
success: result.getSuccess(),
|
|
17363
|
+
error: result.getError(),
|
|
17364
|
+
nodeId: result.getNodeId(),
|
|
17365
|
+
outputDataCase: result.getOutputDataCase()
|
|
17366
|
+
});
|
|
17367
|
+
}
|
|
17368
|
+
let responseData;
|
|
17369
|
+
try {
|
|
17370
|
+
responseData = factory_default2.fromOutputData(result);
|
|
17371
|
+
if (debugMode) {
|
|
17372
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Output data parsed successfully:", responseData);
|
|
17373
|
+
}
|
|
17374
|
+
} catch (error) {
|
|
17375
|
+
console.error("\u274C [GRPC-DEBUG] Failed to parse output data:", error);
|
|
17376
|
+
if (debugMode) {
|
|
17377
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Raw response object:", result.toObject());
|
|
17378
|
+
}
|
|
17379
|
+
throw error;
|
|
17380
|
+
}
|
|
17381
|
+
return {
|
|
17382
|
+
success: result.getSuccess(),
|
|
17383
|
+
data: responseData,
|
|
17384
|
+
error: result.getError(),
|
|
17385
|
+
nodeId: result.getNodeId()
|
|
17386
|
+
};
|
|
17387
|
+
} catch (error) {
|
|
17388
|
+
console.error("\u274C [GRPC-DEBUG] runNodeWithInputs failed:", {
|
|
17389
|
+
error: error instanceof Error ? error.message : String(error),
|
|
17390
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
17391
|
+
nodeType,
|
|
17392
|
+
nodeConfig,
|
|
17393
|
+
inputVariables
|
|
17394
|
+
});
|
|
17395
|
+
throw error;
|
|
17396
|
+
}
|
|
17161
17397
|
}
|
|
17162
17398
|
/**
|
|
17163
17399
|
* Run a trigger for testing purposes
|
|
@@ -17263,6 +17499,7 @@ var Client = class extends BaseClient {
|
|
|
17263
17499
|
RestAPINode,
|
|
17264
17500
|
Secret,
|
|
17265
17501
|
Step,
|
|
17502
|
+
TimeoutPresets,
|
|
17266
17503
|
Trigger,
|
|
17267
17504
|
TriggerFactory,
|
|
17268
17505
|
Workflow
|
package/dist/index.mjs
CHANGED
|
@@ -14872,7 +14872,7 @@ var require_avs_grpc_pb = __commonJS({
|
|
|
14872
14872
|
// src/index.ts
|
|
14873
14873
|
var import_avs_grpc_pb = __toESM(require_avs_grpc_pb());
|
|
14874
14874
|
var avs_pb22 = __toESM(require_avs_pb());
|
|
14875
|
-
import { credentials, Metadata } from "@grpc/grpc-js";
|
|
14875
|
+
import { credentials, Metadata, status } from "@grpc/grpc-js";
|
|
14876
14876
|
|
|
14877
14877
|
// src/models/workflow.ts
|
|
14878
14878
|
var avs_pb19 = __toESM(require_avs_pb());
|
|
@@ -16121,7 +16121,7 @@ var factory_default2 = NodeFactory;
|
|
|
16121
16121
|
|
|
16122
16122
|
// src/models/workflow.ts
|
|
16123
16123
|
import { WorkflowStatus } from "@avaprotocol/types";
|
|
16124
|
-
function convertStatusToString(
|
|
16124
|
+
function convertStatusToString(status2) {
|
|
16125
16125
|
const conversionMap = {
|
|
16126
16126
|
[avs_pb19.TaskStatus.ACTIVE]: WorkflowStatus.Active,
|
|
16127
16127
|
[avs_pb19.TaskStatus.COMPLETED]: WorkflowStatus.Completed,
|
|
@@ -16129,7 +16129,7 @@ function convertStatusToString(status) {
|
|
|
16129
16129
|
[avs_pb19.TaskStatus.CANCELED]: WorkflowStatus.Canceled,
|
|
16130
16130
|
[avs_pb19.TaskStatus.EXECUTING]: WorkflowStatus.Executing
|
|
16131
16131
|
};
|
|
16132
|
-
return conversionMap[
|
|
16132
|
+
return conversionMap[status2];
|
|
16133
16133
|
}
|
|
16134
16134
|
var Workflow = class _Workflow {
|
|
16135
16135
|
/**
|
|
@@ -16479,7 +16479,11 @@ import {
|
|
|
16479
16479
|
TriggerTypeGoConverter,
|
|
16480
16480
|
TriggerTypeConverter,
|
|
16481
16481
|
AUTH_KEY_HEADER,
|
|
16482
|
-
DEFAULT_LIMIT
|
|
16482
|
+
DEFAULT_LIMIT,
|
|
16483
|
+
TimeoutPresets
|
|
16484
|
+
} from "@avaprotocol/types";
|
|
16485
|
+
import {
|
|
16486
|
+
TimeoutPresets as TimeoutPresets2
|
|
16483
16487
|
} from "@avaprotocol/types";
|
|
16484
16488
|
var BaseClient = class {
|
|
16485
16489
|
constructor(opts) {
|
|
@@ -16489,8 +16493,67 @@ var BaseClient = class {
|
|
|
16489
16493
|
credentials.createInsecure()
|
|
16490
16494
|
);
|
|
16491
16495
|
this.factoryAddress = opts.factoryAddress;
|
|
16496
|
+
this.timeoutConfig = {
|
|
16497
|
+
timeout: 3e4,
|
|
16498
|
+
retries: 0,
|
|
16499
|
+
retryDelay: 0,
|
|
16500
|
+
...opts.timeout
|
|
16501
|
+
};
|
|
16492
16502
|
this.metadata = new Metadata();
|
|
16493
16503
|
}
|
|
16504
|
+
/**
|
|
16505
|
+
* Set default timeout configuration for all requests
|
|
16506
|
+
* @param config - The timeout configuration
|
|
16507
|
+
*/
|
|
16508
|
+
setTimeoutConfig(config) {
|
|
16509
|
+
this.timeoutConfig = { ...this.timeoutConfig, ...config };
|
|
16510
|
+
}
|
|
16511
|
+
/**
|
|
16512
|
+
* Get the current timeout configuration
|
|
16513
|
+
* @returns {TimeoutConfig} - The current timeout configuration
|
|
16514
|
+
*/
|
|
16515
|
+
getTimeoutConfig() {
|
|
16516
|
+
return { ...this.timeoutConfig };
|
|
16517
|
+
}
|
|
16518
|
+
/**
|
|
16519
|
+
* Send a fast gRPC request using FAST preset (5s timeout, 2 retries)
|
|
16520
|
+
* @param method - The method name to call
|
|
16521
|
+
* @param request - The request object
|
|
16522
|
+
* @param options - Request options
|
|
16523
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
16524
|
+
*/
|
|
16525
|
+
sendFastRequest(method, request, options) {
|
|
16526
|
+
return this.sendGrpcRequest(method, request, {
|
|
16527
|
+
...options,
|
|
16528
|
+
timeout: TimeoutPresets.FAST
|
|
16529
|
+
});
|
|
16530
|
+
}
|
|
16531
|
+
/**
|
|
16532
|
+
* Send a slow gRPC request using SLOW preset (2min timeout, 2 retries)
|
|
16533
|
+
* @param method - The method name to call
|
|
16534
|
+
* @param request - The request object
|
|
16535
|
+
* @param options - Request options
|
|
16536
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
16537
|
+
*/
|
|
16538
|
+
sendSlowRequest(method, request, options) {
|
|
16539
|
+
return this.sendGrpcRequest(method, request, {
|
|
16540
|
+
...options,
|
|
16541
|
+
timeout: TimeoutPresets.SLOW
|
|
16542
|
+
});
|
|
16543
|
+
}
|
|
16544
|
+
/**
|
|
16545
|
+
* Send a no-retry gRPC request using NO_RETRY preset (30s timeout, no retries)
|
|
16546
|
+
* @param method - The method name to call
|
|
16547
|
+
* @param request - The request object
|
|
16548
|
+
* @param options - Request options
|
|
16549
|
+
* @returns {Promise<TResponse>} - The response from the server
|
|
16550
|
+
*/
|
|
16551
|
+
sendNoRetryRequest(method, request, options) {
|
|
16552
|
+
return this.sendGrpcRequest(method, request, {
|
|
16553
|
+
...options,
|
|
16554
|
+
timeout: TimeoutPresets.NO_RETRY
|
|
16555
|
+
});
|
|
16556
|
+
}
|
|
16494
16557
|
/**
|
|
16495
16558
|
* Check if the auth key is valid by decoding the JWT token and checking the expiration
|
|
16496
16559
|
* @param key - The auth key
|
|
@@ -16583,30 +16646,126 @@ var BaseClient = class {
|
|
|
16583
16646
|
return this.factoryAddress;
|
|
16584
16647
|
}
|
|
16585
16648
|
/**
|
|
16586
|
-
* Send a gRPC request with authentication and error handling
|
|
16649
|
+
* Send a gRPC request with authentication, timeout support, and error handling
|
|
16587
16650
|
* @param method - The method name to call
|
|
16588
16651
|
* @param request - The request object
|
|
16589
|
-
* @param options - Request options
|
|
16652
|
+
* @param options - Request options including timeout configuration
|
|
16590
16653
|
* @returns {Promise<TResponse>} - The response from the server
|
|
16591
16654
|
*/
|
|
16592
16655
|
sendGrpcRequest(method, request, options) {
|
|
16593
16656
|
return new Promise((resolve, reject) => {
|
|
16594
|
-
const
|
|
16595
|
-
|
|
16596
|
-
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16600
|
-
|
|
16601
|
-
|
|
16602
|
-
|
|
16603
|
-
if (
|
|
16604
|
-
|
|
16605
|
-
} else {
|
|
16606
|
-
resolve(response);
|
|
16657
|
+
const debugMode = process.env.GRPC_DEBUG === "true";
|
|
16658
|
+
if (debugMode) {
|
|
16659
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Starting ${method} request:`, {
|
|
16660
|
+
method,
|
|
16661
|
+
hasAuthKey: !!(options?.authKey || this.authKey),
|
|
16662
|
+
endpoint: this.endpoint
|
|
16663
|
+
});
|
|
16664
|
+
try {
|
|
16665
|
+
const serializedRequest = request.serializeBinary?.();
|
|
16666
|
+
if (serializedRequest) {
|
|
16667
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Request serialized, size: ${serializedRequest.length} bytes`);
|
|
16607
16668
|
}
|
|
16669
|
+
} catch (error) {
|
|
16670
|
+
console.error(`\u274C [GRPC-DEBUG] Failed to serialize request for logging:`, error);
|
|
16608
16671
|
}
|
|
16609
|
-
|
|
16672
|
+
}
|
|
16673
|
+
const timeoutConfig = {
|
|
16674
|
+
...this.timeoutConfig,
|
|
16675
|
+
...options?.timeout
|
|
16676
|
+
};
|
|
16677
|
+
const {
|
|
16678
|
+
timeout = timeoutConfig.timeout || 3e4,
|
|
16679
|
+
retries = timeoutConfig.retries || 3,
|
|
16680
|
+
retryDelay = timeoutConfig.retryDelay || 1e3
|
|
16681
|
+
} = timeoutConfig;
|
|
16682
|
+
if (debugMode) {
|
|
16683
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Timeout configuration:`, {
|
|
16684
|
+
timeout,
|
|
16685
|
+
retries,
|
|
16686
|
+
retryDelay
|
|
16687
|
+
});
|
|
16688
|
+
}
|
|
16689
|
+
let attempt = 0;
|
|
16690
|
+
const executeRequest = () => {
|
|
16691
|
+
attempt++;
|
|
16692
|
+
let timeoutId;
|
|
16693
|
+
const timeoutPromise = new Promise((_4, timeoutReject) => {
|
|
16694
|
+
timeoutId = setTimeout(() => {
|
|
16695
|
+
const error = new Error(`gRPC request timeout after ${timeout}ms for method ${method}`);
|
|
16696
|
+
error.isTimeout = true;
|
|
16697
|
+
error.attemptsMade = attempt;
|
|
16698
|
+
error.methodName = method;
|
|
16699
|
+
timeoutReject(error);
|
|
16700
|
+
}, timeout);
|
|
16701
|
+
});
|
|
16702
|
+
const grpcPromise = new Promise((grpcResolve, grpcReject) => {
|
|
16703
|
+
const metadata = new Metadata();
|
|
16704
|
+
const authKey = options?.authKey || this.authKey;
|
|
16705
|
+
if (authKey) {
|
|
16706
|
+
metadata.set(AUTH_KEY_HEADER, authKey);
|
|
16707
|
+
}
|
|
16708
|
+
if (debugMode) {
|
|
16709
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Making gRPC call for ${method}, attempt ${attempt}`);
|
|
16710
|
+
}
|
|
16711
|
+
const call = this.rpcClient[method](
|
|
16712
|
+
request,
|
|
16713
|
+
metadata,
|
|
16714
|
+
(error, response) => {
|
|
16715
|
+
if (error) {
|
|
16716
|
+
if (debugMode) {
|
|
16717
|
+
console.error(`\u274C [GRPC-DEBUG] gRPC call failed for ${method}:`, {
|
|
16718
|
+
code: error.code,
|
|
16719
|
+
message: error.message,
|
|
16720
|
+
details: error.details,
|
|
16721
|
+
metadata: error.metadata?.getMap ? error.metadata.getMap() : error.metadata
|
|
16722
|
+
});
|
|
16723
|
+
}
|
|
16724
|
+
grpcReject(error);
|
|
16725
|
+
} else {
|
|
16726
|
+
if (debugMode) {
|
|
16727
|
+
try {
|
|
16728
|
+
const responseObj = response?.toObject ? response.toObject() : response;
|
|
16729
|
+
console.log(`\u2705 [GRPC-DEBUG] gRPC call succeeded for ${method}:`, {
|
|
16730
|
+
responseType: typeof response,
|
|
16731
|
+
hasToObject: !!response?.toObject,
|
|
16732
|
+
sampleResponse: JSON.stringify(responseObj).substring(0, 500) + (JSON.stringify(responseObj).length > 500 ? "..." : "")
|
|
16733
|
+
});
|
|
16734
|
+
} catch (parseError) {
|
|
16735
|
+
console.log(`\u2705 [GRPC-DEBUG] gRPC call succeeded for ${method}, but failed to parse response for logging:`, parseError);
|
|
16736
|
+
}
|
|
16737
|
+
}
|
|
16738
|
+
grpcResolve(response);
|
|
16739
|
+
}
|
|
16740
|
+
}
|
|
16741
|
+
);
|
|
16742
|
+
timeoutPromise.catch(() => {
|
|
16743
|
+
if (call && call.cancel) {
|
|
16744
|
+
call.cancel();
|
|
16745
|
+
}
|
|
16746
|
+
});
|
|
16747
|
+
});
|
|
16748
|
+
Promise.race([grpcPromise, timeoutPromise]).then((result) => {
|
|
16749
|
+
clearTimeout(timeoutId);
|
|
16750
|
+
resolve(result);
|
|
16751
|
+
}).catch((error) => {
|
|
16752
|
+
clearTimeout(timeoutId);
|
|
16753
|
+
const isTimeoutError = error.isTimeout || error.message?.includes("timeout");
|
|
16754
|
+
const isRetryableError = isTimeoutError || error.code === status.UNAVAILABLE || error.code === status.DEADLINE_EXCEEDED || error.code === status.RESOURCE_EXHAUSTED;
|
|
16755
|
+
if (isRetryableError && attempt < retries) {
|
|
16756
|
+
console.warn(`gRPC ${method} attempt ${attempt} failed, retrying in ${retryDelay}ms:`, error.message);
|
|
16757
|
+
setTimeout(executeRequest, retryDelay);
|
|
16758
|
+
} else {
|
|
16759
|
+
if (isTimeoutError && !error.isTimeout) {
|
|
16760
|
+
error.isTimeout = true;
|
|
16761
|
+
error.attemptsMade = attempt;
|
|
16762
|
+
error.methodName = method;
|
|
16763
|
+
}
|
|
16764
|
+
reject(error);
|
|
16765
|
+
}
|
|
16766
|
+
});
|
|
16767
|
+
};
|
|
16768
|
+
executeRequest();
|
|
16610
16769
|
});
|
|
16611
16770
|
}
|
|
16612
16771
|
};
|
|
@@ -17113,6 +17272,14 @@ var Client = class extends BaseClient {
|
|
|
17113
17272
|
* @returns {Promise<RunNodeWithInputsResponse>} - The response from running the node
|
|
17114
17273
|
*/
|
|
17115
17274
|
async runNodeWithInputs({ nodeType, nodeConfig, inputVariables = {} }, options) {
|
|
17275
|
+
const debugMode = process.env.GRPC_DEBUG === "true";
|
|
17276
|
+
if (debugMode) {
|
|
17277
|
+
console.log("\u{1F50D} [GRPC-DEBUG] runNodeWithInputs called with:", {
|
|
17278
|
+
nodeType,
|
|
17279
|
+
nodeConfig: JSON.stringify(nodeConfig, null, 2),
|
|
17280
|
+
inputVariables: JSON.stringify(inputVariables, null, 2)
|
|
17281
|
+
});
|
|
17282
|
+
}
|
|
17116
17283
|
const triggerTypes = [
|
|
17117
17284
|
TriggerType13.Block,
|
|
17118
17285
|
TriggerType13.FixedTime,
|
|
@@ -17130,23 +17297,94 @@ var Client = class extends BaseClient {
|
|
|
17130
17297
|
const request = new avs_pb22.RunNodeWithInputsReq();
|
|
17131
17298
|
const protobufNodeType = NodeTypeGoConverter2.fromGoString(nodeType);
|
|
17132
17299
|
request.setNodeType(protobufNodeType);
|
|
17300
|
+
if (debugMode) {
|
|
17301
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Converted nodeType:", {
|
|
17302
|
+
original: nodeType,
|
|
17303
|
+
protobuf: protobufNodeType
|
|
17304
|
+
});
|
|
17305
|
+
}
|
|
17133
17306
|
const nodeConfigMap = request.getNodeConfigMap();
|
|
17134
17307
|
for (const [key, value] of Object.entries(nodeConfig)) {
|
|
17135
|
-
|
|
17308
|
+
try {
|
|
17309
|
+
const protobufValue = convertJSValueToProtobuf(value);
|
|
17310
|
+
nodeConfigMap.set(key, protobufValue);
|
|
17311
|
+
if (debugMode) {
|
|
17312
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Converted nodeConfig[${key}]:`, {
|
|
17313
|
+
original: value,
|
|
17314
|
+
protobuf: protobufValue?.toObject ? protobufValue.toObject() : protobufValue
|
|
17315
|
+
});
|
|
17316
|
+
}
|
|
17317
|
+
} catch (error) {
|
|
17318
|
+
console.error(`\u274C [GRPC-DEBUG] Failed to convert nodeConfig[${key}]:`, error);
|
|
17319
|
+
throw error;
|
|
17320
|
+
}
|
|
17136
17321
|
}
|
|
17137
17322
|
if (inputVariables && Object.keys(inputVariables).length > 0) {
|
|
17138
17323
|
const inputVarsMap = request.getInputVariablesMap();
|
|
17139
17324
|
for (const [key, value] of Object.entries(inputVariables)) {
|
|
17140
|
-
|
|
17325
|
+
try {
|
|
17326
|
+
const protobufValue = convertJSValueToProtobuf(value);
|
|
17327
|
+
inputVarsMap.set(key, protobufValue);
|
|
17328
|
+
if (debugMode) {
|
|
17329
|
+
console.log(`\u{1F50D} [GRPC-DEBUG] Converted inputVariable[${key}]:`, {
|
|
17330
|
+
original: value,
|
|
17331
|
+
protobuf: protobufValue?.toObject ? protobufValue.toObject() : protobufValue
|
|
17332
|
+
});
|
|
17333
|
+
}
|
|
17334
|
+
} catch (error) {
|
|
17335
|
+
console.error(`\u274C [GRPC-DEBUG] Failed to convert inputVariable[${key}]:`, error);
|
|
17336
|
+
throw error;
|
|
17337
|
+
}
|
|
17141
17338
|
}
|
|
17142
17339
|
}
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17340
|
+
if (debugMode) {
|
|
17341
|
+
try {
|
|
17342
|
+
const serializedRequest = request.serializeBinary();
|
|
17343
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Request serialized successfully, size:", serializedRequest.length, "bytes");
|
|
17344
|
+
} catch (error) {
|
|
17345
|
+
console.error("\u274C [GRPC-DEBUG] Failed to serialize request:", error);
|
|
17346
|
+
throw error;
|
|
17347
|
+
}
|
|
17348
|
+
}
|
|
17349
|
+
try {
|
|
17350
|
+
const result = await this.sendGrpcRequest("runNodeWithInputs", request, options);
|
|
17351
|
+
if (debugMode) {
|
|
17352
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Response received successfully:", {
|
|
17353
|
+
success: result.getSuccess(),
|
|
17354
|
+
error: result.getError(),
|
|
17355
|
+
nodeId: result.getNodeId(),
|
|
17356
|
+
outputDataCase: result.getOutputDataCase()
|
|
17357
|
+
});
|
|
17358
|
+
}
|
|
17359
|
+
let responseData;
|
|
17360
|
+
try {
|
|
17361
|
+
responseData = factory_default2.fromOutputData(result);
|
|
17362
|
+
if (debugMode) {
|
|
17363
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Output data parsed successfully:", responseData);
|
|
17364
|
+
}
|
|
17365
|
+
} catch (error) {
|
|
17366
|
+
console.error("\u274C [GRPC-DEBUG] Failed to parse output data:", error);
|
|
17367
|
+
if (debugMode) {
|
|
17368
|
+
console.log("\u{1F50D} [GRPC-DEBUG] Raw response object:", result.toObject());
|
|
17369
|
+
}
|
|
17370
|
+
throw error;
|
|
17371
|
+
}
|
|
17372
|
+
return {
|
|
17373
|
+
success: result.getSuccess(),
|
|
17374
|
+
data: responseData,
|
|
17375
|
+
error: result.getError(),
|
|
17376
|
+
nodeId: result.getNodeId()
|
|
17377
|
+
};
|
|
17378
|
+
} catch (error) {
|
|
17379
|
+
console.error("\u274C [GRPC-DEBUG] runNodeWithInputs failed:", {
|
|
17380
|
+
error: error instanceof Error ? error.message : String(error),
|
|
17381
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
17382
|
+
nodeType,
|
|
17383
|
+
nodeConfig,
|
|
17384
|
+
inputVariables
|
|
17385
|
+
});
|
|
17386
|
+
throw error;
|
|
17387
|
+
}
|
|
17150
17388
|
}
|
|
17151
17389
|
/**
|
|
17152
17390
|
* Run a trigger for testing purposes
|
|
@@ -17251,6 +17489,7 @@ export {
|
|
|
17251
17489
|
restApi_default as RestAPINode,
|
|
17252
17490
|
secret_default as Secret,
|
|
17253
17491
|
step_default as Step,
|
|
17492
|
+
TimeoutPresets2 as TimeoutPresets,
|
|
17254
17493
|
interface_default as Trigger,
|
|
17255
17494
|
factory_default as TriggerFactory,
|
|
17256
17495
|
workflow_default as Workflow
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avaprotocol/sdk-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"clean": "rm -rf node_modules dist tsconfig.tsbuildinfo"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@avaprotocol/types": "
|
|
33
|
+
"@avaprotocol/types": "workspace:*",
|
|
34
34
|
"@grpc/grpc-js": "^1.11.3",
|
|
35
35
|
"@grpc/proto-loader": "^0.7.13",
|
|
36
36
|
"dotenv": "^16.4.5",
|