@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
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
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 { createLog } from '../../../lib/logs/createLog';
|
|
28
|
+
import { serializeThread } from './lib/serializeThread';
|
|
29
|
+
import { getWorkspaceId } from './lib/getWorkspaceId';
|
|
30
|
+
import { validThreadId } from '../../../lib/threads/validThreadId';
|
|
31
|
+
import { isOpenaiAssistantsStorageProvider } from '../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
|
|
32
|
+
import { serializeMetadata } from '../../../lib/metadata/serializeMetadata';
|
|
33
|
+
import { isResponsesStorageProvider } from '../../../lib/storageProviders/isResponsesStorageProvider';
|
|
34
|
+
import { serializeError } from '../../../lib/errors/serializeError';
|
|
35
|
+
export const maxDuration = 800;
|
|
36
|
+
export const buildGET = ({ prisma }) => async (request) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const paramsResult = z
|
|
39
|
+
.object({
|
|
40
|
+
publicApiKey: z.string().optional(),
|
|
41
|
+
assistantId: z.string().optional(),
|
|
42
|
+
threadId: z.string().optional(),
|
|
43
|
+
pageParam: z.string().optional(),
|
|
44
|
+
})
|
|
45
|
+
.parse(Object.fromEntries(request.nextUrl.searchParams.entries()));
|
|
46
|
+
const workspaceAccessWhere = await getWorkspaceAccessWhere({
|
|
47
|
+
publicApiKey: (_a = paramsResult.publicApiKey) !== null && _a !== void 0 ? _a : null,
|
|
48
|
+
prisma,
|
|
49
|
+
});
|
|
50
|
+
if (!workspaceAccessWhere) {
|
|
51
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
52
|
+
}
|
|
53
|
+
const assistantId = paramsResult.assistantId;
|
|
54
|
+
if (!assistantId) {
|
|
55
|
+
createLog({
|
|
56
|
+
log: {
|
|
57
|
+
requestMethod: LogRequestMethod.POST,
|
|
58
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
59
|
+
level: LogLevel.ERROR,
|
|
60
|
+
status: 400,
|
|
61
|
+
message: 'No assistantId found.',
|
|
62
|
+
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
63
|
+
},
|
|
64
|
+
prisma,
|
|
65
|
+
});
|
|
66
|
+
return NextResponse.json({ error: 'No assistant id found' }, { status: 400 });
|
|
67
|
+
}
|
|
68
|
+
const { threadId, pageParam } = paramsResult;
|
|
69
|
+
const assistant = await prisma.assistant.findFirst({
|
|
70
|
+
where: {
|
|
71
|
+
id: assistantId,
|
|
72
|
+
workspace: workspaceAccessWhere,
|
|
73
|
+
},
|
|
74
|
+
include: {
|
|
75
|
+
threads: {
|
|
76
|
+
where: {
|
|
77
|
+
id: validThreadId({ threadId: threadId !== null && threadId !== void 0 ? threadId : null }),
|
|
78
|
+
},
|
|
79
|
+
take: 1,
|
|
80
|
+
include: {
|
|
81
|
+
assistant: {
|
|
82
|
+
select: {
|
|
83
|
+
storageProviderType: true,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
workspace: {
|
|
89
|
+
include: {
|
|
90
|
+
modelProviders: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
modelProvider: true,
|
|
94
|
+
initialMessages: {
|
|
95
|
+
orderBy: {
|
|
96
|
+
orderNumber: 'desc',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
mcpServers: {
|
|
100
|
+
include: {
|
|
101
|
+
computerUseTool: true,
|
|
102
|
+
stdioTransport: true,
|
|
103
|
+
sseTransport: true,
|
|
104
|
+
httpTransport: true,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
tools: {
|
|
108
|
+
include: {
|
|
109
|
+
fileSearchTool: true,
|
|
110
|
+
webSearchTool: true,
|
|
111
|
+
imageGenerationTool: true,
|
|
112
|
+
codeInterpreterTool: true,
|
|
113
|
+
computerUseTool: true,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
functions: true,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
if (!assistant) {
|
|
120
|
+
createLog({
|
|
121
|
+
log: {
|
|
122
|
+
requestMethod: LogRequestMethod.POST,
|
|
123
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
124
|
+
level: LogLevel.ERROR,
|
|
125
|
+
status: 400,
|
|
126
|
+
message: 'No assistant found.',
|
|
127
|
+
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
128
|
+
},
|
|
129
|
+
prisma,
|
|
130
|
+
});
|
|
131
|
+
return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
|
|
132
|
+
}
|
|
133
|
+
if (!threadId) {
|
|
134
|
+
return NextResponse.json(await initialMessagesResponse({ assistant }), {
|
|
135
|
+
headers: cacheHeaders,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const thread = assistant.threads[0];
|
|
139
|
+
if (!thread) {
|
|
140
|
+
return NextResponse.json(await initialMessagesResponse({ assistant }), {
|
|
141
|
+
headers: cacheHeaders,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const assistantClient = assistantClientAdapter({
|
|
145
|
+
assistant,
|
|
146
|
+
prisma,
|
|
147
|
+
thread,
|
|
148
|
+
});
|
|
149
|
+
const storageThreadId = getStorageThreadId({
|
|
150
|
+
thread,
|
|
151
|
+
});
|
|
152
|
+
if (!storageThreadId) {
|
|
153
|
+
return NextResponse.json(await initialMessagesResponse({ assistant }), {
|
|
154
|
+
headers: cacheHeaders,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
return NextResponse.json(await messagesResponse(Object.assign({ threadId: storageThreadId, client: assistantClient }, (pageParam ? { pageParam } : {}))), {
|
|
159
|
+
headers: cacheHeaders,
|
|
160
|
+
});
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.dir({ error }, { depth: null });
|
|
165
|
+
createLog({
|
|
166
|
+
log: {
|
|
167
|
+
requestMethod: LogRequestMethod.GET,
|
|
168
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
169
|
+
level: LogLevel.ERROR,
|
|
170
|
+
status: 500,
|
|
171
|
+
message: `Failed to load messages: ${error.message}`,
|
|
172
|
+
workspaceId: assistant.workspaceId,
|
|
173
|
+
assistantId: assistant.id,
|
|
174
|
+
threadId: thread.id,
|
|
175
|
+
},
|
|
176
|
+
prisma,
|
|
177
|
+
});
|
|
178
|
+
return NextResponse.json({ error: 'Failed to load messages.' }, { status: 500 });
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
export const buildPOST = ({ prisma, onSuccessCreateThread = () => void 0, }) => async (request) => {
|
|
182
|
+
var _a;
|
|
183
|
+
const bodyResult = z
|
|
184
|
+
.object({
|
|
185
|
+
audioContent: z.any().optional(),
|
|
186
|
+
content: z.any().optional(),
|
|
187
|
+
attachments: z.array(z.any()).optional(),
|
|
188
|
+
assistantId: z.string().optional(),
|
|
189
|
+
publicApiKey: z.string().optional(),
|
|
190
|
+
threadId: z.string().optional(),
|
|
191
|
+
})
|
|
192
|
+
.passthrough()
|
|
193
|
+
.parse(await request.json());
|
|
194
|
+
const { audioContent, content: textContent, attachments, assistantId, publicApiKey } = bodyResult, variables = __rest(bodyResult, ["audioContent", "content", "attachments", "assistantId", "publicApiKey"]);
|
|
195
|
+
const workspaceAccessWhere = await getWorkspaceAccessWhere({
|
|
196
|
+
publicApiKey: publicApiKey !== null && publicApiKey !== void 0 ? publicApiKey : null,
|
|
197
|
+
prisma,
|
|
198
|
+
});
|
|
199
|
+
if (!workspaceAccessWhere) {
|
|
200
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
201
|
+
}
|
|
202
|
+
if (!assistantId) {
|
|
203
|
+
createLog({
|
|
204
|
+
log: {
|
|
205
|
+
requestMethod: LogRequestMethod.POST,
|
|
206
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
207
|
+
level: LogLevel.ERROR,
|
|
208
|
+
status: 400,
|
|
209
|
+
message: 'No assistantId found.',
|
|
210
|
+
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
211
|
+
},
|
|
212
|
+
prisma,
|
|
213
|
+
});
|
|
214
|
+
return NextResponse.json({ error: 'No assistantId found.' }, { status: 400 });
|
|
215
|
+
}
|
|
216
|
+
if (!textContent && !audioContent && !(attachments === null || attachments === void 0 ? void 0 : attachments.length)) {
|
|
217
|
+
createLog({
|
|
218
|
+
log: {
|
|
219
|
+
requestMethod: LogRequestMethod.POST,
|
|
220
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
221
|
+
level: LogLevel.ERROR,
|
|
222
|
+
status: 400,
|
|
223
|
+
message: 'No content found.',
|
|
224
|
+
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
225
|
+
},
|
|
226
|
+
prisma,
|
|
227
|
+
});
|
|
228
|
+
return NextResponse.json({ error: 'No content found.' }, { status: 400 });
|
|
229
|
+
}
|
|
230
|
+
const assistant = await prisma.assistant.findFirst({
|
|
231
|
+
where: {
|
|
232
|
+
id: assistantId,
|
|
233
|
+
workspace: workspaceAccessWhere,
|
|
234
|
+
},
|
|
235
|
+
include: {
|
|
236
|
+
threads: {
|
|
237
|
+
where: {
|
|
238
|
+
id: validThreadId({ threadId: (_a = bodyResult.threadId) !== null && _a !== void 0 ? _a : null }),
|
|
239
|
+
},
|
|
240
|
+
include: {
|
|
241
|
+
assistant: {
|
|
242
|
+
select: {
|
|
243
|
+
storageProviderType: true,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
take: 1,
|
|
248
|
+
},
|
|
249
|
+
workspace: {
|
|
250
|
+
include: {
|
|
251
|
+
modelProviders: true,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
mcpServers: {
|
|
255
|
+
include: {
|
|
256
|
+
computerUseTool: true,
|
|
257
|
+
stdioTransport: true,
|
|
258
|
+
sseTransport: true,
|
|
259
|
+
httpTransport: true,
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
tools: {
|
|
263
|
+
include: {
|
|
264
|
+
fileSearchTool: true,
|
|
265
|
+
webSearchTool: true,
|
|
266
|
+
imageGenerationTool: true,
|
|
267
|
+
codeInterpreterTool: true,
|
|
268
|
+
computerUseTool: {
|
|
269
|
+
include: {
|
|
270
|
+
mcpServer: {
|
|
271
|
+
include: {
|
|
272
|
+
stdioTransport: true,
|
|
273
|
+
sseTransport: true,
|
|
274
|
+
httpTransport: true,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
functions: {
|
|
282
|
+
include: {
|
|
283
|
+
handler: {
|
|
284
|
+
include: {
|
|
285
|
+
requestHandler: true,
|
|
286
|
+
firecrawlHandler: true,
|
|
287
|
+
replicateHandler: true,
|
|
288
|
+
clientToolHandler: true,
|
|
289
|
+
assistantHandler: true,
|
|
290
|
+
createTaskHandler: true,
|
|
291
|
+
listTasksHandler: true,
|
|
292
|
+
updateTaskHandler: true,
|
|
293
|
+
deleteTaskHandler: true,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
modelProvider: true,
|
|
299
|
+
initialMessages: {
|
|
300
|
+
orderBy: {
|
|
301
|
+
orderNumber: 'asc',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
if (!assistant) {
|
|
307
|
+
createLog({
|
|
308
|
+
log: {
|
|
309
|
+
requestMethod: LogRequestMethod.POST,
|
|
310
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
311
|
+
level: LogLevel.ERROR,
|
|
312
|
+
status: 400,
|
|
313
|
+
message: 'No assistant found.',
|
|
314
|
+
workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
|
|
315
|
+
},
|
|
316
|
+
prisma,
|
|
317
|
+
});
|
|
318
|
+
return NextResponse.json({ error: 'No assistant found.' }, { status: 400 });
|
|
319
|
+
}
|
|
320
|
+
if (isOpenaiAssistantsStorageProvider({
|
|
321
|
+
storageProviderType: assistant.storageProviderType,
|
|
322
|
+
}) &&
|
|
323
|
+
!assistant.openaiAssistantId) {
|
|
324
|
+
createLog({
|
|
325
|
+
log: {
|
|
326
|
+
requestMethod: LogRequestMethod.POST,
|
|
327
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
328
|
+
level: LogLevel.ERROR,
|
|
329
|
+
status: 400,
|
|
330
|
+
message: 'Assistant setup is not done.',
|
|
331
|
+
workspaceId: assistant.workspaceId,
|
|
332
|
+
assistantId: assistant.id,
|
|
333
|
+
},
|
|
334
|
+
prisma,
|
|
335
|
+
});
|
|
336
|
+
return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
|
|
337
|
+
}
|
|
338
|
+
let thread = assistant.threads[0];
|
|
339
|
+
let isThreadCreated = false;
|
|
340
|
+
if (!thread) {
|
|
341
|
+
const createThreadClient = assistantClientAdapter({ assistant, prisma });
|
|
342
|
+
try {
|
|
343
|
+
thread = await createThread({
|
|
344
|
+
client: createThreadClient,
|
|
345
|
+
assistant,
|
|
346
|
+
prisma,
|
|
347
|
+
variables: variables,
|
|
348
|
+
});
|
|
349
|
+
onSuccessCreateThread({ thread });
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
console.error(error);
|
|
354
|
+
createLog({
|
|
355
|
+
log: {
|
|
356
|
+
requestMethod: LogRequestMethod.POST,
|
|
357
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
358
|
+
level: LogLevel.ERROR,
|
|
359
|
+
status: 500,
|
|
360
|
+
message: `Failed to create thread: ${error.message}`,
|
|
361
|
+
workspaceId: assistant.workspaceId,
|
|
362
|
+
assistantId: assistant.id,
|
|
363
|
+
},
|
|
364
|
+
prisma,
|
|
365
|
+
});
|
|
366
|
+
return NextResponse.json({ error: 'Failed to create thread.' }, { status: 500 });
|
|
367
|
+
}
|
|
368
|
+
isThreadCreated = true;
|
|
369
|
+
}
|
|
370
|
+
let storageThreadId;
|
|
371
|
+
try {
|
|
372
|
+
storageThreadId = getStorageThreadId({
|
|
373
|
+
thread,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
console.error(error);
|
|
378
|
+
createLog({
|
|
379
|
+
log: {
|
|
380
|
+
requestMethod: LogRequestMethod.POST,
|
|
381
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
382
|
+
level: LogLevel.ERROR,
|
|
383
|
+
status: 500,
|
|
384
|
+
message: 'Failed to get storage thread id.',
|
|
385
|
+
workspaceId: assistant.workspaceId,
|
|
386
|
+
assistantId: assistant.id,
|
|
387
|
+
threadId: thread.id,
|
|
388
|
+
},
|
|
389
|
+
prisma,
|
|
390
|
+
});
|
|
391
|
+
return NextResponse.json({ error: 'Failed to get storage thread id.' }, { status: 500 });
|
|
392
|
+
}
|
|
393
|
+
if (!storageThreadId &&
|
|
394
|
+
(isOpenaiAssistantsStorageProvider({
|
|
395
|
+
storageProviderType: assistant.storageProviderType,
|
|
396
|
+
}) ||
|
|
397
|
+
isResponsesStorageProvider({
|
|
398
|
+
storageProviderType: assistant.storageProviderType,
|
|
399
|
+
}))) {
|
|
400
|
+
try {
|
|
401
|
+
storageThreadId = await managedOpenaiThreadId({
|
|
402
|
+
assistant,
|
|
403
|
+
threadId: thread.id,
|
|
404
|
+
prisma,
|
|
405
|
+
});
|
|
406
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
createLog({
|
|
410
|
+
log: {
|
|
411
|
+
requestMethod: LogRequestMethod.POST,
|
|
412
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
413
|
+
level: LogLevel.ERROR,
|
|
414
|
+
status: 500,
|
|
415
|
+
message: `Failed to get managed openai thread id: ${error.message}`,
|
|
416
|
+
workspaceId: assistant.workspaceId,
|
|
417
|
+
assistantId: assistant.id,
|
|
418
|
+
threadId: thread.id,
|
|
419
|
+
},
|
|
420
|
+
prisma,
|
|
421
|
+
});
|
|
422
|
+
return NextResponse.json({ error: 'Failed to get managed openai thread id.' }, { status: 500 });
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (!storageThreadId) {
|
|
426
|
+
createLog({
|
|
427
|
+
log: {
|
|
428
|
+
requestMethod: LogRequestMethod.POST,
|
|
429
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
430
|
+
level: LogLevel.ERROR,
|
|
431
|
+
status: 500,
|
|
432
|
+
message: 'Invalid thread configuration.',
|
|
433
|
+
workspaceId: assistant.workspaceId,
|
|
434
|
+
assistantId: assistant.id,
|
|
435
|
+
threadId: thread.id,
|
|
436
|
+
},
|
|
437
|
+
prisma,
|
|
438
|
+
});
|
|
439
|
+
return NextResponse.json({ error: 'Invalid thread configuration.' }, { status: 500 });
|
|
440
|
+
}
|
|
441
|
+
let content;
|
|
442
|
+
try {
|
|
443
|
+
content = await getContent({
|
|
444
|
+
audioContent,
|
|
445
|
+
textContent,
|
|
446
|
+
assistant,
|
|
447
|
+
});
|
|
448
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
449
|
+
}
|
|
450
|
+
catch (error) {
|
|
451
|
+
console.error(error);
|
|
452
|
+
createLog({
|
|
453
|
+
log: {
|
|
454
|
+
requestMethod: LogRequestMethod.POST,
|
|
455
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
456
|
+
level: LogLevel.ERROR,
|
|
457
|
+
status: 500,
|
|
458
|
+
message: `Failed to get content: ${error.message}`,
|
|
459
|
+
workspaceId: assistant.workspaceId,
|
|
460
|
+
assistantId: assistant.id,
|
|
461
|
+
threadId: thread.id,
|
|
462
|
+
},
|
|
463
|
+
prisma,
|
|
464
|
+
});
|
|
465
|
+
return NextResponse.json({ error: 'Failed to get content.' }, { status: 500 });
|
|
466
|
+
}
|
|
467
|
+
const assistantClient = assistantClientAdapter({
|
|
468
|
+
assistant,
|
|
469
|
+
prisma,
|
|
470
|
+
thread,
|
|
471
|
+
});
|
|
472
|
+
try {
|
|
473
|
+
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({
|
|
474
|
+
variables,
|
|
475
|
+
workspaceId: assistant.workspaceId,
|
|
476
|
+
prisma,
|
|
477
|
+
}) }));
|
|
478
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
console.log({ error });
|
|
482
|
+
createLog({
|
|
483
|
+
log: {
|
|
484
|
+
requestMethod: LogRequestMethod.POST,
|
|
485
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
486
|
+
level: LogLevel.ERROR,
|
|
487
|
+
status: 500,
|
|
488
|
+
message: `Failed to create message: ${error.message}`,
|
|
489
|
+
workspaceId: assistant.workspaceId,
|
|
490
|
+
assistantId: assistant.id,
|
|
491
|
+
threadId: thread.id,
|
|
492
|
+
},
|
|
493
|
+
prisma,
|
|
494
|
+
});
|
|
495
|
+
return NextResponse.json({ error: 'Failed to create message.' }, { status: 500 });
|
|
496
|
+
}
|
|
497
|
+
let createRunStream;
|
|
498
|
+
try {
|
|
499
|
+
createRunStream = await assistantClient.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread, prisma }));
|
|
500
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
console.error(error);
|
|
504
|
+
createLog({
|
|
505
|
+
log: {
|
|
506
|
+
requestMethod: LogRequestMethod.POST,
|
|
507
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
508
|
+
level: LogLevel.ERROR,
|
|
509
|
+
status: 500,
|
|
510
|
+
message: `Failed to create run stream: ${serializeError({ error })}`,
|
|
511
|
+
workspaceId: assistant.workspaceId,
|
|
512
|
+
assistantId: assistant.id,
|
|
513
|
+
threadId: thread.id,
|
|
514
|
+
},
|
|
515
|
+
prisma,
|
|
516
|
+
});
|
|
517
|
+
return NextResponse.json({ error: 'Failed to create run stream.' }, { status: 500 });
|
|
518
|
+
}
|
|
519
|
+
let latestInProgressRunData = null;
|
|
520
|
+
let latestCompletedRunData = null;
|
|
521
|
+
return new Response(createMessageResponse({
|
|
522
|
+
client: assistantClient,
|
|
523
|
+
createRunStream,
|
|
524
|
+
handleToolCall: handleToolCall({ assistant, thread, prisma }),
|
|
525
|
+
onStart: ({ controller, }) => {
|
|
526
|
+
if (!isThreadCreated)
|
|
527
|
+
return;
|
|
528
|
+
return enqueueJson({
|
|
529
|
+
controller,
|
|
530
|
+
value: {
|
|
531
|
+
event: 'thread.created',
|
|
532
|
+
data: serializeThread({
|
|
533
|
+
thread,
|
|
534
|
+
}),
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
},
|
|
538
|
+
onError: async ({ error }) => {
|
|
539
|
+
if (request.signal.aborted)
|
|
540
|
+
return;
|
|
541
|
+
createLog({
|
|
542
|
+
log: {
|
|
543
|
+
requestMethod: LogRequestMethod.POST,
|
|
544
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
545
|
+
level: LogLevel.ERROR,
|
|
546
|
+
status: 500,
|
|
547
|
+
message: `Thread Run failed: ${error.message}`,
|
|
548
|
+
workspaceId: assistant.workspaceId,
|
|
549
|
+
assistantId: assistant.id,
|
|
550
|
+
threadId: thread.id,
|
|
551
|
+
},
|
|
552
|
+
prisma,
|
|
553
|
+
});
|
|
554
|
+
// if (latestInProgressRunData) {
|
|
555
|
+
// await assistantClient.beta.threads.runs.cancel(
|
|
556
|
+
// latestInProgressRunData.thread_id,
|
|
557
|
+
// latestInProgressRunData.id,
|
|
558
|
+
// )
|
|
559
|
+
// }
|
|
560
|
+
},
|
|
561
|
+
onEvent: ({ event, data }) => {
|
|
562
|
+
var _a;
|
|
563
|
+
if (event === 'thread.run.failed') {
|
|
564
|
+
createLog({
|
|
565
|
+
log: {
|
|
566
|
+
requestMethod: LogRequestMethod.POST,
|
|
567
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
568
|
+
level: LogLevel.ERROR,
|
|
569
|
+
status: 500,
|
|
570
|
+
message: `Thread Run failed: ${(_a = data.last_error) === null || _a === void 0 ? void 0 : _a.message}`,
|
|
571
|
+
workspaceId: assistant.workspaceId,
|
|
572
|
+
assistantId: assistant.id,
|
|
573
|
+
threadId: thread.id,
|
|
574
|
+
},
|
|
575
|
+
prisma,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
else if (event === 'thread.run.in_progress') {
|
|
579
|
+
latestInProgressRunData = data;
|
|
580
|
+
}
|
|
581
|
+
else if (event === 'thread.run.completed') {
|
|
582
|
+
latestCompletedRunData = data;
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
onClose: async () => {
|
|
586
|
+
if (latestCompletedRunData)
|
|
587
|
+
return;
|
|
588
|
+
if (!isOpenaiAssistantsStorageProvider({
|
|
589
|
+
storageProviderType: assistant.storageProviderType,
|
|
590
|
+
}))
|
|
591
|
+
return;
|
|
592
|
+
if (latestInProgressRunData) {
|
|
593
|
+
await assistantClient.beta.threads.runs.cancel(latestInProgressRunData.id, {
|
|
594
|
+
thread_id: latestInProgressRunData.thread_id,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
}), {
|
|
599
|
+
status: 200,
|
|
600
|
+
headers: {
|
|
601
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
606
|
+
headers: cacheHeaders,
|
|
607
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialMessagesResponse.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/messages/lib/initialMessagesResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EACL,MAAM,EAIP,MAAM,gBAAgB,CAAA;AA+BvB,eAAO,MAAM,uBAAuB,GAAU,gBAE3C;IACD,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC;QACpC,OAAO,EAAE;YACP,eAAe,EAAE,IAAI,CAAA;SACtB,CAAA;KACF,CAAC,CAAA;CACH;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"initialMessagesResponse.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/messages/lib/initialMessagesResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EACL,MAAM,EAIP,MAAM,gBAAgB,CAAA;AA+BvB,eAAO,MAAM,uBAAuB,GAAU,gBAE3C;IACD,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC;QACpC,OAAO,EAAE;YACP,eAAe,EAAE,IAAI,CAAA;SACtB,CAAA;KACF,CAAC,CAAA;CACH;;;;;;;;;;;;;;;;EAgDA,CAAA"}
|
|
@@ -23,7 +23,7 @@ export const initialMessagesResponse = async ({ assistant, }) => {
|
|
|
23
23
|
const threadId = optimisticId();
|
|
24
24
|
const initialCreatedAt = dayjs().unix();
|
|
25
25
|
return {
|
|
26
|
-
data: await Promise.all(assistant.initialMessages.map((message, index) => serializeMessage({
|
|
26
|
+
data: await Promise.all(assistant.initialMessages.map(async (message, index) => serializeMessage({
|
|
27
27
|
message: {
|
|
28
28
|
id: optimisticId(),
|
|
29
29
|
role: message.role.toLowerCase(),
|
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { Thread } from '@prisma/client';
|
|
5
|
-
export declare const maxDuration = 800;
|
|
6
|
-
export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
7
|
-
prisma?: PrismaClient;
|
|
8
|
-
}) => (request: NextRequest) => Promise<NextResponse<{
|
|
1
|
+
import { maxDuration } from './buildRoute';
|
|
2
|
+
export { maxDuration };
|
|
3
|
+
export declare const GET: (request: import("next/server").NextRequest) => Promise<import("next/server").NextResponse<{
|
|
9
4
|
error: string;
|
|
10
|
-
}> | NextResponse<{
|
|
5
|
+
}> | import("next/server").NextResponse<{
|
|
11
6
|
data: {
|
|
12
7
|
id: string;
|
|
13
8
|
role: "user" | "assistant";
|
|
14
9
|
created_at: number;
|
|
15
|
-
content:
|
|
10
|
+
content: import("openai/resources/beta/threads/messages.mjs").MessageContent[];
|
|
16
11
|
run_id: string;
|
|
17
12
|
assistant_id: string;
|
|
18
13
|
thread_id: string;
|
|
19
|
-
attachments:
|
|
14
|
+
attachments: import("openai/resources/beta/threads/messages.mjs").Message.Attachment[];
|
|
20
15
|
metadata: import("openai/resources/shared.mjs").Metadata;
|
|
21
|
-
runSteps: Pick<
|
|
16
|
+
runSteps: Pick<import("openai/resources/beta/threads/runs/steps.mjs").RunStep, "id" | "run_id" | "step_details" | "completed_at" | "cancelled_at" | "failed_at" | "status">[];
|
|
22
17
|
status: "in_progress" | "incomplete" | "completed";
|
|
23
18
|
}[];
|
|
24
19
|
hasNextPage: boolean;
|
|
25
20
|
lastId: null;
|
|
26
|
-
}> | NextResponse<import("@superinterface/react/types/index").MessagesPage>>;
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
prisma?: PrismaClient;
|
|
30
|
-
onSuccessCreateThread?: ({ thread, }: {
|
|
31
|
-
thread: Thread;
|
|
32
|
-
}) => void | Promise<void>;
|
|
33
|
-
}) => (request: NextRequest) => Promise<Response>;
|
|
34
|
-
export declare const POST: ReturnType<typeof buildPOST>;
|
|
35
|
-
export declare const OPTIONS: () => NextResponse<{}>;
|
|
21
|
+
}> | import("next/server").NextResponse<import("@superinterface/react/types/index").MessagesPage>>;
|
|
22
|
+
export declare const POST: (request: import("next/server").NextRequest) => Promise<Response>;
|
|
23
|
+
export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
|
|
36
24
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/messages/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/messages/route.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,WAAW,EACZ,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;kGAAuB,CAAA;AAEvC,eAAO,MAAM,IAAI,mEAAwB,CAAA;AAEzC,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
|