oneie 2.0.1 → 2.0.3

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 (406) hide show
  1. package/AGENTS.md +245 -0
  2. package/CLAUDE.md +534 -0
  3. package/README.md +61 -4
  4. package/one/.obsidian/app.json +1 -0
  5. package/one/.obsidian/appearance.json +1 -0
  6. package/one/.obsidian/core-plugins.json +33 -0
  7. package/one/.obsidian/workspace.json +211 -0
  8. package/one/connections/a2a.md +551 -0
  9. package/one/connections/acp.md +761 -0
  10. package/one/connections/acps.md +731 -0
  11. package/one/connections/agui.md +767 -0
  12. package/one/connections/any-backend.md +1702 -0
  13. package/one/connections/ap2.md +998 -0
  14. package/one/connections/api-docs.md +1891 -0
  15. package/one/connections/api.md +2190 -0
  16. package/one/connections/architecture-diagram.md +94 -0
  17. package/one/connections/communications.md +449 -0
  18. package/one/connections/connections.md +339 -0
  19. package/one/connections/cryptonetworks.md +781 -0
  20. package/one/connections/documentation.md +1120 -0
  21. package/one/connections/effect.md +279 -0
  22. package/one/connections/elizaos.md +1290 -0
  23. package/one/connections/inference.md +58 -0
  24. package/one/connections/kyc.md +632 -0
  25. package/one/connections/mcp.md +842 -0
  26. package/one/connections/membership.md +1152 -0
  27. package/one/connections/middleware.md +1067 -0
  28. package/one/connections/multitenant.md +1341 -0
  29. package/one/connections/n8n.md +1015 -0
  30. package/one/connections/patterns.md +89 -0
  31. package/one/connections/protocols.md +279 -0
  32. package/one/connections/relationships.md +107 -0
  33. package/one/connections/schema.md +587 -0
  34. package/one/connections/service-layer.md +550 -0
  35. package/one/connections/structure.md +0 -0
  36. package/one/connections/vectors.md +207 -0
  37. package/one/connections/wordpress.md +1302 -0
  38. package/one/connections/workflow-copy.md +905 -0
  39. package/one/connections/workflow-examples.md +741 -0
  40. package/one/connections/workflow.md +905 -0
  41. package/one/connections/workflows/delegation.md +885 -0
  42. package/one/connections/workflows/frontend.md +1037 -0
  43. package/one/connections/workflows/strategy.md +903 -0
  44. package/one/connections/workflows/tasks.md +698 -0
  45. package/one/connections/x402.md +1249 -0
  46. package/one/events/events.md +545 -0
  47. package/one/knowledge/ai-platform.md +305 -0
  48. package/one/knowledge/architecture-diagram.md +94 -0
  49. package/one/knowledge/architecture-frontend.md +930 -0
  50. package/one/knowledge/architecture.md +2077 -0
  51. package/one/knowledge/crypto.md +960 -0
  52. package/one/knowledge/dsl.md +1660 -0
  53. package/one/knowledge/files.md +2471 -0
  54. package/one/knowledge/frontend.md +1038 -0
  55. package/one/knowledge/hono.md +2109 -0
  56. package/one/knowledge/implementation-examples.md +2536 -0
  57. package/one/knowledge/inference-score.md +159 -0
  58. package/one/knowledge/knowledge.md +642 -0
  59. package/one/knowledge/language.md +980 -0
  60. package/one/knowledge/lessons-learned.md +70 -0
  61. package/one/knowledge/ontology-6-dimensions.md +0 -0
  62. package/one/knowledge/ontology-documentation.md +356 -0
  63. package/one/knowledge/ontology-engineering-specification.md +1292 -0
  64. package/one/knowledge/ontology-engineering.md +1652 -0
  65. package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
  66. package/one/knowledge/ontology-frontend-copy.md +753 -0
  67. package/one/knowledge/ontology-frontend-specifications.md +2188 -0
  68. package/one/knowledge/ontology-frontend.md +2427 -0
  69. package/one/knowledge/ontology-minimal.yaml +299 -0
  70. package/one/knowledge/ontology.md +2819 -0
  71. package/one/knowledge/ontology.yaml +1165 -0
  72. package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
  73. package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
  74. package/one/knowledge/patterns/backend/mutation-template.md +231 -0
  75. package/one/knowledge/patterns/backend/query-template.md +267 -0
  76. package/one/knowledge/patterns/backend/service-template.md +237 -0
  77. package/one/knowledge/patterns/design/component-architecture.md +399 -0
  78. package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
  79. package/one/knowledge/patterns/design/wireframe-template.md +216 -0
  80. package/one/knowledge/patterns/frontend/component-template.md +195 -0
  81. package/one/knowledge/patterns/frontend/form-template.md +276 -0
  82. package/one/knowledge/patterns/frontend/page-template.md +178 -0
  83. package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
  84. package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
  85. package/one/knowledge/patterns/test/technical-test-template.md +544 -0
  86. package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
  87. package/one/knowledge/patterns/test/user-flow-template.md +254 -0
  88. package/one/knowledge/quality-loop.md +401 -0
  89. package/one/knowledge/readme.md +131 -0
  90. package/one/knowledge/rules.md +626 -0
  91. package/one/knowledge/score.md +67 -0
  92. package/one/knowledge/specifications.md +855 -0
  93. package/one/knowledge/tags.md +130 -0
  94. package/one/organisation/one.md +599 -0
  95. package/one/organisation/organisation.md +438 -0
  96. package/one/organisation/revenue.md +673 -0
  97. package/one/organisation/strategy.md +869 -0
  98. package/one/organisation/vision.md +98 -0
  99. package/one/people/anthony-o-connell.md +440 -0
  100. package/one/people/people.md +567 -0
  101. package/one/repomix-output.md +92634 -0
  102. package/one/things/agentkit.md +349 -0
  103. package/one/things/agents/agent-backend.md +1401 -0
  104. package/one/things/agents/agent-builder.md +955 -0
  105. package/one/things/agents/agent-clean.md +709 -0
  106. package/one/things/agents/agent-clone.md +1341 -0
  107. package/one/things/agents/agent-designer.md +2177 -0
  108. package/one/things/agents/agent-director.md +1508 -0
  109. package/one/things/agents/agent-documenter.md +1049 -0
  110. package/one/things/agents/agent-frontend.md +1119 -0
  111. package/one/things/agents/agent-integrator.md +1192 -0
  112. package/one/things/agents/agent-problem-solver.md +1379 -0
  113. package/one/things/agents/agent-quality.md +1353 -0
  114. package/one/things/agents/agent-sales.md +986 -0
  115. package/one/things/cascade/cascade.yaml +464 -0
  116. package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
  117. package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
  118. package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
  119. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
  120. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
  121. package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
  122. package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
  123. package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
  124. package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
  125. package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
  126. package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
  127. package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
  128. package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
  129. package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
  130. package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
  131. package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
  132. package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
  133. package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
  134. package/one/things/cascade/docs/examples/readme.md +222 -0
  135. package/one/things/cascade/docs/getting-started.md +515 -0
  136. package/one/things/cascade/docs/workflow.md +1372 -0
  137. package/one/things/cascade/readme.md +336 -0
  138. package/one/things/cascade/templates/feature-template.md +267 -0
  139. package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
  140. package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
  141. package/one/things/claude/agents/analyst.md +483 -0
  142. package/one/things/claude/agents/architect.md +480 -0
  143. package/one/things/claude/agents/brand-identity-specialist.md +513 -0
  144. package/one/things/claude/agents/bstp-token-strategist.md +667 -0
  145. package/one/things/claude/agents/builder-repo.md +489 -0
  146. package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
  147. package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
  148. package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
  149. package/one/things/claude/agents/company-bullstamp-character.md +587 -0
  150. package/one/things/claude/agents/company-bullstamp-community.md +292 -0
  151. package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
  152. package/one/things/claude/agents/company-bullstamp-token.md +292 -0
  153. package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
  154. package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
  155. package/one/things/claude/agents/content-calendar-planner.md +448 -0
  156. package/one/things/claude/agents/content-chapter-formatter.md +488 -0
  157. package/one/things/claude/agents/content-formatter.md +546 -0
  158. package/one/things/claude/agents/content-hook-specialist.md +462 -0
  159. package/one/things/claude/agents/content-image-formatter.md +535 -0
  160. package/one/things/claude/agents/content-introduction-formatter.md +485 -0
  161. package/one/things/claude/agents/content-multiplication-engine.md +556 -0
  162. package/one/things/claude/agents/content-playbook-writer.md +448 -0
  163. package/one/things/claude/agents/content-team-manager.md +622 -0
  164. package/one/things/claude/agents/content-toc-formatter.md +522 -0
  165. package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
  166. package/one/things/claude/agents/core-manager.md +582 -0
  167. package/one/things/claude/agents/core-master.md +403 -0
  168. package/one/things/claude/agents/cross-functional-manager.md +471 -0
  169. package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
  170. package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
  171. package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
  172. package/one/things/claude/agents/crypto-community-analyst.md +298 -0
  173. package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
  174. package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
  175. package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
  176. package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
  177. package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
  178. package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
  179. package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
  180. package/one/things/claude/agents/crypto-market-researcher.md +292 -0
  181. package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
  182. package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
  183. package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
  184. package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
  185. package/one/things/claude/agents/crypto-team-manager.md +387 -0
  186. package/one/things/claude/agents/crypto-token-analyst.md +278 -0
  187. package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
  188. package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
  189. package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
  190. package/one/things/claude/agents/customer-journey-designer.md +481 -0
  191. package/one/things/claude/agents/customer-success-manager.md +581 -0
  192. package/one/things/claude/agents/dev.md +413 -0
  193. package/one/things/claude/agents/documenter.md +546 -0
  194. package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
  195. package/one/things/claude/agents/engagement-specialist.md +509 -0
  196. package/one/things/claude/agents/engineering-architect.md +387 -0
  197. package/one/things/claude/agents/engineering-business-analyst.md +537 -0
  198. package/one/things/claude/agents/engineering-developer.md +387 -0
  199. package/one/things/claude/agents/engineering-director.md +282 -0
  200. package/one/things/claude/agents/engineering-ingestor.md +649 -0
  201. package/one/things/claude/agents/engineering-product-manager.md +537 -0
  202. package/one/things/claude/agents/engineering-product-owner.md +537 -0
  203. package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
  204. package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
  205. package/one/things/claude/agents/engineering-team-manager.md +512 -0
  206. package/one/things/claude/agents/engineering-user-experience.md +387 -0
  207. package/one/things/claude/agents/framework-elevate-manager.md +294 -0
  208. package/one/things/claude/agents/improver.md +763 -0
  209. package/one/things/claude/agents/intelligence-team-manager.md +385 -0
  210. package/one/things/claude/agents/lead-capture-expert.md +466 -0
  211. package/one/things/claude/agents/lead-magnet-creator.md +453 -0
  212. package/one/things/claude/agents/market-research-analyst.md +412 -0
  213. package/one/things/claude/agents/marketing-brand-identity.md +314 -0
  214. package/one/things/claude/agents/marketing-content-hooks.md +450 -0
  215. package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
  216. package/one/things/claude/agents/marketing-content-poster.md +361 -0
  217. package/one/things/claude/agents/marketing-customer-journey.md +326 -0
  218. package/one/things/claude/agents/marketing-director.md +397 -0
  219. package/one/things/claude/agents/marketing-engagement.md +326 -0
  220. package/one/things/claude/agents/marketing-lead-capture.md +326 -0
  221. package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
  222. package/one/things/claude/agents/marketing-network-effects.md +326 -0
  223. package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
  224. package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
  225. package/one/things/claude/agents/marketing-team-manager.md +446 -0
  226. package/one/things/claude/agents/marketing-viral-growth.md +201 -0
  227. package/one/things/claude/agents/mission-commander.md +373 -0
  228. package/one/things/claude/agents/network-effect-analyst.md +587 -0
  229. package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
  230. package/one/things/claude/agents/npx.md +890 -0
  231. package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
  232. package/one/things/claude/agents/one-master.md +355 -0
  233. package/one/things/claude/agents/one-orchestrator.md +315 -0
  234. package/one/things/claude/agents/one.md +601 -0
  235. package/one/things/claude/agents/playbook-generator.md +503 -0
  236. package/one/things/claude/agents/pm.md +326 -0
  237. package/one/things/claude/agents/po.md +345 -0
  238. package/one/things/claude/agents/qa.md +336 -0
  239. package/one/things/claude/agents/research-foundation-analyst.md +307 -0
  240. package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
  241. package/one/things/claude/agents/research-market-analyst.md +307 -0
  242. package/one/things/claude/agents/research-team-manager.md +482 -0
  243. package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
  244. package/one/things/claude/agents/sales-team-manager.md +400 -0
  245. package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
  246. package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
  247. package/one/things/claude/agents/service-advocacy-manager.md +307 -0
  248. package/one/things/claude/agents/service-success-manager.md +307 -0
  249. package/one/things/claude/agents/service-team-manager.md +400 -0
  250. package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
  251. package/one/things/claude/agents/share-optimization-specialist.md +551 -0
  252. package/one/things/claude/agents/sm.md +327 -0
  253. package/one/things/claude/agents/story-teller.md +473 -0
  254. package/one/things/claude/agents/task-master.md +596 -0
  255. package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
  256. package/one/things/claude/agents/tester.md +556 -0
  257. package/one/things/claude/agents/the-bull-character-manager.md +580 -0
  258. package/one/things/claude/agents/tools-playbook-generator.md +489 -0
  259. package/one/things/claude/agents/turbo-repo-builder.md +316 -0
  260. package/one/things/claude/agents/upsell-strategist.md +480 -0
  261. package/one/things/claude/agents/ux-expert.md +335 -0
  262. package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
  263. package/one/things/claude/claude-code-hooks-development.json +21 -0
  264. package/one/things/claude/claude-code-hooks-production.json +21 -0
  265. package/one/things/claude/claude-code-hooks.json +25 -0
  266. package/one/things/claude/commands/agent.md +104 -0
  267. package/one/things/claude/commands/cascade-status.md +128 -0
  268. package/one/things/claude/commands/ingest.md +290 -0
  269. package/one/things/claude/commands/ingestor.md +136 -0
  270. package/one/things/claude/commands/mission.md +83 -0
  271. package/one/things/claude/commands/npx.md +133 -0
  272. package/one/things/claude/commands/one.md +440 -0
  273. package/one/things/claude/commands/quality-check.md +204 -0
  274. package/one/things/claude/commands/smart-route.md +220 -0
  275. package/one/things/claude/commands/start.md +121 -0
  276. package/one/things/claude/commands/story.md +83 -0
  277. package/one/things/claude/commands/task.md +173 -0
  278. package/one/things/claude/hook-bypass.json +32 -0
  279. package/one/things/claude/hooks/agent-hook-config.json +427 -0
  280. package/one/things/claude/hooks/agent-hook-manager.js +525 -0
  281. package/one/things/claude/hooks/agent-load-balancer.js +271 -0
  282. package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
  283. package/one/things/claude/hooks/build-hook.sh +156 -0
  284. package/one/things/claude/hooks/cascade-feedback.js +297 -0
  285. package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
  286. package/one/things/claude/hooks/cleanup-hook.sh +201 -0
  287. package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
  288. package/one/things/claude/hooks/file-organization-engine.js +427 -0
  289. package/one/things/claude/hooks/file-organization-hook.sh +80 -0
  290. package/one/things/claude/hooks/file-organization-monitor.js +269 -0
  291. package/one/things/claude/hooks/format-hook.sh +43 -0
  292. package/one/things/claude/hooks/hook-bypass.sh +293 -0
  293. package/one/things/claude/hooks/hook-config-manager.js +202 -0
  294. package/one/things/claude/hooks/hook-debouncer.sh +62 -0
  295. package/one/things/claude/hooks/hook-logger.sh +89 -0
  296. package/one/things/claude/hooks/hook-orchestrator.js +662 -0
  297. package/one/things/claude/hooks/hook-performance-report.js +120 -0
  298. package/one/things/claude/hooks/lint-hook.sh +140 -0
  299. package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
  300. package/one/things/claude/hooks/memory-optimizer.js +510 -0
  301. package/one/things/claude/hooks/notification-hook.sh +204 -0
  302. package/one/things/claude/hooks/ontology-compliance.js +394 -0
  303. package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
  304. package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
  305. package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
  306. package/one/things/claude/hooks/performance-metrics.json +25 -0
  307. package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
  308. package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
  309. package/one/things/claude/hooks/security-hook.sh +256 -0
  310. package/one/things/claude/hooks/simple-load-balancer.js +238 -0
  311. package/one/things/claude/hooks/startup-optimizer.js +625 -0
  312. package/one/things/claude/hooks/story-scoring-system.js +445 -0
  313. package/one/things/claude/hooks/story-validation-engine.js +473 -0
  314. package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
  315. package/one/things/claude/hooks/story-validation-hook.sh +145 -0
  316. package/one/things/claude/hooks/structure-synchronizer.js +194 -0
  317. package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
  318. package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
  319. package/one/things/claude/hooks/test-hook.sh +145 -0
  320. package/one/things/claude/hooks/test-story-validation.sh +170 -0
  321. package/one/things/claude/hooks/trinity-validation-system.js +392 -0
  322. package/one/things/claude/settings-local.json +86 -0
  323. package/one/things/cli-code.md +652 -0
  324. package/one/things/cli-compiler-code.md +652 -0
  325. package/one/things/cli.md +1045 -0
  326. package/one/things/components/card-shadcn.md +929 -0
  327. package/one/things/components/card.md +1050 -0
  328. package/one/things/components.md +1669 -0
  329. package/one/things/componets.md +4 -0
  330. package/one/things/copilotkit.md +1559 -0
  331. package/one/things/creator-diagram.md +166 -0
  332. package/one/things/examples/children/lemonade-stand.md +366 -0
  333. package/one/things/examples/enterprise/crm-saas.md +1429 -0
  334. package/one/things/features/1-1-agent-prompts/design.md +470 -0
  335. package/one/things/features/1-1-agent-prompts/tests.md +264 -0
  336. package/one/things/features/1-1-agent-prompts.md +486 -0
  337. package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
  338. package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
  339. package/one/things/features/1-2-yaml-orchestrator.md +516 -0
  340. package/one/things/features/1-3-event-coordination/design.md +544 -0
  341. package/one/things/features/1-3-event-coordination/tests.md +223 -0
  342. package/one/things/features/1-3-event-coordination.md +508 -0
  343. package/one/things/features/1-4-knowledge-management/design.md +609 -0
  344. package/one/things/features/1-4-knowledge-management/tests.md +195 -0
  345. package/one/things/features/1-4-knowledge-management.md +577 -0
  346. package/one/things/features/1-5-quality-loops/design.md +797 -0
  347. package/one/things/features/1-5-quality-loops/tests.md +212 -0
  348. package/one/things/features/1-5-quality-loops.md +641 -0
  349. package/one/things/features/1-6-numbering-structure/design.md +610 -0
  350. package/one/things/features/1-6-numbering-structure/tests.md +213 -0
  351. package/one/things/features/1-6-numbering-structure.md +575 -0
  352. package/one/things/features/2-cli.md +1235 -0
  353. package/one/things/features/use-one-backend.md +1180 -0
  354. package/one/things/ideas/1-create-workflow.md +189 -0
  355. package/one/things/plans/1-create-workflow-status.md +555 -0
  356. package/one/things/plans/1-create-workflow.md +713 -0
  357. package/one/things/plans/app.md +761 -0
  358. package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
  359. package/one/things/plans/better-auth-any-backend.md +1852 -0
  360. package/one/things/plans/better-auth-available-features.md +235 -0
  361. package/one/things/plans/big-plan.md +38 -0
  362. package/one/things/plans/convex-better-auth.md +1109 -0
  363. package/one/things/plans/convex-on-off.md +389 -0
  364. package/one/things/plans/desktop.md +1121 -0
  365. package/one/things/plans/effect-components.md +1669 -0
  366. package/one/things/plans/effect.md +973 -0
  367. package/one/things/plans/email.md +953 -0
  368. package/one/things/plans/enhance-auth.md +1669 -0
  369. package/one/things/plans/install-components.md +198 -0
  370. package/one/things/plans/landing.md +728 -0
  371. package/one/things/plans/layout.md +205 -0
  372. package/one/things/plans/mail-backend.md +1308 -0
  373. package/one/things/plans/mail.md +2624 -0
  374. package/one/things/plans/next-features.md +83 -0
  375. package/one/things/plans/one.md +658 -0
  376. package/one/things/plans/ontology-6-dimensions.md +2216 -0
  377. package/one/things/plans/ontology-driven-strategy.md +866 -0
  378. package/one/things/plans/ontology-ui-approach.md +357 -0
  379. package/one/things/plans/open-agent.md +785 -0
  380. package/one/things/plans/performace.md +90 -0
  381. package/one/things/plans/releases.md +809 -0
  382. package/one/things/plans/repos.md +76 -0
  383. package/one/things/plans/separate-copy-2.md +1293 -0
  384. package/one/things/plans/separate-copy-3.md +2458 -0
  385. package/one/things/plans/separate-copy.md +1293 -0
  386. package/one/things/plans/separate.md +1983 -0
  387. package/one/things/plans/shadcn-integration-summary.md +450 -0
  388. package/one/things/plans/sidebar.md +172 -0
  389. package/one/things/plans/small-fixes.md +5 -0
  390. package/one/things/plans/test-backend-connection.md +476 -0
  391. package/one/things/plans/workflow-files.md +1196 -0
  392. package/one/things/plans/workflow.md +1372 -0
  393. package/one/things/products/cascade-landing-page.md +737 -0
  394. package/one/things/products/cascade.md +1518 -0
  395. package/one/things/products/context-engineering.md +1427 -0
  396. package/one/things/products/onthology.md +0 -0
  397. package/one/things/products/ontology-ui-shadcn.md +1280 -0
  398. package/one/things/products/ontology-ui.md +1387 -0
  399. package/one/things/products/ontology.md +717 -0
  400. package/one/things/products/sdk.md +557 -0
  401. package/one/things/promptkit.md +903 -0
  402. package/one/things/service-providers-new.md +982 -0
  403. package/one/things/service-providers.md +1092 -0
  404. package/one/things/things.md +349 -0
  405. package/one/things/todo.md +1248 -0
  406. package/package.json +5 -2
@@ -0,0 +1,1669 @@
1
+ # Production Integration Guide: Effect.ts + Confect + Convex Components for AI Agents
2
+
3
+ **Building sophisticated multi-agent systems with functional patterns, type safety, and durable workflows**
4
+
5
+ Effect.ts and Confect bring powerful functional programming patterns to Convex's already robust backend platform. While no official Effect integrations exist yet for Convex components, this guide provides production-ready patterns for combining these technologies to build reliable, type-safe AI agent systems.
6
+
7
+ ## Integration Philosophy: Effect Wraps Components, Not Replaces
8
+
9
+ The key insight is that **Effect.ts enhances business logic composition while Convex components handle infrastructure concerns**. Components like Agent, Workflow, and RAG provide production-tested patterns that you wrap with Effect for better error handling, dependency injection, and testability.
10
+
11
+ ```typescript
12
+ // WRONG: Trying to replace components with Effect
13
+ const myOwnAgentLogic = Effect.gen(function* () {...})
14
+
15
+ // RIGHT: Wrapping components with Effect for better composition
16
+ const agentWithEffect = (agent: Agent) => Effect.gen(function* () {
17
+ const result = yield* Effect.tryPromise({
18
+ try: () => agent.generateText(ctx, { threadId }, { prompt }),
19
+ catch: (error) => new AgentExecutionError({ cause: error })
20
+ })
21
+ return result
22
+ })
23
+ ```
24
+
25
+ ## Integration Patterns by Component
26
+
27
+ ### 1. @convex-dev/agent with Effect Integration
28
+
29
+ **Where Effect Adds Value**: Business logic orchestration, error handling, composing multiple agent calls, dependency injection for services used by tools.
30
+
31
+ **Where to Use Component Directly**: Thread/message management, streaming, built-in RAG, tool calling infrastructure.
32
+
33
+ #### Pattern: Effect-Wrapped Agent Execution
34
+
35
+ ```typescript
36
+ import { Effect, Context } from "effect"
37
+ import { Agent } from "@convex-dev/agent"
38
+ import { openai } from "@ai-sdk/openai"
39
+ import { components } from "./_generated/api"
40
+
41
+ // Define errors as tagged classes
42
+ class AgentError extends Data.TaggedError("AgentError")<{
43
+ agentName: string
44
+ cause: unknown
45
+ }> {}
46
+
47
+ // Service definition for agent
48
+ class AgentService extends Context.Tag("AgentService")<
49
+ AgentService,
50
+ {
51
+ readonly generateResponse: (
52
+ ctx: ActionCtx,
53
+ threadId: string,
54
+ prompt: string
55
+ ) => Effect.Effect<string, AgentError>
56
+ }
57
+ >() {}
58
+
59
+ // Implementation with Effect
60
+ const AgentServiceLive = Layer.effect(
61
+ AgentService,
62
+ Effect.gen(function* () {
63
+ // Agent component handles infrastructure
64
+ const supportAgent = new Agent(components.agent, {
65
+ name: "Support Agent",
66
+ chat: openai.chat("gpt-4o-mini"),
67
+ instructions: "You are a helpful assistant.",
68
+ tools: { /* ... */ }
69
+ })
70
+
71
+ return {
72
+ generateResponse: (ctx, threadId, prompt) =>
73
+ Effect.tryPromise({
74
+ try: async () => {
75
+ const { thread } = await supportAgent.continueThread(ctx, { threadId })
76
+ const result = await thread.generateText({ prompt })
77
+ return result.text
78
+ },
79
+ catch: (error) => new AgentError({
80
+ agentName: "Support Agent",
81
+ cause: error
82
+ })
83
+ })
84
+ }
85
+ })
86
+ )
87
+ ```
88
+
89
+ #### Pattern: Composing Multiple Agents with Effect
90
+
91
+ ```typescript
92
+ // Multi-agent orchestration with Effect
93
+ export const multiAgentPipeline = action({
94
+ args: { prompt: v.string(), userId: v.string() },
95
+ handler: (ctx, args) =>
96
+ Effect.gen(function* () {
97
+ const agentService = yield* AgentService
98
+ const ragService = yield* RAGService
99
+
100
+ // Sequential with automatic error propagation
101
+ const context = yield* ragService.search(args.prompt)
102
+ const classification = yield* agentService.classify(ctx, args.prompt)
103
+
104
+ // Conditional routing
105
+ const response = yield* classification.intent === "technical"
106
+ ? agentService.technicalAgent(ctx, args.prompt, context)
107
+ : agentService.generalAgent(ctx, args.prompt, context)
108
+
109
+ // Parallel quality checks
110
+ const [grammar, factuality] = yield* Effect.all([
111
+ agentService.checkGrammar(response),
112
+ agentService.checkFactuality(response, context)
113
+ ], { concurrency: 2 })
114
+
115
+ return { response, grammar, factuality }
116
+ }).pipe(
117
+ Effect.provide(Layer.merge(AgentServiceLive, RAGServiceLive)),
118
+ Effect.catchAll((error) => {
119
+ console.error("Multi-agent pipeline failed:", error)
120
+ return Effect.succeed({
121
+ response: "I'm having trouble processing that request.",
122
+ error: true
123
+ })
124
+ })
125
+ )
126
+ })
127
+ ```
128
+
129
+ #### Pattern: Effect-Based Tool Definitions
130
+
131
+ ```typescript
132
+ import { createTool } from "@convex-dev/agent"
133
+ import { z } from "zod"
134
+
135
+ // Define service for external integrations
136
+ class EmailService extends Context.Tag("EmailService")<
137
+ EmailService,
138
+ {
139
+ readonly send: (to: string, subject: string, body: string)
140
+ => Effect.Effect<void, EmailError>
141
+ }
142
+ >() {}
143
+
144
+ const EmailServiceLive = Layer.succeed(EmailService, {
145
+ send: (to, subject, body) =>
146
+ Effect.tryPromise({
147
+ try: () => sendgrid.send({ to, subject, body }),
148
+ catch: (error) => new EmailError({ cause: error })
149
+ })
150
+ })
151
+
152
+ // Tool that uses Effect internally
153
+ export const emailTool = createTool({
154
+ description: "Send an email to a user",
155
+ args: z.object({
156
+ userEmail: z.string().email(),
157
+ subject: z.string(),
158
+ message: z.string()
159
+ }),
160
+ handler: async (toolCtx, args) => {
161
+ // Convert Effect to Promise for tool handler
162
+ const program = Effect.gen(function* () {
163
+ const emailService = yield* EmailService
164
+ yield* emailService.send(args.userEmail, args.subject, args.message)
165
+ return "Email sent successfully"
166
+ })
167
+
168
+ return await Effect.runPromise(
169
+ program.pipe(
170
+ Effect.provide(EmailServiceLive),
171
+ Effect.catchAll((error) =>
172
+ Effect.succeed(`Failed to send email: ${error.message}`)
173
+ )
174
+ )
175
+ )
176
+ }
177
+ })
178
+
179
+ const agent = new Agent(components.agent, {
180
+ chat: openai.chat("gpt-4o"),
181
+ tools: { sendEmail: emailTool }
182
+ })
183
+ ```
184
+
185
+ **Type Safety Considerations**:
186
+
187
+ - Effect's error channel tracks all possible failures
188
+ - Tool context provides typed access to `userId`, `threadId`, `messageId`
189
+ - Convert Effects to Promises at the tool boundary using `Effect.runPromise`
190
+ - Use `Effect.tryPromise` to wrap agent component calls
191
+
192
+ ---
193
+
194
+ ### 2. @convex-dev/persistent-text-streaming with Effect
195
+
196
+ **Where Effect Adds Value**: Error recovery during streaming, composing stream generation with other services, handling stream lifecycle.
197
+
198
+ **Where to Use Component Directly**: WebSocket delivery, delta storage, client subscription.
199
+
200
+ #### Pattern: Effect-Managed Streaming Lifecycle
201
+
202
+ ```typescript
203
+ import { PersistentTextStreaming } from "@convex-dev/persistent-text-streaming"
204
+ import { Effect, Stream } from "effect"
205
+
206
+ class StreamingService extends Context.Tag("StreamingService")<
207
+ StreamingService,
208
+ {
209
+ readonly generateStream: (
210
+ ctx: ActionCtx,
211
+ prompt: string,
212
+ streamId: string
213
+ ) => Effect.Effect<void, StreamingError>
214
+ }
215
+ >() {}
216
+
217
+ const StreamingServiceLive = Layer.effect(
218
+ StreamingService,
219
+ Effect.gen(function* () {
220
+ const persistentTextStreaming = new PersistentTextStreaming(
221
+ components.persistentTextStreaming
222
+ )
223
+
224
+ const llmService = yield* LLMService
225
+
226
+ return {
227
+ generateStream: (ctx, prompt, streamId) =>
228
+ Effect.gen(function* () {
229
+ // Fetch context with Effect error handling
230
+ const context = yield* Effect.tryPromise({
231
+ try: () => ctx.runQuery(api.chat.getContext, { streamId }),
232
+ catch: () => new ContextFetchError()
233
+ })
234
+
235
+ // Stream with Effect composition
236
+ const stream = yield* llmService.streamCompletion(prompt, context)
237
+
238
+ // Handle chunks with backpressure
239
+ yield* Stream.fromAsyncIterable(stream, () =>
240
+ new StreamProcessingError()
241
+ ).pipe(
242
+ Stream.mapEffect((chunk) =>
243
+ Effect.tryPromise({
244
+ try: async () => {
245
+ await persistentTextStreaming.appendChunk(ctx, streamId, chunk)
246
+ },
247
+ catch: () => new ChunkAppendError({ chunk })
248
+ })
249
+ ),
250
+ Stream.runDrain
251
+ )
252
+
253
+ // Mark complete
254
+ yield* Effect.tryPromise({
255
+ try: () =>
256
+ ctx.runMutation(api.chat.markComplete, { streamId }),
257
+ catch: () => new StreamCompletionError()
258
+ })
259
+ }).pipe(
260
+ Effect.retry(Schedule.exponential("100 millis").pipe(
261
+ Schedule.compose(Schedule.recurs(3))
262
+ ))
263
+ )
264
+ }
265
+ })
266
+ )
267
+ ```
268
+
269
+ **Recommendation**: Use Agent component's built-in streaming (`saveStreamDeltas: true`) for most use cases. Only use persistent-text-streaming if you need HTTP streaming for the initiating client specifically.
270
+
271
+ ---
272
+
273
+ ### 3. @convex-dev/rate-limiter with Effect
274
+
275
+ **Where Effect Adds Value**: Composing rate limiting with business logic, handling rate limit errors functionally, coordinating multiple rate limits.
276
+
277
+ **Where to Use Component Directly**: Token bucket/fixed window algorithms, per-user isolation, capacity reservation.
278
+
279
+ #### Pattern: Effect Service Layer with Rate Limiting
280
+
281
+ ```typescript
282
+ import { RateLimiter, MINUTE } from "@convex-dev/rate-limiter"
283
+ import { Effect, Schedule } from "effect"
284
+
285
+ class RateLimitedLLMService extends Context.Tag("RateLimitedLLMService")<
286
+ RateLimitedLLMService,
287
+ {
288
+ readonly generateCompletion: (
289
+ ctx: ActionCtx,
290
+ userId: string,
291
+ prompt: string
292
+ ) => Effect.Effect<string, RateLimitError | LLMError>
293
+ }
294
+ >() {}
295
+
296
+ const RateLimitedLLMServiceLive = Layer.effect(
297
+ RateLimitedLLMService,
298
+ Effect.gen(function* () {
299
+ const rateLimiter = new RateLimiter(components.rateLimiter, {
300
+ llmRequests: {
301
+ kind: "token bucket",
302
+ rate: 20,
303
+ period: MINUTE,
304
+ capacity: 30
305
+ },
306
+ llmTokens: {
307
+ kind: "token bucket",
308
+ rate: 40000,
309
+ period: MINUTE,
310
+ shards: 10
311
+ }
312
+ })
313
+
314
+ return {
315
+ generateCompletion: (ctx, userId, prompt) =>
316
+ Effect.gen(function* () {
317
+ // Check request limit
318
+ const requestLimit = yield* Effect.tryPromise({
319
+ try: () => rateLimiter.limit(ctx, "llmRequests", {
320
+ key: userId,
321
+ reserve: true
322
+ }),
323
+ catch: () => new RateLimiterError()
324
+ })
325
+
326
+ if (!requestLimit.ok) {
327
+ return yield* Effect.fail(new RateLimitError({
328
+ type: "requests",
329
+ retryAfter: requestLimit.retryAfter
330
+ }))
331
+ }
332
+
333
+ // Estimate token usage
334
+ const estimatedTokens = Math.ceil(prompt.length / 4)
335
+
336
+ const tokenLimit = yield* Effect.tryPromise({
337
+ try: () => rateLimiter.limit(ctx, "llmTokens", {
338
+ key: userId,
339
+ count: estimatedTokens
340
+ }),
341
+ catch: () => new RateLimiterError()
342
+ })
343
+
344
+ if (!tokenLimit.ok) {
345
+ return yield* Effect.fail(new RateLimitError({
346
+ type: "tokens",
347
+ retryAfter: tokenLimit.retryAfter
348
+ }))
349
+ }
350
+
351
+ // Make LLM call
352
+ const result = yield* Effect.tryPromise({
353
+ try: () => openai.chat.completions.create({
354
+ model: "gpt-4",
355
+ messages: [{ role: "user", content: prompt }]
356
+ }),
357
+ catch: (error) => new LLMError({ cause: error })
358
+ })
359
+
360
+ return result.choices[0].message.content
361
+ }).pipe(
362
+ // Automatic retry with exponential backoff on rate limits
363
+ Effect.retry(
364
+ Schedule.exponential("1 second").pipe(
365
+ Schedule.whileInput((error: RateLimitError | LLMError) =>
366
+ error._tag === "RateLimitError"
367
+ ),
368
+ Schedule.recurs(5)
369
+ )
370
+ )
371
+ )
372
+ }
373
+ })
374
+ )
375
+ ```
376
+
377
+ #### Pattern: Multi-Level Rate Limiting with Effect
378
+
379
+ ```typescript
380
+ // Service that coordinates user and global rate limits
381
+ export const protectedAgentCall = action({
382
+ args: { userId: v.string(), prompt: v.string() },
383
+ handler: (ctx, args) =>
384
+ Effect.gen(function* () {
385
+ const rateLimitService = yield* RateLimitService
386
+
387
+ // Check multiple limits in parallel
388
+ const [userLimit, globalLimit] = yield* Effect.all([
389
+ rateLimitService.checkUserLimit(ctx, args.userId),
390
+ rateLimitService.checkGlobalLimit(ctx)
391
+ ], { concurrency: 2 })
392
+
393
+ // Fail fast if any limit exceeded
394
+ if (!userLimit.ok) {
395
+ return yield* Effect.fail(new UserRateLimitExceeded({
396
+ retryAfter: userLimit.retryAfter
397
+ }))
398
+ }
399
+
400
+ if (!globalLimit.ok) {
401
+ return yield* Effect.fail(new GlobalRateLimitExceeded({
402
+ retryAfter: globalLimit.retryAfter
403
+ }))
404
+ }
405
+
406
+ // Execute with agent
407
+ const agentService = yield* AgentService
408
+ const result = yield* agentService.generateResponse(
409
+ ctx,
410
+ args.userId,
411
+ args.prompt
412
+ )
413
+
414
+ return result
415
+ }).pipe(
416
+ Effect.provide(Layer.merge(RateLimitServiceLive, AgentServiceLive)),
417
+ Effect.catchTag("UserRateLimitExceeded", (error) =>
418
+ Effect.succeed({
419
+ error: "You've reached your request limit. Please try again later.",
420
+ retryAfter: error.retryAfter
421
+ })
422
+ )
423
+ )
424
+ })
425
+ ```
426
+
427
+ **Type Safety Considerations**:
428
+
429
+ - Effect's error channel explicitly tracks rate limit vs other errors
430
+ - Use `Effect.retry` with `Schedule.whileInput` for smart retry logic
431
+ - `Effect.all` enables parallel rate limit checks
432
+ - Convert Promise-based rate limiter to Effect with `Effect.tryPromise`
433
+
434
+ ---
435
+
436
+ ### 4. @convex-dev/retrier with Effect
437
+
438
+ **Where Effect Adds Value**: Coordinating retries across multiple operations, custom retry policies, composing retry logic with other effects.
439
+
440
+ **Where to Use Component Directly**: Action retries with persistent state, status tracking, completion callbacks.
441
+
442
+ #### Pattern: Effect-Based Retry Orchestration
443
+
444
+ ```typescript
445
+ import { ActionRetrier } from "@convex-dev/action-retrier"
446
+ import { Effect, Schedule } from "effect"
447
+
448
+ class ResilientExecutionService extends Context.Tag("ResilientExecutionService")<
449
+ ResilientExecutionService,
450
+ {
451
+ readonly executeWithRetry: <A>(
452
+ ctx: MutationCtx,
453
+ action: FunctionReference<"action">,
454
+ args: any
455
+ ) => Effect.Effect<A, ExecutionError>
456
+ }
457
+ >() {}
458
+
459
+ const ResilientExecutionServiceLive = Layer.effect(
460
+ ResilientExecutionService,
461
+ Effect.gen(function* () {
462
+ const retrier = new ActionRetrier(components.actionRetrier, {
463
+ initialBackoffMs: 250,
464
+ base: 2,
465
+ maxFailures: 4
466
+ })
467
+
468
+ return {
469
+ executeWithRetry: (ctx, action, args) =>
470
+ Effect.gen(function* () {
471
+ // Start retry execution
472
+ const runId = yield* Effect.tryPromise({
473
+ try: () => retrier.run(ctx, action, args),
474
+ catch: () => new RetrierStartError()
475
+ })
476
+
477
+ // Poll for completion with Effect
478
+ const result = yield* Effect.repeat(
479
+ Effect.gen(function* () {
480
+ const status = yield* Effect.tryPromise({
481
+ try: () => retrier.status(ctx, runId),
482
+ catch: () => new StatusCheckError()
483
+ })
484
+
485
+ if (status.type === "inProgress") {
486
+ return yield* Effect.fail(Option.none()) // Continue polling
487
+ }
488
+
489
+ return status.result
490
+ }),
491
+ Schedule.spaced("500 millis").pipe(
492
+ Schedule.compose(Schedule.recurs(60)) // Max 30 seconds
493
+ )
494
+ ).pipe(
495
+ Effect.catchAll((error) =>
496
+ Effect.fail(new ExecutionTimeout({ runId }))
497
+ )
498
+ )
499
+
500
+ // Handle result
501
+ if (result.type === "success") {
502
+ return result.returnValue
503
+ } else if (result.type === "failed") {
504
+ return yield* Effect.fail(new ExecutionFailed({
505
+ error: result.error
506
+ }))
507
+ } else {
508
+ return yield* Effect.fail(new ExecutionCanceled())
509
+ }
510
+ })
511
+ }
512
+ })
513
+ )
514
+ ```
515
+
516
+ #### Pattern: Combining Retrier with Custom Effect Retry
517
+
518
+ ```typescript
519
+ // Use retrier for infrastructure-level retries,
520
+ // Effect for application-level retries
521
+ export const reliableWorkflow = mutation({
522
+ args: { userId: v.string(), data: v.any() },
523
+ handler: (ctx, args) =>
524
+ Effect.gen(function* () {
525
+ const resilientService = yield* ResilientExecutionService
526
+
527
+ // Effect-level retry for transient errors
528
+ const validated = yield* Effect.retry(
529
+ validateUserData(args.data),
530
+ Schedule.exponential("100 millis").pipe(
531
+ Schedule.compose(Schedule.recurs(3))
532
+ )
533
+ )
534
+
535
+ // Retrier-level retry for action execution
536
+ const processed = yield* resilientService.executeWithRetry(
537
+ ctx,
538
+ internal.processing.processData,
539
+ { userId: args.userId, data: validated }
540
+ )
541
+
542
+ return processed
543
+ }).pipe(
544
+ Effect.provide(ResilientExecutionServiceLive),
545
+ Effect.catchAll((error) => {
546
+ console.error("Workflow failed:", error)
547
+ return Effect.fail(new ConvexError("Workflow execution failed"))
548
+ })
549
+ )
550
+ })
551
+ ```
552
+
553
+ **Recommendation**: Use component's retrier for long-running actions with persistent state. Use Effect's `Effect.retry` for in-memory retries of short operations.
554
+
555
+ ---
556
+
557
+ ### 5. @convex-dev/workpool with Effect
558
+
559
+ **Where Effect Adds Value**: Composing work queue operations, error handling for enqueued tasks, coordinating multiple workpools.
560
+
561
+ **Where to Use Component Directly**: Task queuing, parallelism control, completion callbacks.
562
+
563
+ #### Pattern: Effect Service Layer for Workpool
564
+
565
+ ```typescript
566
+ import { Workpool } from "@convex-dev/workpool"
567
+ import { Effect, Queue } from "effect"
568
+
569
+ class TaskQueueService extends Context.Tag("TaskQueueService")<
570
+ TaskQueueService,
571
+ {
572
+ readonly enqueueTask: <A>(
573
+ ctx: MutationCtx,
574
+ priority: "high" | "low",
575
+ action: FunctionReference<"action">,
576
+ args: any
577
+ ) => Effect.Effect<string, EnqueueError>
578
+
579
+ readonly getTaskStatus: (
580
+ ctx: QueryCtx,
581
+ taskId: string
582
+ ) => Effect.Effect<TaskStatus, StatusError>
583
+ }
584
+ >() {}
585
+
586
+ const TaskQueueServiceLive = Layer.effect(
587
+ TaskQueueService,
588
+ Effect.gen(function* () {
589
+ const highPriorityPool = new Workpool(components.highPriorityWorkpool, {
590
+ maxParallelism: 20,
591
+ retryActionsByDefault: true
592
+ })
593
+
594
+ const lowPriorityPool = new Workpool(components.lowPriorityWorkpool, {
595
+ maxParallelism: 5,
596
+ retryActionsByDefault: true
597
+ })
598
+
599
+ return {
600
+ enqueueTask: (ctx, priority, action, args) =>
601
+ Effect.gen(function* () {
602
+ const pool = priority === "high" ? highPriorityPool : lowPriorityPool
603
+
604
+ const taskId = yield* Effect.tryPromise({
605
+ try: () => pool.enqueueAction(ctx, action, args, {
606
+ onComplete: internal.tasks.handleCompletion,
607
+ context: { priority }
608
+ }),
609
+ catch: (error) => new EnqueueError({ cause: error })
610
+ })
611
+
612
+ return taskId
613
+ }),
614
+
615
+ getTaskStatus: (ctx, taskId) =>
616
+ Effect.tryPromise({
617
+ try: () => highPriorityPool.status(taskId).then(status =>
618
+ status ?? lowPriorityPool.status(taskId)
619
+ ),
620
+ catch: () => new StatusError({ taskId })
621
+ })
622
+ }
623
+ })
624
+ )
625
+ ```
626
+
627
+ #### Pattern: Batch Task Enqueuing with Effect
628
+
629
+ ```typescript
630
+ export const processBatch = mutation({
631
+ args: { items: v.array(v.any()) },
632
+ handler: (ctx, args) =>
633
+ Effect.gen(function* () {
634
+ const taskQueue = yield* TaskQueueService
635
+
636
+ // Enqueue all tasks in parallel
637
+ const taskIds = yield* Effect.all(
638
+ args.items.map(item =>
639
+ taskQueue.enqueueTask(ctx, "low", internal.tasks.processItem, item)
640
+ ),
641
+ { concurrency: 10 }
642
+ )
643
+
644
+ return { taskIds, count: taskIds.length }
645
+ }).pipe(
646
+ Effect.provide(TaskQueueServiceLive),
647
+ Effect.catchAll((error) => {
648
+ console.error("Batch processing failed:", error)
649
+ return Effect.succeed({ taskIds: [], count: 0, error: true })
650
+ })
651
+ )
652
+ })
653
+ ```
654
+
655
+ ---
656
+
657
+ ### 6. @convex-dev/workflow with Effect
658
+
659
+ **Where Effect Adds Value**: Business logic in workflow steps, error handling across steps, service composition in workflows.
660
+
661
+ **Where to Use Component Directly**: Durable execution, journaling, long-running operations, retry policies.
662
+
663
+ #### Pattern: Effect Services in Workflow Steps
664
+
665
+ ```typescript
666
+ import { WorkflowManager } from "@convex-dev/workflow"
667
+ import { Effect } from "effect"
668
+
669
+ const workflow = new WorkflowManager(components.workflow, {
670
+ defaultRetryBehavior: {
671
+ maxAttempts: 3,
672
+ initialBackoffMs: 1000,
673
+ base: 2
674
+ }
675
+ })
676
+
677
+ export const aiAgentWorkflow = workflow.define({
678
+ args: { userId: v.string(), prompt: v.string() },
679
+ handler: async (step, args): Promise<WorkflowResult> => {
680
+ // Step 1: Fetch user context (query)
681
+ const userContext = await step.runQuery(
682
+ internal.workflows.getUserContext,
683
+ { userId: args.userId }
684
+ )
685
+
686
+ // Step 2: Generate initial response with Effect composition (action)
687
+ const initialResponse = await step.runAction(
688
+ internal.workflows.generateResponseWithEffect,
689
+ { prompt: args.prompt, context: userContext }
690
+ )
691
+
692
+ // Step 3: Quality check in parallel (actions)
693
+ const [grammarScore, factualityScore] = await Promise.all([
694
+ step.runAction(internal.workflows.checkGrammar, { text: initialResponse }),
695
+ step.runAction(internal.workflows.checkFactuality, { text: initialResponse })
696
+ ])
697
+
698
+ // Step 4: Refine if needed (action with conditional logic)
699
+ const finalResponse = grammarScore < 0.8 || factualityScore < 0.8
700
+ ? await step.runAction(
701
+ internal.workflows.refineResponse,
702
+ { original: initialResponse, context: userContext },
703
+ { retry: { maxAttempts: 2 } }
704
+ )
705
+ : initialResponse
706
+
707
+ // Step 5: Save result (mutation)
708
+ await step.runMutation(
709
+ internal.workflows.saveResult,
710
+ { userId: args.userId, response: finalResponse }
711
+ )
712
+
713
+ return { response: finalResponse, refined: finalResponse !== initialResponse }
714
+ }
715
+ })
716
+
717
+ // The action called by the workflow uses Effect internally
718
+ export const generateResponseWithEffect = internalAction({
719
+ args: { prompt: v.string(), context: v.any() },
720
+ handler: async (ctx, args) => {
721
+ // Use Effect for business logic composition
722
+ const program = Effect.gen(function* () {
723
+ const agentService = yield* AgentService
724
+ const ragService = yield* RAGService
725
+
726
+ // Enrich context with RAG
727
+ const enrichedContext = yield* ragService.search(args.prompt)
728
+
729
+ // Generate with agent
730
+ const response = yield* agentService.generateResponse(
731
+ ctx,
732
+ args.prompt,
733
+ { ...args.context, rag: enrichedContext }
734
+ )
735
+
736
+ return response
737
+ })
738
+
739
+ return await Effect.runPromise(
740
+ program.pipe(
741
+ Effect.provide(Layer.merge(AgentServiceLive, RAGServiceLive)),
742
+ Effect.catchAll((error) => {
743
+ console.error("Generation failed:", error)
744
+ return Effect.succeed("I apologize, but I'm having trouble generating a response.")
745
+ })
746
+ )
747
+ )
748
+ }
749
+ })
750
+ ```
751
+
752
+ **Key Pattern**: Workflow component handles durability and retry at the step level. Use Effect within actions for business logic composition and error handling.
753
+
754
+ ---
755
+
756
+ ### 7. @convex-dev/rag with Effect
757
+
758
+ **Where Effect Adds Value**: Composing RAG with other services, custom embedding generation, error handling for vector operations.
759
+
760
+ **Where to Use Component Directly**: Vector storage, semantic search, chunking, filtering.
761
+
762
+ #### Pattern: Effect Service Layer for RAG
763
+
764
+ ```typescript
765
+ import { RAG } from "@convex-dev/rag"
766
+ import { openai } from "@ai-sdk/openai"
767
+ import { Effect } from "effect"
768
+
769
+ class RAGService extends Context.Tag("RAGService")<
770
+ RAGService,
771
+ {
772
+ readonly addDocument: (
773
+ ctx: ActionCtx,
774
+ namespace: string,
775
+ content: string,
776
+ metadata: Record<string, any>
777
+ ) => Effect.Effect<string, RAGError>
778
+
779
+ readonly search: (
780
+ ctx: ActionCtx,
781
+ namespace: string,
782
+ query: string,
783
+ limit?: number
784
+ ) => Effect.Effect<SearchResults, RAGError>
785
+ }
786
+ >() {}
787
+
788
+ const RAGServiceLive = Layer.effect(
789
+ RAGService,
790
+ Effect.gen(function* () {
791
+ const rag = new RAG(components.rag, {
792
+ textEmbeddingModel: openai.embedding("text-embedding-3-small"),
793
+ embeddingDimension: 1536
794
+ })
795
+
796
+ return {
797
+ addDocument: (ctx, namespace, content, metadata) =>
798
+ Effect.gen(function* () {
799
+ // Pre-process content with Effect
800
+ const processed = yield* preprocessContent(content)
801
+
802
+ // Add to RAG
803
+ const entryId = yield* Effect.tryPromise({
804
+ try: () => rag.add(ctx, {
805
+ namespace,
806
+ text: processed,
807
+ filterValues: Object.entries(metadata).map(([name, value]) => ({
808
+ name,
809
+ value
810
+ })),
811
+ onComplete: internal.rag.handleComplete
812
+ }),
813
+ catch: (error) => new RAGAddError({ cause: error })
814
+ })
815
+
816
+ return entryId.entryId
817
+ }),
818
+
819
+ search: (ctx, namespace, query, limit = 10) =>
820
+ Effect.tryPromise({
821
+ try: () => rag.search(ctx, {
822
+ namespace,
823
+ query,
824
+ limit,
825
+ chunkContext: { before: 1, after: 1 },
826
+ vectorScoreThreshold: 0.6
827
+ }),
828
+ catch: (error) => new RAGSearchError({ cause: error })
829
+ })
830
+ }
831
+ })
832
+ )
833
+ ```
834
+
835
+ #### Pattern: Composing RAG with Agent Using Effect
836
+
837
+ ```typescript
838
+ // Agent tool that uses RAG service
839
+ export const contextualAnswerAgent = action({
840
+ args: { userId: v.string(), question: v.string() },
841
+ handler: (ctx, args) =>
842
+ Effect.gen(function* () {
843
+ const ragService = yield* RAGService
844
+ const agentService = yield* AgentService
845
+
846
+ // Fetch relevant context
847
+ const searchResults = yield* ragService.search(
848
+ ctx,
849
+ args.userId, // User-specific namespace
850
+ args.question,
851
+ 8
852
+ )
853
+
854
+ // Generate answer with context
855
+ const answer = yield* agentService.generateWithContext(
856
+ ctx,
857
+ args.question,
858
+ searchResults.text
859
+ )
860
+
861
+ return {
862
+ answer,
863
+ sources: searchResults.entries.map(e => ({
864
+ id: e.entryId,
865
+ title: e.title,
866
+ relevance: e.score
867
+ }))
868
+ }
869
+ }).pipe(
870
+ Effect.provide(Layer.merge(RAGServiceLive, AgentServiceLive)),
871
+ Effect.catchAll((error) => {
872
+ console.error("Contextual answer failed:", error)
873
+ return Effect.succeed({
874
+ answer: "I'm having trouble finding relevant information.",
875
+ sources: [],
876
+ error: true
877
+ })
878
+ })
879
+ )
880
+ })
881
+ ```
882
+
883
+ ---
884
+
885
+ ### 8. @convex-dev/crons with Effect
886
+
887
+ **Where Effect Adds Value**: Scheduled job logic composition, error handling in cron jobs, service orchestration.
888
+
889
+ **Where to Use Component Directly**: Dynamic cron registration, schedule management.
890
+
891
+ #### Pattern: Effect-Based Cron Job Logic
892
+
893
+ ```typescript
894
+ import { Crons } from "@convex-dev/crons"
895
+ import { Effect } from "effect"
896
+
897
+ // Register cron that executes Effect-based business logic
898
+ export const setupDailyCron = internalMutation({
899
+ handler: async (ctx) => {
900
+ const crons = new Crons(components.crons)
901
+
902
+ await crons.register(
903
+ ctx,
904
+ { kind: "cron", cronspec: "0 0 * * *" }, // Daily at midnight
905
+ internal.crons.dailyMaintenanceWithEffect,
906
+ {},
907
+ "daily-maintenance"
908
+ )
909
+ }
910
+ })
911
+
912
+ // Cron job uses Effect for composition
913
+ export const dailyMaintenanceWithEffect = internalAction({
914
+ handler: async (ctx) => {
915
+ const program = Effect.gen(function* () {
916
+ const ragService = yield* RAGService
917
+ const monitoringService = yield* MonitoringService
918
+
919
+ // Clean up old content
920
+ yield* Effect.tryPromise({
921
+ try: () => ctx.runMutation(internal.rag.cleanupOldContent, {}),
922
+ catch: () => new CleanupError()
923
+ })
924
+
925
+ // Generate daily report
926
+ const report = yield* monitoringService.generateDailyReport(ctx)
927
+
928
+ // Send to admin
929
+ yield* Effect.tryPromise({
930
+ try: () => ctx.runAction(internal.email.sendReport, { report }),
931
+ catch: () => new EmailError()
932
+ })
933
+
934
+ return { success: true, report }
935
+ })
936
+
937
+ await Effect.runPromise(
938
+ program.pipe(
939
+ Effect.provide(Layer.merge(RAGServiceLive, MonitoringServiceLive)),
940
+ Effect.catchAll((error) => {
941
+ console.error("Daily maintenance failed:", error)
942
+ return Effect.succeed({ success: false, error })
943
+ })
944
+ )
945
+ )
946
+ }
947
+ })
948
+ ```
949
+
950
+ ---
951
+
952
+ ## Confect Integration: Full Effect.ts Integration for Convex
953
+
954
+ **Confect** (by rjdellecese) provides comprehensive Effect.ts integration with Convex, enabling Effect-native function definitions and database operations.
955
+
956
+ ### When to Use Confect
957
+
958
+ **Use Confect if:**
959
+
960
+ - Your team is already invested in Effect.ts patterns
961
+ - You want Effect schemas instead of Convex validators
962
+ - You need deep Effect integration throughout your codebase
963
+ - You want `Option<A>` instead of `A | null` everywhere
964
+ - You're building a new project from scratch
965
+
966
+ **Use manual Effect integration (patterns above) if:**
967
+
968
+ - You have an existing Convex project
969
+ - You want to adopt Effect gradually
970
+ - Your team is learning Effect.ts
971
+ - You need to maintain compatibility with existing Convex patterns
972
+
973
+ ### Confect Architecture
974
+
975
+ ```typescript
976
+ // convex/schema.ts - Define schema with Effect Schema
977
+ import { Id, defineSchema, defineTable } from "@rjdellecese/confect/server"
978
+ import { Schema } from "effect"
979
+
980
+ export const confectSchema = defineSchema({
981
+ users: defineTable(
982
+ Schema.Struct({
983
+ username: Schema.String,
984
+ email: Schema.String.pipe(Schema.maxLength(100)),
985
+ role: Schema.Literal("admin", "user")
986
+ })
987
+ ),
988
+
989
+ threads: defineTable(
990
+ Schema.Struct({
991
+ userId: Id.Id("users"),
992
+ title: Schema.String,
993
+ messages: Schema.Array(
994
+ Schema.Struct({
995
+ role: Schema.Literal("user", "assistant"),
996
+ content: Schema.String
997
+ })
998
+ )
999
+ })
1000
+ ).index("by_user", ["userId"])
1001
+ })
1002
+
1003
+ export default confectSchema.convexSchemaDefinition
1004
+ ```
1005
+
1006
+ ```typescript
1007
+ // convex/confect.ts - Generate function constructors
1008
+ import {
1009
+ ConfectActionCtx as ConfectActionCtxService,
1010
+ type ConfectActionCtx as ConfectActionCtxType,
1011
+ ConfectMutationCtx as ConfectMutationCtxService,
1012
+ type ConfectMutationCtx as ConfectMutationCtxType,
1013
+ ConfectQueryCtx as ConfectQueryCtxService,
1014
+ type ConfectQueryCtx as ConfectQueryCtxType,
1015
+ makeFunctions
1016
+ } from "@rjdellecese/confect/server"
1017
+
1018
+ import { confectSchema } from "./schema"
1019
+
1020
+ export const { query, mutation, action, internalQuery, internalMutation, internalAction } =
1021
+ makeFunctions(confectSchema)
1022
+
1023
+ type ConfectDataModel = ConfectDataModelFromConfectSchemaDefinition<typeof confectSchema>
1024
+
1025
+ export const ConfectQueryCtx = ConfectQueryCtxService<ConfectDataModel>()
1026
+ export type ConfectQueryCtx = ConfectQueryCtxType<ConfectDataModel>
1027
+
1028
+ export const ConfectMutationCtx = ConfectMutationCtxService<ConfectDataModel>()
1029
+ export type ConfectMutationCtx = ConfectMutationCtxType<ConfectDataModel>
1030
+
1031
+ export const ConfectActionCtx = ConfectActionCtxService<ConfectDataModel>()
1032
+ export type ConfectActionCtx = ConfectActionCtxType<ConfectDataModel>
1033
+ ```
1034
+
1035
+ ```typescript
1036
+ // convex/users.ts - Write functions with Effect
1037
+ import { Effect, Option } from "effect"
1038
+ import { ConfectMutationCtx, ConfectQueryCtx, mutation, query } from "./confect"
1039
+ import { Schema } from "effect"
1040
+
1041
+ // Define args and returns with Effect Schema
1042
+ const CreateUserArgs = Schema.Struct({
1043
+ username: Schema.String,
1044
+ email: Schema.String
1045
+ })
1046
+
1047
+ const CreateUserResult = Schema.Struct({
1048
+ userId: Schema.String
1049
+ })
1050
+
1051
+ export const createUser = mutation({
1052
+ args: CreateUserArgs,
1053
+ returns: CreateUserResult,
1054
+ handler: ({ username, email }) =>
1055
+ Effect.gen(function* () {
1056
+ // Inject Convex context via Effect
1057
+ const { db } = yield* ConfectMutationCtx
1058
+
1059
+ // Database operations return Effects, not Promises
1060
+ const existing = yield* db
1061
+ .query("users")
1062
+ .withIndex("by_username", q => q.eq("username", username))
1063
+ .first()
1064
+
1065
+ // Option<Doc<"users">> instead of Doc<"users"> | null
1066
+ if (Option.isSome(existing)) {
1067
+ return yield* Effect.fail(new UserAlreadyExistsError({ username }))
1068
+ }
1069
+
1070
+ const userId = yield* db.insert("users", { username, email, role: "user" })
1071
+
1072
+ return { userId }
1073
+ })
1074
+ })
1075
+ ```
1076
+
1077
+ ### Confect + Convex Components Pattern
1078
+
1079
+ ```typescript
1080
+ // Combine Confect with Convex components using custom services
1081
+ import { Effect, Context, Layer } from "effect"
1082
+ import { Agent } from "@convex-dev/agent"
1083
+
1084
+ class ConvexAgentService extends Context.Tag("ConvexAgentService")<
1085
+ ConvexAgentService,
1086
+ {
1087
+ readonly createThread: (
1088
+ ctx: ConfectActionCtx,
1089
+ userId: string
1090
+ ) => Effect.Effect<string, AgentError>
1091
+ }
1092
+ >() {}
1093
+
1094
+ const ConvexAgentServiceLive = Layer.effect(
1095
+ ConvexAgentService,
1096
+ Effect.gen(function* () {
1097
+ const agent = new Agent(components.agent, {
1098
+ chat: openai.chat("gpt-4o"),
1099
+ instructions: "You are a helpful assistant."
1100
+ })
1101
+
1102
+ return {
1103
+ createThread: (ctx, userId) =>
1104
+ Effect.gen(function* () {
1105
+ // Convert ConfectActionCtx to native Convex context
1106
+ const nativeCtx = ctx // Confect provides compatible context
1107
+
1108
+ const result = yield* Effect.tryPromise({
1109
+ try: async () => {
1110
+ const { threadId } = await agent.createThread(nativeCtx, { userId })
1111
+ return threadId
1112
+ },
1113
+ catch: (error) => new AgentError({ cause: error })
1114
+ })
1115
+
1116
+ return result
1117
+ })
1118
+ }
1119
+ })
1120
+ )
1121
+
1122
+ // Confect action using agent service
1123
+ export const createAgentThread = action({
1124
+ args: CreateThreadArgs,
1125
+ returns: CreateThreadResult,
1126
+ handler: ({ userId }) =>
1127
+ Effect.gen(function* () {
1128
+ const agentService = yield* ConvexAgentService
1129
+ const threadId = yield* agentService.createThread(/* ... */, userId)
1130
+ return { threadId }
1131
+ }).pipe(
1132
+ Effect.provide(ConvexAgentServiceLive)
1133
+ )
1134
+ })
1135
+ ```
1136
+
1137
+ ---
1138
+
1139
+ ## Complete Production Architecture
1140
+
1141
+ ### Recommended Service Layer Structure
1142
+
1143
+ ```
1144
+ convex/
1145
+ ├── schema.ts # Database schema
1146
+ ├── confect.ts # Confect setup (if using)
1147
+ │
1148
+ ├── services/
1149
+ │ ├── agent.service.ts # AgentService layer
1150
+ │ ├── rag.service.ts # RAGService layer
1151
+ │ ├── rate-limit.service.ts # RateLimitService layer
1152
+ │ ├── workflow.service.ts # WorkflowService layer
1153
+ │ └── layers.ts # Combined layers
1154
+ │
1155
+ ├── domain/
1156
+ │ ├── users/
1157
+ │ │ ├── types.ts # Domain types
1158
+ │ │ ├── errors.ts # Domain errors
1159
+ │ │ └── logic.ts # Business logic (Effect)
1160
+ │ │
1161
+ │ └── agents/
1162
+ │ ├── types.ts
1163
+ │ ├── errors.ts
1164
+ │ └── orchestration.ts # Multi-agent logic
1165
+ │
1166
+ └── api/
1167
+ ├── users.ts # User queries/mutations
1168
+ ├── agents.ts # Agent endpoints
1169
+ └── workflows.ts # Workflow triggers
1170
+ ```
1171
+
1172
+ ### Complete Example: Customer Support Agent System
1173
+
1174
+ ```typescript
1175
+ // convex/services/agent.service.ts
1176
+ import { Effect, Context, Layer } from "effect"
1177
+ import { Agent } from "@convex-dev/agent"
1178
+ import { openai } from "@ai-sdk/openai"
1179
+
1180
+ class SupportAgentService extends Context.Tag("SupportAgentService")<
1181
+ SupportAgentService,
1182
+ {
1183
+ readonly createSupportThread: (
1184
+ ctx: ActionCtx,
1185
+ userId: string,
1186
+ issue: string
1187
+ ) => Effect.Effect<ThreadResult, AgentError>
1188
+
1189
+ readonly continueSupportThread: (
1190
+ ctx: ActionCtx,
1191
+ threadId: string,
1192
+ message: string
1193
+ ) => Effect.Effect<AgentResponse, AgentError>
1194
+ }
1195
+ >() {}
1196
+
1197
+ const SupportAgentServiceLive = Layer.effect(
1198
+ SupportAgentService,
1199
+ Effect.gen(function* () {
1200
+ const ragService = yield* RAGService
1201
+ const rateLimitService = yield* RateLimitService
1202
+
1203
+ const agent = new Agent(components.agent, {
1204
+ name: "Support Agent",
1205
+ chat: openai.chat("gpt-4o-mini"),
1206
+ textEmbedding: openai.embedding("text-embedding-3-small"),
1207
+ instructions: "You are a helpful customer support agent.",
1208
+ tools: {
1209
+ searchKnowledgeBase: createTool({
1210
+ description: "Search the knowledge base for relevant articles",
1211
+ args: z.object({ query: z.string() }),
1212
+ handler: async (toolCtx, { query }) => {
1213
+ const program = ragService.search(/* ... */, query)
1214
+ return await Effect.runPromise(program)
1215
+ }
1216
+ })
1217
+ },
1218
+ usageHandler: async (ctx, args) => {
1219
+ await ctx.runMutation(internal.billing.trackUsage, args)
1220
+ }
1221
+ })
1222
+
1223
+ return {
1224
+ createSupportThread: (ctx, userId, issue) =>
1225
+ Effect.gen(function* () {
1226
+ // Check rate limit
1227
+ const rateLimitOk = yield* rateLimitService.checkUserLimit(ctx, userId)
1228
+ if (!rateLimitOk) {
1229
+ return yield* Effect.fail(new RateLimitError())
1230
+ }
1231
+
1232
+ // Fetch user context
1233
+ const userContext = yield* Effect.tryPromise({
1234
+ try: () => ctx.runQuery(api.users.getContext, { userId }),
1235
+ catch: () => new ContextFetchError()
1236
+ })
1237
+
1238
+ // Create thread
1239
+ const result = yield* Effect.tryPromise({
1240
+ try: async () => {
1241
+ const { threadId, thread } = await agent.createThread(ctx, { userId })
1242
+ const response = await thread.generateText({
1243
+ prompt: `User issue: ${issue}\n\nUser context: ${JSON.stringify(userContext)}`
1244
+ })
1245
+ return { threadId, text: response.text }
1246
+ },
1247
+ catch: (error) => new AgentError({ cause: error })
1248
+ })
1249
+
1250
+ return result
1251
+ }),
1252
+
1253
+ continueSupportThread: (ctx, threadId, message) =>
1254
+ Effect.gen(function* () {
1255
+ const result = yield* Effect.tryPromise({
1256
+ try: async () => {
1257
+ const { thread } = await agent.continueThread(ctx, { threadId })
1258
+ const response = await thread.generateText({ prompt: message })
1259
+ return { text: response.text, usage: response.usage }
1260
+ },
1261
+ catch: (error) => new AgentError({ cause: error })
1262
+ })
1263
+
1264
+ return result
1265
+ })
1266
+ }
1267
+ })
1268
+ )
1269
+
1270
+ // convex/api/support.ts
1271
+ export const createSupportTicket = action({
1272
+ args: { userId: v.string(), issue: v.string() },
1273
+ handler: (ctx, args) =>
1274
+ Effect.gen(function* () {
1275
+ const supportAgent = yield* SupportAgentService
1276
+
1277
+ // Create thread with agent
1278
+ const threadResult = yield* supportAgent.createSupportThread(
1279
+ ctx,
1280
+ args.userId,
1281
+ args.issue
1282
+ )
1283
+
1284
+ // Save to database
1285
+ yield* Effect.tryPromise({
1286
+ try: () => ctx.runMutation(internal.tickets.create, {
1287
+ userId: args.userId,
1288
+ threadId: threadResult.threadId,
1289
+ initialResponse: threadResult.text
1290
+ }),
1291
+ catch: () => new DatabaseError()
1292
+ })
1293
+
1294
+ return threadResult
1295
+ }).pipe(
1296
+ Effect.provide(Layer.merge(
1297
+ SupportAgentServiceLive,
1298
+ RAGServiceLive,
1299
+ RateLimitServiceLive
1300
+ )),
1301
+ Effect.catchAll((error) => {
1302
+ console.error("Support ticket creation failed:", error)
1303
+ return Effect.succeed({
1304
+ error: true,
1305
+ message: "Failed to create support ticket. Please try again."
1306
+ })
1307
+ }),
1308
+ Effect.runPromise
1309
+ )
1310
+ })
1311
+ ```
1312
+
1313
+ ### Multi-Agent Research System
1314
+
1315
+ ```typescript
1316
+ // convex/domain/agents/research-orchestration.ts
1317
+ export const researchWorkflow = workflow.define({
1318
+ args: { query: v.string(), userId: v.string() },
1319
+ handler: async (step, args): Promise<ResearchResult> => {
1320
+ // Step 1: Classify query type
1321
+ const classification = await step.runAction(
1322
+ internal.research.classifyQueryWithEffect,
1323
+ { query: args.query }
1324
+ )
1325
+
1326
+ // Step 2: Parallel research with multiple agents
1327
+ const [webResults, academicResults, newsResults] = await Promise.all([
1328
+ step.runAction(internal.research.webSearchAgent, { query: args.query }),
1329
+ step.runAction(internal.research.academicAgent, { query: args.query }),
1330
+ step.runAction(internal.research.newsAgent, { query: args.query })
1331
+ ])
1332
+
1333
+ // Step 3: Synthesize findings
1334
+ const synthesis = await step.runAction(
1335
+ internal.research.synthesisAgentWithEffect,
1336
+ {
1337
+ query: args.query,
1338
+ webResults,
1339
+ academicResults,
1340
+ newsResults
1341
+ }
1342
+ )
1343
+
1344
+ // Step 4: Generate final report
1345
+ const report = await step.runAction(
1346
+ internal.research.reportGeneratorWithEffect,
1347
+ { synthesis, classification }
1348
+ )
1349
+
1350
+ // Step 5: Save and notify
1351
+ await step.runMutation(internal.research.saveReport, {
1352
+ userId: args.userId,
1353
+ query: args.query,
1354
+ report
1355
+ })
1356
+
1357
+ return report
1358
+ }
1359
+ })
1360
+
1361
+ export const synthesisAgentWithEffect = internalAction({
1362
+ args: { /* ... */ },
1363
+ handler: async (ctx, args) => {
1364
+ const program = Effect.gen(function* () {
1365
+ const agentService = yield* AgentService
1366
+ const ragService = yield* RAGService
1367
+
1368
+ // Fetch relevant background context
1369
+ const background = yield* ragService.search(ctx, "global", args.query, 5)
1370
+
1371
+ // Synthesize with agent
1372
+ const synthesis = yield* agentService.generateResponse(
1373
+ ctx,
1374
+ `Synthesize these research findings:\n\n${formatResults(args)}\n\nBackground: ${background.text}`
1375
+ )
1376
+
1377
+ return synthesis
1378
+ })
1379
+
1380
+ return await Effect.runPromise(
1381
+ program.pipe(
1382
+ Effect.provide(Layer.merge(AgentServiceLive, RAGServiceLive)),
1383
+ Effect.retry(
1384
+ Schedule.exponential("1 second").pipe(
1385
+ Schedule.compose(Schedule.recurs(3))
1386
+ )
1387
+ )
1388
+ )
1389
+ )
1390
+ }
1391
+ })
1392
+ ```
1393
+
1394
+ ---
1395
+
1396
+ ## Production Patterns Summary
1397
+
1398
+ ### Error Handling
1399
+
1400
+ **Pattern: Layered Error Handling**
1401
+
1402
+ ```typescript
1403
+ // Domain errors (typed)
1404
+ class UserNotFoundError extends Data.TaggedError("UserNotFoundError")<{
1405
+ userId: string
1406
+ }> {}
1407
+
1408
+ // Infrastructure errors (typed)
1409
+ class AgentError extends Data.TaggedError("AgentError")<{
1410
+ agentName: string
1411
+ cause: unknown
1412
+ }> {}
1413
+
1414
+ // Handle at appropriate layer
1415
+ Effect.gen(function* () {
1416
+ const result = yield* agentService.generateResponse(/* ... */)
1417
+ return result
1418
+ }).pipe(
1419
+ // Handle domain errors specifically
1420
+ Effect.catchTag("UserNotFoundError", (error) =>
1421
+ Effect.succeed({ error: "User not found" })
1422
+ ),
1423
+ // Handle infrastructure errors with retry
1424
+ Effect.catchTag("AgentError", (error) =>
1425
+ Effect.retry(
1426
+ Effect.fail(error),
1427
+ Schedule.exponential("1 second").pipe(Schedule.recurs(2))
1428
+ )
1429
+ ),
1430
+ // Catch-all for unexpected errors
1431
+ Effect.catchAll((error) => {
1432
+ console.error("Unexpected error:", error)
1433
+ return Effect.succeed({ error: "Something went wrong" })
1434
+ })
1435
+ )
1436
+ ```
1437
+
1438
+ ### Monitoring and Observability
1439
+
1440
+ **Pattern: Usage Tracking with Effect**
1441
+
1442
+ ```typescript
1443
+ class MonitoringService extends Context.Tag("MonitoringService")<
1444
+ MonitoringService,
1445
+ {
1446
+ readonly trackAgentUsage: (data: UsageData) => Effect.Effect<void>
1447
+ readonly trackError: (error: unknown) => Effect.Effect<void>
1448
+ }
1449
+ >() {}
1450
+
1451
+ const MonitoringServiceLive = Layer.succeed(MonitoringService, {
1452
+ trackAgentUsage: (data) =>
1453
+ Effect.sync(() => {
1454
+ console.log("Agent usage:", data)
1455
+ // Send to analytics service
1456
+ }),
1457
+
1458
+ trackError: (error) =>
1459
+ Effect.sync(() => {
1460
+ console.error("Error tracked:", error)
1461
+ // Send to error tracking service
1462
+ })
1463
+ })
1464
+
1465
+ // Wrap service calls with monitoring
1466
+ const monitoredAgentCall = (
1467
+ agentService: AgentService,
1468
+ ctx: ActionCtx,
1469
+ prompt: string
1470
+ ) =>
1471
+ Effect.gen(function* () {
1472
+ const monitoring = yield* MonitoringService
1473
+
1474
+ const startTime = Date.now()
1475
+
1476
+ const result = yield* agentService.generateResponse(ctx, prompt).pipe(
1477
+ Effect.tap((response) =>
1478
+ monitoring.trackAgentUsage({
1479
+ duration: Date.now() - startTime,
1480
+ tokenCount: response.usage.totalTokens,
1481
+ model: "gpt-4o-mini"
1482
+ })
1483
+ ),
1484
+ Effect.tapError((error) =>
1485
+ monitoring.trackError(error)
1486
+ )
1487
+ )
1488
+
1489
+ return result
1490
+ })
1491
+ ```
1492
+
1493
+ ### Testing Strategies
1494
+
1495
+ **Pattern: Test Layers for Components**
1496
+
1497
+ ```typescript
1498
+ // Test implementation of AgentService
1499
+ const TestAgentServiceLive = Layer.succeed(AgentService, {
1500
+ generateResponse: (ctx, prompt) =>
1501
+ Effect.succeed({
1502
+ text: "Mock response",
1503
+ usage: { totalTokens: 100, promptTokens: 50, completionTokens: 50 }
1504
+ }),
1505
+
1506
+ createThread: (ctx, userId) =>
1507
+ Effect.succeed({ threadId: "test-thread-id" })
1508
+ })
1509
+
1510
+ // Test with mock
1511
+ describe("Support Agent", () => {
1512
+ it("should create support ticket", async () => {
1513
+ const program = createSupportTicket({ userId: "123", issue: "Help!" })
1514
+
1515
+ const result = await Effect.runPromise(
1516
+ program.pipe(
1517
+ Effect.provide(Layer.merge(
1518
+ TestAgentServiceLive,
1519
+ TestRAGServiceLive,
1520
+ TestRateLimitServiceLive
1521
+ ))
1522
+ )
1523
+ )
1524
+
1525
+ expect(result.threadId).toBe("test-thread-id")
1526
+ })
1527
+ })
1528
+ ```
1529
+
1530
+ ### Resource Management
1531
+
1532
+ **Pattern: Scoped Resources with Components**
1533
+
1534
+ ```typescript
1535
+ // Use Effect.Scope for resource lifecycle
1536
+ const withAgentPool = <A, E>(
1537
+ program: Effect.Effect<A, E, AgentService>
1538
+ ): Effect.Effect<A, E> =>
1539
+ Effect.scoped(
1540
+ Effect.gen(function* () {
1541
+ // Acquire agents
1542
+ const agentPool = yield* Effect.acquireRelease(
1543
+ Effect.sync(() => createAgentPool(10)),
1544
+ (pool) => Effect.sync(() => pool.shutdown())
1545
+ )
1546
+
1547
+ // Provide service
1548
+ const service = yield* AgentService
1549
+
1550
+ // Run program
1551
+ return yield* program
1552
+ })
1553
+ )
1554
+ ```
1555
+
1556
+ ### Performance Optimization
1557
+
1558
+ **Pattern: Parallel Execution with Concurrency Control**
1559
+
1560
+ ```typescript
1561
+ // Process multiple items with controlled parallelism
1562
+ export const processBatchWithEffect = action({
1563
+ args: { items: v.array(v.any()) },
1564
+ handler: (ctx, args) =>
1565
+ Effect.gen(function* () {
1566
+ const results = yield* Effect.all(
1567
+ args.items.map(item =>
1568
+ processItemWithEffect(ctx, item)
1569
+ ),
1570
+ {
1571
+ concurrency: 5, // Limit concurrent operations
1572
+ mode: "default" // Fail fast on first error
1573
+ }
1574
+ )
1575
+
1576
+ return { results, count: results.length }
1577
+ }).pipe(
1578
+ Effect.provide(/* ... */),
1579
+ Effect.runPromise
1580
+ )
1581
+ })
1582
+ ```
1583
+
1584
+ ---
1585
+
1586
+ ## Key Recommendations for ONE Network
1587
+
1588
+ ### Architecture Decisions
1589
+
1590
+ 1. **Start with Manual Effect Integration**: Don't adopt Confect initially. Use the wrapper patterns shown above to integrate Effect gradually.
1591
+
1592
+ 2. **Use Components for Infrastructure**: Let Convex components handle durability, retries, and rate limiting. Use Effect for business logic.
1593
+
1594
+ 3. **Service Layer with Effect**: Build a service layer using Effect's Context and Layer patterns for testability and composition.
1595
+
1596
+ 4. **Agent Component + Workflow**: Use @convex-dev/agent for AI capabilities and @convex-dev/workflow for long-running operations.
1597
+
1598
+ 5. **RAG with Effect Services**: Wrap @convex-dev/rag in an Effect service for composable context retrieval.
1599
+
1600
+
1601
+ ### Astro Integration
1602
+
1603
+ ```typescript
1604
+ // src/lib/convex-provider.tsx
1605
+ import { ConvexReactClient, ConvexProvider } from "convex/react"
1606
+ import { type FunctionComponent } from "react"
1607
+
1608
+ const convexClient = new ConvexReactClient(import.meta.env.PUBLIC_CONVEX_URL)
1609
+
1610
+ export function withConvexProvider<Props>(
1611
+ Component: FunctionComponent<Props>
1612
+ ) {
1613
+ return function WithConvexProvider(props: Props) {
1614
+ return (
1615
+ <ConvexProvider client={convexClient}>
1616
+ <Component {...props} />
1617
+ </ConvexProvider>
1618
+ )
1619
+ }
1620
+ }
1621
+
1622
+ // Use in components
1623
+ export default withConvexProvider(function ChatInterface() {
1624
+ const messages = useQuery(api.chat.listMessages, { threadId })
1625
+ const sendMessage = useMutation(api.chat.sendMessage)
1626
+
1627
+ // Your UI code
1628
+ })
1629
+ ```
1630
+
1631
+ ### Deployment
1632
+
1633
+ 1. **Convex Deploy**: `npx convex deploy` for backend
1634
+ 2. **Vercel**: Use Vercel for Astro frontend with automatic Convex integration
1635
+ 3. **Environment Variables**: Manage through Convex Dashboard
1636
+ 4. **Monitoring**: Use Convex Dashboard + custom monitoring service
1637
+
1638
+ ---
1639
+
1640
+ ## Conclusion
1641
+
1642
+ Effect.ts and Confect enhance Convex's already powerful platform for building AI agents:
1643
+
1644
+ **Effect.ts provides**:
1645
+
1646
+ - Type-safe error handling
1647
+ - Powerful composition primitives
1648
+ - Dependency injection
1649
+ - Resource management
1650
+ - Testability
1651
+
1652
+ **Convex components provide**:
1653
+
1654
+ - Durable workflows
1655
+ - Rate limiting
1656
+ - Retries with backoff
1657
+ - Vector search (RAG)
1658
+ - Real-time streaming
1659
+ - Transactional guarantees
1660
+
1661
+ **Together they enable**:
1662
+
1663
+ - Production-ready AI agent systems
1664
+ - Type-safe, testable business logic
1665
+ - Reliable long-running workflows
1666
+ - Sophisticated error recovery
1667
+ - Composable multi-agent orchestration
1668
+
1669
+ Start by wrapping components with Effect services for key business logic, then gradually expand Effect usage as your team becomes comfortable with the patterns. The combination provides an excellent foundation for building sophisticated AI agents at scale.