Skip to content

Commit 91494e2

Browse files
committed
feat (organizer): adding organizer and feedback mechanism flow
2 parents e368ff9 + 7ca25dd commit 91494e2

File tree

35 files changed

+2923
-739
lines changed

35 files changed

+2923
-739
lines changed

dev/null

Whitespace-only changes.

src/.env.selfhost.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Root environment variables for docker-compose.yml (self-hosting)
22
# Copy this file to .env in the same directory (src/.env) and fill in the values.
33

4+
# The public-facing URL of your client application.
5+
# This is crucial for OAuth redirects to work correctly.
6+
APP_BASE_URL=http://localhost:3000
7+
48
# --- Client Build-Time Variables ---
59
# The URL where the backend server will be accessible from the user's browser
610
NEXT_PUBLIC_APP_SERVER_URL=http://localhost:5000
711

12+
# The internal URL for the backend server, used for server-to-server communication inside Docker.
13+
INTERNAL_APP_SERVER_URL=http://server:80
14+
15+
# The internal URL for the client container, used for server-side self-requests
16+
INTERNAL_CLIENT_URL=http://client:3000
17+
818
# The mode to run the application in
919
NEXT_PUBLIC_ENVIRONMENT=selfhost
1020

src/client/.env.selfhost.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ NEXT_PUBLIC_APP_SERVER_URL=http://localhost:5000
1010
# The internal URL for the backend server, used for server-to-server communication inside Docker.
1111
INTERNAL_APP_SERVER_URL=http://server:80
1212

13+
# The internal URL for this client, used for server-side self-requests within Docker.
14+
INTERNAL_CLIENT_URL=http://client:3000
15+
16+
# The public-facing base URL of the client application.
17+
APP_BASE_URL=http://localhost:3000
18+
1319
# The static token for authenticating with the backend.
1420
# This MUST match the `SELF_HOST_AUTH_SECRET` in the server's .env.selfhost file.
1521
SELF_HOST_AUTH_TOKEN=<use_the_same_strong_secret_as_in_the_root_env>

src/client/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

src/client/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ WORKDIR /app
1010
# Others are needed for server-side logic during the build (if any).
1111
ARG NEXT_PUBLIC_APP_SERVER_URL
1212
ARG AUTH0_SECRET
13+
ARG INTERNAL_APP_SERVER_URL
1314
ARG NEXT_PUBLIC_ENVIRONMENT
1415
ARG SELF_HOST_AUTH_TOKEN
1516
ARG APP_BASE_URL
@@ -23,6 +24,7 @@ ARG AUTH0_SCOPE
2324
# Set them as environment variables for the build process
2425
ENV NEXT_PUBLIC_APP_SERVER_URL=$NEXT_PUBLIC_APP_SERVER_URL
2526
ENV AUTH0_SECRET=$AUTH0_SECRET
27+
ENV INTERNAL_APP_SERVER_URL=$INTERNAL_APP_SERVER_URL
2628
ENV NEXT_PUBLIC_ENVIRONMENT=$NEXT_PUBLIC_ENVIRONMENT
2729
ENV SELF_HOST_AUTH_TOKEN=$SELF_HOST_AUTH_TOKEN
2830
ENV APP_BASE_URL=$APP_BASE_URL

src/client/app/api/journal/route.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export const GET = withAuth(async function GET(request, { authHeader }) {
3737
)
3838
const data = await response.json()
3939
if (!response.ok)
40-
throw new Error(data.detail || "Failed to fetch blocks")
40+
throw new Error(
41+
data.detail || data.error || "Failed to fetch blocks"
42+
)
4143
return NextResponse.json(data)
4244
} catch (error) {
4345
return NextResponse.json({ error: error.message }, { status: 500 })
@@ -55,7 +57,9 @@ export const POST = withAuth(async function POST(request, { authHeader }) {
5557
})
5658
const data = await response.json()
5759
if (!response.ok)
58-
throw new Error(data.detail || "Failed to create block")
60+
throw new Error(
61+
data.detail || data.error || "Failed to create block"
62+
)
5963
return NextResponse.json(data)
6064
} catch (error) {
6165
return NextResponse.json({ error: error.message }, { status: 500 })
@@ -85,7 +89,9 @@ export const PUT = withAuth(async function PUT(request, { authHeader }) {
8589
)
8690
const data = await response.json()
8791
if (!response.ok)
88-
throw new Error(data.detail || "Failed to update block")
92+
throw new Error(
93+
data.detail || data.error || "Failed to update block"
94+
)
8995
return NextResponse.json(data)
9096
} catch (error) {
9197
return NextResponse.json({ error: error.message }, { status: 500 })

src/client/app/api/settings/integrations/connect/oauth/callback/route.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ export async function GET(request) {
88
const state = searchParams.get("state") // This will be 'gdrive', 'gcalendar', etc.
99
const error = searchParams.get("error")
1010

11-
const baseUrl = process.env.APP_BASE_URL
12-
if (!baseUrl) {
11+
const publicBaseUrl = process.env.APP_BASE_URL
12+
if (!publicBaseUrl) {
1313
console.error("APP_BASE_URL environment variable is not set.")
1414
return new Response("Server configuration error.", { status: 500 })
1515
}
1616

17+
// Determine the correct URL for server-side fetching.
18+
// In a docker-compose self-host setup, containers communicate via internal service names.
19+
// In all other environments (local dev, cloud), use the public URL.
20+
const isSelfHostDocker = process.env.NEXT_PUBLIC_ENVIRONMENT === "selfhost"
21+
const apiUrlForFetch = isSelfHostDocker
22+
? process.env.INTERNAL_CLIENT_URL
23+
: publicBaseUrl
24+
1725
// FIX: Use the public-facing APP_BASE_URL for redirection, not the internal request.url.
1826
// This ensures the browser is redirected to the correct, publicly accessible address.
19-
const integrationsUrl = new URL("/integrations", baseUrl)
27+
const integrationsUrl = new URL("/integrations", publicBaseUrl)
2028

2129
if (error) {
2230
// User denied access or an error occurred
@@ -41,7 +49,7 @@ export async function GET(request) {
4149
// The browser session (cookie) is automatically forwarded by Next.js server-side fetch,
4250
// which authenticates the user to our own API proxy.
4351
const apiResponse = await fetch(
44-
`${baseUrl}/api/settings/integrations/connect/oauth`,
52+
`${apiUrlForFetch}/api/settings/integrations/connect/oauth`,
4553
{
4654
method: "POST",
4755
headers: {
@@ -51,7 +59,7 @@ export async function GET(request) {
5159
body: JSON.stringify({
5260
service_name: state,
5361
code: code,
54-
redirect_uri: `${baseUrl}/api/settings/integrations/connect/oauth/callback`
62+
redirect_uri: `${publicBaseUrl}/api/settings/integrations/connect/oauth/callback`
5563
})
5664
}
5765
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { NextResponse } from "next/server"
2+
import { withAuth } from "@lib/api-utils"
3+
4+
const appServerUrl =
5+
process.env.NEXT_PUBLIC_ENVIRONMENT === "selfhost"
6+
? process.env.INTERNAL_APP_SERVER_URL
7+
: process.env.NEXT_PUBLIC_APP_SERVER_URL
8+
9+
export const POST = withAuth(async function POST(request, { authHeader }) {
10+
try {
11+
const body = await request.json() // { taskId, answers: [{ question_id, answer_text }] }
12+
const response = await fetch(
13+
`${appServerUrl}/agents/answer-clarifications`,
14+
{
15+
method: "POST",
16+
headers: { "Content-Type": "application/json", ...authHeader },
17+
body: JSON.stringify(body)
18+
}
19+
)
20+
21+
const data = await response.json()
22+
if (!response.ok) {
23+
throw new Error(data.detail || "Failed to submit answers")
24+
}
25+
return NextResponse.json(data)
26+
} catch (error) {
27+
console.error("API Error in /tasks/answer-clarifications:", error)
28+
return NextResponse.json({ error: error.message }, { status: 500 })
29+
}
30+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { NextResponse } from "next/server"
2+
import { withAuth } from "@lib/api-utils"
3+
4+
const appServerUrl =
5+
process.env.NEXT_PUBLIC_ENVIRONMENT === "selfhost"
6+
? process.env.INTERNAL_APP_SERVER_URL
7+
: process.env.NEXT_PUBLIC_APP_SERVER_URL
8+
9+
export const POST = withAuth(async function POST(request, { authHeader }) {
10+
try {
11+
const body = await request.json() // { taskId, answers: [{ question_id, answer_text }] }
12+
const response = await fetch(
13+
`${appServerUrl}/agents/answer-clarifications`,
14+
{
15+
method: "POST",
16+
headers: { "Content-Type": "application/json", ...authHeader },
17+
body: JSON.stringify(body)
18+
}
19+
)
20+
21+
const data = await response.json()
22+
if (!response.ok) {
23+
throw new Error(data.detail || "Failed to submit answers")
24+
}
25+
return NextResponse.json(data)
26+
} catch (error) {
27+
console.error("API Error in /tasks/clarify:", error)
28+
return NextResponse.json({ error: error.message }, { status: 500 })
29+
}
30+
})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { NextResponse } from "next/server"
2+
import { withAuth } from "@lib/api-utils"
3+
4+
const appServerUrl =
5+
process.env.NEXT_PUBLIC_ENVIRONMENT === "selfhost"
6+
? process.env.INTERNAL_APP_SERVER_URL
7+
: process.env.NEXT_PUBLIC_APP_SERVER_URL
8+
9+
export const POST = withAuth(async function POST(request, { authHeader }) {
10+
try {
11+
const body = await request.json() // { service_name, event_data }
12+
const response = await fetch(`${appServerUrl}/testing/inject-context`, {
13+
method: "POST",
14+
headers: { "Content-Type": "application/json", ...authHeader },
15+
body: JSON.stringify(body)
16+
})
17+
18+
const data = await response.json()
19+
if (!response.ok) {
20+
throw new Error(data.detail || "Failed to inject context event")
21+
}
22+
return NextResponse.json(data)
23+
} catch (error) {
24+
console.error("API Error in /testing/inject-context:", error)
25+
return NextResponse.json({ error: error.message }, { status: 500 })
26+
}
27+
})

0 commit comments

Comments
 (0)