@superinterface/server 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +2 -2
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/eslint/.cache_btwyo7 +1 -1
- package/.next/fallback-build-manifest.json +2 -2
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/api/api-keys/[apiKeyId]/route.js +1 -1
- package/.next/server/app/api/api-keys/[apiKeyId]/route.js.nft.json +1 -1
- package/.next/server/app/api/api-keys/route.js +1 -1
- package/.next/server/app/api/api-keys/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/[functionId]/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/[functionId]/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/functions/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/initial-messages/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/initial-messages/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/mcp-servers/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/[assistantId]/route.js +1 -1
- package/.next/server/app/api/assistants/[assistantId]/route.js.nft.json +1 -1
- package/.next/server/app/api/assistants/route.js +1 -1
- package/.next/server/app/api/assistants/route.js.nft.json +1 -1
- package/.next/server/app/api/files/[fileId]/contents/route.js +1 -1
- package/.next/server/app/api/files/[fileId]/contents/route.js.nft.json +1 -1
- package/.next/server/app/api/files/route.js +1 -1
- package/.next/server/app/api/files/route.js.nft.json +1 -1
- package/.next/server/app/api/messages/route.js +1 -1
- package/.next/server/app/api/messages/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/assistants/route.js +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/assistants/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/models/route.js +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/models/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/route.js +1 -1
- package/.next/server/app/api/providers/[modelProviderId]/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/route.js +1 -1
- package/.next/server/app/api/providers/route.js.nft.json +1 -1
- package/.next/server/app/api/tasks/[taskId]/route.js +1 -1
- package/.next/server/app/api/tasks/[taskId]/route.js.nft.json +1 -1
- package/.next/server/app/api/tasks/callback/route.js +1 -1
- package/.next/server/app/api/tasks/callback/route.js.nft.json +1 -1
- package/.next/server/app/api/tasks/route.js +1 -1
- package/.next/server/app/api/tasks/route.js.nft.json +1 -1
- package/.next/server/app/api/threads/runs/submit-client-tool-outputs/route.js +1 -1
- package/.next/server/app/api/threads/runs/submit-client-tool-outputs/route.js.nft.json +1 -1
- package/.next/server/app/api/workspaces/[workspaceId]/route.js +1 -1
- package/.next/server/app/api/workspaces/[workspaceId]/route.js.nft.json +1 -1
- package/.next/server/app/api/workspaces/route.js +1 -1
- package/.next/server/app/api/workspaces/route.js.nft.json +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__29635e8e._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__29635e8e._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__315f084a._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__315f084a._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__40ab45eb._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__40ab45eb._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__441cee00._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__441cee00._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__464a4377._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__464a4377._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__47b17fad._.js +38 -0
- package/.next/server/chunks/[root-of-the-server]__47b17fad._.js.map +1 -0
- package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__5abf1160._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__5abf1160._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__5d09614a._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__5d09614a._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__62d958e7._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__62d958e7._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__676affb1._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__676affb1._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__83461316._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__83461316._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__9a611d42._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__9a611d42._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__a878c913._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__a878c913._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__c1629392._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__c1629392._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__eb816e13._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__eb816e13._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__f6f61507._.js +38 -0
- package/.next/server/chunks/[root-of-the-server]__f6f61507._.js.map +1 -0
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js +1 -1
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js.map +1 -1
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js +1 -1
- package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js.map +1 -1
- package/.next/server/functions-config-manifest.json +1 -8
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/trace +1 -1
- package/dist/app/api/api-keys/[apiKeyId]/buildRoute.d.ts +52 -0
- package/dist/app/api/api-keys/[apiKeyId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/api-keys/[apiKeyId]/buildRoute.js +121 -0
- package/dist/app/api/api-keys/[apiKeyId]/route.d.ts +10 -21
- package/dist/app/api/api-keys/[apiKeyId]/route.d.ts.map +1 -1
- package/dist/app/api/api-keys/[apiKeyId]/route.js +6 -125
- package/dist/app/api/api-keys/buildRoute.d.ts +32 -0
- package/dist/app/api/api-keys/buildRoute.d.ts.map +1 -0
- package/dist/app/api/api-keys/buildRoute.js +104 -0
- package/dist/app/api/api-keys/builders.d.ts +31 -0
- package/dist/app/api/api-keys/builders.d.ts.map +1 -0
- package/dist/app/api/api-keys/builders.js +109 -0
- package/dist/app/api/api-keys/route.d.ts +5 -13
- package/dist/app/api/api-keys/route.d.ts.map +1 -1
- package/dist/app/api/api-keys/route.js +8 -108
- package/dist/app/api/assistants/[assistantId]/buildRoute.d.ts +120 -0
- package/dist/app/api/assistants/[assistantId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/buildRoute.js +226 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.d.ts +167 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.js +184 -0
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts +10 -21
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.js +6 -191
- package/dist/app/api/assistants/[assistantId]/functions/buildRoute.d.ts +114 -0
- package/dist/app/api/assistants/[assistantId]/functions/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/functions/buildRoute.js +117 -0
- package/dist/app/api/assistants/[assistantId]/functions/route.d.ts +7 -15
- package/dist/app/api/assistants/[assistantId]/functions/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/functions/route.js +5 -122
- package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.d.ts +40 -0
- package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.js +85 -0
- package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts +7 -15
- package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/initial-messages/route.js +5 -90
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.d.ts +89 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.js +167 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts +10 -21
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +6 -174
- package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.d.ts +62 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.js +115 -0
- package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts +7 -15
- package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/mcp-servers/route.js +5 -120
- package/dist/app/api/assistants/[assistantId]/route.d.ts +11 -22
- package/dist/app/api/assistants/[assistantId]/route.d.ts.map +1 -1
- package/dist/app/api/assistants/[assistantId]/route.js +6 -233
- package/dist/app/api/assistants/buildRoute.d.ts +121 -0
- package/dist/app/api/assistants/buildRoute.d.ts.map +1 -0
- package/dist/app/api/assistants/buildRoute.js +144 -0
- package/dist/app/api/assistants/route.d.ts +7 -13
- package/dist/app/api/assistants/route.d.ts.map +1 -1
- package/dist/app/api/assistants/route.js +6 -148
- package/dist/app/api/files/[fileId]/contents/buildRoute.d.ts +18 -0
- package/dist/app/api/files/[fileId]/contents/buildRoute.d.ts.map +1 -0
- package/dist/app/api/files/[fileId]/contents/buildRoute.js +81 -0
- package/dist/app/api/files/[fileId]/contents/route.d.ts +3 -13
- package/dist/app/api/files/[fileId]/contents/route.d.ts.map +1 -1
- package/dist/app/api/files/[fileId]/contents/route.js +4 -84
- package/dist/app/api/files/buildRoute.d.ts +14 -0
- package/dist/app/api/files/buildRoute.d.ts.map +1 -0
- package/dist/app/api/files/buildRoute.js +88 -0
- package/dist/app/api/files/route.d.ts +4 -10
- package/dist/app/api/files/route.d.ts.map +1 -1
- package/dist/app/api/files/route.js +4 -91
- package/dist/app/api/messages/buildRoute.d.ts +34 -0
- package/dist/app/api/messages/buildRoute.d.ts.map +1 -0
- package/dist/app/api/messages/buildRoute.js +607 -0
- package/dist/app/api/messages/lib/initialMessagesResponse.d.ts.map +1 -1
- package/dist/app/api/messages/lib/initialMessagesResponse.js +1 -1
- package/dist/app/api/messages/route.d.ts +10 -22
- package/dist/app/api/messages/route.d.ts.map +1 -1
- package/dist/app/api/messages/route.js +6 -612
- package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.d.ts +24 -0
- package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.js +43 -0
- package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts +4 -9
- package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts.map +1 -1
- package/dist/app/api/providers/[modelProviderId]/assistants/route.js +4 -46
- package/dist/app/api/providers/[modelProviderId]/buildRoute.d.ts +61 -0
- package/dist/app/api/providers/[modelProviderId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/[modelProviderId]/buildRoute.js +134 -0
- package/dist/app/api/providers/[modelProviderId]/models/buildRoute.d.ts +19 -0
- package/dist/app/api/providers/[modelProviderId]/models/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/[modelProviderId]/models/buildRoute.js +43 -0
- package/dist/app/api/providers/[modelProviderId]/models/route.d.ts +4 -9
- package/dist/app/api/providers/[modelProviderId]/models/route.d.ts.map +1 -1
- package/dist/app/api/providers/[modelProviderId]/models/route.js +4 -46
- package/dist/app/api/providers/[modelProviderId]/route.d.ts +10 -21
- package/dist/app/api/providers/[modelProviderId]/route.d.ts.map +1 -1
- package/dist/app/api/providers/[modelProviderId]/route.js +6 -141
- package/dist/app/api/providers/buildRoute.d.ts +38 -0
- package/dist/app/api/providers/buildRoute.d.ts.map +1 -0
- package/dist/app/api/providers/buildRoute.js +75 -0
- package/dist/app/api/providers/route.d.ts +5 -13
- package/dist/app/api/providers/route.d.ts.map +1 -1
- package/dist/app/api/providers/route.js +5 -80
- package/dist/app/api/tasks/[taskId]/buildRoute.d.ts +19 -0
- package/dist/app/api/tasks/[taskId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/tasks/[taskId]/buildRoute.js +125 -0
- package/dist/app/api/tasks/[taskId]/route.d.ts +7 -57
- package/dist/app/api/tasks/[taskId]/route.d.ts.map +1 -1
- package/dist/app/api/tasks/[taskId]/route.js +6 -144
- package/dist/app/api/tasks/buildRoute.d.ts +36 -0
- package/dist/app/api/tasks/buildRoute.d.ts.map +1 -0
- package/dist/app/api/tasks/buildRoute.js +85 -0
- package/dist/app/api/tasks/callback/buildRoute.d.ts +6 -0
- package/dist/app/api/tasks/callback/buildRoute.d.ts.map +1 -0
- package/dist/app/api/tasks/callback/buildRoute.js +244 -0
- package/dist/app/api/tasks/callback/route.d.ts +2 -1
- package/dist/app/api/tasks/callback/route.d.ts.map +1 -1
- package/dist/app/api/tasks/callback/route.js +4 -244
- package/dist/app/api/tasks/route.d.ts +5 -13
- package/dist/app/api/tasks/route.d.ts.map +1 -1
- package/dist/app/api/tasks/route.js +5 -90
- package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.d.ts +10 -0
- package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.d.ts.map +1 -0
- package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.js +36 -0
- package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts +2 -7
- package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts.map +1 -1
- package/dist/app/api/threads/runs/submit-client-tool-outputs/route.js +3 -37
- package/dist/app/api/workspaces/[workspaceId]/buildRoute.d.ts +16 -0
- package/dist/app/api/workspaces/[workspaceId]/buildRoute.d.ts.map +1 -0
- package/dist/app/api/workspaces/[workspaceId]/buildRoute.js +89 -0
- package/dist/app/api/workspaces/[workspaceId]/route.d.ts +5 -31
- package/dist/app/api/workspaces/[workspaceId]/route.d.ts.map +1 -1
- package/dist/app/api/workspaces/[workspaceId]/route.js +5 -89
- package/dist/app/api/workspaces/buildRoute.d.ts +42 -0
- package/dist/app/api/workspaces/buildRoute.d.ts.map +1 -0
- package/dist/app/api/workspaces/buildRoute.js +78 -0
- package/dist/app/api/workspaces/route.d.ts +7 -27
- package/dist/app/api/workspaces/route.d.ts.map +1 -1
- package/dist/app/api/workspaces/route.js +6 -82
- package/dist/lib/functions/functionSchema.d.ts +56 -56
- package/dist/lib/functions/handleFunction/getFunction.d.ts +4 -4
- package/dist/lib/mcpServers/mcpServerSchema.d.ts +20 -20
- package/dist/lib/prisma/index.d.ts +1 -9
- package/dist/lib/prisma/index.d.ts.map +1 -1
- package/dist/lib/prisma/index.js +10 -78
- package/package.json +4 -12
- package/.next/server/chunks/[root-of-the-server]__228bff78._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__228bff78._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__3307123c._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__3307123c._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__e7819e95._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__e7819e95._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js.map +0 -1
- package/.next/server/chunks/[root-of-the-server]__ff90af03._.js +0 -38
- package/.next/server/chunks/[root-of-the-server]__ff90af03._.js.map +0 -1
- /package/.next/static/{jt8inwg6nWaLQZ4qpiSJ- → iaWEclnh6aHcuw0CBnWpA}/_buildManifest.js +0 -0
- /package/.next/static/{jt8inwg6nWaLQZ4qpiSJ- → iaWEclnh6aHcuw0CBnWpA}/_clientMiddlewareManifest.json +0 -0
- /package/.next/static/{jt8inwg6nWaLQZ4qpiSJ- → iaWEclnh6aHcuw0CBnWpA}/_ssgManifest.js +0 -0
|
@@ -1,612 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import { NextResponse } from 'next/server';
|
|
13
|
-
import { LogRequestMethod, LogRequestRoute, LogLevel, } from '@prisma/client';
|
|
14
|
-
import { messagesResponse, createMessageResponse, } from '@superinterface/react/server';
|
|
15
|
-
import { enqueueJson } from '@superinterface/react/utils';
|
|
16
|
-
import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
|
|
17
|
-
import { z } from 'zod';
|
|
18
|
-
import { storageThreadId as getStorageThreadId } from '../../../lib/threads/storageThreadId';
|
|
19
|
-
import { assistantClientAdapter } from '../../../lib/assistants/assistantClientAdapter';
|
|
20
|
-
import { content as getContent } from '../../../lib/messages/content';
|
|
21
|
-
import { workspaceAccessWhere as getWorkspaceAccessWhere } from '../../../lib/apiKeys/workspaceAccessWhere';
|
|
22
|
-
import { initialMessagesResponse } from './lib/initialMessagesResponse';
|
|
23
|
-
import { createRunOpts } from '../../../lib/runs/createRunOpts';
|
|
24
|
-
import { handleToolCall } from '../../../lib/toolCalls/handleToolCall';
|
|
25
|
-
import { createThread } from '../../../lib/threads/createThread';
|
|
26
|
-
import { managedOpenaiThreadId } from '../../../lib/threads/managedOpenaiThreadId';
|
|
27
|
-
import { resolvePrisma } from '../../../lib/prisma';
|
|
28
|
-
import { createLog } from '../../../lib/logs/createLog';
|
|
29
|
-
import { serializeThread } from './lib/serializeThread';
|
|
30
|
-
import { getWorkspaceId } from './lib/getWorkspaceId';
|
|
31
|
-
import { validThreadId } from '../../../lib/threads/validThreadId';
|
|
32
|
-
import { isOpenaiAssistantsStorageProvider } from '../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
|
|
33
|
-
import { serializeMetadata } from '../../../lib/metadata/serializeMetadata';
|
|
34
|
-
import { isResponsesStorageProvider } from '../../../lib/storageProviders/isResponsesStorageProvider';
|
|
35
|
-
import { serializeError } from '../../../lib/errors/serializeError';
|
|
36
|
-
export const maxDuration = 800;
|
|
37
|
-
export const buildGET = ({ prisma: providedPrisma } = {}) => async (request) => {
|
|
38
|
-
var _a;
|
|
39
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
40
|
-
const paramsResult = z
|
|
41
|
-
.object({
|
|
42
|
-
publicApiKey: z.string().optional(),
|
|
43
|
-
assistantId: z.string().optional(),
|
|
44
|
-
threadId: z.string().optional(),
|
|
45
|
-
pageParam: z.string().optional(),
|
|
46
|
-
})
|
|
47
|
-
.parse(Object.fromEntries(request.nextUrl.searchParams.entries()));
|
|
48
|
-
const workspaceAccessWhere = await getWorkspaceAccessWhere({
|
|
49
|
-
publicApiKey: (_a = paramsResult.publicApiKey) !== null && _a !== void 0 ? _a : null,
|
|
50
|
-
prisma,
|
|
51
|
-
});
|
|
52
|
-
if (!workspaceAccessWhere) {
|
|
53
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
54
|
-
}
|
|
55
|
-
const assistantId = paramsResult.assistantId;
|
|
56
|
-
if (!assistantId) {
|
|
57
|
-
createLog({
|
|
58
|
-
log: {
|
|
59
|
-
requestMethod: LogRequestMethod.POST,
|
|
60
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
61
|
-
level: LogLevel.ERROR,
|
|
62
|
-
status: 400,
|
|
63
|
-
message: 'No assistantId found.',
|
|
64
|
-
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
65
|
-
},
|
|
66
|
-
prisma,
|
|
67
|
-
});
|
|
68
|
-
return NextResponse.json({ error: 'No assistant id found' }, { status: 400 });
|
|
69
|
-
}
|
|
70
|
-
const { threadId, pageParam } = paramsResult;
|
|
71
|
-
const assistant = await prisma.assistant.findFirst({
|
|
72
|
-
where: {
|
|
73
|
-
id: assistantId,
|
|
74
|
-
workspace: workspaceAccessWhere,
|
|
75
|
-
},
|
|
76
|
-
include: {
|
|
77
|
-
threads: {
|
|
78
|
-
where: {
|
|
79
|
-
id: validThreadId({ threadId: threadId !== null && threadId !== void 0 ? threadId : null }),
|
|
80
|
-
},
|
|
81
|
-
take: 1,
|
|
82
|
-
include: {
|
|
83
|
-
assistant: {
|
|
84
|
-
select: {
|
|
85
|
-
storageProviderType: true,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
workspace: {
|
|
91
|
-
include: {
|
|
92
|
-
modelProviders: true,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
modelProvider: true,
|
|
96
|
-
initialMessages: {
|
|
97
|
-
orderBy: {
|
|
98
|
-
orderNumber: 'desc',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
mcpServers: {
|
|
102
|
-
include: {
|
|
103
|
-
computerUseTool: true,
|
|
104
|
-
stdioTransport: true,
|
|
105
|
-
sseTransport: true,
|
|
106
|
-
httpTransport: true,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
tools: {
|
|
110
|
-
include: {
|
|
111
|
-
fileSearchTool: true,
|
|
112
|
-
webSearchTool: true,
|
|
113
|
-
imageGenerationTool: true,
|
|
114
|
-
codeInterpreterTool: true,
|
|
115
|
-
computerUseTool: true,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
functions: true,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
if (!assistant) {
|
|
122
|
-
createLog({
|
|
123
|
-
log: {
|
|
124
|
-
requestMethod: LogRequestMethod.POST,
|
|
125
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
126
|
-
level: LogLevel.ERROR,
|
|
127
|
-
status: 400,
|
|
128
|
-
message: 'No assistant found.',
|
|
129
|
-
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
130
|
-
},
|
|
131
|
-
prisma,
|
|
132
|
-
});
|
|
133
|
-
return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
|
|
134
|
-
}
|
|
135
|
-
if (!threadId) {
|
|
136
|
-
return NextResponse.json(await initialMessagesResponse({ assistant }), {
|
|
137
|
-
headers: cacheHeaders,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
const thread = assistant.threads[0];
|
|
141
|
-
if (!thread) {
|
|
142
|
-
return NextResponse.json(await initialMessagesResponse({ assistant }), {
|
|
143
|
-
headers: cacheHeaders,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const assistantClient = assistantClientAdapter({
|
|
147
|
-
assistant,
|
|
148
|
-
prisma,
|
|
149
|
-
thread,
|
|
150
|
-
});
|
|
151
|
-
const storageThreadId = getStorageThreadId({
|
|
152
|
-
thread,
|
|
153
|
-
});
|
|
154
|
-
if (!storageThreadId) {
|
|
155
|
-
return NextResponse.json(await initialMessagesResponse({ assistant }), {
|
|
156
|
-
headers: cacheHeaders,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
try {
|
|
160
|
-
return NextResponse.json(await messagesResponse(Object.assign({ threadId: storageThreadId, client: assistantClient }, (pageParam ? { pageParam } : {}))), {
|
|
161
|
-
headers: cacheHeaders,
|
|
162
|
-
});
|
|
163
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
console.dir({ error }, { depth: null });
|
|
167
|
-
createLog({
|
|
168
|
-
log: {
|
|
169
|
-
requestMethod: LogRequestMethod.GET,
|
|
170
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
171
|
-
level: LogLevel.ERROR,
|
|
172
|
-
status: 500,
|
|
173
|
-
message: `Failed to load messages: ${error.message}`,
|
|
174
|
-
workspaceId: assistant.workspaceId,
|
|
175
|
-
assistantId: assistant.id,
|
|
176
|
-
threadId: thread.id,
|
|
177
|
-
},
|
|
178
|
-
prisma,
|
|
179
|
-
});
|
|
180
|
-
return NextResponse.json({ error: 'Failed to load messages.' }, { status: 500 });
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
export const GET = ((...args) => buildGET()(...args));
|
|
184
|
-
export const buildPOST = ({ prisma: providedPrisma, onSuccessCreateThread = () => void 0, } = {}) => async (request) => {
|
|
185
|
-
var _a;
|
|
186
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
187
|
-
const bodyResult = z
|
|
188
|
-
.object({
|
|
189
|
-
audioContent: z.any().optional(),
|
|
190
|
-
content: z.any().optional(),
|
|
191
|
-
attachments: z.array(z.any()).optional(),
|
|
192
|
-
assistantId: z.string().optional(),
|
|
193
|
-
publicApiKey: z.string().optional(),
|
|
194
|
-
threadId: z.string().optional(),
|
|
195
|
-
})
|
|
196
|
-
.passthrough()
|
|
197
|
-
.parse(await request.json());
|
|
198
|
-
const { audioContent, content: textContent, attachments, assistantId, publicApiKey } = bodyResult, variables = __rest(bodyResult, ["audioContent", "content", "attachments", "assistantId", "publicApiKey"]);
|
|
199
|
-
const workspaceAccessWhere = await getWorkspaceAccessWhere({
|
|
200
|
-
publicApiKey: publicApiKey !== null && publicApiKey !== void 0 ? publicApiKey : null,
|
|
201
|
-
prisma,
|
|
202
|
-
});
|
|
203
|
-
if (!workspaceAccessWhere) {
|
|
204
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
205
|
-
}
|
|
206
|
-
if (!assistantId) {
|
|
207
|
-
createLog({
|
|
208
|
-
log: {
|
|
209
|
-
requestMethod: LogRequestMethod.POST,
|
|
210
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
211
|
-
level: LogLevel.ERROR,
|
|
212
|
-
status: 400,
|
|
213
|
-
message: 'No assistantId found.',
|
|
214
|
-
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
215
|
-
},
|
|
216
|
-
prisma,
|
|
217
|
-
});
|
|
218
|
-
return NextResponse.json({ error: 'No assistantId found.' }, { status: 400 });
|
|
219
|
-
}
|
|
220
|
-
if (!textContent && !audioContent && !(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
|
|
221
|
-
createLog({
|
|
222
|
-
log: {
|
|
223
|
-
requestMethod: LogRequestMethod.POST,
|
|
224
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
225
|
-
level: LogLevel.ERROR,
|
|
226
|
-
status: 400,
|
|
227
|
-
message: 'No content found.',
|
|
228
|
-
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
229
|
-
},
|
|
230
|
-
prisma,
|
|
231
|
-
});
|
|
232
|
-
return NextResponse.json({ error: 'No content found.' }, { status: 400 });
|
|
233
|
-
}
|
|
234
|
-
const assistant = await prisma.assistant.findFirst({
|
|
235
|
-
where: {
|
|
236
|
-
id: assistantId,
|
|
237
|
-
workspace: workspaceAccessWhere,
|
|
238
|
-
},
|
|
239
|
-
include: {
|
|
240
|
-
threads: {
|
|
241
|
-
where: {
|
|
242
|
-
id: validThreadId({ threadId: (_a = bodyResult.threadId) !== null && _a !== void 0 ? _a : null }),
|
|
243
|
-
},
|
|
244
|
-
include: {
|
|
245
|
-
assistant: {
|
|
246
|
-
select: {
|
|
247
|
-
storageProviderType: true,
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
take: 1,
|
|
252
|
-
},
|
|
253
|
-
workspace: {
|
|
254
|
-
include: {
|
|
255
|
-
modelProviders: true,
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
mcpServers: {
|
|
259
|
-
include: {
|
|
260
|
-
computerUseTool: true,
|
|
261
|
-
stdioTransport: true,
|
|
262
|
-
sseTransport: true,
|
|
263
|
-
httpTransport: true,
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
tools: {
|
|
267
|
-
include: {
|
|
268
|
-
fileSearchTool: true,
|
|
269
|
-
webSearchTool: true,
|
|
270
|
-
imageGenerationTool: true,
|
|
271
|
-
codeInterpreterTool: true,
|
|
272
|
-
computerUseTool: {
|
|
273
|
-
include: {
|
|
274
|
-
mcpServer: {
|
|
275
|
-
include: {
|
|
276
|
-
stdioTransport: true,
|
|
277
|
-
sseTransport: true,
|
|
278
|
-
httpTransport: true,
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
functions: {
|
|
286
|
-
include: {
|
|
287
|
-
handler: {
|
|
288
|
-
include: {
|
|
289
|
-
requestHandler: true,
|
|
290
|
-
firecrawlHandler: true,
|
|
291
|
-
replicateHandler: true,
|
|
292
|
-
clientToolHandler: true,
|
|
293
|
-
assistantHandler: true,
|
|
294
|
-
createTaskHandler: true,
|
|
295
|
-
listTasksHandler: true,
|
|
296
|
-
updateTaskHandler: true,
|
|
297
|
-
deleteTaskHandler: true,
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
modelProvider: true,
|
|
303
|
-
initialMessages: {
|
|
304
|
-
orderBy: {
|
|
305
|
-
orderNumber: 'asc',
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
if (!assistant) {
|
|
311
|
-
createLog({
|
|
312
|
-
log: {
|
|
313
|
-
requestMethod: LogRequestMethod.POST,
|
|
314
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
315
|
-
level: LogLevel.ERROR,
|
|
316
|
-
status: 400,
|
|
317
|
-
message: 'No assistant found.',
|
|
318
|
-
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
319
|
-
},
|
|
320
|
-
prisma,
|
|
321
|
-
});
|
|
322
|
-
return NextResponse.json({ error: 'No assistant found.' }, { status: 400 });
|
|
323
|
-
}
|
|
324
|
-
if (isOpenaiAssistantsStorageProvider({
|
|
325
|
-
storageProviderType: assistant.storageProviderType,
|
|
326
|
-
}) &&
|
|
327
|
-
!assistant.openaiAssistantId) {
|
|
328
|
-
createLog({
|
|
329
|
-
log: {
|
|
330
|
-
requestMethod: LogRequestMethod.POST,
|
|
331
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
332
|
-
level: LogLevel.ERROR,
|
|
333
|
-
status: 400,
|
|
334
|
-
message: 'Assistant setup is not done.',
|
|
335
|
-
workspaceId: assistant.workspaceId,
|
|
336
|
-
assistantId: assistant.id,
|
|
337
|
-
},
|
|
338
|
-
prisma,
|
|
339
|
-
});
|
|
340
|
-
return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
|
|
341
|
-
}
|
|
342
|
-
let thread = assistant.threads[0];
|
|
343
|
-
let isThreadCreated = false;
|
|
344
|
-
if (!thread) {
|
|
345
|
-
const createThreadClient = assistantClientAdapter({ assistant, prisma });
|
|
346
|
-
try {
|
|
347
|
-
thread = await createThread({
|
|
348
|
-
client: createThreadClient,
|
|
349
|
-
assistant,
|
|
350
|
-
prisma,
|
|
351
|
-
variables: variables,
|
|
352
|
-
});
|
|
353
|
-
onSuccessCreateThread({ thread });
|
|
354
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
355
|
-
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
console.error(error);
|
|
358
|
-
createLog({
|
|
359
|
-
log: {
|
|
360
|
-
requestMethod: LogRequestMethod.POST,
|
|
361
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
362
|
-
level: LogLevel.ERROR,
|
|
363
|
-
status: 500,
|
|
364
|
-
message: `Failed to create thread: ${error.message}`,
|
|
365
|
-
workspaceId: assistant.workspaceId,
|
|
366
|
-
assistantId: assistant.id,
|
|
367
|
-
},
|
|
368
|
-
prisma,
|
|
369
|
-
});
|
|
370
|
-
return NextResponse.json({ error: 'Failed to create thread.' }, { status: 500 });
|
|
371
|
-
}
|
|
372
|
-
isThreadCreated = true;
|
|
373
|
-
}
|
|
374
|
-
let storageThreadId;
|
|
375
|
-
try {
|
|
376
|
-
storageThreadId = getStorageThreadId({
|
|
377
|
-
thread,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
console.error(error);
|
|
382
|
-
createLog({
|
|
383
|
-
log: {
|
|
384
|
-
requestMethod: LogRequestMethod.POST,
|
|
385
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
386
|
-
level: LogLevel.ERROR,
|
|
387
|
-
status: 500,
|
|
388
|
-
message: 'Failed to get storage thread id.',
|
|
389
|
-
workspaceId: assistant.workspaceId,
|
|
390
|
-
assistantId: assistant.id,
|
|
391
|
-
threadId: thread.id,
|
|
392
|
-
},
|
|
393
|
-
prisma,
|
|
394
|
-
});
|
|
395
|
-
return NextResponse.json({ error: 'Failed to get storage thread id.' }, { status: 500 });
|
|
396
|
-
}
|
|
397
|
-
if (!storageThreadId &&
|
|
398
|
-
(isOpenaiAssistantsStorageProvider({
|
|
399
|
-
storageProviderType: assistant.storageProviderType,
|
|
400
|
-
}) ||
|
|
401
|
-
isResponsesStorageProvider({
|
|
402
|
-
storageProviderType: assistant.storageProviderType,
|
|
403
|
-
}))) {
|
|
404
|
-
try {
|
|
405
|
-
storageThreadId = await managedOpenaiThreadId({
|
|
406
|
-
assistant,
|
|
407
|
-
threadId: thread.id,
|
|
408
|
-
prisma,
|
|
409
|
-
});
|
|
410
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
createLog({
|
|
414
|
-
log: {
|
|
415
|
-
requestMethod: LogRequestMethod.POST,
|
|
416
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
417
|
-
level: LogLevel.ERROR,
|
|
418
|
-
status: 500,
|
|
419
|
-
message: `Failed to get managed openai thread id: ${error.message}`,
|
|
420
|
-
workspaceId: assistant.workspaceId,
|
|
421
|
-
assistantId: assistant.id,
|
|
422
|
-
threadId: thread.id,
|
|
423
|
-
},
|
|
424
|
-
prisma,
|
|
425
|
-
});
|
|
426
|
-
return NextResponse.json({ error: 'Failed to get managed openai thread id.' }, { status: 500 });
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
if (!storageThreadId) {
|
|
430
|
-
createLog({
|
|
431
|
-
log: {
|
|
432
|
-
requestMethod: LogRequestMethod.POST,
|
|
433
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
434
|
-
level: LogLevel.ERROR,
|
|
435
|
-
status: 500,
|
|
436
|
-
message: 'Invalid thread configuration.',
|
|
437
|
-
workspaceId: assistant.workspaceId,
|
|
438
|
-
assistantId: assistant.id,
|
|
439
|
-
threadId: thread.id,
|
|
440
|
-
},
|
|
441
|
-
prisma,
|
|
442
|
-
});
|
|
443
|
-
return NextResponse.json({ error: 'Invalid thread configuration.' }, { status: 500 });
|
|
444
|
-
}
|
|
445
|
-
let content;
|
|
446
|
-
try {
|
|
447
|
-
content = await getContent({
|
|
448
|
-
audioContent,
|
|
449
|
-
textContent,
|
|
450
|
-
assistant,
|
|
451
|
-
});
|
|
452
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
453
|
-
}
|
|
454
|
-
catch (error) {
|
|
455
|
-
console.error(error);
|
|
456
|
-
createLog({
|
|
457
|
-
log: {
|
|
458
|
-
requestMethod: LogRequestMethod.POST,
|
|
459
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
460
|
-
level: LogLevel.ERROR,
|
|
461
|
-
status: 500,
|
|
462
|
-
message: `Failed to get content: ${error.message}`,
|
|
463
|
-
workspaceId: assistant.workspaceId,
|
|
464
|
-
assistantId: assistant.id,
|
|
465
|
-
threadId: thread.id,
|
|
466
|
-
},
|
|
467
|
-
prisma,
|
|
468
|
-
});
|
|
469
|
-
return NextResponse.json({ error: 'Failed to get content.' }, { status: 500 });
|
|
470
|
-
}
|
|
471
|
-
const assistantClient = assistantClientAdapter({
|
|
472
|
-
assistant,
|
|
473
|
-
prisma,
|
|
474
|
-
thread,
|
|
475
|
-
});
|
|
476
|
-
try {
|
|
477
|
-
await assistantClient.beta.threads.messages.create(storageThreadId, Object.assign(Object.assign({ role: 'user', content }, ((attachments === null || attachments === void 0 ? void 0 : attachments.length) ? { attachments } : {})), { metadata: serializeMetadata({
|
|
478
|
-
variables,
|
|
479
|
-
workspaceId: assistant.workspaceId,
|
|
480
|
-
prisma,
|
|
481
|
-
}) }));
|
|
482
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
483
|
-
}
|
|
484
|
-
catch (error) {
|
|
485
|
-
console.log({ error });
|
|
486
|
-
createLog({
|
|
487
|
-
log: {
|
|
488
|
-
requestMethod: LogRequestMethod.POST,
|
|
489
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
490
|
-
level: LogLevel.ERROR,
|
|
491
|
-
status: 500,
|
|
492
|
-
message: `Failed to create message: ${error.message}`,
|
|
493
|
-
workspaceId: assistant.workspaceId,
|
|
494
|
-
assistantId: assistant.id,
|
|
495
|
-
threadId: thread.id,
|
|
496
|
-
},
|
|
497
|
-
prisma,
|
|
498
|
-
});
|
|
499
|
-
return NextResponse.json({ error: 'Failed to create message.' }, { status: 500 });
|
|
500
|
-
}
|
|
501
|
-
let createRunStream;
|
|
502
|
-
try {
|
|
503
|
-
createRunStream = await assistantClient.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread, prisma }));
|
|
504
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
505
|
-
}
|
|
506
|
-
catch (error) {
|
|
507
|
-
console.error(error);
|
|
508
|
-
createLog({
|
|
509
|
-
log: {
|
|
510
|
-
requestMethod: LogRequestMethod.POST,
|
|
511
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
512
|
-
level: LogLevel.ERROR,
|
|
513
|
-
status: 500,
|
|
514
|
-
message: `Failed to create run stream: ${serializeError({ error })}`,
|
|
515
|
-
workspaceId: assistant.workspaceId,
|
|
516
|
-
assistantId: assistant.id,
|
|
517
|
-
threadId: thread.id,
|
|
518
|
-
},
|
|
519
|
-
prisma,
|
|
520
|
-
});
|
|
521
|
-
return NextResponse.json({ error: 'Failed to create run stream.' }, { status: 500 });
|
|
522
|
-
}
|
|
523
|
-
let latestInProgressRunData = null;
|
|
524
|
-
let latestCompletedRunData = null;
|
|
525
|
-
return new Response(createMessageResponse({
|
|
526
|
-
client: assistantClient,
|
|
527
|
-
createRunStream,
|
|
528
|
-
handleToolCall: handleToolCall({ assistant, thread, prisma }),
|
|
529
|
-
onStart: ({ controller, }) => {
|
|
530
|
-
if (!isThreadCreated)
|
|
531
|
-
return;
|
|
532
|
-
return enqueueJson({
|
|
533
|
-
controller,
|
|
534
|
-
value: {
|
|
535
|
-
event: 'thread.created',
|
|
536
|
-
data: serializeThread({
|
|
537
|
-
thread,
|
|
538
|
-
}),
|
|
539
|
-
},
|
|
540
|
-
});
|
|
541
|
-
},
|
|
542
|
-
onError: async ({ error }) => {
|
|
543
|
-
if (request.signal.aborted)
|
|
544
|
-
return;
|
|
545
|
-
createLog({
|
|
546
|
-
log: {
|
|
547
|
-
requestMethod: LogRequestMethod.POST,
|
|
548
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
549
|
-
level: LogLevel.ERROR,
|
|
550
|
-
status: 500,
|
|
551
|
-
message: `Thread Run failed: ${error.message}`,
|
|
552
|
-
workspaceId: assistant.workspaceId,
|
|
553
|
-
assistantId: assistant.id,
|
|
554
|
-
threadId: thread.id,
|
|
555
|
-
},
|
|
556
|
-
prisma,
|
|
557
|
-
});
|
|
558
|
-
// if (latestInProgressRunData) {
|
|
559
|
-
// await assistantClient.beta.threads.runs.cancel(
|
|
560
|
-
// latestInProgressRunData.thread_id,
|
|
561
|
-
// latestInProgressRunData.id,
|
|
562
|
-
// )
|
|
563
|
-
// }
|
|
564
|
-
},
|
|
565
|
-
onEvent: ({ event, data }) => {
|
|
566
|
-
var _a;
|
|
567
|
-
if (event === 'thread.run.failed') {
|
|
568
|
-
createLog({
|
|
569
|
-
log: {
|
|
570
|
-
requestMethod: LogRequestMethod.POST,
|
|
571
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
572
|
-
level: LogLevel.ERROR,
|
|
573
|
-
status: 500,
|
|
574
|
-
message: `Thread Run failed: ${(_a = data.last_error) === null || _a === void 0 ? void 0 : _a.message}`,
|
|
575
|
-
workspaceId: assistant.workspaceId,
|
|
576
|
-
assistantId: assistant.id,
|
|
577
|
-
threadId: thread.id,
|
|
578
|
-
},
|
|
579
|
-
prisma,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
else if (event === 'thread.run.in_progress') {
|
|
583
|
-
latestInProgressRunData = data;
|
|
584
|
-
}
|
|
585
|
-
else if (event === 'thread.run.completed') {
|
|
586
|
-
latestCompletedRunData = data;
|
|
587
|
-
}
|
|
588
|
-
},
|
|
589
|
-
onClose: async () => {
|
|
590
|
-
if (latestCompletedRunData)
|
|
591
|
-
return;
|
|
592
|
-
if (!isOpenaiAssistantsStorageProvider({
|
|
593
|
-
storageProviderType: assistant.storageProviderType,
|
|
594
|
-
}))
|
|
595
|
-
return;
|
|
596
|
-
if (latestInProgressRunData) {
|
|
597
|
-
await assistantClient.beta.threads.runs.cancel(latestInProgressRunData.id, {
|
|
598
|
-
thread_id: latestInProgressRunData.thread_id,
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
},
|
|
602
|
-
}), {
|
|
603
|
-
status: 200,
|
|
604
|
-
headers: {
|
|
605
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
606
|
-
},
|
|
607
|
-
});
|
|
608
|
-
};
|
|
609
|
-
export const POST = ((...args) => buildPOST({})(...args));
|
|
610
|
-
export const OPTIONS = () => NextResponse.json({}, {
|
|
611
|
-
headers: cacheHeaders,
|
|
612
|
-
});
|
|
1
|
+
import { prisma } from '../../../lib/prisma';
|
|
2
|
+
import { buildGET, buildOPTIONS, buildPOST, maxDuration, } from './buildRoute';
|
|
3
|
+
export { maxDuration };
|
|
4
|
+
export const GET = buildGET({ prisma });
|
|
5
|
+
export const POST = buildPOST({ prisma });
|
|
6
|
+
export const OPTIONS = buildOPTIONS();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type PrismaClient } from '@prisma/client';
|
|
2
|
+
import { NextResponse, type NextRequest } from 'next/server';
|
|
3
|
+
type RouteProps = {
|
|
4
|
+
params: Promise<{
|
|
5
|
+
modelProviderId: string;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
export declare const buildGET: ({ prisma }: {
|
|
9
|
+
prisma: PrismaClient;
|
|
10
|
+
}) => (_request: NextRequest, props: RouteProps) => Promise<NextResponse<{
|
|
11
|
+
error: string;
|
|
12
|
+
}> | NextResponse<{
|
|
13
|
+
storageProviderAssistants: {
|
|
14
|
+
id: string;
|
|
15
|
+
model: string;
|
|
16
|
+
name: string | null;
|
|
17
|
+
description: string | null;
|
|
18
|
+
instructions: string | null;
|
|
19
|
+
tools: import("openai/resources/beta/assistants.mjs").AssistantTool[];
|
|
20
|
+
}[];
|
|
21
|
+
}>>;
|
|
22
|
+
export declare const buildOPTIONS: () => () => NextResponse<{}>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=buildRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/providers/[modelProviderId]/assistants/buildRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAM5D,KAAK,UAAU,GAAG;IAChB,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C,CAAA;AAED,eAAO,MAAM,QAAQ,GAClB,YAAY;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,MAC9B,UAAU,WAAW,EAAE,OAAO,UAAU;;;;;;;;;;;GAgD9C,CAAA;AAEH,eAAO,MAAM,YAAY,8BAMtB,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { headers } from 'next/headers';
|
|
2
|
+
import { ApiKeyType } from '@prisma/client';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { cacheHeaders } from '../../../../../lib/cache/cacheHeaders';
|
|
5
|
+
import { getApiKey } from '../../../../../lib/apiKeys/getApiKey';
|
|
6
|
+
import { getStorageProviderAssistants } from '../../../../../lib/storageProviders/getStorageProviderAssistants';
|
|
7
|
+
import { serializeApiStorageProviderAssistant } from '../../../../../lib/storageProviders/serializeApiStorageProviderAssistant';
|
|
8
|
+
export const buildGET = ({ prisma }) => async (_request, props) => {
|
|
9
|
+
const { modelProviderId } = await props.params;
|
|
10
|
+
const headersList = await headers();
|
|
11
|
+
const authorization = headersList.get('authorization');
|
|
12
|
+
if (!authorization) {
|
|
13
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
14
|
+
}
|
|
15
|
+
const privateApiKey = await getApiKey({
|
|
16
|
+
type: ApiKeyType.PRIVATE,
|
|
17
|
+
authorization,
|
|
18
|
+
prisma,
|
|
19
|
+
});
|
|
20
|
+
if (!privateApiKey) {
|
|
21
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
22
|
+
}
|
|
23
|
+
const provider = await prisma.modelProvider.findUnique({
|
|
24
|
+
where: {
|
|
25
|
+
id: modelProviderId,
|
|
26
|
+
workspaceId: privateApiKey.workspaceId,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
if (!provider) {
|
|
30
|
+
return NextResponse.json({ error: 'No provider found' }, { status: 400 });
|
|
31
|
+
}
|
|
32
|
+
const storageProviderAssistants = await getStorageProviderAssistants({
|
|
33
|
+
modelProvider: provider,
|
|
34
|
+
});
|
|
35
|
+
return NextResponse.json({
|
|
36
|
+
storageProviderAssistants: storageProviderAssistants.map((storageProviderAssistant) => serializeApiStorageProviderAssistant({
|
|
37
|
+
storageProviderAssistant,
|
|
38
|
+
})),
|
|
39
|
+
}, { headers: cacheHeaders });
|
|
40
|
+
};
|
|
41
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
42
|
+
headers: cacheHeaders,
|
|
43
|
+
});
|