@feltdb/core 0.15.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/agent-state.d.ts +20 -0
  2. package/dist/agent-state.d.ts.map +1 -1
  3. package/dist/agent-state.js +36 -0
  4. package/dist/build-identity.json +12 -4
  5. package/dist/cli/commands.js +187 -4
  6. package/dist/cli/publish-engine.js +116 -16
  7. package/dist/collection.d.ts.map +1 -1
  8. package/dist/collection.js +20 -2
  9. package/dist/create/build-identity.json +12 -4
  10. package/dist/create/managed-account.js +93 -35
  11. package/dist/create/package-versions.js +1 -1
  12. package/dist/create/server-source/Cargo.lock +6 -509
  13. package/dist/create/server-source/Cargo.toml +2 -13
  14. package/dist/create/server-source/crates/feltdb-client/Cargo.toml +1 -1
  15. package/dist/create/server-source/crates/feltdb-server/Cargo.toml +1 -1
  16. package/dist/create/server-source/crates/feltdb-server/src/main.rs +356 -24
  17. package/dist/create/server-source/crates/feltdb-server/tests/rust_client.rs +10 -1
  18. package/dist/create/server-source/crates/feltdb-wasm/Cargo.toml +1 -1
  19. package/dist/db.d.ts +11 -1
  20. package/dist/db.d.ts.map +1 -1
  21. package/dist/db.js +15 -2
  22. package/dist/error-codes.d.ts +5 -0
  23. package/dist/error-codes.d.ts.map +1 -1
  24. package/dist/error-codes.js +9 -1
  25. package/dist/http-db.d.ts +16 -0
  26. package/dist/http-db.d.ts.map +1 -1
  27. package/dist/http-db.js +36 -6
  28. package/dist/managed-recovery.d.ts +6 -0
  29. package/dist/managed-recovery.d.ts.map +1 -1
  30. package/dist/managed-recovery.js +9 -0
  31. package/dist/studio-app/assets/{feltdb_wasm-BjM1ylL3.js → feltdb_wasm-BUIxCuTR.js} +1 -1
  32. package/dist/studio-app/assets/feltdb_wasm_bg-C3D6y6DK.wasm +0 -0
  33. package/dist/studio-app/assets/index-BhXYAhgS.js +37 -0
  34. package/dist/studio-app/index.html +1 -1
  35. package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
  36. package/dist/wasm/package.json +1 -1
  37. package/dist/workload.d.ts +55 -3
  38. package/dist/workload.d.ts.map +1 -1
  39. package/dist/workload.js +23 -0
  40. package/dist/workspace/workspace-connection.d.ts.map +1 -1
  41. package/dist/workspace/workspace-connection.js +14 -3
  42. package/package.json +1 -1
  43. package/dist/create/server-source/crates/feltdb/Cargo.lock +0 -175
  44. package/dist/create/server-source/crates/feltdb/Cargo.toml +0 -102
  45. package/dist/create/server-source/crates/feltdb/LICENSE +0 -21
  46. package/dist/create/server-source/crates/feltdb/README.md +0 -75
  47. package/dist/create/server-source/crates/feltdb/benches/baselines/gate-13-redux.json +0 -370
  48. package/dist/create/server-source/crates/feltdb/benches/gate13_baseline.rs +0 -589
  49. package/dist/create/server-source/crates/feltdb/benches/gate13_phase_7_1_release_economics.rs +0 -247
  50. package/dist/create/server-source/crates/feltdb/benches/gate_13_redux.rs +0 -440
  51. package/dist/create/server-source/crates/feltdb/benches/gate_13_regression_runner.rs +0 -275
  52. package/dist/create/server-source/crates/feltdb/benches/gate_14a_concurrent_writer_scaling.rs +0 -381
  53. package/dist/create/server-source/crates/feltdb/benches/gate_14a_production_admission_revalidation.rs +0 -467
  54. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc2_admission_contract.rs +0 -489
  55. package/dist/create/server-source/crates/feltdb/benches/gate_14a_rc_root_cause.rs +0 -281
  56. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync1_queued_prototype.rs +0 -606
  57. package/dist/create/server-source/crates/feltdb/benches/gate_14a_sync_economics.rs +0 -531
  58. package/dist/create/server-source/crates/feltdb/benches/gate_14b_causal_backlog_scaling.rs +0 -462
  59. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_contract_test.rs +0 -505
  60. package/dist/create/server-source/crates/feltdb/benches/gate_14c_replication_scaling.rs +0 -484
  61. package/dist/create/server-source/crates/feltdb/benches/gate_14d_combined_dimension_scaling.rs +0 -758
  62. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_2_optimization_benchmark.rs +0 -421
  63. package/dist/create/server-source/crates/feltdb/benches/phase_7_1_3_crossover_analysis.rs +0 -329
  64. package/dist/create/server-source/crates/feltdb/src/acceptance_tests.rs +0 -1705
  65. package/dist/create/server-source/crates/feltdb/src/acquisition.rs +0 -286
  66. package/dist/create/server-source/crates/feltdb/src/admission.rs +0 -185
  67. package/dist/create/server-source/crates/feltdb/src/admission_contract_tests.rs +0 -507
  68. package/dist/create/server-source/crates/feltdb/src/adversarial_transport.rs +0 -539
  69. package/dist/create/server-source/crates/feltdb/src/agent_state.rs +0 -320
  70. package/dist/create/server-source/crates/feltdb/src/agent_transition_contract.rs +0 -1545
  71. package/dist/create/server-source/crates/feltdb/src/analytics.rs +0 -521
  72. package/dist/create/server-source/crates/feltdb/src/application.rs +0 -2674
  73. package/dist/create/server-source/crates/feltdb/src/application_runtime.rs +0 -1070
  74. package/dist/create/server-source/crates/feltdb/src/authority.rs +0 -479
  75. package/dist/create/server-source/crates/feltdb/src/authority_failover.rs +0 -847
  76. package/dist/create/server-source/crates/feltdb/src/authorization.rs +0 -1030
  77. package/dist/create/server-source/crates/feltdb/src/authorization_security_tests.rs +0 -1122
  78. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority-client.rs +0 -32
  79. package/dist/create/server-source/crates/feltdb/src/bin/feltdb-authority.rs +0 -19
  80. package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +0 -1474
  81. package/dist/create/server-source/crates/feltdb/src/capabilities/mod.rs +0 -8
  82. package/dist/create/server-source/crates/feltdb/src/capabilities/search.rs +0 -418
  83. package/dist/create/server-source/crates/feltdb/src/capabilities/vector.rs +0 -482
  84. package/dist/create/server-source/crates/feltdb/src/capability.rs +0 -903
  85. package/dist/create/server-source/crates/feltdb/src/cardinality_diagnostics.rs +0 -263
  86. package/dist/create/server-source/crates/feltdb/src/cardinality_endpoint.rs +0 -77
  87. package/dist/create/server-source/crates/feltdb/src/causal_backlog_bound.rs +0 -496
  88. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier.rs +0 -2574
  89. package/dist/create/server-source/crates/feltdb/src/causal_dependency_barrier_phase_7_1.rs +0 -212
  90. package/dist/create/server-source/crates/feltdb/src/concurrency_fuzzing.rs +0 -422
  91. package/dist/create/server-source/crates/feltdb/src/consistency_contract.rs +0 -445
  92. package/dist/create/server-source/crates/feltdb/src/content_distribution.rs +0 -465
  93. package/dist/create/server-source/crates/feltdb/src/convergence.rs +0 -634
  94. package/dist/create/server-source/crates/feltdb/src/crash_atomic_boundary.rs +0 -427
  95. package/dist/create/server-source/crates/feltdb/src/crash_injection.rs +0 -376
  96. package/dist/create/server-source/crates/feltdb/src/crash_recovery_tests.rs +0 -365
  97. package/dist/create/server-source/crates/feltdb/src/cron.rs +0 -294
  98. package/dist/create/server-source/crates/feltdb/src/dedup_bound_investigation.rs +0 -483
  99. package/dist/create/server-source/crates/feltdb/src/distributed_indexing.rs +0 -477
  100. package/dist/create/server-source/crates/feltdb/src/distributed_tests.rs +0 -1003
  101. package/dist/create/server-source/crates/feltdb/src/distributed_transactions.rs +0 -1334
  102. package/dist/create/server-source/crates/feltdb/src/durability_guarantees.rs +0 -368
  103. package/dist/create/server-source/crates/feltdb/src/durable_dedup_set.rs +0 -231
  104. package/dist/create/server-source/crates/feltdb/src/durable_operation_identity.rs +0 -482
  105. package/dist/create/server-source/crates/feltdb/src/durable_operation_log.rs +0 -203
  106. package/dist/create/server-source/crates/feltdb/src/durable_sync.rs +0 -317
  107. package/dist/create/server-source/crates/feltdb/src/equality_index.rs +0 -595
  108. package/dist/create/server-source/crates/feltdb/src/execution.rs +0 -426
  109. package/dist/create/server-source/crates/feltdb/src/in_process_transport.rs +0 -214
  110. package/dist/create/server-source/crates/feltdb/src/indexing.rs +0 -776
  111. package/dist/create/server-source/crates/feltdb/src/lib.rs +0 -7365
  112. package/dist/create/server-source/crates/feltdb/src/managed_cas_tests.rs +0 -234
  113. package/dist/create/server-source/crates/feltdb/src/materialization.rs +0 -184
  114. package/dist/create/server-source/crates/feltdb/src/metrics.rs +0 -266
  115. package/dist/create/server-source/crates/feltdb/src/multi_node_convergence.rs +0 -310
  116. package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +0 -736
  117. package/dist/create/server-source/crates/feltdb/src/observability.rs +0 -379
  118. package/dist/create/server-source/crates/feltdb/src/operation.rs +0 -290
  119. package/dist/create/server-source/crates/feltdb/src/operation_algebra.rs +0 -439
  120. package/dist/create/server-source/crates/feltdb/src/operation_log.rs +0 -349
  121. package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +0 -332
  122. package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +0 -718
  123. package/dist/create/server-source/crates/feltdb/src/partition_reconciliation.rs +0 -487
  124. package/dist/create/server-source/crates/feltdb/src/peer_registry.rs +0 -166
  125. package/dist/create/server-source/crates/feltdb/src/permutation_scheduler.rs +0 -289
  126. package/dist/create/server-source/crates/feltdb/src/persistence_reality.rs +0 -566
  127. package/dist/create/server-source/crates/feltdb/src/phase1b_acceptance.rs +0 -3391
  128. package/dist/create/server-source/crates/feltdb/src/phase1c1_acceptance.rs +0 -203
  129. package/dist/create/server-source/crates/feltdb/src/phase1c2_acceptance.rs +0 -261
  130. package/dist/create/server-source/crates/feltdb/src/phase1c3_acceptance.rs +0 -502
  131. package/dist/create/server-source/crates/feltdb/src/phase1c_atomicity_proof.rs +0 -216
  132. package/dist/create/server-source/crates/feltdb/src/phase5_integration.rs +0 -303
  133. package/dist/create/server-source/crates/feltdb/src/phase5_scenarios.rs +0 -323
  134. package/dist/create/server-source/crates/feltdb/src/phase6_adversarial_scenarios.rs +0 -531
  135. package/dist/create/server-source/crates/feltdb/src/phase6_convergence_validator.rs +0 -406
  136. package/dist/create/server-source/crates/feltdb/src/phase6_persistence.rs +0 -436
  137. package/dist/create/server-source/crates/feltdb/src/phase_1c_real_tcp.rs +0 -387
  138. package/dist/create/server-source/crates/feltdb/src/phase_2a_failures.rs +0 -378
  139. package/dist/create/server-source/crates/feltdb/src/phase_2b_network.rs +0 -359
  140. package/dist/create/server-source/crates/feltdb/src/phase_2c_cascading.rs +0 -372
  141. package/dist/create/server-source/crates/feltdb/src/phase_3_durability.rs +0 -404
  142. package/dist/create/server-source/crates/feltdb/src/phase_4_baseline.rs +0 -376
  143. package/dist/create/server-source/crates/feltdb/src/phase_5_soak.rs +0 -461
  144. package/dist/create/server-source/crates/feltdb/src/policy_evaluation.rs +0 -2125
  145. package/dist/create/server-source/crates/feltdb/src/production_api.rs +0 -418
  146. package/dist/create/server-source/crates/feltdb/src/provenance.rs +0 -207
  147. package/dist/create/server-source/crates/feltdb/src/query_execution_diagnostics.rs +0 -126
  148. package/dist/create/server-source/crates/feltdb/src/query_performance.rs +0 -218
  149. package/dist/create/server-source/crates/feltdb/src/read_basis.rs +0 -257
  150. package/dist/create/server-source/crates/feltdb/src/references.rs +0 -404
  151. package/dist/create/server-source/crates/feltdb/src/replay_fuzzing.rs +0 -401
  152. package/dist/create/server-source/crates/feltdb/src/replica_acknowledgements.rs +0 -501
  153. package/dist/create/server-source/crates/feltdb/src/replica_membership.rs +0 -680
  154. package/dist/create/server-source/crates/feltdb/src/replication_manager.rs +0 -163
  155. package/dist/create/server-source/crates/feltdb/src/replication_protocol.rs +0 -133
  156. package/dist/create/server-source/crates/feltdb/src/routing.rs +0 -409
  157. package/dist/create/server-source/crates/feltdb/src/semantic_decision.rs +0 -2029
  158. package/dist/create/server-source/crates/feltdb/src/semantic_query.rs +0 -599
  159. package/dist/create/server-source/crates/feltdb/src/sharding.rs +0 -549
  160. package/dist/create/server-source/crates/feltdb/src/state_conflict_contract.rs +0 -516
  161. package/dist/create/server-source/crates/feltdb/src/state_contract.rs +0 -6003
  162. package/dist/create/server-source/crates/feltdb/src/state_diff_contract.rs +0 -222
  163. package/dist/create/server-source/crates/feltdb/src/state_facade.rs +0 -320
  164. package/dist/create/server-source/crates/feltdb/src/state_hash.rs +0 -291
  165. package/dist/create/server-source/crates/feltdb/src/state_model.rs +0 -4158
  166. package/dist/create/server-source/crates/feltdb/src/state_transition_store.rs +0 -379
  167. package/dist/create/server-source/crates/feltdb/src/state_trigger.rs +0 -673
  168. package/dist/create/server-source/crates/feltdb/src/storage.rs +0 -273
  169. package/dist/create/server-source/crates/feltdb/src/submission.rs +0 -471
  170. package/dist/create/server-source/crates/feltdb/src/sync.rs +0 -495
  171. package/dist/create/server-source/crates/feltdb/src/sync_contract.rs +0 -822
  172. package/dist/create/server-source/crates/feltdb/src/tcp_transport.rs +0 -433
  173. package/dist/create/server-source/crates/feltdb/src/transaction_api.rs +0 -462
  174. package/dist/create/server-source/crates/feltdb/src/transaction_invariants.rs +0 -965
  175. package/dist/create/server-source/crates/feltdb/src/transaction_preconditions.rs +0 -1120
  176. package/dist/create/server-source/crates/feltdb/src/transactions.rs +0 -643
  177. package/dist/create/server-source/crates/feltdb/src/trigger.rs +0 -390
  178. package/dist/create/server-source/crates/feltdb/src/trigger_contract.rs +0 -749
  179. package/dist/create/server-source/crates/feltdb/src/versioned_object_substrate.rs +0 -708
  180. package/dist/create/server-source/crates/feltdb/src/worker_mesh.rs +0 -1269
  181. package/dist/create/server-source/crates/feltdb/src/workflow.rs +0 -713
  182. package/dist/create/server-source/crates/feltdb/src/workflow_acceptance_tests.rs +0 -510
  183. package/dist/create/server-source/crates/feltdb/src/workflow_integration.rs +0 -354
  184. package/dist/create/server-source/crates/feltdb/src/workflow_runtime.rs +0 -594
  185. package/dist/create/server-source/crates/feltdb/src/workload.rs +0 -4222
  186. package/dist/create/server-source/crates/feltdb/src/workload_diagnostics.rs +0 -456
  187. package/dist/create/server-source/crates/feltdb/tests/agent_state_native.rs +0 -1188
  188. package/dist/create/server-source/crates/feltdb/tests/agent_transition_contract_conformance.rs +0 -2884
  189. package/dist/create/server-source/crates/feltdb/tests/authority_process.rs +0 -297
  190. package/dist/create/server-source/crates/feltdb/tests/authority_transaction_identity.rs +0 -534
  191. package/dist/create/server-source/crates/feltdb/tests/bounded_read_contract.rs +0 -132
  192. package/dist/create/server-source/crates/feltdb/tests/branching_evidence.rs +0 -299
  193. package/dist/create/server-source/crates/feltdb/tests/common/mod.rs +0 -96
  194. package/dist/create/server-source/crates/feltdb/tests/compaction_stall_contract.rs +0 -272
  195. package/dist/create/server-source/crates/feltdb/tests/crash_durability_contract.rs +0 -467
  196. package/dist/create/server-source/crates/feltdb/tests/current_revision_authority_evidence.rs +0 -309
  197. package/dist/create/server-source/crates/feltdb/tests/durable_backup_contract.rs +0 -445
  198. package/dist/create/server-source/crates/feltdb/tests/durable_corruption_contract.rs +0 -518
  199. package/dist/create/server-source/crates/feltdb/tests/durable_format_compatibility.rs +0 -392
  200. package/dist/create/server-source/crates/feltdb/tests/feltdb_state_boundary_tests.rs +0 -850
  201. package/dist/create/server-source/crates/feltdb/tests/fixtures/agent_transition_corpus.json +0 -23340
  202. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_conflict_contract_corpus.json +0 -1916
  203. package/dist/create/server-source/crates/feltdb/tests/fixtures/state_diff_contract_corpus.json +0 -1878
  204. package/dist/create/server-source/crates/feltdb/tests/fixtures/trigger_contract_corpus.json +0 -1862
  205. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_evidence.rs +0 -123
  206. package/dist/create/server-source/crates/feltdb/tests/generalized_version_control_substrate_completion.rs +0 -299
  207. package/dist/create/server-source/crates/feltdb/tests/local_process_ownership.rs +0 -69
  208. package/dist/create/server-source/crates/feltdb/tests/managed_incident_regression.rs +0 -191
  209. package/dist/create/server-source/crates/feltdb/tests/operational_health_contract.rs +0 -278
  210. package/dist/create/server-source/crates/feltdb/tests/pr34_query_collection.rs +0 -234
  211. package/dist/create/server-source/crates/feltdb/tests/pr35_equality_index.rs +0 -947
  212. package/dist/create/server-source/crates/feltdb/tests/pr7_self_authorization_proof.rs +0 -404
  213. package/dist/create/server-source/crates/feltdb/tests/pr8_vocabulary_assessment.rs +0 -916
  214. package/dist/create/server-source/crates/feltdb/tests/pr9_phase2_boundary_tests.rs +0 -1045
  215. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3a_path_a_tests.rs +0 -347
  216. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_authorized_mutations.rs +0 -361
  217. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_role_based_authorization.rs +0 -330
  218. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_simple_auth_delete.rs +0 -93
  219. package/dist/create/server-source/crates/feltdb/tests/pr9_phase3c_team_delete_role_authorization.rs +0 -622
  220. package/dist/create/server-source/crates/feltdb/tests/pr9_teams_role_based_access.rs +0 -517
  221. package/dist/create/server-source/crates/feltdb/tests/production_certification.rs +0 -1153
  222. package/dist/create/server-source/crates/feltdb/tests/production_contract.rs +0 -771
  223. package/dist/create/server-source/crates/feltdb/tests/production_readiness_contract.rs +0 -1383
  224. package/dist/create/server-source/crates/feltdb/tests/reconciliation_application.rs +0 -868
  225. package/dist/create/server-source/crates/feltdb/tests/reconciliation_wire_format_evidence.rs +0 -221
  226. package/dist/create/server-source/crates/feltdb/tests/replicated_history_contract.rs +0 -417
  227. package/dist/create/server-source/crates/feltdb/tests/resource_scoped_revisions.rs +0 -338
  228. package/dist/create/server-source/crates/feltdb/tests/revision_identity_contract.rs +0 -1039
  229. package/dist/create/server-source/crates/feltdb/tests/revision_model_decision.rs +0 -739
  230. package/dist/create/server-source/crates/feltdb/tests/revision_retention_boundary_evidence.rs +0 -452
  231. package/dist/create/server-source/crates/feltdb/tests/saas_authorization_integration.rs +0 -81
  232. package/dist/create/server-source/crates/feltdb/tests/saas_invitation_lifecycle.rs +0 -438
  233. package/dist/create/server-source/crates/feltdb/tests/semantic_decision.rs +0 -1165
  234. package/dist/create/server-source/crates/feltdb/tests/semantic_query.rs +0 -767
  235. package/dist/create/server-source/crates/feltdb/tests/semantic_query_contract.rs +0 -363
  236. package/dist/create/server-source/crates/feltdb/tests/state_conflict_contract_conformance.rs +0 -1799
  237. package/dist/create/server-source/crates/feltdb/tests/state_diff_contract_conformance.rs +0 -1316
  238. package/dist/create/server-source/crates/feltdb/tests/state_model_integration.rs +0 -358
  239. package/dist/create/server-source/crates/feltdb/tests/state_persistence_integration.rs +0 -365
  240. package/dist/create/server-source/crates/feltdb/tests/state_ref_authority.rs +0 -918
  241. package/dist/create/server-source/crates/feltdb/tests/state_store_boundary_evidence.rs +0 -299
  242. package/dist/create/server-source/crates/feltdb/tests/storage_independent_versioned_object_substrate.rs +0 -328
  243. package/dist/create/server-source/crates/feltdb/tests/sync_divergence_evidence.rs +0 -255
  244. package/dist/create/server-source/crates/feltdb/tests/three_way_input_boundary_evidence.rs +0 -249
  245. package/dist/create/server-source/crates/feltdb/tests/trigger_contract_conformance.rs +0 -994
  246. package/dist/create/server-source/crates/feltdb/tests/workload_envelope_contract.rs +0 -484
  247. package/dist/studio-app/assets/feltdb_wasm_bg-TseJn2Ax.wasm +0 -0
  248. package/dist/studio-app/assets/index-1wd0uKua.js +0 -30
@@ -1,903 +0,0 @@
1
- use crate::Operation;
2
- /// Capability and Extension Runtime module
3
- ///
4
- /// Capabilities are extensible projections that consume the FeltDB operation stream
5
- /// and maintain rebuildable derived state. They follow a generic contract:
6
- ///
7
- /// canonical operation → capability → derived state → capability query
8
- ///
9
- /// This keeps the core log generic while allowing specialized behavior.
10
- use serde::{Deserialize, Serialize};
11
- use serde_json::Value;
12
- use std::collections::HashMap;
13
- use std::fmt;
14
-
15
- /// Unique capability identifier
16
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
17
- pub struct CapabilityId(pub String);
18
-
19
- impl fmt::Display for CapabilityId {
20
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21
- write!(f, "{}", self.0)
22
- }
23
- }
24
-
25
- impl CapabilityId {
26
- pub fn new(id: String) -> Self {
27
- CapabilityId(id)
28
- }
29
- }
30
-
31
- /// The roles a capability can fulfill
32
- #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
33
- pub enum CapabilityRole {
34
- /// Triggers and executes business logic
35
- ExecutionEngine,
36
- /// Maintains a projection/index of canonical state
37
- Projection,
38
- /// Both executes and maintains a projection
39
- ExecutionWithProjection,
40
- }
41
-
42
- /// Lifecycle states for a capability
43
- #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
44
- pub enum CapabilityLifecycleState {
45
- /// Capability has been registered but not yet initialized
46
- Registered,
47
- /// Capability is initializing its state
48
- Initializing,
49
- /// Capability is catching up with historical operations
50
- CatchingUp,
51
- /// Capability is active and processing new operations
52
- Active,
53
- /// Capability is paused
54
- Paused,
55
- /// Capability is being rebuilt
56
- Rebuilding,
57
- /// Capability has been removed
58
- Removed,
59
- }
60
-
61
- /// Context passed to capability operations
62
- #[derive(Debug, Clone, Serialize, Deserialize)]
63
- pub struct CapabilityContext {
64
- /// The capability ID
65
- pub capability_id: CapabilityId,
66
- /// Instance ID of the FeltDB instance
67
- pub instance_id: String,
68
- /// Current sequence number
69
- pub sequence: u64,
70
- /// Capability version
71
- pub version: u32,
72
- }
73
-
74
- /// Query structure for capability queries
75
- #[derive(Debug, Clone, Serialize, Deserialize)]
76
- pub struct CapabilityQuery {
77
- /// Query type (e.g., "search", "vector_find", "analytics")
78
- pub query_type: String,
79
- /// Query parameters
80
- pub params: Value,
81
- }
82
-
83
- impl CapabilityQuery {
84
- pub fn new(query_type: String, params: Value) -> Self {
85
- Self { query_type, params }
86
- }
87
- }
88
-
89
- /// Checkpoint for capability progress tracking
90
- #[derive(Debug, Clone, Serialize, Deserialize)]
91
- pub struct CapabilityCheckpoint {
92
- /// The capability ID
93
- pub capability_id: CapabilityId,
94
- /// Last processed instance ID
95
- pub last_processed_instance_id: String,
96
- /// Last processed sequence number
97
- pub last_processed_sequence: u64,
98
- /// Current lifecycle state
99
- pub lifecycle_state: CapabilityLifecycleState,
100
- /// Timestamp of last checkpoint (ms since UNIX epoch)
101
- pub checkpoint_ms: u128,
102
- /// Capability version
103
- pub version: u32,
104
- }
105
-
106
- impl CapabilityCheckpoint {
107
- pub fn new(capability_id: CapabilityId, instance_id: String) -> Self {
108
- Self {
109
- capability_id,
110
- last_processed_instance_id: instance_id,
111
- last_processed_sequence: 0,
112
- lifecycle_state: CapabilityLifecycleState::Registered,
113
- checkpoint_ms: crate::now_ms(),
114
- version: 1,
115
- }
116
- }
117
-
118
- /// Update checkpoint with new processed position
119
- pub fn update_position(&mut self, instance_id: String, sequence: u64) {
120
- self.last_processed_instance_id = instance_id;
121
- self.last_processed_sequence = sequence;
122
- self.checkpoint_ms = crate::now_ms();
123
- }
124
-
125
- /// Set lifecycle state
126
- pub fn set_state(&mut self, state: CapabilityLifecycleState) {
127
- self.lifecycle_state = state;
128
- self.checkpoint_ms = crate::now_ms();
129
- }
130
- }
131
-
132
- /// Result of processing an operation through a capability
133
- #[derive(Debug, Clone, Serialize, Deserialize)]
134
- pub struct CapabilityOperationResult {
135
- /// Whether the operation was successfully processed
136
- pub success: bool,
137
- /// Optional error message
138
- pub error: Option<String>,
139
- /// Optional result data
140
- pub result: Option<Value>,
141
- /// Whether this capability produced derived state
142
- pub produced_derived_state: bool,
143
- }
144
-
145
- impl CapabilityOperationResult {
146
- pub fn success() -> Self {
147
- Self {
148
- success: true,
149
- error: None,
150
- result: None,
151
- produced_derived_state: false,
152
- }
153
- }
154
-
155
- pub fn with_derived_state(result: Value) -> Self {
156
- Self {
157
- success: true,
158
- error: None,
159
- result: Some(result),
160
- produced_derived_state: true,
161
- }
162
- }
163
-
164
- pub fn error(msg: String) -> Self {
165
- Self {
166
- success: false,
167
- error: Some(msg),
168
- result: None,
169
- produced_derived_state: false,
170
- }
171
- }
172
- }
173
-
174
- /// Result of a capability query
175
- #[derive(Debug, Clone, Serialize, Deserialize)]
176
- pub struct CapabilityQueryResult {
177
- /// Whether the query succeeded
178
- pub success: bool,
179
- /// Query results
180
- pub results: Vec<Value>,
181
- /// Optional error message
182
- pub error: Option<String>,
183
- }
184
-
185
- impl CapabilityQueryResult {
186
- pub fn success(results: Vec<Value>) -> Self {
187
- Self {
188
- success: true,
189
- results,
190
- error: None,
191
- }
192
- }
193
-
194
- pub fn empty() -> Self {
195
- Self {
196
- success: true,
197
- results: Vec::new(),
198
- error: None,
199
- }
200
- }
201
-
202
- pub fn error(msg: String) -> Self {
203
- Self {
204
- success: false,
205
- results: Vec::new(),
206
- error: Some(msg),
207
- }
208
- }
209
- }
210
-
211
- /// Access model for capability security
212
- #[derive(Debug, Clone, Serialize, Deserialize)]
213
- pub struct CapabilityAccessModel {
214
- /// Collections this capability can read from
215
- pub reads: Vec<String>,
216
- /// Collections this capability can write to
217
- pub writes: Vec<String>,
218
- /// External systems this capability can execute
219
- pub executes: Vec<String>,
220
- }
221
-
222
- impl CapabilityAccessModel {
223
- pub fn new(reads: Vec<String>, writes: Vec<String>, executes: Vec<String>) -> Self {
224
- Self {
225
- reads,
226
- writes,
227
- executes,
228
- }
229
- }
230
-
231
- /// Check if capability can read from collection
232
- pub fn can_read(&self, collection: &str) -> bool {
233
- self.reads.contains(&collection.to_string()) || self.reads.iter().any(|r| r == "*")
234
- }
235
-
236
- /// Check if capability can write to collection
237
- pub fn can_write(&self, collection: &str) -> bool {
238
- self.writes.contains(&collection.to_string()) || self.writes.iter().any(|w| w == "*")
239
- }
240
-
241
- /// Check if capability can execute external system
242
- pub fn can_execute(&self, system: &str) -> bool {
243
- self.executes.contains(&system.to_string()) || self.executes.iter().any(|e| e == "*")
244
- }
245
- }
246
-
247
- /// Capability metadata and configuration
248
- #[derive(Debug, Clone, Serialize, Deserialize)]
249
- pub struct CapabilityMetadata {
250
- pub id: CapabilityId,
251
- pub name: String,
252
- pub description: String,
253
- pub role: CapabilityRole,
254
- pub access_model: CapabilityAccessModel,
255
- pub version: u32,
256
- pub created_ms: u128,
257
- }
258
-
259
- impl CapabilityMetadata {
260
- pub fn new(
261
- id: CapabilityId,
262
- name: String,
263
- description: String,
264
- role: CapabilityRole,
265
- access_model: CapabilityAccessModel,
266
- ) -> Self {
267
- Self {
268
- id,
269
- name,
270
- description,
271
- role,
272
- access_model,
273
- version: 1,
274
- created_ms: crate::now_ms(),
275
- }
276
- }
277
- }
278
-
279
- /// Capability registry - tracks all capabilities
280
- #[derive(Debug, Clone, Serialize, Deserialize)]
281
- pub struct CapabilityRegistry {
282
- /// All capabilities by ID
283
- #[serde(default)]
284
- capabilities: HashMap<CapabilityId, CapabilityMetadata>,
285
- /// Checkpoints by capability ID
286
- #[serde(default)]
287
- checkpoints: HashMap<CapabilityId, CapabilityCheckpoint>,
288
- }
289
-
290
- impl CapabilityRegistry {
291
- pub fn new() -> Self {
292
- Self {
293
- capabilities: HashMap::new(),
294
- checkpoints: HashMap::new(),
295
- }
296
- }
297
-
298
- /// Register a new capability
299
- pub fn register(&mut self, metadata: CapabilityMetadata) -> crate::Result<()> {
300
- let id = metadata.id.clone();
301
- if self.capabilities.contains_key(&id) {
302
- return Err(crate::FlowError::CapabilityError(
303
- "Capability already registered".to_string(),
304
- ));
305
- }
306
- let checkpoint = CapabilityCheckpoint::new(id.clone(), String::new());
307
- self.capabilities.insert(id.clone(), metadata);
308
- self.checkpoints.insert(id, checkpoint);
309
- Ok(())
310
- }
311
-
312
- /// Get capability metadata
313
- pub fn get(&self, id: &CapabilityId) -> Option<&CapabilityMetadata> {
314
- self.capabilities.get(id)
315
- }
316
-
317
- /// Get capability checkpoint
318
- pub fn get_checkpoint(&self, id: &CapabilityId) -> Option<&CapabilityCheckpoint> {
319
- self.checkpoints.get(id)
320
- }
321
-
322
- /// Update capability checkpoint
323
- pub fn update_checkpoint(&mut self, checkpoint: CapabilityCheckpoint) {
324
- self.checkpoints
325
- .insert(checkpoint.capability_id.clone(), checkpoint);
326
- }
327
-
328
- /// List all capabilities
329
- pub fn list(&self) -> Vec<&CapabilityMetadata> {
330
- self.capabilities.values().collect()
331
- }
332
-
333
- /// Remove a capability
334
- pub fn remove(&mut self, id: &CapabilityId) -> Option<CapabilityMetadata> {
335
- self.checkpoints.remove(id);
336
- self.capabilities.remove(id)
337
- }
338
- }
339
-
340
- impl Default for CapabilityRegistry {
341
- fn default() -> Self {
342
- Self::new()
343
- }
344
- }
345
-
346
- /// Trait for implementing capabilities
347
- /// This is the core contract for extending FeltDB with specialized behavior
348
- pub trait FlowCapability: Send + Sync {
349
- /// Get the capability ID
350
- fn id(&self) -> CapabilityId;
351
-
352
- /// Get the capability metadata
353
- fn metadata(&self) -> CapabilityMetadata;
354
-
355
- /// Initialize the capability (called on registration)
356
- fn initialize(&mut self, context: &CapabilityContext) -> crate::Result<()>;
357
-
358
- /// Process an operation - maintain derived state
359
- fn on_operation(
360
- &mut self,
361
- operation: &Operation,
362
- context: &CapabilityContext,
363
- ) -> crate::Result<CapabilityOperationResult>;
364
-
365
- /// Query the capability's derived state
366
- fn query(
367
- &self,
368
- query: &CapabilityQuery,
369
- context: &CapabilityContext,
370
- ) -> crate::Result<CapabilityQueryResult>;
371
-
372
- /// Rebuild the capability's derived state from scratch
373
- fn rebuild(
374
- &mut self,
375
- operations: &[Operation],
376
- context: &CapabilityContext,
377
- ) -> crate::Result<()>;
378
-
379
- /// Pause the capability
380
- fn pause(&mut self) -> crate::Result<()> {
381
- Ok(())
382
- }
383
-
384
- /// Resume the capability
385
- fn resume(&mut self) -> crate::Result<()> {
386
- Ok(())
387
- }
388
-
389
- /// Check if the capability is ready (fully caught up)
390
- fn is_ready(&self) -> bool {
391
- true
392
- }
393
- }
394
-
395
- /// Reference to a capability with namespace and version
396
- /// Canonical form: flow://capability/namespace:name@version
397
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
398
- pub struct CapabilityRef {
399
- /// Namespace (e.g., "docs", "images")
400
- pub namespace: String,
401
- /// Capability name (e.g., "vector-search", "image-analysis")
402
- pub capability: String,
403
- /// Capability version
404
- pub version: u32,
405
- }
406
-
407
- impl CapabilityRef {
408
- /// Create a new capability reference
409
- pub fn new(namespace: String, capability: String, version: u32) -> Self {
410
- Self {
411
- namespace,
412
- capability,
413
- version,
414
- }
415
- }
416
-
417
- /// Get canonical form for serialization
418
- pub fn canonical(&self) -> String {
419
- format!(
420
- "flow://capability/{}/{}@{}",
421
- self.namespace, self.capability, self.version
422
- )
423
- }
424
-
425
- /// Parse from canonical form
426
- pub fn from_canonical(canonical: &str) -> crate::Result<Self> {
427
- if !canonical.starts_with("flow://capability/") {
428
- return Err(crate::FlowError::CapabilityError(
429
- "Invalid capability reference format".to_string(),
430
- ));
431
- }
432
-
433
- let rest = &canonical[18..]; // Skip "flow://capability/"
434
- let parts: Vec<&str> = rest.split('/').collect();
435
- if parts.len() != 2 {
436
- return Err(crate::FlowError::CapabilityError(
437
- "Invalid capability reference format".to_string(),
438
- ));
439
- }
440
-
441
- let namespace = parts[0].to_string();
442
- let cap_parts: Vec<&str> = parts[1].split('@').collect();
443
- if cap_parts.len() != 2 {
444
- return Err(crate::FlowError::CapabilityError(
445
- "Invalid capability reference format".to_string(),
446
- ));
447
- }
448
-
449
- let capability = cap_parts[0].to_string();
450
- let version = cap_parts[1]
451
- .parse::<u32>()
452
- .map_err(|_| crate::FlowError::CapabilityError("Invalid version number".to_string()))?;
453
-
454
- Ok(Self::new(namespace, capability, version))
455
- }
456
- }
457
-
458
- impl fmt::Display for CapabilityRef {
459
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
460
- write!(f, "{}", self.canonical())
461
- }
462
- }
463
-
464
- /// Represents a required state for a capability to execute
465
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
466
- pub struct StateRequirement {
467
- /// Namespace containing the required state
468
- pub namespace: String,
469
- /// Minimum version required (0 means any)
470
- pub min_version: u64,
471
- }
472
-
473
- impl StateRequirement {
474
- pub fn new(namespace: String, min_version: u64) -> Self {
475
- Self {
476
- namespace,
477
- min_version,
478
- }
479
- }
480
- }
481
-
482
- /// Requirements for a capability to execute
483
- #[derive(Debug, Clone, Serialize, Deserialize)]
484
- pub struct CapabilityRequirements {
485
- /// Required namespaces and minimum versions
486
- pub required_state: Vec<StateRequirement>,
487
- /// Maximum acceptable latency for state (ms)
488
- pub max_state_latency_ms: Option<u64>,
489
- /// Whether execution requires single-owner semantics
490
- pub requires_ownership: bool,
491
- }
492
-
493
- impl CapabilityRequirements {
494
- pub fn new() -> Self {
495
- Self {
496
- required_state: Vec::new(),
497
- max_state_latency_ms: None,
498
- requires_ownership: false,
499
- }
500
- }
501
-
502
- pub fn with_required_state(mut self, requirement: StateRequirement) -> Self {
503
- self.required_state.push(requirement);
504
- self
505
- }
506
-
507
- pub fn with_max_latency(mut self, latency_ms: u64) -> Self {
508
- self.max_state_latency_ms = Some(latency_ms);
509
- self
510
- }
511
-
512
- pub fn with_ownership_requirement(mut self, requires: bool) -> Self {
513
- self.requires_ownership = requires;
514
- self
515
- }
516
- }
517
-
518
- impl Default for CapabilityRequirements {
519
- fn default() -> Self {
520
- Self::new()
521
- }
522
- }
523
-
524
- /// Advertises a capability at a specific peer with its requirements
525
- #[derive(Debug, Clone, Serialize, Deserialize)]
526
- pub struct DistributedCapabilityAdvertisement {
527
- /// The capability reference
528
- pub capability_ref: CapabilityRef,
529
- /// Peer ID providing this capability
530
- pub peer_id: String,
531
- /// Requirements for this capability
532
- pub requirements: CapabilityRequirements,
533
- /// Timestamp of advertisement
534
- pub advertised_ms: u128,
535
- }
536
-
537
- impl DistributedCapabilityAdvertisement {
538
- pub fn new(capability_ref: CapabilityRef, peer_id: String) -> Self {
539
- Self {
540
- capability_ref,
541
- peer_id,
542
- requirements: CapabilityRequirements::new(),
543
- advertised_ms: crate::now_ms(),
544
- }
545
- }
546
-
547
- pub fn with_requirements(mut self, requirements: CapabilityRequirements) -> Self {
548
- self.requirements = requirements;
549
- self
550
- }
551
- }
552
-
553
- /// Context for executing a capability (local or remote)
554
- #[derive(Debug, Clone, Serialize, Deserialize)]
555
- pub struct CapabilityExecutionContext {
556
- /// Unique execution ID
557
- pub execution_id: String,
558
- /// The capability being executed
559
- pub capability_ref: CapabilityRef,
560
- /// References to input data (instead of serialized payloads)
561
- pub input_refs: Vec<String>,
562
- /// Required state version for execution
563
- pub required_state_version: u64,
564
- /// Requester instance/peer ID
565
- pub requester: String,
566
- /// Timestamp when execution was requested
567
- pub requested_ms: u128,
568
- }
569
-
570
- impl CapabilityExecutionContext {
571
- pub fn new(execution_id: String, capability_ref: CapabilityRef, requester: String) -> Self {
572
- Self {
573
- execution_id,
574
- capability_ref,
575
- input_refs: Vec::new(),
576
- required_state_version: 0,
577
- requester,
578
- requested_ms: crate::now_ms(),
579
- }
580
- }
581
-
582
- pub fn with_input_ref(mut self, input_ref: String) -> Self {
583
- self.input_refs.push(input_ref);
584
- self
585
- }
586
-
587
- pub fn with_required_state_version(mut self, version: u64) -> Self {
588
- self.required_state_version = version;
589
- self
590
- }
591
- }
592
-
593
- /// Reference to an execution result with provenance
594
- #[derive(Debug, Clone, Serialize, Deserialize)]
595
- pub struct ExecutionRef {
596
- /// Unique execution ID
597
- pub execution_id: String,
598
- /// The capability that was executed
599
- pub capability_ref: CapabilityRef,
600
- /// Peer that executed the capability
601
- pub provider_peer: String,
602
- /// Input references used
603
- pub input_refs: Vec<String>,
604
- /// State version at time of execution
605
- pub input_state_version: u64,
606
- /// Content identity of the result
607
- pub result_content_identity: String,
608
- /// Operation that recorded this result
609
- pub created_operation: Option<String>,
610
- }
611
-
612
- impl ExecutionRef {
613
- pub fn new(execution_id: String, capability_ref: CapabilityRef, provider_peer: String) -> Self {
614
- Self {
615
- execution_id,
616
- capability_ref,
617
- provider_peer,
618
- input_refs: Vec::new(),
619
- input_state_version: 0,
620
- result_content_identity: String::new(),
621
- created_operation: None,
622
- }
623
- }
624
- }
625
-
626
- /// Result of a capability execution with full provenance
627
- #[derive(Debug, Clone, Serialize, Deserialize)]
628
- pub struct CapabilityExecutionResult {
629
- /// Reference to the execution
630
- pub execution_ref: ExecutionRef,
631
- /// The actual result data
632
- pub result: Value,
633
- /// Timestamp when execution completed
634
- pub completed_ms: u128,
635
- /// Any error that occurred
636
- pub error: Option<String>,
637
- }
638
-
639
- impl CapabilityExecutionResult {
640
- pub fn success(execution_ref: ExecutionRef, result: Value) -> Self {
641
- Self {
642
- execution_ref,
643
- result,
644
- completed_ms: crate::now_ms(),
645
- error: None,
646
- }
647
- }
648
-
649
- pub fn error(execution_ref: ExecutionRef, error: String) -> Self {
650
- Self {
651
- execution_ref,
652
- result: Value::Null,
653
- completed_ms: crate::now_ms(),
654
- error: Some(error),
655
- }
656
- }
657
- }
658
-
659
- /// Resolver for capabilities - routes to appropriate provider
660
- pub struct CapabilityResolver {
661
- /// Registered capabilities by ref
662
- capabilities: HashMap<String, DistributedCapabilityAdvertisement>,
663
- }
664
-
665
- impl CapabilityResolver {
666
- pub fn new() -> Self {
667
- Self {
668
- capabilities: HashMap::new(),
669
- }
670
- }
671
-
672
- /// Register a capability advertisement
673
- pub fn register(&mut self, ad: DistributedCapabilityAdvertisement) {
674
- self.capabilities.insert(ad.capability_ref.canonical(), ad);
675
- }
676
-
677
- /// Find a provider for a capability
678
- pub fn resolve(&self, cap_ref: &CapabilityRef) -> Option<&DistributedCapabilityAdvertisement> {
679
- self.capabilities.get(&cap_ref.canonical())
680
- }
681
-
682
- /// Find all providers for a capability (by name only)
683
- pub fn resolve_all(
684
- &self,
685
- namespace: &str,
686
- capability: &str,
687
- ) -> Vec<&DistributedCapabilityAdvertisement> {
688
- self.capabilities
689
- .values()
690
- .filter(|ad| {
691
- ad.capability_ref.namespace == namespace
692
- && ad.capability_ref.capability == capability
693
- })
694
- .collect()
695
- }
696
- }
697
-
698
- impl Default for CapabilityResolver {
699
- fn default() -> Self {
700
- Self::new()
701
- }
702
- }
703
-
704
- #[cfg(test)]
705
- mod tests {
706
- use super::*;
707
-
708
- #[test]
709
- fn test_capability_id_creation() {
710
- let id = CapabilityId::new("search".to_string());
711
- assert_eq!(id.0, "search");
712
- }
713
-
714
- #[test]
715
- fn test_capability_checkpoint() {
716
- let mut checkpoint = CapabilityCheckpoint::new(
717
- CapabilityId::new("search".to_string()),
718
- "instance-1".to_string(),
719
- );
720
- assert_eq!(checkpoint.last_processed_sequence, 0);
721
-
722
- checkpoint.update_position("instance-1".to_string(), 100);
723
- assert_eq!(checkpoint.last_processed_sequence, 100);
724
- }
725
-
726
- #[test]
727
- fn test_capability_access_model() {
728
- let access = CapabilityAccessModel::new(
729
- vec!["docs".to_string()],
730
- vec!["docs.search".to_string()],
731
- vec!["embedding-api".to_string()],
732
- );
733
-
734
- assert!(access.can_read("docs"));
735
- assert!(!access.can_read("users"));
736
- assert!(access.can_write("docs.search"));
737
- assert!(access.can_execute("embedding-api"));
738
- }
739
-
740
- #[test]
741
- fn test_capability_access_wildcard() {
742
- let access =
743
- CapabilityAccessModel::new(vec!["*".to_string()], vec!["*".to_string()], vec![]);
744
-
745
- assert!(access.can_read("anything"));
746
- assert!(access.can_write("anything"));
747
- }
748
-
749
- #[test]
750
- fn test_capability_registry() {
751
- let mut registry = CapabilityRegistry::new();
752
- let metadata = CapabilityMetadata::new(
753
- CapabilityId::new("search".to_string()),
754
- "Search Capability".to_string(),
755
- "Full-text search".to_string(),
756
- CapabilityRole::Projection,
757
- CapabilityAccessModel::new(
758
- vec!["docs".to_string()],
759
- vec!["docs.search".to_string()],
760
- vec![],
761
- ),
762
- );
763
-
764
- registry.register(metadata).unwrap();
765
- let cap_id = CapabilityId::new("search".to_string());
766
- assert!(registry.get(&cap_id).is_some());
767
- assert!(registry.get_checkpoint(&cap_id).is_some());
768
- }
769
-
770
- #[test]
771
- fn test_capability_ref_creation_and_canonical() {
772
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
773
- assert_eq!(cap_ref.namespace, "docs");
774
- assert_eq!(cap_ref.capability, "vector-search");
775
- assert_eq!(cap_ref.version, 1);
776
- assert_eq!(
777
- cap_ref.canonical(),
778
- "flow://capability/docs/vector-search@1"
779
- );
780
- }
781
-
782
- #[test]
783
- fn test_capability_ref_parse_canonical() {
784
- let canonical = "flow://capability/docs/vector-search@1";
785
- let cap_ref = CapabilityRef::from_canonical(canonical).unwrap();
786
- assert_eq!(cap_ref.namespace, "docs");
787
- assert_eq!(cap_ref.capability, "vector-search");
788
- assert_eq!(cap_ref.version, 1);
789
- }
790
-
791
- #[test]
792
- fn test_capability_ref_display() {
793
- let cap_ref = CapabilityRef::new("images".to_string(), "image-analysis".to_string(), 2);
794
- assert_eq!(
795
- cap_ref.to_string(),
796
- "flow://capability/images/image-analysis@2"
797
- );
798
- }
799
-
800
- #[test]
801
- fn test_state_requirement_creation() {
802
- let req = StateRequirement::new("docs".to_string(), 847);
803
- assert_eq!(req.namespace, "docs");
804
- assert_eq!(req.min_version, 847);
805
- }
806
-
807
- #[test]
808
- fn test_capability_requirements_builder() {
809
- let reqs = CapabilityRequirements::new()
810
- .with_required_state(StateRequirement::new("docs".to_string(), 847))
811
- .with_max_latency(5000)
812
- .with_ownership_requirement(true);
813
-
814
- assert_eq!(reqs.required_state.len(), 1);
815
- assert_eq!(reqs.max_state_latency_ms, Some(5000));
816
- assert!(reqs.requires_ownership);
817
- }
818
-
819
- #[test]
820
- fn test_distributed_capability_advertisement() {
821
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
822
- let ad = DistributedCapabilityAdvertisement::new(cap_ref.clone(), "peer-b".to_string())
823
- .with_requirements(
824
- CapabilityRequirements::new()
825
- .with_required_state(StateRequirement::new("docs".to_string(), 847)),
826
- );
827
-
828
- assert_eq!(ad.capability_ref, cap_ref);
829
- assert_eq!(ad.peer_id, "peer-b");
830
- assert_eq!(ad.requirements.required_state.len(), 1);
831
- }
832
-
833
- #[test]
834
- fn test_capability_execution_context() {
835
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
836
- let ctx = CapabilityExecutionContext::new(
837
- "exec-123".to_string(),
838
- cap_ref.clone(),
839
- "requester".to_string(),
840
- )
841
- .with_input_ref("flow://docs#123".to_string())
842
- .with_required_state_version(851);
843
-
844
- assert_eq!(ctx.execution_id, "exec-123");
845
- assert_eq!(ctx.capability_ref, cap_ref);
846
- assert_eq!(ctx.input_refs.len(), 1);
847
- assert_eq!(ctx.required_state_version, 851);
848
- }
849
-
850
- #[test]
851
- fn test_execution_ref_creation() {
852
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
853
- let exec_ref = ExecutionRef::new(
854
- "exec-123".to_string(),
855
- cap_ref.clone(),
856
- "peer-b".to_string(),
857
- );
858
-
859
- assert_eq!(exec_ref.execution_id, "exec-123");
860
- assert_eq!(exec_ref.capability_ref, cap_ref);
861
- assert_eq!(exec_ref.provider_peer, "peer-b");
862
- }
863
-
864
- #[test]
865
- fn test_capability_execution_result_success() {
866
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
867
- let exec_ref = ExecutionRef::new("exec-123".to_string(), cap_ref, "peer-b".to_string());
868
- let result = serde_json::json!({"results": [1, 2, 3]});
869
-
870
- let exec_result = CapabilityExecutionResult::success(exec_ref.clone(), result.clone());
871
- assert!(exec_result.error.is_none());
872
- assert_eq!(exec_result.result, result);
873
- }
874
-
875
- #[test]
876
- fn test_capability_resolver_registration() {
877
- let mut resolver = CapabilityResolver::new();
878
- let cap_ref = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
879
- let ad = DistributedCapabilityAdvertisement::new(cap_ref.clone(), "peer-b".to_string());
880
-
881
- resolver.register(ad);
882
-
883
- let resolved = resolver.resolve(&cap_ref);
884
- assert!(resolved.is_some());
885
- assert_eq!(resolved.unwrap().peer_id, "peer-b");
886
- }
887
-
888
- #[test]
889
- fn test_capability_resolver_resolve_all() {
890
- let mut resolver = CapabilityResolver::new();
891
-
892
- let cap_ref_v1 = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 1);
893
- let ad1 = DistributedCapabilityAdvertisement::new(cap_ref_v1, "peer-a".to_string());
894
- resolver.register(ad1);
895
-
896
- let cap_ref_v2 = CapabilityRef::new("docs".to_string(), "vector-search".to_string(), 2);
897
- let ad2 = DistributedCapabilityAdvertisement::new(cap_ref_v2, "peer-b".to_string());
898
- resolver.register(ad2);
899
-
900
- let all = resolver.resolve_all("docs", "vector-search");
901
- assert_eq!(all.len(), 2);
902
- }
903
- }