-
Notifications
You must be signed in to change notification settings - Fork 510
Custom dashboards and unified ai no playground #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aadesh18
merged 195 commits into
dev
from
custom-dashboards-and-unified-ai-no-playground
Mar 13, 2026
+7,281
−2,745
Merged
Changes from all commits
Commits
Show all changes
195 commits
Select commit
Hold shift + click to select a range
9e41309
added external-db-sync
aadesh18 3879001
stopped using yupArray
aadesh18 937db90
fixed build errors
aadesh18 3f2a8ef
Revert "fixed build errors"
aadesh18 dcda402
Update apps/backend/scripts/run-cron-jobs.ts
aadesh18 9e954b9
Update apps/backend/src/app/api/latest/internal/external-db-sync/poll…
aadesh18 f0cc311
Update apps/backend/src/app/api/latest/internal/external-db-sync/poll…
aadesh18 1d7a0de
pr changes
aadesh18 8c2d1c3
merge dev
BilalG1 409d89b
Merge remote-tracking branch 'origin/dev' into external-db-sync
BilalG1 0d2b3b9
fix pnpm lock
BilalG1 ef8f74e
fix typecheck
BilalG1 8cdd107
prisma fix
BilalG1 871fe12
fix tests
BilalG1 5d6bde2
fix lint
BilalG1 c4ed09a
fix
BilalG1 b102db3
fix tests
BilalG1 2eeb537
fix tests
BilalG1 c61a2b9
fix test
BilalG1 ac261d2
increase session test time
BilalG1 0c1a02e
fix flaky test and external sot sync
BilalG1 79e330f
comment resolving
BilalG1 939b1a9
resolve pr comments
BilalG1 2974c83
retry
BilalG1 0799a0b
attempt test fixes
BilalG1 1f67742
fix env
BilalG1 bd788b4
fix env
BilalG1 4b7dd53
attempt test fixes
BilalG1 044377e
fix tests
BilalG1 744b871
Merge branch 'dev' into external-db-sync
BilalG1 74c634b
fix lint
BilalG1 ce5a1bb
fix tests
BilalG1 2c5440b
fix tests
BilalG1 f726f61
Merge remote-tracking branch 'origin/dev' into external-db-sync
BilalG1 665c084
fix tests
BilalG1 85bb893
Merge branch 'dev' into external-db-sync
BilalG1 856aaf3
fix tests
BilalG1 8f3ad45
m
BilalG1 fe393e9
merge dev
BilalG1 b9c0ef4
fix lockfile
BilalG1 b5781a1
Merge remote-tracking branch 'origin/dev' into external-db-sync
BilalG1 b841f7b
fix tests
BilalG1 2e0d8de
m
BilalG1 e5cbc1a
Merge branch 'dev' into external-db-sync
BilalG1 ba1df26
fix tests
BilalG1 093eaf0
e2e: isolate external DB sync cleanup per suite (#1148)
BilalG1 5192875
CI: run dev tests single-worker (#1153)
BilalG1 686a1e6
Merge branch 'dev' into external-db-sync
BilalG1 8910138
fixes
BilalG1 62171dc
single test run
BilalG1 1038d1a
Merge branch 'dev' into external-db-sync
BilalG1 3370e63
test fixes (#1155)
BilalG1 d04e944
concurrent fix
BilalG1 61f2b79
Merge branch 'external-db-sync' of https://github.com/stack-auth/stac…
BilalG1 bbac70e
Merge branch 'dev' into external-db-sync
BilalG1 8e92205
fix routes, external-db dashboard
BilalG1 3b9c22e
merge dev
BilalG1 c0a3f7a
replace trigger
BilalG1 d34a2c7
fusebox
BilalG1 c91998e
add tracing
BilalG1 64d9d93
remove old tests
BilalG1 7fd7886
fix sot test
BilalG1 719d1c2
Merge remote-tracking branch 'origin/dev' into external-db-sync
BilalG1 43c1f15
clickhouse user sync
BilalG1 04970c2
Update vercel.json
N2D4 4abd410
Various fixes
N2D4 8247481
test: disable direct external db sync in CI
BilalG1 362e1fb
merge dev
BilalG1 98d451d
increase test timeout
BilalG1 6b89370
cmd k query analytics (#1160)
BilalG1 ff370b6
Merge branch 'external-db-sync' into external-db-sync-clickhouse-default
BilalG1 8be639d
Merge branch 'dev' into external-db-sync
BilalG1 caa3dca
remove fusebox sync engine col
BilalG1 445e889
Merge branch 'external-db-sync' of https://github.com/stack-auth/stac…
BilalG1 63df87a
fix test
BilalG1 9c340f4
Merge branch 'external-db-sync' into external-db-sync-clickhouse-default
BilalG1 45e7d2d
merge dev
BilalG1 925a865
fix zod version
BilalG1 b83063c
move test
BilalG1 b673ab5
fix lint
BilalG1 fcf493e
Merge branch 'dev' into external-db-sync-clickhouse-default
BilalG1 8534caa
Merge branch 'dev' into external-db-sync-clickhouse-default
BilalG1 2f7acb4
Add STACK_OPENAI_API_KEY to .env.development
N2D4 cf5558e
pr comment fixes
BilalG1 4ab4be8
merge dev
BilalG1 1421461
Add TEST_TIMEOUT to ClickHouse sync tests
BilalG1 90eb9ae
Merge branch 'dev' into external-db-sync-clickhouse-default
BilalG1 afa76be
token refresh event change (#1162)
BilalG1 a509be3
fix type issue
BilalG1 02b6ef6
Merge branch 'dev' into external-db-sync-clickhouse-default
BilalG1 62d054e
fix tests
BilalG1 558d0f6
Merge branch 'external-db-sync-clickhouse-default' of https://github.…
BilalG1 0dc2e94
fix clickhouse needsResync
BilalG1 3db832e
Increase ClickHouse poll interval from 500ms to 2s
BilalG1 3cde6fa
fix test ordering
BilalG1 a2033bc
added ai custom dashboards
aadesh18 b01d17b
Update apps/dashboard/src/components/commands/create-dashboard/dashbo…
aadesh18 0fcc37c
Update apps/dashboard/src/components/commands/create-dashboard/dashbo…
aadesh18 7c6173e
Update apps/dashboard/src/components/commands/create-dashboard/dashbo…
aadesh18 416051f
Update apps/dashboard/src/components/commands/create-dashboard/create…
aadesh18 8cff361
added greptile suggestion
aadesh18 e107078
fixed conflict
aadesh18 5accb8b
updated imports
aadesh18 c52bdd1
Merge commit 'd09a180dfe800a471ca1fb8ea101fd0cdeef0d4d' into custom-d…
N2D4 ad6eb03
Merge branch 'custom-dashboards-last-from-bilal-2' into custom-dashbo…
N2D4 579c723
Update apps/dashboard/scripts/bundle-type-definitions.ts
aadesh18 59f6998
Update apps/dashboard/src/app/api/create-dashboard/route.ts
aadesh18 4799b34
Update apps/dashboard/src/lib/ai-dashboard/contracts.ts
aadesh18 bb94e48
Apply suggestion from @N2D4
aadesh18 3dac1cd
Apply suggestion from @N2D4
aadesh18 805a78f
Apply suggestion from @N2D4
aadesh18 e89989e
Apply suggestion from @N2D4
aadesh18 183ce10
Apply suggestion from @N2D4
aadesh18 593cb26
dynamic esm versioning
aadesh18 7c96c52
changes based on the pr review
aadesh18 64cc8ab
minor bug fix
aadesh18 4309859
bug fixes
aadesh18 00c01b3
pnpm lock
aadesh18 f764f50
Merge remote-tracking branch 'origin/dev' into custom-dashboards
aadesh18 aaeab15
removed temp file
aadesh18 7afa78b
v1 working
aadesh18 a677486
cmd center ai chat working
aadesh18 0e71470
email templates, drafts and theme working
aadesh18 592c2c0
docs ai working
aadesh18 44f4303
saving dashboards + dashboard package
aadesh18 241f646
Merge remote-tracking branch 'origin/dev' into unified-ai-endpoint
aadesh18 fc45436
bug fixes
aadesh18 90701e8
Merge branch 'unified-ai-endpoint' into custom-dashboards
aadesh18 5acb916
using unified ai endpoint for custom dashboards as well
aadesh18 91c6bcb
bug fixes
aadesh18 bca8547
bug fix
aadesh18 8dbbf9b
pnpm update
aadesh18 4379976
More stringent caching mitigation
N2D4 68a5d8d
Merge branch 'dev' into unified-ai-endpoint
aadesh18 87c18e4
minor issues fixed
aadesh18 97dead3
minor bug fixes
aadesh18 c6caf88
bug fixes
aadesh18 56c4951
Merge remote-tracking branch 'origin/unified-ai-endpoint' into custom…
aadesh18 66ba625
using unified endpoint
aadesh18 0b895f9
removed local testing
aadesh18 261feaf
minor changes
aadesh18 c031124
more changes
aadesh18 3fa91d5
minor bug fix
aadesh18 bcb2534
pnpm changes
aadesh18 a50240c
removed comment
aadesh18 e066cac
pr review changes
aadesh18 0c23229
refactoring changes
aadesh18 2b6bd54
pnpm changes
aadesh18 1b8652b
minor changes
aadesh18 a72c5bd
add comment
aadesh18 f2ec371
minor bug fix
aadesh18 fad9ef4
Merge remote-tracking branch 'origin/unified-ai-endpoint' into custom…
aadesh18 b92a8e9
merge changes
aadesh18 b412b68
ui changes
aadesh18 93f7984
fixed bug
aadesh18 33d9e44
unused file
aadesh18 a7aa24c
refactoring changes
aadesh18 6d39d36
Fix casing of allowTransparency attribute
aadesh18 d866df4
Type cast dashboard variable for better type safety
aadesh18 e418165
Update allowTransparency prop to use boolean syntax
aadesh18 2485c1b
working version 1
aadesh18 957cef3
pnpm changes
aadesh18 782e592
good version v1
aadesh18 24e5620
merged unified ai and custom-dashboard-features
aadesh18 b1ce9
8000
f3
Merge branch 'dev' into custom-dashboards-and-unified-ai
aadesh18 21e21c8
wip 1
aadesh18 4d50344
everything working v1
aadesh18 d45f99d
buggy version
aadesh18 998d670
slight improvements
aadesh18 94457fb
working
aadesh18 d5955b9
Delete .cursor/debug-9f43b8.log
aadesh18 ec1d658
bug fix
aadesh18 95b5500
sdk update
aadesh18 bef05a9
pr changes
aadesh18 2d0923a
reverse playground changes
aadesh18 9ee952b
bug fixes
aadesh18 b039e6a
Merge remote-tracking branch 'origin/dev' into custom-dashboards-and-…
aadesh18 cfd714f
minor changes
aadesh18 1680c7e
Merge branch 'dev' into custom-dashboards-and-unified-ai-no-playground
aadesh18 1ee0b99
more pr changes
aadesh18 c2baf80
type def changes
aadesh18 48fdc6e
more pr changes
aadesh18 0ae952d
type changes
aadesh18 d6de4e6
test and docs fix
aadesh18 316cfda
edited test
aadesh18 b0091ee
fix chat
aadesh18 3406272
removed 35k lines :]
aadesh18 0fddfd0
pr changes
aadesh18 d06ee3f
bug fix
aadesh18 a74c401
Merge remote-tracking branch 'origin/dev' into custom-dashboards-and-…
aadesh18 2afa321
bug fix
aadesh18 d67cbd4
test fix
aadesh18 91546bf
test fix
aadesh18 46e7fb0
Merge branch 'dev' into custom-dashboards-and-unified-ai-no-playground
aadesh18 e2d57c0
dev merge bug fixes
aadesh18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
apps/backend/src/app/api/latest/ai/query/[mode]/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { forwardToProduction } from "@/lib/ai/forward"; | ||
| import { selectModel } from "@/lib/ai/models"; | ||
| import { getFullSystemPrompt } from "@/lib/ai/prompts"; | ||
| import { requestBodySchema } from "@/lib/ai/schema"; | ||
| 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 { yupMixed, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
| import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env"; | ||
| import { StatusError } from "@stackframe/stack-shared/dist/utils/errors"; | ||
| import { Json } from "@stackframe/stack-shared/dist/utils/json"; | ||
| import { generateText, ModelMessage, stepCountIs, streamText } from "ai"; | ||
|
|
||
| export const POST = createSmartRouteHandler({ | ||
| metadata: { | ||
| hidden: true, | ||
| }, | ||
| request: yupObject({ | ||
| params: yupObject({ | ||
| mode: yupString().oneOf(["stream", "generate"]).defined(), | ||
| }), | ||
| body: requestBodySchema, | ||
| }), | ||
| response: yupMixed<SmartResponse>().defined(), | ||
| async handler({ params, body }, fullReq) { | ||
| const { mode } = params; | ||
|
|
||
| if (!validateToolNames(body.tools)) { | ||
| throw new StatusError(StatusError.BadRequest, `Invalid tool names in request.`); | ||
| } | ||
|
|
||
| const apiKey = getEnvVariable("STACK_OPENROUTER_API_KEY"); | ||
|
|
||
|
|
||
| if (apiKey === "FORWARD_TO_PRODUCTION") { | ||
| const prodResponse = await forwardToProduction(mode, body); | ||
| return { | ||
| statusCode: prodResponse.status, | ||
| bodyType: "response" as const, | ||
| body: prodResponse, | ||
| }; | ||
| } | ||
|
|
||
| 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) { | ||
| const user = fullReq.auth?.user; | ||
| if (user == null) { | ||
| throw new StatusError(StatusError.Forbidden, "You do not have access to this project"); | ||
| } | ||
| const managedProjectIds = await listManagedProjectIds(user); | ||
| if (!managedProjectIds.includes(projectId)) { | ||
| throw new StatusError(StatusError.Forbidden, "You do not have access to this project"); | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
|
|
||
| if (mode === "stream") { | ||
| const result = streamText({ | ||
| model, | ||
| system: systemPrompt, | ||
| messages: messages as ModelMessage[], | ||
| tools: toolsArg, | ||
| stopWhen: stepCountIs(stepLimit), | ||
| }); | ||
| return { | ||
| statusCode: 200, | ||
| bodyType: "response" as const, | ||
| body: result.toUIMessageStreamResponse(), | ||
| }; | ||
| } else { | ||
| const controller = new AbortController(); | ||
| const timeoutId = setTimeout(() => controller.abort(), 120_000); | ||
aadesh18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const result = await generateText({ | ||
| model, | ||
| system: systemPrompt, | ||
| messages: messages as ModelMessage[], | ||
| tools: toolsArg, | ||
aadesh18 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| abortSignal: controller.signal, | ||
| stopWhen: stepCountIs(stepLimit), | ||
| }).finally(() => clearTimeout(timeoutId)); | ||
|
|
||
| const contentBlocks: Array< | ||
| | { type: "text", text: string } | ||
| | { | ||
| type: "tool-call", | ||
| toolName: string, | ||
| toolCallId: string, | ||
| args: Json, | ||
| argsText: string, | ||
| result: Json, | ||
| } | ||
| > = []; | ||
|
|
||
| result.steps.forEach((step) => { | ||
| if (step.text) { | ||
| contentBlocks.push({ | ||
| type: "text", | ||
| text: step.text, | ||
| }); | ||
| } | ||
|
|
||
| const toolResultsByCallId = new Map( | ||
| step.toolResults.map((r) => [r.toolCallId, r]) | ||
| ); | ||
|
|
||
| step.toolCalls.forEach((toolCall) => { | ||
| const toolResult = toolResultsByCallId.get(toolCall.toolCallId); | ||
| contentBlocks.push({ | ||
| type: "tool-call", | ||
| toolName: toolCall.toolName, | ||
| toolCallId: toolCall.toolCallId, | ||
| args: toolCall.input, | ||
| argsText: JSON.stringify(toolCall.input), | ||
| result: (toolResult?.output ?? null) as Json, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| return { | ||
| statusCode: 200, | ||
| bodyType: "json" as const, | ||
| body: { content: contentBlocks }, | ||
| }; | ||
| } | ||
| }, | ||
| }); | ||
140 changes: 1 addition & 139 deletions
140
apps/backend/src/app/api/latest/internal/ai-chat/[threadId]/route.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.