🧮 feat: Improve structured token spending and testing; fix: Anthropic Cache Spend (#3766)

* chore: update jest and mongodb-memory-server dependencies

* fix: Anthropic edge case of increasing balance

* refactor: Update token calculations in Transaction model/spec

* refactor: `spendTokens` always record transactions, add Tx related tests

* feat: Add error handling for CHECK_BALANCE environment variable

* feat: Update import path for Balance model in Balance controller

* chore: remove logging

* refactor: Improve structured token spend logging in spendTokens.js

* ci: add unit tests for spend token

* ci: Improve structured token spend unit testing

* chore: improve logging phrase for no tx spent from balance
This commit is contained in:
Danny Avila 2024-08-24 04:36:08 -04:00 committed by GitHub
parent ea5140ff0f
commit d54458b3a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 850 additions and 82 deletions

View file

@ -1,6 +1,7 @@
const path = require('path');
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') });
const { askQuestion, silentExit } = require('./helpers');
const { isEnabled } = require('~/server/utils/handleText');
const { Transaction } = require('~/models/Transaction');
const User = require('~/models/User');
const connect = require('./connect');
@ -36,6 +37,12 @@ const connect = require('./connect');
);
silentExit(1);
}
if (isEnabled(process.env.CHECK_BALANCE) === false) {
console.red(
'Error: CHECK_BALANCE environment variable is set to `false`! Please configure: `CHECK_BALANCE=true`',
);
silentExit(1);
}
/**
* If we don't have the right number of arguments, lets prompt the user for them