stagent 0.9.1 → 0.9.2
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
|
@@ -116,7 +116,7 @@ export function AnalyticsDashboard({
|
|
|
116
116
|
<CartesianGrid strokeDasharray="3 3" className="stroke-border" />
|
|
117
117
|
<XAxis dataKey="date" tick={{ fontSize: 10 }} tickFormatter={(v) => v.slice(5)} />
|
|
118
118
|
<YAxis tick={{ fontSize: 10 }} tickFormatter={(v) => `$${(v / 1_000_000).toFixed(2)}`} />
|
|
119
|
-
<Tooltip formatter={(v
|
|
119
|
+
<Tooltip formatter={(v) => [`$${(Number(v) / 1_000_000).toFixed(4)}`, "Avg Cost"]} />
|
|
120
120
|
<Line type="monotone" dataKey="avgCostMicros" stroke="oklch(0.6 0.2 250)" strokeWidth={2} dot={false} />
|
|
121
121
|
</LineChart>
|
|
122
122
|
</ResponsiveContainer>
|
package/src/instrumentation.ts
CHANGED
|
@@ -1,10 +1,51 @@
|
|
|
1
1
|
export async function register() {
|
|
2
|
+
// Only start background services on the server (not during build or edge)
|
|
2
3
|
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
try {
|
|
5
|
+
// License manager — initialize from DB (creates default row if needed)
|
|
6
|
+
const { licenseManager } = await import("@/lib/license/manager");
|
|
7
|
+
licenseManager.initialize();
|
|
8
|
+
licenseManager.startValidationTimer();
|
|
9
|
+
|
|
10
|
+
const { startScheduler } = await import("@/lib/schedules/scheduler");
|
|
11
|
+
startScheduler();
|
|
12
|
+
|
|
13
|
+
const { startChannelPoller } = await import("@/lib/channels/poller");
|
|
14
|
+
startChannelPoller();
|
|
15
|
+
|
|
16
|
+
const { startAutoBackup } = await import("@/lib/snapshots/auto-backup");
|
|
17
|
+
startAutoBackup();
|
|
18
|
+
|
|
19
|
+
// History retention cleanup — prunes old agent_logs and usage_ledger
|
|
20
|
+
// based on tier retention limit (Community: 30 days)
|
|
21
|
+
startHistoryCleanup(licenseManager);
|
|
22
|
+
|
|
23
|
+
// Telemetry batch flush (opt-in, every 5 minutes)
|
|
24
|
+
const { startTelemetryFlush } = await import("@/lib/telemetry/queue");
|
|
25
|
+
startTelemetryFlush();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error("Instrumentation startup failed:", err);
|
|
28
|
+
}
|
|
9
29
|
}
|
|
10
30
|
}
|
|
31
|
+
|
|
32
|
+
async function startHistoryCleanup(licenseManager: { getLimit: (r: "historyRetentionDays") => number }) {
|
|
33
|
+
const CLEANUP_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
|
34
|
+
|
|
35
|
+
async function cleanup() {
|
|
36
|
+
const retentionDays = licenseManager.getLimit("historyRetentionDays");
|
|
37
|
+
if (!Number.isFinite(retentionDays)) return; // Unlimited retention
|
|
38
|
+
|
|
39
|
+
const { db } = await import("@/lib/db");
|
|
40
|
+
const { agentLogs, usageLedger } = await import("@/lib/db/schema");
|
|
41
|
+
const { lt } = await import("drizzle-orm");
|
|
42
|
+
|
|
43
|
+
const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
|
|
44
|
+
db.delete(agentLogs).where(lt(agentLogs.timestamp, cutoff)).run();
|
|
45
|
+
db.delete(usageLedger).where(lt(usageLedger.startedAt, cutoff)).run();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Run once at startup, then daily
|
|
49
|
+
cleanup().catch(() => {});
|
|
50
|
+
setInterval(() => cleanup().catch(() => {}), CLEANUP_INTERVAL);
|
|
51
|
+
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js-only instrumentation startup.
|
|
3
|
-
* Imported dynamically from instrumentation.ts with a bundler-ignore comment
|
|
4
|
-
* so the Edge runtime never analyzes this module's dependency tree.
|
|
5
|
-
*/
|
|
6
|
-
export async function registerNode() {
|
|
7
|
-
// License manager — initialize from DB (creates default row if needed)
|
|
8
|
-
const { licenseManager } = await import("@/lib/license/manager");
|
|
9
|
-
licenseManager.initialize();
|
|
10
|
-
licenseManager.startValidationTimer();
|
|
11
|
-
|
|
12
|
-
const { startScheduler } = await import("@/lib/schedules/scheduler");
|
|
13
|
-
startScheduler();
|
|
14
|
-
|
|
15
|
-
const { startChannelPoller } = await import("@/lib/channels/poller");
|
|
16
|
-
startChannelPoller();
|
|
17
|
-
|
|
18
|
-
const { startAutoBackup } = await import("@/lib/snapshots/auto-backup");
|
|
19
|
-
startAutoBackup();
|
|
20
|
-
|
|
21
|
-
// History retention cleanup — prunes old agent_logs and usage_ledger
|
|
22
|
-
// based on tier retention limit (Community: 30 days)
|
|
23
|
-
const CLEANUP_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
|
24
|
-
|
|
25
|
-
async function cleanup() {
|
|
26
|
-
const retentionDays = licenseManager.getLimit("historyRetentionDays");
|
|
27
|
-
if (!Number.isFinite(retentionDays)) return; // Unlimited retention
|
|
28
|
-
|
|
29
|
-
const { db } = await import("@/lib/db");
|
|
30
|
-
const { agentLogs, usageLedger } = await import("@/lib/db/schema");
|
|
31
|
-
const { lt } = await import("drizzle-orm");
|
|
32
|
-
|
|
33
|
-
const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
|
|
34
|
-
db.delete(agentLogs).where(lt(agentLogs.timestamp, cutoff)).run();
|
|
35
|
-
db.delete(usageLedger).where(lt(usageLedger.startedAt, cutoff)).run();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
cleanup().catch(() => {});
|
|
39
|
-
setInterval(() => cleanup().catch(() => {}), CLEANUP_INTERVAL);
|
|
40
|
-
|
|
41
|
-
// Telemetry batch flush (opt-in, every 5 minutes)
|
|
42
|
-
const { startTelemetryFlush } = await import("@/lib/telemetry/queue");
|
|
43
|
-
startTelemetryFlush();
|
|
44
|
-
}
|