From 0485c73ba292bd27cee6021212879a58d4828396 Mon Sep 17 00:00:00 2001 From: Aadesh Kheria Date: Sun, 12 Apr 2026 19:03:47 -0700 Subject: [PATCH] pr comment changes --- apps/backend/src/lib/ai/tools/docs.ts | 68 ------------------- apps/internal-tool/package.json | 8 +-- .../scripts/spacetime-publish.mjs | 36 ++++++++++ .../internal-tool/scripts/spacetime-token.mjs | 27 ++++++++ .../src/components/CallLogDetail.tsx | 2 +- .../internal-tool/src/hooks/useSpacetimeDB.ts | 12 +++- apps/internal-tool/tailwind.config.js | 4 +- docker/dependencies/docker.compose.yaml | 2 +- .../src/app/api/internal/[transport]/route.ts | 2 +- 9 files changed, 84 insertions(+), 77 deletions(-) create mode 100644 apps/internal-tool/scripts/spacetime-publish.mjs create mode 100644 apps/internal-tool/scripts/spacetime-token.mjs diff --git a/apps/backend/src/lib/ai/tools/docs.ts b/apps/backend/src/lib/ai/tools/docs.ts index 2327914ef..0c11e02d9 100644 --- a/apps/backend/src/lib/ai/tools/docs.ts +++ b/apps/backend/src/lib/ai/tools/docs.ts @@ -123,72 +123,4 @@ export async function createDocsTools() { }, }), }; - return { - list_available_docs: tool({ - description: - "Use this tool to learn about what Stack Auth is, available documentation, and see if you can use it for what you're working on. It returns a list of all available Stack Auth Documentation pages.", - inputSchema: z.object({}), - execute: async () => { - return await postDocsToolAction({ action: "list_available_docs" }); - }, - }), - - search_docs: tool({ - description: - "Search through all Stack Auth documentation including API docs, guides, and examples. Returns ranked results with snippets and relevance scores.", - inputSchema: z.object({ - search_query: z.string().describe("The search query to find relevant documentation"), - result_limit: z.number().optional().describe("Maximum number of results to return (default: 50)"), - }), - execute: async ({ search_query, result_limit = 50 }) => { - return await postDocsToolAction({ - action: "search_docs", - search_query, - result_limit, - }); - }, - }), - - get_docs_by_id: tool({ - description: - "Use this tool to retrieve a specific Stack Auth Documentation page by its ID. It gives you the full content of the page so you can know exactly how to use specific Stack Auth APIs. Whenever using Stack Auth, you should always check the documentation first to have the most up-to-date information. When you write code using Stack Auth documentation you should reference the content you used in your comments.", - inputSchema: z.object({ - id: z.string(), - }), - execute: async ({ id }) => { - return await postDocsToolAction({ action: "get_docs_by_id", id }); - }, - }), - - get_stack_auth_setup_instructions: tool({ - description: - "Use this tool when the user wants to set up authentication in a new project. It provides step-by-step instructions for installing and configuring Stack Auth authentication.", - inputSchema: z.object({}), - execute: async () => { - return await postDocsToolAction({ action: "get_stack_auth_setup_instructions" }); - }, - }), - - search: tool({ - description: - "Search for Stack Auth documentation pages.\n\nUse this tool to find documentation pages that contain a specific keyword or phrase.", - inputSchema: z.object({ - query: z.string(), - }), - execute: async ({ query }) => { - return await postDocsToolAction({ action: "search", query }); - }, - }), - - fetch: tool({ - description: - "Fetch a particular Stack Auth Documentation page by its ID.\n\nThis tool is identical to `get_docs_by_id`.", - inputSchema: z.object({ - id: z.string(), - }), - execute: async ({ id }) => { - return await postDocsToolAction({ action: "fetch", id }); - }, - }), - }; } diff --git a/apps/internal-tool/package.json b/apps/internal-tool/package.json index 98e4b49b4..3c75f36f8 100644 --- a/apps/internal-tool/package.json +++ b/apps/internal-tool/package.json @@ -11,10 +11,10 @@ "lint": "eslint --ext .ts,.tsx .", "clean": "rimraf .next && rimraf node_modules", "spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --module-path spacetimedb", - "spacetime:inject-token": "sed -i.bak \"s/__SPACETIMEDB_LOG_TOKEN__/${STACK_MCP_LOG_TOKEN:-change-me}/\" spacetimedb/src/index.ts", - "spacetime:restore-token": "mv spacetimedb/src/index.ts.bak spacetimedb/src/index.ts", - "spacetime:publish:local": "pnpm spacetime:inject-token && spacetime publish stack-auth-llm --server local -p spacetimedb --yes --no-config --delete-data=on-conflict; EXIT=$?; pnpm spacetime:restore-token; exit $EXIT", - "spacetime:publish:prod": "pnpm spacetime:inject-token && spacetime publish stack-auth-llm --server maincloud -p spacetimedb --yes --no-config; EXIT=$?; pnpm spacetime:restore-token; exit $EXIT" + "spacetime:inject-token": "node scripts/spacetime-token.mjs inject", + "spacetime:restore-token": "node scripts/spacetime-token.mjs restore", + "spacetime:publish:local": "node scripts/spacetime-publish.mjs local", + "spacetime:publish:prod": "node scripts/spacetime-publish.mjs prod" }, "dependencies": { "@stackframe/react": "workspace:*", diff --git a/apps/internal-tool/scripts/spacetime-publish.mjs b/apps/internal-tool/scripts/spacetime-publish.mjs new file mode 100644 index 000000000..51892eda7 --- /dev/null +++ b/apps/internal-tool/scripts/spacetime-publish.mjs @@ -0,0 +1,36 @@ +#!/usr/bin/env node +// Cross-platform SpacetimeDB publish that injects the token, publishes, and +// always restores the original file — even on failure. + +import { spawnSync } from "node:child_process"; + +const target = process.argv[2]; // "local" or "prod" + +const configs = { + local: ["publish", "stack-auth-llm", "--server", "local", "-p", "spacetimedb", "--yes", "--no-config", "--delete-data=on-conflict"], + prod: ["publish", "stack-auth-llm", "--server", "maincloud", "-p", "spacetimedb", "--yes", "--no-config"], +}; + +const args = configs[target]; +if (!args) { + console.error("Usage: node scripts/spacetime-publish.mjs "); + process.exit(1); +} + +if (target === "prod" && !process.env.STACK_MCP_LOG_TOKEN) { + console.error("Error: STACK_MCP_LOG_TOKEN must be set for prod publish"); + process.exit(1); +} + +// Inject token +const inject = spawnSync("node", ["scripts/spacetime-token.mjs", "inject"], { stdio: "inherit" }); +if (inject.status !== 0) { + process.exit(inject.status ?? 1); +} + +try { + const publish = spawnSync("spacetime", args, { stdio: "inherit" }); + process.exitCode = publish.status ?? 1; +} finally { + spawnSync("node", ["scripts/spacetime-token.mjs", "restore"], { stdio: "inherit" }); +} diff --git a/apps/internal-tool/scripts/spacetime-token.mjs b/apps/internal-tool/scripts/spacetime-token.mjs new file mode 100644 index 000000000..415ac1610 --- /dev/null +++ b/apps/internal-tool/scripts/spacetime-token.mjs @@ -0,0 +1,27 @@ +#!/usr/bin/env node +// Cross-platform token injection/restoration for SpacetimeDB publish. +// Replaces the Unix-only sed/mv scripts so pnpm dev works on Windows too. + +import { readFileSync, writeFileSync, existsSync, renameSync, unlinkSync } from "node:fs"; +import { resolve } from "node:path"; + +const TARGET = resolve("spacetimedb/src/index.ts"); +const BACKUP = TARGET + ".bak"; +const PLACEHOLDER = "__SPACETIMEDB_LOG_TOKEN__"; + +const action = process.argv[2]; + +if (action === "inject") { + const token = process.env.STACK_MCP_LOG_TOKEN || "change-me"; + const content = readFileSync(TARGET, "utf8"); + writeFileSync(BACKUP, content, "utf8"); + writeFileSync(TARGET, content.replaceAll(PLACEHOLDER, token), "utf8"); +} else if (action === "restore") { + if (existsSync(BACKUP)) { + unlinkSync(TARGET); + renameSync(BACKUP, TARGET); + } +} else { + console.error("Usage: node scripts/spacetime-token.mjs "); + process.exit(1); +} diff --git a/apps/internal-tool/src/components/CallLogDetail.tsx b/apps/internal-tool/src/components/CallLogDetail.tsx index db8ac2d54..a9716fdd2 100644 --- a/apps/internal-tool/src/components/CallLogDetail.tsx +++ b/apps/internal-tool/src/components/CallLogDetail.tsx @@ -295,7 +295,7 @@ function QaReviewCard({ row }: { row: McpCallLogRow }) { {flags.length > 0 && (
{flags.map((flag, i) => ( -
+
{flag.type} {flag.severity} diff --git a/apps/internal-tool/src/hooks/useSpacetimeDB.ts b/apps/internal-tool/src/hooks/useSpacetimeDB.ts index 90df1a5a0..683072360 100644 --- a/apps/internal-tool/src/hooks/useSpacetimeDB.ts +++ b/apps/internal-tool/src/hooks/useSpacetimeDB.ts @@ -23,6 +23,7 @@ export function useMcpCallLogs() { useEffect(() => { let cancelled = false; let retryCount = 0; + let retryTimer: ReturnType | null = null; console.log("[SpacetimeDB] Connecting to", HOST, "db:", DB_NAME); @@ -35,7 +36,8 @@ export function useMcpCallLogs() { return; } console.log(`[SpacetimeDB] Retrying in ${RETRY_DELAY_MS}ms (attempt ${retryCount}/${MAX_RETRIES})...`); - setTimeout(() => { + retryTimer = setTimeout(() => { + retryTimer = null; if (!cancelled) { connect().catch(() => {}); } @@ -110,6 +112,14 @@ export function useMcpCallLogs() { return () => { cancelled = true; + if (retryTimer !== null) { + clearTimeout(retryTimer); + retryTimer = null; + } + if (connRef.current) { + connRef.current.disconnect(); + connRef.current = null; + } }; }, []); diff --git a/apps/internal-tool/tailwind.config.js b/apps/internal-tool/tailwind.config.js index bf79d1f82..bc5e5c624 100644 --- a/apps/internal-tool/tailwind.config.js +++ b/apps/internal-tool/tailwind.config.js @@ -1,8 +1,10 @@ +import typography from '@tailwindcss/typography'; + /** @type {import('tailwindcss').Config} */ export default { content: ['./src/**/*.{ts,tsx}'], theme: { extend: {}, }, - plugins: [require('@tailwindcss/typography')], + plugins: [typography], }; diff --git a/docker/dependencies/docker.compose.yaml b/docker/dependencies/docker.compose.yaml index c371cd894..c745fea72 100644 --- a/docker/dependencies/docker.compose.yaml +++ b/docker/dependencies/docker.compose.yaml @@ -292,7 +292,7 @@ services: # ================= SpacetimeDB ================= spacetimedb: - image: clockworklabs/spacetime:latest + image: clockworklabs/spacetime:v2.1.0 pull_policy: always ports: - "${NEXT_PUBLIC_STACK_PORT_PREFIX:-81}39:3000" diff --git a/docs/src/app/api/internal/[transport]/route.ts b/docs/src/app/api/internal/[transport]/route.ts index 4df99e8bf..925a587b3 100644 --- a/docs/src/app/api/internal/[transport]/route.ts +++ b/docs/src/app/api/internal/[transport]/route.ts @@ -23,7 +23,7 @@ const handler = createMcpHandler( .string() .min(1) .describe( - "The original user message/prompt that triggered this tool call. Copy the user's exact words.", + "The original user message/prompt that triggered this tool call. Copy the user's exact words. Don't include any sensitive information.", ), conversationId: z .string()