@kapishdima/ai-ledger 0.0.4 → 0.0.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/plugin.js +18 -8
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -3739,6 +3739,8 @@ async function deductBalance(provider, cost) {
|
|
|
3739
3739
|
}
|
|
3740
3740
|
|
|
3741
3741
|
// plugin.ts
|
|
3742
|
+
var pending = new Map;
|
|
3743
|
+
var DEBOUNCE_MS = 1500;
|
|
3742
3744
|
var plugin_default = async (input) => {
|
|
3743
3745
|
await initializeDatabase();
|
|
3744
3746
|
return {
|
|
@@ -3769,14 +3771,22 @@ var plugin_default = async (input) => {
|
|
|
3769
3771
|
created_at: new Date().toISOString(),
|
|
3770
3772
|
synced: 0
|
|
3771
3773
|
});
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3774
|
+
const existing = pending.get(msg.providerID);
|
|
3775
|
+
if (existing)
|
|
3776
|
+
clearTimeout(existing.timer);
|
|
3777
|
+
const totalCost = (existing?.totalCost ?? 0) + msg.cost;
|
|
3778
|
+
const timer = setTimeout(() => {
|
|
3779
|
+
pending.delete(msg.providerID);
|
|
3780
|
+
input.client.tui.showToast({
|
|
3781
|
+
body: {
|
|
3782
|
+
title: `ai-ledger \xB7 ${msg.providerID}`,
|
|
3783
|
+
message: `-$${totalCost.toFixed(4)} | balance: $${newBalance.toFixed(2)}`,
|
|
3784
|
+
variant: newBalance < 0 ? "warning" : "info",
|
|
3785
|
+
duration: 4000
|
|
3786
|
+
}
|
|
3787
|
+
});
|
|
3788
|
+
}, DEBOUNCE_MS);
|
|
3789
|
+
pending.set(msg.providerID, { totalCost, lastBalance: newBalance, timer });
|
|
3780
3790
|
}
|
|
3781
3791
|
};
|
|
3782
3792
|
};
|