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

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,46 @@
1
+ import type * as OpenRouterClient from "@effect/ai-openrouter/OpenRouterClient";
2
+ import * as OpenRouterDecisionModel from "@effect/ai-openrouter/OpenRouterDecisionModel";
3
+ import type * as Effect from "effect/Effect";
4
+ import type * as Layer from "effect/Layer";
5
+ import type * as DecisionModel from "effect/ai/DecisionModel";
6
+ import type * as AiModel from "effect/ai/Model";
7
+
8
+ export interface Options {
9
+ readonly model: string;
10
+ }
11
+
12
+ /**
13
+ * Create an Effect AI decision model backed by the Convex AI gateway.
14
+ *
15
+ * Model identifiers use Convex's `provider/model` format, such as
16
+ * `typesafe/jev-1.13`.
17
+ */
18
+ export const model = (
19
+ modelId: string,
20
+ ): AiModel.Model<
21
+ "openrouter",
22
+ DecisionModel.DecisionModel,
23
+ OpenRouterClient.OpenRouterClient
24
+ > => OpenRouterDecisionModel.model(modelId);
25
+
26
+ /**
27
+ * Construct a decision-model service backed by the Convex AI gateway.
28
+ */
29
+ export const make = ({
30
+ model: modelId,
31
+ }: Options): Effect.Effect<
32
+ DecisionModel.DecisionModel,
33
+ never,
34
+ OpenRouterClient.OpenRouterClient
35
+ > => OpenRouterDecisionModel.make({ model: modelId });
36
+
37
+ /**
38
+ * Provide a decision-model service backed by the Convex AI gateway.
39
+ */
40
+ export const layer = ({
41
+ model: modelId,
42
+ }: Options): Layer.Layer<
43
+ DecisionModel.DecisionModel,
44
+ never,
45
+ OpenRouterClient.OpenRouterClient
46
+ > => OpenRouterDecisionModel.layer({ model: modelId });
@@ -0,0 +1,41 @@
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 type * as HttpClient from "effect/http/HttpClient";
5
+ import * as InternalAiGatewayLanguageClient from "./internal/AiGatewayLanguageClient";
6
+ import * as AiGatewayServiceToken from "./internal/AiGatewayServiceToken";
7
+
8
+ export {
9
+ AiGatewayDisabled,
10
+ AiGatewayError,
11
+ AiGatewayUnavailable,
12
+ } from "./internal/AiGatewayServiceToken";
13
+
14
+ /**
15
+ * The client service configured for Convex AI gateway language models.
16
+ */
17
+ export const AiGatewayLanguageClient = OpenAiClient.OpenAiClient;
18
+ export type AiGatewayLanguageClient = OpenAiClient.OpenAiClient;
19
+
20
+ /**
21
+ * Construct a language client using the current Effect HTTP client.
22
+ */
23
+ export const make: Effect.Effect<
24
+ OpenAiClient.Service,
25
+ AiGatewayServiceToken.AiGatewayError,
26
+ HttpClient.HttpClient
27
+ > = InternalAiGatewayLanguageClient.make.pipe(
28
+ Effect.provide(AiGatewayServiceToken.layer),
29
+ );
30
+
31
+ /**
32
+ * Provide the AI gateway language model client using the current Effect HTTP
33
+ * client.
34
+ */
35
+ export const layer: Layer.Layer<
36
+ AiGatewayLanguageClient,
37
+ AiGatewayServiceToken.AiGatewayError,
38
+ HttpClient.HttpClient
39
+ > = InternalAiGatewayLanguageClient.layer.pipe(
40
+ Layer.provide(AiGatewayServiceToken.layer),
41
+ );
@@ -0,0 +1,61 @@
1
+ import type * as OpenAiClient from "@effect/ai-openai-compat/OpenAiClient";
2
+ import * as OpenAiLanguageModel from "@effect/ai-openai-compat/OpenAiLanguageModel";
3
+ import type * as Effect from "effect/Effect";
4
+ import type * as Layer from "effect/Layer";
5
+ import type * as LanguageModel from "effect/ai/LanguageModel";
6
+ import type * as AiModel from "effect/ai/Model";
7
+
8
+ /**
9
+ * Configuration overrides for Convex AI gateway language-model requests.
10
+ */
11
+ export const Config = OpenAiLanguageModel.Config;
12
+
13
+ export type Config = OpenAiLanguageModel.Config;
14
+
15
+ export interface Options {
16
+ readonly model: string;
17
+ readonly config?: Omit<typeof OpenAiLanguageModel.Config.Service, "model">;
18
+ }
19
+
20
+ /**
21
+ * Create an Effect AI model backed by the Convex AI gateway.
22
+ *
23
+ * Model identifiers use Convex's `provider/model` format.
24
+ */
25
+ export const model = (
26
+ modelId: string,
27
+ config?: Omit<typeof OpenAiLanguageModel.Config.Service, "model">,
28
+ ): AiModel.Model<
29
+ "openai",
30
+ LanguageModel.LanguageModel,
31
+ OpenAiClient.OpenAiClient
32
+ > => OpenAiLanguageModel.model(modelId, config);
33
+
34
+ /**
35
+ * Construct a language-model service backed by the Convex AI gateway.
36
+ */
37
+ export const make = ({
38
+ model: modelId,
39
+ config,
40
+ }: Options): Effect.Effect<
41
+ LanguageModel.LanguageModel,
42
+ never,
43
+ OpenAiClient.OpenAiClient
44
+ > => OpenAiLanguageModel.make({ model: modelId, config });
45
+
46
+ /**
47
+ * Provide a language-model service backed by the Convex AI gateway.
48
+ */
49
+ export const layer = ({
50
+ model: modelId,
51
+ config,
52
+ }: Options): Layer.Layer<
53
+ LanguageModel.LanguageModel,
54
+ never,
55
+ OpenAiClient.OpenAiClient
56
+ > => OpenAiLanguageModel.layer({ model: modelId, config });
57
+
58
+ /**
59
+ * Apply request configuration to an Effect AI operation within a local scope.
60
+ */
61
+ export const withConfigOverride = OpenAiLanguageModel.withConfigOverride;
package/src/Auth.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type { Auth as ConvexAuth } from "convex/server";
2
+ import * as Context from "effect/Context";
3
+ import { flow } from "effect/Function";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Match from "effect/Match";
7
+ import * as Option from "effect/Option";
8
+ import * as Schema from "effect/Schema";
9
+ import type * as DatabaseSchema from "./DatabaseSchema";
10
+
11
+ const make = (auth: ConvexAuth) => ({
12
+ getUserIdentity: Effect.promise(() => auth.getUserIdentity()).pipe(
13
+ Effect.andThen(
14
+ flow(
15
+ Option.fromNullishOr,
16
+ Option.match({
17
+ onNone: () => Effect.fail(new NoUserIdentityFoundError()),
18
+ onSome: Effect.succeed,
19
+ }),
20
+ ),
21
+ ),
22
+ ),
23
+ });
24
+
25
+ export class Auth extends Context.Service<Auth, ReturnType<typeof make>>()(
26
+ "@confect/server/Auth",
27
+ ) {}
28
+
29
+ export const layer = (auth: ConvexAuth) => Layer.succeed(Auth, make(auth));
30
+
31
+ export type ForTarget<Target extends DatabaseSchema.Target> =
32
+ Target["kind"] extends "component" ? never : Auth;
33
+
34
+ export const layerForTarget = <Target extends DatabaseSchema.Target>(
35
+ target: Target,
36
+ auth: ConvexAuth,
37
+ ): Layer.Layer<ForTarget<Target>> =>
38
+ Match.value(target.kind).pipe(
39
+ Match.when("app", () => layer(auth)),
40
+ Match.when("component", () => Layer.empty),
41
+ Match.exhaustive,
42
+ ) as Layer.Layer<ForTarget<Target>>;
43
+
44
+ export class NoUserIdentityFoundError extends Schema.TaggedError<NoUserIdentityFoundError>()(
45
+ "NoUserIdentityFoundError",
46
+ {},
47
+ ) {
48
+ override get message(): string {
49
+ return "No user identity found";
50
+ }
51
+ }
@@ -0,0 +1,12 @@
1
+ import * as Schema from "effect/Schema";
2
+
3
+ export class BlobNotFoundError extends Schema.TaggedError<BlobNotFoundError>()(
4
+ "BlobNotFoundError",
5
+ {
6
+ id: Schema.String,
7
+ },
8
+ ) {
9
+ override get message(): string {
10
+ return `File with ID '${this.id}' not found`;
11
+ }
12
+ }
@@ -0,0 +1,313 @@
1
+ import * as Callback from "@confect/core/Callback";
2
+ import * as MiddlewareSpec from "@confect/core/MiddlewareSpec";
3
+ import * as Ref from "@confect/core/Ref";
4
+ import {
5
+ compileAst,
6
+ UnsupportedPropertySignatureKeyTypeError,
7
+ } from "@confect/core/SchemaToValidator";
8
+ import { createFunctionHandle } from "convex/server";
9
+ import { convexToJson, v, type GenericValidator } from "convex/values";
10
+ import * as Array from "effect/Array";
11
+ import * as Effect from "effect/Effect";
12
+ import { pipe } from "effect/Function";
13
+ import * as Number from "effect/Number";
14
+ import * as Option from "effect/Option";
15
+ import * as Order from "effect/Order";
16
+ import * as Predicate from "effect/Predicate";
17
+ import * as Result from "effect/Result";
18
+ import * as Schema from "effect/Schema";
19
+ import * as SchemaAST from "effect/SchemaAST";
20
+
21
+ /**
22
+ * The host function does not satisfy the contract on one side. `expected` and
23
+ * `actual` describe the contract's and the host's validators, with union
24
+ * members in a fixed order, or the reason a schema is unsupported.
25
+ */
26
+ export class CallbackContractMismatch extends Schema.TaggedError<CallbackContractMismatch>()(
27
+ "CallbackContractMismatch",
28
+ {
29
+ contract: Schema.String,
30
+ side: Schema.Literals(["args", "returns", "error"]),
31
+ expected: Schema.Json,
32
+ actual: Schema.Json,
33
+ },
34
+ ) {
35
+ override get message(): string {
36
+ return `The host function does not satisfy callback contract "${this.contract}": its ${this.side === "error" ? "errors" : this.side} compile to ${JSON.stringify(this.actual)}, the contract's to ${JSON.stringify(this.expected)}.`;
37
+ }
38
+ }
39
+
40
+ const alternatives = (
41
+ validator: GenericValidator,
42
+ ): ReadonlyArray<GenericValidator> =>
43
+ validator.kind === "union"
44
+ ? validator.members.flatMap(alternatives)
45
+ : [validator];
46
+
47
+ const literalKinds: Record<string, string> = {
48
+ string: "string",
49
+ number: "float64",
50
+ bigint: "int64",
51
+ boolean: "boolean",
52
+ };
53
+
54
+ /**
55
+ * The alternatives `validators` accept, without those another alternative
56
+ * already covers: everything under `v.any()`, and a literal under its base
57
+ * kind. `true` and `false` together are `v.boolean()`.
58
+ */
59
+ const alternativesOf = (
60
+ validators: ReadonlyArray<GenericValidator>,
61
+ ): ReadonlyArray<GenericValidator> => {
62
+ const flat = validators.flatMap(alternatives);
63
+ if (flat.some(({ kind }) => kind === "any")) {
64
+ return [v.any()];
65
+ }
66
+ const booleans = new Set(
67
+ flat.flatMap((validator) =>
68
+ validator.kind === "literal" && typeof validator.value === "boolean"
69
+ ? [validator.value]
70
+ : [],
71
+ ),
72
+ );
73
+ const widened =
74
+ booleans.has(true) && booleans.has(false) ? [...flat, v.boolean()] : flat;
75
+ const kinds = new Set<string>(widened.map(({ kind }) => kind));
76
+ return widened.filter(
77
+ (validator) =>
78
+ validator.kind !== "literal" ||
79
+ !kinds.has(literalKinds[typeof validator.value] ?? ""),
80
+ );
81
+ };
82
+
83
+ const keyed = (
84
+ described: ReadonlyArray<Schema.Json>,
85
+ ): ReadonlyArray<readonly [string, Schema.Json]> =>
86
+ pipe(
87
+ described,
88
+ Array.map((json) => [JSON.stringify(json), json] as const),
89
+ Array.dedupeWith(([a], [b]) => a === b),
90
+ Array.sortWith(([key]) => key, Order.String),
91
+ );
92
+
93
+ /**
94
+ * The distinct alternatives `validators` accept, keyed by their description and
95
+ * sorted by it, so union order and repetition do not count as differences.
96
+ */
97
+ const membersOf = (validators: ReadonlyArray<GenericValidator>) =>
98
+ keyed(alternativesOf(validators).map(describe));
99
+
100
+ const unionOf = (
101
+ members: ReadonlyArray<readonly [string, Schema.Json]>,
102
+ ): Schema.Json => {
103
+ const [only, ...rest] = members;
104
+ return only !== undefined && rest.length === 0
105
+ ? only[1]
106
+ : { kind: "union", members: members.map(([, described]) => described) };
107
+ };
108
+
109
+ const describe = (validator: GenericValidator): Schema.Json => {
110
+ switch (validator.kind) {
111
+ case "id":
112
+ return { kind: "id", tableName: validator.tableName };
113
+ case "literal":
114
+ return { kind: "literal", value: convexToJson(validator.value) };
115
+ case "array":
116
+ return { kind: "array", element: describe(validator.element) };
117
+ case "record":
118
+ return {
119
+ kind: "record",
120
+ key: describe(validator.key),
121
+ value: describe(validator.value),
122
+ };
123
+ case "object":
124
+ return {
125
+ kind: "object",
126
+ fields: Object.fromEntries(
127
+ pipe(
128
+ Object.entries(validator.fields),
129
+ Array.sortWith(([name]) => name, Order.String),
130
+ Array.map(([name, field]) => [
131
+ name,
132
+ field.isOptional === "optional"
133
+ ? { kind: "optional", value: describe(field) }
134
+ : describe(field),
135
+ ]),
136
+ ),
137
+ ),
138
+ };
139
+ case "union":
140
+ return unionOf(membersOf([validator]));
141
+ default:
142
+ return { kind: validator.kind };
143
+ }
144
+ };
145
+
146
+ const ownError = (provenance: {
147
+ readonly error?: Schema.Codec<any, any>;
148
+ }): ReadonlyArray<Schema.Codec<any, any>> =>
149
+ "error" in provenance && provenance.error !== undefined
150
+ ? [provenance.error]
151
+ : [];
152
+
153
+ const errorAlternatives = (schema: Schema.Top): ReadonlyArray<Schema.Top> =>
154
+ SchemaAST.isUnion(schema.ast) &&
155
+ Predicate.hasProperty(schema, "members") &&
156
+ Array.isArray(schema.members)
157
+ ? schema.members.flatMap((member) =>
158
+ Schema.isSchema(member) ? errorAlternatives(member) : [],
159
+ )
160
+ : [schema];
161
+
162
+ /**
163
+ * Compile args field by field, as registration does, so a recursive field does
164
+ * not widen the entire args object to `v.any()`.
165
+ */
166
+ const compileArgs = (ast: SchemaAST.Objects): ReturnType<typeof compileAst> =>
167
+ Effect.forEach(ast.propertySignatures, ({ name, type }) => {
168
+ if (typeof name !== "string") {
169
+ return Effect.fail(
170
+ new UnsupportedPropertySignatureKeyTypeError({ propertyKey: name }),
171
+ );
172
+ }
173
+ return Option.match(Number.parse(name), {
174
+ onSome: (propertyKey) =>
175
+ Effect.fail(
176
+ new UnsupportedPropertySignatureKeyTypeError({ propertyKey }),
177
+ ),
178
+ onNone: () => {
179
+ const optional = SchemaAST.isOptional(type);
180
+ return compileAst(type, optional).pipe(
181
+ Effect.map(
182
+ (validator) =>
183
+ [name, optional ? v.optional(validator) : validator] as const,
184
+ ),
185
+ );
186
+ },
187
+ });
188
+ }).pipe(Effect.map((fields) => v.object(Object.fromEntries(fields))));
189
+
190
+ const compileSchema = (schema: Schema.Top, side?: "args" | "returns") => {
191
+ const ast = Schema.toEncoded(schema).ast;
192
+ return Effect.runSync(
193
+ Effect.result(
194
+ side === "args" && SchemaAST.isObjects(ast)
195
+ ? compileArgs(ast)
196
+ : compileAst(ast),
197
+ ),
198
+ );
199
+ };
200
+
201
+ const describeCompiled = (
202
+ compiled: ReadonlyArray<ReturnType<typeof compileSchema>>,
203
+ ): Schema.Json =>
204
+ unionOf(
205
+ keyed([
206
+ ...membersOf(Array.getSuccesses(compiled)).map(([, json]) => json),
207
+ ...Array.getFailures(compiled).map((error) => ({
208
+ kind: "unsupported",
209
+ reason: error.message,
210
+ })),
211
+ ]),
212
+ );
213
+
214
+ /**
215
+ * Compare the validators Convex would compile for the contract and for the host
216
+ * function, both in the application's ID scope, so a component's IDs are
217
+ * strings on both sides and the host's own IDs stay `v.id`. A host that is
218
+ * itself a component registers its own IDs as `v.id` in its scope, which this
219
+ * check cannot see and compares as strings. Args and returns must be equal.
220
+ * Every error the host may fail with, its middleware's included, must be one
221
+ * the contract declares: the same schema, or one compiling to the same
222
+ * validator. The host may declare fewer errors.
223
+ */
224
+ const verify = (
225
+ contract: Callback.Any,
226
+ ref: Ref.AnyConfect,
227
+ ): Result.Result<void, CallbackContractMismatch> => {
228
+ const mismatch = (
229
+ side: CallbackContractMismatch["side"],
230
+ expected: Schema.Json,
231
+ actual: Schema.Json,
232
+ ) =>
233
+ Result.fail(
234
+ new CallbackContractMismatch({
235
+ contract: contract.id,
236
+ side,
237
+ expected,
238
+ actual,
239
+ }),
240
+ );
241
+ const provenance = contract.functionProvenance;
242
+
243
+ for (const side of ["args", "returns"] as const) {
244
+ const expected = compileSchema(provenance[side], side);
245
+ const actual = compileSchema(ref[side], side);
246
+ const expectedDescription = describeCompiled([expected]);
247
+ const actualDescription = describeCompiled([actual]);
248
+ if (
249
+ Result.isFailure(expected) ||
250
+ Result.isFailure(actual) ||
251
+ JSON.stringify(expectedDescription) !== JSON.stringify(actualDescription)
252
+ ) {
253
+ return mismatch(side, expectedDescription, actualDescription);
254
+ }
255
+ }
256
+
257
+ const declared = ownError(provenance).flatMap(errorAlternatives);
258
+ const undeclared = [
259
+ ...ownError(ref),
260
+ ...MiddlewareSpec.errorSchemas(ref.middlewareSpecs),
261
+ ]
262
+ .flatMap(errorAlternatives)
263
+ .filter((schema) => !declared.includes(schema));
264
+ if (undeclared.length > 0) {
265
+ const expectedErrors = declared.map((schema) => compileSchema(schema));
266
+ const actualErrors = undeclared.map((schema) => compileSchema(schema));
267
+ const keys = new Set(
268
+ membersOf(Array.getSuccesses(expectedErrors)).map(([key]) => key),
269
+ );
270
+ if (
271
+ Array.getFailures(actualErrors).length > 0 ||
272
+ !membersOf(Array.getSuccesses(actualErrors)).every(([key]) =>
273
+ keys.has(key),
274
+ )
275
+ ) {
276
+ return mismatch(
277
+ "error",
278
+ describeCompiled(expectedErrors),
279
+ describeCompiled(actualErrors),
280
+ );
281
+ }
282
+ }
283
+
284
+ return Result.void;
285
+ };
286
+
287
+ /**
288
+ * Create a handle a component can store and run to call `ref` under `contract`.
289
+ * A ref whose function type, args or returns visibly differ from the contract
290
+ * on the wire, or whose errors are undeclared, is a type error. The host may
291
+ * declare fewer errors. Before asking Convex for the handle, a Confect ref's
292
+ * compiled validators are checked against the contract's. A mismatch or an
293
+ * unsupported schema fails with `CallbackContractMismatch`. A plain Convex ref
294
+ * has no codecs to compile, so only the type check applies to it. A ref to a
295
+ * function that is not deployed is a defect.
296
+ */
297
+ export const create = Effect.fn("Callback.create")(function* <
298
+ Contract_ extends Callback.Any,
299
+ Ref_ extends Ref.Any,
300
+ >(
301
+ contract: Contract_,
302
+ ref: Ref_ & Callback.Check<Contract_, Ref_>,
303
+ ): Effect.fn.Return<Callback.Handle<Contract_>, CallbackContractMismatch> {
304
+ if (ref._tag === "Confect") {
305
+ yield* Effect.fromResult(verify(contract, ref));
306
+ }
307
+ const text = yield* Effect.promise(() =>
308
+ createFunctionHandle(Ref.getFunctionReference(ref)),
309
+ );
310
+ return yield* Schema.decodeEffect(Callback.handle(contract))(text).pipe(
311
+ Effect.orDie,
312
+ );
313
+ });