stagent 0.9.1 → 0.9.3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stagent",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "AI Business Operating System — run your business with AI agents. Local-first, multi-provider, governed.",
5
5
  "keywords": [
6
6
  "ai",
@@ -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: number) => [`$${(v / 1_000_000).toFixed(4)}`, "Avg Cost"]} />
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>
@@ -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
- // Single dynamic import with bundler-ignore so Turbopack's Edge analyzer
4
- // never follows this module's Node.js dependency tree.
5
- const { registerNode } = await import(
6
- /* webpackIgnore: true */ "./instrumentation.node"
7
- );
8
- await registerNode();
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
+ }
@@ -35,8 +35,8 @@ export const STRIPE_PRODUCTS: StripeProduct[] = [
35
35
  annual: { id: "price_1TJ2d5RCxnzBPkIXjjiyc7lb", amount: 19000, currency: "usd" },
36
36
  },
37
37
  paymentLinks: {
38
- monthly: "https://buy.stripe.com/fZufZjgKC4q9azrgDzdwc06",
39
- annual: "https://buy.stripe.com/bJe00l1PI7Cl7nf1IFdwc0b",
38
+ monthly: "https://buy.stagent.io/fZufZjgKC4q9azrgDzdwc06",
39
+ annual: "https://buy.stagent.io/bJe00l1PI7Cl7nf1IFdwc0b",
40
40
  },
41
41
  },
42
42
  {
@@ -48,8 +48,8 @@ export const STRIPE_PRODUCTS: StripeProduct[] = [
48
48
  annual: { id: "price_1TJ2e1RCxnzBPkIXODs5fZW2", amount: 49000, currency: "usd" },
49
49
  },
50
50
  paymentLinks: {
51
- monthly: "https://buy.stripe.com/aFa4gB0LE9Kt22Vevrdwc07",
52
- annual: "https://buy.stripe.com/bJe6oJdyq2i1bDv1IFdwc0a",
51
+ monthly: "https://buy.stagent.io/aFa4gB0LE9Kt22Vevrdwc07",
52
+ annual: "https://buy.stagent.io/bJe6oJdyq2i1bDv1IFdwc0a",
53
53
  },
54
54
  },
55
55
  {
@@ -61,8 +61,8 @@ export const STRIPE_PRODUCTS: StripeProduct[] = [
61
61
  annual: { id: "price_1TJ2evRCxnzBPkIXqIRaDxQp", amount: 99000, currency: "usd" },
62
62
  },
63
63
  paymentLinks: {
64
- monthly: "https://buy.stripe.com/9B628t2TM5udazr72Zdwc08",
65
- annual: "https://buy.stripe.com/dRmfZjbqicWF5f7873dwc09",
64
+ monthly: "https://buy.stagent.io/9B628t2TM5udazr72Zdwc08",
65
+ annual: "https://buy.stagent.io/dRmfZjbqicWF5f7873dwc09",
66
66
  },
67
67
  },
68
68
  ];
@@ -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
- }