Skip to content

Commit

Permalink
update to use standard response object
Browse files Browse the repository at this point in the history
  • Loading branch information
roodboi committed Nov 9, 2023
1 parent eaf539b commit ec07027
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-turkeys-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-assistants": patch
---

Dont use NextResponse
25 changes: 21 additions & 4 deletions packages/next-assistants/src/lib/oai.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { NextResponse } from "next/server"
import OpenAI from "openai"
import { ThreadCreateParams, Threads } from "openai/resources/beta/threads/threads"

Expand Down Expand Up @@ -278,7 +277,15 @@ export function createAssistantRoutes({ debug = false }: { debug?: boolean } = {
const handler = getRouteHandler(object, action, req.method)

if (!handler) {
return NextResponse.json({ error: "Not Found" }, { status: 404 })
return new Response(
JSON.stringify({
error: "Not found"
}),
{
headers: { "Content-Type": "application/json" },
status: 404
}
)
}

try {
Expand All @@ -288,11 +295,21 @@ export function createAssistantRoutes({ debug = false }: { debug?: boolean } = {

const result = await handler(args)
debug && console.log("Request successful:", { object, action, method: req.method })
return NextResponse.json(result, { status: 200 })
return new Response(
JSON.stringify({
result
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
)
} catch (e) {
debug &&
console.error("Error handling request:", e.message, { object, action, method: req.method })
return NextResponse.json({ error: e.message }, { status: 500 })
return new Response(
JSON.stringify({
error: e.message
}),
{ status: 500, headers: { "Content-Type": "application/json" } }
)
}
}
}
2 changes: 1 addition & 1 deletion packages/next-assistants/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default defineConfig(options => {
minify: true,
target: "es2020",
format: ["cjs", "esm"],
external: ["openai", "react", "react-dom", "next", "next/server"]
external: ["openai", "react", "react-dom", "next"]
}
})

0 comments on commit ec07027

Please sign in to comment.