vzcode 1.34.0 → 1.35.0
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/package.json
CHANGED
|
@@ -12,7 +12,8 @@ import { handleError } from './errorHandling.js';
|
|
|
12
12
|
const debug = false;
|
|
13
13
|
|
|
14
14
|
export const handleAIChatMessage =
|
|
15
|
-
(shareDBDoc
|
|
15
|
+
(shareDBDoc, options = {}) =>
|
|
16
|
+
async (req, res) => {
|
|
16
17
|
const { content, chatId } = req.body;
|
|
17
18
|
|
|
18
19
|
if (debug) {
|
|
@@ -62,6 +63,27 @@ export const handleAIChatMessage =
|
|
|
62
63
|
editResult.content,
|
|
63
64
|
);
|
|
64
65
|
|
|
66
|
+
// Handle credit deduction if callback is provided
|
|
67
|
+
if (
|
|
68
|
+
options.onCreditDeduction &&
|
|
69
|
+
editResult.upstreamCostCents
|
|
70
|
+
) {
|
|
71
|
+
try {
|
|
72
|
+
await options.onCreditDeduction({
|
|
73
|
+
upstreamCostCents: editResult.upstreamCostCents,
|
|
74
|
+
provider: editResult.provider,
|
|
75
|
+
inputTokens: editResult.inputTokens,
|
|
76
|
+
outputTokens: editResult.outputTokens,
|
|
77
|
+
});
|
|
78
|
+
} catch (creditError) {
|
|
79
|
+
console.error(
|
|
80
|
+
'Credit deduction error:',
|
|
81
|
+
creditError,
|
|
82
|
+
);
|
|
83
|
+
// Don't fail the request if credit deduction fails
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
65
87
|
res.status(200).json(aiResponse);
|
|
66
88
|
} catch (error) {
|
|
67
89
|
handleError(shareDBDoc, chatId, error, res);
|