@superinterface/server 1.0.17 → 1.0.19

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.
Files changed (250) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +2 -2
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/eslint/.cache_btwyo7 +1 -1
  5. package/.next/fallback-build-manifest.json +2 -2
  6. package/.next/server/app/_not-found.html +1 -1
  7. package/.next/server/app/_not-found.rsc +1 -1
  8. package/.next/server/app/api/files/[fileId]/contents/route.js +1 -1
  9. package/.next/server/app/api/files/[fileId]/contents/route.js.nft.json +1 -1
  10. package/.next/server/app/api/files/route.js +1 -1
  11. package/.next/server/app/api/files/route.js.nft.json +1 -1
  12. package/.next/server/app/api/messages/route.js +3 -3
  13. package/.next/server/app/api/messages/route.js.nft.json +1 -1
  14. package/.next/server/app/index.html +1 -1
  15. package/.next/server/app/index.rsc +1 -1
  16. package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js +1 -1
  17. package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js.map +1 -1
  18. package/.next/server/chunks/[root-of-the-server]__13c6bd62._.js +1 -1
  19. package/.next/server/chunks/[root-of-the-server]__13c6bd62._.js.map +1 -1
  20. package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js +1 -1
  21. package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js.map +1 -1
  22. package/.next/server/chunks/[root-of-the-server]__27aadac9._.js +1 -1
  23. package/.next/server/chunks/[root-of-the-server]__27aadac9._.js.map +1 -1
  24. package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js +1 -1
  25. package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js.map +1 -1
  26. package/.next/server/chunks/[root-of-the-server]__29635e8e._.js +1 -1
  27. package/.next/server/chunks/[root-of-the-server]__29635e8e._.js.map +1 -1
  28. package/.next/server/chunks/[root-of-the-server]__29b43490._.js +2 -2
  29. package/.next/server/chunks/[root-of-the-server]__29b43490._.js.map +1 -1
  30. package/.next/server/chunks/[root-of-the-server]__315f084a._.js +1 -1
  31. package/.next/server/chunks/[root-of-the-server]__315f084a._.js.map +1 -1
  32. package/.next/server/chunks/[root-of-the-server]__441cee00._.js +1 -1
  33. package/.next/server/chunks/[root-of-the-server]__441cee00._.js.map +1 -1
  34. package/.next/server/chunks/[root-of-the-server]__464a4377._.js +1 -1
  35. package/.next/server/chunks/[root-of-the-server]__464a4377._.js.map +1 -1
  36. package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js +1 -1
  37. package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js.map +1 -1
  38. package/.next/server/chunks/[root-of-the-server]__51977f30._.js +1 -1
  39. package/.next/server/chunks/[root-of-the-server]__51977f30._.js.map +1 -1
  40. package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js +1 -1
  41. package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js.map +1 -1
  42. package/.next/server/chunks/[root-of-the-server]__5abf1160._.js +1 -1
  43. package/.next/server/chunks/[root-of-the-server]__5abf1160._.js.map +1 -1
  44. package/.next/server/chunks/[root-of-the-server]__5d09614a._.js +1 -1
  45. package/.next/server/chunks/[root-of-the-server]__5d09614a._.js.map +1 -1
  46. package/.next/server/chunks/[root-of-the-server]__62d958e7._.js +1 -1
  47. package/.next/server/chunks/[root-of-the-server]__62d958e7._.js.map +1 -1
  48. package/.next/server/chunks/[root-of-the-server]__7f9ca1e3._.js +1 -1
  49. package/.next/server/chunks/[root-of-the-server]__7f9ca1e3._.js.map +1 -1
  50. package/.next/server/chunks/[root-of-the-server]__83461316._.js +1 -1
  51. package/.next/server/chunks/[root-of-the-server]__83461316._.js.map +1 -1
  52. package/.next/server/chunks/[root-of-the-server]__9a611d42._.js +1 -1
  53. package/.next/server/chunks/[root-of-the-server]__9a611d42._.js.map +1 -1
  54. package/.next/server/chunks/[root-of-the-server]__a135e388._.js +1 -1
  55. package/.next/server/chunks/[root-of-the-server]__a135e388._.js.map +1 -1
  56. package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js +1 -1
  57. package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js.map +1 -1
  58. package/.next/server/chunks/[root-of-the-server]__b9a334c3._.js +1 -1
  59. package/.next/server/chunks/[root-of-the-server]__b9a334c3._.js.map +1 -1
  60. package/.next/server/chunks/[root-of-the-server]__c1629392._.js +1 -1
  61. package/.next/server/chunks/[root-of-the-server]__c1629392._.js.map +1 -1
  62. package/.next/server/chunks/[root-of-the-server]__dd176cb5._.js +2 -2
  63. package/.next/server/chunks/[root-of-the-server]__dd176cb5._.js.map +1 -1
  64. package/.next/server/chunks/[root-of-the-server]__eb816e13._.js +1 -1
  65. package/.next/server/chunks/[root-of-the-server]__eb816e13._.js.map +1 -1
  66. package/.next/server/chunks/[root-of-the-server]__ed6cf593._.js +1 -1
  67. package/.next/server/chunks/[root-of-the-server]__ed6cf593._.js.map +1 -1
  68. package/.next/server/chunks/{[root-of-the-server]__30845206._.js → [root-of-the-server]__ff90af03._.js} +3 -3
  69. package/.next/server/chunks/{[root-of-the-server]__30845206._.js.map → [root-of-the-server]__ff90af03._.js.map} +1 -1
  70. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js +1 -1
  71. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js.map +1 -1
  72. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js +1 -1
  73. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js.map +1 -1
  74. package/.next/server/chunks/supercorp_superinterface_bebd2c96._.js +2 -2
  75. package/.next/server/chunks/supercorp_superinterface_bebd2c96._.js.map +1 -1
  76. package/.next/server/pages/404.html +1 -1
  77. package/.next/server/pages/500.html +1 -1
  78. package/.next/trace +1 -1
  79. package/bin/index.cjs +2 -0
  80. package/dist/app/api/api-keys/[apiKeyId]/route.d.ts +55 -0
  81. package/dist/app/api/api-keys/[apiKeyId]/route.d.ts.map +1 -1
  82. package/dist/app/api/api-keys/[apiKeyId]/route.js +10 -4
  83. package/dist/app/api/api-keys/route.d.ts +29 -0
  84. package/dist/app/api/api-keys/route.d.ts.map +1 -1
  85. package/dist/app/api/api-keys/route.js +8 -3
  86. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts +172 -0
  87. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts.map +1 -1
  88. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.js +11 -4
  89. package/dist/app/api/assistants/[assistantId]/functions/route.d.ts +113 -0
  90. package/dist/app/api/assistants/[assistantId]/functions/route.d.ts.map +1 -1
  91. package/dist/app/api/assistants/[assistantId]/functions/route.js +8 -3
  92. package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts +39 -0
  93. package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts.map +1 -1
  94. package/dist/app/api/assistants/[assistantId]/initial-messages/route.js +8 -3
  95. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts +94 -0
  96. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts.map +1 -1
  97. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +10 -4
  98. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts +61 -0
  99. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts.map +1 -1
  100. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.js +7 -3
  101. package/dist/app/api/assistants/[assistantId]/route.d.ts +123 -0
  102. package/dist/app/api/assistants/[assistantId]/route.d.ts.map +1 -1
  103. package/dist/app/api/assistants/[assistantId]/route.js +15 -6
  104. package/dist/app/api/assistants/route.d.ts +59 -0
  105. package/dist/app/api/assistants/route.d.ts.map +1 -1
  106. package/dist/app/api/assistants/route.js +8 -4
  107. package/dist/app/api/files/[fileId]/contents/route.d.ts +3 -2
  108. package/dist/app/api/files/[fileId]/contents/route.d.ts.map +1 -1
  109. package/dist/app/api/files/[fileId]/contents/route.js +6 -3
  110. package/dist/app/api/files/route.d.ts +10 -0
  111. package/dist/app/api/files/route.d.ts.map +1 -1
  112. package/dist/app/api/files/route.js +7 -3
  113. package/dist/app/api/messages/route.d.ts +24 -1
  114. package/dist/app/api/messages/route.d.ts.map +1 -1
  115. package/dist/app/api/messages/route.js +27 -6
  116. package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts +19 -0
  117. package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts.map +1 -1
  118. package/dist/app/api/providers/[modelProviderId]/assistants/route.js +4 -2
  119. package/dist/app/api/providers/[modelProviderId]/models/route.d.ts +14 -0
  120. package/dist/app/api/providers/[modelProviderId]/models/route.d.ts.map +1 -1
  121. package/dist/app/api/providers/[modelProviderId]/models/route.js +4 -2
  122. package/dist/app/api/providers/[modelProviderId]/route.d.ts +64 -0
  123. package/dist/app/api/providers/[modelProviderId]/route.d.ts.map +1 -1
  124. package/dist/app/api/providers/[modelProviderId]/route.js +12 -6
  125. package/dist/app/api/providers/route.d.ts +35 -0
  126. package/dist/app/api/providers/route.d.ts.map +1 -1
  127. package/dist/app/api/providers/route.js +9 -5
  128. package/dist/app/api/tasks/[taskId]/route.d.ts +61 -0
  129. package/dist/app/api/tasks/[taskId]/route.d.ts.map +1 -1
  130. package/dist/app/api/tasks/[taskId]/route.js +11 -5
  131. package/dist/app/api/tasks/callback/route.d.ts.map +1 -1
  132. package/dist/app/api/tasks/callback/route.js +14 -6
  133. package/dist/app/api/tasks/route.d.ts +33 -0
  134. package/dist/app/api/tasks/route.d.ts.map +1 -1
  135. package/dist/app/api/tasks/route.js +8 -4
  136. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts +9 -1
  137. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts.map +1 -1
  138. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.js +5 -3
  139. package/dist/app/api/workspaces/[workspaceId]/route.d.ts +33 -0
  140. package/dist/app/api/workspaces/[workspaceId]/route.d.ts.map +1 -1
  141. package/dist/app/api/workspaces/[workspaceId]/route.js +7 -3
  142. package/dist/app/api/workspaces/route.d.ts +17 -3
  143. package/dist/app/api/workspaces/route.d.ts.map +1 -1
  144. package/dist/app/api/workspaces/route.js +8 -4
  145. package/dist/lib/apiKeys/getApiKey.d.ts +3 -2
  146. package/dist/lib/apiKeys/getApiKey.d.ts.map +1 -1
  147. package/dist/lib/apiKeys/getApiKey.js +1 -2
  148. package/dist/lib/apiKeys/workspaceAccessWhere.d.ts +3 -1
  149. package/dist/lib/apiKeys/workspaceAccessWhere.d.ts.map +1 -1
  150. package/dist/lib/apiKeys/workspaceAccessWhere.js +2 -1
  151. package/dist/lib/assistants/assistantClientAdapter/buildGetOpenaiAssistant.d.ts +3 -2
  152. package/dist/lib/assistants/assistantClientAdapter/buildGetOpenaiAssistant.d.ts.map +1 -1
  153. package/dist/lib/assistants/assistantClientAdapter/buildGetOpenaiAssistant.js +3 -3
  154. package/dist/lib/assistants/assistantClientAdapter/index.d.ts.map +1 -1
  155. package/dist/lib/assistants/assistantClientAdapter/index.js +7 -2
  156. package/dist/lib/computerCalls/handleComputerCall/index.d.ts +3 -2
  157. package/dist/lib/computerCalls/handleComputerCall/index.d.ts.map +1 -1
  158. package/dist/lib/computerCalls/handleComputerCall/index.js +5 -1
  159. package/dist/lib/functions/createFunction.d.ts +2 -1
  160. package/dist/lib/functions/createFunction.d.ts.map +1 -1
  161. package/dist/lib/functions/createFunction.js +2 -2
  162. package/dist/lib/functions/handleFunction/handleAssistant.d.ts +3 -2
  163. package/dist/lib/functions/handleFunction/handleAssistant.d.ts.map +1 -1
  164. package/dist/lib/functions/handleFunction/handleAssistant.js +12 -2
  165. package/dist/lib/functions/handleFunction/handleClientTool.d.ts +3 -2
  166. package/dist/lib/functions/handleFunction/handleClientTool.d.ts.map +1 -1
  167. package/dist/lib/functions/handleFunction/handleClientTool.js +2 -1
  168. package/dist/lib/functions/handleFunction/handleFirecrawl.d.ts +3 -2
  169. package/dist/lib/functions/handleFunction/handleFirecrawl.d.ts.map +1 -1
  170. package/dist/lib/functions/handleFunction/handleFirecrawl.js +7 -1
  171. package/dist/lib/functions/handleFunction/handleReplicate.d.ts +3 -2
  172. package/dist/lib/functions/handleFunction/handleReplicate.d.ts.map +1 -1
  173. package/dist/lib/functions/handleFunction/handleReplicate.js +4 -1
  174. package/dist/lib/functions/handleFunction/handleRequest.d.ts +3 -2
  175. package/dist/lib/functions/handleFunction/handleRequest.d.ts.map +1 -1
  176. package/dist/lib/functions/handleFunction/handleRequest.js +6 -1
  177. package/dist/lib/functions/handleFunction/index.d.ts +3 -2
  178. package/dist/lib/functions/handleFunction/index.d.ts.map +1 -1
  179. package/dist/lib/functions/handleFunction/index.js +25 -1
  180. package/dist/lib/functions/handleFunction/tasks/handleCreateTask.d.ts +3 -2
  181. package/dist/lib/functions/handleFunction/tasks/handleCreateTask.d.ts.map +1 -1
  182. package/dist/lib/functions/handleFunction/tasks/handleCreateTask.js +4 -4
  183. package/dist/lib/functions/handleFunction/tasks/handleDeleteTask.d.ts +3 -2
  184. package/dist/lib/functions/handleFunction/tasks/handleDeleteTask.d.ts.map +1 -1
  185. package/dist/lib/functions/handleFunction/tasks/handleDeleteTask.js +3 -3
  186. package/dist/lib/functions/handleFunction/tasks/handleListTasks.d.ts +3 -2
  187. package/dist/lib/functions/handleFunction/tasks/handleListTasks.d.ts.map +1 -1
  188. package/dist/lib/functions/handleFunction/tasks/handleListTasks.js +3 -3
  189. package/dist/lib/functions/handleFunction/tasks/handleUpdateTask.d.ts +3 -2
  190. package/dist/lib/functions/handleFunction/tasks/handleUpdateTask.d.ts.map +1 -1
  191. package/dist/lib/functions/handleFunction/tasks/handleUpdateTask.js +4 -4
  192. package/dist/lib/functions/updateFunction.d.ts +2 -1
  193. package/dist/lib/functions/updateFunction.d.ts.map +1 -1
  194. package/dist/lib/functions/updateFunction.js +2 -2
  195. package/dist/lib/handlers/handlerPrismaInput.d.ts +3 -1
  196. package/dist/lib/handlers/handlerPrismaInput.d.ts.map +1 -1
  197. package/dist/lib/handlers/handlerPrismaInput.jsx +1 -2
  198. package/dist/lib/initialMessages/updateInitialMessages.d.ts +3 -2
  199. package/dist/lib/initialMessages/updateInitialMessages.d.ts.map +1 -1
  200. package/dist/lib/initialMessages/updateInitialMessages.js +1 -2
  201. package/dist/lib/logs/createLog.d.ts +3 -2
  202. package/dist/lib/logs/createLog.d.ts.map +1 -1
  203. package/dist/lib/logs/createLog.js +1 -2
  204. package/dist/lib/mcpServers/connectMcpServer.d.ts +6 -4
  205. package/dist/lib/mcpServers/connectMcpServer.d.ts.map +1 -1
  206. package/dist/lib/mcpServers/connectMcpServer.js +7 -5
  207. package/dist/lib/mcpServers/getToolCallMcpServer.d.ts +3 -2
  208. package/dist/lib/mcpServers/getToolCallMcpServer.d.ts.map +1 -1
  209. package/dist/lib/mcpServers/getToolCallMcpServer.js +2 -1
  210. package/dist/lib/mcpServers/headers.d.ts +3 -2
  211. package/dist/lib/mcpServers/headers.d.ts.map +1 -1
  212. package/dist/lib/mcpServers/headers.js +2 -1
  213. package/dist/lib/mcpServers/url.d.ts +3 -2
  214. package/dist/lib/mcpServers/url.d.ts.map +1 -1
  215. package/dist/lib/mcpServers/url.js +2 -1
  216. package/dist/lib/metadata/serializeMetadata.d.ts +3 -1
  217. package/dist/lib/metadata/serializeMetadata.d.ts.map +1 -1
  218. package/dist/lib/metadata/serializeMetadata.js +3 -2
  219. package/dist/lib/organizationApiKeys/getOrganizationApiKey.d.ts +3 -2
  220. package/dist/lib/organizationApiKeys/getOrganizationApiKey.d.ts.map +1 -1
  221. package/dist/lib/organizationApiKeys/getOrganizationApiKey.js +1 -2
  222. package/dist/lib/runs/createRunOpts.d.ts +3 -2
  223. package/dist/lib/runs/createRunOpts.d.ts.map +1 -1
  224. package/dist/lib/runs/createRunOpts.js +2 -2
  225. package/dist/lib/tasks/getTaskToolKey.d.ts +3 -2
  226. package/dist/lib/tasks/getTaskToolKey.d.ts.map +1 -1
  227. package/dist/lib/tasks/getTaskToolKey.js +2 -1
  228. package/dist/lib/tasks/parseTaskToolArgs.d.ts +3 -2
  229. package/dist/lib/tasks/parseTaskToolArgs.d.ts.map +1 -1
  230. package/dist/lib/tasks/parseTaskToolArgs.js +4 -1
  231. package/dist/lib/tasks/scheduleTask.d.ts +3 -2
  232. package/dist/lib/tasks/scheduleTask.d.ts.map +1 -1
  233. package/dist/lib/tasks/scheduleTask.js +1 -2
  234. package/dist/lib/threads/createThread/index.d.ts +3 -3
  235. package/dist/lib/threads/createThread/index.d.ts.map +1 -1
  236. package/dist/lib/threads/createThread/index.js +1 -0
  237. package/dist/lib/threads/managedOpenaiThreadId.d.ts +3 -2
  238. package/dist/lib/threads/managedOpenaiThreadId.d.ts.map +1 -1
  239. package/dist/lib/threads/managedOpenaiThreadId.js +1 -2
  240. package/dist/lib/toolCalls/handleToolCall.d.ts +3 -2
  241. package/dist/lib/toolCalls/handleToolCall.d.ts.map +1 -1
  242. package/dist/lib/toolCalls/handleToolCall.js +5 -1
  243. package/dist/lib/tools/tools/index.d.ts +3 -2
  244. package/dist/lib/tools/tools/index.d.ts.map +1 -1
  245. package/dist/lib/tools/tools/index.js +9 -6
  246. package/package.json +2 -2
  247. package/scripts/utils/loadPrisma.ts +1 -2
  248. /package/.next/static/{kvFNeiykUJqaQCo-lW8D0 → rEvucoSBXJWMKfLWTgPF2}/_buildManifest.js +0 -0
  249. /package/.next/static/{kvFNeiykUJqaQCo-lW8D0 → rEvucoSBXJWMKfLWTgPF2}/_clientMiddlewareManifest.json +0 -0
  250. /package/.next/static/{kvFNeiykUJqaQCo-lW8D0 → rEvucoSBXJWMKfLWTgPF2}/_ssgManifest.js +0 -0
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { NextResponse } from 'next/server';
13
- import { LogRequestMethod, LogRequestRoute, LogLevel } from '@prisma/client';
13
+ import { LogRequestMethod, LogRequestRoute, LogLevel, } from '@prisma/client';
14
14
  import { messagesResponse, createMessageResponse, } from '@superinterface/react/server';
15
15
  import { enqueueJson } from '@superinterface/react/utils';
16
16
  import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
@@ -24,7 +24,7 @@ import { createRunOpts } from '../../../lib/runs/createRunOpts';
24
24
  import { handleToolCall } from '../../../lib/toolCalls/handleToolCall';
25
25
  import { createThread } from '../../../lib/threads/createThread';
26
26
  import { managedOpenaiThreadId } from '../../../lib/threads/managedOpenaiThreadId';
27
- import { prisma } from '../../../lib/prisma';
27
+ import { prisma as defaultPrisma } from '../../../lib/prisma';
28
28
  import { createLog } from '../../../lib/logs/createLog';
29
29
  import { serializeThread } from './lib/serializeThread';
30
30
  import { getWorkspaceId } from './lib/getWorkspaceId';
@@ -34,7 +34,7 @@ import { serializeMetadata } from '../../../lib/metadata/serializeMetadata';
34
34
  import { isResponsesStorageProvider } from '../../../lib/storageProviders/isResponsesStorageProvider';
35
35
  import { serializeError } from '../../../lib/errors/serializeError';
36
36
  export const maxDuration = 800;
37
- export const GET = async (request) => {
37
+ export const buildGET = ({ prisma = defaultPrisma } = {}) => async (request) => {
38
38
  var _a;
39
39
  const paramsResult = z
40
40
  .object({
@@ -46,6 +46,7 @@ export const GET = async (request) => {
46
46
  .parse(Object.fromEntries(request.nextUrl.searchParams.entries()));
47
47
  const workspaceAccessWhere = await getWorkspaceAccessWhere({
48
48
  publicApiKey: (_a = paramsResult.publicApiKey) !== null && _a !== void 0 ? _a : null,
49
+ prisma,
49
50
  });
50
51
  if (!workspaceAccessWhere) {
51
52
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -61,6 +62,7 @@ export const GET = async (request) => {
61
62
  message: 'No assistantId found.',
62
63
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
63
64
  },
65
+ prisma,
64
66
  });
65
67
  return NextResponse.json({ error: 'No assistant id found' }, { status: 400 });
66
68
  }
@@ -125,6 +127,7 @@ export const GET = async (request) => {
125
127
  message: 'No assistant found.',
126
128
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
127
129
  },
130
+ prisma,
128
131
  });
129
132
  return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
130
133
  }
@@ -167,11 +170,13 @@ export const GET = async (request) => {
167
170
  assistantId: assistant.id,
168
171
  threadId: thread.id,
169
172
  },
173
+ prisma,
170
174
  });
171
175
  return NextResponse.json({ error: 'Failed to load messages.' }, { status: 500 });
172
176
  }
173
177
  };
174
- export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (request) => {
178
+ export const GET = buildGET();
179
+ export const buildPOST = ({ prisma = defaultPrisma, onSuccessCreateThread = () => void 0, } = {}) => async (request) => {
175
180
  var _a;
176
181
  const bodyResult = z
177
182
  .object({
@@ -187,6 +192,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
187
192
  const { audioContent, content: textContent, attachments, assistantId, publicApiKey } = bodyResult, variables = __rest(bodyResult, ["audioContent", "content", "attachments", "assistantId", "publicApiKey"]);
188
193
  const workspaceAccessWhere = await getWorkspaceAccessWhere({
189
194
  publicApiKey: publicApiKey !== null && publicApiKey !== void 0 ? publicApiKey : null,
195
+ prisma,
190
196
  });
191
197
  if (!workspaceAccessWhere) {
192
198
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -201,6 +207,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
201
207
  message: 'No assistantId found.',
202
208
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
203
209
  },
210
+ prisma,
204
211
  });
205
212
  return NextResponse.json({ error: 'No assistantId found.' }, { status: 400 });
206
213
  }
@@ -214,6 +221,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
214
221
  message: 'No content found.',
215
222
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
216
223
  },
224
+ prisma,
217
225
  });
218
226
  return NextResponse.json({ error: 'No content found.' }, { status: 400 });
219
227
  }
@@ -303,6 +311,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
303
311
  message: 'No assistant found.',
304
312
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
305
313
  },
314
+ prisma,
306
315
  });
307
316
  return NextResponse.json({ error: 'No assistant found.' }, { status: 400 });
308
317
  }
@@ -320,6 +329,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
320
329
  workspaceId: assistant.workspaceId,
321
330
  assistantId: assistant.id,
322
331
  },
332
+ prisma,
323
333
  });
324
334
  return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
325
335
  }
@@ -349,6 +359,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
349
359
  workspaceId: assistant.workspaceId,
350
360
  assistantId: assistant.id,
351
361
  },
362
+ prisma,
352
363
  });
353
364
  return NextResponse.json({ error: 'Failed to create thread.' }, { status: 500 });
354
365
  }
@@ -373,6 +384,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
373
384
  assistantId: assistant.id,
374
385
  threadId: thread.id,
375
386
  },
387
+ prisma,
376
388
  });
377
389
  return NextResponse.json({ error: 'Failed to get storage thread id.' }, { status: 500 });
378
390
  }
@@ -387,6 +399,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
387
399
  storageThreadId = await managedOpenaiThreadId({
388
400
  assistant,
389
401
  threadId: thread.id,
402
+ prisma,
390
403
  });
391
404
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
405
  }
@@ -402,6 +415,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
402
415
  assistantId: assistant.id,
403
416
  threadId: thread.id,
404
417
  },
418
+ prisma,
405
419
  });
406
420
  return NextResponse.json({ error: 'Failed to get managed openai thread id.' }, { status: 500 });
407
421
  }
@@ -418,6 +432,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
418
432
  assistantId: assistant.id,
419
433
  threadId: thread.id,
420
434
  },
435
+ prisma,
421
436
  });
422
437
  return NextResponse.json({ error: 'Invalid thread configuration.' }, { status: 500 });
423
438
  }
@@ -443,6 +458,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
443
458
  assistantId: assistant.id,
444
459
  threadId: thread.id,
445
460
  },
461
+ prisma,
446
462
  });
447
463
  return NextResponse.json({ error: 'Failed to get content.' }, { status: 500 });
448
464
  }
@@ -455,6 +471,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
455
471
  await client.beta.threads.messages.create(storageThreadId, Object.assign(Object.assign({ role: 'user', content }, ((attachments === null || attachments === void 0 ? void 0 : attachments.length) ? { attachments } : {})), { metadata: serializeMetadata({
456
472
  variables,
457
473
  workspaceId: assistant.workspaceId,
474
+ prisma,
458
475
  }) }));
459
476
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
477
  }
@@ -471,12 +488,13 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
471
488
  assistantId: assistant.id,
472
489
  threadId: thread.id,
473
490
  },
491
+ prisma,
474
492
  });
475
493
  return NextResponse.json({ error: 'Failed to create message.' }, { status: 500 });
476
494
  }
477
495
  let createRunStream;
478
496
  try {
479
- createRunStream = await client.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread }));
497
+ createRunStream = await client.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread, prisma }));
480
498
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
481
499
  }
482
500
  catch (error) {
@@ -492,6 +510,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
492
510
  assistantId: assistant.id,
493
511
  threadId: thread.id,
494
512
  },
513
+ prisma,
495
514
  });
496
515
  return NextResponse.json({ error: 'Failed to create run stream.' }, { status: 500 });
497
516
  }
@@ -500,7 +519,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
500
519
  return new Response(createMessageResponse({
501
520
  client,
502
521
  createRunStream,
503
- handleToolCall: handleToolCall({ assistant, thread }),
522
+ handleToolCall: handleToolCall({ assistant, thread, prisma }),
504
523
  onStart: ({ controller, }) => {
505
524
  if (!isThreadCreated)
506
525
  return;
@@ -528,6 +547,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
528
547
  assistantId: assistant.id,
529
548
  threadId: thread.id,
530
549
  },
550
+ prisma,
531
551
  });
532
552
  // if (latestInProgressRunData) {
533
553
  // await client.beta.threads.runs.cancel(
@@ -550,6 +570,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
550
570
  assistantId: assistant.id,
551
571
  threadId: thread.id,
552
572
  },
573
+ prisma,
553
574
  });
554
575
  }
555
576
  else if (event === 'thread.run.in_progress') {
@@ -1,4 +1,23 @@
1
+ import { type PrismaClient } from '@prisma/client';
1
2
  import { NextResponse, type NextRequest } from 'next/server';
3
+ export declare const buildGET: ({ prisma }?: {
4
+ prisma?: PrismaClient;
5
+ }) => (_request: NextRequest, props: {
6
+ params: Promise<{
7
+ modelProviderId: string;
8
+ }>;
9
+ }) => Promise<NextResponse<{
10
+ error: string;
11
+ }> | NextResponse<{
12
+ storageProviderAssistants: {
13
+ id: string;
14
+ model: string;
15
+ name: string | null;
16
+ description: string | null;
17
+ instructions: string | null;
18
+ tools: import("openai/resources/beta/assistants.mjs").AssistantTool[];
19
+ }[];
20
+ }>>;
2
21
  export declare const GET: (_request: NextRequest, props: {
3
22
  params: Promise<{
4
23
  modelProviderId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/providers/[modelProviderId]/assistants/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,GAAG,GACd,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;GAgDxD,CAAA;AAED,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/providers/[modelProviderId]/assistants/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,QAAQ,GAClB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEzD,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;GAiDxD,CAAA;AAEH,eAAO,MAAM,GAAG,aApDF,WAAW,SACd;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;GAmD9B,CAAA;AAE7B,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
@@ -2,11 +2,11 @@ import { headers } from 'next/headers';
2
2
  import { ApiKeyType } from '@prisma/client';
3
3
  import { NextResponse } from 'next/server';
4
4
  import { cacheHeaders } from '../../../../../lib/cache/cacheHeaders';
5
- import { prisma } from '../../../../../lib/prisma';
5
+ import { prisma as defaultPrisma } from '../../../../../lib/prisma';
6
6
  import { getApiKey } from '../../../../../lib/apiKeys/getApiKey';
7
7
  import { getStorageProviderAssistants } from '../../../../../lib/storageProviders/getStorageProviderAssistants';
8
8
  import { serializeApiStorageProviderAssistant } from '../../../../../lib/storageProviders/serializeApiStorageProviderAssistant';
9
- export const GET = async (_request, props) => {
9
+ export const buildGET = ({ prisma = defaultPrisma } = {}) => async (_request, props) => {
10
10
  const { modelProviderId } = await props.params;
11
11
  const headersList = await headers();
12
12
  const authorization = headersList.get('authorization');
@@ -16,6 +16,7 @@ export const GET = async (_request, props) => {
16
16
  const privateApiKey = await getApiKey({
17
17
  type: ApiKeyType.PRIVATE,
18
18
  authorization,
19
+ prisma,
19
20
  });
20
21
  if (!privateApiKey) {
21
22
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -38,6 +39,7 @@ export const GET = async (_request, props) => {
38
39
  })),
39
40
  }, { headers: cacheHeaders });
40
41
  };
42
+ export const GET = buildGET();
41
43
  export const OPTIONS = () => NextResponse.json({}, {
42
44
  headers: cacheHeaders,
43
45
  });
@@ -1,4 +1,18 @@
1
+ import { type PrismaClient } from '@prisma/client';
1
2
  import { NextResponse, type NextRequest } from 'next/server';
3
+ export declare const buildGET: ({ prisma }?: {
4
+ prisma?: PrismaClient;
5
+ }) => (_request: NextRequest, props: {
6
+ params: Promise<{
7
+ modelProviderId: string;
8
+ }>;
9
+ }) => Promise<NextResponse<{
10
+ error: string;
11
+ }> | NextResponse<{
12
+ models: {
13
+ id: string;
14
+ }[];
15
+ }>>;
2
16
  export declare const GET: (_request: NextRequest, props: {
3
17
  params: Promise<{
4
18
  modelProviderId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/providers/[modelProviderId]/models/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,GAAG,GACd,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;GAgDxD,CAAA;AAED,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/providers/[modelProviderId]/models/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,QAAQ,GAClB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEzD,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;GAiDxD,CAAA;AAEH,eAAO,MAAM,GAAG,aApDF,WAAW,SACd;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;GAmD9B,CAAA;AAE7B,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
@@ -2,11 +2,11 @@ import { headers } from 'next/headers';
2
2
  import { ApiKeyType } from '@prisma/client';
3
3
  import { NextResponse } from 'next/server';
4
4
  import { cacheHeaders } from '../../../../../lib/cache/cacheHeaders';
5
- import { prisma } from '../../../../../lib/prisma';
5
+ import { prisma as defaultPrisma } from '../../../../../lib/prisma';
6
6
  import { getApiKey } from '../../../../../lib/apiKeys/getApiKey';
7
7
  import { getModels } from '../../../../../lib/models/getModels';
8
8
  import { serializeApiModel } from '../../../../../lib/models/serializeApiModel';
9
- export const GET = async (_request, props) => {
9
+ export const buildGET = ({ prisma = defaultPrisma } = {}) => async (_request, props) => {
10
10
  const { modelProviderId } = await props.params;
11
11
  const headersList = await headers();
12
12
  const authorization = headersList.get('authorization');
@@ -16,6 +16,7 @@ export const GET = async (_request, props) => {
16
16
  const privateApiKey = await getApiKey({
17
17
  type: ApiKeyType.PRIVATE,
18
18
  authorization,
19
+ prisma,
19
20
  });
20
21
  if (!privateApiKey) {
21
22
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -38,6 +39,7 @@ export const GET = async (_request, props) => {
38
39
  })),
39
40
  }, { headers: cacheHeaders });
40
41
  };
42
+ export const GET = buildGET();
41
43
  export const OPTIONS = () => NextResponse.json({}, {
42
44
  headers: cacheHeaders,
43
45
  });
@@ -1,4 +1,26 @@
1
+ import { type PrismaClient } from '@prisma/client';
1
2
  import { NextResponse, type NextRequest } from 'next/server';
3
+ export declare const buildGET: ({ prisma }?: {
4
+ prisma?: PrismaClient;
5
+ }) => (_request: NextRequest, props: {
6
+ params: Promise<{
7
+ modelProviderId: string;
8
+ }>;
9
+ }) => Promise<NextResponse<{
10
+ error: string;
11
+ }> | NextResponse<{
12
+ provider: {
13
+ id: string;
14
+ type: import("@prisma/client").$Enums.ModelProviderType;
15
+ name: string;
16
+ apiKey: string;
17
+ endpoint: string | null;
18
+ apiVersion: string | null;
19
+ workspaceId: string;
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ };
23
+ }>>;
2
24
  export declare const GET: (_request: NextRequest, props: {
3
25
  params: Promise<{
4
26
  modelProviderId: string;
@@ -18,6 +40,27 @@ export declare const GET: (_request: NextRequest, props: {
18
40
  updatedAt: string;
19
41
  };
20
42
  }>>;
43
+ export declare const buildPATCH: ({ prisma }?: {
44
+ prisma?: PrismaClient;
45
+ }) => (request: NextRequest, props: {
46
+ params: Promise<{
47
+ modelProviderId: string;
48
+ }>;
49
+ }) => Promise<NextResponse<{
50
+ error: string;
51
+ }> | NextResponse<{
52
+ provider: {
53
+ id: string;
54
+ type: import("@prisma/client").$Enums.ModelProviderType;
55
+ name: string;
56
+ apiKey: string;
57
+ endpoint: string | null;
58
+ apiVersion: string | null;
59
+ workspaceId: string;
60
+ createdAt: string;
61
+ updatedAt: string;
62
+ };
63
+ }>>;
21
64
  export declare const PATCH: (request: NextRequest, props: {
22
65
  params: Promise<{
23
66
  modelProviderId: string;
@@ -37,6 +80,27 @@ export declare const PATCH: (request: NextRequest, props: {
37
80
  updatedAt: string;
38
81
  };
39
82
  }>>;
83
+ export declare const buildDELETE: ({ prisma }?: {
84
+ prisma?: PrismaClient;
85
+ }) => (_request: NextRequest, props: {
86
+ params: Promise<{
87
+ modelProviderId: string;
88
+ }>;
89
+ }) => Promise<NextResponse<{
90
+ error: string;
91
+ }> | NextResponse<{
92
+ provider: {
93
+ id: string;
94
+ type: import("@prisma/client").$Enums.ModelProviderType;
95
+ name: string;
96
+ apiKey: string;
97
+ endpoint: string | null;
98
+ apiVersion: string | null;
99
+ workspaceId: string;
100
+ createdAt: string;
101
+ updatedAt: string;
102
+ };
103
+ }>>;
40
104
  export declare const DELETE: (_request: NextRequest, props: {
41
105
  params: Promise<{
42
106
  modelProviderId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/providers/[modelProviderId]/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAQ5D,eAAO,MAAM,GAAG,GACd,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GA2CxD,CAAA;AAED,eAAO,MAAM,KAAK,GAChB,SAAS,WAAW,EACpB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GAwExD,CAAA;AAED,eAAO,MAAM,MAAM,GACjB,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GA0DxD,CAAA;AAED,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/app/api/providers/[modelProviderId]/route.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAQ5D,eAAO,MAAM,QAAQ,GAClB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEzD,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GA+CxD,CAAA;AAEH,eAAO,MAAM,GAAG,aAlDF,WAAW,SACd;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GAiD9B,CAAA;AAE7B,eAAO,MAAM,UAAU,GACpB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEzD,SAAS,WAAW,EACpB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GAkFxD,CAAA;AAEH,eAAO,MAAM,KAAK,YArFL,WAAW,SACb;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GAoF1B,CAAA;AAEjC,eAAO,MAAM,WAAW,GACrB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEzD,UAAU,WAAW,EACrB,OAAO;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GA8DxD,CAAA;AAEH,eAAO,MAAM,MAAM,aAjEL,WAAW,SACd;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE;;;;;;;;;;;;;;GAgExB,CAAA;AAEnC,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
@@ -1,13 +1,13 @@
1
1
  import { headers } from 'next/headers';
2
- import { ApiKeyType, ModelProviderType } from '@prisma/client';
2
+ import { ApiKeyType, ModelProviderType, } from '@prisma/client';
3
3
  import { NextResponse } from 'next/server';
4
4
  import { z } from 'zod';
5
5
  import { cacheHeaders } from '../../../../lib/cache/cacheHeaders';
6
- import { prisma } from '../../../../lib/prisma';
6
+ import { prisma as defaultPrisma } from '../../../../lib/prisma';
7
7
  import { serializeModelProvider } from '../../../../lib/modelProviders/serializeModelProvider';
8
8
  import { getApiKey } from '../../../../lib/apiKeys/getApiKey';
9
9
  import { validate } from 'uuid';
10
- export const GET = async (_request, props) => {
10
+ export const buildGET = ({ prisma = defaultPrisma } = {}) => async (_request, props) => {
11
11
  const { modelProviderId } = await props.params;
12
12
  const headersList = await headers();
13
13
  const authorization = headersList.get('authorization');
@@ -17,6 +17,7 @@ export const GET = async (_request, props) => {
17
17
  const privateApiKey = await getApiKey({
18
18
  type: ApiKeyType.PRIVATE,
19
19
  authorization,
20
+ prisma,
20
21
  });
21
22
  if (!privateApiKey) {
22
23
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -37,7 +38,8 @@ export const GET = async (_request, props) => {
37
38
  provider: serializeModelProvider({ provider }),
38
39
  }, { headers: cacheHeaders });
39
40
  };
40
- export const PATCH = async (request, props) => {
41
+ export const GET = buildGET();
42
+ export const buildPATCH = ({ prisma = defaultPrisma } = {}) => async (request, props) => {
41
43
  const { modelProviderId } = await props.params;
42
44
  const headersList = await headers();
43
45
  const authorization = headersList.get('authorization');
@@ -47,6 +49,7 @@ export const PATCH = async (request, props) => {
47
49
  const privateApiKey = await getApiKey({
48
50
  authorization,
49
51
  type: ApiKeyType.PRIVATE,
52
+ prisma,
50
53
  });
51
54
  if (!privateApiKey) {
52
55
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -66,7 +69,7 @@ export const PATCH = async (request, props) => {
66
69
  if (!parsed.success) {
67
70
  return NextResponse.json({ error: 'Invalid payload' }, { status: 400 });
68
71
  }
69
- const { type, apiKey: providerKey, endpoint, apiVersion, name } = parsed.data;
72
+ const { type, apiKey: providerKey, endpoint, apiVersion, name, } = parsed.data;
70
73
  const updateData = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (type ? { type } : {})), (name !== undefined ? { name } : {})), (providerKey !== undefined ? { apiKey: providerKey } : {})), (endpoint !== undefined ? { endpoint } : {})), (apiVersion !== undefined ? { apiVersion } : {}));
71
74
  const existingProvider = await prisma.modelProvider.findFirst({
72
75
  where: {
@@ -85,7 +88,8 @@ export const PATCH = async (request, props) => {
85
88
  provider: serializeModelProvider({ provider }),
86
89
  }, { headers: cacheHeaders });
87
90
  };
88
- export const DELETE = async (_request, props) => {
91
+ export const PATCH = buildPATCH();
92
+ export const buildDELETE = ({ prisma = defaultPrisma } = {}) => async (_request, props) => {
89
93
  const { modelProviderId } = await props.params;
90
94
  const headersList = await headers();
91
95
  const authorization = headersList.get('authorization');
@@ -95,6 +99,7 @@ export const DELETE = async (_request, props) => {
95
99
  const privateApiKey = await getApiKey({
96
100
  authorization,
97
101
  type: ApiKeyType.PRIVATE,
102
+ prisma,
98
103
  });
99
104
  if (!privateApiKey) {
100
105
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -127,6 +132,7 @@ export const DELETE = async (_request, props) => {
127
132
  provider: serializeModelProvider({ provider }),
128
133
  }, { headers: cacheHeaders });
129
134
  };
135
+ export const DELETE = buildDELETE();
130
136
  export const OPTIONS = () => NextResponse.json({}, {
131
137
  headers: cacheHeaders,
132
138
  });
@@ -1,4 +1,22 @@
1
+ import { type PrismaClient } from '@prisma/client';
1
2
  import { NextResponse, type NextRequest } from 'next/server';
3
+ export declare const buildGET: ({ prisma }?: {
4
+ prisma?: PrismaClient;
5
+ }) => () => Promise<NextResponse<{
6
+ error: string;
7
+ }> | NextResponse<{
8
+ providers: {
9
+ id: string;
10
+ type: import("@prisma/client").$Enums.ModelProviderType;
11
+ name: string;
12
+ apiKey: string;
13
+ endpoint: string | null;
14
+ apiVersion: string | null;
15
+ workspaceId: string;
16
+ createdAt: string;
17
+ updatedAt: string;
18
+ }[];
19
+ }>>;
2
20
  export declare const GET: () => Promise<NextResponse<{
3
21
  error: string;
4
22
  }> | NextResponse<{
@@ -14,6 +32,23 @@ export declare const GET: () => Promise<NextResponse<{
14
32
  updatedAt: string;
15
33
  }[];
16
34
  }>>;
35
+ export declare const buildPOST: ({ prisma }?: {
36
+ prisma?: PrismaClient;
37
+ }) => (request: NextRequest) => Promise<NextResponse<{
38
+ error: string;
39
+ }> | NextResponse<{
40
+ provider: {
41
+ id: string;
42
+ type: import("@prisma/client").$Enums.ModelProviderType;
43
+ name: string;
44
+ apiKey: string;
45
+ endpoint: string | null;
46
+ apiVersion: string | null;
47
+ workspaceId: string;
48
+ createdAt: string;
49
+ updatedAt: string;
50
+ };
51
+ }>>;
17
52
  export declare const POST: (request: NextRequest) => Promise<NextResponse<{
18
53
  error: string;
19
54
  }> | NextResponse<{
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/providers/route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,GAAG;;;;;;;;;;;;;;GA+Bf,CAAA;AAED,eAAO,MAAM,IAAI,GAAU,SAAS,WAAW;;;;;;;;;;;;;;GAsD9C,CAAA;AAED,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/providers/route.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,QAAQ,GAClB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO;;;;;;;;;;;;;;GAmC1D,CAAA;AAEH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;GAAa,CAAA;AAE7B,eAAO,MAAM,SAAS,GACnB,aAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MACpD,SAAS,WAAW;;;;;;;;;;;;;;GA6D1B,CAAA;AAEH,eAAO,MAAM,IAAI,YA/DC,WAAW;;;;;;;;;;;;;;GA+DE,CAAA;AAE/B,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
@@ -1,12 +1,12 @@
1
1
  import { headers } from 'next/headers';
2
- import { ApiKeyType, ModelProviderType } from '@prisma/client';
2
+ import { ApiKeyType, ModelProviderType, } from '@prisma/client';
3
3
  import { NextResponse } from 'next/server';
4
4
  import { z } from 'zod';
5
5
  import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
6
- import { prisma } from '../../../lib/prisma';
6
+ import { prisma as defaultPrisma } from '../../../lib/prisma';
7
7
  import { serializeModelProvider } from '../../../lib/modelProviders/serializeModelProvider';
8
8
  import { getApiKey } from '../../../lib/apiKeys/getApiKey';
9
- export const GET = async () => {
9
+ export const buildGET = ({ prisma = defaultPrisma } = {}) => async () => {
10
10
  const headersList = await headers();
11
11
  const authorization = headersList.get('authorization');
12
12
  if (!authorization) {
@@ -15,6 +15,7 @@ export const GET = async () => {
15
15
  const privateApiKey = await getApiKey({
16
16
  type: ApiKeyType.PRIVATE,
17
17
  authorization,
18
+ prisma,
18
19
  });
19
20
  if (!privateApiKey) {
20
21
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -28,7 +29,8 @@ export const GET = async () => {
28
29
  providers: providers.map((p) => serializeModelProvider({ provider: p })),
29
30
  }, { headers: cacheHeaders });
30
31
  };
31
- export const POST = async (request) => {
32
+ export const GET = buildGET();
33
+ export const buildPOST = ({ prisma = defaultPrisma } = {}) => async (request) => {
32
34
  const headersList = await headers();
33
35
  const authorization = headersList.get('authorization');
34
36
  if (!authorization) {
@@ -37,6 +39,7 @@ export const POST = async (request) => {
37
39
  const privateApiKey = await getApiKey({
38
40
  authorization,
39
41
  type: ApiKeyType.PRIVATE,
42
+ prisma,
40
43
  });
41
44
  if (!privateApiKey) {
42
45
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -53,7 +56,7 @@ export const POST = async (request) => {
53
56
  if (!parsed.success) {
54
57
  return NextResponse.json({ error: 'Invalid payload' }, { status: 400 });
55
58
  }
56
- const { type, name, apiKey: providerKey, endpoint, apiVersion } = parsed.data;
59
+ const { type, name, apiKey: providerKey, endpoint, apiVersion, } = parsed.data;
57
60
  const workspaceId = privateApiKey.workspaceId;
58
61
  const provider = await prisma.modelProvider.create({
59
62
  data: {
@@ -69,6 +72,7 @@ export const POST = async (request) => {
69
72
  provider: serializeModelProvider({ provider }),
70
73
  }, { headers: cacheHeaders });
71
74
  };
75
+ export const POST = buildPOST();
72
76
  export const OPTIONS = () => NextResponse.json({}, {
73
77
  headers: cacheHeaders,
74
78
  });