@superinterface/server 1.0.18 → 1.0.20

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 (264) 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]__228bff78._.js +2 -2
  21. package/.next/server/chunks/[root-of-the-server]__228bff78._.js.map +1 -1
  22. package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js +1 -1
  23. package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js.map +1 -1
  24. package/.next/server/chunks/[root-of-the-server]__27aadac9._.js +1 -1
  25. package/.next/server/chunks/[root-of-the-server]__27aadac9._.js.map +1 -1
  26. package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js +1 -1
  27. package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js.map +1 -1
  28. package/.next/server/chunks/[root-of-the-server]__29635e8e._.js +1 -1
  29. package/.next/server/chunks/[root-of-the-server]__29635e8e._.js.map +1 -1
  30. package/.next/server/chunks/[root-of-the-server]__29b43490._.js +2 -2
  31. package/.next/server/chunks/[root-of-the-server]__29b43490._.js.map +1 -1
  32. package/.next/server/chunks/[root-of-the-server]__315f084a._.js +1 -1
  33. package/.next/server/chunks/[root-of-the-server]__315f084a._.js.map +1 -1
  34. package/.next/server/chunks/[root-of-the-server]__3307123c._.js +2 -2
  35. package/.next/server/chunks/[root-of-the-server]__3307123c._.js.map +1 -1
  36. package/.next/server/chunks/[root-of-the-server]__441cee00._.js +1 -1
  37. package/.next/server/chunks/[root-of-the-server]__441cee00._.js.map +1 -1
  38. package/.next/server/chunks/[root-of-the-server]__464a4377._.js +1 -1
  39. package/.next/server/chunks/[root-of-the-server]__464a4377._.js.map +1 -1
  40. package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js +1 -1
  41. package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js.map +1 -1
  42. package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js +2 -2
  43. package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js.map +1 -1
  44. package/.next/server/chunks/[root-of-the-server]__51977f30._.js +1 -1
  45. package/.next/server/chunks/[root-of-the-server]__51977f30._.js.map +1 -1
  46. package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js +1 -1
  47. package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js.map +1 -1
  48. package/.next/server/chunks/[root-of-the-server]__5abf1160._.js +1 -1
  49. package/.next/server/chunks/[root-of-the-server]__5abf1160._.js.map +1 -1
  50. package/.next/server/chunks/[root-of-the-server]__5d09614a._.js +1 -1
  51. package/.next/server/chunks/[root-of-the-server]__5d09614a._.js.map +1 -1
  52. package/.next/server/chunks/[root-of-the-server]__62d958e7._.js +1 -1
  53. package/.next/server/chunks/[root-of-the-server]__62d958e7._.js.map +1 -1
  54. package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js +2 -2
  55. package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js.map +1 -1
  56. package/.next/server/chunks/[root-of-the-server]__7f9ca1e3._.js +1 -1
  57. package/.next/server/chunks/[root-of-the-server]__7f9ca1e3._.js.map +1 -1
  58. package/.next/server/chunks/[root-of-the-server]__83461316._.js +1 -1
  59. package/.next/server/chunks/[root-of-the-server]__83461316._.js.map +1 -1
  60. package/.next/server/chunks/[root-of-the-server]__9a611d42._.js +1 -1
  61. package/.next/server/chunks/[root-of-the-server]__9a611d42._.js.map +1 -1
  62. package/.next/server/chunks/[root-of-the-server]__a135e388._.js +1 -1
  63. package/.next/server/chunks/[root-of-the-server]__a135e388._.js.map +1 -1
  64. package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js +1 -1
  65. package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js.map +1 -1
  66. package/.next/server/chunks/[root-of-the-server]__b9a334c3._.js +1 -1
  67. package/.next/server/chunks/[root-of-the-server]__b9a334c3._.js.map +1 -1
  68. package/.next/server/chunks/[root-of-the-server]__c1629392._.js +1 -1
  69. package/.next/server/chunks/[root-of-the-server]__c1629392._.js.map +1 -1
  70. package/.next/server/chunks/[root-of-the-server]__dd176cb5._.js +2 -2
  71. package/.next/server/chunks/[root-of-the-server]__dd176cb5._.js.map +1 -1
  72. package/.next/server/chunks/[root-of-the-server]__e7819e95._.js +2 -2
  73. package/.next/server/chunks/[root-of-the-server]__e7819e95._.js.map +1 -1
  74. package/.next/server/chunks/[root-of-the-server]__eb816e13._.js +1 -1
  75. package/.next/server/chunks/[root-of-the-server]__eb816e13._.js.map +1 -1
  76. package/.next/server/chunks/[root-of-the-server]__ed6cf593._.js +1 -1
  77. package/.next/server/chunks/[root-of-the-server]__ed6cf593._.js.map +1 -1
  78. package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js +2 -2
  79. package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js.map +1 -1
  80. package/.next/server/chunks/{[root-of-the-server]__30845206._.js → [root-of-the-server]__ff90af03._.js} +3 -3
  81. package/.next/server/chunks/{[root-of-the-server]__30845206._.js.map → [root-of-the-server]__ff90af03._.js.map} +1 -1
  82. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js +1 -1
  83. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js.map +1 -1
  84. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js +1 -1
  85. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js.map +1 -1
  86. package/.next/server/chunks/supercorp_superinterface_bebd2c96._.js +2 -2
  87. package/.next/server/chunks/supercorp_superinterface_bebd2c96._.js.map +1 -1
  88. package/.next/server/pages/404.html +1 -1
  89. package/.next/server/pages/500.html +1 -1
  90. package/.next/trace +1 -1
  91. package/bin/index.cjs +2 -0
  92. package/dist/app/api/api-keys/[apiKeyId]/route.d.ts +55 -0
  93. package/dist/app/api/api-keys/[apiKeyId]/route.d.ts.map +1 -1
  94. package/dist/app/api/api-keys/[apiKeyId]/route.js +10 -4
  95. package/dist/app/api/api-keys/route.d.ts +29 -0
  96. package/dist/app/api/api-keys/route.d.ts.map +1 -1
  97. package/dist/app/api/api-keys/route.js +8 -3
  98. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts +172 -0
  99. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts.map +1 -1
  100. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.js +11 -4
  101. package/dist/app/api/assistants/[assistantId]/functions/route.d.ts +113 -0
  102. package/dist/app/api/assistants/[assistantId]/functions/route.d.ts.map +1 -1
  103. package/dist/app/api/assistants/[assistantId]/functions/route.js +8 -3
  104. package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts +39 -0
  105. package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts.map +1 -1
  106. package/dist/app/api/assistants/[assistantId]/initial-messages/route.js +8 -3
  107. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts +94 -0
  108. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts.map +1 -1
  109. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +10 -4
  110. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts +61 -0
  111. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts.map +1 -1
  112. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.js +7 -3
  113. package/dist/app/api/assistants/[assistantId]/route.d.ts +123 -0
  114. package/dist/app/api/assistants/[assistantId]/route.d.ts.map +1 -1
  115. package/dist/app/api/assistants/[assistantId]/route.js +15 -6
  116. package/dist/app/api/assistants/route.d.ts +59 -0
  117. package/dist/app/api/assistants/route.d.ts.map +1 -1
  118. package/dist/app/api/assistants/route.js +8 -4
  119. package/dist/app/api/files/[fileId]/contents/route.d.ts +3 -2
  120. package/dist/app/api/files/[fileId]/contents/route.d.ts.map +1 -1
  121. package/dist/app/api/files/[fileId]/contents/route.js +9 -6
  122. package/dist/app/api/files/route.d.ts +10 -0
  123. package/dist/app/api/files/route.d.ts.map +1 -1
  124. package/dist/app/api/files/route.js +9 -5
  125. package/dist/app/api/messages/route.d.ts +24 -1
  126. package/dist/app/api/messages/route.d.ts.map +1 -1
  127. package/dist/app/api/messages/route.js +38 -13
  128. package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts +19 -0
  129. package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts.map +1 -1
  130. package/dist/app/api/providers/[modelProviderId]/assistants/route.js +4 -2
  131. package/dist/app/api/providers/[modelProviderId]/models/route.d.ts +14 -0
  132. package/dist/app/api/providers/[modelProviderId]/models/route.d.ts.map +1 -1
  133. package/dist/app/api/providers/[modelProviderId]/models/route.js +4 -2
  134. package/dist/app/api/providers/[modelProviderId]/route.d.ts +64 -0
  135. package/dist/app/api/providers/[modelProviderId]/route.d.ts.map +1 -1
  136. package/dist/app/api/providers/[modelProviderId]/route.js +12 -6
  137. package/dist/app/api/providers/route.d.ts +35 -0
  138. package/dist/app/api/providers/route.d.ts.map +1 -1
  139. package/dist/app/api/providers/route.js +9 -5
  140. package/dist/app/api/tasks/[taskId]/route.d.ts +61 -0
  141. package/dist/app/api/tasks/[taskId]/route.d.ts.map +1 -1
  142. package/dist/app/api/tasks/[taskId]/route.js +11 -5
  143. package/dist/app/api/tasks/callback/route.d.ts.map +1 -1
  144. package/dist/app/api/tasks/callback/route.js +17 -9
  145. package/dist/app/api/tasks/route.d.ts +33 -0
  146. package/dist/app/api/tasks/route.d.ts.map +1 -1
  147. package/dist/app/api/tasks/route.js +8 -4
  148. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts +9 -1
  149. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts.map +1 -1
  150. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.js +5 -3
  151. package/dist/app/api/workspaces/[workspaceId]/route.d.ts +33 -0
  152. package/dist/app/api/workspaces/[workspaceId]/route.d.ts.map +1 -1
  153. package/dist/app/api/workspaces/[workspaceId]/route.js +7 -3
  154. package/dist/app/api/workspaces/route.d.ts +17 -3
  155. package/dist/app/api/workspaces/route.d.ts.map +1 -1
  156. package/dist/app/api/workspaces/route.js +8 -4
  157. package/dist/lib/apiKeys/getApiKey.d.ts +3 -2
  158. package/dist/lib/apiKeys/getApiKey.d.ts.map +1 -1
  159. package/dist/lib/apiKeys/getApiKey.js +1 -2
  160. package/dist/lib/apiKeys/workspaceAccessWhere.d.ts +3 -1
  161. package/dist/lib/apiKeys/workspaceAccessWhere.d.ts.map +1 -1
  162. package/dist/lib/apiKeys/workspaceAccessWhere.js +2 -1
  163. package/dist/lib/assistants/assistantClientAdapter/buildGetOpenaiAssistant.d.ts +3 -2
  164. package/dist/lib/assistants/assistantClientAdapter/buildGetOpenaiAssistant.d.ts.map +1 -1
  165. package/dist/lib/assistants/assistantClientAdapter/buildGetOpenaiAssistant.js +3 -3
  166. package/dist/lib/assistants/assistantClientAdapter/index.d.ts.map +1 -1
  167. package/dist/lib/assistants/assistantClientAdapter/index.js +7 -2
  168. package/dist/lib/computerCalls/handleComputerCall/index.d.ts +3 -2
  169. package/dist/lib/computerCalls/handleComputerCall/index.d.ts.map +1 -1
  170. package/dist/lib/computerCalls/handleComputerCall/index.js +5 -1
  171. package/dist/lib/functions/createFunction.d.ts +2 -1
  172. package/dist/lib/functions/createFunction.d.ts.map +1 -1
  173. package/dist/lib/functions/createFunction.js +2 -2
  174. package/dist/lib/functions/handleFunction/handleAssistant.d.ts +3 -2
  175. package/dist/lib/functions/handleFunction/handleAssistant.d.ts.map +1 -1
  176. package/dist/lib/functions/handleFunction/handleAssistant.js +12 -2
  177. package/dist/lib/functions/handleFunction/handleClientTool.d.ts +3 -2
  178. package/dist/lib/functions/handleFunction/handleClientTool.d.ts.map +1 -1
  179. package/dist/lib/functions/handleFunction/handleClientTool.js +2 -1
  180. package/dist/lib/functions/handleFunction/handleFirecrawl.d.ts +3 -2
  181. package/dist/lib/functions/handleFunction/handleFirecrawl.d.ts.map +1 -1
  182. package/dist/lib/functions/handleFunction/handleFirecrawl.js +7 -1
  183. package/dist/lib/functions/handleFunction/handleReplicate.d.ts +3 -2
  184. package/dist/lib/functions/handleFunction/handleReplicate.d.ts.map +1 -1
  185. package/dist/lib/functions/handleFunction/handleReplicate.js +4 -1
  186. package/dist/lib/functions/handleFunction/handleRequest.d.ts +3 -2
  187. package/dist/lib/functions/handleFunction/handleRequest.d.ts.map +1 -1
  188. package/dist/lib/functions/handleFunction/handleRequest.js +6 -1
  189. package/dist/lib/functions/handleFunction/index.d.ts +3 -2
  190. package/dist/lib/functions/handleFunction/index.d.ts.map +1 -1
  191. package/dist/lib/functions/handleFunction/index.js +25 -1
  192. package/dist/lib/functions/handleFunction/tasks/handleCreateTask.d.ts +3 -2
  193. package/dist/lib/functions/handleFunction/tasks/handleCreateTask.d.ts.map +1 -1
  194. package/dist/lib/functions/handleFunction/tasks/handleCreateTask.js +4 -4
  195. package/dist/lib/functions/handleFunction/tasks/handleDeleteTask.d.ts +3 -2
  196. package/dist/lib/functions/handleFunction/tasks/handleDeleteTask.d.ts.map +1 -1
  197. package/dist/lib/functions/handleFunction/tasks/handleDeleteTask.js +3 -3
  198. package/dist/lib/functions/handleFunction/tasks/handleListTasks.d.ts +3 -2
  199. package/dist/lib/functions/handleFunction/tasks/handleListTasks.d.ts.map +1 -1
  200. package/dist/lib/functions/handleFunction/tasks/handleListTasks.js +3 -3
  201. package/dist/lib/functions/handleFunction/tasks/handleUpdateTask.d.ts +3 -2
  202. package/dist/lib/functions/handleFunction/tasks/handleUpdateTask.d.ts.map +1 -1
  203. package/dist/lib/functions/handleFunction/tasks/handleUpdateTask.js +4 -4
  204. package/dist/lib/functions/updateFunction.d.ts +2 -1
  205. package/dist/lib/functions/updateFunction.d.ts.map +1 -1
  206. package/dist/lib/functions/updateFunction.js +2 -2
  207. package/dist/lib/handlers/handlerPrismaInput.d.ts +3 -1
  208. package/dist/lib/handlers/handlerPrismaInput.d.ts.map +1 -1
  209. package/dist/lib/handlers/handlerPrismaInput.jsx +1 -2
  210. package/dist/lib/initialMessages/updateInitialMessages.d.ts +3 -2
  211. package/dist/lib/initialMessages/updateInitialMessages.d.ts.map +1 -1
  212. package/dist/lib/initialMessages/updateInitialMessages.js +1 -2
  213. package/dist/lib/logs/createLog.d.ts +3 -2
  214. package/dist/lib/logs/createLog.d.ts.map +1 -1
  215. package/dist/lib/logs/createLog.js +1 -2
  216. package/dist/lib/mcpServers/connectMcpServer.d.ts +5 -3
  217. package/dist/lib/mcpServers/connectMcpServer.d.ts.map +1 -1
  218. package/dist/lib/mcpServers/connectMcpServer.js +7 -5
  219. package/dist/lib/mcpServers/getToolCallMcpServer.d.ts +3 -2
  220. package/dist/lib/mcpServers/getToolCallMcpServer.d.ts.map +1 -1
  221. package/dist/lib/mcpServers/getToolCallMcpServer.js +2 -1
  222. package/dist/lib/mcpServers/headers.d.ts +3 -2
  223. package/dist/lib/mcpServers/headers.d.ts.map +1 -1
  224. package/dist/lib/mcpServers/headers.js +2 -1
  225. package/dist/lib/mcpServers/url.d.ts +3 -2
  226. package/dist/lib/mcpServers/url.d.ts.map +1 -1
  227. package/dist/lib/mcpServers/url.js +2 -1
  228. package/dist/lib/metadata/serializeMetadata.d.ts +3 -1
  229. package/dist/lib/metadata/serializeMetadata.d.ts.map +1 -1
  230. package/dist/lib/metadata/serializeMetadata.js +3 -2
  231. package/dist/lib/organizationApiKeys/getOrganizationApiKey.d.ts +3 -2
  232. package/dist/lib/organizationApiKeys/getOrganizationApiKey.d.ts.map +1 -1
  233. package/dist/lib/organizationApiKeys/getOrganizationApiKey.js +1 -2
  234. package/dist/lib/prisma/index.d.ts +2 -0
  235. package/dist/lib/prisma/index.d.ts.map +1 -1
  236. package/dist/lib/prisma/index.js +16 -4
  237. package/dist/lib/runs/createRunOpts.d.ts +3 -2
  238. package/dist/lib/runs/createRunOpts.d.ts.map +1 -1
  239. package/dist/lib/runs/createRunOpts.js +2 -2
  240. package/dist/lib/tasks/getTaskToolKey.d.ts +3 -2
  241. package/dist/lib/tasks/getTaskToolKey.d.ts.map +1 -1
  242. package/dist/lib/tasks/getTaskToolKey.js +2 -1
  243. package/dist/lib/tasks/parseTaskToolArgs.d.ts +3 -2
  244. package/dist/lib/tasks/parseTaskToolArgs.d.ts.map +1 -1
  245. package/dist/lib/tasks/parseTaskToolArgs.js +4 -1
  246. package/dist/lib/tasks/scheduleTask.d.ts +3 -2
  247. package/dist/lib/tasks/scheduleTask.d.ts.map +1 -1
  248. package/dist/lib/tasks/scheduleTask.js +1 -2
  249. package/dist/lib/threads/createThread/index.d.ts.map +1 -1
  250. package/dist/lib/threads/createThread/index.js +1 -0
  251. package/dist/lib/threads/managedOpenaiThreadId.d.ts +3 -2
  252. package/dist/lib/threads/managedOpenaiThreadId.d.ts.map +1 -1
  253. package/dist/lib/threads/managedOpenaiThreadId.js +1 -2
  254. package/dist/lib/toolCalls/handleToolCall.d.ts +3 -2
  255. package/dist/lib/toolCalls/handleToolCall.d.ts.map +1 -1
  256. package/dist/lib/toolCalls/handleToolCall.js +5 -1
  257. package/dist/lib/tools/tools/index.d.ts +3 -2
  258. package/dist/lib/tools/tools/index.d.ts.map +1 -1
  259. package/dist/lib/tools/tools/index.js +9 -6
  260. package/package.json +1 -1
  261. package/scripts/utils/loadPrisma.ts +1 -2
  262. /package/.next/static/{s_BjB5fnRbk2L3A0fMr5L → Ggpv5PXa7pPyxP1NXVbh6}/_buildManifest.js +0 -0
  263. /package/.next/static/{s_BjB5fnRbk2L3A0fMr5L → Ggpv5PXa7pPyxP1NXVbh6}/_clientMiddlewareManifest.json +0 -0
  264. /package/.next/static/{s_BjB5fnRbk2L3A0fMr5L → Ggpv5PXa7pPyxP1NXVbh6}/_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 { getPrisma } 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 = getPrisma() } = {}) => 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
  }
@@ -139,7 +142,11 @@ export const GET = async (request) => {
139
142
  headers: cacheHeaders,
140
143
  });
141
144
  }
142
- const client = assistantClientAdapter({ assistant, prisma, thread });
145
+ const assistantClient = assistantClientAdapter({
146
+ assistant,
147
+ prisma,
148
+ thread,
149
+ });
143
150
  const storageThreadId = getStorageThreadId({
144
151
  thread,
145
152
  });
@@ -149,7 +156,7 @@ export const GET = async (request) => {
149
156
  });
150
157
  }
151
158
  try {
152
- return NextResponse.json(await messagesResponse(Object.assign({ threadId: storageThreadId, client }, (pageParam ? { pageParam } : {}))), {
159
+ return NextResponse.json(await messagesResponse(Object.assign({ threadId: storageThreadId, client: assistantClient }, (pageParam ? { pageParam } : {}))), {
153
160
  headers: cacheHeaders,
154
161
  });
155
162
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -167,11 +174,13 @@ export const GET = async (request) => {
167
174
  assistantId: assistant.id,
168
175
  threadId: thread.id,
169
176
  },
177
+ prisma,
170
178
  });
171
179
  return NextResponse.json({ error: 'Failed to load messages.' }, { status: 500 });
172
180
  }
173
181
  };
174
- export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (request) => {
182
+ export const GET = buildGET();
183
+ export const buildPOST = ({ prisma = getPrisma(), onSuccessCreateThread = () => void 0, } = {}) => async (request) => {
175
184
  var _a;
176
185
  const bodyResult = z
177
186
  .object({
@@ -187,6 +196,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
187
196
  const { audioContent, content: textContent, attachments, assistantId, publicApiKey } = bodyResult, variables = __rest(bodyResult, ["audioContent", "content", "attachments", "assistantId", "publicApiKey"]);
188
197
  const workspaceAccessWhere = await getWorkspaceAccessWhere({
189
198
  publicApiKey: publicApiKey !== null && publicApiKey !== void 0 ? publicApiKey : null,
199
+ prisma,
190
200
  });
191
201
  if (!workspaceAccessWhere) {
192
202
  return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
@@ -201,6 +211,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
201
211
  message: 'No assistantId found.',
202
212
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
203
213
  },
214
+ prisma,
204
215
  });
205
216
  return NextResponse.json({ error: 'No assistantId found.' }, { status: 400 });
206
217
  }
@@ -214,6 +225,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
214
225
  message: 'No content found.',
215
226
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
216
227
  },
228
+ prisma,
217
229
  });
218
230
  return NextResponse.json({ error: 'No content found.' }, { status: 400 });
219
231
  }
@@ -303,6 +315,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
303
315
  message: 'No assistant found.',
304
316
  workspaceId: await getWorkspaceId({ workspaceAccessWhere, prisma }),
305
317
  },
318
+ prisma,
306
319
  });
307
320
  return NextResponse.json({ error: 'No assistant found.' }, { status: 400 });
308
321
  }
@@ -320,6 +333,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
320
333
  workspaceId: assistant.workspaceId,
321
334
  assistantId: assistant.id,
322
335
  },
336
+ prisma,
323
337
  });
324
338
  return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
325
339
  }
@@ -349,6 +363,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
349
363
  workspaceId: assistant.workspaceId,
350
364
  assistantId: assistant.id,
351
365
  },
366
+ prisma,
352
367
  });
353
368
  return NextResponse.json({ error: 'Failed to create thread.' }, { status: 500 });
354
369
  }
@@ -373,6 +388,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
373
388
  assistantId: assistant.id,
374
389
  threadId: thread.id,
375
390
  },
391
+ prisma,
376
392
  });
377
393
  return NextResponse.json({ error: 'Failed to get storage thread id.' }, { status: 500 });
378
394
  }
@@ -387,6 +403,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
387
403
  storageThreadId = await managedOpenaiThreadId({
388
404
  assistant,
389
405
  threadId: thread.id,
406
+ prisma,
390
407
  });
391
408
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
409
  }
@@ -402,6 +419,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
402
419
  assistantId: assistant.id,
403
420
  threadId: thread.id,
404
421
  },
422
+ prisma,
405
423
  });
406
424
  return NextResponse.json({ error: 'Failed to get managed openai thread id.' }, { status: 500 });
407
425
  }
@@ -418,6 +436,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
418
436
  assistantId: assistant.id,
419
437
  threadId: thread.id,
420
438
  },
439
+ prisma,
421
440
  });
422
441
  return NextResponse.json({ error: 'Invalid thread configuration.' }, { status: 500 });
423
442
  }
@@ -443,18 +462,20 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
443
462
  assistantId: assistant.id,
444
463
  threadId: thread.id,
445
464
  },
465
+ prisma,
446
466
  });
447
467
  return NextResponse.json({ error: 'Failed to get content.' }, { status: 500 });
448
468
  }
449
- const client = assistantClientAdapter({
469
+ const assistantClient = assistantClientAdapter({
450
470
  assistant,
451
471
  prisma,
452
472
  thread,
453
473
  });
454
474
  try {
455
- 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({
475
+ await assistantClient.beta.threads.messages.create(storageThreadId, Object.assign(Object.assign({ role: 'user', content }, ((attachments === null || attachments === void 0 ? void 0 : attachments.length) ? { attachments } : {})), { metadata: serializeMetadata({
456
476
  variables,
457
477
  workspaceId: assistant.workspaceId,
478
+ prisma,
458
479
  }) }));
459
480
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
460
481
  }
@@ -471,12 +492,13 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
471
492
  assistantId: assistant.id,
472
493
  threadId: thread.id,
473
494
  },
495
+ prisma,
474
496
  });
475
497
  return NextResponse.json({ error: 'Failed to create message.' }, { status: 500 });
476
498
  }
477
499
  let createRunStream;
478
500
  try {
479
- createRunStream = await client.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread }));
501
+ createRunStream = await assistantClient.beta.threads.runs.create(storageThreadId, await createRunOpts({ assistant, thread, prisma }));
480
502
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
481
503
  }
482
504
  catch (error) {
@@ -492,15 +514,16 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
492
514
  assistantId: assistant.id,
493
515
  threadId: thread.id,
494
516
  },
517
+ prisma,
495
518
  });
496
519
  return NextResponse.json({ error: 'Failed to create run stream.' }, { status: 500 });
497
520
  }
498
521
  let latestInProgressRunData = null;
499
522
  let latestCompletedRunData = null;
500
523
  return new Response(createMessageResponse({
501
- client,
524
+ client: assistantClient,
502
525
  createRunStream,
503
- handleToolCall: handleToolCall({ assistant, thread }),
526
+ handleToolCall: handleToolCall({ assistant, thread, prisma }),
504
527
  onStart: ({ controller, }) => {
505
528
  if (!isThreadCreated)
506
529
  return;
@@ -528,9 +551,10 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
528
551
  assistantId: assistant.id,
529
552
  threadId: thread.id,
530
553
  },
554
+ prisma,
531
555
  });
532
556
  // if (latestInProgressRunData) {
533
- // await client.beta.threads.runs.cancel(
557
+ // await assistantClient.beta.threads.runs.cancel(
534
558
  // latestInProgressRunData.thread_id,
535
559
  // latestInProgressRunData.id,
536
560
  // )
@@ -550,6 +574,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
550
574
  assistantId: assistant.id,
551
575
  threadId: thread.id,
552
576
  },
577
+ prisma,
553
578
  });
554
579
  }
555
580
  else if (event === 'thread.run.in_progress') {
@@ -567,7 +592,7 @@ export const buildPOST = ({ onSuccessCreateThread = () => void 0, }) => async (r
567
592
  }))
568
593
  return;
569
594
  if (latestInProgressRunData) {
570
- await client.beta.threads.runs.cancel(latestInProgressRunData.id, {
595
+ await assistantClient.beta.threads.runs.cancel(latestInProgressRunData.id, {
571
596
  thread_id: latestInProgressRunData.thread_id,
572
597
  });
573
598
  }
@@ -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,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEvD,UAAU,WAAW,EACrB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;GAiDF,CAAA;AAEH,eAAO,MAAM,GAAG,aAtDF,WAAW,SACd;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;GAmDwB,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 { getPrisma } 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 = getPrisma() } = {}) => 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,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEvD,UAAU,WAAW,EACrB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;GAiDF,CAAA;AAEH,eAAO,MAAM,GAAG,aAtDF,WAAW,SACd;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;GAmDwB,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 { getPrisma } 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 = getPrisma() } = {}) => 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,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEvD,UAAU,WAAW,EACrB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;;;;GA+CF,CAAA;AAEH,eAAO,MAAM,GAAG,aApDF,WAAW,SACd;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;;;;GAiDwB,CAAA;AAE7B,eAAO,MAAM,UAAU,GACpB,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEvD,SAAS,WAAW,EACpB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;;;;GAkFF,CAAA;AAEH,eAAO,MAAM,KAAK,YAvFL,WAAW,SACb;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;;;;GAoF4B,CAAA;AAEjC,eAAO,MAAM,WAAW,GACrB,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAEvD,UAAU,WAAW,EACrB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;;;;GA8DF,CAAA;AAEH,eAAO,MAAM,MAAM,aAnEL,WAAW,SACd;IACL,MAAM,EAAE,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC7C;;;;;;;;;;;;;;GAgE8B,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 { getPrisma } 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 = getPrisma() } = {}) => 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 = getPrisma() } = {}) => 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 = getPrisma() } = {}) => 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,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO;;;;;;;;;;;;;;GAmCxD,CAAA;AAEH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;GAAa,CAAA;AAE7B,eAAO,MAAM,SAAS,GACnB,aAA0B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MAClD,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 { getPrisma } 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 = getPrisma() } = {}) => 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 = getPrisma() } = {}) => 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
  });