@superinterface/server 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) 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/api-keys/[apiKeyId]/route.js +1 -1
  9. package/.next/server/app/api/api-keys/[apiKeyId]/route.js.nft.json +1 -1
  10. package/.next/server/app/api/api-keys/route.js +1 -1
  11. package/.next/server/app/api/api-keys/route.js.nft.json +1 -1
  12. package/.next/server/app/api/assistants/[assistantId]/functions/[functionId]/route.js +1 -1
  13. package/.next/server/app/api/assistants/[assistantId]/functions/[functionId]/route.js.nft.json +1 -1
  14. package/.next/server/app/api/assistants/[assistantId]/functions/route.js +1 -1
  15. package/.next/server/app/api/assistants/[assistantId]/functions/route.js.nft.json +1 -1
  16. package/.next/server/app/api/assistants/[assistantId]/initial-messages/route.js +1 -1
  17. package/.next/server/app/api/assistants/[assistantId]/initial-messages/route.js.nft.json +1 -1
  18. package/.next/server/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +1 -1
  19. package/.next/server/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js.nft.json +1 -1
  20. package/.next/server/app/api/assistants/[assistantId]/mcp-servers/route.js +1 -1
  21. package/.next/server/app/api/assistants/[assistantId]/mcp-servers/route.js.nft.json +1 -1
  22. package/.next/server/app/api/assistants/[assistantId]/route.js +1 -1
  23. package/.next/server/app/api/assistants/[assistantId]/route.js.nft.json +1 -1
  24. package/.next/server/app/api/assistants/route.js +1 -1
  25. package/.next/server/app/api/assistants/route.js.nft.json +1 -1
  26. package/.next/server/app/api/files/[fileId]/contents/route.js +1 -1
  27. package/.next/server/app/api/files/[fileId]/contents/route.js.nft.json +1 -1
  28. package/.next/server/app/api/files/route.js +1 -1
  29. package/.next/server/app/api/files/route.js.nft.json +1 -1
  30. package/.next/server/app/api/messages/route.js +1 -1
  31. package/.next/server/app/api/messages/route.js.nft.json +1 -1
  32. package/.next/server/app/api/providers/[modelProviderId]/assistants/route.js +1 -1
  33. package/.next/server/app/api/providers/[modelProviderId]/assistants/route.js.nft.json +1 -1
  34. package/.next/server/app/api/providers/[modelProviderId]/models/route.js +1 -1
  35. package/.next/server/app/api/providers/[modelProviderId]/models/route.js.nft.json +1 -1
  36. package/.next/server/app/api/providers/[modelProviderId]/route.js +1 -1
  37. package/.next/server/app/api/providers/[modelProviderId]/route.js.nft.json +1 -1
  38. package/.next/server/app/api/providers/route.js +1 -1
  39. package/.next/server/app/api/providers/route.js.nft.json +1 -1
  40. package/.next/server/app/api/tasks/[taskId]/route.js +1 -1
  41. package/.next/server/app/api/tasks/[taskId]/route.js.nft.json +1 -1
  42. package/.next/server/app/api/tasks/callback/route.js +1 -1
  43. package/.next/server/app/api/tasks/callback/route.js.nft.json +1 -1
  44. package/.next/server/app/api/tasks/route.js +1 -1
  45. package/.next/server/app/api/tasks/route.js.nft.json +1 -1
  46. package/.next/server/app/api/threads/runs/submit-client-tool-outputs/route.js +1 -1
  47. package/.next/server/app/api/threads/runs/submit-client-tool-outputs/route.js.nft.json +1 -1
  48. package/.next/server/app/api/workspaces/[workspaceId]/route.js +1 -1
  49. package/.next/server/app/api/workspaces/[workspaceId]/route.js.nft.json +1 -1
  50. package/.next/server/app/api/workspaces/route.js +1 -1
  51. package/.next/server/app/api/workspaces/route.js.nft.json +1 -1
  52. package/.next/server/app/index.html +1 -1
  53. package/.next/server/app/index.rsc +1 -1
  54. package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js +1 -1
  55. package/.next/server/chunks/[root-of-the-server]__0c1bc5ed._.js.map +1 -1
  56. package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js +1 -1
  57. package/.next/server/chunks/[root-of-the-server]__25ee13bc._.js.map +1 -1
  58. package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js +1 -1
  59. package/.next/server/chunks/[root-of-the-server]__2945c9e9._.js.map +1 -1
  60. package/.next/server/chunks/[root-of-the-server]__29635e8e._.js +1 -1
  61. package/.next/server/chunks/[root-of-the-server]__29635e8e._.js.map +1 -1
  62. package/.next/server/chunks/[root-of-the-server]__315f084a._.js +1 -1
  63. package/.next/server/chunks/[root-of-the-server]__315f084a._.js.map +1 -1
  64. package/.next/server/chunks/[root-of-the-server]__40ab45eb._.js +1 -1
  65. package/.next/server/chunks/[root-of-the-server]__40ab45eb._.js.map +1 -1
  66. package/.next/server/chunks/[root-of-the-server]__441cee00._.js +1 -1
  67. package/.next/server/chunks/[root-of-the-server]__441cee00._.js.map +1 -1
  68. package/.next/server/chunks/[root-of-the-server]__464a4377._.js +1 -1
  69. package/.next/server/chunks/[root-of-the-server]__464a4377._.js.map +1 -1
  70. package/.next/server/chunks/[root-of-the-server]__47b17fad._.js +38 -0
  71. package/.next/server/chunks/[root-of-the-server]__47b17fad._.js.map +1 -0
  72. package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js +1 -1
  73. package/.next/server/chunks/[root-of-the-server]__4e536bc0._.js.map +1 -1
  74. package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js +1 -1
  75. package/.next/server/chunks/[root-of-the-server]__583a7f1c._.js.map +1 -1
  76. package/.next/server/chunks/[root-of-the-server]__5abf1160._.js +1 -1
  77. package/.next/server/chunks/[root-of-the-server]__5abf1160._.js.map +1 -1
  78. package/.next/server/chunks/[root-of-the-server]__5d09614a._.js +1 -1
  79. package/.next/server/chunks/[root-of-the-server]__5d09614a._.js.map +1 -1
  80. package/.next/server/chunks/[root-of-the-server]__62d958e7._.js +1 -1
  81. package/.next/server/chunks/[root-of-the-server]__62d958e7._.js.map +1 -1
  82. package/.next/server/chunks/[root-of-the-server]__676affb1._.js +1 -1
  83. package/.next/server/chunks/[root-of-the-server]__676affb1._.js.map +1 -1
  84. package/.next/server/chunks/[root-of-the-server]__83461316._.js +1 -1
  85. package/.next/server/chunks/[root-of-the-server]__83461316._.js.map +1 -1
  86. package/.next/server/chunks/[root-of-the-server]__9a611d42._.js +1 -1
  87. package/.next/server/chunks/[root-of-the-server]__9a611d42._.js.map +1 -1
  88. package/.next/server/chunks/[root-of-the-server]__a878c913._.js +1 -1
  89. package/.next/server/chunks/[root-of-the-server]__a878c913._.js.map +1 -1
  90. package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js +1 -1
  91. package/.next/server/chunks/[root-of-the-server]__b10ec83e._.js.map +1 -1
  92. package/.next/server/chunks/[root-of-the-server]__c1629392._.js +1 -1
  93. package/.next/server/chunks/[root-of-the-server]__c1629392._.js.map +1 -1
  94. package/.next/server/chunks/[root-of-the-server]__eb816e13._.js +1 -1
  95. package/.next/server/chunks/[root-of-the-server]__eb816e13._.js.map +1 -1
  96. package/.next/server/chunks/[root-of-the-server]__f6f61507._.js +38 -0
  97. package/.next/server/chunks/[root-of-the-server]__f6f61507._.js.map +1 -0
  98. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js +1 -1
  99. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_cb746cf4.js.map +1 -1
  100. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js +1 -1
  101. package/.next/server/chunks/c4f00_next_dist_esm_build_templates_app-route_f952d9ab.js.map +1 -1
  102. package/.next/server/functions-config-manifest.json +1 -8
  103. package/.next/server/pages/404.html +1 -1
  104. package/.next/server/pages/500.html +1 -1
  105. package/.next/trace +1 -1
  106. package/dist/app/api/api-keys/[apiKeyId]/buildRoute.d.ts +52 -0
  107. package/dist/app/api/api-keys/[apiKeyId]/buildRoute.d.ts.map +1 -0
  108. package/dist/app/api/api-keys/[apiKeyId]/buildRoute.js +121 -0
  109. package/dist/app/api/api-keys/[apiKeyId]/route.d.ts +10 -21
  110. package/dist/app/api/api-keys/[apiKeyId]/route.d.ts.map +1 -1
  111. package/dist/app/api/api-keys/[apiKeyId]/route.js +6 -125
  112. package/dist/app/api/api-keys/buildRoute.d.ts +32 -0
  113. package/dist/app/api/api-keys/buildRoute.d.ts.map +1 -0
  114. package/dist/app/api/api-keys/buildRoute.js +104 -0
  115. package/dist/app/api/api-keys/builders.d.ts +31 -0
  116. package/dist/app/api/api-keys/builders.d.ts.map +1 -0
  117. package/dist/app/api/api-keys/builders.js +109 -0
  118. package/dist/app/api/api-keys/route.d.ts +5 -13
  119. package/dist/app/api/api-keys/route.d.ts.map +1 -1
  120. package/dist/app/api/api-keys/route.js +8 -108
  121. package/dist/app/api/assistants/[assistantId]/buildRoute.d.ts +120 -0
  122. package/dist/app/api/assistants/[assistantId]/buildRoute.d.ts.map +1 -0
  123. package/dist/app/api/assistants/[assistantId]/buildRoute.js +226 -0
  124. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.d.ts +167 -0
  125. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.d.ts.map +1 -0
  126. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/buildRoute.js +184 -0
  127. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts +10 -21
  128. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.d.ts.map +1 -1
  129. package/dist/app/api/assistants/[assistantId]/functions/[functionId]/route.js +6 -191
  130. package/dist/app/api/assistants/[assistantId]/functions/buildRoute.d.ts +114 -0
  131. package/dist/app/api/assistants/[assistantId]/functions/buildRoute.d.ts.map +1 -0
  132. package/dist/app/api/assistants/[assistantId]/functions/buildRoute.js +117 -0
  133. package/dist/app/api/assistants/[assistantId]/functions/route.d.ts +7 -15
  134. package/dist/app/api/assistants/[assistantId]/functions/route.d.ts.map +1 -1
  135. package/dist/app/api/assistants/[assistantId]/functions/route.js +5 -122
  136. package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.d.ts +40 -0
  137. package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.d.ts.map +1 -0
  138. package/dist/app/api/assistants/[assistantId]/initial-messages/buildRoute.js +85 -0
  139. package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts +7 -15
  140. package/dist/app/api/assistants/[assistantId]/initial-messages/route.d.ts.map +1 -1
  141. package/dist/app/api/assistants/[assistantId]/initial-messages/route.js +5 -90
  142. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.d.ts +89 -0
  143. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.d.ts.map +1 -0
  144. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/buildRoute.js +167 -0
  145. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts +10 -21
  146. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.d.ts.map +1 -1
  147. package/dist/app/api/assistants/[assistantId]/mcp-servers/[mcpServerId]/route.js +6 -174
  148. package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.d.ts +62 -0
  149. package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.d.ts.map +1 -0
  150. package/dist/app/api/assistants/[assistantId]/mcp-servers/buildRoute.js +115 -0
  151. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts +7 -15
  152. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.d.ts.map +1 -1
  153. package/dist/app/api/assistants/[assistantId]/mcp-servers/route.js +5 -120
  154. package/dist/app/api/assistants/[assistantId]/route.d.ts +11 -22
  155. package/dist/app/api/assistants/[assistantId]/route.d.ts.map +1 -1
  156. package/dist/app/api/assistants/[assistantId]/route.js +6 -233
  157. package/dist/app/api/assistants/buildRoute.d.ts +121 -0
  158. package/dist/app/api/assistants/buildRoute.d.ts.map +1 -0
  159. package/dist/app/api/assistants/buildRoute.js +144 -0
  160. package/dist/app/api/assistants/route.d.ts +7 -13
  161. package/dist/app/api/assistants/route.d.ts.map +1 -1
  162. package/dist/app/api/assistants/route.js +6 -148
  163. package/dist/app/api/files/[fileId]/contents/buildRoute.d.ts +18 -0
  164. package/dist/app/api/files/[fileId]/contents/buildRoute.d.ts.map +1 -0
  165. package/dist/app/api/files/[fileId]/contents/buildRoute.js +81 -0
  166. package/dist/app/api/files/[fileId]/contents/route.d.ts +3 -13
  167. package/dist/app/api/files/[fileId]/contents/route.d.ts.map +1 -1
  168. package/dist/app/api/files/[fileId]/contents/route.js +4 -84
  169. package/dist/app/api/files/buildRoute.d.ts +14 -0
  170. package/dist/app/api/files/buildRoute.d.ts.map +1 -0
  171. package/dist/app/api/files/buildRoute.js +88 -0
  172. package/dist/app/api/files/route.d.ts +4 -10
  173. package/dist/app/api/files/route.d.ts.map +1 -1
  174. package/dist/app/api/files/route.js +4 -91
  175. package/dist/app/api/messages/buildRoute.d.ts +34 -0
  176. package/dist/app/api/messages/buildRoute.d.ts.map +1 -0
  177. package/dist/app/api/messages/buildRoute.js +607 -0
  178. package/dist/app/api/messages/lib/initialMessagesResponse.d.ts.map +1 -1
  179. package/dist/app/api/messages/lib/initialMessagesResponse.js +1 -1
  180. package/dist/app/api/messages/route.d.ts +10 -22
  181. package/dist/app/api/messages/route.d.ts.map +1 -1
  182. package/dist/app/api/messages/route.js +6 -612
  183. package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.d.ts +24 -0
  184. package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.d.ts.map +1 -0
  185. package/dist/app/api/providers/[modelProviderId]/assistants/buildRoute.js +43 -0
  186. package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts +4 -9
  187. package/dist/app/api/providers/[modelProviderId]/assistants/route.d.ts.map +1 -1
  188. package/dist/app/api/providers/[modelProviderId]/assistants/route.js +4 -46
  189. package/dist/app/api/providers/[modelProviderId]/buildRoute.d.ts +61 -0
  190. package/dist/app/api/providers/[modelProviderId]/buildRoute.d.ts.map +1 -0
  191. package/dist/app/api/providers/[modelProviderId]/buildRoute.js +134 -0
  192. package/dist/app/api/providers/[modelProviderId]/models/buildRoute.d.ts +19 -0
  193. package/dist/app/api/providers/[modelProviderId]/models/buildRoute.d.ts.map +1 -0
  194. package/dist/app/api/providers/[modelProviderId]/models/buildRoute.js +43 -0
  195. package/dist/app/api/providers/[modelProviderId]/models/route.d.ts +4 -9
  196. package/dist/app/api/providers/[modelProviderId]/models/route.d.ts.map +1 -1
  197. package/dist/app/api/providers/[modelProviderId]/models/route.js +4 -46
  198. package/dist/app/api/providers/[modelProviderId]/route.d.ts +10 -21
  199. package/dist/app/api/providers/[modelProviderId]/route.d.ts.map +1 -1
  200. package/dist/app/api/providers/[modelProviderId]/route.js +6 -141
  201. package/dist/app/api/providers/buildRoute.d.ts +38 -0
  202. package/dist/app/api/providers/buildRoute.d.ts.map +1 -0
  203. package/dist/app/api/providers/buildRoute.js +75 -0
  204. package/dist/app/api/providers/route.d.ts +5 -13
  205. package/dist/app/api/providers/route.d.ts.map +1 -1
  206. package/dist/app/api/providers/route.js +5 -80
  207. package/dist/app/api/tasks/[taskId]/buildRoute.d.ts +19 -0
  208. package/dist/app/api/tasks/[taskId]/buildRoute.d.ts.map +1 -0
  209. package/dist/app/api/tasks/[taskId]/buildRoute.js +125 -0
  210. package/dist/app/api/tasks/[taskId]/route.d.ts +7 -57
  211. package/dist/app/api/tasks/[taskId]/route.d.ts.map +1 -1
  212. package/dist/app/api/tasks/[taskId]/route.js +6 -144
  213. package/dist/app/api/tasks/buildRoute.d.ts +36 -0
  214. package/dist/app/api/tasks/buildRoute.d.ts.map +1 -0
  215. package/dist/app/api/tasks/buildRoute.js +85 -0
  216. package/dist/app/api/tasks/callback/buildRoute.d.ts +6 -0
  217. package/dist/app/api/tasks/callback/buildRoute.d.ts.map +1 -0
  218. package/dist/app/api/tasks/callback/buildRoute.js +244 -0
  219. package/dist/app/api/tasks/callback/route.d.ts +2 -1
  220. package/dist/app/api/tasks/callback/route.d.ts.map +1 -1
  221. package/dist/app/api/tasks/callback/route.js +4 -244
  222. package/dist/app/api/tasks/route.d.ts +5 -13
  223. package/dist/app/api/tasks/route.d.ts.map +1 -1
  224. package/dist/app/api/tasks/route.js +5 -90
  225. package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.d.ts +10 -0
  226. package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.d.ts.map +1 -0
  227. package/dist/app/api/threads/runs/submit-client-tool-outputs/buildRoute.js +36 -0
  228. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts +2 -7
  229. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.d.ts.map +1 -1
  230. package/dist/app/api/threads/runs/submit-client-tool-outputs/route.js +3 -37
  231. package/dist/app/api/workspaces/[workspaceId]/buildRoute.d.ts +16 -0
  232. package/dist/app/api/workspaces/[workspaceId]/buildRoute.d.ts.map +1 -0
  233. package/dist/app/api/workspaces/[workspaceId]/buildRoute.js +89 -0
  234. package/dist/app/api/workspaces/[workspaceId]/route.d.ts +5 -31
  235. package/dist/app/api/workspaces/[workspaceId]/route.d.ts.map +1 -1
  236. package/dist/app/api/workspaces/[workspaceId]/route.js +5 -89
  237. package/dist/app/api/workspaces/buildRoute.d.ts +42 -0
  238. package/dist/app/api/workspaces/buildRoute.d.ts.map +1 -0
  239. package/dist/app/api/workspaces/buildRoute.js +78 -0
  240. package/dist/app/api/workspaces/route.d.ts +7 -27
  241. package/dist/app/api/workspaces/route.d.ts.map +1 -1
  242. package/dist/app/api/workspaces/route.js +6 -82
  243. package/dist/lib/functions/functionSchema.d.ts +56 -56
  244. package/dist/lib/functions/handleFunction/getFunction.d.ts +4 -4
  245. package/dist/lib/mcpServers/mcpServerSchema.d.ts +20 -20
  246. package/dist/lib/prisma/index.d.ts +2 -5
  247. package/dist/lib/prisma/index.d.ts.map +1 -1
  248. package/dist/lib/prisma/index.js +5 -70
  249. package/package.json +2 -2
  250. package/.next/server/chunks/[root-of-the-server]__228bff78._.js +0 -38
  251. package/.next/server/chunks/[root-of-the-server]__228bff78._.js.map +0 -1
  252. package/.next/server/chunks/[root-of-the-server]__3307123c._.js +0 -38
  253. package/.next/server/chunks/[root-of-the-server]__3307123c._.js.map +0 -1
  254. package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js +0 -38
  255. package/.next/server/chunks/[root-of-the-server]__50c5f12c._.js.map +0 -1
  256. package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js +0 -38
  257. package/.next/server/chunks/[root-of-the-server]__6b8ba839._.js.map +0 -1
  258. package/.next/server/chunks/[root-of-the-server]__e7819e95._.js +0 -38
  259. package/.next/server/chunks/[root-of-the-server]__e7819e95._.js.map +0 -1
  260. package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js +0 -38
  261. package/.next/server/chunks/[root-of-the-server]__f0dfab03._.js.map +0 -1
  262. package/.next/server/chunks/[root-of-the-server]__ff90af03._.js +0 -38
  263. package/.next/server/chunks/[root-of-the-server]__ff90af03._.js.map +0 -1
  264. /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_buildManifest.js +0 -0
  265. /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_clientMiddlewareManifest.json +0 -0
  266. /package/.next/static/{X1k4ISA6YteJsnJalPLxm → KhKDqyqUf75vkMRrXaWJf}/_ssgManifest.js +0 -0
@@ -0,0 +1,144 @@
1
+ import { headers } from 'next/headers';
2
+ import { ApiKeyType, StorageProviderType, ToolType, } from '@prisma/client';
3
+ import { NextResponse } from 'next/server';
4
+ import { z } from 'zod';
5
+ import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
6
+ import { serializeApiAssistant } from '../../../lib/assistants/serializeApiAssistant';
7
+ import { getApiKey } from '../../../lib/apiKeys/getApiKey';
8
+ const createAssistantSchema = z
9
+ .object({
10
+ storageProviderType: z.nativeEnum(StorageProviderType),
11
+ storageProviderAssistantId: z.string().nullable().optional(),
12
+ modelProviderId: z.string(),
13
+ model: z.string(),
14
+ name: z.string().optional(),
15
+ description: z.string().optional().default(''),
16
+ instructions: z.string().optional().default(''),
17
+ codeInterpreterEnabled: z.boolean().optional().default(false),
18
+ fileSearchEnabled: z.boolean().optional().default(false),
19
+ })
20
+ .superRefine((data, ctx) => {
21
+ if (data.storageProviderType === StorageProviderType.SUPERINTERFACE_CLOUD &&
22
+ data.storageProviderAssistantId) {
23
+ ctx.addIssue({
24
+ code: z.ZodIssueCode.custom,
25
+ message: 'storageProviderAssistantId should not be provided for SUPERINTERFACE_CLOUD',
26
+ path: ['storageProviderAssistantId'],
27
+ });
28
+ }
29
+ if (data.storageProviderType !== StorageProviderType.SUPERINTERFACE_CLOUD &&
30
+ !data.storageProviderAssistantId) {
31
+ ctx.addIssue({
32
+ code: z.ZodIssueCode.custom,
33
+ message: 'storageProviderAssistantId is required for this storage provider',
34
+ path: ['storageProviderAssistantId'],
35
+ });
36
+ }
37
+ });
38
+ export const buildGET = ({ prisma }) => async () => {
39
+ const headersList = await headers();
40
+ const authorization = headersList.get('authorization');
41
+ if (!authorization) {
42
+ return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
43
+ }
44
+ const privateApiKey = await getApiKey({
45
+ authorization,
46
+ type: ApiKeyType.PRIVATE,
47
+ prisma,
48
+ });
49
+ if (!privateApiKey) {
50
+ return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
51
+ }
52
+ const assistants = await prisma.assistant.findMany({
53
+ where: {
54
+ workspaceId: privateApiKey.workspaceId,
55
+ },
56
+ include: {
57
+ tools: true,
58
+ avatar: {
59
+ include: {
60
+ imageAvatar: true,
61
+ iconAvatar: true,
62
+ },
63
+ },
64
+ },
65
+ });
66
+ return NextResponse.json({
67
+ assistants: assistants.map((a) => serializeApiAssistant({ assistant: a })),
68
+ }, { headers: cacheHeaders });
69
+ };
70
+ export const buildPOST = ({ prisma }) => async (request) => {
71
+ const headersList = await headers();
72
+ const authorization = headersList.get('authorization');
73
+ if (!authorization) {
74
+ return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
75
+ }
76
+ const privateApiKey = await getApiKey({
77
+ authorization,
78
+ type: ApiKeyType.PRIVATE,
79
+ prisma,
80
+ });
81
+ if (!privateApiKey) {
82
+ return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
83
+ }
84
+ const parseResult = createAssistantSchema.safeParse(await request.json());
85
+ if (!parseResult.success) {
86
+ return NextResponse.json({
87
+ error: `Missing required fields. ${JSON.stringify(parseResult.error.format())}`,
88
+ }, { status: 400 });
89
+ }
90
+ const { storageProviderType, storageProviderAssistantId, modelProviderId, model, name, description, instructions, codeInterpreterEnabled, fileSearchEnabled, } = parseResult.data;
91
+ const workspaceId = privateApiKey.workspaceId;
92
+ const assistant = await prisma.assistant.create({
93
+ data: {
94
+ workspace: { connect: { id: workspaceId } },
95
+ modelProvider: { connect: { id: modelProviderId } },
96
+ modelSlug: model,
97
+ name,
98
+ description,
99
+ instructions,
100
+ storageProviderType,
101
+ openaiAssistantId: storageProviderAssistantId !== null && storageProviderAssistantId !== void 0 ? storageProviderAssistantId : null,
102
+ tools: {
103
+ create: [
104
+ ...(fileSearchEnabled
105
+ ? [
106
+ {
107
+ type: ToolType.FILE_SEARCH,
108
+ fileSearchTool: {
109
+ create: {},
110
+ },
111
+ },
112
+ ]
113
+ : []),
114
+ ...(codeInterpreterEnabled
115
+ ? [
116
+ {
117
+ type: ToolType.CODE_INTERPRETER,
118
+ codeInterpreterTool: {
119
+ create: {},
120
+ },
121
+ },
122
+ ]
123
+ : []),
124
+ ],
125
+ },
126
+ },
127
+ include: {
128
+ tools: true,
129
+ avatar: {
130
+ include: {
131
+ imageAvatar: true,
132
+ iconAvatar: true,
133
+ },
134
+ },
135
+ },
136
+ });
137
+ return NextResponse.json({
138
+ assistant: serializeApiAssistant({ assistant }),
139
+ }, { headers: cacheHeaders });
140
+ };
141
+ export const buildOPTIONS = () => () => NextResponse.json({}, {
142
+ headers: cacheHeaders,
143
+ });
144
+ export { createAssistantSchema };
@@ -1,10 +1,8 @@
1
- import { type PrismaClient } from '@prisma/client';
2
- import { NextResponse } from 'next/server';
3
- export declare const buildGET: ({ prisma: providedPrisma }?: {
4
- prisma?: PrismaClient;
5
- }) => () => Promise<NextResponse<{
1
+ import { createAssistantSchema } from './buildRoute';
2
+ export { createAssistantSchema };
3
+ export declare const GET: () => Promise<import("next/server").NextResponse<{
6
4
  error: string;
7
- }> | NextResponse<{
5
+ }> | import("next/server").NextResponse<{
8
6
  assistants: {
9
7
  id: string;
10
8
  storageProviderType: import("@prisma/client").$Enums.StorageProviderType;
@@ -29,12 +27,9 @@ export declare const buildGET: ({ prisma: providedPrisma }?: {
29
27
  };
30
28
  }[];
31
29
  }>>;
32
- export declare const GET: ReturnType<typeof buildGET>;
33
- export declare const buildPOST: ({ prisma: providedPrisma }?: {
34
- prisma?: PrismaClient;
35
- }) => (request: Request) => Promise<NextResponse<{
30
+ export declare const POST: (request: Request) => Promise<import("next/server").NextResponse<{
36
31
  error: string;
37
- }> | NextResponse<{
32
+ }> | import("next/server").NextResponse<{
38
33
  assistant: {
39
34
  id: string;
40
35
  storageProviderType: import("@prisma/client").$Enums.StorageProviderType;
@@ -59,6 +54,5 @@ export declare const buildPOST: ({ prisma: providedPrisma }?: {
59
54
  };
60
55
  };
61
56
  }>>;
62
- export declare const POST: ReturnType<typeof buildPOST>;
63
- export declare const OPTIONS: () => NextResponse<{}>;
57
+ export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
64
58
  //# sourceMappingURL=route.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/assistants/route.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAO1C,eAAO,MAAM,QAAQ,GAClB,6BAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO;;;;;;;;;;;;;;;;;;;;;;;;;;GA6C1D,CAAA;AAEH,eAAO,MAAM,GAAG,EACU,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAA;AAwCrD,eAAO,MAAM,SAAS,GACnB,6BAA4B;IAAE,MAAM,CAAC,EAAE,YAAY,CAAA;CAAO,MACpD,SAAS,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;GAkGtB,CAAA;AAEH,eAAO,MAAM,IAAI,EACU,UAAU,CAAC,OAAO,SAAS,CAAC,CAAA;AAEvD,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../src/app/api/assistants/route.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,qBAAqB,EACtB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,qBAAqB,EAAE,CAAA;AAEhC,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;GAAuB,CAAA;AAEvC,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;GAAwB,CAAA;AAEzC,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
@@ -1,148 +1,6 @@
1
- import { headers } from 'next/headers';
2
- import { ApiKeyType, StorageProviderType, ToolType, } from '@prisma/client';
3
- import { NextResponse } from 'next/server';
4
- import { z } from 'zod';
5
- import { cacheHeaders } from '../../../lib/cache/cacheHeaders';
6
- import { resolvePrisma } from '../../../lib/prisma';
7
- import { serializeApiAssistant } from '../../../lib/assistants/serializeApiAssistant';
8
- import { getApiKey } from '../../../lib/apiKeys/getApiKey';
9
- export const buildGET = ({ prisma: providedPrisma } = {}) => async () => {
10
- const prisma = resolvePrisma(providedPrisma);
11
- const headersList = await headers();
12
- const authorization = headersList.get('authorization');
13
- if (!authorization) {
14
- return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
15
- }
16
- const privateApiKey = await getApiKey({
17
- authorization,
18
- type: ApiKeyType.PRIVATE,
19
- prisma,
20
- });
21
- if (!privateApiKey) {
22
- return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
23
- }
24
- const assistants = await prisma.assistant.findMany({
25
- where: {
26
- workspaceId: privateApiKey.workspaceId,
27
- },
28
- include: {
29
- tools: true,
30
- avatar: {
31
- include: {
32
- imageAvatar: true,
33
- iconAvatar: true,
34
- },
35
- },
36
- },
37
- });
38
- return NextResponse.json({
39
- assistants: assistants.map((a) => serializeApiAssistant({ assistant: a })),
40
- }, { headers: cacheHeaders });
41
- };
42
- export const GET = ((...args) => buildGET()(...args));
43
- const createAssistantSchema = z
44
- .object({
45
- storageProviderType: z.nativeEnum(StorageProviderType),
46
- storageProviderAssistantId: z.string().nullable().optional(),
47
- modelProviderId: z.string(),
48
- model: z.string(),
49
- name: z.string().optional(),
50
- description: z.string().optional().default(''),
51
- instructions: z.string().optional().default(''),
52
- codeInterpreterEnabled: z.boolean().optional().default(false),
53
- fileSearchEnabled: z.boolean().optional().default(false),
54
- })
55
- .superRefine((data, ctx) => {
56
- if (data.storageProviderType === StorageProviderType.SUPERINTERFACE_CLOUD &&
57
- data.storageProviderAssistantId) {
58
- ctx.addIssue({
59
- code: z.ZodIssueCode.custom,
60
- message: 'storageProviderAssistantId should not be provided for SUPERINTERFACE_CLOUD',
61
- path: ['storageProviderAssistantId'],
62
- });
63
- }
64
- if (data.storageProviderType !== StorageProviderType.SUPERINTERFACE_CLOUD &&
65
- !data.storageProviderAssistantId) {
66
- ctx.addIssue({
67
- code: z.ZodIssueCode.custom,
68
- message: 'storageProviderAssistantId is required for this storage provider',
69
- path: ['storageProviderAssistantId'],
70
- });
71
- }
72
- });
73
- export const buildPOST = ({ prisma: providedPrisma } = {}) => async (request) => {
74
- const prisma = resolvePrisma(providedPrisma);
75
- const headersList = await headers();
76
- const authorization = headersList.get('authorization');
77
- if (!authorization) {
78
- return NextResponse.json({ error: 'No authorization header found' }, { status: 400 });
79
- }
80
- const privateApiKey = await getApiKey({
81
- authorization,
82
- type: ApiKeyType.PRIVATE,
83
- prisma,
84
- });
85
- if (!privateApiKey) {
86
- return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
87
- }
88
- const parseResult = createAssistantSchema.safeParse(await request.json());
89
- if (!parseResult.success) {
90
- return NextResponse.json({
91
- error: `Missing required fields. ${JSON.stringify(parseResult.error.format())}`,
92
- }, { status: 400 });
93
- }
94
- const { storageProviderType, storageProviderAssistantId, modelProviderId, model, name, description, instructions, codeInterpreterEnabled, fileSearchEnabled, } = parseResult.data;
95
- const workspaceId = privateApiKey.workspaceId;
96
- const assistant = await prisma.assistant.create({
97
- data: {
98
- workspace: { connect: { id: workspaceId } },
99
- modelProvider: { connect: { id: modelProviderId } },
100
- modelSlug: model,
101
- name,
102
- description,
103
- instructions,
104
- storageProviderType,
105
- openaiAssistantId: storageProviderAssistantId !== null && storageProviderAssistantId !== void 0 ? storageProviderAssistantId : null,
106
- tools: {
107
- create: [
108
- ...(fileSearchEnabled
109
- ? [
110
- {
111
- type: ToolType.FILE_SEARCH,
112
- fileSearchTool: {
113
- create: {},
114
- },
115
- },
116
- ]
117
- : []),
118
- ...(codeInterpreterEnabled
119
- ? [
120
- {
121
- type: ToolType.CODE_INTERPRETER,
122
- codeInterpreterTool: {
123
- create: {},
124
- },
125
- },
126
- ]
127
- : []),
128
- ],
129
- },
130
- },
131
- include: {
132
- tools: true,
133
- avatar: {
134
- include: {
135
- imageAvatar: true,
136
- iconAvatar: true,
137
- },
138
- },
139
- },
140
- });
141
- return NextResponse.json({
142
- assistant: serializeApiAssistant({ assistant }),
143
- }, { headers: cacheHeaders });
144
- };
145
- export const POST = ((...args) => buildPOST()(...args));
146
- export const OPTIONS = () => NextResponse.json({}, {
147
- headers: cacheHeaders,
148
- });
1
+ import { prisma } from '../../../lib/prisma';
2
+ import { buildGET, buildOPTIONS, buildPOST, createAssistantSchema, } from './buildRoute';
3
+ export { createAssistantSchema };
4
+ export const GET = buildGET({ prisma });
5
+ export const POST = buildPOST({ prisma });
6
+ export const OPTIONS = buildOPTIONS();
@@ -0,0 +1,18 @@
1
+ import type { OpenAI } from 'openai';
2
+ import { type Prisma, type PrismaClient } from '@prisma/client';
3
+ import { type NextRequest, NextResponse } from 'next/server';
4
+ type PurposeAssistantsResponse = ({ file, workspaceAccessWhere, }: {
5
+ file: OpenAI.Files.FileObject;
6
+ workspaceAccessWhere: Prisma.WorkspaceWhereInput;
7
+ }) => Promise<NextResponse> | NextResponse;
8
+ export declare const buildGET: ({ prisma, purposeAssistantsResponse, }: {
9
+ prisma: PrismaClient;
10
+ purposeAssistantsResponse?: PurposeAssistantsResponse;
11
+ }) => (request: NextRequest, props: {
12
+ params: Promise<{
13
+ fileId: string;
14
+ }>;
15
+ }) => Promise<NextResponse<unknown>>;
16
+ export declare const buildOPTIONS: () => () => NextResponse<{}>;
17
+ export {};
18
+ //# sourceMappingURL=buildRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/files/[fileId]/contents/buildRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM5D,KAAK,yBAAyB,GAAG,CAAC,EAChC,IAAI,EACJ,oBAAoB,GACrB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAA;IAC7B,oBAAoB,EAAE,MAAM,CAAC,mBAAmB,CAAA;CACjD,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAA;AAE1C,eAAO,MAAM,QAAQ,GAClB,wCAIE;IACD,MAAM,EAAE,YAAY,CAAA;IACpB,yBAAyB,CAAC,EAAE,yBAAyB,CAAA;CACtD,MAEC,SAAS,WAAW,EACpB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QACd,MAAM,EAAE,MAAM,CAAA;KACf,CAAC,CAAA;CACH,mCA6GF,CAAA;AAEH,eAAO,MAAM,YAAY,8BAMtB,CAAA"}
@@ -0,0 +1,81 @@
1
+ import { isString } from 'radash';
2
+ import { NextResponse } from 'next/server';
3
+ import { cacheHeaders } from '../../../../../lib/cache/cacheHeaders';
4
+ import { assistantClientAdapter } from '../../../../../lib/assistants/assistantClientAdapter';
5
+ import { workspaceAccessWhere as getWorkspaceAccessWhere } from '../../../../../lib/apiKeys/workspaceAccessWhere';
6
+ import { isOpenaiAssistantsStorageProvider } from '../../../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
7
+ export const buildGET = ({ prisma, purposeAssistantsResponse = () => NextResponse.json({ error: 'No file source found' }, { status: 404 }), }) => async (request, props) => {
8
+ var _a, _b;
9
+ const params = await props.params;
10
+ const { fileId } = params;
11
+ const assistantId = request.nextUrl.searchParams.get('assistantId');
12
+ if (!isString(assistantId)) {
13
+ return NextResponse.json({ error: 'Invalid assistantId' }, { status: 400 });
14
+ }
15
+ const publicApiKey = request.nextUrl.searchParams.get('publicApiKey');
16
+ if (!isString(publicApiKey)) {
17
+ return NextResponse.json({ error: 'Invalid publicApiKey' }, { status: 400 });
18
+ }
19
+ const workspaceAccessWhere = await getWorkspaceAccessWhere({
20
+ publicApiKey,
21
+ prisma,
22
+ });
23
+ if (!workspaceAccessWhere) {
24
+ return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
25
+ }
26
+ if (!assistantId) {
27
+ return NextResponse.json({ error: 'No assistantId found' }, { status: 400 });
28
+ }
29
+ const assistant = await prisma.assistant.findFirst({
30
+ where: {
31
+ id: assistantId,
32
+ workspace: workspaceAccessWhere,
33
+ },
34
+ include: {
35
+ modelProvider: true,
36
+ tools: {
37
+ include: {
38
+ fileSearchTool: true,
39
+ webSearchTool: true,
40
+ imageGenerationTool: true,
41
+ codeInterpreterTool: true,
42
+ computerUseTool: true,
43
+ },
44
+ },
45
+ mcpServers: {
46
+ include: {
47
+ computerUseTool: true,
48
+ stdioTransport: true,
49
+ sseTransport: true,
50
+ httpTransport: true,
51
+ },
52
+ },
53
+ functions: true,
54
+ },
55
+ });
56
+ if (!assistant) {
57
+ return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
58
+ }
59
+ if (isOpenaiAssistantsStorageProvider({
60
+ storageProviderType: assistant.storageProviderType,
61
+ }) &&
62
+ !assistant.openaiAssistantId) {
63
+ return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
64
+ }
65
+ const assistantClient = assistantClientAdapter({ assistant, prisma });
66
+ const file = await assistantClient.files.retrieve(fileId);
67
+ if (!file) {
68
+ return NextResponse.json({ error: 'No file found' }, { status: 404 });
69
+ }
70
+ if (file.purpose === 'assistants') {
71
+ return purposeAssistantsResponse({ file, workspaceAccessWhere });
72
+ }
73
+ const fileContentResponse = await assistantClient.files.content(fileId);
74
+ const fileData = await fileContentResponse.arrayBuffer();
75
+ return new NextResponse(fileData, {
76
+ headers: Object.assign(Object.assign({}, cacheHeaders), { 'Content-Type': (_a = fileContentResponse.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'application/octet-stream', 'Content-Disposition': (_b = fileContentResponse.headers.get('Content-Disposition')) !== null && _b !== void 0 ? _b : 'inline' }),
77
+ });
78
+ };
79
+ export const buildOPTIONS = () => () => NextResponse.json({}, {
80
+ headers: cacheHeaders,
81
+ });
@@ -1,17 +1,7 @@
1
- import type { OpenAI } from 'openai';
2
- import { type Prisma, type PrismaClient } from '@prisma/client';
3
- import { type NextRequest, NextResponse } from 'next/server';
4
- export declare const buildGET: ({ prisma: providedPrisma, purposeAssistantsResponse, }?: {
5
- prisma?: PrismaClient;
6
- purposeAssistantsResponse?: ({ file, }: {
7
- file: OpenAI.Files.FileObject;
8
- workspaceAccessWhere: Prisma.WorkspaceWhereInput;
9
- }) => Promise<NextResponse> | NextResponse;
10
- }) => (request: NextRequest, props: {
1
+ export declare const GET: (request: import("next/server").NextRequest, props: {
11
2
  params: Promise<{
12
3
  fileId: string;
13
4
  }>;
14
- }) => Promise<NextResponse<unknown>>;
15
- export declare const GET: ReturnType<typeof buildGET>;
16
- export declare const OPTIONS: () => NextResponse<{}>;
5
+ }) => Promise<import("next/server").NextResponse<unknown>>;
6
+ export declare const OPTIONS: () => import("next/server").NextResponse<{}>;
17
7
  //# sourceMappingURL=route.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/files/[fileId]/contents/route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAO5D,eAAO,MAAM,QAAQ,GAClB,yDAIE;IACD,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,yBAAyB,CAAC,EAAE,CAAC,EAC3B,IAAI,GACL,EAAE;QACD,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAA;QAC7B,oBAAoB,EAAE,MAAM,CAAC,mBAAmB,CAAA;KACjD,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAA;CACtC,MAEJ,SAAS,WAAW,EACpB,OAAO;IACL,MAAM,EAAE,OAAO,CAAC;QACd,MAAM,EAAE,MAAM,CAAA;KACf,CAAC,CAAA;CACH,mCA8GF,CAAA;AAEH,eAAO,MAAM,GAAG,EACY,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAA;AAEvD,eAAO,MAAM,OAAO,wBAMjB,CAAA"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../../src/app/api/files/[fileId]/contents/route.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;;0DAAuB,CAAA;AAEvC,eAAO,MAAM,OAAO,8CAAiB,CAAA"}
@@ -1,84 +1,4 @@
1
- import { isString } from 'radash';
2
- import { NextResponse } from 'next/server';
3
- import { cacheHeaders } from '../../../../../lib/cache/cacheHeaders';
4
- import { assistantClientAdapter } from '../../../../../lib/assistants/assistantClientAdapter';
5
- import { workspaceAccessWhere as getWorkspaceAccessWhere } from '../../../../../lib/apiKeys/workspaceAccessWhere';
6
- import { resolvePrisma } from '../../../../../lib/prisma';
7
- import { isOpenaiAssistantsStorageProvider } from '../../../../../lib/storageProviders/isOpenaiAssistantsStorageProvider';
8
- export const buildGET = ({ prisma: providedPrisma, purposeAssistantsResponse = () => NextResponse.json({ error: 'No file source found' }, { status: 404 }), } = {}) => async (request, props) => {
9
- var _a, _b;
10
- const prisma = resolvePrisma(providedPrisma);
11
- const params = await props.params;
12
- const { fileId } = params;
13
- const assistantId = request.nextUrl.searchParams.get('assistantId');
14
- if (!isString(assistantId)) {
15
- return NextResponse.json({ error: 'Invalid assistantId' }, { status: 400 });
16
- }
17
- const publicApiKey = request.nextUrl.searchParams.get('publicApiKey');
18
- if (!isString(publicApiKey)) {
19
- return NextResponse.json({ error: 'Invalid publicApiKey' }, { status: 400 });
20
- }
21
- const workspaceAccessWhere = await getWorkspaceAccessWhere({
22
- publicApiKey,
23
- prisma,
24
- });
25
- if (!workspaceAccessWhere) {
26
- return NextResponse.json({ error: 'Invalid api key' }, { status: 400 });
27
- }
28
- if (!assistantId) {
29
- return NextResponse.json({ error: 'No assistantId found' }, { status: 400 });
30
- }
31
- const assistant = await prisma.assistant.findFirst({
32
- where: {
33
- id: assistantId,
34
- workspace: workspaceAccessWhere,
35
- },
36
- include: {
37
- modelProvider: true,
38
- tools: {
39
- include: {
40
- fileSearchTool: true,
41
- webSearchTool: true,
42
- imageGenerationTool: true,
43
- codeInterpreterTool: true,
44
- computerUseTool: true,
45
- },
46
- },
47
- mcpServers: {
48
- include: {
49
- computerUseTool: true,
50
- stdioTransport: true,
51
- sseTransport: true,
52
- httpTransport: true,
53
- },
54
- },
55
- functions: true,
56
- },
57
- });
58
- if (!assistant) {
59
- return NextResponse.json({ error: 'No assistant found' }, { status: 400 });
60
- }
61
- if (isOpenaiAssistantsStorageProvider({
62
- storageProviderType: assistant.storageProviderType,
63
- }) &&
64
- !assistant.openaiAssistantId) {
65
- return NextResponse.json({ error: 'Assistant setup is not done.' }, { status: 400 });
66
- }
67
- const assistantClient = assistantClientAdapter({ assistant, prisma });
68
- const file = await assistantClient.files.retrieve(fileId);
69
- if (!file) {
70
- return NextResponse.json({ error: 'No file found' }, { status: 404 });
71
- }
72
- if (file.purpose === 'assistants') {
73
- return purposeAssistantsResponse({ file, workspaceAccessWhere });
74
- }
75
- const fileContentResponse = await assistantClient.files.content(fileId);
76
- const fileData = await fileContentResponse.arrayBuffer();
77
- return new NextResponse(fileData, {
78
- headers: Object.assign(Object.assign({}, cacheHeaders), { 'Content-Type': (_a = fileContentResponse.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'application/octet-stream', 'Content-Disposition': (_b = fileContentResponse.headers.get('Content-Disposition')) !== null && _b !== void 0 ? _b : 'inline' }),
79
- });
80
- };
81
- export const GET = ((...args) => buildGET({})(...args));
82
- export const OPTIONS = () => NextResponse.json({}, {
83
- headers: cacheHeaders,
84
- });
1
+ import { prisma } from '../../../../../lib/prisma';
2
+ import { buildGET, buildOPTIONS } from './buildRoute';
3
+ export const GET = buildGET({ prisma });
4
+ export const OPTIONS = buildOPTIONS();
@@ -0,0 +1,14 @@
1
+ import type OpenAI from 'openai';
2
+ import { type PrismaClient } from '@prisma/client';
3
+ import { type NextRequest, NextResponse } from 'next/server';
4
+ export declare const buildPOST: ({ prisma }: {
5
+ prisma: PrismaClient;
6
+ }) => (request: NextRequest) => Promise<NextResponse<{
7
+ error: string;
8
+ }> | NextResponse<{
9
+ file: OpenAI.Files.FileObject & {
10
+ _request_id?: string | null;
11
+ };
12
+ }>>;
13
+ export declare const buildOPTIONS: () => () => NextResponse<{}>;
14
+ //# sourceMappingURL=buildRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildRoute.d.ts","sourceRoot":"","sources":["../../../../src/app/api/files/buildRoute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM5D,eAAO,MAAM,SAAS,GACnB,YAAY;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,MAC9B,SAAS,WAAW;;;;;;GA8G1B,CAAA;AAEH,eAAO,MAAM,YAAY,8BAMtB,CAAA"}