oneie 3.6.12 → 3.6.14
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.
- package/.claude/agents/AUDIT-agent-ops-alignment.md +379 -0
- package/.claude/agents/NEWS-QUICKSTART.md +321 -0
- package/.claude/agents/NEWS-README.md +353 -0
- package/.claude/agents/agent-backend.md +1 -1
- package/.claude/agents/agent-builder.md +220 -151
- package/.claude/agents/agent-clean.md +39 -31
- package/.claude/agents/agent-clone.md +107 -54
- package/.claude/agents/agent-designer.md +76 -71
- package/.claude/agents/agent-director.md +164 -1
- package/.claude/agents/agent-documenter.md +169 -132
- package/.claude/agents/agent-frontend.md +442 -446
- package/.claude/agents/agent-integrator.md +30 -23
- package/.claude/agents/agent-lawyer.md +145 -98
- package/.claude/agents/agent-news.md +363 -0
- package/.claude/agents/agent-onboard.md +99 -69
- package/.claude/agents/agent-ontology.md +585 -0
- package/.claude/agents/agent-ops.md +178 -171
- package/.claude/agents/agent-problem-solver.md +132 -115
- package/.claude/agents/agent-quality.md +94 -77
- package/.claude/agents/agent-sales.md +89 -67
- package/.claude/commands/release.md +3 -1
- package/.claude/commands/server.md +64 -5
- package/.claude/hooks/README-knowledge-hooks.md +266 -80
- package/.claude/hooks/README-root-cleanup.md +200 -0
- package/.claude/hooks/README.md +284 -0
- package/.claude/hooks/__pycache__/done.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
- package/.claude/hooks/check-filenames.py +169 -32
- package/.claude/hooks/clean-post.py +195 -28
- package/.claude/hooks/clean-pre.py +96 -11
- package/.claude/hooks/done.py +74 -13
- package/.claude/hooks/format-hook.sh +105 -17
- package/.claude/hooks/hook-logger.sh +121 -7
- package/.claude/hooks/knowledge-post.py +136 -32
- package/.claude/hooks/knowledge-pre.py +129 -34
- package/.claude/hooks/notification-hook.sh +184 -17
- package/.claude/hooks/root-cleanup.py +181 -39
- package/.claude/hooks/security-hook.sh +248 -8
- package/.claude/hooks/tag-all-docs.py +175 -49
- package/.claude/hooks/test-validate-ontology.sh +170 -0
- package/.claude/hooks/todo.py +92 -22
- package/.claude/hooks/validate-ontology-structure-summary.md +243 -0
- package/.claude/hooks/validate-ontology-structure.py +83 -20
- package/AGENTS.md +60 -245
- package/CLAUDE.md +70 -1
- package/README.md +25 -0
- package/folders.yaml +1 -1
- package/one/.claude/settings.local.json +11 -0
- package/one/.obsidian/community-plugins.json +3 -1
- package/one/.obsidian/plugins/editing-toolbar/data.json +328 -0
- package/one/.obsidian/plugins/editing-toolbar/main.js +12 -0
- package/one/.obsidian/plugins/editing-toolbar/manifest.json +10 -0
- package/one/.obsidian/plugins/editing-toolbar/styles.css +1338 -0
- package/one/.obsidian/plugins/terminal/data.json +154 -0
- package/one/.obsidian/plugins/terminal/main.js +197 -0
- package/one/.obsidian/plugins/terminal/manifest.json +14 -0
- package/one/.obsidian/plugins/terminal/styles.css +32 -0
- package/one/.obsidian/workspace.json +71 -45
- package/one/README.md +18 -0
- package/one/connections/a2a.md +49 -0
- package/one/connections/acp.md +47 -0
- package/one/connections/acps.md +18 -0
- package/one/connections/agentkit.md +18 -0
- package/one/connections/agui.md +18 -0
- package/one/connections/any-backend.md +39 -21
- package/one/connections/ap2.md +74 -0
- package/one/connections/api/queries-reference.md +18 -0
- package/one/connections/api-docs.md +18 -0
- package/one/connections/api-reference.md +18 -0
- package/one/connections/api.md +18 -0
- package/one/connections/architecture-diagram.md +18 -0
- package/one/connections/communications.md +18 -0
- package/one/connections/connections.md +18 -0
- package/one/connections/copilotkit.md +18 -0
- package/one/connections/cryptonetworks.md +18 -0
- package/one/connections/documentation.md +18 -0
- package/one/connections/effect.md +18 -0
- package/one/connections/elizaos.md +18 -0
- package/one/connections/groups.md +814 -0
- package/one/connections/inference.md +18 -0
- package/one/connections/integration-examples.md +18 -0
- package/one/connections/integration-guide.md +18 -0
- package/one/connections/integration-phase2.md +32 -14
- package/one/connections/kyc.md +18 -0
- package/one/connections/mcp.md +18 -0
- package/one/connections/membership.md +18 -0
- package/one/connections/middleware.md +18 -0
- package/one/connections/multitenant.md +18 -0
- package/one/connections/n8n.md +18 -0
- package/one/connections/patterns.md +18 -0
- package/one/connections/protocols.md +20 -2
- package/one/connections/relationships.md +18 -0
- package/one/connections/schema.md +18 -0
- package/one/connections/service-layer.md +18 -0
- package/one/connections/vectors.md +18 -0
- package/one/connections/wordpress.md +18 -0
- package/one/connections/workflow-copy.md +18 -0
- package/one/connections/workflow-examples.md +18 -0
- package/one/connections/workflow-onboarding.md +18 -0
- package/one/connections/workflow.md +18 -0
- package/one/connections/workflows/delegation.md +18 -0
- package/one/connections/workflows/frontend.md +18 -0
- package/one/connections/workflows/strategy.md +18 -0
- package/one/connections/workflows/tasks.md +18 -0
- package/one/connections/x402-baazar.md +131 -0
- package/one/connections/x402.md +268 -164
- package/one/events/2024-10-14-deployment-plan.md +15 -16
- package/one/events/2024-10-14-deployment-success.md +15 -16
- package/one/events/2024-10-14-final-sync-complete.md +15 -16
- package/one/events/2024-10-14-release-v2.0.6.md +15 -16
- package/one/events/2024-10-15-agent-clean-v2-summary.md +15 -16
- package/one/events/2024-10-15-handoff-to-clean.md +15 -16
- package/one/events/2024-10-15-package-manager-tests.md +15 -16
- package/one/events/2024-10-15-release-command-complete.md +15 -16
- package/one/events/2025-10-15-private-files-secured.md +18 -0
- package/one/events/2025-10-15-unignore-public-group-docs.md +18 -0
- package/one/events/ALIGNMENT_REPORT_PROBLEM_SOLVER.md +335 -0
- package/one/events/ALIGNMENT_SUMMARY.md +280 -0
- package/one/events/API_ROUTES_FIXES_SUMMARY.md +18 -0
- package/one/events/ASTRO-INTEGRATION-EXAMPLES.md +18 -0
- package/one/events/AUDIT-ONTOLOGY-ALIGNMENT.md +598 -0
- package/one/events/BEFORE_AFTER_COMPARISON.md +18 -0
- package/one/events/CART-DRAWER-INTEGRATION-GUIDE.md +18 -0
- package/one/events/CASCADE-2-BACKEND-AGNOSTIC.md +18 -0
- package/one/events/CLAUDE copy.md +897 -0
- package/one/events/CLEANUP-RELEASE-V2.0.8.md +18 -0
- package/one/events/CONNECTIONS_DEMO.md +18 -0
- package/one/events/CREATE-WEBSITE.md +18 -0
- package/one/events/CRITICAL-FIXES-COMPLETE.md +18 -0
- package/one/events/CUSTOM-DOMAIN.md +18 -0
- package/one/events/DELIVERABLES.md +18 -0
- package/one/events/DEMO-GROUPS-PAGE.md +18 -0
- package/one/events/DEMO-TESTING-SUMMARY.md +18 -0
- package/one/events/DEMO_COMPONENTS.md +18 -0
- package/one/events/DEMO_HOOKS_INDEX.md +18 -0
- package/one/events/DEMO_INFRASTRUCTURE.md +18 -0
- package/one/events/DEMO_INFRASTRUCTURE_SUMMARY.md +18 -0
- package/one/events/DEMO_INTEGRATION_CHECKLIST.md +18 -0
- package/one/events/DEMO_QUICK_REFERENCE.md +18 -0
- package/one/events/DEMO_SETUP.md +18 -0
- package/one/events/DEPLOYMENT copy.md +18 -0
- package/one/events/DEPLOYMENT.md +18 -0
- package/one/events/ECOMMERCE-BEFORE-AFTER.md +16 -0
- package/one/events/ECOMMERCE-DEMO-PLAN.md +18 -0
- package/one/events/ECOMMERCE-ENHANCEMENTS.md +18 -0
- package/one/events/ECOMMERCE-HIGH-CONVERTING-ELEMENTS.md +18 -0
- package/one/events/ECOMMERCE-LIVE-DEMO.md +18 -0
- package/one/events/ECOMMERCE-REFACTOR-SUMMARY.md +18 -0
- package/one/events/ECOMMERCE-SETUP-SUMMARY.md +18 -0
- package/one/events/ECOMMERCE-TEMPLATE-COMPLETE.md +18 -0
- package/one/events/ECOMMERCE-TEMPLATES-SUMMARY.md +18 -0
- package/one/events/EFFECT_TS_API_PATTERN.md +18 -0
- package/one/events/FEATURE-2-4-COMPLETE.md +18 -0
- package/one/events/FEATURE_2_3_COMPLETE.md +18 -0
- package/one/events/GRADIENT-TEXT-PERMANENT-FIX.md +18 -0
- package/one/events/GROUPS-MIGRATION.md +18 -0
- package/one/events/GROUPS_DEMO_IMPLEMENTATION.md +18 -0
- package/one/events/HANDOFF.md +18 -0
- package/one/events/HOOKS-DEMO.md +18 -0
- package/one/events/IMPLEMENTATION-SUMMARY-FINAL.md +18 -0
- package/one/events/IMPLEMENTATION_SUMMARY.md +18 -0
- package/one/events/INSTALL-TESTS.md +18 -0
- package/one/events/INSTALLATION_FOLDERS.md +18 -0
- package/one/events/INSTALLATION_FOLDERS_FILES.md +18 -0
- package/one/events/INSTALLATION_FOLDERS_SUMMARY.md +18 -0
- package/one/events/INTEGRATION-ARCHITECTURE.md +18 -0
- package/one/events/INTEGRATION-CHECKLIST.md +18 -0
- package/one/events/INTEGRATION-ORCHESTRATION.md +18 -0
- package/one/events/INTEGRATION-SUMMARY.md +18 -0
- package/one/events/LANDING-PAGE-EXAMPLE-OUTPUT.md +18 -0
- package/one/events/LANDING-PAGE-IMPLEMENTATION.md +18 -0
- package/one/events/LANDING-PAGE-QUICKSTART.md +18 -0
- package/one/events/LICENSE.md +18 -0
- package/one/events/MCP-CONFIGURATION.md +18 -0
- package/one/events/MCP-SETUP-COMPLETE.md +18 -0
- package/one/events/MIGRATION-REPORT.md +18 -0
- package/one/events/MIGRATION.md +18 -0
- package/one/events/MULTI-ONTOLOGY-COMPLETE-GUIDE.md +18 -0
- package/one/events/MULTI-ONTOLOGY-IMPLEMENTATION-COMPLETE.md +18 -0
- package/one/events/NODE-UPGRADE.md +18 -0
- package/one/events/ONBOARDING-IMPLEMENTATION-COMPLETE copy.md +18 -0
- package/one/events/ONTOLOGY-HOOKS-README.md +18 -0
- package/one/events/ONTOLOGY-INTEGRATION-MANIFEST.md +18 -0
- package/one/events/ONTOLOGY-TUTORIALS-SUMMARY.md +18 -0
- package/one/events/ONTOLOGY-TYPE-GENERATOR-SUMMARY.md +18 -0
- package/one/events/ONTOLOGY_DISCOVERY_IMPLEMENTATION.md +18 -0
- package/one/events/ONTOLOGY_DISCOVERY_QUICKSTART.md +18 -0
- package/one/events/PACKAGE-STRUCTURE.md +18 -0
- package/one/events/PLAYBOOK-SETUP-SUMMARY.md +18 -0
- package/one/events/PROMPT_FIX_FRONTEND_ONLY.md +18 -0
- package/one/events/QA-CHECKLIST.md +18 -0
- package/one/events/QUICK-START-ONTOLOGY.md +18 -0
- package/one/events/README-archived.md +18 -0
- package/one/events/SEARCH_DEMO_CODE_REFERENCE.md +18 -0
- package/one/events/SEARCH_DEMO_DELIVERY.md +18 -0
- package/one/events/SEARCH_DEMO_SUMMARY.md +18 -0
- package/one/events/SEARCH_DEMO_VISUAL_GUIDE.md +18 -0
- package/one/events/SECURITY-AUDIT-FIXES.md +18 -0
- package/one/events/SECURITY-SCAN-COMPLETE.md +18 -0
- package/one/events/SHOP-BUILD-STATUS.md +18 -0
- package/one/events/SHOP-PREMIUM-UPDATE.md +16 -0
- package/one/events/SIMPLE_FIX_FRONTEND_ONLY.md +18 -0
- package/one/events/SITE-WIDE-GRADIENT-FIX.md +18 -0
- package/one/events/STORE-PRODUCTION-READY-STATUS.md +18 -0
- package/one/events/STRIPE-INTEGRATION.md +18 -0
- package/one/events/STRIPE-PAYMENT-METHODS-GUIDE.md +18 -0
- package/one/events/STRIPE-SETUP-GUIDE.md +18 -0
- package/one/events/TEST-PLAN-INDEX.md +18 -0
- package/one/events/TEST-PLAN.md +18 -0
- package/one/events/TEST-SUMMARY.md +18 -0
- package/one/events/TESTS-QUICK-REF.md +18 -0
- package/one/events/TRANSITIONS-QUICK-START.md +18 -0
- package/one/events/TRANSPARENCY-FIXES.md +18 -0
- package/one/events/TYPESCRIPT_FIXES.md +18 -0
- package/one/events/TYPESCRIPT_FIXES_INDEX.md +18 -0
- package/one/events/VIEW-TRANSITIONS.md +18 -0
- package/one/events/agent-director-enhancement-summary.md +18 -0
- package/one/events/agent-onboard-implementation-summary.md +18 -0
- package/one/events/agent-ontology-alignment-completion.md +263 -0
- package/one/events/backend-integration-tests.md +18 -0
- package/one/events/clean-agent-ontology-cleanup-report.md +18 -0
- package/one/events/clean-agent-todo-analysis-summary.md +336 -0
- package/one/events/cloudflare-automation-complete.md +18 -0
- package/one/events/cloudflare-pages-infrastructure-setup.md +18 -0
- package/one/events/contact-page-complete.md +18 -0
- package/one/events/convex-analysis-index.md +18 -0
- package/one/events/convex-structure-analysis.md +18 -0
- package/one/events/deployment-installation-folders.md +18 -0
- package/one/events/deployment-ops-summary.md +18 -0
- package/one/events/deployment-verification.md +18 -0
- package/one/events/design-spec-complete.md +18 -0
- package/one/events/documentation-audit-index.md +473 -0
- package/one/events/documentation-audit-summary.md +417 -0
- package/one/events/documentation-improvement-roadmap.md +906 -0
- package/one/events/documentation-standards-compliance-report.md +538 -0
- package/one/events/events.md +18 -0
- package/one/events/frontend-effects-complete.md +584 -0
- package/one/events/frontend-effects-orchestration.md +1356 -0
- package/one/events/frontend-effects-risk-register.md +1055 -0
- package/one/events/frontend-effects-week1-assignments.md +1594 -0
- package/one/events/hook-ontology-alignment-summary.md +528 -0
- package/one/events/installation-folders-workflow-integration.md +18 -0
- package/one/events/landing-page-generator.md +18 -0
- package/one/events/legal-assessment-2025-10-16.md +18 -0
- package/one/events/onboarding-implementation-complete.md +18 -0
- package/one/events/ontology-test-examples.md +18 -0
- package/one/events/phase1-backend-implementation-complete.md +18 -0
- package/one/events/release.md +18 -0
- package/one/events/root-cleanup-alignment-report.md +265 -0
- package/one/events/separate-implementation-status.md +18 -0
- package/one/events/session-summary-2025-10-18.md +18 -0
- package/one/events/skills-complete.md +18 -0
- package/one/events/skills-infer-6-10-summary.md +18 -0
- package/one/events/skills-phase1-complete.md +18 -0
- package/one/events/structural-analysis-architecture-vs-plans.md +559 -0
- package/one/events/test-dashboard.md +18 -0
- package/one/events/test-index.md +18 -0
- package/one/events/test-report-ontology.md +18 -0
- package/one/events/testing-summary.md +18 -0
- package/one/events/todo-refactoring-complete.md +408 -0
- package/one/events/wave1-backend-implementation-complete.md +698 -0
- package/one/groups/features.md +26 -0
- package/one/groups/groups.md +83 -39
- package/one/groups/one.md +47 -27
- package/one/groups/{strategy copy.md → strategy-copy.md} +23 -5
- package/one/knowledge/.obsidian/ecommerce-ontology.md +18 -0
- package/one/knowledge/100-inference-quick-reference.md +18 -0
- package/one/knowledge/agent-onboard-usage.md +18 -0
- package/one/knowledge/agentic-commerce.md +146 -0
- package/one/knowledge/ai-agents-vs-memecoins-thesis.md +683 -0
- package/one/knowledge/ai-platform.md +18 -0
- package/one/knowledge/ai-token-crypto-analysis-framework.md +1191 -0
- package/one/knowledge/ai-token-paradigm-shift-2025.md +732 -0
- package/one/knowledge/altcoin-cycle-prediction-ontology.md +884 -0
- package/one/knowledge/altcoin-cycle-trading-strategy.md +642 -0
- package/one/knowledge/architecture-any-backend.md +265 -42
- package/one/knowledge/architecture-diagram.md +404 -94
- package/one/knowledge/architecture-frontend.md +130 -51
- package/one/knowledge/architecture.md +1496 -1831
- package/one/knowledge/{ontology.md.backup → archived/ontology.old.md} +18 -0
- package/one/knowledge/astro-effect-complete-vision.md +2148 -0
- package/one/knowledge/astro-effect-simple-architecture.md +717 -0
- package/one/knowledge/audit-agent-onboard-alignment.md +481 -0
- package/one/knowledge/audit-agent-sales-alignment.md +444 -0
- package/one/knowledge/backend-api-reference.md +18 -0
- package/one/knowledge/cli-claude-handoff.md +18 -0
- package/one/knowledge/context-engineering.md +610 -0
- package/one/knowledge/crypto-analysis-strategy.md +1276 -0
- package/one/knowledge/crypto-cycle-2024-2025-analysis.md +44 -0
- package/one/knowledge/crypto.md +18 -0
- package/one/knowledge/docs.md +627 -0
- package/one/knowledge/dsl.md +18 -0
- package/one/knowledge/files.md +18 -0
- package/one/knowledge/frontend.md +18 -0
- package/one/knowledge/hono.md +18 -0
- package/one/knowledge/implementation-examples.md +18 -0
- package/one/knowledge/installation-folders.md +18 -0
- package/one/knowledge/institutional-cycle-paradigm-2025.md +555 -0
- package/one/knowledge/knowledge.md +18 -0
- package/one/knowledge/language.md +18 -0
- package/one/knowledge/lessons-learned.md +18 -0
- package/one/knowledge/lessons-website-building-focus.md +18 -0
- package/one/knowledge/merge-report.md +254 -0
- package/one/knowledge/nine-padel-playbook.md +18 -0
- package/one/knowledge/ontology-blog.yaml +42 -26
- package/one/knowledge/ontology-cheatsheet.md +18 -0
- package/one/knowledge/ontology-community.yaml +60 -37
- package/one/knowledge/ontology-core-universal.md +19 -1
- package/one/knowledge/ontology-core.yaml +58 -45
- package/one/knowledge/ontology-courses.yaml +71 -48
- package/one/knowledge/ontology-creator.md +30 -4
- package/one/knowledge/ontology-crypto.md +1603 -0
- package/one/knowledge/ontology-developer-guide.md +18 -0
- package/one/knowledge/ontology-documentation.md +46 -25
- package/one/knowledge/ontology-ecommerce.md +24 -6
- package/one/knowledge/ontology-education.md +18 -0
- package/one/knowledge/ontology-engineering-specification.md +22 -4
- package/one/knowledge/ontology-engineering.md +67 -43
- package/one/knowledge/ontology-files.yaml +525 -0
- package/one/knowledge/ontology-frontend-master.md +2898 -0
- package/one/knowledge/ontology-frontend-specifications.md +57 -49
- package/one/knowledge/ontology-frontend.md +40 -22
- package/one/knowledge/ontology-index.md +18 -0
- package/one/knowledge/ontology-minimal.yaml +18 -16
- package/one/knowledge/ontology-portfolio.yaml +40 -26
- package/one/knowledge/ontology-quickstart.md +18 -0
- package/one/knowledge/ontology-release.md +317 -0
- package/one/knowledge/ontology-shop.yaml +146 -119
- package/one/knowledge/ontology-tokens.yaml +46 -27
- package/one/knowledge/ontology-tutorial.md +18 -0
- package/one/knowledge/ontology-video-script.md +18 -0
- package/one/knowledge/ontology-visual-guide.md +20 -2
- package/one/knowledge/ontology.md +1329 -304
- package/one/knowledge/ontology.yaml +763 -275
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +48 -18
- package/one/knowledge/patterns/backend/convex-query-pattern.md +78 -23
- package/one/knowledge/patterns/backend/mutation-template.md +28 -10
- package/one/knowledge/patterns/backend/query-template.md +44 -25
- package/one/knowledge/patterns/backend/service-template.md +35 -14
- package/one/knowledge/patterns/design/component-architecture.md +45 -9
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +37 -3
- package/one/knowledge/patterns/design/wireframe-template.md +36 -2
- package/one/knowledge/patterns/frontend/component-template.md +91 -40
- package/one/knowledge/patterns/frontend/form-template.md +131 -59
- package/one/knowledge/patterns/frontend/page-template.md +59 -28
- package/one/knowledge/patterns/frontend/react-component-pattern.md +87 -27
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +28 -10
- package/one/knowledge/patterns/test/technical-test-template.md +48 -26
- package/one/knowledge/patterns/test/test-driven-pattern.md +25 -5
- package/one/knowledge/patterns/test/user-flow-template.md +18 -0
- package/one/knowledge/provider-agnostic-content.md +995 -0
- package/one/knowledge/provider-creation-guide.md +18 -0
- package/one/knowledge/quality-loop.md +18 -0
- package/one/knowledge/readme-architecture.md +158 -0
- package/one/knowledge/readme.md +18 -0
- package/one/knowledge/rules.md +18 -0
- package/one/knowledge/score.md +18 -0
- package/one/knowledge/specifications.md +18 -0
- package/one/knowledge/tags.md +18 -0
- package/one/knowledge/todo-template.md +18 -0
- package/one/knowledge/todo.md +18 -0
- package/one/knowledge/typescript-patterns.md +18 -0
- package/one/knowledge/universal-generation-language.md +827 -0
- package/one/knowledge/x402-research.md +104 -0
- package/one/license.md +18 -0
- package/one/people/anthony-o-connell.md +48 -19
- package/one/people/people.md +54 -31
- package/one/things/ALIGNMENT_AUDIT_QUALITY_AGENT.md +401 -0
- package/one/things/AUDIT_AGENT_INTEGRATOR_ALIGNMENT.md +588 -0
- package/one/things/AUDIT_REPORT_AGENT_CLEAN.md +461 -0
- package/one/things/CHECKLIST.md +51 -0
- package/one/things/IMPLEMENTATION_STATUS.md +379 -0
- package/one/things/ONE.md +19 -1
- package/one/things/agents/agent-backend.md +198 -98
- package/one/things/agents/agent-builder.md +267 -158
- package/one/things/agents/agent-clean.md +40 -15
- package/one/things/agents/agent-clone.md +33 -50
- package/one/things/agents/agent-deploy.md +59 -11
- package/one/things/agents/agent-designer.md +274 -146
- package/one/things/agents/agent-director.md +20 -2
- package/one/things/agents/agent-documenter.md +126 -46
- package/one/things/agents/agent-frontend.md +104 -22
- package/one/things/agents/agent-integrator.md +153 -76
- package/one/things/agents/agent-lawyer.md +197 -92
- package/one/things/agents/agent-problem-solver.md +302 -224
- package/one/things/agents/agent-quality.md +149 -19
- package/one/things/agents/agent-sales.md +95 -7
- package/one/things/cascade/cascade.yaml +20 -3
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +53 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +50 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +76 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +49 -3
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +45 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +32 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +45 -3
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +44 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +40 -1
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +81 -25
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +41 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +91 -16
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +136 -73
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +43 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +88 -4
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +52 -3
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +44 -1
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +78 -14
- package/one/things/cascade/docs/examples/readme.md +37 -0
- package/one/things/cascade/docs/getting-started.md +18 -0
- package/one/things/cascade/docs/workflow.md +18 -12
- package/one/things/cascade/readme.md +43 -0
- package/one/things/cascade/templates/feature-template.md +28 -6
- package/one/things/claude/agents/advocacy-activation-manager.md +64 -39
- package/one/things/claude/agents/advocacy-campaign-designer.md +64 -39
- package/one/things/claude/agents/analyst.md +64 -39
- package/one/things/claude/agents/architect.md +64 -39
- package/one/things/claude/agents/brand-identity-specialist.md +64 -39
- package/one/things/claude/agents/bstp-token-strategist.md +48 -25
- package/one/things/claude/agents/builder-repo.md +69 -26
- package/one/things/claude/agents/bullstamp-community-builder.md +48 -25
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +48 -25
- package/one/things/claude/agents/bulltilt-platform-growth.md +48 -25
- package/one/things/claude/agents/company-bullstamp-character.md +45 -30
- package/one/things/claude/agents/company-bullstamp-community.md +45 -30
- package/one/things/claude/agents/company-bullstamp-marketing.md +45 -30
- package/one/things/claude/agents/company-bullstamp-token.md +45 -30
- package/one/things/claude/agents/company-bulltilt-growth.md +45 -30
- package/one/things/claude/agents/content-bibliography-formatter.md +48 -25
- package/one/things/claude/agents/content-calendar-planner.md +59 -34
- package/one/things/claude/agents/content-chapter-formatter.md +60 -35
- package/one/things/claude/agents/content-formatter.md +59 -34
- package/one/things/claude/agents/content-hook-specialist.md +54 -31
- package/one/things/claude/agents/content-image-formatter.md +59 -34
- package/one/things/claude/agents/content-introduction-formatter.md +59 -34
- package/one/things/claude/agents/content-multiplication-engine.md +54 -31
- package/one/things/claude/agents/content-playbook-writer.md +60 -35
- package/one/things/claude/agents/content-team-manager.md +59 -34
- package/one/things/claude/agents/content-toc-formatter.md +60 -35
- package/one/things/claude/agents/convex-backend-specialist.md +380 -216
- package/one/things/claude/agents/core-manager.md +59 -34
- package/one/things/claude/agents/core-master.md +55 -32
- package/one/things/claude/agents/cross-functional-manager.md +46 -41
- package/one/things/claude/agents/crypto-airdrop-strategist.md +74 -54
- package/one/things/claude/agents/crypto-analytics-educator.md +73 -30
- package/one/things/claude/agents/crypto-architecture-specialist.md +70 -39
- package/one/things/claude/agents/crypto-community-analyst.md +47 -31
- package/one/things/claude/agents/crypto-community-psychologist.md +68 -31
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +72 -31
- package/one/things/claude/agents/crypto-dex-optimizer.md +45 -30
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +69 -30
- package/one/things/claude/agents/crypto-diamond-hands.md +45 -30
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +73 -30
- package/one/things/claude/agents/crypto-engagement-specialist.md +71 -30
- package/one/things/claude/agents/crypto-market-researcher.md +45 -30
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +74 -34
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +75 -30
- package/one/things/claude/agents/crypto-optimization-analyst.md +73 -30
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +69 -30
- package/one/things/claude/agents/crypto-team-manager.md +45 -40
- package/one/things/claude/agents/crypto-token-analyst.md +66 -25
- package/one/things/claude/agents/crypto-viral-content-creator.md +64 -61
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +61 -51
- package/one/things/claude/agents/crypto-wallet-identifier.md +45 -30
- package/one/things/claude/agents/customer-journey-designer.md +51 -58
- package/one/things/claude/agents/customer-success-manager.md +51 -58
- package/one/things/claude/agents/dev.md +51 -58
- package/one/things/claude/agents/documenter.md +71 -69
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +45 -52
- package/one/things/claude/agents/engagement-specialist.md +45 -52
- package/one/things/claude/agents/engineering-architect.md +54 -54
- package/one/things/claude/agents/engineering-business-analyst.md +46 -56
- package/one/things/claude/agents/engineering-developer.md +51 -52
- package/one/things/claude/agents/engineering-director.md +65 -25
- package/one/things/claude/agents/engineering-ingestor.md +110 -100
- package/one/things/claude/agents/engineering-product-manager.md +43 -55
- package/one/things/claude/agents/engineering-product-owner.md +46 -56
- package/one/things/claude/agents/engineering-project-coordinator.md +44 -56
- package/one/things/claude/agents/engineering-quality-assurance.md +53 -54
- package/one/things/claude/agents/engineering-team-manager.md +46 -43
- package/one/things/claude/agents/engineering-user-experience.md +51 -52
- package/one/things/claude/agents/framework-elevate-manager.md +45 -30
- package/one/things/claude/agents/improver.md +120 -78
- package/one/things/claude/agents/intelligence-team-manager.md +45 -40
- package/one/things/claude/agents/lead-capture-expert.md +45 -52
- package/one/things/claude/agents/lead-magnet-creator.md +45 -52
- package/one/things/claude/agents/market-research-analyst.md +48 -25
- package/one/things/claude/agents/marketing-brand-identity.md +57 -27
- package/one/things/claude/agents/marketing-content-hooks.md +45 -40
- package/one/things/claude/agents/marketing-content-multiplier.md +45 -40
- package/one/things/claude/agents/marketing-content-poster.md +71 -60
- package/one/things/claude/agents/marketing-customer-journey.md +45 -40
- package/one/things/claude/agents/marketing-director.md +46 -41
- package/one/things/claude/agents/marketing-engagement.md +45 -40
- package/one/things/claude/agents/marketing-lead-capture.md +45 -40
- package/one/things/claude/agents/marketing-lead-magnet.md +45 -40
- package/one/things/claude/agents/marketing-network-effects.md +45 -40
- package/one/things/claude/agents/marketing-nurture-campaigns.md +45 -40
- package/one/things/claude/agents/marketing-share-optimizer.md +45 -40
- package/one/things/claude/agents/marketing-team-manager.md +45 -40
- package/one/things/claude/agents/marketing-viral-growth.md +49 -18
- package/one/things/claude/agents/mission-commander.md +45 -40
- package/one/things/claude/agents/network-effect-analyst.md +48 -31
- package/one/things/claude/agents/nextjs-15-specialist.md +209 -122
- package/one/things/claude/agents/npx.md +126 -70
- package/one/things/claude/agents/nurture-campaign-manager.md +48 -25
- package/one/things/claude/agents/one-master.md +48 -25
- package/one/things/claude/agents/one-orchestrator.md +57 -27
- package/one/things/claude/agents/one.md +88 -31
- package/one/things/claude/agents/playbook-generator.md +48 -25
- package/one/things/claude/agents/pm.md +48 -25
- package/one/things/claude/agents/po.md +51 -26
- package/one/things/claude/agents/qa.md +50 -25
- package/one/things/claude/agents/research-foundation-analyst.md +48 -31
- package/one/things/claude/agents/research-intelligence-gatherer.md +59 -32
- package/one/things/claude/agents/research-market-analyst.md +47 -30
- package/one/things/claude/agents/research-team-manager.md +47 -40
- package/one/things/claude/agents/sales-environment-optimizer.md +50 -25
- package/one/things/claude/agents/sales-team-manager.md +47 -40
- package/one/things/claude/agents/sales-upsell-strategist.md +47 -30
- package/one/things/claude/agents/service-advocacy-campaigns.md +47 -30
- package/one/things/claude/agents/service-advocacy-manager.md +47 -30
- package/one/things/claude/agents/service-success-manager.md +47 -30
- package/one/things/claude/agents/service-team-manager.md +45 -40
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +85 -30
- package/one/things/claude/agents/share-optimization-specialist.md +50 -25
- package/one/things/claude/agents/sm.md +50 -25
- package/one/things/claude/agents/story-teller.md +51 -26
- package/one/things/claude/agents/task-master.md +52 -27
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +201 -116
- package/one/things/claude/agents/tester.md +85 -46
- package/one/things/claude/agents/the-bull-character-manager.md +48 -25
- package/one/things/claude/agents/tools-playbook-generator.md +43 -40
- package/one/things/claude/agents/turbo-repo-builder.md +57 -27
- package/one/things/claude/agents/upsell-strategist.md +48 -25
- package/one/things/claude/agents/ux-expert.md +50 -25
- package/one/things/claude/agents/viral-growth-orchestrator.md +50 -27
- package/one/things/claude/commands/agent.md +25 -5
- package/one/things/claude/commands/cascade-status.md +33 -8
- package/one/things/claude/commands/ingest.md +64 -11
- package/one/things/claude/commands/ingestor.md +29 -7
- package/one/things/claude/commands/mission.md +24 -4
- package/one/things/claude/commands/npx.md +30 -7
- package/one/things/claude/commands/one.md +114 -68
- package/one/things/claude/commands/quality-check.md +72 -24
- package/one/things/claude/commands/smart-route.md +45 -4
- package/one/things/claude/commands/start.md +22 -4
- package/one/things/claude/commands/story.md +25 -5
- package/one/things/claude/commands/task.md +21 -1
- package/one/things/cli/cli-code.md +244 -219
- package/one/things/cli/cli-compiler-code.md +244 -219
- package/one/things/cli/cli.md +30 -6
- package/one/things/components/card-shadcn.md +252 -228
- package/one/things/components/card.md +315 -324
- package/one/things/components.md +667 -593
- package/one/things/componets.md +16 -1
- package/one/things/creator-diagram.md +23 -5
- package/one/things/demo-accessibility-animations.md +73 -47
- package/one/things/demo-components.md +225 -219
- package/one/things/demo-design-summary.md +89 -26
- package/one/things/demo-design-system.md +184 -130
- package/one/things/demo-page-layouts.md +52 -25
- package/one/things/designs/accessibility-audit.md +153 -66
- package/one/things/designs/component-specifications.md +163 -65
- package/one/things/designs/design-overview.md +81 -22
- package/one/things/designs/design-tokens.md +127 -93
- package/one/things/designs/wireframes-dashboard.md +64 -7
- package/one/things/docs/api-requests.md +75 -11
- package/one/things/docs/ecommerce/ARCHITECTURE-DIAGRAM.md +18 -0
- package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-IMPLEMENTATION.md +57 -0
- package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-SUMMARY.md +62 -6
- package/one/things/docs/ecommerce/CONVERSION-UX-IMPLEMENTATION-SUMMARY.md +60 -5
- package/one/things/docs/ecommerce/FEATURE-SUMMARY.md +95 -27
- package/one/things/docs/ecommerce/IMPLEMENTATION-NOTES.md +130 -62
- package/one/things/docs/ecommerce/INTEGRATION-EXAMPLE.md +43 -19
- package/one/things/docs/ecommerce/QUICK-START.md +41 -4
- package/one/things/docs/ecommerce/URGENCY-IMPLEMENTATION-SUMMARY.md +75 -6
- package/one/things/docs/ecommerce/URGENCY-QUICK-REFERENCE.md +58 -24
- package/one/things/examples/children/lemonade-stand.md +52 -14
- package/one/things/examples/enterprise/crm-saas.md +43 -28
- package/one/things/features/1-1-agent-prompts.md +76 -0
- package/one/things/features/1-2-yaml-orchestrator.md +32 -0
- package/one/things/features/1-3-event-coordination.md +40 -1
- package/one/things/features/1-4-knowledge-management.md +91 -16
- package/one/things/features/1-5-quality-loops.md +88 -4
- package/one/things/features/1-6-numbering-structure.md +78 -14
- package/one/things/features/2-1-dataprovider-interface.md +311 -86
- package/one/things/features/2-2-config-system.md +307 -140
- package/one/things/features/2-3-effectts-services.md +263 -116
- package/one/things/features/2-4-react-hooks.md +217 -201
- package/one/things/features/2-5-auth-migration.md +406 -308
- package/one/things/features/2-6-dashboard-migration.md +112 -13
- package/one/things/features/2-7-alternative-providers.md +138 -65
- package/one/things/features/2-7-implementation-report.md +68 -24
- package/one/things/features/2-cli.md +88 -76
- package/one/things/features/2-design.md +112 -80
- package/one/things/features/2-tests.md +56 -0
- package/one/things/features/AUTH_HOOKS_IMPLEMENTATION.md +91 -36
- package/one/things/features/DECOUPLING.md +36 -18
- package/one/things/features/DEPLOYMENT.md +22 -4
- package/one/things/features/IMPLEMENTATION_SUMMARY.md +48 -2
- package/one/things/features/improve.md +47 -29
- package/one/things/features/remove-convex-deps.md +18 -0
- package/one/things/features/top-features.md +28 -20
- package/one/things/features/use-one-backend.md +210 -173
- package/one/things/features-in-english.md +19 -6
- package/one/things/files.yaml +721 -0
- package/one/things/ideas/1-create-workflow.md +18 -0
- package/one/things/ideas/2-backend-agnostic-frontend.md +57 -2
- package/one/things/implementation/backend-guide.md +64 -19
- package/one/things/interface.md +43 -0
- package/one/things/landing-page-implementation.md +455 -0
- package/one/things/legal/README.md +44 -0
- package/one/things/legal/privacy-policy.md +186 -23
- package/one/things/legal/terms-of-service.md +164 -3
- package/one/things/master-workflow-plan.md +806 -0
- package/one/things/plans/0-timeline.md +36 -0
- package/one/things/plans/1-create-workflow.md +19 -0
- package/one/things/plans/QUICK-START-SIMPLIFICATION.md +333 -0
- package/one/things/plans/README-SIMPLIFICATION.md +349 -0
- package/one/things/plans/SIMPLIFICATION-EXAMPLES.md +16 -0
- package/one/things/plans/SIMPLIFICATION-SUMMARY.md +455 -0
- package/one/things/plans/ai-elements.md +21 -2
- package/one/things/plans/ai-integration.md +108 -59
- package/one/things/plans/ai-sdk.md +85 -48
- package/one/things/plans/ai-tools.md +621 -0
- package/one/things/plans/app.md +142 -71
- package/one/things/plans/architecture-summary.md +34 -5
- package/one/things/plans/async-ai-agents.md +19 -1
- package/one/things/plans/backend-agnostic-frontend.md +70 -8
- package/one/things/plans/backend-cleanup-quickstart.md +52 -18
- package/one/things/plans/backend-ontology-conformance.md +110 -51
- package/one/things/plans/backend-status.md +58 -0
- package/one/things/plans/backend-structure.md +103 -55
- package/one/things/plans/backend-target-structure.md +61 -17
- package/one/things/plans/backend.md +60 -18
- package/one/things/plans/better-auth-any-backend-revised.md +325 -287
- package/one/things/plans/better-auth-any-backend.md +575 -531
- package/one/things/plans/better-auth-available-features.md +43 -5
- package/one/things/plans/big-plan.md +20 -6
- package/one/things/plans/cli-updates-required.md +44 -4
- package/one/things/plans/complete-step-by-step.md +223 -116
- package/one/things/plans/components.md +709 -0
- package/one/things/plans/convex-agents.md +79 -50
- package/one/things/plans/convex-better-auth.md +186 -154
- package/one/things/plans/convex-on-off.md +47 -29
- package/one/things/plans/crypto-token-researcher.md +629 -0
- package/one/things/plans/data-quality-metrics.md +745 -0
- package/one/things/plans/deep-researcher-agent.md +466 -0
- package/one/things/plans/deploy-to-cloudflare.md +55 -13
- package/one/things/plans/deployment-architecture.md +54 -11
- package/one/things/plans/desktop.md +21 -3
- package/one/things/plans/development-plan.md +184 -121
- package/one/things/plans/development-workflow-tldr.md +207 -0
- package/one/things/plans/development-workflow.md +959 -0
- package/one/things/plans/effect-components.md +667 -593
- package/one/things/plans/effect-patterns-reference.md +2235 -0
- package/one/things/plans/effect.md +204 -131
- package/one/things/plans/email.md +21 -8
- package/one/things/plans/enhance-auth.md +64 -41
- package/one/things/plans/execution-strategy.md +1291 -0
- package/one/things/plans/existing-infrastructure.md +712 -0
- package/one/things/plans/feature-based-sites.md +124 -51
- package/one/things/plans/frontend-effects.md +1276 -0
- package/one/things/plans/group-folder-multi-tenancy.md +92 -29
- package/one/things/plans/improve-codebase.md +498 -421
- package/one/things/plans/install-components.md +18 -1
- package/one/things/plans/integrate-frontend-and-backend.md +68 -44
- package/one/things/plans/landing.md +92 -0
- package/one/things/plans/layout.md +45 -1
- package/one/things/plans/mail-backend.md +546 -493
- package/one/things/plans/mail.md +379 -326
- package/one/things/plans/mcp-clear-context-prompt.md +21 -0
- package/one/things/plans/mcp-simple.md +20 -0
- package/one/things/plans/multi-ontology-architecture.md +115 -66
- package/one/things/plans/next-features.md +31 -0
- package/one/things/plans/onboarding.md +20 -1
- package/one/things/plans/one.md +18 -0
- package/one/things/plans/ontology-6-dimensions.md +24 -45
- package/one/things/plans/ontology-compliance-audit.md +315 -0
- package/one/things/plans/ontology-driven-strategy.md +19 -3
- package/one/things/plans/ontology-refine.md +586 -0
- package/one/things/plans/ontology-ui-approach.md +18 -0
- package/one/things/plans/open-agent.md +152 -97
- package/one/things/plans/performace.md +32 -0
- package/one/things/plans/phase-1-foundation.md +620 -0
- package/one/things/plans/phase-3-implementation.md +1037 -0
- package/one/things/plans/quick-wins.md +342 -187
- package/one/things/plans/readme-backend-cleanup.md +54 -13
- package/one/things/plans/release.md +55 -2
- package/one/things/plans/repos.md +22 -0
- package/one/things/plans/separate-copy-2.md +127 -71
- package/one/things/plans/separate-copy-3.md +35 -14
- package/one/things/plans/separate-copy.md +127 -71
- package/one/things/plans/separate-demo.md +37 -3
- package/one/things/plans/separate.md +24 -6
- package/one/things/plans/sequence.md +155 -12
- package/one/things/plans/shadcn-integration-summary.md +104 -44
- package/one/things/plans/sidebar.md +44 -10
- package/one/things/plans/skills.md +103 -0
- package/one/things/plans/small-fixes.md +19 -1
- package/one/things/plans/start-new.md +34 -8
- package/one/things/plans/switch-off-auth.md +22 -0
- package/one/things/plans/sync-checklist.md +30 -0
- package/one/things/plans/test-backend-connection.md +38 -0
- package/one/things/plans/unified-implementation-plan.md +144 -62
- package/one/things/plans/update-demos.md +103 -35
- package/one/things/plans/use-our-backend.md +572 -0
- package/one/things/plans/wave1-onboarding-100-inferences.md +1686 -0
- package/one/things/plans/wave1-onboarding-vision.md +744 -0
- package/one/things/plans/wave1-orchestration-summary.md +604 -0
- package/one/things/plans/wave1-specialist-assignments.md +1413 -0
- package/one/things/plans/workflow-files.md +28 -14
- package/one/things/plans/workflow.md +18 -12
- package/one/things/products/cascade-landing-page.md +150 -46
- package/one/things/products/cascade.md +185 -135
- package/one/things/products/context-engineering.md +411 -350
- package/one/things/products/onthology.md +15 -0
- package/one/things/products/ontology-ui-shadcn.md +375 -353
- package/one/things/products/ontology-ui.md +101 -59
- package/one/things/products/ontology.md +90 -18
- package/one/things/products/sdk.md +181 -165
- package/one/things/promptkit.md +70 -43
- package/one/things/repos/all-repos.md +0 -0
- package/one/things/service-providers-new.md +95 -25
- package/one/things/service-providers.md +231 -202
- package/one/things/structure.md +532 -0
- package/one/things/system.md +18 -0
- package/one/things/templates.md +40 -0
- package/one/things/tests/2-1-dataprovider-interface.md +103 -31
- package/one/things/tests/2-1-test-analysis.md +65 -17
- package/one/things/things.md +48 -13
- package/one/things/todo-acp-integration.md +744 -0
- package/one/things/todo-ai.md +933 -0
- package/one/things/todo-api.md +1078 -0
- package/one/things/todo-assignment.md +580 -0
- package/one/things/todo-buy-chatgpt.md +1450 -0
- package/one/things/todo-components.md +1683 -0
- package/one/things/todo-connections.md +278 -0
- package/one/things/todo-ecommerce-frontend.md +1313 -0
- package/one/things/todo-ecommerce.md +569 -0
- package/one/things/todo-effects.md +1075 -0
- package/one/things/todo-frontend-effects.md +977 -0
- package/one/things/todo-landing-page.md +1091 -0
- package/one/things/todo-mail.md +1160 -0
- package/one/things/todo-master-plan.md +490 -0
- package/one/things/todo-onboard.md +666 -0
- package/one/things/todo-one-ie.md +538 -0
- package/one/things/todo-page.md +606 -0
- package/one/things/todo-plans.md +282 -0
- package/one/things/todo-projects.md +241 -0
- package/one/things/todo-refactoring-plan.md +366 -0
- package/one/things/todo-sequence.md +1621 -0
- package/one/things/todo-use-our-backend.md +1908 -0
- package/one/things/todo-workflow.md +626 -0
- package/one/things/todo-x402.md +2047 -0
- package/one/things/todo.md +459 -1075
- package/one/things/video/scripts-crypto.md +835 -0
- package/one/things/video-script-ontology.md +334 -0
- package/package.json +1 -1
- package/one/knowledge/CLOUDFLARE_ENV_SETUP.md +0 -49
- package/one/knowledge/docs/flow.md +0 -0
- package/one/knowledge/documentation-summary.md +0 -285
- package/one/knowledge/inference-score.md +0 -159
- package/one/knowledge/ontology-frontend-copy-2.md +0 -1492
- package/one/knowledge/ontology-frontend-copy.md +0 -753
- package/one/knowledge/ontology-migration-guide.md +0 -811
- package/one/things/features/0 All Features.md +0 -2
- package/one/things/plans/1-create-workflow-status.md +0 -555
- package/one/things/plans/2-backend-agnostic-frontend.md +0 -546
- package/one/things/plans/2-sites.md +0 -895
- package/one/things/plans/3-groups.md +0 -735
- package/one/things/plans/5-build-frontend.md +0 -0
- package/one/things/plans/5-complete.md +0 -17
- package/one/things/plans/agent-director-100-inference-plans.md +0 -410
- package/one/things/plans/dual-website-strategy.md +0 -612
- package/one/things/plans/releases.md +0 -809
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Effect Components
|
|
3
|
+
dimension: things
|
|
4
|
+
category: plans
|
|
5
|
+
tags: agent, ai, backend
|
|
6
|
+
related_dimensions: events, knowledge
|
|
7
|
+
scope: global
|
|
8
|
+
created: 2025-11-03
|
|
9
|
+
updated: 2025-11-03
|
|
10
|
+
version: 1.0.0
|
|
11
|
+
ai_context: |
|
|
12
|
+
This document is part of the things dimension in the plans category.
|
|
13
|
+
Location: one/things/plans/effect-components.md
|
|
14
|
+
Purpose: Documents production integration guide: effect.ts + confect + convex components for ai agents
|
|
15
|
+
Related dimensions: events, knowledge
|
|
16
|
+
For AI agents: Read this to understand effect components.
|
|
17
|
+
---
|
|
18
|
+
|
|
1
19
|
# Production Integration Guide: Effect.ts + Confect + Convex Components for AI Agents
|
|
2
20
|
|
|
3
21
|
**Building sophisticated multi-agent systems with functional patterns, type safety, and durable workflows**
|
|
@@ -33,15 +51,15 @@ const agentWithEffect = (agent: Agent) => Effect.gen(function* () {
|
|
|
33
51
|
#### Pattern: Effect-Wrapped Agent Execution
|
|
34
52
|
|
|
35
53
|
```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"
|
|
54
|
+
import { Effect, Context } from "effect";
|
|
55
|
+
import { Agent } from "@convex-dev/agent";
|
|
56
|
+
import { openai } from "@ai-sdk/openai";
|
|
57
|
+
import { components } from "./_generated/api";
|
|
40
58
|
|
|
41
59
|
// Define errors as tagged classes
|
|
42
60
|
class AgentError extends Data.TaggedError("AgentError")<{
|
|
43
|
-
agentName: string
|
|
44
|
-
cause: unknown
|
|
61
|
+
agentName: string;
|
|
62
|
+
cause: unknown;
|
|
45
63
|
}> {}
|
|
46
64
|
|
|
47
65
|
// Service definition for agent
|
|
@@ -51,8 +69,8 @@ class AgentService extends Context.Tag("AgentService")<
|
|
|
51
69
|
readonly generateResponse: (
|
|
52
70
|
ctx: ActionCtx,
|
|
53
71
|
threadId: string,
|
|
54
|
-
prompt: string
|
|
55
|
-
) => Effect.Effect<string, AgentError
|
|
72
|
+
prompt: string,
|
|
73
|
+
) => Effect.Effect<string, AgentError>;
|
|
56
74
|
}
|
|
57
75
|
>() {}
|
|
58
76
|
|
|
@@ -65,25 +83,30 @@ const AgentServiceLive = Layer.effect(
|
|
|
65
83
|
name: "Support Agent",
|
|
66
84
|
chat: openai.chat("gpt-4o-mini"),
|
|
67
85
|
instructions: "You are a helpful assistant.",
|
|
68
|
-
tools: {
|
|
69
|
-
|
|
70
|
-
|
|
86
|
+
tools: {
|
|
87
|
+
/* ... */
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
71
91
|
return {
|
|
72
92
|
generateResponse: (ctx, threadId, prompt) =>
|
|
73
93
|
Effect.tryPromise({
|
|
74
94
|
try: async () => {
|
|
75
|
-
const { thread } = await supportAgent.continueThread(ctx, {
|
|
76
|
-
|
|
77
|
-
|
|
95
|
+
const { thread } = await supportAgent.continueThread(ctx, {
|
|
96
|
+
threadId,
|
|
97
|
+
});
|
|
98
|
+
const result = await thread.generateText({ prompt });
|
|
99
|
+
return result.text;
|
|
78
100
|
},
|
|
79
|
-
catch: (error) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)
|
|
101
|
+
catch: (error) =>
|
|
102
|
+
new AgentError({
|
|
103
|
+
agentName: "Support Agent",
|
|
104
|
+
cause: error,
|
|
105
|
+
}),
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
87
110
|
```
|
|
88
111
|
|
|
89
112
|
#### Pattern: Composing Multiple Agents with Effect
|
|
@@ -94,50 +117,56 @@ export const multiAgentPipeline = action({
|
|
|
94
117
|
args: { prompt: v.string(), userId: v.string() },
|
|
95
118
|
handler: (ctx, args) =>
|
|
96
119
|
Effect.gen(function* () {
|
|
97
|
-
const agentService = yield* AgentService
|
|
98
|
-
const ragService = yield* RAGService
|
|
99
|
-
|
|
120
|
+
const agentService = yield* AgentService;
|
|
121
|
+
const ragService = yield* RAGService;
|
|
122
|
+
|
|
100
123
|
// Sequential with automatic error propagation
|
|
101
|
-
const context = yield* ragService.search(args.prompt)
|
|
102
|
-
const classification = yield* agentService.classify(ctx, args.prompt)
|
|
103
|
-
|
|
124
|
+
const context = yield* ragService.search(args.prompt);
|
|
125
|
+
const classification = yield* agentService.classify(ctx, args.prompt);
|
|
126
|
+
|
|
104
127
|
// Conditional routing
|
|
105
128
|
const response = yield* classification.intent === "technical"
|
|
106
129
|
? agentService.technicalAgent(ctx, args.prompt, context)
|
|
107
|
-
: agentService.generalAgent(ctx, args.prompt, context)
|
|
108
|
-
|
|
130
|
+
: agentService.generalAgent(ctx, args.prompt, context);
|
|
131
|
+
|
|
109
132
|
// Parallel quality checks
|
|
110
|
-
const [grammar, factuality] = yield* Effect.all(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
133
|
+
const [grammar, factuality] = yield* Effect.all(
|
|
134
|
+
[
|
|
135
|
+
agentService.checkGrammar(response),
|
|
136
|
+
agentService.checkFactuality(response, context),
|
|
137
|
+
],
|
|
138
|
+
{ concurrency: 2 },
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return { response, grammar, factuality };
|
|
116
142
|
}).pipe(
|
|
117
143
|
Effect.provide(Layer.merge(AgentServiceLive, RAGServiceLive)),
|
|
118
144
|
Effect.catchAll((error) => {
|
|
119
|
-
console.error("Multi-agent pipeline failed:", error)
|
|
120
|
-
return Effect.succeed({
|
|
145
|
+
console.error("Multi-agent pipeline failed:", error);
|
|
146
|
+
return Effect.succeed({
|
|
121
147
|
response: "I'm having trouble processing that request.",
|
|
122
|
-
error: true
|
|
123
|
-
})
|
|
124
|
-
})
|
|
125
|
-
)
|
|
126
|
-
})
|
|
148
|
+
error: true,
|
|
149
|
+
});
|
|
150
|
+
}),
|
|
151
|
+
),
|
|
152
|
+
});
|
|
127
153
|
```
|
|
128
154
|
|
|
129
155
|
#### Pattern: Effect-Based Tool Definitions
|
|
130
156
|
|
|
131
157
|
```typescript
|
|
132
|
-
import { createTool } from "@convex-dev/agent"
|
|
133
|
-
import { z } from "zod"
|
|
158
|
+
import { createTool } from "@convex-dev/agent";
|
|
159
|
+
import { z } from "zod";
|
|
134
160
|
|
|
135
161
|
// Define service for external integrations
|
|
136
162
|
class EmailService extends Context.Tag("EmailService")<
|
|
137
163
|
EmailService,
|
|
138
164
|
{
|
|
139
|
-
readonly send: (
|
|
140
|
-
|
|
165
|
+
readonly send: (
|
|
166
|
+
to: string,
|
|
167
|
+
subject: string,
|
|
168
|
+
body: string,
|
|
169
|
+
) => Effect.Effect<void, EmailError>;
|
|
141
170
|
}
|
|
142
171
|
>() {}
|
|
143
172
|
|
|
@@ -145,9 +174,9 @@ const EmailServiceLive = Layer.succeed(EmailService, {
|
|
|
145
174
|
send: (to, subject, body) =>
|
|
146
175
|
Effect.tryPromise({
|
|
147
176
|
try: () => sendgrid.send({ to, subject, body }),
|
|
148
|
-
catch: (error) => new EmailError({ cause: error })
|
|
149
|
-
})
|
|
150
|
-
})
|
|
177
|
+
catch: (error) => new EmailError({ cause: error }),
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
151
180
|
|
|
152
181
|
// Tool that uses Effect internally
|
|
153
182
|
export const emailTool = createTool({
|
|
@@ -155,31 +184,31 @@ export const emailTool = createTool({
|
|
|
155
184
|
args: z.object({
|
|
156
185
|
userEmail: z.string().email(),
|
|
157
186
|
subject: z.string(),
|
|
158
|
-
message: z.string()
|
|
187
|
+
message: z.string(),
|
|
159
188
|
}),
|
|
160
189
|
handler: async (toolCtx, args) => {
|
|
161
190
|
// Convert Effect to Promise for tool handler
|
|
162
191
|
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
|
-
|
|
192
|
+
const emailService = yield* EmailService;
|
|
193
|
+
yield* emailService.send(args.userEmail, args.subject, args.message);
|
|
194
|
+
return "Email sent successfully";
|
|
195
|
+
});
|
|
196
|
+
|
|
168
197
|
return await Effect.runPromise(
|
|
169
198
|
program.pipe(
|
|
170
199
|
Effect.provide(EmailServiceLive),
|
|
171
|
-
Effect.catchAll((error) =>
|
|
172
|
-
Effect.succeed(`Failed to send email: ${error.message}`)
|
|
173
|
-
)
|
|
174
|
-
)
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
})
|
|
200
|
+
Effect.catchAll((error) =>
|
|
201
|
+
Effect.succeed(`Failed to send email: ${error.message}`),
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
});
|
|
178
207
|
|
|
179
208
|
const agent = new Agent(components.agent, {
|
|
180
209
|
chat: openai.chat("gpt-4o"),
|
|
181
|
-
tools: { sendEmail: emailTool }
|
|
182
|
-
})
|
|
210
|
+
tools: { sendEmail: emailTool },
|
|
211
|
+
});
|
|
183
212
|
```
|
|
184
213
|
|
|
185
214
|
**Type Safety Considerations**:
|
|
@@ -200,8 +229,8 @@ const agent = new Agent(components.agent, {
|
|
|
200
229
|
#### Pattern: Effect-Managed Streaming Lifecycle
|
|
201
230
|
|
|
202
231
|
```typescript
|
|
203
|
-
import { PersistentTextStreaming } from "@convex-dev/persistent-text-streaming"
|
|
204
|
-
import { Effect, Stream } from "effect"
|
|
232
|
+
import { PersistentTextStreaming } from "@convex-dev/persistent-text-streaming";
|
|
233
|
+
import { Effect, Stream } from "effect";
|
|
205
234
|
|
|
206
235
|
class StreamingService extends Context.Tag("StreamingService")<
|
|
207
236
|
StreamingService,
|
|
@@ -209,8 +238,8 @@ class StreamingService extends Context.Tag("StreamingService")<
|
|
|
209
238
|
readonly generateStream: (
|
|
210
239
|
ctx: ActionCtx,
|
|
211
240
|
prompt: string,
|
|
212
|
-
streamId: string
|
|
213
|
-
) => Effect.Effect<void, StreamingError
|
|
241
|
+
streamId: string,
|
|
242
|
+
) => Effect.Effect<void, StreamingError>;
|
|
214
243
|
}
|
|
215
244
|
>() {}
|
|
216
245
|
|
|
@@ -218,52 +247,58 @@ const StreamingServiceLive = Layer.effect(
|
|
|
218
247
|
StreamingService,
|
|
219
248
|
Effect.gen(function* () {
|
|
220
249
|
const persistentTextStreaming = new PersistentTextStreaming(
|
|
221
|
-
components.persistentTextStreaming
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
const llmService = yield* LLMService
|
|
225
|
-
|
|
250
|
+
components.persistentTextStreaming,
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
const llmService = yield* LLMService;
|
|
254
|
+
|
|
226
255
|
return {
|
|
227
256
|
generateStream: (ctx, prompt, streamId) =>
|
|
228
257
|
Effect.gen(function* () {
|
|
229
258
|
// Fetch context with Effect error handling
|
|
230
259
|
const context = yield* Effect.tryPromise({
|
|
231
260
|
try: () => ctx.runQuery(api.chat.getContext, { streamId }),
|
|
232
|
-
catch: () => new ContextFetchError()
|
|
233
|
-
})
|
|
234
|
-
|
|
261
|
+
catch: () => new ContextFetchError(),
|
|
262
|
+
});
|
|
263
|
+
|
|
235
264
|
// Stream with Effect composition
|
|
236
|
-
const stream = yield* llmService.streamCompletion(prompt, context)
|
|
237
|
-
|
|
265
|
+
const stream = yield* llmService.streamCompletion(prompt, context);
|
|
266
|
+
|
|
238
267
|
// Handle chunks with backpressure
|
|
239
|
-
yield* Stream.fromAsyncIterable(
|
|
240
|
-
|
|
268
|
+
yield* Stream.fromAsyncIterable(
|
|
269
|
+
stream,
|
|
270
|
+
() => new StreamProcessingError(),
|
|
241
271
|
).pipe(
|
|
242
272
|
Stream.mapEffect((chunk) =>
|
|
243
273
|
Effect.tryPromise({
|
|
244
274
|
try: async () => {
|
|
245
|
-
await persistentTextStreaming.appendChunk(
|
|
275
|
+
await persistentTextStreaming.appendChunk(
|
|
276
|
+
ctx,
|
|
277
|
+
streamId,
|
|
278
|
+
chunk,
|
|
279
|
+
);
|
|
246
280
|
},
|
|
247
|
-
catch: () => new ChunkAppendError({ chunk })
|
|
248
|
-
})
|
|
281
|
+
catch: () => new ChunkAppendError({ chunk }),
|
|
282
|
+
}),
|
|
249
283
|
),
|
|
250
|
-
Stream.runDrain
|
|
251
|
-
)
|
|
252
|
-
|
|
284
|
+
Stream.runDrain,
|
|
285
|
+
);
|
|
286
|
+
|
|
253
287
|
// Mark complete
|
|
254
288
|
yield* Effect.tryPromise({
|
|
255
|
-
try: () =>
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
})
|
|
289
|
+
try: () => ctx.runMutation(api.chat.markComplete, { streamId }),
|
|
290
|
+
catch: () => new StreamCompletionError(),
|
|
291
|
+
});
|
|
259
292
|
}).pipe(
|
|
260
|
-
Effect.retry(
|
|
261
|
-
Schedule.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
293
|
+
Effect.retry(
|
|
294
|
+
Schedule.exponential("100 millis").pipe(
|
|
295
|
+
Schedule.compose(Schedule.recurs(3)),
|
|
296
|
+
),
|
|
297
|
+
),
|
|
298
|
+
),
|
|
299
|
+
};
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
267
302
|
```
|
|
268
303
|
|
|
269
304
|
**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.
|
|
@@ -279,8 +314,8 @@ const StreamingServiceLive = Layer.effect(
|
|
|
279
314
|
#### Pattern: Effect Service Layer with Rate Limiting
|
|
280
315
|
|
|
281
316
|
```typescript
|
|
282
|
-
import { RateLimiter, MINUTE } from "@convex-dev/rate-limiter"
|
|
283
|
-
import { Effect, Schedule } from "effect"
|
|
317
|
+
import { RateLimiter, MINUTE } from "@convex-dev/rate-limiter";
|
|
318
|
+
import { Effect, Schedule } from "effect";
|
|
284
319
|
|
|
285
320
|
class RateLimitedLLMService extends Context.Tag("RateLimitedLLMService")<
|
|
286
321
|
RateLimitedLLMService,
|
|
@@ -288,8 +323,8 @@ class RateLimitedLLMService extends Context.Tag("RateLimitedLLMService")<
|
|
|
288
323
|
readonly generateCompletion: (
|
|
289
324
|
ctx: ActionCtx,
|
|
290
325
|
userId: string,
|
|
291
|
-
prompt: string
|
|
292
|
-
) => Effect.Effect<string, RateLimitError | LLMError
|
|
326
|
+
prompt: string,
|
|
327
|
+
) => Effect.Effect<string, RateLimitError | LLMError>;
|
|
293
328
|
}
|
|
294
329
|
>() {}
|
|
295
330
|
|
|
@@ -297,81 +332,89 @@ const RateLimitedLLMServiceLive = Layer.effect(
|
|
|
297
332
|
RateLimitedLLMService,
|
|
298
333
|
Effect.gen(function* () {
|
|
299
334
|
const rateLimiter = new RateLimiter(components.rateLimiter, {
|
|
300
|
-
llmRequests: {
|
|
301
|
-
kind: "token bucket",
|
|
302
|
-
rate: 20,
|
|
335
|
+
llmRequests: {
|
|
336
|
+
kind: "token bucket",
|
|
337
|
+
rate: 20,
|
|
303
338
|
period: MINUTE,
|
|
304
|
-
capacity: 30
|
|
339
|
+
capacity: 30,
|
|
305
340
|
},
|
|
306
|
-
llmTokens: {
|
|
307
|
-
kind: "token bucket",
|
|
308
|
-
rate: 40000,
|
|
341
|
+
llmTokens: {
|
|
342
|
+
kind: "token bucket",
|
|
343
|
+
rate: 40000,
|
|
309
344
|
period: MINUTE,
|
|
310
|
-
shards: 10
|
|
311
|
-
}
|
|
312
|
-
})
|
|
313
|
-
|
|
345
|
+
shards: 10,
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
314
349
|
return {
|
|
315
350
|
generateCompletion: (ctx, userId, prompt) =>
|
|
316
351
|
Effect.gen(function* () {
|
|
317
352
|
// Check request limit
|
|
318
353
|
const requestLimit = yield* Effect.tryPromise({
|
|
319
|
-
try: () =>
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
354
|
+
try: () =>
|
|
355
|
+
rateLimiter.limit(ctx, "llmRequests", {
|
|
356
|
+
key: userId,
|
|
357
|
+
reserve: true,
|
|
358
|
+
}),
|
|
359
|
+
catch: () => new RateLimiterError(),
|
|
360
|
+
});
|
|
361
|
+
|
|
326
362
|
if (!requestLimit.ok) {
|
|
327
|
-
return yield* Effect.fail(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
363
|
+
return yield* Effect.fail(
|
|
364
|
+
new RateLimitError({
|
|
365
|
+
type: "requests",
|
|
366
|
+
retryAfter: requestLimit.retryAfter,
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
331
369
|
}
|
|
332
|
-
|
|
370
|
+
|
|
333
371
|
// Estimate token usage
|
|
334
|
-
const estimatedTokens = Math.ceil(prompt.length / 4)
|
|
335
|
-
|
|
372
|
+
const estimatedTokens = Math.ceil(prompt.length / 4);
|
|
373
|
+
|
|
336
374
|
const tokenLimit = yield* Effect.tryPromise({
|
|
337
|
-
try: () =>
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
375
|
+
try: () =>
|
|
376
|
+
rateLimiter.limit(ctx, "llmTokens", {
|
|
377
|
+
key: userId,
|
|
378
|
+
count: estimatedTokens,
|
|
379
|
+
}),
|
|
380
|
+
catch: () => new RateLimiterError(),
|
|
381
|
+
});
|
|
382
|
+
|
|
344
383
|
if (!tokenLimit.ok) {
|
|
345
|
-
return yield* Effect.fail(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
384
|
+
return yield* Effect.fail(
|
|
385
|
+
new RateLimitError({
|
|
386
|
+
type: "tokens",
|
|
387
|
+
retryAfter: tokenLimit.retryAfter,
|
|
388
|
+
}),
|
|
389
|
+
);
|
|
349
390
|
}
|
|
350
|
-
|
|
391
|
+
|
|
351
392
|
// Make LLM call
|
|
352
393
|
const result = yield* Effect.tryPromise({
|
|
353
|
-
try: () =>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
394
|
+
try: () =>
|
|
395
|
+
openai.chat.completions.create({
|
|
396
|
+
model: "gpt-4",
|
|
397
|
+
messages: [{ role: "user", content: prompt }],
|
|
398
|
+
}),
|
|
399
|
+
catch: (error) => new LLMError({ cause: error }),
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
return result.choices[0].message.content;
|
|
361
403
|
}).pipe(
|
|
362
404
|
// Automatic retry with exponential backoff on rate limits
|
|
363
405
|
Effect.retry(
|
|
364
406
|
Schedule.exponential("1 second").pipe(
|
|
365
|
-
Schedule.whileInput(
|
|
366
|
-
error
|
|
407
|
+
Schedule.whileInput(
|
|
408
|
+
(error: RateLimitError | LLMError) =>
|
|
409
|
+
error._tag === "RateLimitError",
|
|
367
410
|
),
|
|
368
|
-
Schedule.recurs(5)
|
|
369
|
-
)
|
|
370
|
-
)
|
|
371
|
-
)
|
|
372
|
-
}
|
|
373
|
-
})
|
|
374
|
-
)
|
|
411
|
+
Schedule.recurs(5),
|
|
412
|
+
),
|
|
413
|
+
),
|
|
414
|
+
),
|
|
415
|
+
};
|
|
416
|
+
}),
|
|
417
|
+
);
|
|
375
418
|
```
|
|
376
419
|
|
|
377
420
|
#### Pattern: Multi-Level Rate Limiting with Effect
|
|
@@ -382,46 +425,53 @@ export const protectedAgentCall = action({
|
|
|
382
425
|
args: { userId: v.string(), prompt: v.string() },
|
|
383
426
|
handler: (ctx, args) =>
|
|
384
427
|
Effect.gen(function* () {
|
|
385
|
-
const rateLimitService = yield* RateLimitService
|
|
386
|
-
|
|
428
|
+
const rateLimitService = yield* RateLimitService;
|
|
429
|
+
|
|
387
430
|
// Check multiple limits in parallel
|
|
388
|
-
const [userLimit, globalLimit] = yield* Effect.all(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
431
|
+
const [userLimit, globalLimit] = yield* Effect.all(
|
|
432
|
+
[
|
|
433
|
+
rateLimitService.checkUserLimit(ctx, args.userId),
|
|
434
|
+
rateLimitService.checkGlobalLimit(ctx),
|
|
435
|
+
],
|
|
436
|
+
{ concurrency: 2 },
|
|
437
|
+
);
|
|
438
|
+
|
|
393
439
|
// Fail fast if any limit exceeded
|
|
394
440
|
if (!userLimit.ok) {
|
|
395
|
-
return yield* Effect.fail(
|
|
396
|
-
|
|
397
|
-
|
|
441
|
+
return yield* Effect.fail(
|
|
442
|
+
new UserRateLimitExceeded({
|
|
443
|
+
retryAfter: userLimit.retryAfter,
|
|
444
|
+
}),
|
|
445
|
+
);
|
|
398
446
|
}
|
|
399
|
-
|
|
447
|
+
|
|
400
448
|
if (!globalLimit.ok) {
|
|
401
|
-
return yield* Effect.fail(
|
|
402
|
-
|
|
403
|
-
|
|
449
|
+
return yield* Effect.fail(
|
|
450
|
+
new GlobalRateLimitExceeded({
|
|
451
|
+
retryAfter: globalLimit.retryAfter,
|
|
452
|
+
}),
|
|
453
|
+
);
|
|
404
454
|
}
|
|
405
|
-
|
|
455
|
+
|
|
406
456
|
// Execute with agent
|
|
407
|
-
const agentService = yield* AgentService
|
|
457
|
+
const agentService = yield* AgentService;
|
|
408
458
|
const result = yield* agentService.generateResponse(
|
|
409
|
-
ctx,
|
|
410
|
-
args.userId,
|
|
411
|
-
args.prompt
|
|
412
|
-
)
|
|
413
|
-
|
|
414
|
-
return result
|
|
459
|
+
ctx,
|
|
460
|
+
args.userId,
|
|
461
|
+
args.prompt,
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
return result;
|
|
415
465
|
}).pipe(
|
|
416
466
|
Effect.provide(Layer.merge(RateLimitServiceLive, AgentServiceLive)),
|
|
417
467
|
Effect.catchTag("UserRateLimitExceeded", (error) =>
|
|
418
468
|
Effect.succeed({
|
|
419
469
|
error: "You've reached your request limit. Please try again later.",
|
|
420
|
-
retryAfter: error.retryAfter
|
|
421
|
-
})
|
|
422
|
-
)
|
|
423
|
-
)
|
|
424
|
-
})
|
|
470
|
+
retryAfter: error.retryAfter,
|
|
471
|
+
}),
|
|
472
|
+
),
|
|
473
|
+
),
|
|
474
|
+
});
|
|
425
475
|
```
|
|
426
476
|
|
|
427
477
|
**Type Safety Considerations**:
|
|
@@ -442,17 +492,19 @@ export const protectedAgentCall = action({
|
|
|
442
492
|
#### Pattern: Effect-Based Retry Orchestration
|
|
443
493
|
|
|
444
494
|
```typescript
|
|
445
|
-
import { ActionRetrier } from "@convex-dev/action-retrier"
|
|
446
|
-
import { Effect, Schedule } from "effect"
|
|
495
|
+
import { ActionRetrier } from "@convex-dev/action-retrier";
|
|
496
|
+
import { Effect, Schedule } from "effect";
|
|
447
497
|
|
|
448
|
-
class ResilientExecutionService extends Context.Tag(
|
|
498
|
+
class ResilientExecutionService extends Context.Tag(
|
|
499
|
+
"ResilientExecutionService",
|
|
500
|
+
)<
|
|
449
501
|
ResilientExecutionService,
|
|
450
502
|
{
|
|
451
503
|
readonly executeWithRetry: <A>(
|
|
452
504
|
ctx: MutationCtx,
|
|
453
505
|
action: FunctionReference<"action">,
|
|
454
|
-
args: any
|
|
455
|
-
) => Effect.Effect<A, ExecutionError
|
|
506
|
+
args: any,
|
|
507
|
+
) => Effect.Effect<A, ExecutionError>;
|
|
456
508
|
}
|
|
457
509
|
>() {}
|
|
458
510
|
|
|
@@ -462,55 +514,57 @@ const ResilientExecutionServiceLive = Layer.effect(
|
|
|
462
514
|
const retrier = new ActionRetrier(components.actionRetrier, {
|
|
463
515
|
initialBackoffMs: 250,
|
|
464
516
|
base: 2,
|
|
465
|
-
maxFailures: 4
|
|
466
|
-
})
|
|
467
|
-
|
|
517
|
+
maxFailures: 4,
|
|
518
|
+
});
|
|
519
|
+
|
|
468
520
|
return {
|
|
469
521
|
executeWithRetry: (ctx, action, args) =>
|
|
470
522
|
Effect.gen(function* () {
|
|
471
523
|
// Start retry execution
|
|
472
524
|
const runId = yield* Effect.tryPromise({
|
|
473
525
|
try: () => retrier.run(ctx, action, args),
|
|
474
|
-
catch: () => new RetrierStartError()
|
|
475
|
-
})
|
|
476
|
-
|
|
526
|
+
catch: () => new RetrierStartError(),
|
|
527
|
+
});
|
|
528
|
+
|
|
477
529
|
// Poll for completion with Effect
|
|
478
530
|
const result = yield* Effect.repeat(
|
|
479
531
|
Effect.gen(function* () {
|
|
480
532
|
const status = yield* Effect.tryPromise({
|
|
481
533
|
try: () => retrier.status(ctx, runId),
|
|
482
|
-
catch: () => new StatusCheckError()
|
|
483
|
-
})
|
|
484
|
-
|
|
534
|
+
catch: () => new StatusCheckError(),
|
|
535
|
+
});
|
|
536
|
+
|
|
485
537
|
if (status.type === "inProgress") {
|
|
486
|
-
return yield* Effect.fail(Option.none()) // Continue polling
|
|
538
|
+
return yield* Effect.fail(Option.none()); // Continue polling
|
|
487
539
|
}
|
|
488
|
-
|
|
489
|
-
return status.result
|
|
540
|
+
|
|
541
|
+
return status.result;
|
|
490
542
|
}),
|
|
491
543
|
Schedule.spaced("500 millis").pipe(
|
|
492
|
-
Schedule.compose(Schedule.recurs(60)) // Max 30 seconds
|
|
493
|
-
)
|
|
544
|
+
Schedule.compose(Schedule.recurs(60)), // Max 30 seconds
|
|
545
|
+
),
|
|
494
546
|
).pipe(
|
|
495
547
|
Effect.catchAll((error) =>
|
|
496
|
-
Effect.fail(new ExecutionTimeout({ runId }))
|
|
497
|
-
)
|
|
498
|
-
)
|
|
499
|
-
|
|
548
|
+
Effect.fail(new ExecutionTimeout({ runId })),
|
|
549
|
+
),
|
|
550
|
+
);
|
|
551
|
+
|
|
500
552
|
// Handle result
|
|
501
553
|
if (result.type === "success") {
|
|
502
|
-
return result.returnValue
|
|
554
|
+
return result.returnValue;
|
|
503
555
|
} else if (result.type === "failed") {
|
|
504
|
-
return yield* Effect.fail(
|
|
505
|
-
|
|
506
|
-
|
|
556
|
+
return yield* Effect.fail(
|
|
557
|
+
new ExecutionFailed({
|
|
558
|
+
error: result.error,
|
|
559
|
+
}),
|
|
560
|
+
);
|
|
507
561
|
} else {
|
|
508
|
-
return yield* Effect.fail(new ExecutionCanceled())
|
|
562
|
+
return yield* Effect.fail(new ExecutionCanceled());
|
|
509
563
|
}
|
|
510
|
-
})
|
|
511
|
-
}
|
|
512
|
-
})
|
|
513
|
-
)
|
|
564
|
+
}),
|
|
565
|
+
};
|
|
566
|
+
}),
|
|
567
|
+
);
|
|
514
568
|
```
|
|
515
569
|
|
|
516
570
|
#### Pattern: Combining Retrier with Custom Effect Retry
|
|
@@ -522,32 +576,32 @@ export const reliableWorkflow = mutation({
|
|
|
522
576
|
args: { userId: v.string(), data: v.any() },
|
|
523
577
|
handler: (ctx, args) =>
|
|
524
578
|
Effect.gen(function* () {
|
|
525
|
-
const resilientService = yield* ResilientExecutionService
|
|
526
|
-
|
|
579
|
+
const resilientService = yield* ResilientExecutionService;
|
|
580
|
+
|
|
527
581
|
// Effect-level retry for transient errors
|
|
528
582
|
const validated = yield* Effect.retry(
|
|
529
583
|
validateUserData(args.data),
|
|
530
584
|
Schedule.exponential("100 millis").pipe(
|
|
531
|
-
Schedule.compose(Schedule.recurs(3))
|
|
532
|
-
)
|
|
533
|
-
)
|
|
534
|
-
|
|
585
|
+
Schedule.compose(Schedule.recurs(3)),
|
|
586
|
+
),
|
|
587
|
+
);
|
|
588
|
+
|
|
535
589
|
// Retrier-level retry for action execution
|
|
536
590
|
const processed = yield* resilientService.executeWithRetry(
|
|
537
591
|
ctx,
|
|
538
592
|
internal.processing.processData,
|
|
539
|
-
{ userId: args.userId, data: validated }
|
|
540
|
-
)
|
|
541
|
-
|
|
542
|
-
return processed
|
|
593
|
+
{ userId: args.userId, data: validated },
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
return processed;
|
|
543
597
|
}).pipe(
|
|
544
598
|
Effect.provide(ResilientExecutionServiceLive),
|
|
545
599
|
Effect.catchAll((error) => {
|
|
546
|
-
console.error("Workflow failed:", error)
|
|
547
|
-
return Effect.fail(new ConvexError("Workflow execution failed"))
|
|
548
|
-
})
|
|
549
|
-
)
|
|
550
|
-
})
|
|
600
|
+
console.error("Workflow failed:", error);
|
|
601
|
+
return Effect.fail(new ConvexError("Workflow execution failed"));
|
|
602
|
+
}),
|
|
603
|
+
),
|
|
604
|
+
});
|
|
551
605
|
```
|
|
552
606
|
|
|
553
607
|
**Recommendation**: Use component's retrier for long-running actions with persistent state. Use Effect's `Effect.retry` for in-memory retries of short operations.
|
|
@@ -563,8 +617,8 @@ export const reliableWorkflow = mutation({
|
|
|
563
617
|
#### Pattern: Effect Service Layer for Workpool
|
|
564
618
|
|
|
565
619
|
```typescript
|
|
566
|
-
import { Workpool } from "@convex-dev/workpool"
|
|
567
|
-
import { Effect, Queue } from "effect"
|
|
620
|
+
import { Workpool } from "@convex-dev/workpool";
|
|
621
|
+
import { Effect, Queue } from "effect";
|
|
568
622
|
|
|
569
623
|
class TaskQueueService extends Context.Tag("TaskQueueService")<
|
|
570
624
|
TaskQueueService,
|
|
@@ -573,13 +627,13 @@ class TaskQueueService extends Context.Tag("TaskQueueService")<
|
|
|
573
627
|
ctx: MutationCtx,
|
|
574
628
|
priority: "high" | "low",
|
|
575
629
|
action: FunctionReference<"action">,
|
|
576
|
-
args: any
|
|
577
|
-
) => Effect.Effect<string, EnqueueError
|
|
578
|
-
|
|
630
|
+
args: any,
|
|
631
|
+
) => Effect.Effect<string, EnqueueError>;
|
|
632
|
+
|
|
579
633
|
readonly getTaskStatus: (
|
|
580
634
|
ctx: QueryCtx,
|
|
581
|
-
taskId: string
|
|
582
|
-
) => Effect.Effect<TaskStatus, StatusError
|
|
635
|
+
taskId: string,
|
|
636
|
+
) => Effect.Effect<TaskStatus, StatusError>;
|
|
583
637
|
}
|
|
584
638
|
>() {}
|
|
585
639
|
|
|
@@ -588,40 +642,42 @@ const TaskQueueServiceLive = Layer.effect(
|
|
|
588
642
|
Effect.gen(function* () {
|
|
589
643
|
const highPriorityPool = new Workpool(components.highPriorityWorkpool, {
|
|
590
644
|
maxParallelism: 20,
|
|
591
|
-
retryActionsByDefault: true
|
|
592
|
-
})
|
|
593
|
-
|
|
645
|
+
retryActionsByDefault: true,
|
|
646
|
+
});
|
|
647
|
+
|
|
594
648
|
const lowPriorityPool = new Workpool(components.lowPriorityWorkpool, {
|
|
595
649
|
maxParallelism: 5,
|
|
596
|
-
retryActionsByDefault: true
|
|
597
|
-
})
|
|
598
|
-
|
|
650
|
+
retryActionsByDefault: true,
|
|
651
|
+
});
|
|
652
|
+
|
|
599
653
|
return {
|
|
600
654
|
enqueueTask: (ctx, priority, action, args) =>
|
|
601
655
|
Effect.gen(function* () {
|
|
602
|
-
const pool = priority === "high" ? highPriorityPool : lowPriorityPool
|
|
603
|
-
|
|
656
|
+
const pool = priority === "high" ? highPriorityPool : lowPriorityPool;
|
|
657
|
+
|
|
604
658
|
const taskId = yield* Effect.tryPromise({
|
|
605
|
-
try: () =>
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
659
|
+
try: () =>
|
|
660
|
+
pool.enqueueAction(ctx, action, args, {
|
|
661
|
+
onComplete: internal.tasks.handleCompletion,
|
|
662
|
+
context: { priority },
|
|
663
|
+
}),
|
|
664
|
+
catch: (error) => new EnqueueError({ cause: error }),
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
return taskId;
|
|
613
668
|
}),
|
|
614
|
-
|
|
669
|
+
|
|
615
670
|
getTaskStatus: (ctx, taskId) =>
|
|
616
671
|
Effect.tryPromise({
|
|
617
|
-
try: () =>
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
)
|
|
672
|
+
try: () =>
|
|
673
|
+
highPriorityPool
|
|
674
|
+
.status(taskId)
|
|
675
|
+
.then((status) => status ?? lowPriorityPool.status(taskId)),
|
|
676
|
+
catch: () => new StatusError({ taskId }),
|
|
677
|
+
}),
|
|
678
|
+
};
|
|
679
|
+
}),
|
|
680
|
+
);
|
|
625
681
|
```
|
|
626
682
|
|
|
627
683
|
#### Pattern: Batch Task Enqueuing with Effect
|
|
@@ -631,25 +687,25 @@ export const processBatch = mutation({
|
|
|
631
687
|
args: { items: v.array(v.any()) },
|
|
632
688
|
handler: (ctx, args) =>
|
|
633
689
|
Effect.gen(function* () {
|
|
634
|
-
const taskQueue = yield* TaskQueueService
|
|
635
|
-
|
|
690
|
+
const taskQueue = yield* TaskQueueService;
|
|
691
|
+
|
|
636
692
|
// Enqueue all tasks in parallel
|
|
637
693
|
const taskIds = yield* Effect.all(
|
|
638
|
-
args.items.map(item =>
|
|
639
|
-
taskQueue.enqueueTask(ctx, "low", internal.tasks.processItem, item)
|
|
694
|
+
args.items.map((item) =>
|
|
695
|
+
taskQueue.enqueueTask(ctx, "low", internal.tasks.processItem, item),
|
|
640
696
|
),
|
|
641
|
-
{ concurrency: 10 }
|
|
642
|
-
)
|
|
643
|
-
|
|
644
|
-
return { taskIds, count: taskIds.length }
|
|
697
|
+
{ concurrency: 10 },
|
|
698
|
+
);
|
|
699
|
+
|
|
700
|
+
return { taskIds, count: taskIds.length };
|
|
645
701
|
}).pipe(
|
|
646
702
|
Effect.provide(TaskQueueServiceLive),
|
|
647
703
|
Effect.catchAll((error) => {
|
|
648
|
-
console.error("Batch processing failed:", error)
|
|
649
|
-
return Effect.succeed({ taskIds: [], count: 0, error: true })
|
|
650
|
-
})
|
|
651
|
-
)
|
|
652
|
-
})
|
|
704
|
+
console.error("Batch processing failed:", error);
|
|
705
|
+
return Effect.succeed({ taskIds: [], count: 0, error: true });
|
|
706
|
+
}),
|
|
707
|
+
),
|
|
708
|
+
});
|
|
653
709
|
```
|
|
654
710
|
|
|
655
711
|
---
|
|
@@ -663,56 +719,63 @@ export const processBatch = mutation({
|
|
|
663
719
|
#### Pattern: Effect Services in Workflow Steps
|
|
664
720
|
|
|
665
721
|
```typescript
|
|
666
|
-
import { WorkflowManager } from "@convex-dev/workflow"
|
|
667
|
-
import { Effect } from "effect"
|
|
722
|
+
import { WorkflowManager } from "@convex-dev/workflow";
|
|
723
|
+
import { Effect } from "effect";
|
|
668
724
|
|
|
669
725
|
const workflow = new WorkflowManager(components.workflow, {
|
|
670
726
|
defaultRetryBehavior: {
|
|
671
727
|
maxAttempts: 3,
|
|
672
728
|
initialBackoffMs: 1000,
|
|
673
|
-
base: 2
|
|
674
|
-
}
|
|
675
|
-
})
|
|
729
|
+
base: 2,
|
|
730
|
+
},
|
|
731
|
+
});
|
|
676
732
|
|
|
677
733
|
export const aiAgentWorkflow = workflow.define({
|
|
678
734
|
args: { userId: v.string(), prompt: v.string() },
|
|
679
735
|
handler: async (step, args): Promise<WorkflowResult> => {
|
|
680
736
|
// Step 1: Fetch user context (query)
|
|
681
|
-
const userContext = await step.runQuery(
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
737
|
+
const userContext = await step.runQuery(internal.workflows.getUserContext, {
|
|
738
|
+
userId: args.userId,
|
|
739
|
+
});
|
|
740
|
+
|
|
686
741
|
// Step 2: Generate initial response with Effect composition (action)
|
|
687
742
|
const initialResponse = await step.runAction(
|
|
688
743
|
internal.workflows.generateResponseWithEffect,
|
|
689
|
-
{ prompt: args.prompt, context: userContext }
|
|
690
|
-
)
|
|
691
|
-
|
|
744
|
+
{ prompt: args.prompt, context: userContext },
|
|
745
|
+
);
|
|
746
|
+
|
|
692
747
|
// Step 3: Quality check in parallel (actions)
|
|
693
748
|
const [grammarScore, factualityScore] = await Promise.all([
|
|
694
|
-
step.runAction(internal.workflows.checkGrammar, {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
749
|
+
step.runAction(internal.workflows.checkGrammar, {
|
|
750
|
+
text: initialResponse,
|
|
751
|
+
}),
|
|
752
|
+
step.runAction(internal.workflows.checkFactuality, {
|
|
753
|
+
text: initialResponse,
|
|
754
|
+
}),
|
|
755
|
+
]);
|
|
756
|
+
|
|
698
757
|
// Step 4: Refine if needed (action with conditional logic)
|
|
699
|
-
const finalResponse =
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
758
|
+
const finalResponse =
|
|
759
|
+
grammarScore < 0.8 || factualityScore < 0.8
|
|
760
|
+
? await step.runAction(
|
|
761
|
+
internal.workflows.refineResponse,
|
|
762
|
+
{ original: initialResponse, context: userContext },
|
|
763
|
+
{ retry: { maxAttempts: 2 } },
|
|
764
|
+
)
|
|
765
|
+
: initialResponse;
|
|
766
|
+
|
|
707
767
|
// Step 5: Save result (mutation)
|
|
708
|
-
await step.runMutation(
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
)
|
|
712
|
-
|
|
713
|
-
return {
|
|
714
|
-
|
|
715
|
-
|
|
768
|
+
await step.runMutation(internal.workflows.saveResult, {
|
|
769
|
+
userId: args.userId,
|
|
770
|
+
response: finalResponse,
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
return {
|
|
774
|
+
response: finalResponse,
|
|
775
|
+
refined: finalResponse !== initialResponse,
|
|
776
|
+
};
|
|
777
|
+
},
|
|
778
|
+
});
|
|
716
779
|
|
|
717
780
|
// The action called by the workflow uses Effect internally
|
|
718
781
|
export const generateResponseWithEffect = internalAction({
|
|
@@ -720,33 +783,34 @@ export const generateResponseWithEffect = internalAction({
|
|
|
720
783
|
handler: async (ctx, args) => {
|
|
721
784
|
// Use Effect for business logic composition
|
|
722
785
|
const program = Effect.gen(function* () {
|
|
723
|
-
const agentService = yield* AgentService
|
|
724
|
-
const ragService = yield* RAGService
|
|
725
|
-
|
|
786
|
+
const agentService = yield* AgentService;
|
|
787
|
+
const ragService = yield* RAGService;
|
|
788
|
+
|
|
726
789
|
// Enrich context with RAG
|
|
727
|
-
const enrichedContext = yield* ragService.search(args.prompt)
|
|
728
|
-
|
|
790
|
+
const enrichedContext = yield* ragService.search(args.prompt);
|
|
791
|
+
|
|
729
792
|
// Generate with agent
|
|
730
|
-
const response = yield* agentService.generateResponse(
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
793
|
+
const response = yield* agentService.generateResponse(ctx, args.prompt, {
|
|
794
|
+
...args.context,
|
|
795
|
+
rag: enrichedContext,
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
return response;
|
|
799
|
+
});
|
|
800
|
+
|
|
739
801
|
return await Effect.runPromise(
|
|
740
802
|
program.pipe(
|
|
741
803
|
Effect.provide(Layer.merge(AgentServiceLive, RAGServiceLive)),
|
|
742
804
|
Effect.catchAll((error) => {
|
|
743
|
-
console.error("Generation failed:", error)
|
|
744
|
-
return Effect.succeed(
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
805
|
+
console.error("Generation failed:", error);
|
|
806
|
+
return Effect.succeed(
|
|
807
|
+
"I apologize, but I'm having trouble generating a response.",
|
|
808
|
+
);
|
|
809
|
+
}),
|
|
810
|
+
),
|
|
811
|
+
);
|
|
812
|
+
},
|
|
813
|
+
});
|
|
750
814
|
```
|
|
751
815
|
|
|
752
816
|
**Key Pattern**: Workflow component handles durability and retry at the step level. Use Effect within actions for business logic composition and error handling.
|
|
@@ -762,9 +826,9 @@ export const generateResponseWithEffect = internalAction({
|
|
|
762
826
|
#### Pattern: Effect Service Layer for RAG
|
|
763
827
|
|
|
764
828
|
```typescript
|
|
765
|
-
import { RAG } from "@convex-dev/rag"
|
|
766
|
-
import { openai } from "@ai-sdk/openai"
|
|
767
|
-
import { Effect } from "effect"
|
|
829
|
+
import { RAG } from "@convex-dev/rag";
|
|
830
|
+
import { openai } from "@ai-sdk/openai";
|
|
831
|
+
import { Effect } from "effect";
|
|
768
832
|
|
|
769
833
|
class RAGService extends Context.Tag("RAGService")<
|
|
770
834
|
RAGService,
|
|
@@ -773,15 +837,15 @@ class RAGService extends Context.Tag("RAGService")<
|
|
|
773
837
|
ctx: ActionCtx,
|
|
774
838
|
namespace: string,
|
|
775
839
|
content: string,
|
|
776
|
-
metadata: Record<string, any
|
|
777
|
-
) => Effect.Effect<string, RAGError
|
|
778
|
-
|
|
840
|
+
metadata: Record<string, any>,
|
|
841
|
+
) => Effect.Effect<string, RAGError>;
|
|
842
|
+
|
|
779
843
|
readonly search: (
|
|
780
844
|
ctx: ActionCtx,
|
|
781
845
|
namespace: string,
|
|
782
846
|
query: string,
|
|
783
|
-
limit?: number
|
|
784
|
-
) => Effect.Effect<SearchResults, RAGError
|
|
847
|
+
limit?: number,
|
|
848
|
+
) => Effect.Effect<SearchResults, RAGError>;
|
|
785
849
|
}
|
|
786
850
|
>() {}
|
|
787
851
|
|
|
@@ -790,46 +854,48 @@ const RAGServiceLive = Layer.effect(
|
|
|
790
854
|
Effect.gen(function* () {
|
|
791
855
|
const rag = new RAG(components.rag, {
|
|
792
856
|
textEmbeddingModel: openai.embedding("text-embedding-3-small"),
|
|
793
|
-
embeddingDimension: 1536
|
|
794
|
-
})
|
|
795
|
-
|
|
857
|
+
embeddingDimension: 1536,
|
|
858
|
+
});
|
|
859
|
+
|
|
796
860
|
return {
|
|
797
861
|
addDocument: (ctx, namespace, content, metadata) =>
|
|
798
862
|
Effect.gen(function* () {
|
|
799
863
|
// Pre-process content with Effect
|
|
800
|
-
const processed = yield* preprocessContent(content)
|
|
801
|
-
|
|
864
|
+
const processed = yield* preprocessContent(content);
|
|
865
|
+
|
|
802
866
|
// Add to RAG
|
|
803
867
|
const entryId = yield* Effect.tryPromise({
|
|
804
|
-
try: () =>
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
name,
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
868
|
+
try: () =>
|
|
869
|
+
rag.add(ctx, {
|
|
870
|
+
namespace,
|
|
871
|
+
text: processed,
|
|
872
|
+
filterValues: Object.entries(metadata).map(([name, value]) => ({
|
|
873
|
+
name,
|
|
874
|
+
value,
|
|
875
|
+
})),
|
|
876
|
+
onComplete: internal.rag.handleComplete,
|
|
877
|
+
}),
|
|
878
|
+
catch: (error) => new RAGAddError({ cause: error }),
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
return entryId.entryId;
|
|
817
882
|
}),
|
|
818
|
-
|
|
883
|
+
|
|
819
884
|
search: (ctx, namespace, query, limit = 10) =>
|
|
820
885
|
Effect.tryPromise({
|
|
821
|
-
try: () =>
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
)
|
|
886
|
+
try: () =>
|
|
887
|
+
rag.search(ctx, {
|
|
888
|
+
namespace,
|
|
889
|
+
query,
|
|
890
|
+
limit,
|
|
891
|
+
chunkContext: { before: 1, after: 1 },
|
|
892
|
+
vectorScoreThreshold: 0.6,
|
|
893
|
+
}),
|
|
894
|
+
catch: (error) => new RAGSearchError({ cause: error }),
|
|
895
|
+
}),
|
|
896
|
+
};
|
|
897
|
+
}),
|
|
898
|
+
);
|
|
833
899
|
```
|
|
834
900
|
|
|
835
901
|
#### Pattern: Composing RAG with Agent Using Effect
|
|
@@ -840,44 +906,44 @@ export const contextualAnswerAgent = action({
|
|
|
840
906
|
args: { userId: v.string(), question: v.string() },
|
|
841
907
|
handler: (ctx, args) =>
|
|
842
908
|
Effect.gen(function* () {
|
|
843
|
-
const ragService = yield* RAGService
|
|
844
|
-
const agentService = yield* AgentService
|
|
845
|
-
|
|
909
|
+
const ragService = yield* RAGService;
|
|
910
|
+
const agentService = yield* AgentService;
|
|
911
|
+
|
|
846
912
|
// Fetch relevant context
|
|
847
913
|
const searchResults = yield* ragService.search(
|
|
848
914
|
ctx,
|
|
849
915
|
args.userId, // User-specific namespace
|
|
850
916
|
args.question,
|
|
851
|
-
8
|
|
852
|
-
)
|
|
853
|
-
|
|
917
|
+
8,
|
|
918
|
+
);
|
|
919
|
+
|
|
854
920
|
// Generate answer with context
|
|
855
921
|
const answer = yield* agentService.generateWithContext(
|
|
856
922
|
ctx,
|
|
857
923
|
args.question,
|
|
858
|
-
searchResults.text
|
|
859
|
-
)
|
|
860
|
-
|
|
924
|
+
searchResults.text,
|
|
925
|
+
);
|
|
926
|
+
|
|
861
927
|
return {
|
|
862
928
|
answer,
|
|
863
|
-
sources: searchResults.entries.map(e => ({
|
|
929
|
+
sources: searchResults.entries.map((e) => ({
|
|
864
930
|
id: e.entryId,
|
|
865
931
|
title: e.title,
|
|
866
|
-
relevance: e.score
|
|
867
|
-
}))
|
|
868
|
-
}
|
|
932
|
+
relevance: e.score,
|
|
933
|
+
})),
|
|
934
|
+
};
|
|
869
935
|
}).pipe(
|
|
870
936
|
Effect.provide(Layer.merge(RAGServiceLive, AgentServiceLive)),
|
|
871
937
|
Effect.catchAll((error) => {
|
|
872
|
-
console.error("Contextual answer failed:", error)
|
|
938
|
+
console.error("Contextual answer failed:", error);
|
|
873
939
|
return Effect.succeed({
|
|
874
940
|
answer: "I'm having trouble finding relevant information.",
|
|
875
941
|
sources: [],
|
|
876
|
-
error: true
|
|
877
|
-
})
|
|
878
|
-
})
|
|
879
|
-
)
|
|
880
|
-
})
|
|
942
|
+
error: true,
|
|
943
|
+
});
|
|
944
|
+
}),
|
|
945
|
+
),
|
|
946
|
+
});
|
|
881
947
|
```
|
|
882
948
|
|
|
883
949
|
---
|
|
@@ -891,60 +957,60 @@ export const contextualAnswerAgent = action({
|
|
|
891
957
|
#### Pattern: Effect-Based Cron Job Logic
|
|
892
958
|
|
|
893
959
|
```typescript
|
|
894
|
-
import { Crons } from "@convex-dev/crons"
|
|
895
|
-
import { Effect } from "effect"
|
|
960
|
+
import { Crons } from "@convex-dev/crons";
|
|
961
|
+
import { Effect } from "effect";
|
|
896
962
|
|
|
897
963
|
// Register cron that executes Effect-based business logic
|
|
898
964
|
export const setupDailyCron = internalMutation({
|
|
899
965
|
handler: async (ctx) => {
|
|
900
|
-
const crons = new Crons(components.crons)
|
|
901
|
-
|
|
966
|
+
const crons = new Crons(components.crons);
|
|
967
|
+
|
|
902
968
|
await crons.register(
|
|
903
969
|
ctx,
|
|
904
970
|
{ kind: "cron", cronspec: "0 0 * * *" }, // Daily at midnight
|
|
905
971
|
internal.crons.dailyMaintenanceWithEffect,
|
|
906
972
|
{},
|
|
907
|
-
"daily-maintenance"
|
|
908
|
-
)
|
|
909
|
-
}
|
|
910
|
-
})
|
|
973
|
+
"daily-maintenance",
|
|
974
|
+
);
|
|
975
|
+
},
|
|
976
|
+
});
|
|
911
977
|
|
|
912
978
|
// Cron job uses Effect for composition
|
|
913
979
|
export const dailyMaintenanceWithEffect = internalAction({
|
|
914
980
|
handler: async (ctx) => {
|
|
915
981
|
const program = Effect.gen(function* () {
|
|
916
|
-
const ragService = yield* RAGService
|
|
917
|
-
const monitoringService = yield* MonitoringService
|
|
918
|
-
|
|
982
|
+
const ragService = yield* RAGService;
|
|
983
|
+
const monitoringService = yield* MonitoringService;
|
|
984
|
+
|
|
919
985
|
// Clean up old content
|
|
920
986
|
yield* Effect.tryPromise({
|
|
921
987
|
try: () => ctx.runMutation(internal.rag.cleanupOldContent, {}),
|
|
922
|
-
catch: () => new CleanupError()
|
|
923
|
-
})
|
|
924
|
-
|
|
988
|
+
catch: () => new CleanupError(),
|
|
989
|
+
});
|
|
990
|
+
|
|
925
991
|
// Generate daily report
|
|
926
|
-
const report = yield* monitoringService.generateDailyReport(ctx)
|
|
927
|
-
|
|
992
|
+
const report = yield* monitoringService.generateDailyReport(ctx);
|
|
993
|
+
|
|
928
994
|
// Send to admin
|
|
929
995
|
yield* Effect.tryPromise({
|
|
930
996
|
try: () => ctx.runAction(internal.email.sendReport, { report }),
|
|
931
|
-
catch: () => new EmailError()
|
|
932
|
-
})
|
|
933
|
-
|
|
934
|
-
return { success: true, report }
|
|
935
|
-
})
|
|
936
|
-
|
|
997
|
+
catch: () => new EmailError(),
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
return { success: true, report };
|
|
1001
|
+
});
|
|
1002
|
+
|
|
937
1003
|
await Effect.runPromise(
|
|
938
1004
|
program.pipe(
|
|
939
1005
|
Effect.provide(Layer.merge(RAGServiceLive, MonitoringServiceLive)),
|
|
940
1006
|
Effect.catchAll((error) => {
|
|
941
|
-
console.error("Daily maintenance failed:", error)
|
|
942
|
-
return Effect.succeed({ success: false, error })
|
|
943
|
-
})
|
|
944
|
-
)
|
|
945
|
-
)
|
|
946
|
-
}
|
|
947
|
-
})
|
|
1007
|
+
console.error("Daily maintenance failed:", error);
|
|
1008
|
+
return Effect.succeed({ success: false, error });
|
|
1009
|
+
}),
|
|
1010
|
+
),
|
|
1011
|
+
);
|
|
1012
|
+
},
|
|
1013
|
+
});
|
|
948
1014
|
```
|
|
949
1015
|
|
|
950
1016
|
---
|
|
@@ -974,18 +1040,18 @@ export const dailyMaintenanceWithEffect = internalAction({
|
|
|
974
1040
|
|
|
975
1041
|
```typescript
|
|
976
1042
|
// convex/schema.ts - Define schema with Effect Schema
|
|
977
|
-
import { Id, defineSchema, defineTable } from "@rjdellecese/confect/server"
|
|
978
|
-
import { Schema } from "effect"
|
|
1043
|
+
import { Id, defineSchema, defineTable } from "@rjdellecese/confect/server";
|
|
1044
|
+
import { Schema } from "effect";
|
|
979
1045
|
|
|
980
1046
|
export const confectSchema = defineSchema({
|
|
981
1047
|
users: defineTable(
|
|
982
1048
|
Schema.Struct({
|
|
983
1049
|
username: Schema.String,
|
|
984
1050
|
email: Schema.String.pipe(Schema.maxLength(100)),
|
|
985
|
-
role: Schema.Literal("admin", "user")
|
|
986
|
-
})
|
|
1051
|
+
role: Schema.Literal("admin", "user"),
|
|
1052
|
+
}),
|
|
987
1053
|
),
|
|
988
|
-
|
|
1054
|
+
|
|
989
1055
|
threads: defineTable(
|
|
990
1056
|
Schema.Struct({
|
|
991
1057
|
userId: Id.Id("users"),
|
|
@@ -993,14 +1059,14 @@ export const confectSchema = defineSchema({
|
|
|
993
1059
|
messages: Schema.Array(
|
|
994
1060
|
Schema.Struct({
|
|
995
1061
|
role: Schema.Literal("user", "assistant"),
|
|
996
|
-
content: Schema.String
|
|
997
|
-
})
|
|
998
|
-
)
|
|
999
|
-
})
|
|
1000
|
-
).index("by_user", ["userId"])
|
|
1001
|
-
})
|
|
1062
|
+
content: Schema.String,
|
|
1063
|
+
}),
|
|
1064
|
+
),
|
|
1065
|
+
}),
|
|
1066
|
+
).index("by_user", ["userId"]),
|
|
1067
|
+
});
|
|
1002
1068
|
|
|
1003
|
-
export default confectSchema.convexSchemaDefinition
|
|
1069
|
+
export default confectSchema.convexSchemaDefinition;
|
|
1004
1070
|
```
|
|
1005
1071
|
|
|
1006
1072
|
```typescript
|
|
@@ -1012,41 +1078,54 @@ import {
|
|
|
1012
1078
|
type ConfectMutationCtx as ConfectMutationCtxType,
|
|
1013
1079
|
ConfectQueryCtx as ConfectQueryCtxService,
|
|
1014
1080
|
type ConfectQueryCtx as ConfectQueryCtxType,
|
|
1015
|
-
makeFunctions
|
|
1016
|
-
} from "@rjdellecese/confect/server"
|
|
1081
|
+
makeFunctions,
|
|
1082
|
+
} from "@rjdellecese/confect/server";
|
|
1017
1083
|
|
|
1018
|
-
import { confectSchema } from "./schema"
|
|
1084
|
+
import { confectSchema } from "./schema";
|
|
1019
1085
|
|
|
1020
|
-
export const {
|
|
1021
|
-
|
|
1086
|
+
export const {
|
|
1087
|
+
query,
|
|
1088
|
+
mutation,
|
|
1089
|
+
action,
|
|
1090
|
+
internalQuery,
|
|
1091
|
+
internalMutation,
|
|
1092
|
+
internalAction,
|
|
1093
|
+
} = makeFunctions(confectSchema);
|
|
1022
1094
|
|
|
1023
|
-
type ConfectDataModel = ConfectDataModelFromConfectSchemaDefinition<
|
|
1095
|
+
type ConfectDataModel = ConfectDataModelFromConfectSchemaDefinition<
|
|
1096
|
+
typeof confectSchema
|
|
1097
|
+
>;
|
|
1024
1098
|
|
|
1025
|
-
export const ConfectQueryCtx = ConfectQueryCtxService<ConfectDataModel>()
|
|
1026
|
-
export type ConfectQueryCtx = ConfectQueryCtxType<ConfectDataModel
|
|
1099
|
+
export const ConfectQueryCtx = ConfectQueryCtxService<ConfectDataModel>();
|
|
1100
|
+
export type ConfectQueryCtx = ConfectQueryCtxType<ConfectDataModel>;
|
|
1027
1101
|
|
|
1028
|
-
export const ConfectMutationCtx = ConfectMutationCtxService<ConfectDataModel>()
|
|
1029
|
-
export type ConfectMutationCtx = ConfectMutationCtxType<ConfectDataModel
|
|
1102
|
+
export const ConfectMutationCtx = ConfectMutationCtxService<ConfectDataModel>();
|
|
1103
|
+
export type ConfectMutationCtx = ConfectMutationCtxType<ConfectDataModel>;
|
|
1030
1104
|
|
|
1031
|
-
export const ConfectActionCtx = ConfectActionCtxService<ConfectDataModel>()
|
|
1032
|
-
export type ConfectActionCtx = ConfectActionCtxType<ConfectDataModel
|
|
1105
|
+
export const ConfectActionCtx = ConfectActionCtxService<ConfectDataModel>();
|
|
1106
|
+
export type ConfectActionCtx = ConfectActionCtxType<ConfectDataModel>;
|
|
1033
1107
|
```
|
|
1034
1108
|
|
|
1035
1109
|
```typescript
|
|
1036
1110
|
// convex/users.ts - Write functions with Effect
|
|
1037
|
-
import { Effect, Option } from "effect"
|
|
1038
|
-
import {
|
|
1039
|
-
|
|
1111
|
+
import { Effect, Option } from "effect";
|
|
1112
|
+
import {
|
|
1113
|
+
ConfectMutationCtx,
|
|
1114
|
+
ConfectQueryCtx,
|
|
1115
|
+
mutation,
|
|
1116
|
+
query,
|
|
1117
|
+
} from "./confect";
|
|
1118
|
+
import { Schema } from "effect";
|
|
1040
1119
|
|
|
1041
1120
|
// Define args and returns with Effect Schema
|
|
1042
1121
|
const CreateUserArgs = Schema.Struct({
|
|
1043
1122
|
username: Schema.String,
|
|
1044
|
-
email: Schema.String
|
|
1045
|
-
})
|
|
1123
|
+
email: Schema.String,
|
|
1124
|
+
});
|
|
1046
1125
|
|
|
1047
1126
|
const CreateUserResult = Schema.Struct({
|
|
1048
|
-
userId: Schema.String
|
|
1049
|
-
})
|
|
1127
|
+
userId: Schema.String,
|
|
1128
|
+
});
|
|
1050
1129
|
|
|
1051
1130
|
export const createUser = mutation({
|
|
1052
1131
|
args: CreateUserArgs,
|
|
@@ -1054,24 +1133,28 @@ export const createUser = mutation({
|
|
|
1054
1133
|
handler: ({ username, email }) =>
|
|
1055
1134
|
Effect.gen(function* () {
|
|
1056
1135
|
// Inject Convex context via Effect
|
|
1057
|
-
const { db } = yield* ConfectMutationCtx
|
|
1058
|
-
|
|
1136
|
+
const { db } = yield* ConfectMutationCtx;
|
|
1137
|
+
|
|
1059
1138
|
// Database operations return Effects, not Promises
|
|
1060
1139
|
const existing = yield* db
|
|
1061
1140
|
.query("users")
|
|
1062
|
-
.withIndex("by_username", q => q.eq("username", username))
|
|
1063
|
-
.first()
|
|
1064
|
-
|
|
1141
|
+
.withIndex("by_username", (q) => q.eq("username", username))
|
|
1142
|
+
.first();
|
|
1143
|
+
|
|
1065
1144
|
// Option<Doc<"users">> instead of Doc<"users"> | null
|
|
1066
1145
|
if (Option.isSome(existing)) {
|
|
1067
|
-
return yield* Effect.fail(new UserAlreadyExistsError({ username }))
|
|
1146
|
+
return yield* Effect.fail(new UserAlreadyExistsError({ username }));
|
|
1068
1147
|
}
|
|
1069
|
-
|
|
1070
|
-
const userId = yield* db.insert("users", {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
})
|
|
1148
|
+
|
|
1149
|
+
const userId = yield* db.insert("users", {
|
|
1150
|
+
username,
|
|
1151
|
+
email,
|
|
1152
|
+
role: "user",
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
return { userId };
|
|
1156
|
+
}),
|
|
1157
|
+
});
|
|
1075
1158
|
```
|
|
1076
1159
|
|
|
1077
1160
|
### Confect + Convex Components Pattern
|
|
@@ -1098,13 +1181,13 @@ const ConvexAgentServiceLive = Layer.effect(
|
|
|
1098
1181
|
chat: openai.chat("gpt-4o"),
|
|
1099
1182
|
instructions: "You are a helpful assistant."
|
|
1100
1183
|
})
|
|
1101
|
-
|
|
1184
|
+
|
|
1102
1185
|
return {
|
|
1103
1186
|
createThread: (ctx, userId) =>
|
|
1104
1187
|
Effect.gen(function* () {
|
|
1105
1188
|
// Convert ConfectActionCtx to native Convex context
|
|
1106
1189
|
const nativeCtx = ctx // Confect provides compatible context
|
|
1107
|
-
|
|
1190
|
+
|
|
1108
1191
|
const result = yield* Effect.tryPromise({
|
|
1109
1192
|
try: async () => {
|
|
1110
1193
|
const { threadId } = await agent.createThread(nativeCtx, { userId })
|
|
@@ -1112,7 +1195,7 @@ const ConvexAgentServiceLive = Layer.effect(
|
|
|
1112
1195
|
},
|
|
1113
1196
|
catch: (error) => new AgentError({ cause: error })
|
|
1114
1197
|
})
|
|
1115
|
-
|
|
1198
|
+
|
|
1116
1199
|
return result
|
|
1117
1200
|
})
|
|
1118
1201
|
}
|
|
@@ -1185,7 +1268,7 @@ class SupportAgentService extends Context.Tag("SupportAgentService")<
|
|
|
1185
1268
|
userId: string,
|
|
1186
1269
|
issue: string
|
|
1187
1270
|
) => Effect.Effect<ThreadResult, AgentError>
|
|
1188
|
-
|
|
1271
|
+
|
|
1189
1272
|
readonly continueSupportThread: (
|
|
1190
1273
|
ctx: ActionCtx,
|
|
1191
1274
|
threadId: string,
|
|
@@ -1199,7 +1282,7 @@ const SupportAgentServiceLive = Layer.effect(
|
|
|
1199
1282
|
Effect.gen(function* () {
|
|
1200
1283
|
const ragService = yield* RAGService
|
|
1201
1284
|
const rateLimitService = yield* RateLimitService
|
|
1202
|
-
|
|
1285
|
+
|
|
1203
1286
|
const agent = new Agent(components.agent, {
|
|
1204
1287
|
name: "Support Agent",
|
|
1205
1288
|
chat: openai.chat("gpt-4o-mini"),
|
|
@@ -1219,7 +1302,7 @@ const SupportAgentServiceLive = Layer.effect(
|
|
|
1219
1302
|
await ctx.runMutation(internal.billing.trackUsage, args)
|
|
1220
1303
|
}
|
|
1221
1304
|
})
|
|
1222
|
-
|
|
1305
|
+
|
|
1223
1306
|
return {
|
|
1224
1307
|
createSupportThread: (ctx, userId, issue) =>
|
|
1225
1308
|
Effect.gen(function* () {
|
|
@@ -1228,13 +1311,13 @@ const SupportAgentServiceLive = Layer.effect(
|
|
|
1228
1311
|
if (!rateLimitOk) {
|
|
1229
1312
|
return yield* Effect.fail(new RateLimitError())
|
|
1230
1313
|
}
|
|
1231
|
-
|
|
1314
|
+
|
|
1232
1315
|
// Fetch user context
|
|
1233
1316
|
const userContext = yield* Effect.tryPromise({
|
|
1234
1317
|
try: () => ctx.runQuery(api.users.getContext, { userId }),
|
|
1235
1318
|
catch: () => new ContextFetchError()
|
|
1236
1319
|
})
|
|
1237
|
-
|
|
1320
|
+
|
|
1238
1321
|
// Create thread
|
|
1239
1322
|
const result = yield* Effect.tryPromise({
|
|
1240
1323
|
try: async () => {
|
|
@@ -1246,10 +1329,10 @@ const SupportAgentServiceLive = Layer.effect(
|
|
|
1246
1329
|
},
|
|
1247
1330
|
catch: (error) => new AgentError({ cause: error })
|
|
1248
1331
|
})
|
|
1249
|
-
|
|
1332
|
+
|
|
1250
1333
|
return result
|
|
1251
1334
|
}),
|
|
1252
|
-
|
|
1335
|
+
|
|
1253
1336
|
continueSupportThread: (ctx, threadId, message) =>
|
|
1254
1337
|
Effect.gen(function* () {
|
|
1255
1338
|
const result = yield* Effect.tryPromise({
|
|
@@ -1260,7 +1343,7 @@ const SupportAgentServiceLive = Layer.effect(
|
|
|
1260
1343
|
},
|
|
1261
1344
|
catch: (error) => new AgentError({ cause: error })
|
|
1262
1345
|
})
|
|
1263
|
-
|
|
1346
|
+
|
|
1264
1347
|
return result
|
|
1265
1348
|
})
|
|
1266
1349
|
}
|
|
@@ -1273,14 +1356,14 @@ export const createSupportTicket = action({
|
|
|
1273
1356
|
handler: (ctx, args) =>
|
|
1274
1357
|
Effect.gen(function* () {
|
|
1275
1358
|
const supportAgent = yield* SupportAgentService
|
|
1276
|
-
|
|
1359
|
+
|
|
1277
1360
|
// Create thread with agent
|
|
1278
1361
|
const threadResult = yield* supportAgent.createSupportThread(
|
|
1279
1362
|
ctx,
|
|
1280
1363
|
args.userId,
|
|
1281
1364
|
args.issue
|
|
1282
1365
|
)
|
|
1283
|
-
|
|
1366
|
+
|
|
1284
1367
|
// Save to database
|
|
1285
1368
|
yield* Effect.tryPromise({
|
|
1286
1369
|
try: () => ctx.runMutation(internal.tickets.create, {
|
|
@@ -1290,7 +1373,7 @@ export const createSupportTicket = action({
|
|
|
1290
1373
|
}),
|
|
1291
1374
|
catch: () => new DatabaseError()
|
|
1292
1375
|
})
|
|
1293
|
-
|
|
1376
|
+
|
|
1294
1377
|
return threadResult
|
|
1295
1378
|
}).pipe(
|
|
1296
1379
|
Effect.provide(Layer.merge(
|
|
@@ -1320,16 +1403,16 @@ export const researchWorkflow = workflow.define({
|
|
|
1320
1403
|
// Step 1: Classify query type
|
|
1321
1404
|
const classification = await step.runAction(
|
|
1322
1405
|
internal.research.classifyQueryWithEffect,
|
|
1323
|
-
{ query: args.query }
|
|
1324
|
-
)
|
|
1325
|
-
|
|
1406
|
+
{ query: args.query },
|
|
1407
|
+
);
|
|
1408
|
+
|
|
1326
1409
|
// Step 2: Parallel research with multiple agents
|
|
1327
1410
|
const [webResults, academicResults, newsResults] = await Promise.all([
|
|
1328
1411
|
step.runAction(internal.research.webSearchAgent, { query: args.query }),
|
|
1329
1412
|
step.runAction(internal.research.academicAgent, { query: args.query }),
|
|
1330
|
-
step.runAction(internal.research.newsAgent, { query: args.query })
|
|
1331
|
-
])
|
|
1332
|
-
|
|
1413
|
+
step.runAction(internal.research.newsAgent, { query: args.query }),
|
|
1414
|
+
]);
|
|
1415
|
+
|
|
1333
1416
|
// Step 3: Synthesize findings
|
|
1334
1417
|
const synthesis = await step.runAction(
|
|
1335
1418
|
internal.research.synthesisAgentWithEffect,
|
|
@@ -1337,58 +1420,60 @@ export const researchWorkflow = workflow.define({
|
|
|
1337
1420
|
query: args.query,
|
|
1338
1421
|
webResults,
|
|
1339
1422
|
academicResults,
|
|
1340
|
-
newsResults
|
|
1341
|
-
}
|
|
1342
|
-
)
|
|
1343
|
-
|
|
1423
|
+
newsResults,
|
|
1424
|
+
},
|
|
1425
|
+
);
|
|
1426
|
+
|
|
1344
1427
|
// Step 4: Generate final report
|
|
1345
1428
|
const report = await step.runAction(
|
|
1346
1429
|
internal.research.reportGeneratorWithEffect,
|
|
1347
|
-
{ synthesis, classification }
|
|
1348
|
-
)
|
|
1349
|
-
|
|
1430
|
+
{ synthesis, classification },
|
|
1431
|
+
);
|
|
1432
|
+
|
|
1350
1433
|
// Step 5: Save and notify
|
|
1351
1434
|
await step.runMutation(internal.research.saveReport, {
|
|
1352
1435
|
userId: args.userId,
|
|
1353
1436
|
query: args.query,
|
|
1354
|
-
report
|
|
1355
|
-
})
|
|
1356
|
-
|
|
1357
|
-
return report
|
|
1358
|
-
}
|
|
1359
|
-
})
|
|
1437
|
+
report,
|
|
1438
|
+
});
|
|
1439
|
+
|
|
1440
|
+
return report;
|
|
1441
|
+
},
|
|
1442
|
+
});
|
|
1360
1443
|
|
|
1361
1444
|
export const synthesisAgentWithEffect = internalAction({
|
|
1362
|
-
args: {
|
|
1445
|
+
args: {
|
|
1446
|
+
/* ... */
|
|
1447
|
+
},
|
|
1363
1448
|
handler: async (ctx, args) => {
|
|
1364
1449
|
const program = Effect.gen(function* () {
|
|
1365
|
-
const agentService = yield* AgentService
|
|
1366
|
-
const ragService = yield* RAGService
|
|
1367
|
-
|
|
1450
|
+
const agentService = yield* AgentService;
|
|
1451
|
+
const ragService = yield* RAGService;
|
|
1452
|
+
|
|
1368
1453
|
// Fetch relevant background context
|
|
1369
|
-
const background = yield* ragService.search(ctx, "global", args.query, 5)
|
|
1370
|
-
|
|
1454
|
+
const background = yield* ragService.search(ctx, "global", args.query, 5);
|
|
1455
|
+
|
|
1371
1456
|
// Synthesize with agent
|
|
1372
1457
|
const synthesis = yield* agentService.generateResponse(
|
|
1373
1458
|
ctx,
|
|
1374
|
-
`Synthesize these research findings:\n\n${formatResults(args)}\n\nBackground: ${background.text}
|
|
1375
|
-
)
|
|
1376
|
-
|
|
1377
|
-
return synthesis
|
|
1378
|
-
})
|
|
1379
|
-
|
|
1459
|
+
`Synthesize these research findings:\n\n${formatResults(args)}\n\nBackground: ${background.text}`,
|
|
1460
|
+
);
|
|
1461
|
+
|
|
1462
|
+
return synthesis;
|
|
1463
|
+
});
|
|
1464
|
+
|
|
1380
1465
|
return await Effect.runPromise(
|
|
1381
1466
|
program.pipe(
|
|
1382
1467
|
Effect.provide(Layer.merge(AgentServiceLive, RAGServiceLive)),
|
|
1383
1468
|
Effect.retry(
|
|
1384
1469
|
Schedule.exponential("1 second").pipe(
|
|
1385
|
-
Schedule.compose(Schedule.recurs(3))
|
|
1386
|
-
)
|
|
1387
|
-
)
|
|
1388
|
-
)
|
|
1389
|
-
)
|
|
1390
|
-
}
|
|
1391
|
-
})
|
|
1470
|
+
Schedule.compose(Schedule.recurs(3)),
|
|
1471
|
+
),
|
|
1472
|
+
),
|
|
1473
|
+
),
|
|
1474
|
+
);
|
|
1475
|
+
},
|
|
1476
|
+
});
|
|
1392
1477
|
```
|
|
1393
1478
|
|
|
1394
1479
|
---
|
|
@@ -1402,37 +1487,37 @@ export const synthesisAgentWithEffect = internalAction({
|
|
|
1402
1487
|
```typescript
|
|
1403
1488
|
// Domain errors (typed)
|
|
1404
1489
|
class UserNotFoundError extends Data.TaggedError("UserNotFoundError")<{
|
|
1405
|
-
userId: string
|
|
1490
|
+
userId: string;
|
|
1406
1491
|
}> {}
|
|
1407
1492
|
|
|
1408
1493
|
// Infrastructure errors (typed)
|
|
1409
1494
|
class AgentError extends Data.TaggedError("AgentError")<{
|
|
1410
|
-
agentName: string
|
|
1411
|
-
cause: unknown
|
|
1495
|
+
agentName: string;
|
|
1496
|
+
cause: unknown;
|
|
1412
1497
|
}> {}
|
|
1413
1498
|
|
|
1414
1499
|
// Handle at appropriate layer
|
|
1415
1500
|
Effect.gen(function* () {
|
|
1416
|
-
const result = yield* agentService.generateResponse(/* ... */)
|
|
1417
|
-
return result
|
|
1501
|
+
const result = yield* agentService.generateResponse(/* ... */);
|
|
1502
|
+
return result;
|
|
1418
1503
|
}).pipe(
|
|
1419
1504
|
// Handle domain errors specifically
|
|
1420
1505
|
Effect.catchTag("UserNotFoundError", (error) =>
|
|
1421
|
-
Effect.succeed({ error: "User not found" })
|
|
1506
|
+
Effect.succeed({ error: "User not found" }),
|
|
1422
1507
|
),
|
|
1423
1508
|
// Handle infrastructure errors with retry
|
|
1424
1509
|
Effect.catchTag("AgentError", (error) =>
|
|
1425
1510
|
Effect.retry(
|
|
1426
1511
|
Effect.fail(error),
|
|
1427
|
-
Schedule.exponential("1 second").pipe(Schedule.recurs(2))
|
|
1428
|
-
)
|
|
1512
|
+
Schedule.exponential("1 second").pipe(Schedule.recurs(2)),
|
|
1513
|
+
),
|
|
1429
1514
|
),
|
|
1430
1515
|
// Catch-all for unexpected errors
|
|
1431
1516
|
Effect.catchAll((error) => {
|
|
1432
|
-
console.error("Unexpected error:", error)
|
|
1433
|
-
return Effect.succeed({ error: "Something went wrong" })
|
|
1434
|
-
})
|
|
1435
|
-
)
|
|
1517
|
+
console.error("Unexpected error:", error);
|
|
1518
|
+
return Effect.succeed({ error: "Something went wrong" });
|
|
1519
|
+
}),
|
|
1520
|
+
);
|
|
1436
1521
|
```
|
|
1437
1522
|
|
|
1438
1523
|
### Monitoring and Observability
|
|
@@ -1443,51 +1528,49 @@ Effect.gen(function* () {
|
|
|
1443
1528
|
class MonitoringService extends Context.Tag("MonitoringService")<
|
|
1444
1529
|
MonitoringService,
|
|
1445
1530
|
{
|
|
1446
|
-
readonly trackAgentUsage: (data: UsageData) => Effect.Effect<void
|
|
1447
|
-
readonly trackError: (error: unknown) => Effect.Effect<void
|
|
1531
|
+
readonly trackAgentUsage: (data: UsageData) => Effect.Effect<void>;
|
|
1532
|
+
readonly trackError: (error: unknown) => Effect.Effect<void>;
|
|
1448
1533
|
}
|
|
1449
1534
|
>() {}
|
|
1450
1535
|
|
|
1451
1536
|
const MonitoringServiceLive = Layer.succeed(MonitoringService, {
|
|
1452
1537
|
trackAgentUsage: (data) =>
|
|
1453
1538
|
Effect.sync(() => {
|
|
1454
|
-
console.log("Agent usage:", data)
|
|
1539
|
+
console.log("Agent usage:", data);
|
|
1455
1540
|
// Send to analytics service
|
|
1456
1541
|
}),
|
|
1457
|
-
|
|
1542
|
+
|
|
1458
1543
|
trackError: (error) =>
|
|
1459
1544
|
Effect.sync(() => {
|
|
1460
|
-
console.error("Error tracked:", error)
|
|
1545
|
+
console.error("Error tracked:", error);
|
|
1461
1546
|
// Send to error tracking service
|
|
1462
|
-
})
|
|
1463
|
-
})
|
|
1547
|
+
}),
|
|
1548
|
+
});
|
|
1464
1549
|
|
|
1465
1550
|
// Wrap service calls with monitoring
|
|
1466
1551
|
const monitoredAgentCall = (
|
|
1467
1552
|
agentService: AgentService,
|
|
1468
1553
|
ctx: ActionCtx,
|
|
1469
|
-
prompt: string
|
|
1554
|
+
prompt: string,
|
|
1470
1555
|
) =>
|
|
1471
1556
|
Effect.gen(function* () {
|
|
1472
|
-
const monitoring = yield* MonitoringService
|
|
1473
|
-
|
|
1474
|
-
const startTime = Date.now()
|
|
1475
|
-
|
|
1557
|
+
const monitoring = yield* MonitoringService;
|
|
1558
|
+
|
|
1559
|
+
const startTime = Date.now();
|
|
1560
|
+
|
|
1476
1561
|
const result = yield* agentService.generateResponse(ctx, prompt).pipe(
|
|
1477
1562
|
Effect.tap((response) =>
|
|
1478
1563
|
monitoring.trackAgentUsage({
|
|
1479
1564
|
duration: Date.now() - startTime,
|
|
1480
1565
|
tokenCount: response.usage.totalTokens,
|
|
1481
|
-
model: "gpt-4o-mini"
|
|
1482
|
-
})
|
|
1566
|
+
model: "gpt-4o-mini",
|
|
1567
|
+
}),
|
|
1483
1568
|
),
|
|
1484
|
-
Effect.tapError((error) =>
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
return result
|
|
1490
|
-
})
|
|
1569
|
+
Effect.tapError((error) => monitoring.trackError(error)),
|
|
1570
|
+
);
|
|
1571
|
+
|
|
1572
|
+
return result;
|
|
1573
|
+
});
|
|
1491
1574
|
```
|
|
1492
1575
|
|
|
1493
1576
|
### Testing Strategies
|
|
@@ -1500,31 +1583,32 @@ const TestAgentServiceLive = Layer.succeed(AgentService, {
|
|
|
1500
1583
|
generateResponse: (ctx, prompt) =>
|
|
1501
1584
|
Effect.succeed({
|
|
1502
1585
|
text: "Mock response",
|
|
1503
|
-
usage: { totalTokens: 100, promptTokens: 50, completionTokens: 50 }
|
|
1586
|
+
usage: { totalTokens: 100, promptTokens: 50, completionTokens: 50 },
|
|
1504
1587
|
}),
|
|
1505
|
-
|
|
1506
|
-
createThread: (ctx, userId) =>
|
|
1507
|
-
|
|
1508
|
-
})
|
|
1588
|
+
|
|
1589
|
+
createThread: (ctx, userId) => Effect.succeed({ threadId: "test-thread-id" }),
|
|
1590
|
+
});
|
|
1509
1591
|
|
|
1510
1592
|
// Test with mock
|
|
1511
1593
|
describe("Support Agent", () => {
|
|
1512
1594
|
it("should create support ticket", async () => {
|
|
1513
|
-
const program = createSupportTicket({ userId: "123", issue: "Help!" })
|
|
1514
|
-
|
|
1595
|
+
const program = createSupportTicket({ userId: "123", issue: "Help!" });
|
|
1596
|
+
|
|
1515
1597
|
const result = await Effect.runPromise(
|
|
1516
1598
|
program.pipe(
|
|
1517
|
-
Effect.provide(
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1599
|
+
Effect.provide(
|
|
1600
|
+
Layer.merge(
|
|
1601
|
+
TestAgentServiceLive,
|
|
1602
|
+
TestRAGServiceLive,
|
|
1603
|
+
TestRateLimitServiceLive,
|
|
1604
|
+
),
|
|
1605
|
+
),
|
|
1606
|
+
),
|
|
1607
|
+
);
|
|
1608
|
+
|
|
1609
|
+
expect(result.threadId).toBe("test-thread-id");
|
|
1610
|
+
});
|
|
1611
|
+
});
|
|
1528
1612
|
```
|
|
1529
1613
|
|
|
1530
1614
|
### Resource Management
|
|
@@ -1534,23 +1618,23 @@ describe("Support Agent", () => {
|
|
|
1534
1618
|
```typescript
|
|
1535
1619
|
// Use Effect.Scope for resource lifecycle
|
|
1536
1620
|
const withAgentPool = <A, E>(
|
|
1537
|
-
program: Effect.Effect<A, E, AgentService
|
|
1621
|
+
program: Effect.Effect<A, E, AgentService>,
|
|
1538
1622
|
): Effect.Effect<A, E> =>
|
|
1539
1623
|
Effect.scoped(
|
|
1540
1624
|
Effect.gen(function* () {
|
|
1541
1625
|
// Acquire agents
|
|
1542
1626
|
const agentPool = yield* Effect.acquireRelease(
|
|
1543
1627
|
Effect.sync(() => createAgentPool(10)),
|
|
1544
|
-
(pool) => Effect.sync(() => pool.shutdown())
|
|
1545
|
-
)
|
|
1546
|
-
|
|
1628
|
+
(pool) => Effect.sync(() => pool.shutdown()),
|
|
1629
|
+
);
|
|
1630
|
+
|
|
1547
1631
|
// Provide service
|
|
1548
|
-
const service = yield* AgentService
|
|
1549
|
-
|
|
1632
|
+
const service = yield* AgentService;
|
|
1633
|
+
|
|
1550
1634
|
// Run program
|
|
1551
|
-
return yield* program
|
|
1552
|
-
})
|
|
1553
|
-
)
|
|
1635
|
+
return yield* program;
|
|
1636
|
+
}),
|
|
1637
|
+
);
|
|
1554
1638
|
```
|
|
1555
1639
|
|
|
1556
1640
|
### Performance Optimization
|
|
@@ -1564,21 +1648,16 @@ export const processBatchWithEffect = action({
|
|
|
1564
1648
|
handler: (ctx, args) =>
|
|
1565
1649
|
Effect.gen(function* () {
|
|
1566
1650
|
const results = yield* Effect.all(
|
|
1567
|
-
args.items.map(item =>
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
}).pipe(
|
|
1578
|
-
Effect.provide(/* ... */),
|
|
1579
|
-
Effect.runPromise
|
|
1580
|
-
)
|
|
1581
|
-
})
|
|
1651
|
+
args.items.map((item) => processItemWithEffect(ctx, item)),
|
|
1652
|
+
{
|
|
1653
|
+
concurrency: 5, // Limit concurrent operations
|
|
1654
|
+
mode: "default", // Fail fast on first error
|
|
1655
|
+
},
|
|
1656
|
+
);
|
|
1657
|
+
|
|
1658
|
+
return { results, count: results.length };
|
|
1659
|
+
}).pipe(Effect.provide(/* ... */), Effect.runPromise),
|
|
1660
|
+
});
|
|
1582
1661
|
```
|
|
1583
1662
|
|
|
1584
1663
|
---
|
|
@@ -1588,15 +1667,10 @@ export const processBatchWithEffect = action({
|
|
|
1588
1667
|
### Architecture Decisions
|
|
1589
1668
|
|
|
1590
1669
|
1. **Start with Manual Effect Integration**: Don't adopt Confect initially. Use the wrapper patterns shown above to integrate Effect gradually.
|
|
1591
|
-
|
|
1592
1670
|
2. **Use Components for Infrastructure**: Let Convex components handle durability, retries, and rate limiting. Use Effect for business logic.
|
|
1593
|
-
|
|
1594
1671
|
3. **Service Layer with Effect**: Build a service layer using Effect's Context and Layer patterns for testability and composition.
|
|
1595
|
-
|
|
1596
1672
|
4. **Agent Component + Workflow**: Use @convex-dev/agent for AI capabilities and @convex-dev/workflow for long-running operations.
|
|
1597
|
-
|
|
1598
1673
|
5. **RAG with Effect Services**: Wrap @convex-dev/rag in an Effect service for composable context retrieval.
|
|
1599
|
-
|
|
1600
1674
|
|
|
1601
1675
|
### Astro Integration
|
|
1602
1676
|
|
|
@@ -1623,7 +1697,7 @@ export function withConvexProvider<Props>(
|
|
|
1623
1697
|
export default withConvexProvider(function ChatInterface() {
|
|
1624
1698
|
const messages = useQuery(api.chat.listMessages, { threadId })
|
|
1625
1699
|
const sendMessage = useMutation(api.chat.sendMessage)
|
|
1626
|
-
|
|
1700
|
+
|
|
1627
1701
|
// Your UI code
|
|
1628
1702
|
})
|
|
1629
1703
|
```
|
|
@@ -1666,4 +1740,4 @@ Effect.ts and Confect enhance Convex's already powerful platform for building AI
|
|
|
1666
1740
|
- Sophisticated error recovery
|
|
1667
1741
|
- Composable multi-agent orchestration
|
|
1668
1742
|
|
|
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.
|
|
1743
|
+
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.
|