vidspotai-shared 1.0.34 → 1.0.35
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/lib/globals/aiModels/providers/bytedance.d.ts.map +1 -1
- package/lib/globals/aiModels/providers/bytedance.js +3 -0
- package/lib/globals/aiModels/providers/google.js +14 -14
- package/lib/globals/aiModels/types.d.ts +2 -0
- package/lib/globals/aiModels/types.d.ts.map +1 -1
- package/lib/models/editorState.model.d.ts +9 -0
- package/lib/models/editorState.model.d.ts.map +1 -0
- package/lib/models/editorState.model.js +2 -0
- package/lib/services/aiGen/providers/bytedance/bytedance.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/bytedance/bytedance.service.js +12 -5
- package/lib/utils/errors.d.ts +9 -0
- package/lib/utils/errors.d.ts.map +1 -0
- package/lib/utils/errors.js +15 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/logger.d.ts.map +1 -1
- package/lib/utils/logger.js +72 -21
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytedance.d.ts","sourceRoot":"","sources":["../../../../src/globals/aiModels/providers/bytedance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"bytedance.d.ts","sourceRoot":"","sources":["../../../../src/globals/aiModels/providers/bytedance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,eAAO,MAAM,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,CAkEvE,CAAC"}
|
|
@@ -5,6 +5,7 @@ exports.bytedanceConfigs = {
|
|
|
5
5
|
"bytedance-seedance-1.5-pro": {
|
|
6
6
|
modelId: "seedance-1-5-pro-251215",
|
|
7
7
|
type: ["text-to-video", "image-to-video"],
|
|
8
|
+
acceptedImageFormats: ["image/jpeg", "image/jpg", "image/png"],
|
|
8
9
|
fields: {
|
|
9
10
|
prompt: { required: true }, // not required for image-to-video, but we can ignore that for simplicity
|
|
10
11
|
aspectRatio: {
|
|
@@ -31,6 +32,7 @@ exports.bytedanceConfigs = {
|
|
|
31
32
|
"bytedance-seedance-1.0-pro-fast": {
|
|
32
33
|
modelId: "seedance-1-0-pro-fast-251015",
|
|
33
34
|
type: ["text-to-video", "image-to-video"],
|
|
35
|
+
acceptedImageFormats: ["image/jpeg", "image/jpg", "image/png"],
|
|
34
36
|
fields: {
|
|
35
37
|
prompt: { required: true },
|
|
36
38
|
aspectRatio: {
|
|
@@ -48,6 +50,7 @@ exports.bytedanceConfigs = {
|
|
|
48
50
|
"bytedance-seedance-1.0-pro": {
|
|
49
51
|
modelId: "seedance-1-0-pro-250528",
|
|
50
52
|
type: ["text-to-video", "image-to-video"],
|
|
53
|
+
acceptedImageFormats: ["image/jpeg", "image/jpg", "image/png"],
|
|
51
54
|
fields: {
|
|
52
55
|
prompt: { required: true },
|
|
53
56
|
aspectRatio: {
|
|
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.googleConfigs = void 0;
|
|
4
4
|
exports.googleConfigs = {
|
|
5
5
|
"google-veo-3.1": {
|
|
6
|
-
modelId: "veo-3.1-generate",
|
|
6
|
+
modelId: "veo-3.1-generate-001",
|
|
7
7
|
type: ["text-to-video", "image-to-video"],
|
|
8
8
|
fields: {
|
|
9
9
|
prompt: { required: true },
|
|
10
|
-
aspectRatio: { allowedValues: ["16:9", "9:16"] },
|
|
11
|
-
resolution: { allowedValues: ["720p", "1080p"] },
|
|
12
|
-
duration: { allowedValues: [4, 6, 8] },
|
|
10
|
+
aspectRatio: { allowedValues: ["16:9", "9:16"] },
|
|
11
|
+
resolution: { allowedValues: ["720p", "1080p"] },
|
|
12
|
+
duration: { allowedValues: [4, 6, 8] },
|
|
13
13
|
imageUrl: {},
|
|
14
14
|
negative_prompt: {},
|
|
15
15
|
audio: {},
|
|
16
16
|
},
|
|
17
17
|
durationRules: {
|
|
18
|
-
4: ["720p"
|
|
19
|
-
6: ["720p"
|
|
20
|
-
8: ["1080p"],
|
|
18
|
+
4: ["720p"],
|
|
19
|
+
6: ["720p"],
|
|
20
|
+
8: ["720p", "1080p"],
|
|
21
21
|
},
|
|
22
22
|
requestPerMin: 10,
|
|
23
23
|
cost: {
|
|
@@ -25,21 +25,21 @@ exports.googleConfigs = {
|
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
"google-veo-3.1-fast": {
|
|
28
|
-
modelId: "veo-3.1-fast-generate",
|
|
28
|
+
modelId: "veo-3.1-fast-generate-001",
|
|
29
29
|
type: ["text-to-video", "image-to-video"],
|
|
30
30
|
fields: {
|
|
31
31
|
prompt: { required: true },
|
|
32
|
-
aspectRatio: { allowedValues: ["16:9", "9:16"] },
|
|
33
|
-
resolution: { allowedValues: ["720p", "1080p"] },
|
|
34
|
-
duration: { allowedValues: [4, 6, 8] },
|
|
32
|
+
aspectRatio: { allowedValues: ["16:9", "9:16"] },
|
|
33
|
+
resolution: { allowedValues: ["720p", "1080p"] },
|
|
34
|
+
duration: { allowedValues: [4, 6, 8] },
|
|
35
35
|
imageUrl: {},
|
|
36
36
|
negative_prompt: {},
|
|
37
37
|
audio: {},
|
|
38
38
|
},
|
|
39
39
|
durationRules: {
|
|
40
|
-
4: ["720p"
|
|
41
|
-
6: ["720p"
|
|
42
|
-
8: ["1080p"],
|
|
40
|
+
4: ["720p"],
|
|
41
|
+
6: ["720p"],
|
|
42
|
+
8: ["720p", "1080p"],
|
|
43
43
|
},
|
|
44
44
|
requestPerMin: 10,
|
|
45
45
|
cost: {
|
|
@@ -41,5 +41,7 @@ export interface IModelSchema {
|
|
|
41
41
|
};
|
|
42
42
|
/** Required when type includes "avatar-video". Contains all avatar-specific constraints. */
|
|
43
43
|
avatar?: IAvatarModelConfig;
|
|
44
|
+
/** MIME types accepted for image input (e.g. ["image/jpeg", "image/png"]). If absent, all formats are allowed. */
|
|
45
|
+
acceptedImageFormats?: string[];
|
|
44
46
|
}
|
|
45
47
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/globals/aiModels/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,cAAc,GACtB,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,cAAc,GACd,eAAe,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,wFAAwF;IACxF,gBAAgB,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAErC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE;QACL,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,4FAA4F;IAC5F,MAAM,CAAC,EAAE,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/globals/aiModels/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,cAAc,GACtB,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,cAAc,GACd,eAAe,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,wFAAwF;IACxF,gBAAgB,EAAE,MAAM,CAAC;IACzB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAErC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE;QACL,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,4FAA4F;IAC5F,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,kHAAkH;IAClH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FieldValue } from "firebase-admin/firestore";
|
|
2
|
+
export interface IEditorStateModel {
|
|
3
|
+
videoJobId: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
design: Record<string, any>;
|
|
6
|
+
createdAt: FieldValue;
|
|
7
|
+
updatedAt: FieldValue;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=editorState.model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorState.model.d.ts","sourceRoot":"","sources":["../../src/models/editorState.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,SAAS,EAAE,UAAU,CAAC;IACtB,SAAS,EAAE,UAAU,CAAC;CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytedance.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/bytedance/bytedance.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"bytedance.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/bytedance/bytedance.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAUlB,qBAAa,gBAAiB,SAAQ,wBAAwB;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CACsD;IAExE,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAsG3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA8FjD,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;CAoCjD"}
|
|
@@ -11,6 +11,7 @@ const aiModels_1 = require("../../../../globals/aiModels");
|
|
|
11
11
|
const types_1 = require("../../../../globals/types");
|
|
12
12
|
const firebase_1 = require("../../../../libs/firebase");
|
|
13
13
|
const helpers_2 = require("../../../../utils/helpers");
|
|
14
|
+
const errors_1 = require("../../../../utils/errors");
|
|
14
15
|
const logger_1 = require("../../../../utils/logger");
|
|
15
16
|
const crypto_1 = __importDefault(require("crypto"));
|
|
16
17
|
class ByteDanceService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
|
|
@@ -65,16 +66,22 @@ class ByteDanceService extends baseAiGenProvider_service_1.BaseAiGenProviderServ
|
|
|
65
66
|
const param = parsed?.error?.param;
|
|
66
67
|
const message = parsed?.error?.message ?? "";
|
|
67
68
|
if (code === "InputTextSensitiveContentDetected") {
|
|
68
|
-
throw new
|
|
69
|
+
throw new errors_1.UserFacingError("Your prompt contains content that violates the content policy. Please modify your prompt and try again.");
|
|
69
70
|
}
|
|
70
|
-
if (code === "
|
|
71
|
+
if (code === "InputImageSensitiveContentDetected") {
|
|
72
|
+
throw new errors_1.UserFacingError("Your input image contains sensitive content and cannot be processed. Please use a different image.");
|
|
73
|
+
}
|
|
74
|
+
if (code === "InvalidParameter.UnsupportedImageFormat" || (code?.includes("UnsupportedImageFormat"))) {
|
|
75
|
+
throw new errors_1.UserFacingError("Your input image format is not supported. Please use JPEG or PNG.");
|
|
76
|
+
}
|
|
77
|
+
if (code === "InvalidParameter" && param?.includes("image_url")) {
|
|
71
78
|
if (message.includes("aspect ratio")) {
|
|
72
|
-
throw new
|
|
79
|
+
throw new errors_1.UserFacingError("Your input image's aspect ratio is not supported by this model. Please use an image with an aspect ratio between 0.40 and 2.50 (e.g. 1:1, 9:16, 16:9).");
|
|
73
80
|
}
|
|
74
81
|
if (message.includes("width") || message.includes("height") || message.includes("px")) {
|
|
75
|
-
throw new
|
|
82
|
+
throw new errors_1.UserFacingError("Your input image is too small. Please use an image with a minimum width of 300px.");
|
|
76
83
|
}
|
|
77
|
-
throw new
|
|
84
|
+
throw new errors_1.UserFacingError(`Your input image is not valid: ${message}`);
|
|
78
85
|
}
|
|
79
86
|
throw new Error(`ByteDance generateVideo failed (${resp.status}): ${errText}`);
|
|
80
87
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when an error is caused by invalid user input rather than a system failure.
|
|
3
|
+
* These are logged as `warn` (Loki only) instead of `error` (Slack) to reduce noise.
|
|
4
|
+
*/
|
|
5
|
+
export declare class UserFacingError extends Error {
|
|
6
|
+
readonly isUserFacingError = true;
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,iBAAiB,QAAQ;gBAEtB,OAAO,EAAE,MAAM;CAI5B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserFacingError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when an error is caused by invalid user input rather than a system failure.
|
|
6
|
+
* These are logged as `warn` (Loki only) instead of `error` (Slack) to reduce noise.
|
|
7
|
+
*/
|
|
8
|
+
class UserFacingError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.isUserFacingError = true;
|
|
12
|
+
this.name = "UserFacingError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.UserFacingError = UserFacingError;
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
package/lib/utils/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./errors"), exports);
|
|
17
18
|
__exportStar(require("./helpers"), exports);
|
|
18
19
|
__exportStar(require("./logger"), exports);
|
|
19
20
|
__exportStar(require("./ttsUtils"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AA0B1C;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AA0B1C;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAuHxD;AAED,eAAO,MAAM,MAAM,gBAAyB,CAAC"}
|
package/lib/utils/logger.js
CHANGED
|
@@ -47,29 +47,80 @@ function createLogger(serviceName) {
|
|
|
47
47
|
webhookUrl: process.env.SLACK_WEBHOOK_URL,
|
|
48
48
|
level: "error",
|
|
49
49
|
formatter: (info) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
try {
|
|
51
|
+
const { level, message, stack, timestamp, splat, ...meta } = info;
|
|
52
|
+
// Serialize metadata — convert Error objects to plain objects, handle circular refs
|
|
53
|
+
const serializeMeta = (val, depth = 0) => {
|
|
54
|
+
if (depth > 5)
|
|
55
|
+
return "[MaxDepth]";
|
|
56
|
+
if (val instanceof Error)
|
|
57
|
+
return { message: val.message, stack: val.stack };
|
|
58
|
+
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
59
|
+
const out = {};
|
|
60
|
+
for (const [k, v] of Object.entries(val)) {
|
|
61
|
+
try {
|
|
62
|
+
out[k] = serializeMeta(v, depth + 1);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
out[k] = "[Unserializable]";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
return val;
|
|
71
|
+
};
|
|
72
|
+
const serialized = serializeMeta(meta);
|
|
73
|
+
// Safely stringify with fallback for circular references
|
|
74
|
+
let metaStr = null;
|
|
75
|
+
try {
|
|
76
|
+
const raw = JSON.stringify(serialized, null, 2);
|
|
77
|
+
metaStr = raw && Object.keys(serialized).length ? raw : null;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
metaStr = Object.keys(serialized).length ? JSON.stringify(Object.keys(serialized)) : null;
|
|
81
|
+
}
|
|
82
|
+
// Extract stack from meta.error when info.stack is not available
|
|
83
|
+
const resolvedStack = stack ||
|
|
84
|
+
(meta?.error instanceof Error ? meta.error.stack : null) ||
|
|
85
|
+
(meta?.error?.stack ? meta.error.stack : null);
|
|
86
|
+
const blocks = [
|
|
87
|
+
{
|
|
88
|
+
type: "section",
|
|
89
|
+
text: {
|
|
90
|
+
type: "mrkdwn",
|
|
91
|
+
text: `🚨 *${serviceName}*\n\`\`\`${message}\`\`\``,
|
|
92
|
+
},
|
|
57
93
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
}
|
|
94
|
+
];
|
|
95
|
+
if (metaStr) {
|
|
96
|
+
blocks.push({
|
|
97
|
+
type: "section",
|
|
98
|
+
text: {
|
|
99
|
+
type: "mrkdwn",
|
|
100
|
+
text: `*Context:*\n\`\`\`${metaStr.slice(0, 2800)}\`\`\``,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (resolvedStack) {
|
|
105
|
+
blocks.push({
|
|
106
|
+
type: "section",
|
|
107
|
+
text: {
|
|
108
|
+
type: "mrkdwn",
|
|
109
|
+
text: `*Stack Trace:*\n\`\`\`${String(resolvedStack).slice(0, 2800)}\`\`\``,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
text: `🚨 [${serviceName}] ${message}`,
|
|
115
|
+
blocks,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (formatterErr) {
|
|
119
|
+
// Last-resort fallback — never let a formatter crash silence an error
|
|
120
|
+
return {
|
|
121
|
+
text: `🚨 [${serviceName}] ${info.message ?? "error"} (formatter failed: ${formatterErr})`,
|
|
122
|
+
};
|
|
68
123
|
}
|
|
69
|
-
return {
|
|
70
|
-
text: `🚨 ${serviceName} error`,
|
|
71
|
-
blocks,
|
|
72
|
-
};
|
|
73
124
|
},
|
|
74
125
|
})
|
|
75
126
|
: null;
|