@gaganref/confect-server 0.0.0-stage → 10.3.1-fork.10

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 (367) hide show
  1. package/CHANGELOG.md +2119 -0
  2. package/LICENSE +7 -0
  3. package/README.md +16 -2
  4. package/dist/ActionCtx.d.ts +10 -0
  5. package/dist/ActionCtx.d.ts.map +1 -0
  6. package/dist/ActionCtx.js +18 -0
  7. package/dist/ActionCtx.js.map +1 -0
  8. package/dist/ActionRunner.d.ts +16 -0
  9. package/dist/ActionRunner.d.ts.map +1 -0
  10. package/dist/ActionRunner.js +18 -0
  11. package/dist/ActionRunner.js.map +1 -0
  12. package/dist/AiGatewayDecisionClient.d.ts +20 -0
  13. package/dist/AiGatewayDecisionClient.d.ts.map +1 -0
  14. package/dist/AiGatewayDecisionClient.js +31 -0
  15. package/dist/AiGatewayDecisionClient.js.map +1 -0
  16. package/dist/AiGatewayDecisionModel.d.ts +24 -0
  17. package/dist/AiGatewayDecisionModel.d.ts.map +1 -0
  18. package/dist/AiGatewayDecisionModel.js +27 -0
  19. package/dist/AiGatewayDecisionModel.js.map +1 -0
  20. package/dist/AiGatewayLanguageClient.d.ts +21 -0
  21. package/dist/AiGatewayLanguageClient.d.ts.map +1 -0
  22. package/dist/AiGatewayLanguageClient.js +32 -0
  23. package/dist/AiGatewayLanguageClient.js.map +1 -0
  24. package/dist/AiGatewayLanguageModel.d.ts +95 -0
  25. package/dist/AiGatewayLanguageModel.d.ts.map +1 -0
  26. package/dist/AiGatewayLanguageModel.js +42 -0
  27. package/dist/AiGatewayLanguageModel.js.map +1 -0
  28. package/dist/Auth.d.ts +20 -0
  29. package/dist/Auth.d.ts.map +1 -0
  30. package/dist/Auth.js +31 -0
  31. package/dist/Auth.js.map +1 -0
  32. package/dist/BlobNotFoundError.d.ts +9 -0
  33. package/dist/BlobNotFoundError.d.ts.map +1 -0
  34. package/dist/BlobNotFoundError.js +13 -0
  35. package/dist/BlobNotFoundError.js.map +1 -0
  36. package/dist/Callback.d.ts +31 -0
  37. package/dist/Callback.d.ts.map +1 -0
  38. package/dist/Callback.js +182 -0
  39. package/dist/Callback.js.map +1 -0
  40. package/dist/ComponentCtx.d.ts +71 -0
  41. package/dist/ComponentCtx.d.ts.map +1 -0
  42. package/dist/ComponentCtx.js +0 -0
  43. package/dist/ConvexConfigProvider.d.ts +21 -0
  44. package/dist/ConvexConfigProvider.d.ts.map +1 -0
  45. package/dist/ConvexConfigProvider.js +36 -0
  46. package/dist/ConvexConfigProvider.js.map +1 -0
  47. package/dist/ConvexFunctionDefinitions.d.ts +25 -0
  48. package/dist/ConvexFunctionDefinitions.d.ts.map +1 -0
  49. package/dist/ConvexFunctionDefinitions.js +25 -0
  50. package/dist/ConvexFunctionDefinitions.js.map +1 -0
  51. package/dist/ConvexLogger.d.ts +17 -0
  52. package/dist/ConvexLogger.d.ts.map +1 -0
  53. package/dist/ConvexLogger.js +33 -0
  54. package/dist/ConvexLogger.js.map +1 -0
  55. package/dist/CronJob.d.ts +14 -0
  56. package/dist/CronJob.d.ts.map +1 -0
  57. package/dist/CronJob.js +22 -0
  58. package/dist/CronJob.js.map +1 -0
  59. package/dist/CronJobs.d.ts +22 -0
  60. package/dist/CronJobs.d.ts.map +1 -0
  61. package/dist/CronJobs.js +83 -0
  62. package/dist/CronJobs.js.map +1 -0
  63. package/dist/DataModel.d.ts +28 -0
  64. package/dist/DataModel.d.ts.map +1 -0
  65. package/dist/DataModel.js +7 -0
  66. package/dist/DataModel.js.map +1 -0
  67. package/dist/DatabaseReader.d.ts +26 -0
  68. package/dist/DatabaseReader.d.ts.map +1 -0
  69. package/dist/DatabaseReader.js +33 -0
  70. package/dist/DatabaseReader.js.map +1 -0
  71. package/dist/DatabaseSchema.d.ts +67 -0
  72. package/dist/DatabaseSchema.d.ts.map +1 -0
  73. package/dist/DatabaseSchema.js +61 -0
  74. package/dist/DatabaseSchema.js.map +1 -0
  75. package/dist/DatabaseWriter.d.ts +44 -0
  76. package/dist/DatabaseWriter.d.ts.map +1 -0
  77. package/dist/DatabaseWriter.js +47 -0
  78. package/dist/DatabaseWriter.js.map +1 -0
  79. package/dist/Document.d.ts +37 -0
  80. package/dist/Document.d.ts.map +1 -0
  81. package/dist/Document.js +54 -0
  82. package/dist/Document.js.map +1 -0
  83. package/dist/ExecutionMetadata.d.ts +13 -0
  84. package/dist/ExecutionMetadata.d.ts.map +1 -0
  85. package/dist/ExecutionMetadata.js +19 -0
  86. package/dist/ExecutionMetadata.js.map +1 -0
  87. package/dist/FunctionImpl.d.ts +39 -0
  88. package/dist/FunctionImpl.d.ts.map +1 -0
  89. package/dist/FunctionImpl.js +46 -0
  90. package/dist/FunctionImpl.js.map +1 -0
  91. package/dist/FunctionRegistryItem.d.ts +36 -0
  92. package/dist/FunctionRegistryItem.d.ts.map +1 -0
  93. package/dist/FunctionRegistryItem.js +34 -0
  94. package/dist/FunctionRegistryItem.js.map +1 -0
  95. package/dist/GroupImpl.d.ts +77 -0
  96. package/dist/GroupImpl.d.ts.map +1 -0
  97. package/dist/GroupImpl.js +81 -0
  98. package/dist/GroupImpl.js.map +1 -0
  99. package/dist/GroupRegistry.d.ts +8 -0
  100. package/dist/GroupRegistry.d.ts.map +1 -0
  101. package/dist/GroupRegistry.js +26 -0
  102. package/dist/GroupRegistry.js.map +1 -0
  103. package/dist/Handler.d.ts +47 -0
  104. package/dist/Handler.d.ts.map +1 -0
  105. package/dist/Handler.js +7 -0
  106. package/dist/Handler.js.map +1 -0
  107. package/dist/HttpRouter.d.ts +80 -0
  108. package/dist/HttpRouter.d.ts.map +1 -0
  109. package/dist/HttpRouter.js +195 -0
  110. package/dist/HttpRouter.js.map +1 -0
  111. package/dist/MiddlewareImpl.d.ts +79 -0
  112. package/dist/MiddlewareImpl.d.ts.map +1 -0
  113. package/dist/MiddlewareImpl.js +58 -0
  114. package/dist/MiddlewareImpl.js.map +1 -0
  115. package/dist/MiddlewareRegistryItem.d.ts +12 -0
  116. package/dist/MiddlewareRegistryItem.d.ts.map +1 -0
  117. package/dist/MiddlewareRegistryItem.js +15 -0
  118. package/dist/MiddlewareRegistryItem.js.map +1 -0
  119. package/dist/MutationCtx.d.ts +10 -0
  120. package/dist/MutationCtx.d.ts.map +1 -0
  121. package/dist/MutationCtx.js +18 -0
  122. package/dist/MutationCtx.js.map +1 -0
  123. package/dist/MutationRunner.d.ts +27 -0
  124. package/dist/MutationRunner.d.ts.map +1 -0
  125. package/dist/MutationRunner.js +28 -0
  126. package/dist/MutationRunner.js.map +1 -0
  127. package/dist/MutationTransactionContext.d.ts +17 -0
  128. package/dist/MutationTransactionContext.d.ts.map +1 -0
  129. package/dist/MutationTransactionContext.js +20 -0
  130. package/dist/MutationTransactionContext.js.map +1 -0
  131. package/dist/OrderedQuery.d.ts +32 -0
  132. package/dist/OrderedQuery.d.ts.map +1 -0
  133. package/dist/OrderedQuery.js +36 -0
  134. package/dist/OrderedQuery.js.map +1 -0
  135. package/dist/QueryCtx.d.ts +10 -0
  136. package/dist/QueryCtx.d.ts.map +1 -0
  137. package/dist/QueryCtx.js +18 -0
  138. package/dist/QueryCtx.js.map +1 -0
  139. package/dist/QueryInitializer.d.ts +75 -0
  140. package/dist/QueryInitializer.d.ts.map +1 -0
  141. package/dist/QueryInitializer.js +105 -0
  142. package/dist/QueryInitializer.js.map +1 -0
  143. package/dist/QueryRunner.d.ts +46 -0
  144. package/dist/QueryRunner.d.ts.map +1 -0
  145. package/dist/QueryRunner.js +30 -0
  146. package/dist/QueryRunner.js.map +1 -0
  147. package/dist/QueryStream.d.ts +678 -0
  148. package/dist/QueryStream.d.ts.map +1 -0
  149. package/dist/QueryStream.js +943 -0
  150. package/dist/QueryStream.js.map +1 -0
  151. package/dist/QueryStreamCursor.d.ts +39 -0
  152. package/dist/QueryStreamCursor.d.ts.map +1 -0
  153. package/dist/QueryStreamCursor.js +52 -0
  154. package/dist/QueryStreamCursor.js.map +1 -0
  155. package/dist/QueryStreamIndexPrefix.d.ts +48 -0
  156. package/dist/QueryStreamIndexPrefix.d.ts.map +1 -0
  157. package/dist/QueryStreamIndexPrefix.js +38 -0
  158. package/dist/QueryStreamIndexPrefix.js.map +1 -0
  159. package/dist/QueryStreamIndexRange.d.ts +193 -0
  160. package/dist/QueryStreamIndexRange.d.ts.map +1 -0
  161. package/dist/QueryStreamIndexRange.js +241 -0
  162. package/dist/QueryStreamIndexRange.js.map +1 -0
  163. package/dist/QueryStreamKey.d.ts +64 -0
  164. package/dist/QueryStreamKey.d.ts.map +1 -0
  165. package/dist/QueryStreamKey.js +69 -0
  166. package/dist/QueryStreamKey.js.map +1 -0
  167. package/dist/QueryStreamKeyBounds.d.ts +136 -0
  168. package/dist/QueryStreamKeyBounds.d.ts.map +1 -0
  169. package/dist/QueryStreamKeyBounds.js +208 -0
  170. package/dist/QueryStreamKeyBounds.js.map +1 -0
  171. package/dist/QueryStreamKeyLabels.d.ts +27 -0
  172. package/dist/QueryStreamKeyLabels.d.ts.map +1 -0
  173. package/dist/QueryStreamKeyLabels.js +22 -0
  174. package/dist/QueryStreamKeyLabels.js.map +1 -0
  175. package/dist/QueryStreamKeyLayout.d.ts +179 -0
  176. package/dist/QueryStreamKeyLayout.d.ts.map +1 -0
  177. package/dist/QueryStreamKeyLayout.js +167 -0
  178. package/dist/QueryStreamKeyLayout.js.map +1 -0
  179. package/dist/QueryStreamKeyValues.d.ts +40 -0
  180. package/dist/QueryStreamKeyValues.d.ts.map +1 -0
  181. package/dist/QueryStreamKeyValues.js +57 -0
  182. package/dist/QueryStreamKeyValues.js.map +1 -0
  183. package/dist/QueryStreamOrderDirection.d.ts +24 -0
  184. package/dist/QueryStreamOrderDirection.d.ts.map +1 -0
  185. package/dist/QueryStreamOrderDirection.js +11 -0
  186. package/dist/QueryStreamOrderDirection.js.map +1 -0
  187. package/dist/QueryStreamPagination.d.ts +264 -0
  188. package/dist/QueryStreamPagination.d.ts.map +1 -0
  189. package/dist/QueryStreamPagination.js +172 -0
  190. package/dist/QueryStreamPagination.js.map +1 -0
  191. package/dist/QueryStreamReadBudget.d.ts +63 -0
  192. package/dist/QueryStreamReadBudget.d.ts.map +1 -0
  193. package/dist/QueryStreamReadBudget.js +81 -0
  194. package/dist/QueryStreamReadBudget.js.map +1 -0
  195. package/dist/QueryTransactionContext.d.ts +16 -0
  196. package/dist/QueryTransactionContext.d.ts.map +1 -0
  197. package/dist/QueryTransactionContext.js +17 -0
  198. package/dist/QueryTransactionContext.js.map +1 -0
  199. package/dist/RegisteredConvexFunction.d.ts +359 -0
  200. package/dist/RegisteredConvexFunction.d.ts.map +1 -0
  201. package/dist/RegisteredConvexFunction.js +154 -0
  202. package/dist/RegisteredConvexFunction.js.map +1 -0
  203. package/dist/RegisteredFunction.d.ts +143 -0
  204. package/dist/RegisteredFunction.d.ts.map +1 -0
  205. package/dist/RegisteredFunction.js +125 -0
  206. package/dist/RegisteredFunction.js.map +1 -0
  207. package/dist/RegisteredFunctions.d.ts +57 -0
  208. package/dist/RegisteredFunctions.d.ts.map +1 -0
  209. package/dist/RegisteredFunctions.js +32 -0
  210. package/dist/RegisteredFunctions.js.map +1 -0
  211. package/dist/RegisteredNodeFunction.d.ts +11 -0
  212. package/dist/RegisteredNodeFunction.d.ts.map +1 -0
  213. package/dist/RegisteredNodeFunction.js +45 -0
  214. package/dist/RegisteredNodeFunction.js.map +1 -0
  215. package/dist/Registry.d.ts +12 -0
  216. package/dist/Registry.d.ts.map +1 -0
  217. package/dist/Registry.js +17 -0
  218. package/dist/Registry.js.map +1 -0
  219. package/dist/RegistryItems.d.ts +21 -0
  220. package/dist/RegistryItems.d.ts.map +1 -0
  221. package/dist/RegistryItems.js +27 -0
  222. package/dist/RegistryItems.js.map +1 -0
  223. package/dist/RequestMetadata.d.ts +12 -0
  224. package/dist/RequestMetadata.d.ts.map +1 -0
  225. package/dist/RequestMetadata.js +16 -0
  226. package/dist/RequestMetadata.js.map +1 -0
  227. package/dist/ResolvedMiddleware.d.ts +24 -0
  228. package/dist/ResolvedMiddleware.d.ts.map +1 -0
  229. package/dist/ResolvedMiddleware.js +34 -0
  230. package/dist/ResolvedMiddleware.js.map +1 -0
  231. package/dist/Scheduler.d.ts +31 -0
  232. package/dist/Scheduler.d.ts.map +1 -0
  233. package/dist/Scheduler.js +35 -0
  234. package/dist/Scheduler.js.map +1 -0
  235. package/dist/Storage.d.ts +22 -0
  236. package/dist/Storage.d.ts.map +1 -0
  237. package/dist/Storage.js +27 -0
  238. package/dist/Storage.js.map +1 -0
  239. package/dist/StorageActionWriter.d.ts +35 -0
  240. package/dist/StorageActionWriter.d.ts.map +1 -0
  241. package/dist/StorageActionWriter.js +24 -0
  242. package/dist/StorageActionWriter.js.map +1 -0
  243. package/dist/StorageReader.d.ts +26 -0
  244. package/dist/StorageReader.d.ts.map +1 -0
  245. package/dist/StorageReader.js +22 -0
  246. package/dist/StorageReader.js.map +1 -0
  247. package/dist/StorageWriter.d.ts +29 -0
  248. package/dist/StorageWriter.d.ts.map +1 -0
  249. package/dist/StorageWriter.js +24 -0
  250. package/dist/StorageWriter.js.map +1 -0
  251. package/dist/Table.d.ts +274 -0
  252. package/dist/Table.d.ts.map +1 -0
  253. package/dist/Table.js +70 -0
  254. package/dist/Table.js.map +1 -0
  255. package/dist/TableInfo.d.ts +44 -0
  256. package/dist/TableInfo.d.ts.map +1 -0
  257. package/dist/TableInfo.js +7 -0
  258. package/dist/TableInfo.js.map +1 -0
  259. package/dist/TransactionMetadata.d.ts +12 -0
  260. package/dist/TransactionMetadata.d.ts.map +1 -0
  261. package/dist/TransactionMetadata.js +16 -0
  262. package/dist/TransactionMetadata.js.map +1 -0
  263. package/dist/VectorSearch.d.ts +23 -0
  264. package/dist/VectorSearch.d.ts.map +1 -0
  265. package/dist/VectorSearch.js +17 -0
  266. package/dist/VectorSearch.js.map +1 -0
  267. package/dist/_virtual/_rolldown/runtime.js +13 -0
  268. package/dist/index.d.ts +88 -0
  269. package/dist/index.d.ts.map +1 -0
  270. package/dist/index.js +61 -0
  271. package/dist/internal/AiGatewayDecisionClient.d.ts +7 -0
  272. package/dist/internal/AiGatewayDecisionClient.d.ts.map +1 -0
  273. package/dist/internal/AiGatewayDecisionClient.js +19 -0
  274. package/dist/internal/AiGatewayDecisionClient.js.map +1 -0
  275. package/dist/internal/AiGatewayLanguageClient.d.ts +7 -0
  276. package/dist/internal/AiGatewayLanguageClient.d.ts.map +1 -0
  277. package/dist/internal/AiGatewayLanguageClient.js +19 -0
  278. package/dist/internal/AiGatewayLanguageClient.js.map +1 -0
  279. package/dist/internal/AiGatewayServiceToken.d.ts +46 -0
  280. package/dist/internal/AiGatewayServiceToken.d.ts.map +1 -0
  281. package/dist/internal/AiGatewayServiceToken.js +62 -0
  282. package/dist/internal/AiGatewayServiceToken.js.map +1 -0
  283. package/dist/internal/constants.d.ts +2 -0
  284. package/dist/internal/constants.d.ts.map +1 -0
  285. package/dist/internal/constants.js +6 -0
  286. package/dist/internal/constants.js.map +1 -0
  287. package/dist/internal/utils.d.ts +13 -0
  288. package/dist/internal/utils.d.ts.map +1 -0
  289. package/dist/internal/utils.js +50 -0
  290. package/dist/internal/utils.js.map +1 -0
  291. package/dist/node.d.ts +2 -0
  292. package/dist/node.d.ts.map +1 -0
  293. package/dist/node.js +1 -0
  294. package/package.json +68 -3
  295. package/src/ActionCtx.ts +45 -0
  296. package/src/ActionRunner.ts +36 -0
  297. package/src/AiGatewayDecisionClient.ts +40 -0
  298. package/src/AiGatewayDecisionModel.ts +46 -0
  299. package/src/AiGatewayLanguageClient.ts +41 -0
  300. package/src/AiGatewayLanguageModel.ts +61 -0
  301. package/src/Auth.ts +51 -0
  302. package/src/BlobNotFoundError.ts +12 -0
  303. package/src/Callback.ts +313 -0
  304. package/src/ComponentCtx.ts +192 -0
  305. package/src/ConvexConfigProvider.ts +39 -0
  306. package/src/ConvexFunctionDefinitions.ts +91 -0
  307. package/src/ConvexLogger.ts +43 -0
  308. package/src/CronJob.ts +42 -0
  309. package/src/CronJobs.ts +165 -0
  310. package/src/DataModel.ts +81 -0
  311. package/src/DatabaseReader.ts +118 -0
  312. package/src/DatabaseSchema.ts +139 -0
  313. package/src/DatabaseWriter.ts +232 -0
  314. package/src/Document.ts +146 -0
  315. package/src/ExecutionMetadata.ts +26 -0
  316. package/src/FunctionImpl.ts +96 -0
  317. package/src/FunctionRegistryItem.ts +85 -0
  318. package/src/GroupImpl.ts +167 -0
  319. package/src/GroupRegistry.ts +41 -0
  320. package/src/Handler.ts +191 -0
  321. package/src/HttpRouter.ts +388 -0
  322. package/src/MiddlewareImpl.ts +247 -0
  323. package/src/MiddlewareRegistryItem.ts +21 -0
  324. package/src/MutationCtx.ts +45 -0
  325. package/src/MutationRunner.ts +66 -0
  326. package/src/MutationTransactionContext.ts +48 -0
  327. package/src/OrderedQuery.ts +136 -0
  328. package/src/QueryCtx.ts +45 -0
  329. package/src/QueryInitializer.ts +537 -0
  330. package/src/QueryRunner.ts +91 -0
  331. package/src/QueryStream.ts +2476 -0
  332. package/src/QueryStreamCursor.ts +99 -0
  333. package/src/QueryStreamIndexPrefix.ts +79 -0
  334. package/src/QueryStreamIndexRange.ts +489 -0
  335. package/src/QueryStreamKey.ts +118 -0
  336. package/src/QueryStreamKeyBounds.ts +395 -0
  337. package/src/QueryStreamKeyLabels.ts +56 -0
  338. package/src/QueryStreamKeyLayout.ts +382 -0
  339. package/src/QueryStreamKeyValues.ts +112 -0
  340. package/src/QueryStreamOrderDirection.ts +29 -0
  341. package/src/QueryStreamPagination.ts +357 -0
  342. package/src/QueryStreamReadBudget.ts +167 -0
  343. package/src/QueryTransactionContext.ts +37 -0
  344. package/src/RegisteredConvexFunction.ts +415 -0
  345. package/src/RegisteredFunction.ts +391 -0
  346. package/src/RegisteredFunctions.ts +88 -0
  347. package/src/RegisteredNodeFunction.ts +120 -0
  348. package/src/Registry.ts +17 -0
  349. package/src/RegistryItems.ts +40 -0
  350. package/src/RequestMetadata.ts +20 -0
  351. package/src/ResolvedMiddleware.ts +70 -0
  352. package/src/Scheduler.ts +85 -0
  353. package/src/Storage.ts +37 -0
  354. package/src/StorageActionWriter.ts +59 -0
  355. package/src/StorageReader.ts +59 -0
  356. package/src/StorageWriter.ts +58 -0
  357. package/src/Table.ts +156 -0
  358. package/src/TableInfo.ts +106 -0
  359. package/src/TransactionMetadata.ts +20 -0
  360. package/src/VectorSearch.ts +75 -0
  361. package/src/index.ts +87 -0
  362. package/src/internal/AiGatewayDecisionClient.ts +16 -0
  363. package/src/internal/AiGatewayLanguageClient.ts +16 -0
  364. package/src/internal/AiGatewayServiceToken.ts +129 -0
  365. package/src/internal/constants.ts +1 -0
  366. package/src/internal/utils.ts +89 -0
  367. package/src/node.ts +1 -0
@@ -0,0 +1,75 @@
1
+ import type {
2
+ Expand,
3
+ GenericActionCtx,
4
+ NamedTableInfo,
5
+ VectorIndexNames,
6
+ VectorSearchQuery,
7
+ } from "convex/server";
8
+ import * as Context from "effect/Context";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Layer from "effect/Layer";
11
+ import type * as DataModel from "./DataModel.js";
12
+
13
+ type ConvexVectorSearch<DataModel_ extends DataModel.AnyWithProps> =
14
+ GenericActionCtx<DataModel.ToConvex<DataModel_>>["vectorSearch"];
15
+
16
+ /**
17
+ * The service shape backing the `VectorSearch` tag. Named so declaration emit
18
+ * references it instead of expanding the call signature at every usage.
19
+ */
20
+ export interface VectorSearchService<
21
+ DataModel_ extends DataModel.AnyWithProps,
22
+ > {
23
+ <
24
+ TableName extends DataModel.TableNames<DataModel_>,
25
+ IndexName extends VectorIndexNames<
26
+ NamedTableInfo<DataModel.ToConvex<DataModel_>, TableName>
27
+ >,
28
+ >(
29
+ tableName: TableName,
30
+ indexName: IndexName,
31
+ query: Expand<
32
+ VectorSearchQuery<
33
+ NamedTableInfo<DataModel.ToConvex<DataModel_>, TableName>,
34
+ IndexName
35
+ >
36
+ >,
37
+ ): Effect.Effect<
38
+ Array<{ _id: DataModel.Id<DataModel_, TableName>; _score: number }>
39
+ >;
40
+ }
41
+
42
+ export type VectorSearchTag<DataModel_ extends DataModel.AnyWithProps> =
43
+ Context.Service<
44
+ VectorSearchService<DataModel_>,
45
+ VectorSearchService<DataModel_>
46
+ >;
47
+
48
+ export const make =
49
+ <DataModel_ extends DataModel.AnyWithProps>(
50
+ vectorSearch: ConvexVectorSearch<DataModel_>,
51
+ ): VectorSearchService<DataModel_> =>
52
+ (tableName, indexName, query) =>
53
+ Effect.promise(() => vectorSearch(tableName, indexName, query)).pipe(
54
+ Effect.map(
55
+ (rows) =>
56
+ rows as unknown as Array<{
57
+ _id: DataModel.Id<DataModel_, typeof tableName>;
58
+ _score: number;
59
+ }>,
60
+ ),
61
+ );
62
+
63
+ export const VectorSearch = <
64
+ DataModel_ extends DataModel.AnyWithProps,
65
+ >(): VectorSearchTag<DataModel_> =>
66
+ Context.Service<VectorSearchService<DataModel_>>(
67
+ "@confect/server/VectorSearch",
68
+ );
69
+
70
+ export type VectorSearch<DataModel_ extends DataModel.AnyWithProps> =
71
+ VectorSearchService<DataModel_>;
72
+
73
+ export const layer = <DataModel_ extends DataModel.AnyWithProps>(
74
+ vectorSearch: ConvexVectorSearch<DataModel_>,
75
+ ) => Layer.succeed(VectorSearch<DataModel_>(), make(vectorSearch));
package/src/index.ts ADDED
@@ -0,0 +1,87 @@
1
+ export * as AiGatewayDecisionClient from "./AiGatewayDecisionClient.js";
2
+ export * as AiGatewayDecisionModel from "./AiGatewayDecisionModel.js";
3
+ export * as AiGatewayLanguageClient from "./AiGatewayLanguageClient.js";
4
+ export * as AiGatewayLanguageModel from "./AiGatewayLanguageModel.js";
5
+ export * as ActionCtx from "./ActionCtx.js";
6
+ export * as ActionRunner from "./ActionRunner.js";
7
+ export * as Auth from "./Auth.js";
8
+ export * as BlobNotFoundError from "./BlobNotFoundError.js";
9
+ export * as Callback from "./Callback.js";
10
+ export * as ConvexConfigProvider from "./ConvexConfigProvider.js";
11
+ export * as ConvexFunctionDefinitions from "./ConvexFunctionDefinitions.js";
12
+ export * as ConvexLogger from "./ConvexLogger.js";
13
+ export * as CronJob from "./CronJob.js";
14
+ export * as CronJobs from "./CronJobs.js";
15
+ export * as DatabaseReader from "./DatabaseReader.js";
16
+ export * as DatabaseSchema from "./DatabaseSchema.js";
17
+ export * as DatabaseWriter from "./DatabaseWriter.js";
18
+ export * as DataModel from "./DataModel.js";
19
+ export * as Document from "./Document.js";
20
+ export * as ExecutionMetadata from "./ExecutionMetadata.js";
21
+ export * as FunctionImpl from "./FunctionImpl.js";
22
+ export * as FunctionRegistryItem from "./FunctionRegistryItem.js";
23
+ export * as GroupImpl from "./GroupImpl.js";
24
+ export * as Handler from "./Handler.js";
25
+ export * as HttpRouter from "./HttpRouter.js";
26
+ export * as MiddlewareImpl from "./MiddlewareImpl.js";
27
+ export * as MiddlewareRegistryItem from "./MiddlewareRegistryItem.js";
28
+ export * as MutationCtx from "./MutationCtx.js";
29
+ export * as MutationRunner from "./MutationRunner.js";
30
+ export * as MutationTransactionContext from "./MutationTransactionContext.js";
31
+ export * as OrderedQuery from "./OrderedQuery.js";
32
+ export * as QueryCtx from "./QueryCtx.js";
33
+ export * as QueryInitializer from "./QueryInitializer.js";
34
+ export * as QueryRunner from "./QueryRunner.js";
35
+ export * as QueryTransactionContext from "./QueryTransactionContext.js";
36
+ /**
37
+ * @experimental
38
+ */
39
+ export * as QueryStream from "./QueryStream.js";
40
+ /**
41
+ * @experimental
42
+ */
43
+ export * as QueryStreamCursor from "./QueryStreamCursor.js";
44
+ /**
45
+ * @experimental
46
+ */
47
+ export * as QueryStreamKeyLabels from "./QueryStreamKeyLabels.js";
48
+ /**
49
+ * @experimental
50
+ */
51
+ export * as QueryStreamKeyLayout from "./QueryStreamKeyLayout.js";
52
+ /**
53
+ * @experimental
54
+ */
55
+ export * as QueryStreamOrderDirection from "./QueryStreamOrderDirection.js";
56
+ /**
57
+ * @experimental
58
+ */
59
+ export * as QueryStreamKeyValues from "./QueryStreamKeyValues.js";
60
+ /**
61
+ * @experimental
62
+ */
63
+ export * as QueryStreamKeyBounds from "./QueryStreamKeyBounds.js";
64
+ /**
65
+ * @experimental
66
+ */
67
+ export * as QueryStreamIndexRange from "./QueryStreamIndexRange.js";
68
+ /**
69
+ * @experimental
70
+ */
71
+ export * as QueryStreamReadBudget from "./QueryStreamReadBudget.js";
72
+ export * as RegisteredConvexFunction from "./RegisteredConvexFunction.js";
73
+ export * as RegisteredFunction from "./RegisteredFunction.js";
74
+ export * as RegisteredFunctions from "./RegisteredFunctions.js";
75
+ export * as Registry from "./Registry.js";
76
+ export * as RegistryItems from "./RegistryItems.js";
77
+ export * as ResolvedMiddleware from "./ResolvedMiddleware.js";
78
+ export * as RequestMetadata from "./RequestMetadata.js";
79
+ export * as Scheduler from "./Scheduler.js";
80
+ export * as Storage from "./Storage.js";
81
+ export * as StorageActionWriter from "./StorageActionWriter.js";
82
+ export * as StorageReader from "./StorageReader.js";
83
+ export * as StorageWriter from "./StorageWriter.js";
84
+ export * as Table from "./Table.js";
85
+ export * as TableInfo from "./TableInfo.js";
86
+ export * as TransactionMetadata from "./TransactionMetadata.js";
87
+ export * as VectorSearch from "./VectorSearch.js";
@@ -0,0 +1,16 @@
1
+ import * as OpenRouterClient from "@effect/ai-openrouter/OpenRouterClient";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as AiGatewayServiceToken from "./AiGatewayServiceToken.js";
5
+ import { AI_GATEWAY_API_URL } from "./constants.js";
6
+
7
+ export const make = Effect.gen(function* () {
8
+ const serviceToken = yield* AiGatewayServiceToken.AiGatewayServiceToken;
9
+ yield* serviceToken.get("ai-gateway");
10
+ return yield* OpenRouterClient.make({
11
+ apiUrl: AI_GATEWAY_API_URL,
12
+ transformClient: AiGatewayServiceToken.transformClientRequest(serviceToken),
13
+ });
14
+ });
15
+
16
+ export const layer = Layer.effect(OpenRouterClient.OpenRouterClient, make);
@@ -0,0 +1,16 @@
1
+ import * as OpenAiClient from "@effect/ai-openai-compat/OpenAiClient";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as AiGatewayServiceToken from "./AiGatewayServiceToken.js";
5
+ import { AI_GATEWAY_API_URL } from "./constants.js";
6
+
7
+ export const make = Effect.gen(function* () {
8
+ const serviceToken = yield* AiGatewayServiceToken.AiGatewayServiceToken;
9
+ yield* serviceToken.get("ai-gateway");
10
+ return yield* OpenAiClient.make({
11
+ apiUrl: AI_GATEWAY_API_URL,
12
+ transformClient: AiGatewayServiceToken.transformClientRequest(serviceToken),
13
+ });
14
+ });
15
+
16
+ export const layer = Layer.effect(OpenAiClient.OpenAiClient, make);
@@ -0,0 +1,129 @@
1
+ import { getServiceToken as getConvexServiceToken } from "convex/server";
2
+ import * as Context from "effect/Context";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Schema from "effect/Schema";
6
+ import * as HttpClient from "effect/http/HttpClient";
7
+ import * as HttpClientError from "effect/http/HttpClientError";
8
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
9
+
10
+ /**
11
+ * The current team is on the free plan or has the Convex AI gateway disabled.
12
+ * Upgrade to a paid plan, or contact Convex support if this looks wrong.
13
+ */
14
+ export class AiGatewayDisabled extends Schema.TaggedError<AiGatewayDisabled>()(
15
+ "AiGatewayDisabled",
16
+ {},
17
+ ) {
18
+ override get message(): string {
19
+ return "The Convex AI gateway is disabled. Your team may be on the free plan, or the gateway may have been disabled for your team. Upgrade to a paid plan, or email support@convex.dev if this looks wrong.";
20
+ }
21
+ }
22
+
23
+ /**
24
+ * The current deployment is anonymous, outdated, or self-hosted and cannot use
25
+ * the Convex AI gateway. Authenticated, project-linked local deployments are
26
+ * supported.
27
+ */
28
+ export class AiGatewayUnavailable extends Schema.TaggedError<AiGatewayUnavailable>()(
29
+ "AiGatewayUnavailable",
30
+ {},
31
+ ) {
32
+ override get message(): string {
33
+ return "The Convex AI gateway is unavailable on this deployment. For local development, log in, link the deployment to a Convex project, and update the Convex CLI and local backend. Anonymous and self-hosted deployments cannot use the gateway; call the model provider directly with your own API key instead.";
34
+ }
35
+ }
36
+
37
+ /**
38
+ * A schema for the possible failures that can occur while obtaining a Convex AI
39
+ * gateway service token.
40
+ */
41
+ export const AiGatewayError = Schema.Union([
42
+ AiGatewayDisabled,
43
+ AiGatewayUnavailable,
44
+ ]);
45
+
46
+ /**
47
+ * The possible failures that can occur while obtaining a Convex AI gateway
48
+ * service token.
49
+ */
50
+ export type AiGatewayError = typeof AiGatewayError.Type;
51
+
52
+ type GetServiceToken = typeof getConvexServiceToken;
53
+ type AiGatewayErrorCode = AiGatewayError["_tag"];
54
+
55
+ const nodeRuntimeErrorCodeFragments: Record<AiGatewayErrorCode, string> = {
56
+ AiGatewayDisabled: '"code":"AiGatewayDisabled"',
57
+ AiGatewayUnavailable: '"code":"AiGatewayUnavailable"',
58
+ };
59
+
60
+ // The default Convex runtime exposes only the human-readable ErrorMetadata
61
+ // message. Node actions preserve the short code in a wrapped JSON response.
62
+ const defaultRuntimeErrorMessagePrefixes: Record<AiGatewayErrorCode, string> = {
63
+ AiGatewayDisabled: "The Convex AI gateway is not enabled for your team.",
64
+ AiGatewayUnavailable:
65
+ '`getServiceToken("ai-gateway")` isn\'t available on this deployment',
66
+ };
67
+
68
+ export interface Service {
69
+ readonly get: (
70
+ service: "ai-gateway",
71
+ ) => Effect.Effect<string, AiGatewayError>;
72
+ }
73
+
74
+ export class AiGatewayServiceToken extends Context.Service<
75
+ AiGatewayServiceToken,
76
+ Service
77
+ >()("@confect/server/internal/AiGatewayServiceToken") {}
78
+
79
+ const matchesErrorCode = (
80
+ rejection: unknown,
81
+ code: AiGatewayErrorCode,
82
+ ): boolean =>
83
+ (typeof rejection === "object" &&
84
+ rejection !== null &&
85
+ "code" in rejection &&
86
+ rejection.code === code) ||
87
+ (rejection instanceof Error &&
88
+ (rejection.message.includes(nodeRuntimeErrorCodeFragments[code]) ||
89
+ rejection.message.includes(defaultRuntimeErrorMessagePrefixes[code])));
90
+
91
+ const classifyError = (rejection: unknown): AiGatewayError => {
92
+ if (matchesErrorCode(rejection, "AiGatewayDisabled")) {
93
+ return new AiGatewayDisabled();
94
+ }
95
+ if (matchesErrorCode(rejection, "AiGatewayUnavailable")) {
96
+ return new AiGatewayUnavailable();
97
+ }
98
+ throw rejection;
99
+ };
100
+
101
+ export const make = (getServiceToken: GetServiceToken): Service => ({
102
+ get: (service) =>
103
+ Effect.tryPromise({
104
+ try: () => getServiceToken(service),
105
+ catch: classifyError,
106
+ }),
107
+ });
108
+
109
+ export const layer = Layer.succeed(
110
+ AiGatewayServiceToken,
111
+ make(getConvexServiceToken),
112
+ );
113
+
114
+ export const transformClientRequest = (serviceToken: Service) =>
115
+ HttpClient.mapRequestEffect((request) =>
116
+ serviceToken.get("ai-gateway").pipe(
117
+ Effect.map((token) => HttpClientRequest.bearerToken(request, token)),
118
+ Effect.mapError(
119
+ (cause) =>
120
+ new HttpClientError.HttpClientError({
121
+ reason: new HttpClientError.TransportError({
122
+ request,
123
+ cause,
124
+ description: cause.message,
125
+ }),
126
+ }),
127
+ ),
128
+ ),
129
+ );
@@ -0,0 +1 @@
1
+ export const AI_GATEWAY_API_URL = "https://ai-gateway.convex.dev/v1";
@@ -0,0 +1,89 @@
1
+ import type { Predicate } from "effect";
2
+ import * as Array from "effect/Array";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Record from "effect/Record";
5
+
6
+ type NestedObject<T> = {
7
+ [key: string]: T | NestedObject<T>;
8
+ };
9
+
10
+ export const mapLeaves = <T, U>(
11
+ obj: NestedObject<T>,
12
+ leafRefinement: Predicate.Refinement<unknown, T>,
13
+ f: (value: T) => U,
14
+ ): NestedObject<U> => {
15
+ const result: any = {};
16
+
17
+ for (const key in obj) {
18
+ const value = obj[key];
19
+
20
+ if (leafRefinement(value)) {
21
+ result[key] = f(value as T);
22
+ } else {
23
+ result[key] = mapLeaves(value as NestedObject<T>, leafRefinement, f);
24
+ }
25
+ }
26
+
27
+ return result;
28
+ };
29
+
30
+ const collectBranchLeaves = <T>(
31
+ obj: NestedObject<T>,
32
+ leafRefinement: Predicate.Refinement<unknown, T>,
33
+ path: string[] = [],
34
+ ): { path: string[]; values: Record<string, T> }[] => {
35
+ const leaves = Record.filter(obj, leafRefinement) as Record<string, T>;
36
+ const hasLeaves = Record.keys(leaves).length > 0;
37
+
38
+ const currentBranch = hasLeaves ? [{ path, values: leaves }] : [];
39
+
40
+ const nestedBranches = Array.flatMap(Record.keys(obj), (key) => {
41
+ const value = obj[key];
42
+
43
+ if (!leafRefinement(value) && typeof value === "object") {
44
+ return collectBranchLeaves(value as NestedObject<T>, leafRefinement, [
45
+ ...path,
46
+ key,
47
+ ]);
48
+ }
49
+ return [];
50
+ });
51
+
52
+ return [...currentBranch, ...nestedBranches];
53
+ };
54
+
55
+ export const forEachBranchLeaves = <T, A, E, R>(
56
+ obj: NestedObject<T>,
57
+ leafRefinement: Predicate.Refinement<unknown, T>,
58
+ f: (branchLeaves: {
59
+ path: string[];
60
+ values: Record<string, T>;
61
+ }) => Effect.Effect<A, E, R>,
62
+ ): Effect.Effect<void, E, R> => {
63
+ const branchLeaves = collectBranchLeaves(obj, leafRefinement);
64
+ return Effect.forEach(branchLeaves, f, {
65
+ discard: true,
66
+ });
67
+ };
68
+
69
+ export const setNestedProperty = <T extends object>(
70
+ obj: T,
71
+ path: PropertyKey[],
72
+ value: any,
73
+ ): T => {
74
+ if (path.length === 0) {
75
+ return obj;
76
+ }
77
+
78
+ if (path.length === 1) {
79
+ const key = path[0] as keyof T;
80
+ return { ...obj, [key]: value };
81
+ }
82
+
83
+ const [head, ...tail] = path;
84
+ const key = head as keyof T;
85
+ return {
86
+ ...obj,
87
+ [key]: setNestedProperty((obj as any)[key] ?? {}, tail, value),
88
+ };
89
+ };
package/src/node.ts ADDED
@@ -0,0 +1 @@
1
+ export * as RegisteredNodeFunction from "./RegisteredNodeFunction.js";