@ty_krystal/sei-ai 0.1.4 → 0.1.5

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/dist/errors.js ADDED
@@ -0,0 +1,55 @@
1
+ export class SeiMcpError extends Error {
2
+ code;
3
+ details;
4
+ constructor(message, code = 'INTERNAL_ERROR', details) {
5
+ super(message);
6
+ this.name = 'SeiMcpError';
7
+ this.code = code;
8
+ this.details = details;
9
+ }
10
+ }
11
+ export function isSeiMcpError(error) {
12
+ return error instanceof SeiMcpError;
13
+ }
14
+ export function normalizeErrorMessage(error) {
15
+ return error instanceof Error ? error.message : 'Unknown error';
16
+ }
17
+ export function formatCliError(error) {
18
+ if (error instanceof SeiMcpError) {
19
+ return `[${error.code}] ${error.message}`;
20
+ }
21
+ return `[INTERNAL_ERROR] ${normalizeErrorMessage(error)}`;
22
+ }
23
+ export function toErrorLogMeta(error) {
24
+ if (error instanceof SeiMcpError) {
25
+ return {
26
+ code: error.code,
27
+ message: error.message,
28
+ details: toJsonValue(error.details),
29
+ };
30
+ }
31
+ if (error instanceof Error) {
32
+ return {
33
+ message: error.message,
34
+ stack: error.stack ?? '',
35
+ };
36
+ }
37
+ return {
38
+ message: normalizeErrorMessage(error),
39
+ };
40
+ }
41
+ function toJsonValue(value) {
42
+ if (value === null) {
43
+ return null;
44
+ }
45
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
46
+ return value;
47
+ }
48
+ if (Array.isArray(value)) {
49
+ return value.map((item) => toJsonValue(item));
50
+ }
51
+ if (value && typeof value === 'object') {
52
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toJsonValue(item)]));
53
+ }
54
+ return String(value);
55
+ }