@jack-kernel/sdk 1.0.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/README.md +757 -0
- package/dist/cjs/agent.js +321 -0
- package/dist/cjs/agent.js.map +1 -0
- package/dist/cjs/cache.js +58 -0
- package/dist/cjs/cache.js.map +1 -0
- package/dist/cjs/client.js +196 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/costs.js +104 -0
- package/dist/cjs/costs.js.map +1 -0
- package/dist/cjs/errors.js +287 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/execution.js +385 -0
- package/dist/cjs/execution.js.map +1 -0
- package/dist/cjs/index.js +256 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/intents.js +185 -0
- package/dist/cjs/intents.js.map +1 -0
- package/dist/cjs/serialization.js +164 -0
- package/dist/cjs/serialization.js.map +1 -0
- package/dist/cjs/types.js +31 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/validation.js +114 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/esm/agent.js +317 -0
- package/dist/esm/agent.js.map +1 -0
- package/dist/esm/cache.js +54 -0
- package/dist/esm/cache.js.map +1 -0
- package/dist/esm/client.js +192 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/costs.js +100 -0
- package/dist/esm/costs.js.map +1 -0
- package/dist/esm/errors.js +278 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/execution.js +381 -0
- package/dist/esm/execution.js.map +1 -0
- package/dist/esm/index.js +236 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/intents.js +181 -0
- package/dist/esm/intents.js.map +1 -0
- package/dist/esm/serialization.js +159 -0
- package/dist/esm/serialization.js.map +1 -0
- package/dist/esm/types.js +28 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validation.js +111 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/types/agent.d.ts +171 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/cache.d.ts +25 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/client.d.ts +46 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/costs.d.ts +91 -0
- package/dist/types/costs.d.ts.map +1 -0
- package/dist/types/errors.d.ts +242 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/execution.d.ts +145 -0
- package/dist/types/execution.d.ts.map +1 -0
- package/dist/types/index.d.ts +205 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/intents.d.ts +158 -0
- package/dist/types/intents.d.ts.map +1 -0
- package/dist/types/serialization.d.ts +82 -0
- package/dist/types/serialization.d.ts.map +1 -0
- package/dist/types/types.d.ts +302 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/validation.d.ts +40 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple in-memory cache with TTL support
|
|
3
|
+
*/
|
|
4
|
+
export declare class Cache {
|
|
5
|
+
private store;
|
|
6
|
+
private readonly defaultTTL;
|
|
7
|
+
constructor(defaultTTL?: number);
|
|
8
|
+
/**
|
|
9
|
+
* Get value from cache if not expired
|
|
10
|
+
*/
|
|
11
|
+
get<T>(key: string): T | null;
|
|
12
|
+
/**
|
|
13
|
+
* Set value in cache with TTL
|
|
14
|
+
*/
|
|
15
|
+
set<T>(key: string, value: T, ttl?: number): void;
|
|
16
|
+
/**
|
|
17
|
+
* Clear cache entries matching pattern
|
|
18
|
+
*/
|
|
19
|
+
clear(pattern?: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Get cache size
|
|
22
|
+
*/
|
|
23
|
+
size(): number;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,UAAU,GAAE,MAAc;IAItC;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAgB7B;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAKjD;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAc7B;;OAEG;IACH,IAAI,IAAI,MAAM;CAGf"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ClientConfig, RequestOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Core HTTP client for JACK API with retry logic, timeout handling, and caching
|
|
4
|
+
*/
|
|
5
|
+
export declare class JackClient {
|
|
6
|
+
private readonly config;
|
|
7
|
+
private readonly cache;
|
|
8
|
+
constructor(config: ClientConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Validate client configuration
|
|
11
|
+
*/
|
|
12
|
+
private validateConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Perform GET request with caching support
|
|
15
|
+
*/
|
|
16
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Perform POST request (never cached)
|
|
19
|
+
*/
|
|
20
|
+
post<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Clear cache entries matching pattern
|
|
23
|
+
*/
|
|
24
|
+
clearCache(pattern?: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Generate cache key from URL and options
|
|
27
|
+
*/
|
|
28
|
+
private getCacheKey;
|
|
29
|
+
/**
|
|
30
|
+
* Execute HTTP request with timeout
|
|
31
|
+
*/
|
|
32
|
+
private executeRequest;
|
|
33
|
+
/**
|
|
34
|
+
* Execute function with retry logic and exponential backoff
|
|
35
|
+
*/
|
|
36
|
+
private executeWithRetry;
|
|
37
|
+
/**
|
|
38
|
+
* Check if error is retryable
|
|
39
|
+
*/
|
|
40
|
+
private isRetryable;
|
|
41
|
+
/**
|
|
42
|
+
* Sleep for specified milliseconds
|
|
43
|
+
*/
|
|
44
|
+
private sleep;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG/D;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;gBAElB,MAAM,EAAE,YAAY;IAiBhC;;OAEG;IACH,OAAO,CAAC,cAAc;IAgCtB;;OAEG;IACG,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAwBhE;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAMhF;;OAEG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlC;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;YACW,cAAc;IA0E5B;;OAEG;YACW,gBAAgB;IA8C9B;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACH,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost tracking module for JACK SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides methods to query execution costs and budgets.
|
|
5
|
+
* Validates Requirements 4.1, 4.2
|
|
6
|
+
*/
|
|
7
|
+
import type { JackClient } from './client.js';
|
|
8
|
+
import type { CostsResponse, IssueCost } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* CostTracker class for querying execution costs and budgets
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const tracker = new CostTracker(client);
|
|
15
|
+
* const costs = await tracker.getCosts();
|
|
16
|
+
* const issueCost = await tracker.getIssueCost('ISSUE-123');
|
|
17
|
+
* const overBudget = await tracker.getOverBudgetIssues();
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class CostTracker {
|
|
21
|
+
private readonly client;
|
|
22
|
+
constructor(client: JackClient);
|
|
23
|
+
/**
|
|
24
|
+
* Get all issue costs from the API
|
|
25
|
+
*
|
|
26
|
+
* Makes a GET request to /api/costs and returns the complete response
|
|
27
|
+
* with cost data for all issues.
|
|
28
|
+
*
|
|
29
|
+
* @returns Promise resolving to CostsResponse with all issue costs
|
|
30
|
+
* @throws {APIError} If the API request fails
|
|
31
|
+
* @throws {NetworkError} If network connection fails
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const costs = await tracker.getCosts();
|
|
36
|
+
* console.log(`Found ${costs.issueCosts.length} issues`);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* Validates Requirement 4.1
|
|
40
|
+
*/
|
|
41
|
+
getCosts(): Promise<CostsResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Get costs for a specific issue
|
|
44
|
+
*
|
|
45
|
+
* Fetches all costs and filters by the specified issue ID.
|
|
46
|
+
* Returns null if the issue is not found.
|
|
47
|
+
*
|
|
48
|
+
* @param issueId - The issue identifier to filter by
|
|
49
|
+
* @returns Promise resolving to IssueCost or null if not found
|
|
50
|
+
* @throws {APIError} If the API request fails
|
|
51
|
+
* @throws {NetworkError} If network connection fails
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const issueCost = await tracker.getIssueCost('ISSUE-123');
|
|
56
|
+
* if (issueCost) {
|
|
57
|
+
* console.log(`Total cost: ${issueCost.totalCost}`);
|
|
58
|
+
* console.log(`Budget: ${issueCost.budget}`);
|
|
59
|
+
* console.log(`Over budget: ${issueCost.overBudget}`);
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Validates Requirement 4.2
|
|
64
|
+
*/
|
|
65
|
+
getIssueCost(issueId: string): Promise<IssueCost | null>;
|
|
66
|
+
/**
|
|
67
|
+
* Get all issues that are over budget
|
|
68
|
+
*
|
|
69
|
+
* Fetches all costs and filters to only those with overBudget flag set to true.
|
|
70
|
+
* Returns an empty array if no issues are over budget.
|
|
71
|
+
*
|
|
72
|
+
* @returns Promise resolving to array of IssueCost objects that are over budget
|
|
73
|
+
* @throws {APIError} If the API request fails
|
|
74
|
+
* @throws {NetworkError} If network connection fails
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const overBudget = await tracker.getOverBudgetIssues();
|
|
79
|
+
* if (overBudget.length > 0) {
|
|
80
|
+
* console.log(`Warning: ${overBudget.length} issues are over budget`);
|
|
81
|
+
* overBudget.forEach(issue => {
|
|
82
|
+
* console.log(`${issue.issueId}: ${issue.totalCost} / ${issue.budget}`);
|
|
83
|
+
* });
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* Validates Requirement 4.2
|
|
88
|
+
*/
|
|
89
|
+
getOverBudgetIssues(): Promise<IssueCost[]>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=costs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"costs.d.ts","sourceRoot":"","sources":["../../src/costs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAE/C;;;;;;;;;;;;;;;;;OAiBG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;IAIxC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAQ9D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,mBAAmB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAIlD"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error hierarchy for the JACK SDK
|
|
3
|
+
*
|
|
4
|
+
* This module defines custom error classes for different failure scenarios.
|
|
5
|
+
* All errors extend the base JackError class and include context for debugging.
|
|
6
|
+
* Requirements: 5.2, 5.3
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Base error class for all JACK SDK errors
|
|
10
|
+
*
|
|
11
|
+
* Extends the native Error class and adds optional context for debugging.
|
|
12
|
+
* All SDK-specific errors inherit from this class.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* throw new JackError('Something went wrong', { requestId: '123', timestamp: Date.now() });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Requirement 5.2
|
|
20
|
+
*/
|
|
21
|
+
export declare class JackError extends Error {
|
|
22
|
+
/**
|
|
23
|
+
* Additional context information for debugging
|
|
24
|
+
* Can include request details, timestamps, or any relevant metadata
|
|
25
|
+
*/
|
|
26
|
+
readonly context?: Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new JackError
|
|
29
|
+
*
|
|
30
|
+
* @param message - Human-readable error message
|
|
31
|
+
* @param context - Optional context object with debugging information
|
|
32
|
+
*/
|
|
33
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when network-level failures occur
|
|
37
|
+
*
|
|
38
|
+
* This includes connection failures, DNS resolution errors, timeouts at the
|
|
39
|
+
* network layer, and other transport-level issues. The original error is
|
|
40
|
+
* preserved for detailed debugging.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* try {
|
|
45
|
+
* await fetch('https://api.jack.example');
|
|
46
|
+
* } catch (err) {
|
|
47
|
+
* throw new NetworkError('Failed to connect to API', err as Error);
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* Requirement 5.3
|
|
52
|
+
*/
|
|
53
|
+
export declare class NetworkError extends JackError {
|
|
54
|
+
/**
|
|
55
|
+
* The original error that caused the network failure
|
|
56
|
+
* Preserved for detailed debugging and error analysis
|
|
57
|
+
*/
|
|
58
|
+
readonly originalError: Error;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new NetworkError
|
|
61
|
+
*
|
|
62
|
+
* @param message - Human-readable error message
|
|
63
|
+
* @param originalError - The underlying error that caused the network failure
|
|
64
|
+
* @param context - Optional additional context
|
|
65
|
+
*/
|
|
66
|
+
constructor(message: string, originalError: Error, context?: Record<string, unknown>);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Error thrown when the API returns an error response
|
|
70
|
+
*
|
|
71
|
+
* This includes 4xx client errors (bad request, not found, unauthorized) and
|
|
72
|
+
* 5xx server errors (internal server error, service unavailable). The HTTP
|
|
73
|
+
* status code and response body are included for debugging.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* if (response.status >= 400) {
|
|
78
|
+
* throw new APIError(
|
|
79
|
+
* 'Intent not found',
|
|
80
|
+
* 404,
|
|
81
|
+
* { error: 'Intent with ID JK-ABC123456 does not exist' }
|
|
82
|
+
* );
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* Requirement 5.3
|
|
87
|
+
*/
|
|
88
|
+
export declare class APIError extends JackError {
|
|
89
|
+
/**
|
|
90
|
+
* HTTP status code from the API response
|
|
91
|
+
* Used to distinguish between client errors (4xx) and server errors (5xx)
|
|
92
|
+
*/
|
|
93
|
+
readonly statusCode: number;
|
|
94
|
+
/**
|
|
95
|
+
* The parsed response body from the API
|
|
96
|
+
* May contain error details, validation messages, or other diagnostic information
|
|
97
|
+
*/
|
|
98
|
+
readonly response?: unknown;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new APIError
|
|
101
|
+
*
|
|
102
|
+
* @param message - Human-readable error message
|
|
103
|
+
* @param statusCode - HTTP status code from the response
|
|
104
|
+
* @param response - Optional parsed response body
|
|
105
|
+
* @param context - Optional additional context
|
|
106
|
+
*/
|
|
107
|
+
constructor(message: string, statusCode: number, response?: unknown, context?: Record<string, unknown>);
|
|
108
|
+
/**
|
|
109
|
+
* Check if this is a client error (4xx status code)
|
|
110
|
+
* @returns true if status code is in the 400-499 range
|
|
111
|
+
*/
|
|
112
|
+
isClientError(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Check if this is a server error (5xx status code)
|
|
115
|
+
* @returns true if status code is in the 500-599 range
|
|
116
|
+
*/
|
|
117
|
+
isServerError(): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Check if this error is retryable
|
|
120
|
+
* Server errors (5xx) are typically retryable, client errors (4xx) are not
|
|
121
|
+
* @returns true if the error should be retried
|
|
122
|
+
*/
|
|
123
|
+
isRetryable(): boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Error thrown when client-side validation fails
|
|
127
|
+
*
|
|
128
|
+
* This error is thrown before making any network requests when input parameters
|
|
129
|
+
* fail validation checks. It includes an array of specific validation errors
|
|
130
|
+
* to help developers identify and fix issues.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const errors = [];
|
|
135
|
+
* if (params.amountIn <= 0) errors.push('amountIn must be positive');
|
|
136
|
+
* if (params.deadline < Date.now()) errors.push('deadline must be in the future');
|
|
137
|
+
* if (errors.length > 0) {
|
|
138
|
+
* throw new ValidationError('Invalid intent parameters', errors);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* Requirement 5.3
|
|
143
|
+
*/
|
|
144
|
+
export declare class ValidationError extends JackError {
|
|
145
|
+
/**
|
|
146
|
+
* Array of specific validation error messages
|
|
147
|
+
* Each message describes a single validation failure
|
|
148
|
+
*/
|
|
149
|
+
readonly errors: string[];
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new ValidationError
|
|
152
|
+
*
|
|
153
|
+
* @param message - Human-readable error message
|
|
154
|
+
* @param errors - Array of specific validation error messages
|
|
155
|
+
* @param context - Optional additional context
|
|
156
|
+
*/
|
|
157
|
+
constructor(message: string, errors: string[], context?: Record<string, unknown>);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Error thrown when an operation exceeds its timeout
|
|
161
|
+
*
|
|
162
|
+
* This includes request timeouts, polling timeouts, and any other time-bound
|
|
163
|
+
* operations. The timeout duration is included for debugging.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const timeout = 30000; // 30 seconds
|
|
168
|
+
* const timeoutPromise = new Promise((_, reject) => {
|
|
169
|
+
* setTimeout(() => {
|
|
170
|
+
* reject(new TimeoutError('Request timed out', timeout));
|
|
171
|
+
* }, timeout);
|
|
172
|
+
* });
|
|
173
|
+
* await Promise.race([fetchPromise, timeoutPromise]);
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* Requirement 5.3
|
|
177
|
+
*/
|
|
178
|
+
export declare class TimeoutError extends JackError {
|
|
179
|
+
/**
|
|
180
|
+
* The timeout duration in milliseconds
|
|
181
|
+
* Indicates how long the operation was allowed to run before timing out
|
|
182
|
+
*/
|
|
183
|
+
readonly timeoutMs: number;
|
|
184
|
+
/**
|
|
185
|
+
* Creates a new TimeoutError
|
|
186
|
+
*
|
|
187
|
+
* @param message - Human-readable error message
|
|
188
|
+
* @param timeoutMs - The timeout duration in milliseconds
|
|
189
|
+
* @param context - Optional additional context
|
|
190
|
+
*/
|
|
191
|
+
constructor(message: string, timeoutMs: number, context?: Record<string, unknown>);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Error thrown when retry attempts are exhausted
|
|
195
|
+
*
|
|
196
|
+
* This error is thrown after all retry attempts have failed. It includes the
|
|
197
|
+
* number of attempts made and the final error that caused the failure.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* let lastError: Error;
|
|
202
|
+
* for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
203
|
+
* try {
|
|
204
|
+
* return await makeRequest();
|
|
205
|
+
* } catch (err) {
|
|
206
|
+
* lastError = err as Error;
|
|
207
|
+
* if (attempt === maxRetries) {
|
|
208
|
+
* throw new RetryError(
|
|
209
|
+
* 'All retry attempts exhausted',
|
|
210
|
+
* attempt,
|
|
211
|
+
* lastError
|
|
212
|
+
* );
|
|
213
|
+
* }
|
|
214
|
+
* await delay(retryDelay * Math.pow(retryBackoff, attempt - 1));
|
|
215
|
+
* }
|
|
216
|
+
* }
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* Requirement 5.3
|
|
220
|
+
*/
|
|
221
|
+
export declare class RetryError extends JackError {
|
|
222
|
+
/**
|
|
223
|
+
* The number of retry attempts that were made
|
|
224
|
+
* Includes the initial attempt plus all retries
|
|
225
|
+
*/
|
|
226
|
+
readonly attempts: number;
|
|
227
|
+
/**
|
|
228
|
+
* The final error that caused the retry loop to fail
|
|
229
|
+
* This is the error from the last retry attempt
|
|
230
|
+
*/
|
|
231
|
+
readonly lastError: Error;
|
|
232
|
+
/**
|
|
233
|
+
* Creates a new RetryError
|
|
234
|
+
*
|
|
235
|
+
* @param message - Human-readable error message
|
|
236
|
+
* @param attempts - The number of attempts that were made
|
|
237
|
+
* @param lastError - The final error from the last attempt
|
|
238
|
+
* @param context - Optional additional context
|
|
239
|
+
*/
|
|
240
|
+
constructor(message: string, attempts: number, lastError: Error, context?: Record<string, unknown>);
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;GAYG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;OAGG;IACH,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElD;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAU/D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC;;;OAGG;IACH,SAAgB,aAAa,EAAE,KAAK,CAAC;IAErC;;;;;;OAMG;gBACS,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAKrF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAS,SAAQ,SAAS;IACrC;;;OAGG;IACH,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC;;;OAGG;IACH,SAAgB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnC;;;;;;;OAOG;gBAED,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,OAAO,EAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQnC;;;OAGG;IACH,aAAa,IAAI,OAAO;IAIxB;;;OAGG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;OAIG;IACH,WAAW,IAAI,OAAO;CAGvB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC5C;;;OAGG;IACH,SAAgB,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjC;;;;;;OAMG;gBACS,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAKjF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC;;;OAGG;IACH,SAAgB,SAAS,EAAE,MAAM,CAAC;IAElC;;;;;;OAMG;gBACS,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAKlF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,UAAW,SAAQ,SAAS;IACvC;;;OAGG;IACH,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC;;;OAGG;IACH,SAAgB,SAAS,EAAE,KAAK,CAAC;IAEjC;;;;;;;OAOG;gBAED,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,KAAK,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution tracking for the JACK SDK
|
|
3
|
+
*
|
|
4
|
+
* This module provides the ExecutionTracker class for polling intent status
|
|
5
|
+
* and waiting for specific execution states.
|
|
6
|
+
*
|
|
7
|
+
* Requirements: 2.1, 2.5
|
|
8
|
+
*/
|
|
9
|
+
import { ExecutionStatus, type Intent, type PollOptions, type ExecutionWatcher } from './types.js';
|
|
10
|
+
import type { JackClient } from './client.js';
|
|
11
|
+
/**
|
|
12
|
+
* Manager for execution tracking operations
|
|
13
|
+
*
|
|
14
|
+
* Provides methods to poll intent status, wait for specific statuses,
|
|
15
|
+
* and track execution progress with configurable timeouts.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const client = new JackClient({ baseUrl: 'https://api.jack.example' });
|
|
20
|
+
* const tracker = new ExecutionTracker(client);
|
|
21
|
+
*
|
|
22
|
+
* // Wait for intent to settle
|
|
23
|
+
* const intent = await tracker.waitForStatus(
|
|
24
|
+
* 'JK-ABC123456',
|
|
25
|
+
* ExecutionStatus.SETTLED,
|
|
26
|
+
* { timeout: 120000 }
|
|
27
|
+
* );
|
|
28
|
+
*
|
|
29
|
+
* console.log('Settlement tx:', intent.settlementTx);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class ExecutionTracker {
|
|
33
|
+
private readonly client;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new ExecutionTracker
|
|
36
|
+
*
|
|
37
|
+
* @param client - The JackClient instance to use for API requests
|
|
38
|
+
*/
|
|
39
|
+
constructor(client: JackClient);
|
|
40
|
+
/**
|
|
41
|
+
* Get current status of an intent
|
|
42
|
+
*
|
|
43
|
+
* Queries the JACK API for the current intent status. This is a single
|
|
44
|
+
* request that returns the intent's current state without polling.
|
|
45
|
+
* This method delegates to the IntentManager's get() method.
|
|
46
|
+
*
|
|
47
|
+
* @param intentId - The intent ID to query (format: JK-[A-Z0-9]{9})
|
|
48
|
+
* @returns Promise resolving to the complete Intent object
|
|
49
|
+
* @throws APIError if the intent is not found (404) or other API error
|
|
50
|
+
* @throws NetworkError if the network request fails
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const intent = await tracker.getStatus('JK-ABC123456');
|
|
55
|
+
* console.log('Current status:', intent.status);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* **Validates: Requirement 2.1**
|
|
59
|
+
*/
|
|
60
|
+
getStatus(intentId: string): Promise<Intent>;
|
|
61
|
+
/**
|
|
62
|
+
* Wait for intent to reach a specific status
|
|
63
|
+
*
|
|
64
|
+
* Polls the intent status at regular intervals until it reaches one of the
|
|
65
|
+
* target statuses or the timeout is exceeded. This is useful for waiting
|
|
66
|
+
* for intent completion or specific state transitions.
|
|
67
|
+
*
|
|
68
|
+
* The polling loop will stop when:
|
|
69
|
+
* - The intent reaches one of the target statuses
|
|
70
|
+
* - The timeout is exceeded (throws TimeoutError)
|
|
71
|
+
* - An API error occurs (throws APIError)
|
|
72
|
+
*
|
|
73
|
+
* @param intentId - The intent ID to poll
|
|
74
|
+
* @param targetStatus - Single status or array of statuses to wait for
|
|
75
|
+
* @param options - Polling configuration (interval, timeout, stopStatuses)
|
|
76
|
+
* @returns Promise resolving to the Intent when target status is reached
|
|
77
|
+
* @throws TimeoutError if timeout is exceeded before reaching target status
|
|
78
|
+
* @throws APIError if the API returns an error
|
|
79
|
+
* @throws NetworkError if the network request fails
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Wait for settlement with custom timeout
|
|
84
|
+
* const intent = await tracker.waitForStatus(
|
|
85
|
+
* 'JK-ABC123456',
|
|
86
|
+
* ExecutionStatus.SETTLED,
|
|
87
|
+
* { interval: 3000, timeout: 120000 }
|
|
88
|
+
* );
|
|
89
|
+
*
|
|
90
|
+
* // Wait for any terminal status
|
|
91
|
+
* const intent = await tracker.waitForStatus(
|
|
92
|
+
* 'JK-ABC123456',
|
|
93
|
+
* [ExecutionStatus.SETTLED, ExecutionStatus.ABORTED, ExecutionStatus.EXPIRED]
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* **Validates: Requirement 2.5**
|
|
98
|
+
*/
|
|
99
|
+
waitForStatus(intentId: string, targetStatus: ExecutionStatus | ExecutionStatus[], options?: PollOptions): Promise<Intent>;
|
|
100
|
+
/**
|
|
101
|
+
* Create a watcher for continuous intent status updates
|
|
102
|
+
*
|
|
103
|
+
* Returns an ExecutionWatcher that polls the intent status at regular
|
|
104
|
+
* intervals and emits events when the status changes. This is useful for
|
|
105
|
+
* real-time monitoring of intent execution.
|
|
106
|
+
*
|
|
107
|
+
* The watcher will continue polling until:
|
|
108
|
+
* - stop() is called
|
|
109
|
+
* - A terminal status is reached (SETTLED, ABORTED, EXPIRED)
|
|
110
|
+
* - An error occurs (emitted via onError callback)
|
|
111
|
+
*
|
|
112
|
+
* @param intentId - The intent ID to watch
|
|
113
|
+
* @param options - Polling configuration (interval, timeout)
|
|
114
|
+
* @returns ExecutionWatcher instance with event callbacks
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const watcher = tracker.watch('JK-ABC123456', { interval: 3000 });
|
|
119
|
+
*
|
|
120
|
+
* watcher.onUpdate((intent) => {
|
|
121
|
+
* console.log('Status updated:', intent.status);
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* watcher.onComplete((intent) => {
|
|
125
|
+
* console.log('Intent completed:', intent.settlementTx);
|
|
126
|
+
* watcher.stop();
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* watcher.onError((error) => {
|
|
130
|
+
* console.error('Polling error:', error);
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* **Validates: Requirements 2.2, 8.3**
|
|
135
|
+
*/
|
|
136
|
+
watch(intentId: string, options?: PollOptions): ExecutionWatcher;
|
|
137
|
+
/**
|
|
138
|
+
* Sleep for specified milliseconds
|
|
139
|
+
*
|
|
140
|
+
* @param ms - Milliseconds to sleep
|
|
141
|
+
* @returns Promise that resolves after the specified delay
|
|
142
|
+
*/
|
|
143
|
+
private sleep;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/execution.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IAEpC;;;;OAIG;gBACS,MAAM,EAAE,UAAU;IAI9B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,aAAa,CACjB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,eAAe,GAAG,eAAe,EAAE,EACjD,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,MAAM,CAAC;IAoClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,gBAAgB;IAIhE;;;;;OAKG;IACH,OAAO,CAAC,KAAK;CAGd"}
|