@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,144 @@
|
|
|
1
|
+
import { headers } from 'next/headers';
|
|
2
|
+
import { ApiKeyType, StorageProviderType, ToolType, } from '@prisma/client';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
|
|
6
|
+
import { serializeApiAssistant } from '../../../lib/assistants/serializeApiAssistant';
|
|
7
|
+
import { getApiKey } from '../../../lib/apiKeys/getApiKey';
|
|
8
|
+
const createAssistantSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
storageProviderType: z.nativeEnum(StorageProviderType),
|
|
11
|
+
storageProviderAssistantId: z.string().nullable().optional(),
|
|
12
|
+
modelProviderId: z.string(),
|
|
13
|
+
model: z.string(),
|
|
14
|
+
name: z.string().optional(),
|
|
15
|
+
description: z.string().optional().default(''),
|
|
16
|
+
instructions: z.string().optional().default(''),
|
|
17
|
+
codeInterpreterEnabled: z.boolean().optional().default(false),
|
|
18
|
+
fileSearchEnabled: z.boolean().optional().default(false),
|
|
19
|
+
})
|
|
20
|
+
.superRefine((data, ctx) => {
|
|
21
|
+
if (data.storageProviderType === StorageProviderType.SUPERINTERFACE_CLOUD &&
|
|
22
|
+
data.storageProviderAssistantId) {
|
|
23
|
+
ctx.addIssue({
|
|
24
|
+
code: z.ZodIssueCode.custom,
|
|
25
|
+
message: 'storageProviderAssistantId should not be provided for SUPERINTERFACE_CLOUD',
|
|
26
|
+
path: ['storageProviderAssistantId'],
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (data.storageProviderType !== StorageProviderType.SUPERINTERFACE_CLOUD &&
|
|
30
|
+
!data.storageProviderAssistantId) {
|
|
31
|
+
ctx.addIssue({
|
|
32
|
+
code: z.ZodIssueCode.custom,
|
|
33
|
+
message: 'storageProviderAssistantId is required for this storage provider',
|
|
34
|
+
path: ['storageProviderAssistantId'],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
export const buildGET = ({ prisma }) => async () => {
|
|
39
|
+
const headersList = await headers();
|
|
40
|
+
const authorization = headersList.get('authorization');
|
|
41
|
+
if (!authorization) {
|
|
42
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
43
|
+
}
|
|
44
|
+
const privateApiKey = await getApiKey({
|
|
45
|
+
authorization,
|
|
46
|
+
type: ApiKeyType.PRIVATE,
|
|
47
|
+
prisma,
|
|
48
|
+
});
|
|
49
|
+
if (!privateApiKey) {
|
|
50
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
51
|
+
}
|
|
52
|
+
const assistants = await prisma.assistant.findMany({
|
|
53
|
+
where: {
|
|
54
|
+
workspaceId: privateApiKey.workspaceId,
|
|
55
|
+
},
|
|
56
|
+
include: {
|
|
57
|
+
tools: true,
|
|
58
|
+
avatar: {
|
|
59
|
+
include: {
|
|
60
|
+
imageAvatar: true,
|
|
61
|
+
iconAvatar: true,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
return NextResponse.json({
|
|
67
|
+
assistants: assistants.map((a) => serializeApiAssistant({ assistant: a })),
|
|
68
|
+
}, { headers: cacheHeaders });
|
|
69
|
+
};
|
|
70
|
+
export const buildPOST = ({ prisma }) => async (request) => {
|
|
71
|
+
const headersList = await headers();
|
|
72
|
+
const authorization = headersList.get('authorization');
|
|
73
|
+
if (!authorization) {
|
|
74
|
+
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
75
|
+
}
|
|
76
|
+
const privateApiKey = await getApiKey({
|
|
77
|
+
authorization,
|
|
78
|
+
type: ApiKeyType.PRIVATE,
|
|
79
|
+
prisma,
|
|
80
|
+
});
|
|
81
|
+
if (!privateApiKey) {
|
|
82
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
83
|
+
}
|
|
84
|
+
const parseResult = createAssistantSchema.safeParse(await request.json());
|
|
85
|
+
if (!parseResult.success) {
|
|
86
|
+
return NextResponse.json({
|
|
87
|
+
error: `Missing required fields. ${JSON.stringify(parseResult.error.format())}`,
|
|
88
|
+
}, { status: 400 });
|
|
89
|
+
}
|
|
90
|
+
const { storageProviderType, storageProviderAssistantId, modelProviderId, model, name, description, instructions, codeInterpreterEnabled, fileSearchEnabled, } = parseResult.data;
|
|
91
|
+
const workspaceId = privateApiKey.workspaceId;
|
|
92
|
+
const assistant = await prisma.assistant.create({
|
|
93
|
+
data: {
|
|
94
|
+
workspace: { connect: { id: workspaceId } },
|
|
95
|
+
modelProvider: { connect: { id: modelProviderId } },
|
|
96
|
+
modelSlug: model,
|
|
97
|
+
name,
|
|
98
|
+
description,
|
|
99
|
+
instructions,
|
|
100
|
+
storageProviderType,
|
|
101
|
+
openaiAssistantId: storageProviderAssistantId !== null && storageProviderAssistantId !== void 0 ? storageProviderAssistantId : null,
|
|
102
|
+
tools: {
|
|
103
|
+
create: [
|
|
104
|
+
...(fileSearchEnabled
|
|
105
|
+
? [
|
|
106
|
+
{
|
|
107
|
+
type: ToolType.FILE_SEARCH,
|
|
108
|
+
fileSearchTool: {
|
|
109
|
+
create: {},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
]
|
|
113
|
+
: []),
|
|
114
|
+
...(codeInterpreterEnabled
|
|
115
|
+
? [
|
|
116
|
+
{
|
|
117
|
+
type: ToolType.CODE_INTERPRETER,
|
|
118
|
+
codeInterpreterTool: {
|
|
119
|
+
create: {},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
]
|
|
123
|
+
: []),
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
include: {
|
|
128
|
+
tools: true,
|
|
129
|
+
avatar: {
|
|
130
|
+
include: {
|
|
131
|
+
imageAvatar: true,
|
|
132
|
+
iconAvatar: true,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
return NextResponse.json({
|
|
138
|
+
assistant: serializeApiAssistant({ assistant }),
|
|
139
|
+
}, { headers: cacheHeaders });
|
|
140
|
+
};
|
|
141
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
142
|
+
headers: cacheHeaders,
|
|
143
|
+
});
|
|
144
|
+
export { createAssistantSchema };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
prisma?: PrismaClient;
|
|
5
|
-
}) => () => Promise<NextResponse<{
|
|
1
|
+
import { createAssistantSchema } from './buildRoute';
|
|
2
|
+
export { createAssistantSchema };
|
|
3
|
+
export declare const GET: () => Promise<import("next/server").NextResponse<{
|
|
6
4
|
error: string;
|
|
7
|
-
}> | NextResponse<{
|
|
5
|
+
}> | import("next/server").NextResponse<{
|
|
8
6
|
assistants: {
|
|
9
7
|
id: string;
|
|
10
8
|
storageProviderType: import("@prisma/client").$Enums.StorageProviderType;
|
|
@@ -29,12 +27,9 @@ export declare const buildGET: ({ prisma: providedPrisma }?: {
|
|
|
29
27
|
};
|
|
30
28
|
}[];
|
|
31
29
|
}>>;
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
34
|
-
prisma?: PrismaClient;
|
|
35
|
-
}) => (request: Request) => Promise<NextResponse<{
|
|
30
|
+
export declare const POST: (request: Request) => Promise<import("next/server").NextResponse<{
|
|
36
31
|
error: string;
|
|
37
|
-
}> | NextResponse<{
|
|
32
|
+
}> | import("next/server").NextResponse<{
|
|
38
33
|
assistant: {
|
|
39
34
|
id: string;
|
|
40
35
|
storageProviderType: import("@prisma/client").$Enums.StorageProviderType;
|
|
@@ -59,6 +54,5 @@ export declare const buildPOST: ({ prisma: providedPrisma }?: {
|
|
|
59
54
|
};
|
|
60
55
|
};
|
|
61
56
|
}>>;
|
|
62
|
-
export declare const
|
|
63
|
-
export declare const OPTIONS: () => NextResponse<{}>;
|
|
57
|
+
export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
|
|
64
58
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/assistants/route.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/assistants/route.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,qBAAqB,EACtB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAEhC,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GAAuB,CAAA;AAEvC,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;GAAwB,CAAA;AAEzC,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
|
|
@@ -1,148 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { serializeApiAssistant } from '../../../lib/assistants/serializeApiAssistant';
|
|
8
|
-
import { getApiKey } from '../../../lib/apiKeys/getApiKey';
|
|
9
|
-
export const buildGET = ({ prisma: providedPrisma } = {}) => async () => {
|
|
10
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
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 assistants = await prisma.assistant.findMany({
|
|
25
|
-
where: {
|
|
26
|
-
workspaceId: privateApiKey.workspaceId,
|
|
27
|
-
},
|
|
28
|
-
include: {
|
|
29
|
-
tools: true,
|
|
30
|
-
avatar: {
|
|
31
|
-
include: {
|
|
32
|
-
imageAvatar: true,
|
|
33
|
-
iconAvatar: true,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
return NextResponse.json({
|
|
39
|
-
assistants: assistants.map((a) => serializeApiAssistant({ assistant: a })),
|
|
40
|
-
}, { headers: cacheHeaders });
|
|
41
|
-
};
|
|
42
|
-
export const GET = ((...args) => buildGET()(...args));
|
|
43
|
-
const createAssistantSchema = z
|
|
44
|
-
.object({
|
|
45
|
-
storageProviderType: z.nativeEnum(StorageProviderType),
|
|
46
|
-
storageProviderAssistantId: z.string().nullable().optional(),
|
|
47
|
-
modelProviderId: z.string(),
|
|
48
|
-
model: z.string(),
|
|
49
|
-
name: z.string().optional(),
|
|
50
|
-
description: z.string().optional().default(''),
|
|
51
|
-
instructions: z.string().optional().default(''),
|
|
52
|
-
codeInterpreterEnabled: z.boolean().optional().default(false),
|
|
53
|
-
fileSearchEnabled: z.boolean().optional().default(false),
|
|
54
|
-
})
|
|
55
|
-
.superRefine((data, ctx) => {
|
|
56
|
-
if (data.storageProviderType === StorageProviderType.SUPERINTERFACE_CLOUD &&
|
|
57
|
-
data.storageProviderAssistantId) {
|
|
58
|
-
ctx.addIssue({
|
|
59
|
-
code: z.ZodIssueCode.custom,
|
|
60
|
-
message: 'storageProviderAssistantId should not be provided for SUPERINTERFACE_CLOUD',
|
|
61
|
-
path: ['storageProviderAssistantId'],
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
if (data.storageProviderType !== StorageProviderType.SUPERINTERFACE_CLOUD &&
|
|
65
|
-
!data.storageProviderAssistantId) {
|
|
66
|
-
ctx.addIssue({
|
|
67
|
-
code: z.ZodIssueCode.custom,
|
|
68
|
-
message: 'storageProviderAssistantId is required for this storage provider',
|
|
69
|
-
path: ['storageProviderAssistantId'],
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
export const buildPOST = ({ prisma: providedPrisma } = {}) => async (request) => {
|
|
74
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
75
|
-
const headersList = await headers();
|
|
76
|
-
const authorization = headersList.get('authorization');
|
|
77
|
-
if (!authorization) {
|
|
78
|
-
return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
|
|
79
|
-
}
|
|
80
|
-
const privateApiKey = await getApiKey({
|
|
81
|
-
authorization,
|
|
82
|
-
type: ApiKeyType.PRIVATE,
|
|
83
|
-
prisma,
|
|
84
|
-
});
|
|
85
|
-
if (!privateApiKey) {
|
|
86
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
87
|
-
}
|
|
88
|
-
const parseResult = createAssistantSchema.safeParse(await request.json());
|
|
89
|
-
if (!parseResult.success) {
|
|
90
|
-
return NextResponse.json({
|
|
91
|
-
error: `Missing required fields. ${JSON.stringify(parseResult.error.format())}`,
|
|
92
|
-
}, { status: 400 });
|
|
93
|
-
}
|
|
94
|
-
const { storageProviderType, storageProviderAssistantId, modelProviderId, model, name, description, instructions, codeInterpreterEnabled, fileSearchEnabled, } = parseResult.data;
|
|
95
|
-
const workspaceId = privateApiKey.workspaceId;
|
|
96
|
-
const assistant = await prisma.assistant.create({
|
|
97
|
-
data: {
|
|
98
|
-
workspace: { connect: { id: workspaceId } },
|
|
99
|
-
modelProvider: { connect: { id: modelProviderId } },
|
|
100
|
-
modelSlug: model,
|
|
101
|
-
name,
|
|
102
|
-
description,
|
|
103
|
-
instructions,
|
|
104
|
-
storageProviderType,
|
|
105
|
-
openaiAssistantId: storageProviderAssistantId !== null && storageProviderAssistantId !== void 0 ? storageProviderAssistantId : null,
|
|
106
|
-
tools: {
|
|
107
|
-
create: [
|
|
108
|
-
...(fileSearchEnabled
|
|
109
|
-
? [
|
|
110
|
-
{
|
|
111
|
-
type: ToolType.FILE_SEARCH,
|
|
112
|
-
fileSearchTool: {
|
|
113
|
-
create: {},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
]
|
|
117
|
-
: []),
|
|
118
|
-
...(codeInterpreterEnabled
|
|
119
|
-
? [
|
|
120
|
-
{
|
|
121
|
-
type: ToolType.CODE_INTERPRETER,
|
|
122
|
-
codeInterpreterTool: {
|
|
123
|
-
create: {},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
]
|
|
127
|
-
: []),
|
|
128
|
-
],
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
include: {
|
|
132
|
-
tools: true,
|
|
133
|
-
avatar: {
|
|
134
|
-
include: {
|
|
135
|
-
imageAvatar: true,
|
|
136
|
-
iconAvatar: true,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
return NextResponse.json({
|
|
142
|
-
assistant: serializeApiAssistant({ assistant }),
|
|
143
|
-
}, { headers: cacheHeaders });
|
|
144
|
-
};
|
|
145
|
-
export const POST = ((...args) => buildPOST()(...args));
|
|
146
|
-
export const OPTIONS = () => NextResponse.json({}, {
|
|
147
|
-
headers: cacheHeaders,
|
|
148
|
-
});
|
|
1
|
+
import { prisma } from '../../../lib/prisma';
|
|
2
|
+
import { buildGET, buildOPTIONS, buildPOST, createAssistantSchema, } from './buildRoute';
|
|
3
|
+
export { createAssistantSchema };
|
|
4
|
+
export const GET = buildGET({ prisma });
|
|
5
|
+
export const POST = buildPOST({ prisma });
|
|
6
|
+
export const OPTIONS = buildOPTIONS();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OpenAI } from 'openai';
|
|
2
|
+
import { type Prisma, type PrismaClient } from '@prisma/client';
|
|
3
|
+
import { type NextRequest, NextResponse } from 'next/server';
|
|
4
|
+
type PurposeAssistantsResponse = ({ file, workspaceAccessWhere, }: {
|
|
5
|
+
file: OpenAI.Files.FileObject;
|
|
6
|
+
workspaceAccessWhere: Prisma.WorkspaceWhereInput;
|
|
7
|
+
}) => Promise<NextResponse> | NextResponse;
|
|
8
|
+
export declare const buildGET: ({ prisma, purposeAssistantsResponse, }: {
|
|
9
|
+
prisma: PrismaClient;
|
|
10
|
+
purposeAssistantsResponse?: PurposeAssistantsResponse;
|
|
11
|
+
}) => (request: NextRequest, props: {
|
|
12
|
+
params: Promise<{
|
|
13
|
+
fileId: string;
|
|
14
|
+
}>;
|
|
15
|
+
}) => Promise<NextResponse<unknown>>;
|
|
16
|
+
export declare const buildOPTIONS: () => () => NextResponse<{}>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=buildRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/files/[fileId]/contents/buildRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM5D,KAAK,yBAAyB,GAAG,CAAC,EAChC,IAAI,EACJ,oBAAoB,GACrB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAA;IAC7B,oBAAoB,EAAE,MAAM,CAAC,mBAAmB,CAAA;CACjD,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAA;AAE1C,eAAO,MAAM,QAAQ,GAClB,wCAIE;IACD,MAAM,EAAE,YAAY,CAAA;IACpB,yBAAyB,CAAC,EAAE,yBAAyB,CAAA;CACtD,MAEC,SAAS,WAAW,EACpB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QACd,MAAM,EAAE,MAAM,CAAA;KACf,CAAC,CAAA;CACH,mCA6GF,CAAA;AAEH,eAAO,MAAM,YAAY,8BAMtB,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isString } from 'radash';
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
import { cacheHeaders } from '../../../../../lib/cache/cacheHeaders';
|
|
4
|
+
import { assistantClientAdapter } from '../../../../../lib/assistants/assistantClientAdapter';
|
|
5
|
+
import { workspaceAccessWhere as getWorkspaceAccessWhere } from '../../../../../lib/apiKeys/workspaceAccessWhere';
|
|
6
|
+
import { isOpenaiAssistantsStorageProvider } from '../../../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
|
|
7
|
+
export const buildGET = ({ prisma, purposeAssistantsResponse = () => NextResponse.json({ error: 'No file source found' }, { status: 404 }), }) => async (request, props) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const params = await props.params;
|
|
10
|
+
const { fileId } = params;
|
|
11
|
+
const assistantId = request.nextUrl.searchParams.get('assistantId');
|
|
12
|
+
if (!isString(assistantId)) {
|
|
13
|
+
return NextResponse.json({ error: 'Invalid assistantId' }, { status: 400 });
|
|
14
|
+
}
|
|
15
|
+
const publicApiKey = request.nextUrl.searchParams.get('publicApiKey');
|
|
16
|
+
if (!isString(publicApiKey)) {
|
|
17
|
+
return NextResponse.json({ error: 'Invalid publicApiKey' }, { status: 400 });
|
|
18
|
+
}
|
|
19
|
+
const workspaceAccessWhere = await getWorkspaceAccessWhere({
|
|
20
|
+
publicApiKey,
|
|
21
|
+
prisma,
|
|
22
|
+
});
|
|
23
|
+
if (!workspaceAccessWhere) {
|
|
24
|
+
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
25
|
+
}
|
|
26
|
+
if (!assistantId) {
|
|
27
|
+
return NextResponse.json({ error: 'No assistantId found' }, { status: 400 });
|
|
28
|
+
}
|
|
29
|
+
const assistant = await prisma.assistant.findFirst({
|
|
30
|
+
where: {
|
|
31
|
+
id: assistantId,
|
|
32
|
+
workspace: workspaceAccessWhere,
|
|
33
|
+
},
|
|
34
|
+
include: {
|
|
35
|
+
modelProvider: true,
|
|
36
|
+
tools: {
|
|
37
|
+
include: {
|
|
38
|
+
fileSearchTool: true,
|
|
39
|
+
webSearchTool: true,
|
|
40
|
+
imageGenerationTool: true,
|
|
41
|
+
codeInterpreterTool: true,
|
|
42
|
+
computerUseTool: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
mcpServers: {
|
|
46
|
+
include: {
|
|
47
|
+
computerUseTool: true,
|
|
48
|
+
stdioTransport: true,
|
|
49
|
+
sseTransport: true,
|
|
50
|
+
httpTransport: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
functions: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
if (!assistant) {
|
|
57
|
+
return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
|
|
58
|
+
}
|
|
59
|
+
if (isOpenaiAssistantsStorageProvider({
|
|
60
|
+
storageProviderType: assistant.storageProviderType,
|
|
61
|
+
}) &&
|
|
62
|
+
!assistant.openaiAssistantId) {
|
|
63
|
+
return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
|
|
64
|
+
}
|
|
65
|
+
const assistantClient = assistantClientAdapter({ assistant, prisma });
|
|
66
|
+
const file = await assistantClient.files.retrieve(fileId);
|
|
67
|
+
if (!file) {
|
|
68
|
+
return NextResponse.json({ error: 'No file found' }, { status: 404 });
|
|
69
|
+
}
|
|
70
|
+
if (file.purpose === 'assistants') {
|
|
71
|
+
return purposeAssistantsResponse({ file, workspaceAccessWhere });
|
|
72
|
+
}
|
|
73
|
+
const fileContentResponse = await assistantClient.files.content(fileId);
|
|
74
|
+
const fileData = await fileContentResponse.arrayBuffer();
|
|
75
|
+
return new NextResponse(fileData, {
|
|
76
|
+
headers: Object.assign(Object.assign({}, cacheHeaders), { 'Content-Type': (_a = fileContentResponse.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'application/octet-stream', 'Content-Disposition': (_b = fileContentResponse.headers.get('Content-Disposition')) !== null && _b !== void 0 ? _b : 'inline' }),
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
export const buildOPTIONS = () => () => NextResponse.json({}, {
|
|
80
|
+
headers: cacheHeaders,
|
|
81
|
+
});
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { type Prisma, type PrismaClient } from '@prisma/client';
|
|
3
|
-
import { type NextRequest, NextResponse } from 'next/server';
|
|
4
|
-
export declare const buildGET: ({ prisma: providedPrisma, purposeAssistantsResponse, }?: {
|
|
5
|
-
prisma?: PrismaClient;
|
|
6
|
-
purposeAssistantsResponse?: ({ file, }: {
|
|
7
|
-
file: OpenAI.Files.FileObject;
|
|
8
|
-
workspaceAccessWhere: Prisma.WorkspaceWhereInput;
|
|
9
|
-
}) => Promise<NextResponse> | NextResponse;
|
|
10
|
-
}) => (request: NextRequest, props: {
|
|
1
|
+
export declare const GET: (request: import("next/server").NextRequest, props: {
|
|
11
2
|
params: Promise<{
|
|
12
3
|
fileId: string;
|
|
13
4
|
}>;
|
|
14
|
-
}) => Promise<NextResponse<unknown>>;
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const OPTIONS: () => NextResponse<{}>;
|
|
5
|
+
}) => Promise<import("next/server").NextResponse<unknown>>;
|
|
6
|
+
export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
|
|
17
7
|
//# sourceMappingURL=route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/files/[fileId]/contents/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/files/[fileId]/contents/route.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;0DAAuB,CAAA;AAEvC,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
|
|
@@ -1,84 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { workspaceAccessWhere as getWorkspaceAccessWhere } from '../../../../../lib/apiKeys/workspaceAccessWhere';
|
|
6
|
-
import { resolvePrisma } from '../../../../../lib/prisma';
|
|
7
|
-
import { isOpenaiAssistantsStorageProvider } from '../../../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
|
|
8
|
-
export const buildGET = ({ prisma: providedPrisma, purposeAssistantsResponse = () => NextResponse.json({ error: 'No file source found' }, { status: 404 }), } = {}) => async (request, props) => {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
const prisma = resolvePrisma(providedPrisma);
|
|
11
|
-
const params = await props.params;
|
|
12
|
-
const { fileId } = params;
|
|
13
|
-
const assistantId = request.nextUrl.searchParams.get('assistantId');
|
|
14
|
-
if (!isString(assistantId)) {
|
|
15
|
-
return NextResponse.json({ error: 'Invalid assistantId' }, { status: 400 });
|
|
16
|
-
}
|
|
17
|
-
const publicApiKey = request.nextUrl.searchParams.get('publicApiKey');
|
|
18
|
-
if (!isString(publicApiKey)) {
|
|
19
|
-
return NextResponse.json({ error: 'Invalid publicApiKey' }, { status: 400 });
|
|
20
|
-
}
|
|
21
|
-
const workspaceAccessWhere = await getWorkspaceAccessWhere({
|
|
22
|
-
publicApiKey,
|
|
23
|
-
prisma,
|
|
24
|
-
});
|
|
25
|
-
if (!workspaceAccessWhere) {
|
|
26
|
-
return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
|
|
27
|
-
}
|
|
28
|
-
if (!assistantId) {
|
|
29
|
-
return NextResponse.json({ error: 'No assistantId found' }, { status: 400 });
|
|
30
|
-
}
|
|
31
|
-
const assistant = await prisma.assistant.findFirst({
|
|
32
|
-
where: {
|
|
33
|
-
id: assistantId,
|
|
34
|
-
workspace: workspaceAccessWhere,
|
|
35
|
-
},
|
|
36
|
-
include: {
|
|
37
|
-
modelProvider: true,
|
|
38
|
-
tools: {
|
|
39
|
-
include: {
|
|
40
|
-
fileSearchTool: true,
|
|
41
|
-
webSearchTool: true,
|
|
42
|
-
imageGenerationTool: true,
|
|
43
|
-
codeInterpreterTool: true,
|
|
44
|
-
computerUseTool: true,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
mcpServers: {
|
|
48
|
-
include: {
|
|
49
|
-
computerUseTool: true,
|
|
50
|
-
stdioTransport: true,
|
|
51
|
-
sseTransport: true,
|
|
52
|
-
httpTransport: true,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
functions: true,
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
if (!assistant) {
|
|
59
|
-
return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
|
|
60
|
-
}
|
|
61
|
-
if (isOpenaiAssistantsStorageProvider({
|
|
62
|
-
storageProviderType: assistant.storageProviderType,
|
|
63
|
-
}) &&
|
|
64
|
-
!assistant.openaiAssistantId) {
|
|
65
|
-
return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
|
|
66
|
-
}
|
|
67
|
-
const assistantClient = assistantClientAdapter({ assistant, prisma });
|
|
68
|
-
const file = await assistantClient.files.retrieve(fileId);
|
|
69
|
-
if (!file) {
|
|
70
|
-
return NextResponse.json({ error: 'No file found' }, { status: 404 });
|
|
71
|
-
}
|
|
72
|
-
if (file.purpose === 'assistants') {
|
|
73
|
-
return purposeAssistantsResponse({ file, workspaceAccessWhere });
|
|
74
|
-
}
|
|
75
|
-
const fileContentResponse = await assistantClient.files.content(fileId);
|
|
76
|
-
const fileData = await fileContentResponse.arrayBuffer();
|
|
77
|
-
return new NextResponse(fileData, {
|
|
78
|
-
headers: Object.assign(Object.assign({}, cacheHeaders), { 'Content-Type': (_a = fileContentResponse.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'application/octet-stream', 'Content-Disposition': (_b = fileContentResponse.headers.get('Content-Disposition')) !== null && _b !== void 0 ? _b : 'inline' }),
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
export const GET = ((...args) => buildGET({})(...args));
|
|
82
|
-
export const OPTIONS = () => NextResponse.json({}, {
|
|
83
|
-
headers: cacheHeaders,
|
|
84
|
-
});
|
|
1
|
+
import { prisma } from '../../../../../lib/prisma';
|
|
2
|
+
import { buildGET, buildOPTIONS } from './buildRoute';
|
|
3
|
+
export const GET = buildGET({ prisma });
|
|
4
|
+
export const OPTIONS = buildOPTIONS();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type OpenAI from 'openai';
|
|
2
|
+
import { type PrismaClient } from '@prisma/client';
|
|
3
|
+
import { type NextRequest, NextResponse } from 'next/server';
|
|
4
|
+
export declare const buildPOST: ({ prisma }: {
|
|
5
|
+
prisma: PrismaClient;
|
|
6
|
+
}) => (request: NextRequest) => Promise<NextResponse<{
|
|
7
|
+
error: string;
|
|
8
|
+
}> | NextResponse<{
|
|
9
|
+
file: OpenAI.Files.FileObject & {
|
|
10
|
+
_request_id?: string | null;
|
|
11
|
+
};
|
|
12
|
+
}>>;
|
|
13
|
+
export declare const buildOPTIONS: () => () => NextResponse<{}>;
|
|
14
|
+
//# sourceMappingURL=buildRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../src/app/api/files/buildRoute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM5D,eAAO,MAAM,SAAS,GACnB,YAAY;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,MAC9B,SAAS,WAAW;;;;;;GA8G1B,CAAA;AAEH,eAAO,MAAM,YAAY,8BAMtB,CAAA"}
|