@maximem/synap-js-sdk 0.2.0 → 0.2.1
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/bridge/synap_bridge.py +1 -1
- package/package.json +1 -1
- package/src/bridge-manager.js +2 -1
- package/src/errors.js +187 -0
- package/src/index.js +2 -0
- package/types/index.d.ts +27 -0
package/bridge/synap_bridge.py
CHANGED
|
@@ -709,7 +709,7 @@ async def main() -> None:
|
|
|
709
709
|
write_response({"id": req_id, "result": result, "error": None})
|
|
710
710
|
except Exception as exc:
|
|
711
711
|
logger.error("Handler error for %s: %s", method, traceback.format_exc())
|
|
712
|
-
write_response({"id": req_id, "result": None, "error": str(exc)})
|
|
712
|
+
write_response({"id": req_id, "result": None, "error": str(exc), "error_type": type(exc).__name__})
|
|
713
713
|
|
|
714
714
|
|
|
715
715
|
if __name__ == "__main__":
|
package/package.json
CHANGED
package/src/bridge-manager.js
CHANGED
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
resolveInstanceId,
|
|
8
8
|
setupPythonRuntime,
|
|
9
9
|
} = require('./runtime');
|
|
10
|
+
const { createSynapError } = require('./errors');
|
|
10
11
|
|
|
11
12
|
class BridgeManager {
|
|
12
13
|
constructor(options = {}) {
|
|
@@ -147,7 +148,7 @@ class BridgeManager {
|
|
|
147
148
|
this.pending.delete(payload.id);
|
|
148
149
|
|
|
149
150
|
if (payload.error) {
|
|
150
|
-
pending.reject(
|
|
151
|
+
pending.reject(createSynapError(payload.error, payload.error_type));
|
|
151
152
|
} else {
|
|
152
153
|
pending.resolve(payload.result);
|
|
153
154
|
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class SynapError extends Error {
|
|
4
|
+
constructor(message, correlationId) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'SynapError';
|
|
7
|
+
this.correlationId = correlationId || null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class SynapTransientError extends SynapError {
|
|
12
|
+
constructor(message, correlationId) {
|
|
13
|
+
super(message, correlationId);
|
|
14
|
+
this.name = 'SynapTransientError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class SynapPermanentError extends SynapError {
|
|
19
|
+
constructor(message, correlationId) {
|
|
20
|
+
super(message, correlationId);
|
|
21
|
+
this.name = 'SynapPermanentError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class NetworkTimeoutError extends SynapTransientError {
|
|
26
|
+
constructor(message, correlationId) {
|
|
27
|
+
super(message, correlationId);
|
|
28
|
+
this.name = 'NetworkTimeoutError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class RateLimitError extends SynapTransientError {
|
|
33
|
+
constructor(message, retryAfterSeconds, correlationId) {
|
|
34
|
+
super(message, correlationId);
|
|
35
|
+
this.name = 'RateLimitError';
|
|
36
|
+
this.retryAfterSeconds = retryAfterSeconds || null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class ServiceUnavailableError extends SynapTransientError {
|
|
41
|
+
constructor(message, correlationId) {
|
|
42
|
+
super(message, correlationId);
|
|
43
|
+
this.name = 'ServiceUnavailableError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
class AgentUnavailableError extends SynapTransientError {
|
|
48
|
+
constructor(message, correlationId) {
|
|
49
|
+
super(message, correlationId);
|
|
50
|
+
this.name = 'AgentUnavailableError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class InvalidInputError extends SynapPermanentError {
|
|
55
|
+
constructor(message, correlationId) {
|
|
56
|
+
super(message, correlationId);
|
|
57
|
+
this.name = 'InvalidInputError';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class InvalidInstanceIdError extends InvalidInputError {
|
|
62
|
+
constructor(message, correlationId) {
|
|
63
|
+
super(message, correlationId);
|
|
64
|
+
this.name = 'InvalidInstanceIdError';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class InvalidConversationIdError extends InvalidInputError {
|
|
69
|
+
constructor(message, correlationId) {
|
|
70
|
+
super(message, correlationId);
|
|
71
|
+
this.name = 'InvalidConversationIdError';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
class AuthenticationError extends SynapPermanentError {
|
|
76
|
+
constructor(message, correlationId) {
|
|
77
|
+
super(message, correlationId);
|
|
78
|
+
this.name = 'AuthenticationError';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class CertificateExpiredError extends AuthenticationError {
|
|
83
|
+
constructor(message, correlationId) {
|
|
84
|
+
super(message, correlationId);
|
|
85
|
+
this.name = 'CertificateExpiredError';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class CertificateRenewalError extends AuthenticationError {
|
|
90
|
+
constructor(message, correlationId) {
|
|
91
|
+
super(message, correlationId);
|
|
92
|
+
this.name = 'CertificateRenewalError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
class BootstrapKeyInvalidError extends AuthenticationError {
|
|
97
|
+
constructor(message, correlationId) {
|
|
98
|
+
super(message, correlationId);
|
|
99
|
+
this.name = 'BootstrapKeyInvalidError';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class BootstrapError extends SynapPermanentError {
|
|
104
|
+
constructor(message, correlationId) {
|
|
105
|
+
super(message, correlationId);
|
|
106
|
+
this.name = 'BootstrapError';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class ContextNotFoundError extends SynapPermanentError {
|
|
111
|
+
constructor(message, correlationId) {
|
|
112
|
+
super(message, correlationId);
|
|
113
|
+
this.name = 'ContextNotFoundError';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class SessionExpiredError extends SynapPermanentError {
|
|
118
|
+
constructor(message, correlationId) {
|
|
119
|
+
super(message, correlationId);
|
|
120
|
+
this.name = 'SessionExpiredError';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
class ListeningAlreadyActiveError extends SynapPermanentError {
|
|
125
|
+
constructor(message, correlationId) {
|
|
126
|
+
super(message, correlationId);
|
|
127
|
+
this.name = 'ListeningAlreadyActiveError';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class ListeningNotActiveError extends SynapPermanentError {
|
|
132
|
+
constructor(message, correlationId) {
|
|
133
|
+
super(message, correlationId);
|
|
134
|
+
this.name = 'ListeningNotActiveError';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const ERROR_MAP = {
|
|
139
|
+
SynapError,
|
|
140
|
+
SynapTransientError,
|
|
141
|
+
SynapPermanentError,
|
|
142
|
+
NetworkTimeoutError,
|
|
143
|
+
RateLimitError,
|
|
144
|
+
ServiceUnavailableError,
|
|
145
|
+
AgentUnavailableError,
|
|
146
|
+
InvalidInputError,
|
|
147
|
+
InvalidInstanceIdError,
|
|
148
|
+
InvalidConversationIdError,
|
|
149
|
+
AuthenticationError,
|
|
150
|
+
CertificateExpiredError,
|
|
151
|
+
CertificateRenewalError,
|
|
152
|
+
BootstrapKeyInvalidError,
|
|
153
|
+
BootstrapError,
|
|
154
|
+
ContextNotFoundError,
|
|
155
|
+
SessionExpiredError,
|
|
156
|
+
ListeningAlreadyActiveError,
|
|
157
|
+
ListeningNotActiveError,
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
function createSynapError(message, errorType) {
|
|
161
|
+
const ErrorClass = ERROR_MAP[errorType];
|
|
162
|
+
if (ErrorClass) return new ErrorClass(message);
|
|
163
|
+
return new SynapError(message);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
SynapError,
|
|
168
|
+
SynapTransientError,
|
|
169
|
+
SynapPermanentError,
|
|
170
|
+
NetworkTimeoutError,
|
|
171
|
+
RateLimitError,
|
|
172
|
+
ServiceUnavailableError,
|
|
173
|
+
AgentUnavailableError,
|
|
174
|
+
InvalidInputError,
|
|
175
|
+
InvalidInstanceIdError,
|
|
176
|
+
InvalidConversationIdError,
|
|
177
|
+
AuthenticationError,
|
|
178
|
+
CertificateExpiredError,
|
|
179
|
+
CertificateRenewalError,
|
|
180
|
+
BootstrapKeyInvalidError,
|
|
181
|
+
BootstrapError,
|
|
182
|
+
ContextNotFoundError,
|
|
183
|
+
SessionExpiredError,
|
|
184
|
+
ListeningAlreadyActiveError,
|
|
185
|
+
ListeningNotActiveError,
|
|
186
|
+
createSynapError,
|
|
187
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { SynapClient } = require('./synap-client');
|
|
2
2
|
const { setupPythonRuntime, resolveInstanceId } = require('./runtime');
|
|
3
3
|
const { setupTypeScriptExtension } = require('./setup-typescript');
|
|
4
|
+
const errors = require('./errors');
|
|
4
5
|
|
|
5
6
|
module.exports = {
|
|
6
7
|
SynapClient,
|
|
@@ -8,4 +9,5 @@ module.exports = {
|
|
|
8
9
|
setupPythonRuntime,
|
|
9
10
|
setupTypeScriptExtension,
|
|
10
11
|
resolveInstanceId,
|
|
12
|
+
...errors,
|
|
11
13
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -352,6 +352,33 @@ export interface SetupTypeScriptExtensionResult {
|
|
|
352
352
|
wrapperCreated: boolean;
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
// Error classes
|
|
356
|
+
export class SynapError extends Error {
|
|
357
|
+
correlationId: string | null;
|
|
358
|
+
constructor(message: string, correlationId?: string);
|
|
359
|
+
}
|
|
360
|
+
export class SynapTransientError extends SynapError {}
|
|
361
|
+
export class SynapPermanentError extends SynapError {}
|
|
362
|
+
export class NetworkTimeoutError extends SynapTransientError {}
|
|
363
|
+
export class RateLimitError extends SynapTransientError {
|
|
364
|
+
retryAfterSeconds: number | null;
|
|
365
|
+
constructor(message: string, retryAfterSeconds?: number, correlationId?: string);
|
|
366
|
+
}
|
|
367
|
+
export class ServiceUnavailableError extends SynapTransientError {}
|
|
368
|
+
export class AgentUnavailableError extends SynapTransientError {}
|
|
369
|
+
export class InvalidInputError extends SynapPermanentError {}
|
|
370
|
+
export class InvalidInstanceIdError extends InvalidInputError {}
|
|
371
|
+
export class InvalidConversationIdError extends InvalidInputError {}
|
|
372
|
+
export class AuthenticationError extends SynapPermanentError {}
|
|
373
|
+
export class CertificateExpiredError extends AuthenticationError {}
|
|
374
|
+
export class CertificateRenewalError extends AuthenticationError {}
|
|
375
|
+
export class BootstrapKeyInvalidError extends AuthenticationError {}
|
|
376
|
+
export class BootstrapError extends SynapPermanentError {}
|
|
377
|
+
export class ContextNotFoundError extends SynapPermanentError {}
|
|
378
|
+
export class SessionExpiredError extends SynapPermanentError {}
|
|
379
|
+
export class ListeningAlreadyActiveError extends SynapPermanentError {}
|
|
380
|
+
export class ListeningNotActiveError extends SynapPermanentError {}
|
|
381
|
+
|
|
355
382
|
export function createClient(options?: SynapClientOptions): SynapClient;
|
|
356
383
|
export function resolveInstanceId(explicitInstanceId?: string): string;
|
|
357
384
|
export function setupPythonRuntime(
|