-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move aws-markerplace and copilotkit routes to App router
- Loading branch information
Showing
5 changed files
with
45 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { NextRequest } from "next/server"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
// In App Router, we need to parse the request body manually | ||
const body = await request.json(); | ||
|
||
const token = body["x-amzn-marketplace-token"]; | ||
const offerType = body["x-amzn-marketplace-offer-type"]; | ||
|
||
// Base64 encode the token | ||
const base64EncodedToken = encodeURIComponent(btoa(token)); | ||
|
||
// In App Router, we use the redirect function for redirects | ||
return redirect(`/signin?amt=${base64EncodedToken}`); | ||
} catch (error) { | ||
console.error("Error processing request:", error); | ||
return new Response("Bad Request", { status: 400 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { | ||
CopilotRuntime, | ||
OpenAIAdapter, | ||
copilotRuntimeNextJSAppRouterEndpoint, | ||
} from "@copilotkit/runtime"; | ||
import OpenAI from "openai"; | ||
import { NextRequest } from "next/server"; | ||
|
||
const openai = new OpenAI({ | ||
organization: process.env.OPEN_AI_ORGANIZATION_ID, | ||
apiKey: process.env.OPEN_AI_API_KEY, | ||
}); | ||
const serviceAdapter = new OpenAIAdapter({ openai }); | ||
const runtime = new CopilotRuntime(); | ||
|
||
export const POST = async (req: NextRequest) => { | ||
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({ | ||
runtime, | ||
serviceAdapter, | ||
endpoint: "/api/copilotkit", | ||
}); | ||
|
||
return handleRequest(req); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.