Skip to content

Commit 8bc8965

Browse files
committed
Merge branch 'development' into staging
2 parents b8ca5dd + e40d72f commit 8bc8965

149 files changed

Lines changed: 4955 additions & 5446 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/.env.selfhost.template

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,40 @@
55
# The public-facing URL of your client application.
66
# [BUILD-TIME & RUNTIME] Crucial for OAuth redirects and server-side requests.
77
APP_BASE_URL=http://localhost:3000
8+
NEXT_PUBLIC_APP_BASE_URL=http://localhost:3000
89

910
# The URL where the backend server will be accessible from the user's browser
1011
# [BUILD-TIME & RUNTIME] Used by the client to make API calls.
1112
NEXT_PUBLIC_APP_SERVER_URL=http://localhost:5000
1213

1314
# The internal URL for the backend server, used for server-to-server communication inside Docker.
14-
# [RUNTIME] Used by the client's Next.js server to talk to the backend server.
15+
# [BUILD-TIME & RUNTIME] Used by the client's Next.js server to talk to the backend server.
1516
INTERNAL_APP_SERVER_URL=http://server:80
1617

1718
# The internal URL for the client container, used for server-side self-requests
18-
# [RUNTIME] Used for OAuth callbacks within the Docker network.
19+
# [BUILD-TIME & RUNTIME] Used for OAuth callbacks within the Docker network.
1920
INTERNAL_CLIENT_URL=http://client:3000
2021

2122
# The mode to run the application in
2223
# [BUILD-TIME & RUNTIME] Switches between Auth0 and self-host auth mode.
2324
NEXT_PUBLIC_ENVIRONMENT=selfhost
2425

25-
# [BUILD-TIME & RUNTIME] A long, random, secret string. It must match SELF_HOST_AUTH_SECRET in server/.env.selfhost
26+
# [BUILD-TIME & RUNTIME] A long, random, secret string. It must match SELF_HOST_AUTH_SECRET in server/.env.selfhost.template
2627
SELF_HOST_AUTH_TOKEN=<generate_a_strong_secret_here>
2728

2829
# --- Server (Backend) Build-Time Variables ---
2930
# [BUILD-TIME] Set OPENAI_API_KEY to "ollama" to install Ollama in the server container.
3031
# Otherwise, provide your key for a remote service.
3132
OPENAI_API_KEY=ollama
32-
# [BUILD-TIME] The model to pull if Ollama is being installed.
33+
# [BUILD-TIME] The model to pull if Ollama is being installed. This should match the model in the server's Modelfile.
3334
OPENAI_MODEL_NAME=qwen3:4b
3435

36+
# --- Gemini API Key (for Server - Memory MCP & optional LiteLLM) ---
37+
# [RUNTIME] Required for memory embeddings and can be used for chat via LiteLLM.
38+
GEMINI_API_KEY=<your-gemini-api-key>
39+
3540
# --- MongoDB Credentials (for Server) ---
36-
MONGO_USER=sentient
41+
MONGO_USER=test
3742
MONGO_PASS=<generate_a_strong_password_for_mongo>
3843

3944
# --- PostgreSQL Credentials (for Server - Memory MCP) ---
@@ -42,4 +47,10 @@ POSTGRES_PASS=<generate_a_strong_password_for_postgres>
4247
POSTGRES_DB=sentient_memory_db
4348

4449
# --- Redis Password (for Server - Celery) ---
45-
REDIS_PASSWORD=<generate_a_strong_password_for_redis>
50+
REDIS_PASSWORD=<generate_a_strong_password_for_redis>
51+
52+
# --- WhatsApp (WAHA) Credentials (for WAHA Service) ---
53+
# These are used by the WAHA container for WhatsApp integration.
54+
WAHA_API_KEY=admin
55+
WAHA_DASHBOARD_USERNAME=admin
56+
WAHA_DASHBOARD_PASSWORD=admin

src/client/.env.selfhost.template

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,28 @@ NEXT_PUBLIC_ENVIRONMENT=selfhost
88
NEXT_PUBLIC_APP_SERVER_URL=http://localhost:5000
99

1010
# The internal URL for the backend server, used for server-to-server communication inside Docker.
11-
INTERNAL_APP_SERVER_URL=http://server:80
12-
13-
# The internal URL for this client, used for server-side self-requests within Docker.
14-
INTERNAL_CLIENT_URL=http://client:3000
11+
# This is passed at build time and used by the Next.js server part of the client.
12+
INTERNAL_APP_SERVER_URL=http://server:80 # Must match the root .env
1513

1614
# The public-facing base URL of the client application.
1715
APP_BASE_URL=http://localhost:3000
16+
NEXT_PUBLIC_APP_BASE_URL=http://localhost:3000
1817

1918
# The static token for authenticating with the backend.
2019
# This MUST match the `SELF_HOST_AUTH_SECRET` in the server's .env.selfhost file.
21-
SELF_HOST_AUTH_TOKEN=<use_the_same_strong_secret_as_in_the_root_env>
20+
SELF_HOST_AUTH_TOKEN=<use_the_same_strong_secret_as_in_src/.env>
2221

2322
# --- Database (for Server Actions) ---
2423
# This is the internal URI for the MongoDB service within Docker.
2524
# It MUST include the credentials defined in the root .env file.
26-
MONGO_URI=mongodb://<user_from_root_env>:<pass_from_root_env>@mongodb:27017/
27-
MONGO_DB_NAME=sentient_selfhost_db
25+
MONGO_URI=mongodb://test:<pass_from_src/.env>@mongodb:27017/
26+
MONGO_DB_NAME=development
2827

2928
# Auth0 variables are not used in selfhost mode, but are kept here
3029
# to avoid breaking any code that might reference them before a check.
3130
# The build process requires them to be present in some form.
3231
AUTH0_SECRET=""
33-
AUTH0_BASE_URL="http://localhost:3000"
32+
APP_BASE_URL="http://localhost:3000"
3433
AUTH0_ISSUER_BASE_URL=""
3534
AUTH0_CLIENT_ID=""
3635
AUTH0_CLIENT_SECRET=""
@@ -41,7 +40,8 @@ AUTH0_SCOPE=""
4140
# If you want to enable product analytics, provide your PostHog project key.
4241
NEXT_PUBLIC_POSTHOG_KEY=
4342
# If using a self-hosted PostHog instance, provide the host URL. Otherwise, leave it empty to default to PostHog's US cloud.
44-
NEXT_PUBLIC_POSTHOG_HOST=
43+
NEXT_PUBLIC_POSTHOG_HOST= # e.g. https://us.i.posthog.com
44+
4545
# --- PWA Push Notifications (Optional) ---
4646
# Generate VAPID keys using `npx web-push generate-vapid-keys` and add the public key here.
4747
# The private key is also needed here for Next.js Server Actions.

src/client/.env.template

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@
33
# For self-hosting, set NEXT_PUBLIC_ENVIRONMENT to selfhost and provide a secure token.
44
NEXT_PUBLIC_ENVIRONMENT="AUTH0" # Can be "AUTH0" or "selfhost"
55
SELF_HOST_AUTH_TOKEN="" # Must match SELF_HOST_AUTH_SECRET on the server if using selfhost mode
6+
APP_BASE_URL="http://localhost:3000" # The base URL of your Next.js app, where it's running
7+
NEXT_PUBLIC_APP_BASE_URL="http://localhost:3000" # The base URL of your Next.js app, where it's running
8+
NEXT_PUBLIC_APP_SERVER_URL="http://localhost:5000"
9+
NEXT_PUBLIC_AUTH0_NAMESPACE="https://existence.sentient/auth0"
610

7-
NEXT_PUBLIC_APP_SERVER_URL=
11+
# URL for the landing page/dashboard for billing and account management
12+
NEXT_PUBLIC_LANDING_PAGE_URL="http://localhost:3002"
13+
14+
# --- Auth0 ---
815
AUTH0_SECRET=
9-
APP_BASE_URL="http://localhost:3000"
1016
AUTH0_ISSUER_BASE_URL="" # Your Auth0 domain with protocol, e.g. "https://YOUR_TENANT.us.auth0.com"
1117
AUTH0_CLIENT_ID=
1218
AUTH0_DOMAIN=
1319
AUTH0_CLIENT_SECRET=
1420
AUTH0_AUDIENCE=
15-
AUTH0_SCOPE='openid profile email offline_access read:profile write:profile read:tasks write:tasks read:notifications read:config write:config admin:user_metadata read:contacts write:contacts'
21+
AUTH0_SCOPE="openid profile email offline_access read:chat write:chat read:profile write:profile manage:google_auth read:memory write:memory read:tasks write:tasks read:notifications write:notifications read:config write:config admin:user_metadata read:journal write:journal read:contacts write:contacts"
1622

17-
# --- Database (for Server Actions) ---
18-
# The full connection string for your MongoDB Atlas cluster.
19-
MONGO_URI=
20-
MONGO_DB_NAME=
23+
# --- Database ---
24+
# IMPORTANT: If your password contains special characters like '@', ':', '/', or '+', you MUST URL-encode them.
25+
# Example: 'my@password' should become 'my%40password'.
26+
MONGO_URI=mongodb://localhost:27017/
27+
MONGO_DB_NAME=development
2128

2229
# --- Analytics (Optional) ---
2330
# If you want to enable product analytics, provide your PostHog project key.
2431
NEXT_PUBLIC_POSTHOG_KEY=
2532
# If using a self-hosted PostHog instance, provide the host URL. Otherwise, leave it empty to default to PostHog's US cloud.
2633
NEXT_PUBLIC_POSTHOG_HOST=
34+
2735
# --- PWA Push Notifications (Optional) ---
28-
# Generate VAPID keys using `npx web-push generate-vapid-keys`.
36+
# Generate VAPID keys using `npx web-push generate-vapid-keys` and add the public key here.
37+
# This MUST match the public key derived from VAPID_PRIVATE_KEY in the server's .env.
2938
NEXT_PUBLIC_VAPID_PUBLIC_KEY=
3039
VAPID_PRIVATE_KEY=
3140
VAPID_ADMIN_EMAIL=mailto:your-email@example.com

src/client/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ ENV NODE_ENV=production
99

1010
# ---- MODIFIED SECTION ----
1111
# Declare all build-time arguments that your application needs.
12-
# Anything prefixed with NEXT_PUBLIC_ is needed for the client-side bundle.
13-
# Others are needed for server-side logic during the build (if any).
1412
ARG NEXT_PUBLIC_APP_SERVER_URL
1513
ARG AUTH0_SECRET
1614
ARG INTERNAL_APP_SERVER_URL
@@ -29,6 +27,8 @@ ARG VAPID_PRIVATE_KEY
2927
ARG VAPID_ADMIN_EMAIL
3028
ARG NEXT_PUBLIC_POSTHOG_KEY
3129
ARG NEXT_PUBLIC_POSTHOG_HOST
30+
ARG NEXT_PUBLIC_AUTH0_NAMESPACE
31+
ARG NEXT_PUBLIC_LANDING_PAGE_URL
3232
ARG NEXT_PUBLIC_VAPID_PUBLIC_KEY
3333

3434
# Set them as environment variables for the build process
@@ -50,6 +50,8 @@ ENV MONGO_URI=$MONGO_URI
5050
ENV MONGO_DB_NAME=$MONGO_DB_NAME
5151
ENV NEXT_PUBLIC_POSTHOG_KEY=$NEXT_PUBLIC_POSTHOG_KEY
5252
ENV NEXT_PUBLIC_POSTHOG_HOST=$NEXT_PUBLIC_POSTHOG_HOST
53+
ENV NEXT_PUBLIC_AUTH0_NAMESPACE=$NEXT_PUBLIC_AUTH0_NAMESPACE
54+
ENV NEXT_PUBLIC_LANDING_PAGE_URL=$NEXT_PUBLIC_LANDING_PAGE_URL
5355
ENV NEXT_PUBLIC_VAPID_PUBLIC_KEY=$NEXT_PUBLIC_VAPID_PUBLIC_KEY
5456
# --------------------------
5557

@@ -61,7 +63,6 @@ RUN npm ci
6163
COPY . .
6264

6365
# Build the Next.js application for production
64-
# This command will now have access to all the ENV vars
6566
RUN npm run build
6667

6768

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { NextResponse } from "next/server"
2+
import { auth0 } from "@lib/auth0"
3+
4+
// This route is only for Auth0 environments
5+
export async function GET(request) {
6+
if (process.env.NEXT_PUBLIC_ENVIRONMENT === "selfhost") {
7+
return NextResponse.json({
8+
status: "ok",
9+
message: "Self-host mode, no refresh needed."
10+
})
11+
}
12+
13+
const res = new NextResponse()
14+
15+
try {
16+
const session = await auth0.getSession(request, res)
17+
if (!session) {
18+
return NextResponse.json(
19+
{ error: "No session found" },
20+
{ status: 401 }
21+
)
22+
}
23+
24+
// Force a token refresh to get new claims (like roles)
25+
await auth0.getAccessToken(request, res, {
26+
refresh: true
27+
})
28+
29+
// The new session cookie is now on the `res` object.
30+
// Return a success response with the new headers.
31+
return NextResponse.json(
32+
{ status: "ok" },
33+
{ status: 200, headers: res.headers }
34+
)
35+
} catch (error) {
36+
console.error("Error refreshing session in main app:", error.message)
37+
return NextResponse.json(
38+
{ error: "Failed to refresh session" },
39+
{ status: 500 }
40+
)
41+
}
42+
}

src/client/app/api/chat/history/route.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ export const GET = withAuth(async function GET(request, { authHeader }) {
2020
try {
2121
const response = await fetch(backendUrl.toString(), {
2222
method: "GET",
23-
headers: { "Content-Type": "application/json", ...authHeader }
23+
headers: { "Content-Type": "application/json", ...authHeader },
24+
// Prevent Next.js server-side caching of this fetch
25+
cache: "no-store"
2426
})
2527

2628
const data = await response.json()
2729
if (!response.ok) {
2830
throw new Error(data.detail || "Failed to fetch chat history")
2931
}
30-
return NextResponse.json(data)
32+
// Add cache-control headers to prevent browser caching of history
33+
return NextResponse.json(data, {
34+
headers: {
35+
"Cache-Control": "no-store, max-age=0"
36+
}
37+
})
3138
} catch (error) {
3239
console.error("API Error in /chat/history:", error)
3340
return NextResponse.json({ error: error.message }, { status: 500 })

src/client/app/api/chat/message/route.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ export const POST = withAuth(async function POST(request, { authHeader }) {
3636
})
3737

3838
if (!backendResponse.ok) {
39-
const errorText = await backendResponse.text()
40-
let errorMessage
39+
const errorText = await backendResponse
40+
.text()
41+
.catch(() => "Unknown backend error")
42+
let errorJson = {}
4143
try {
42-
const errorJson = JSON.parse(errorText)
43-
errorMessage =
44-
errorJson.detail ||
45-
errorJson.message ||
46-
"Backend chat endpoint failed"
44+
errorJson = JSON.parse(errorText)
4745
} catch (e) {
48-
errorMessage =
49-
errorText ||
50-
`Backend chat endpoint failed with status ${backendResponse.status}`
46+
// Not a JSON error, use the raw text
5147
}
52-
throw new Error(errorMessage)
48+
// Return the error from the backend with its original status code
49+
return NextResponse.json(
50+
{ detail: errorJson.detail || errorText },
51+
{ status: backendResponse.status }
52+
)
5353
}
5454

5555
// Return the streaming response directly to the client
@@ -67,7 +67,7 @@ export const POST = withAuth(async function POST(request, { authHeader }) {
6767
} catch (error) {
6868
console.error("API Error in /chat/message:", error)
6969
return NextResponse.json(
70-
{ message: "Internal Server Error", error: error.message },
70+
{ detail: "Internal Server Error", error: error.message },
7171
{ status: 500 }
7272
)
7373
}

src/client/app/api/files/upload/route.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ export const POST = withAuth(async function POST(request, { authHeader }) {
2525
const data = await backendResponse.json()
2626

2727
if (!backendResponse.ok) {
28-
throw new Error(data.detail || "Failed to upload file")
28+
return NextResponse.json(
29+
{ error: data.detail || "Failed to upload file" },
30+
{ status: backendResponse.status }
31+
)
2932
}
3033

3134
return NextResponse.json(data)
3235
} catch (error) {
3336
console.error("API Error in /files/upload:", error)
3437
return NextResponse.json(
35-
{ message: "Internal Server Error", error: error.message },
38+
{ error: "Internal Server Error", details: error.message },
3639
{ status: 500 }
3740
)
3841
}

src/client/app/api/integrations/connected/route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const GET = withAuth(async function GET(request, { authHeader }) {
1212
// This reuses the same backend endpoint but we will filter on the client
1313
const response = await fetch(`${appServerUrl}/integrations/sources`, {
1414
method: "GET",
15-
headers: { "Content-Type": "application/json", ...authHeader }
15+
headers: { "Content-Type": "application/json", ...authHeader },
16+
cache: "no-store" // Prevent Next.js from caching this server-side fetch
1617
})
1718

1819
const data = await response.json()

src/client/app/api/integrations/gcalendar/events/route.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)