Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
97157a4
Good with dummy data, very buggy, not finalized
Developing-Gamer Mar 10, 2026
388796c
Better design, still a lot of bugs, not final
Developing-Gamer Mar 10, 2026
c0bf265
Add email overview metrics and enhance chart interactivity
Developing-Gamer Mar 10, 2026
8467fc5
Add monthly active users metric and enhance dashboard interactivity
Developing-Gamer Mar 10, 2026
cb96f84
Merge branch 'dev' into overview-revamp
Developing-Gamer Mar 10, 2026
b71f9a1
Enhance dashboard interactivity with custom date range support
Developing-Gamer Mar 11, 2026
4ba4c7e
Completed, design, dummy data, not design-components
Developing-Gamer Mar 11, 2026
4a823a5
Refactor dashboard components to utilize DesignAnalyticsCard
Developing-Gamer Mar 11, 2026
f34c4ba
Enhance analytics overview with additional visitor metrics
Developing-Gamer Mar 11, 2026
4bd4ed2
Cursor PR review changes #1
Developing-Gamer Mar 11, 2026
6672e70
Enhance ComposedAnalyticsChart with conditional rendering for visitor…
Developing-Gamer Mar 11, 2026
659b5a6
Enhance PageLayout and ComposedAnalyticsChart with new props and cond…
Developing-Gamer Mar 11, 2026
2cb2596
Merge branch 'dev' into overview-revamp
Developing-Gamer Mar 11, 2026
1bdf953
fix
Developing-Gamer Mar 11, 2026
515d695
Refactor seeding functions and enhance metrics loading logic
Developing-Gamer Mar 12, 2026
d15f3f9
Refactor date handling in metrics loading functions
Developing-Gamer Mar 12, 2026
d3bd0f2
Refactor UUID handling and improve metrics data sanitization
Developing-Gamer Mar 12, 2026
919ae53
Merge branch 'dev' into overview-revamp
Developing-Gamer Mar 12, 2026
28956a9
Merge remote-tracking branch 'origin/dev' into overview-revamp
N2D4 Apr 3, 2026
5c42f80
Fix PR comments
N2D4 Apr 4, 2026
396a9b2
Enhance metrics calculations and UI components
mantrakp04 Apr 6, 2026
3f9b656
Refactor metrics data retrieval to use raw SQL queries
mantrakp04 Apr 6, 2026
3147102
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 6, 2026
c7f64ca
Enhance metrics functionality and introduce deterministic UUIDs
mantrakp04 Apr 6, 2026
ea576c2
Add chart demo components for interactive data visualization
mantrakp04 Apr 8, 2026
451bbb0
Implement new analytics chart demo components
mantrakp04 Apr 8, 2026
dec11b4
Refactor analytics chart components and update imports
mantrakp04 Apr 8, 2026
3dd62d4
Add db:seed-activity script and enhance image validation in AI query …
mantrakp04 Apr 9, 2026
6c718e1
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 9, 2026
11014b0
Refactor backend seed scripts and enhance data grid functionality
mantrakp04 Apr 10, 2026
7ff0cf8
Enhance image attachment validation and refactor related components
mantrakp04 Apr 11, 2026
a812ba2
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 13, 2026
c17eb7c
Enhance AI Query Functionality and UI Components
mantrakp04 Apr 13, 2026
de3de70
Add Metrics Helper Functions and Tests
mantrakp04 Apr 13, 2026
31d3a8d
Refactor Analytics Metrics Queries
mantrakp04 Apr 13, 2026
19ad10e
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 13, 2026
a52cba2
Update test snapshots to reflect changes in risk scores for sign-up m…
mantrakp04 Apr 13, 2026
7076f77
Increase timeout for internal metrics and team invitations tests to 1…
mantrakp04 Apr 14, 2026
ac1949b
Merge branch 'dev' into overview-revamp
N2D4 Apr 14, 2026
561d918
Merge branch 'dev' into overview-revamp
N2D4 Apr 14, 2026
096237c
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 14, 2026
8ff2ad7
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 14, 2026
49cef06
Merge branch 'dev' into overview-revamp
mantrakp04 Apr 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions apps/backend/src/app/api/latest/ai/query/[mode]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getTools, validateToolNames } from "@/lib/ai/tools";
import { listManagedProjectIds } from "@/lib/projects";
import { SmartResponse } from "@/route-handlers/smart-response";
import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler";
import { validateImageAttachments } from "@stackframe/stack-shared/dist/ai/image-limits";
import { yupMixed, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
import { StatusError } from "@stackframe/stack-shared/dist/utils/errors";
import { Json } from "@stackframe/stack-shared/dist/utils/json";
Expand All @@ -31,7 +32,6 @@ export const POST = createSmartRouteHandler({
const isAuthenticated = fullReq.auth != null;
const { quality, speed, systemPrompt: systemPromptId, tools: toolNames, messages, projectId } = body;

// Verify user has access to the target project
if (projectId != null) {
if (fullReq.auth?.project.id !== "internal") {
throw new StatusError(StatusError.Forbidden, "You do not have access to this project");
Expand All @@ -46,12 +46,31 @@ export const POST = createSmartRouteHandler({
}
}

const imageValidationResult = validateImageAttachments(messages);
if (!imageValidationResult.ok) {
throw new StatusError(StatusError.BadRequest, imageValidationResult.reason);
}

const model = selectModel(quality, speed, isAuthenticated);
const systemPrompt = getFullSystemPrompt(systemPromptId);
const tools = await getTools(toolNames, { auth: fullReq.auth, targetProjectId: projectId });
const toolsArg = Object.keys(tools).length > 0 ? tools : undefined;
const isDocsOrSearch = systemPromptId === "docs-ask-ai" || systemPromptId === "command-center-ask-ai";
const stepLimit = toolsArg == null ? 1 : isDocsOrSearch ? 50 : 5;
// create-dashboard now does an inspection loop (queryAnalytics) before calling updateDashboard,
// so it needs room for ~3 exploratory queries + the final tool call + some retry slack.
const isCreateDashboard = systemPromptId === "create-dashboard";
// build-analytics-query aims for one-shot queries with complete schema
// knowledge, but needs a few steps for retries on errors or follow-ups.
const isBuildAnalyticsQuery = systemPromptId === "build-analytics-query";
const stepLimit = toolsArg == null
? 1
: isDocsOrSearch
? 50
: isCreateDashboard
? 12
: isBuildAnalyticsQuery
? 5
: 5;

if (mode === "stream") {
const result = streamText({
Expand Down
20 changes: 20 additions & 0 deletions apps/backend/src/app/api/latest/internal/metrics/route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import { getMetricsWindowBounds, isMetricsRevenueInvoiceStatus } from "./route";

describe("internal metrics helpers", () => {
it("only counts paid and succeeded invoices as revenue", () => {
expect(isMetricsRevenueInvoiceStatus("paid")).toBe(true);
expect(isMetricsRevenueInvoiceStatus("succeeded")).toBe(true);
expect(isMetricsRevenueInvoiceStatus("failed")).toBe(false);
expect(isMetricsRevenueInvoiceStatus("uncollectible")).toBe(false);
expect(isMetricsRevenueInvoiceStatus(null)).toBe(false);
});

it("derives a single UTC-aligned rolling window from one clock", () => {
const { todayUtc, since, untilExclusive } = getMetricsWindowBounds(new Date("2026-04-13T23:59:59.999Z"));

expect(todayUtc.toISOString()).toBe("2026-04-13T00:00:00.000Z");
expect(since.toISOString()).toBe("2026-03-14T00:00:00.000Z");
expect(untilExclusive.toISOString()).toBe("2026-04-14T00:00:00.000Z");
});
});
Loading
Loading