mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-28 13:17:14 +00:00
fix(monitoring): restore SQLite token statistics (#2479)
* fix(monitoring): restore SQLite token statistics Allow the monitored SQLite strftime bucket expression through the tenant SQL guard and preserve structured backend errors in the token dashboard. Add persistence and frontend regressions.\n\nVerified-by: independent-review * test(runtime): accept reconcile timeout in capacity stub Keep the PostgreSQL capacity probe aligned with the runtime handler contract and assert the bounded reconcile timeout. --------- Co-authored-by: dadachann <185672915+dadachann@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
TrendingUp,
|
||||
} from 'lucide-react';
|
||||
import { httpClient } from '@/app/infra/http/HttpClient';
|
||||
import { getErrorMessage } from '../utils';
|
||||
|
||||
interface TokenSummary {
|
||||
total_calls: number;
|
||||
@@ -152,7 +153,7 @@ export default function TokenMonitoring({
|
||||
});
|
||||
setStats(result);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : String(e));
|
||||
setError(getErrorMessage(e));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
if (error instanceof Error) return error.message;
|
||||
if (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
'msg' in error &&
|
||||
typeof error.msg === 'string'
|
||||
) {
|
||||
return error.msg;
|
||||
}
|
||||
return String(error);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import test from 'node:test';
|
||||
import ts from 'typescript';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const utilsPath = path.resolve(
|
||||
currentDirectory,
|
||||
'../../src/app/home/monitoring/utils.ts',
|
||||
);
|
||||
const componentPath = path.resolve(
|
||||
currentDirectory,
|
||||
'../../src/app/home/monitoring/components/TokenMonitoring.tsx',
|
||||
);
|
||||
|
||||
function loadMonitoringUtils() {
|
||||
const source = fs.readFileSync(utilsPath, 'utf8');
|
||||
const compiled = ts.transpileModule(source, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS },
|
||||
}).outputText;
|
||||
const loadedModule = { exports: {} };
|
||||
new Function('require', 'module', 'exports', compiled)(
|
||||
() => {
|
||||
throw new Error('Monitoring utils must not have runtime imports');
|
||||
},
|
||||
loadedModule,
|
||||
loadedModule.exports,
|
||||
);
|
||||
return loadedModule.exports;
|
||||
}
|
||||
|
||||
const { getErrorMessage } = loadMonitoringUtils();
|
||||
|
||||
test('token monitoring extracts messages from structured API errors', () => {
|
||||
assert.equal(
|
||||
getErrorMessage({
|
||||
code: 500,
|
||||
msg: 'SQLite aggregation failed',
|
||||
data: null,
|
||||
}),
|
||||
'SQLite aggregation failed',
|
||||
);
|
||||
assert.equal(getErrorMessage(new Error('Network failed')), 'Network failed');
|
||||
assert.equal(getErrorMessage('Request failed'), 'Request failed');
|
||||
});
|
||||
|
||||
test('token monitoring uses the structured API error helper', () => {
|
||||
const source = fs.readFileSync(componentPath, 'utf8');
|
||||
assert.match(source, /import \{ getErrorMessage \} from '\.\.\/utils';/);
|
||||
assert.match(source, /setError\(getErrorMessage\(e\)\)/);
|
||||
});
|
||||
Reference in New Issue
Block a user