@superinterface/server 1.0.24 → 1.0.26
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 +2 -5
- package/dist/lib/prisma/index.d.ts.map +1 -1
- package/dist/lib/prisma/index.js +5 -70
- package/package.json +2 -2
- 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/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_buildManifest.js +0 -0
- /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_clientMiddlewareManifest.json +0 -0
- /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { headers } from 'next/headers';
|
|
2
|
+
import { ApiKeyType } from '@prisma/client';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { createTaskSchema } from '../../../lib/tasks/schemas';
|
|
5
|
+
import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
|
|
6
|
+
import { serializeTask } from '../../../lib/tasks/serializeTask';
|
|
7
|
+
import { validateSchedule } from '../../../lib/tasks/validateSchedule';
|
|
8
|
+
import { getApiKey } from '../../../lib/apiKeys/getApiKey';
|
|
9
|
+
import { scheduleTask } from '../../../lib/tasks/scheduleTask';
|
|
10
|
+
export const buildGET = ({ prisma }) => async (request) => {
|
|
11
|
+
const headersList = await headers();
|
|
12
|
+
const authorization = headersList.get('authorization');
|
|
13
|
+
if (!authorization) {
|
|
14
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
15
|
+
}
|
|
16
|
+
const privateApiKey = await getApiKey({
|
|
17
|
+
authorization,
|
|
18
|
+
type: ApiKeyType.PRIVATE,
|
|
19
|
+
prisma,
|
|
20
|
+
});
|
|
21
|
+
if (!privateApiKey) {
|
|
22
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
23
|
+
}
|
|
24
|
+
const key = request.nextUrl.searchParams.get('key');
|
|
25
|
+
const tasks = await prisma.task.findMany({
|
|
26
|
+
where: Object.assign(Object.assign({}, (key ? { key } : {})), { thread: { assistant: { workspaceId: privateApiKey.workspaceId } } }),
|
|
27
|
+
orderBy: { createdAt: 'desc' },
|
|
28
|
+
});
|
|
29
|
+
return NextResponse.json({
|
|
30
|
+
tasks: tasks.map((t) => serializeTask({ task: t })),
|
|
31
|
+
}, { headers: cacheHeaders });
|
|
32
|
+
};
|
|
33
|
+
export const buildPOST = ({ prisma }) => async (request) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const headersList = await headers();
|
|
36
|
+
const authorization = headersList.get('authorization');
|
|
37
|
+
if (!authorization) {
|
|
38
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
39
|
+
}
|
|
40
|
+
const privateApiKey = await getApiKey({
|
|
41
|
+
authorization,
|
|
42
|
+
type: ApiKeyType.PRIVATE,
|
|
43
|
+
prisma,
|
|
44
|
+
});
|
|
45
|
+
if (!privateApiKey) {
|
|
46
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
47
|
+
}
|
|
48
|
+
const parsed = createTaskSchema.safeParse(await request.json());
|
|
49
|
+
if (!parsed.success) {
|
|
50
|
+
return NextResponse.json({ error: 'Invalid payload' }, { status: 400 });
|
|
51
|
+
}
|
|
52
|
+
const { title, message, schedule, threadId } = parsed.data;
|
|
53
|
+
if (!validateSchedule(schedule)) {
|
|
54
|
+
return NextResponse.json({ error: 'Invalid schedule' }, { status: 400 });
|
|
55
|
+
}
|
|
56
|
+
const thread = await prisma.thread.findFirst({
|
|
57
|
+
where: {
|
|
58
|
+
id: threadId,
|
|
59
|
+
assistant: {
|
|
60
|
+
workspaceId: privateApiKey.workspaceId,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (!thread) {
|
|
65
|
+
return NextResponse.json({ error: 'Thread not found' }, { status: 400 });
|
|
66
|
+
}
|
|
67
|
+
const task = await prisma.task.create({
|
|
68
|
+
data: {
|
|
69
|
+
title,
|
|
70
|
+
message,
|
|
71
|
+
schedule,
|
|
72
|
+
thread: {
|
|
73
|
+
connect: { id: thread.id },
|
|
74
|
+
},
|
|
75
|
+
key: (_a = parsed.data.key) !== null && _a !== void 0 ? _a : '',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
await scheduleTask({ task, prisma });
|
|
79
|
+
return NextResponse.json({
|
|
80
|
+
task: serializeTask({ task }),
|
|
81
|
+
}, { headers: cacheHeaders });
|
|
82
|
+
};
|
|
83
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
84
|
+
headers: cacheHeaders,
|
|
85
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type PrismaClient } from '@prisma/client';
|
|
2
|
+
export declare const maxDuration = 800;
|
|
3
|
+
export declare const buildPOST: ({ prisma }: {
|
|
4
|
+
prisma: PrismaClient;
|
|
5
|
+
}) => (request: import("next/server").NextRequest | Request, params?: any) => Promise<Response>;
|
|
6
|
+
//# sourceMappingURL=buildRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/tasks/callback/buildRoute.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAYvB,eAAO,MAAM,WAAW,MAAM,CAAA;AA+Q9B,eAAO,MAAM,SAAS,GAAI,YAAY;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,8FAO7D,CAAA"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { verifySignatureAppRouter } from '@upstash/qstash/nextjs';
|
|
3
|
+
import { createMessageResponse } from '@superinterface/react/server';
|
|
4
|
+
import { LogRequestMethod, LogRequestRoute, LogLevel, } from '@prisma/client';
|
|
5
|
+
import { assistantClientAdapter } from '../../../../lib/assistants/assistantClientAdapter';
|
|
6
|
+
import { createRunOpts } from '../../../../lib/runs/createRunOpts';
|
|
7
|
+
import { scheduleTask } from '../../../../lib/tasks/scheduleTask';
|
|
8
|
+
import { handleToolCall } from '../../../../lib/toolCalls/handleToolCall';
|
|
9
|
+
import { createLog } from '../../../../lib/logs/createLog';
|
|
10
|
+
import { storageThreadId as getStorageThreadId } from '../../../../lib/threads/storageThreadId';
|
|
11
|
+
import { redis } from '../../../../lib/redis';
|
|
12
|
+
import { isOpenaiAssistantsStorageProvider } from '../../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
|
|
13
|
+
import { managedOpenaiThreadId } from '../../../../lib/threads/managedOpenaiThreadId';
|
|
14
|
+
import { serializeMetadata } from '../../../../lib/metadata/serializeMetadata';
|
|
15
|
+
export const maxDuration = 800;
|
|
16
|
+
const buildPostHandler = ({ prisma }) => async (request) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const { taskId } = await request.json();
|
|
19
|
+
const task = await prisma.task.findUnique({
|
|
20
|
+
where: { id: taskId },
|
|
21
|
+
include: {
|
|
22
|
+
thread: {
|
|
23
|
+
include: {
|
|
24
|
+
assistant: {
|
|
25
|
+
include: {
|
|
26
|
+
modelProvider: true,
|
|
27
|
+
tools: {
|
|
28
|
+
include: {
|
|
29
|
+
fileSearchTool: true,
|
|
30
|
+
webSearchTool: true,
|
|
31
|
+
imageGenerationTool: true,
|
|
32
|
+
codeInterpreterTool: true,
|
|
33
|
+
computerUseTool: {
|
|
34
|
+
include: {
|
|
35
|
+
mcpServer: {
|
|
36
|
+
include: {
|
|
37
|
+
stdioTransport: true,
|
|
38
|
+
sseTransport: true,
|
|
39
|
+
httpTransport: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
functions: {
|
|
47
|
+
include: {
|
|
48
|
+
handler: {
|
|
49
|
+
include: {
|
|
50
|
+
requestHandler: true,
|
|
51
|
+
firecrawlHandler: true,
|
|
52
|
+
replicateHandler: true,
|
|
53
|
+
clientToolHandler: true,
|
|
54
|
+
assistantHandler: true,
|
|
55
|
+
createTaskHandler: true,
|
|
56
|
+
listTasksHandler: true,
|
|
57
|
+
updateTaskHandler: true,
|
|
58
|
+
deleteTaskHandler: true,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
mcpServers: {
|
|
64
|
+
include: {
|
|
65
|
+
computerUseTool: true,
|
|
66
|
+
stdioTransport: true,
|
|
67
|
+
sseTransport: true,
|
|
68
|
+
httpTransport: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (!task) {
|
|
78
|
+
return NextResponse.json({ error: 'Task not found' }, { status: 400 });
|
|
79
|
+
}
|
|
80
|
+
const assistant = task.thread.assistant;
|
|
81
|
+
const thread = task.thread;
|
|
82
|
+
const assistantClient = assistantClientAdapter({ assistant, prisma });
|
|
83
|
+
let storageThreadId;
|
|
84
|
+
try {
|
|
85
|
+
storageThreadId = getStorageThreadId({
|
|
86
|
+
thread,
|
|
87
|
+
});
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
createLog({
|
|
92
|
+
log: {
|
|
93
|
+
requestMethod: LogRequestMethod.POST,
|
|
94
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
95
|
+
level: LogLevel.ERROR,
|
|
96
|
+
status: 500,
|
|
97
|
+
message: 'Failed to get storage thread id.',
|
|
98
|
+
workspaceId: assistant.workspaceId,
|
|
99
|
+
assistantId: assistant.id,
|
|
100
|
+
threadId: thread.id,
|
|
101
|
+
},
|
|
102
|
+
prisma,
|
|
103
|
+
});
|
|
104
|
+
return NextResponse.json({ error: 'Failed to get storage thread id.' }, { status: 500 });
|
|
105
|
+
}
|
|
106
|
+
if (!storageThreadId &&
|
|
107
|
+
isOpenaiAssistantsStorageProvider({
|
|
108
|
+
storageProviderType: assistant.storageProviderType,
|
|
109
|
+
})) {
|
|
110
|
+
try {
|
|
111
|
+
storageThreadId = await managedOpenaiThreadId({
|
|
112
|
+
assistant,
|
|
113
|
+
threadId: thread.id,
|
|
114
|
+
prisma,
|
|
115
|
+
});
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
createLog({
|
|
120
|
+
log: {
|
|
121
|
+
requestMethod: LogRequestMethod.POST,
|
|
122
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
123
|
+
level: LogLevel.ERROR,
|
|
124
|
+
status: 500,
|
|
125
|
+
message: `Failed to get managed openai thread id: ${error.message}`,
|
|
126
|
+
workspaceId: assistant.workspaceId,
|
|
127
|
+
assistantId: assistant.id,
|
|
128
|
+
threadId: thread.id,
|
|
129
|
+
},
|
|
130
|
+
prisma,
|
|
131
|
+
});
|
|
132
|
+
return NextResponse.json({ error: 'Failed to get managed openai thread id.' }, { status: 500 });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!storageThreadId) {
|
|
136
|
+
createLog({
|
|
137
|
+
log: {
|
|
138
|
+
requestMethod: LogRequestMethod.POST,
|
|
139
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
140
|
+
level: LogLevel.ERROR,
|
|
141
|
+
status: 500,
|
|
142
|
+
message: 'Invalid thread configuration.',
|
|
143
|
+
workspaceId: assistant.workspaceId,
|
|
144
|
+
assistantId: assistant.id,
|
|
145
|
+
threadId: thread.id,
|
|
146
|
+
},
|
|
147
|
+
prisma,
|
|
148
|
+
});
|
|
149
|
+
return NextResponse.json({ error: 'Invalid thread configuration.' }, { status: 500 });
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
await assistantClient.beta.threads.messages.create(storageThreadId, {
|
|
153
|
+
role: 'user',
|
|
154
|
+
content: task.message,
|
|
155
|
+
metadata: serializeMetadata({
|
|
156
|
+
variables: {
|
|
157
|
+
superinterfaceCreatedByType: 'TASK',
|
|
158
|
+
superinterfaceCreatedById: task.id,
|
|
159
|
+
},
|
|
160
|
+
workspaceId: assistant.workspaceId,
|
|
161
|
+
prisma,
|
|
162
|
+
}),
|
|
163
|
+
});
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.log({ error });
|
|
168
|
+
createLog({
|
|
169
|
+
log: {
|
|
170
|
+
requestMethod: LogRequestMethod.POST,
|
|
171
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
172
|
+
level: LogLevel.ERROR,
|
|
173
|
+
status: 500,
|
|
174
|
+
message: `Failed to create message: ${error.message}`,
|
|
175
|
+
workspaceId: assistant.workspaceId,
|
|
176
|
+
assistantId: assistant.id,
|
|
177
|
+
threadId: thread.id,
|
|
178
|
+
},
|
|
179
|
+
prisma,
|
|
180
|
+
});
|
|
181
|
+
return NextResponse.json({ error: 'Failed to create message' }, { status: 500 });
|
|
182
|
+
}
|
|
183
|
+
let createRunStream;
|
|
184
|
+
try {
|
|
185
|
+
createRunStream = await assistantClient.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread, prisma }));
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
console.log({ error });
|
|
190
|
+
createLog({
|
|
191
|
+
log: {
|
|
192
|
+
requestMethod: LogRequestMethod.POST,
|
|
193
|
+
requestRoute: LogRequestRoute.MESSAGES,
|
|
194
|
+
level: LogLevel.ERROR,
|
|
195
|
+
status: 500,
|
|
196
|
+
message: `Failed to create run stream: ${error.message}`,
|
|
197
|
+
workspaceId: assistant.workspaceId,
|
|
198
|
+
assistantId: assistant.id,
|
|
199
|
+
threadId: thread.id,
|
|
200
|
+
},
|
|
201
|
+
prisma,
|
|
202
|
+
});
|
|
203
|
+
return NextResponse.json({ error: 'Failed to create run stream' }, { status: 500 });
|
|
204
|
+
}
|
|
205
|
+
const messageResponse = createMessageResponse({
|
|
206
|
+
client: assistantClient,
|
|
207
|
+
createRunStream,
|
|
208
|
+
handleToolCall: handleToolCall({ assistant, thread, prisma }),
|
|
209
|
+
});
|
|
210
|
+
const decoder = new TextDecoder();
|
|
211
|
+
const reader = messageResponse.getReader();
|
|
212
|
+
while (true) {
|
|
213
|
+
const { value, done } = await reader.read();
|
|
214
|
+
if (done)
|
|
215
|
+
break;
|
|
216
|
+
if (!value)
|
|
217
|
+
continue;
|
|
218
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
219
|
+
let event;
|
|
220
|
+
try {
|
|
221
|
+
event = JSON.parse(decoder.decode(value));
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (event.event === 'thread.run.requires_action' &&
|
|
228
|
+
((_b = (_a = event.data) === null || _a === void 0 ? void 0 : _a.required_action) === null || _b === void 0 ? void 0 : _b.type) === 'submit_client_tool_outputs') {
|
|
229
|
+
const toolCalls = event.data.required_action.submit_client_tool_outputs.tool_calls;
|
|
230
|
+
if (Array.isArray(toolCalls)) {
|
|
231
|
+
await Promise.all(toolCalls.map((toolCall) => redis.set(`submit-client-tool-outputs:output:${toolCall.id}`, 'Client tools cannot be used during tasks', { ex: 60 * 60 * 24 * 7 })));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
await scheduleTask({ task, prisma });
|
|
236
|
+
return NextResponse.json({ ok: true });
|
|
237
|
+
};
|
|
238
|
+
export const buildPOST = ({ prisma }) => {
|
|
239
|
+
const postHandler = buildPostHandler({ prisma });
|
|
240
|
+
return process.env.NODE_ENV === 'test' ||
|
|
241
|
+
!process.env.QSTASH_CURRENT_SIGNING_KEY
|
|
242
|
+
? postHandler
|
|
243
|
+
: verifySignatureAppRouter(postHandler);
|
|
244
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/tasks/callback/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/tasks/callback/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,eAAO,MAAM,IAAI,2FAAwB,CAAA"}
|
|
@@ -1,244 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { resolvePrisma } from '../../../../lib/prisma';
|
|
6
|
-
import { assistantClientAdapter } from '../../../../lib/assistants/assistantClientAdapter';
|
|
7
|
-
import { createRunOpts } from '../../../../lib/runs/createRunOpts';
|
|
8
|
-
import { scheduleTask } from '../../../../lib/tasks/scheduleTask';
|
|
9
|
-
import { handleToolCall } from '../../../../lib/toolCalls/handleToolCall';
|
|
10
|
-
import { createLog } from '../../../../lib/logs/createLog';
|
|
11
|
-
import { storageThreadId as getStorageThreadId } from '../../../../lib/threads/storageThreadId';
|
|
12
|
-
import { redis } from '../../../../lib/redis';
|
|
13
|
-
import { isOpenaiAssistantsStorageProvider } from '../../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
|
|
14
|
-
import { managedOpenaiThreadId } from '../../../../lib/threads/managedOpenaiThreadId';
|
|
15
|
-
import { serializeMetadata } from '../../../../lib/metadata/serializeMetadata';
|
|
16
|
-
export const maxDuration = 800;
|
|
17
|
-
const buildPostHandler = ({ prisma: providedPrisma } = {}) => async (request) => {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
20
|
-
const { taskId } = await request.json();
|
|
21
|
-
const task = await prisma.task.findUnique({
|
|
22
|
-
where: { id: taskId },
|
|
23
|
-
include: {
|
|
24
|
-
thread: {
|
|
25
|
-
include: {
|
|
26
|
-
assistant: {
|
|
27
|
-
include: {
|
|
28
|
-
modelProvider: true,
|
|
29
|
-
tools: {
|
|
30
|
-
include: {
|
|
31
|
-
fileSearchTool: true,
|
|
32
|
-
webSearchTool: true,
|
|
33
|
-
imageGenerationTool: true,
|
|
34
|
-
codeInterpreterTool: true,
|
|
35
|
-
computerUseTool: {
|
|
36
|
-
include: {
|
|
37
|
-
mcpServer: {
|
|
38
|
-
include: {
|
|
39
|
-
stdioTransport: true,
|
|
40
|
-
sseTransport: true,
|
|
41
|
-
httpTransport: true,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
functions: {
|
|
49
|
-
include: {
|
|
50
|
-
handler: {
|
|
51
|
-
include: {
|
|
52
|
-
requestHandler: true,
|
|
53
|
-
firecrawlHandler: true,
|
|
54
|
-
replicateHandler: true,
|
|
55
|
-
clientToolHandler: true,
|
|
56
|
-
assistantHandler: true,
|
|
57
|
-
createTaskHandler: true,
|
|
58
|
-
listTasksHandler: true,
|
|
59
|
-
updateTaskHandler: true,
|
|
60
|
-
deleteTaskHandler: true,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
mcpServers: {
|
|
66
|
-
include: {
|
|
67
|
-
computerUseTool: true,
|
|
68
|
-
stdioTransport: true,
|
|
69
|
-
sseTransport: true,
|
|
70
|
-
httpTransport: true,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
if (!task) {
|
|
80
|
-
return NextResponse.json({ error: 'Task not found' }, { status: 400 });
|
|
81
|
-
}
|
|
82
|
-
const assistant = task.thread.assistant;
|
|
83
|
-
const thread = task.thread;
|
|
84
|
-
const assistantClient = assistantClientAdapter({ assistant, prisma });
|
|
85
|
-
let storageThreadId;
|
|
86
|
-
try {
|
|
87
|
-
storageThreadId = getStorageThreadId({
|
|
88
|
-
thread,
|
|
89
|
-
});
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
createLog({
|
|
94
|
-
log: {
|
|
95
|
-
requestMethod: LogRequestMethod.POST,
|
|
96
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
97
|
-
level: LogLevel.ERROR,
|
|
98
|
-
status: 500,
|
|
99
|
-
message: 'Failed to get storage thread id.',
|
|
100
|
-
workspaceId: assistant.workspaceId,
|
|
101
|
-
assistantId: assistant.id,
|
|
102
|
-
threadId: thread.id,
|
|
103
|
-
},
|
|
104
|
-
prisma,
|
|
105
|
-
});
|
|
106
|
-
return NextResponse.json({ error: 'Failed to get storage thread id.' }, { status: 500 });
|
|
107
|
-
}
|
|
108
|
-
if (!storageThreadId &&
|
|
109
|
-
isOpenaiAssistantsStorageProvider({
|
|
110
|
-
storageProviderType: assistant.storageProviderType,
|
|
111
|
-
})) {
|
|
112
|
-
try {
|
|
113
|
-
storageThreadId = await managedOpenaiThreadId({
|
|
114
|
-
assistant,
|
|
115
|
-
threadId: thread.id,
|
|
116
|
-
prisma,
|
|
117
|
-
});
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
createLog({
|
|
122
|
-
log: {
|
|
123
|
-
requestMethod: LogRequestMethod.POST,
|
|
124
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
125
|
-
level: LogLevel.ERROR,
|
|
126
|
-
status: 500,
|
|
127
|
-
message: `Failed to get managed openai thread id: ${error.message}`,
|
|
128
|
-
workspaceId: assistant.workspaceId,
|
|
129
|
-
assistantId: assistant.id,
|
|
130
|
-
threadId: thread.id,
|
|
131
|
-
},
|
|
132
|
-
prisma,
|
|
133
|
-
});
|
|
134
|
-
return NextResponse.json({ error: 'Failed to get managed openai thread id.' }, { status: 500 });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (!storageThreadId) {
|
|
138
|
-
createLog({
|
|
139
|
-
log: {
|
|
140
|
-
requestMethod: LogRequestMethod.POST,
|
|
141
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
142
|
-
level: LogLevel.ERROR,
|
|
143
|
-
status: 500,
|
|
144
|
-
message: 'Invalid thread configuration.',
|
|
145
|
-
workspaceId: assistant.workspaceId,
|
|
146
|
-
assistantId: assistant.id,
|
|
147
|
-
threadId: thread.id,
|
|
148
|
-
},
|
|
149
|
-
prisma,
|
|
150
|
-
});
|
|
151
|
-
return NextResponse.json({ error: 'Invalid thread configuration.' }, { status: 500 });
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
await assistantClient.beta.threads.messages.create(storageThreadId, {
|
|
155
|
-
role: 'user',
|
|
156
|
-
content: task.message,
|
|
157
|
-
metadata: serializeMetadata({
|
|
158
|
-
variables: {
|
|
159
|
-
superinterfaceCreatedByType: 'TASK',
|
|
160
|
-
superinterfaceCreatedById: task.id,
|
|
161
|
-
},
|
|
162
|
-
workspaceId: assistant.workspaceId,
|
|
163
|
-
prisma,
|
|
164
|
-
}),
|
|
165
|
-
});
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.log({ error });
|
|
170
|
-
createLog({
|
|
171
|
-
log: {
|
|
172
|
-
requestMethod: LogRequestMethod.POST,
|
|
173
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
174
|
-
level: LogLevel.ERROR,
|
|
175
|
-
status: 500,
|
|
176
|
-
message: `Failed to create message: ${error.message}`,
|
|
177
|
-
workspaceId: assistant.workspaceId,
|
|
178
|
-
assistantId: assistant.id,
|
|
179
|
-
threadId: thread.id,
|
|
180
|
-
},
|
|
181
|
-
prisma,
|
|
182
|
-
});
|
|
183
|
-
return NextResponse.json({ error: 'Failed to create message' }, { status: 500 });
|
|
184
|
-
}
|
|
185
|
-
let createRunStream;
|
|
186
|
-
try {
|
|
187
|
-
createRunStream = await assistantClient.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread, prisma }));
|
|
188
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
console.log({ error });
|
|
192
|
-
createLog({
|
|
193
|
-
log: {
|
|
194
|
-
requestMethod: LogRequestMethod.POST,
|
|
195
|
-
requestRoute: LogRequestRoute.MESSAGES,
|
|
196
|
-
level: LogLevel.ERROR,
|
|
197
|
-
status: 500,
|
|
198
|
-
message: `Failed to create run stream: ${error.message}`,
|
|
199
|
-
workspaceId: assistant.workspaceId,
|
|
200
|
-
assistantId: assistant.id,
|
|
201
|
-
threadId: thread.id,
|
|
202
|
-
},
|
|
203
|
-
prisma,
|
|
204
|
-
});
|
|
205
|
-
return NextResponse.json({ error: 'Failed to create run stream' }, { status: 500 });
|
|
206
|
-
}
|
|
207
|
-
const messageResponse = createMessageResponse({
|
|
208
|
-
client: assistantClient,
|
|
209
|
-
createRunStream,
|
|
210
|
-
handleToolCall: handleToolCall({ assistant, thread, prisma }),
|
|
211
|
-
});
|
|
212
|
-
const decoder = new TextDecoder();
|
|
213
|
-
const reader = messageResponse.getReader();
|
|
214
|
-
while (true) {
|
|
215
|
-
const { value, done } = await reader.read();
|
|
216
|
-
if (done)
|
|
217
|
-
break;
|
|
218
|
-
if (!value)
|
|
219
|
-
continue;
|
|
220
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
221
|
-
let event;
|
|
222
|
-
try {
|
|
223
|
-
event = JSON.parse(decoder.decode(value));
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
225
|
-
}
|
|
226
|
-
catch (e) {
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
if (event.event === 'thread.run.requires_action' &&
|
|
230
|
-
((_b = (_a = event.data) === null || _a === void 0 ? void 0 : _a.required_action) === null || _b === void 0 ? void 0 : _b.type) === 'submit_client_tool_outputs') {
|
|
231
|
-
await Promise.all(event.data.required_action.submit_client_tool_outputs.tool_calls.map(
|
|
232
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
233
|
-
async (toolCall) => {
|
|
234
|
-
await redis.set(`submit-client-tool-outputs:output:${toolCall.id}`, 'Client tools cannot be used during tasks', { ex: 60 * 60 * 24 * 7 });
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
await scheduleTask({ task, prisma });
|
|
239
|
-
return NextResponse.json({ ok: true });
|
|
240
|
-
};
|
|
241
|
-
const postHandler = buildPostHandler();
|
|
242
|
-
export const POST = process.env.NODE_ENV === 'test' || !process.env.QSTASH_CURRENT_SIGNING_KEY
|
|
243
|
-
? postHandler
|
|
244
|
-
: verifySignatureAppRouter(postHandler);
|
|
1
|
+
import { prisma } from '../../../../lib/prisma';
|
|
2
|
+
import { buildPOST, maxDuration } from './buildRoute';
|
|
3
|
+
export { maxDuration };
|
|
4
|
+
export const POST = buildPOST({ prisma });
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { NextResponse, type NextRequest } from 'next/server';
|
|
3
|
-
export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
4
|
-
prisma?: PrismaClient;
|
|
5
|
-
}) => (request: NextRequest) => Promise<NextResponse<{
|
|
1
|
+
export declare const GET: (request: import("next/server").NextRequest) => Promise<import("next/server").NextResponse<{
|
|
6
2
|
error: string;
|
|
7
|
-
}> | NextResponse<{
|
|
3
|
+
}> | import("next/server").NextResponse<{
|
|
8
4
|
tasks: {
|
|
9
5
|
id: string;
|
|
10
6
|
title: string;
|
|
@@ -16,12 +12,9 @@ export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
|
16
12
|
updatedAt: string;
|
|
17
13
|
}[];
|
|
18
14
|
}>>;
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
21
|
-
prisma?: PrismaClient;
|
|
22
|
-
}) => (request: NextRequest) => Promise<NextResponse<{
|
|
15
|
+
export declare const POST: (request: import("next/server").NextRequest) => Promise<import("next/server").NextResponse<{
|
|
23
16
|
error: string;
|
|
24
|
-
}> | NextResponse<{
|
|
17
|
+
}> | import("next/server").NextResponse<{
|
|
25
18
|
task: {
|
|
26
19
|
id: string;
|
|
27
20
|
title: string;
|
|
@@ -33,6 +26,5 @@ export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
|
33
26
|
updatedAt: string;
|
|
34
27
|
};
|
|
35
28
|
}>>;
|
|
36
|
-
export declare const
|
|
37
|
-
export declare const OPTIONS: () => NextResponse<{}>;
|
|
29
|
+
export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
|
|
38
30
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/tasks/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/tasks/route.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;;;;;;;;;;GAAuB,CAAA;AAEvC,eAAO,MAAM,IAAI;;;;;;;;;;;;;GAAwB,CAAA;AAEzC,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
|