first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { geminiGenerate } from "@/lib/gemini";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* AI assistant. The UI sends a user prompt plus optional message context
|
||||
* (e.g. a copied message to summarize / draft a reply to). The Gemini key
|
||||
* never leaves the server.
|
||||
*/
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const prompt: string = (body.prompt ?? "").toString().trim();
|
||||
const context: string | undefined = body.context ? String(body.context) : undefined;
|
||||
|
||||
if (!prompt && !context) {
|
||||
return NextResponse.json({ ok: false, error: "Nothing to ask." }, { status: 400 });
|
||||
}
|
||||
|
||||
const parts: string[] = [];
|
||||
if (context) parts.push(`Here is a chat message for context:\n"""\n${context}\n"""`);
|
||||
parts.push(prompt || "Summarize the message above.");
|
||||
|
||||
const result = await geminiGenerate(parts.join("\n\n"), {
|
||||
system:
|
||||
"You are a concise, helpful assistant embedded in a team-messaging app. " +
|
||||
"Answer directly in a professional but friendly tone. When drafting a reply, write it in first person, ready to send. Keep responses tight.",
|
||||
temperature: 0.5,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ ok: false, error: result.error, retryable: result.retryable }, { status: result.status || 502 });
|
||||
}
|
||||
return NextResponse.json({ ok: true, text: result.text });
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// GET /api/bff/bootstrap — the initial client payload (me, workspace, users, channels).
|
||||
export async function GET() {
|
||||
return NextResponse.json(await getBackend().bootstrap());
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function POST(req: NextRequest, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const channel = await getBackend().addMember(id, String(body.userId ?? ""));
|
||||
if (!channel) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ channel });
|
||||
}
|
||||
|
||||
export async function DELETE(req: NextRequest, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const channel = await getBackend().removeMember(id, String(body.userId ?? ""));
|
||||
if (!channel) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ channel });
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string; messageId: string }> },
|
||||
) {
|
||||
const { id, messageId } = await params;
|
||||
const message = await getBackend().pin(id, messageId);
|
||||
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ message });
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string; messageId: string }> },
|
||||
) {
|
||||
const { id, messageId } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const message = await getBackend().react(id, messageId, String(body.emoji ?? "👍"));
|
||||
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ message });
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type Params = { params: Promise<{ id: string; messageId: string }> };
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: Params) {
|
||||
const { id, messageId } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const message = await getBackend().editMessage(id, messageId, String(body.body ?? ""));
|
||||
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ message });
|
||||
}
|
||||
|
||||
export async function DELETE(_req: NextRequest, { params }: Params) {
|
||||
const { id, messageId } = await params;
|
||||
const r = await getBackend().deleteMessage(id, messageId);
|
||||
return NextResponse.json(r);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string; messageId: string }> },
|
||||
) {
|
||||
const { id, messageId } = await params;
|
||||
const message = await getBackend().save(id, messageId);
|
||||
if (!message) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ message });
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_req: NextRequest, { params }: Params) {
|
||||
const { id } = await params;
|
||||
return NextResponse.json({ messages: await getBackend().channelMessages(id) });
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const message = await getBackend().send(id, String(body.body ?? ""), {
|
||||
parentId: body.parentId,
|
||||
scheduledFor: body.scheduledFor,
|
||||
attachments: body.attachments,
|
||||
threadRootId: body.threadRootId,
|
||||
});
|
||||
return NextResponse.json({ message }, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const channel = await getBackend().markRead(id);
|
||||
return NextResponse.json({ channel });
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string; parentId: string }> },
|
||||
) {
|
||||
const { id, parentId } = await params;
|
||||
return NextResponse.json(await getBackend().thread(id, parentId));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ channels: await getBackend().listChannels() });
|
||||
}
|
||||
|
||||
// POST /api/bff/channels — create a channel or DM
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const channel = await getBackend().createChannel({
|
||||
name: String(body.name ?? "new-channel"),
|
||||
kind: body.kind,
|
||||
topic: body.topic,
|
||||
memberIds: body.memberIds,
|
||||
});
|
||||
return NextResponse.json({ channel }, { status: 201 });
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
import type { InboxState } from "@lynkd/messaging-inbox-sdk";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function PATCH(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const item = await getBackend().patchInbox(id, (body.state as InboxState) ?? "DONE");
|
||||
if (!item) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ item });
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
import type { InboxState } from "@lynkd/messaging-inbox-sdk";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const state = (req.nextUrl.searchParams.get("state") as InboxState | null) ?? undefined;
|
||||
return NextResponse.json({ items: await getBackend().listInbox(state) });
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function PATCH(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const user = await getBackend().updateMe({
|
||||
name: body.name,
|
||||
title: body.title,
|
||||
avatarColor: body.avatarColor,
|
||||
avatarUrl: body.avatarUrl,
|
||||
presence: body.presence,
|
||||
});
|
||||
return NextResponse.json({ user });
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function PATCH(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const user = await getBackend().setStatus(
|
||||
body.statusText ?? undefined,
|
||||
body.statusEmoji ?? undefined,
|
||||
body.clearAt ?? undefined,
|
||||
);
|
||||
return NextResponse.json({ user });
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ notifications: await getBackend().notifications() });
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ messages: await getBackend().savedMessages() });
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const q = req.nextUrl.searchParams.get("q") ?? "";
|
||||
return NextResponse.json({ results: await getBackend().search(q) });
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ agents: await getBackend().availability() });
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const ticket = await getBackend().replyTicket(id, String(body.body ?? ""));
|
||||
if (!ticket) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ ticket });
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
import type { TicketState } from "@lynkd/messaging-inbox-sdk";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_req: NextRequest, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const ticket = await getBackend().getTicket(id);
|
||||
if (!ticket) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ ticket });
|
||||
}
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const ticket = await getBackend().patchTicket(id, (body.state as TicketState) ?? "OPEN");
|
||||
if (!ticket) return NextResponse.json({ error: "not found" }, { status: 404 });
|
||||
return NextResponse.json({ ticket });
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const scope = req.nextUrl.searchParams.get("scope") ?? undefined;
|
||||
return NextResponse.json({ tickets: await getBackend().listTickets(scope ?? undefined) });
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getBackend } from "@/lib/backend";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({ messages: await getBackend().threadParents() });
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { geminiGenerate } from "@/lib/gemini";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* Translate arbitrary text to a target language. Used for per-message
|
||||
* translation and composer "translate before send". Server-side Gemini only.
|
||||
*/
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const text: string = (body.text ?? "").toString();
|
||||
const targetLang: string = (body.targetLang ?? "").toString().trim();
|
||||
|
||||
if (!text.trim()) return NextResponse.json({ ok: false, error: "Nothing to translate." }, { status: 400 });
|
||||
if (!targetLang) return NextResponse.json({ ok: false, error: "No target language." }, { status: 400 });
|
||||
|
||||
const result = await geminiGenerate(
|
||||
`Translate the following text into ${targetLang}. Preserve markdown, emoji, @mentions and #channel references exactly. ` +
|
||||
`Return ONLY the translated text with no quotes, notes, or preamble.\n\n${text}`,
|
||||
{
|
||||
system: "You are a professional translator. Output only the translation.",
|
||||
temperature: 0.2,
|
||||
},
|
||||
);
|
||||
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ ok: false, error: result.error, retryable: result.retryable }, { status: result.status || 502 });
|
||||
}
|
||||
return NextResponse.json({ ok: true, text: result.text });
|
||||
}
|
||||
Reference in New Issue
Block a user