vidspotai-shared 1.0.27 → 1.0.29
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/services/aiGen/providers/google/google.service.js +1 -1
- package/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/kling/kling.service.js +2 -3
- package/lib/services/aiGen/providers/minimax/minimax.service.js +1 -1
- package/lib/services/aiGen/providers/openai/openai.service.d.ts +1 -1
- package/lib/services/aiGen/providers/openai/openai.service.d.ts.map +1 -1
- package/lib/services/aiGen/providers/openai/openai.service.js +3 -4
- package/lib/services/credit.service.d.ts.map +1 -1
- package/lib/services/credit.service.js +2 -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 +6 -0
- package/lib/utils/logger.d.ts.map +1 -0
- package/lib/utils/logger.js +85 -0
- package/package.json +5 -1
|
@@ -105,7 +105,7 @@ class GoogleService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
105
105
|
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
106
106
|
return modelConfig.cost?.perSecond
|
|
107
107
|
? (0, helpers_1.getCreditsFromCost)(modelConfig.cost?.perSecond * duration)
|
|
108
|
-
:
|
|
108
|
+
: 3; // should not happen
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
exports.GoogleService = GoogleService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kling.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/kling/kling.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAWlB,qBAAa,YAAa,SAAQ,wBAAwB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;YAWnB,OAAO;IA6Bf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IA8B3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA8DjD,cAAc,IAAI,MAAM;IAexB,aAAa,CAAC,EACZ,QAAQ,EACR,IAA8B,EAC9B,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"kling.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/kling/kling.service.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAWlB,qBAAa,YAAa,SAAQ,wBAAwB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;YAWnB,OAAO;IA6Bf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IA8B3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA8DjD,cAAc,IAAI,MAAM;IAexB,aAAa,CAAC,EACZ,QAAQ,EACR,IAA8B,EAC9B,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;CAK9B"}
|
|
@@ -116,9 +116,8 @@ class KlingService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
116
116
|
}
|
|
117
117
|
getCreditUsed({ modelKey, mode = types_2.EVideoMode.PROFESSIONAL, duration = 5, }) {
|
|
118
118
|
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
: 0;
|
|
119
|
+
const cost = modelConfig?.cost?.table?.[mode]?.[duration];
|
|
120
|
+
return (0, helpers_2.getCreditsFromCost)(cost ?? 1);
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
exports.KlingService = KlingService;
|
|
@@ -112,7 +112,7 @@ class MinimaxService extends baseAiGenProvider_service_1.BaseAiGenProviderServic
|
|
|
112
112
|
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
113
113
|
const cost = modelConfig.cost?.fixed ??
|
|
114
114
|
modelConfig.cost?.table?.[resolution]?.[duration];
|
|
115
|
-
return (0, helpers_2.getCreditsFromCost)(cost ?? 0);
|
|
115
|
+
return (0, helpers_2.getCreditsFromCost)(cost ?? 0.5); // default to 10 cents if unknown // log error as well
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
exports.MinimaxService = MinimaxService;
|
|
@@ -7,6 +7,6 @@ export declare class OpenaiService extends BaseAiGenProviderService {
|
|
|
7
7
|
generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
8
8
|
checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult>;
|
|
9
9
|
generateText(params: TextGenerationParams): Promise<TextGenerationResult>;
|
|
10
|
-
getCreditUsed({ modelKey, duration }: CreditUsageParams): number;
|
|
10
|
+
getCreditUsed({ modelKey, resolution, duration, }: CreditUsageParams): number;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=openai.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/openai/openai.service.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,MAAM,CAAS;;IAQjB,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAoB3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsC3C,YAAY,CAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IA2ChC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"openai.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/openai/openai.service.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,MAAM,CAAS;;IAQjB,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAoB3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAsC3C,YAAY,CAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IA2ChC,aAAa,CAAC,EACZ,QAAQ,EACR,UAAuB,EACvB,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;CAK9B"}
|
|
@@ -102,11 +102,10 @@ class OpenaiService extends baseAiGenProvider_service_1.BaseAiGenProviderService
|
|
|
102
102
|
text,
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
getCreditUsed({ modelKey, duration = 5 }) {
|
|
105
|
+
getCreditUsed({ modelKey, resolution = "720x1280", duration = 5, }) {
|
|
106
106
|
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: 0;
|
|
107
|
+
const cost = modelConfig?.cost?.table?.[resolution]?.[duration];
|
|
108
|
+
return (0, utils_1.getCreditsFromCost)(cost ?? 2);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
exports.OpenaiService = OpenaiService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../src/services/credit.service.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;WACX,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"credit.service.d.ts","sourceRoot":"","sources":["../../src/services/credit.service.ts"],"names":[],"mappings":"AAGA,qBAAa,aAAa;WACX,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,IAAI,CAAC;CAwBjB"}
|
|
@@ -14,6 +14,8 @@ class CreditService {
|
|
|
14
14
|
const credits = snap.data()?.credits;
|
|
15
15
|
const consumed = credits?.consumed ?? 0;
|
|
16
16
|
const total = credits?.total ?? 0;
|
|
17
|
+
// console.log(`Consuming ${creditsToConsume} credits for user ${userId}`);
|
|
18
|
+
// console.log(`Current credits: ${consumed}/${total}`);
|
|
17
19
|
// 🔒 HARD INVARIANT
|
|
18
20
|
if (consumed + creditsToConsume > total) {
|
|
19
21
|
throw new Error("INSUFFICIENT_CREDITS");
|
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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
package/lib/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AA0B1C;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAsExD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createLogger = createLogger;
|
|
7
|
+
const winston_1 = __importDefault(require("winston"));
|
|
8
|
+
const winston_slack_webhook_transport_1 = __importDefault(require("winston-slack-webhook-transport"));
|
|
9
|
+
const winston_loki_1 = __importDefault(require("winston-loki"));
|
|
10
|
+
const { combine, timestamp, errors, printf, colorize, json } = winston_1.default.format;
|
|
11
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
12
|
+
/**
|
|
13
|
+
* Console log format
|
|
14
|
+
*/
|
|
15
|
+
const consoleFormat = combine(colorize(), timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), printf((info) => {
|
|
16
|
+
const { timestamp, level, message, stack, ...meta } = info;
|
|
17
|
+
return `${timestamp} [${level}]: ${stack ?? message}${Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : ""}`;
|
|
18
|
+
}));
|
|
19
|
+
/**
|
|
20
|
+
* Logger factory
|
|
21
|
+
*/
|
|
22
|
+
function createLogger(serviceName) {
|
|
23
|
+
/**
|
|
24
|
+
* Grafana Loki transport (ALL LOGS)
|
|
25
|
+
*/
|
|
26
|
+
const lokiTransport = process.env.GRAFANA_LOKI_URL && process.env.GRAFANA_LOKI_AUTH
|
|
27
|
+
? new winston_loki_1.default({
|
|
28
|
+
host: process.env.GRAFANA_LOKI_URL,
|
|
29
|
+
basicAuth: process.env.GRAFANA_LOKI_AUTH,
|
|
30
|
+
labels: {
|
|
31
|
+
service: serviceName,
|
|
32
|
+
environment: process.env.NODE_ENV ?? "unknown",
|
|
33
|
+
},
|
|
34
|
+
json: true,
|
|
35
|
+
replaceTimestamp: true,
|
|
36
|
+
onConnectionError: (err) => {
|
|
37
|
+
console.error("Loki connection error", err);
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
: null;
|
|
41
|
+
/**
|
|
42
|
+
* Slack transport (ERROR ONLY)
|
|
43
|
+
*/
|
|
44
|
+
const slackTransport = isProduction && process.env.SLACK_WEBHOOK_URL
|
|
45
|
+
? new winston_slack_webhook_transport_1.default({
|
|
46
|
+
webhookUrl: process.env.SLACK_WEBHOOK_URL,
|
|
47
|
+
level: "error",
|
|
48
|
+
formatter: (info) => {
|
|
49
|
+
const log = info;
|
|
50
|
+
const blocks = [
|
|
51
|
+
{
|
|
52
|
+
type: "section",
|
|
53
|
+
text: {
|
|
54
|
+
type: "mrkdwn",
|
|
55
|
+
text: `🚨 *${serviceName}*\n\`\`\`${log.message}\`\`\``,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
if (log.stack) {
|
|
60
|
+
blocks.push({
|
|
61
|
+
type: "section",
|
|
62
|
+
text: {
|
|
63
|
+
type: "mrkdwn",
|
|
64
|
+
text: `*Stack Trace:*\n\`\`\`${log.stack}\`\`\``,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
text: `🚨 ${serviceName} error`,
|
|
70
|
+
blocks,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
: null;
|
|
75
|
+
return winston_1.default.createLogger({
|
|
76
|
+
level: "info",
|
|
77
|
+
format: json(),
|
|
78
|
+
transports: [
|
|
79
|
+
new winston_1.default.transports.Console({ format: consoleFormat }),
|
|
80
|
+
...(lokiTransport ? [lokiTransport] : []),
|
|
81
|
+
...(slackTransport ? [slackTransport] : []),
|
|
82
|
+
],
|
|
83
|
+
exitOnError: false,
|
|
84
|
+
});
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vidspotai-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -24,7 +24,11 @@
|
|
|
24
24
|
"googleapis": "^170.0.0",
|
|
25
25
|
"ioredis": "^5.8.0",
|
|
26
26
|
"jsonwebtoken": "^9.0.2",
|
|
27
|
+
"logform": "^2.7.0",
|
|
27
28
|
"openai": "^6.1.0",
|
|
29
|
+
"winston": "^3.19.0",
|
|
30
|
+
"winston-loki": "^6.1.3",
|
|
31
|
+
"winston-slack-webhook-transport": "^2.3.6",
|
|
28
32
|
"zod": "^4.1.11"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|