Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 25 additions & 42 deletions apps/studio.giselles.ai/lib/trace.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
import { traceGeneration } from "@giselles-ai/langfuse";
import type {
CompletedGeneration,
FailedGeneration,
OutputFileBlob,
} from "@giselles-ai/protocol";
import type { ModelMessage, ProviderMetadata } from "ai";
import type { CurrentTeam } from "@/services/teams";
import { Langfuse } from "langfuse";
import { traceGeneration } from "@repo/langfuse/trace-generation";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Import traceGeneration from a resolvable package path

This import switches to @repo/langfuse/trace-generation, but apps/studio.giselles.ai/tsconfig.json only maps @/* and @giselles-ai/*, so the module cannot be resolved during type-check/build. In this state the studio app fails to compile before telemetry runs, so the deploymentId change never reaches production.

Useful? React with 👍 / 👎.

Comment on lines +1 to +2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. trace.ts imports not organized 📘 Rule violation ✓ Correctness

The new imports in apps/studio.giselles.ai/lib/trace.ts are not organized/sorted in a
Biome-compatible way, which can cause formatting/CI failures and inconsistent style. Biome typically
expects organized imports (including consistent ordering).
Agent Prompt
## Issue description
`apps/studio.giselles.ai/lib/trace.ts` has newly-added imports that are not organized/sorted in a Biome-compatible way.

## Issue Context
PR Compliance requires Biome-compatible formatting, including organized imports.

## Fix Focus Areas
- apps/studio.giselles.ai/lib/trace.ts[1-2]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


type TeamForPlan = Pick<
CurrentTeam,
"id" | "activeSubscriptionId" | "activeCustomerId" | "plan"
>;
const langfuse = new Langfuse({
secretKey: process.env.LANGFUSE_SECRET_KEY,
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
baseUrl: process.env.LANGFUSE_BASE_URL,
});
Comment on lines +4 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Wrong langfuse base env 🐞 Bug ⛯ Reliability

apps/studio.giselles.ai/lib/trace.ts reads LANGFUSE_BASE_URL, but the repo documents
LANGFUSE_BASEURL, so baseUrl configuration will not be applied. This can route telemetry to the
wrong Langfuse endpoint or fail in self-hosted setups.
Agent Prompt
## Issue description
The code reads `LANGFUSE_BASE_URL` but the repo’s documented env var is `LANGFUSE_BASEURL`, so `baseUrl` will stay undefined for correctly configured environments.

## Issue Context
This silently breaks base URL configuration for Langfuse.

## Fix Focus Areas
- apps/studio.giselles.ai/lib/trace.ts[4-8]
- apps/studio.giselles.ai/.env.example[22-26]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +1 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Direct imports of lib/trace from client modules =="
rg -n --type ts --type tsx 'from ["'\''].*lib/trace["'\'']|from ["'\''].*\/trace["'\'']' apps/studio.giselles.ai \
| cut -d: -f1 | sort -u \
| while read -r file; do
  if rg -n '^\s*["'\'']use client["'\'']' "$file" >/dev/null; then
    echo "CLIENT_IMPORT: $file"
  fi
done

Repository: giselles-ai/giselle

Length of output: 283


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# First, let's check the current content of the trace.ts file
echo "=== Current content of trace.ts ==="
cat -n apps/studio.giselles.ai/lib/trace.ts

echo ""
echo "=== Checking for direct imports of trace module ==="
# Fix: Use simpler regex pattern for ripgrep
rg 'from ["\x27].*trace["\x27]' apps/studio.giselles.ai --type ts --type tsx -n

echo ""
echo "=== Checking for imports with full path ==="
rg 'import.*from.*lib/trace' apps/studio.giselles.ai --type ts --type tsx -n

echo ""
echo "=== Checking for client components that might import trace ==="
rg '(use client|"use client")' apps/studio.giselles.ai --type ts --type tsx -l | head -20

Repository: giselles-ai/giselle

Length of output: 987


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Searching for imports of trace module ==="
# Search for imports of the trace module
rg 'from ["\x27].*trace["\x27]|import.*trace' apps/studio.giselles.ai -n | grep -i 'lib/trace\|/trace'

echo ""
echo "=== Checking if trace is imported in any client component ==="
# Find all client components first
find apps/studio.giselles.ai -type f \( -name "*.ts" -o -name "*.tsx" \) | while read -r file; do
  if grep -q '"use client"' "$file" 2>/dev/null; then
    # This is a client component - check if it imports trace
    if grep -q 'trace' "$file" 2>/dev/null; then
      echo "CLIENT_COMPONENT_WITH_TRACE: $file"
      grep -n 'import.*trace\|from.*trace' "$file" 2>/dev/null || true
    fi
  fi
done

echo ""
echo "=== Searching all imports of trace anywhere ==="
rg 'import.*trace' apps/studio.giselles.ai -n | head -30

Repository: giselles-ai/giselle

Length of output: 1219


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Checking trigger/generate-content-job.ts ==="
head -30 apps/studio.giselles.ai/trigger/generate-content-job.ts

echo ""
echo "=== Checking app/giselle.ts ==="
head -50 apps/studio.giselles.ai/app/giselle.ts

echo ""
echo "=== Verifying if any of these importing files are client components ==="
for file in apps/studio.giselles.ai/trigger/generate-content-job.ts apps/studio.giselles.ai/app/giselle.ts; do
  echo "File: $file"
  grep '"use client"' "$file" 2>/dev/null && echo "  -> HAS 'use client'" || echo "  -> NO 'use client' (server-side)"
done

echo ""
echo "=== Checking what is exported from trace.ts ==="
grep '^export' apps/studio.giselles.ai/lib/trace.ts

Repository: giselles-ai/giselle

Length of output: 3425


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Full content of trace.ts ==="
wc -l apps/studio.giselles.ai/lib/trace.ts

echo ""
echo "=== Complete trace.ts file ==="
cat apps/studio.giselles.ai/lib/trace.ts

echo ""
echo "=== Searching for traceGenerationForTeam in the entire apps/studio.giselles.ai ==="
rg 'traceGenerationForTeam' apps/studio.giselles.ai -n

Repository: giselles-ai/giselle

Length of output: 1541


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Searching for traceGenerationForTeam export ==="
rg 'export.*traceGenerationForTeam' apps/studio.giselles.ai -n

echo ""
echo "=== Searching for traceGenerationForTeam definition anywhere in repo ==="
rg 'const traceGenerationForTeam|function traceGenerationForTeam|export.*traceGenerationForTeam' . -n | head -20

echo ""
echo "=== Check if there might be a re-export or aliasing in trace.ts ==="
rg 'traceGenerationForTeam' apps/studio.giselles.ai/lib/trace.ts -n

Repository: giselles-ai/giselle

Length of output: 114


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Checking if trace.ts might be exporting traceGenerationForTeam via star export or re-export ==="
cat apps/studio.giselles.ai/lib/trace.ts | grep -E 'export|traceGenerationForTeam' || echo "No match found"

echo ""
echo "=== Looking for any trace.ts files ==="
find apps/studio.giselles.ai -name "trace.ts" -o -name "trace.tsx"

echo ""
echo "=== Checking if there's an index file that might re-export ==="
ls -la apps/studio.giselles.ai/lib/ | grep -E 'index|trace'

echo ""
echo "=== Let's verify the actual import line from generate-content-job.ts ==="
sed -n '1,10p' apps/studio.giselles.ai/trigger/generate-content-job.ts

Repository: giselles-ai/giselle

Length of output: 873


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Searching for traceGenerationForTeam in entire repository ==="
rg 'traceGenerationForTeam' . -n 2>/dev/null | head -30

echo ""
echo "=== Checking `@repo/langfuse` package for this export ==="
find . -path "*/langfuse/*" -name "*.ts" -o -name "*.tsx" 2>/dev/null | head -20

echo ""
echo "=== Checking if there's a langfuse directory ==="
find . -type d -name "langfuse" 2>/dev/null

Repository: giselles-ai/giselle

Length of output: 2192


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Looking for langfuse in packages directory ==="
find . -path "*/packages/*langfuse*" -type d 2>/dev/null | head -10

echo ""
echo "=== Checking monorepo structure ==="
ls -la packages/ 2>/dev/null | head -20

echo ""
echo "=== Search for where traceGenerationForTeam might be defined ==="
rg 'export.*function.*traceGenerationForTeam|export const traceGenerationForTeam' . 2>/dev/null

echo ""
echo "=== Check if perhaps the review comment is about a file that doesn't match current state ==="
echo "Looking for any recent changes or different trace files:"
find apps -name "*trace*" -type f 2>/dev/null | grep -v node_modules

Repository: giselles-ai/giselle

Length of output: 1402


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Checking packages/langfuse structure ==="
find packages/langfuse -type f -name "*.ts" -o -name "*.tsx" 2>/dev/null

echo ""
echo "=== Checking main export from packages/langfuse ==="
cat packages/langfuse/src/index.ts 2>/dev/null || cat packages/langfuse/src/main.ts 2>/dev/null || ls -la packages/langfuse/src/

echo ""
echo "=== Search for traceGenerationForTeam in packages ==="
rg 'traceGenerationForTeam' packages/ 2>/dev/null

echo ""
echo "=== Check if trace.ts might be a recent addition and this is incomplete ==="
echo "Looking at the actual import in context:"
sed -n '1,25p' apps/studio.giselles.ai/app/giselle.ts | tail -10

Repository: giselles-ai/giselle

Length of output: 433


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Content of packages/langfuse/src/trace-generation.ts ==="
cat packages/langfuse/src/trace-generation.ts

echo ""
echo "=== Content of packages/langfuse/src/trace-embedding.ts ==="
head -50 packages/langfuse/src/trace-embedding.ts

Repository: giselles-ai/giselle

Length of output: 1892


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Comprehensive search for traceGenerationForTeam in entire repo ==="
rg 'traceGenerationForTeam' . --type ts --type tsx 2>/dev/null | head -30

echo ""
echo "=== Check if maybe it's defined in app/giselle.ts itself ==="
grep -n 'traceGenerationForTeam\|export.*trace' apps/studio.giselles.ai/app/giselle.ts | head -20

echo ""
echo "=== Check if there's aliasing happening in the imports ==="
grep -A5 'import.*trace' apps/studio.giselles.ai/app/giselle.ts | head -20

echo ""
echo "=== Double-check what's actually exported from trace.ts ==="
grep '^export' apps/studio.giselles.ai/lib/trace.ts

Repository: giselles-ai/giselle

Length of output: 133


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Checking the exact line where traceGenerationForTeam is imported ==="
sed -n '7p' apps/studio.giselles.ai/trigger/generate-content-job.ts

echo ""
echo "=== Checking if perhaps the file has been modified and export is missing ==="
echo "Full trace.ts again:"
cat -n apps/studio.giselles.ai/lib/trace.ts

echo ""
echo "=== Let's check if there are any TypeScript errors or if this even compiles ==="
echo "Checking tsconfig paths to understand module resolution:"
grep -r '"@/lib' apps/studio.giselles.ai/tsconfig.json 2>/dev/null || grep -r '"@/' tsconfig.json 2>/dev/null | head -5

Repository: giselles-ai/giselle

Length of output: 1217


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Checking git status to see if trace.ts is being modified ==="
cd apps/studio.giselles.ai && git diff lib/trace.ts 2>/dev/null || echo "No git diff available"
cd - > /dev/null

echo ""
echo "=== Let's verify what the actual issue is - check app/giselle.ts usage ==="
sed -n '228,235p' apps/studio.giselles.ai/app/giselle.ts

echo ""
echo "=== Let's see how traceGenerationForTeam is being called ==="
sed -n '228,245p' apps/studio.giselles.ai/app/giselle.ts

Repository: giselles-ai/giselle

Length of output: 851


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== This is a critical issue - let's understand what traceGenerationForTeam should be ==="
echo "Based on usage patterns, checking if it's supposed to be a wrapper around trace:"

echo ""
echo "=== Check if there's a team parameter in the trace function ==="
sed -n '10,29p' apps/studio.giselles.ai/lib/trace.ts

echo ""
echo "=== Let's check what parameters traceGenerationForTeam receives ==="
sed -n '66,75p' apps/studio.giselles.ai/trigger/generate-content-job.ts

echo ""
echo "=== Summary: Is trace.ts exporting everything it should? ==="
echo "Expected exports from trace.ts based on imports:"
echo "1. trace (currently exported)"
echo "2. traceGenerationForTeam (NOT exported - MISSING!)"

echo ""
echo "=== This appears to be incomplete code - let's verify the review comment is about this file ==="
echo "Review comment references lines 1-8 of trace.ts, which matches what we see."

Repository: giselles-ai/giselle

Length of output: 1399


Add "server-only" guard to prevent accidental client-side imports of secret environment variables.

This module initializes Langfuse with secret keys (LANGFUSE_SECRET_KEY, LANGFUSE_PUBLIC_KEY, LANGFUSE_BASE_URL). Add the "server-only" directive at the top to enforce server-side-only usage and align with Next.js best practices.

Proposed fix
+import "server-only";
 import { Langfuse } from "langfuse";
 import { traceGeneration } from "@repo/langfuse/trace-generation";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { Langfuse } from "langfuse";
import { traceGeneration } from "@repo/langfuse/trace-generation";
type TeamForPlan = Pick<
CurrentTeam,
"id" | "activeSubscriptionId" | "activeCustomerId" | "plan"
>;
const langfuse = new Langfuse({
secretKey: process.env.LANGFUSE_SECRET_KEY,
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
baseUrl: process.env.LANGFUSE_BASE_URL,
});
import "server-only";
import { Langfuse } from "langfuse";
import { traceGeneration } from "@repo/langfuse/trace-generation";
const langfuse = new Langfuse({
secretKey: process.env.LANGFUSE_SECRET_KEY,
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
baseUrl: process.env.LANGFUSE_BASE_URL,
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/studio.giselles.ai/lib/trace.ts` around lines 1 - 8, This module
initializes Langfuse with secret environment keys (Langfuse, langfuse,
traceGeneration); add the Next.js server-only guard by importing/adding the
"server-only" directive as the very first statement in the file (before any
other imports) so the module cannot be accidentally bundled for client-side use;
keep the rest of the file unchanged and ensure the directive appears above the
imports of Langfuse and traceGeneration.

Comment on lines +4 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fail fast on missing Langfuse credentials with actionable errors.

Lines 5-6 currently pass env vars through without validation. If missing, telemetry failures become hard to diagnose.

Proposed fix
 import { Langfuse } from "langfuse";
 import { traceGeneration } from "@repo/langfuse/trace-generation";
 
+const getRequiredEnvVar = (name: string): string => {
+	const value = process.env[name];
+	if (!value) {
+		throw new Error(`Missing required environment variable: ${name}`);
+	}
+	return value;
+};
+
 const langfuse = new Langfuse({
-	secretKey: process.env.LANGFUSE_SECRET_KEY,
-	publicKey: process.env.LANGFUSE_PUBLIC_KEY,
+	secretKey: getRequiredEnvVar("LANGFUSE_SECRET_KEY"),
+	publicKey: getRequiredEnvVar("LANGFUSE_PUBLIC_KEY"),
 	baseUrl: process.env.LANGFUSE_BASE_URL,
 });
As per coding guidelines, "Validate inputs early and throw errors with actionable messages — fail fast."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/studio.giselles.ai/lib/trace.ts` around lines 4 - 8, Validate the
Langfuse configuration before constructing the Langfuse instance: check
process.env.LANGFUSE_SECRET_KEY, process.env.LANGFUSE_PUBLIC_KEY, and
process.env.LANGFUSE_BASE_URL and throw a clear, actionable Error if any are
missing (e.g., mention which specific env var is absent and how to set it) so
the Langfuse constructor (Langfuse) never receives undefined values; update the
code around the Langfuse instantiation to perform this early validation and fail
fast with descriptive messages.


export async function traceGenerationForTeam(args: {
generation: CompletedGeneration | FailedGeneration;
inputMessages: ModelMessage[];
outputFileBlobs?: OutputFileBlob[];
export const trace = ({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Preserve traceGenerationForTeam export used by callbacks

Replacing traceGenerationForTeam with trace breaks existing callback wiring, because callers in apps/studio.giselles.ai/app/giselle.ts and apps/studio.giselles.ai/trigger/generate-content-job.ts still import and invoke traceGenerationForTeam. That missing export causes a hard compile/runtime-module error for generation callbacks, so telemetry code paths cannot execute.

Useful? React with 👍 / 👎.

traceId,
userId,
sessionId,
metadata,
}: {
traceId: string;
userId?: string;
sessionId?: string;
userId: string;
team: TeamForPlan;
providerMetadata?: ProviderMetadata;
requestId?: string;
}) {
const teamPlan = args.team.plan;
const planTag = `plan:${teamPlan}`;

await traceGeneration({
generation: args.generation,
outputFileBlobs: args.outputFileBlobs,
inputMessages: args.inputMessages,
userId: args.userId,
tags: [planTag],
metadata: {
generationId: args.generation.id,
teamPlan,
userId: args.userId,
subscriptionId: args.team.activeSubscriptionId ?? "",
customerId: args.team.activeCustomerId ?? "",
providerMetadata: args.providerMetadata,
requestId: args.requestId,
workspaceId: args.generation.context.origin.workspaceId,
},
sessionId: args.sessionId,
metadata?: Record<string, unknown>;
}) => {
return traceGeneration({
langfuse,
traceId,
userId,
sessionId,
metadata,
deploymentId: process.env.VERCEL_DEPLOYMENT_ID,
});
}
};
Comment on lines +10 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Missing tracing export 🐞 Bug ✓ Correctness

apps/studio.giselles.ai/lib/trace.ts no longer exports traceGenerationForTeam, but studio runtime
code still imports and calls it, causing a compile-time error. This blocks all code paths that trace
generationComplete/generationError and trigger jobs.
Agent Prompt
## Issue description
`traceGenerationForTeam` was removed/replaced by `trace`, but existing studio code still imports and calls `traceGenerationForTeam`, causing a build failure.

## Issue Context
This impacts generation telemetry in both request-driven flows (`app/giselle.ts`) and Trigger jobs (`trigger/generate-content-job.ts`).

## Fix Focus Areas
- apps/studio.giselles.ai/lib/trace.ts[1-29]
- apps/studio.giselles.ai/app/giselle.ts[19-281]
- apps/studio.giselles.ai/trigger/generate-content-job.ts[1-103]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +10 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== References to removed/old API =="
rg -n -C2 '\btraceGenerationForTeam\b' --type ts --type tsx

echo
echo "== Exports from trace helper modules =="
fd 'trace\.ts$' | while read -r file; do
  echo "-- $file"
  rg -n 'export\s+(const|function|async function)\s+(trace|traceGenerationForTeam)\b' "$file" || true
done

Repository: giselles-ai/giselle

Length of output: 143


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== References to traceGenerationForTeam =="
rg -n -C2 'traceGenerationForTeam' --type ts || echo "No matches found"

echo
echo "== Checking trace.ts file =="
fd -e ts 'trace\.ts$' -x cat -n {}

echo
echo "== Checking generate-content-job.ts =="
fd -e ts 'generate-content-job\.ts$' -x cat -n {}

Repository: giselles-ai/giselle

Length of output: 7926


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Looking for traceGenerationForTeam definition/export =="
rg -n 'export.*traceGenerationForTeam|function traceGenerationForTeam|const traceGenerationForTeam' --type ts -A 3

echo
echo "== Full contents of trace.ts =="
cat apps/studio.giselles.ai/lib/trace.ts

echo
echo "== Search in repo for traceGenerationForTeam definition =="
rg -n 'traceGenerationForTeam\s*[=:({]' --type ts | head -20

Repository: giselles-ai/giselle

Length of output: 121


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Searching entire codebase for traceGenerationForTeam =="
rg 'traceGenerationForTeam' --type ts -l

echo
echo "== Check if trace.ts is the file under review =="
ls -la apps/studio.giselles.ai/lib/trace.ts

Repository: giselles-ai/giselle

Length of output: 351


Critical breaking API change: 6 active callsites still reference removed traceGenerationForTeam export.

The trace() function replaces traceGenerationForTeam(), but 2 files still import and call the old API:

  • apps/studio.giselles.ai/trigger/generate-content-job.ts (lines 66, 86)
  • apps/studio.giselles.ai/app/giselle.ts (lines 228, 244, 261, 276)

These callsites must be migrated to use the new trace() export to prevent compilation and runtime failures.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/studio.giselles.ai/lib/trace.ts` around lines 10 - 29, Several callsites
still call the removed export traceGenerationForTeam; replace those imports and
calls to use the new trace function and its parameter shape. Update any import
that references traceGenerationForTeam to import trace instead, and adjust
call-sites to pass an object with traceId, optional userId, sessionId, and
metadata (instead of the old team-based signature), then remove any now-unused
team-related args; make sure the invoked function is trace(...) (not
traceGenerationForTeam) and that you pass deploymentId via the environment as
the trace implementation expects.

Loading