oneie 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +245 -0
- package/CLAUDE.md +534 -0
- package/one/.obsidian/app.json +1 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/workspace.json +211 -0
- package/one/connections/a2a.md +551 -0
- package/one/connections/acp.md +761 -0
- package/one/connections/acps.md +731 -0
- package/one/connections/agui.md +767 -0
- package/one/connections/any-backend.md +1702 -0
- package/one/connections/ap2.md +998 -0
- package/one/connections/api-docs.md +1891 -0
- package/one/connections/api.md +2190 -0
- package/one/connections/architecture-diagram.md +94 -0
- package/one/connections/communications.md +449 -0
- package/one/connections/connections.md +339 -0
- package/one/connections/cryptonetworks.md +781 -0
- package/one/connections/documentation.md +1120 -0
- package/one/connections/effect.md +279 -0
- package/one/connections/elizaos.md +1290 -0
- package/one/connections/inference.md +58 -0
- package/one/connections/kyc.md +632 -0
- package/one/connections/mcp.md +842 -0
- package/one/connections/membership.md +1152 -0
- package/one/connections/middleware.md +1067 -0
- package/one/connections/multitenant.md +1341 -0
- package/one/connections/n8n.md +1015 -0
- package/one/connections/patterns.md +89 -0
- package/one/connections/protocols.md +279 -0
- package/one/connections/relationships.md +107 -0
- package/one/connections/schema.md +587 -0
- package/one/connections/service-layer.md +550 -0
- package/one/connections/structure.md +0 -0
- package/one/connections/vectors.md +207 -0
- package/one/connections/wordpress.md +1302 -0
- package/one/connections/workflow-copy.md +905 -0
- package/one/connections/workflow-examples.md +741 -0
- package/one/connections/workflow.md +905 -0
- package/one/connections/workflows/delegation.md +885 -0
- package/one/connections/workflows/frontend.md +1037 -0
- package/one/connections/workflows/strategy.md +903 -0
- package/one/connections/workflows/tasks.md +698 -0
- package/one/connections/x402.md +1249 -0
- package/one/events/events.md +545 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-diagram.md +94 -0
- package/one/knowledge/architecture-frontend.md +930 -0
- package/one/knowledge/architecture.md +2077 -0
- package/one/knowledge/crypto.md +960 -0
- package/one/knowledge/dsl.md +1660 -0
- package/one/knowledge/files.md +2471 -0
- package/one/knowledge/frontend.md +1038 -0
- package/one/knowledge/hono.md +2109 -0
- package/one/knowledge/implementation-examples.md +2536 -0
- package/one/knowledge/inference-score.md +159 -0
- package/one/knowledge/knowledge.md +642 -0
- package/one/knowledge/language.md +980 -0
- package/one/knowledge/lessons-learned.md +70 -0
- package/one/knowledge/ontology-6-dimensions.md +0 -0
- package/one/knowledge/ontology-documentation.md +356 -0
- package/one/knowledge/ontology-engineering-specification.md +1292 -0
- package/one/knowledge/ontology-engineering.md +1652 -0
- package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
- package/one/knowledge/ontology-frontend-copy.md +753 -0
- package/one/knowledge/ontology-frontend-specifications.md +2188 -0
- package/one/knowledge/ontology-frontend.md +2427 -0
- package/one/knowledge/ontology-minimal.yaml +299 -0
- package/one/knowledge/ontology.md +2819 -0
- package/one/knowledge/ontology.yaml +1165 -0
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
- package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
- package/one/knowledge/patterns/backend/mutation-template.md +231 -0
- package/one/knowledge/patterns/backend/query-template.md +267 -0
- package/one/knowledge/patterns/backend/service-template.md +237 -0
- package/one/knowledge/patterns/design/component-architecture.md +399 -0
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
- package/one/knowledge/patterns/design/wireframe-template.md +216 -0
- package/one/knowledge/patterns/frontend/component-template.md +195 -0
- package/one/knowledge/patterns/frontend/form-template.md +276 -0
- package/one/knowledge/patterns/frontend/page-template.md +178 -0
- package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
- package/one/knowledge/patterns/test/technical-test-template.md +544 -0
- package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
- package/one/knowledge/patterns/test/user-flow-template.md +254 -0
- package/one/knowledge/quality-loop.md +401 -0
- package/one/knowledge/readme.md +131 -0
- package/one/knowledge/rules.md +626 -0
- package/one/knowledge/score.md +67 -0
- package/one/knowledge/specifications.md +855 -0
- package/one/knowledge/tags.md +130 -0
- package/one/organisation/one.md +599 -0
- package/one/organisation/organisation.md +438 -0
- package/one/organisation/revenue.md +673 -0
- package/one/organisation/strategy.md +869 -0
- package/one/organisation/vision.md +98 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/repomix-output.md +92634 -0
- package/one/things/agentkit.md +349 -0
- package/one/things/agents/agent-backend.md +1401 -0
- package/one/things/agents/agent-builder.md +955 -0
- package/one/things/agents/agent-clean.md +709 -0
- package/one/things/agents/agent-clone.md +1341 -0
- package/one/things/agents/agent-designer.md +2177 -0
- package/one/things/agents/agent-director.md +1508 -0
- package/one/things/agents/agent-documenter.md +1049 -0
- package/one/things/agents/agent-frontend.md +1119 -0
- package/one/things/agents/agent-integrator.md +1192 -0
- package/one/things/agents/agent-problem-solver.md +1379 -0
- package/one/things/agents/agent-quality.md +1353 -0
- package/one/things/agents/agent-sales.md +986 -0
- package/one/things/cascade/cascade.yaml +464 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
- package/one/things/cascade/docs/examples/readme.md +222 -0
- package/one/things/cascade/docs/getting-started.md +515 -0
- package/one/things/cascade/docs/workflow.md +1372 -0
- package/one/things/cascade/readme.md +336 -0
- package/one/things/cascade/templates/feature-template.md +267 -0
- package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
- package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
- package/one/things/claude/agents/analyst.md +483 -0
- package/one/things/claude/agents/architect.md +480 -0
- package/one/things/claude/agents/brand-identity-specialist.md +513 -0
- package/one/things/claude/agents/bstp-token-strategist.md +667 -0
- package/one/things/claude/agents/builder-repo.md +489 -0
- package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
- package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
- package/one/things/claude/agents/company-bullstamp-character.md +587 -0
- package/one/things/claude/agents/company-bullstamp-community.md +292 -0
- package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
- package/one/things/claude/agents/company-bullstamp-token.md +292 -0
- package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
- package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
- package/one/things/claude/agents/content-calendar-planner.md +448 -0
- package/one/things/claude/agents/content-chapter-formatter.md +488 -0
- package/one/things/claude/agents/content-formatter.md +546 -0
- package/one/things/claude/agents/content-hook-specialist.md +462 -0
- package/one/things/claude/agents/content-image-formatter.md +535 -0
- package/one/things/claude/agents/content-introduction-formatter.md +485 -0
- package/one/things/claude/agents/content-multiplication-engine.md +556 -0
- package/one/things/claude/agents/content-playbook-writer.md +448 -0
- package/one/things/claude/agents/content-team-manager.md +622 -0
- package/one/things/claude/agents/content-toc-formatter.md +522 -0
- package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
- package/one/things/claude/agents/core-manager.md +582 -0
- package/one/things/claude/agents/core-master.md +403 -0
- package/one/things/claude/agents/cross-functional-manager.md +471 -0
- package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
- package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
- package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
- package/one/things/claude/agents/crypto-community-analyst.md +298 -0
- package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
- package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
- package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
- package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
- package/one/things/claude/agents/crypto-market-researcher.md +292 -0
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
- package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
- package/one/things/claude/agents/crypto-team-manager.md +387 -0
- package/one/things/claude/agents/crypto-token-analyst.md +278 -0
- package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
- package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
- package/one/things/claude/agents/customer-journey-designer.md +481 -0
- package/one/things/claude/agents/customer-success-manager.md +581 -0
- package/one/things/claude/agents/dev.md +413 -0
- package/one/things/claude/agents/documenter.md +546 -0
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
- package/one/things/claude/agents/engagement-specialist.md +509 -0
- package/one/things/claude/agents/engineering-architect.md +387 -0
- package/one/things/claude/agents/engineering-business-analyst.md +537 -0
- package/one/things/claude/agents/engineering-developer.md +387 -0
- package/one/things/claude/agents/engineering-director.md +282 -0
- package/one/things/claude/agents/engineering-ingestor.md +649 -0
- package/one/things/claude/agents/engineering-product-manager.md +537 -0
- package/one/things/claude/agents/engineering-product-owner.md +537 -0
- package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
- package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
- package/one/things/claude/agents/engineering-team-manager.md +512 -0
- package/one/things/claude/agents/engineering-user-experience.md +387 -0
- package/one/things/claude/agents/framework-elevate-manager.md +294 -0
- package/one/things/claude/agents/improver.md +763 -0
- package/one/things/claude/agents/intelligence-team-manager.md +385 -0
- package/one/things/claude/agents/lead-capture-expert.md +466 -0
- package/one/things/claude/agents/lead-magnet-creator.md +453 -0
- package/one/things/claude/agents/market-research-analyst.md +412 -0
- package/one/things/claude/agents/marketing-brand-identity.md +314 -0
- package/one/things/claude/agents/marketing-content-hooks.md +450 -0
- package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
- package/one/things/claude/agents/marketing-content-poster.md +361 -0
- package/one/things/claude/agents/marketing-customer-journey.md +326 -0
- package/one/things/claude/agents/marketing-director.md +397 -0
- package/one/things/claude/agents/marketing-engagement.md +326 -0
- package/one/things/claude/agents/marketing-lead-capture.md +326 -0
- package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
- package/one/things/claude/agents/marketing-network-effects.md +326 -0
- package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
- package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
- package/one/things/claude/agents/marketing-team-manager.md +446 -0
- package/one/things/claude/agents/marketing-viral-growth.md +201 -0
- package/one/things/claude/agents/mission-commander.md +373 -0
- package/one/things/claude/agents/network-effect-analyst.md +587 -0
- package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
- package/one/things/claude/agents/npx.md +890 -0
- package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
- package/one/things/claude/agents/one-master.md +355 -0
- package/one/things/claude/agents/one-orchestrator.md +315 -0
- package/one/things/claude/agents/one.md +601 -0
- package/one/things/claude/agents/playbook-generator.md +503 -0
- package/one/things/claude/agents/pm.md +326 -0
- package/one/things/claude/agents/po.md +345 -0
- package/one/things/claude/agents/qa.md +336 -0
- package/one/things/claude/agents/research-foundation-analyst.md +307 -0
- package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
- package/one/things/claude/agents/research-market-analyst.md +307 -0
- package/one/things/claude/agents/research-team-manager.md +482 -0
- package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
- package/one/things/claude/agents/sales-team-manager.md +400 -0
- package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
- package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
- package/one/things/claude/agents/service-advocacy-manager.md +307 -0
- package/one/things/claude/agents/service-success-manager.md +307 -0
- package/one/things/claude/agents/service-team-manager.md +400 -0
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
- package/one/things/claude/agents/share-optimization-specialist.md +551 -0
- package/one/things/claude/agents/sm.md +327 -0
- package/one/things/claude/agents/story-teller.md +473 -0
- package/one/things/claude/agents/task-master.md +596 -0
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
- package/one/things/claude/agents/tester.md +556 -0
- package/one/things/claude/agents/the-bull-character-manager.md +580 -0
- package/one/things/claude/agents/tools-playbook-generator.md +489 -0
- package/one/things/claude/agents/turbo-repo-builder.md +316 -0
- package/one/things/claude/agents/upsell-strategist.md +480 -0
- package/one/things/claude/agents/ux-expert.md +335 -0
- package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
- package/one/things/claude/claude-code-hooks-development.json +21 -0
- package/one/things/claude/claude-code-hooks-production.json +21 -0
- package/one/things/claude/claude-code-hooks.json +25 -0
- package/one/things/claude/commands/agent.md +104 -0
- package/one/things/claude/commands/cascade-status.md +128 -0
- package/one/things/claude/commands/ingest.md +290 -0
- package/one/things/claude/commands/ingestor.md +136 -0
- package/one/things/claude/commands/mission.md +83 -0
- package/one/things/claude/commands/npx.md +133 -0
- package/one/things/claude/commands/one.md +440 -0
- package/one/things/claude/commands/quality-check.md +204 -0
- package/one/things/claude/commands/smart-route.md +220 -0
- package/one/things/claude/commands/start.md +121 -0
- package/one/things/claude/commands/story.md +83 -0
- package/one/things/claude/commands/task.md +173 -0
- package/one/things/claude/hook-bypass.json +32 -0
- package/one/things/claude/hooks/agent-hook-config.json +427 -0
- package/one/things/claude/hooks/agent-hook-manager.js +525 -0
- package/one/things/claude/hooks/agent-load-balancer.js +271 -0
- package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
- package/one/things/claude/hooks/build-hook.sh +156 -0
- package/one/things/claude/hooks/cascade-feedback.js +297 -0
- package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
- package/one/things/claude/hooks/cleanup-hook.sh +201 -0
- package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
- package/one/things/claude/hooks/file-organization-engine.js +427 -0
- package/one/things/claude/hooks/file-organization-hook.sh +80 -0
- package/one/things/claude/hooks/file-organization-monitor.js +269 -0
- package/one/things/claude/hooks/format-hook.sh +43 -0
- package/one/things/claude/hooks/hook-bypass.sh +293 -0
- package/one/things/claude/hooks/hook-config-manager.js +202 -0
- package/one/things/claude/hooks/hook-debouncer.sh +62 -0
- package/one/things/claude/hooks/hook-logger.sh +89 -0
- package/one/things/claude/hooks/hook-orchestrator.js +662 -0
- package/one/things/claude/hooks/hook-performance-report.js +120 -0
- package/one/things/claude/hooks/lint-hook.sh +140 -0
- package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
- package/one/things/claude/hooks/memory-optimizer.js +510 -0
- package/one/things/claude/hooks/notification-hook.sh +204 -0
- package/one/things/claude/hooks/ontology-compliance.js +394 -0
- package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
- package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
- package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
- package/one/things/claude/hooks/performance-metrics.json +25 -0
- package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
- package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
- package/one/things/claude/hooks/security-hook.sh +256 -0
- package/one/things/claude/hooks/simple-load-balancer.js +238 -0
- package/one/things/claude/hooks/startup-optimizer.js +625 -0
- package/one/things/claude/hooks/story-scoring-system.js +445 -0
- package/one/things/claude/hooks/story-validation-engine.js +473 -0
- package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
- package/one/things/claude/hooks/story-validation-hook.sh +145 -0
- package/one/things/claude/hooks/structure-synchronizer.js +194 -0
- package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
- package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
- package/one/things/claude/hooks/test-hook.sh +145 -0
- package/one/things/claude/hooks/test-story-validation.sh +170 -0
- package/one/things/claude/hooks/trinity-validation-system.js +392 -0
- package/one/things/claude/settings-local.json +86 -0
- package/one/things/cli-code.md +652 -0
- package/one/things/cli-compiler-code.md +652 -0
- package/one/things/cli.md +1045 -0
- package/one/things/components/card-shadcn.md +929 -0
- package/one/things/components/card.md +1050 -0
- package/one/things/components.md +1669 -0
- package/one/things/componets.md +4 -0
- package/one/things/copilotkit.md +1559 -0
- package/one/things/creator-diagram.md +166 -0
- package/one/things/examples/children/lemonade-stand.md +366 -0
- package/one/things/examples/enterprise/crm-saas.md +1429 -0
- package/one/things/features/1-1-agent-prompts/design.md +470 -0
- package/one/things/features/1-1-agent-prompts/tests.md +264 -0
- package/one/things/features/1-1-agent-prompts.md +486 -0
- package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/features/1-2-yaml-orchestrator.md +516 -0
- package/one/things/features/1-3-event-coordination/design.md +544 -0
- package/one/things/features/1-3-event-coordination/tests.md +223 -0
- package/one/things/features/1-3-event-coordination.md +508 -0
- package/one/things/features/1-4-knowledge-management/design.md +609 -0
- package/one/things/features/1-4-knowledge-management/tests.md +195 -0
- package/one/things/features/1-4-knowledge-management.md +577 -0
- package/one/things/features/1-5-quality-loops/design.md +797 -0
- package/one/things/features/1-5-quality-loops/tests.md +212 -0
- package/one/things/features/1-5-quality-loops.md +641 -0
- package/one/things/features/1-6-numbering-structure/design.md +610 -0
- package/one/things/features/1-6-numbering-structure/tests.md +213 -0
- package/one/things/features/1-6-numbering-structure.md +575 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/plans/1-create-workflow-status.md +555 -0
- package/one/things/plans/1-create-workflow.md +713 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
- package/one/things/plans/better-auth-any-backend.md +1852 -0
- package/one/things/plans/better-auth-available-features.md +235 -0
- package/one/things/plans/big-plan.md +38 -0
- package/one/things/plans/convex-better-auth.md +1109 -0
- package/one/things/plans/convex-on-off.md +389 -0
- package/one/things/plans/desktop.md +1121 -0
- package/one/things/plans/effect-components.md +1669 -0
- package/one/things/plans/effect.md +973 -0
- package/one/things/plans/email.md +953 -0
- package/one/things/plans/enhance-auth.md +1669 -0
- package/one/things/plans/install-components.md +198 -0
- package/one/things/plans/landing.md +728 -0
- package/one/things/plans/layout.md +205 -0
- package/one/things/plans/mail-backend.md +1308 -0
- package/one/things/plans/mail.md +2624 -0
- package/one/things/plans/next-features.md +83 -0
- package/one/things/plans/one.md +658 -0
- package/one/things/plans/ontology-6-dimensions.md +2216 -0
- package/one/things/plans/ontology-driven-strategy.md +866 -0
- package/one/things/plans/ontology-ui-approach.md +357 -0
- package/one/things/plans/open-agent.md +785 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/releases.md +809 -0
- package/one/things/plans/repos.md +76 -0
- package/one/things/plans/separate-copy-2.md +1293 -0
- package/one/things/plans/separate-copy-3.md +2458 -0
- package/one/things/plans/separate-copy.md +1293 -0
- package/one/things/plans/separate.md +1983 -0
- package/one/things/plans/shadcn-integration-summary.md +450 -0
- package/one/things/plans/sidebar.md +172 -0
- package/one/things/plans/small-fixes.md +5 -0
- package/one/things/plans/test-backend-connection.md +476 -0
- package/one/things/plans/workflow-files.md +1196 -0
- package/one/things/plans/workflow.md +1372 -0
- package/one/things/products/cascade-landing-page.md +737 -0
- package/one/things/products/cascade.md +1518 -0
- package/one/things/products/context-engineering.md +1427 -0
- package/one/things/products/onthology.md +0 -0
- package/one/things/products/ontology-ui-shadcn.md +1280 -0
- package/one/things/products/ontology-ui.md +1387 -0
- package/one/things/products/ontology.md +717 -0
- package/one/things/products/sdk.md +557 -0
- package/one/things/promptkit.md +903 -0
- package/one/things/service-providers-new.md +982 -0
- package/one/things/service-providers.md +1092 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/package.json +5 -2
|
@@ -0,0 +1,2190 @@
|
|
|
1
|
+
# ONE Platform - API Reference
|
|
2
|
+
|
|
3
|
+
**Version:** 1.0.0
|
|
4
|
+
**Last Updated:** 2025-01-15
|
|
5
|
+
**Purpose:** Complete API reference for Convex backend, service layer, and external integrations
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
1. [Convex Backend API](#convex-backend-api)
|
|
12
|
+
2. [Effect.ts Service Layer](#effectts-service-layer)
|
|
13
|
+
3. [External Service Providers](#external-service-providers)
|
|
14
|
+
4. [Frontend Integration](#frontend-integration)
|
|
15
|
+
5. [Authentication API](#authentication-api)
|
|
16
|
+
6. [Schema Reference](#schema-reference)
|
|
17
|
+
7. [Error Handling](#error-handling)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Convex Backend API
|
|
22
|
+
|
|
23
|
+
### Core Function Types
|
|
24
|
+
|
|
25
|
+
The ONE platform uses Convex for real-time backend operations with three primary function types:
|
|
26
|
+
|
|
27
|
+
#### Queries (Read Operations)
|
|
28
|
+
|
|
29
|
+
**Purpose:** Read data, automatically cached, real-time reactive subscriptions
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// convex/queries/creators.ts
|
|
33
|
+
import { query } from "./_generated/server";
|
|
34
|
+
import { v } from "convex/values";
|
|
35
|
+
|
|
36
|
+
export const get = query({
|
|
37
|
+
args: { id: v.id("entities") },
|
|
38
|
+
handler: async (ctx, args) => {
|
|
39
|
+
const creator = await ctx.db.get(args.id);
|
|
40
|
+
|
|
41
|
+
if (!creator || creator.type !== "creator") {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get relationships
|
|
46
|
+
const contentConnections = await ctx.db
|
|
47
|
+
.query("connections")
|
|
48
|
+
.withIndex("from_type", q =>
|
|
49
|
+
q.eq("fromEntityId", args.id)
|
|
50
|
+
.eq("relationshipType", "authored")
|
|
51
|
+
)
|
|
52
|
+
.collect();
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...creator,
|
|
56
|
+
contentCount: contentConnections.length
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const list = query({
|
|
62
|
+
args: {
|
|
63
|
+
limit: v.optional(v.number()),
|
|
64
|
+
niche: v.optional(v.string())
|
|
65
|
+
},
|
|
66
|
+
handler: async (ctx, args) => {
|
|
67
|
+
let query = ctx.db
|
|
68
|
+
.query("entities")
|
|
69
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
70
|
+
.filter(q => q.eq(q.field("status"), "active"));
|
|
71
|
+
|
|
72
|
+
if (args.niche) {
|
|
73
|
+
query = query.filter(q =>
|
|
74
|
+
q.eq(q.field("properties.niche"), args.niche)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return await query.take(args.limit || 20);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Key Features:**
|
|
84
|
+
- Automatic caching and invalidation
|
|
85
|
+
- Real-time subscriptions (updates push to clients)
|
|
86
|
+
- Can run in parallel
|
|
87
|
+
- Read-only (no database modifications)
|
|
88
|
+
|
|
89
|
+
#### Mutations (Write Operations)
|
|
90
|
+
|
|
91
|
+
**Purpose:** Write/modify data, transactional (all-or-nothing), optimistic UI updates
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// convex/mutations/creators.ts
|
|
95
|
+
import { mutation } from "./_generated/server";
|
|
96
|
+
import { v } from "convex/values";
|
|
97
|
+
|
|
98
|
+
export const create = mutation({
|
|
99
|
+
args: {
|
|
100
|
+
email: v.string(),
|
|
101
|
+
name: v.string(),
|
|
102
|
+
niche: v.array(v.string())
|
|
103
|
+
},
|
|
104
|
+
handler: async (ctx, args) => {
|
|
105
|
+
// Check uniqueness
|
|
106
|
+
const existing = await ctx.db
|
|
107
|
+
.query("entities")
|
|
108
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
109
|
+
.filter(q => q.eq(q.field("properties.email"), args.email))
|
|
110
|
+
.first();
|
|
111
|
+
|
|
112
|
+
if (existing) {
|
|
113
|
+
throw new Error(`Creator with email ${args.email} already exists`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Create entity
|
|
117
|
+
const creatorId = await ctx.db.insert("entities", {
|
|
118
|
+
type: "creator",
|
|
119
|
+
name: args.name,
|
|
120
|
+
properties: {
|
|
121
|
+
email: args.email,
|
|
122
|
+
username: args.email.split("@")[0],
|
|
123
|
+
displayName: args.name,
|
|
124
|
+
niche: args.niche,
|
|
125
|
+
expertise: [],
|
|
126
|
+
totalFollowers: 0,
|
|
127
|
+
totalContent: 0,
|
|
128
|
+
totalRevenue: 0
|
|
129
|
+
},
|
|
130
|
+
status: "active",
|
|
131
|
+
createdAt: Date.now(),
|
|
132
|
+
updatedAt: Date.now()
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Log creation event
|
|
136
|
+
await ctx.db.insert("events", {
|
|
137
|
+
type: "creator_created",
|
|
138
|
+
actorId: creatorId,
|
|
139
|
+
timestamp: Date.now(),
|
|
140
|
+
metadata: {
|
|
141
|
+
email: args.email,
|
|
142
|
+
niche: args.niche
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return { creatorId };
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export const update = mutation({
|
|
151
|
+
args: {
|
|
152
|
+
id: v.id("entities"),
|
|
153
|
+
bio: v.optional(v.string()),
|
|
154
|
+
niche: v.optional(v.array(v.string())),
|
|
155
|
+
avatar: v.optional(v.string())
|
|
156
|
+
},
|
|
157
|
+
handler: async (ctx, args) => {
|
|
158
|
+
const { id, ...updates } = args;
|
|
159
|
+
|
|
160
|
+
const current = await ctx.db.get(id);
|
|
161
|
+
if (!current || current.type !== "creator") {
|
|
162
|
+
throw new Error("Creator not found");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Merge updates
|
|
166
|
+
const newProperties = {
|
|
167
|
+
...current.properties,
|
|
168
|
+
...updates
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
await ctx.db.patch(id, {
|
|
172
|
+
properties: newProperties,
|
|
173
|
+
updatedAt: Date.now()
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Log update event
|
|
177
|
+
await ctx.db.insert("events", {
|
|
178
|
+
type: "creator_updated",
|
|
179
|
+
actorId: id,
|
|
180
|
+
timestamp: Date.now(),
|
|
181
|
+
metadata: {
|
|
182
|
+
updatedFields: Object.keys(updates)
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return { success: true };
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Key Features:**
|
|
192
|
+
- Transactional (all succeed or all fail)
|
|
193
|
+
- Optimistic UI updates
|
|
194
|
+
- Validated with Convex validators
|
|
195
|
+
- Can schedule background actions
|
|
196
|
+
|
|
197
|
+
#### Actions (External API Calls)
|
|
198
|
+
|
|
199
|
+
**Purpose:** Call external services (OpenAI, Stripe, etc.), non-transactional, can be long-running
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// convex/actions/ai/clone-voice.ts
|
|
203
|
+
import { action } from "../../_generated/server";
|
|
204
|
+
import { v } from "convex/values";
|
|
205
|
+
import { api } from "../../_generated/api";
|
|
206
|
+
|
|
207
|
+
export const cloneVoice = action({
|
|
208
|
+
args: {
|
|
209
|
+
creatorId: v.id("entities"),
|
|
210
|
+
audioSamples: v.array(v.string())
|
|
211
|
+
},
|
|
212
|
+
handler: async (ctx, args) => {
|
|
213
|
+
// Call external ElevenLabs API
|
|
214
|
+
const response = await fetch("https://api.elevenlabs.io/v1/voices/add", {
|
|
215
|
+
method: "POST",
|
|
216
|
+
headers: {
|
|
217
|
+
"xi-api-key": process.env.ELEVENLABS_API_KEY!,
|
|
218
|
+
"Content-Type": "application/json",
|
|
219
|
+
},
|
|
220
|
+
body: JSON.stringify({
|
|
221
|
+
name: `Creator-${args.creatorId}`,
|
|
222
|
+
files: args.audioSamples,
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
throw new Error(`ElevenLabs API error: ${response.statusText}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const data = await response.json();
|
|
231
|
+
const voiceId = data.voice_id;
|
|
232
|
+
|
|
233
|
+
// Update creator entity with voice ID
|
|
234
|
+
await ctx.runMutation(api.creators.update, {
|
|
235
|
+
id: args.creatorId,
|
|
236
|
+
voiceId
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
return { voiceId };
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Key Features:**
|
|
245
|
+
- Can call external services
|
|
246
|
+
- Can call mutations/queries via `ctx.runMutation()` and `ctx.runQuery()`
|
|
247
|
+
- Not transactional (no automatic rollback)
|
|
248
|
+
- Access to `process.env` for secrets
|
|
249
|
+
|
|
250
|
+
#### Internal Functions
|
|
251
|
+
|
|
252
|
+
**Purpose:** Functions only callable from other Convex functions (not from clients)
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
// convex/auth.ts (internal functions)
|
|
256
|
+
import { internalMutation, internalAction } from "./_generated/server";
|
|
257
|
+
import { v } from "convex/values";
|
|
258
|
+
import { Resend } from "@convex-dev/resend";
|
|
259
|
+
import { components } from "./_generated/api";
|
|
260
|
+
|
|
261
|
+
export const createPasswordResetToken = internalMutation({
|
|
262
|
+
args: { email: v.string() },
|
|
263
|
+
handler: async (ctx, args) => {
|
|
264
|
+
const user = await ctx.db
|
|
265
|
+
.query("users")
|
|
266
|
+
.withIndex("by_email", q => q.eq("email", args.email))
|
|
267
|
+
.unique();
|
|
268
|
+
|
|
269
|
+
if (!user) return null;
|
|
270
|
+
|
|
271
|
+
const token = crypto.randomUUID();
|
|
272
|
+
const expires = Date.now() + 3600000; // 1 hour
|
|
273
|
+
|
|
274
|
+
await ctx.db.insert("verificationTokens", {
|
|
275
|
+
identifier: args.email,
|
|
276
|
+
token,
|
|
277
|
+
expires,
|
|
278
|
+
type: "password_reset"
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return { token, email: args.email };
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
export const sendPasswordResetEmailAction = internalAction({
|
|
286
|
+
args: { email: v.string(), resetLink: v.string() },
|
|
287
|
+
handler: async (ctx, args) => {
|
|
288
|
+
const resend = new Resend(components.resend, { testMode: false });
|
|
289
|
+
|
|
290
|
+
await resend.sendEmail(ctx, {
|
|
291
|
+
from: process.env.RESEND_FROM_EMAIL || "onboarding@resend.dev",
|
|
292
|
+
to: args.email,
|
|
293
|
+
subject: "Reset your password",
|
|
294
|
+
html: `
|
|
295
|
+
<h1>Reset your password</h1>
|
|
296
|
+
<p>Click the link below to reset your password:</p>
|
|
297
|
+
<a href="${args.resetLink}">Reset Password</a>
|
|
298
|
+
<p>This link expires in 1 hour.</p>
|
|
299
|
+
`,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Database Operations
|
|
306
|
+
|
|
307
|
+
#### Basic CRUD
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// Insert
|
|
311
|
+
const id = await ctx.db.insert("entities", {
|
|
312
|
+
type: "creator",
|
|
313
|
+
name: "John Doe",
|
|
314
|
+
properties: {},
|
|
315
|
+
status: "active",
|
|
316
|
+
createdAt: Date.now(),
|
|
317
|
+
updatedAt: Date.now()
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// Get by ID
|
|
321
|
+
const entity = await ctx.db.get(id);
|
|
322
|
+
|
|
323
|
+
// Update (partial)
|
|
324
|
+
await ctx.db.patch(id, {
|
|
325
|
+
properties: { bio: "Updated bio" },
|
|
326
|
+
updatedAt: Date.now()
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Replace (full)
|
|
330
|
+
await ctx.db.replace(id, {
|
|
331
|
+
type: "creator",
|
|
332
|
+
name: "John Doe",
|
|
333
|
+
properties: { bio: "New bio" },
|
|
334
|
+
status: "active",
|
|
335
|
+
createdAt: entity.createdAt,
|
|
336
|
+
updatedAt: Date.now()
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// Delete
|
|
340
|
+
await ctx.db.delete(id);
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
#### Queries with Indexes
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
// Query by index
|
|
347
|
+
const creators = await ctx.db
|
|
348
|
+
.query("entities")
|
|
349
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
350
|
+
.collect();
|
|
351
|
+
|
|
352
|
+
// Compound index query
|
|
353
|
+
const activeCreators = await ctx.db
|
|
354
|
+
.query("entities")
|
|
355
|
+
.withIndex("by_type_status", q =>
|
|
356
|
+
q.eq("type", "creator").eq("status", "active")
|
|
357
|
+
)
|
|
358
|
+
.collect();
|
|
359
|
+
|
|
360
|
+
// Filter after index
|
|
361
|
+
const recentCreators = await ctx.db
|
|
362
|
+
.query("entities")
|
|
363
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
364
|
+
.filter(q => q.gt(q.field("createdAt"), Date.now() - 86400000))
|
|
365
|
+
.order("desc")
|
|
366
|
+
.take(10);
|
|
367
|
+
|
|
368
|
+
// Unique result
|
|
369
|
+
const creator = await ctx.db
|
|
370
|
+
.query("entities")
|
|
371
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
372
|
+
.filter(q => q.eq(q.field("properties.email"), email))
|
|
373
|
+
.unique();
|
|
374
|
+
|
|
375
|
+
// First result (optional)
|
|
376
|
+
const firstCreator = await ctx.db
|
|
377
|
+
.query("entities")
|
|
378
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
379
|
+
.first();
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
#### Pagination
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
import { paginationOptsValidator } from "convex/server";
|
|
386
|
+
|
|
387
|
+
export const listPaginated = query({
|
|
388
|
+
args: { paginationOpts: paginationOptsValidator },
|
|
389
|
+
handler: async (ctx, args) => {
|
|
390
|
+
return await ctx.db
|
|
391
|
+
.query("entities")
|
|
392
|
+
.withIndex("by_type", q => q.eq("type", "creator"))
|
|
393
|
+
.order("desc")
|
|
394
|
+
.paginate(args.paginationOpts);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
#### Relationship Queries
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
// Get all content authored by creator
|
|
403
|
+
const contentConnections = await ctx.db
|
|
404
|
+
.query("connections")
|
|
405
|
+
.withIndex("from_type", q =>
|
|
406
|
+
q.eq("fromEntityId", creatorId)
|
|
407
|
+
.eq("relationshipType", "authored")
|
|
408
|
+
)
|
|
409
|
+
.collect();
|
|
410
|
+
|
|
411
|
+
const content = await Promise.all(
|
|
412
|
+
contentConnections.map(conn => ctx.db.get(conn.toEntityId))
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
// Get all followers of creator
|
|
416
|
+
const followerConnections = await ctx.db
|
|
417
|
+
.query("connections")
|
|
418
|
+
.withIndex("to_type", q =>
|
|
419
|
+
q.eq("toEntityId", creatorId)
|
|
420
|
+
.eq("relationshipType", "following")
|
|
421
|
+
)
|
|
422
|
+
.collect();
|
|
423
|
+
|
|
424
|
+
// Bidirectional relationship check
|
|
425
|
+
const existingConnection = await ctx.db
|
|
426
|
+
.query("connections")
|
|
427
|
+
.withIndex("bidirectional", q =>
|
|
428
|
+
q.eq("fromEntityId", userId)
|
|
429
|
+
.eq("toEntityId", creatorId)
|
|
430
|
+
.eq("relationshipType", "following")
|
|
431
|
+
)
|
|
432
|
+
.unique();
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### File Storage
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
// Generate upload URL (mutation)
|
|
439
|
+
export const generateUploadUrl = mutation({
|
|
440
|
+
args: {},
|
|
441
|
+
handler: async (ctx) => {
|
|
442
|
+
return await ctx.storage.generateUploadUrl();
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// Save file reference (mutation)
|
|
447
|
+
export const saveFile = mutation({
|
|
448
|
+
args: {
|
|
449
|
+
storageId: v.id("_storage"),
|
|
450
|
+
name: v.string(),
|
|
451
|
+
type: v.string(),
|
|
452
|
+
size: v.number()
|
|
453
|
+
},
|
|
454
|
+
handler: async (ctx, args) => {
|
|
455
|
+
const fileId = await ctx.db.insert("entities", {
|
|
456
|
+
type: "media_asset",
|
|
457
|
+
name: args.name,
|
|
458
|
+
properties: {
|
|
459
|
+
storageId: args.storageId,
|
|
460
|
+
fileType: args.type,
|
|
461
|
+
fileSize: args.size
|
|
462
|
+
},
|
|
463
|
+
status: "active",
|
|
464
|
+
createdAt: Date.now(),
|
|
465
|
+
updatedAt: Date.now()
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
return { fileId };
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// Get file URL (mutation or action)
|
|
473
|
+
export const getFileUrl = mutation({
|
|
474
|
+
args: { storageId: v.id("_storage") },
|
|
475
|
+
handler: async (ctx, args) => {
|
|
476
|
+
return await ctx.storage.getUrl(args.storageId);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### Scheduled Functions (Crons)
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
// convex/crons.ts
|
|
485
|
+
import { cronJobs } from "convex/server";
|
|
486
|
+
import { internal } from "./_generated/api";
|
|
487
|
+
|
|
488
|
+
const crons = cronJobs();
|
|
489
|
+
|
|
490
|
+
// Every hour
|
|
491
|
+
crons.interval(
|
|
492
|
+
"cleanup expired tokens",
|
|
493
|
+
{ minutes: 60 },
|
|
494
|
+
internal.auth.cleanupExpiredTokens
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
// Every day at midnight UTC
|
|
498
|
+
crons.daily(
|
|
499
|
+
"daily content generation",
|
|
500
|
+
{ hourUTC: 0, minuteUTC: 0 },
|
|
501
|
+
internal.content.generateDailyContent
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
// Every Monday at 9 AM UTC
|
|
505
|
+
crons.weekly(
|
|
506
|
+
"weekly analytics report",
|
|
507
|
+
{ hourUTC: 9, minuteUTC: 0, dayOfWeek: "monday" },
|
|
508
|
+
internal.analytics.generateWeeklyReport
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
// Every month on the 1st at 10 AM UTC
|
|
512
|
+
crons.monthly(
|
|
513
|
+
"monthly billing",
|
|
514
|
+
{ hourUTC: 10, minuteUTC: 0, day: 1 },
|
|
515
|
+
internal.billing.processMonthlyBilling
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
export default crons;
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
---
|
|
522
|
+
|
|
523
|
+
## Effect.ts Service Layer
|
|
524
|
+
|
|
525
|
+
### Service Architecture
|
|
526
|
+
|
|
527
|
+
Effect.ts services provide typed, composable business logic with automatic dependency injection.
|
|
528
|
+
|
|
529
|
+
#### Creating a Service
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
// convex/services/tokens/purchase.ts
|
|
533
|
+
import { Effect } from "effect";
|
|
534
|
+
import { ConvexDatabase } from "../core/database";
|
|
535
|
+
import { StripeProvider } from "../providers/stripe";
|
|
536
|
+
import { BlockchainProvider } from "../providers/blockchain";
|
|
537
|
+
|
|
538
|
+
export class TokenService extends Effect.Service<TokenService>()(
|
|
539
|
+
"TokenService",
|
|
540
|
+
{
|
|
541
|
+
effect: Effect.gen(function* () {
|
|
542
|
+
const db = yield* ConvexDatabase;
|
|
543
|
+
const stripe = yield* StripeProvider;
|
|
544
|
+
const blockchain = yield* BlockchainProvider;
|
|
545
|
+
|
|
546
|
+
return {
|
|
547
|
+
purchase: ({
|
|
548
|
+
userId,
|
|
549
|
+
tokenId,
|
|
550
|
+
amount,
|
|
551
|
+
usdAmount
|
|
552
|
+
}: {
|
|
553
|
+
userId: Id<"entities">;
|
|
554
|
+
tokenId: Id<"entities">;
|
|
555
|
+
amount: number;
|
|
556
|
+
usdAmount: number;
|
|
557
|
+
}) =>
|
|
558
|
+
Effect.gen(function* () {
|
|
559
|
+
// All operations must succeed atomically
|
|
560
|
+
const [payment, tokens] = yield* Effect.all(
|
|
561
|
+
[
|
|
562
|
+
stripe.charge({
|
|
563
|
+
amount: usdAmount * 100,
|
|
564
|
+
currency: "usd",
|
|
565
|
+
metadata: { userId, tokenId, amount }
|
|
566
|
+
}),
|
|
567
|
+
blockchain.mint({
|
|
568
|
+
contractAddress: tokenId,
|
|
569
|
+
toAddress: userId,
|
|
570
|
+
amount
|
|
571
|
+
})
|
|
572
|
+
],
|
|
573
|
+
{ concurrency: 2 }
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
// Record in database
|
|
577
|
+
yield* db.insert("events", {
|
|
578
|
+
type: "tokens_purchased",
|
|
579
|
+
actorId: userId,
|
|
580
|
+
targetId: tokenId,
|
|
581
|
+
timestamp: Date.now(),
|
|
582
|
+
metadata: {
|
|
583
|
+
amount,
|
|
584
|
+
usdAmount,
|
|
585
|
+
paymentId: payment.id,
|
|
586
|
+
txHash: tokens.transactionHash
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
// Update balance
|
|
591
|
+
yield* db.upsert("connections", {
|
|
592
|
+
fromEntityId: userId,
|
|
593
|
+
toEntityId: tokenId,
|
|
594
|
+
relationshipType: "holds_tokens",
|
|
595
|
+
metadata: { balance: amount }
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
return {
|
|
599
|
+
paymentId: payment.id,
|
|
600
|
+
txHash: tokens.transactionHash,
|
|
601
|
+
amount
|
|
602
|
+
};
|
|
603
|
+
}).pipe(
|
|
604
|
+
// Automatic rollback on error
|
|
605
|
+
Effect.onError((error) =>
|
|
606
|
+
Effect.all([
|
|
607
|
+
stripe.refund(payment.id),
|
|
608
|
+
blockchain.burn({ contractAddress: tokenId, amount })
|
|
609
|
+
])
|
|
610
|
+
),
|
|
611
|
+
Effect.retry({ times: 3 }),
|
|
612
|
+
Effect.timeout("5 minutes"),
|
|
613
|
+
Effect.withSpan("purchaseTokens", {
|
|
614
|
+
attributes: { userId, tokenId, amount }
|
|
615
|
+
})
|
|
616
|
+
)
|
|
617
|
+
};
|
|
618
|
+
}),
|
|
619
|
+
dependencies: [
|
|
620
|
+
ConvexDatabase.Default,
|
|
621
|
+
StripeProvider.Default,
|
|
622
|
+
BlockchainProvider.Default
|
|
623
|
+
]
|
|
624
|
+
}
|
|
625
|
+
) {}
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
#### Using Services in Convex Functions
|
|
629
|
+
|
|
630
|
+
```typescript
|
|
631
|
+
// convex/mutations/tokens.ts
|
|
632
|
+
import { confect } from "convex-helpers/server/confect";
|
|
633
|
+
import { v } from "convex/values";
|
|
634
|
+
import { Effect } from "effect";
|
|
635
|
+
import { TokenService } from "../services/tokens/purchase";
|
|
636
|
+
import { MainLayer } from "../services";
|
|
637
|
+
|
|
638
|
+
export const purchase = confect.mutation({
|
|
639
|
+
args: {
|
|
640
|
+
tokenId: v.id("entities"),
|
|
641
|
+
amount: v.number(),
|
|
642
|
+
usdAmount: v.number()
|
|
643
|
+
},
|
|
644
|
+
handler: (ctx, args) =>
|
|
645
|
+
Effect.gen(function* () {
|
|
646
|
+
const userId = yield* getUserId(ctx);
|
|
647
|
+
const tokenService = yield* TokenService;
|
|
648
|
+
|
|
649
|
+
return yield* tokenService.purchase({
|
|
650
|
+
userId,
|
|
651
|
+
tokenId: args.tokenId,
|
|
652
|
+
amount: args.amount,
|
|
653
|
+
usdAmount: args.usdAmount
|
|
654
|
+
});
|
|
655
|
+
}).pipe(
|
|
656
|
+
Effect.provide(MainLayer),
|
|
657
|
+
Effect.catchTags({
|
|
658
|
+
StripeError: (error) =>
|
|
659
|
+
Effect.fail(new ConvexError({
|
|
660
|
+
message: `Payment failed: ${error.message}`
|
|
661
|
+
})),
|
|
662
|
+
BlockchainError: (error) =>
|
|
663
|
+
Effect.fail(new ConvexError({
|
|
664
|
+
message: `Token minting failed: ${error.message}`
|
|
665
|
+
}))
|
|
666
|
+
})
|
|
667
|
+
)
|
|
668
|
+
});
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
### Typed Errors
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
// convex/services/errors.ts
|
|
675
|
+
export class NotFoundError {
|
|
676
|
+
readonly _tag = "NotFoundError";
|
|
677
|
+
constructor(
|
|
678
|
+
readonly message: string,
|
|
679
|
+
readonly entityId?: string
|
|
680
|
+
) {}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export class ValidationError {
|
|
684
|
+
readonly _tag = "ValidationError";
|
|
685
|
+
constructor(
|
|
686
|
+
readonly field: string,
|
|
687
|
+
readonly message: string
|
|
688
|
+
) {}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
export class InsufficientTokensError {
|
|
692
|
+
readonly _tag = "InsufficientTokensError";
|
|
693
|
+
constructor(
|
|
694
|
+
readonly userId: string,
|
|
695
|
+
readonly required: number,
|
|
696
|
+
readonly available: number
|
|
697
|
+
) {}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export class PaymentFailedError {
|
|
701
|
+
readonly _tag = "PaymentFailedError";
|
|
702
|
+
constructor(
|
|
703
|
+
readonly message: string,
|
|
704
|
+
readonly code?: string
|
|
705
|
+
) {}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// Usage with typed error handling
|
|
709
|
+
Effect.gen(function* () {
|
|
710
|
+
const result = yield* tokenService.purchase(args);
|
|
711
|
+
return result;
|
|
712
|
+
}).pipe(
|
|
713
|
+
Effect.catchTag("InsufficientTokensError", (error) =>
|
|
714
|
+
Effect.succeed({
|
|
715
|
+
error: `You need ${error.required} tokens but only have ${error.available}`
|
|
716
|
+
})
|
|
717
|
+
),
|
|
718
|
+
Effect.catchTag("PaymentFailedError", (error) =>
|
|
719
|
+
Effect.succeed({
|
|
720
|
+
error: `Payment failed: ${error.message}`
|
|
721
|
+
})
|
|
722
|
+
)
|
|
723
|
+
)
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
---
|
|
727
|
+
|
|
728
|
+
## External Service Providers
|
|
729
|
+
|
|
730
|
+
### OpenAI Provider
|
|
731
|
+
|
|
732
|
+
```typescript
|
|
733
|
+
// convex/services/providers/openai.ts
|
|
734
|
+
import { Effect } from "effect";
|
|
735
|
+
|
|
736
|
+
export class OpenAIProvider extends Effect.Service<OpenAIProvider>()(
|
|
737
|
+
"OpenAIProvider",
|
|
738
|
+
{
|
|
739
|
+
effect: Effect.gen(function* () {
|
|
740
|
+
return {
|
|
741
|
+
chat: ({
|
|
742
|
+
systemPrompt,
|
|
743
|
+
messages,
|
|
744
|
+
temperature = 0.7
|
|
745
|
+
}: {
|
|
746
|
+
systemPrompt: string;
|
|
747
|
+
messages: Array<{ role: string; content: string }>;
|
|
748
|
+
temperature?: number;
|
|
749
|
+
}) =>
|
|
750
|
+
Effect.tryPromise({
|
|
751
|
+
try: async () => {
|
|
752
|
+
const response = await fetch(
|
|
753
|
+
"https://api.openai.com/v1/chat/completions",
|
|
754
|
+
{
|
|
755
|
+
method: "POST",
|
|
756
|
+
headers: {
|
|
757
|
+
"Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
758
|
+
"Content-Type": "application/json",
|
|
759
|
+
},
|
|
760
|
+
body: JSON.stringify({
|
|
761
|
+
model: "gpt-4-turbo-preview",
|
|
762
|
+
messages: [
|
|
763
|
+
{ role: "system", content: systemPrompt },
|
|
764
|
+
...messages
|
|
765
|
+
],
|
|
766
|
+
temperature
|
|
767
|
+
}),
|
|
768
|
+
}
|
|
769
|
+
);
|
|
770
|
+
|
|
771
|
+
const data = await response.json();
|
|
772
|
+
return {
|
|
773
|
+
content: data.choices[0].message.content,
|
|
774
|
+
usage: data.usage
|
|
775
|
+
};
|
|
776
|
+
},
|
|
777
|
+
catch: (error) => new OpenAIError(String(error))
|
|
778
|
+
}),
|
|
779
|
+
|
|
780
|
+
embed: (text: string) =>
|
|
781
|
+
Effect.tryPromise({
|
|
782
|
+
try: async () => {
|
|
783
|
+
const response = await fetch(
|
|
784
|
+
"https://api.openai.com/v1/embeddings",
|
|
785
|
+
{
|
|
786
|
+
method: "POST",
|
|
787
|
+
headers: {
|
|
788
|
+
"Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
|
|
789
|
+
"Content-Type": "application/json",
|
|
790
|
+
},
|
|
791
|
+
body: JSON.stringify({
|
|
792
|
+
model: "text-embedding-ada-002",
|
|
793
|
+
input: text
|
|
794
|
+
}),
|
|
795
|
+
}
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
const data = await response.json();
|
|
799
|
+
return data.data[0].embedding;
|
|
800
|
+
},
|
|
801
|
+
catch: (error) => new OpenAIError(String(error))
|
|
802
|
+
})
|
|
803
|
+
};
|
|
804
|
+
})
|
|
805
|
+
}
|
|
806
|
+
) {}
|
|
807
|
+
|
|
808
|
+
class OpenAIError {
|
|
809
|
+
readonly _tag = "OpenAIError";
|
|
810
|
+
constructor(readonly message: string) {}
|
|
811
|
+
}
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
### Stripe Provider
|
|
815
|
+
|
|
816
|
+
```typescript
|
|
817
|
+
// convex/services/providers/stripe.ts
|
|
818
|
+
import { Effect } from "effect";
|
|
819
|
+
import Stripe from "stripe";
|
|
820
|
+
|
|
821
|
+
export class StripeProvider extends Effect.Service<StripeProvider>()(
|
|
822
|
+
"StripeProvider",
|
|
823
|
+
{
|
|
824
|
+
effect: Effect.gen(function* () {
|
|
825
|
+
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
|
826
|
+
apiVersion: "2023-10-16"
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
return {
|
|
830
|
+
charge: ({
|
|
831
|
+
amount,
|
|
832
|
+
currency,
|
|
833
|
+
metadata
|
|
834
|
+
}: {
|
|
835
|
+
amount: number;
|
|
836
|
+
currency: string;
|
|
837
|
+
metadata?: Record<string, string>;
|
|
838
|
+
}) =>
|
|
839
|
+
Effect.tryPromise({
|
|
840
|
+
try: async () => {
|
|
841
|
+
const paymentIntent = await stripe.paymentIntents.create({
|
|
842
|
+
amount,
|
|
843
|
+
currency,
|
|
844
|
+
metadata
|
|
845
|
+
});
|
|
846
|
+
return paymentIntent;
|
|
847
|
+
},
|
|
848
|
+
catch: (error) => new StripeError(String(error))
|
|
849
|
+
}),
|
|
850
|
+
|
|
851
|
+
refund: (paymentIntentId: string) =>
|
|
852
|
+
Effect.tryPromise({
|
|
853
|
+
try: async () => {
|
|
854
|
+
const refund = await stripe.refunds.create({
|
|
855
|
+
payment_intent: paymentIntentId
|
|
856
|
+
});
|
|
857
|
+
return refund;
|
|
858
|
+
},
|
|
859
|
+
catch: (error) => new StripeError(String(error))
|
|
860
|
+
})
|
|
861
|
+
};
|
|
862
|
+
})
|
|
863
|
+
}
|
|
864
|
+
) {}
|
|
865
|
+
|
|
866
|
+
class StripeError {
|
|
867
|
+
readonly _tag = "StripeError";
|
|
868
|
+
constructor(readonly message: string) {}
|
|
869
|
+
}
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
### Blockchain Provider
|
|
873
|
+
|
|
874
|
+
```typescript
|
|
875
|
+
// convex/services/providers/blockchain.ts
|
|
876
|
+
import { Effect } from "effect";
|
|
877
|
+
import { ethers } from "ethers";
|
|
878
|
+
|
|
879
|
+
export class BlockchainProvider extends Effect.Service<BlockchainProvider>()(
|
|
880
|
+
"BlockchainProvider",
|
|
881
|
+
{
|
|
882
|
+
effect: Effect.gen(function* () {
|
|
883
|
+
const provider = new ethers.JsonRpcProvider(process.env.BASE_RPC_URL);
|
|
884
|
+
const wallet = new ethers.Wallet(
|
|
885
|
+
process.env.DEPLOYER_PRIVATE_KEY!,
|
|
886
|
+
provider
|
|
887
|
+
);
|
|
888
|
+
|
|
889
|
+
return {
|
|
890
|
+
mint: ({
|
|
891
|
+
contractAddress,
|
|
892
|
+
toAddress,
|
|
893
|
+
amount
|
|
894
|
+
}: {
|
|
895
|
+
contractAddress: string;
|
|
896
|
+
toAddress: string;
|
|
897
|
+
amount: number;
|
|
898
|
+
}) =>
|
|
899
|
+
Effect.tryPromise({
|
|
900
|
+
try: async () => {
|
|
901
|
+
const contract = new ethers.Contract(
|
|
902
|
+
contractAddress,
|
|
903
|
+
["function mint(address to, uint256 amount)"],
|
|
904
|
+
wallet
|
|
905
|
+
);
|
|
906
|
+
|
|
907
|
+
const tx = await contract.mint(toAddress, amount);
|
|
908
|
+
const receipt = await tx.wait();
|
|
909
|
+
|
|
910
|
+
return {
|
|
911
|
+
transactionHash: receipt.hash,
|
|
912
|
+
blockNumber: receipt.blockNumber
|
|
913
|
+
};
|
|
914
|
+
},
|
|
915
|
+
catch: (error) => new BlockchainError(String(error))
|
|
916
|
+
}),
|
|
917
|
+
|
|
918
|
+
burn: ({
|
|
919
|
+
contractAddress,
|
|
920
|
+
amount
|
|
921
|
+
}: {
|
|
922
|
+
contractAddress: string;
|
|
923
|
+
amount: number;
|
|
924
|
+
}) =>
|
|
925
|
+
Effect.tryPromise({
|
|
926
|
+
try: async () => {
|
|
927
|
+
const contract = new ethers.Contract(
|
|
928
|
+
contractAddress,
|
|
929
|
+
["function burn(uint256 amount)"],
|
|
930
|
+
wallet
|
|
931
|
+
);
|
|
932
|
+
|
|
933
|
+
const tx = await contract.burn(amount);
|
|
934
|
+
const receipt = await tx.wait();
|
|
935
|
+
|
|
936
|
+
return {
|
|
937
|
+
transactionHash: receipt.hash,
|
|
938
|
+
blockNumber: receipt.blockNumber
|
|
939
|
+
};
|
|
940
|
+
},
|
|
941
|
+
catch: (error) => new BlockchainError(String(error))
|
|
942
|
+
})
|
|
943
|
+
};
|
|
944
|
+
})
|
|
945
|
+
}
|
|
946
|
+
) {}
|
|
947
|
+
|
|
948
|
+
class BlockchainError {
|
|
949
|
+
readonly _tag = "BlockchainError";
|
|
950
|
+
constructor(readonly message: string) {}
|
|
951
|
+
}
|
|
952
|
+
```
|
|
953
|
+
|
|
954
|
+
---
|
|
955
|
+
|
|
956
|
+
## Frontend Integration
|
|
957
|
+
|
|
958
|
+
### React Components with Convex Hooks
|
|
959
|
+
|
|
960
|
+
```typescript
|
|
961
|
+
// src/components/features/tokens/TokenPurchase.tsx
|
|
962
|
+
import { useQuery, useMutation } from "convex/react";
|
|
963
|
+
import { api } from "@/convex/_generated/api";
|
|
964
|
+
import { Id } from "@/convex/_generated/dataModel";
|
|
965
|
+
import { Button } from "@/components/ui/button";
|
|
966
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
967
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
968
|
+
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
969
|
+
import { useState } from "react";
|
|
970
|
+
|
|
971
|
+
interface TokenPurchaseProps {
|
|
972
|
+
tokenId: Id<"entities">;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
export function TokenPurchase({ tokenId }: TokenPurchaseProps) {
|
|
976
|
+
const token = useQuery(api.tokens.get, { id: tokenId });
|
|
977
|
+
const balance = useQuery(api.tokens.getBalance, { tokenId });
|
|
978
|
+
const purchase = useMutation(api.tokens.purchase);
|
|
979
|
+
|
|
980
|
+
const [amount, setAmount] = useState(100);
|
|
981
|
+
const [error, setError] = useState<string | null>(null);
|
|
982
|
+
const [loading, setLoading] = useState(false);
|
|
983
|
+
|
|
984
|
+
// Loading state
|
|
985
|
+
if (token === undefined || balance === undefined) {
|
|
986
|
+
return (
|
|
987
|
+
<Card>
|
|
988
|
+
<CardHeader>
|
|
989
|
+
<Skeleton className="h-6 w-48" />
|
|
990
|
+
</CardHeader>
|
|
991
|
+
<CardContent>
|
|
992
|
+
<Skeleton className="h-24 w-full" />
|
|
993
|
+
</CardContent>
|
|
994
|
+
</Card>
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// Error state
|
|
999
|
+
if (token === null) {
|
|
1000
|
+
return (
|
|
1001
|
+
<Card>
|
|
1002
|
+
<CardContent className="py-6">
|
|
1003
|
+
<Alert variant="destructive">
|
|
1004
|
+
<AlertDescription>Token not found</AlertDescription>
|
|
1005
|
+
</Alert>
|
|
1006
|
+
</CardContent>
|
|
1007
|
+
</Card>
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const handlePurchase = async () => {
|
|
1012
|
+
setLoading(true);
|
|
1013
|
+
setError(null);
|
|
1014
|
+
|
|
1015
|
+
try {
|
|
1016
|
+
await purchase({
|
|
1017
|
+
tokenId,
|
|
1018
|
+
amount,
|
|
1019
|
+
usdAmount: amount * token.properties.priceUsd
|
|
1020
|
+
});
|
|
1021
|
+
} catch (err) {
|
|
1022
|
+
setError(err.message);
|
|
1023
|
+
} finally {
|
|
1024
|
+
setLoading(false);
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
return (
|
|
1029
|
+
<Card>
|
|
1030
|
+
<CardHeader>
|
|
1031
|
+
<CardTitle>Purchase {token.name}</CardTitle>
|
|
1032
|
+
</CardHeader>
|
|
1033
|
+
<CardContent className="space-y-4">
|
|
1034
|
+
<div>
|
|
1035
|
+
<p className="text-sm text-muted-foreground">Current Balance</p>
|
|
1036
|
+
<p className="text-2xl font-bold">{balance?.amount || 0}</p>
|
|
1037
|
+
</div>
|
|
1038
|
+
|
|
1039
|
+
<div>
|
|
1040
|
+
<label className="text-sm font-medium">Amount</label>
|
|
1041
|
+
<input
|
|
1042
|
+
type="number"
|
|
1043
|
+
value={amount}
|
|
1044
|
+
onChange={(e) => setAmount(Number(e.target.value))}
|
|
1045
|
+
className="w-full px-3 py-2 border rounded"
|
|
1046
|
+
/>
|
|
1047
|
+
</div>
|
|
1048
|
+
|
|
1049
|
+
<div>
|
|
1050
|
+
<p className="text-sm text-muted-foreground">Total Cost</p>
|
|
1051
|
+
<p className="text-xl font-bold">
|
|
1052
|
+
${(amount * token.properties.priceUsd).toFixed(2)}
|
|
1053
|
+
</p>
|
|
1054
|
+
</div>
|
|
1055
|
+
|
|
1056
|
+
{error && (
|
|
1057
|
+
<Alert variant="destructive">
|
|
1058
|
+
<AlertDescription>{error}</AlertDescription>
|
|
1059
|
+
</Alert>
|
|
1060
|
+
)}
|
|
1061
|
+
|
|
1062
|
+
<Button
|
|
1063
|
+
onClick={handlePurchase}
|
|
1064
|
+
disabled={loading || amount <= 0}
|
|
1065
|
+
className="w-full"
|
|
1066
|
+
>
|
|
1067
|
+
{loading ? "Processing..." : `Buy ${amount} Tokens`}
|
|
1068
|
+
</Button>
|
|
1069
|
+
</CardContent>
|
|
1070
|
+
</Card>
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
```
|
|
1074
|
+
|
|
1075
|
+
### Astro Pages with SSR
|
|
1076
|
+
|
|
1077
|
+
```astro
|
|
1078
|
+
---
|
|
1079
|
+
// src/pages/tokens/[id].astro
|
|
1080
|
+
import { ConvexHttpClient } from "convex/browser";
|
|
1081
|
+
import { api } from "@/convex/_generated/api";
|
|
1082
|
+
import Layout from "@/layouts/Layout.astro";
|
|
1083
|
+
import { TokenPurchase } from "@/components/features/tokens/TokenPurchase";
|
|
1084
|
+
|
|
1085
|
+
const convex = new ConvexHttpClient(import.meta.env.PUBLIC_CONVEX_URL);
|
|
1086
|
+
const token = await convex.query(api.tokens.get, { id: Astro.params.id as any });
|
|
1087
|
+
|
|
1088
|
+
if (!token) {
|
|
1089
|
+
return Astro.redirect("/404");
|
|
1090
|
+
}
|
|
1091
|
+
---
|
|
1092
|
+
|
|
1093
|
+
<Layout title={`${token.name} - Token Details`}>
|
|
1094
|
+
<div class="container mx-auto py-12">
|
|
1095
|
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
|
|
1096
|
+
<div>
|
|
1097
|
+
<h1 class="text-4xl font-bold mb-4">{token.name}</h1>
|
|
1098
|
+
<p class="text-lg text-muted-foreground mb-6">
|
|
1099
|
+
{token.properties.description}
|
|
1100
|
+
</p>
|
|
1101
|
+
|
|
1102
|
+
<div class="space-y-4">
|
|
1103
|
+
<div>
|
|
1104
|
+
<p class="text-sm text-muted-foreground">Price</p>
|
|
1105
|
+
<p class="text-2xl font-bold">
|
|
1106
|
+
${token.properties.priceUsd.toFixed(2)}
|
|
1107
|
+
</p>
|
|
1108
|
+
</div>
|
|
1109
|
+
|
|
1110
|
+
<div>
|
|
1111
|
+
<p class="text-sm text-muted-foreground">Total Supply</p>
|
|
1112
|
+
<p class="text-2xl font-bold">
|
|
1113
|
+
{token.properties.totalSupply.toLocaleString()}
|
|
1114
|
+
</p>
|
|
1115
|
+
</div>
|
|
1116
|
+
</div>
|
|
1117
|
+
</div>
|
|
1118
|
+
|
|
1119
|
+
<div>
|
|
1120
|
+
<TokenPurchase client:load tokenId={token._id} />
|
|
1121
|
+
</div>
|
|
1122
|
+
</div>
|
|
1123
|
+
</div>
|
|
1124
|
+
</Layout>
|
|
1125
|
+
```
|
|
1126
|
+
|
|
1127
|
+
---
|
|
1128
|
+
|
|
1129
|
+
## Authentication API
|
|
1130
|
+
|
|
1131
|
+
### Better Auth Integration
|
|
1132
|
+
|
|
1133
|
+
The ONE platform uses Better Auth for authentication, not Convex Auth.
|
|
1134
|
+
|
|
1135
|
+
#### Auth Configuration
|
|
1136
|
+
|
|
1137
|
+
```typescript
|
|
1138
|
+
// convex/auth.config.ts
|
|
1139
|
+
import { betterAuth } from "better-auth";
|
|
1140
|
+
import { convexAdapter } from "better-auth/adapters/convex";
|
|
1141
|
+
|
|
1142
|
+
export const auth = betterAuth({
|
|
1143
|
+
database: convexAdapter(),
|
|
1144
|
+
emailAndPassword: {
|
|
1145
|
+
enabled: true,
|
|
1146
|
+
requireEmailVerification: true,
|
|
1147
|
+
},
|
|
1148
|
+
socialProviders: {
|
|
1149
|
+
github: {
|
|
1150
|
+
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
1151
|
+
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
1152
|
+
},
|
|
1153
|
+
google: {
|
|
1154
|
+
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
1155
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
});
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
#### Auth Helpers
|
|
1162
|
+
|
|
1163
|
+
```typescript
|
|
1164
|
+
// convex/auth.ts
|
|
1165
|
+
import { query, mutation, internalMutation, internalAction } from "./_generated/server";
|
|
1166
|
+
import { v } from "convex/values";
|
|
1167
|
+
import { Resend } from "@convex-dev/resend";
|
|
1168
|
+
import { components } from "./_generated/api";
|
|
1169
|
+
import { internal } from "./_generated/api";
|
|
1170
|
+
|
|
1171
|
+
export const getUserId = async (ctx: any): Promise<string | null> => {
|
|
1172
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
1173
|
+
if (!identity) return null;
|
|
1174
|
+
|
|
1175
|
+
const user = await ctx.db
|
|
1176
|
+
.query("users")
|
|
1177
|
+
.withIndex("by_token", q => q.eq("tokenIdentifier", identity.tokenIdentifier))
|
|
1178
|
+
.unique();
|
|
1179
|
+
|
|
1180
|
+
return user?._id || null;
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
export const requestPasswordReset = mutation({
|
|
1184
|
+
args: { email: v.string(), baseUrl: v.string() },
|
|
1185
|
+
handler: async (ctx, args) => {
|
|
1186
|
+
const result = await ctx.runMutation(internal.auth.createPasswordResetToken, {
|
|
1187
|
+
email: args.email,
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
if (!result) return { success: true };
|
|
1191
|
+
|
|
1192
|
+
const resetLink = `${args.baseUrl}/reset-password?token=${result.token}`;
|
|
1193
|
+
|
|
1194
|
+
await ctx.scheduler.runAfter(0, internal.auth.sendPasswordResetEmailAction, {
|
|
1195
|
+
email: result.email,
|
|
1196
|
+
resetLink,
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
return { success: true };
|
|
1200
|
+
},
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
export const createPasswordResetToken = internalMutation({
|
|
1204
|
+
args: { email: v.string() },
|
|
1205
|
+
handler: async (ctx, args) => {
|
|
1206
|
+
const user = await ctx.db
|
|
1207
|
+
.query("users")
|
|
1208
|
+
.withIndex("by_email", q => q.eq("email", args.email))
|
|
1209
|
+
.unique();
|
|
1210
|
+
|
|
1211
|
+
if (!user) return null;
|
|
1212
|
+
|
|
1213
|
+
const token = crypto.randomUUID();
|
|
1214
|
+
const expires = Date.now() + 3600000; // 1 hour
|
|
1215
|
+
|
|
1216
|
+
await ctx.db.insert("verificationTokens", {
|
|
1217
|
+
identifier: args.email,
|
|
1218
|
+
token,
|
|
1219
|
+
expires,
|
|
1220
|
+
type: "password_reset"
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
return { token, email: args.email };
|
|
1224
|
+
},
|
|
1225
|
+
});
|
|
1226
|
+
|
|
1227
|
+
export const sendPasswordResetEmailAction = internalAction({
|
|
1228
|
+
args: { email: v.string(), resetLink: v.string() },
|
|
1229
|
+
handler: async (ctx, args) => {
|
|
1230
|
+
const resend = new Resend(components.resend, { testMode: false });
|
|
1231
|
+
|
|
1232
|
+
await resend.sendEmail(ctx, {
|
|
1233
|
+
from: process.env.RESEND_FROM_EMAIL || "onboarding@resend.dev",
|
|
1234
|
+
to: args.email,
|
|
1235
|
+
subject: "Reset your password",
|
|
1236
|
+
html: `<a href="${args.resetLink}">Reset Password</a>`,
|
|
1237
|
+
});
|
|
1238
|
+
},
|
|
1239
|
+
});
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
---
|
|
1243
|
+
|
|
1244
|
+
## Schema Reference (6-Dimension Ontology)
|
|
1245
|
+
|
|
1246
|
+
The ONE platform uses a **6-dimension ontology** where every feature maps to one of these dimensions:
|
|
1247
|
+
|
|
1248
|
+
```
|
|
1249
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
1250
|
+
│ ORGANIZATIONS TABLE │
|
|
1251
|
+
│ Multi-tenant isolation - who owns what at org level │
|
|
1252
|
+
└──────────────────────────────────────────────────────────────┘
|
|
1253
|
+
↓
|
|
1254
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
1255
|
+
│ PEOPLE TABLE │
|
|
1256
|
+
│ Authorization & governance - who can do what │
|
|
1257
|
+
└──────────────────────────────────────────────────────────────┘
|
|
1258
|
+
↓
|
|
1259
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
1260
|
+
│ THINGS TABLE │
|
|
1261
|
+
│ Every "thing" - users, agents, content, tokens, courses │
|
|
1262
|
+
└──────────────────────────────────────────────────────────────┘
|
|
1263
|
+
↓
|
|
1264
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
1265
|
+
│ CONNECTIONS TABLE │
|
|
1266
|
+
│ Every relationship - owns, follows, taught_by, powers │
|
|
1267
|
+
└──────────────────────────────────────────────────────────────┘
|
|
1268
|
+
↓
|
|
1269
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
1270
|
+
│ EVENTS TABLE │
|
|
1271
|
+
│ Every action - purchased, created, viewed, completed │
|
|
1272
|
+
└──────────────────────────────────────────────────────────────┘
|
|
1273
|
+
↓
|
|
1274
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
1275
|
+
│ KNOWLEDGE TABLE │
|
|
1276
|
+
│ Labels + vectors powering RAG & search │
|
|
1277
|
+
└──────────────────────────────────────────────────────────────┘
|
|
1278
|
+
```
|
|
1279
|
+
|
|
1280
|
+
**Golden Rule:** If you can't map your feature to these 6 dimensions, you're thinking about it wrong.
|
|
1281
|
+
|
|
1282
|
+
### Entities Table
|
|
1283
|
+
|
|
1284
|
+
**46 entity types** representing all objects in the ONE platform.
|
|
1285
|
+
|
|
1286
|
+
**What goes in Entities?**
|
|
1287
|
+
- Simple test: If you can point at it and say "this is a ___", it's an entity.
|
|
1288
|
+
- Examples: "This is a creator" ✅ | "This is a relationship" ❌ (that's a connection)
|
|
1289
|
+
|
|
1290
|
+
```typescript
|
|
1291
|
+
entities: defineTable({
|
|
1292
|
+
type: v.union(
|
|
1293
|
+
// Core (3)
|
|
1294
|
+
v.literal("creator"), // Human creator
|
|
1295
|
+
v.literal("ai_clone"), // Digital twin of creator
|
|
1296
|
+
v.literal("audience_member"), // Fan/user
|
|
1297
|
+
|
|
1298
|
+
// Business Agents (10)
|
|
1299
|
+
v.literal("strategy_agent"), // Vision, planning, OKRs
|
|
1300
|
+
v.literal("research_agent"), // Market, trends, competitors
|
|
1301
|
+
v.literal("marketing_agent"), // Content strategy, SEO
|
|
1302
|
+
v.literal("sales_agent"), // Funnels, conversion
|
|
1303
|
+
v.literal("service_agent"), // Support, onboarding
|
|
1304
|
+
v.literal("design_agent"), // Brand, UI/UX, assets
|
|
1305
|
+
v.literal("engineering_agent"), // Tech, integration
|
|
1306
|
+
v.literal("finance_agent"), // Revenue, costs, forecasting
|
|
1307
|
+
v.literal("legal_agent"), // Compliance, contracts, IP
|
|
1308
|
+
v.literal("intelligence_agent"), // Analytics, insights
|
|
1309
|
+
|
|
1310
|
+
// Content (7)
|
|
1311
|
+
v.literal("blog_post"),
|
|
1312
|
+
v.literal("video"),
|
|
1313
|
+
v.literal("podcast"),
|
|
1314
|
+
v.literal("social_post"),
|
|
1315
|
+
v.literal("email"),
|
|
1316
|
+
v.literal("course"),
|
|
1317
|
+
v.literal("lesson"),
|
|
1318
|
+
|
|
1319
|
+
// Products (4)
|
|
1320
|
+
v.literal("digital_product"),
|
|
1321
|
+
v.literal("membership"),
|
|
1322
|
+
v.literal("consultation"),
|
|
1323
|
+
v.literal("nft"),
|
|
1324
|
+
|
|
1325
|
+
// Community (3)
|
|
1326
|
+
v.literal("community"),
|
|
1327
|
+
v.literal("conversation"),
|
|
1328
|
+
v.literal("message"),
|
|
1329
|
+
|
|
1330
|
+
// Token (2)
|
|
1331
|
+
v.literal("token"),
|
|
1332
|
+
v.literal("token_contract"),
|
|
1333
|
+
|
|
1334
|
+
// Knowledge (2)
|
|
1335
|
+
v.literal("knowledge_item"),
|
|
1336
|
+
v.literal("embedding"),
|
|
1337
|
+
|
|
1338
|
+
// Platform (6)
|
|
1339
|
+
v.literal("website"),
|
|
1340
|
+
v.literal("landing_page"),
|
|
1341
|
+
v.literal("template"),
|
|
1342
|
+
v.literal("livestream"),
|
|
1343
|
+
v.literal("recording"),
|
|
1344
|
+
v.literal("media_asset"),
|
|
1345
|
+
|
|
1346
|
+
// Business (7)
|
|
1347
|
+
v.literal("payment"),
|
|
1348
|
+
v.literal("subscription"),
|
|
1349
|
+
v.literal("invoice"),
|
|
1350
|
+
v.literal("metric"),
|
|
1351
|
+
v.literal("insight"),
|
|
1352
|
+
v.literal("prediction"),
|
|
1353
|
+
v.literal("report"),
|
|
1354
|
+
|
|
1355
|
+
// Marketing (5)
|
|
1356
|
+
v.literal("notification"),
|
|
1357
|
+
v.literal("email_campaign"),
|
|
1358
|
+
v.literal("announcement"),
|
|
1359
|
+
v.literal("referral"),
|
|
1360
|
+
v.literal("campaign"),
|
|
1361
|
+
v.literal("lead")
|
|
1362
|
+
),
|
|
1363
|
+
|
|
1364
|
+
name: v.string(), // Display name
|
|
1365
|
+
properties: v.any(), // Type-specific data (JSON)
|
|
1366
|
+
status: v.optional(v.union(
|
|
1367
|
+
v.literal("active"),
|
|
1368
|
+
v.literal("inactive"),
|
|
1369
|
+
v.literal("draft"),
|
|
1370
|
+
v.literal("published"),
|
|
1371
|
+
v.literal("archived")
|
|
1372
|
+
)),
|
|
1373
|
+
createdAt: v.number(),
|
|
1374
|
+
updatedAt: v.number(),
|
|
1375
|
+
deletedAt: v.optional(v.number())
|
|
1376
|
+
})
|
|
1377
|
+
.index("by_type", ["type"])
|
|
1378
|
+
.index("by_status", ["status"])
|
|
1379
|
+
.index("by_type_status", ["type", "status"])
|
|
1380
|
+
.index("by_created", ["createdAt"])
|
|
1381
|
+
.index("by_updated", ["updatedAt"])
|
|
1382
|
+
.searchIndex("search_entities", {
|
|
1383
|
+
searchField: "name",
|
|
1384
|
+
filterFields: ["type", "status"]
|
|
1385
|
+
})
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
#### Example Entity Properties by Type
|
|
1389
|
+
|
|
1390
|
+
**Creator:**
|
|
1391
|
+
```typescript
|
|
1392
|
+
{
|
|
1393
|
+
email: string,
|
|
1394
|
+
username: string,
|
|
1395
|
+
displayName: string,
|
|
1396
|
+
bio?: string,
|
|
1397
|
+
avatar?: string,
|
|
1398
|
+
niche: string[], // ["fitness", "nutrition"]
|
|
1399
|
+
expertise: string[],
|
|
1400
|
+
targetAudience: string,
|
|
1401
|
+
brandColors?: {
|
|
1402
|
+
primary: string,
|
|
1403
|
+
secondary: string,
|
|
1404
|
+
accent: string
|
|
1405
|
+
},
|
|
1406
|
+
totalFollowers: number,
|
|
1407
|
+
totalContent: number,
|
|
1408
|
+
totalRevenue: number
|
|
1409
|
+
}
|
|
1410
|
+
```
|
|
1411
|
+
|
|
1412
|
+
**AI Clone:**
|
|
1413
|
+
```typescript
|
|
1414
|
+
{
|
|
1415
|
+
voiceId?: string,
|
|
1416
|
+
voiceProvider?: "elevenlabs" | "azure" | "custom",
|
|
1417
|
+
appearanceId?: string,
|
|
1418
|
+
appearanceProvider?: "d-id" | "heygen" | "custom",
|
|
1419
|
+
systemPrompt: string,
|
|
1420
|
+
temperature: number,
|
|
1421
|
+
knowledgeBaseSize: number,
|
|
1422
|
+
lastTrainingDate: number,
|
|
1423
|
+
totalInteractions: number,
|
|
1424
|
+
satisfactionScore: number
|
|
1425
|
+
}
|
|
1426
|
+
```
|
|
1427
|
+
|
|
1428
|
+
**Token:**
|
|
1429
|
+
```typescript
|
|
1430
|
+
{
|
|
1431
|
+
contractAddress: string,
|
|
1432
|
+
blockchain: "sui" | "base" | "solana",
|
|
1433
|
+
standard: "ERC20" | "ERC721" | "ERC1155",
|
|
1434
|
+
totalSupply: number,
|
|
1435
|
+
circulatingSupply: number,
|
|
1436
|
+
price: number,
|
|
1437
|
+
marketCap: number,
|
|
1438
|
+
utility: string[],
|
|
1439
|
+
burnRate: number,
|
|
1440
|
+
holders: number,
|
|
1441
|
+
transactions24h: number,
|
|
1442
|
+
volume24h: number
|
|
1443
|
+
}
|
|
1444
|
+
```
|
|
1445
|
+
|
|
1446
|
+
**Course:**
|
|
1447
|
+
```typescript
|
|
1448
|
+
{
|
|
1449
|
+
title: string,
|
|
1450
|
+
description: string,
|
|
1451
|
+
thumbnail?: string,
|
|
1452
|
+
modules: number,
|
|
1453
|
+
lessons: number,
|
|
1454
|
+
totalDuration: number,
|
|
1455
|
+
price: number,
|
|
1456
|
+
currency: string,
|
|
1457
|
+
tokenPrice?: number,
|
|
1458
|
+
enrollments: number,
|
|
1459
|
+
completions: number,
|
|
1460
|
+
averageRating: number,
|
|
1461
|
+
generatedBy: "ai" | "human" | "hybrid",
|
|
1462
|
+
personalizationLevel: "none" | "basic" | "advanced"
|
|
1463
|
+
}
|
|
1464
|
+
```
|
|
1465
|
+
|
|
1466
|
+
### Connections Table
|
|
1467
|
+
|
|
1468
|
+
**24 relationship types** (consolidated from 33).
|
|
1469
|
+
|
|
1470
|
+
```typescript
|
|
1471
|
+
connections: defineTable({
|
|
1472
|
+
fromEntityId: v.id("entities"),
|
|
1473
|
+
toEntityId: v.id("entities"),
|
|
1474
|
+
relationshipType: v.union(
|
|
1475
|
+
// Ownership (2)
|
|
1476
|
+
v.literal("owns"),
|
|
1477
|
+
v.literal("created_by"),
|
|
1478
|
+
|
|
1479
|
+
// AI (3)
|
|
1480
|
+
v.literal("clone_of"),
|
|
1481
|
+
v.literal("trained_on"),
|
|
1482
|
+
v.literal("powers"),
|
|
1483
|
+
|
|
1484
|
+
// Content (5)
|
|
1485
|
+
v.literal("authored"),
|
|
1486
|
+
v.literal("generated_by"),
|
|
1487
|
+
v.literal("published_to"),
|
|
1488
|
+
v.literal("part_of"),
|
|
1489
|
+
v.literal("references"),
|
|
1490
|
+
|
|
1491
|
+
// Community (4)
|
|
1492
|
+
v.literal("member_of"),
|
|
1493
|
+
v.literal("following"),
|
|
1494
|
+
v.literal("moderates"),
|
|
1495
|
+
v.literal("participated_in"),
|
|
1496
|
+
|
|
1497
|
+
// Business (4)
|
|
1498
|
+
v.literal("manages"),
|
|
1499
|
+
v.literal("reports_to"),
|
|
1500
|
+
v.literal("collaborates_with"),
|
|
1501
|
+
v.literal("assigned_to"),
|
|
1502
|
+
|
|
1503
|
+
// Token (3)
|
|
1504
|
+
v.literal("holds_tokens"),
|
|
1505
|
+
v.literal("staked_in"),
|
|
1506
|
+
v.literal("earned_from"),
|
|
1507
|
+
|
|
1508
|
+
// Product (4)
|
|
1509
|
+
v.literal("purchased"),
|
|
1510
|
+
v.literal("enrolled_in"),
|
|
1511
|
+
v.literal("completed"),
|
|
1512
|
+
v.literal("teaching"),
|
|
1513
|
+
|
|
1514
|
+
// Consolidated (3)
|
|
1515
|
+
v.literal("transacted"), // payment, subscription, invoice
|
|
1516
|
+
v.literal("referred"), // direct, conversion, campaign
|
|
1517
|
+
v.literal("notified"), // email, sms, push, in_app
|
|
1518
|
+
|
|
1519
|
+
// Media (2)
|
|
1520
|
+
v.literal("featured_in"),
|
|
1521
|
+
v.literal("hosted_on"),
|
|
1522
|
+
|
|
1523
|
+
// Analytics (3)
|
|
1524
|
+
v.literal("analyzed_by"),
|
|
1525
|
+
v.literal("optimized_by"),
|
|
1526
|
+
v.literal("influences")
|
|
1527
|
+
),
|
|
1528
|
+
metadata: v.optional(v.any()),
|
|
1529
|
+
createdAt: v.number(),
|
|
1530
|
+
deletedAt: v.optional(v.number())
|
|
1531
|
+
})
|
|
1532
|
+
.index("from_entity", ["fromEntityId"])
|
|
1533
|
+
.index("to_entity", ["toEntityId"])
|
|
1534
|
+
.index("from_type", ["fromEntityId", "relationshipType"])
|
|
1535
|
+
.index("to_type", ["toEntityId", "relationshipType"])
|
|
1536
|
+
.index("bidirectional", ["fromEntityId", "toEntityId", "relationshipType"])
|
|
1537
|
+
.index("by_created", ["createdAt"])
|
|
1538
|
+
```
|
|
1539
|
+
|
|
1540
|
+
### Events Table
|
|
1541
|
+
|
|
1542
|
+
**35 event types** (consolidated from 54).
|
|
1543
|
+
|
|
1544
|
+
```typescript
|
|
1545
|
+
events: defineTable({
|
|
1546
|
+
type: v.union(
|
|
1547
|
+
// Creator (3)
|
|
1548
|
+
v.literal("creator_created"),
|
|
1549
|
+
v.literal("creator_updated"),
|
|
1550
|
+
v.literal("content_uploaded"),
|
|
1551
|
+
|
|
1552
|
+
// AI Clone (5)
|
|
1553
|
+
v.literal("clone_created"),
|
|
1554
|
+
v.literal("clone_interaction"),
|
|
1555
|
+
v.literal("clone_generated_content"),
|
|
1556
|
+
v.literal("voice_cloned"),
|
|
1557
|
+
v.literal("appearance_cloned"),
|
|
1558
|
+
|
|
1559
|
+
// Agent (4)
|
|
1560
|
+
v.literal("agent_created"),
|
|
1561
|
+
v.literal("agent_executed"),
|
|
1562
|
+
v.literal("agent_completed"),
|
|
1563
|
+
v.literal("agent_failed"),
|
|
1564
|
+
|
|
1565
|
+
// Content (2 - consolidated)
|
|
1566
|
+
v.literal("content_changed"), // created, updated, deleted
|
|
1567
|
+
v.literal("content_interacted"), // viewed, shared, liked
|
|
1568
|
+
|
|
1569
|
+
// Audience (4)
|
|
1570
|
+
v.literal("user_joined"),
|
|
1571
|
+
v.literal("user_engaged"),
|
|
1572
|
+
v.literal("ugc_created"),
|
|
1573
|
+
v.literal("comment_posted"),
|
|
1574
|
+
|
|
1575
|
+
// Course (5)
|
|
1576
|
+
v.literal("course_created"),
|
|
1577
|
+
v.literal("course_enrolled"),
|
|
1578
|
+
v.literal("lesson_completed"),
|
|
1579
|
+
v.literal("course_completed"),
|
|
1580
|
+
v.literal("certificate_earned"),
|
|
1581
|
+
|
|
1582
|
+
// Token (7)
|
|
1583
|
+
v.literal("token_deployed"),
|
|
1584
|
+
v.literal("tokens_purchased"),
|
|
1585
|
+
v.literal("tokens_earned"),
|
|
1586
|
+
v.literal("tokens_burned"),
|
|
1587
|
+
v.literal("tokens_staked"),
|
|
1588
|
+
v.literal("tokens_unstaked"),
|
|
1589
|
+
v.literal("governance_vote"),
|
|
1590
|
+
|
|
1591
|
+
// Business (3)
|
|
1592
|
+
v.literal("revenue_generated"),
|
|
1593
|
+
v.literal("cost_incurred"),
|
|
1594
|
+
v.literal("referral_made"),
|
|
1595
|
+
|
|
1596
|
+
// Growth (4)
|
|
1597
|
+
v.literal("viral_share"),
|
|
1598
|
+
v.literal("referral_converted"),
|
|
1599
|
+
v.literal("achievement_unlocked"),
|
|
1600
|
+
v.literal("level_up"),
|
|
1601
|
+
|
|
1602
|
+
// Analytics (5)
|
|
1603
|
+
v.literal("metric_calculated"),
|
|
1604
|
+
v.literal("insight_generated"),
|
|
1605
|
+
v.literal("prediction_made"),
|
|
1606
|
+
v.literal("optimization_applied"),
|
|
1607
|
+
v.literal("report_generated"),
|
|
1608
|
+
|
|
1609
|
+
// Consolidated events
|
|
1610
|
+
v.literal("payment_processed"), // initiated, completed, failed, refunded
|
|
1611
|
+
v.literal("subscription_updated"), // started, renewed, cancelled
|
|
1612
|
+
v.literal("livestream_status_changed"), // scheduled, started, ended
|
|
1613
|
+
v.literal("livestream_interaction"), // joined, left, message
|
|
1614
|
+
v.literal("notification_delivered"), // email, sms, push, in_app
|
|
1615
|
+
v.literal("referral_activity"), // created, converted
|
|
1616
|
+
v.literal("lead_captured")
|
|
1617
|
+
),
|
|
1618
|
+
actorId: v.id("entities"),
|
|
1619
|
+
targetId: v.optional(v.id("entities")),
|
|
1620
|
+
timestamp: v.number(),
|
|
1621
|
+
metadata: v.any() // Event-specific data
|
|
1622
|
+
})
|
|
1623
|
+
.index("by_type", ["type"])
|
|
1624
|
+
.index("by_actor", ["actorId"])
|
|
1625
|
+
.index("by_target", ["targetId"])
|
|
1626
|
+
.index("by_timestamp", ["timestamp"])
|
|
1627
|
+
.index("by_actor_type", ["actorId", "type"])
|
|
1628
|
+
.index("by_target_type", ["targetId", "type"])
|
|
1629
|
+
```
|
|
1630
|
+
|
|
1631
|
+
### Tags Table
|
|
1632
|
+
|
|
1633
|
+
Simple key-value tagging system for categorization.
|
|
1634
|
+
|
|
1635
|
+
```typescript
|
|
1636
|
+
tags: defineTable({
|
|
1637
|
+
entityId: v.id("entities"),
|
|
1638
|
+
key: v.string(),
|
|
1639
|
+
value: v.string()
|
|
1640
|
+
})
|
|
1641
|
+
.index("by_entity", ["entityId"])
|
|
1642
|
+
.index("by_key", ["key"])
|
|
1643
|
+
.index("by_key_value", ["key", "value"])
|
|
1644
|
+
```
|
|
1645
|
+
|
|
1646
|
+
---
|
|
1647
|
+
|
|
1648
|
+
## Error Handling
|
|
1649
|
+
|
|
1650
|
+
### Typed Errors in Effect.ts
|
|
1651
|
+
|
|
1652
|
+
```typescript
|
|
1653
|
+
// Define error classes
|
|
1654
|
+
export class NotFoundError {
|
|
1655
|
+
readonly _tag = "NotFoundError";
|
|
1656
|
+
constructor(readonly message: string) {}
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
export class ValidationError {
|
|
1660
|
+
readonly _tag = "ValidationError";
|
|
1661
|
+
constructor(
|
|
1662
|
+
readonly field: string,
|
|
1663
|
+
readonly message: string
|
|
1664
|
+
) {}
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// Use in service
|
|
1668
|
+
Effect.gen(function* () {
|
|
1669
|
+
const user = yield* db.get(userId);
|
|
1670
|
+
if (!user) {
|
|
1671
|
+
return yield* Effect.fail(new NotFoundError("User not found"));
|
|
1672
|
+
}
|
|
1673
|
+
return user;
|
|
1674
|
+
}).pipe(
|
|
1675
|
+
Effect.catchTag("NotFoundError", (error) =>
|
|
1676
|
+
Effect.succeed({ error: error.message })
|
|
1677
|
+
)
|
|
1678
|
+
)
|
|
1679
|
+
```
|
|
1680
|
+
|
|
1681
|
+
### Convex Error Handling
|
|
1682
|
+
|
|
1683
|
+
```typescript
|
|
1684
|
+
import { ConvexError } from "convex/values";
|
|
1685
|
+
|
|
1686
|
+
export const myMutation = mutation({
|
|
1687
|
+
handler: async (ctx, args) => {
|
|
1688
|
+
const user = await ctx.db.get(args.userId);
|
|
1689
|
+
|
|
1690
|
+
if (!user) {
|
|
1691
|
+
throw new ConvexError({
|
|
1692
|
+
message: "User not found",
|
|
1693
|
+
code: "NOT_FOUND"
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// ... continue
|
|
1698
|
+
}
|
|
1699
|
+
});
|
|
1700
|
+
```
|
|
1701
|
+
|
|
1702
|
+
---
|
|
1703
|
+
|
|
1704
|
+
## Environment Variables
|
|
1705
|
+
|
|
1706
|
+
### Required Variables
|
|
1707
|
+
|
|
1708
|
+
```bash
|
|
1709
|
+
# Convex
|
|
1710
|
+
CONVEX_URL=https://your-deployment.convex.cloud
|
|
1711
|
+
CONVEX_DEPLOYMENT=your-deployment-name
|
|
1712
|
+
|
|
1713
|
+
# Better Auth
|
|
1714
|
+
BETTER_AUTH_SECRET=your-secret-key
|
|
1715
|
+
BETTER_AUTH_URL=https://your-domain.com
|
|
1716
|
+
|
|
1717
|
+
# OAuth Providers
|
|
1718
|
+
GITHUB_CLIENT_ID=your-github-client-id
|
|
1719
|
+
GITHUB_CLIENT_SECRET=your-github-client-secret
|
|
1720
|
+
GOOGLE_CLIENT_ID=your-google-client-id
|
|
1721
|
+
GOOGLE_CLIENT_SECRET=your-google-client-secret
|
|
1722
|
+
|
|
1723
|
+
# Email (Resend)
|
|
1724
|
+
RESEND_API_KEY=re_...
|
|
1725
|
+
RESEND_FROM_EMAIL=noreply@yourdomain.com
|
|
1726
|
+
|
|
1727
|
+
# Payments (Stripe)
|
|
1728
|
+
STRIPE_SECRET_KEY=sk_...
|
|
1729
|
+
STRIPE_PUBLISHABLE_KEY=pk_...
|
|
1730
|
+
|
|
1731
|
+
# Blockchain (Base L2)
|
|
1732
|
+
BASE_RPC_URL=https://mainnet.base.org
|
|
1733
|
+
DEPLOYER_PRIVATE_KEY=0x...
|
|
1734
|
+
|
|
1735
|
+
# AI Services
|
|
1736
|
+
OPENAI_API_KEY=sk-...
|
|
1737
|
+
ELEVENLABS_API_KEY=...
|
|
1738
|
+
```
|
|
1739
|
+
|
|
1740
|
+
---
|
|
1741
|
+
|
|
1742
|
+
## Quick Reference
|
|
1743
|
+
|
|
1744
|
+
### Common Validators
|
|
1745
|
+
|
|
1746
|
+
```typescript
|
|
1747
|
+
import { v } from "convex/values";
|
|
1748
|
+
|
|
1749
|
+
// Primitives
|
|
1750
|
+
v.string()
|
|
1751
|
+
v.number()
|
|
1752
|
+
v.boolean()
|
|
1753
|
+
v.null()
|
|
1754
|
+
v.any()
|
|
1755
|
+
|
|
1756
|
+
// Complex types
|
|
1757
|
+
v.id("tableName")
|
|
1758
|
+
v.array(v.string())
|
|
1759
|
+
v.object({ name: v.string(), age: v.number() })
|
|
1760
|
+
v.union(v.literal("a"), v.literal("b"))
|
|
1761
|
+
v.optional(v.string())
|
|
1762
|
+
|
|
1763
|
+
// Pagination
|
|
1764
|
+
paginationOptsValidator
|
|
1765
|
+
```
|
|
1766
|
+
|
|
1767
|
+
### Best Practices
|
|
1768
|
+
|
|
1769
|
+
1. **Always use indexes** for queries on non-_id fields
|
|
1770
|
+
2. **Email sending** must be in internal actions, scheduled from mutations
|
|
1771
|
+
3. **Use Effect.ts** for all business logic with multiple steps or external calls
|
|
1772
|
+
4. **Type all errors** with `_tag` for exhaustive error handling
|
|
1773
|
+
5. **Validate args** with Convex validators
|
|
1774
|
+
6. **Log events** for all significant actions
|
|
1775
|
+
7. **Use .unique()** when expecting exactly one result, `.first()` for optional
|
|
1776
|
+
8. **Schedule background work** with `ctx.scheduler.runAfter()`
|
|
1777
|
+
9. **Keep mutations fast** - use actions for long-running operations
|
|
1778
|
+
10. **Always provide MainLayer** when using Effect.ts services in Convex functions
|
|
1779
|
+
|
|
1780
|
+
---
|
|
1781
|
+
|
|
1782
|
+
## How Features Map to Ontology
|
|
1783
|
+
|
|
1784
|
+
Understanding how to map features to the 6-dimension ontology is critical for implementing new functionality.
|
|
1785
|
+
|
|
1786
|
+
### Example: AI Clone Creation
|
|
1787
|
+
|
|
1788
|
+
**Feature Goal:** Allow creators to create AI clones of themselves.
|
|
1789
|
+
|
|
1790
|
+
**Ontology Mapping:**
|
|
1791
|
+
|
|
1792
|
+
**Entities Created:**
|
|
1793
|
+
1. `ai_clone` entity (the digital twin)
|
|
1794
|
+
2. Multiple `knowledge_item` entities (training data from creator's content)
|
|
1795
|
+
|
|
1796
|
+
**Connections Created:**
|
|
1797
|
+
1. creator → ai_clone (`owns`)
|
|
1798
|
+
2. ai_clone → knowledge_items (`trained_on`)
|
|
1799
|
+
3. agent → ai_clone (`powers`) - which agent runs the clone
|
|
1800
|
+
|
|
1801
|
+
**Events Logged:**
|
|
1802
|
+
1. `clone_created` - when clone entity created
|
|
1803
|
+
2. `voice_cloned` - when voice cloning completes
|
|
1804
|
+
3. `appearance_cloned` - when appearance cloning completes
|
|
1805
|
+
|
|
1806
|
+
**Tags Added:**
|
|
1807
|
+
- Clone inherits creator's `industry` and `skill` tags
|
|
1808
|
+
- Additional tags: `status:training`, `status:active`
|
|
1809
|
+
|
|
1810
|
+
### Example: Token Purchase
|
|
1811
|
+
|
|
1812
|
+
**Feature Goal:** Allow users to purchase creator tokens.
|
|
1813
|
+
|
|
1814
|
+
**Ontology Mapping:**
|
|
1815
|
+
|
|
1816
|
+
**Entities Involved:**
|
|
1817
|
+
1. `token` entity (the token being purchased)
|
|
1818
|
+
2. `audience_member` entity (the buyer)
|
|
1819
|
+
|
|
1820
|
+
**Connections Created/Updated:**
|
|
1821
|
+
1. buyer → token (`holds_tokens`, metadata: { balance: 100, blockchain: "sui" })
|
|
1822
|
+
|
|
1823
|
+
**Events Logged:**
|
|
1824
|
+
1. `tokens_purchased` (amount, blockchain, payment details)
|
|
1825
|
+
2. `revenue_generated` (for creator)
|
|
1826
|
+
3. `payment_processed` (fiat) OR blockchain transaction event (crypto)
|
|
1827
|
+
|
|
1828
|
+
**Tags Added:**
|
|
1829
|
+
- None (tokens already have tags)
|
|
1830
|
+
|
|
1831
|
+
### Example: Course Generation
|
|
1832
|
+
|
|
1833
|
+
**Feature Goal:** AI generates a personalized course for a creator.
|
|
1834
|
+
|
|
1835
|
+
**Ontology Mapping:**
|
|
1836
|
+
|
|
1837
|
+
**Entities Created:**
|
|
1838
|
+
1. `course` entity
|
|
1839
|
+
2. Multiple `lesson` entities (one per lesson)
|
|
1840
|
+
3. `content` entities for each lesson (video, text, quiz)
|
|
1841
|
+
|
|
1842
|
+
**Connections Created:**
|
|
1843
|
+
1. creator → course (`owns`)
|
|
1844
|
+
2. ai_agent → course (`generated_by`)
|
|
1845
|
+
3. ai_clone → course (`teaching`)
|
|
1846
|
+
4. course → lessons (`part_of`)
|
|
1847
|
+
5. lessons → content (`part_of`)
|
|
1848
|
+
|
|
1849
|
+
**Events Logged:**
|
|
1850
|
+
1. `course_created`
|
|
1851
|
+
2. `clone_generated_content` (for each lesson)
|
|
1852
|
+
|
|
1853
|
+
**Tags Added:**
|
|
1854
|
+
- `skill` tags - what the course teaches
|
|
1855
|
+
- `industry` tags - course category
|
|
1856
|
+
- `audience` tags - target skill level
|
|
1857
|
+
- `format` tag - video, text, interactive
|
|
1858
|
+
|
|
1859
|
+
### Example: Livestream Session
|
|
1860
|
+
|
|
1861
|
+
**Feature Goal:** Creator hosts a livestream with AI clone co-host.
|
|
1862
|
+
|
|
1863
|
+
**Ontology Mapping:**
|
|
1864
|
+
|
|
1865
|
+
**Entities Created:**
|
|
1866
|
+
1. `livestream` entity
|
|
1867
|
+
2. `recording` entity (after stream ends)
|
|
1868
|
+
3. Multiple `message` entities (chat messages)
|
|
1869
|
+
|
|
1870
|
+
**Connections Created:**
|
|
1871
|
+
1. creator → livestream (`owns`)
|
|
1872
|
+
2. ai_clone → livestream (`participated_in`)
|
|
1873
|
+
3. livestream → platform (`hosted_on`)
|
|
1874
|
+
4. viewers → livestream (`participated_in`)
|
|
1875
|
+
|
|
1876
|
+
**Events Logged:**
|
|
1877
|
+
1. `livestream_status_changed` (scheduled → started → ended)
|
|
1878
|
+
2. `livestream_interaction` (viewers joining, leaving, chatting)
|
|
1879
|
+
3. `content_changed` (recording created after stream)
|
|
1880
|
+
|
|
1881
|
+
**Tags Added:**
|
|
1882
|
+
- `topic` tags for stream content
|
|
1883
|
+
- `format:live` tag
|
|
1884
|
+
|
|
1885
|
+
---
|
|
1886
|
+
|
|
1887
|
+
## Query Patterns for Common Operations
|
|
1888
|
+
|
|
1889
|
+
### Get Creator with All Their Content
|
|
1890
|
+
|
|
1891
|
+
```typescript
|
|
1892
|
+
export const getCreatorWithContent = query({
|
|
1893
|
+
args: { creatorId: v.id("entities") },
|
|
1894
|
+
handler: async (ctx, args) => {
|
|
1895
|
+
// Get creator
|
|
1896
|
+
const creator = await ctx.db.get(args.creatorId);
|
|
1897
|
+
if (!creator || creator.type !== "creator") {
|
|
1898
|
+
return null;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// Get all authored connections
|
|
1902
|
+
const authoredConnections = await ctx.db
|
|
1903
|
+
.query("connections")
|
|
1904
|
+
.withIndex("from_type", q =>
|
|
1905
|
+
q.eq("fromEntityId", args.creatorId)
|
|
1906
|
+
.eq("relationshipType", "authored")
|
|
1907
|
+
)
|
|
1908
|
+
.collect();
|
|
1909
|
+
|
|
1910
|
+
// Get all content entities
|
|
1911
|
+
const content = await Promise.all(
|
|
1912
|
+
authoredConnections.map(conn => ctx.db.get(conn.toEntityId))
|
|
1913
|
+
);
|
|
1914
|
+
|
|
1915
|
+
// Get follower count
|
|
1916
|
+
const followers = await ctx.db
|
|
1917
|
+
.query("connections")
|
|
1918
|
+
.withIndex("to_type", q =>
|
|
1919
|
+
q.eq("toEntityId", args.creatorId)
|
|
1920
|
+
.eq("relationshipType", "following")
|
|
1921
|
+
)
|
|
1922
|
+
.collect();
|
|
1923
|
+
|
|
1924
|
+
return {
|
|
1925
|
+
...creator,
|
|
1926
|
+
content: content.filter(Boolean),
|
|
1927
|
+
followerCount: followers.length
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
```
|
|
1932
|
+
|
|
1933
|
+
### Get User's Token Holdings
|
|
1934
|
+
|
|
1935
|
+
```typescript
|
|
1936
|
+
export const getUserTokenHoldings = query({
|
|
1937
|
+
args: { userId: v.id("entities") },
|
|
1938
|
+
handler: async (ctx, args) => {
|
|
1939
|
+
// Get all token holding connections
|
|
1940
|
+
const holdings = await ctx.db
|
|
1941
|
+
.query("connections")
|
|
1942
|
+
.withIndex("from_type", q =>
|
|
1943
|
+
q.eq("fromEntityId", args.userId)
|
|
1944
|
+
.eq("relationshipType", "holds_tokens")
|
|
1945
|
+
)
|
|
1946
|
+
.collect();
|
|
1947
|
+
|
|
1948
|
+
// Get token details
|
|
1949
|
+
const tokens = await Promise.all(
|
|
1950
|
+
holdings.map(async (holding) => {
|
|
1951
|
+
const token = await ctx.db.get(holding.toEntityId);
|
|
1952
|
+
return {
|
|
1953
|
+
...token,
|
|
1954
|
+
balance: holding.metadata?.balance || 0,
|
|
1955
|
+
blockchain: holding.metadata?.blockchain || "unknown"
|
|
1956
|
+
};
|
|
1957
|
+
})
|
|
1958
|
+
);
|
|
1959
|
+
|
|
1960
|
+
return tokens.filter(Boolean);
|
|
1961
|
+
}
|
|
1962
|
+
});
|
|
1963
|
+
```
|
|
1964
|
+
|
|
1965
|
+
### Get Content Interaction History
|
|
1966
|
+
|
|
1967
|
+
```typescript
|
|
1968
|
+
export const getContentHistory = query({
|
|
1969
|
+
args: { contentId: v.id("entities"), limit: v.optional(v.number()) },
|
|
1970
|
+
handler: async (ctx, args) => {
|
|
1971
|
+
const events = await ctx.db
|
|
1972
|
+
.query("events")
|
|
1973
|
+
.withIndex("by_target_type", q =>
|
|
1974
|
+
q.eq("targetId", args.contentId)
|
|
1975
|
+
.eq("type", "content_interacted")
|
|
1976
|
+
)
|
|
1977
|
+
.order("desc")
|
|
1978
|
+
.take(args.limit || 100);
|
|
1979
|
+
|
|
1980
|
+
// Get actor details for each event
|
|
1981
|
+
const history = await Promise.all(
|
|
1982
|
+
events.map(async (event) => {
|
|
1983
|
+
const actor = await ctx.db.get(event.actorId);
|
|
1984
|
+
return {
|
|
1985
|
+
timestamp: event.timestamp,
|
|
1986
|
+
interactionType: event.metadata.interactionType,
|
|
1987
|
+
actor: actor?.name || "Unknown",
|
|
1988
|
+
duration: event.metadata.duration
|
|
1989
|
+
};
|
|
1990
|
+
})
|
|
1991
|
+
);
|
|
1992
|
+
|
|
1993
|
+
return history;
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
```
|
|
1997
|
+
|
|
1998
|
+
### Get AI Clone Performance Metrics
|
|
1999
|
+
|
|
2000
|
+
```typescript
|
|
2001
|
+
export const getCloneMetrics = query({
|
|
2002
|
+
args: { cloneId: v.id("entities") },
|
|
2003
|
+
handler: async (ctx, args) => {
|
|
2004
|
+
const clone = await ctx.db.get(args.cloneId);
|
|
2005
|
+
if (!clone || clone.type !== "ai_clone") {
|
|
2006
|
+
return null;
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
// Get interaction count (last 30 days)
|
|
2010
|
+
const thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
|
|
2011
|
+
const interactions = await ctx.db
|
|
2012
|
+
.query("events")
|
|
2013
|
+
.withIndex("by_target_type", q =>
|
|
2014
|
+
q.eq("targetId", args.cloneId)
|
|
2015
|
+
.eq("type", "clone_interaction")
|
|
2016
|
+
)
|
|
2017
|
+
.filter(q => q.gte(q.field("timestamp"), thirtyDaysAgo))
|
|
2018
|
+
.collect();
|
|
2019
|
+
|
|
2020
|
+
// Calculate average sentiment
|
|
2021
|
+
const sentiments = interactions
|
|
2022
|
+
.map(e => e.metadata.sentiment)
|
|
2023
|
+
.filter(Boolean);
|
|
2024
|
+
|
|
2025
|
+
const avgSentiment = sentiments.length > 0
|
|
2026
|
+
? sentiments.filter(s => s === "positive").length / sentiments.length
|
|
2027
|
+
: 0;
|
|
2028
|
+
|
|
2029
|
+
// Get tokens earned from clone interactions
|
|
2030
|
+
const tokensEarned = await ctx.db
|
|
2031
|
+
.query("events")
|
|
2032
|
+
.withIndex("by_type", q => q.eq("type", "tokens_earned"))
|
|
2033
|
+
.filter(q =>
|
|
2034
|
+
q.and(
|
|
2035
|
+
q.gte(q.field("timestamp"), thirtyDaysAgo),
|
|
2036
|
+
q.eq(q.field("metadata.source"), "clone_interaction")
|
|
2037
|
+
)
|
|
2038
|
+
)
|
|
2039
|
+
.collect()
|
|
2040
|
+
.then(events =>
|
|
2041
|
+
events.reduce((sum, e) => sum + (e.metadata.amount || 0), 0)
|
|
2042
|
+
);
|
|
2043
|
+
|
|
2044
|
+
return {
|
|
2045
|
+
...clone,
|
|
2046
|
+
metrics: {
|
|
2047
|
+
interactions30d: interactions.length,
|
|
2048
|
+
avgSentiment,
|
|
2049
|
+
tokensEarned30d: tokensEarned,
|
|
2050
|
+
satisfactionScore: clone.properties.satisfactionScore
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
```
|
|
2056
|
+
|
|
2057
|
+
---
|
|
2058
|
+
|
|
2059
|
+
## Migration Guide: Old System → 6-Dimension Ontology
|
|
2060
|
+
|
|
2061
|
+
### Step 1: Identify Entity Types
|
|
2062
|
+
|
|
2063
|
+
Map your existing models to the 46 entity types:
|
|
2064
|
+
|
|
2065
|
+
| Old Model | New Entity Type | Notes |
|
|
2066
|
+
|-----------|-----------------|-------|
|
|
2067
|
+
| User (creator) | `creator` | If they create content |
|
|
2068
|
+
| User (consumer) | `audience_member` | If they consume content |
|
|
2069
|
+
| Post | `blog_post` | Or `social_post` depending on platform |
|
|
2070
|
+
| Video | `video` | Content type |
|
|
2071
|
+
| Follow | N/A | This becomes a `connection` |
|
|
2072
|
+
| Like | N/A | This becomes an `event` |
|
|
2073
|
+
| Comment | `message` | Part of a `conversation` |
|
|
2074
|
+
| Subscription | `subscription` | Business entity |
|
|
2075
|
+
|
|
2076
|
+
### Step 2: Transform Properties
|
|
2077
|
+
|
|
2078
|
+
Extract structured data into the `properties` JSON field:
|
|
2079
|
+
|
|
2080
|
+
```typescript
|
|
2081
|
+
// OLD USER MODEL
|
|
2082
|
+
{
|
|
2083
|
+
id: "123",
|
|
2084
|
+
name: "John Doe",
|
|
2085
|
+
email: "john@example.com",
|
|
2086
|
+
bio: "Fitness coach",
|
|
2087
|
+
follower_count: 5000,
|
|
2088
|
+
created_at: "2024-01-15"
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
// NEW ENTITY
|
|
2092
|
+
{
|
|
2093
|
+
_id: "creator-123",
|
|
2094
|
+
type: "creator",
|
|
2095
|
+
name: "John Doe",
|
|
2096
|
+
properties: {
|
|
2097
|
+
email: "john@example.com",
|
|
2098
|
+
username: "johndoe",
|
|
2099
|
+
displayName: "John Doe",
|
|
2100
|
+
bio: "Fitness coach",
|
|
2101
|
+
niche: ["fitness", "health"],
|
|
2102
|
+
expertise: ["training", "nutrition"],
|
|
2103
|
+
targetAudience: "fitness enthusiasts",
|
|
2104
|
+
totalFollowers: 5000,
|
|
2105
|
+
totalContent: 0,
|
|
2106
|
+
totalRevenue: 0
|
|
2107
|
+
},
|
|
2108
|
+
status: "active",
|
|
2109
|
+
createdAt: new Date("2024-01-15").getTime(),
|
|
2110
|
+
updatedAt: Date.now()
|
|
2111
|
+
}
|
|
2112
|
+
```
|
|
2113
|
+
|
|
2114
|
+
### Step 3: Convert Relationships
|
|
2115
|
+
|
|
2116
|
+
Transform foreign keys into connections:
|
|
2117
|
+
|
|
2118
|
+
```typescript
|
|
2119
|
+
// OLD: posts table with user_id foreign key
|
|
2120
|
+
{
|
|
2121
|
+
id: "post-456",
|
|
2122
|
+
user_id: "user-123",
|
|
2123
|
+
title: "My First Post",
|
|
2124
|
+
content: "..."
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
// NEW: Separate entities + connection
|
|
2128
|
+
// 1. Creator entity (user-123 → creator-123)
|
|
2129
|
+
// 2. Post entity
|
|
2130
|
+
{
|
|
2131
|
+
_id: "post-456",
|
|
2132
|
+
type: "blog_post",
|
|
2133
|
+
name: "My First Post",
|
|
2134
|
+
properties: {
|
|
2135
|
+
content: "...",
|
|
2136
|
+
publishedAt: Date.now(),
|
|
2137
|
+
views: 0
|
|
2138
|
+
},
|
|
2139
|
+
status: "published",
|
|
2140
|
+
createdAt: Date.now(),
|
|
2141
|
+
updatedAt: Date.now()
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// 3. Connection
|
|
2145
|
+
{
|
|
2146
|
+
fromEntityId: "creator-123",
|
|
2147
|
+
toEntityId: "post-456",
|
|
2148
|
+
relationshipType: "authored",
|
|
2149
|
+
createdAt: Date.now()
|
|
2150
|
+
}
|
|
2151
|
+
```
|
|
2152
|
+
|
|
2153
|
+
### Step 4: Preserve History
|
|
2154
|
+
|
|
2155
|
+
Convert activity logs to events:
|
|
2156
|
+
|
|
2157
|
+
```typescript
|
|
2158
|
+
// OLD: Activity log entry
|
|
2159
|
+
{
|
|
2160
|
+
user_id: "123",
|
|
2161
|
+
action: "viewed",
|
|
2162
|
+
post_id: "456",
|
|
2163
|
+
timestamp: 1705334400000
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
// NEW: Event
|
|
2167
|
+
{
|
|
2168
|
+
type: "content_interacted",
|
|
2169
|
+
actorId: "user-123",
|
|
2170
|
+
targetId: "post-456",
|
|
2171
|
+
timestamp: 1705334400000,
|
|
2172
|
+
metadata: {
|
|
2173
|
+
interactionType: "viewed",
|
|
2174
|
+
source: "feed",
|
|
2175
|
+
duration: 120
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
```
|
|
2179
|
+
|
|
2180
|
+
---
|
|
2181
|
+
|
|
2182
|
+
**Last Updated:** 2025-01-15
|
|
2183
|
+
**Maintainer:** AI Agents + Human Developers
|
|
2184
|
+
|
|
2185
|
+
**See Also:**
|
|
2186
|
+
- `Ontology.md` - Complete ontology specification
|
|
2187
|
+
- `Schema.md` - Convex schema details
|
|
2188
|
+
- `Patterns.md` - Code patterns to replicate
|
|
2189
|
+
- `Architecture.md` - System architecture overview
|
|
2190
|
+
- `AGENTS.md` - Quick Convex reference for agents
|