@terminals-tech/sdk 1.0.0-rc.1 → 1.0.0-rc.2

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 (79) hide show
  1. package/dist/WebContainerManager-SHXC5VKI.js +22 -0
  2. package/dist/browser-http-client-ZQLDWZMU.js +317 -0
  3. package/dist/cache-VKYSQRXX.js +45 -0
  4. package/dist/capabilities-MIPUMBLL.js +96 -0
  5. package/dist/chunk-2ESYSVXG.js +48 -0
  6. package/dist/chunk-2WTYE4SW.js +190 -0
  7. package/dist/chunk-3CEM77QZ.js +474 -0
  8. package/dist/chunk-3LFMIVJM.js +40 -0
  9. package/dist/chunk-ABCK4FWN.js +136 -0
  10. package/dist/chunk-AFDUOYHD.js +2060 -0
  11. package/dist/chunk-BCOQMFKT.js +265 -0
  12. package/dist/chunk-BKB3MD5Y.js +723 -0
  13. package/dist/chunk-BYXBJQAS.js +0 -0
  14. package/dist/chunk-DKFJIILR.js +9798 -0
  15. package/dist/chunk-EXI3LJVJ.js +51 -0
  16. package/dist/chunk-FOXUEYWK.js +42 -0
  17. package/dist/chunk-GJWAJAX3.js +173 -0
  18. package/dist/chunk-H3POJCFA.js +333 -0
  19. package/dist/chunk-KHR7ZYCX.js +4034 -0
  20. package/dist/chunk-NTMBOESX.js +152 -0
  21. package/dist/chunk-OSSRZOGC.js +190 -0
  22. package/dist/chunk-PUZ2S62E.js +977 -0
  23. package/dist/chunk-PWAHFID5.js +381 -0
  24. package/dist/chunk-Q2VI6ICE.js +188 -0
  25. package/dist/chunk-Q4B7YS7T.js +557 -0
  26. package/dist/chunk-QJFKEQHF.js +6460 -0
  27. package/dist/chunk-QWXPVB2L.js +320 -0
  28. package/dist/chunk-QWZRZKLZ.js +896 -0
  29. package/dist/chunk-SHPGIVDH.js +5521 -0
  30. package/dist/chunk-TSQ3BGLA.js +11945 -0
  31. package/dist/chunk-UJDUQNE2.js +79 -0
  32. package/dist/chunk-UKVUPKZP.js +296 -0
  33. package/dist/chunk-VZA2NUH3.js +118 -0
  34. package/dist/chunk-WGBCRNMB.js +1817 -0
  35. package/dist/chunk-WU4OTGJE.js +752 -0
  36. package/dist/chunk-XPJ63Y6T.js +70 -0
  37. package/dist/chunk-Y2EULKA2.js +172 -0
  38. package/dist/chunk-YJEZWCYV.js +94 -0
  39. package/dist/chunk-ZVO47SQV.js +150 -0
  40. package/dist/container-lite-KQX3NMPY.js +327 -0
  41. package/dist/core-H2UUDATO.js +146 -0
  42. package/dist/crypto-D4LMI2RN.js +45 -0
  43. package/dist/db-BWC2GGBN.js +50 -0
  44. package/dist/demo-VXMGMJNK.js +87 -0
  45. package/dist/diagnostics-6RQTBR6I.js +113 -0
  46. package/dist/dist-OPDCWARF.js +727 -0
  47. package/dist/dist-VXJEKX3T.js +2441 -0
  48. package/dist/dist-VYGJXGUS.js +1008 -0
  49. package/dist/embeddings-7QXTXUMC.js +15 -0
  50. package/dist/embeddings-MAEWWUHW.js +9 -0
  51. package/dist/graph-RKMNE2X5.js +36 -0
  52. package/dist/hvm-DRQK2MUT.js +126 -0
  53. package/dist/index.cjs +11706 -4004
  54. package/dist/index.d.cts +1299 -1339
  55. package/dist/index.d.ts +1299 -1339
  56. package/dist/index.js +189 -7938
  57. package/dist/mcp-NK34ZNM5.js +101 -0
  58. package/dist/mcp-client-service-browser-SGB2K3VZ.js +14 -0
  59. package/dist/neuro-state-XHRGIRVO.js +498 -0
  60. package/dist/nodes-DXKYDTVO.js +224 -0
  61. package/dist/package-EXUIU2RL.js +93 -0
  62. package/dist/package-VGL7HYTO.js +106 -0
  63. package/dist/package-XHMLOAQ4.js +98 -0
  64. package/dist/pg-events-QJAM2HIP.js +15 -0
  65. package/dist/pgliteService-IUGNNOVU.js +258 -0
  66. package/dist/policy-IRJCM6FS.js +13 -0
  67. package/dist/registry-BL3TDQDB.js +26 -0
  68. package/dist/registry-FW63E7FE.js +16 -0
  69. package/dist/registry-ZQ2IBLF6.js +9 -0
  70. package/dist/scheduler-H6Q53IMI.js +122 -0
  71. package/dist/secret-store-H7273UIT.js +18 -0
  72. package/dist/server-7DM74VFW.js +18 -0
  73. package/dist/skills-KLTTT2RM.js +6375 -0
  74. package/dist/stack-CHDAFU2S.js +103 -0
  75. package/dist/storage-L7MWNSPG.js +13 -0
  76. package/dist/supabaseService-6AYP2VY3.js +476 -0
  77. package/dist/topology-CIWWNVAN.js +13 -0
  78. package/dist/webcontainer-3LDJVIIL.js +281 -0
  79. package/package.json +2 -2
@@ -0,0 +1,152 @@
1
+ // ../../lib/terminals-tech/core/base/retry.ts
2
+ function calculateDelay(attempt, baseDelayMs, maxDelayMs, jitter = 0) {
3
+ let delay = baseDelayMs * Math.pow(2, attempt);
4
+ delay = Math.min(delay, maxDelayMs);
5
+ if (jitter > 0) {
6
+ const jitterAmount = delay * jitter * Math.random();
7
+ delay = delay + jitterAmount - jitter * delay / 2;
8
+ delay = Math.max(baseDelayMs, delay);
9
+ }
10
+ return Math.floor(delay);
11
+ }
12
+ function exponentialBackoff(options = {}) {
13
+ return {
14
+ maxAttempts: options.maxAttempts ?? 3,
15
+ baseDelayMs: options.baseDelayMs ?? 100,
16
+ maxDelayMs: options.maxDelayMs ?? 1e4,
17
+ jitter: options.jitter ?? 0.1,
18
+ shouldRetry: options.shouldRetry ?? defaultShouldRetry
19
+ };
20
+ }
21
+ function defaultShouldRetry(error, _attempt) {
22
+ if (error.name === "TypeError" && error.message.includes("fetch")) {
23
+ return true;
24
+ }
25
+ if (error.name === "AbortError") {
26
+ return false;
27
+ }
28
+ if ("status" in error) {
29
+ const status = error.status;
30
+ return status >= 500 || status === 429;
31
+ }
32
+ return true;
33
+ }
34
+ async function withRetry(fn, strategyOrOptions = {}) {
35
+ const strategy = "maxAttempts" in strategyOrOptions && "shouldRetry" in strategyOrOptions ? strategyOrOptions : exponentialBackoff(strategyOrOptions);
36
+ const options = strategyOrOptions;
37
+ let lastError = null;
38
+ for (let attempt = 0; attempt < strategy.maxAttempts; attempt++) {
39
+ if (options.signal?.aborted) {
40
+ throw new DOMException("Operation was aborted", "AbortError");
41
+ }
42
+ try {
43
+ return await fn();
44
+ } catch (error) {
45
+ lastError = error instanceof Error ? error : new Error(String(error));
46
+ const isLastAttempt = attempt >= strategy.maxAttempts - 1;
47
+ if (isLastAttempt || !strategy.shouldRetry(lastError, attempt)) {
48
+ throw lastError;
49
+ }
50
+ const delay = calculateDelay(
51
+ attempt,
52
+ strategy.baseDelayMs,
53
+ strategy.maxDelayMs,
54
+ strategy.jitter
55
+ );
56
+ options.onRetry?.(lastError, attempt + 1, delay);
57
+ await new Promise((resolve, reject) => {
58
+ const timeoutId = setTimeout(resolve, delay);
59
+ if (options.signal) {
60
+ const abortHandler = () => {
61
+ clearTimeout(timeoutId);
62
+ reject(new DOMException("Operation was aborted", "AbortError"));
63
+ };
64
+ options.signal.addEventListener("abort", abortHandler, {
65
+ once: true
66
+ });
67
+ }
68
+ });
69
+ }
70
+ }
71
+ throw lastError ?? new Error("Retry failed");
72
+ }
73
+ function createCircuitBreaker(options) {
74
+ const state = {
75
+ failures: 0,
76
+ lastFailure: null,
77
+ isOpen: false,
78
+ nextAttempt: null
79
+ };
80
+ let halfOpenInFlight = 0;
81
+ return {
82
+ /**
83
+ * Execute function with circuit breaker protection.
84
+ *
85
+ * States:
86
+ * CLOSED — failures < threshold, all requests pass through
87
+ * OPEN — failures >= threshold, fast-fails until resetTimeoutMs elapses
88
+ * HALF_OPEN — resetTimeoutMs elapsed, allows `halfOpenRequests` concurrent probes
89
+ *
90
+ * Transitions:
91
+ * T1: CLOSED → CLOSED (success resets failures)
92
+ * T2: CLOSED → OPEN (failure hits threshold)
93
+ * T3: OPEN → OPEN (fast-fail, time not elapsed)
94
+ * T4: OPEN → HALF_OPEN (time elapsed, probe allowed)
95
+ * T5: HALF_OPEN → CLOSED (probe succeeds)
96
+ * T6: HALF_OPEN → OPEN (probe fails)
97
+ */
98
+ async execute(fn) {
99
+ if (state.isOpen) {
100
+ const now = Date.now();
101
+ if (state.nextAttempt && now < state.nextAttempt) {
102
+ throw new Error("Circuit breaker is open");
103
+ }
104
+ if (options.halfOpenRequests != null && halfOpenInFlight >= options.halfOpenRequests) {
105
+ throw new Error("Circuit breaker half-open \u2014 probe limit reached");
106
+ }
107
+ halfOpenInFlight++;
108
+ }
109
+ try {
110
+ const result = await fn();
111
+ state.failures = 0;
112
+ state.isOpen = false;
113
+ state.nextAttempt = null;
114
+ halfOpenInFlight = 0;
115
+ return result;
116
+ } catch (error) {
117
+ if (state.isOpen) {
118
+ halfOpenInFlight = Math.max(0, halfOpenInFlight - 1);
119
+ }
120
+ state.failures++;
121
+ state.lastFailure = Date.now();
122
+ if (state.failures >= options.failureThreshold) {
123
+ state.isOpen = true;
124
+ state.nextAttempt = Date.now() + options.resetTimeoutMs;
125
+ halfOpenInFlight = 0;
126
+ }
127
+ throw error;
128
+ }
129
+ },
130
+ /**
131
+ * Get current state
132
+ */
133
+ getState() {
134
+ return { ...state };
135
+ },
136
+ /**
137
+ * Manually reset the circuit breaker
138
+ */
139
+ reset() {
140
+ state.failures = 0;
141
+ state.lastFailure = null;
142
+ state.isOpen = false;
143
+ state.nextAttempt = null;
144
+ halfOpenInFlight = 0;
145
+ }
146
+ };
147
+ }
148
+
149
+ export {
150
+ withRetry,
151
+ createCircuitBreaker
152
+ };
@@ -0,0 +1,190 @@
1
+ // ../../lib/errors/types.ts
2
+ var ErrorCodes = {
3
+ // Auth errors
4
+ AUTH_TOKEN_EXPIRED: "AUTH_TOKEN_EXPIRED",
5
+ AUTH_TOKEN_REFRESH_FAILED: "AUTH_TOKEN_REFRESH_FAILED",
6
+ AUTH_SESSION_INVALID: "AUTH_SESSION_INVALID",
7
+ AUTH_INIT_RACE: "AUTH_INIT_RACE",
8
+ AUTH_PROVIDER_UNAVAILABLE: "AUTH_PROVIDER_UNAVAILABLE",
9
+ // Inference errors
10
+ INFERENCE_PROVIDER_UNAVAILABLE: "INFERENCE_PROVIDER_UNAVAILABLE",
11
+ INFERENCE_CIRCUIT_OPEN: "INFERENCE_CIRCUIT_OPEN",
12
+ INFERENCE_TIMEOUT: "INFERENCE_TIMEOUT",
13
+ INFERENCE_RATE_LIMITED: "INFERENCE_RATE_LIMITED",
14
+ INFERENCE_API_ERROR: "INFERENCE_API_ERROR",
15
+ // Sync errors
16
+ SYNC_CONFLICT: "SYNC_CONFLICT",
17
+ SYNC_OFFLINE: "SYNC_OFFLINE",
18
+ SYNC_FAILED: "SYNC_FAILED",
19
+ SYNC_LEADER_CHANGED: "SYNC_LEADER_CHANGED",
20
+ // MCP errors
21
+ MCP_CONNECTION_FAILED: "MCP_CONNECTION_FAILED",
22
+ MCP_TOOL_EXECUTION_FAILED: "MCP_TOOL_EXECUTION_FAILED",
23
+ MCP_SERVER_UNAVAILABLE: "MCP_SERVER_UNAVAILABLE",
24
+ // WebContainer errors
25
+ WEBCONTAINER_NOT_SUPPORTED: "WEBCONTAINER_NOT_SUPPORTED",
26
+ WEBCONTAINER_COOP_MISSING: "WEBCONTAINER_COOP_MISSING",
27
+ WEBCONTAINER_BOOT_FAILED: "WEBCONTAINER_BOOT_FAILED",
28
+ WEBCONTAINER_FS_ERROR: "WEBCONTAINER_FS_ERROR",
29
+ // Network errors
30
+ NETWORK_OFFLINE: "NETWORK_OFFLINE",
31
+ NETWORK_TIMEOUT: "NETWORK_TIMEOUT",
32
+ NETWORK_DNS_FAILED: "NETWORK_DNS_FAILED",
33
+ // Storage errors
34
+ STORAGE_QUOTA_EXCEEDED: "STORAGE_QUOTA_EXCEEDED",
35
+ STORAGE_ACCESS_DENIED: "STORAGE_ACCESS_DENIED",
36
+ STORAGE_CORRUPTED: "STORAGE_CORRUPTED",
37
+ // Platform errors
38
+ PLATFORM_STACK_FAILED: "PLATFORM_STACK_FAILED",
39
+ PLATFORM_NODE_FAILED: "PLATFORM_NODE_FAILED",
40
+ PLATFORM_TRAINING_FAILED: "PLATFORM_TRAINING_FAILED",
41
+ PLATFORM_TRAINING_NOT_CONFIGURED: "PLATFORM_TRAINING_NOT_CONFIGURED",
42
+ PLATFORM_TRAINING_UNAUTHORIZED: "PLATFORM_TRAINING_UNAUTHORIZED",
43
+ PLATFORM_TRAINING_OFFLINE: "PLATFORM_TRAINING_OFFLINE",
44
+ PLATFORM_TRAINING_RATE_LIMITED: "PLATFORM_TRAINING_RATE_LIMITED",
45
+ PLATFORM_TRAINING_INVALID_REQUEST: "PLATFORM_TRAINING_INVALID_REQUEST",
46
+ // Generic
47
+ UNKNOWN_ERROR: "UNKNOWN_ERROR",
48
+ RUNAWAY_ERRORS: "RUNAWAY_ERRORS"
49
+ };
50
+ var DEFAULT_ERROR_BUS_CONFIG = {
51
+ dedupWindowMs: 5e3,
52
+ maxErrorsBeforeCutoff: 100,
53
+ retentionMs: 5 * 60 * 1e3,
54
+ maxPerSourcePerMinute: 10,
55
+ cutoffPauseMs: 3e4
56
+ };
57
+
58
+ // ../../lib/errors/base.ts
59
+ var TerminalsError = class _TerminalsError extends Error {
60
+ /** Error source domain */
61
+ source;
62
+ /** Machine-readable error code */
63
+ code;
64
+ /** Error severity level */
65
+ severity;
66
+ /** Whether the operation can be retried */
67
+ retryable;
68
+ /** Whether error should be shown to user */
69
+ userFacing;
70
+ /** Additional context/metadata */
71
+ metadata;
72
+ /** Original error if this wraps another error */
73
+ cause;
74
+ constructor(message, options) {
75
+ super(message);
76
+ this.name = this.constructor.name;
77
+ this.source = options.source;
78
+ this.code = options.code;
79
+ this.severity = options.severity ?? "error";
80
+ this.retryable = options.retryable ?? false;
81
+ this.userFacing = options.userFacing ?? false;
82
+ this.metadata = options.metadata;
83
+ this.cause = options.cause;
84
+ if (Error.captureStackTrace) {
85
+ Error.captureStackTrace(this, this.constructor);
86
+ }
87
+ }
88
+ /**
89
+ * Convert to ErrorInput for error bus emission.
90
+ */
91
+ toErrorInput() {
92
+ return {
93
+ source: this.source,
94
+ severity: this.severity,
95
+ message: this.message,
96
+ code: this.code,
97
+ userFacing: this.userFacing,
98
+ retryable: this.retryable,
99
+ metadata: {
100
+ ...this.metadata,
101
+ errorName: this.name,
102
+ ...this.cause && {
103
+ causeName: this.cause.name,
104
+ causeMessage: this.cause.message
105
+ }
106
+ }
107
+ };
108
+ }
109
+ /**
110
+ * Serialize for logging/transmission.
111
+ */
112
+ toJSON() {
113
+ return {
114
+ name: this.name,
115
+ message: this.message,
116
+ source: this.source,
117
+ code: this.code,
118
+ severity: this.severity,
119
+ retryable: this.retryable,
120
+ userFacing: this.userFacing,
121
+ metadata: this.metadata,
122
+ stack: this.stack,
123
+ cause: this.cause ? { name: this.cause.name, message: this.cause.message } : void 0
124
+ };
125
+ }
126
+ /**
127
+ * Create from an unknown error.
128
+ */
129
+ static fromUnknown(error, source = "unknown") {
130
+ if (error instanceof _TerminalsError) {
131
+ return error;
132
+ }
133
+ if (error instanceof Error) {
134
+ return new _TerminalsError(error.message, {
135
+ source,
136
+ code: ErrorCodes.UNKNOWN_ERROR,
137
+ severity: "error",
138
+ cause: error
139
+ });
140
+ }
141
+ return new _TerminalsError(String(error), {
142
+ source,
143
+ code: ErrorCodes.UNKNOWN_ERROR,
144
+ severity: "error"
145
+ });
146
+ }
147
+ };
148
+ var SyncError = class extends TerminalsError {
149
+ constructor(message, code = ErrorCodes.SYNC_FAILED, metadata) {
150
+ super(message, {
151
+ source: "sync",
152
+ code,
153
+ severity: code === ErrorCodes.SYNC_CONFLICT ? "warn" : "error",
154
+ retryable: code !== ErrorCodes.SYNC_CONFLICT,
155
+ userFacing: code === ErrorCodes.SYNC_OFFLINE,
156
+ metadata
157
+ });
158
+ }
159
+ };
160
+ var MCPError = class extends TerminalsError {
161
+ constructor(message, code = ErrorCodes.MCP_CONNECTION_FAILED, metadata) {
162
+ super(message, {
163
+ source: "mcp",
164
+ code,
165
+ severity: code === ErrorCodes.MCP_SERVER_UNAVAILABLE ? "warn" : "error",
166
+ retryable: code !== ErrorCodes.MCP_TOOL_EXECUTION_FAILED,
167
+ userFacing: true,
168
+ metadata
169
+ });
170
+ }
171
+ };
172
+ var WebContainerError = class extends TerminalsError {
173
+ constructor(message, code = ErrorCodes.WEBCONTAINER_BOOT_FAILED, metadata) {
174
+ super(message, {
175
+ source: "webcontainer",
176
+ code,
177
+ severity: code === ErrorCodes.WEBCONTAINER_NOT_SUPPORTED ? "info" : "error",
178
+ retryable: code === ErrorCodes.WEBCONTAINER_BOOT_FAILED,
179
+ userFacing: true,
180
+ metadata
181
+ });
182
+ }
183
+ };
184
+
185
+ export {
186
+ ErrorCodes,
187
+ SyncError,
188
+ MCPError,
189
+ WebContainerError
190
+ };