@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.
Files changed (68) hide show
  1. package/README.md +757 -0
  2. package/dist/cjs/agent.js +321 -0
  3. package/dist/cjs/agent.js.map +1 -0
  4. package/dist/cjs/cache.js +58 -0
  5. package/dist/cjs/cache.js.map +1 -0
  6. package/dist/cjs/client.js +196 -0
  7. package/dist/cjs/client.js.map +1 -0
  8. package/dist/cjs/costs.js +104 -0
  9. package/dist/cjs/costs.js.map +1 -0
  10. package/dist/cjs/errors.js +287 -0
  11. package/dist/cjs/errors.js.map +1 -0
  12. package/dist/cjs/execution.js +385 -0
  13. package/dist/cjs/execution.js.map +1 -0
  14. package/dist/cjs/index.js +256 -0
  15. package/dist/cjs/index.js.map +1 -0
  16. package/dist/cjs/intents.js +185 -0
  17. package/dist/cjs/intents.js.map +1 -0
  18. package/dist/cjs/serialization.js +164 -0
  19. package/dist/cjs/serialization.js.map +1 -0
  20. package/dist/cjs/types.js +31 -0
  21. package/dist/cjs/types.js.map +1 -0
  22. package/dist/cjs/validation.js +114 -0
  23. package/dist/cjs/validation.js.map +1 -0
  24. package/dist/esm/agent.js +317 -0
  25. package/dist/esm/agent.js.map +1 -0
  26. package/dist/esm/cache.js +54 -0
  27. package/dist/esm/cache.js.map +1 -0
  28. package/dist/esm/client.js +192 -0
  29. package/dist/esm/client.js.map +1 -0
  30. package/dist/esm/costs.js +100 -0
  31. package/dist/esm/costs.js.map +1 -0
  32. package/dist/esm/errors.js +278 -0
  33. package/dist/esm/errors.js.map +1 -0
  34. package/dist/esm/execution.js +381 -0
  35. package/dist/esm/execution.js.map +1 -0
  36. package/dist/esm/index.js +236 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/intents.js +181 -0
  39. package/dist/esm/intents.js.map +1 -0
  40. package/dist/esm/serialization.js +159 -0
  41. package/dist/esm/serialization.js.map +1 -0
  42. package/dist/esm/types.js +28 -0
  43. package/dist/esm/types.js.map +1 -0
  44. package/dist/esm/validation.js +111 -0
  45. package/dist/esm/validation.js.map +1 -0
  46. package/dist/types/agent.d.ts +171 -0
  47. package/dist/types/agent.d.ts.map +1 -0
  48. package/dist/types/cache.d.ts +25 -0
  49. package/dist/types/cache.d.ts.map +1 -0
  50. package/dist/types/client.d.ts +46 -0
  51. package/dist/types/client.d.ts.map +1 -0
  52. package/dist/types/costs.d.ts +91 -0
  53. package/dist/types/costs.d.ts.map +1 -0
  54. package/dist/types/errors.d.ts +242 -0
  55. package/dist/types/errors.d.ts.map +1 -0
  56. package/dist/types/execution.d.ts +145 -0
  57. package/dist/types/execution.d.ts.map +1 -0
  58. package/dist/types/index.d.ts +205 -0
  59. package/dist/types/index.d.ts.map +1 -0
  60. package/dist/types/intents.d.ts +158 -0
  61. package/dist/types/intents.d.ts.map +1 -0
  62. package/dist/types/serialization.d.ts +82 -0
  63. package/dist/types/serialization.d.ts.map +1 -0
  64. package/dist/types/types.d.ts +302 -0
  65. package/dist/types/types.d.ts.map +1 -0
  66. package/dist/types/validation.d.ts +40 -0
  67. package/dist/types/validation.d.ts.map +1 -0
  68. package/package.json +56 -0
@@ -0,0 +1,385 @@
1
+ "use strict";
2
+ /**
3
+ * Execution tracking for the JACK SDK
4
+ *
5
+ * This module provides the ExecutionTracker class for polling intent status
6
+ * and waiting for specific execution states.
7
+ *
8
+ * Requirements: 2.1, 2.5
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ExecutionTracker = void 0;
12
+ const types_js_1 = require("./types.js");
13
+ const errors_js_1 = require("./errors.js");
14
+ /**
15
+ * Manager for execution tracking operations
16
+ *
17
+ * Provides methods to poll intent status, wait for specific statuses,
18
+ * and track execution progress with configurable timeouts.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const client = new JackClient({ baseUrl: 'https://api.jack.example' });
23
+ * const tracker = new ExecutionTracker(client);
24
+ *
25
+ * // Wait for intent to settle
26
+ * const intent = await tracker.waitForStatus(
27
+ * 'JK-ABC123456',
28
+ * ExecutionStatus.SETTLED,
29
+ * { timeout: 120000 }
30
+ * );
31
+ *
32
+ * console.log('Settlement tx:', intent.settlementTx);
33
+ * ```
34
+ */
35
+ class ExecutionTracker {
36
+ client;
37
+ /**
38
+ * Creates a new ExecutionTracker
39
+ *
40
+ * @param client - The JackClient instance to use for API requests
41
+ */
42
+ constructor(client) {
43
+ this.client = client;
44
+ }
45
+ /**
46
+ * Get current status of an intent
47
+ *
48
+ * Queries the JACK API for the current intent status. This is a single
49
+ * request that returns the intent's current state without polling.
50
+ * This method delegates to the IntentManager's get() method.
51
+ *
52
+ * @param intentId - The intent ID to query (format: JK-[A-Z0-9]{9})
53
+ * @returns Promise resolving to the complete Intent object
54
+ * @throws APIError if the intent is not found (404) or other API error
55
+ * @throws NetworkError if the network request fails
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const intent = await tracker.getStatus('JK-ABC123456');
60
+ * console.log('Current status:', intent.status);
61
+ * ```
62
+ *
63
+ * **Validates: Requirement 2.1**
64
+ */
65
+ async getStatus(intentId) {
66
+ return this.client.get(`/api/intents/${intentId}`);
67
+ }
68
+ /**
69
+ * Wait for intent to reach a specific status
70
+ *
71
+ * Polls the intent status at regular intervals until it reaches one of the
72
+ * target statuses or the timeout is exceeded. This is useful for waiting
73
+ * for intent completion or specific state transitions.
74
+ *
75
+ * The polling loop will stop when:
76
+ * - The intent reaches one of the target statuses
77
+ * - The timeout is exceeded (throws TimeoutError)
78
+ * - An API error occurs (throws APIError)
79
+ *
80
+ * @param intentId - The intent ID to poll
81
+ * @param targetStatus - Single status or array of statuses to wait for
82
+ * @param options - Polling configuration (interval, timeout, stopStatuses)
83
+ * @returns Promise resolving to the Intent when target status is reached
84
+ * @throws TimeoutError if timeout is exceeded before reaching target status
85
+ * @throws APIError if the API returns an error
86
+ * @throws NetworkError if the network request fails
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * // Wait for settlement with custom timeout
91
+ * const intent = await tracker.waitForStatus(
92
+ * 'JK-ABC123456',
93
+ * ExecutionStatus.SETTLED,
94
+ * { interval: 3000, timeout: 120000 }
95
+ * );
96
+ *
97
+ * // Wait for any terminal status
98
+ * const intent = await tracker.waitForStatus(
99
+ * 'JK-ABC123456',
100
+ * [ExecutionStatus.SETTLED, ExecutionStatus.ABORTED, ExecutionStatus.EXPIRED]
101
+ * );
102
+ * ```
103
+ *
104
+ * **Validates: Requirement 2.5**
105
+ */
106
+ async waitForStatus(intentId, targetStatus, options) {
107
+ const interval = options?.interval ?? 2000;
108
+ const timeout = options?.timeout ?? 60000;
109
+ const targetStatuses = Array.isArray(targetStatus) ? targetStatus : [targetStatus];
110
+ const startTime = Date.now();
111
+ while (true) {
112
+ // Check if timeout exceeded
113
+ const elapsed = Date.now() - startTime;
114
+ if (elapsed >= timeout) {
115
+ throw new errors_js_1.TimeoutError(`Timeout waiting for intent ${intentId} to reach status ${targetStatuses.join(' or ')}`, timeout, { intentId, targetStatuses, elapsed });
116
+ }
117
+ // Get current status
118
+ const intent = await this.getStatus(intentId);
119
+ // Check if we've reached target status
120
+ if (targetStatuses.includes(intent.status)) {
121
+ return intent;
122
+ }
123
+ // Check if we should stop polling based on stopStatuses
124
+ if (options?.stopStatuses && options.stopStatuses.includes(intent.status)) {
125
+ return intent;
126
+ }
127
+ // Wait before next poll
128
+ await this.sleep(interval);
129
+ }
130
+ }
131
+ /**
132
+ * Create a watcher for continuous intent status updates
133
+ *
134
+ * Returns an ExecutionWatcher that polls the intent status at regular
135
+ * intervals and emits events when the status changes. This is useful for
136
+ * real-time monitoring of intent execution.
137
+ *
138
+ * The watcher will continue polling until:
139
+ * - stop() is called
140
+ * - A terminal status is reached (SETTLED, ABORTED, EXPIRED)
141
+ * - An error occurs (emitted via onError callback)
142
+ *
143
+ * @param intentId - The intent ID to watch
144
+ * @param options - Polling configuration (interval, timeout)
145
+ * @returns ExecutionWatcher instance with event callbacks
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const watcher = tracker.watch('JK-ABC123456', { interval: 3000 });
150
+ *
151
+ * watcher.onUpdate((intent) => {
152
+ * console.log('Status updated:', intent.status);
153
+ * });
154
+ *
155
+ * watcher.onComplete((intent) => {
156
+ * console.log('Intent completed:', intent.settlementTx);
157
+ * watcher.stop();
158
+ * });
159
+ *
160
+ * watcher.onError((error) => {
161
+ * console.error('Polling error:', error);
162
+ * });
163
+ * ```
164
+ *
165
+ * **Validates: Requirements 2.2, 8.3**
166
+ */
167
+ watch(intentId, options) {
168
+ return new ExecutionWatcherImpl(this, intentId, options);
169
+ }
170
+ /**
171
+ * Sleep for specified milliseconds
172
+ *
173
+ * @param ms - Milliseconds to sleep
174
+ * @returns Promise that resolves after the specified delay
175
+ */
176
+ sleep(ms) {
177
+ return new Promise(resolve => setTimeout(resolve, ms));
178
+ }
179
+ }
180
+ exports.ExecutionTracker = ExecutionTracker;
181
+ /**
182
+ * Implementation of ExecutionWatcher for continuous intent monitoring
183
+ *
184
+ * This class implements the event emitter pattern for watching intent status
185
+ * changes. It polls the API at regular intervals and emits events when the
186
+ * status changes or when terminal states are reached.
187
+ *
188
+ * Requirements: 2.2, 8.3
189
+ */
190
+ class ExecutionWatcherImpl {
191
+ intentId;
192
+ tracker;
193
+ interval;
194
+ timeout;
195
+ startTime;
196
+ updateCallbacks = [];
197
+ errorCallbacks = [];
198
+ completeCallbacks = [];
199
+ isRunning = false;
200
+ isStopped = false;
201
+ timeoutHandle = null;
202
+ lastStatus = null;
203
+ /**
204
+ * Creates a new ExecutionWatcher
205
+ *
206
+ * @param tracker - The ExecutionTracker instance to use for polling
207
+ * @param intentId - The intent ID to watch
208
+ * @param options - Polling configuration
209
+ */
210
+ constructor(tracker, intentId, options) {
211
+ this.tracker = tracker;
212
+ this.intentId = intentId;
213
+ this.interval = options?.interval ?? 2000;
214
+ this.timeout = options?.timeout ?? 60000;
215
+ this.startTime = Date.now();
216
+ // Start polling immediately
217
+ this.startPolling();
218
+ }
219
+ /**
220
+ * Register callback for status updates
221
+ *
222
+ * The callback is invoked whenever the intent status changes. Multiple
223
+ * callbacks can be registered and will all be invoked in order.
224
+ *
225
+ * @param callback - Function to call with updated intent
226
+ */
227
+ onUpdate(callback) {
228
+ this.updateCallbacks.push(callback);
229
+ }
230
+ /**
231
+ * Register callback for errors
232
+ *
233
+ * The callback is invoked when an error occurs during polling (e.g.,
234
+ * network error, API error, timeout). Multiple callbacks can be registered.
235
+ *
236
+ * @param callback - Function to call with error
237
+ */
238
+ onError(callback) {
239
+ this.errorCallbacks.push(callback);
240
+ }
241
+ /**
242
+ * Register callback for completion
243
+ *
244
+ * The callback is invoked when the intent reaches a terminal status
245
+ * (SETTLED, ABORTED, or EXPIRED). Multiple callbacks can be registered.
246
+ * After completion, polling stops automatically.
247
+ *
248
+ * @param callback - Function to call with final intent state
249
+ */
250
+ onComplete(callback) {
251
+ this.completeCallbacks.push(callback);
252
+ }
253
+ /**
254
+ * Stop watching and clean up resources
255
+ *
256
+ * Stops the polling loop and clears all callbacks. This method is
257
+ * idempotent and can be called multiple times safely.
258
+ */
259
+ stop() {
260
+ this.isStopped = true;
261
+ this.isRunning = false;
262
+ if (this.timeoutHandle) {
263
+ clearTimeout(this.timeoutHandle);
264
+ this.timeoutHandle = null;
265
+ }
266
+ // Clear all callbacks to prevent memory leaks
267
+ this.updateCallbacks = [];
268
+ this.errorCallbacks = [];
269
+ this.completeCallbacks = [];
270
+ }
271
+ /**
272
+ * Alias for stop() to implement Subscription interface
273
+ */
274
+ unsubscribe() {
275
+ this.stop();
276
+ }
277
+ /**
278
+ * Start the polling loop
279
+ */
280
+ startPolling() {
281
+ if (this.isStopped || this.isRunning) {
282
+ return;
283
+ }
284
+ this.isRunning = true;
285
+ this.poll();
286
+ }
287
+ /**
288
+ * Execute a single poll iteration
289
+ */
290
+ async poll() {
291
+ if (this.isStopped || !this.isRunning) {
292
+ return;
293
+ }
294
+ try {
295
+ // Check if timeout exceeded
296
+ const elapsed = Date.now() - this.startTime;
297
+ if (elapsed >= this.timeout) {
298
+ const error = new errors_js_1.TimeoutError(`Timeout watching intent ${this.intentId}`, this.timeout, { intentId: this.intentId, elapsed });
299
+ this.emitError(error);
300
+ this.stop();
301
+ return;
302
+ }
303
+ // Get current status
304
+ const intent = await this.tracker.getStatus(this.intentId);
305
+ // Check if status changed
306
+ const statusChanged = this.lastStatus !== null && this.lastStatus !== intent.status;
307
+ this.lastStatus = intent.status;
308
+ // Emit update if status changed
309
+ if (statusChanged) {
310
+ this.emitUpdate(intent);
311
+ }
312
+ // Check if we've reached a terminal status
313
+ const terminalStatuses = [
314
+ types_js_1.ExecutionStatus.SETTLED,
315
+ types_js_1.ExecutionStatus.ABORTED,
316
+ types_js_1.ExecutionStatus.EXPIRED
317
+ ];
318
+ if (terminalStatuses.includes(intent.status)) {
319
+ this.emitComplete(intent);
320
+ this.stop();
321
+ return;
322
+ }
323
+ // Schedule next poll
324
+ this.scheduleNextPoll();
325
+ }
326
+ catch (error) {
327
+ this.emitError(error instanceof Error ? error : new Error(String(error)));
328
+ this.stop();
329
+ }
330
+ }
331
+ /**
332
+ * Schedule the next poll iteration
333
+ */
334
+ scheduleNextPoll() {
335
+ if (this.isStopped || !this.isRunning) {
336
+ return;
337
+ }
338
+ this.timeoutHandle = setTimeout(() => {
339
+ this.poll();
340
+ }, this.interval);
341
+ }
342
+ /**
343
+ * Emit update event to all registered callbacks
344
+ */
345
+ emitUpdate(intent) {
346
+ for (const callback of this.updateCallbacks) {
347
+ try {
348
+ callback(intent);
349
+ }
350
+ catch (error) {
351
+ // Catch errors in callbacks to prevent them from breaking the polling loop
352
+ console.error('Error in onUpdate callback:', error);
353
+ }
354
+ }
355
+ }
356
+ /**
357
+ * Emit error event to all registered callbacks
358
+ */
359
+ emitError(error) {
360
+ for (const callback of this.errorCallbacks) {
361
+ try {
362
+ callback(error);
363
+ }
364
+ catch (err) {
365
+ // Catch errors in callbacks
366
+ console.error('Error in onError callback:', err);
367
+ }
368
+ }
369
+ }
370
+ /**
371
+ * Emit complete event to all registered callbacks
372
+ */
373
+ emitComplete(intent) {
374
+ for (const callback of this.completeCallbacks) {
375
+ try {
376
+ callback(intent);
377
+ }
378
+ catch (error) {
379
+ // Catch errors in callbacks
380
+ console.error('Error in onComplete callback:', error);
381
+ }
382
+ }
383
+ }
384
+ }
385
+ //# sourceMappingURL=execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/execution.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,yCAAmG;AACnG,2CAA2C;AAG3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,gBAAgB;IACV,MAAM,CAAa;IAEpC;;;;OAIG;IACH,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,SAAS,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAS,gBAAgB,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,KAAK,CAAC,aAAa,CACjB,QAAgB,EAChB,YAAiD,EACjD,OAAqB;QAErB,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,IAAI,CAAC;QAC3C,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;QAC1C,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAEnF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,OAAO,IAAI,EAAE,CAAC;YACZ,4BAA4B;YAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACvC,IAA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gBAC3E,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,KAAY;QAC5B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACH,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,4BAA4B;gBAC5B,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,MAAc;QACjC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC9C,IAAI,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,4BAA4B;gBAC5B,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JACK_SDK = exports.JackClient = exports.AgentUtils = exports.CostTracker = exports.ExecutionTracker = exports.IntentManager = exports.validateIntentParams = exports.parseIntentParams = exports.serializeIntentParams = exports.getTypedData = exports.RetryError = exports.TimeoutError = exports.ValidationError = exports.APIError = exports.NetworkError = exports.JackError = exports.ExecutionStatus = void 0;
4
+ // Re-export enums
5
+ var types_js_1 = require("./types.js");
6
+ Object.defineProperty(exports, "ExecutionStatus", { enumerable: true, get: function () { return types_js_1.ExecutionStatus; } });
7
+ // Re-export all error classes
8
+ var errors_js_1 = require("./errors.js");
9
+ Object.defineProperty(exports, "JackError", { enumerable: true, get: function () { return errors_js_1.JackError; } });
10
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_js_1.NetworkError; } });
11
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
12
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_js_1.ValidationError; } });
13
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_js_1.TimeoutError; } });
14
+ Object.defineProperty(exports, "RetryError", { enumerable: true, get: function () { return errors_js_1.RetryError; } });
15
+ // Re-export serialization functions
16
+ var serialization_js_1 = require("./serialization.js");
17
+ Object.defineProperty(exports, "getTypedData", { enumerable: true, get: function () { return serialization_js_1.getTypedData; } });
18
+ Object.defineProperty(exports, "serializeIntentParams", { enumerable: true, get: function () { return serialization_js_1.serializeIntentParams; } });
19
+ Object.defineProperty(exports, "parseIntentParams", { enumerable: true, get: function () { return serialization_js_1.parseIntentParams; } });
20
+ // Re-export validation functions
21
+ var validation_js_1 = require("./validation.js");
22
+ Object.defineProperty(exports, "validateIntentParams", { enumerable: true, get: function () { return validation_js_1.validateIntentParams; } });
23
+ // Re-export IntentManager
24
+ var intents_js_1 = require("./intents.js");
25
+ Object.defineProperty(exports, "IntentManager", { enumerable: true, get: function () { return intents_js_1.IntentManager; } });
26
+ // Re-export ExecutionTracker
27
+ var execution_js_1 = require("./execution.js");
28
+ Object.defineProperty(exports, "ExecutionTracker", { enumerable: true, get: function () { return execution_js_1.ExecutionTracker; } });
29
+ // Re-export CostTracker
30
+ var costs_js_1 = require("./costs.js");
31
+ Object.defineProperty(exports, "CostTracker", { enumerable: true, get: function () { return costs_js_1.CostTracker; } });
32
+ // Re-export AgentUtils
33
+ var agent_js_1 = require("./agent.js");
34
+ Object.defineProperty(exports, "AgentUtils", { enumerable: true, get: function () { return agent_js_1.AgentUtils; } });
35
+ // Re-export JackClient
36
+ var client_js_1 = require("./client.js");
37
+ Object.defineProperty(exports, "JackClient", { enumerable: true, get: function () { return client_js_1.JackClient; } });
38
+ // Import manager classes
39
+ const client_js_2 = require("./client.js");
40
+ const intents_js_2 = require("./intents.js");
41
+ const execution_js_2 = require("./execution.js");
42
+ const costs_js_2 = require("./costs.js");
43
+ const agent_js_2 = require("./agent.js");
44
+ // Import types and enums for use in this file
45
+ const types_js_2 = require("./types.js");
46
+ /**
47
+ * Main SDK class for JACK cross-chain execution kernel
48
+ *
49
+ * Provides a comprehensive, type-safe interface for interacting with the JACK system.
50
+ * Initializes all managers (intents, execution, costs, agent) and exposes them as
51
+ * public readonly properties. Also provides convenience methods for common operations.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // Initialize SDK
56
+ * const sdk = new JACK_SDK({ baseUrl: 'https://api.jack.example' });
57
+ *
58
+ * // Create and submit intent
59
+ * const typedData = sdk.intents.getTypedData(params);
60
+ * const signature = await wallet.signTypedData(typedData);
61
+ * const intentId = await sdk.submitIntent(params, signature);
62
+ *
63
+ * // Track execution
64
+ * const intent = await sdk.waitForSettlement(intentId);
65
+ * console.log('Settlement tx:', intent.settlementTx);
66
+ *
67
+ * // Access managers directly
68
+ * const costs = await sdk.costs.getCosts();
69
+ * const results = await sdk.agent.batchSubmit([...]);
70
+ * ```
71
+ *
72
+ * **Validates: Requirements 1.1, 1.2, 1.3, 1.4, 2.5**
73
+ */
74
+ class JACK_SDK {
75
+ /**
76
+ * Intent management - create, submit, query intents
77
+ */
78
+ intents;
79
+ /**
80
+ * Execution tracking - poll status, wait for completion
81
+ */
82
+ execution;
83
+ /**
84
+ * Cost tracking - query costs and budgets
85
+ */
86
+ costs;
87
+ /**
88
+ * Agent utilities - batch operations, subscriptions
89
+ */
90
+ agent;
91
+ /**
92
+ * Internal HTTP client (exposed for advanced use cases)
93
+ */
94
+ client;
95
+ /**
96
+ * Creates a new JACK_SDK instance
97
+ *
98
+ * Initializes all managers with the provided configuration. The configuration
99
+ * includes the base URL for the API and optional settings for timeout, retries,
100
+ * caching, and custom headers.
101
+ *
102
+ * @param config - Client configuration (baseUrl required, other options optional)
103
+ * @throws ValidationError if configuration is invalid
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // Basic initialization
108
+ * const sdk = new JACK_SDK({ baseUrl: 'https://api.jack.example' });
109
+ *
110
+ * // With custom configuration
111
+ * const sdk = new JACK_SDK({
112
+ * baseUrl: 'https://api.jack.example',
113
+ * timeout: 60000,
114
+ * maxRetries: 5,
115
+ * enableCache: true,
116
+ * cacheTTL: 120000,
117
+ * headers: { 'Authorization': 'Bearer token' }
118
+ * });
119
+ * ```
120
+ */
121
+ constructor(config) {
122
+ // Initialize core HTTP client
123
+ this.client = new client_js_2.JackClient(config);
124
+ // Initialize all managers
125
+ this.intents = new intents_js_2.IntentManager(this.client);
126
+ this.execution = new execution_js_2.ExecutionTracker(this.client);
127
+ this.costs = new costs_js_2.CostTracker(this.client);
128
+ this.agent = new agent_js_2.AgentUtils(this.client);
129
+ }
130
+ /**
131
+ * Convenience method: Submit a signed intent
132
+ *
133
+ * Delegates to IntentManager.submit(). This is a convenience method
134
+ * for the most common operation - submitting a signed intent.
135
+ *
136
+ * @param params - Intent parameters
137
+ * @param signature - EIP-712 signature from wallet
138
+ * @returns Promise resolving to the intent ID
139
+ * @throws ValidationError if parameters are invalid
140
+ * @throws APIError if the API returns an error
141
+ * @throws NetworkError if the network request fails
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const intentId = await sdk.submitIntent(params, signature);
146
+ * console.log('Intent submitted:', intentId);
147
+ * ```
148
+ *
149
+ * **Validates: Requirement 1.2**
150
+ */
151
+ async submitIntent(params, signature) {
152
+ return this.intents.submit(params, signature);
153
+ }
154
+ /**
155
+ * Convenience method: Get a single intent by ID
156
+ *
157
+ * Delegates to IntentManager.get(). This is a convenience method
158
+ * for querying a single intent's current state.
159
+ *
160
+ * @param intentId - The intent ID to query
161
+ * @returns Promise resolving to the complete Intent object
162
+ * @throws APIError if the intent is not found or other API error
163
+ * @throws NetworkError if the network request fails
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const intent = await sdk.getIntent('JK-ABC123456');
168
+ * console.log('Status:', intent.status);
169
+ * ```
170
+ *
171
+ * **Validates: Requirement 1.3**
172
+ */
173
+ async getIntent(intentId) {
174
+ return this.intents.get(intentId);
175
+ }
176
+ /**
177
+ * Convenience method: List all intents
178
+ *
179
+ * Delegates to IntentManager.list(). This is a convenience method
180
+ * for retrieving all intents.
181
+ *
182
+ * @returns Promise resolving to an array of Intent objects
183
+ * @throws APIError if the API returns an error
184
+ * @throws NetworkError if the network request fails
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const intents = await sdk.listIntents();
189
+ * console.log(`Found ${intents.length} intents`);
190
+ * ```
191
+ *
192
+ * **Validates: Requirement 1.4**
193
+ */
194
+ async listIntents() {
195
+ return this.intents.list();
196
+ }
197
+ /**
198
+ * Convenience method: Wait for intent to settle
199
+ *
200
+ * Polls the intent status until it reaches SETTLED status or the timeout
201
+ * is exceeded. This is a convenience method that wraps ExecutionTracker.waitForStatus()
202
+ * with sensible defaults for waiting for settlement.
203
+ *
204
+ * @param intentId - The intent ID to wait for
205
+ * @param timeout - Maximum time to wait in milliseconds (default: 120000 = 2 minutes)
206
+ * @returns Promise resolving to the Intent when settled
207
+ * @throws TimeoutError if timeout is exceeded before settlement
208
+ * @throws APIError if the API returns an error
209
+ * @throws NetworkError if the network request fails
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * // Wait with default timeout (2 minutes)
214
+ * const intent = await sdk.waitForSettlement('JK-ABC123456');
215
+ * console.log('Settlement tx:', intent.settlementTx);
216
+ *
217
+ * // Wait with custom timeout (5 minutes)
218
+ * const intent = await sdk.waitForSettlement('JK-ABC123456', 300000);
219
+ * ```
220
+ *
221
+ * **Validates: Requirement 2.5**
222
+ */
223
+ async waitForSettlement(intentId, timeout = 120000) {
224
+ return this.execution.waitForStatus(intentId, types_js_2.ExecutionStatus.SETTLED, { timeout, interval: 2000 });
225
+ }
226
+ /**
227
+ * Legacy method: Get execution status
228
+ *
229
+ * @deprecated Use sdk.getIntent() or sdk.execution.getStatus() instead
230
+ *
231
+ * This method is kept for backward compatibility with existing dashboard code.
232
+ * It delegates to the execution tracker's getStatus method.
233
+ *
234
+ * @param intentId - The intent ID to query
235
+ * @returns Promise resolving to the Intent object
236
+ */
237
+ async getExecutionStatus(intentId) {
238
+ return this.execution.getStatus(intentId);
239
+ }
240
+ /**
241
+ * Legacy method: Get intent typed data
242
+ *
243
+ * @deprecated Use sdk.intents.getTypedData() instead
244
+ *
245
+ * This method is kept for backward compatibility with existing dashboard code.
246
+ * It delegates to the intent manager's getTypedData method.
247
+ *
248
+ * @param params - Intent parameters
249
+ * @returns EIP-712 TypedData object
250
+ */
251
+ getIntentTypedData(params) {
252
+ return this.intents.getTypedData(params);
253
+ }
254
+ }
255
+ exports.JACK_SDK = JACK_SDK;
256
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AA+BA,kBAAkB;AAClB,uCAA6C;AAApC,2GAAA,eAAe,OAAA;AAExB,8BAA8B;AAC9B,yCAOqB;AANnB,sGAAA,SAAS,OAAA;AACT,yGAAA,YAAY,OAAA;AACZ,qGAAA,QAAQ,OAAA;AACR,4GAAA,eAAe,OAAA;AACf,yGAAA,YAAY,OAAA;AACZ,uGAAA,UAAU,OAAA;AAGZ,oCAAoC;AACpC,uDAI4B;AAH1B,gHAAA,YAAY,OAAA;AACZ,yHAAA,qBAAqB,OAAA;AACrB,qHAAA,iBAAiB,OAAA;AAGnB,iCAAiC;AACjC,iDAEyB;AADvB,qHAAA,oBAAoB,OAAA;AAGtB,0BAA0B;AAC1B,2CAA6C;AAApC,2GAAA,aAAa,OAAA;AAEtB,6BAA6B;AAC7B,+CAAkD;AAAzC,gHAAA,gBAAgB,OAAA;AAEzB,wBAAwB;AACxB,uCAAyC;AAAhC,uGAAA,WAAW,OAAA;AAEpB,uBAAuB;AACvB,uCAAwC;AAA/B,sGAAA,UAAU,OAAA;AAEnB,uBAAuB;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